-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlueprintBuilder.java
173 lines (141 loc) · 3.89 KB
/
BlueprintBuilder.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
/**
* 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.builders.blueprints;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.builder.BlockHandler;
import buildcraft.api.core.IAreaProvider;
public class BlueprintBuilder implements IAreaProvider {
public final Blueprint blueprint;
public final ForgeDirection orientation;
public final World worldObj;
public final int x, y, z;
private final List<SchematicBuilder> builders;
public BlueprintBuilder(Blueprint blueprint, World world, int x, int y, int z, ForgeDirection orientation) {
this.blueprint = blueprint;
this.orientation = orientation;
this.worldObj = world;
this.x = translateX(x, -blueprint.anchorX, -blueprint.anchorZ);
this.y = y - blueprint.anchorY;
this.z = translateZ(z, -blueprint.anchorX, -blueprint.anchorZ);
builders = new ArrayList<SchematicBuilder>(blueprint.schematicSequence.size());
for (Schematic schematic : blueprint.schematicSequence) {
BlockHandler handler = schematic.getHandler();
if (handler != null) {
builders.add(new SchematicBuilder(schematic, handler));
}
}
}
public List<SchematicBuilder> getBuilders() {
return Collections.unmodifiableList(builders);
}
@Override
public float xMin() {
return x;
}
@Override
public float yMin() {
return y;
}
@Override
public float zMin() {
return z;
}
@Override
public float xMax() {
return translateX(x, blueprint.sizeX - 1, blueprint.sizeZ - 1);
}
@Override
public float yMax() {
return y + blueprint.sizeY - 1;
}
@Override
public float zMax() {
return translateZ(z, blueprint.sizeX - 1, blueprint.sizeZ - 1);
}
@Override
public void removeFromWorld() {
}
private int translateX(int corner, int x, int z) {
switch (orientation) {
case SOUTH:
return corner - x;
case EAST:
return corner - z;
case WEST:
return corner + z;
default:
return corner + x;
}
}
private int translateZ(int corner, int x, int z) {
switch (orientation) {
case SOUTH:
return corner - z;
case EAST:
return corner + x;
case WEST:
return corner - x;
default:
return corner + z;
}
}
public class SchematicBuilder {
public final Schematic schematic;
public final BlockHandler handler;
private boolean complete;
private SchematicBuilder(Schematic schematic, BlockHandler handler) {
this.schematic = schematic;
this.handler = handler;
}
public int getX() {
return translateX(x, schematic.x, schematic.z);
}
public int getY() {
return y + schematic.y;
}
public int getZ() {
return translateZ(z, schematic.x, schematic.z);
}
public boolean blockExists() {
return handler.doesBlockMatchSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.data);
}
public boolean canBuild() {
return handler.canPlaceNow(worldObj, getX(), getY(), getZ(), orientation, schematic.data);
}
//public boolean build () {
// return build (CoreProxy.proxy.getBuildCraftPlayer(worldObj, x, y + 2, z));
//}
public boolean build(IBlueprintBuilderAgent builderAgent) {
// if (blockExists()) {
// markComplete();
// return false;
// }
// if (!BlockUtil.canChangeBlock(worldObj, getX(), getY(), getZ()))
// return false;
if (!canBuild()) {
return false;
}
boolean built = handler.buildBlockFromSchematic(worldObj, this, builderAgent);
if (built) {
markComplete();
}
return built;
}
public boolean isComplete() {
return complete || handler.isComplete(worldObj, this);
}
public void markComplete() {
complete = true;
}
}
}