Update the DependencyHandler to support circular references
This commit is contained in:
+1
-1
Submodule core updated: 2149da59df...58392a8ac1
+22
-9
@@ -23,6 +23,7 @@ import com.seibel.lod.common.LodCommonMain;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import com.seibel.lod.core.api.ClientApi;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.DependencyHandler;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.ModAccessorHandler;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
@@ -31,7 +32,7 @@ import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.ModChecker;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.OptifineAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.SodiumAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.DependencySetup;
|
||||
import com.seibel.lod.fabric.wrappers.FabricDependencySetup;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
@@ -44,7 +45,7 @@ import net.fabricmc.api.ClientModInitializer;
|
||||
* @author Ran
|
||||
* @version 12-1-2021
|
||||
*/
|
||||
public class Main implements ClientModInitializer
|
||||
public class FabricMain implements ClientModInitializer
|
||||
{
|
||||
// This is a client mod so it should implement ClientModInitializer and in fabric.mod.json it should have "environment": "client"
|
||||
// Once it works on servers change the implement to ModInitializer and in fabric.mod.json it should be "environment": "*"
|
||||
@@ -63,25 +64,37 @@ public class Main implements ClientModInitializer
|
||||
public static void init() {
|
||||
LodCommonMain.initConfig();
|
||||
LodCommonMain.startup(null, false);
|
||||
DependencySetup.createInitialBindings();
|
||||
SingletonHandler.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
|
||||
ApiShared.LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
|
||||
|
||||
// Check if this works
|
||||
client_proxy = new ClientProxy();
|
||||
client_proxy.registerEvents();
|
||||
|
||||
|
||||
// make sure the dependencies are set up before the mod needs them
|
||||
FabricDependencySetup.createInitialBindings();
|
||||
FabricDependencySetup.finishBinding();
|
||||
|
||||
// mod dependencies
|
||||
if (SingletonHandler.get(IModChecker.class).isModLoaded("sodium")) {
|
||||
ModAccessorHandler.bind(ISodiumAccessor.class, new SodiumAccessor());
|
||||
}
|
||||
if (SingletonHandler.get(IModChecker.class).isModLoaded("optifine")) {
|
||||
ModAccessorHandler.bind(IOptifineAccessor.class, new OptifineAccessor());
|
||||
}
|
||||
|
||||
ModAccessorHandler.finishBinding();
|
||||
|
||||
|
||||
// Check if this works
|
||||
client_proxy = new ClientProxy();
|
||||
client_proxy.registerEvents();
|
||||
}
|
||||
|
||||
public static void initServer() {
|
||||
LodCommonMain.initConfig();
|
||||
LodCommonMain.startup(null, true);
|
||||
DependencySetup.createInitialBindings();
|
||||
|
||||
ApiShared.LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
|
||||
|
||||
FabricDependencySetup.createInitialBindings();
|
||||
FabricDependencySetup.finishBinding();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.fabric.mixins;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import com.seibel.lod.fabric.FabricMain;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.main.GameConfig;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -16,6 +16,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public class MixinMinecraft {
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void startMod(GameConfig gameConfig, CallbackInfo ci) {
|
||||
Main.init();
|
||||
FabricMain.init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.fabric.mixins.events;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import com.seibel.lod.fabric.FabricMain;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
@@ -23,6 +23,6 @@ public abstract class MixinBlockUpdate {
|
||||
|
||||
@Inject(method = "handle(Lnet/minecraft/network/protocol/game/ClientGamePacketListener;)V", at = @At("TAIL"))
|
||||
private void onBlockUpdate(ClientGamePacketListener clientGamePacketListener, CallbackInfo ci) {
|
||||
Main.client_proxy.blockChangeEvent(Minecraft.getInstance().player.clientLevel, this.getPos());
|
||||
FabricMain.client_proxy.blockChangeEvent(Minecraft.getInstance().player.clientLevel, this.getPos());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.fabric.mixins.events;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import com.seibel.lod.fabric.FabricMain;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
@@ -23,6 +23,6 @@ import java.util.function.Supplier;
|
||||
public class MixinClientLevel {
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void loadWorldEvent(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey<Level> resourceKey, DimensionType dimensionType, int i, Supplier<ProfilerFiller> supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) {
|
||||
Main.client_proxy.worldLoadEvent((ClientLevel) (Object) this);
|
||||
FabricMain.client_proxy.worldLoadEvent((ClientLevel) (Object) this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.fabric.mixins.events;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import com.seibel.lod.fabric.FabricMain;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
@@ -23,11 +23,11 @@ public class MixinMinecraft {
|
||||
|
||||
@Inject(method = "setLevel", at = @At("HEAD"))
|
||||
private void unloadWorldEvent_sL(ClientLevel clientLevel, CallbackInfo ci) {
|
||||
if (level != null) Main.client_proxy.worldUnloadEvent(level);
|
||||
if (level != null) FabricMain.client_proxy.worldUnloadEvent(level);
|
||||
}
|
||||
|
||||
@Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD"))
|
||||
private void unloadWorldEvent_cL(Screen screen, CallbackInfo ci) {
|
||||
if (this.level != null) Main.client_proxy.worldUnloadEvent(this.level);
|
||||
if (this.level != null) FabricMain.client_proxy.worldUnloadEvent(this.level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.fabric.mixins.events;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import com.seibel.lod.fabric.FabricMain;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.ProgressListener;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -16,6 +16,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public class MixinServerLevel {
|
||||
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;save(Z)V", shift = At.Shift.AFTER))
|
||||
private void saveWorldEvent(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) {
|
||||
Main.client_proxy.worldSaveEvent();
|
||||
FabricMain.client_proxy.worldSaveEvent();
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -1,7 +1,10 @@
|
||||
package com.seibel.lod.fabric.wrappers;
|
||||
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.DependencyHandler;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.ModChecker;
|
||||
import com.seibel.lod.common.wrappers.config.LodConfigWrapperSingleton;
|
||||
|
||||
/**
|
||||
@@ -14,10 +17,16 @@ import com.seibel.lod.common.wrappers.config.LodConfigWrapperSingleton;
|
||||
* @author Ran
|
||||
* @version 12-1-2021
|
||||
*/
|
||||
public class DependencySetup
|
||||
public class FabricDependencySetup
|
||||
{
|
||||
public static void createInitialBindings()
|
||||
{
|
||||
SingletonHandler.bind(ILodConfigWrapperSingleton.class, LodConfigWrapperSingleton.INSTANCE);;
|
||||
SingletonHandler.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
}
|
||||
|
||||
public static void finishBinding()
|
||||
{
|
||||
SingletonHandler.finishBinding();
|
||||
}
|
||||
}
|
||||
@@ -67,16 +67,21 @@ public class ForgeMain implements LodForgeMethodCaller
|
||||
|
||||
private void init(final FMLCommonSetupEvent event)
|
||||
{
|
||||
// make sure the dependencies are set up before the mod needs them
|
||||
ApiShared.LOGGER.info("Distant Horizons initializing...");
|
||||
|
||||
LodCommonMain.initConfig();
|
||||
LodCommonMain.startup(this, !FMLLoader.getDist().isClient());
|
||||
|
||||
// make sure the dependencies are set up before the mod needs them
|
||||
ForgeDependencySetup.createInitialBindings();
|
||||
ApiShared.LOGGER.info("Distant Horizons initializing...");
|
||||
|
||||
SingletonHandler.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
ForgeDependencySetup.finishBinding();
|
||||
|
||||
// mod dependencies
|
||||
if (ReflectionHandler.instance.optifinePresent()) {
|
||||
ModAccessorHandler.bind(IOptifineAccessor.class, new OptifineAccessor());
|
||||
}
|
||||
|
||||
ModAccessorHandler.finishBinding();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.seibel.lod.forge.wrappers;
|
||||
import com.seibel.lod.common.wrappers.config.LodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.lod.forge.wrappers.modAccessor.ModChecker;
|
||||
|
||||
/**
|
||||
* Binds all necessary dependencies so we
|
||||
@@ -12,12 +14,18 @@ import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
*
|
||||
* @author James Seibel
|
||||
* @author Ran
|
||||
* @version 12-1-2021
|
||||
* @version 3-5-2022
|
||||
*/
|
||||
public class ForgeDependencySetup
|
||||
{
|
||||
public static void createInitialBindings()
|
||||
{
|
||||
SingletonHandler.bind(ILodConfigWrapperSingleton.class, LodConfigWrapperSingleton.INSTANCE);
|
||||
SingletonHandler.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
}
|
||||
|
||||
public static void finishBinding()
|
||||
{
|
||||
SingletonHandler.finishBinding();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user