From d5d179e6f46809967968c65132d1b110942b51eb Mon Sep 17 00:00:00 2001 From: itsmeow Date: Tue, 19 Apr 2022 04:48:58 -0500 Subject: [PATCH] Fix race condition in Forge Particle Factory registration loading --- .../src/main/resources/whisperwoods.mixins.json | 4 +--- .../whisperwoods/mixin/ParticleEngineMixin.java | 2 -- fabric/src/main/resources/fabric.mod.json | 3 ++- .../resources/whisperwoods-fabric.mixins.json | 13 +++++++++++++ .../whisperwoods/WhisperwoodsModForge.java | 3 --- .../client/WhisperwoodsClientForge.java | 16 +++++++++++++++- 6 files changed, 31 insertions(+), 10 deletions(-) rename {common => fabric}/src/main/java/dev/itsmeow/whisperwoods/mixin/ParticleEngineMixin.java (91%) create mode 100644 fabric/src/main/resources/whisperwoods-fabric.mixins.json diff --git a/common/src/main/resources/whisperwoods.mixins.json b/common/src/main/resources/whisperwoods.mixins.json index 2757f03..3a39fe6 100644 --- a/common/src/main/resources/whisperwoods.mixins.json +++ b/common/src/main/resources/whisperwoods.mixins.json @@ -8,9 +8,7 @@ "LivingEntityMixin", "GroundPathNavigationMixin" ], - "client": [ - "ParticleEngineMixin" - ], + "client": [], "injectors": { "defaultRequire": 1 } diff --git a/common/src/main/java/dev/itsmeow/whisperwoods/mixin/ParticleEngineMixin.java b/fabric/src/main/java/dev/itsmeow/whisperwoods/mixin/ParticleEngineMixin.java similarity index 91% rename from common/src/main/java/dev/itsmeow/whisperwoods/mixin/ParticleEngineMixin.java rename to fabric/src/main/java/dev/itsmeow/whisperwoods/mixin/ParticleEngineMixin.java index 7bf2451..63d49d3 100644 --- a/common/src/main/java/dev/itsmeow/whisperwoods/mixin/ParticleEngineMixin.java +++ b/fabric/src/main/java/dev/itsmeow/whisperwoods/mixin/ParticleEngineMixin.java @@ -2,8 +2,6 @@ import dev.itsmeow.whisperwoods.client.init.ClientLifecycleHandler; import net.minecraft.client.particle.ParticleEngine; -import net.minecraft.client.particle.ParticleProvider; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; import org.spongepowered.asm.mixin.Mixin; diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 915cedc..9cf730e 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -27,7 +27,8 @@ }, "mixins": [ "mixin.imdlib.json", - "whisperwoods.mixins.json" + "whisperwoods.mixins.json", + "whisperwoods-fabric.mixins.json" ], "custom": { "modmenu": { diff --git a/fabric/src/main/resources/whisperwoods-fabric.mixins.json b/fabric/src/main/resources/whisperwoods-fabric.mixins.json new file mode 100644 index 0000000..c49024a --- /dev/null +++ b/fabric/src/main/resources/whisperwoods-fabric.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "dev.itsmeow.whisperwoods.mixin", + "compatibilityLevel": "JAVA_8", + "minVersion": "0.8", + "mixins": [], + "client": [ + "ParticleEngineMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/forge/src/main/java/dev/itsmeow/whisperwoods/WhisperwoodsModForge.java b/forge/src/main/java/dev/itsmeow/whisperwoods/WhisperwoodsModForge.java index c93759a..521f200 100644 --- a/forge/src/main/java/dev/itsmeow/whisperwoods/WhisperwoodsModForge.java +++ b/forge/src/main/java/dev/itsmeow/whisperwoods/WhisperwoodsModForge.java @@ -1,10 +1,8 @@ package dev.itsmeow.whisperwoods; -import dev.itsmeow.whisperwoods.client.WhisperwoodsClientForge; import me.shedaniel.architectury.platform.forge.EventBuses; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -18,6 +16,5 @@ public WhisperwoodsModForge() { modBus.addListener(e -> { WhisperwoodsMod.init(e::enqueueWork); }); - modBus.addListener(e -> new WhisperwoodsClientForge().clientSetup(e)); } } diff --git a/forge/src/main/java/dev/itsmeow/whisperwoods/client/WhisperwoodsClientForge.java b/forge/src/main/java/dev/itsmeow/whisperwoods/client/WhisperwoodsClientForge.java index b1f75de..602917e 100644 --- a/forge/src/main/java/dev/itsmeow/whisperwoods/client/WhisperwoodsClientForge.java +++ b/forge/src/main/java/dev/itsmeow/whisperwoods/client/WhisperwoodsClientForge.java @@ -1,10 +1,24 @@ package dev.itsmeow.whisperwoods.client; +import dev.itsmeow.whisperwoods.WhisperwoodsMod; import dev.itsmeow.whisperwoods.client.init.ClientLifecycleHandler; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.ParticleEngine; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.ParticleFactoryRegisterEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +@Mod.EventBusSubscriber(modid = WhisperwoodsMod.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public class WhisperwoodsClientForge { - public void clientSetup(FMLClientSetupEvent event) { + @SubscribeEvent + public static void clientSetup(FMLClientSetupEvent event) { ClientLifecycleHandler.clientInit(); } + + @SubscribeEvent + public static void registerParticleFactory(ParticleFactoryRegisterEvent event) { + ClientLifecycleHandler.registerParticles((type, provider) -> Minecraft.getInstance().particleEngine.register(type, (ParticleEngine.SpriteParticleRegistration) spriteSet -> provider.apply(spriteSet))); + } }