-
Notifications
You must be signed in to change notification settings - Fork 497
/
BuildingSlotBlock.java
executable file
·116 lines (98 loc) · 2.76 KB
/
BuildingSlotBlock.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
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* 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.LinkedList;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.core.Position;
public class BuildingSlotBlock extends BuildingSlot implements Comparable<BuildingSlotBlock> {
public int x, y, z;
public Schematic schematic;
public enum Mode {
ClearIfInvalid, Build
};
public Mode mode = Mode.Build;
public Schematic getSchematic () {
if (schematic == null) {
return new SchematicMask(false);
} else {
return schematic;
}
}
@Override
public void writeToWorld(IBuilderContext context) {
if (mode == Mode.ClearIfInvalid) {
if (!getSchematic().isValid(context, x, y, z)) {
context.world().setBlockToAir(x, y, z);
}
} else {
try {
getSchematic().writeToWorld(context, x, y, z, stackConsumed);
// Once the schematic has been written, we're going to issue
// calls
// to various functions, in particular updating the tile entity.
// If these calls issue problems, in order to avoid corrupting
// the world, we're logging the problem and setting the block to
// air.
TileEntity e = context.world().getTileEntity(x, y, z);
if (e != null) {
e.updateEntity();
}
} catch (Throwable t) {
t.printStackTrace();
context.world().setBlockToAir(x, y, z);
}
}
}
@Override
public void postProcessing (IBuilderContext context) {
getSchematic().postProcessing(context, x, y, z);
}
@Override
public LinkedList<ItemStack> getRequirements (IBuilderContext context) {
if (mode == Mode.ClearIfInvalid) {
return new LinkedList<ItemStack>();
} else {
return getSchematic().getRequirements(context);
}
}
@Override
public int compareTo(BuildingSlotBlock o) {
if (o.schematic instanceof Comparable && schematic instanceof Comparable ) {
Comparable comp1 = (Comparable) schematic;
Comparable comp2 = (Comparable) o.schematic;
int cmp = comp1.compareTo(comp2);
if (cmp != 0) {
return cmp;
}
}
if (y < o.y) {
return -1;
} else if (y > o.y) {
return 1;
} else if (x < o.x) {
return -1;
} else if (x > o.x) {
return 1;
} else if (z < o.z) {
return -1;
} else if (z > o.z) {
return 1;
} else {
return 0;
}
}
@Override
public Position getDestination () {
return new Position (x + 0.5, y + 0.5, z + 0.5);
}
}