/
PlotGen.java
165 lines (138 loc) · 4.93 KB
/
PlotGen.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
package com.guntherdw.bukkit.tweakcraft.Worlds.Generators;
import com.guntherdw.bukkit.tweakcraft.Worlds.WorldManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
import java.util.Random;
/**
* @author GuntherDW
*/
public class PlotGen extends FlatGen {
private WorldManager wm = null;
private byte toplayer = (byte) Material.GRASS.getId();
private byte normal = (byte) Material.DIRT.getId();
private int height = 64;
private boolean bedrockBottom = true;
private int plotSize = 32;
private int plotSize_parsed = plotSize + 7;
@Override
public boolean isBedrockBottom() {
return bedrockBottom;
}
public void setPlotSize(int plotSize) {
this.plotSize = plotSize;
this.plotSize_parsed = plotSize + 7;
}
@Override
public void setBedrockBottom(boolean bedrockBottom) {
this.bedrockBottom = bedrockBottom;
}
@Override
public void assignWorldManager(WorldManager instance) {
this.wm = instance;
}
@Override
public void setToplayer(byte md) {
toplayer = md;
}
@Override
public void setNormal(byte md) {
normal = md;
}
@Override
public void setmapHeight(int height) {
this.height = height;
}
@Override
public WorldManager getWm() {
return wm;
}
@Override
public int getHeight() {
return height;
}
@Override
public byte getNormal() {
return normal;
}
@Override
public byte getToplayer() {
return toplayer;
}
@Deprecated
@Override
public byte[] generate(World world, Random random, int x, int z) {
return null;
}
@Override
public short[][] generateExtBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) {
return null;
}
boolean isBorder(int x, int z) {
return ( x % plotSize_parsed == 0) || ( z % plotSize_parsed == 0)
|| ((x + 1) % plotSize_parsed == 0) || ((z + 1) % plotSize_parsed == 0)
|| ((x + 2) % plotSize_parsed == 0) || ((z + 2) % plotSize_parsed == 0)
|| ((x - 1) % plotSize_parsed == 0) || ((z - 1) % plotSize_parsed == 0)
|| ((x - 2) % plotSize_parsed == 0) || ((z - 2) % plotSize_parsed == 0);
}
boolean isDefiniteBorder(int x, int z) {
return ((x + 3) % plotSize_parsed == 0) || ((z + 3) % plotSize_parsed == 0)
|| ((x - 3) % plotSize_parsed == 0) || ((z - 3) % plotSize_parsed == 0);
}
@Override
public byte[][] generateBlockSections(World world, Random random, int cx, int cz, BiomeGrid biomes) {
int maxHeight = world.getMaxHeight();
byte[][] result = new byte[maxHeight / 16][];
int realChunkX = cx << 4;
int realChunkZ = cz << 4;
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < maxHeight; y++) {
if (y == 0 && bedrockBottom)
setBlock(result, x, y, z, (byte) 7);
else if (y < height)
setBlock(result, x, y, z, normal);
else if (y == height)
setBlock(result, x, y, z, toplayer);
else
setBlock(result, x, y, z, (byte) 0);
if(isBorder(realChunkX + x, realChunkZ + z) && y == height) {
setBlock(result, x, y, z, (byte) Material.WOOD.getId());
} else if(isDefiniteBorder(realChunkX + x, realChunkZ + z) && y == height) {
setBlock(result, x, y, z, (byte) Material.DOUBLE_STEP.getId());
} /* else if(isDefiniteBorder(realChunkZ + x, realChunkZ + z) && y == height + 1) {
if(!isBorder(realChunkX + x, realChunkZ + z))
setBlock(result, x, y, z, (byte) Material.STEP.getId());
} */
}
}
}
// return null; // Default - returns null, which drives call to generate()
return result;
}
@Override
public void setBlock(byte[][] result, int x, int y, int z, byte blkid) {
if (result[y >> 4] == null) {
result[y >> 4] = new byte[4096];
}
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
}
@Override
public byte getBlock(byte[][] result, int x, int y, int z) {
if (result[y >> 4] == null) {
return (byte) 0;
}
return result[y >> 4][((y & 0xF) << 8) | (z << 4) | x];
}
@Override
public Location getFixedSpawnLocation(World world, Random random) {
int x = random.nextInt(200) - 100;
int z = random.nextInt(200) - 100;
int y = world.getHighestBlockYAt(x, z);
return new Location(world, x, y, z);
}
public int getPlotSize() {
return plotSize;
}
}