From 430b23bb4568eb387d4df026fd569137319cc084 Mon Sep 17 00:00:00 2001 From: TomTheFurry Date: Fri, 1 Jul 2022 18:17:08 +0800 Subject: [PATCH] Milestone!! Both fabric:runclient & fabric:runserver now works!!!!! (in 1.18.2 for now) --- .../minecraft/MinecraftClientWrapper.java | 3 ++ .../MinecraftDedicatedServerWrapper.java | 3 ++ .../minecraft/MinecraftRenderWrapper.java | 3 ++ .../common/wrappers/world/LevelWrapper.java | 3 ++ .../BatchGenerationEnvironment.java | 2 +- core | 2 +- .../seibel/lod/fabric/FabricClientMain.java | 3 ++ .../seibel/lod/fabric/FabricClientProxy.java | 6 ++-- .../lod/fabric/FabricDedicatedServerMain.java | 7 +++- .../com/seibel/lod/fabric/FabricMain.java | 2 +- .../seibel/lod/fabric/FabricServerProxy.java | 12 +++++-- .../fabric/mixins/MixinDedicatedServer.java | 33 ----------------- .../lod/fabric/mixins/MixinMinecraft.java | 36 ------------------- .../server/MixinUtilBackgroudThread.java | 8 +++-- 14 files changed, 41 insertions(+), 82 deletions(-) delete mode 100644 fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinDedicatedServer.java delete mode 100644 fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinMinecraft.java 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 a88dcd582..9443c3058 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 @@ -41,6 +41,8 @@ import com.seibel.lod.core.objects.DHBlockPos; import com.seibel.lod.core.objects.DHChunkPos; import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.CrashReport; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -70,6 +72,7 @@ import org.jetbrains.annotations.Nullable; * @author James Seibel * @version 3-5-2022 */ +@Environment(EnvType.CLIENT) public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecraftSharedWrapper { private static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName()); diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftDedicatedServerWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftDedicatedServerWrapper.java index 3794827ef..d19efbd7c 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftDedicatedServerWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftDedicatedServerWrapper.java @@ -2,10 +2,13 @@ package com.seibel.lod.common.wrappers.minecraft; import com.seibel.lod.core.api.internal.a7.SharedApi; import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.server.dedicated.DedicatedServer; import java.io.File; +@Environment(EnvType.SERVER) public class MinecraftDedicatedServerWrapper implements IMinecraftSharedWrapper { public static final MinecraftDedicatedServerWrapper INSTANCE = new MinecraftDedicatedServerWrapper(); private MinecraftDedicatedServerWrapper() {} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java index d3cce7003..ceec9a959 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java @@ -47,6 +47,8 @@ import com.seibel.lod.common.wrappers.McObjectConverter; import com.seibel.lod.common.wrappers.WrapperFactory; import com.seibel.lod.core.objects.DHBlockPos; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.FogRenderer; @@ -75,6 +77,7 @@ import org.apache.logging.log4j.Logger; * @author James Seibel * @version 12-12-2021 */ +@Environment(EnvType.CLIENT) public class MinecraftRenderWrapper implements IMinecraftRenderWrapper { public static final MinecraftRenderWrapper INSTANCE = new MinecraftRenderWrapper(); diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/world/LevelWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/world/LevelWrapper.java index 27a3e7672..bde65634c 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/world/LevelWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/world/LevelWrapper.java @@ -35,6 +35,8 @@ import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper; import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerChunkCache; @@ -73,6 +75,7 @@ public class LevelWrapper implements ILevelWrapper levelType = ELevelType.Unknown; } + @Environment(EnvType.CLIENT) private static LevelAccessor getSinglePlayerServerLevel() { MinecraftClientWrapper client = MinecraftClientWrapper.INSTANCE; return client.mc.getSingleplayerServer().getPlayerList() diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index b0e11abd6..8dc7e8b9f 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -235,7 +235,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv public final StepLight stepLight = new StepLight(this); public boolean unsafeThreadingRecorded = false; //public boolean safeMode = false; - private static final IMinecraftClientWrapper MC = SingletonHandler.get(IMinecraftClientWrapper.class); + //private static final IMinecraftClientWrapper MC = SingletonHandler.get(IMinecraftClientWrapper.class); public static final long EXCEPTION_TIMER_RESET_TIME = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); public static final int EXCEPTION_COUNTER_TRIGGER = 20; public static final int RANGE_TO_RANGE_EMPTY_EXTENSION = 1; diff --git a/core b/core index 1c63dd518..932146eea 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 1c63dd5183da23ccf3756c331c4004cecb8f0f69 +Subproject commit 932146eea855184ce82c8bd9f3e4524440b788ba diff --git a/fabric/src/main/java/com/seibel/lod/fabric/FabricClientMain.java b/fabric/src/main/java/com/seibel/lod/fabric/FabricClientMain.java index b622abedc..bb16c7a17 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/FabricClientMain.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/FabricClientMain.java @@ -2,8 +2,11 @@ package com.seibel.lod.fabric; import com.seibel.lod.common.wrappers.DependencySetup; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; +@Environment(EnvType.CLIENT) public class FabricClientMain implements ClientModInitializer { public static FabricClientProxy client_proxy; public static FabricServerProxy server_proxy; 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 24b9de7d9..1004b9b2c 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/FabricClientProxy.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/FabricClientProxy.java @@ -28,6 +28,8 @@ import com.mojang.blaze3d.platform.InputConstants; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; import com.seibel.lod.core.logging.DhLoggerBuilder; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; 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; @@ -49,13 +51,12 @@ import org.lwjgl.glfw.GLFW; * @author Ran * @version 11-23-2021 */ +@Environment(EnvType.CLIENT) public class FabricClientProxy { private final ClientApi clientApi = ClientApi.INSTANCE; private static final Logger LOGGER = DhLoggerBuilder.getLogger("FabricClientProxy"); - public static Supplier isGenerationThreadChecker = null; - /** * Registers Fabric Events * @author Ran @@ -63,7 +64,6 @@ public class FabricClientProxy 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/FabricDedicatedServerMain.java b/fabric/src/main/java/com/seibel/lod/fabric/FabricDedicatedServerMain.java index 6ccdcf78c..2bd8ba22e 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/FabricDedicatedServerMain.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/FabricDedicatedServerMain.java @@ -2,11 +2,15 @@ package com.seibel.lod.fabric; import com.seibel.lod.common.wrappers.DependencySetup; import com.seibel.lod.common.wrappers.minecraft.MinecraftDedicatedServerWrapper; +import com.seibel.lod.core.api.internal.a7.SharedApi; import com.seibel.lod.core.util.LodUtil; import net.fabricmc.api.DedicatedServerModInitializer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.server.dedicated.DedicatedServer; +@Environment(EnvType.SERVER) public class FabricDedicatedServerMain implements DedicatedServerModInitializer { public static FabricServerProxy server_proxy; public boolean hasPostSetupDone = false; @@ -22,9 +26,10 @@ public class FabricDedicatedServerMain implements DedicatedServerModInitializer ServerLifecycleEvents.SERVER_STARTING.register((server) -> { if (hasPostSetupDone) return; hasPostSetupDone = true; - FabricMain.postInit(); LodUtil.assertTrue(server instanceof DedicatedServer); MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer) server; + FabricMain.postInit(); + SharedApi.LOGGER.info("Dedicated server inited at {}", server.getServerDirectory()); }); } } diff --git a/fabric/src/main/java/com/seibel/lod/fabric/FabricMain.java b/fabric/src/main/java/com/seibel/lod/fabric/FabricMain.java index e09fdb0f3..cc1ab6c6d 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/FabricMain.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/FabricMain.java @@ -59,6 +59,7 @@ public class FabricMain public static void postInit() { LOGGER.info("Post-Initializing Mod"); FabricDependencySetup.runDelayedSetup(); + LodCommonMain.initConfig(); LOGGER.info("Mod Post-Initialized"); } @@ -69,7 +70,6 @@ public class FabricMain LodCommonMain.startup(null); FabricDependencySetup.createInitialBindings(); FabricDependencySetup.finishBinding(); - LodCommonMain.initConfig(); LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION); if (SingletonHandler.get(IModChecker.class).isModLoaded("sodium")) { 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 fac44e621..28f625d9c 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/FabricServerProxy.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/FabricServerProxy.java @@ -3,6 +3,7 @@ package com.seibel.lod.fabric; import com.seibel.lod.common.networking.Networking; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; import com.seibel.lod.core.api.internal.a7.ServerApi; import com.seibel.lod.core.api.internal.a7.SharedApi; import com.seibel.lod.core.logging.DhLoggerBuilder; @@ -19,6 +20,8 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; import org.apache.logging.log4j.Logger; +import java.util.function.Supplier; + /** * This handles all events sent to the server, * and is the starting point for most of the mod. @@ -27,18 +30,20 @@ import org.apache.logging.log4j.Logger; * @version 5-11-2022 */ -// TODO public class FabricServerProxy { private final ServerApi serverApi = ServerApi.INSTANCE; private static final Logger LOGGER = DhLoggerBuilder.getLogger("FabricServerProxy"); private final boolean isDedicated; + public static Supplier isGenerationThreadChecker = null; public FabricServerProxy(boolean isDedicated) { this.isDedicated = isDedicated; } private boolean isValidTime() { - //FIXME: return true immediately if this is a dedicated server + if (isDedicated) return true; + + //FIXME: This may cause init issue... return !(Minecraft.getInstance().screen instanceof TitleScreen); } private LevelWrapper getLevelWrapper(Level level) { @@ -46,10 +51,11 @@ public class FabricServerProxy { } /** * Registers Fabric Events - * @author Ran, Tom + * @author Ran, Tomlee */ public void registerEvents() { LOGGER.info("Registering Fabric Server Events"); + isGenerationThreadChecker = BatchGenerationEnvironment::isCurrentThreadDistantGeneratorThread; /* Register the mod needed event callbacks */ diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinDedicatedServer.java b/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinDedicatedServer.java deleted file mode 100644 index 784f9311f..000000000 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinDedicatedServer.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the Distant Horizons mod (formerly the LOD Mod), - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2022 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.lod.fabric.mixins; - -import net.minecraft.server.dedicated.DedicatedServer; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(DedicatedServer.class) -@Deprecated // Please use the OnServerLoadEvent in core instead, or - // the ServerLifecycleEvents in Fabric -public class MixinDedicatedServer { -// @Inject(method = "initServer", at = @At("TAIL")) -// public void initServer(CallbackInfoReturnable cir) { -// Main.initServer(); -// } -} diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinMinecraft.java b/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinMinecraft.java deleted file mode 100644 index 485915ebc..000000000 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinMinecraft.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Distant Horizons mod (formerly the LOD Mod), - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2022 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.lod.fabric.mixins; - -import net.minecraft.client.Minecraft; -import org.spongepowered.asm.mixin.Mixin; - -/** - * Loads the mod after minecraft loads. - * @author Ran - */ -@Mixin(value = Minecraft.class) -@Deprecated // Moved to using fabric lifecycle events -public class MixinMinecraft { -// @Inject(method = "", at = @At("TAIL")) -// private void startMod(GameConfig gameConfig, CallbackInfo ci) { -// Main.init(); -// } -} diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/server/MixinUtilBackgroudThread.java b/fabric/src/main/java/com/seibel/lod/fabric/mixins/server/MixinUtilBackgroudThread.java index dfc499b6b..a4ae2a0d7 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/server/MixinUtilBackgroudThread.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/mixins/server/MixinUtilBackgroudThread.java @@ -23,6 +23,8 @@ import java.util.concurrent.ExecutorService; import java.util.function.Supplier; import com.seibel.lod.fabric.FabricClientProxy; +import com.seibel.lod.fabric.FabricDedicatedServerMain; +import com.seibel.lod.fabric.FabricServerProxy; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -38,7 +40,7 @@ public class MixinUtilBackgroudThread @Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true) private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable ci) { - if (FabricClientProxy.isGenerationThreadChecker != null && FabricClientProxy.isGenerationThreadChecker.get()) + if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get()) { //ApiShared.LOGGER.info("util backgroundExecutor triggered"); ci.setReturnValue(new DummyRunExecutorService()); @@ -50,7 +52,7 @@ public class MixinUtilBackgroudThread at = @At("HEAD"), cancellable = true) private static void overrideUtil$wrapThreadWithTaskName(String string, Runnable r, CallbackInfoReturnable ci) { - if (FabricClientProxy.isGenerationThreadChecker != null && FabricClientProxy.isGenerationThreadChecker.get()) + if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get()) { //ApiShared.LOGGER.info("util wrapThreadWithTaskName(Runnable) triggered"); ci.setReturnValue(r); @@ -62,7 +64,7 @@ public class MixinUtilBackgroudThread at = @At("HEAD"), cancellable = true) private static void overrideUtil$wrapThreadWithTaskNameForSupplier(String string, Supplier r, CallbackInfoReturnable> ci) { - if (FabricClientProxy.isGenerationThreadChecker != null && FabricClientProxy.isGenerationThreadChecker.get()) + if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get()) { //ApiShared.LOGGER.info("util wrapThreadWithTaskName(Supplier) triggered"); ci.setReturnValue(r);