Search in sources :

Example 6 with NbtMapBuilder

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

the class LecternInventoryTranslator method getBaseLecternTag.

public static NbtMapBuilder getBaseLecternTag(int x, int y, int z, int totalPages) {
    NbtMapBuilder builder = NbtMap.builder().putInt("x", x).putInt("y", y).putInt("z", z).putString("id", "Lectern");
    if (totalPages != 0) {
        builder.putByte("hasBook", (byte) 1);
        builder.putInt("totalPages", totalPages);
    } else {
        // Not usually needed, but helps with kicking out Bedrock players from reading the UI
        builder.putByte("hasBook", (byte) 0);
    }
    return builder;
}
Also used : NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder)

Example 7 with NbtMapBuilder

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

the class JavaHorseScreenOpenTranslator method translate.

@Override
public void translate(GeyserSession session, ClientboundHorseScreenOpenPacket packet) {
    Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
    if (entity == null) {
        return;
    }
    UpdateEquipPacket updateEquipPacket = new UpdateEquipPacket();
    updateEquipPacket.setWindowId((short) packet.getContainerId());
    updateEquipPacket.setWindowType((short) ContainerType.HORSE.getId());
    updateEquipPacket.setUniqueEntityId(entity.getGeyserId());
    NbtMapBuilder builder = NbtMap.builder();
    List<NbtMap> slots = new ArrayList<>();
    InventoryTranslator inventoryTranslator;
    if (entity instanceof LlamaEntity) {
        inventoryTranslator = new LlamaInventoryTranslator(packet.getNumberOfSlots());
        slots.add(CARPET_SLOT);
    } else if (entity instanceof ChestedHorseEntity) {
        inventoryTranslator = new DonkeyInventoryTranslator(packet.getNumberOfSlots());
        slots.add(SADDLE_SLOT);
    } else {
        inventoryTranslator = new HorseInventoryTranslator(packet.getNumberOfSlots());
        slots.add(SADDLE_SLOT);
        slots.add(ARMOR_SLOT);
    }
    // Build the NbtMap that sets the icons for Bedrock (e.g. sets the saddle outline on the saddle slot)
    builder.putList("slots", NbtType.COMPOUND, slots);
    updateEquipPacket.setTag(builder.build());
    session.sendUpstreamPacket(updateEquipPacket);
    session.setInventoryTranslator(inventoryTranslator);
    InventoryUtils.openInventory(session, new Container(entity.getNametag(), packet.getContainerId(), packet.getNumberOfSlots(), null, session.getPlayerInventory()));
}
Also used : LlamaEntity(org.geysermc.geyser.entity.type.living.animal.horse.LlamaEntity) Entity(org.geysermc.geyser.entity.type.Entity) ChestedHorseEntity(org.geysermc.geyser.entity.type.living.animal.horse.ChestedHorseEntity) HorseInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.HorseInventoryTranslator) InventoryTranslator(org.geysermc.geyser.translator.inventory.InventoryTranslator) DonkeyInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.DonkeyInventoryTranslator) LlamaInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.LlamaInventoryTranslator) ChestedHorseEntity(org.geysermc.geyser.entity.type.living.animal.horse.ChestedHorseEntity) NbtMap(com.nukkitx.nbt.NbtMap) ArrayList(java.util.ArrayList) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) UpdateEquipPacket(com.nukkitx.protocol.bedrock.packet.UpdateEquipPacket) Container(org.geysermc.geyser.inventory.Container) LlamaEntity(org.geysermc.geyser.entity.type.living.animal.horse.LlamaEntity) LlamaInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.LlamaInventoryTranslator) DonkeyInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.DonkeyInventoryTranslator) HorseInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.HorseInventoryTranslator)

Example 8 with NbtMapBuilder

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

the class BedrockPositionTrackingDBClientRequestTranslator method translate.

@Override
public void translate(GeyserSession session, PositionTrackingDBClientRequestPacket packet) {
    PositionTrackingDBServerBroadcastPacket broadcastPacket = new PositionTrackingDBServerBroadcastPacket();
    broadcastPacket.setTrackingId(packet.getTrackingId());
    // Fetch the stored lodestone
    LodestoneCache.LodestonePos pos = session.getLodestoneCache().getPos(packet.getTrackingId());
    // If we don't have data for that ID tell the client its not found
    if (pos == null) {
        broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.NOT_FOUND);
        session.sendUpstreamPacket(broadcastPacket);
        return;
    }
    broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.UPDATE);
    // Build the NBT data for the update
    NbtMapBuilder builder = NbtMap.builder();
    builder.putInt("dim", DimensionUtils.javaToBedrock(pos.dimension()));
    builder.putString("id", "0x" + String.format("%08X", packet.getTrackingId()));
    // Not sure what this is for
    builder.putByte("version", (byte) 1);
    // Not sure what this is for
    builder.putByte("status", (byte) 0);
    // Build the position for the update
    builder.putList("pos", NbtType.INT, pos.x(), pos.y(), pos.z());
    broadcastPacket.setTag(builder.build());
    session.sendUpstreamPacket(broadcastPacket);
}
Also used : PositionTrackingDBServerBroadcastPacket(com.nukkitx.protocol.bedrock.packet.PositionTrackingDBServerBroadcastPacket) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) LodestoneCache(org.geysermc.geyser.session.cache.LodestoneCache)

Example 9 with NbtMapBuilder

use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.

the class BlockEntity method toCompound.

public NbtMapBuilder toCompound() {
    NbtMapBuilder compound = NbtMap.builder();
    Vector position = this.block.getLocation();
    compound.putString("id", BlockEntityType.getId(this.getClass()));
    compound.putInt("x", position.getBlockX());
    compound.putInt("y", position.getBlockY());
    compound.putInt("z", position.getBlockZ());
    compound.putBoolean("isMovable", this.isMoveable);
    return compound;
}
Also used : NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) Vector(org.jukeboxmc.math.Vector)

Example 10 with NbtMapBuilder

use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.

the class BlockEntityBlastFurnace method toCompound.

@Override
public NbtMapBuilder toCompound() {
    NbtMapBuilder builder = super.toCompound();
    List<NbtMap> itemsCompoundList = new ArrayList<>();
    for (int slot = 0; slot < this.blastFurnaceInventory.getSize(); slot++) {
        NbtMapBuilder itemCompound = NbtMap.builder();
        Item item = this.blastFurnaceInventory.getItem(slot);
        itemCompound.putByte("Slot", (byte) slot);
        this.fromItem(item, itemCompound);
        itemsCompoundList.add(itemCompound.build());
    }
    builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
    return builder;
}
Also used : Item(org.jukeboxmc.item.Item) NbtMap(com.nukkitx.nbt.NbtMap) ArrayList(java.util.ArrayList) 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