-
Notifications
You must be signed in to change notification settings - Fork 497
/
BptBuilderBlueprint.java
797 lines (654 loc) · 21.3 KB
/
BptBuilderBlueprint.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
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
* <p/>
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.blueprints;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map.Entry;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.blueprints.BuilderAPI;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IInvSlot;
import buildcraft.api.core.StackKey;
import buildcraft.core.builders.BuilderItemMetaPair;
import buildcraft.core.builders.BuildingSlot;
import buildcraft.core.builders.BuildingSlotBlock;
import buildcraft.core.builders.BuildingSlotBlock.Mode;
import buildcraft.core.builders.BuildingSlotEntity;
import buildcraft.core.builders.BuildingSlotMapIterator;
import buildcraft.core.builders.IBuildingItemsProvider;
import buildcraft.core.builders.TileAbstractBuilder;
import buildcraft.core.lib.inventory.InventoryCopy;
import buildcraft.core.lib.inventory.InventoryIterator;
import buildcraft.core.lib.utils.BlockUtils;
public class BptBuilderBlueprint extends BptBuilderBase {
public ArrayList<RequirementItemStack> neededItems = new ArrayList<RequirementItemStack>();
protected HashSet<Integer> builtEntities = new HashSet<Integer>();
private HashMap<BuilderItemMetaPair, List<BuildingSlotBlock>> buildList = new HashMap<BuilderItemMetaPair, List<BuildingSlotBlock>>();
private int[] buildStageOccurences;
private LinkedList<BuildingSlotEntity> entityList = new LinkedList<BuildingSlotEntity>();
private LinkedList<BuildingSlot> postProcessing = new LinkedList<BuildingSlot>();
private BuildingSlotMapIterator iterator;
private IndexRequirementMap requirementMap = new IndexRequirementMap();
public BptBuilderBlueprint(Blueprint bluePrint, World world, int x, int y, int z) {
super(bluePrint, world, x, y, z);
}
@Override
protected void internalInit() {
for (int j = blueprint.sizeY - 1; j >= 0; --j) {
int yCoord = j + y - blueprint.anchorY;
if (yCoord < 0 || yCoord >= context.world.getHeight()) {
continue;
}
for (int i = 0; i < blueprint.sizeX; ++i) {
int xCoord = i + x - blueprint.anchorX;
for (int k = 0; k < blueprint.sizeZ; ++k) {
int zCoord = k + z - blueprint.anchorZ;
if (!isLocationUsed(xCoord, yCoord, zCoord)) {
SchematicBlock slot = (SchematicBlock) blueprint.get(i, j, k);
if (slot == null && !blueprint.excavate) {
continue;
}
if (slot == null) {
slot = new SchematicBlock();
slot.meta = 0;
slot.block = Blocks.air;
}
if (!SchematicRegistry.INSTANCE.isAllowedForBuilding(slot.block, slot.meta)) {
continue;
}
BuildingSlotBlock b = new BuildingSlotBlock();
b.schematic = slot;
b.x = xCoord;
b.y = yCoord;
b.z = zCoord;
b.mode = Mode.ClearIfInvalid;
b.buildStage = 0;
addToBuildList(b);
}
}
}
}
LinkedList<BuildingSlotBlock> tmpStandalone = new LinkedList<BuildingSlotBlock>();
LinkedList<BuildingSlotBlock> tmpExpanding = new LinkedList<BuildingSlotBlock>();
for (int j = 0; j < blueprint.sizeY; ++j) {
int yCoord = j + y - blueprint.anchorY;
if (yCoord < 0 || yCoord >= context.world.getHeight()) {
continue;
}
for (int i = 0; i < blueprint.sizeX; ++i) {
int xCoord = i + x - blueprint.anchorX;
for (int k = 0; k < blueprint.sizeZ; ++k) {
int zCoord = k + z - blueprint.anchorZ;
SchematicBlock slot = (SchematicBlock) blueprint.get(i, j, k);
if (slot == null) {
continue;
}
if (!SchematicRegistry.INSTANCE.isAllowedForBuilding(slot.block, slot.meta)) {
continue;
}
BuildingSlotBlock b = new BuildingSlotBlock();
b.schematic = slot;
b.x = xCoord;
b.y = yCoord;
b.z = zCoord;
b.mode = Mode.Build;
if (!isLocationUsed(xCoord, yCoord, zCoord)) {
switch (slot.getBuildStage()) {
case STANDALONE:
tmpStandalone.add(b);
b.buildStage = 1;
break;
case EXPANDING:
tmpExpanding.add(b);
b.buildStage = 2;
break;
}
} else {
postProcessing.add(b);
}
}
}
}
for (BuildingSlotBlock b : tmpStandalone) {
addToBuildList(b);
}
for (BuildingSlotBlock b : tmpExpanding) {
addToBuildList(b);
}
int seqId = 0;
for (SchematicEntity e : ((Blueprint) blueprint).entities) {
BuildingSlotEntity b = new BuildingSlotEntity();
b.schematic = e;
b.sequenceNumber = seqId;
if (!builtEntities.contains(seqId)) {
entityList.add(b);
} else {
postProcessing.add(b);
}
seqId++;
}
recomputeNeededItems();
}
public void deploy() {
initialize();
for (List<BuildingSlotBlock> lb : buildList.values()) {
for (BuildingSlotBlock b : lb) {
if (b.mode == Mode.ClearIfInvalid) {
context.world.setBlockToAir(b.x, b.y, b.z);
} else if (!b.schematic.doNotBuild()) {
b.stackConsumed = new LinkedList<ItemStack>();
try {
for (ItemStack stk : b.getRequirements(context)) {
if (stk != null) {
b.stackConsumed.add(stk.copy());
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
b.writeToWorld(context);
}
}
}
for (BuildingSlotEntity e : entityList) {
e.stackConsumed = new LinkedList<ItemStack>();
try {
for (ItemStack stk : e.getRequirements(context)) {
if (stk != null) {
e.stackConsumed.add(stk.copy());
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
e.writeToWorld(context);
}
for (List<BuildingSlotBlock> lb : buildList.values()) {
for (BuildingSlotBlock b : lb) {
if (b.mode != Mode.ClearIfInvalid) {
b.postProcessing(context);
}
}
}
for (BuildingSlotEntity e : entityList) {
e.postProcessing(context);
}
}
private void checkDone() {
recomputeNeededItems();
if (getBuildListCount() == 0 && entityList.size() == 0) {
done = true;
} else {
done = false;
}
}
private int getBuildListCount() {
int out = 0;
if (buildStageOccurences != null) {
for (int i = 0; i < buildStageOccurences.length; i++) {
out += buildStageOccurences[i];
}
}
return out;
}
@Override
public BuildingSlot reserveNextBlock(World world) {
if (getBuildListCount() != 0) {
BuildingSlot slot = internalGetNextBlock(world, null);
checkDone();
if (slot != null) {
slot.reserved = true;
}
return slot;
}
return null;
}
private void addToBuildList(BuildingSlotBlock b) {
if (b != null) {
BuilderItemMetaPair imp = new BuilderItemMetaPair(context, b);
if (!buildList.containsKey(imp)) {
buildList.put(imp, new ArrayList<BuildingSlotBlock>());
}
buildList.get(imp).add(b);
if (buildStageOccurences == null) {
buildStageOccurences = new int[Math.max(3, b.buildStage + 1)];
} else if (buildStageOccurences.length <= b.buildStage) {
int[] newBSO = new int[b.buildStage + 1];
System.arraycopy(buildStageOccurences, 0, newBSO, 0, buildStageOccurences.length);
buildStageOccurences = newBSO;
}
buildStageOccurences[b.buildStage]++;
if (b.mode == Mode.Build) {
requirementMap.add(b, context);
b.internalRequirementRemovalListener = requirementMap;
}
}
}
@Override
public BuildingSlot getNextBlock(World world, TileAbstractBuilder inv) {
if (getBuildListCount() != 0) {
BuildingSlot slot = internalGetNextBlock(world, inv);
checkDone();
return slot;
}
if (entityList.size() != 0) {
BuildingSlot slot = internalGetNextEntity(world, inv);
checkDone();
return slot;
}
checkDone();
return null;
}
protected boolean readyForSlotLookup(TileAbstractBuilder builder) {
return builder == null || builder.energyAvailable() >= BuilderAPI.BREAK_ENERGY;
}
/**
* Gets the next available block. If builder is not null, then building will
* be verified and performed. Otherwise, the next possible building slot is
* returned, possibly for reservation, with no building.
*/
private BuildingSlot internalGetNextBlock(World world, TileAbstractBuilder builder) {
if (!readyForSlotLookup(builder)) {
return null;
}
if (iterator == null) {
iterator = new BuildingSlotMapIterator(buildList, builder, buildStageOccurences);
}
BuildingSlotBlock slot;
iterator.refresh(builder);
while (readyForSlotLookup(builder) && (slot = iterator.next()) != null) {
if (!world.blockExists(slot.x, slot.y, slot.z)) {
continue;
}
boolean skipped = false;
for (int i = 0; i < slot.buildStage; i++) {
if (buildStageOccurences[i] > 0) {
iterator.skipKey();
skipped = true;
break;
}
}
if (skipped) {
continue;
}
if (slot.built) {
iterator.remove();
markLocationUsed(slot.x, slot.y, slot.z);
postProcessing.add(slot);
continue;
}
if (slot.reserved) {
continue;
}
try {
if (slot.isAlreadyBuilt(context)) {
if (slot.mode == Mode.Build) {
requirementMap.remove(slot);
// Even slots that considered already built may need
// post processing calls. For example, flowing water
// may need to be adjusted, engines may need to be
// turned to the right direction, etc.
postProcessing.add(slot);
}
iterator.remove();
continue;
}
if (BlockUtils.isUnbreakableBlock(world, slot.x, slot.y, slot.z)) {
// if the block can't be broken, just forget this iterator
iterator.remove();
markLocationUsed(slot.x, slot.y, slot.z);
requirementMap.remove(slot);
} else {
if (slot.mode == Mode.ClearIfInvalid) {
if (BuildCraftAPI.isSoftBlock(world, slot.x, slot.y,
slot.z)
|| isBlockBreakCanceled(world, slot.x, slot.y, slot.z)) {
iterator.remove();
markLocationUsed(slot.x, slot.y, slot.z);
} else {
if (builder == null) {
createDestroyItems(slot);
return slot;
} else if (canDestroy(builder, context, slot)) {
consumeEnergyToDestroy(builder, slot);
createDestroyItems(slot);
iterator.remove();
markLocationUsed(slot.x, slot.y, slot.z);
return slot;
}
}
} else if (!slot.schematic.doNotBuild()) {
if (builder == null) {
return slot;
} else if (checkRequirements(builder, slot.schematic)) {
if (!BuildCraftAPI.isSoftBlock(world, slot.x, slot.y,
slot.z) || requirementMap.contains(new BlockIndex(slot.x, slot.y, slot.z))) {
continue; // Can't build yet, wait (#2751)
} else if (isBlockPlaceCanceled(world, slot.x, slot.y, slot.z, slot.schematic)) {
// Forge does not allow us to place a block in
// this position.
iterator.remove();
requirementMap.remove(slot);
markLocationUsed(slot.x, slot.y, slot.z);
continue;
}
// At this stage, regardless of the fact that the
// block can actually be built or not, we'll try.
// When the item reaches the actual block, we'll
// verify that the location is indeed clear, and
// avoid building otherwise.
builder.consumeEnergy(slot.getEnergyRequirement());
useRequirements(builder, slot);
iterator.remove();
markLocationUsed(slot.x, slot.y, slot.z);
postProcessing.add(slot);
return slot;
}
} else {
// Even slots that don't need to be build may need
// post processing, see above for the argument.
postProcessing.add(slot);
requirementMap.remove(slot);
iterator.remove();
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
iterator.remove();
requirementMap.remove(slot);
}
}
return null;
}
private BuildingSlot internalGetNextEntity(World world, TileAbstractBuilder builder) {
Iterator<BuildingSlotEntity> it = entityList.iterator();
while (it.hasNext()) {
BuildingSlotEntity slot = it.next();
if (slot.isAlreadyBuilt(context)) {
it.remove();
} else {
if (checkRequirements(builder, slot.schematic)) {
builder.consumeEnergy(slot.getEnergyRequirement());
useRequirements(builder, slot);
it.remove();
postProcessing.add(slot);
builtEntities.add(slot.sequenceNumber);
return slot;
}
}
}
return null;
}
public boolean checkRequirements(TileAbstractBuilder builder, Schematic slot) {
LinkedList<ItemStack> tmpReq = new LinkedList<ItemStack>();
try {
LinkedList<ItemStack> req = new LinkedList<ItemStack>();
slot.getRequirementsForPlacement(context, req);
for (ItemStack stk : req) {
if (stk != null) {
tmpReq.add(stk.copy());
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
LinkedList<ItemStack> stacksUsed = new LinkedList<ItemStack>();
if (context.world().getWorldInfo().getGameType() == GameType.CREATIVE) {
for (ItemStack s : tmpReq) {
stacksUsed.add(s);
}
return !(builder.energyAvailable() < slot.getEnergyRequirement(stacksUsed));
}
for (ItemStack reqStk : tmpReq) {
boolean itemBlock = reqStk.getItem() instanceof ItemBlock;
Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).field_150939_a) : null;
if (fluid != null && builder.drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) {
continue;
}
for (IInvSlot slotInv : InventoryIterator.getIterable(new InventoryCopy(builder), ForgeDirection.UNKNOWN)) {
if (!builder.isBuildingMaterialSlot(slotInv.getIndex())) {
continue;
}
ItemStack invStk = slotInv.getStackInSlot();
if (invStk == null || invStk.stackSize == 0) {
continue;
}
FluidStack fluidStack = fluid != null ? FluidContainerRegistry.getFluidForFilledItem(invStk) : null;
boolean compatibleContainer = fluidStack != null && fluidStack.getFluid() == fluid && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME;
if (slot.isItemMatchingRequirement(invStk, reqStk) || compatibleContainer) {
try {
stacksUsed.add(slot.useItem(context, reqStk, slotInv));
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
if (reqStk.stackSize == 0) {
break;
}
}
}
if (reqStk.stackSize != 0) {
return false;
}
}
return builder.energyAvailable() >= slot.getEnergyRequirement(stacksUsed);
}
@Override
public void useRequirements(IInventory inv, BuildingSlot slot) {
if (slot instanceof BuildingSlotBlock && ((BuildingSlotBlock) slot).mode == Mode.ClearIfInvalid) {
return;
}
LinkedList<ItemStack> tmpReq = new LinkedList<ItemStack>();
try {
for (ItemStack stk : slot.getRequirements(context)) {
if (stk != null) {
tmpReq.add(stk.copy());
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
if (context.world().getWorldInfo().getGameType() == GameType.CREATIVE) {
for (ItemStack s : tmpReq) {
slot.addStackConsumed(s);
}
return;
}
ListIterator<ItemStack> itr = tmpReq.listIterator();
while (itr.hasNext()) {
ItemStack reqStk = itr.next();
boolean smallStack = reqStk.stackSize == 1;
ItemStack usedStack = reqStk;
boolean itemBlock = reqStk.getItem() instanceof ItemBlock;
Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).field_150939_a) : null;
if (fluid != null
&& inv instanceof TileAbstractBuilder
&& ((TileAbstractBuilder) inv).drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) {
continue;
}
for (IInvSlot slotInv : InventoryIterator.getIterable(inv, ForgeDirection.UNKNOWN)) {
if (inv instanceof TileAbstractBuilder &&
!((TileAbstractBuilder) inv).isBuildingMaterialSlot(slotInv.getIndex())) {
continue;
}
ItemStack invStk = slotInv.getStackInSlot();
if (invStk == null || invStk.stackSize == 0) {
continue;
}
FluidStack fluidStack = fluid != null ? FluidContainerRegistry.getFluidForFilledItem(invStk) : null;
boolean fluidFound = fluidStack != null && fluidStack.getFluid() == fluid && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME;
if (fluidFound || slot.getSchematic().isItemMatchingRequirement(invStk, reqStk)) {
try {
usedStack = slot.getSchematic().useItem(context, reqStk, slotInv);
slot.addStackConsumed(usedStack);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
if (reqStk.stackSize == 0) {
break;
}
}
}
if (reqStk.stackSize != 0) {
return;
}
if (smallStack) {
itr.set(usedStack); // set to the actual item used.
}
}
}
public void recomputeNeededItems() {
neededItems.clear();
HashMap<StackKey, Integer> computeStacks = new HashMap<StackKey, Integer>();
for (List<BuildingSlotBlock> lb : buildList.values()) {
for (BuildingSlotBlock slot : lb) {
if (slot == null) {
continue;
}
LinkedList<ItemStack> stacks = new LinkedList<ItemStack>();
try {
stacks = slot.getRequirements(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
for (ItemStack stack : stacks) {
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
StackKey key = new StackKey(stack);
if (!computeStacks.containsKey(key)) {
computeStacks.put(key, stack.stackSize);
} else {
Integer num = computeStacks.get(key);
num += stack.stackSize;
computeStacks.put(key, num);
}
}
}
}
for (BuildingSlotEntity slot : entityList) {
LinkedList<ItemStack> stacks = new LinkedList<ItemStack>();
try {
stacks = slot.getRequirements(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
for (ItemStack stack : stacks) {
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
StackKey key = new StackKey(stack);
if (!computeStacks.containsKey(key)) {
computeStacks.put(key, stack.stackSize);
} else {
Integer num = computeStacks.get(key);
num += stack.stackSize;
computeStacks.put(key, num);
}
}
}
for (Entry<StackKey, Integer> e : computeStacks.entrySet()) {
neededItems.add(new RequirementItemStack(e.getKey().stack.copy(), e.getValue()));
}
Collections.sort(neededItems, new Comparator<RequirementItemStack>() {
@Override
public int compare(RequirementItemStack o1, RequirementItemStack o2) {
if (o1.size != o2.size) {
return o1.size < o2.size ? 1 : -1;
} else {
ItemStack os1 = o1.stack;
ItemStack os2 = o2.stack;
if (Item.getIdFromItem(os1.getItem()) > Item.getIdFromItem(os2.getItem())) {
return -1;
} else if (Item.getIdFromItem(os1.getItem()) < Item.getIdFromItem(os2.getItem())) {
return 1;
} else if (os1.getItemDamage() > os2.getItemDamage()) {
return -1;
} else if (os1.getItemDamage() < os2.getItemDamage()) {
return 1;
} else {
return 0;
}
}
}
});
}
@Override
public void postProcessing(World world) {
for (BuildingSlot s : postProcessing) {
try {
s.postProcessing(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
}
}
@Override
public void saveBuildStateToNBT(NBTTagCompound nbt, IBuildingItemsProvider builder) {
super.saveBuildStateToNBT(nbt, builder);
int[] entitiesBuiltArr = new int[builtEntities.size()];
int id = 0;
for (Integer i : builtEntities) {
entitiesBuiltArr[id] = i;
id++;
}
nbt.setIntArray("builtEntities", entitiesBuiltArr);
}
@Override
public void loadBuildStateToNBT(NBTTagCompound nbt, IBuildingItemsProvider builder) {
super.loadBuildStateToNBT(nbt, builder);
int[] entitiesBuiltArr = nbt.getIntArray("builtEntities");
for (int i = 0; i < entitiesBuiltArr.length; ++i) {
builtEntities.add(i);
}
}
}