Cleanup ConnectionData#update and fix doors

This commit is contained in:
creeper123123321 2019-02-13 16:02:58 -02:00
parent 0886fdabd3
commit 7859f5ebd6
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
2 changed files with 22 additions and 19 deletions

View File

@ -9,7 +9,12 @@ import java.util.Map;
@Getter
@AllArgsConstructor
public enum BlockFace {
NORTH(0, 0, -1, EnumAxis.Z), SOUTH(0, 0, 1, EnumAxis.Z), EAST(1, 0, 0, EnumAxis.X), WEST(-1, 0, 0, EnumAxis.X), TOP(0, 1, 0, EnumAxis.Y), BOTTOM(0, -1, 0, EnumAxis.Y);
NORTH(0, 0, -1, EnumAxis.Z),
SOUTH(0, 0, 1, EnumAxis.Z),
EAST(1, 0, 0, EnumAxis.X),
WEST(-1, 0, 0, EnumAxis.X),
TOP(0, 1, 0, EnumAxis.Y),
BOTTOM(0, -1, 0, EnumAxis.Y);
private static Map<BlockFace, BlockFace> opposites = new HashMap<>();

View File

@ -27,25 +27,23 @@ public class ConnectionData {
static Set<Integer> occludingStates = new HashSet<>();
public static void update(UserConnection user, Position position) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
for (int y = -1; y <= 1; y++) {
if (Math.abs(x) + Math.abs(y) + Math.abs(z) != 1) continue;
Position pos = new Position(position.getX() + x, position.getY() + y, position.getZ() + z);
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
if (!connects(blockState)) continue;
int newBlockState = connect(user, pos, blockState);
if (newBlockState == blockState) continue;
for (BlockFace face : BlockFace.values()) {
Position pos = new Position(
position.getX() + face.getModX(),
position.getY() + face.getModY(),
position.getZ() + face.getModZ()
);
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
if (!connects(blockState)) continue;
int newBlockState = connect(user, pos, blockState);
PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
blockUpdatePacket.write(Type.POSITION, pos);
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
try {
blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false);
} catch (Exception ex) {
ex.printStackTrace();
}
}
PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
blockUpdatePacket.write(Type.POSITION, pos);
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
try {
blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}