2021-06-16 21:57:52 +02:00
|
|
|
package com.jozufozu.flywheel;
|
|
|
|
|
2022-01-31 22:13:27 +01:00
|
|
|
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
2022-03-14 18:52:28 +01:00
|
|
|
import org.slf4j.Logger;
|
2021-12-06 10:47:52 +01:00
|
|
|
|
2023-04-08 01:01:03 +02:00
|
|
|
import com.jozufozu.flywheel.backend.Backends;
|
2023-04-03 08:58:28 +02:00
|
|
|
import com.jozufozu.flywheel.backend.Loader;
|
2023-04-08 01:01:03 +02:00
|
|
|
import com.jozufozu.flywheel.backend.Pipelines;
|
2023-03-31 01:52:51 +02:00
|
|
|
import com.jozufozu.flywheel.backend.engine.batching.DrawBuffer;
|
2023-04-03 08:58:28 +02:00
|
|
|
import com.jozufozu.flywheel.config.BackendArgument;
|
2021-06-30 21:43:54 +02:00
|
|
|
import com.jozufozu.flywheel.config.FlwCommands;
|
|
|
|
import com.jozufozu.flywheel.config.FlwConfig;
|
2023-03-31 01:52:51 +02:00
|
|
|
import com.jozufozu.flywheel.handler.EntityWorldHandler;
|
|
|
|
import com.jozufozu.flywheel.handler.ForgeEvents;
|
2023-04-06 03:03:25 +02:00
|
|
|
import com.jozufozu.flywheel.impl.BackendManagerImpl;
|
2023-04-03 08:58:28 +02:00
|
|
|
import com.jozufozu.flywheel.impl.IdRegistryImpl;
|
|
|
|
import com.jozufozu.flywheel.impl.RegistryImpl;
|
2023-04-06 03:03:25 +02:00
|
|
|
import com.jozufozu.flywheel.impl.instancing.InstancedRenderDispatcher;
|
2023-03-31 01:52:51 +02:00
|
|
|
import com.jozufozu.flywheel.lib.context.Contexts;
|
|
|
|
import com.jozufozu.flywheel.lib.format.Formats;
|
2023-04-04 21:36:54 +02:00
|
|
|
import com.jozufozu.flywheel.lib.material.MaterialIndices;
|
2023-03-31 01:52:51 +02:00
|
|
|
import com.jozufozu.flywheel.lib.material.Materials;
|
|
|
|
import com.jozufozu.flywheel.lib.model.Models;
|
|
|
|
import com.jozufozu.flywheel.lib.model.PartialModel;
|
|
|
|
import com.jozufozu.flywheel.lib.struct.StructTypes;
|
|
|
|
import com.jozufozu.flywheel.lib.util.QuadConverter;
|
|
|
|
import com.jozufozu.flywheel.lib.util.ShadersModHandler;
|
2022-02-01 21:46:47 +01:00
|
|
|
import com.jozufozu.flywheel.mixin.PausedPartialTickAccessor;
|
|
|
|
import com.jozufozu.flywheel.vanilla.VanillaInstances;
|
2022-03-14 18:52:28 +01:00
|
|
|
import com.mojang.logging.LogUtils;
|
2021-06-19 07:52:33 +02:00
|
|
|
|
2021-12-23 06:35:48 +01:00
|
|
|
import net.minecraft.commands.synchronization.ArgumentTypes;
|
2021-12-23 07:29:52 +01:00
|
|
|
import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.resources.ResourceLocation;
|
2021-06-19 07:52:33 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
2021-06-16 21:57:52 +02:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2022-06-20 08:25:44 +02:00
|
|
|
import net.minecraftforge.eventbus.api.EventPriority;
|
2022-02-01 21:46:47 +01:00
|
|
|
import net.minecraftforge.eventbus.api.IEventBus;
|
2021-06-19 07:52:33 +02:00
|
|
|
import net.minecraftforge.fml.DistExecutor;
|
2022-03-12 23:24:15 +01:00
|
|
|
import net.minecraftforge.fml.IExtensionPoint;
|
|
|
|
import net.minecraftforge.fml.ModLoadingContext;
|
2021-06-16 21:57:52 +02:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
|
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
2022-03-12 23:24:15 +01:00
|
|
|
import net.minecraftforge.network.NetworkConstants;
|
2021-06-16 21:57:52 +02:00
|
|
|
|
2021-12-25 08:26:18 +01:00
|
|
|
@Mod(Flywheel.ID)
|
2021-06-16 21:57:52 +02:00
|
|
|
public class Flywheel {
|
2021-06-30 21:43:54 +02:00
|
|
|
public static final String ID = "flywheel";
|
2022-03-14 18:52:28 +01:00
|
|
|
public static final Logger LOGGER = LogUtils.getLogger();
|
2022-02-02 05:44:53 +01:00
|
|
|
private static ArtifactVersion version;
|
2021-06-16 21:57:52 +02:00
|
|
|
|
2021-06-30 21:43:54 +02:00
|
|
|
public Flywheel() {
|
2022-03-12 23:24:15 +01:00
|
|
|
ModLoadingContext modLoadingContext = ModLoadingContext.get();
|
2022-01-31 22:13:27 +01:00
|
|
|
|
2022-03-12 23:24:15 +01:00
|
|
|
version = modLoadingContext
|
|
|
|
.getActiveContainer()
|
|
|
|
.getModInfo()
|
2022-01-31 22:13:27 +01:00
|
|
|
.getVersion();
|
|
|
|
|
2022-03-12 23:24:15 +01:00
|
|
|
IEventBus forgeEventBus = MinecraftForge.EVENT_BUS;
|
|
|
|
IEventBus modEventBus = FMLJavaModLoadingContext.get()
|
|
|
|
.getModEventBus();
|
|
|
|
modEventBus.addListener(Flywheel::setup);
|
2021-06-16 21:57:52 +02:00
|
|
|
|
2023-04-03 08:58:28 +02:00
|
|
|
FlwConfig.get().registerSpecs(modLoadingContext);
|
2021-06-16 21:57:52 +02:00
|
|
|
|
2022-03-12 23:24:15 +01:00
|
|
|
modLoadingContext.registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(
|
|
|
|
() -> NetworkConstants.IGNORESERVERONLY,
|
|
|
|
(serverVersion, isNetwork) -> isNetwork
|
|
|
|
));
|
|
|
|
|
|
|
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> Flywheel.clientInit(forgeEventBus, modEventBus));
|
2021-06-19 07:52:33 +02:00
|
|
|
}
|
2021-06-16 21:57:52 +02:00
|
|
|
|
2022-03-12 23:24:15 +01:00
|
|
|
private static void clientInit(IEventBus forgeEventBus, IEventBus modEventBus) {
|
|
|
|
forgeEventBus.addListener(FlwCommands::registerClientCommands);
|
2022-06-20 08:25:44 +02:00
|
|
|
|
2023-04-08 01:01:03 +02:00
|
|
|
forgeEventBus.addListener(BackendManagerImpl::onReloadRenderers);
|
|
|
|
|
2022-08-18 01:20:31 +02:00
|
|
|
forgeEventBus.addListener(EventPriority.HIGHEST, QuadConverter::onReloadRenderers);
|
|
|
|
forgeEventBus.addListener(Models::onReloadRenderers);
|
|
|
|
forgeEventBus.addListener(DrawBuffer::onReloadRenderers);
|
2022-06-20 08:25:44 +02:00
|
|
|
|
2022-07-23 01:41:39 +02:00
|
|
|
forgeEventBus.addListener(InstancedRenderDispatcher::onRenderStage);
|
2022-06-20 08:25:44 +02:00
|
|
|
forgeEventBus.addListener(InstancedRenderDispatcher::onBeginFrame);
|
|
|
|
forgeEventBus.addListener(InstancedRenderDispatcher::tick);
|
|
|
|
|
|
|
|
forgeEventBus.addListener(EntityWorldHandler::onEntityJoinWorld);
|
|
|
|
forgeEventBus.addListener(EntityWorldHandler::onEntityLeaveWorld);
|
|
|
|
|
|
|
|
forgeEventBus.addListener(ForgeEvents::addToDebugScreen);
|
|
|
|
forgeEventBus.addListener(ForgeEvents::unloadWorld);
|
|
|
|
forgeEventBus.addListener(ForgeEvents::tickLight);
|
|
|
|
|
2022-02-01 21:46:47 +01:00
|
|
|
modEventBus.addListener(PartialModel::onModelRegistry);
|
|
|
|
modEventBus.addListener(PartialModel::onModelBake);
|
|
|
|
|
2022-07-19 08:33:00 +02:00
|
|
|
// forgeEventBus.addListener(ExampleEffect::tick);
|
|
|
|
// forgeEventBus.addListener(ExampleEffect::onReload);
|
2022-07-17 23:01:30 +02:00
|
|
|
|
2023-04-08 01:01:03 +02:00
|
|
|
BackendManagerImpl.init();
|
2023-04-03 08:58:28 +02:00
|
|
|
|
2023-04-08 01:01:03 +02:00
|
|
|
Pipelines.init();
|
2023-04-03 08:58:28 +02:00
|
|
|
Backends.init();
|
|
|
|
Loader.init();
|
|
|
|
|
2023-04-08 01:01:03 +02:00
|
|
|
ShadersModHandler.init();
|
|
|
|
|
2023-03-31 01:52:51 +02:00
|
|
|
Formats.init();
|
|
|
|
StructTypes.init();
|
|
|
|
Materials.init();
|
|
|
|
Contexts.init();
|
2022-05-17 21:56:09 +02:00
|
|
|
|
2023-04-04 21:36:54 +02:00
|
|
|
MaterialIndices.init();
|
2023-04-03 08:58:28 +02:00
|
|
|
|
2022-02-01 21:46:47 +01:00
|
|
|
VanillaInstances.init();
|
|
|
|
|
|
|
|
// https://github.com/Jozufozu/Flywheel/issues/69
|
|
|
|
// Weird issue with accessor loading.
|
|
|
|
// Only thing I've seen that's close to a fix is to force the class to load before trying to use it.
|
|
|
|
// From the SpongePowered discord:
|
|
|
|
// https://discord.com/channels/142425412096491520/626802111455297538/675007581168599041
|
2022-02-02 05:44:53 +01:00
|
|
|
LOGGER.debug("Successfully loaded {}", PausedPartialTickAccessor.class.getName());
|
2022-02-01 21:46:47 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 05:44:53 +01:00
|
|
|
private static void setup(final FMLCommonSetupEvent event) {
|
2023-04-03 08:58:28 +02:00
|
|
|
RegistryImpl.freezeAll();
|
|
|
|
IdRegistryImpl.freezeAll();
|
2023-04-04 21:36:54 +02:00
|
|
|
|
2023-04-06 03:03:25 +02:00
|
|
|
ArgumentTypes.register(rl("backend").toString(), BackendArgument.class, new EmptyArgumentSerializer<>(() -> BackendArgument.INSTANCE));
|
2021-06-19 07:52:33 +02:00
|
|
|
}
|
2022-02-02 05:44:53 +01:00
|
|
|
|
|
|
|
public static ArtifactVersion getVersion() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ResourceLocation rl(String path) {
|
|
|
|
return new ResourceLocation(ID, path);
|
|
|
|
}
|
2021-06-16 21:57:52 +02:00
|
|
|
}
|