com.nukkitx.nbt.tag.CompoundTag Java Examples
The following examples show how to use
com.nukkitx.nbt.tag.CompoundTag.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StructureTemplateDataExportResponseSerializer_v388.java From Protocol with Apache License 2.0 | 6 votes |
@Override public void deserialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) { packet.setName(BedrockUtils.readString(buffer)); boolean save = buffer.readBoolean(); packet.setSave(save); if (save) { try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { Tag<?> tag = reader.readTag(); if (tag instanceof CompoundTag) { packet.setTag((CompoundTag) tag); } else { throw new IllegalArgumentException("Tag received was not a CompoundTag"); } } catch (IOException e) { throw new RuntimeException(e); } } }
Example #2
Source File: PaletteManager.java From BedrockConnect with GNU General Public License v3.0 | 6 votes |
public PaletteManager() { InputStream stream = BedrockConnect.class.getClassLoader().getResourceAsStream("tables/runtime_block_states.dat"); if (stream == null) { throw new AssertionError("Unable to locate block state nbt"); } Map<String, Integer> blockIdToIdentifier = new HashMap<>(); ListTag<CompoundTag> tag; NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream); ListTag<CompoundTag> blocksTag; try { tag = (ListTag<CompoundTag>) nbtInputStream.readTag(); nbtInputStream.close(); } catch (Exception ex) { System.out.println("Failed to receive blocks palette"); throw new AssertionError(ex); } CACHED_PALLETE = tag; }
Example #3
Source File: PistonBlockEntityTranslator.java From Geyser with MIT License | 6 votes |
/** * Calculates the Nukkit CompoundTag to send to the client on chunk * @param blockState Java BlockState of block. * @param position Bedrock position of piston. * @return Bedrock tag of piston. */ public static CompoundTag getTag(BlockState blockState, Vector3i position) { CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder() .intTag("x", position.getX()) .intTag("y", position.getY()) .intTag("z", position.getZ()) .byteTag("isMovable", (byte) 1) .stringTag("id", "PistonArm"); if (BlockStateValues.getPistonValues().containsKey(blockState.getId())) { boolean extended = BlockStateValues.getPistonValues().get(blockState.getId()); // 1f if extended, otherwise 0f tagBuilder.floatTag("Progress", (extended) ? 1.0f : 0.0f); // 1 if sticky, 0 if not tagBuilder.byteTag("Sticky", (byte)((BlockStateValues.isStickyPiston(blockState)) ? 1 : 0)); } return tagBuilder.buildRootTag(); }
Example #4
Source File: BlockInventoryHolder.java From Geyser with MIT License | 6 votes |
@Override public void prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { Vector3i position = session.getPlayerEntity().getPosition().toInt(); position = position.add(Vector3i.UP); UpdateBlockPacket blockPacket = new UpdateBlockPacket(); blockPacket.setDataLayer(0); blockPacket.setBlockPosition(position); blockPacket.setRuntimeId(blockId); blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY); session.sendUpstreamPacket(blockPacket); inventory.setHolderPosition(position); CompoundTag tag = CompoundTag.builder() .intTag("x", position.getX()) .intTag("y", position.getY()) .intTag("z", position.getZ()) .stringTag("CustomName", LocaleUtils.getLocaleString(inventory.getTitle(), session.getClientData().getLanguageCode())).buildRootTag(); BlockEntityDataPacket dataPacket = new BlockEntityDataPacket(); dataPacket.setData(tag); dataPacket.setBlockPosition(position); session.sendUpstreamPacket(dataPacket); }
Example #5
Source File: FlowerPotBlockEntityTranslator.java From Geyser with MIT License | 6 votes |
/** * Get the Nukkit CompoundTag of the flower pot. * @param blockState Java BlockState of flower pot. * @param position Bedrock position of flower pot. * @return Bedrock tag of flower pot. */ public static CompoundTag getTag(BlockState blockState, Vector3i position) { CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder() .intTag("x", position.getX()) .intTag("y", position.getY()) .intTag("z", position.getZ()) .byteTag("isMovable", (byte) 1) .stringTag("id", "FlowerPot"); // Get the Java name of the plant inside. e.g. minecraft:oak_sapling String name = BlockStateValues.getFlowerPotValues().get(blockState.getId()); if (name != null) { // Get the Bedrock CompoundTag of the block. // This is where we need to store the *Java* name because Bedrock has six minecraft:sapling blocks with different block states. CompoundTag plant = BlockStateValues.getFlowerPotBlocks().get(name); if (plant != null) { tagBuilder.tag(plant.toBuilder().build("PlantBlock")); } } return tagBuilder.buildRootTag(); }
Example #6
Source File: StructureTemplateDataExportResponseSerializer_v361.java From Protocol with Apache License 2.0 | 6 votes |
@Override public void deserialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) { packet.setName(BedrockUtils.readString(buffer)); boolean save = buffer.readBoolean(); packet.setSave(save); if (save) { try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { Tag<?> tag = reader.readTag(); if (tag instanceof CompoundTag) { packet.setTag((CompoundTag) tag); } else { throw new IllegalArgumentException("Tag received was not a CompoundTag"); } } catch (IOException e) { throw new RuntimeException(e); } } }
Example #7
Source File: PipePlayer.java From BedrockConnect with GNU General Public License v3.0 | 5 votes |
public void spawn() { Vector3f pos = Vector3f.ZERO; int chunkX = pos.getFloorX() >> 4; int chunkZ = pos.getFloorX() >> 4; for (int x = -3; x < 3; x++) { for (int z = -3; z < 3; z++) { LevelChunkPacket data2 = new LevelChunkPacket(); data2.setChunkX(chunkX + x); data2.setChunkZ(chunkZ + z); data2.setSubChunksLength(0); data2.setData(EMPTY_LEVEL_CHUNK_DATA); session.sendPacket(data2); } } BiomeDefinitionListPacket biomePacket = new BiomeDefinitionListPacket(); biomePacket.setTag(CompoundTag.EMPTY); session.sendPacket(biomePacket); AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket(); entityPacket.setTag(CompoundTag.EMPTY); session.sendPacket(entityPacket); PlayStatusPacket playStatus = new PlayStatusPacket(); playStatus.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); session.sendPacket(playStatus); }
Example #8
Source File: ItemData.java From Protocol with Apache License 2.0 | 5 votes |
public static ItemData of(int id, short damage, int count, CompoundTag tag, String[] canPlace, String[] canBreak, long blockingTicks) { if (id == 0) { return AIR; } Preconditions.checkNotNull(canPlace, "canPlace"); Preconditions.checkNotNull(canBreak, "canBreak"); Preconditions.checkArgument(count < 256, "count exceeds maximum of 255"); return new ItemData(id, damage, count, tag, canPlace, canBreak, blockingTicks); }
Example #9
Source File: BlockPaletteUtils.java From ProxyPass with GNU Affero General Public License v3.0 | 5 votes |
public static void convertToJson(ProxyPass proxy, List<CompoundTag> tags) { List<Entry> palette = new ArrayList<>(tags.size()); for (CompoundTag tag : tags) { int id = tag.getShort("id"); CompoundTag blockTag = tag.getCompound("block"); String name = blockTag.getString("name"); Map<String, BlockState> states = new LinkedHashMap<>(); blockTag.getCompound("states").getValue().forEach((key, value) -> { states.put(key, new BlockState(value.getValue(), TagType.byClass(value.getClass()).getId())); }); Integer meta = null; if (tag.contains("meta")) { meta = (int) tag.getShort("meta"); } palette.add(new Entry(id, meta, name, states)); } palette.sort((o1, o2) -> { int compare = Integer.compare(o1.id, o2.id); if (compare == 0) { for (Map.Entry<String, BlockState> entry : o1.states.entrySet()) { BlockState bs2 = o2.states.get(entry.getKey()); compare = ((Comparable) entry.getValue().val).compareTo(bs2.val); if (compare != 0) { break; } } } return compare; }); proxy.saveJson("runtime_block_states.json", palette); }
Example #10
Source File: RecipeUtils.java From ProxyPass with GNU Affero General Public License v3.0 | 5 votes |
private static String nbtToBase64(CompoundTag tag) { if (tag != null) { ByteArrayOutputStream tagStream = new ByteArrayOutputStream(); try (NBTOutputStream writer = NbtUtils.createWriterLE(tagStream)) { writer.write(tag); } catch (IOException e) { throw new RuntimeException(e); } return Base64.getEncoder().encodeToString(tagStream.toByteArray()); } else { return null; } }
Example #11
Source File: DownstreamPacketHandler.java From ProxyPass with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean handle(InventoryContentPacket packet) { if (packet.getContainerId() == ContainerId.CREATIVE) { List<CreativeItemEntry> entries = new ArrayList<>(); for (ItemData data : packet.getContents()) { int id = data.getId(); Integer damage = data.getDamage() == 0 ? null : (int) data.getDamage(); CompoundTag tag = data.getTag(); String tagData = null; if (tag != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (NBTOutputStream stream = new NBTOutputStream(new LittleEndianDataOutputStream(byteArrayOutputStream))) { stream.write(tag); } catch (IOException e) { throw new RuntimeException(e); } tagData = Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()); } entries.add(new CreativeItemEntry(id, damage, tagData)); } CreativeItems items = new CreativeItems(entries); proxy.saveJson("creative_items.json", items); } return false; }
Example #12
Source File: ItemTranslator.java From Geyser with MIT License | 5 votes |
public CompoundTag translateNbtToBedrock(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) { Map<String, Tag<?>> javaValue = new HashMap<>(); if (tag.getValue() != null && !tag.getValue().isEmpty()) { for (String str : tag.getValue().keySet()) { com.github.steveice10.opennbt.tag.builtin.Tag javaTag = tag.get(str); com.nukkitx.nbt.tag.Tag<?> translatedTag = translateToBedrockNBT(javaTag); if (translatedTag == null) continue; javaValue.put(translatedTag.getName(), translatedTag); } } return new CompoundTag(tag.getName(), javaValue); }
Example #13
Source File: ItemTranslator.java From Geyser with MIT License | 5 votes |
public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) { if (itemData == null) return null; if (itemData.getTag() == null) { return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new com.github.steveice10.opennbt.tag.builtin.CompoundTag("")); } return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT(itemData.getTag())); }
Example #14
Source File: JavaTradeListTranslator.java From Geyser with MIT License | 5 votes |
private CompoundTag getItemTag(GeyserSession session, ItemStack stack, String name, int specialPrice) { ItemData itemData = ItemTranslator.translateToBedrock(session, stack); ItemEntry itemEntry = ItemRegistry.getItem(stack); CompoundTagBuilder builder = CompoundTagBuilder.builder(); builder.byteTag("Count", (byte) (Math.max(itemData.getCount() + specialPrice, 1))); builder.shortTag("Damage", itemData.getDamage()); builder.shortTag("id", (short) itemEntry.getBedrockId()); if (itemData.getTag() != null) { CompoundTag tag = itemData.getTag().toBuilder().build("tag"); builder.tag(tag); } return builder.build(name); }
Example #15
Source File: JavaBlockValueTranslator.java From Geyser with MIT License | 5 votes |
/** * Build a piston tag * @param position Piston position * @param progress Current progress of piston * @param lastProgress Last progress of piston * @param state * @return Bedrock CompoundTag of piston */ private CompoundTag buildPistonTag(Vector3i position, float progress, float lastProgress, byte state) { CompoundTagBuilder builder = CompoundTag.EMPTY.toBuilder(); builder.intTag("x", position.getX()) .intTag("y", position.getY()) .intTag("z", position.getZ()) .floatTag("Progress", progress) .floatTag("LastProgress", lastProgress) .stringTag("id", "PistonArm") .byteTag("NewState", state) .byteTag("State", state); return builder.buildRootTag(); }
Example #16
Source File: BlockTranslator.java From Geyser with MIT License | 5 votes |
private static CompoundTag buildBedrockState(JsonNode node) { CompoundTagBuilder tagBuilder = CompoundTag.builder(); tagBuilder.stringTag("name", node.get("bedrock_identifier").textValue()) .intTag("version", BlockTranslator.BLOCK_STATE_VERSION); CompoundTagBuilder statesBuilder = CompoundTag.builder(); // check for states if (node.has("bedrock_states")) { Iterator<Map.Entry<String, JsonNode>> statesIterator = node.get("bedrock_states").fields(); while (statesIterator.hasNext()) { Map.Entry<String, JsonNode> stateEntry = statesIterator.next(); JsonNode stateValue = stateEntry.getValue(); switch (stateValue.getNodeType()) { case BOOLEAN: statesBuilder.booleanTag(stateEntry.getKey(), stateValue.booleanValue()); continue; case STRING: statesBuilder.stringTag(stateEntry.getKey(), stateValue.textValue()); continue; case NUMBER: statesBuilder.intTag(stateEntry.getKey(), stateValue.intValue()); } } } return tagBuilder.tag(statesBuilder.build("states")).build("block"); }
Example #17
Source File: BedrockOnlyBlockEntity.java From Geyser with MIT License | 5 votes |
/** * Get the tag of the Bedrock-only block entity * @param position Bedrock position of block. * @param blockState Java BlockState of block. * @return Bedrock tag, or null if not a Bedrock-only Block Entity */ static CompoundTag getTag(Vector3i position, BlockState blockState) { if (new FlowerPotBlockEntityTranslator().isBlock(blockState)) { return FlowerPotBlockEntityTranslator.getTag(blockState, position); } else if (PistonBlockEntityTranslator.isBlock(blockState)) { return PistonBlockEntityTranslator.getTag(blockState, position); } return null; }
Example #18
Source File: SkullBlockEntityTranslator.java From Geyser with MIT License | 5 votes |
@Override public CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) { CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder(); tagBuilder.floatTag("Rotation", 0); tagBuilder.byteTag("SkullType", (byte) 0); return tagBuilder.buildRootTag(); }
Example #19
Source File: SkullBlockEntityTranslator.java From Geyser with MIT License | 5 votes |
@Override public List<Tag<?>> translateTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); byte skullVariant = BlockStateValues.getSkullVariant(blockState); float rotation = BlockStateValues.getSkullRotation(blockState) * 22.5f; // Just in case... if (skullVariant == -1) skullVariant = 0; tags.add(new FloatTag("Rotation", rotation)); tags.add(new ByteTag("SkullType", skullVariant)); return tags; }
Example #20
Source File: ItemFrameEntity.java From Geyser with MIT License | 5 votes |
private CompoundTag getDefaultTag() { CompoundTagBuilder builder = CompoundTag.builder(); builder.intTag("x", bedrockPosition.getX()); builder.intTag("y", bedrockPosition.getY()); builder.intTag("z", bedrockPosition.getZ()); builder.byteTag("isMovable", (byte) 1); builder.stringTag("id", "ItemFrame"); return builder.buildRootTag(); }
Example #21
Source File: ItemFrameEntity.java From Geyser with MIT License | 5 votes |
public ItemFrameEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, HangingDirection direction) { super(entityId, geyserId, entityType, position, motion, rotation); CompoundTagBuilder builder = CompoundTag.builder(); builder.tag(CompoundTag.builder() .stringTag("name", "minecraft:frame") .intTag("version", BlockTranslator.getBlockStateVersion()) .tag(CompoundTag.builder() .intTag("facing_direction", direction.ordinal()) .byteTag("item_frame_map_bit", (byte) 0) .build("states")) .build("block")); builder.shortTag("id", (short) 199); bedrockRuntimeId = BlockTranslator.getItemFrame(builder.buildRootTag()); bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ()); }
Example #22
Source File: StartGameSerializer_v291.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, StartGamePacket packet) { packet.setUniqueEntityId(VarInts.readLong(buffer)); packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPlayerGamemode(VarInts.readInt(buffer)); packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector2f(buffer)); // Level settings start packet.setSeed(VarInts.readInt(buffer)); packet.setDimensionId(VarInts.readInt(buffer)); packet.setGeneratorId(VarInts.readInt(buffer)); packet.setLevelGamemode(VarInts.readInt(buffer)); packet.setDifficulty(VarInts.readInt(buffer)); packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); packet.setAchievementsDisabled(buffer.readBoolean()); packet.setTime(VarInts.readInt(buffer)); packet.setEduEditionOffers(buffer.readBoolean() ? 1 : 0); packet.setEduFeaturesEnabled(buffer.readBoolean()); packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); packet.setMultiplayerGame(buffer.readBoolean()); packet.setBroadcastingToLan(buffer.readBoolean()); buffer.readBoolean(); // broadcasting to XBL packet.setCommandsEnabled(buffer.readBoolean()); packet.setTexturePacksRequired(buffer.readBoolean()); BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); packet.setTrustingPlayers(buffer.readBoolean()); packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); packet.setServerChunkTickRange(buffer.readIntLE()); buffer.readBoolean(); // Broadcasting to Platform packet.setPlatformBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); buffer.readBoolean(); // Intent on XBL broadcast packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); packet.setFromLockedWorldTemplate(buffer.readBoolean()); packet.setUsingMsaGamertagsOnly(buffer.readBoolean()); // Level settings end packet.setLevelId(BedrockUtils.readString(buffer)); packet.setWorldName(BedrockUtils.readString(buffer)); packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer)); packet.setTrial(buffer.readBoolean()); packet.setCurrentTick(buffer.readLongLE()); packet.setEnchantmentSeed(VarInts.readInt(buffer)); int paletteLength = VarInts.readUnsignedInt(buffer); List<CompoundTag> palette = new ObjectArrayList<>(paletteLength); for (int i = 0; i < paletteLength; i++) { palette.add(CompoundTagBuilder.builder() .tag(CompoundTagBuilder.builder() .stringTag("name", BedrockUtils.readString(buffer)) .build("block")) .shortTag("meta", buffer.readShortLE()) .buildRootTag()); } packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer)); }
Example #23
Source File: StartGameSerializer_v332.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, StartGamePacket packet) { packet.setUniqueEntityId(VarInts.readLong(buffer)); packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPlayerGamemode(VarInts.readInt(buffer)); packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector2f(buffer)); // Level settings start packet.setSeed(VarInts.readInt(buffer)); packet.setDimensionId(VarInts.readInt(buffer)); packet.setGeneratorId(VarInts.readInt(buffer)); packet.setLevelGamemode(VarInts.readInt(buffer)); packet.setDifficulty(VarInts.readInt(buffer)); packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); packet.setAchievementsDisabled(buffer.readBoolean()); packet.setTime(VarInts.readInt(buffer)); packet.setEduEditionOffers(buffer.readBoolean() ? 1 : 0); packet.setEduFeaturesEnabled(buffer.readBoolean()); packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); packet.setMultiplayerGame(buffer.readBoolean()); packet.setBroadcastingToLan(buffer.readBoolean()); packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); packet.setPlatformBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); packet.setCommandsEnabled(buffer.readBoolean()); packet.setTexturePacksRequired(buffer.readBoolean()); BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); packet.setFromLockedWorldTemplate(buffer.readBoolean()); packet.setUsingMsaGamertagsOnly(buffer.readBoolean()); packet.setFromWorldTemplate(buffer.readBoolean()); packet.setWorldTemplateOptionLocked(buffer.readBoolean()); // Level settings end packet.setLevelId(BedrockUtils.readString(buffer)); packet.setWorldName(BedrockUtils.readString(buffer)); packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer)); packet.setTrial(buffer.readBoolean()); packet.setCurrentTick(buffer.readLongLE()); packet.setEnchantmentSeed(VarInts.readInt(buffer)); int paletteLength = VarInts.readUnsignedInt(buffer); List<CompoundTag> palette = new ObjectArrayList<>(paletteLength); for (int i = 0; i < paletteLength; i++) { palette.add(CompoundTagBuilder.builder() .tag(CompoundTagBuilder.builder() .stringTag("name", BedrockUtils.readString(buffer)) .build("block")) .shortTag("meta", buffer.readShortLE()) .buildRootTag()); } packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer)); }
Example #24
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 4 votes |
public static void writeEntityData(ByteBuf buffer, EntityDataMap entityDataMap) { Preconditions.checkNotNull(buffer, "buffer"); Preconditions.checkNotNull(entityDataMap, "entityDataDictionary"); VarInts.writeUnsignedInt(buffer, entityDataMap.size()); for (Map.Entry<EntityData, Object> entry : entityDataMap.entrySet()) { int index = buffer.writerIndex(); VarInts.writeUnsignedInt(buffer, METADATAS.get(entry.getKey())); Object object = entry.getValue(); EntityData.Type type = EntityData.Type.from(object); VarInts.writeUnsignedInt(buffer, METADATA_TYPES.get(type)); switch (type) { case BYTE: buffer.writeByte((byte) object); break; case SHORT: buffer.writeShortLE((short) object); break; case INT: VarInts.writeInt(buffer, (int) object); break; case FLOAT: buffer.writeFloatLE((float) object); break; case STRING: BedrockUtils.writeString(buffer, (String) object); break; case NBT: ItemData item; if (object instanceof CompoundTag) { item = ItemData.of(1, (short) 0, 1, (CompoundTag) object); } else { item = (ItemData) object; } BedrockUtils.writeItemData(buffer, item); break; case VECTOR3I: BedrockUtils.writeVector3i(buffer, (Vector3i) object); break; case FLAGS: int flagsIndex = entry.getKey() == FLAGS_2 ? 1 : 0; object = ((EntityFlags) object).get(flagsIndex, METADATA_FLAGS); case LONG: VarInts.writeLong(buffer, (long) object); break; case VECTOR3F: BedrockUtils.writeVector3f(buffer, (Vector3f) object); break; default: buffer.writerIndex(index); break; } } }
Example #25
Source File: StartGameSerializer_v340.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void serialize(ByteBuf buffer, StartGamePacket packet) { VarInts.writeLong(buffer, packet.getUniqueEntityId()); VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); VarInts.writeInt(buffer, packet.getPlayerGamemode()); BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); BedrockUtils.writeVector2f(buffer, packet.getRotation()); // Level settings start VarInts.writeInt(buffer, packet.getSeed()); VarInts.writeInt(buffer, packet.getDimensionId()); VarInts.writeInt(buffer, packet.getGeneratorId()); VarInts.writeInt(buffer, packet.getLevelGamemode()); VarInts.writeInt(buffer, packet.getDifficulty()); BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn()); buffer.writeBoolean(packet.isAchievementsDisabled()); VarInts.writeInt(buffer, packet.getTime()); buffer.writeBoolean(packet.getEduEditionOffers() != 0); buffer.writeBoolean(packet.isEduFeaturesEnabled()); buffer.writeFloatLE(packet.getRainLevel()); buffer.writeFloatLE(packet.getLightningLevel()); buffer.writeBoolean(packet.isPlatformLockedContentConfirmed()); buffer.writeBoolean(packet.isMultiplayerGame()); buffer.writeBoolean(packet.isBroadcastingToLan()); VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal()); VarInts.writeInt(buffer, packet.getPlatformBroadcastMode().ordinal()); buffer.writeBoolean(packet.isCommandsEnabled()); buffer.writeBoolean(packet.isTexturePacksRequired()); BedrockUtils.writeArray(buffer, packet.getGamerules(), BedrockUtils::writeGameRule); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); buffer.writeBoolean(packet.isFromLockedWorldTemplate()); buffer.writeBoolean(packet.isUsingMsaGamertagsOnly()); buffer.writeBoolean(packet.isFromWorldTemplate()); buffer.writeBoolean(packet.isWorldTemplateOptionLocked()); // Level settings end BedrockUtils.writeString(buffer, packet.getLevelId()); BedrockUtils.writeString(buffer, packet.getWorldName()); BedrockUtils.writeString(buffer, packet.getPremiumWorldTemplateId()); buffer.writeBoolean(packet.isTrial()); buffer.writeLongLE(packet.getCurrentTick()); VarInts.writeInt(buffer, packet.getEnchantmentSeed()); List<CompoundTag> palette = packet.getBlockPalette().getValue(); VarInts.writeUnsignedInt(buffer, palette.size()); for (CompoundTag entry : palette) { CompoundTag blockTag = entry.getCompound("block"); BedrockUtils.writeString(buffer, blockTag.getString("name")); buffer.writeShortLE(entry.getShort("meta")); } BedrockUtils.writeString(buffer, packet.getMultiplayerCorrelationId()); }
Example #26
Source File: StartGameSerializer_v340.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, StartGamePacket packet) { packet.setUniqueEntityId(VarInts.readLong(buffer)); packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPlayerGamemode(VarInts.readInt(buffer)); packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector2f(buffer)); // Level settings start packet.setSeed(VarInts.readInt(buffer)); packet.setDimensionId(VarInts.readInt(buffer)); packet.setGeneratorId(VarInts.readInt(buffer)); packet.setLevelGamemode(VarInts.readInt(buffer)); packet.setDifficulty(VarInts.readInt(buffer)); packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); packet.setAchievementsDisabled(buffer.readBoolean()); packet.setTime(VarInts.readInt(buffer)); packet.setEduEditionOffers(buffer.readBoolean() ? 1 : 0); packet.setEduFeaturesEnabled(buffer.readBoolean()); packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); packet.setPlatformLockedContentConfirmed(buffer.readBoolean()); packet.setMultiplayerGame(buffer.readBoolean()); packet.setBroadcastingToLan(buffer.readBoolean()); packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); packet.setPlatformBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); packet.setCommandsEnabled(buffer.readBoolean()); packet.setTexturePacksRequired(buffer.readBoolean()); BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); packet.setFromLockedWorldTemplate(buffer.readBoolean()); packet.setUsingMsaGamertagsOnly(buffer.readBoolean()); packet.setFromWorldTemplate(buffer.readBoolean()); packet.setWorldTemplateOptionLocked(buffer.readBoolean()); // Level settings end packet.setLevelId(BedrockUtils.readString(buffer)); packet.setWorldName(BedrockUtils.readString(buffer)); packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer)); packet.setTrial(buffer.readBoolean()); packet.setCurrentTick(buffer.readLongLE()); packet.setEnchantmentSeed(VarInts.readInt(buffer)); int paletteLength = VarInts.readUnsignedInt(buffer); List<CompoundTag> palette = new ObjectArrayList<>(paletteLength); for (int i = 0; i < paletteLength; i++) { palette.add(CompoundTagBuilder.builder() .tag(CompoundTagBuilder.builder() .stringTag("name", BedrockUtils.readString(buffer)) .build("block")) .shortTag("meta", buffer.readShortLE()) .buildRootTag()); } packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer)); }
Example #27
Source File: BedrockUtils.java From Protocol with Apache License 2.0 | 4 votes |
public static void writeEntityData(ByteBuf buffer, EntityDataMap entityDataMap) { Preconditions.checkNotNull(buffer, "buffer"); Preconditions.checkNotNull(entityDataMap, "entityDataDictionary"); VarInts.writeUnsignedInt(buffer, entityDataMap.size()); for (Map.Entry<EntityData, Object> entry : entityDataMap.entrySet()) { int index = buffer.writerIndex(); VarInts.writeUnsignedInt(buffer, METADATAS.get(entry.getKey())); Object object = entry.getValue(); EntityData.Type type = EntityData.Type.from(object); VarInts.writeUnsignedInt(buffer, METADATA_TYPES.get(type)); switch (type) { case BYTE: buffer.writeByte((byte) object); break; case SHORT: buffer.writeShortLE((short) object); break; case INT: VarInts.writeInt(buffer, (int) object); break; case FLOAT: buffer.writeFloatLE((float) object); break; case STRING: BedrockUtils.writeString(buffer, (String) object); break; case NBT: ItemData item; if (object instanceof CompoundTag) { item = ItemData.of(1, (short) 0, 1, (CompoundTag) object); } else { item = (ItemData) object; } BedrockUtils.writeItemData(buffer, item); break; case VECTOR3I: BedrockUtils.writeVector3i(buffer, (Vector3i) object); break; case FLAGS: int flagsIndex = entry.getKey() == FLAGS_2 ? 1 : 0; object = ((EntityFlags) object).get(flagsIndex, METADATA_FLAGS); case LONG: VarInts.writeLong(buffer, (long) object); break; case VECTOR3F: BedrockUtils.writeVector3f(buffer, (Vector3f) object); break; default: buffer.writerIndex(index); break; } } }
Example #28
Source File: StartGameSerializer_v313.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void serialize(ByteBuf buffer, StartGamePacket packet) { VarInts.writeLong(buffer, packet.getUniqueEntityId()); VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); VarInts.writeInt(buffer, packet.getPlayerGamemode()); BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); BedrockUtils.writeVector2f(buffer, packet.getRotation()); // Level settings start VarInts.writeInt(buffer, packet.getSeed()); VarInts.writeInt(buffer, packet.getDimensionId()); VarInts.writeInt(buffer, packet.getGeneratorId()); VarInts.writeInt(buffer, packet.getLevelGamemode()); VarInts.writeInt(buffer, packet.getDifficulty()); BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn()); buffer.writeBoolean(packet.isAchievementsDisabled()); VarInts.writeInt(buffer, packet.getTime()); buffer.writeBoolean(packet.getEduEditionOffers() != 0); buffer.writeBoolean(packet.isEduFeaturesEnabled()); buffer.writeFloatLE(packet.getRainLevel()); buffer.writeFloatLE(packet.getLightningLevel()); buffer.writeBoolean(packet.isMultiplayerGame()); buffer.writeBoolean(packet.isBroadcastingToLan()); buffer.writeBoolean(packet.getXblBroadcastMode() != GamePublishSetting.NO_MULTI_PLAY); buffer.writeBoolean(packet.isCommandsEnabled()); buffer.writeBoolean(packet.isTexturePacksRequired()); BedrockUtils.writeArray(buffer, packet.getGamerules(), BedrockUtils::writeGameRule); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); buffer.writeBoolean(packet.isTrustingPlayers()); VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.getPlatformBroadcastMode() != GamePublishSetting.NO_MULTI_PLAY); VarInts.writeInt(buffer, packet.getPlatformBroadcastMode().ordinal()); buffer.writeBoolean(packet.getXblBroadcastMode() != GamePublishSetting.NO_MULTI_PLAY); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); buffer.writeBoolean(packet.isFromLockedWorldTemplate()); buffer.writeBoolean(packet.isUsingMsaGamertagsOnly()); buffer.writeBoolean(packet.isFromWorldTemplate()); buffer.writeBoolean(packet.isWorldTemplateOptionLocked()); // Level settings end BedrockUtils.writeString(buffer, packet.getLevelId()); BedrockUtils.writeString(buffer, packet.getWorldName()); BedrockUtils.writeString(buffer, packet.getPremiumWorldTemplateId()); buffer.writeBoolean(packet.isTrial()); buffer.writeLongLE(packet.getCurrentTick()); VarInts.writeInt(buffer, packet.getEnchantmentSeed()); List<CompoundTag> palette = packet.getBlockPalette().getValue(); VarInts.writeUnsignedInt(buffer, palette.size()); for (CompoundTag entry : palette) { CompoundTag blockTag = entry.getCompound("block"); BedrockUtils.writeString(buffer, blockTag.getString("name")); buffer.writeShortLE(entry.getShort("meta")); } BedrockUtils.writeString(buffer, packet.getMultiplayerCorrelationId()); }
Example #29
Source File: StartGameSerializer_v313.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, StartGamePacket packet) { packet.setUniqueEntityId(VarInts.readLong(buffer)); packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPlayerGamemode(VarInts.readInt(buffer)); packet.setPlayerPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector2f(buffer)); // Level settings start packet.setSeed(VarInts.readInt(buffer)); packet.setDimensionId(VarInts.readInt(buffer)); packet.setGeneratorId(VarInts.readInt(buffer)); packet.setLevelGamemode(VarInts.readInt(buffer)); packet.setDifficulty(VarInts.readInt(buffer)); packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer)); packet.setAchievementsDisabled(buffer.readBoolean()); packet.setTime(VarInts.readInt(buffer)); packet.setEduEditionOffers(buffer.readBoolean() ? 1 : 0); packet.setEduFeaturesEnabled(buffer.readBoolean()); packet.setRainLevel(buffer.readFloatLE()); packet.setLightningLevel(buffer.readFloatLE()); packet.setMultiplayerGame(buffer.readBoolean()); packet.setBroadcastingToLan(buffer.readBoolean()); buffer.readBoolean(); // broadcasting to XBL packet.setCommandsEnabled(buffer.readBoolean()); packet.setTexturePacksRequired(buffer.readBoolean()); BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); packet.setTrustingPlayers(buffer.readBoolean()); packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); packet.setServerChunkTickRange(buffer.readIntLE()); buffer.readBoolean(); // broadcasting to Platform packet.setPlatformBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); buffer.readBoolean(); // Intent to broadcast XBL packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); packet.setFromLockedWorldTemplate(buffer.readBoolean()); packet.setUsingMsaGamertagsOnly(buffer.readBoolean()); packet.setFromWorldTemplate(buffer.readBoolean()); packet.setWorldTemplateOptionLocked(buffer.readBoolean()); // Level settings end packet.setLevelId(BedrockUtils.readString(buffer)); packet.setWorldName(BedrockUtils.readString(buffer)); packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer)); packet.setTrial(buffer.readBoolean()); packet.setCurrentTick(buffer.readLongLE()); packet.setEnchantmentSeed(VarInts.readInt(buffer)); int paletteLength = VarInts.readUnsignedInt(buffer); List<CompoundTag> palette = new ObjectArrayList<>(paletteLength); for (int i = 0; i < paletteLength; i++) { palette.add(CompoundTagBuilder.builder() .tag(CompoundTagBuilder.builder() .stringTag("name", BedrockUtils.readString(buffer)) .build("block")) .shortTag("meta", buffer.readShortLE()) .buildRootTag()); } packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette)); packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer)); }
Example #30
Source File: StartGameSerializer_v361.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void serialize(ByteBuf buffer, StartGamePacket packet) { VarInts.writeLong(buffer, packet.getUniqueEntityId()); VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); VarInts.writeInt(buffer, packet.getPlayerGamemode()); BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition()); BedrockUtils.writeVector2f(buffer, packet.getRotation()); // Level settings start VarInts.writeInt(buffer, packet.getSeed()); VarInts.writeInt(buffer, packet.getDimensionId()); VarInts.writeInt(buffer, packet.getGeneratorId()); VarInts.writeInt(buffer, packet.getLevelGamemode()); VarInts.writeInt(buffer, packet.getDifficulty()); BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn()); buffer.writeBoolean(packet.isAchievementsDisabled()); VarInts.writeInt(buffer, packet.getTime()); buffer.writeBoolean(packet.getEduEditionOffers() != 0); buffer.writeBoolean(packet.isEduFeaturesEnabled()); buffer.writeFloatLE(packet.getRainLevel()); buffer.writeFloatLE(packet.getLightningLevel()); buffer.writeBoolean(packet.isPlatformLockedContentConfirmed()); buffer.writeBoolean(packet.isMultiplayerGame()); buffer.writeBoolean(packet.isBroadcastingToLan()); VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal()); VarInts.writeInt(buffer, packet.getPlatformBroadcastMode().ordinal()); buffer.writeBoolean(packet.isCommandsEnabled()); buffer.writeBoolean(packet.isTexturePacksRequired()); BedrockUtils.writeArray(buffer, packet.getGamerules(), BedrockUtils::writeGameRule); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); buffer.writeBoolean(packet.isFromLockedWorldTemplate()); buffer.writeBoolean(packet.isUsingMsaGamertagsOnly()); buffer.writeBoolean(packet.isFromWorldTemplate()); buffer.writeBoolean(packet.isWorldTemplateOptionLocked()); buffer.writeBoolean(packet.isOnlySpawningV1Villagers()); // Level settings end BedrockUtils.writeString(buffer, packet.getLevelId()); BedrockUtils.writeString(buffer, packet.getWorldName()); BedrockUtils.writeString(buffer, packet.getPremiumWorldTemplateId()); buffer.writeBoolean(packet.isTrial()); buffer.writeLongLE(packet.getCurrentTick()); VarInts.writeInt(buffer, packet.getEnchantmentSeed()); List<CompoundTag> palette = packet.getBlockPalette().getValue(); VarInts.writeUnsignedInt(buffer, palette.size()); for (CompoundTag entry : palette) { CompoundTag blockTag = entry.getCompound("block"); BedrockUtils.writeString(buffer, blockTag.getString("name")); buffer.writeShortLE(entry.getShort("meta")); buffer.writeShortLE(entry.getShort("id")); } BedrockUtils.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> { BedrockUtils.writeString(buf, entry.getIdentifier()); buf.writeShortLE(entry.getId()); }); BedrockUtils.writeString(buffer, packet.getMultiplayerCorrelationId()); }