Jump to content

Recommended Posts

Posted

Currently, I am working on creating custom particles for 1.13.2. However, the public static final value of the particle type seems to throw null each time rather than getting the value. When I try adding an ObjectHolder annotation, the game says it cannot get the registry (which in my opinion is very confusing since Particles.class has a ObjectHolder annotation). If anyone could help, it would be much appreciated.

 

Particle:

Spoiler

package io.github.championash5357.superminecraftbrothers.client.particle;

import io.github.championash5357.superminecraftbrothers.init.SMBBlocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.particles.BasicParticleType;
import net.minecraft.util.IItemProvider;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;


@OnlyIn(Dist.CLIENT)
public class ParticleCoin extends Particle {

    protected ParticleCoin(World worldIn, double posXIn, double posYIn, double posZIn, IItemProvider item) {
        super(worldIn, posXIn, posYIn, posZIn, 0.0D, 0.0D, 0.0D);
        this.setParticleTexture(Minecraft.getInstance().getItemRenderer().getItemModelMesher().getParticleIcon(item));
        this.particleRed = this.particleGreen = this.particleBlue = 1.0F;
        this.motionX = this.motionY = this.motionZ = 0.0D;
        this.particleGravity = 0.0F;
        this.maxAge = 80;
        this.canCollide = true;
    }
    
    @Override
    public int getFXLayer() {
        return 1;
    }
    
    @Override
    public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
        float f = this.particleTexture.getMinU();
          float f1 = this.particleTexture.getMaxU();
          float f2 = this.particleTexture.getMinV();
          float f3 = this.particleTexture.getMaxV();
          float f5 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)partialTicks - interpPosX);
          float f6 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)partialTicks - interpPosY);
          float f7 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTicks - interpPosZ);
          int i = this.getBrightnessForRender(partialTicks);
          int j = i >> 16 & '\uffff';
          int k = i & '\uffff';
          buffer.pos((double)(f5 - rotationX * 0.5F - rotationXY * 0.5F), (double)(f6 - rotationZ * 0.5F), (double)(f7 - rotationYZ * 0.5F - rotationXZ * 0.5F)).tex((double)f1, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex();
          buffer.pos((double)(f5 - rotationX * 0.5F + rotationXY * 0.5F), (double)(f6 + rotationZ * 0.5F), (double)(f7 - rotationYZ * 0.5F + rotationXZ * 0.5F)).tex((double)f1, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex();
          buffer.pos((double)(f5 + rotationX * 0.5F + rotationXY * 0.5F), (double)(f6 + rotationZ * 0.5F), (double)(f7 + rotationYZ * 0.5F + rotationXZ * 0.5F)).tex((double)f, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex();
          buffer.pos((double)(f5 + rotationX * 0.5F - rotationXY * 0.5F), (double)(f6 - rotationZ * 0.5F), (double)(f7 + rotationYZ * 0.5F - rotationXZ * 0.5F)).tex((double)f, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F).lightmap(j, k).endVertex();
    }
    
    @OnlyIn(Dist.CLIENT)
    public static class OverworldFactory implements IParticleFactory<BasicParticleType> {

        @Override
        public Particle makeParticle(BasicParticleType typeIn, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
            return new ParticleCoin(worldIn, x, y, z, SMBBlocks.OVERWORLD_COIN.asItem());
        }
        
    }
}

 

Extension of BasicParticleType:

Spoiler

package io.github.championash5357.superminecraftbrothers.client.particle;

import net.minecraft.particles.BasicParticleType;
import net.minecraft.util.ResourceLocation;

public class SMBBasicParticleType extends BasicParticleType {

    public SMBBasicParticleType(ResourceLocation resourceLocationIn, boolean alwaysRender) {
        super(resourceLocationIn, alwaysRender);
    }
}

 

ParticleType:

Spoiler

package io.github.championash5357.superminecraftbrothers.client.particle;

import io.github.championash5357.superminecraftbrothers.SuperMinecraftBrothers;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;

public class SMBParticleType {
    
    public static void register() {
        registerParticleType("overworld_coin", true);
    }
    
    private static void registerParticleType(String id, boolean alwaysRender) {
        IRegistry.field_212632_u.put(new ResourceLocation(SuperMinecraftBrothers.ID, id), new SMBBasicParticleType(new ResourceLocation(SuperMinecraftBrothers.ID, id), alwaysRender));
    }
}

 

ParticleManager:

Spoiler

package io.github.championash5357.superminecraftbrothers.client.particle;

import io.github.championash5357.superminecraftbrothers.init.SMBParticles;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class SMBParticleManager {
    
    public static void register() {
        Minecraft.getInstance().particles.registerFactory(SMBParticles.OVERWORLD_COIN, new ParticleCoin.OverworldFactory());
    }
}

 

Particles:

Spoiler

package io.github.championash5357.superminecraftbrothers.init;

import io.github.championash5357.superminecraftbrothers.SuperMinecraftBrothers;
import io.github.championash5357.superminecraftbrothers.client.particle.SMBBasicParticleType;
import net.minecraft.init.Bootstrap;
import net.minecraft.particles.ParticleType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;

public class SMBParticles {
    
    public static final SMBBasicParticleType OVERWORLD_COIN;
    
    private static <T extends ParticleType<?>> T getRegisteredParticleTypes(String id) {
        @SuppressWarnings("unchecked")
        T t = (T)IRegistry.field_212632_u.func_212608_b(new ResourceLocation(SuperMinecraftBrothers.ID, id));
        if (t == null) {
            throw new IllegalStateException("Invalid or unknown particle type: " + id);
        } else {
            return t;
        }
    }
    
    static {
        if(!Bootstrap.isRegistered()) {
            throw new RuntimeException("Accessed particles before Bootstrap!");
        } else {
            OVERWORLD_COIN = getRegisteredParticleTypes("overworld_coin");
        }
    }
}

 

Main (Common and Client setup):

Spoiler

    public void setup(final FMLCommonSetupEvent event) {
        SMBParticleType.register();
    }
    
    public void clientSetup(final FMLClientSetupEvent event) {
        SMBParticleManager.register();
    }

 

Posted

Post the error you get

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.

Announcements



×
×
  • Create New...

Important Information

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