-
Notifications
You must be signed in to change notification settings - Fork 497
/
SchematicAutoWorkbench.java
79 lines (66 loc) · 2.75 KB
/
SchematicAutoWorkbench.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
/** 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.factory.schematics;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import buildcraft.BuildCraftFactory;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicTile;
import buildcraft.api.core.IInvSlot;
import buildcraft.api.core.JavaTools;
import buildcraft.core.lib.inventory.InventoryIterator;
import buildcraft.factory.TileAutoWorkbench;
public class SchematicAutoWorkbench extends SchematicTile {
@Override
public void storeRequirements(IBuilderContext context, BlockPos pos) {
TileAutoWorkbench autoWb = getTile(context, pos);
if (autoWb != null) {
ArrayList<ItemStack> rqs = new ArrayList<>();
rqs.add(new ItemStack(BuildCraftFactory.autoWorkbenchBlock));
for (IInvSlot slot : InventoryIterator.getIterable(autoWb.craftMatrix, EnumFacing.UP)) {
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
stack = stack.copy();
stack.stackSize = 1;
rqs.add(stack);
}
}
storedRequirements = JavaTools.concat(storedRequirements, rqs.toArray(new ItemStack[rqs.size()]));
}
}
@Override
public void initializeFromObjectAt(IBuilderContext context, BlockPos pos) {
super.initializeFromObjectAt(context, pos);
tileNBT.removeTag("Items");
}
@Override
public void placeInWorld(IBuilderContext context, BlockPos pos, List<ItemStack> stacks) {
super.placeInWorld(context, pos, stacks);
TileAutoWorkbench autoWb = getTile(context, pos);
if (autoWb != null) {
for (IInvSlot slot : InventoryIterator.getIterable(autoWb.craftMatrix, EnumFacing.UP)) {
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
stack.stackSize = 1;
}
}
}
}
@Override
public BuildingStage getBuildStage() {
return BuildingStage.STANDALONE;
}
private TileAutoWorkbench getTile(IBuilderContext context, BlockPos pos) {
TileEntity tile = context.world().getTileEntity(pos);
if (tile != null && tile instanceof TileAutoWorkbench) {
return (TileAutoWorkbench) tile;
}
return null;
}
}