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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
package gregtech.common.gui;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorState;
import gregtech.api.gui.GT_ContainerMetaTile_Machine;
import gregtech.api.gui.GT_Slot_Holo;
import gregtech.api.gui.GT_Slot_Output;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GT_ApiaryUpgrade;
import gregtech.api.util.GT_Utility;
import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_IndustrialApiary;
import net.bdew.gendustry.api.items.IApiaryUpgrade;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import java.util.ArrayList;
public class GT_Container_IndustrialApiary extends GT_ContainerMetaTile_Machine {
GT_Slot_Holo slotItemTransferToggle;
GT_Slot_Holo slotSpeedToggle;
GT_Slot_Holo slotPollenToggle;
GT_Slot_Holo slotCancelProcess;
Slot slotBattery;
Slot slotSpecial;
boolean mItemTransfer;
boolean mStuttering;
int mSpeed = 0; // scale 0 - 8
boolean mLockedSpeed = true;
boolean retrievePollen;
ArrayList<String> mErrorStates = new ArrayList<>(50);
public GT_Container_IndustrialApiary(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) {
super(aInventoryPlayer, aTileEntity);
}
@Override
public void addSlots(InventoryPlayer aInventoryPlayer) {
addSlotToContainer(slotItemTransferToggle = new GT_Slot_Holo(mTileEntity, 0, 8, 63, false, true, 1));
addSlotToContainer(slotSpeedToggle = new GT_Slot_Holo(mTileEntity, 0, 26, 63, false, true, 1));
addSlotToContainer(slotPollenToggle = new GT_Slot_Holo(mTileEntity, 0, 8, 45, false, true, 1));
addSlotToContainer(slotCancelProcess = new GT_Slot_Holo(mTileEntity, 0, 8, 27, false, true, 1));
int tStartIndex = 5;
addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 37, 22));
addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 37, 42));
addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 62, 24));
addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 80, 24));
addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 62, 42));
addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 80, 42));
for(int i = 107; i <= 143; i += 18)
for(int j = 6; j <= 42; j += 18)
addSlotToContainer(new GT_Slot_Output(this.mTileEntity, tStartIndex++, i, j));
addSlotToContainer(slotBattery = new Slot(mTileEntity, 1, 80, 63));
addSlotToContainer(slotSpecial = new Slot(mTileEntity, 3, 125, 63));
}
@Override
public ItemStack slotClick(int aSlotNumber, int aMouseclick, int aShifthold, EntityPlayer aPlayer) {
if (mTileEntity.getMetaTileEntity() == null) return null;
GT_MetaTileEntity_IndustrialApiary machine = getMachine();
if (machine == null) return null;
switch (aSlotNumber) {
case 0:
machine.mItemTransfer = !machine.mItemTransfer;
return null;
case 1:
if(aMouseclick == 0) {
if(machine.mLockedSpeed)
return null;
if(aShifthold == 0) {
machine.mSpeed++;
if (machine.mSpeed > machine.getMaxSpeed()) machine.mSpeed = 0;
}
else if(aShifthold == 1)
{
machine.mSpeed--;
if (machine.mSpeed < 0) machine.mSpeed = machine.getMaxSpeed();
}
}
else if(aMouseclick == 1)
{
machine.mLockedSpeed = !machine.mLockedSpeed;
if(machine.mLockedSpeed)
machine.mSpeed = machine.getMaxSpeed();
}
return null;
case 2:
machine.retreviePollen = !machine.retreviePollen;
return null;
case 3:
machine.cancelProcess();
detectAndSendChanges();
return null;
}
if(!(aSlotNumber >= getSlotStartIndex()+2 && aSlotNumber < getSlotStartIndex()+2+4))
return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer);
if(aShifthold == 5)
return null;
if(aShifthold != 0)
return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer);
if(aMouseclick > 1)
return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer);
ItemStack s = aPlayer.inventory.getItemStack();
if(s == null)
return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer);
Slot slot = getSlot(aSlotNumber);
ItemStack slotstack = slot.getStack();
if(slotstack != null && !GT_Utility.areStacksEqual(slotstack, s))
return null; // super would replace item
if(slotstack == null && !slot.isItemValid(s))
return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer);
if(!(s.getItem() instanceof IApiaryUpgrade) && !GT_ApiaryUpgrade.isUpgrade(s))
return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer);
int max = 1;
if (s.getItem() instanceof IApiaryUpgrade)
max = ((IApiaryUpgrade) s.getItem()).getMaxNumber(s);
else
max = GT_ApiaryUpgrade.getUpgrade(s).getMaxNumber();
if(slotstack != null)
max = Math.max(0, max - slotstack.stackSize);
max = Math.min(max, s.stackSize);
if(max == 0)
return null;
if(aMouseclick == 1)
max = 1;
if(max == s.stackSize)
return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer);
ItemStack newstack = s.splitStack(s.stackSize - max);
ItemStack result = super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer);
aPlayer.inventory.setItemStack(newstack);
return result;
}
@Override
public int getSlotStartIndex() {
return 4;
}
@Override
public int getSlotCount() {
return 6+9+2;
}
@Override
public int getShiftClickSlotCount() {
return 6;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) {
return;
}
this.mSpeed = getMachine().mSpeed;
this.mItemTransfer = getMachine().mItemTransfer;
this.mStuttering = getMachine().mStuttering;
this.retrievePollen = getMachine().retreviePollen;
this.mLockedSpeed = getMachine().mLockedSpeed;
for (Object crafter : this.crafters) {
ICrafting var1 = (ICrafting) crafter;
var1.sendProgressBarUpdate(this, 100, this.mSpeed);
var1.sendProgressBarUpdate(this, 101, this.mItemTransfer ? 1 : 0);
var1.sendProgressBarUpdate(this, 102, 0);
for(IErrorState s : getMachine().mErrorStates)
var1.sendProgressBarUpdate(this, 103, s.getID());
var1.sendProgressBarUpdate(this, 104, this.mStuttering ? 1 : 0);
var1.sendProgressBarUpdate(this, 105, this.retrievePollen ? 1 : 0);
var1.sendProgressBarUpdate(this, 106, this.mLockedSpeed ? 1 : 0);
}
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2) {
super.updateProgressBar(par1, par2);
switch (par1) {
case 100:
this.mSpeed = par2;
break;
case 101:
this.mItemTransfer = par2 == 1;
break;
case 102:
this.mErrorStates.clear();
break;
case 103:
this.mErrorStates.add(EnumChatFormatting.RED + StatCollector.translateToLocal("for." + ForestryAPI.errorStateRegistry.getErrorState((short) par2).getDescription()));
break;
case 104:
this.mStuttering = par2 == 1;
break;
case 105:
this.retrievePollen = par2 == 1;
break;
case 106:
this.mLockedSpeed = par2 == 1;
break;
}
}
public GT_MetaTileEntity_IndustrialApiary getMachine() {
return (GT_MetaTileEntity_IndustrialApiary) mTileEntity.getMetaTileEntity();
}
@Override
public ItemStack transferStackInSlot(EntityPlayer aPlayer, int aSlotIndex) {
Slot s = getSlot(aSlotIndex);
if(s == null)
return super.transferStackInSlot(aPlayer, aSlotIndex);
if(!(s.inventory instanceof InventoryPlayer))
return super.transferStackInSlot(aPlayer, aSlotIndex);
ItemStack aStack = s.getStack();
if(aStack == null)
return super.transferStackInSlot(aPlayer, aSlotIndex);
if(!(aStack.getItem() instanceof IApiaryUpgrade) && !GT_ApiaryUpgrade.isUpgrade(aStack))
return super.transferStackInSlot(aPlayer, aSlotIndex);
for(int i = getSlotStartIndex()+2; i < getSlotStartIndex()+2+4; i++) {
Slot iSlot = getSlot(i);
ItemStack iStack = iSlot.getStack();
if(iStack == null)
{
if(!iSlot.isItemValid(aStack))
continue;
}
else
{
if(!GT_Utility.areStacksEqual(aStack, iStack))
continue;
}
int max = 1;
if (aStack.getItem() instanceof IApiaryUpgrade)
max = ((IApiaryUpgrade) aStack.getItem()).getMaxNumber(aStack);
else
max = GT_ApiaryUpgrade.getUpgrade(aStack).getMaxNumber();
if (iStack == null) {
max = Math.min(max, aStack.stackSize);
ItemStack newstack = aStack.splitStack(max);
iSlot.putStack(newstack);
} else {
max = Math.max(0, max - iStack.stackSize);
max = Math.min(max, aStack.stackSize);
iStack.stackSize += max;
aStack.stackSize -= max;
iSlot.onSlotChanged();
}
if (aStack.stackSize == 0)
s.putStack(null);
else
s.onSlotChanged();
break;
}
return null;
}
private static class ApiarySlot extends Slot{
public ApiarySlot(IInventory p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_) {
super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_);
}
@Override
public boolean isItemValid(ItemStack p_75214_1_) {
return this.inventory.isItemValidForSlot(this.getSlotIndex(), p_75214_1_);
}
@Override
public void onSlotChanged() {
super.onSlotChanged();
((GT_MetaTileEntity_IndustrialApiary)((IGregTechTileEntity)this.inventory).getMetaTileEntity()).onInventoryUpdate(this.getSlotIndex());
}
}
}
|