Added basic aesu controls, just need to finish the gui :)
This commit is contained in:
parent
92b95b9ff0
commit
9b1093c22c
5 changed files with 154 additions and 0 deletions
|
@ -1,10 +1,14 @@
|
||||||
package techreborn.client.gui;
|
package techreborn.client.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
import techreborn.client.container.ContainerAesu;
|
import techreborn.client.container.ContainerAesu;
|
||||||
|
import techreborn.client.gui.componets.GuiHiddenButton;
|
||||||
|
import techreborn.packets.PacketAesu;
|
||||||
|
import techreborn.packets.PacketHandler;
|
||||||
import techreborn.tiles.TileAesu;
|
import techreborn.tiles.TileAesu;
|
||||||
|
|
||||||
public class GuiAesu extends GuiContainer {
|
public class GuiAesu extends GuiContainer {
|
||||||
|
@ -23,6 +27,18 @@ public class GuiAesu extends GuiContainer {
|
||||||
aesu = tileaesu;
|
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
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
|
protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
|
||||||
int p_146976_2_, int p_146976_3_)
|
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);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
src/main/java/techreborn/packets/PacketAesu.java
Normal file
41
src/main/java/techreborn/packets/PacketAesu.java
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ public class PacketHandler extends
|
||||||
private static EnumMap<Side, FMLEmbeddedChannel> channels;
|
private static EnumMap<Side, FMLEmbeddedChannel> channels;
|
||||||
|
|
||||||
public PacketHandler() {
|
public PacketHandler() {
|
||||||
|
addDiscriminator(0, PacketAesu.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnumMap<Side, FMLEmbeddedChannel> getChannels()
|
public static EnumMap<Side, FMLEmbeddedChannel> getChannels()
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
package techreborn.tiles;
|
package techreborn.tiles;
|
||||||
|
|
||||||
|
import codechicken.microblock.FaceEdgeGrid;
|
||||||
import ic2.api.tile.IWrenchable;
|
import ic2.api.tile.IWrenchable;
|
||||||
import ic2.core.block.wiring.TileEntityElectricBlock;
|
import ic2.core.block.wiring.TileEntityElectricBlock;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.util.Inventory;
|
import techreborn.util.Inventory;
|
||||||
|
import techreborn.util.LogHelper;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
|
public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
|
||||||
|
|
||||||
public static final int MAX_OUTPUT = 8192;
|
public static final int MAX_OUTPUT = 8192;
|
||||||
public static final int MAX_STORAGE = 1000000000; //One billion!
|
public static final int MAX_STORAGE = 1000000000; //One billion!
|
||||||
public Inventory inventory = new Inventory(2, "TileAesu", 64);
|
public Inventory inventory = new Inventory(2, "TileAesu", 64);
|
||||||
|
public int OUTPUT = 64; //The current output
|
||||||
|
|
||||||
public TileAesu()
|
public TileAesu()
|
||||||
{
|
{
|
||||||
|
@ -76,4 +81,38 @@ public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
|
||||||
return "AESU";
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue