Fixed lag with external storage, fixes issues #492 and #277

This commit is contained in:
Raoul Van den Berge
2016-10-29 15:35:04 +02:00
parent 30ddc2aef8
commit c3e67814ae
2 changed files with 13 additions and 9 deletions

View File

@@ -528,13 +528,17 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
remainder = storage.insertItem(remainder, size, simulate);
}
if (storage instanceof ItemStorageExternal && !simulate) {
((ItemStorageExternal) storage).updateCacheForcefully();
}
if (remainder == null || remainder.stackSize < 0) {
if (storage instanceof ItemStorageExternal && !simulate) {
((ItemStorageExternal) storage).updateCacheForcefully();
}
break;
} else {
if (size != remainder.stackSize && storage instanceof ItemStorageExternal && !simulate) {
((ItemStorageExternal) storage).updateCacheForcefully();
}
size = remainder.stackSize;
}
}

View File

@@ -14,16 +14,16 @@ public abstract class ItemStorageExternal implements IItemStorage {
public boolean updateCache() {
List<ItemStack> items = getStacks();
if (cache == null) {
cache = items;
if (this.cache == null) {
this.cache = items;
} else if (items.size() != cache.size()) {
cache = items;
this.cache = items;
return true;
} else {
for (int i = 0; i < items.size(); ++i) {
if (!API.instance().getComparer().isEqual(items.get(i), cache.get(i))) {
cache = items;
this.cache = items;
return true;
}
@@ -34,6 +34,6 @@ public abstract class ItemStorageExternal implements IItemStorage {
}
public void updateCacheForcefully() {
cache = getStacks();
this.cache = getStacks();
}
}