public BlockPositon(Position position) { x = position.getX().intValue(); y = position.getY().intValue(); z = position.getZ().intValue(); } }
private Pair<Integer, Integer> getChunkCoords(Position position) { int chunkX = (int) Math.floor(position.getX() / 16); int chunkZ = (int) Math.floor(position.getZ() / 16); return new Pair<>(chunkX, chunkZ); }
@Override public void write(ByteBuf buffer, Position object) { buffer.writeLong(((object.getX() & 0x3ffffff) << 38) | ((object.getY() & 0xfff) << 26) | (object.getZ() & 0x3ffffff)); } }
public boolean interactedBlockRecently(int x, int y, int z) { if (blockInteractions.size() == 0) return false; for (Position p : blockInteractions.asMap().keySet()) { if (p.getX() == x) if (p.getY() == y) if (p.getZ() == z) return true; } return false; }
private Pair<Integer, Integer> getPair(Position position) { int chunkX = (int) (position.getX() >> 4); int chunkZ = (int) (position.getZ() >> 4); return new Pair<>(chunkX, chunkZ); }
@Override public int getWorldBlockData(UserConnection user, Position position) { if (blockStateIds != null) { UUID uuid = user.get(ProtocolInfo.class).getUuid(); Optional<Player> player = Sponge.getServer().getPlayer(uuid); if (player.isPresent()) { World world = player.get().getWorld(); Optional<Chunk> chunk = world.getChunkAtBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); if (chunk.isPresent()) { BlockState b = chunk.get().getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); Integer id = blockStateIds.get(b); if (id == null) { System.out.println("id not found"); } else { return id; } } } } return 0; } }
@Override public int getWorldBlockData(UserConnection user, Position position) { UUID uuid = user.get(ProtocolInfo.class).getUuid(); Player player = Bukkit.getPlayer(uuid); if (player != null) { World world = player.getWorld(); int x = (int) (position.getX() >> 4); int z = (int) (position.getZ() >> 4); if (world.isChunkLoaded(x, z)) { Chunk c = getChunk(world, x, z); Block b = c.getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); return b.getTypeId() << 4 | b.getData(); } } return 0; }
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; 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(); } } } } }