From 6d68efe6979091415696d80a573788bfdab9b7d2 Mon Sep 17 00:00:00 2001 From: Robert S Date: Sat, 26 Apr 2014 11:43:28 -0400 Subject: [PATCH] Minor change to crates in attempt to fix a waila issue --- .../archaic/crate/InventoryCrate.java | 1 - .../archaic/crate/TileCrate.java | 32 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/archaic/src/main/scala/resonantinduction/archaic/crate/InventoryCrate.java b/archaic/src/main/scala/resonantinduction/archaic/crate/InventoryCrate.java index 6fba855d..25daca6b 100644 --- a/archaic/src/main/scala/resonantinduction/archaic/crate/InventoryCrate.java +++ b/archaic/src/main/scala/resonantinduction/archaic/crate/InventoryCrate.java @@ -33,7 +33,6 @@ public class InventoryCrate extends ExternalInventory break; } } - this.onInventoryChanged(); } } diff --git a/archaic/src/main/scala/resonantinduction/archaic/crate/TileCrate.java b/archaic/src/main/scala/resonantinduction/archaic/crate/TileCrate.java index af555d82..e540ce13 100644 --- a/archaic/src/main/scala/resonantinduction/archaic/crate/TileCrate.java +++ b/archaic/src/main/scala/resonantinduction/archaic/crate/TileCrate.java @@ -37,17 +37,27 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver, private ItemStack filterStack; private long updateTick = 1; + private boolean doUpdate = false; @Override public void updateEntity() { super.updateEntity(); - if (!worldObj.isRemote && ticks % updateTick == 0) + if (!worldObj.isRemote) { - //Send desc packet, done already in onInventoryChanged() - onInventoryChanged(); - updateTick = 5 + worldObj.rand.nextInt(50); + this.writeToNBT(new NBTTagCompound()); + if (ticks % updateTick == 0) + { + updateTick = 5 + worldObj.rand.nextInt(50); + doUpdate = true; + } + if (doUpdate) + { + doUpdate = false; + PacketHandler.sendPacketToClients(getDescriptionPacket(), this.worldObj); + } } + } /** Gets the slot count for the crate meta */ @@ -87,6 +97,11 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver, /** Builds the sample stack using the inventory as a point of reference. Assumes all items match * each other, and only takes into account stack sizes */ public void buildSampleStack() + { + buildSampleStack(true); + } + + public void buildSampleStack(boolean buildInv) { ItemStack newSampleStack = null; boolean rebuildBase = false; @@ -122,7 +137,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver, } /* Rebuild inventory if the inventory is not valid */ - if (this.sampleStack != null && (rebuildBase || this.getInventory().getContainedItems().length > this.getSizeInventory())) + if (buildInv && this.sampleStack != null && (rebuildBase || this.getInventory().getContainedItems().length > this.getSizeInventory())) { this.getInventory().buildInventory(this.sampleStack); } @@ -202,11 +217,8 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver, public void onInventoryChanged() { super.onInventoryChanged(); - if (worldObj != null && !worldObj.isRemote) - { - PacketHandler.sendPacketToClients(getDescriptionPacket(), this.worldObj); - } + doUpdate = true; } @Override @@ -304,7 +316,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver, { super.writeToNBT(nbt); /* Re-Build sample stack for saving */ - this.buildSampleStack(); + this.buildSampleStack(false); ItemStack stack = this.getSampleStack(); /* Save sample stack */ if (stack != null)