Fixed sending deltas while the storage is being rebuilt

This commit is contained in:
Raoul Van den Berge
2016-07-10 20:22:41 +02:00
parent 23044e5b63
commit a57e9e8e9b
5 changed files with 17 additions and 13 deletions

View File

@@ -20,8 +20,9 @@ public interface IGroupedStorage {
* Adds an item to the network. Will merge it with another item if it already exists. * Adds an item to the network. Will merge it with another item if it already exists.
* *
* @param stack The stack to add, do NOT modify * @param stack The stack to add, do NOT modify
* @param rebuilding Whether this method is called while the storage is rebuilding
*/ */
void add(ItemStack stack); void add(ItemStack stack, boolean rebuilding);
/** /**
* Removes a item from the network. * Removes a item from the network.

View File

@@ -39,7 +39,7 @@ public class GroupedStorage implements IGroupedStorage {
for (IStorage storage : storages) { for (IStorage storage : storages) {
for (ItemStack stack : storage.getItems()) { for (ItemStack stack : storage.getItems()) {
add(stack); add(stack, true);
} }
} }
@@ -47,7 +47,7 @@ public class GroupedStorage implements IGroupedStorage {
for (ItemStack output : pattern.getOutputs()) { for (ItemStack output : pattern.getOutputs()) {
ItemStack patternStack = output.copy(); ItemStack patternStack = output.copy();
patternStack.stackSize = 0; patternStack.stackSize = 0;
add(patternStack); add(patternStack, true);
} }
} }
@@ -55,12 +55,14 @@ public class GroupedStorage implements IGroupedStorage {
} }
@Override @Override
public void add(ItemStack stack) { public void add(ItemStack stack, boolean rebuilding) {
for (ItemStack otherStack : stacks.get(stack.getItem())) { for (ItemStack otherStack : stacks.get(stack.getItem())) {
if (RefinedStorageUtils.compareStackNoQuantity(otherStack, stack)) { if (RefinedStorageUtils.compareStackNoQuantity(otherStack, stack)) {
otherStack.stackSize += stack.stackSize; otherStack.stackSize += stack.stackSize;
if (!rebuilding) {
network.sendStorageDeltaToClient(stack, stack.stackSize); network.sendStorageDeltaToClient(stack, stack.stackSize);
}
return; return;
} }
@@ -68,8 +70,10 @@ public class GroupedStorage implements IGroupedStorage {
stacks.put(stack.getItem(), stack.copy()); stacks.put(stack.getItem(), stack.copy());
if (!rebuilding) {
network.sendStorageDeltaToClient(stack, stack.stackSize); network.sendStorageDeltaToClient(stack, stack.stackSize);
} }
}
@Override @Override
public void remove(ItemStack stack) { public void remove(ItemStack stack) {

View File

@@ -516,7 +516,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
} }
} }
storage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted)); storage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted), false);
} }
return remainder; return remainder;

View File

@@ -4,18 +4,19 @@ import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageUtils; import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.storage.IStorage; import refinedstorage.api.storage.IStorage;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class ExternalStorage implements IStorage { public abstract class ExternalStorage implements IStorage {
private List<ItemStack> cache = new ArrayList<ItemStack>(); private List<ItemStack> cache;
public abstract int getCapacity(); public abstract int getCapacity();
public boolean updateCache() { public boolean updateCache() {
List<ItemStack> items = getItems(); List<ItemStack> items = getItems();
if (items.size() != cache.size()) { if (cache == null) {
cache = items;
} else if (items.size() != cache.size()) {
cache = items; cache = items;
return true; return true;

View File

@@ -74,8 +74,6 @@ public class TileExternalStorage extends TileNode implements IStorageProvider, I
} }
if (shouldRebuild) { if (shouldRebuild) {
System.out.println("Rebuilding ext storage");
network.getStorage().rebuild(); network.getStorage().rebuild();
} }
} }