Merge pull request #474 from nevercast/patch-gates
Gate GUI is now calculated server-side
This commit is contained in:
commit
09957806ca
4 changed files with 50 additions and 17 deletions
|
@ -160,11 +160,11 @@
|
|||
<target name="compile" depends="setup">
|
||||
|
||||
<!-- Recompile -->
|
||||
<exec dir="${mcp.dir}" executable="cmd" osfamily="windows">
|
||||
<exec dir="${mcp.dir}" executable="cmd" osfamily="windows" failonerror="true">
|
||||
<arg line="/c recompile.bat"/>
|
||||
</exec>
|
||||
|
||||
<exec dir="${mcp.dir}" executable="sh" osfamily="unix">
|
||||
<exec dir="${mcp.dir}" executable="sh" osfamily="unix" failonerror="true">
|
||||
<arg value="recompile.sh" />
|
||||
</exec>
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ public class ItemGate extends ItemBuildCraft {
|
|||
return (new StringBuilder()).append(super.getItemName()).append(".").append(itemstack.getItemDamage()).toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
|
|
|
@ -12,6 +12,13 @@ package buildcraft.transport.gui;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ICrafting;
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.Slot;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.api.gates.ActionManager;
|
||||
|
@ -28,13 +35,6 @@ import buildcraft.core.network.PacketUpdate;
|
|||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.transport.Pipe;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.Slot;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public class ContainerGateInterface extends BuildCraftContainer {
|
||||
|
||||
IInventory playerIInventory;
|
||||
|
@ -45,6 +45,8 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
|
||||
private boolean isSynchronized = false;
|
||||
private boolean isNetInitialized = false;
|
||||
public boolean[] triggerState = new boolean[8];
|
||||
private int lastTriggerState = 0;
|
||||
|
||||
public ContainerGateInterface(IInventory playerInventory, Pipe pipe) {
|
||||
super(0);
|
||||
|
@ -214,10 +216,43 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
CoreProxy.proxy.sendToServer(new PacketCoordinates(PacketIds.GATE_REQUEST_SELECTION, pipe.xCoord, pipe.yCoord, pipe.zCoord)
|
||||
.getPacket());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int id, int state) {
|
||||
if(id == 0 /* Trigger state update */){
|
||||
for(int i = 0; i < 8; i++){
|
||||
/* Bit mask of triggers */
|
||||
triggerState[i] = ((state >> i) & 0x01) == 0x01;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** SERVER SIDE **/
|
||||
private int calculateTriggerState(){
|
||||
int state = 0;
|
||||
for(int i = 0; i < triggerState.length; i++){
|
||||
if(pipe.activatedTriggers[i] != null){
|
||||
triggerState[i] = isNearbyTriggerActive(pipe.activatedTriggers[i], pipe.getTriggerParameter(i));
|
||||
}
|
||||
state |= triggerState[i] ? 0x01 << i : 0x0;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCraftingResults() {
|
||||
super.updateCraftingResults();
|
||||
int state = calculateTriggerState();
|
||||
if(state != lastTriggerState){
|
||||
for(int i = 0; i < this.crafters.size(); i++){
|
||||
ICrafting viewingPlayer = (ICrafting)this.crafters.get(i);
|
||||
|
||||
viewingPlayer.sendProgressBarUpdate(this, 0 /* State update */, state);
|
||||
}
|
||||
lastTriggerState = state;
|
||||
}
|
||||
}
|
||||
|
||||
public void handleInitRequest(EntityPlayer player) {
|
||||
sendActions(player);
|
||||
|
|
|
@ -260,6 +260,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
|
|||
int cornerY = (height - ySize) / 2;
|
||||
drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);
|
||||
|
||||
int triggerTracker = 0;
|
||||
for (int s = 0; s < slots.length; ++s) {
|
||||
AdvancedSlot slot = slots[s];
|
||||
|
||||
|
@ -267,12 +268,8 @@ public class GuiGateInterface extends GuiAdvancedInterface {
|
|||
ITrigger trigger = ((TriggerSlot) slot).getTrigger();
|
||||
|
||||
if (_container.getGateOrdinal() >= GateKind.AND_3.ordinal()) {
|
||||
ITriggerParameter parameter = null;
|
||||
|
||||
if (slots[s + nbEntries * 2] != null && slots[s + nbEntries * 2].isDefined())
|
||||
parameter = ((TriggerParameterSlot) slots[s + nbEntries * 2]).getTriggerParameter();
|
||||
|
||||
if (_container.isNearbyTriggerActive(trigger, parameter)) {
|
||||
|
||||
if (_container.triggerState[triggerTracker++]) {
|
||||
mc.renderEngine.bindTexture(texture);
|
||||
|
||||
drawTexturedModalRect(cornerX + slot.x + 35, cornerY + slot.y + 6, 176, 18, 18, 4);
|
||||
|
@ -283,7 +280,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
|
|||
|
||||
drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y - 1, 176, 0, 18, 18);
|
||||
}
|
||||
} else if (_container.isNearbyTriggerActive(trigger, null)) {
|
||||
} else if (_container.triggerState[triggerTracker++]) {
|
||||
mc.renderEngine.bindTexture(texture);
|
||||
|
||||
drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y + 6, 176, 18, 18, 4);
|
||||
|
|
Loading…
Reference in a new issue