com.nukkitx.nbt.CompoundTagBuilder Java Examples

The following examples show how to use com.nukkitx.nbt.CompoundTagBuilder. 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: BannerTranslator.java    From Geyser with MIT License 6 votes vote down vote up
@Override
public ItemData translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) {
    if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, itemEntry);

    ItemData itemData = super.translateToBedrock(itemStack, itemEntry);

    CompoundTag blockEntityTag = itemStack.getNbt().get("BlockEntityTag");
    if (blockEntityTag.contains("Patterns")) {
        ListTag patterns = blockEntityTag.get("Patterns");

        CompoundTagBuilder builder = itemData.getTag().toBuilder();
        builder.tag(convertBannerPattern(patterns));

        itemData = ItemData.of(itemData.getId(), itemData.getDamage(), itemData.getCount(), builder.buildRootTag());
    }

    return itemData;
}
 
Example #2
Source File: PistonBlockEntityTranslator.java    From Geyser with MIT License 6 votes vote down vote up
/**
 * 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 #3
Source File: FlowerPotBlockEntityTranslator.java    From Geyser with MIT License 6 votes vote down vote up
/**
 * 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 #4
Source File: ItemFrameEntity.java    From Geyser with MIT License 5 votes vote down vote up
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 #5
Source File: InventoryUtils.java    From Geyser with MIT License 5 votes vote down vote up
/**
 * Returns a barrier block with custom name and lore to explain why
 * part of the inventory is unusable.
 */
public static ItemData createUnusableSpaceBlock(String description) {
    CompoundTagBuilder root = CompoundTagBuilder.builder();
    CompoundTagBuilder display = CompoundTagBuilder.builder();

    display.stringTag("Name", ChatColor.RESET + "Unusable inventory space");
    display.listTag("Lore", StringTag.class, Collections.singletonList(new StringTag("", ChatColor.RESET + ChatColor.DARK_PURPLE + description)));

    root.tag(display.build("display"));
    return ItemData.of(ItemRegistry.ITEM_ENTRIES.get(ItemRegistry.BARRIER_INDEX).getBedrockId(), (short) 0, 1, root.buildRootTag());
}
 
Example #6
Source File: BannerTranslator.java    From Geyser with MIT License 5 votes vote down vote up
/**
 * Convert the Java edition banner pattern nbt to Bedrock edition, null if the pattern doesn't exist
 *
 * @param pattern Java edition pattern nbt
 * @return The Bedrock edition format pattern nbt
 */
public static com.nukkitx.nbt.tag.CompoundTag getBedrockBannerPattern(CompoundTag pattern) {
    String patternName = (String) pattern.get("Pattern").getValue();

    // Return null if its the globe pattern as it doesn't exist on bedrock
    if (patternName.equals("glb")) {
        return null;
    }

    return CompoundTagBuilder.builder()
            .intTag("Color", 15 - (int) pattern.get("Color").getValue())
            .stringTag("Pattern", (String) pattern.get("Pattern").getValue())
            .stringTag("Pattern", patternName)
            .buildRootTag();
}
 
