Skip to content

Commit

Permalink
Rewriting multiple worlds (50%)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Jan 26, 2024
1 parent ae57ebd commit 5f69591
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 221 deletions.
106 changes: 63 additions & 43 deletions patches/minecraft/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -201,29 +201,44 @@
}

}
@@ -333,6 +_,7 @@
@@ -333,9 +_,12 @@
}

ServerWorld serverworld = new ServerWorld(this, this.field_213217_au, this.field_71310_m, iserverworldinfo, World.field_234918_g_, dimensiontype, p_240787_1_, chunkgenerator, flag, j, list, true);
+ ForgeInjectBukkit.addEnumEnvironment();
+ ForgeInjectBukkit.addEnumEnvironment(this.field_240768_i_.func_230418_z_().func_236224_e_()); // Mohist register mods world
+ this.initWorld(serverworld, iserverworldinfo, this.field_240768_i_, dimensiongeneratorsettings); // Mohist
this.field_71305_c.put(World.field_234918_g_, serverworld);
DimensionSavedDataManager dimensionsaveddatamanager = serverworld.func_217481_x();
this.func_213204_a(dimensionsaveddatamanager);
@@ -371,13 +_,22 @@
+ this.server.scoreboardManager = new org.bukkit.craftbukkit.v1_16_R3.scoreboard.CraftScoreboardManager(this, serverworld.func_96441_U());
this.field_229733_al_ = new CommandStorage(dimensionsaveddatamanager);
WorldBorder worldborder = serverworld.func_175723_af();
worldborder.func_235926_a_(iserverworldinfo.func_230398_q_());
@@ -371,13 +_,31 @@
RegistryKey<World> registrykey1 = RegistryKey.func_240903_a_(Registry.field_239699_ae_, registrykey.func_240901_a_());
DimensionType dimensiontype1 = entry.getValue().func_236063_b_();
ChunkGenerator chunkgenerator1 = entry.getValue().func_236064_c_();
- DerivedWorldInfo derivedworldinfo = new DerivedWorldInfo(this.field_240768_i_, iserverworldinfo);
- ServerWorld serverworld1 = new ServerWorld(this, this.field_213217_au, this.field_71310_m, derivedworldinfo, registrykey1, dimensiontype1, p_240787_1_, chunkgenerator1, flag, j, ImmutableList.of(), false);
+ DerivedWorldInfo derivedworldinfo = new DerivedWorldInfo(this.field_240768_i_, iserverworldinfo, DimensionType.func_236031_a_(registrykey1, this.field_71310_m.getWorldDir().toFile()).getName());
ServerWorld serverworld1 = new ServerWorld(this, this.field_213217_au, this.field_71310_m, derivedworldinfo, registrykey1, dimensiontype1, p_240787_1_, chunkgenerator1, flag, j, ImmutableList.of(), false);
+ String name = (registrykey1 == World.field_234919_h_ ? "DIM1" : "DIM-1");
+ if (registrykey1 == World.field_234919_h_) {
+ if (!this.func_71255_r()) {
+ continue;
+ }
+ } else if (registrykey1 == World.field_234920_i_) {
+ if (!this.server.getAllowEnd()) {
+ continue;
+ }
+ }
+ World.setGeneratorAndEnv(this.server.getGenerator(name), ForgeInjectBukkit.environment.get(registrykey1));
+ // Mohist start - split calculate for ServerLeverl Preparing
+ IChunkStatusListener mohist$progressListener = this.field_213220_d.create(11);
+ ServerWorld serverworld1 = new ServerWorld(this, this.field_213217_au, this.field_71310_m, derivedworldinfo, registrykey1, dimensiontype1, mohist$progressListener, chunkgenerator1, flag, j, ImmutableList.of(), false);
+ this.initWorld(serverworld1, derivedworldinfo, this.field_240768_i_, dimensiongeneratorsettings);
+ // Mohist end
worldborder.func_177737_a(new IBorderListener.Impl(serverworld1.func_175723_af()));
this.field_71305_c.put(registrykey1, serverworld1);
+ if (this.server.scoreboardManager == null) {
+ this.server.scoreboardManager = new org.bukkit.craftbukkit.v1_16_R3.scoreboard.CraftScoreboardManager(this, serverworld1.func_96441_U());
+ }
+ if (serverworld1.generator != null) {
+ serverworld1.getWorld().getPopulators().addAll(serverworld1.generator.getDefaultPopulators(serverworld1.getWorld()));
+ }
}
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Load(field_71305_c.get(registrykey)));
}
Expand Down Expand Up @@ -251,62 +266,67 @@
}

