11package cn .wode490390 .nukkit .theend .populator .theend ;
22
3+ import cn .nukkit .Server ;
34import cn .nukkit .level .ChunkManager ;
5+ import cn .nukkit .level .Level ;
46import cn .nukkit .level .format .FullChunk ;
7+ import cn .nukkit .level .format .generic .BaseFullChunk ;
58import cn .nukkit .level .generator .populator .type .Populator ;
69import cn .nukkit .math .NukkitRandom ;
710import cn .nukkit .math .Vector3 ;
11+ import cn .nukkit .scheduler .ServerScheduler ;
12+ import cn .wode490390 .nukkit .theend .task .GenerationTask ;
813
914public 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}
0 commit comments