Jump to content

[1.16.3] Custom Particle Registry Object not Present.


Pickle_Face5

Recommended Posts

I'm making a custom particle to ake the game more "alive", but I've never done particles, so this is fun. Anyway, heres the code for the part where I register the factory:

@Mod.EventBusSubscriber(modid = WildCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ParticleUtil {

    @SubscribeEvent()
    public static void registerParticles(ParticleFactoryRegisterEvent event) {
        Minecraft.getInstance().particles.registerFactory(Registry.SPIDER_PARTICLE.get(), SpiderParticle.Factory::new);
    }
}

I'm assuming there something wrong with the particle class itself also, so I'll put its code here also:

@OnlyIn(Dist.CLIENT)
public class SpiderParticle extends SpriteTexturedParticle {
    public SpiderParticle(ClientWorld world, double x, double y, double z, double motionX, double motionY, double motionZ) {
        super(world, x, y, z, motionX, motionY, motionZ);

        float f = this.rand.nextFloat() * 1.0F;
        this.particleRed = f;
        this.particleGreen = f;
        this.particleBlue = f;

        this.setSize(0.02F, 0.02F);
        this.particleScale *= this.rand.nextFloat() * 1.1F;
        this.motionX *= (double)0.02F;
        this.motionY *= (double)0.02F;
        this.motionZ *= (double)0.02F;
        this.maxAge = (int)(20.0D / (Math.random() * 1.0D));
    }

    @Override
    public IParticleRenderType getRenderType() {
        return IParticleRenderType.PARTICLE_SHEET_OPAQUE;
    }

    @Override
    public void tick() {
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;

        if(this.maxAge-- <= 0) {
            this.setExpired();
        } else {
            this.move(this.motionX, this.motionY, this.motionZ);
            this.motionX *= 1.0D;
            this.motionY *= 1.0D;
            this.motionZ *= 1.0D;
        }
    }

    @OnlyIn(Dist.CLIENT)
    public static class Factory implements IParticleFactory<BasicParticleType> {
        private final IAnimatedSprite spriteSet;
        public Factory(IAnimatedSprite sprite) {
            this.spriteSet = sprite;
        }

        @Override
        public Particle makeParticle(BasicParticleType typeIn, ClientWorld worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
            SpiderParticle spiderParticle = new SpiderParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed);
            spiderParticle.setColor(1.0F, 1.0F, 1.0F);
            spiderParticle.selectSpriteRandomly(spriteSet);
            return spiderParticle;
        }
    }
}

Any help is appreciated, thanks.

Have some lorem ispum.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.