Search in sources :

Example 1 with NbtMapBuilder

use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.

the class ItemFrameEntity method getDefaultTag.

private NbtMap getDefaultTag() {
    NbtMapBuilder builder = NbtMap.builder();
    builder.putInt("x", bedrockPosition.getX());
    builder.putInt("y", bedrockPosition.getY());
    builder.putInt("z", bedrockPosition.getZ());
    builder.putByte("isMovable", (byte) 1);
    builder.putString("id", this.definition.entityType() == EntityType.GLOW_ITEM_FRAME ? "GlowItemFrame" : "ItemFrame");
    return builder.build();
}
Also used : NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder)

Example 2 with NbtMapBuilder

use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.

the class ItemFrameEntity method setItemRotation.

public void setItemRotation(IntEntityMetadata entityMetadata) {
    rotation = entityMetadata.getPrimitiveValue() * 45;
    if (cachedTag == null) {
        return;
    }
    NbtMapBuilder builder = cachedTag.toBuilder();
    builder.putFloat("ItemRotation", rotation);
    cachedTag = builder.build();
    changed = true;
}
Also used : NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder)

Example 3 with NbtMapBuilder

use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.

the class ItemFrameEntity method setItemInFrame.

public void setItemInFrame(EntityMetadata<ItemStack, ?> entityMetadata) {
    if (entityMetadata.getValue() != null) {
        this.heldItem = entityMetadata.getValue();
        ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem);
        ItemMapping mapping = session.getItemMappings().getMapping(entityMetadata.getValue());
        NbtMapBuilder builder = NbtMap.builder();
        builder.putByte("Count", (byte) itemData.getCount());
        if (itemData.getTag() != null) {
            builder.put("tag", itemData.getTag());
        }
        builder.putShort("Damage", (short) itemData.getDamage());
        builder.putString("Name", mapping.getBedrockIdentifier());
        NbtMapBuilder tag = getDefaultTag().toBuilder();
        tag.put("Item", builder.build());
        tag.putFloat("ItemDropChance", 1.0f);
        tag.putFloat("ItemRotation", rotation);
        cachedTag = tag.build();
        changed = true;
    } else if (cachedTag != null) {
        cachedTag = getDefaultTag();
        changed = true;
    }
}
Also used : ItemMapping(org.geysermc.geyser.registry.type.ItemMapping) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 4 with NbtMapBuilder

use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.

the class BlockEntityTranslator method getBlockEntityTag.

public NbtMap getBlockEntityTag(BlockEntityType type, int x, int y, int z, CompoundTag tag, int blockState) {
    NbtMapBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(type), x, y, z);
    translateTag(tagBuilder, tag, blockState);
    return tagBuilder.build();
}
Also used : NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder)

Example 5 with NbtMapBuilder

use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.

the class FlowerPotBlockEntityTranslator method getTag.

/**
 * Get the Nukkit CompoundTag of the flower pot.
 *
 * @param blockState Java block state of flower pot.
 * @param position   Bedrock position of flower pot.
 * @return Bedrock tag of flower pot.
 */
public static NbtMap getTag(GeyserSession session, int blockState, Vector3i position) {
    NbtMapBuilder tagBuilder = NbtMap.builder().putInt("x", position.getX()).putInt("y", position.getY()).putInt("z", position.getZ()).putByte("isMovable", (byte) 1).putString("id", "FlowerPot");
    // Get the Java name of the plant inside. e.g. minecraft:oak_sapling
    String name = BlockStateValues.getFlowerPotValues().get(blockState);
    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.
        NbtMap plant = session.getBlockMappings().getFlowerPotBlocks().get(name);
        if (plant != null) {
            tagBuilder.put("PlantBlock", plant.toBuilder().build());
        }
    }
    return tagBuilder.build();
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder)

Aggregations

NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)30 NbtMap (com.nukkitx.nbt.NbtMap)15 ArrayList (java.util.ArrayList)11 Item (org.jukeboxmc.item.Item)7 Vector3i (com.nukkitx.math.vector.Vector3i)3 ItemData (com.nukkitx.protocol.bedrock.data.inventory.ItemData)3 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)2 BlockEntityDataPacket (com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Container (org.geysermc.geyser.inventory.Container)2 ItemMapping (org.geysermc.geyser.registry.type.ItemMapping)2 BlockEntityShulkerBox (org.jukeboxmc.blockentity.BlockEntityShulkerBox)2 ShulkerBoxInventory (org.jukeboxmc.inventory.ShulkerBoxInventory)2 ItemAir (org.jukeboxmc.item.ItemAir)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)1 ServerboundContainerButtonClickPacket (com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket)1 ServerboundContainerClosePacket (com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket)1