implement StateFunction

This commit is contained in:
dfsek
2021-01-05 01:04:15 -07:00
parent aec1d671fa
commit a38eba2916
14 changed files with 306 additions and 32 deletions

View File

@@ -55,8 +55,7 @@ public class EventListener implements Listener {
TreeRegistry registry = c.getTreeRegistry();
Tree tree = registry.get(TREE_TYPE_STRING_TRANSFORMER.translate(e.getSpecies()));
Debug.info("Overrode tree type: " + e.getSpecies());
org.bukkit.Location location = e.getLocation().subtract(0, 1, 0);
org.bukkit.Location location = e.getLocation();
if(!tree.plant(new Location(bukkit, location.getX(), location.getY(), location.getZ()), new FastRandom())) block.setBlockData(data);
}
}

View File

@@ -6,6 +6,7 @@ import com.dfsek.terra.api.platform.block.state.BlockState;
import com.dfsek.terra.bukkit.world.block.BukkitBlock;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData;
import org.bukkit.block.Container;
import org.bukkit.block.Sign;
public class BukkitBlockState implements BlockState {
private final org.bukkit.block.BlockState delegate;
@@ -16,6 +17,7 @@ public class BukkitBlockState implements BlockState {
public static BukkitBlockState newInstance(org.bukkit.block.BlockState block) {
if(block instanceof Container) return new BukkitContainer((Container) block);
if(block instanceof Sign) return new BukkitSign((Sign) block);
return new BukkitBlockState(block);
}

View File

@@ -5,6 +5,7 @@ import com.dfsek.terra.api.platform.inventory.Inventory;
import com.dfsek.terra.bukkit.world.inventory.BukkitInventory;
public class BukkitContainer extends BukkitBlockState implements Container {
protected BukkitContainer(org.bukkit.block.Container block) {
super(block);
}
@@ -13,4 +14,5 @@ public class BukkitContainer extends BukkitBlockState implements Container {
public Inventory getInventory() {
return new BukkitInventory(((org.bukkit.block.Container) getHandle()).getInventory());
}
}

View File

@@ -0,0 +1,32 @@
package com.dfsek.terra.bukkit.world.block.state;
import com.dfsek.terra.api.platform.block.state.SerialState;
import com.dfsek.terra.api.platform.block.state.Sign;
import org.jetbrains.annotations.NotNull;
public class BukkitSign extends BukkitBlockState implements Sign {
protected BukkitSign(org.bukkit.block.Sign block) {
super(block);
}
@Override
public @NotNull String[] getLines() {
return ((org.bukkit.block.Sign) getHandle()).getLines();
}
@Override
public @NotNull String getLine(int index) throws IndexOutOfBoundsException {
return ((org.bukkit.block.Sign) getHandle()).getLine(index);
}
@Override
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
((org.bukkit.block.Sign) getHandle()).setLine(index, line);
}
@Override
public void applyState(String state) {
SerialState.parse(state).forEach((k, v) -> setLine(Integer.parseInt(k), v));
}
}