From 7d521ea841fc9c29971d44740090486b2212ead1 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Sun, 29 Mar 2015 15:23:13 -0400 Subject: [PATCH] Logic adapter work --- .../client/gui/GuiReactorLogicAdapter.java | 99 +++++++++++++++++++ .../generators/common/block/BlockReactor.java | 12 ++- .../TileEntityReactorLogicAdapter.java | 21 ++-- .../resources/assets/mekanism/lang/en_US.lang | 3 + 4 files changed, 127 insertions(+), 8 deletions(-) diff --git a/src/main/java/mekanism/generators/client/gui/GuiReactorLogicAdapter.java b/src/main/java/mekanism/generators/client/gui/GuiReactorLogicAdapter.java index f47801e56..bcacb1bb3 100644 --- a/src/main/java/mekanism/generators/client/gui/GuiReactorLogicAdapter.java +++ b/src/main/java/mekanism/generators/client/gui/GuiReactorLogicAdapter.java @@ -1,10 +1,20 @@ package mekanism.generators.client.gui; +import java.util.ArrayList; + +import mekanism.api.Coord4D; +import mekanism.api.EnumColor; import mekanism.client.gui.GuiMekanism; +import mekanism.client.render.MekanismRenderer; +import mekanism.client.sound.SoundHandler; +import mekanism.common.Mekanism; import mekanism.common.inventory.container.ContainerNull; +import mekanism.common.network.PacketTileEntity.TileEntityMessage; +import mekanism.common.util.LangUtils; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter; +import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter.ReactorLogic; import net.minecraft.entity.player.InventoryPlayer; import org.lwjgl.opengl.GL11; @@ -27,7 +37,33 @@ public class GuiReactorLogicAdapter extends GuiMekanism @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + int xAxis = (mouseX - (width - xSize) / 2); + int yAxis = (mouseY - (height - ySize) / 2); + fontRendererObj.drawString(tileEntity.getInventoryName(), 46, 6, 0x404040); + fontRendererObj.drawString(MekanismUtils.localize("gui.coolingMeasurements") + ": " + LangUtils.transOnOff(tileEntity.activeCooled), 36, 20, 0x404040); + fontRendererObj.drawString(MekanismUtils.localize("gui.redstoneOutputMode") + ": " + EnumColor.RED + tileEntity.logicType.getLocalizedName(), 23, 123, 0x404040); + + for(ReactorLogic type : ReactorLogic.values()) + { + GL11.glPushMatrix(); + GL11.glEnable(GL11.GL_LIGHTING); + itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), type.getRenderStack(), 27, 35 + (22*type.ordinal())); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glPopMatrix(); + + fontRendererObj.drawString(type.getLocalizedName(), 46, 34+(22*type.ordinal()), 0x404040); + + if(xAxis >= 24 && xAxis <= 152 && yAxis >= 32+(22*type.ordinal()) && yAxis <= 32+22+(22*type.ordinal())) + { + drawCreativeTabHoveringText(type.getDescription(), xAxis, yAxis); + } + } + + if(xAxis >= 23 && xAxis <= 34 && yAxis >= 19 && yAxis <= 30) + { + drawCreativeTabHoveringText(MekanismUtils.localize("gui.toggleCooling"), xAxis, yAxis); + } super.drawGuiContainerForegroundLayer(mouseX, mouseY); } @@ -40,7 +76,70 @@ public class GuiReactorLogicAdapter extends GuiMekanism int guiWidth = (width - xSize) / 2; int guiHeight = (height - ySize) / 2; drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize); + + int xAxis = (mouseX - (width - xSize) / 2); + int yAxis = (mouseY - (height - ySize) / 2); + + for(ReactorLogic type : ReactorLogic.values()) + { + MekanismRenderer.color(EnumColor.RED); + + drawTexturedModalRect(24, 32+(22*type.ordinal()), 0, 166+(type == tileEntity.logicType ? 22 : 0), 128, 22); + + MekanismRenderer.resetColor(); + } + + if(xAxis >= 23 && xAxis <= 34 && yAxis >= 19 && yAxis <= 30) + { + drawTexturedModalRect(guiWidth + 23, guiHeight + 19, 176, 0, 12, 12); + } + else { + drawTexturedModalRect(guiWidth + 23, guiHeight + 19, 176, 12, 12, 12); + } super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int button) + { + super.mouseClicked(mouseX, mouseY, button); + + if(button == 0) + { + int xAxis = (mouseX - (width - xSize) / 2); + int yAxis = (mouseY - (height - ySize) / 2); + + if(xAxis >= 23 && xAxis <= 34 && yAxis >= 19 && yAxis <= 30) + { + SoundHandler.playSound("gui.button.press"); + + ArrayList data = new ArrayList(); + data.add(0); + + Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data)); + + return; + } + + for(ReactorLogic type : ReactorLogic.values()) + { + if(xAxis >= 24 && xAxis <= 152 && yAxis >= 32+(22*type.ordinal()) && yAxis <= 32+22+(22*type.ordinal())) + { + if(type != tileEntity.logicType) + { + SoundHandler.playSound("gui.button.press"); + + ArrayList data = new ArrayList(); + data.add(1); + data.add(type.ordinal()); + + Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data)); + + return; + } + } + } + } + } } diff --git a/src/main/java/mekanism/generators/common/block/BlockReactor.java b/src/main/java/mekanism/generators/common/block/BlockReactor.java index e3ad9d210..5bf8e19c2 100644 --- a/src/main/java/mekanism/generators/common/block/BlockReactor.java +++ b/src/main/java/mekanism/generators/common/block/BlockReactor.java @@ -213,9 +213,17 @@ public class BlockReactor extends BlockContainer implements IBlockCTM if(!entityplayer.isSneaking()) { entityplayer.openGui(MekanismGenerators.instance, ReactorBlockType.get(this, metadata).guiId, world, x, y, z); + return true; + } + } + + if(tileEntity instanceof TileEntityReactorLogicAdapter) + { + if(!entityplayer.isSneaking()) + { + entityplayer.openGui(MekanismGenerators.instance, ReactorBlockType.get(this, metadata).guiId, world, x, y, z); + return true; } - - return true; } return false; diff --git a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java index 72ccbd701..8ed07f290 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java @@ -6,6 +6,8 @@ import java.util.ArrayList; import java.util.List; import mekanism.common.util.MekanismUtils; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import cpw.mods.fml.common.Optional.Method; import dan200.computercraft.api.lua.ILuaContext; @@ -15,7 +17,7 @@ import dan200.computercraft.api.peripheral.IPeripheral; public class TileEntityReactorLogicAdapter extends TileEntityReactorBlock implements IPeripheral { - public ReactorLogic logicType; + public ReactorLogic logicType = ReactorLogic.DISABLED; public boolean activeCooled; @@ -164,16 +166,23 @@ public class TileEntityReactorLogicAdapter extends TileEntityReactorBlock implem public static enum ReactorLogic { - DISABLED("disabled"), - READY("ready"), - CAPACITY("capacity"), - DEPLETED("depleted"); + DISABLED("disabled", new ItemStack(Items.gunpowder)), + READY("ready", new ItemStack(Items.redstone)), + CAPACITY("capacity", new ItemStack(Items.redstone)), + DEPLETED("depleted", new ItemStack(Items.redstone)); private String name; + private ItemStack renderStack; - private ReactorLogic(String s) + private ReactorLogic(String s, ItemStack stack) { name = s; + renderStack = stack; + } + + public ItemStack getRenderStack() + { + return renderStack; } public String getLocalizedName() diff --git a/src/main/resources/assets/mekanism/lang/en_US.lang b/src/main/resources/assets/mekanism/lang/en_US.lang index d7862c10c..703c4c413 100644 --- a/src/main/resources/assets/mekanism/lang/en_US.lang +++ b/src/main/resources/assets/mekanism/lang/en_US.lang @@ -465,6 +465,9 @@ gui.abundancy=Abundancy gui.nextItem=Next Item gui.lastItem=Last Item gui.oreDictCompat=Compatible OreDict Key +gui.toggleCooling=Toggle Cooling Measurements +gui.coolingMeasurements=Active cooling measurements +gui.redstoneOutputMode=Redstone output mode gui.reactor.injectionRate=Injection Rate