From 5b2bc53cfce5b58e8af7ce9484683957ff56778e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 16 Aug 2015 12:03:22 +0100 Subject: [PATCH] Added gui elements to rolling machine. Fixes #95 --- .../container/ContainerRollingMachine.java | 53 +++++++++++++++++++ .../client/gui/GuiRollingMachine.java | 10 ++++ 2 files changed, 63 insertions(+) diff --git a/src/main/java/techreborn/client/container/ContainerRollingMachine.java b/src/main/java/techreborn/client/container/ContainerRollingMachine.java index 84c957a1f..25a0d3646 100644 --- a/src/main/java/techreborn/client/container/ContainerRollingMachine.java +++ b/src/main/java/techreborn/client/container/ContainerRollingMachine.java @@ -1,6 +1,7 @@ package techreborn.client.container; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -62,4 +63,56 @@ public class ContainerRollingMachine extends TechRebornContainer { tile.inventory.setInventorySlotContents(1, output); } + int currentItemBurnTime; + int burnTime; + int energy; + + @Override + public void addCraftingToCrafters(ICrafting crafting) { + super.addCraftingToCrafters(crafting); + crafting.sendProgressBarUpdate(this, 0, tile.runTime); + crafting.sendProgressBarUpdate(this, 1, tile.tickTime); + crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy()); + } + + @Override + public void detectAndSendChanges() { + for (int i = 0; i < this.crafters.size(); i++) { + ICrafting crafting = (ICrafting) this.crafters.get(i); + if (this.currentItemBurnTime != tile.runTime) { + crafting.sendProgressBarUpdate(this, 0, tile.runTime); + } + if (this.burnTime != tile.tickTime) { + crafting.sendProgressBarUpdate(this, 1, tile.tickTime); + } + if (this.energy != (int) tile.getEnergy()) { + crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy()); + } + } + super.detectAndSendChanges(); + } + + @Override + public void updateProgressBar(int id, int value) { + super.updateProgressBar(id, value); + if(id == 0){ + this.currentItemBurnTime = value; + } else if(id ==1){ + this.burnTime = value; + } else if(id == 2){ + this.energy = value; + } + this.tile.runTime = this.currentItemBurnTime; + this.tile.tickTime = this.burnTime; + this.tile.setEnergy(this.energy); + } + + public int getBurnTimeRemainingScaled(int scale) + { + if(burnTime == 0 || this.currentItemBurnTime == 0){ + return 0; + } + return this.burnTime * scale / this.currentItemBurnTime; + } + } diff --git a/src/main/java/techreborn/client/gui/GuiRollingMachine.java b/src/main/java/techreborn/client/gui/GuiRollingMachine.java index 4b41dd78b..537cbac01 100644 --- a/src/main/java/techreborn/client/gui/GuiRollingMachine.java +++ b/src/main/java/techreborn/client/gui/GuiRollingMachine.java @@ -14,12 +14,14 @@ public class GuiRollingMachine extends GuiContainer { private static final ResourceLocation texture = new ResourceLocation( "techreborn", "textures/gui/rolling_machine.png"); TileRollingMachine rollingMachine; + ContainerRollingMachine containerRollingMachine; public GuiRollingMachine(EntityPlayer player, TileRollingMachine tileRollingmachine) { super(new ContainerRollingMachine(tileRollingmachine, player)); this.xSize = 176; this.ySize = 167; rollingMachine = tileRollingmachine; + containerRollingMachine = (ContainerRollingMachine) this.inventorySlots; } @Override @@ -28,6 +30,14 @@ public class GuiRollingMachine extends GuiContainer { int k = (this.width - this.xSize) / 2; int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); + + int j = this.containerRollingMachine.getBurnTimeRemainingScaled(24); + this.drawTexturedModalRect(k + 91, l + 34, 176, 14, j + 1, 19); + + j = this.rollingMachine.getEnergyScaled(12); + if (j > 0) { + this.drawTexturedModalRect(k + 7, l + 33 + 12 - j, 176, 12 - j, 14, j + 2); + } } protected void drawGuiContainerForegroundLayer(int p_146979_1_,