Don't send when rebuilding

This commit is contained in:
Raoul Van den Berge
2016-06-30 21:57:57 +02:00
parent 0d8d60e045
commit e6b5015ef8
3 changed files with 23 additions and 4 deletions

View File

@@ -15,6 +15,11 @@ public interface IGroupedStorage {
*/ */
void rebuild(); void rebuild();
/**
* @return If this storage is currently rebuilding
*/
boolean isRebuilding();
/** /**
* 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.
* *

View File

@@ -15,6 +15,7 @@ import java.util.Collection;
public class GroupedStorage implements IGroupedStorage { public class GroupedStorage implements IGroupedStorage {
private INetworkMaster network; private INetworkMaster network;
private Multimap<Item, ItemStack> stacks = ArrayListMultimap.create(); private Multimap<Item, ItemStack> stacks = ArrayListMultimap.create();
private boolean rebuilding;
public GroupedStorage(INetworkMaster network) { public GroupedStorage(INetworkMaster network) {
this.network = network; this.network = network;
@@ -22,6 +23,8 @@ public class GroupedStorage implements IGroupedStorage {
@Override @Override
public void rebuild() { public void rebuild() {
this.rebuilding = true;
stacks.clear(); stacks.clear();
for (IStorage storage : network.getStorages()) { for (IStorage storage : network.getStorages()) {
@@ -38,9 +41,16 @@ public class GroupedStorage implements IGroupedStorage {
} }
} }
this.rebuilding = false;
network.sendStorageToClient(); network.sendStorageToClient();
} }
@Override
public boolean isRebuilding() {
return rebuilding;
}
@Override @Override
public void add(ItemStack stack) { public void add(ItemStack stack) {
for (ItemStack otherStack : stacks.get(stack.getItem())) { for (ItemStack otherStack : stacks.get(stack.getItem())) {

View File

@@ -410,16 +410,20 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
@Override @Override
public void sendStorageToClient() { public void sendStorageToClient() {
for (EntityPlayer player : worldObj.playerEntities) { if (!storage.isRebuilding()) {
if (isWatchingGrid(player)) { for (EntityPlayer player : worldObj.playerEntities) {
sendStorageToClient((EntityPlayerMP) player); if (isWatchingGrid(player)) {
sendStorageToClient((EntityPlayerMP) player);
}
} }
} }
} }
@Override @Override
public void sendStorageToClient(EntityPlayerMP player) { public void sendStorageToClient(EntityPlayerMP player) {
RefinedStorage.NETWORK.sendTo(new MessageGridItems(this), player); if (!storage.isRebuilding()) {
RefinedStorage.NETWORK.sendTo(new MessageGridItems(this), player);
}
} }
private boolean isWatchingGrid(EntityPlayer player) { private boolean isWatchingGrid(EntityPlayer player) {