diff --git a/src/main/java/techreborn/client/gui/GuiAESU.java b/src/main/java/techreborn/client/gui/GuiAESU.java index 25c1e0f8c..3bec50e2f 100644 --- a/src/main/java/techreborn/client/gui/GuiAESU.java +++ b/src/main/java/techreborn/client/gui/GuiAESU.java @@ -24,9 +24,15 @@ package techreborn.client.gui; +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; +import reborncore.common.network.NetworkManager; import reborncore.common.powerSystem.PowerSystem; +import techreborn.client.gui.widget.GuiButtonUpDown; +import techreborn.packets.PacketAesu; import techreborn.tiles.storage.TileAdjustableSU; public class GuiAESU extends GuiBase { @@ -63,66 +69,18 @@ public class GuiAESU extends GuiBase { GlStateManager.popMatrix(); this.builder.drawMultiEnergyBar(this, 81, 28, (int) this.tile.getEnergy(), (int) this.tile.getMaxPower(), mouseX, mouseY, 0, layer); - } + + buttonList.add(new GuiButtonUpDown(300, 121, 79, this, layer)); + buttonList.add(new GuiButtonUpDown(301, 121 + 12, 79, this, layer)); + buttonList.add(new GuiButtonUpDown(302, 121 + 24, 79, this, layer)); + buttonList.add(new GuiButtonUpDown(303, 121 + 36, 79, this, layer)); + } + @Override + public void actionPerformed(final GuiButton button) throws IOException { + super.actionPerformed(button); + if (button.id >= 300 && button.id <= 303) { + NetworkManager.sendToServer(new PacketAesu(button.id, tile)); + } + } } - -// private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/aesu.png"); -// -// TileAdjustableSU aesu; -// -// ContainerAESU containerAesu; -// -// public GuiAESU(EntityPlayer player, TileAdjustableSU tileaesu) { -// super(new ContainerAESU(tileaesu, player)); -// this.xSize = 176; -// this.ySize = 197; -// aesu = tileaesu; -// this.containerAesu = (ContainerAESU) this.inventorySlots; -// } -// -// @Override -// public void initGui() { -// super.initGui(); -// this.buttonList.clear(); -// int k = (this.width - this.xSize) / 2; -// int l = (this.height - this.ySize) / 2; -// this.buttonList.add(new GuiButton(0, k + 115, l + 5, 15, 20, "++")); -// this.buttonList.add(new GuiButton(1, k + 115, l + 5 + 20, 15, 20, "+")); -// this.buttonList.add(new GuiButton(2, k + 115, l + 5 + (20 * 2), 15, 20, "-")); -// this.buttonList.add(new GuiButton(3, k + 115, l + 5 + (20 * 3), 15, 20, "--")); -// } -// -// @Override -// protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { -// this.drawDefaultBackground(); -// GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); -// this.mc.getTextureManager().bindTexture(texture); -// int k = (this.width - this.xSize) / 2; -// int l = (this.height - this.ySize) / 2; -// this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); -// } -// -// protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { -// this.fontRenderer.drawString(I18n.format("tile.techreborn:adjustable_su.name"), 40, 10, -// Color.WHITE.getRGB()); -// this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(containerAesu.euOut) + " /tick", 10, 20, -// Color.WHITE.getRGB()); -// this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(containerAesu.storedEu) + " ", 10, 30, -// Color.WHITE.getRGB()); -// this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(containerAesu.euChange) + " change", 10, 40, -// Color.WHITE.getRGB()); -// } -// -// @Override -// protected void actionPerformed(GuiButton button) throws IOException { -// super.actionPerformed(button); -// NetworkManager.sendToServer(new PacketAesu(button.id, aesu)); -// } -// -// @Override -// public void drawScreen(int mouseX, int mouseY, float partialTicks) { -// super.drawScreen(mouseX, mouseY, partialTicks); -// this.renderHoveredToolTip(mouseX, mouseY); -// } -//} diff --git a/src/main/java/techreborn/client/gui/widget/GuiButtonUpDown.java b/src/main/java/techreborn/client/gui/widget/GuiButtonUpDown.java index 77c1fad0f..2158add2c 100644 --- a/src/main/java/techreborn/client/gui/widget/GuiButtonUpDown.java +++ b/src/main/java/techreborn/client/gui/widget/GuiButtonUpDown.java @@ -21,8 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + package techreborn.client.gui.widget; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import techreborn.client.gui.GuiBase; @@ -40,5 +42,23 @@ public class GuiButtonUpDown extends GuiButton { this.layer = layer; this.gui = gui; } + + @Override + public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { + if (layer == GuiBase.Layer.FOREGROUND) { + mouseX -= gui.getGuiLeft(); + mouseY -= gui.getGuiTop(); + } + if (this.enabled && this.visible && mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height) { + return true; + } + return false; + } + + + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) { + // We already have texture drawn + } } diff --git a/src/main/java/techreborn/packets/PacketAesu.java b/src/main/java/techreborn/packets/PacketAesu.java index a1bc53665..9583da8dc 100644 --- a/src/main/java/techreborn/packets/PacketAesu.java +++ b/src/main/java/techreborn/packets/PacketAesu.java @@ -24,6 +24,7 @@ package techreborn.packets; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; import reborncore.common.network.ExtendedPacketBuffer; @@ -54,13 +55,14 @@ public class PacketAesu implements INetworkPacket { @Override public void readData(ExtendedPacketBuffer in) throws IOException { this.pos = in.readBlockPos(); - buttonID = in.readInt(); + this.buttonID = in.readInt(); } @Override public void processData(PacketAesu message, MessageContext context) { - // if (!pos.getWorld().isRemote) { - // pos.handleGuiInputFromClient(buttonID); - // } + TileEntity tile = context.getServerHandler().player.world.getTileEntity(message.pos); + if (tile instanceof TileAdjustableSU){ + ((TileAdjustableSU) tile).handleGuiInputFromClient(message.buttonID); + } } } diff --git a/src/main/java/techreborn/tiles/storage/TileAdjustableSU.java b/src/main/java/techreborn/tiles/storage/TileAdjustableSU.java index da6857d14..01387ab92 100644 --- a/src/main/java/techreborn/tiles/storage/TileAdjustableSU.java +++ b/src/main/java/techreborn/tiles/storage/TileAdjustableSU.java @@ -49,32 +49,11 @@ public class TileAdjustableSU extends TileEnergyStorage implements IContainerPro public Inventory inventory = new Inventory(4, "TileAdjustableSU", 64, this); private int OUTPUT = 64; // The current output - //private double euLastTick = 0; - //private double euChange; - //private int ticks; public TileAdjustableSU() { super("ADJUSTABLE_SU", 4, ModBlocks.ADJUSTABLE_SU, EnumPowerTier.INSANE, maxInput, maxOutput, maxEnergy); } -// @Override -// public void update() { -// super.update(); -// if (ticks == 100) { -// euChange = -1; -// ticks = 0; -// -// } else { -// ticks++; -// euChange += getEnergy() - euLastTick; -// if (euLastTick == getEnergy()) { -// euChange = 0; -// } -// } -// -// euLastTick = getEnergy(); -// } - @Override public ItemStack getToolDrop(EntityPlayer entityPlayer) { return getDropWithNBT(); @@ -85,16 +64,16 @@ public class TileAdjustableSU extends TileEnergyStorage implements IContainerPro } public void handleGuiInputFromClient(int id) { - if (id == 0) { + if (id == 300) { OUTPUT += 256; } - if (id == 1) { + if (id == 301) { OUTPUT += 64; } - if (id == 2) { + if (id == 302) { OUTPUT -= 64; } - if (id == 3) { + if (id == 303) { OUTPUT -= 256; } if (OUTPUT > maxOutput) { @@ -105,13 +84,6 @@ public class TileAdjustableSU extends TileEnergyStorage implements IContainerPro } } -// public double getEuChange() { -// if (euChange == -1) { -// return -1; -// } -// return (euChange / ticks); -// } - public ItemStack getDropWithNBT() { NBTTagCompound tileEntity = new NBTTagCompound(); ItemStack dropStack = new ItemStack(ModBlocks.ADJUSTABLE_SU, 1); @@ -123,8 +95,6 @@ public class TileAdjustableSU extends TileEnergyStorage implements IContainerPro public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); - //tagCompound.setDouble("euChange", euChange); - //tagCompound.setDouble("euLastTick", euLastTick); tagCompound.setInteger("output", OUTPUT); inventory.writeToNBT(tagCompound); return tagCompound; @@ -132,22 +102,27 @@ public class TileAdjustableSU extends TileEnergyStorage implements IContainerPro public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - //this.euChange = nbttagcompound.getDouble("euChange"); - //this.euLastTick = nbttagcompound.getDouble("euLastTick"); this.OUTPUT = nbttagcompound.getInteger("output"); inventory.readFromNBT(nbttagcompound); } - @Override public double getBaseMaxOutput() { return OUTPUT; } + + public int getBaseMaxOutputInt() { + return OUTPUT; + } + + public void setBaseMaxOutput(int output) { + this.OUTPUT = output; + } @Override public BuiltContainer createContainer(EntityPlayer player) { return new ContainerBuilder("aesu").player(player.inventory).inventory().hotbar().armor() .complete(8, 18).addArmor().addInventory().tile(this).energySlot(0, 62, 45).energySlot(1, 98, 45) - .syncEnergyValue().addInventory().create(this); + .syncEnergyValue().syncIntegerValue(this::getBaseMaxOutputInt, this::setBaseMaxOutput).addInventory().create(this); } }