Search in sources :

Example 21 with DataItem

use of com.viaversion.viaversion.api.minecraft.item.DataItem in project ViaVersion by ViaVersion.

the class FlatItemType method read.

@Override
public Item read(ByteBuf buffer) throws Exception {
    short id = buffer.readShort();
    if (id < 0) {
        return null;
    } else {
        Item item = new DataItem();
        item.setIdentifier(id);
        item.setAmount(buffer.readByte());
        item.setTag(Type.NBT.read(buffer));
        return item;
    }
}
Also used : DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) Item(com.viaversion.viaversion.api.minecraft.item.Item) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem)

Example 22 with DataItem

use of com.viaversion.viaversion.api.minecraft.item.DataItem in project ViaVersion by ViaVersion.

the class ItemType method read.

@Override
public Item read(ByteBuf buffer) throws Exception {
    short id = buffer.readShort();
    if (id < 0) {
        return null;
    } else {
        Item item = new DataItem();
        item.setIdentifier(id);
        item.setAmount(buffer.readByte());
        item.setData(buffer.readShort());
        item.setTag(NBT.read(buffer));
        return item;
    }
}
Also used : DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) Item(com.viaversion.viaversion.api.minecraft.item.Item) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem)

Example 23 with DataItem

use of com.viaversion.viaversion.api.minecraft.item.DataItem in project DirtMultiversion by DirtPowered.

the class ViaHandItemProvider method getHandItem.

@Override
public Item getHandItem(UserConnection userConnection) {
    if (userConnection.getProtocolInfo() == null) {
        return super.getHandItem(userConnection);
    }
    UserData userData = api.getUserDataFromUsername(userConnection.getProtocolInfo().getUsername());
    if (userData != null) {
        ProtocolStorage storage = userData.getProtocolStorage();
        if (storage.hasObject(QuickBarTracker.class)) {
            QuickBarTracker cache = storage.get(QuickBarTracker.class);
            ItemStack item = cache.getItemInHand();
            return new DataItem(item.getItemId(), (byte) item.getAmount(), (short) item.getData(), null);
        }
    }
    return super.getHandItem(userConnection);
}
Also used : ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) UserData(com.github.dirtpowered.dirtmv.data.user.UserData) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) ItemStack(com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack) QuickBarTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.inventory.QuickBarTracker)

Aggregations

DataItem (com.viaversion.viaversion.api.minecraft.item.DataItem)23 Item (com.viaversion.viaversion.api.minecraft.item.Item)12 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)7 Identifier (net.minecraft.util.Identifier)6 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)5 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)4 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)4 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)4 Type (com.viaversion.viaversion.api.type.Type)4 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)3 JsonObject (com.google.gson.JsonObject)3 Via (com.viaversion.viaversion.api.Via)3 ListTag (com.github.steveice10.opennbt.tag.builtin.ListTag)2 Sets (com.google.common.collect.Sets)2 JsonElement (com.google.gson.JsonElement)2 Position (com.viaversion.viaversion.api.minecraft.Position)2 AbstractProtocol (com.viaversion.viaversion.api.protocol.AbstractProtocol)2 Protocol1_14To1_13_2 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2)2 EntityTracker1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14)2 EntityTracker1_9 (com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9)2