From 0f508b538e55e4461699ea8c94dadcf0aea863fe Mon Sep 17 00:00:00 2001 From: panda885 Date: Sat, 1 Apr 2023 22:14:29 +0200 Subject: [PATCH] fix: add cad capability data to item share tag --- .../java/vazkii/psi/common/item/ItemCAD.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/vazkii/psi/common/item/ItemCAD.java b/src/main/java/vazkii/psi/common/item/ItemCAD.java index c1579560..b10eeb66 100644 --- a/src/main/java/vazkii/psi/common/item/ItemCAD.java +++ b/src/main/java/vazkii/psi/common/item/ItemCAD.java @@ -129,6 +129,22 @@ public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundT return data; } + @Override + public @Nullable CompoundTag getShareTag(ItemStack stack) { + CompoundTag nbt = stack.getOrCreateTag(); + stack.getCapability(PsiAPI.CAD_DATA_CAPABILITY).ifPresent(data -> nbt.put("CapabilityData", data.serializeNBT())); + return nbt; + } + + @Override + public void readShareTag(ItemStack stack, @Nullable CompoundTag nbt) { + super.readShareTag(stack, nbt); + + if (nbt != null) { + stack.getCapability(PsiAPI.CAD_DATA_CAPABILITY).ifPresent(data -> data.deserializeNBT(nbt.getCompound("CapabilityData"))); + } + } + @Override public void inventoryTick(ItemStack stack, Level world, Entity entityIn, int itemSlot, boolean isSelected) { CompoundTag compound = stack.getOrCreateTag();