From 0bb85e4437cd5ec1bd5e6ee3aaf41984892a7db8 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 23 Jun 2021 13:19:03 -0700 Subject: [PATCH] Cleanup flywheel event listeners, fix crash on server startup --- .../java/com/jozufozu/flywheel/Client.java | 12 +++++++++++- .../instancing/InstancedRenderDispatcher.java | 4 +++- .../com/jozufozu/flywheel/core/Contexts.java | 4 ++-- .../com/jozufozu/flywheel/core/Materials.java | 19 ++++++------------- .../jozufozu/flywheel/core/QuadConverter.java | 2 +- .../jozufozu/flywheel/event/ForgeEvents.java | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/Client.java b/src/main/java/com/jozufozu/flywheel/Client.java index 13166acc6..bf0618b6c 100644 --- a/src/main/java/com/jozufozu/flywheel/Client.java +++ b/src/main/java/com/jozufozu/flywheel/Client.java @@ -3,6 +3,11 @@ package com.jozufozu.flywheel; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.core.AtlasStitcher; +import com.jozufozu.flywheel.core.Contexts; + +import com.jozufozu.flywheel.core.Materials; + +import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; public class Client { @@ -10,6 +15,11 @@ public class Client { public static void clientInit() { Backend.init(); - FMLJavaModLoadingContext.get().getModEventBus().addListener(AtlasStitcher.getInstance()::onTextureStitch); + IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + + modEventBus.addListener(AtlasStitcher.getInstance()::onTextureStitch); + + modEventBus.addListener(Contexts::flwInit); + modEventBus.addListener(Materials::flwInit); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java index 1a59be843..cbe2028b7 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -42,11 +42,13 @@ import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -@Mod.EventBusSubscriber(value = Dist.CLIENT) +@OnlyIn(Dist.CLIENT) +@Mod.EventBusSubscriber(Dist.CLIENT) public class InstancedRenderDispatcher { private static final WorldAttached entityInstanceManager = new WorldAttached<>(world -> new EntityInstanceManager(Contexts.WORLD.getMaterialManager(world))); diff --git a/src/main/java/com/jozufozu/flywheel/core/Contexts.java b/src/main/java/com/jozufozu/flywheel/core/Contexts.java index 18433bf76..3de518034 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Contexts.java +++ b/src/main/java/com/jozufozu/flywheel/core/Contexts.java @@ -12,16 +12,16 @@ import com.jozufozu.flywheel.event.GatherContextEvent; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) +@OnlyIn(Dist.CLIENT) public class Contexts { public static WorldContext WORLD; public static WorldContext CRUMBLING; - @SubscribeEvent public static void flwInit(GatherContextEvent event) { Backend backend = event.getBackend(); diff --git a/src/main/java/com/jozufozu/flywheel/core/Materials.java b/src/main/java/com/jozufozu/flywheel/core/Materials.java index 38d6b08b1..e0593b3b1 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Materials.java +++ b/src/main/java/com/jozufozu/flywheel/core/Materials.java @@ -1,7 +1,6 @@ package com.jozufozu.flywheel.core; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; import com.jozufozu.flywheel.core.materials.ModelData; import com.jozufozu.flywheel.core.materials.OrientedData; @@ -9,22 +8,16 @@ import com.jozufozu.flywheel.event.GatherContextEvent; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.api.distmarker.OnlyIn; -@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) +@OnlyIn(Dist.CLIENT) public class Materials { - public static final MaterialSpec ORIENTED = register(new MaterialSpec<>(Locations.ORIENTED, Programs.ORIENTED, Formats.UNLIT_MODEL, Formats.ORIENTED, OrientedData::new)); - public static final MaterialSpec TRANSFORMED = register(new MaterialSpec<>(Locations.MODEL, Programs.TRANSFORMED, Formats.UNLIT_MODEL, Formats.TRANSFORMED, ModelData::new)); + public static final MaterialSpec ORIENTED = new MaterialSpec<>(Locations.ORIENTED, Programs.ORIENTED, Formats.UNLIT_MODEL, Formats.ORIENTED, OrientedData::new); + public static final MaterialSpec TRANSFORMED = new MaterialSpec<>(Locations.MODEL, Programs.TRANSFORMED, Formats.UNLIT_MODEL, Formats.TRANSFORMED, ModelData::new); - public static MaterialSpec register(MaterialSpec spec) { - return Backend.getInstance().register(spec); - } - - @SubscribeEvent public static void flwInit(GatherContextEvent event) { - register(ORIENTED); - register(TRANSFORMED); + event.getBackend().register(ORIENTED); + event.getBackend().register(TRANSFORMED); } public static class Locations { diff --git a/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java b/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java index 6fa635f59..03bace3f0 100644 --- a/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java +++ b/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java @@ -25,7 +25,7 @@ import net.minecraftforge.fml.common.Mod; /** * A class to manage EBOs that index quads as triangles. */ -@Mod.EventBusSubscriber(value = Dist.CLIENT) +@Mod.EventBusSubscriber(Dist.CLIENT) public class QuadConverter { public static final int STARTING_CAPACITY = 42; diff --git a/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java b/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java index e89ccd26d..50b1a4fc9 100644 --- a/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java +++ b/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java @@ -16,7 +16,7 @@ import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -@Mod.EventBusSubscriber(value = Dist.CLIENT) +@Mod.EventBusSubscriber(Dist.CLIENT) public class ForgeEvents { @SubscribeEvent