@@ -30,7 +30,7 @@ public class TileEntityStorageCore extends TileEntity {
3030 private EZInventory inventory ;
3131
3232 Set <BlockRef > multiblock = new HashSet <BlockRef >();
33- private boolean firstTick = false ;
33+ private int ticks ;
3434 public boolean hasCraftBox = false ;
3535 public String inventoryId = "" ;
3636
@@ -116,18 +116,31 @@ public void readFromNBT(NBTTagCompound paramNBTTagCompound) {
116116 * Scans the multiblock structure for valid blocks
117117 */
118118 public void scanMultiblock (EntityLivingBase entity ) {
119+ scanMultiblock (entity , true );
120+ }
121+
122+ /**
123+ * Scans the multiblock structure for valid blocks
124+ */
125+ public void scanMultiblock (EntityLivingBase entity , boolean force ) {
119126 EZInventory inventory = getInventory (true );
127+ int maxItems = 0 ;
120128 inventory .maxItems = 0 ;
121129 this .hasCraftBox = false ;
122- multiblock = new HashSet <BlockRef >();
130+ var multiblock = new HashSet <BlockRef >();
123131 BlockRef ref = new BlockRef (this );
124132 multiblock .add (ref );
125133 getValidNeighbors (ref , entity );
126134 for (BlockRef blockRef : multiblock ) {
127135 if (blockRef .block instanceof BlockStorage sb ) {
128- inventory . maxItems += sb .getCapacity ();
136+ maxItems += sb .getCapacity ();
129137 }
130138 }
139+ if (!force && inventory .maxItems == maxItems ) {
140+ return ;
141+ }
142+ inventory .maxItems = maxItems ;
143+ this .multiblock = multiblock ;
131144 this .worldObj .markBlockForUpdate (xCoord , yCoord , zCoord );
132145 }
133146
@@ -183,11 +196,24 @@ public boolean isPartOfMultiblock(BlockRef blockRef) {
183196
184197 @ Override
185198 public void updateEntity () {
186- if (!firstTick && worldObj != null ) {
187- firstTick = true ;
199+ // First scan
200+ if (ticks == 0 && worldObj != null && !worldObj .isRemote ) {
201+ scanMultiblock (null );
202+ }
203+
204+ // 400 ticks = 20 ticks * 20 seconds
205+ if (ticks >= 400 ) {
206+
207+ // Periodical scan
188208 if (!worldObj .isRemote ) {
189- scanMultiblock (null );
209+ scanMultiblock (null , false );
190210 }
211+
212+ // Reset
213+ ticks = 0 ;
191214 }
215+
216+ // Increment
217+ ticks += 1 ;
192218 }
193219}
0 commit comments