diff --git a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/blocks/DoorHandler.java b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/blocks/DoorHandler.java index 3d6ab4f2..45c8f05e 100644 --- a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/blocks/DoorHandler.java +++ b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/blocks/DoorHandler.java @@ -3,9 +3,11 @@ import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion; import cc.funkemunky.api.utils.BlockUtils; import cc.funkemunky.api.utils.world.CollisionBox; +import cc.funkemunky.api.utils.world.state.BlockStateManager; import cc.funkemunky.api.utils.world.types.CollisionFactory; import cc.funkemunky.api.utils.world.types.NoCollisionBox; import cc.funkemunky.api.utils.world.types.SimpleCollisionBox; +import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.material.Door; @@ -16,39 +18,35 @@ public class DoorHandler implements CollisionFactory { @Override public CollisionBox fetch(ProtocolVersion version, Block b) { - Door state = (Door) b.getState().getData(); - byte data = state.getData(); - if (( data & 0b01000 ) != 0) { + Block blockTwo; + if ((boolean)BlockStateManager.getInterface("top", b)) { Optional rel = BlockUtils.getRelativeAsync(b, BlockFace.DOWN); if(!rel.isPresent()) return NoCollisionBox.INSTANCE; - MaterialData state2 = rel.get().getState().getData(); - if (state2 instanceof Door) { - data = state2.getData(); + + if(BlockUtils.isDoor(rel.get())) { + blockTwo = rel.get(); } else { return NoCollisionBox.INSTANCE; } - } else { + } else if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_13)) { Optional rel = BlockUtils.getRelativeAsync(b, BlockFace.UP); if(!rel.isPresent()) return NoCollisionBox.INSTANCE; - MaterialData state2 = rel.get().getState().getData(); - if (state2 instanceof Door) { - state = (Door) state2; + if(BlockUtils.isDoor(rel.get())) { + blockTwo = rel.get(); } else { return NoCollisionBox.INSTANCE; } - } + } else blockTwo = b; SimpleCollisionBox box; float offset = 0.1875F; - int direction = (data & 0b11); - boolean open = (data & 0b100) != 0; - boolean hinge = (state.getData() & 1) == 1; - - + int direction = (int) BlockStateManager.getInterface("facing", b); + boolean open = (boolean) BlockStateManager.getInterface("open", b); + boolean hinge = (boolean) BlockStateManager.getInterface("hinge", blockTwo); if (direction == 0) { if (open) { if (!hinge) { diff --git a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/state/states/Version_1_13.java b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/state/states/Version_1_13.java new file mode 100644 index 00000000..820306eb --- /dev/null +++ b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/state/states/Version_1_13.java @@ -0,0 +1,38 @@ +package cc.funkemunky.api.utils.world.state.states; + +import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion; +import cc.funkemunky.api.utils.Init; +import cc.funkemunky.api.utils.world.state.BlockStateManager; +import org.bukkit.Material; +import org.bukkit.block.data.Bisected; +import org.bukkit.block.data.type.Door; + +import java.util.Arrays; + +@Init(requireProtocolVersion = ProtocolVersion.V1_13) +public class Version_1_13 { + public Version_1_13() { + Arrays.stream(Material.values()) + .filter(m -> m.name().contains("DOOR") && !m.name().contains("TRAP")) + .forEach(m -> { + BlockStateManager.stateInterfaceMap.put(m, (field, block) -> { + Door door = (Door) block.getBlockData(); + switch (field.toLowerCase()) { + case "hinge": { + return door.getHinge().equals(Door.Hinge.RIGHT); + } + case "top": { + return door.getHalf().equals(Bisected.Half.TOP); + } + case "facing": { + return door.getFacing().ordinal() - 1; + } + case "open": { + return door.isOpen(); + } + } + return null; + }); + }); + } +} diff --git a/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/state/states/Version_1_7_10.java b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/state/states/Version_1_7_10.java new file mode 100644 index 00000000..f32f0b3a --- /dev/null +++ b/AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/world/state/states/Version_1_7_10.java @@ -0,0 +1,40 @@ +package cc.funkemunky.api.utils.world.state.states; + +import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion; +import cc.funkemunky.api.utils.Init; +import cc.funkemunky.api.utils.world.state.BlockStateManager; +import org.bukkit.Material; +import org.bukkit.block.data.Bisected; +import org.bukkit.material.Door; + +import java.util.Arrays; + +@Init +public class Version_1_7_10 { + public Version_1_7_10() { + if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_13)) { + Arrays.stream(Material.values()) + .filter(m -> m.name().contains("DOOR") && !m.name().contains("TRAP")) + .forEach(m -> { + BlockStateManager.stateInterfaceMap.put(m, (field, block) -> { + Door door = (Door) block.getType().getNewData(block.getData()); + switch (field.toLowerCase()) { + case "hinge": { + return door.getHinge(); + } + case "top": { + return door.isTopHalf(); + } + case "facing": { + return door.getFacing().ordinal(); + } + case "open": { + return door.isOpen(); + } + } + return null; + }); + }); + } + } +}