private Environment getEnvFromId(int id) { Environment output = Environment.getEnvironmentById(id); if (output == null) return Environment.NETHER; return output; } }
@Override public Position read(ByteBuf buffer) { long val = buffer.readLong(); long x = (val >> 38); // signed long y = (val >> 26) & 0xfff; // unsigned // this shifting madness is used to preserve sign long z = (val << 38) >> 38; // signed return new Position(x, y, z); }
@Override public void write(ByteBuf buffer, BlockChangeRecord object) throws Exception { Type.UNSIGNED_BYTE.write(buffer, object.getHorizontal()); Type.UNSIGNED_BYTE.write(buffer, object.getY()); Type.VAR_INT.write(buffer, object.getBlockId()); } }
public boolean connectsTo(String blockConnection, BlockFace face) { final Boolean[] booleans = connectData.get(blockConnection); return booleans != null && booleans[face.ordinal()]; } }
protected byte getStates(UserConnection user, Position position, int blockState) { byte states = 0; if (connects(BlockFace.EAST, getBlockData(user, position.getRelative(BlockFace.EAST)))) states |= 1; if (connects(BlockFace.NORTH, getBlockData(user, position.getRelative(BlockFace.NORTH)))) states |= 2; if (connects(BlockFace.SOUTH, getBlockData(user, position.getRelative(BlockFace.SOUTH)))) states |= 4; if (connects(BlockFace.WEST, getBlockData(user, position.getRelative(BlockFace.WEST)))) states |= 8; return states; }
@Override public BlockChangeRecord read(ByteBuf buffer) throws Exception { short horizontal = Type.UNSIGNED_BYTE.read(buffer); short y = Type.UNSIGNED_BYTE.read(buffer); int blockId = Type.VAR_INT.read(buffer); return new BlockChangeRecord(horizontal, y, blockId); }
@Override public Vector read(ByteBuf buffer) throws Exception { int x = Type.INT.read(buffer); int y = Type.INT.read(buffer); int z = Type.INT.read(buffer); return new Vector(x, y, z); }
@Override public EulerAngle read(ByteBuf buffer) throws Exception { float x = Type.FLOAT.read(buffer); float y = Type.FLOAT.read(buffer); float z = Type.FLOAT.read(buffer); return new EulerAngle(x, y, z); }
public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) { storeBlock(connection, new Position(x, y, z), blockState); }
private static short getStates(StairData stairData) { short s = 0; if (stairData.isBottom()) s |= 1; s |= stairData.getShape() << 1; s |= stairData.getType() << 4; s |= stairData.getFacing().ordinal() << 9; return s; }
private int getBlockFaces(UserConnection user, Position position) { int blockFaces = 0; for (int i = 0; i < BLOCK_FACES.length; i++) { if (isWall(getBlockData(user, position.getRelative(BLOCK_FACES[i])))) { blockFaces |= 1 << i; } } return blockFaces; }
private static short getStates(DoorData doorData) { short s = 0; if (doorData.isLower()) s |= 1; if (doorData.isOpen()) s |= 2; if (doorData.isPowered()) s |= 4; if (doorData.isRightHinge()) s |= 8; s |= doorData.getFacing().ordinal() << 4; s |= (doorData.getType() & 0x7) << 6; return s; }
public boolean up(UserConnection user, Position position) { if (isWall(getBlockData(user, position.getRelative(BlockFace.BOTTOM))) || isWall(getBlockData(user, position.getRelative(BlockFace.TOP)))) return true; int blockFaces = getBlockFaces(user, position); if (blockFaces == 0 || blockFaces == 0xF) return true; for (int i = 0; i < BLOCK_FACES.length; i++) { if ((blockFaces & (1 << i)) != 0 && (blockFaces & (1 << OPPOSITES[i])) == 0) return true; } return false; }