88import io .izzel .arclight .common .bridge .core .inventory .IInventoryBridge ;
99import io .izzel .arclight .common .bridge .core .server .MinecraftServerBridge ;
1010import io .izzel .arclight .common .bridge .core .world .ExplosionBridge ;
11- import io .izzel .arclight .common .bridge .core .world .IWorldBridge ;
1211import io .izzel .arclight .common .bridge .core .world .level .levelgen .flat .FlatLevelGeneratorSettingsBridge ;
1312import io .izzel .arclight .common .bridge .core .world .server .ServerChunkProviderBridge ;
1413import io .izzel .arclight .common .bridge .core .world .server .ServerWorldBridge ;
7372import org .bukkit .Bukkit ;
7473import org .bukkit .Location ;
7574import org .bukkit .World ;
75+ import org .bukkit .craftbukkit .v .CraftWorld ;
7676import org .bukkit .craftbukkit .v .block .CraftBlockState ;
7777import org .bukkit .craftbukkit .v .entity .CraftHumanEntity ;
7878import org .bukkit .craftbukkit .v .event .CraftEventFactory ;
@@ -157,7 +157,6 @@ public ResourceKey<LevelStem> getTypeKey() {
157157 craftBridge .bridge$offerGeneratorCache (worldInfo .getLevelName (), gen );
158158 craftBridge .bridge$offerBiomeProviderCache (worldInfo .getLevelName (), biomeProvider );
159159 arclight$constructor (server , backgroundExecutor , levelSave , worldInfo , dimension , levelStem , statusListener , isDebug , seed , specialSpawners , shouldBeTicking , seq );
160- bridge$getWorld ();
161160 }
162161
163162 // Support custom chunk generator; in consistency with CraftBukkit
@@ -168,51 +167,62 @@ public ResourceKey<LevelStem> getTypeKey() {
168167 @ Decorate (method = "<init>" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/world/level/dimension/LevelStem;generator()Lnet/minecraft/world/level/chunk/ChunkGenerator;" ))
169168 private ChunkGenerator arclight$initChunkGenerator (LevelStem instance , @ Local (ordinal = -1 ) MinecraftServer server , @ Local (ordinal = -1 ) ServerLevelData worldInfo ) throws Throwable {
170169 // Pulling up world info init since level info is used when selecting ChunkGenerator.
171- if (worldInfo instanceof PrimaryLevelData primary ) {
172- this .K = primary ;
170+ if (arclight$isActual ()) {
171+ if (worldInfo instanceof PrimaryLevelData primary ) {
172+ this .K = primary ;
173+ } else {
174+ // damn spigot again
175+ this .K = DelegateWorldInfo .wrap (worldInfo );
176+ }
173177 } else {
174- // damn spigot again
175- this .K = DelegateWorldInfo .wrap (worldInfo );
178+ this .K = null ;
176179 }
177180
178- var craftBridge = (CraftServerBridge ) (Object ) ((MinecraftServerBridge ) server ).bridge$getServer ();
179-
180- this .biomeProvider = craftBridge .bridge$consumeBiomeProviderCache (worldInfo .getLevelName ());
181- this .generator = craftBridge .bridge$consumeGeneratorCache (worldInfo .getLevelName ());
182- this .environment = craftBridge .bridge$consumeEnvironmentCache (worldInfo .getLevelName ());
183-
184- if (this .environment == null ) {
185- // Select world environment for vanilla/mod world creation
186- if (instance .type ().is (LevelStem .OVERWORLD .location ())) {
187- this .environment = World .Environment .NORMAL ;
188- } else if (instance .type ().is (LevelStem .NETHER .location ())) {
189- this .environment = World .Environment .NETHER ;
190- } else if (instance .type ().is (LevelStem .END .location ())) {
191- this .environment = World .Environment .THE_END ;
192- } else {
193- // Don't use CUSTOM; it's not even supported in Multiverse
194- // this.environment = World.Environment.CUSTOM;
195- this .environment = World .Environment .NORMAL ;
181+ if (arclight$isActual ()) {
182+ var craftBridge = (CraftServerBridge ) (Object ) ((MinecraftServerBridge ) server ).bridge$getServer ();
183+
184+ this .biomeProvider = craftBridge .bridge$consumeBiomeProviderCache (worldInfo .getLevelName ());
185+ this .generator = craftBridge .bridge$consumeGeneratorCache (worldInfo .getLevelName ());
186+ this .environment = craftBridge .bridge$consumeEnvironmentCache (worldInfo .getLevelName ());
187+
188+ if (this .environment == null ) {
189+ // Select world environment for vanilla/mod world creation
190+ if (instance .type ().is (LevelStem .OVERWORLD .location ())) {
191+ this .environment = World .Environment .NORMAL ;
192+ } else if (instance .type ().is (LevelStem .NETHER .location ())) {
193+ this .environment = World .Environment .NETHER ;
194+ } else if (instance .type ().is (LevelStem .END .location ())) {
195+ this .environment = World .Environment .THE_END ;
196+ } else {
197+ // Don't use CUSTOM; it's not even supported in Multiverse
198+ // this.environment = World.Environment.CUSTOM;
199+ this .environment = World .Environment .NORMAL ;
200+ }
196201 }
197202 }
198203
199- // Data needed by getWorld() are all initialized for possible creating CraftWorld.
200- // CraftBukkit start: select custom chunk generator
201204 ChunkGenerator raw = (ChunkGenerator ) DecorationOps .callsite ().invoke (instance );
202- if (biomeProvider != null ) {
203- BiomeSource biomeSource = new CustomWorldChunkManager (getWorld (), biomeProvider , getServer ().registryAccess ().registryOrThrow (Registries .BIOME ));
204- if (raw instanceof NoiseBasedChunkGenerator noise ) {
205- raw = new NoiseBasedChunkGenerator (biomeSource , noise .settings );
206- } else if (raw instanceof FlatLevelSource flat ) {
207- raw = new FlatLevelSource (((FlatLevelGeneratorSettingsBridge )flat .settings ()).bridge$withBiomeSource (biomeSource ));
208- } else {
209- ArclightServer .LOGGER .warn ("Level {} has unknown customized generator -- requested biome provider won't be satisfied." , this .serverLevelData .getLevelName ());
205+ if (arclight$isActual ()) {
206+ // Data needed by getWorld() are all initialized for possible creating CraftWorld.
207+ // CraftBukkit start: select custom chunk generator
208+ if (biomeProvider != null ) {
209+ BiomeSource biomeSource = new CustomWorldChunkManager (getWorld (), biomeProvider , getServer ().registryAccess ().registryOrThrow (Registries .BIOME ));
210+ if (raw instanceof NoiseBasedChunkGenerator noise ) {
211+ raw = new NoiseBasedChunkGenerator (biomeSource , noise .settings );
212+ } else if (raw instanceof FlatLevelSource flat ) {
213+ raw = new FlatLevelSource (((FlatLevelGeneratorSettingsBridge ) flat .settings ()).bridge$withBiomeSource (biomeSource ));
214+ } else {
215+ ArclightServer .LOGGER .warn ("Level {} has unknown customized generator -- requested biome provider won't be satisfied." , this .serverLevelData .getLevelName ());
216+ }
210217 }
218+ if (generator != null ) {
219+ raw = new CustomChunkGenerator ((ServerLevel ) (Object ) this , raw , generator );
220+ }
221+ // CraftBukkit end
222+
223+ // Now we create the CraftWorld
224+ this .world = new CraftWorld ((ServerLevel ) (Object ) this , generator , biomeProvider , environment );
211225 }
212- if (generator != null ) {
213- raw = new CustomChunkGenerator ((ServerLevel )(Object ) this , raw , generator );
214- }
215- // CraftBukkit end
216226 return raw ;
217227 }
218228
@@ -225,7 +235,7 @@ public ResourceKey<LevelStem> getTypeKey() {
225235 private void arclight$init (MinecraftServer minecraftServer , Executor backgroundExecutor , LevelStorageSource .LevelStorageAccess levelSave , ServerLevelData worldInfo , ResourceKey <Level > dimension , LevelStem levelStem , ChunkProgressListener statusListener , boolean isDebug , long seed , List <CustomSpawner > specialSpawners , boolean shouldBeTicking , RandomSequences seq , CallbackInfo ci ) {
226236 this .pvpMode = minecraftServer .isPvpAllowed ();
227237 this .convertable = levelSave ;
228- if (this .dragonFight == null && this .environment == World .Environment .THE_END ) {
238+ if (arclight$isActual () && this .dragonFight == null && this .environment == World .Environment .THE_END ) {
229239 this .dragonFight = new EndDragonFight ((ServerLevel )(Object ) this , K .worldGenOptions ().seed (), K .endDragonFightData ());
230240 }
231241 var typeKey = ((LevelStorageSourceBridge .LevelStorageAccessBridge ) levelSave ).bridge$getTypeKey ();
@@ -251,9 +261,11 @@ public ResourceKey<LevelStem> getTypeKey() {
251261 this .uuid = WorldUUID .getUUID (levelSave .getDimensionPath (this .dimension ()).toFile ());
252262 ((ServerChunkProviderBridge ) this .chunkSource ).bridge$setViewDistance (spigotConfig .viewDistance );
253263 ((ServerChunkProviderBridge ) this .chunkSource ).bridge$setSimulationDistance (spigotConfig .simulationDistance );
254- ((WorldInfoBridge ) this .K ).bridge$setWorld ((ServerLevel ) (Object ) this );
255- var data = this .getDataStorage ().computeIfAbsent (LevelPersistentData .factory (), "bukkit_pdc" );
256- this .bridge$getWorld ().readBukkitValues (data .getTag ());
264+ if (arclight$isActual ()) {
265+ ((WorldInfoBridge ) this .K ).bridge$setWorld ((ServerLevel ) (Object ) this );
266+ var data = this .getDataStorage ().computeIfAbsent (LevelPersistentData .factory (), "bukkit_pdc" );
267+ this .bridge$getWorld ().readBukkitValues (data .getTag ());
268+ }
257269 }
258270
259271 @ Inject (method = "saveLevelData" , at = @ At ("RETURN" ))
@@ -439,7 +451,7 @@ public <T extends ParticleOptions> int sendParticles(T type, double posX, double
439451 return ;
440452 }
441453 CreatureSpawnEvent .SpawnReason spawnReason = reason == null ? CreatureSpawnEvent .SpawnReason .DEFAULT : reason ;
442- if (!DistValidate . isValid ( this )) {
454+ if (!arclight$isActual ( )) {
443455 return ;
444456 }
445457 ((EntityBridge ) entityIn ).arclight$onAddedToLevel ();
0 commit comments