2021-06-16 21:57:52 +02:00
|
|
|
package com.jozufozu.flywheel;
|
|
|
|
|
2021-12-06 10:47:52 +01:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2022-01-31 22:13:27 +01:00
|
|
|
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
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;
|
2021-12-23 06:35:48 +01:00
|
|
|
import com.jozufozu.flywheel.config.EngineArgument;
|
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;
|
|
|
|
import com.jozufozu.flywheel.core.PartialModel;
|
|
|
|
import com.jozufozu.flywheel.core.StitchedSprite;
|
|
|
|
import com.jozufozu.flywheel.core.compile.ProgramCompiler;
|
|
|
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
|
|
|
import com.jozufozu.flywheel.mixin.PausedPartialTickAccessor;
|
|
|
|
import com.jozufozu.flywheel.vanilla.VanillaInstances;
|
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-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";
|
2021-12-25 08:26:18 +01:00
|
|
|
public static final Logger LOGGER = LogManager.getLogger(Flywheel.class);
|
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);
|
|
|
|
forgeEventBus.<ReloadRenderersEvent>addListener(ProgramCompiler::invalidateAll);
|
2022-02-01 21:46:47 +01:00
|
|
|
|
|
|
|
modEventBus.addListener(Contexts::flwInit);
|
|
|
|
modEventBus.addListener(PartialModel::onModelRegistry);
|
|
|
|
modEventBus.addListener(PartialModel::onModelBake);
|
|
|
|
modEventBus.addListener(StitchedSprite::onTextureStitchPre);
|
|
|
|
modEventBus.addListener(StitchedSprite::onTextureStitchPost);
|
|
|
|
|
|
|
|
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) {
|
2021-12-25 08:26:18 +01:00
|
|
|
ArgumentTypes.register(rl("engine").toString(), EngineArgument.class, new EmptyArgumentSerializer<>(EngineArgument::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
|
|
|
}
|