From e7e5292526734a75c4cd337cc1ceaf964df878ec Mon Sep 17 00:00:00 2001 From: Quantumlyy Date: Sat, 9 Dec 2023 08:57:32 +0100 Subject: [PATCH] read and write nbt --- .../client/gui/ContainerPhialingCabinet.java | 33 ------------------- .../tileentity/TileEntityPhialingCabinet.java | 33 ++++++++++++++++--- 2 files changed, 28 insertions(+), 38 deletions(-) delete mode 100644 src/main/java/magicbees/client/gui/ContainerPhialingCabinet.java diff --git a/src/main/java/magicbees/client/gui/ContainerPhialingCabinet.java b/src/main/java/magicbees/client/gui/ContainerPhialingCabinet.java deleted file mode 100644 index 23033fd..0000000 --- a/src/main/java/magicbees/client/gui/ContainerPhialingCabinet.java +++ /dev/null @@ -1,33 +0,0 @@ -package magicbees.client.gui; - -/* - * public class ContainerPhialingCabinet extends ContainerMB { public TileEntityPhialingCabinet phialingCabinet; public - * int maxSlot = 0; // Constants private static final int SLOT_ONE = 0; private static final int SLOT_TWO = 1; private - * static final int SLOT_THREE = 2; private static final int SLOT_FOUR = 3; private static final int SLOT_FIVE = 4; - * private static final int SLOT_SIX = 5; private static final int SLOT_SEVEN = 6; private static final int SLOT_EIGHT = - * 7; private static final int SLOT_NINE = 8; public ContainerPhialingCabinet(InventoryPlayer inventoryPlayer, - * TileEntityPhialingCabinet phialingCabinet){ this.phialingCabinet = phialingCabinet; // Queen/Princess slot - * addSlotToContainer(new SlotCustomItems(this.phialingCabinet, 0, 29, 39, ItemInterface.getItemStack("Forestry", - * "beeQueenGE", 1), ItemInterface.getItemStack("Forestry", "beePrincessGE", 1))); // Drone slot addSlotToContainer(new - * SlotCustomItems(this.phialingCabinet, 1, 29, 65, ItemInterface.getItemStack("Forestry", "beeDroneGE", 64))); int - * currentSlot = 1; // Frame slots for (int x = 0; x < 3; x++){ currentSlot++; addSlotToContainer(new - * SlotFrame(phialingCabinet, currentSlot, 66, 23 + x * 29)); //LogHelper.info("[1] CURRENTSLOT: " + currentSlot); } for - * (int x = 0; x < 3; x++){ currentSlot++; addSlotToContainer(new Slot(phialingCabinet, currentSlot, 116, 26 + x * 26)); - * //LogHelper.info("[2] CURRENTSLOT: " + currentSlot); } int j = 0; for (int y = 0; y < 2; y++){ for (int x = 0; x < 2; - * x++){ currentSlot++; addSlotToContainer(new Slot(phialingCabinet, currentSlot, 95 + x * 42, 39 + j * 26)); - * //LogHelper.info("[3] CURRENTSLOT: " + currentSlot); } j++; } addPlayerInventory(inventoryPlayer, 0, 110); maxSlot = - * currentSlot; } - * @Override public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex){ Slot itemSlot = - * this.getSlot(slotIndex); boolean clearSlot = false; if (itemSlot != null && itemSlot.getHasStack()) { ItemStack - * srcStack = itemSlot.getStack(); if (slotIndex <= maxSlot && srcStack != null){ clearSlot = - * this.mergeItemStack(srcStack, maxSlot + 1, maxSlot + 36, false); }else{ if (slotIndex > maxSlot && srcStack != null){ - * if (BeeManager.beeRoot.isMember(srcStack)){ if (!BeeManager.beeRoot.isDrone(srcStack)){ if - * (this.getSlot(SLOT_ONE).getHasStack() == false) { clearSlot = this.mergeItemStack(srcStack, SLOT_ONE, SLOT_ONE + 1, - * false); } }else{ if (this.getSlot(SLOT_TWO).isItemValid(srcStack)){ clearSlot = this.mergeItemStack(srcStack, - * SLOT_TWO, SLOT_TWO + 1, false); } } }else if(srcStack.getItem() instanceof IHiveFrame){ clearSlot = - * this.mergeItemStack(srcStack, SLOT_THREE, SLOT_THREE + SLOT_FOUR, false); } } } } if (clearSlot){ - * itemSlot.putStack(null); } itemSlot.onSlotChanged(); player.inventory.markDirty(); return null; } - * @Override public boolean canInteractWith(EntityPlayer entityPlayer) { return - * phialingCabinet.isUseableByPlayer(entityPlayer); } - */ -// } diff --git a/src/main/java/magicbees/tileentity/TileEntityPhialingCabinet.java b/src/main/java/magicbees/tileentity/TileEntityPhialingCabinet.java index 85bd963..4c2e6bf 100644 --- a/src/main/java/magicbees/tileentity/TileEntityPhialingCabinet.java +++ b/src/main/java/magicbees/tileentity/TileEntityPhialingCabinet.java @@ -2,7 +2,9 @@ package magicbees.tileentity; import java.util.Objects; +import magicbees.main.utils.ChunkCoords; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; @@ -23,7 +25,6 @@ public class TileEntityPhialingCabinet extends TileEntity implements IAspectCont public Aspect aspect; public AspectList essentia = new AspectList(); - public int amount = 0; public final int maxAmount = Config.thaumcraftEssentiaBeePhialingCabinetCapacity; private int increment = 0; @@ -38,12 +39,12 @@ public class TileEntityPhialingCabinet extends TileEntity implements IAspectCont TileEntity above = worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord); if (IBeeHousing.class.isAssignableFrom(above.getClass())) { IBeeHousing beeHousing = (IBeeHousing) above; - ItemStack queenStack = beeHousing.getBeeInventory().getQueen(); // This performs all the checks to see if the bee is a living queen and if the species conditions // are met. if (!beeHousing.getBeekeepingLogic().canWork()) return; + ItemStack queenStack = beeHousing.getBeeInventory().getQueen(); IAlleleBeeSpecies queenSpecies = BeeGenome.getSpecies(queenStack); if (queenSpecies == null) return; @@ -76,10 +77,10 @@ public class TileEntityPhialingCabinet extends TileEntity implements IAspectCont @Override public int addToContainer(Aspect tag, int am) { if (am != 0) { - if (this.amount < this.maxAmount && tag == this.aspect || this.amount == 0) { + int amount = this.essentia.visSize(); + if (amount < this.maxAmount && tag == this.aspect || amount == 0) { this.aspect = tag; - int added = Math.min(am, this.maxAmount - this.amount); - this.amount += added; + int added = Math.min(am, this.maxAmount - amount); am -= added; } } @@ -212,4 +213,26 @@ public class TileEntityPhialingCabinet extends TileEntity implements IAspectCont public int addEssentia(Aspect aspect, int amount, ForgeDirection face) { return this.canInputFrom(face) ? amount - this.addToContainer(aspect, amount) : 0; } + + /* Saving and loading */ + @Override + public void writeToNBT(NBTTagCompound compound) { + super.writeToNBT(compound); + + this.essentia.writeToNBT(compound); + compound.setString("aspect", aspect.getTag()); + compound.setInteger("increment", increment); + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + super.readFromNBT(compound); + + this.essentia.readFromNBT(compound); + if (this.essentia.visSize() > this.maxAmount) { + this.essentia = new AspectList(); + } + aspect = Aspect.getAspect(compound.getString("aspect")); + increment = compound.getInteger("increment"); + } }