Sync storedStack via NBT instead of registry (Keep tags)

This commit is contained in:
Justin Vitale 2020-07-09 16:32:03 +10:00
parent bd860d8073
commit 501c2d68c4

View file

@ -26,9 +26,7 @@ package techreborn.blockentity.storage.item;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -114,7 +112,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
} }
} }
if(inventory.hasChanged()){ if (inventory.hasChanged()) {
syncWithAll(); syncWithAll();
inventory.resetChanged(); inventory.resetChanged();
} }
@ -449,14 +447,15 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
this.storedAmount = storedAmount; this.storedAmount = storedAmount;
} }
public void setStoredStack(String itemStringID) { public void setStoredStackFromNBT(CompoundTag tag) {
storeItemStack = new ItemStack(Registry.ITEM.get(new Identifier(itemStringID))); storeItemStack = ItemStack.fromTag(tag);
} }
public CompoundTag getStoredStackNBT() {
public String convertItemStringID() { CompoundTag tag = new CompoundTag();
return Registry.ITEM.getId(getStoredStack().getItem()).toString(); getStoredStack().toTag(tag);
return tag;
} }
@Override @Override
@ -466,7 +465,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
.slot(INPUT_SLOT, 100, 53) .slot(INPUT_SLOT, 100, 53)
.outputSlot(OUTPUT_SLOT, 140, 53) .outputSlot(OUTPUT_SLOT, 140, 53)
.sync(this::isLockedInt, this::setLockedInt) .sync(this::isLockedInt, this::setLockedInt)
.sync(this::convertItemStringID, this::setStoredStack) .sync(this::getStoredStackNBT, this::setStoredStackFromNBT)
.sync(this::getStoredAmount, this::setStoredAmount) .sync(this::getStoredAmount, this::setStoredAmount)
.addInventory().create(this, syncID); .addInventory().create(this, syncID);