Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mokonaDesu.undercraft.tileentities;
- import java.util.List;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.ICrafting;
- import net.minecraft.inventory.Slot;
- import net.minecraft.inventory.SlotFurnace;
- import net.minecraft.item.ItemStack;
- public class ContainerAlloyFurnace extends Container
- {
- private TileEntityAlloyFurnace furnace;
- private int lastFuelLevel[] = {0, 0, 0, 0};
- private int lastMaxFuelLevel[] = {0, 0, 0, 0};
- private int[] lastItemHeat = {0, 0, 0};
- private int[] lastItemHeatRequired = {0, 0, 0};
- private int lastTemperature = 0;
- public ContainerAlloyFurnace(InventoryPlayer par1InventoryPlayer, TileEntityAlloyFurnace par2TileEntityFurnace)
- {
- furnace = par2TileEntityFurnace;
- //fuel
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 0, 53, 73));
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 1, 72, 73));
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 2, 92, 73));
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 3, 111, 73));
- //smelting
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 4, 43, 32));
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 5, 82, -7));
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 6, 121, 32));
- //molds
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 7, 149, -10));
- //result
- this.addSlotToContainer(new Slot(par2TileEntityFurnace, 8, 82, 32));
- for (int i = 0; i < 3; i++)
- {
- for (int k = 0; k < 9; k++)
- {
- this.addSlotToContainer(new Slot(par1InventoryPlayer, k + i * 9 + 9, 8 + k * 18, 105 + (i * 18)));
- }
- }
- for (int j = 0; j < 9; j++)
- {
- this.addSlotToContainer(new Slot(par1InventoryPlayer, j, 8 + j * 18, 163));
- }
- }
- @Override
- public boolean canInteractWith(EntityPlayer par1EntityPlayer)
- {
- return furnace.isUseableByPlayer(par1EntityPlayer);
- }
- public void addCraftingToCrafters(ICrafting par1ICrafting)
- {
- super.addCraftingToCrafters(par1ICrafting);
- for (int i = 0; i < 4; i++)
- par1ICrafting.sendProgressBarUpdate(this, i, this.furnace.fuelLevel[i]);
- for (int i = 0; i < 4; i++)
- par1ICrafting.sendProgressBarUpdate(this, i + 4, this.furnace.maxFuelLevel[i]);
- for (int i = 0; i < 3; i++)
- par1ICrafting.sendProgressBarUpdate(this, i + 8, this.furnace.itemHeat[i]);
- for (int i = 0; i < 3; i++)
- par1ICrafting.sendProgressBarUpdate(this, i + 11, this.furnace.itemHeatRequired[i]);
- par1ICrafting.sendProgressBarUpdate(this, 14, this.furnace.temperature);
- }
- public void detectAndSendChanges()
- {
- super.detectAndSendChanges();
- for (int i = 0; i < this.crafters.size(); i++)
- {
- ICrafting crafting = (ICrafting)this.crafters.get(i);
- for (int j = 0; j < 4; j++)
- if (this.lastFuelLevel[j] != this.furnace.fuelLevel[j])
- {
- crafting.sendProgressBarUpdate(this, j, this.furnace.fuelLevel[j]);
- this.lastFuelLevel[j] = this.furnace.fuelLevel[j];
- }
- for (int j = 0; j < 4; j++)
- if (this.lastMaxFuelLevel[j] != this.furnace.maxFuelLevel[j])
- {
- crafting.sendProgressBarUpdate(this, j + 4, this.furnace.maxFuelLevel[j]);
- this.lastMaxFuelLevel[j] = this.furnace.maxFuelLevel[j];
- }
- for (int j = 0; j < 3; j++)
- if (this.lastItemHeat[j] != this.furnace.itemHeat[j])
- {
- crafting.sendProgressBarUpdate(this, j + 8, this.furnace.itemHeat[j]);
- this.lastItemHeat[j] = this.furnace.itemHeat[j];
- }
- for (int j = 0; j < 3; j++)
- if (this.lastItemHeatRequired[j] != this.furnace.itemHeatRequired[j])
- {
- crafting.sendProgressBarUpdate(this, j + 11, this.furnace.itemHeatRequired[j]);
- this.lastItemHeatRequired[j] = this.furnace.itemHeatRequired[j];
- }
- if (this.lastTemperature != this.furnace.temperature)
- {
- crafting.sendProgressBarUpdate(this, 14, this.furnace.temperature);
- this.lastTemperature = this.furnace.temperature;
- }
- }
- }
- @SideOnly(Side.CLIENT)
- public void updateProgressBar(int index, int value)
- {
- if (index >= 0 && index <= 3) { //fuelLevel update
- this.furnace.fuelLevel[index] = value;
- return;
- }
- if (index >= 4 && index <= 7) { //maxFuelLevel update
- this.furnace.maxFuelLevel[index - 4] = value;
- return;
- }
- if (index >= 8 && index <= 10) { //itemHeat update
- this.furnace.itemHeat[index - 8] = value;
- return;
- }
- if (index >= 11 && index <= 13) { //itemHeatRequired update
- this.furnace.itemHeatRequired[index - 11] = value;
- return;
- }
- if (index == 14) this.furnace.temperature = value;
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
- ItemStack stack = null;
- Slot slotObject = (Slot) inventorySlots.get(slot);
- //null checks and checks if the item can be stacked (maxStackSize > 1)
- if (slotObject != null && slotObject.getHasStack()) {
- ItemStack stackInSlot = slotObject.getStack();
- stack = stackInSlot.copy();
- //merges the item into player inventory since its in the tileEntity
- if (slot < 9) {
- if (!this.mergeItemStack(stackInSlot, 9, 45, true)) {
- return null;
- }
- }
- //places it into the tileEntity is possible since its in the player inventory
- else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
- return null;
- }
- if (stackInSlot.stackSize == 0) {
- slotObject.putStack(null);
- } else {
- slotObject.onSlotChanged();
- }
- if (stackInSlot.stackSize == stack.stackSize) {
- return null;
- }
- slotObject.onPickupFromSlot(player, stackInSlot);
- }
- return stack;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement