Search in sources :

Example 26 with ItemStack

use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack 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

ItemStack (com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack)26 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)15 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)14 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)14 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)14 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)6 WatchableObject (com.github.dirtpowered.dirtmv.data.protocol.objects.WatchableObject)5 CompoundBinaryTag (net.kyori.adventure.nbt.CompoundBinaryTag)5 Motion (com.github.dirtpowered.dirtmv.data.protocol.objects.Motion)4 SneakyThrows (lombok.SneakyThrows)4 EntityType (com.github.dirtpowered.dirtmv.data.entity.EntityType)3 DimensionTracker (com.github.dirtpowered.dirtmv.network.versions.Release28To23.chunk.DimensionTracker)3 ServerMotd (com.github.dirtpowered.dirtmv.network.versions.Release73To61.ping.ServerMotd)3 List (java.util.List)3 MinecraftVersion (com.github.dirtpowered.dirtmv.data.MinecraftVersion)2 NettyInputWrapper (com.github.dirtpowered.dirtmv.data.protocol.io.NettyInputWrapper)2 NettyOutputWrapper (com.github.dirtpowered.dirtmv.data.protocol.io.NettyOutputWrapper)2 BlockLocation (com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation)2 Location (com.github.dirtpowered.dirtmv.data.protocol.objects.Location)2 MetadataType (com.github.dirtpowered.dirtmv.data.protocol.objects.MetadataType)2