Cache the mod world directory in getWorldDirectory.
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-import org.spongepowered.common.SpongeImpl;
import org.spongepowered.common.interfaces.IMixinSaveHandler;
import org.spongepowered.common.plugin.PluginContainerExtension;
import org.spongepowered.mod.SpongeMod;
-import org.spongepowered.mod.interfaces.IMixinLoadController;
import java.io.File;
@Shadow @Final protected DataFixer dataFixer;
@Shadow @Final private File worldDirectory;
+ private File modWorldDirectory = null;
@Redirect(method = "saveWorldInfoWithPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;handleWorldDataSave"
+ "(Lnet/minecraft/world/storage/SaveHandler;Lnet/minecraft/world/storage/WorldInfo;Lnet/minecraft/nbt/NBTTagCompound;)V", remap = false))
@@ -82,8 +81,12 @@ public void onGetWorldDirectory(CallbackInfoReturnable<File> cir) {
// Since Forge uses a single save handler mods will expect this method to return overworld's world directory
// Fixes mods such as ComputerCraft and FuturePack
if ((activeContainer != null && activeContainer != SpongeMod.instance && !(activeContainer instanceof PluginContainerExtension))) {
- final File directory = new File(".", Sponge.getServer().getDefaultWorldName());
- cir.setReturnValue(directory);
+ if (this.modWorldDirectory != null) {
+ cir.setReturnValue(this.modWorldDirectory);
+ } else {
+ this.modWorldDirectory = new File(".", Sponge.getServer().getDefaultWorldName());
+ cir.setReturnValue(this.modWorldDirectory);
+ }
}
}
}
