/*
* Copyright (c) CovertJaguar, 2014 http://railcraft.info
*
* This code is the property of CovertJaguar
* and may only be used with explicit written
* permission unless otherwise specified on the
* license page at http://railcraft.info/wiki/info:license.
*/
package mods.railcraft.common.gui.containers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import mods.railcraft.common.blocks.machine.beta.TileEngineSteamHobby;
import mods.railcraft.common.gui.widgets.IndicatorWidget;
import mods.railcraft.common.gui.slots.SlotFuel;
import mods.railcraft.common.gui.slots.SlotOutput;
import mods.railcraft.common.gui.slots.SlotWater;
import mods.railcraft.common.gui.widgets.FluidGaugeWidget;
public class ContainerEngineSteamHobby extends RailcraftContainer {
private TileEngineSteamHobby tile;
private double lastBurnTime;
private double lastItemBurnTime;
private double lastEnergy;
private float lastOutput;
private double lastHeat;
public ContainerEngineSteamHobby(InventoryPlayer inventoryplayer, TileEngineSteamHobby tile) {
super(tile);
this.tile = tile;
addWidget(new FluidGaugeWidget(tile.getTankManager().get(0), 17, 23, 176, 0, 16, 47));
addWidget(new FluidGaugeWidget(tile.getTankManager().get(1), 107, 23, 176, 0, 16, 47));
addWidget(new IndicatorWidget(tile.boiler.heatIndicator, 40, 25, 176, 61, 6, 43));
addWidget(new IndicatorWidget(tile.getEnergyIndicator(), 94, 25, 182, 61, 6, 43));
addSlot(new SlotFuel(tile, 0, 62, 39));
addSlot(new SlotWater(tile, 1, 143, 21));
addSlot(new SlotOutput(tile, 2, 143, 56));
for (int i = 0; i < 3; i++) {
for (int k = 0; k < 9; k++) {
addSlot(new Slot(inventoryplayer, k + i * 9 + 9, 8 + k * 18, 84 + i * 18));
}
}
for (int j = 0; j < 9; j++) {
addSlot(new Slot(inventoryplayer, j, 8 + j * 18, 142));
}
}
@Override
public void addCraftingToCrafters(ICrafting icrafting) {
super.addCraftingToCrafters(icrafting);
tile.getTankManager().initGuiData(this, icrafting, 0);
tile.getTankManager().initGuiData(this, icrafting, 1);
icrafting.sendProgressBarUpdate(this, 10, (int) Math.round(tile.boiler.burnTime));
icrafting.sendProgressBarUpdate(this, 11, (int) Math.round(tile.boiler.currentItemBurnTime));
icrafting.sendProgressBarUpdate(this, 12, (int) Math.round(tile.energy));
icrafting.sendProgressBarUpdate(this, 13, (int) Math.round(tile.currentOutput * 100));
icrafting.sendProgressBarUpdate(this, 14, (int) Math.round(tile.boiler.getHeat()));
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
tile.getTankManager().updateGuiData(this, crafters, 0);
tile.getTankManager().updateGuiData(this, crafters, 1);
for (int var1 = 0; var1 < this.crafters.size(); ++var1) {
ICrafting var2 = (ICrafting) this.crafters.get(var1);
if (this.lastBurnTime != tile.boiler.burnTime)
var2.sendProgressBarUpdate(this, 10, (int) Math.round(tile.boiler.burnTime));
if (this.lastItemBurnTime != tile.boiler.currentItemBurnTime)
var2.sendProgressBarUpdate(this, 11, (int) Math.round(tile.boiler.currentItemBurnTime));
if (this.lastEnergy != tile.energy)
var2.sendProgressBarUpdate(this, 12, (int) Math.round(tile.energy));
if (this.lastOutput != tile.currentOutput)
var2.sendProgressBarUpdate(this, 13, (int) Math.round(tile.currentOutput * 100));
if (this.lastHeat != tile.boiler.getHeat())
var2.sendProgressBarUpdate(this, 14, (int) Math.round(tile.boiler.getHeat()));
}
this.lastBurnTime = tile.boiler.burnTime;
this.lastItemBurnTime = tile.boiler.currentItemBurnTime;
this.lastEnergy = tile.energy;
this.lastOutput = tile.currentOutput;
this.lastHeat = tile.boiler.getHeat();
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int value) {
tile.getTankManager().processGuiUpdate(id, value);
switch (id) {
case 10:
tile.boiler.burnTime = value;
break;
case 11:
tile.boiler.currentItemBurnTime = value;
break;
case 12:
tile.energy = value;
break;
case 13:
tile.currentOutput = value / 100f;
break;
case 14:
tile.boiler.setHeat(value);
break;
}
}
}