builders now only send packets to GUI watchers

This commit is contained in:
asiekierka 2014-11-02 07:36:33 +01:00
parent 98c5d71087
commit ad25b17c6e
6 changed files with 68 additions and 19 deletions

View file

@ -283,12 +283,12 @@ tile.zonePlan.name=Zone Planner
tile.architect.rotate=Rotate: On
tile.architect.norotate=Rotate: Off
tile.architect.allblocks=Blocks: All
tile.architect.simpleblocks=Blocks: Simple
tile.architect.allowCreative=Mode: Creative
tile.architect.noallowCreative=Mode: Survival
tile.architect.tooltip.allowCreative.1=Creative allows all blocks - Creative Mode only!
tile.architect.tooltip.allowCreative.2=Survival ignores all unsupported blocks
tile.architect.excavate=Excavate: On
tile.architect.noexcavate=Excavate: Off
tile.architect.supportmods=Mods: Support
tile.architect.allmods=Mods: All
tip.gate.wires=§9§oCompatible Wires:
tip.gate.wires.redstone=Red

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

View file

@ -38,6 +38,7 @@ import buildcraft.api.robots.StackRequest;
import buildcraft.api.tiles.IHasWork;
import buildcraft.core.Box;
import buildcraft.core.Box.Kind;
import buildcraft.core.DefaultProps;
import buildcraft.core.LaserData;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BlueprintBase;
@ -84,7 +85,8 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
private ArrayList<ItemStack> requiredToBuild;
private NBTTagCompound initNBT = null;
private boolean done = true;
private boolean isBuilding = false;
private class PathIterator {
public Iterator<BlockIndex> currentIterator;
@ -593,6 +595,10 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
}
}
if (!isBuilding && this.isBuildingBlueprint()) {
updateRequirements();
}
isBuilding = this.isBuildingBlueprint();
if (done) {
return;
@ -685,10 +691,17 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
}
}
public void updateRequirements () {
public void updateRequirements() {
if (guiWatchers.size() == 0) {
// Nobody watching, do not update.
return;
}
ArrayList<ItemStack> reqCopy = null;
ArrayList<Integer> realSize = null;
if (currentBuilder instanceof BptBuilderBlueprint) {
ArrayList<ItemStack> reqCopy = new ArrayList<ItemStack>();
ArrayList<Integer> realSize = new ArrayList<Integer>();
reqCopy = new ArrayList<ItemStack>();
realSize = new ArrayList<Integer>();
for (ItemStack stack : ((BptBuilderBlueprint) currentBuilder).neededItems) {
realSize.add(stack.stackSize);
@ -696,12 +709,29 @@ public class TileBuilder extends TileAbstractBuilder implements IHasWork, IFluid
newStack.stackSize = 0;
reqCopy.add(newStack);
}
}
for (EntityPlayer p : guiWatchers) {
RPCHandler.rpcPlayer(p, this, "setItemRequirements", reqCopy, realSize);
}
}
public void updateRequirements(EntityPlayer caller) {
ArrayList<ItemStack> reqCopy = null;
ArrayList<Integer> realSize = null;
if (currentBuilder instanceof BptBuilderBlueprint) {
reqCopy = new ArrayList<ItemStack>();
realSize = new ArrayList<Integer>();
RPCHandler.rpcBroadcastWorldPlayers(worldObj, this, "setItemRequirements", reqCopy, realSize);
} else {
RPCHandler.rpcBroadcastWorldPlayers(worldObj, this, "setItemRequirements", null, null);
for (ItemStack stack : ((BptBuilderBlueprint) currentBuilder).neededItems) {
realSize.add(stack.stackSize);
ItemStack newStack = stack.copy();
newStack.stackSize = 0;
reqCopy.add(newStack);
}
}
RPCHandler.rpcPlayer(caller, this, "setItemRequirements", reqCopy, realSize);
}
public BptBuilderBase getBlueprint () {

View file

@ -9,9 +9,9 @@
package buildcraft.builders.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import buildcraft.builders.TileBuilder;
import buildcraft.core.gui.BuildCraftContainer;
@ -43,12 +43,19 @@ public class ContainerBuilder extends BuildCraftContainer {
addSlotToContainer(new Slot(playerInventory, x, 8 + x * 18, 198));
}
if (!builder.getWorldObj().isRemote) {
// TODO: Figure out a nicer way of fixing this bug.
// Refreshes the requirement list on every GUI opening.
builder.updateRequirements();
if (!builder.getWorldObj().isRemote && playerInventory instanceof InventoryPlayer) {
// Refresh the requirements list for the player opening the GUI,
// in case he does not have it.
builder.updateRequirements(((InventoryPlayer) playerInventory).player);
builder.addGuiWatcher(((InventoryPlayer) playerInventory).player);
}
}
@Override
public void onContainerClosed(EntityPlayer player) {
super.onContainerClosed(player);
builder.removeGuiWatcher(player);
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {

View file

@ -10,6 +10,7 @@ package buildcraft.core;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import net.minecraft.entity.EntityLivingBase;
@ -19,11 +20,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyHandler;
import buildcraft.BuildCraftCore;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.core.network.BuildCraftPacket;
@ -35,6 +33,8 @@ import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.utils.Utils;
public abstract class TileBuildCraft extends TileEntity implements ISynchronizedTile, IEnergyHandler {
protected HashSet<EntityPlayer> guiWatchers = new HashSet<EntityPlayer>();
@SuppressWarnings("rawtypes")
private static Map<Class, TilePacketWrapper> updateWrappers = new HashMap<Class, TilePacketWrapper>();
@SuppressWarnings("rawtypes")
@ -61,7 +61,19 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
public String getOwner() {
return owner;
}
public void addGuiWatcher(EntityPlayer player) {
if (!guiWatchers.contains(player)) {
guiWatchers.add(player);
}
}
public void removeGuiWatcher(EntityPlayer player) {
if (guiWatchers.contains(player)) {
guiWatchers.remove(player);
}
}
@Override
public void updateEntity() {
if (!init && !isInvalid()) {