From ad25b17c6e07b8eb0823575ca47ea704d8cf546e Mon Sep 17 00:00:00 2001 From: asiekierka Date: Sun, 2 Nov 2014 07:36:33 +0100 Subject: [PATCH] builders now only send packets to GUI watchers --- .../assets/buildcraft/lang/en_US.lang | 8 ++-- .../textures/blocks/transparent.png | Bin 0 -> 150 bytes .../items/triggers/action_redstoneoutput.png | Bin 0 -> 236 bytes common/buildcraft/builders/TileBuilder.java | 44 +++++++++++++++--- .../builders/gui/ContainerBuilder.java | 17 +++++-- common/buildcraft/core/TileBuildCraft.java | 18 +++++-- 6 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 buildcraft_resources/assets/buildcraft/textures/blocks/transparent.png create mode 100644 buildcraft_resources/assets/buildcraft/textures/items/triggers/action_redstoneoutput.png diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index eac08686..3d77a6e2 100644 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -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 diff --git a/buildcraft_resources/assets/buildcraft/textures/blocks/transparent.png b/buildcraft_resources/assets/buildcraft/textures/blocks/transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..9417aa21609c55bb5bf9f38e2dbc282d07441b86 GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;bAV5XE0A7ZWqS)qF_r}R1v5B2 zyO9RsBze2LFm$lWdH^|`1s;*b3=G`DAk4@xYmNj^kiEpy*OmPqHxnDH@R8c*K0qNJ iPZ!4!j_b(@3cNs`0R!XlRjqwM7K5j&pUXO@geCyNj~(y; literal 0 HcmV?d00001 diff --git a/buildcraft_resources/assets/buildcraft/textures/items/triggers/action_redstoneoutput.png b/buildcraft_resources/assets/buildcraft/textures/items/triggers/action_redstoneoutput.png new file mode 100644 index 0000000000000000000000000000000000000000..4f71d2ed69deda6f044dcaff6a781a7b32425102 GIT binary patch literal 236 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!O@L2`Yj=0|Uj~N%HyHl+GyMNQ z{r~^}>lqj(7rWT#%SvG_iYf5<(9Xf)zF}@i%U_1 ZnZf8G!wC)%F)N@644$rjF6*2UngDB~L;U~% literal 0 HcmV?d00001 diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index eb561598..c4728ccc 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -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 requiredToBuild; private NBTTagCompound initNBT = null; private boolean done = true; - + private boolean isBuilding = false; + private class PathIterator { public Iterator 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 reqCopy = null; + ArrayList realSize = null; if (currentBuilder instanceof BptBuilderBlueprint) { - ArrayList reqCopy = new ArrayList(); - ArrayList realSize = new ArrayList(); + reqCopy = new ArrayList(); + realSize = new ArrayList(); 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 reqCopy = null; + ArrayList realSize = null; + if (currentBuilder instanceof BptBuilderBlueprint) { + reqCopy = new ArrayList(); + realSize = new ArrayList(); - 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 () { diff --git a/common/buildcraft/builders/gui/ContainerBuilder.java b/common/buildcraft/builders/gui/ContainerBuilder.java index 8fb5accb..210933db 100644 --- a/common/buildcraft/builders/gui/ContainerBuilder.java +++ b/common/buildcraft/builders/gui/ContainerBuilder.java @@ -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) { diff --git a/common/buildcraft/core/TileBuildCraft.java b/common/buildcraft/core/TileBuildCraft.java index 5ad63044..bf8fd2d5 100644 --- a/common/buildcraft/core/TileBuildCraft.java +++ b/common/buildcraft/core/TileBuildCraft.java @@ -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 guiWatchers = new HashSet(); + @SuppressWarnings("rawtypes") private static Map updateWrappers = new HashMap(); @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()) {