-
Notifications
You must be signed in to change notification settings - Fork 497
/
FillerPattern.java
125 lines (104 loc) · 3.22 KB
/
FillerPattern.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
/**
* 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.filler.pattern;
import java.util.Map;
import java.util.TreeMap;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.Template;
import buildcraft.core.utils.StringUtils;
public abstract class FillerPattern implements IFillerPattern {
public static final Map<String, FillerPattern> patterns = new TreeMap<String, FillerPattern>();
private final String tag;
private IIcon icon;
public FillerPattern(String tag) {
this.tag = tag;
patterns.put(getUniqueTag (), this);
}
@Override
public String getDisplayName() {
return StringUtils.localize("fillerpattern." + tag);
}
@Override
public String getUniqueTag() {
return "buildcraft:" + tag;
}
public void registerIcon(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:fillerPatterns/" + tag);
}
@Override
public IIcon getIcon() {
return icon;
}
@Override
public String toString() {
return "Pattern: " + getUniqueTag();
}
/**
* Generates a filling in a given area
*/
public static void fill(int xMin, int yMin, int zMin, int xMax, int yMax,
int zMax, Template template) {
for (int y = yMin; y <= yMax; ++y) {
for (int x = xMin; x <= xMax; ++x) {
for (int z = zMin; z <= zMax; ++z) {
template.contents[x][y][z] = new SchematicMask(true);
}
}
}
}
/**
* Generates an empty in a given area
*/
public static void empty(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Template template) {
int lastX = Integer.MAX_VALUE, lastY = Integer.MAX_VALUE, lastZ = Integer.MAX_VALUE;
for (int y = yMax; y >= yMin; y--) {
for (int x = xMin; x <= xMax; ++x) {
for (int z = zMin; z <= zMax; ++z) {
template.contents[x][y][z] = null;
}
}
}
}
/**
* Generates a flatten in a given area
*/
public static void flatten(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Template template) {
int lastX = Integer.MAX_VALUE, lastY = Integer.MAX_VALUE, lastZ = Integer.MAX_VALUE;
for (int x = xMin; x <= xMax; ++x) {
for (int z = zMin; z <= zMax; ++z) {
for (int y = yMax; y >= yMin; --y) {
template.contents [x][y][z] = new SchematicMask(true);
}
}
}
}
@Override
public Blueprint getBlueprint (Box box, Block block) {
Blueprint result = new Blueprint (box.sizeX(), box.sizeY(), box.sizeZ());
Template tmpl = getTemplate(box);
for (int x = 0; x < box.sizeX(); ++x) {
for (int y = 0; y < box.sizeY(); ++y) {
for (int z = 0; z < box.sizeZ(); ++z) {
if (tmpl.contents[x][y][z] != null) {
result.contents[x][y][z] = SchematicRegistry
.newSchematicBlock(block);
}
}
}
}
return result;
}
}