/
FurnaceContainer.java
183 lines (159 loc) · 5.72 KB
/
FurnaceContainer.java
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package mods.natura.gui;
import mods.natura.blocks.tech.NetherrackFurnaceLogic;
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;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class FurnaceContainer extends Container
{
private NetherrackFurnaceLogic furnace;
private int lastCookTime;
private int lastBurnTime;
private int lastItemBurnTime;
public FurnaceContainer(InventoryPlayer par1InventoryPlayer, NetherrackFurnaceLogic par2TileEntityFurnace)
{
this.furnace = par2TileEntityFurnace;
this.addSlotToContainer(new Slot(par2TileEntityFurnace, 0, 56, 17));
this.addSlotToContainer(new Slot(par2TileEntityFurnace, 1, 56, 53));
this.addSlotToContainer(new SlotFurnace(par1InventoryPlayer.player, par2TileEntityFurnace, 2, 116, 35));
int i;
for (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 (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, i, 8 + i * 18, 142));
}
}
public void addCraftingToCrafters (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);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges ()
{
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i)
{
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);
}
}
this.lastCookTime = this.furnace.furnaceCookTime;
this.lastBurnTime = this.furnace.furnaceBurnTime;
this.lastItemBurnTime = this.furnace.currentItemBurnTime;
}
@SideOnly(Side.CLIENT)
public void updateProgressBar (int par1, int par2)
{
if (par1 == 0)
{
this.furnace.furnaceCookTime = par2;
}
if (par1 == 1)
{
this.furnace.furnaceBurnTime = par2;
}
if (par1 == 2)
{
this.furnace.currentItemBurnTime = par2;
}
}
public boolean canInteractWith (EntityPlayer par1EntityPlayer)
{
return this.furnace.isUseableByPlayer(par1EntityPlayer);
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
public ItemStack transferStackInSlot (EntityPlayer par1EntityPlayer, int par2)
{
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(par2);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (par2 == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (par2 != 1 && par2 != 0)
{
if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return null;
}
}
else if (TileEntityFurnace.isItemFuel(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 1, 2, false))
{
return null;
}
}
else if (par2 >= 3 && par2 < 30)
{
if (!this.mergeItemStack(itemstack1, 30, 39, false))
{
return null;
}
}
else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack) null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
}
return itemstack;
}
}