Java Code Examples for com.nukkitx.nbt.CompoundTagBuilder#buildRootTag()

The following examples show how to use com.nukkitx.nbt.CompoundTagBuilder#buildRootTag() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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();
}
 
Example 13
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();
}