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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
  • Topics

×
×
  • Create New...

Important Information

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