Remove (usually) redundant datapack reload on world creation screen

The second, Forge-added reload is enough in all cases except when
mods supply invalid datapacks.

In this edge case, we will need to reload server resources when the
user requests to revert to vanilla
This commit is contained in:
embeddedt 2023-03-18 19:53:07 -04:00
parent 214015dfe9
commit bc1c70bd0c
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 34 additions and 0 deletions

View File

@ -24,6 +24,7 @@ public class ModernFixEarlyConfig {
this.addMixinRule("feature.reduce_loading_screen_freezes", false);
this.addMixinRule("feature.direct_stack_trace", false);
this.addMixinRule("perf.fast_registry_validation", true);
this.addMixinRule("perf.skip_first_datapack_reload", true);
this.addMixinRule("perf.use_integrated_resources", true);
this.addMixinRule("perf.remove_biome_temperature_cache", true);
this.addMixinRule("perf.reduce_blockstate_cache_rebuilds", true);

View File

@ -0,0 +1,32 @@
package org.embeddedt.modernfix.mixin.perf.skip_first_datapack_reload;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Lifecycle;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
import net.minecraft.client.gui.screens.worldselection.WorldCreationContext;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldLoader;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import org.embeddedt.modernfix.ModernFix;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
@Mixin(CreateWorldScreen.class)
public class CreateWorldScreenMixin {
@Redirect(method = "openFresh", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/WorldLoader;load(Lnet/minecraft/server/WorldLoader$InitConfig;Lnet/minecraft/server/WorldLoader$WorldDataSupplier;Lnet/minecraft/server/WorldLoader$ResultFactory;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
private static CompletableFuture<WorldCreationContext> doLoad(WorldLoader.InitConfig config, WorldLoader.WorldDataSupplier<WorldGenSettings> supplier, WorldLoader.ResultFactory<WorldGenSettings, WorldCreationContext> factory, Executor backgroundExecutor, Executor mainExecutor) {
ModernFix.LOGGER.warn("Skipping first datapack reload");
// Make sure to configure the pack repository as though the load happened
MinecraftServer.configurePackRepository(config.packConfig().packRepository(), config.packConfig().initialDataPacks(), config.packConfig().safeMode());
Pair<WorldGenSettings, RegistryAccess.Frozen> creationPair = supplier.get(null, null);
WorldGenSettings settings = creationPair.getFirst();
// Don't load any datapack resources, since Forge is about to do it themselves
WorldCreationContext context = new WorldCreationContext(settings, Lifecycle.stable(), creationPair.getSecond(), null);
return CompletableFuture.completedFuture(context);
}
}

View File

@ -60,6 +60,7 @@
"perf.cache_model_materials.MultipartMixin",
"perf.faster_texture_stitching.StitcherMixin",
"perf.use_integrated_resources.LootTableHelperMixin",
"perf.skip_first_datapack_reload.CreateWorldScreenMixin",
"perf.faster_singleplayer_load.MinecraftServerMixin"
],
"injectors": {