Skip to content

Commit 7e77838

Browse files
committed
1.0.1
1 parent 81f4df9 commit 7e77838

File tree

3 files changed

+145
-30
lines changed

3 files changed

+145
-30
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>cn.wode490390.nukkit</groupId>
55
<artifactId>theend</artifactId>
6-
<version>1.0.0</version>
6+
<version>1.0.1</version>
77
<name>TheEnd</name>
88
<description>The end plugin for Nukkit</description>
99
<inceptionYear>2018</inceptionYear>
Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
package cn.wode490390.nukkit.theend.populator.theend;
22

3+
import cn.nukkit.Server;
34
import cn.nukkit.level.ChunkManager;
5+
import cn.nukkit.level.Level;
46
import cn.nukkit.level.format.FullChunk;
7+
import cn.nukkit.level.format.generic.BaseFullChunk;
58
import cn.nukkit.level.generator.populator.type.Populator;
69
import cn.nukkit.math.NukkitRandom;
710
import cn.nukkit.math.Vector3;
11+
import cn.nukkit.scheduler.ServerScheduler;
12+
import cn.wode490390.nukkit.theend.task.GenerationTask;
813

914
public class PopulatorPodium extends Populator {
1015

16+
private Level level;
17+
private boolean zero_negativeOne = false;
18+
private boolean negativeOne_negativeOne = false;
19+
private boolean negativeOne_zero = false;
20+
private boolean generated = false;
21+
1122
private boolean actived;
23+
private int y;
1224

1325
public PopulatorPodium() {
1426
this(false);
@@ -27,41 +39,79 @@ public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom ra
2739
if (level.getBlockIdAt(0, y, 0) != END_STONE) {
2840
return;
2941
}
42+
level.setBlockAt(0, y, 0, BEDROCK);
43+
this.level = chunk.getProvider().getLevel();
44+
this.y = y;
3045

31-
for (int i = -1; i <= 32; i++) {
32-
for (int x = -4; x <= 4; x++) {
33-
for (int z = -4; z <= 4; z++) {
34-
int dy = y + i;
35-
double distance = new Vector3(0, y).distance(new Vector3(x, dy, z));
36-
if (distance <= 3.5) {
37-
if (dy < y) {
38-
if (distance <= 2.5) {
39-
level.setBlockAt(x, dy, z, BEDROCK);
40-
} else if (dy < y) {
41-
level.setBlockAt(x, dy, z, END_STONE);
46+
ServerScheduler scheduler = Server.getInstance().getScheduler();
47+
BaseFullChunk zero_negativeOne = this.level.getChunk(0, -1, true);
48+
if (!zero_negativeOne.isGenerated()) {
49+
scheduler.scheduleAsyncTask(null, new GenerationTask(this.level, zero_negativeOne, this));
50+
} else {
51+
this.zero_negativeOne = true;
52+
}
53+
BaseFullChunk negativeOne_negativeOne = this.level.getChunk(-1, -1, true);
54+
if (!negativeOne_negativeOne.isGenerated()) {
55+
scheduler.scheduleAsyncTask(null, new GenerationTask(this.level, negativeOne_negativeOne, this));
56+
} else {
57+
this.negativeOne_negativeOne = true;
58+
}
59+
BaseFullChunk negativeOne_zero = this.level.getChunk(-1, 0, true);
60+
if (!negativeOne_zero.isGenerated()) {
61+
scheduler.scheduleAsyncTask(null, new GenerationTask(this.level, negativeOne_zero, this));
62+
} else {
63+
this.negativeOne_zero = true;
64+
}
65+
this.generate();
66+
}
67+
68+
public void generateChunkCallback(int chunkX, int chunkZ) {
69+
if (chunkX == 0 && chunkZ == -1) {
70+
this.zero_negativeOne = true;
71+
} else if (chunkX == -1 && chunkZ == -1) {
72+
this.negativeOne_negativeOne = true;
73+
} else if (chunkX == -1 && chunkZ == 0) {
74+
this.negativeOne_zero = true;
75+
}
76+
this.generate();
77+
}
78+
79+
private synchronized void generate() {
80+
if (this.zero_negativeOne && this.negativeOne_negativeOne && this.negativeOne_zero && !this.generated) {
81+
this.generated = true;
82+
for (int i = -1; i <= 32; i++) {
83+
for (int x = -4; x <= 4; x++) {
84+
for (int z = -4; z <= 4; z++) {
85+
int dy = this.y + i;
86+
double distance = new Vector3(0, this.y).distance(new Vector3(x, dy, z));
87+
if (distance <= 3.5) {
88+
if (dy < this.y) {
89+
if (distance <= 2.5) {
90+
this.level.setBlockAt(x, dy, z, BEDROCK);
91+
} else if (dy < this.y) {
92+
this.level.setBlockAt(x, dy, z, END_STONE);
93+
}
94+
} else if (dy > this.y) {
95+
this.level.setBlockAt(x, dy, z, AIR);
96+
} else if (distance > 2.5) {
97+
this.level.setBlockAt(x, dy, z, BEDROCK);
98+
} else if (this.actived) {
99+
this.level.setBlockAt(x, dy, z, END_PORTAL);
100+
} else {
101+
this.level.setBlockAt(x, dy, z, AIR);
42102
}
43-
} else if (dy > y) {
44-
level.setBlockAt(x, dy, z, AIR);
45-
} else if (distance > 2.5) {
46-
level.setBlockAt(x, dy, z, BEDROCK);
47-
} else if (this.actived) {
48-
level.setBlockAt(x, dy, z, END_PORTAL);
49-
} else {
50-
level.setBlockAt(x, dy, z, AIR);
51103
}
52104
}
53105
}
54106
}
107+
for (int i = 0; i < 4; ++i) {
108+
this.level.setBlockAt(0, this.y + i, 0, BEDROCK);
109+
}
110+
int torch = this.y + 2;
111+
this.level.setBlockAt(1, torch, 0, TORCH, 1);
112+
this.level.setBlockAt(-1, torch, 0, TORCH, 2);
113+
this.level.setBlockAt(0, torch, 1, TORCH, 3);
114+
this.level.setBlockAt(0, torch, -1, TORCH, 4);
55115
}
56-
57-
for (int i = 0; i < 4; ++i) {
58-
level.setBlockAt(0, y + i, 0, BEDROCK);
59-
}
60-
61-
int torch = y + 2;
62-
level.setBlockAt(1, torch, 0, TORCH, 1);
63-
level.setBlockAt(-1, torch, 0, TORCH, 2);
64-
level.setBlockAt(0, torch, 1, TORCH, 3);
65-
level.setBlockAt(0, torch, -1, TORCH, 4);
66116
}
67117
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package cn.wode490390.nukkit.theend.task;
2+
3+
import cn.nukkit.Server;
4+
import cn.nukkit.level.Level;
5+
import cn.nukkit.level.format.generic.BaseFullChunk;
6+
import cn.nukkit.level.generator.Generator;
7+
import cn.nukkit.level.generator.SimpleChunkManager;
8+
import cn.nukkit.scheduler.AsyncTask;
9+
import cn.wode490390.nukkit.theend.populator.theend.PopulatorPodium;
10+
11+
public class GenerationTask extends AsyncTask {
12+
13+
public boolean state = true;
14+
15+
private final Level level;
16+
private BaseFullChunk chunk;
17+
18+
private PopulatorPodium podium;
19+
20+
public GenerationTask(Level level, BaseFullChunk chunk, PopulatorPodium podium) {
21+
this.chunk = chunk;
22+
this.level = level;
23+
this.podium = podium;
24+
}
25+
26+
@Override
27+
public void onRun() {
28+
this.state = false;
29+
Generator generator = this.level.getGenerator();
30+
if (generator != null) {
31+
SimpleChunkManager manager = (SimpleChunkManager) generator.getChunkManager();
32+
if (manager != null) {
33+
manager.cleanChunks(this.level.getSeed());
34+
synchronized (manager) {
35+
try {
36+
BaseFullChunk chunk = this.chunk;
37+
if (chunk != null) {
38+
synchronized (chunk) {
39+
if (!chunk.isGenerated()) {
40+
manager.setChunk(chunk.getX(), chunk.getZ(), chunk);
41+
generator.generateChunk(chunk.getX(), chunk.getZ());
42+
chunk = manager.getChunk(chunk.getX(), chunk.getZ());
43+
chunk.setGenerated();
44+
}
45+
}
46+
this.chunk = chunk;
47+
this.state = true;
48+
}
49+
} finally {
50+
manager.cleanChunks(this.level.getSeed());
51+
}
52+
}
53+
}
54+
}
55+
}
56+
57+
@Override
58+
public void onCompletion(Server server) {
59+
if (this.state && this.level != null) {
60+
if (this.chunk != null) {
61+
this.podium.generateChunkCallback(this.chunk.getX(), this.chunk.getZ());
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)