Skip to content

Commit f8f2371

Browse files
committed
1.0.1
1 parent 756c0ad commit f8f2371

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>cn.wode490390.nukkit</groupId>
88
<artifactId>vipop</artifactId>
99
<packaging>jar</packaging>
10-
<version>1.0.0</version>
10+
<version>1.0.1</version>
1111
<name>Classic Village Populator</name>
1212
<description>This is a plugin that implements the old village feature for Nukkit servers</description>
1313
<url>http://wode490390.cn/</url>

src/main/java/cn/wode490390/nukkit/vipop/ClassicVillagePlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import cn.nukkit.event.level.LevelUnloadEvent;
88
import cn.nukkit.level.Level;
99
import cn.nukkit.level.generator.Generator;
10+
import cn.nukkit.level.generator.Normal;
1011
import cn.nukkit.level.generator.populator.type.Populator;
1112
import cn.nukkit.plugin.PluginBase;
1213
import cn.wode490390.nukkit.vipop.populator.PopulatorVillage;
@@ -52,7 +53,7 @@ public void onLevelLoad(LevelLoadEvent event) {
5253
Level level = event.getLevel();
5354
Generator generator = level.getGenerator();
5455
if (generator.getId() != Generator.TYPE_FLAT && generator.getDimension() == Level.DIMENSION_OVERWORLD) {
55-
populators.add(new PopulatorVillage());
56+
populators.add(new PopulatorVillage(generator.getClass() == Normal.class));
5657
}
5758
this.populators.put(level, populators);
5859
}

