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
|
|
|
|
2022-02-01 21:46:47 +01:00
|
|
|
import com.jozufozu.flywheel.backend.Backend;
|
|
|
|
import com.jozufozu.flywheel.backend.OptifineHandler;
|
2022-06-20 08:25:44 +02:00
|
|
|
import com.jozufozu.flywheel.backend.RenderWork;
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
|
|
|
import com.jozufozu.flywheel.backend.model.MeshPool;
|
2022-04-07 23:19:36 +02:00
|
|
|
import com.jozufozu.flywheel.config.BackendTypeArgument;
|
2021-06-30 21:43:54 +02:00
|
|
|
import com.jozufozu.flywheel.config.FlwCommands;
|
|
|
|
import com.jozufozu.flywheel.config.FlwConfig;
|
2022-02-01 21:46:47 +01:00
|
|
|
import com.jozufozu.flywheel.core.Contexts;
|
2022-05-21 06:14:31 +02:00
|
|
|
import com.jozufozu.flywheel.core.GameStateRegistry;
|
2022-04-12 00:11:39 +02:00
|
|
|
import com.jozufozu.flywheel.core.Models;
|
2022-02-01 21:46:47 +01:00
|
|
|
import com.jozufozu.flywheel.core.PartialModel;
|
2022-06-20 08:25:44 +02:00
|
|
|
import com.jozufozu.flywheel.core.QuadConverter;
|
2022-02-01 21:46:47 +01:00
|
|
|
import com.jozufozu.flywheel.core.StitchedSprite;
|
|
|
|
import com.jozufozu.flywheel.core.compile.ProgramCompiler;
|
2022-06-20 08:25:44 +02:00
|
|
|
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
|
2022-05-16 05:09:47 +02:00
|
|
|
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
2022-05-21 06:14:31 +02:00
|
|
|
import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider;
|
2022-05-16 05:09:47 +02:00
|
|
|
import com.jozufozu.flywheel.core.structs.InstanceShaders;
|
2022-05-15 10:58:33 +02:00
|
|
|
import com.jozufozu.flywheel.core.vertex.LayoutShaders;
|
2022-06-20 08:25:44 +02:00
|
|
|
import com.jozufozu.flywheel.event.EntityWorldHandler;
|
|
|
|
import com.jozufozu.flywheel.event.ForgeEvents;
|
2022-02-01 21:46:47 +01:00
|
|
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
|
|
|
import com.jozufozu.flywheel.mixin.PausedPartialTickAccessor;
|
|
|
|
import com.jozufozu.flywheel.vanilla.VanillaInstances;
|
2022-07-17 23:01:30 +02:00
|
|
|
import com.jozufozu.flywheel.vanilla.effect.ExampleEffect;
|
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;
|
|
|
|
import net.minecraftforge.fml.CrashReportCallables;
|
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
|
|
|
|
2021-06-19 07:52:33 +02:00
|
|
|
FlwConfig.init();
|
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) {
|
2022-02-01 21:46:47 +01:00
|
|
|
CrashReportCallables.registerCrashCallable("Flywheel Backend", Backend::getBackendDescriptor);
|
|
|
|
|
|
|
|
OptifineHandler.init();
|
|
|
|
Backend.init();
|
2022-03-12 23:24:15 +01:00
|
|
|
|
|
|
|
forgeEventBus.addListener(FlwCommands::registerClientCommands);
|
2022-06-20 08:25:44 +02:00
|
|
|
|
|
|
|
forgeEventBus.addListener(EventPriority.HIGHEST, QuadConverter::onRendererReload);
|
2022-03-12 23:24:15 +01:00
|
|
|
forgeEventBus.<ReloadRenderersEvent>addListener(ProgramCompiler::invalidateAll);
|
2022-04-12 00:11:39 +02:00
|
|
|
forgeEventBus.addListener(Models::onReload);
|
2022-06-20 08:25:44 +02:00
|
|
|
forgeEventBus.addListener(MeshPool::reset);
|
|
|
|
forgeEventBus.addListener(CrumblingRenderer::onReloadRenderers);
|
|
|
|
|
|
|
|
forgeEventBus.addListener(InstancedRenderDispatcher::onReloadRenderers);
|
|
|
|
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);
|
|
|
|
|
|
|
|
forgeEventBus.addListener(EventPriority.LOWEST, RenderWork::onRenderWorldLast);
|
2022-02-01 21:46:47 +01:00
|
|
|
|
|
|
|
modEventBus.addListener(PartialModel::onModelRegistry);
|
|
|
|
modEventBus.addListener(PartialModel::onModelBake);
|
|
|
|
modEventBus.addListener(StitchedSprite::onTextureStitchPre);
|
|
|
|
modEventBus.addListener(StitchedSprite::onTextureStitchPost);
|
|
|
|
|
2022-07-17 23:01:30 +02:00
|
|
|
// forgeEventBus.addListener(ExampleEffect::spawn);
|
|
|
|
|
2022-05-17 21:56:09 +02:00
|
|
|
LayoutShaders.init();
|
|
|
|
InstanceShaders.init();
|
|
|
|
Contexts.init();
|
|
|
|
MaterialShaders.init();
|
|
|
|
|
2022-05-21 06:14:31 +02:00
|
|
|
GameStateRegistry.register(NormalDebugStateProvider.INSTANCE);
|
|
|
|
|
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) {
|
2022-04-07 23:19:36 +02:00
|
|
|
ArgumentTypes.register(rl("engine").toString(), BackendTypeArgument.class, new EmptyArgumentSerializer<>(BackendTypeArgument::getInstance));
|
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
|
|
|
}
|