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();
/**
* @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.
*

View File

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

View File

@@ -410,16 +410,20 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
@Override
public void sendStorageToClient() {
for (EntityPlayer player : worldObj.playerEntities) {
if (isWatchingGrid(player)) {
sendStorageToClient((EntityPlayerMP) player);
if (!storage.isRebuilding()) {
for (EntityPlayer player : worldObj.playerEntities) {
if (isWatchingGrid(player)) {
sendStorageToClient((EntityPlayerMP) player);
}
}
}
}
@Override
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) {