Package mods.railcraft.common.gui.containers

Source Code of mods.railcraft.common.gui.containers.ContainerEngineSteam

/*
* 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 mods.railcraft.common.blocks.RailcraftTileEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import mods.railcraft.common.blocks.machine.beta.TileEngineSteam;
import mods.railcraft.common.gui.widgets.IndicatorWidget;
import mods.railcraft.common.gui.widgets.FluidGaugeWidget;

public class ContainerEngineSteam extends RailcraftContainer {

    private TileEngineSteam tile;
    private double lastEnergy;
    private float lastOutput;

    public ContainerEngineSteam(InventoryPlayer inventoryplayer, TileEngineSteam tile) {
        this.tile = tile;

        addWidget(new FluidGaugeWidget(tile.getTankManager().get(0), 71, 23, 176, 0, 16, 47));

        addWidget(new IndicatorWidget(tile.getEnergyIndicator(), 94, 25, 176, 47, 6, 43));

        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);

        icrafting.sendProgressBarUpdate(this, 12, (int) Math.round(tile.energy));
        icrafting.sendProgressBarUpdate(this, 13, Math.round(tile.currentOutput * 100));
    }

    @Override
    public void detectAndSendChanges() {
        super.detectAndSendChanges();
        tile.getTankManager().updateGuiData(this, crafters, 0);

        for (int var1 = 0; var1 < this.crafters.size(); ++var1) {
            ICrafting var2 = (ICrafting) this.crafters.get(var1);

            if (this.lastEnergy != tile.energy)
                var2.sendProgressBarUpdate(this, 12, (int) Math.round(tile.energy));

            if (this.lastOutput != tile.currentOutput)
                var2.sendProgressBarUpdate(this, 13, Math.round(tile.currentOutput * 100));
        }

        this.lastEnergy = tile.energy;
        this.lastOutput = tile.currentOutput;
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int id, int value) {
        tile.getTankManager().processGuiUpdate(id, value);

        switch (id) {
            case 12:
                tile.energy = value;
                break;
            case 13:
                tile.currentOutput = value / 100f;
                break;
        }
    }

    @Override
    public boolean canInteractWith(EntityPlayer entityplayer) {
        return RailcraftTileEntity.isUseableByPlayerHelper(tile, entityplayer);
    }
}
TOP

Related Classes of mods.railcraft.common.gui.containers.ContainerEngineSteam

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.