Skip to content

Commit

Permalink
Early Capture pf DynamicRegistry from Disk Load as an interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Jun 16, 2024
1 parent c9b950b commit 7941250
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author = masa
mod_file_name = malilib-fabric

# Current mod version
mod_version = 0.19.999-sakura.1
mod_version = 0.19.999-sakura.2

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 18 additions & 0 deletions src/main/java/fi/dy/masa/malilib/event/WorldLoadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import javax.annotation.Nullable;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.registry.DynamicRegistryManager;
import fi.dy.masa.malilib.MaLiLib;
import fi.dy.masa.malilib.config.ConfigManager;
import fi.dy.masa.malilib.interfaces.IWorldLoadListener;

Expand Down Expand Up @@ -50,6 +52,22 @@ public void unregisterWorldLoadPostHandler(IWorldLoadListener listener)
this.worldLoadPostHandlers.remove(listener);
}

/**
* NOT PUBLIC API - DO NOT CALL
*/
public void onWorldLoadImmutable(DynamicRegistryManager.Immutable immutable)
{
MaLiLib.printDebug("WorldLoadHandler#onWorldLoadImmutable(): Captured Immutable DynamicRegistryManager from SaveLoader");

if (this.worldLoadPreHandlers.isEmpty() == false)
{
for (IWorldLoadListener listener : this.worldLoadPreHandlers)
{
listener.onWorldLoadImmutable(immutable);
}
}
}

/**
* NOT PUBLIC API - DO NOT CALL
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
import javax.annotation.Nullable;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.registry.DynamicRegistryManager;

public interface IWorldLoadListener
{
/**
* Called before the IntegratedServer is launched just after the inital reading of the World Save Loader
* @param immutable (Immutable Combined Dynamic Registry Manager)
*/
default void onWorldLoadImmutable(DynamicRegistryManager.Immutable immutable) {}

/**
* Called when the client world is going to be changed,
* before the reference has been changed
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/fi/dy/masa/malilib/mixin/MixinMinecraftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import net.minecraft.client.gui.screen.DownloadingTerrainScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.server.SaveLoader;
import net.minecraft.world.level.storage.LevelStorage;
import fi.dy.masa.malilib.event.InitializationHandler;
import fi.dy.masa.malilib.event.TickHandler;
import fi.dy.masa.malilib.event.WorldLoadHandler;
Expand All @@ -30,6 +33,14 @@ private void onInitComplete(RunArgs args, CallbackInfo ci)
((InitializationHandler) InitializationHandler.getInstance()).onGameInitDone();
}

@Inject(method = "startIntegratedServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/UserCache;setUseRemote(Z)V",
shift = At.Shift.BEFORE))
private void onStartIntegratedServer(LevelStorage.Session session, ResourcePackManager dataPackManager, SaveLoader saveLoader, boolean newWorld, CallbackInfo ci)
{
// Capture CombinedDynamicRegistry
((WorldLoadHandler) WorldLoadHandler.getInstance()).onWorldLoadImmutable(saveLoader.combinedDynamicRegistries().getCombinedRegistryManager());
}

@Inject(method = "tick()V", at = @At("RETURN"))
private void onPostKeyboardInput(CallbackInfo ci)
{
Expand Down

0 comments on commit 7941250

Please sign in to comment.