2021-06-16 21:57:52 +02:00
|
|
|
package com.jozufozu.flywheel;
|
|
|
|
|
2023-11-18 20:46:04 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
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-11-21 07:03:04 +01:00
|
|
|
import com.jozufozu.flywheel.api.event.ReloadRenderersEvent;
|
2023-11-18 20:46:04 +01:00
|
|
|
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
|
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-20 21:22:51 +02:00
|
|
|
import com.jozufozu.flywheel.backend.compile.Pipelines;
|
2023-04-17 02:20:32 +02:00
|
|
|
import com.jozufozu.flywheel.backend.engine.UniformBuffer;
|
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-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-11-18 20:46:04 +01:00
|
|
|
import com.jozufozu.flywheel.impl.visualization.VisualizationEventHandler;
|
2023-03-31 01:52:51 +02:00
|
|
|
import com.jozufozu.flywheel.lib.context.Contexts;
|
2023-04-09 21:00:03 +02:00
|
|
|
import com.jozufozu.flywheel.lib.instance.InstanceTypes;
|
2023-11-18 20:46:04 +01:00
|
|
|
import com.jozufozu.flywheel.lib.light.LightUpdater;
|
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;
|
2023-11-18 20:46:04 +01:00
|
|
|
import com.jozufozu.flywheel.lib.memory.FlwMemoryTracker;
|
2023-11-21 07:03:04 +01:00
|
|
|
import com.jozufozu.flywheel.lib.model.ModelCache;
|
|
|
|
import com.jozufozu.flywheel.lib.model.ModelHolder;
|
2023-11-18 20:46:04 +01:00
|
|
|
import com.jozufozu.flywheel.lib.model.baked.PartialModel;
|
|
|
|
import com.jozufozu.flywheel.lib.util.LevelAttached;
|
2023-03-31 01:52:51 +02:00
|
|
|
import com.jozufozu.flywheel.lib.util.ShadersModHandler;
|
2023-11-18 20:46:04 +01:00
|
|
|
import com.jozufozu.flywheel.lib.util.StringUtil;
|
2023-04-09 21:00:03 +02:00
|
|
|
import com.jozufozu.flywheel.lib.vertex.VertexTypes;
|
|
|
|
import com.jozufozu.flywheel.vanilla.VanillaVisuals;
|
2022-03-14 18:52:28 +01:00
|
|
|
import com.mojang.logging.LogUtils;
|
2021-06-19 07:52:33 +02:00
|
|
|
|
2023-11-18 20:46:04 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2023-11-23 20:42:11 +01:00
|
|
|
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
|
|
|
|
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
|
2023-11-18 20:46:04 +01:00
|
|
|
import net.minecraft.core.Vec3i;
|
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;
|
2023-11-23 20:42:11 +01:00
|
|
|
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
|
2021-06-16 21:57:52 +02:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2023-11-23 06:30:58 +01:00
|
|
|
import net.minecraftforge.event.level.LevelEvent;
|
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;
|
2023-11-24 07:48:29 +01:00
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
2021-06-16 21:57:52 +02:00
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
|
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|
|
|
|
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(
|
2023-11-23 20:42:11 +01:00
|
|
|
() -> "any",
|
|
|
|
(serverVersion, isNetwork) -> true
|
2022-03-12 23:24:15 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
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) {
|
2023-11-18 20:46:04 +01:00
|
|
|
forgeEventBus.addListener(Flywheel::addDebugInfo);
|
2022-06-20 08:25:44 +02:00
|
|
|
|
2023-04-08 01:01:03 +02:00
|
|
|
forgeEventBus.addListener(BackendManagerImpl::onReloadRenderers);
|
|
|
|
|
2023-11-18 20:46:04 +01:00
|
|
|
forgeEventBus.addListener(VisualizationEventHandler::onClientTick);
|
|
|
|
forgeEventBus.addListener(VisualizationEventHandler::onBeginFrame);
|
|
|
|
forgeEventBus.addListener(VisualizationEventHandler::onRenderStage);
|
|
|
|
forgeEventBus.addListener(VisualizationEventHandler::onEntityJoinWorld);
|
|
|
|
forgeEventBus.addListener(VisualizationEventHandler::onEntityLeaveWorld);
|
2022-06-20 08:25:44 +02:00
|
|
|
|
2023-11-18 20:46:04 +01:00
|
|
|
forgeEventBus.addListener(FlwCommands::registerClientCommands);
|
2022-06-20 08:25:44 +02:00
|
|
|
|
2023-11-18 20:46:04 +01:00
|
|
|
forgeEventBus.addListener(DrawBuffer::onReloadRenderers);
|
|
|
|
forgeEventBus.addListener(UniformBuffer::onReloadRenderers);
|
2022-06-20 08:25:44 +02:00
|
|
|
|
2023-11-18 20:46:04 +01:00
|
|
|
forgeEventBus.addListener(LightUpdater::onClientTick);
|
2023-11-21 07:03:04 +01:00
|
|
|
forgeEventBus.addListener((ReloadRenderersEvent e) -> ModelCache.onReloadRenderers(e));
|
|
|
|
forgeEventBus.addListener(ModelHolder::onReloadRenderers);
|
2023-11-23 06:30:58 +01:00
|
|
|
forgeEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.onUnloadLevel(e));
|
2022-06-20 08:25:44 +02:00
|
|
|
|
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-11-24 07:48:29 +01:00
|
|
|
modEventBus.addListener(Flywheel::lateInit);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void lateInit(final FMLClientSetupEvent event) {
|
2023-04-09 21:00:03 +02:00
|
|
|
VertexTypes.init();
|
|
|
|
InstanceTypes.init();
|
2023-03-31 01:52:51 +02:00
|
|
|
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
|
|
|
|
2023-04-09 21:00:03 +02:00
|
|
|
VanillaVisuals.init();
|
2022-02-01 21:46:47 +01:00
|
|
|
|
2023-04-03 08:58:28 +02:00
|
|
|
RegistryImpl.freezeAll();
|
|
|
|
IdRegistryImpl.freezeAll();
|
2023-11-24 07:48:29 +01:00
|
|
|
}
|
2023-04-04 21:36:54 +02:00
|
|
|
|
2023-11-24 07:48:29 +01:00
|
|
|
private static void setup(final FMLCommonSetupEvent event) {
|
2023-11-23 20:42:11 +01:00
|
|
|
ArgumentTypeInfos.registerByClass(BackendArgument.class, SingletonArgumentInfo.contextFree(() -> BackendArgument.INSTANCE));
|
2021-06-19 07:52:33 +02:00
|
|
|
}
|
2022-02-02 05:44:53 +01:00
|
|
|
|
2023-11-23 20:42:11 +01:00
|
|
|
private static void addDebugInfo(CustomizeGuiOverlayEvent.DebugText event) {
|
2023-11-18 20:46:04 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2023-11-24 23:29:03 +01:00
|
|
|
|
|
|
|
if (!mc.options.renderDebug) {
|
|
|
|
return;
|
|
|
|
}
|
2023-11-18 20:46:04 +01:00
|
|
|
|
|
|
|
ArrayList<String> info = event.getRight();
|
|
|
|
info.add("");
|
|
|
|
info.add("Flywheel: " + getVersion());
|
|
|
|
info.add("Backend: " + BackendManagerImpl.getBackendString());
|
|
|
|
info.add("Update limiting: " + FlwCommands.boolToText(FlwConfig.get().limitUpdates()).getString());
|
|
|
|
|
|
|
|
VisualizationManager manager = VisualizationManager.get(mc.level);
|
|
|
|
if (manager != null) {
|
|
|
|
info.add("B: " + manager.getBlockEntities().getVisualCount()
|
|
|
|
+ ", E: " + manager.getEntities().getVisualCount()
|
|
|
|
+ ", F: " + manager.getEffects().getVisualCount());
|
|
|
|
Vec3i renderOrigin = manager.getRenderOrigin();
|
|
|
|
info.add("Origin: " + renderOrigin.getX() + ", " + renderOrigin.getY() + ", " + renderOrigin.getZ());
|
|
|
|
}
|
|
|
|
|
2023-11-23 06:30:58 +01:00
|
|
|
info.add("Memory Usage: CPU: " + StringUtil.formatBytes(FlwMemoryTracker.getCPUMemory()) + ", GPU: " + StringUtil.formatBytes(FlwMemoryTracker.getGPUMemory()));
|
2023-11-18 20:46:04 +01: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
|
|
|
}
|