Search in sources :

Example 1 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData 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 2 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Geyser by GeyserMC.

the class GeyserItemStack method getItemData.

public ItemData getItemData(GeyserSession session) {
    ItemData itemData = ItemTranslator.translateToBedrock(session, getItemStack());
    itemData.setNetId(getNetId());
    // Seems silly - this should probably be on the protocol level
    itemData.setUsingNetId(true);
    return itemData;
}
Also used : ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 3 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Geyser by GeyserMC.

the class ChestedHorseInventoryTranslator method updateInventory.

@Override
public void updateInventory(GeyserSession session, Inventory inventory) {
    ItemData[] bedrockItems = new ItemData[36];
    for (int i = 0; i < 36; i++) {
        final int offset = i < 9 ? 27 : -9;
        bedrockItems[i] = inventory.getItem(this.size + i + offset).getItemData(session);
    }
    InventoryContentPacket contentPacket = new InventoryContentPacket();
    contentPacket.setContainerId(ContainerId.INVENTORY);
    contentPacket.setContents(Arrays.asList(bedrockItems));
    session.sendUpstreamPacket(contentPacket);
    ItemData[] horseItems = new ItemData[chestSize + 1];
    // Manually specify the first slot - Java always has two slots (armor and saddle) and one is invisible.
    // Bedrock doesn't have this invisible slot.
    horseItems[0] = inventory.getItem(this.equipSlot).getItemData(session);
    for (int i = 1; i < horseItems.length; i++) {
        horseItems[i] = inventory.getItem(i + 1).getItemData(session);
    }
    InventoryContentPacket horseContentsPacket = new InventoryContentPacket();
    horseContentsPacket.setContainerId(inventory.getId());
    horseContentsPacket.setContents(Arrays.asList(horseItems));
    session.sendUpstreamPacket(horseContentsPacket);
}
Also used : InventoryContentPacket(com.nukkitx.protocol.bedrock.packet.InventoryContentPacket) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 4 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.

the class CraftingDataSerializer_v361 method readShapelessRecipe.

@Override
protected CraftingData readShapelessRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type, BedrockSession session) {
    String recipeId = helper.readString(buffer);
    List<ItemData> inputs = new ObjectArrayList<>();
    helper.readArray(buffer, inputs, this::readIngredient);
    List<ItemData> outputs = new ObjectArrayList<>();
    helper.readArray(buffer, outputs, buf -> helper.readItem(buf, session));
    UUID uuid = helper.readUuid(buffer);
    String craftingTag = helper.readString(buffer);
    int priority = VarInts.readInt(buffer);
    return new CraftingData(type, recipeId, -1, -1, -1, -1, inputs, outputs, uuid, craftingTag, priority);
}
Also used : ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) CraftingData(com.nukkitx.protocol.bedrock.data.inventory.CraftingData) UUID(java.util.UUID) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Example 5 with ItemData

use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.

the class BedrockPacketHelper_v291 method writeEntityData.

@Override
public 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, this.entityData.get(entry.getKey()));
        Object object = entry.getValue();
        EntityData.Type type = EntityData.Type.from(object);
        VarInts.writeUnsignedInt(buffer, this.entityDataTypes.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:
                writeString(buffer, (String) object);
                break;
            case NBT:
                ItemData item;
                if (object instanceof NbtMap) {
                    item = ItemData.builder().id(1).damage(0).count(1).tag((NbtMap) object).build();
                } else {
                    item = (ItemData) object;
                }
                this.writeItem(buffer, item, null);
                break;
            case VECTOR3I:
                writeVector3i(buffer, (Vector3i) object);
                break;
            case FLAGS:
                int flagsIndex = entry.getKey() == EntityData.FLAGS_2 ? 1 : 0;
                object = ((EntityFlags) object).get(flagsIndex, this.entityFlags);
            case LONG:
                VarInts.writeLong(buffer, (long) object);
                break;
            case VECTOR3F:
                writeVector3f(buffer, (Vector3f) object);
                break;
            default:
                buffer.writerIndex(index);
                break;
        }
    }
}
Also used : Type(com.nukkitx.protocol.bedrock.data.entity.EntityData.Type) NbtMap(com.nukkitx.nbt.NbtMap) NbtMap(com.nukkitx.nbt.NbtMap) Map(java.util.Map) ItemData(com.nukkitx.protocol.bedrock.data.inventory.ItemData)

Aggregations

ItemData (com.nukkitx.protocol.bedrock.data.inventory.ItemData)30 ObjectArrayList (it.unimi.dsi.fastutil.objects.ObjectArrayList)13 CraftingData (com.nukkitx.protocol.bedrock.data.inventory.CraftingData)9 UUID (java.util.UUID)8 NbtMap (com.nukkitx.nbt.NbtMap)6 InventoryContentPacket (com.nukkitx.protocol.bedrock.packet.InventoryContentPacket)6 ArrayList (java.util.ArrayList)6 Item (org.jukeboxmc.item.Item)4 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)3 ItemMapping (org.geysermc.geyser.registry.type.ItemMapping)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)2 Map (java.util.Map)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Ingredient (com.github.steveice10.mc.protocol.data.game.recipe.Ingredient)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 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)1 Vector3i (com.nukkitx.math.vector.Vector3i)1 EntityData (com.nukkitx.protocol.bedrock.data.entity.EntityData)1