forked from dfu/MineColony
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileEntityChanger.java
More file actions
336 lines (291 loc) · 7.92 KB
/
TileEntityChanger.java
File metadata and controls
336 lines (291 loc) · 7.92 KB
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
package net.minecraft.src;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
public class TileEntityChanger extends TileEntity
implements IInventory
{
public TileEntityChanger()
{
changerItemStacks = new ItemStack[13];
changerCurrentItemsValue = 0;
changerCurrentOutputsValue = 0;
changerLastOutputsValue = 0;
lastStackHeight = new int[13];
stackValue = new int [13];
stackItem = new Item [13];
for(int i = 1; i <= 12; i++)
{
lastStackHeight[i] = 0;
}
stackValue[1] = 1;
stackValue[2] = 10;
stackValue[3] = 50;
stackValue[4] = 100;
stackValue[5] = 250;
stackValue[6] = 1000;
stackValue[7] = 1;
stackValue[8] = 10;
stackValue[9] = 50;
stackValue[10] = 100;
stackValue[11] = 250;
stackValue[12] = 1000;
stackItem[1] = mod_MineColony.moneyBronze;
stackItem[2] = mod_MineColony.moneySilver;
stackItem[3] = mod_MineColony.moneyGold;
stackItem[4] = Item.ingotIron;
stackItem[5] = Item.ingotGold;
stackItem[6] = Item.diamond;
stackItem[7] = mod_MineColony.moneyBronze;
stackItem[8] = mod_MineColony.moneySilver;
stackItem[9] = mod_MineColony.moneyGold;
stackItem[10] = Item.ingotIron;
stackItem[11] = Item.ingotGold;
stackItem[12] = Item.diamond;
}
public int getSizeInventory()
{
return changerItemStacks.length;
}
public ItemStack getStackInSlot(int i)
{
return changerItemStacks[i];
}
public ItemStack decrStackSize(int i, int j)
{
if(changerItemStacks[i] != null)
{
if(changerItemStacks[i].stackSize <= j)
{
ItemStack itemstack = changerItemStacks[i];
changerItemStacks[i] = null;
return itemstack;
}
ItemStack itemstack1 = changerItemStacks[i].splitStack(j);
if(changerItemStacks[i].stackSize == 0)
{
changerItemStacks[i] = null;
}
return itemstack1;
} else
{
return null;
}
}
public void setInventorySlotContents(int i, ItemStack itemstack)
{
if(itemstack == null)
{
lastStackHeight[i] = 0;
}
else
{
lastStackHeight[i] = itemstack.stackSize;
}
changerItemStacks[i] = itemstack;
if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
itemstack.stackSize = getInventoryStackLimit();
}
}
public String getInvName()
{
return "Changer";
}
public void readFromNBT(NBTTagCompound nbttagcompound)
{
super.readFromNBT(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
changerItemStacks = new ItemStack[getSizeInventory()];
for(int i = 0; i < nbttaglist.tagCount(); i++)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
byte byte0 = nbttagcompound1.getByte("Slot");
if(byte0 >= 0 && byte0 < changerItemStacks.length)
{
changerItemStacks[byte0] = new ItemStack(nbttagcompound1);
}
}
}
public void writeToNBT(NBTTagCompound nbttagcompound)
{
super.writeToNBT(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList();
for(int i = 0; i < changerItemStacks.length; i++)
{
if(changerItemStacks[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
changerItemStacks[i].writeToNBT(nbttagcompound1);
nbttaglist.setTag(nbttagcompound1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
}
public int getInventoryStackLimit()
{
return 64;
}
public int getStackValue(int i)
{
if(changerItemStacks[i] == null)
{
return 0;
}
return changerItemStacks[i].stackSize * stackValue[i];
}
public void setStackIfPossible(int i, int valueOfItem, int currentCredit, Item stackItem)
{
int value = (currentCredit / valueOfItem);
if(value != 0)
{
ItemStack stack = new ItemStack(stackItem,
1);
setInventorySlotContents(i, stack);
}
else
{
setInventorySlotContents(i, null);
}
}
public void updateEntity()
{
}
public boolean outputChanged()
{
for(int i = 7; i <= 12; i++)
{
if(changerItemStacks[i] != null)
{
if(changerItemStacks[i].stackSize != lastStackHeight[i])
{
return true;
}
}
else
{
if(lastStackHeight[i] != 0)
{
return true;
}
}
}
return false;
}
public void onInventoryChanged()
{
if(outputChanged())
{
//setInventorySlotContents(7, new ItemStack(Item.stick,1));
changerCurrentOutputsValue = 0;
for(int i = 7; i <= 12; i++)
{
changerCurrentOutputsValue += getStackValue(i);
}
changerLastOutputsValue = 0;
for(int i = 7; i <= 12; i++)
{
changerLastOutputsValue += lastStackHeight[i] * stackValue[i];
}
for(int i = 7; i <= 12; i++)
{
lastStackHeight[i] = 0;
setInventorySlotContents(i, null);
}
int OutputsDifference = changerLastOutputsValue
- changerCurrentOutputsValue;
System.out.println(OutputsDifference);
//get as much money without going under 0 beginning with the largest
for(int i = 6; i >= 1; i--)
{
while(stackValue[i] <= OutputsDifference && changerItemStacks[i] != null)
{
if(changerItemStacks[i].stackSize == 1)
{
changerItemStacks[i] = null;
}
else
{
changerItemStacks[i].splitStack(1);
}
OutputsDifference -= stackValue[i];
}
}
System.out.println(OutputsDifference);
//go the smallest amount under zero
for(int i = 1; i <= 6; i++)
{
System.out.println(stackValue[i]);
if(stackValue[i] >= OutputsDifference && changerItemStacks[i] != null)
{
if(changerItemStacks[i].stackSize == 1)
{
changerItemStacks[i] = null;
}
else
{
changerItemStacks[i].splitStack(1);
}
OutputsDifference -= stackValue[i];
}
}
OutputsDifference = 0 - OutputsDifference;
System.out.println(OutputsDifference);
//give recharge
for(int i = 6; i >= 1; i--)
{
while(stackValue[i] <= OutputsDifference)
{
if(changerItemStacks[i] == null)
{
setInventorySlotContents(i, new ItemStack(stackItem[i], 1));
}
else if(changerItemStacks[i].stackSize <= 63)
{
changerItemStacks[i].stackSize++;
}
else
{
break;
}
OutputsDifference -= stackValue[i];
}
}
System.out.println(OutputsDifference);
onInventoryChanged();
}
else
{
if(!worldObj.multiplayerWorld)
{
changerCurrentItemsValue = 0;
for(int i = 1; i <= 6; i++)
{
changerCurrentItemsValue += getStackValue(i);
}
setStackIfPossible(7, 1, changerCurrentItemsValue, mod_MineColony.moneyBronze);
setStackIfPossible(8, 10, changerCurrentItemsValue, mod_MineColony.moneySilver);
setStackIfPossible(9, 50, changerCurrentItemsValue, mod_MineColony.moneyGold);
setStackIfPossible(10, 100, changerCurrentItemsValue, Item.ingotIron);
setStackIfPossible(11, 250, changerCurrentItemsValue, Item.ingotGold);
setStackIfPossible(12, 1000, changerCurrentItemsValue, Item.diamond);
}
}
}
public boolean canInteractWith(EntityPlayer entityplayer)
{
if(worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
{
return false;
}
return entityplayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;
}
private ItemStack changerItemStacks[];
public int changerCurrentItemsValue;
public int changerCurrentOutputsValue;
public int changerLastOutputsValue;
public int[] lastStackHeight;
public int[] stackValue;
public Item[] stackItem;
}