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.

93 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.brokenmoon.afloydwiremod.packet.WiremodSettingsPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringPacket;
import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity;
import net.minecraft.src.*;
public class GuiSettings extends GuiScreen {
private EntityPlayer player;
private AbstractWireTileEntity wireEntity;
@Override
public void initGui() {
//this.height - 240 is top
//This.width / 2 - 214 is left
//Inputs
if(wireEntity instanceof ChipTileEntity){
switch(((ChipTileEntity) wireEntity).mode){
case "constant":
initConst();
break;
case "Pulse":
initPulse();
break;
}
}
}
private void initPulse() {
this.controlList.add(new GuiButton(1, this.width /2 - 100, this.height/2 - 20 - 10, "+"));
this.controlList.add(1,new GuiButton(0, this.width /2 - 100, this.height/2 - 10, ((ChipTileEntity)wireEntity).tickAmount + ""));
this.controlList.add(new GuiButton(2, this.width /2 - 100, this.height/2 + 20 - 10, "-"));
}
public void initConst(){
this.controlList.add(new GuiButton(1, this.width /2 - 100, this.height/2 - 20 - 10, "+"));
this.controlList.add(1,new GuiButton(0, this.width /2 - 100, this.height/2 - 10 , wireEntity.outputs[0].floatvalue + ""));
this.controlList.add(new GuiButton(2, this.width /2 - 100, this.height/2 + 20 - 10, "-"));
}
public GuiSettings(EntityPlayer player, AbstractWireTileEntity wireEntity) {
super.initGui();
this.player = player;
this.wireEntity = wireEntity;
}
@Override
protected void actionPerformed(GuiButton guiButton){
if(wireEntity instanceof ChipTileEntity){
switch(((ChipTileEntity)wireEntity).mode){
case "constant":
constAction(guiButton);
break;
case "Pulse":
pulseAction(guiButton);
break;
}
}
}
private void pulseAction(GuiButton guiButton) {
if(guiButton.id == 1){
((ChipTileEntity)wireEntity).tickAmount++;
}
if(guiButton.id == 2 && ((ChipTileEntity)wireEntity).tickAmount > 0){
((ChipTileEntity)wireEntity).tickAmount--;
}
if(this.player instanceof EntityClientPlayerMP){
NetClientHandler netclienthandler = ((EntityClientPlayerMP)this.mc.thePlayer).sendQueue;
netclienthandler.addToSendQueue(new WiremodSettingsPacket(1, ((ChipTileEntity)wireEntity).tickAmount, wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord));
}
this.controlList.get(1).displayString = ((ChipTileEntity)wireEntity).tickAmount + "";
}
private void constAction(GuiButton guiButton) {
if(guiButton.id == 1){
wireEntity.outputs[0].floatvalue++;
}
if(guiButton.id == 2){
wireEntity.outputs[0].floatvalue--;
}
this.controlList.get(1).displayString = wireEntity.outputs[0].floatvalue + "";
if(this.player instanceof EntityClientPlayerMP){
NetClientHandler netclienthandler = ((EntityClientPlayerMP)this.mc.thePlayer).sendQueue;
netclienthandler.addToSendQueue(new WiremodSettingsPacket(0, wireEntity.outputs[0].floatvalue, wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord));
}
wireEntity.updateIO();
}
}