Example #7
Source File: JavaTradeListTranslator.java    From Geyser with MIT License 5 votes vote down vote up
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 #8
Source File: JavaBlockValueTranslator.java    From Geyser with MIT License 5 votes vote down vote up
/**
 * 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 #9
Source File: BlockTranslator.java    From Geyser with MIT License 5 votes vote down vote up
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 #10
Source File: CampfireBlockEntityTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item1", new HashMap<>()));
    tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item2", new HashMap<>()));
    tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item3", new HashMap<>()));
    tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item4", new HashMap<>()));
    return tagBuilder.buildRootTag();
}
 
Example #11
Source File: EndGatewayBlockEntityTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    List<IntTag> tagsList = new ArrayList<>();
    tagsList.add(new IntTag("", 0));
    tagsList.add(new IntTag("", 0));
    tagsList.add(new IntTag("", 0));
    tagBuilder.listTag("ExitPortal", IntTag.class, tagsList);
    return tagBuilder.buildRootTag();
}
 
Example #12
Source File: BlockEntityTranslator.java    From Geyser with MIT License 5 votes vote down vote up
protected com.nukkitx.nbt.tag.CompoundTag getConstantBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
            .intTag("x", x)
            .intTag("y", y)
            .intTag("z", z)
            .stringTag("id", bedrockId);
    return tagBuilder.buildRootTag();
}
 
Example #13
Source File: DoubleChestBlockEntityTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void updateBlock(GeyserSession session, BlockState blockState, Vector3i position) {
    CompoundTag javaTag = getConstantJavaTag("chest", position.getX(), position.getY(), position.getZ());
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId("chest"), position.getX(), position.getY(), position.getZ()).toBuilder();
    translateTag(javaTag, blockState).forEach(tagBuilder::tag);
    BlockEntityUtils.updateBlockEntity(session, tagBuilder.buildRootTag(), position);
}
 
Example #14
Source File: SpawnerBlockEntityTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    tagBuilder.byteTag("isMovable", (byte) 1)
            .stringTag("id", "MobSpawner");

    return tagBuilder.buildRootTag();
}
 
Example #15
Source File: SkullBlockEntityTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@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 #16
Source File: ItemFrameEntity.java    From Geyser with MIT License 5 votes vote down vote up
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 #17
Source File: ShulkerBoxBlockEntityTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    tagBuilder.byteTag("facing", (byte)1);
    return tagBuilder.buildRootTag();
}
 
Example #18
Source File: StartGameSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@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 #19
Source File: StartGameSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@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 #20
Source File: StartGameSerializer_v361.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@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());
    packet.setOnlySpawningV1Villagers(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())
                .shortTag("id", buffer.readShortLE())
                .buildRootTag());
    }
    packet.setBlockPalette(new ListTag<>("", CompoundTag.class, palette));

    BedrockUtils.readArray(buffer, packet.getItemEntries(), buf -> {
        String identifier = BedrockUtils.readString(buf);
        short id = buf.readShortLE();
        return new StartGamePacket.ItemEntry(identifier, id);
    });

    packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer));
}
 
Example #21
Source File: StartGameSerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@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 #22
Source File: StartGameSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@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 #23
Source File: StartGameSerializer_v354.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@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: JavaTradeListTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void translate(ServerTradeListPacket packet, GeyserSession session) {
    Entity villager = session.getPlayerEntity();
    session.setVillagerTrades(packet.getTrades());
    villager.getMetadata().put(EntityData.TRADE_TIER, packet.getVillagerLevel() - 1);
    villager.getMetadata().put(EntityData.MAX_TRADE_TIER, 4);
    villager.getMetadata().put(EntityData.TRADE_XP, packet.getExperience());
    villager.updateBedrockMetadata(session);

    UpdateTradePacket updateTradePacket = new UpdateTradePacket();
    updateTradePacket.setTradeTier(packet.getVillagerLevel() - 1);
    updateTradePacket.setWindowId((short) packet.getWindowId());
    updateTradePacket.setWindowType((short) ContainerType.TRADING.id());
    String displayName;
    Entity realVillager = session.getEntityCache().getEntityByGeyserId(session.getLastInteractedVillagerEid());
    if (realVillager != null && realVillager.getMetadata().containsKey(EntityData.NAMETAG) && realVillager.getMetadata().getString(EntityData.NAMETAG) != null) {
        displayName = realVillager.getMetadata().getString(EntityData.NAMETAG);
    } else {
        displayName = packet.isRegularVillager() ? "Villager" : "Wandering Trader";
    }
    updateTradePacket.setDisplayName(displayName);
    updateTradePacket.setUnknownInt(0);
    updateTradePacket.setScreen2(true);
    updateTradePacket.setWilling(true);
    updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().getGeyserId());
    updateTradePacket.setTraderUniqueEntityId(session.getPlayerEntity().getGeyserId());
    CompoundTagBuilder builder = CompoundTagBuilder.builder();
    List<CompoundTag> tags = new ArrayList<>();
    for (VillagerTrade trade : packet.getTrades()) {
        CompoundTagBuilder recipe = CompoundTagBuilder.builder();
        recipe.intTag("maxUses", trade.getMaxUses());
        recipe.intTag("traderExp", trade.getXp());
        recipe.floatTag("priceMultiplierA", trade.getPriceMultiplier());
        recipe.tag(getItemTag(session, trade.getOutput(), "sell", 0));
        recipe.floatTag("priceMultiplierB", 0.0f);
        recipe.intTag("buyCountB", trade.getSecondInput() != null ? trade.getSecondInput().getAmount() : 0);
        recipe.intTag("buyCountA", trade.getFirstInput().getAmount());
        recipe.intTag("demand", trade.getDemand());
        recipe.intTag("tier", packet.getVillagerLevel() - 1);
        recipe.tag(getItemTag(session, trade.getFirstInput(), "buyA", trade.getSpecialPrice()));
        if (trade.getSecondInput() != null) {
            recipe.tag(getItemTag(session, trade.getSecondInput(), "buyB", 0));
        }
        recipe.intTag("uses", trade.getNumUses());
        recipe.byteTag("rewardExp", (byte) 1);
        tags.add(recipe.buildRootTag());
    }

    //Hidden trade to fix visual experience bug
    if (packet.isRegularVillager() && packet.getVillagerLevel() < 5) {
        tags.add(CompoundTagBuilder.builder()
                .intTag("maxUses", 0)
                .intTag("traderExp", 0)
                .floatTag("priceMultiplierA", 0.0f)
                .floatTag("priceMultiplierB", 0.0f)
                .intTag("buyCountB", 0)
                .intTag("buyCountA", 0)
                .intTag("demand", 0)
                .intTag("tier", 5)
                .intTag("uses", 0)
                .byteTag("rewardExp", (byte) 0)
                .buildRootTag());
    }

    builder.listTag("Recipes", CompoundTag.class, tags);
    List<CompoundTag> expTags = new ArrayList<>();
    expTags.add(CompoundTagBuilder.builder().intTag("0", 0).buildRootTag());
    expTags.add(CompoundTagBuilder.builder().intTag("1", 10).buildRootTag());
    expTags.add(CompoundTagBuilder.builder().intTag("2", 70).buildRootTag());
    expTags.add(CompoundTagBuilder.builder().intTag("3", 150).buildRootTag());
    expTags.add(CompoundTagBuilder.builder().intTag("4", 250).buildRootTag());
    builder.listTag("TierExpRequirements", CompoundTag.class, expTags);
    updateTradePacket.setOffers(builder.buildRootTag());
    session.sendUpstreamPacket(updateTradePacket);
}
 
Example #25
Source File: BedBlockEntityTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    tagBuilder.byteTag("color", (byte) 0);
    return tagBuilder.buildRootTag();
}
 
Example #26
Source File: BannerBlockEntityTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    tagBuilder.listTag("Patterns", com.nukkitx.nbt.tag.CompoundTag.class, new ArrayList<>());
    return tagBuilder.buildRootTag();
}
 
Example #27
Source File: SignBlockEntityTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    tagBuilder.stringTag("Text", "");
    return tagBuilder.buildRootTag();
}