Fixed caching issues with External Storage
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
**Bugfixes**
|
**Bugfixes**
|
||||||
- Several models / texture tweaks
|
- Several models / texture tweaks
|
||||||
- Fixed bug where Grid doesn't handle remainder sometimes
|
- Fixed bug where Grid doesn't handle remainder sometimes
|
||||||
|
- Fixed caching issues with External Storage
|
||||||
|
|
||||||
### 0.8.8
|
### 0.8.8
|
||||||
**Bugfixes**
|
**Bugfixes**
|
||||||
|
@@ -327,16 +327,4 @@ public final class RefinedStorageUtils {
|
|||||||
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
|
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
|
||||||
return RefinedStorageUtils.getPattern(network, stack) != null;
|
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;
|
recipe = null;
|
||||||
progress = 0;
|
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();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
@@ -493,7 +493,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
remainder = storage.insertItem(remainder, size, simulate);
|
remainder = storage.insertItem(remainder, size, simulate);
|
||||||
|
|
||||||
if (storage instanceof ExternalStorage && !simulate) {
|
if (storage instanceof ExternalStorage && !simulate) {
|
||||||
((ExternalStorage) storage).setHash();
|
((ExternalStorage) storage).updateCacheForcefully();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remainder == null) {
|
if (remainder == null) {
|
||||||
@@ -532,11 +532,11 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
for (IStorage storage : this.storage.getStorages()) {
|
for (IStorage storage : this.storage.getStorages()) {
|
||||||
ItemStack took = storage.extractItem(stack, requested - received, flags);
|
ItemStack took = storage.extractItem(stack, requested - received, flags);
|
||||||
|
|
||||||
if (storage instanceof ExternalStorage) {
|
|
||||||
((ExternalStorage) storage).setHash();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (took != null) {
|
if (took != null) {
|
||||||
|
if (storage instanceof ExternalStorage) {
|
||||||
|
((ExternalStorage) storage).updateCacheForcefully();
|
||||||
|
}
|
||||||
|
|
||||||
if (newStack == null) {
|
if (newStack == null) {
|
||||||
newStack = took;
|
newStack = took;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -17,8 +17,6 @@ public class DeepStorageUnitStorage extends ExternalStorage {
|
|||||||
public DeepStorageUnitStorage(TileExternalStorage externalStorage, IDeepStorageUnit unit) {
|
public DeepStorageUnitStorage(TileExternalStorage externalStorage, IDeepStorageUnit unit) {
|
||||||
this.externalStorage = externalStorage;
|
this.externalStorage = externalStorage;
|
||||||
this.unit = unit;
|
this.unit = unit;
|
||||||
|
|
||||||
setHash();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,11 +24,6 @@ public class DeepStorageUnitStorage extends ExternalStorage {
|
|||||||
return unit.getMaxStoredCount();
|
return unit.getMaxStoredCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHash() {
|
|
||||||
return RefinedStorageUtils.getItemStackHashCode(unit.getStoredItemType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getItems() {
|
public List<ItemStack> getItems() {
|
||||||
if (unit.getStoredItemType() != null && unit.getStoredItemType().stackSize > 0) {
|
if (unit.getStoredItemType() != null && unit.getStoredItemType().stackSize > 0) {
|
||||||
|
@@ -17,8 +17,6 @@ public class DrawerStorage extends ExternalStorage {
|
|||||||
public DrawerStorage(TileExternalStorage externalStorage, IDrawer drawer) {
|
public DrawerStorage(TileExternalStorage externalStorage, IDrawer drawer) {
|
||||||
this.externalStorage = externalStorage;
|
this.externalStorage = externalStorage;
|
||||||
this.drawer = drawer;
|
this.drawer = drawer;
|
||||||
|
|
||||||
setHash();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,11 +24,6 @@ public class DrawerStorage extends ExternalStorage {
|
|||||||
return drawer.getMaxCapacity();
|
return drawer.getMaxCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHash() {
|
|
||||||
return RefinedStorageUtils.getItemStackHashCode(drawer.getStoredItemPrototype(), drawer.getStoredItemCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getItems() {
|
public List<ItemStack> getItems() {
|
||||||
if (!drawer.isEmpty() && drawer.getStoredItemCount() > 0) {
|
if (!drawer.isEmpty() && drawer.getStoredItemCount() > 0) {
|
||||||
|
@@ -1,25 +1,38 @@
|
|||||||
package refinedstorage.tile.externalstorage;
|
package refinedstorage.tile.externalstorage;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.api.storage.IStorage;
|
import refinedstorage.api.storage.IStorage;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class ExternalStorage implements IStorage {
|
public abstract class ExternalStorage implements IStorage {
|
||||||
private int hash = -1;
|
private List<ItemStack> cache = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
public abstract int getCapacity();
|
public abstract int getCapacity();
|
||||||
|
|
||||||
public void setHash() {
|
public boolean updateCache() {
|
||||||
this.hash = getHash();
|
List<ItemStack> items = getItems();
|
||||||
}
|
|
||||||
|
|
||||||
public abstract int getHash();
|
if (items.size() != cache.size()) {
|
||||||
|
cache = items;
|
||||||
public boolean isDirty() {
|
|
||||||
if (hash != -1 && hash != getHash()) {
|
|
||||||
hash = getHash();
|
|
||||||
|
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateCacheForcefully() {
|
||||||
|
cache = getItems();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,6 @@ public class ItemHandlerStorage extends ExternalStorage {
|
|||||||
public ItemHandlerStorage(TileExternalStorage externalStorage, IItemHandler handler) {
|
public ItemHandlerStorage(TileExternalStorage externalStorage, IItemHandler handler) {
|
||||||
this.externalStorage = externalStorage;
|
this.externalStorage = externalStorage;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
|
||||||
setHash();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -25,19 +23,6 @@ public class ItemHandlerStorage extends ExternalStorage {
|
|||||||
return handler.getSlots() * 64;
|
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
|
@Override
|
||||||
public List<ItemStack> getItems() {
|
public List<ItemStack> getItems() {
|
||||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
|
@@ -64,11 +64,19 @@ public class TileExternalStorage extends TileNode implements IStorageProvider, I
|
|||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
if (!worldObj.isRemote && network != null) {
|
if (!worldObj.isRemote && network != null) {
|
||||||
for (ExternalStorage storage : storages) {
|
if (ticks % (20 * 4) == 0) {
|
||||||
if (storage.isDirty()) {
|
boolean shouldRebuild = false;
|
||||||
updateStorage(network);
|
|
||||||
|
|
||||||
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