@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); }
public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) { storeBlock(connection, new Position(x, y, z), blockState); }
public Position getRelative(BlockFace face) { return new Position(this.x + face.getModX(), this.y + face.getModY(), this.z + face.getModZ()); }
block = ConnectionData.connect(user, new Position(xOff + x, yOff + y, zOff + z), block); section.setFlatBlock(x, y, z, block); update(user, new Position(xOff - 1, yOff + y, zOff + z)); } else if (x == 15) { update(user, new Position(xOff + 16, yOff + y, zOff + z)); update(user, new Position(xOff + x, yOff + y, zOff - 1)); } else if (z == 15) { update(user, new Position(xOff + x, yOff + y, zOff + 16));
public static void handle(List<CompoundTag> tags, UserConnection connection) { for (CompoundTag tag : tags) { try { if (!tag.contains("id")) throw new Exception("NBT tag not handled because the id key is missing"); String id = (String) tag.get("id").getValue(); if (!types.containsKey(id)) throw new Exception("Not handled id: " + id); int newId = types.get(id); if (newId == -1) continue; int x = (int) tag.get("x").getValue(); int y = (int) tag.get("y").getValue(); int z = (int) tag.get("z").getValue(); Position pos = new Position((long) x, (long) y, (long) z); updateBlockEntity(pos, (short) newId, tag, connection); } catch (Exception e) { if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Block Entity: " + e.getMessage() + ": " + tag); } } } }
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(); } } } } }
@Listener public void placeBlock(ChangeBlockEvent.Place e, @Root Player player) { if (isOnPipe(player.getUniqueId())) { Location loc = e.getTransactions().get(0).getFinal().getLocation().get(); getUserConnection(player.getUniqueId()) .get(EntityTracker.class) .addBlockInteraction(new Position((long) loc.getX(), (long) loc.getY(), (long) loc.getZ())); } } }
@Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag); return -1; } // RED_BED + FIRST_BED int blockId = storage.get(position).getOriginal() - 972 + 748; int color = (int) tag.get("color").getValue(); blockId += (color * 16); return blockId; }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void placeBlock(BlockPlaceEvent e) { if (isOnPipe(e.getPlayer())) { Block b = e.getBlockPlaced(); getUserConnection(e.getPlayer()) .get(EntityTracker.class) .addBlockInteraction(new Position((long) b.getX(), (long) b.getY(), (long) b.getZ())); } } }
@Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag); return -1; } int id = storage.get(position).getOriginal(); if (id >= SKULL_WALL_START && id <= SKULL_END) { id += (byte) tag.get("SkullType").getValue() * 20; if (tag.contains("Rot")) { id += (byte) tag.get("Rot").getValue(); } } else { Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag); return -1; } return id; }
@Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag); return -1; } int blockId = storage.get(position).getOriginal(); int color = (int) tag.get("Base").getValue(); // Standing banner if (blockId >= BANNER_START && blockId <= BANNER_STOP) { blockId += ((15 - color) * 16); // Wall banner } else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) { blockId += ((15 - color) * 4); } else { Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag); } if (tag.get("Patterns") instanceof ListTag) { for (Tag pattern : (ListTag) tag.get("Patterns")) { if (pattern instanceof CompoundTag) { IntTag c = ((CompoundTag) pattern).get("Color"); c.setValue(15 - c.getValue()); // Invert color id } } } return blockId; }
chunk.getBlockEntities().forEach(nbt -> { if (!nbt.contains("x") || !nbt.contains("y") || !nbt.contains("z") || !nbt.contains("id")) return; Position position = new Position((long) (int) nbt.get("x").getValue(), (long) (int) nbt.get("y").getValue(), (long) (int) nbt.get("z").getValue()); String id = (String) nbt.get("id").getValue();