-
Notifications
You must be signed in to change notification settings - Fork 755
/
FrypanContainer.java
132 lines (117 loc) · 3.72 KB
/
FrypanContainer.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
package tconstruct.inventory;
import net.minecraft.block.Block;
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 tconstruct.blocks.logic.FrypanLogic;
import tconstruct.common.TRepo;
public class FrypanContainer extends Container
{
public FrypanLogic logic;
public int progress = 0;
public int fuel = 0;
public int fuelGague = 0;
public FrypanContainer(EntityPlayer player, FrypanLogic frypan)
{
InventoryPlayer inventoryplayer = player.inventory;
logic = frypan;
this.addSlotToContainer(new Slot(frypan, 1, 26, 45));
for (int y = 0; y < 2; y++)
for (int x = 0; x < 4; x++)
this.addSlotToContainer(new SlotFrypan(frypan, 2 + x + y * 4, 70 + x * 18, 27 + y * 18, player));
/* Player inventory */
for (int column = 0; column < 3; column++)
{
for (int row = 0; row < 9; row++)
{
this.addSlotToContainer(new Slot(inventoryplayer, row + column * 9 + 9, 8 + row * 18, 84 + column * 18));
}
}
for (int column = 0; column < 9; column++)
{
this.addSlotToContainer(new Slot(inventoryplayer, column, 8 + column * 18, 142));
}
}
@Override
public void detectAndSendChanges ()
{
super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); i++)
{
ICrafting icrafting = (ICrafting) crafters.get(i);
if (progress != logic.progress)
{
icrafting.sendProgressBarUpdate(this, 0, logic.progress);
}
if (fuel != logic.fuel)
{
icrafting.sendProgressBarUpdate(this, 1, logic.fuel);
}
if (fuelGague != logic.fuelGague)
{
icrafting.sendProgressBarUpdate(this, 2, logic.fuelGague);
}
}
progress = logic.progress;
fuel = logic.fuel;
fuelGague = logic.fuelGague;
}
@Override
public void updateProgressBar (int i, int j)
{
if (i == 0)
{
logic.progress = j;
}
if (i == 1)
{
logic.fuel = j;
}
if (i == 2)
{
logic.fuelGague = j;
}
}
@Override
public boolean canInteractWith (EntityPlayer entityplayer)
{
Block block = logic.getWorldObj().getBlock(logic.xCoord, logic.yCoord, logic.zCoord);
if (block != TRepo.heldItemBlock)
return false;
return logic.isUseableByPlayer(entityplayer);
}
@Override
public ItemStack transferStackInSlot (EntityPlayer player, int slotID)
{
ItemStack stack = null;
Slot slot = (Slot) this.inventorySlots.get(slotID);
if (slot != null && slot.getHasStack())
{
ItemStack slotStack = slot.getStack();
stack = slotStack.copy();
if (slotID < logic.getSizeInventory())
{
if (!this.mergeItemStack(slotStack, logic.getSizeInventory(), this.inventorySlots.size(), true))
{
return null;
}
}
else if (!this.mergeItemStack(slotStack, 0, logic.getSizeInventory(), false))
{
return null;
}
if (slotStack.stackSize == 0)
{
slot.putStack((ItemStack) null);
}
else
{
slot.onSlotChanged();
}
}
return stack;
}
}