Fixed caching issues with External Storage
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
**Bugfixes**
|
||||
- Several models / texture tweaks
|
||||
- Fixed bug where Grid doesn't handle remainder sometimes
|
||||
- Fixed caching issues with External Storage
|
||||
|
||||
### 0.8.8
|
||||
**Bugfixes**
|
||||
|
@@ -327,16 +327,4 @@ public final class RefinedStorageUtils {
|
||||
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
|
||||
return RefinedStorageUtils.getPattern(network, stack) != null;
|
||||
}
|
||||
|
||||
public static int getItemStackHashCode(ItemStack stack) {
|
||||
return getItemStackHashCode(stack, stack == null ? 0 : stack.stackSize);
|
||||
}
|
||||
|
||||
public static int getItemStackHashCode(ItemStack stack, int stackSize) {
|
||||
if (stack == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return stack.getItem().hashCode() + Math.max(1, stackSize) * (stack.hasTagCompound() ? stack.getTagCompound().hashCode() : 1);
|
||||
}
|
||||
}
|
||||
|
@@ -78,7 +78,7 @@ public class TileSolderer extends TileNode {
|
||||
|
||||
recipe = null;
|
||||
progress = 0;
|
||||
// Don't set working to false yet, wait till the next update because we may have another stack waiting.
|
||||
// Don't set working to false yet, wait till the next shouldUpdateCache because we may have another stack waiting.
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
@@ -493,7 +493,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
remainder = storage.insertItem(remainder, size, simulate);
|
||||
|
||||
if (storage instanceof ExternalStorage && !simulate) {
|
||||
((ExternalStorage) storage).setHash();
|
||||
((ExternalStorage) storage).updateCacheForcefully();
|
||||
}
|
||||
|
||||
if (remainder == null) {
|
||||
@@ -532,11 +532,11 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
for (IStorage storage : this.storage.getStorages()) {
|
||||
ItemStack took = storage.extractItem(stack, requested - received, flags);
|
||||
|
||||
if (storage instanceof ExternalStorage) {
|
||||
((ExternalStorage) storage).setHash();
|
||||
}
|
||||
|
||||
if (took != null) {
|
||||
if (storage instanceof ExternalStorage) {
|
||||
((ExternalStorage) storage).updateCacheForcefully();
|
||||
}
|
||||
|
||||
if (newStack == null) {
|
||||
newStack = took;
|
||||
} else {
|
||||
|
@@ -17,8 +17,6 @@ public class DeepStorageUnitStorage extends ExternalStorage {
|
||||
public DeepStorageUnitStorage(TileExternalStorage externalStorage, IDeepStorageUnit unit) {
|
||||
this.externalStorage = externalStorage;
|
||||
this.unit = unit;
|
||||
|
||||
setHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,11 +24,6 @@ public class DeepStorageUnitStorage extends ExternalStorage {
|
||||
return unit.getMaxStoredCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHash() {
|
||||
return RefinedStorageUtils.getItemStackHashCode(unit.getStoredItemType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
if (unit.getStoredItemType() != null && unit.getStoredItemType().stackSize > 0) {
|
||||
|
@@ -17,8 +17,6 @@ public class DrawerStorage extends ExternalStorage {
|
||||
public DrawerStorage(TileExternalStorage externalStorage, IDrawer drawer) {
|
||||
this.externalStorage = externalStorage;
|
||||
this.drawer = drawer;
|
||||
|
||||
setHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,11 +24,6 @@ public class DrawerStorage extends ExternalStorage {
|
||||
return drawer.getMaxCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHash() {
|
||||
return RefinedStorageUtils.getItemStackHashCode(drawer.getStoredItemPrototype(), drawer.getStoredItemCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
if (!drawer.isEmpty() && drawer.getStoredItemCount() > 0) {
|
||||
|
@@ -1,25 +1,38 @@
|
||||
package refinedstorage.tile.externalstorage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.api.storage.IStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ExternalStorage implements IStorage {
|
||||
private int hash = -1;
|
||||
private List<ItemStack> cache = new ArrayList<ItemStack>();
|
||||
|
||||
public abstract int getCapacity();
|
||||
|
||||
public void setHash() {
|
||||
this.hash = getHash();
|
||||
}
|
||||
public boolean updateCache() {
|
||||
List<ItemStack> items = getItems();
|
||||
|
||||
public abstract int getHash();
|
||||
|
||||
public boolean isDirty() {
|
||||
if (hash != -1 && hash != getHash()) {
|
||||
hash = getHash();
|
||||
if (items.size() != cache.size()) {
|
||||
cache = items;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
if (!RefinedStorageUtils.compareStack(items.get(i), cache.get(i))) {
|
||||
cache = items;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateCacheForcefully() {
|
||||
cache = getItems();
|
||||
}
|
||||
}
|
||||
|
@@ -16,8 +16,6 @@ public class ItemHandlerStorage extends ExternalStorage {
|
||||
public ItemHandlerStorage(TileExternalStorage externalStorage, IItemHandler handler) {
|
||||
this.externalStorage = externalStorage;
|
||||
this.handler = handler;
|
||||
|
||||
setHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,19 +23,6 @@ public class ItemHandlerStorage extends ExternalStorage {
|
||||
return handler.getSlots() * 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHash() {
|
||||
int code = 0;
|
||||
|
||||
for (int i = 0; i < handler.getSlots(); ++i) {
|
||||
if (handler.getStackInSlot(i) != null && handler.getStackInSlot(i).getItem() != null) {
|
||||
code += RefinedStorageUtils.getItemStackHashCode(handler.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getItems() {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
|
@@ -64,11 +64,19 @@ public class TileExternalStorage extends TileNode implements IStorageProvider, I
|
||||
@Override
|
||||
public void update() {
|
||||
if (!worldObj.isRemote && network != null) {
|
||||
for (ExternalStorage storage : storages) {
|
||||
if (storage.isDirty()) {
|
||||
updateStorage(network);
|
||||
if (ticks % (20 * 4) == 0) {
|
||||
boolean shouldRebuild = false;
|
||||
|
||||
break;
|
||||
for (ExternalStorage storage : storages) {
|
||||
if (storage.updateCache()) {
|
||||
shouldRebuild = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldRebuild) {
|
||||
System.out.println("Rebuilding ext storage");
|
||||
|
||||
network.getStorage().rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user