aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/thaumcraft/gui/ContainerFastAlchemyFurnace.java
blob: 9689a3fa38757f0625c319aba4d9c9d4bbbc6e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package gtPlusPlus.xmod.thaumcraft.gui;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

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.item.ItemStack;

import gtPlusPlus.xmod.thaumcraft.common.tile.TileFastAlchemyFurnace;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.container.SlotLimitedHasAspects;
import thaumcraft.common.lib.crafting.ThaumcraftCraftingManager;

public class ContainerFastAlchemyFurnace extends Container {
	private final TileFastAlchemyFurnace furnace;
	private int lastCookTime;
	private int lastBurnTime;
	private int lastItemBurnTime;
	private int lastVis;
	private int lastSmelt;

	public ContainerFastAlchemyFurnace(final InventoryPlayer par1InventoryPlayer, final TileFastAlchemyFurnace tileEntity) {
		this.furnace = tileEntity;
		this.addSlotToContainer(new SlotLimitedHasAspects(tileEntity, 0, 80, 8));
		this.addSlotToContainer(new Slot(tileEntity, 1, 80, 48));
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 9; ++j) {
				this.addSlotToContainer(
						new Slot(par1InventoryPlayer, j + (i * 9) + 9, 8 + (j * 18), 84 + (i * 18)));
			}
		}
		for (int i = 0; i < 9; ++i) {
			this.addSlotToContainer(new Slot(par1InventoryPlayer, i, 8 + (i * 18), 142));
		}
	}

	@Override
	public void addCraftingToCrafters(final ICrafting par1ICrafting) {
		super.addCraftingToCrafters(par1ICrafting);
		par1ICrafting.sendProgressBarUpdate(this, 0, this.furnace.furnaceCookTime);
		par1ICrafting.sendProgressBarUpdate(this, 1, this.furnace.furnaceBurnTime);
		par1ICrafting.sendProgressBarUpdate(this, 2, this.furnace.currentItemBurnTime);
		par1ICrafting.sendProgressBarUpdate(this, 3, this.furnace.vis);
		par1ICrafting.sendProgressBarUpdate(this, 4, this.furnace.smeltTime);
	}

	@Override
	public void detectAndSendChanges() {
		super.detectAndSendChanges();
		for (int i = 0; i < this.crafters.size(); ++i) {
			final ICrafting icrafting = (ICrafting) this.crafters.get(i);
			if (this.lastCookTime != this.furnace.furnaceCookTime) {
				icrafting.sendProgressBarUpdate(this, 0, this.furnace.furnaceCookTime);
			}
			if (this.lastBurnTime != this.furnace.furnaceBurnTime) {
				icrafting.sendProgressBarUpdate(this, 1, this.furnace.furnaceBurnTime);
			}
			if (this.lastItemBurnTime != this.furnace.currentItemBurnTime) {
				icrafting.sendProgressBarUpdate(this, 2, this.furnace.currentItemBurnTime);
			}
			if (this.lastVis != this.furnace.vis) {
				icrafting.sendProgressBarUpdate(this, 3, this.furnace.vis);
			}
			if (this.lastSmelt != this.furnace.smeltTime) {
				icrafting.sendProgressBarUpdate(this, 4, this.furnace.smeltTime);
			}
		}
		this.lastCookTime = this.furnace.furnaceCookTime;
		this.lastBurnTime = this.furnace.furnaceBurnTime;
		this.lastItemBurnTime = this.furnace.currentItemBurnTime;
		this.lastVis = this.furnace.vis;
		this.lastSmelt = this.furnace.smeltTime;
	}

	@Override
	@SideOnly(Side.CLIENT)
	public void updateProgressBar(final int par1, final int par2) {
		if (par1 == 0) {
			this.furnace.furnaceCookTime = par2;
		}
		if (par1 == 1) {
			this.furnace.furnaceBurnTime = par2;
		}
		if (par1 == 2) {
			this.furnace.currentItemBurnTime = par2;
		}
		if (par1 == 3) {
			this.furnace.vis = par2;
		}
		if (par1 == 4) {
			this.furnace.smeltTime = par2;
		}
	}

	@Override
	public boolean canInteractWith(final EntityPlayer par1EntityPlayer) {
		return this.furnace.isUseableByPlayer(par1EntityPlayer);
	}

	@Override
	public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) {
		ItemStack itemstack = null;
		final Slot slot = (Slot) this.inventorySlots.get(par2);
		if ((slot != null) && slot.getHasStack()) {
			final ItemStack itemstack2 = slot.getStack();
			itemstack = itemstack2.copy();
			if ((par2 != 1) && (par2 != 0)) {
				AspectList al = ThaumcraftCraftingManager.getObjectTags(itemstack2);
				al = ThaumcraftCraftingManager.getBonusTags(itemstack2, al);
				if (TileFastAlchemyFurnace.isItemFuel(itemstack2)) {
					if (!this.mergeItemStack(itemstack2, 1, 2, false)
							&& !this.mergeItemStack(itemstack2, 0, 1, false)) {
						return null;
					}
				} else if ((al != null) && (al.size() > 0)) {
					if (!this.mergeItemStack(itemstack2, 0, 1, false)) {
						return null;
					}
				} else if ((par2 >= 2) && (par2 < 29)) {
					if (!this.mergeItemStack(itemstack2, 29, 38, false)) {
						return null;
					}
				} else if ((par2 >= 29) && (par2 < 38) && !this.mergeItemStack(itemstack2, 2, 29, false)) {
					return null;
				}
			} else if (!this.mergeItemStack(itemstack2, 2, 38, false)) {
				return null;
			}
			if (itemstack2.stackSize == 0) {
				slot.putStack((ItemStack) null);
			} else {
				slot.onSlotChanged();
			}
			if (itemstack2.stackSize == itemstack.stackSize) {
				return null;
			}
			slot.onPickupFromSlot(par1EntityPlayer, itemstack2);
		}
		return itemstack;
	}
}