src/main/java/cn/wode490390/nukkit/vipop/populator/PopulatorVillage.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public class PopulatorVillage extends Populator {
2222
protected static final int SPACING = 32;
2323
protected static final int SEPARATION = 8;
2424

25+
protected final boolean isNukkitGenerator;
26+
27+
public PopulatorVillage(boolean isNukkitGenerator) {
28+
this.isNukkitGenerator = isNukkitGenerator;
29+
}
30+
2531
@Override
2632
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
2733
//\\ VillageFeature::isFeatureChunk(BiomeSource const &,Random &,ChunkPos const &,uint)
@@ -35,7 +41,7 @@ public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom ra
3541

3642
if (chunkX == cX * SPACING + random.nextBoundedInt(SPACING - SEPARATION) && chunkZ == cZ * SPACING + random.nextBoundedInt(SPACING - SEPARATION)) {
3743
//\\ VillageFeature::createStructureStart(Dimension &,Random &,ChunkPos const &)
38-
VillageStart start = new VillageStart(level, chunkX, chunkZ);
44+
VillageStart start = new VillageStart(level, chunkX, chunkZ, this.isNukkitGenerator);
3945
start.generatePieces(level, chunkX, chunkZ);
4046

4147
if (start.isValid()) { //TODO: serialize nbt
@@ -91,14 +97,16 @@ public static Type byId(int id) {
9197
public static class VillageStart extends StructureStart {
9298

9399
private boolean valid;
100+
private final boolean isNukkitGenerator;
94101

95-
public VillageStart(ChunkManager level, int chunkX, int chunkZ) {
102+
public VillageStart(ChunkManager level, int chunkX, int chunkZ, boolean isNukkitGenerator) {
96103
super(level, chunkX, chunkZ);
104+
this.isNukkitGenerator = isNukkitGenerator;
97105
}
98106

99107
@Override
100108
public void generatePieces(ChunkManager level, int chunkX, int chunkZ) {
101-
VillagePieces.StartPiece start = new VillagePieces.StartPiece(level, 0, this.random, (chunkX << 4) + 2, (chunkZ << 4) + 2, VillagePieces.getStructureVillageWeightedPieceList(this.random, SIZE), SIZE);
109+
VillagePieces.StartPiece start = new VillagePieces.StartPiece(level, 0, this.random, (chunkX << 4) + 2, (chunkZ << 4) + 2, VillagePieces.getStructureVillageWeightedPieceList(this.random, SIZE), SIZE, isNukkitGenerator);
102110
this.pieces.add(start);
103111
start.addChildren(start, this.pieces, this.random);
104112

src/main/java/cn/wode490390/nukkit/vipop/structure/VillagePieces.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,15 @@ abstract static class VillagePiece extends StructurePiece {
233233
protected PopulatorVillage.Type type;
234234
protected boolean isZombieVillage;
235235

236+
protected int yOffset;
237+
236238
protected VillagePiece(StartPiece start, int genDepth) {
237239
super(genDepth);
238240

239241
if (start != null) {
240242
this.type = start.type;
241243
this.isZombieVillage = start.isZombieVillage;
244+
this.yOffset = start.yOffset;
242245
} else {
243246
this.type = PopulatorVillage.Type.PLAINS;
244247
}
@@ -307,21 +310,21 @@ protected int getAverageGroundHeight(ChunkManager level, BoundingBox boundingBox
307310

308311
for (int x = this.boundingBox.x0; x <= this.boundingBox.x1; ++x) {
309312
for (int z = this.boundingBox.z0; z <= this.boundingBox.z1; ++z) {
310-
vec.setComponents(x, 64, z);
313+
vec.setComponents(x, 64 + this.yOffset, z);
311314

312315
if (boundingBox.isInside(vec)) {
313316
BaseFullChunk chunk = level.getChunk(x >> 4, z >> 4);
314317
if (chunk == null) {
315-
sum += 63 + 1 - 1;
318+
sum += 63 + 1 - 1 + this.yOffset;
316319
} else {
317320
int cx = x & 0xf;
318321
int cz = z & 0xf;
319322
int y = chunk.getHighestBlockAt(cx, cz);
320323
int id = chunk.getBlockId(cx, y, cz);
321-
while (Block.transparent[id] && y > 63 + 1 - 1) {
324+
while (Block.transparent[id] && y > 63 + 1 - 1 + this.yOffset) {
322325
id = chunk.getBlockId(cx, --y, cz);
323326
}
324-
sum += Math.max(y, 63 + 1 - 1);
327+
sum += Math.max(y, 63 + 1 - 1 + this.yOffset);
325328
}
326329
++count;
327330
}
@@ -508,7 +511,7 @@ public static class StartPiece extends Well {
508511
public List<StructurePiece> pendingRoads = Lists.newArrayList();
509512

510513
//\\ VillageStart::VillageStart(BiomeSource *,Random &,int,int,int)
511-
public StartPiece(ChunkManager level, int genDepth, NukkitRandom random, int x, int z, List<PieceWeight> availablePieces, int size) {
514+
public StartPiece(ChunkManager level, int genDepth, NukkitRandom random, int x, int z, List<PieceWeight> availablePieces, int size, boolean isNukkitGenerator) {
512515
super(null, 0, random, x, z);
513516
this.world = level;
514517
this.availablePieces = availablePieces;
@@ -533,6 +536,8 @@ public StartPiece(ChunkManager level, int genDepth, NukkitRandom random, int x,
533536
}
534537

535538
this.isZombieVillage = random.nextBoundedInt(50) == 0;
539+
540+
this.yOffset = isNukkitGenerator ? 2 : 0;
536541
}
537542

538543
public StartPiece(CompoundTag tag) {
@@ -1913,28 +1918,28 @@ public boolean postProcess(ChunkManager level, NukkitRandom random, BoundingBox
19131918

19141919
for (int x = this.boundingBox.x0; x <= this.boundingBox.x1; ++x) {
19151920
for (int z = this.boundingBox.z0; z <= this.boundingBox.z1; ++z) {
1916-
BlockVector3 vec = new BlockVector3(x, 64, z);
1921+
BlockVector3 vec = new BlockVector3(x, 64 + this.yOffset, z);
19171922

19181923
if (boundingBox.isInside(vec)) {
19191924
BaseFullChunk chunk = level.getChunk(chunkX, chunkZ);
19201925
if (chunk == null) {
1921-
vec.y = 63 - 1;
1926+
vec.y = 63 - 1 + this.yOffset;
19221927
} else {
19231928
int cx = x & 0xf;
19241929
int cz = z & 0xf;
19251930
int y = chunk.getHighestBlockAt(cx, cz);
19261931
int id = chunk.getBlockId(cx, y, cz);
1927-
while (Block.transparent[id] && y > 63 - 1) {
1932+
while (Block.transparent[id] && y > 63 - 1 + this.yOffset) {
19281933
id = chunk.getBlockId(cx, --y, cz);
19291934
}
19301935
vec.y = y;
19311936
}
19321937

1933-
if (vec.y < 63) {
1934-
vec.y = 63 - 1;
1938+
if (vec.y < 63 + this.yOffset) {
1939+
vec.y = 63 - 1 + this.yOffset;
19351940
}
19361941

1937-
while (vec.y >= 63 - 1) {
1942+
while (vec.y >= 63 - 1 + this.yOffset) {
19381943
int block = level.getBlockIdAt(vec.x, vec.y, vec.z);
19391944

19401945
if (block == Block.GRASS && level.getBlockIdAt(vec.x, vec.y + 1, vec.z) == Block.AIR) {

0 commit comments

Comments
 (0)