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

@@ -19,9 +19,10 @@ public interface IGroupedStorage {
/**
* 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.

View File

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

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;

View File

@@ -4,18 +4,19 @@ 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 List<ItemStack> cache = new ArrayList<ItemStack>();
private List<ItemStack> cache;
public abstract int getCapacity();
public boolean updateCache() {
List<ItemStack> items = getItems();
if (items.size() != cache.size()) {
if (cache == null) {
cache = items;
} else if (items.size() != cache.size()) {
cache = items;
return true;

View File

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