-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlueprintBuilder.java
136 lines (115 loc) · 3.36 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
/*
* Copyright (c) SpaceToad, 2011-2012
* 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 buildcraft.api.builder.BlockHandler;
import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import static net.minecraftforge.common.ForgeDirection.EAST;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class BlueprintBuilder {
public final Blueprint blueprint;
public final ForgeDirection orientation;
public final World worldObj;
public final int x, y, z;
private final IInventory inv;
private final LinkedList<Schematic> buildList;
private final List<SchematicBuilder> builders;
public BlueprintBuilder(Blueprint blueprint, World world, int x, int y, int z, ForgeDirection orientation, IInventory inv) {
this.blueprint = blueprint;
this.orientation = orientation;
this.worldObj = world;
this.x = x;
this.y = y;
this.z = z;
this.inv = inv;
this.buildList = blueprint.getBuildList();
builders = new ArrayList<SchematicBuilder>(buildList.size());
for (Schematic schematic : buildList) {
BlockHandler handler = schematic.getHandler();
if (handler != null)
builders.add(new SchematicBuilder(schematic, handler));
}
}
public List<SchematicBuilder> getBuilders() {
return Collections.unmodifiableList(builders);
}
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() {
switch (orientation) {
case SOUTH:
return x - schematic.x;
case EAST:
return x - schematic.z;
case WEST:
return x + schematic.z;
default:
return x + schematic.x;
}
}
public int getY() {
return y + schematic.y;
}
public int getZ() {
switch (orientation) {
case SOUTH:
return z - schematic.z;
case EAST:
return z + schematic.x;
case WEST:
return z - schematic.x;
default:
return z + 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(EntityPlayer bcPlayer) {
// if (blockExists()) {
// markComplete();
// return false;
// }
// if (!BlockUtil.canChangeBlock(worldObj, getX(), getY(), getZ()))
// return false;
if (!canBuild())
return false;
boolean built = handler.readBlockFromSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.data, inv, bcPlayer);
if (built) {
markComplete();
}
return built;
}
public boolean isComplete() {
return complete;
}
public void markComplete() {
complete = true;
}
}
}