Skip to content

Commit

Permalink
Fix bukkit create world
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Feb 2, 2024
1 parent 0b8649d commit ab17b24
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 54 deletions.
62 changes: 11 additions & 51 deletions patches/minecraft/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
+ }
+
+ for (ServerWorld worldserver : this.func_212370_w()) {
+ this.prepareLevels(worldserver.func_72863_F().field_217237_a.field_219266_t, worldserver);
+ this.loadSpawn(worldserver.func_72863_F().field_217237_a.field_219266_t, worldserver);
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
+ }
+
Expand Down Expand Up @@ -287,7 +287,7 @@

+ public AtomicReference<ServerWorld> prepareLevels$serverlevel = new AtomicReference<>(this.func_241755_D_());
+
+ public void prepareLevels(IChunkStatusListener pListener, ServerWorld serverlevel) {
+ public void loadSpawn(IChunkStatusListener pListener, ServerWorld serverlevel) {
+ prepareLevels$serverlevel.set(serverlevel);
+ func_213186_a(pListener);
+ }
Expand Down Expand Up @@ -626,7 +626,7 @@
}

}
@@ -678,17 +_,36 @@
@@ -678,17 +_,39 @@
}

private boolean func_212379_aT() {
Expand All @@ -650,6 +650,9 @@
+
+ private void executeModerately() {
+ this.func_213160_bf();
+ while (!processQueue.isEmpty()) {
+ processQueue.remove().run();
+ }
+ java.util.concurrent.locks.LockSupport.parkNanos("executing tasks", 1000L);
+ }
+ // CraftBukkit end
Expand Down Expand Up @@ -695,7 +698,7 @@
++this.field_71315_w;
this.func_71190_q(p_71217_1_);
if (i - this.field_147142_T >= 5000000000L) {
@@ -785,41 +_,54 @@
@@ -785,41 +_,48 @@

Collections.shuffle(Arrays.asList(agameprofile));
this.field_147147_p.func_151318_b().func_151330_a(agameprofile);
Expand Down Expand Up @@ -745,12 +748,6 @@
this.field_71304_b.func_219895_b("levels");

- for(ServerWorld serverworld : this.func_212370_w()) {
+ // CraftBukkit start
+ // Run tasks that are waiting on processing
+ while (!processQueue.isEmpty()) {
+ processQueue.remove().run();
+ }
+
+ for(ServerWorld serverworld : this.getWorldArray()) {
+ long tickStart = Util.func_211178_c();
this.field_71304_b.func_194340_a(() -> {
Expand Down Expand Up @@ -950,10 +947,11 @@
public DynamicRegistries func_244267_aX() {
return this.field_240767_f_;
}
@@ -1578,4 +_,84 @@
@@ -1577,5 +_,47 @@
@Nullable
public IChatFilter func_244435_a(ServerPlayerEntity p_244435_1_) {
return null;
}
+ }
+
+ @Override
+ public boolean func_213162_bc() {
Expand Down Expand Up @@ -995,43 +993,5 @@
+ }
+ worldInfo.func_76091_d(true);
+ }
+ }
+
+ public void loadSpawn(IChunkStatusListener listener, ServerWorld serverworld) {
+ ServerChunkProvider serverchunkprovider = serverworld.func_72863_F();
+ net.minecraftforge.common.world.StructureSpawnManager.gatherEntitySpawns();
+ this.forceTicks = true;
+ if (serverworld.getWorld().getKeepSpawnInMemory()) {
+ field_147145_h.info(com.mohistmc.util.i18n.i18n.get("minecraftserver.4", (Object) serverworld.func_234923_W_().func_240901_a_()));
+ BlockPos blockpos = serverworld.func_241135_u_();
+ listener.func_219509_a(new ChunkPos(blockpos));
+ serverchunkprovider.func_212863_j_().func_215598_a(500);
+ this.field_211151_aa = Util.func_211177_b();
+ serverchunkprovider.func_217228_a(TicketType.field_219488_a, new ChunkPos(blockpos), 11, Unit.INSTANCE);
+ this.executeModerately();
+ }
+ ServerWorld serverworld1 = serverworld;
+ ForcedChunksSaveData forcedchunkssavedata = serverworld1.func_217481_x().func_215753_b(ForcedChunksSaveData::new, "chunks");
+
+ if (forcedchunkssavedata != null) {
+ LongIterator longiterator = forcedchunkssavedata.func_212438_a().iterator();
+
+ while (longiterator.hasNext()) {
+ long i = longiterator.nextLong();
+ ChunkPos chunkpos = new ChunkPos(i);
+ serverworld1.func_72863_F().func_217206_a(chunkpos, true);
+ }
+ net.minecraftforge.common.world.ForgeChunkManager.reinstatePersistentChunks(serverworld1, forcedchunkssavedata);
+ }
+ MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Load(serverworld1));
+
+ this.executeModerately();
+ if (serverworld.getWorld().getKeepSpawnInMemory()) {
+ listener.func_219510_b();
+ }
+ serverchunkprovider.func_212863_j_().func_215598_a(5);
+ serverworld.func_72891_a(this.func_230536_N_(), this.func_230537_U_());
+ this.forceTicks = false;
+ }
+
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/mohistmc/plugins/WorldCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void openWorldGui(Player p, String name) {
infoLore.add("§bDifficulty §8》 §7" + w.getDifficulty());
infoLore.add("§bPlayers §8》 §7" + w.getPlayers().size());

inv.setItem(pos, ItemAPI.doItem(Material.MAP, 1, 0, "§7》 §6" + w.getName().toString(), infoLore));
inv.setItem(pos, ItemAPI.doItem(Material.MAP, 1, 0, "§7》 §6" + w.getName(), infoLore));
++pos;
infoLore.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,6 @@ public World createWorld(WorldCreator creator) {
console.initWorld(internal, worlddata, worlddata, worlddata.worldGenSettings());

internal.setSpawnSettings(true, true);
getServer().prepareLevels(internal.getChunkSource().chunkMap.progressListener, internal);

getServer().loadSpawn(internal.getChunkSource().chunkMap.progressListener, internal);

pluginManager.callEvent(new WorldLoadEvent(internal.getWorld()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public enum TeleportCause {
* Indicates the teleportation was caused by an event not covered by
* this enum
*/
MOHIST,
UNKNOWN;
}

Expand Down

0 comments on commit ab17b24

Please sign in to comment.