package net.brokenmoon.afloydwiremod.gui; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.api.WireConnection; import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket; import net.brokenmoon.afloydwiremod.packet.WiremodWiringPacket; import net.minecraft.client.Minecraft; import net.minecraft.src.EntityClientPlayerMP; import net.minecraft.src.EntityPlayer; import net.minecraft.src.GuiButton; import net.minecraft.src.NetClientHandler; import java.util.ArrayList; public class GuiWiring extends GuiScrollable { private ToolWiring tool; private int x; private int y; private int z; private AbstractWireTileEntity wireEntity; private AbstractWireTileEntity otherEntity; @Override public void initGui() { //this.height - 240 is top //This.width / 2 - 214 is left //Inputs if(wireEntity.inputs != null && !this.tool.type.equals("input")) { for (int i = 0; i < wireEntity.inputs.length; i++) { this.controlList.add(new GuiButtonExtended(i, this.width - GuiButtonExtended.width, wireEntity.inputs[i].buttonString, "Input", wireEntity.inputs[i].slot)); } } //Outputs if(wireEntity.outputs != null && !this.tool.type.equals("output")) { for (int i = 0; i < wireEntity.outputs.length; i++) { this.controlList.add(new GuiButtonExtended(i, this.width + GuiButtonExtended.width, wireEntity.outputs[i].buttonString, "Output", wireEntity.outputs[i].slot)); } } } public GuiWiring(EntityPlayer player, ToolWiring tool, AbstractWireTileEntity wireEntity, int x, int y, int z) { super.initGui(); this.player = player; this.tool = tool; this.x = x; this.y = y; this.z = z; this.wireEntity = wireEntity; otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z); System.out.println(player instanceof EntityClientPlayerMP); } @Override protected void actionPerformed(GuiButton guiButton){ this.actionPerformed((GuiButtonExtended)guiButton); } protected void actionPerformed(GuiButtonExtended guibutton) { if(this.tool.type.equals("unpaired")) { if (guibutton.type.equals("Input")) { this.tool.type = "input"; this.tool.slot = guibutton.slot; this.tool.x = x; this.tool.y = y; this.tool.z = z; tool.xadd = new ArrayList(); tool.yadd = new ArrayList(); tool.zadd = new ArrayList(); tool.sideadd = new ArrayList(); } else if (guibutton.type.equals("Output")) { this.tool.type = "output"; this.tool.slot = guibutton.slot; this.tool.x = x; this.tool.y = y; this.tool.z = z; tool.xadd = new ArrayList(); tool.yadd = new ArrayList(); tool.zadd = new ArrayList(); tool.sideadd = new ArrayList(); } } else if(!this.tool.type.equals("unpaired")) { if(this.tool.type.equals("input") && wireEntity.outputs[guibutton.slot].wire.isMade != true && otherEntity != null && otherEntity.inputs[tool.slot].wire.isMade != true) { if(this.player instanceof EntityClientPlayerMP){ NetClientHandler netclienthandler = ((EntityClientPlayerMP)this.mc.thePlayer).sendQueue; netclienthandler.addToSendQueue(new WiremodWiringPacket(wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord, this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, false, tool.red, tool.green, tool.blue, tool.alpha, tool.width)); netclienthandler.addToSendQueue(new WiremodWiringPacket(this.tool.x, this.tool.y, this.tool.z, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot)); System.out.println("Okay"); } else{ wireEntity.outputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, false, tool.red, tool.green, tool.blue, tool.alpha, tool.width); otherEntity.inputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot); wireEntity.update(); wireEntity.updateIO(); otherEntity.update(); otherEntity.updateIO(); } tool.xadd = new ArrayList(); tool.yadd = new ArrayList(); tool.zadd = new ArrayList(); tool.sideadd = new ArrayList(); tool.type = "unpaired"; } else if(this.tool.type.equals("output") && otherEntity.outputs[tool.slot].wire.isMade != true && otherEntity != null && wireEntity.inputs[guibutton.slot].wire.isMade != true ) { if(otherEntity != null) { if(this.player instanceof EntityClientPlayerMP){ NetClientHandler netclienthandler = ((EntityClientPlayerMP)this.mc.thePlayer).sendQueue; netclienthandler.addToSendQueue(new WiremodWiringPacket(wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord, this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, true, tool.red, tool.green, tool.blue, tool.alpha, tool.width)); netclienthandler.addToSendQueue(new WiremodWiringPacket(this.tool.x, this.tool.y, this.tool.z, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot)); System.out.println("Okay"); } else{ otherEntity.outputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, true, tool.red, tool.green, tool.blue, tool.alpha, tool.width); wireEntity.inputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot); wireEntity.update(); wireEntity.updateIO(); otherEntity.update(); otherEntity.updateIO(); } } tool.xadd = new ArrayList(); tool.yadd = new ArrayList(); tool.zadd = new ArrayList(); tool.sideadd = new ArrayList(); tool.type = "unpaired"; } else{ tool.xadd = new ArrayList(); tool.yadd = new ArrayList(); tool.zadd = new ArrayList(); tool.sideadd = new ArrayList(); tool.type = "unpaired"; } } this.mc.displayGuiScreen(null); } }