Refactor initializer code

This commit is contained in:
s809
2024-01-07 20:25:34 +05:00
parent aa6cbd1b7d
commit 526df4f184
19 changed files with 457 additions and 518 deletions
@@ -0,0 +1,178 @@
package com.seibel.distanthorizons.common;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
import com.seibel.distanthorizons.core.api.internal.SharedApi;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
import com.seibel.distanthorizons.core.config.types.AbstractConfigType;
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.jar.ModJarInfo;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.util.objects.Pair;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModAccessor;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
import com.seibel.distanthorizons.coreapi.ModInfo;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import org.apache.logging.log4j.Logger;
#if MC_VER >= MC_1_19_2
import net.minecraft.network.chat.Component;
#else // < 1.19.2
import net.minecraft.network.chat.TranslatableComponent;
#endif
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import static com.mojang.brigadier.arguments.DoubleArgumentType.doubleArg;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
public abstract class AbstractModInitializer
{
protected static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
protected abstract void createInitialBindings();
protected abstract IEventProxy createClientProxy();
protected abstract IEventProxy createServerProxy(boolean isDedicated);
protected abstract void initializeModCompat();
protected abstract void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler);
private CommandDispatcher<CommandSourceStack> commandDispatcher;
protected abstract void subscribeClientStartedEvent(Runnable eventHandler);
protected abstract void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler);
protected abstract void runDelayedSetup();
private void startup()
{
DependencySetup.createSharedBindings();
SharedApi.init();
this.createInitialBindings();
}
private void printModInfo(boolean printGitInfo)
{
LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
if (printGitInfo)
{
// Useful for dev builds
LOGGER.info("DH Branch: " + ModJarInfo.Git_Branch);
LOGGER.info("DH Commit: " + ModJarInfo.Git_Commit);
LOGGER.info("DH Jar Build Source: " + ModJarInfo.Build_Source);
}
}
protected <T extends IModAccessor> void tryCreateModCompatAccessor(String modId, Class<? super T> accessorClass, Supplier<T> accessorConstructor)
{
IModChecker modChecker = SingletonInjector.INSTANCE.get(IModChecker.class);
if (modChecker.isModLoaded(modId))
{
//noinspection unchecked
ModAccessorInjector.INSTANCE.bind((Class<? extends IModAccessor>) accessorClass, accessorConstructor.get());
}
}
private void initConfig()
{
ConfigBase.INSTANCE = new ConfigBase(ModInfo.ID, ModInfo.NAME, Config.class, 2);
Config.completeDelayedSetup();
}
public void onInitializeClient()
{
DependencySetup.createClientBindings();
LOGGER.info("Initializing " + ModInfo.READABLE_NAME);
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
this.startup();
this.printModInfo(true);
this.createClientProxy().registerEvents();
this.createServerProxy(false).registerEvents();
this.initializeModCompat();
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
// Client uses config for auto-updater, so it's initialized here instead of post-init stage
this.initConfig();
this.subscribeClientStartedEvent(this::postInit);
}
public void onInitializeServer()
{
DependencySetup.createServerBindings();
LOGGER.info("Initializing " + ModInfo.READABLE_NAME);
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
this.startup();
this.printModInfo(false);
// This prevents returning uninitialized Config values,
// resulting from a circular reference mid-initialization in a static class
// noinspection ResultOfMethodCallIgnored
ThreadPresetConfigEventHandler.INSTANCE.toString();
this.createServerProxy(true).registerEvents();
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
this.subscribeRegisterCommandsEvent(dispatcher -> {
this.commandDispatcher = dispatcher;
});
this.subscribeServerStartingEvent(server -> {
MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)server;
this.initConfig();
this.postInit();
this.initCommands();
LOGGER.info("Dedicated server initialized at " + server.getServerDirectory());
});
}
private void postInit()
{
LOGGER.info("Post-Initializing Mod");
this.runDelayedSetup();
LOGGER.info("Mod Post-Initialized");
}
private void initCommands()
{
// TODO
}
}
@@ -0,0 +1,6 @@
package com.seibel.distanthorizons.common;
public interface IEventProxy
{
void registerEvents();
}
@@ -1,64 +0,0 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 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 <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.common;
import com.seibel.distanthorizons.common.forge.LodForgeMethodCaller;
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.api.internal.SharedApi;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.ConfigBase;
/**
* This is the common main class
*
* @author Ran
*/
public class LodCommonMain
{
public static boolean forge = false;
public static LodForgeMethodCaller forgeMethodCaller;
public static void startup(LodForgeMethodCaller forgeMethodCaller)
{
if (forgeMethodCaller != null)
{
LodCommonMain.forge = true;
LodCommonMain.forgeMethodCaller = forgeMethodCaller;
}
DependencySetup.createSharedBindings();
SharedApi.init();
// if (!serverSided) {
// new NetworkReceiver().register_Client();
// } else {
// new NetworkReceiver().register_Server();
// }
}
public static void initConfig()
{
ConfigBase.INSTANCE = new ConfigBase(ModInfo.ID, ModInfo.NAME, Config.class, 2);
Config.completeDelayedSetup();
}
}
@@ -1,52 +0,0 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 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 <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.common.forge;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.core.Direction;
#if MC_VER >= MC_1_19_2
import net.minecraft.util.RandomSource;
#endif
import net.minecraft.world.level.ColorResolver;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import java.util.List;
import java.util.Random;
/**
* used for calling methods that forge modified
* (forge modifies vanilla methods for some reason)
*
* @author Ran
*/
public interface LodForgeMethodCaller
{
#if MC_VER < MC_1_19_2
List<BakedQuad> getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, Random random); // FIXME: For 1.19
#else
List<BakedQuad> getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, RandomSource random); // FIXME: For 1.19
#endif
int colorResolverGetColor(ColorResolver resolver, Biome biome, double x, double z);
}
@@ -19,7 +19,6 @@
package com.seibel.distanthorizons.common.wrappers.block;
import com.seibel.distanthorizons.common.LodCommonMain;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.*;
@@ -60,15 +59,15 @@ public class TintGetterOverrideFast implements BlockAndTintGetter
@Override
public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver)
{
if (LodCommonMain.forgeMethodCaller != null)
{
return LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(blockPos),
blockPos.getX(), blockPos.getZ());
}
else
{
return colorResolver.getColor(_getBiome(blockPos), blockPos.getX(), blockPos.getZ());
}
//if (LodCommonMain.forgeMethodCaller != null)
//{
// return LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(blockPos),
// blockPos.getX(), blockPos.getZ());
//}
//else
//{
return colorResolver.getColor(this._getBiome(blockPos), blockPos.getX(), blockPos.getZ());
//}
}
@Override
@@ -19,7 +19,6 @@
package com.seibel.distanthorizons.common.wrappers.block;
import com.seibel.distanthorizons.common.LodCommonMain;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Cursor3D;
import net.minecraft.core.Direction;
@@ -75,15 +74,15 @@ public class TintGetterOverrideSmooth implements BlockAndTintGetter
{
mutableBlockPos.set(cursor3D.nextX(), cursor3D.nextY(), cursor3D.nextZ());
int n;
if (LodCommonMain.forgeMethodCaller != null)
{
n = LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(mutableBlockPos),
mutableBlockPos.getX(), mutableBlockPos.getZ());
}
else
{
n = colorResolver.getColor(_getBiome(mutableBlockPos), mutableBlockPos.getX(), mutableBlockPos.getZ());
}
//if (LodCommonMain.forgeMethodCaller != null)
//{
// n = LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(mutableBlockPos),
// mutableBlockPos.getX(), mutableBlockPos.getZ());
//}
//else
//{
n = colorResolver.getColor(this._getBiome(mutableBlockPos), mutableBlockPos.getX(), mutableBlockPos.getZ());
//}
k += (n & 0xFF0000) >> 16;
l += (n & 0xFF00) >> 8;
@@ -1,35 +0,0 @@
package com.seibel.distanthorizons.fabric;
import com.seibel.distanthorizons.common.LodCommonMain;
import com.seibel.distanthorizons.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;
// Do if implements ClientModInitializer
// This loads the mod before minecraft loads which causes a lot of issues
@Override
public void onInitializeClient()
{
DependencySetup.createClientBindings();
FabricMain.init();
LodCommonMain.initConfig();
server_proxy = new FabricServerProxy(false);
server_proxy.registerEvents();
client_proxy = new FabricClientProxy();
client_proxy.registerEvents();
ClientLifecycleEvents.CLIENT_STARTED.register((mc) -> FabricMain.postInit());
}
}
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.fabric;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.common.rendering.SeamlessOverdraw;
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
@@ -72,7 +73,7 @@ import org.lwjgl.opengl.GL15;
* @version 2023-7-27
*/
@Environment(EnvType.CLIENT)
public class FabricClientProxy
public class FabricClientProxy implements IEventProxy
{
private final ClientApi clientApi = ClientApi.INSTANCE;
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
@@ -1,56 +0,0 @@
package com.seibel.distanthorizons.fabric;
import com.seibel.distanthorizons.common.LodCommonMain;
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
import com.seibel.distanthorizons.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;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Environment(EnvType.SERVER)
public class FabricDedicatedServerMain implements DedicatedServerModInitializer
{
private static final Logger LOGGER = LogManager.getLogger(FabricDedicatedServerMain.class.getSimpleName());
public static FabricServerProxy server_proxy;
public boolean hasPostSetupDone = false;
@Override
public void onInitializeServer()
{
DependencySetup.createServerBindings();
FabricMain.init();
// FIXME this prevents returning uninitialized Config values
// resulting from a circular reference mid-initialization in a static class
// ThreadPresetConfigEventHandler <-> Config
ThreadPresetConfigEventHandler.INSTANCE.toString();
server_proxy = new FabricServerProxy(true);
server_proxy.registerEvents();
ServerLifecycleEvents.SERVER_STARTING.register((server) ->
{
if (this.hasPostSetupDone)
{
return;
}
this.hasPostSetupDone = true;
LodUtil.assertTrue(server instanceof DedicatedServer);
MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer) server;
LodCommonMain.initConfig();
FabricMain.postInit();
LOGGER.info("Dedicated server initialized at " + server.getServerDirectory());
});
}
}
@@ -19,25 +19,29 @@
package com.seibel.distanthorizons.fabric;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.jar.ModJarInfo;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.*;
import com.seibel.distanthorizons.common.LodCommonMain;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.mojang.brigadier.CommandDispatcher;
import com.seibel.distanthorizons.common.AbstractModInitializer;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.*;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.fabric.wrappers.FabricDependencySetup;
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.*;
import org.apache.logging.log4j.Logger;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import javax.swing.*;
import java.util.function.Consumer;
/**
* Initialize and setup the Mod. <br>
@@ -48,44 +52,33 @@ import javax.swing.*;
* @author Ran
* @version 9-2-2022
*/
public class FabricMain
public class FabricMain extends AbstractModInitializer implements ClientModInitializer, DedicatedServerModInitializer
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
private static final ResourceLocation INITIAL_PHASE = ResourceLocation.tryParse("distanthorizons:dedicated_server_initial");
public static void postInit()
@Override
protected void createInitialBindings()
{
LOGGER.info("Post-Initializing Mod");
FabricDependencySetup.runDelayedSetup();
if (Config.Client.Advanced.Graphics.Fog.disableVanillaFog.get() && SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("bclib"))
ModAccessorInjector.INSTANCE.get(IBCLibAccessor.class).setRenderCustomFog(false); // Remove BCLib's fog
#if MC_VER >= MC_1_20_1
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("sodium"))
ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class).setFogOcclusion(false); // FIXME: This is a tmp fix for sodium 0.5.0, and 0.5.1. This is fixed in sodium 0.5.2
#endif
if (ConfigBase.INSTANCE == null)
throw new IllegalStateException("Config was not initialized. Make sure to call LodCommonMain.initConfig() before calling this method.");
LOGGER.info("Mod Post-Initialized");
FabricDependencySetup.createInitialBindings();
}
// This loads the mod after minecraft loads which doesn't causes a lot of issues
public static void init()
@Override
protected IEventProxy createClientProxy()
{
return new FabricClientProxy();
}
@Override
protected IEventProxy createServerProxy(boolean isDedicated)
{
return new FabricServerProxy(isDedicated);
}
@Override
protected void initializeModCompat()
{
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
LOGGER.info("Initializing Mod");
LodCommonMain.startup(null);
FabricDependencySetup.createInitialBindings();
LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
// Print git info (Useful for dev builds)
LOGGER.info("DH Branch: " + ModJarInfo.Git_Branch);
LOGGER.info("DH Commit: " + ModJarInfo.Git_Commit);
LOGGER.info("DH Jar Build Source: " + ModJarInfo.Build_Source);
IModChecker modChecker = SingletonInjector.INSTANCE.get(IModChecker.class);
if (modChecker.isModLoaded("sodium"))
{
@@ -105,30 +98,52 @@ public class FabricMain
mc.crashMinecraft(errorMessage, new Exception(exceptionError));
}
}
if (modChecker.isModLoaded("starlight"))
{
ModAccessorInjector.INSTANCE.bind(IStarlightAccessor.class, new StarlightAccessor());
}
if (modChecker.isModLoaded("optifine"))
{
ModAccessorInjector.INSTANCE.bind(IOptifineAccessor.class, new OptifineAccessor());
}
if (modChecker.isModLoaded("bclib"))
{
ModAccessorInjector.INSTANCE.bind(IBCLibAccessor.class, new BCLibAccessor());
}
this.tryCreateModCompatAccessor("starlight", IStarlightAccessor.class, StarlightAccessor::new);
this.tryCreateModCompatAccessor("optifine", IOptifineAccessor.class, OptifineAccessor::new);
this.tryCreateModCompatAccessor("bclib", IBCLibAccessor.class, BCLibAccessor::new);
#if MC_VER != MC_1_17_1 && MC_VER <= MC_1_20_1
// 1.17.1 won't support this since there isn't a matching Iris version
if (modChecker.isModLoaded("iris"))
{
ModAccessorInjector.INSTANCE.bind(IIrisAccessor.class, new IrisAccessor());
}
this.tryCreateModCompatAccessor("iris", IIrisAccessor.class, IrisAccessor::new);
#endif
}
@Override
protected void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler)
{
// fabric-command-api-v1/v2
//CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess #if MC_VER >= MC_1_19_2 , environment #endif ) -> {
// eventHandler.accept(dispatcher);
//});
}
@Override
protected void subscribeClientStartedEvent(Runnable eventHandler)
{
ClientLifecycleEvents.CLIENT_STARTED.register((mc) -> eventHandler.run());
}
@Override
protected void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler)
{
ServerLifecycleEvents.SERVER_STARTING.addPhaseOrdering(INITIAL_PHASE, Event.DEFAULT_PHASE);
ServerLifecycleEvents.SERVER_STARTING.register(INITIAL_PHASE, eventHandler::accept);
}
@Override
protected void runDelayedSetup()
{
FabricDependencySetup.runDelayedSetup();
if (Config.Client.Advanced.Graphics.Fog.disableVanillaFog.get() && SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("bclib"))
ModAccessorInjector.INSTANCE.get(IBCLibAccessor.class).setRenderCustomFog(false); // Remove BCLib's fog
#if MC_VER >= MC_1_20_1
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("sodium"))
ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class).setFogOcclusion(false); // FIXME: This is a tmp fix for sodium 0.5.0, and 0.5.1. This is fixed in sodium 0.5.2
#endif
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
if (ConfigBase.INSTANCE == null)
throw new IllegalStateException("Config was not initialized. Make sure to call LodCommonMain.initConfig() before calling this method.");
}
}
@@ -1,5 +1,6 @@
package com.seibel.distanthorizons.fabric;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
@@ -32,7 +33,7 @@ import java.util.function.Supplier;
* @author Tomlee
* @version 5-11-2022
*/
public class FabricServerProxy
public class FabricServerProxy implements IEventProxy
{
private static final ServerApi SERVER_API = ServerApi.INSTANCE;
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
+2 -2
View File
@@ -24,10 +24,10 @@
"environment": "*",
"entrypoints": {
"client": [
"com.seibel.distanthorizons.fabric.FabricClientMain"
"com.seibel.distanthorizons.fabric.FabricMain"
],
"server": [
"com.seibel.distanthorizons.fabric.FabricDedicatedServerMain"
"com.seibel.distanthorizons.fabric.FabricMain"
],
"modmenu": [
"com.seibel.distanthorizons.fabric.wrappers.config.ModMenuIntegration"
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.forge;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.common.util.ProxyUtil;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
@@ -50,6 +51,7 @@ import net.minecraftforge.client.event.RenderLevelStageEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
//import net.minecraftforge.network.NetworkRegistry;
//import net.minecraftforge.network.simple.SimpleChannel;
@@ -71,7 +73,7 @@ import org.lwjgl.opengl.GL32;
* @author James_Seibel
* @version 2023-7-27
*/
public class ForgeClientProxy
public class ForgeClientProxy implements IEventProxy
{
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
@@ -87,6 +89,15 @@ public class ForgeClientProxy
@Override
public void registerEvents()
{
MinecraftForge.EVENT_BUS.register(this);
this.setupNetworkingListeners();
}
//=============//
// tick events //
//=============//
@@ -237,8 +248,7 @@ public class ForgeClientProxy
// networking //
//============//
/** @param event this is just to ensure the event is called at the right time, if it is called outside the {@link FMLClientSetupEvent} event, the binding may fail */
public static void setupNetworkingListeners(FMLClientSetupEvent event)
public void setupNetworkingListeners()
{
// multiversePluginChannel = NetworkRegistry.newSimpleChannel(
// new ResourceLocation(ModInfo.NETWORKING_RESOURCE_NAMESPACE, ModInfo.MULTIVERSE_PLUGIN_NAMESPACE),
@@ -19,37 +19,30 @@
package com.seibel.distanthorizons.forge;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
import com.seibel.distanthorizons.common.LodCommonMain;
import com.seibel.distanthorizons.common.forge.LodForgeMethodCaller;
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
import com.mojang.brigadier.CommandDispatcher;
import com.seibel.distanthorizons.common.AbstractModInitializer;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper;
import com.seibel.distanthorizons.core.jar.ModJarInfo;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOptifineAccessor;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
import com.seibel.distanthorizons.forge.wrappers.ForgeDependencySetup;
import com.seibel.distanthorizons.forge.wrappers.modAccessor.OptifineAccessor;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.core.Direction;
#if MC_VER >= MC_1_19_2
import net.minecraft.util.RandomSource;
#endif
import net.minecraft.world.level.ColorResolver;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.*;
#if MC_VER == MC_1_16_5
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
#elif MC_VER == MC_1_17_1
import net.minecraftforge.fmlserverevents.FMLServerStartingEvent;
#else
import net.minecraftforge.event.server.ServerStartingEvent;
#endif
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
#if MC_VER < MC_1_17_1
import net.minecraftforge.fml.ExtensionPoint;
@@ -61,20 +54,15 @@ import net.minecraftforge.client.ConfigGuiHandler;
import net.minecraftforge.client.ConfigScreenHandler;
#endif
import org.apache.logging.log4j.Logger;
// these imports change due to forge refactoring classes in 1.19
#if MC_VER < MC_1_19_2
import net.minecraftforge.client.model.data.ModelDataMap;
import java.util.Random;
#else
import net.minecraft.client.renderer.RenderType;
import net.minecraftforge.client.model.data.ModelData;
#endif
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.function.Consumer;
/**
* Initialize and setup the Mod. <br>
@@ -87,47 +75,38 @@ import java.util.List;
* @version 8-15-2022
*/
@Mod(ModInfo.ID)
public class ForgeMain implements LodForgeMethodCaller
public class ForgeMain extends AbstractModInitializer
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
public static ForgeClientProxy client_proxy = null;
public static ForgeServerProxy server_proxy = null;
public ForgeMain()
{
DependencySetup.createClientBindings();
// initDedicated(null);
// initDedicated(null);
// Register the mod initializer (Actual event registration is done in the different proxies)
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::initClient);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::initDedicated);
FMLJavaModLoadingContext.get().getModEventBus().addListener((FMLClientSetupEvent e) -> this.onInitializeClient());
FMLJavaModLoadingContext.get().getModEventBus().addListener((FMLDedicatedServerSetupEvent e) -> this.onInitializeServer());
}
private void initClient(final FMLClientSetupEvent event)
@Override
protected void createInitialBindings()
{
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
LOGGER.info("Initializing Mod");
LodCommonMain.startup(this);
ForgeDependencySetup.createInitialBindings();
LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
}
@Override
protected IEventProxy createClientProxy()
{
return new ForgeClientProxy();
}
@Override
protected IEventProxy createServerProxy(boolean isDedicated)
{
return new ForgeServerProxy(isDedicated);
}
@Override
protected void initializeModCompat()
{
this.tryCreateModCompatAccessor("optifine", IOptifineAccessor.class, OptifineAccessor::new);
// Print git info (Useful for dev builds)
LOGGER.info("DH Branch: " + ModJarInfo.Git_Branch);
LOGGER.info("DH Commit: " + ModJarInfo.Git_Commit);
LOGGER.info("DH Jar Build Source: " + ModJarInfo.Build_Source);
client_proxy = new ForgeClientProxy();
MinecraftForge.EVENT_BUS.register(client_proxy);
server_proxy = new ForgeServerProxy(false);
MinecraftForge.EVENT_BUS.register(server_proxy);
if (AbstractOptifineAccessor.optifinePresent())
{
ModAccessorInjector.INSTANCE.bind(IOptifineAccessor.class, new OptifineAccessor());
}
#if MC_VER < MC_1_17_1
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY,
() -> (client, parent) -> GetConfigScreen.getScreen(parent));
@@ -138,65 +117,36 @@ public class ForgeMain implements LodForgeMethodCaller
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class,
() -> new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> GetConfigScreen.getScreen(parent)));
#endif
ForgeClientProxy.setupNetworkingListeners(event);
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
// Init config
// The reason im initialising in this rather than the post init process is cus im using this for the auto updater
LodCommonMain.initConfig();
}
private void initDedicated(final FMLDedicatedServerSetupEvent event)
{
// DependencySetup.createServerBindings();
// initCommon();
// server_proxy = new ForgeServerProxy(true);
// MinecraftForge.EVENT_BUS.register(server_proxy);
//
postInitCommon();
}
private void postInitCommon()
{
LOGGER.info("Post-Initializing Mod");
ForgeDependencySetup.runDelayedSetup();
LOGGER.info("Mod Post-Initialized");
}
#if MC_VER < MC_1_19_2
private final ModelDataMap modelData = new ModelDataMap.Builder().build();
#else
private final ModelData modelData = ModelData.EMPTY;
#endif
@Override
#if MC_VER < MC_1_19_2
public List<BakedQuad> getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, Random random)
protected void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler)
{
return mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random, modelData);
MinecraftForge.EVENT_BUS.addListener((RegisterCommandsEvent e) ->
{
eventHandler.accept(e.getDispatcher());
});
}
#else
public List<BakedQuad> getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, RandomSource random)
{
return mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random, modelData #if MC_VER >= MC_1_19_2 , RenderType.solid() #endif );
}
#endif
@Override //TODO: Check this if its still needed
public int colorResolverGetColor(ColorResolver resolver, Biome biome, double x, double z)
@Override
protected void subscribeClientStartedEvent(Runnable eventHandler)
{
#if MC_1_17_1______Still_needed
return resolver.m_130045_(biome, x, z);
#else
return resolver.getColor(biome, x, z);
#endif
// FIXME What event is this?
}
@Override
protected void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler)
{
MinecraftForge.EVENT_BUS.addListener((#if MC_VER >= MC_1_18_2 ServerStartingEvent #else FMLServerStartingEvent #endif e) ->
{
eventHandler.accept(e.getServer());
});
}
@Override
protected void runDelayedSetup()
{
ForgeDependencySetup.runDelayedSetup();
}
}
@@ -1,5 +1,6 @@
package com.seibel.distanthorizons.forge;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.common.util.ProxyUtil;
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
@@ -13,6 +14,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
#if MC_VER < MC_1_19_2
import net.minecraftforge.event.world.ChunkEvent;
@@ -39,7 +41,7 @@ import org.apache.logging.log4j.Logger;
import java.util.function.Supplier;
public class ForgeServerProxy
public class ForgeServerProxy implements IEventProxy
{
#if MC_VER < MC_1_19_2
private static LevelAccessor GetEventLevel(WorldEvent e) { return e.getWorld(); }
@@ -53,6 +55,15 @@ public class ForgeServerProxy
public static Supplier<Boolean> isGenerationThreadChecker = null;
@Override
public void registerEvents()
{
MinecraftForge.EVENT_BUS.register(this);
}
//=============//
// constructor //
//=============//
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.neoforged;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.common.util.ProxyUtil;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
@@ -37,6 +38,7 @@ import net.minecraft.world.level.LevelAccessor;
import net.minecraft.client.multiplayer.ClientLevel;
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.level.ChunkEvent;
import net.neoforged.neoforge.event.level.LevelEvent;
@@ -64,7 +66,7 @@ import org.lwjgl.opengl.GL32;
* @author James_Seibel
* @version 2023-7-27
*/
public class NeoforgeClientProxy
public class NeoforgeClientProxy implements IEventProxy
{
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
@@ -76,6 +78,15 @@ public class NeoforgeClientProxy
@Override
public void registerEvents()
{
NeoForge.EVENT_BUS.register(this);
setupNetworkingListeners();
}
//=============//
// tick events //
//=============//
@@ -202,8 +213,7 @@ public class NeoforgeClientProxy
// networking //
//============//
/** @param event this is just to ensure the event is called at the right time, if it is called outside the {@link FMLClientSetupEvent} event, the binding may fail */
public static void setupNetworkingListeners(FMLClientSetupEvent event)
public static void setupNetworkingListeners()
{
// multiversePluginChannel = NetworkRegistry.newSimpleChannel(
// new ResourceLocation(ModInfo.NETWORKING_RESOURCE_NAMESPACE, ModInfo.MULTIVERSE_PLUGIN_NAMESPACE),
@@ -19,45 +19,27 @@
package com.seibel.distanthorizons.neoforged;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
import com.seibel.distanthorizons.common.LodCommonMain;
import com.seibel.distanthorizons.common.forge.LodForgeMethodCaller;
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
import com.mojang.brigadier.CommandDispatcher;
import com.seibel.distanthorizons.common.AbstractModInitializer;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper;
import com.seibel.distanthorizons.core.jar.ModJarInfo;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOptifineAccessor;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.neoforged.wrappers.NeoforgeDependencySetup;
import com.seibel.distanthorizons.neoforged.wrappers.modAccessor.OptifineAccessor;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.ColorResolver;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.*;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
import net.neoforged.neoforge.client.ConfigScreenHandler;
import net.neoforged.neoforge.common.NeoForge;
import org.apache.logging.log4j.Logger;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.server.ServerStartingEvent;
import net.minecraft.client.renderer.RenderType;
import net.neoforged.neoforge.client.model.data.ModelData;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.function.Consumer;
/**
* Initialize and setup the Mod. <br>
@@ -70,92 +52,67 @@ import java.util.List;
* @version 8-15-2022
*/
@Mod(ModInfo.ID)
public class NeoforgeMain implements LodForgeMethodCaller
public class NeoforgeMain extends AbstractModInitializer
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
public static NeoforgeClientProxy client_proxy = null;
public static NeoforgeServerProxy server_proxy = null;
public NeoforgeMain(IEventBus eventBus)
{
DependencySetup.createClientBindings();
// initDedicated(null);
// initDedicated(null);
// Register the mod initializer (Actual event registration is done in the different proxies)
eventBus.addListener(this::initClient);
eventBus.addListener(this::initDedicated);
eventBus.addListener((FMLClientSetupEvent e) -> this.onInitializeClient());
eventBus.addListener((FMLDedicatedServerSetupEvent e) -> this.onInitializeServer());
}
private void initClient(final FMLClientSetupEvent event)
{
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
LOGGER.info("Initializing Mod");
LodCommonMain.startup(this);
NeoforgeDependencySetup.createInitialBindings();
LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
// Print git info (Useful for dev builds)
LOGGER.info("DH Branch: " + ModJarInfo.Git_Branch);
LOGGER.info("DH Commit: " + ModJarInfo.Git_Commit);
LOGGER.info("DH Jar Build Source: " + ModJarInfo.Build_Source);
client_proxy = new NeoforgeClientProxy();
NeoForge.EVENT_BUS.register(client_proxy);
server_proxy = new NeoforgeServerProxy(false);
NeoForge.EVENT_BUS.register(server_proxy);
if (AbstractOptifineAccessor.optifinePresent())
{
ModAccessorInjector.INSTANCE.bind(IOptifineAccessor.class, new OptifineAccessor());
}
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class,
() -> new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> GetConfigScreen.getScreen(parent)));
NeoforgeClientProxy.setupNetworkingListeners(event);
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
// Init config
// The reason im initialising in this rather than the post init process is cus im using this for the auto updater
LodCommonMain.initConfig();
}
private void initDedicated(final FMLDedicatedServerSetupEvent event)
{
// DependencySetup.createServerBindings();
// initCommon();
// server_proxy = new ForgeServerProxy(true);
// MinecraftForge.EVENT_BUS.register(server_proxy);
//
postInitCommon();
}
private void postInitCommon()
{
LOGGER.info("Post-Initializing Mod");
NeoforgeDependencySetup.runDelayedSetup();
LOGGER.info("Mod Post-Initialized");
}
private final ModelData modelData = ModelData.EMPTY;
@Override
public List<BakedQuad> getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, RandomSource random)
protected void createInitialBindings()
{
return mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random, modelData, RenderType.solid() );
NeoforgeDependencySetup.createInitialBindings();
}
@Override //TODO: Check this if its still needed
public int colorResolverGetColor(ColorResolver resolver, Biome biome, double x, double z)
@Override
protected IEventProxy createClientProxy()
{
return resolver.getColor(biome, x, z);
return new NeoforgeClientProxy();
}
@Override
protected IEventProxy createServerProxy(boolean isDedicated)
{
return new NeoforgeServerProxy(isDedicated);
}
@Override
protected void initializeModCompat()
{
this.tryCreateModCompatAccessor("optifine", IOptifineAccessor.class, OptifineAccessor::new);
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class,
() -> new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> GetConfigScreen.getScreen(parent)));
}
@Override
protected void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler)
{
NeoForge.EVENT_BUS.addListener((RegisterCommandsEvent e) -> {
eventHandler.accept(e.getDispatcher());
});
}
@Override
protected void subscribeClientStartedEvent(Runnable eventHandler)
{
// FIXME What event is this?
}
@Override
protected void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler)
{
NeoForge.EVENT_BUS.addListener((ServerStartingEvent e) -> {
eventHandler.accept(e.getServer());
});
}
@Override
protected void runDelayedSetup()
{
NeoforgeDependencySetup.runDelayedSetup();
}
}
@@ -1,5 +1,6 @@
package com.seibel.distanthorizons.neoforged;
import com.seibel.distanthorizons.common.IEventProxy;
import com.seibel.distanthorizons.common.util.ProxyUtil;
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
@@ -10,6 +11,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.LevelAccessor;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.neoforge.event.level.ChunkEvent;
import net.neoforged.neoforge.event.level.LevelEvent;
@@ -23,7 +25,7 @@ import org.apache.logging.log4j.Logger;
import java.util.function.Supplier;
public class NeoforgeServerProxy
public class NeoforgeServerProxy implements IEventProxy
{
private static LevelAccessor GetEventLevel(LevelEvent e) { return e.getLevel(); }
@@ -43,6 +45,13 @@ public class NeoforgeServerProxy
isGenerationThreadChecker = BatchGenerationEnvironment::isCurrentThreadDistantGeneratorThread;
}
@Override
public void registerEvents()
{
NeoForge.EVENT_BUS.register(this);
}
//========//