You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.7 KiB
Java

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.minecraft.client.Minecraft;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.GuiButton;
import net.minecraft.src.GuiScreen;
import org.lwjgl.input.Mouse;
public class GuiWiring extends GuiScrollable {
private ToolWiring tool;
private int x;
private int y;
private int z;
private AbstractWireTileEntity wireEntity;
@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 + 1, this.width - 50, 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 + 1, this.width + 50, 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.tool = tool;
this.x = x;
this.y = y;
this.z = z;
this.wireEntity = wireEntity;
}
@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;
} 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;
}
} else if(!this.tool.type.equals("unpaired")) {
if(this.tool.type.equals("output")) {
AbstractWireTileEntity otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z);
otherEntity.outputs[guibutton.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot);
Minecraft.getMinecraft().theWorld.markBlocksDirty(x, y, z, x, y, z);
Minecraft.getMinecraft().theWorld.markBlocksDirty(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord);
tool.type = "unpaired";
} else if(this.tool.type.equals("input")) {
this.wireEntity.outputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot);
Minecraft.getMinecraft().theWorld.markBlocksDirty(x, y, z, x, y, z);
Minecraft.getMinecraft().theWorld.markBlocksDirty(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord);
tool.type = "unpaired";
}
}
this.mc.displayGuiScreen(null);
}
}