boolean flag = false;
@@ -452,8 +_,10 @@
@@ -451,42 +_,60 @@
iserverworldinfo.func_230392_a_(GameType.SPECTATOR);
}

+ public AtomicReference<ServerWorld> prepareLevels$serverlevel = new AtomicReference<>(this.func_241755_D_());
+
+ public void prepareLevels(IChunkStatusListener pListener, ServerWorld serverlevel) {
+ prepareLevels$serverlevel.set(serverlevel);
+ func_213186_a(pListener);
+ }
+
private void func_213186_a(IChunkStatusListener p_213186_1_) {
+ net.minecraftforge.common.world.StructureSpawnManager.gatherEntitySpawns();
ServerWorld serverworld = this.func_241755_D_();
- ServerWorld serverworld = this.func_241755_D_();
- field_147145_h.info("Preparing start region for dimension {}", (Object)serverworld.func_234923_W_().func_240901_a_());
+ this.markWorldsDirty();
+ net.minecraftforge.common.world.StructureSpawnManager.gatherEntitySpawns();
+ ServerWorld serverworld = prepareLevels$serverlevel.getAndSet(this.func_241755_D_());
+ MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Load(serverworld));
+ this.forceTicks = true;
+ field_147145_h.info(com.mohistmc.util.i18n.i18n.get("minecraftserver.4", serverworld.func_234923_W_().func_240901_a_()));
BlockPos blockpos = serverworld.func_241135_u_();
p_213186_1_.func_219509_a(new ChunkPos(blockpos));
ServerChunkProvider serverchunkprovider = serverworld.func_72863_F();
@@ -461,32 +_,41 @@
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);
- serverchunkprovider.func_217228_a(TicketType.field_219488_a, new ChunkPos(blockpos), 11, Unit.INSTANCE);
-
- while(serverchunkprovider.func_217229_b() != 441) {
- this.field_211151_aa = Util.func_211177_b() + 10L;
- this.func_213202_o();
+ while(serverchunkprovider.func_217229_b() < 441) {
+ // CraftBukkit start
+ this.executeModerately();
+ // CraftBukkit end
+ if (serverworld.getWorld().getKeepSpawnInMemory()) {
+ serverchunkprovider.func_217228_a(TicketType.field_219488_a, new ChunkPos(blockpos), 11, Unit.INSTANCE);
+ while (serverchunkprovider.func_217229_b() < 441) {
+ // CraftBukkit start
+ this.executeModerately();
+ // CraftBukkit end
+ }
}

- this.field_211151_aa = Util.func_211177_b() + 10L;
- this.func_213202_o();
-
+ // CraftBukkit start
+ //this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
+ this.executeModerately();
+ if (true) {
+ ForcedChunksSaveData forcedchunkssavedata = serverworld.func_217481_x().func_215753_b(ForcedChunksSaveData::new, "chunks");

- for(ServerWorld serverworld1 : this.field_71305_c.values()) {
- ForcedChunksSaveData forcedchunkssavedata = serverworld1.func_217481_x().func_215753_b(ForcedChunksSaveData::new, "chunks");
- if (forcedchunkssavedata != null) {
- LongIterator longiterator = forcedchunkssavedata.func_212438_a().iterator();
-
if (forcedchunkssavedata != null) {
LongIterator longiterator = forcedchunkssavedata.func_212438_a().iterator();
- while(longiterator.hasNext()) {
- long i = longiterator.nextLong();
- ChunkPos chunkpos = new ChunkPos(i);
+ while (longiterator.hasNext()) {
long i = longiterator.nextLong();
ChunkPos chunkpos = new ChunkPos(i);
- serverworld1.func_72863_F().func_217206_a(chunkpos, true);
+ // CraftBukkit start
+ //this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
+ this.executeModerately();
+ for (ServerWorld serverworld1 : this.field_71305_c.values()) {
+ if (serverworld1.getWorld().getKeepSpawnInMemory()) {
+ 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);
+ serverworld.func_72863_F().func_217206_a(chunkpos, true);
}
+ net.minecraftforge.common.world.ForgeChunkManager.reinstatePersistentChunks(serverworld, forcedchunkssavedata);
}
+ MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.WorldEvent.Load(serverworld1));
}

- this.field_211151_aa = Util.func_211177_b() + 10L;
Expand Down
29 changes: 29 additions & 0 deletions patches/minecraft/net/minecraft/world/DimensionType.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- a/net/minecraft/world/DimensionType.java
+++ b/net/minecraft/world/DimensionType.java
@@ -1,5 +_,6 @@
package net.minecraft.world;

+import com.mohistmc.util.Level2LevelStem;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Dynamic;
@@ -56,8 +_,8 @@
public static final RegistryKey<DimensionType> field_236000_d_ = RegistryKey.func_240903_a_(Registry.field_239698_ad_, new ResourceLocation("the_nether"));
public static final RegistryKey<DimensionType> field_236001_e_ = RegistryKey.func_240903_a_(Registry.field_239698_ad_, new ResourceLocation("the_end"));
public static final DimensionType field_236004_h_ = new DimensionType(OptionalLong.empty(), true, false, false, true, 1.0D, false, false, true, false, true, 256, ColumnFuzzedBiomeMagnifier.INSTANCE, BlockTags.field_241277_aC_.func_230234_a_(), field_242710_a, 0.0F);
- protected static final DimensionType field_236005_i_ = new DimensionType(OptionalLong.of(18000L), false, true, true, false, 8.0D, false, true, false, true, false, 128, FuzzedBiomeMagnifier.INSTANCE, BlockTags.field_241278_aD_.func_230234_a_(), field_242711_b, 0.1F);
- protected static final DimensionType field_236006_j_ = new DimensionType(OptionalLong.of(6000L), false, false, false, false, 1.0D, true, false, false, false, true, 256, FuzzedBiomeMagnifier.INSTANCE, BlockTags.field_241279_aE_.func_230234_a_(), field_242712_c, 0.0F);
+ public static final DimensionType field_236005_i_ = new DimensionType(OptionalLong.of(18000L), false, true, true, false, 8.0D, false, true, false, true, false, 128, FuzzedBiomeMagnifier.INSTANCE, BlockTags.field_241278_aD_.func_230234_a_(), field_242711_b, 0.1F);
+ public static final DimensionType field_236006_j_ = new DimensionType(OptionalLong.of(6000L), false, false, false, false, 1.0D, true, false, false, false, true, 256, FuzzedBiomeMagnifier.INSTANCE, BlockTags.field_241279_aE_.func_230234_a_(), field_242712_c, 0.0F);
public static final RegistryKey<DimensionType> field_241497_i_ = RegistryKey.func_240903_a_(Registry.field_239698_ad_, new ResourceLocation("overworld_caves"));
protected static final DimensionType field_241498_j_ = new DimensionType(OptionalLong.empty(), true, true, false, true, 1.0D, false, false, true, false, true, 256, ColumnFuzzedBiomeMagnifier.INSTANCE, BlockTags.field_241277_aC_.func_230234_a_(), field_242710_a, 0.0F);
public static final Codec<Supplier<DimensionType>> field_236002_f_ = RegistryKeyCodec.func_241794_a_(Registry.field_239698_ad_, field_235997_a_);
@@ -185,7 +_,7 @@
} else if (p_236031_0_ == World.field_234920_i_) {
return new File(p_236031_1_, "DIM1");
} else {
- return p_236031_0_ == World.field_234919_h_ ? new File(p_236031_1_, "DIM-1") : new File(p_236031_1_, "dimensions/" + p_236031_0_.func_240901_a_().func_110624_b() + "/" + p_236031_0_.func_240901_a_().func_110623_a());
+ return Level2LevelStem.checkPath(p_236031_0_ == World.field_234919_h_ ? new File(p_236031_1_, "DIM-1") : new File(p_236031_1_, "dimensions/" + p_236031_0_.func_240901_a_().func_110624_b() + "/" + p_236031_0_.func_240901_a_().func_110623_a()));
}
}

Loading

0 comments on commit 5f69591

Please sign in to comment.