From 9b1093c22c0f69c611997893b97ffb6d20caa68e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 10 Jun 2015 13:52:54 +0100 Subject: [PATCH] Added basic aesu controls, just need to finish the gui :) --- .../java/techreborn/client/gui/GuiAesu.java | 22 ++++++++ .../client/gui/componets/GuiHiddenButton.java | 51 +++++++++++++++++++ .../java/techreborn/packets/PacketAesu.java | 41 +++++++++++++++ .../techreborn/packets/PacketHandler.java | 1 + src/main/java/techreborn/tiles/TileAesu.java | 39 ++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 src/main/java/techreborn/client/gui/componets/GuiHiddenButton.java create mode 100644 src/main/java/techreborn/packets/PacketAesu.java diff --git a/src/main/java/techreborn/client/gui/GuiAesu.java b/src/main/java/techreborn/client/gui/GuiAesu.java index d92004bdb..31781e98d 100644 --- a/src/main/java/techreborn/client/gui/GuiAesu.java +++ b/src/main/java/techreborn/client/gui/GuiAesu.java @@ -1,10 +1,14 @@ package techreborn.client.gui; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import techreborn.client.container.ContainerAesu; +import techreborn.client.gui.componets.GuiHiddenButton; +import techreborn.packets.PacketAesu; +import techreborn.packets.PacketHandler; import techreborn.tiles.TileAesu; public class GuiAesu extends GuiContainer { @@ -23,6 +27,18 @@ public class GuiAesu extends GuiContainer { aesu = tileaesu; } + @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 GuiHiddenButton(0, k + 106, l + 4, 18, 18, "")); + this.buttonList.add(new GuiHiddenButton(1, k + 106, l + 4 + 18, 18, 18, "")); + this.buttonList.add(new GuiHiddenButton(2, k + 106, l + 4 + (18*2), 18, 18, "")); + this.buttonList.add(new GuiHiddenButton(3, k + 106, l + 4 + (18*3), 18, 18, "")); + } + @Override protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) @@ -38,4 +54,10 @@ public class GuiAesu extends GuiContainer { { this.fontRendererObj.drawString(StatCollector.translateToLocal("tile.techreborn.aesu.name"), 40, 6, 4210752); } + + @Override + protected void actionPerformed(GuiButton button) { + super.actionPerformed(button); + PacketHandler.sendPacketToServer(new PacketAesu(button.id, aesu)); + } } diff --git a/src/main/java/techreborn/client/gui/componets/GuiHiddenButton.java b/src/main/java/techreborn/client/gui/componets/GuiHiddenButton.java new file mode 100644 index 000000000..0923016ec --- /dev/null +++ b/src/main/java/techreborn/client/gui/componets/GuiHiddenButton.java @@ -0,0 +1,51 @@ +package techreborn.client.gui.componets; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.OpenGlHelper; +import org.lwjgl.opengl.GL11; + + +public class GuiHiddenButton extends GuiButton { + + public GuiHiddenButton(int id, int xPosition, int yPosition, String displayString) { + super(id, xPosition, yPosition, displayString); + } + + public GuiHiddenButton(int id, int xPosition, int yPosition, int width, int height, String displayString) { + super(id, xPosition, yPosition, width, height, displayString); + } + + @Override + public void drawButton(Minecraft p_146112_1_, int p_146112_2_, int p_146112_3_) + { + if (this.visible) + { + FontRenderer fontrenderer = p_146112_1_.fontRenderer; + p_146112_1_.getTextureManager().bindTexture(buttonTextures); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.field_146123_n = p_146112_2_ >= this.xPosition && p_146112_3_ >= this.yPosition && p_146112_2_ < this.xPosition + this.width && p_146112_3_ < this.yPosition + this.height; + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + this.mouseDragged(p_146112_1_, p_146112_2_, p_146112_3_); + int l = 14737632; + + if (packedFGColour != 0) + { + l = packedFGColour; + } + else if (!this.enabled) + { + l = 10526880; + } + else if (this.field_146123_n) + { + l = 16777120; + } + + this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l); + } + } +} diff --git a/src/main/java/techreborn/packets/PacketAesu.java b/src/main/java/techreborn/packets/PacketAesu.java new file mode 100644 index 000000000..cb2b4c147 --- /dev/null +++ b/src/main/java/techreborn/packets/PacketAesu.java @@ -0,0 +1,41 @@ +package techreborn.packets; + +import io.netty.buffer.ByteBuf; +import techreborn.tiles.TileAesu; + +import java.io.IOException; + +public class PacketAesu extends SimplePacket { + + + public PacketAesu() { + } + + int buttonID; + + TileAesu aesu; + + public PacketAesu(int buttonID, TileAesu aesu) { + this.aesu = aesu; + this.buttonID = buttonID; + } + + @Override + public void writeData(ByteBuf out) throws IOException { + SimplePacket.writeTileEntity(aesu, out); + out.writeInt(buttonID); + } + + @Override + public void readData(ByteBuf in) throws IOException { + this.aesu = (TileAesu) SimplePacket.readTileEntity(in); + buttonID = in.readInt(); + } + + @Override + public void execute() { + if(!aesu.getWorldObj().isRemote){ + aesu.handleGuiInputFromClient(buttonID); + } + } +} diff --git a/src/main/java/techreborn/packets/PacketHandler.java b/src/main/java/techreborn/packets/PacketHandler.java index 89ea347a7..1fefdde51 100644 --- a/src/main/java/techreborn/packets/PacketHandler.java +++ b/src/main/java/techreborn/packets/PacketHandler.java @@ -21,6 +21,7 @@ public class PacketHandler extends private static EnumMap channels; public PacketHandler() { + addDiscriminator(0, PacketAesu.class); } public static EnumMap getChannels() diff --git a/src/main/java/techreborn/tiles/TileAesu.java b/src/main/java/techreborn/tiles/TileAesu.java index bc2aebd97..01378ec79 100644 --- a/src/main/java/techreborn/tiles/TileAesu.java +++ b/src/main/java/techreborn/tiles/TileAesu.java @@ -1,17 +1,22 @@ package techreborn.tiles; +import codechicken.microblock.FaceEdgeGrid; import ic2.api.tile.IWrenchable; import ic2.core.block.wiring.TileEntityElectricBlock; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import techreborn.init.ModBlocks; import techreborn.util.Inventory; +import techreborn.util.LogHelper; + +import java.lang.reflect.Field; public class TileAesu extends TileEntityElectricBlock implements IWrenchable { public static final int MAX_OUTPUT = 8192; public static final int MAX_STORAGE = 1000000000; //One billion! public Inventory inventory = new Inventory(2, "TileAesu", 64); + public int OUTPUT = 64; //The current output public TileAesu() { @@ -76,4 +81,38 @@ public class TileAesu extends TileEntityElectricBlock implements IWrenchable { return "AESU"; } + public void handleGuiInputFromClient(int id){ + if(id == 0){ + OUTPUT += 256; + } + if(id == 1){ + OUTPUT += 64; + } + if(id == 2){ + OUTPUT -= 64; + } + if(id == 3){ + OUTPUT -= 256; + } + if(OUTPUT > MAX_OUTPUT){ + OUTPUT = MAX_OUTPUT; + } + if(OUTPUT < 0){ + OUTPUT = 0; + } + + //TODO make a better way and not use reflection for this. + try { + Field field = getClass().getSuperclass().getDeclaredField("output"); + field.setAccessible(true); + field.set(this, OUTPUT); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + LogHelper.info("Set output to " + getOutput()); + } + }