Item Handling · hdimUy9D-
    public Items type;

    public SerializedItemStack() { }

    public SerializedItemStack(CraftItem itemStack) {
        if(itemStack.getType() == Material.AIR) return;

        NBTItem itemNbt = itemStack.getNbt();
        if(!itemNbt.hasKey("data")) return;

        NBTCompound dataTag = itemNbt.getCompound("data");
        this.type = Items.idValue(dataTag.getString("itemId"));
    }

    public boolean isEmpty() {
        return this.type == null;
    }

    public CraftItem deserialize() {
        if(type == null) return CraftItem.convert(ItemUtil.AIR);

        ItemHandler handler = ItemHandlerManager.getItemHandler(this.type.getItemId());
        CraftItem itemStack = CraftItem.convert(handler.construct(handler.getItemData().getBaseMaterial()));

        return itemStack;
    }
  • 4

    3/26/2022, 1:05:16 PM