diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetup.java b/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetup.java index dd307d9ad..fd695c0aa 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetup.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetup.java @@ -21,6 +21,7 @@ package com.seibel.lod.common.wrappers; import com.seibel.lod.common.LodCommonMain; import com.seibel.lod.common.wrappers.config.ConfigWrapper; +import com.seibel.lod.core.api.internal.a7.SharedApi; import com.seibel.lod.core.wrapperInterfaces.config.IConfigWrapper; import com.seibel.lod.common.wrappers.minecraft.MinecraftClientWrapper; import com.seibel.lod.common.wrappers.minecraft.MinecraftRenderWrapper; @@ -47,11 +48,11 @@ public class DependencySetup { { SingletonHandler.bind(IConfigWrapper.class, ConfigWrapper.INSTANCE); SingletonHandler.bind(IVersionConstants.class, VersionConstants.INSTANCE); - if (!LodCommonMain.serverSided) + if (!SharedApi.inDedicatedEnvironment) { SingletonHandler.bind(IMinecraftClientWrapper.class, MinecraftClientWrapper.INSTANCE); SingletonHandler.bind(IMinecraftRenderWrapper.class, MinecraftRenderWrapper.INSTANCE); - SingletonHandler.bind(IReflectionHandler.class, ReflectionHandler.createSingleton(MinecraftClientWrapper.INSTANCE.getOptions().getClass().getDeclaredFields(), MinecraftClientWrapper.INSTANCE.getOptions())); + SingletonHandler.bind(IReflectionHandler.class, ReflectionHandler.createSingleton()); } SingletonHandler.bind(IWrapperFactory.class, WrapperFactory.INSTANCE); diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftClientWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftClientWrapper.java index 3c4531205..8e8d462ef 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftClientWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftClientWrapper.java @@ -197,11 +197,6 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper return new DHChunkPos(playerPos.x, playerPos.z); } - public Options getOptions() - { - return mc.options; - } - public ModelManager getModelManager() { return mc.getModelManager(); @@ -384,6 +379,17 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper Minecraft.crash(report); } + @Override + public Object getOptionsObject() + { + return mc.options; + } + + @Override + public File getSinglePlayerServerFolder() { + return mc.getSingleplayerServer().getServerDirectory(); + } + diff --git a/fabric/src/main/java/com/seibel/lod/fabric/FabricClientProxy.java b/fabric/src/main/java/com/seibel/lod/fabric/FabricClientProxy.java index feb332655..2b72e2701 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/FabricClientProxy.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/FabricClientProxy.java @@ -27,6 +27,7 @@ import com.mojang.blaze3d.platform.InputConstants; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; import com.seibel.lod.common.wrappers.world.WorldWrapper; +import com.seibel.lod.core.logging.DhLoggerBuilder; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; @@ -37,6 +38,7 @@ import net.minecraft.world.level.Level; import java.util.HashSet; import java.util.function.Supplier; +import org.apache.logging.log4j.Logger; import org.lwjgl.glfw.GLFW; /** @@ -50,6 +52,7 @@ import org.lwjgl.glfw.GLFW; public class FabricClientProxy { private final ClientApi clientApi = ClientApi.INSTANCE; + private static final Logger LOGGER = DhLoggerBuilder.getLogger("FabricClientProxy"); public static Supplier isGenerationThreadChecker = null; @@ -58,6 +61,8 @@ public class FabricClientProxy * @author Ran */ public void registerEvents() { + LOGGER.info("Registering Fabric Client Events"); + isGenerationThreadChecker = BatchGenerationEnvironment::isCurrentThreadDistantGeneratorThread; /* Register the mod needed event callbacks */ diff --git a/fabric/src/main/java/com/seibel/lod/fabric/FabricServerProxy.java b/fabric/src/main/java/com/seibel/lod/fabric/FabricServerProxy.java index fda82249e..3fd0e224a 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/FabricServerProxy.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/FabricServerProxy.java @@ -4,6 +4,8 @@ import com.seibel.lod.common.networking.Networking; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; import com.seibel.lod.common.wrappers.world.WorldWrapper; import com.seibel.lod.core.api.internal.a7.ServerApi; +import com.seibel.lod.core.logging.DhLoggerBuilder; +import com.seibel.lod.core.objects.a7.Server; import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents; @@ -17,6 +19,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; +import org.apache.logging.log4j.Logger; /** * This handles all events sent to the server, @@ -29,6 +32,7 @@ import net.minecraft.world.level.Level; // TODO public class FabricServerProxy { private final ServerApi serverApi = ServerApi.INSTANCE; + private static final Logger LOGGER = DhLoggerBuilder.getLogger("FabricServerProxy"); private boolean isValidTime() { //FIXME: return true immediately if this is a dedicated server @@ -42,6 +46,7 @@ public class FabricServerProxy { * @author Ran, Tom */ public void registerEvents() { + LOGGER.info("Registering Fabric Server Events"); /* Register the mod needed event callbacks */ @@ -53,11 +58,11 @@ public class FabricServerProxy { // ServerWorldLoadEvent //TODO: Check if both of this use the correct timed events. (i.e. is it 'ed' or 'ing' one?) - ServerLifecycleEvents.SERVER_STARTED.register((server) -> { + ServerLifecycleEvents.SERVER_STARTING.register((server) -> { if (isValidTime()) ServerApi.INSTANCE.serverWorldLoadEvent(); }); // ServerWorldUnloadEvent - ServerLifecycleEvents.SERVER_STOPPING.register((server) -> { + ServerLifecycleEvents.SERVER_STOPPED.register((server) -> { if (isValidTime()) ServerApi.INSTANCE.serverWorldUnloadEvent(); }); diff --git a/fabric/src/main/java/com/seibel/lod/fabric/Main.java b/fabric/src/main/java/com/seibel/lod/fabric/Main.java index 99fe7b192..a0fe0d91e 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/Main.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/Main.java @@ -67,17 +67,28 @@ public class Main implements ClientModInitializer, DedicatedServerModInitializer @Override public void onInitializeClient() { SharedApi.inDedicatedEnvironment = false; - ClientLifecycleEvents.CLIENT_STARTED.register(Main::init); + init(); + ClientLifecycleEvents.CLIENT_STARTED.register(Main::postInit); } @Override public void onInitializeServer() { SharedApi.inDedicatedEnvironment = true; - init(null); // TODO: Check if init in here is ok + init(); + postInit(null); // TODO: Check if init in here is ok } + public static void postInit(Minecraft minecraft) { + LOGGER.info("Post-Initializing Mod"); + FabricDependencySetup.runDelayedSetup(); + LOGGER.info("Mod Post-Initialized"); + } + + + // This loads the mod after minecraft loads which doesn't causes a lot of issues - public static void init(Minecraft minecraft) { + public static void init() { + LOGGER.info("Initializing Mod"); LodCommonMain.startup(null); FabricDependencySetup.createInitialBindings(); FabricDependencySetup.finishBinding(); @@ -100,5 +111,6 @@ public class Main implements ClientModInitializer, DedicatedServerModInitializer ModAccessorHandler.bind(IOptifineAccessor.class, new OptifineAccessor()); } ModAccessorHandler.finishBinding(); + LOGGER.info("Mod Initialized"); } } diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinClientPacketListener.java b/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinClientPacketListener.java index 19007d4c0..7e0f9a40d 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinClientPacketListener.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/mixins/client/MixinClientPacketListener.java @@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPacketListener.class) public class MixinClientPacketListener { @@ -21,30 +22,26 @@ public class MixinClientPacketListener { * Also anyone can send another GameJoinPacket at any time, so we need to watch out. */ @Inject(method = "handleLogin", at = @At("HEAD")) - void onHandleLoginStart() { + void onHandleLoginStart(CallbackInfo ci) { if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(WorldWrapper.getWorldWrapper(level)); } @Inject(method = "handleLogin", at = @At("RETURN")) - void onHandleLoginEnd() { + void onHandleLoginEnd(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelLoadEvent(WorldWrapper.getWorldWrapper(level)); } @Inject(method = "handleRespawn", at = @At("HEAD")) - void onHandleRespawnStart() { + void onHandleRespawnStart(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelUnloadEvent(WorldWrapper.getWorldWrapper(level)); } @Inject(method = "handleRespawn", at = @At("RETURN")) - void onHandleRespawnEnd() { + void onHandleRespawnEnd(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelLoadEvent(WorldWrapper.getWorldWrapper(level)); } @Inject(method = "cleanup", at = @At("HEAD")) - void onCleanupStart() { + void onCleanupStart(CallbackInfo ci) { if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(WorldWrapper.getWorldWrapper(level)); } - - - - } diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/server/MixinChunkMap.java b/fabric/src/main/java/com/seibel/lod/fabric/mixins/server/MixinChunkMap.java index 56afd2322..f8e15e4c5 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/server/MixinChunkMap.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/mixins/server/MixinChunkMap.java @@ -7,22 +7,33 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.ChunkAccess; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ChunkMap.class) public class MixinChunkMap { - static final String CHUNK_SERIALIZER_WRITE + + @Unique + private static final String CHUNK_SERIALIZER_WRITE = "Lnet/minecraft/world/level/chunk/storage/ChunkSerializer;write(" + "Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/chunk/ChunkAccess;)" + "Lnet/minecraft/nbt/CompoundTag;"; + @Shadow + @Final + ServerLevel level; + @Inject(method = "save", at = @At(value = "INVOKE", target = CHUNK_SERIALIZER_WRITE)) - private void onChunkSave(ServerLevel serverLevel, ChunkAccess chunkAccess, CompoundTag compoundTag) { + private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable ci) { ServerApi.INSTANCE.serverChunkSaveEvent( - new ChunkWrapper(chunkAccess, serverLevel), - WorldWrapper.getWorldWrapper(serverLevel) + new ChunkWrapper(chunk, level), + WorldWrapper.getWorldWrapper(level) ); } diff --git a/fabric/src/main/java/com/seibel/lod/fabric/wrappers/FabricDependencySetup.java b/fabric/src/main/java/com/seibel/lod/fabric/wrappers/FabricDependencySetup.java index d99f8a6c5..919b7d0d5 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/wrappers/FabricDependencySetup.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/wrappers/FabricDependencySetup.java @@ -47,4 +47,8 @@ public class FabricDependencySetup public static void finishBinding() { SingletonHandler.finishBinding(); } + + public static void runDelayedSetup() { + SingletonHandler.runDelayedSetup(); + } }