diff --git a/src/main/java/com/hbm/inventory/gui/GUIPWR.java b/src/main/java/com/hbm/inventory/gui/GUIPWR.java index 083cab0c7..b8888ec02 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIPWR.java +++ b/src/main/java/com/hbm/inventory/gui/GUIPWR.java @@ -1,21 +1,29 @@ package com.hbm.inventory.gui; +import org.apache.commons.lang3.math.NumberUtils; +import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import com.hbm.inventory.container.ContainerPWR; import com.hbm.items.ModItems; import com.hbm.lib.RefStrings; +import com.hbm.packet.NBTControlPacket; +import com.hbm.packet.PacketDispatcher; import com.hbm.render.util.GaugeUtil; import com.hbm.render.util.GaugeUtil.Gauge; import com.hbm.tileentity.machine.TileEntityPWRController; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; public class GUIPWR extends GuiInfoContainer { @@ -23,6 +31,8 @@ public class GUIPWR extends GuiInfoContainer { protected TileEntityPWRController controller; private final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/reactors/gui_pwr.png"); + private GuiTextField field; + public GUIPWR(InventoryPlayer inventory, TileEntityPWRController controller) { super(new ContainerPWR(inventory, controller)); this.controller = controller; @@ -30,6 +40,21 @@ public class GUIPWR extends GuiInfoContainer { this.xSize = 176; this.ySize = 188; } + + @Override + public void initGui() { + super.initGui(); + + Keyboard.enableRepeatEvents(true); + + this.field = new GuiTextField(this.fontRendererObj, guiLeft + 57, guiTop + 63, 30, 8); + this.field.setTextColor(0x00ff00); + this.field.setDisabledTextColour(0x008000); + this.field.setEnableBackgroundDrawing(false); + this.field.setMaxStringLength(3); + + this.field.setText((100 - controller.rodTarget) + ""); + } @Override public void drawScreen(int x, int y, float interp) { @@ -37,13 +62,9 @@ public class GUIPWR extends GuiInfoContainer { this.drawCustomInfoStat(x, y, guiLeft + 115, guiTop + 31, 18, 18, x, y, new String[] { "Core: " + String.format("%,d", controller.coreHeat) + " / " + String.format("%,d", controller.coreHeatCapacity) + " TU" }); this.drawCustomInfoStat(x, y, guiLeft + 151, guiTop + 31, 18, 18, x, y, new String[] { "Hull: " + String.format("%,d", controller.hullHeat) + " / " + String.format("%,d", controller.hullHeatCapacity) + " TU" }); - - //TODO: calculate some prediction using extrapolation (or some math sector that ends with -ic) - //int timeLeft = (controller.processTime - controller.progress) / 20; - //this.drawCustomInfoStat(x, y, guiLeft + 52, guiTop + 31, 36, 18, x, y, new String[] { "Cycle: " + (timeLeft / 60) + ":" + String.format("%02d", timeLeft % 60)}); - - this.drawCustomInfoStat(x, y, guiLeft + 52, guiTop + 31, 36, 18, x, y, new String[] { ((int) (controller.progress * 100 / controller.processTime)) + "%" }); + this.drawCustomInfoStat(x, y, guiLeft + 52, guiTop + 31, 36, 18, x, y, new String[] { ((int) (controller.progress * 100 / controller.processTime)) + "%" }); + this.drawCustomInfoStat(x, y, guiLeft + 52, guiTop + 53, 54, 4, x, y, "Control rod level: " + (100 - controller.rodLevel) + "%"); if(controller.typeLoaded != -1 && controller.amountLoaded > 0) { ItemStack display = new ItemStack(ModItems.pwr_fuel, 1, controller.typeLoaded); @@ -88,12 +109,15 @@ public class GUIPWR extends GuiInfoContainer { Minecraft.getMinecraft().getTextureManager().bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); - if(System.currentTimeMillis() % 1000 < 500) + if(controller.hullHeat > controller.hullHeatCapacity * 0.8 || controller.coreHeat > controller.coreHeatCapacity * 0.8) drawTexturedModalRect(guiLeft + 147, guiTop, 176, 14, 26, 26); int p = (int) (controller.progress * 33 / controller.processTime); drawTexturedModalRect(guiLeft + 54, guiTop + 33, 176, 0, p, 14); + int c = (int) (controller.rodLevel * 52 / 100); + drawTexturedModalRect(guiLeft + 53, guiTop + 54, 176, 40, c, 2); + GaugeUtil.renderGauge(Gauge.ROUND_SMALL, guiLeft + 115, guiTop + 31, this.zLevel, (double) controller.coreHeat / (double) controller.coreHeatCapacity); GaugeUtil.renderGauge(Gauge.ROUND_SMALL, guiLeft + 151, guiTop + 31, this.zLevel, (double) controller.hullHeat / (double) controller.hullHeatCapacity); @@ -103,8 +127,38 @@ public class GUIPWR extends GuiInfoContainer { RenderHelper.enableGUIStandardItemLighting(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); } + + GL11.glDisable(GL11.GL_LIGHTING); controller.tanks[0].renderTank(guiLeft + 8, guiTop + 57, this.zLevel, 16, 52); controller.tanks[1].renderTank(guiLeft + 26, guiTop + 57, this.zLevel, 16, 52); + + this.field.drawTextBox(); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int i) { + super.mouseClicked(mouseX, mouseY, i); + this.field.mouseClicked(mouseX, mouseY, i); + + if(guiLeft + 88 <= mouseX && guiLeft + 88 + 18 > mouseX && guiTop + 58 < mouseY && guiTop + 58 + 18 >= mouseY) { + + if(NumberUtils.isNumber(field.getText())) { + int level = (int)MathHelper.clamp_double(Double.parseDouble(field.getText()), 0, 100); + field.setText(level + ""); + + NBTTagCompound control = new NBTTagCompound(); + control.setInteger("control", 100 - level); + PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(control, controller.xCoord, controller.yCoord, controller.zCoord)); + mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1F)); + + } + } + } + + @Override + protected void keyTyped(char c, int i) { + if(this.field.textboxKeyTyped(c, i)) return; + super.keyTyped(c, i); } } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplant.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplant.java index 379a95c1b..3da9f3833 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplant.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplant.java @@ -304,6 +304,8 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements this.maxProgress = recipe.getDuration() * this.speed / 100; + if(maxProgress <= 0) maxProgress = 1; + if(this.progress >= this.maxProgress) { consumeFluids(recipe); produceFluids(recipe); diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplantBase.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplantBase.java index d91102d51..99e38f3e4 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplantBase.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineChemplantBase.java @@ -150,6 +150,8 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa this.maxProgress[index] = recipe.getDuration() * this.speed / 100; + if(maxProgress[index] <= 0) maxProgress[index] = 1; + if(this.progress[index] >= this.maxProgress[index]) { consumeFluids(recipe, index); produceFluids(recipe, index); diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityPWRController.java b/src/main/java/com/hbm/tileentity/machine/TileEntityPWRController.java index 5aa739e75..ec3a6488a 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityPWRController.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityPWRController.java @@ -16,6 +16,8 @@ import com.hbm.inventory.fluid.trait.FT_Heatable.HeatingType; import com.hbm.inventory.gui.GUIPWR; import com.hbm.items.ModItems; import com.hbm.items.machine.ItemPWRFuel.EnumPWRFuel; +import com.hbm.main.MainRegistry; +import com.hbm.sound.AudioWrapper; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.util.EnumUtil; @@ -41,8 +43,8 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG public static final int hullHeatCapacity = 10_000_000; public double flux; - public int rodLevel; - public int rodTarget; + public int rodLevel = 100; + public int rodTarget = 100; public int typeLoaded; public int amountLoaded; @@ -58,6 +60,8 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG public boolean assembled; + private AudioWrapper audio; + protected List ports = new ArrayList(); public TileEntityPWRController() { @@ -228,7 +232,54 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG data.setDouble("progress", progress); data.setInteger("typeLoaded", typeLoaded); data.setInteger("amountLoaded", amountLoaded); + data.setInteger("rodLevel", rodLevel); + data.setInteger("rodTarget", rodTarget); this.networkPack(data, 150); + } else { + + if(amountLoaded > 0) { + + if(audio == null) { + audio = createAudioLoop(); + audio.startSound(); + } else if(!audio.isPlaying()) { + audio = rebootAudio(audio); + } + + audio.keepAlive(); + + } else { + + if(audio != null) { + audio.stopSound(); + audio = null; + } + } + } + } + + @Override + public AudioWrapper createAudioLoop() { + return MainRegistry.proxy.getLoopedSound("hbm:block.reactorLoop", xCoord, yCoord, zCoord, 1F, 10F, 1.0F, 20); + } + + @Override + public void onChunkUnload() { + + if(audio != null) { + audio.stopSound(); + audio = null; + } + } + + @Override + public void invalidate() { + + super.invalidate(); + + if(audio != null) { + audio.stopSound(); + audio = null; } } @@ -263,6 +314,8 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG progress = nbt.getDouble("progress"); typeLoaded = nbt.getInteger("typeLoaded"); amountLoaded = nbt.getInteger("amountLoaded"); + rodLevel = nbt.getInteger("rodLevel"); + rodTarget = nbt.getInteger("rodTarget"); } protected void setupTanks() { @@ -295,6 +348,9 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); + + tanks[0].readFromNBT(nbt, "t0"); + tanks[1].readFromNBT(nbt, "t1"); this.assembled = nbt.getBoolean("assembled"); this.coreHeat = nbt.getInteger("coreHeat"); @@ -325,6 +381,9 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); + + tanks[0].writeToNBT(nbt, "t0"); + tanks[1].writeToNBT(nbt, "t1"); nbt.setBoolean("assembled", assembled); nbt.setInteger("coreHeat", coreHeat); @@ -361,6 +420,7 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG if(data.hasKey("control")) { this.rodTarget = MathHelper.clamp_int(data.getInteger("control"), 0, 100); + this.markChanged(); } } diff --git a/src/main/resources/assets/hbm/sounds.json b/src/main/resources/assets/hbm/sounds.json index 90efc5334..d2c6248c7 100644 --- a/src/main/resources/assets/hbm/sounds.json +++ b/src/main/resources/assets/hbm/sounds.json @@ -58,6 +58,7 @@ "block.hornNearDual": {"category": "block", "sounds": [{"name": "block/hornNearDual", "stream": false}]}, "block.hornFarSingle": {"category": "block", "sounds": [{"name": "block/hornFarSingle", "stream": false}]}, "block.hornFarDual": {"category": "block", "sounds": [{"name": "block/hornFarDual", "stream": false}]}, + "block.reactorLoop": {"category": "block", "sounds": [{"name": "block/reactorLoop", "stream": false}]}, "door.TransitionSealOpen": {"category": "block", "sounds": [{"name": "block/door/transition_seal_open", "stream": true}]}, "door.wghStart": {"category": "block", "sounds": [{"name": "block/door/wgh_start", "stream": true}]}, diff --git a/src/main/resources/assets/hbm/sounds/block/reactorLoop.ogg b/src/main/resources/assets/hbm/sounds/block/reactorLoop.ogg new file mode 100644 index 000000000..428ddeabb Binary files /dev/null and b/src/main/resources/assets/hbm/sounds/block/reactorLoop.ogg differ