Architectury API

Architectury API

234M Downloads

[1.21.4] [Fabric] Particle provider registration cannot work correctly

QWERTY770 opened this issue ยท 1 comments

commented

I was trying to register a simple particle and its particle provider.
I wrote my code like this.

package top.xdi8.mod.firefly8.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.core.particles.SimpleParticleType;
import org.jetbrains.annotations.NotNull;

public class FireflyParticle extends TextureSheetParticle {
    public FireflyParticle(ClientLevel level, double x, double y, double z, double xs, double ys, double zs) {
        super(level, x, y, z, xs, ys, zs);
        this.setLifetime(80 + random.nextInt(16));
    }

    @Override
    protected int getLightColor(float pPartialTick) {
        return 240;
    }

    @Override
    public @NotNull ParticleRenderType getRenderType() {
        return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
    }

    @Override
    public void tick() {
        if (this.age++ <= 20) {
            this.setAlpha(this.age * 0.05F);
        } else if (this.age >= this.getLifetime() - 20) {
            this.alpha -= 0.05F;
        }
        if (this.age >= this.getLifetime() && this.alpha <= 0) {
            this.remove();
        }
    }

    public static class Type extends SimpleParticleType {
        public Type(boolean overrideLimiter) {
            super(overrideLimiter);
        }
    }

    @Environment(EnvType.CLIENT)
    public static class Provider implements ParticleProvider<SimpleParticleType> {
        private final SpriteSet sprite;

        public Provider(SpriteSet sprites) {
            this.sprite = sprites;
        }

        public Particle createParticle(@NotNull SimpleParticleType type, @NotNull ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
            FireflyParticle particle = new FireflyParticle(level, x, y, z, xSpeed, ySpeed, zSpeed);
            particle.pickSprite(sprite);
            particle.setAlpha(1.0F);
            return particle;
        }
    }
}
// execute when net.fabricmc.api.ModInitializer::onInitialize is called
public static final DeferredRegister<ParticleType<?>> particleTypeRegistry = DeferredRegister.create("firefly8", Registries.PARTICLE_TYPE);
public static final RegistrySupplier<FireflyParticle.Type> FIREFLY = particleTypeRegistry.register("firefly", () -> new FireflyParticle.Type(true));
// execute when net.fabricmc.api.ClientModInitializer::onInitializeClient is called
ParticleProviderRegistry.register(FireflyParticles.FIREFLY, FireflyParticle.Provider::new);

And I created the resource pack like this.
assets/firefly8/particles/firefly.json

{
  "textures": [
    "firefly8:firefly"
  ]
}

The texture file is assets/firefly8/textures/particle/firefly.png.

However, the particle could not be rendered at all. I could use commands to summon the particle, but whenever it is summoned, nothing shows up!
I registered the particle provider via Architectury API, but why it does not work?
The Minecraft version is 1.21.4, the versions of related mods are Fabric Loader 0.16.10, Fabric API 0.118.0+1.21.4 and Architectury API 15.0.3.

commented

You can check ParticleProviderRegistry.register and you can find that this method is commented.

Here is my solution: https://github.com/IAFEnvoy/IceAndFire-CE/blob/34d31e331984cd3b01588723ac482ae5b41f2f40/common/src/main/java/com/iafenvoy/iceandfire/registry/IafRenderers.java#L104