From 3ce4e2c5e89aa90888d3ca55e15833ad64c55ced 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 --- .../com/simibubi/create/CreateClient.java | 4 ++++ .../base/KineticTileEntityRenderer.java | 2 +- .../render/ContraptionRenderDispatcher.java | 7 ++++++- .../foundation/fluid/FluidRenderer.java | 5 ++++- .../foundation/render/AllMaterialSpecs.java | 20 +++++++------------ .../foundation/render/CreateContexts.java | 5 +++-- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index f0b2f45ee..425e61180 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -25,6 +25,8 @@ import com.simibubi.create.foundation.item.render.CustomItemModels; import com.simibubi.create.foundation.item.render.CustomRenderedItems; import com.simibubi.create.foundation.ponder.content.PonderIndex; import com.simibubi.create.foundation.ponder.elements.WorldSectionElement; +import com.simibubi.create.foundation.render.AllMaterialSpecs; +import com.simibubi.create.foundation.render.CreateContexts; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.ghost.GhostBlocks; import com.simibubi.create.foundation.utility.outliner.Outliner; @@ -75,6 +77,8 @@ public class CreateClient { modEventBus.addListener(CreateClient::onModelBake); modEventBus.addListener(AllParticleTypes::registerFactories); modEventBus.addListener(ClientEvents::loadCompleted); + modEventBus.addListener(CreateContexts::flwInit); + modEventBus.addListener(AllMaterialSpecs::flwInit); } public static void clientInit(FMLClientSetupEvent event) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index bea28ca27..213c8f91d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -26,7 +26,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -@EventBusSubscriber(value = Dist.CLIENT) +@EventBusSubscriber(Dist.CLIENT) public class KineticTileEntityRenderer extends SafeTileEntityRenderer { public static final Compartment KINETIC_TILE = new Compartment<>(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 963b93a91..e44176704 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -13,6 +13,10 @@ import static org.lwjgl.opengl.GL20.glUseProgram; import java.util.List; import java.util.Random; +import net.minecraftforge.api.distmarker.Dist; + +import net.minecraftforge.api.distmarker.OnlyIn; + import org.apache.commons.lang3.tuple.Pair; import com.jozufozu.flywheel.backend.Backend; @@ -63,7 +67,8 @@ import net.minecraftforge.fml.common.Mod; import org.lwjgl.opengl.GL20; -@Mod.EventBusSubscriber +@OnlyIn(Dist.CLIENT) +@Mod.EventBusSubscriber(Dist.CLIENT) public class ContraptionRenderDispatcher { private static final Lazy MODEL_RENDERER = Lazy.of(() -> new BlockModelRenderer(Minecraft.getInstance().getBlockColors())); private static final Lazy BLOCK_MODELS = Lazy.of(() -> Minecraft.getInstance().getModelManager().getBlockModelShapes()); diff --git a/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java b/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java index 9870a7fb7..2a82e5a30 100644 --- a/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java @@ -26,12 +26,15 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3i; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fml.common.Mod; -@Mod.EventBusSubscriber +@OnlyIn(Dist.CLIENT) +@Mod.EventBusSubscriber(Dist.CLIENT) public class FluidRenderer { // If we draw to BufferBuilder that minecraft provides for RenderType.getTranslucent(), minecraft draws the contents diff --git a/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java index 3a0c1dbcf..96f7340eb 100644 --- a/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java +++ b/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java @@ -1,7 +1,6 @@ package com.simibubi.create.foundation.render; 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.Formats; import com.jozufozu.flywheel.event.GatherContextEvent; @@ -12,10 +11,10 @@ import com.simibubi.create.content.contraptions.relays.belt.BeltData; import com.simibubi.create.content.logistics.block.FlapData; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; -@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) +@OnlyIn(Dist.CLIENT) public class AllMaterialSpecs { public static void init() { // noop, make sure the static field are loaded. @@ -26,16 +25,11 @@ public class AllMaterialSpecs { public static final MaterialSpec ACTORS = new MaterialSpec<>(Locations.ACTORS, AllProgramSpecs.ACTOR, Formats.UNLIT_MODEL, AllInstanceFormats.ACTOR, ActorData::new); public static final MaterialSpec FLAPS = new MaterialSpec<>(Locations.FLAPS, AllProgramSpecs.FLAPS, Formats.UNLIT_MODEL, AllInstanceFormats.FLAP, FlapData::new); - public static MaterialSpec register(MaterialSpec spec) { - return Backend.getInstance().register(spec); - } - - @SubscribeEvent public static void flwInit(GatherContextEvent event) { - register(ROTATING); - register(BELTS); - register(ACTORS); - register(FLAPS); + event.getBackend().register(ROTATING); + event.getBackend().register(BELTS); + event.getBackend().register(ACTORS); + event.getBackend().register(FLAPS); } public static class Locations { diff --git a/src/main/java/com/simibubi/create/foundation/render/CreateContexts.java b/src/main/java/com/simibubi/create/foundation/render/CreateContexts.java index 15ecb3b4c..5e2efaa4b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/CreateContexts.java +++ b/src/main/java/com/simibubi/create/foundation/render/CreateContexts.java @@ -12,10 +12,12 @@ import com.simibubi.create.content.contraptions.components.structureMovement.ren import com.simibubi.create.foundation.render.effects.EffectsContext; 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(bus = Mod.EventBusSubscriber.Bus.MOD) +@OnlyIn(Dist.CLIENT) public class CreateContexts { private static final ResourceLocation CONTRAPTION = new ResourceLocation("create", "context/contraption"); @@ -23,7 +25,6 @@ public class CreateContexts { public static WorldContext CWORLD; public static WorldContext STRUCTURE; - @SubscribeEvent public static void flwInit(GatherContextEvent event) { Backend backend = event.getBackend();