Skip to content

Commit

Permalink
Fixing doors on 1.13+
Browse files Browse the repository at this point in the history
  • Loading branch information
funkemunky committed Feb 16, 2022
1 parent 9a9077e commit da79bab
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Block> 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<Block> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
});
});
}
}
Original file line number Diff line number Diff line change
@@ -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;
});
});
}
}
}

0 comments on commit da79bab

Please sign in to comment.