mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-10-26 14:23:57 +00:00
Fixes #379 Clean up and fix Naturalist Chest
This commit is contained in:
1 parent
06549d1e2d
commit
db0ab5feda
1 file changed
+10
-63
@@ -15,19 +15,18 @@ import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.GuiHandler;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.gui.IPagedInventory;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
public abstract class TileNaturalistChest extends TileBase implements IInventory, IPagedInventory {
|
||||
|
||||
private ItemStack[] inventoryStacks = new ItemStack[125];
|
||||
private final ISpeciesRoot speciesRoot;
|
||||
private final int guiID;
|
||||
|
||||
public TileNaturalistChest(ISpeciesRoot speciesRoot, int guiId) {
|
||||
setInternalInventory(new TileInventoryAdapter(this, 125, "Items"));
|
||||
setHints(Config.hints.get("apiarist.chest"));
|
||||
this.speciesRoot = speciesRoot;
|
||||
this.guiID = guiId;
|
||||
@@ -48,38 +47,6 @@ public abstract class TileNaturalistChest extends TileBase implements IInventory
|
||||
player.openGui(ForestryAPI.instance, GuiHandler.encodeGuiData(guiID, page), player.worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
for (int i = 0; i < inventoryStacks.length; i++) {
|
||||
if (inventoryStacks[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
inventoryStacks[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
nbttagcompound.setTag("Items", nbttaglist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10);
|
||||
inventoryStacks = new ItemStack[getSizeInventory()];
|
||||
for (int i = 0; i < nbttaglist.tagCount(); i++) {
|
||||
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
byte byte0 = nbttagcompound1.getByte("Slot");
|
||||
if (byte0 >= 0 && byte0 < inventoryStacks.length)
|
||||
inventoryStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
@@ -99,47 +66,27 @@ public abstract class TileNaturalistChest extends TileBase implements IInventory
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventoryStacks.length;
|
||||
return getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return inventoryStacks[i];
|
||||
public ItemStack getStackInSlot(int slotIndex) {
|
||||
return getInternalInventory().getStackInSlot(slotIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (inventoryStacks[i] == null)
|
||||
return null;
|
||||
|
||||
ItemStack product;
|
||||
if (inventoryStacks[i].stackSize <= j) {
|
||||
product = inventoryStacks[i];
|
||||
inventoryStacks[i] = null;
|
||||
return product;
|
||||
} else {
|
||||
product = inventoryStacks[i].splitStack(j);
|
||||
if (inventoryStacks[i].stackSize == 0)
|
||||
inventoryStacks[i] = null;
|
||||
|
||||
return product;
|
||||
}
|
||||
public ItemStack decrStackSize(int slotIndex, int count) {
|
||||
return getInternalInventory().decrStackSize(slotIndex, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
inventoryStacks[i] = itemstack;
|
||||
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
|
||||
itemstack.stackSize = getInventoryStackLimit();
|
||||
public void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
|
||||
getInternalInventory().setInventorySlotContents(slotIndex, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
if (inventoryStacks[slot] == null)
|
||||
return null;
|
||||
ItemStack toReturn = inventoryStacks[slot];
|
||||
inventoryStacks[slot] = null;
|
||||
return toReturn;
|
||||
return getInternalInventory().getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user