Fix crash on dedicated server
This commit is contained in:
parent
87b644834f
commit
9ebeec6fc2
|
|
@ -1,5 +1,7 @@
|
||||||
package org.embeddedt.modernfix.duck;
|
package org.embeddedt.modernfix.duck;
|
||||||
|
|
||||||
|
import net.minecraft.world.storage.SaveFormat;
|
||||||
|
|
||||||
public interface ILevelSave {
|
public interface ILevelSave {
|
||||||
public void runWorldPersistenceHooks();
|
public void runWorldPersistenceHooks(SaveFormat format);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,8 @@ import java.nio.file.Path;
|
||||||
public class LevelSaveMixin implements ILevelSave {
|
public class LevelSaveMixin implements ILevelSave {
|
||||||
@Shadow @Final private Path levelPath;
|
@Shadow @Final private Path levelPath;
|
||||||
|
|
||||||
public void runWorldPersistenceHooks() {
|
public void runWorldPersistenceHooks(SaveFormat format) {
|
||||||
SaveFormat saveFormat = ObfuscationReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getInstance(), "field_71469_aa");
|
((SaveFormatAccessor)format).invokeReadLevelData(this.levelPath.toFile(), (file, dataFixer) -> {
|
||||||
((SaveFormatAccessor)saveFormat).invokeReadLevelData(this.levelPath.toFile(), (file, dataFixer) -> {
|
|
||||||
try {
|
try {
|
||||||
CompoundNBT compoundTag = CompressedStreamTools.readCompressed(file);
|
CompoundNBT compoundTag = CompressedStreamTools.readCompressed(file);
|
||||||
net.minecraftforge.fml.WorldPersistenceHooks.handleWorldDataLoad((SaveFormat.LevelSave)(Object)this, new DummyServerConfiguration(), compoundTag);
|
net.minecraftforge.fml.WorldPersistenceHooks.handleWorldDataLoad((SaveFormat.LevelSave)(Object)this, new DummyServerConfiguration(), compoundTag);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import net.minecraft.world.storage.SaveFormat;
|
||||||
import org.embeddedt.modernfix.ModernFix;
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
import org.embeddedt.modernfix.ModernFixClient;
|
import org.embeddedt.modernfix.ModernFixClient;
|
||||||
import org.embeddedt.modernfix.duck.ILevelSave;
|
import org.embeddedt.modernfix.duck.ILevelSave;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
@ -25,6 +26,8 @@ import java.util.function.Function;
|
||||||
public abstract class MinecraftMixin {
|
public abstract class MinecraftMixin {
|
||||||
@Shadow public abstract Minecraft.PackManager makeServerStem(DynamicRegistries.Impl dynamicRegistries, Function<SaveFormat.LevelSave, DatapackCodec> worldStorageToDatapackFunction, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> quadFunction, boolean vanillaOnly, SaveFormat.LevelSave worldStorage) throws InterruptedException, ExecutionException;
|
@Shadow public abstract Minecraft.PackManager makeServerStem(DynamicRegistries.Impl dynamicRegistries, Function<SaveFormat.LevelSave, DatapackCodec> worldStorageToDatapackFunction, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> quadFunction, boolean vanillaOnly, SaveFormat.LevelSave worldStorage) throws InterruptedException, ExecutionException;
|
||||||
|
|
||||||
|
@Shadow @Final private SaveFormat levelSource;
|
||||||
|
|
||||||
@Redirect(method = "loadLevel(Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DynamicRegistries;builtin()Lnet/minecraft/util/registry/DynamicRegistries$Impl;"))
|
@Redirect(method = "loadLevel(Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DynamicRegistries;builtin()Lnet/minecraft/util/registry/DynamicRegistries$Impl;"))
|
||||||
private DynamicRegistries.Impl useNullRegistry() {
|
private DynamicRegistries.Impl useNullRegistry() {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -35,7 +38,7 @@ public abstract class MinecraftMixin {
|
||||||
if(!creating) {
|
if(!creating) {
|
||||||
ModernFix.LOGGER.warn("Skipping first reload, this is still experimental");
|
ModernFix.LOGGER.warn("Skipping first reload, this is still experimental");
|
||||||
ModernFix.runningFirstInjection = true;
|
ModernFix.runningFirstInjection = true;
|
||||||
((ILevelSave)levelSave).runWorldPersistenceHooks();
|
((ILevelSave)levelSave).runWorldPersistenceHooks(levelSource);
|
||||||
ModernFix.runningFirstInjection = false;
|
ModernFix.runningFirstInjection = false;
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user