Jump to content

[1.7.10] Custom particles not rendering


TehStoneMan

Recommended Posts

Hello. I am trying to create a custom blue flame particle, but I am unable to get it to render. My code appears to work, but nothing comes up in game. Can somebody help?

 

package io.github.tehstoneman.zombiebrains.block;

....

public class BlockLapisTorch extends Block
{

....

/**
 * A randomly called display update to be able to add particles or other
 * items for display
 */
@Override
 @SideOnly( Side.CLIENT )
public void randomDisplayTick( World world, int x, int y, int z, Random rand )
{
	final int l = world.getBlockMetadata( x, y, z );
	final double d0 = x + 0.5F;
	final double d1 = y + 0.7F;
	final double d2 = z + 0.5F;
	final double d3 = 0.2199999988079071D;
	final double d4 = 0.27000001072883606D;

	if( l == 1 )
	{
		world.spawnParticle( "smoke", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D );
		//RenderParticle.spawnParticle( "blueFlame", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D );
		world.spawnParticle( "flame", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D );
	}
	else
		if( l == 2 )
		{
			world.spawnParticle( "smoke", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D );
			RenderParticle.spawnParticle( "blueFlame", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D );
		}
		else
			if( l == 3 )
			{
				world.spawnParticle( "smoke", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D );
				RenderParticle.spawnParticle( "blueFlame", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D );
			}
			else
				if( l == 4 )
				{
					world.spawnParticle( "smoke", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D );
					RenderParticle.spawnParticle( "blueFlame", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D );
				}
				else
				{
					world.spawnParticle( "smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D );
					RenderParticle.spawnParticle( "blueFlame", d0, d1, d2, 0.0D, 0.0D, 0.0D );
				}
}
}

package io.github.tehstoneman.zombiebrains.client.renderer;

import io.github.tehstoneman.zombiebrains.client.particle.EntityBlueFlameFX;

....

public class RenderParticle
{
private static Minecraft		mc				= Minecraft.getMinecraft();
private static World			theWorld		= mc.theWorld;
private static TextureManager	renderEngine	= mc.getTextureManager();

/**
 * Spawns a particle. Arg: particleType, x, y, z, velX, velY, velZ
 */
public static void spawnParticle( String particleType, double x, double y, double z, double velX, double velY, double velZ )
{
	try
	{
		doSpawnParticle( particleType, x, y, z, velX, velY, velZ );
	}
	catch( final Throwable throwable )
	{
		final CrashReport crashreport = CrashReport.makeCrashReport( throwable, "Exception while adding particle" );
		final CrashReportCategory crashreportcategory = crashreport.makeCategory( "Particle being added" );
		crashreportcategory.addCrashSection( "Name", particleType );
		crashreportcategory.addCrashSectionCallable( "Position", new Callable()
		{
			@Override
			public String call()
			{
				return CrashReportCategory.func_85074_a( x, y, z );
			}
		} );
		throw new ReportedException( crashreport );
	}
}

/**
 * Spawns a particle. Arg: particleType, x, y, z, velX, velY, velZ
 */
public static EntityFX doSpawnParticle( String particleType, double x, double y, double z, double velX, double velY, double velZ )
{
	if( mc != null && mc.renderViewEntity != null && mc.effectRenderer != null )
	{
		int particleLevel = mc.gameSettings.particleSetting;

		if( particleLevel == 1 && theWorld.rand.nextInt( 3 ) == 0 )
			particleLevel = 2;

		final double viewX = mc.renderViewEntity.posX - x;
		final double viewY = mc.renderViewEntity.posY - y;
		final double viewZ = mc.renderViewEntity.posZ - z;
		EntityFX entityfx = null;

		final double distance = 16.0D;

		if( viewX * viewX + viewY * viewY + viewZ * viewZ > distance * distance )
			return null;
		else
			if( particleLevel > 1 )
				return null;
			else
			{
				if( particleType.equals( "blueFlame" ) )
					entityfx = new EntityBlueFlameFX( theWorld, x, y, z, velX, velY, velZ );

				if( entityfx != null )
					mc.effectRenderer.addEffect( entityfx );

				return entityfx;
			}
	}
	else
		return null;
}

}

package io.github.tehstoneman.zombiebrains.client.particle;

import io.github.tehstoneman.zombiebrains.ModInfo;

....

@SideOnly( Side.CLIENT )
public class EntityBlueFlameFX extends ZombieEntityFX
{
/** the scale of the flame FX */
private final float	flameScale;

public EntityBlueFlameFX( World p_i1209_1_, double p_i1209_2_, double p_i1209_4_, double p_i1209_6_, double p_i1209_8_, double p_i1209_10_,
		double p_i1209_12_ )
{
	super( p_i1209_1_, p_i1209_2_, p_i1209_4_, p_i1209_6_, p_i1209_8_, p_i1209_10_, p_i1209_12_ );
	motionX = motionX * 0.009999999776482582D + p_i1209_8_;
	motionY = motionY * 0.009999999776482582D + p_i1209_10_;
	motionZ = motionZ * 0.009999999776482582D + p_i1209_12_;
	double d6 = p_i1209_2_ + ( rand.nextFloat() - rand.nextFloat() ) * 0.05F;
	d6 = p_i1209_4_ + ( rand.nextFloat() - rand.nextFloat() ) * 0.05F;
	d6 = p_i1209_6_ + ( rand.nextFloat() - rand.nextFloat() ) * 0.05F;
	flameScale = particleScale;
	particleRed = particleGreen = particleBlue = 1.0F;
	particleMaxAge = (int)( 8.0D / ( Math.random() * 0.8D + 0.2D ) ) + 4;
	noClip = true;
        this.particleTextureIndexX = 0;
        this.particleTextureIndexY = 0;
}

@Override
public void renderParticle( Tessellator p_70539_1_, float p_70539_2_, float p_70539_3_, float p_70539_4_, float p_70539_5_, float p_70539_6_,
		float p_70539_7_ )
{
	final float f6 = ( particleAge + p_70539_2_ ) / particleMaxAge;
	particleScale = flameScale * ( 1.0F - f6 * f6 * 0.5F );
	//Minecraft.getMinecraft().getTextureManager().bindTexture( new ResourceLocation( ModInfo.MODID + ":textures/particle/particles.png" ) );
	super.renderParticle( p_70539_1_, p_70539_2_, p_70539_3_, p_70539_4_, p_70539_5_, p_70539_6_, p_70539_7_ );
}

@Override
public int getBrightnessForRender( float p_70070_1_ )
{
	float f1 = ( particleAge + p_70070_1_ ) / particleMaxAge;

	if( f1 < 0.0F )
		f1 = 0.0F;

	if( f1 > 1.0F )
		f1 = 1.0F;

	final int i = super.getBrightnessForRender( p_70070_1_ );
	int j = i & 255;
	final int k = i >> 16 & 255;
	j += (int)( f1 * 15.0F * 16.0F );

	if( j > 240 )
		j = 240;

	return j | k << 16;
}

/**
 * Gets how bright this entity is.
 */
@Override
public float getBrightness( float p_70013_1_ )
{
	float f1 = ( particleAge + p_70013_1_ ) / particleMaxAge;

	if( f1 < 0.0F )
		f1 = 0.0F;

	if( f1 > 1.0F )
		f1 = 1.0F;

	final float f2 = super.getBrightness( p_70013_1_ );
	return f2 * f1 + ( 1.0F - f1 );
}

/**
 * Called to update the entity's position/logic.
 */
@Override
public void onUpdate()
{
	prevPosX = posX;
	prevPosY = posY;
	prevPosZ = posZ;

	if( particleAge++ >= particleMaxAge )
		setDead();

	moveEntity( motionX, motionY, motionZ );
	motionX *= 0.9599999785423279D;
	motionY *= 0.9599999785423279D;
	motionZ *= 0.9599999785423279D;

	if( onGround )
	{
		motionX *= 0.699999988079071D;
		motionZ *= 0.699999988079071D;
	}
}

@Override
public int getFXLayer()
{
	return 3;
}
}

package io.github.tehstoneman.zombiebrains.client.particle;

import io.github.tehstoneman.zombiebrains.ModInfo;

....

public class ZombieEntityFX extends EntityFX
{

....

@Override
public void renderParticle( Tessellator tess, float par2, float par3, float par4, float par5, float par6, float par7 )
{
	Minecraft.getMinecraft().getTextureManager().bindTexture( new ResourceLocation( ModInfo.MODID + ":textures/particle/particles.png" ) );
	//Minecraft.getMinecraft().getTextureManager().bindTexture( new ResourceLocation( "textures/particle/particles.png" ) );
	//super.renderParticle( tess, par2, par3, par4, par5, par6, par7 );
	float f6 = (float)this.particleTextureIndexX / 16.0F;
        float f7 = f6 + 0.0624375F;
        float f8 = (float)this.particleTextureIndexY / 16.0F;
        float f9 = f8 + 0.0624375F;
        float f10 = 0.1F * this.particleScale;

        float f11 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX);
        float f12 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY);
        float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ);
        tess.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha);
        tess.addVertexWithUV((double)(f11 - par3 * f10 - par6 * f10), (double)(f12 - par4 * f10), (double)(f13 - par5 * f10 - par7 * f10), (double)f7, (double)f9);
        tess.addVertexWithUV((double)(f11 - par3 * f10 + par6 * f10), (double)(f12 + par4 * f10), (double)(f13 - par5 * f10 + par7 * f10), (double)f7, (double)f8);
        tess.addVertexWithUV((double)(f11 + par3 * f10 + par6 * f10), (double)(f12 + par4 * f10), (double)(f13 + par5 * f10 + par7 * f10), (double)f6, (double)f8);
        tess.addVertexWithUV((double)(f11 + par3 * f10 - par6 * f10), (double)(f12 - par4 * f10), (double)(f13 + par5 * f10 - par7 * f10), (double)f6, (double)f9);
}

/**
 * Public method to set private field particleTextureIndex.
 */
@Override
public void setParticleTextureIndex( int index )
{
	particleTextureIndexX = index % 16;
	particleTextureIndexY = index / 16;
}

@Override
public int getFXLayer()
{
	return 3;
}
}

 

If it helps, full source is available on GitHub - https://github.com/TehStoneMan/ZombieBrains

Link to comment
Share on other sites

There doesn't seem to be a way to register particles. You almost need to build your own particle system to have custom particles.

The problem is, even though my code seems to be running, having run it through a debug trace, it just doesn't seem to render my particles.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • no this one https://pastebin.com/5uMxHeWf
    • I am in such a mess. I have lost over 4.7m due to a scammer... It started as bank wires and then bitcoin. it is hard to imagine but it is true and can send any proof, then I tried to use a couple of recovery companies and was as well. Graphic design has been more than just a hobby for me since high school—it has become a thriving career. Starting in my parents' garage, I eventually expanded to my office, running a successful graphic design business. However, like many, I faced the need to diversify my investments due to inflation. This led me to invest 60.16 in Bitcoin, a decision that paid off handsomely as my investment grew to 4.7m over time. This financial windfall allowed me to upgrade my equipment and take on more ambitious projects, furthering the growth of my business. Unfortunately, my excitement was abruptly cut short when I fell victim to a hacking incident. Malware infected my computer, giving hackers access to my Bitcoin wallet. The devastation of potentially losing all my hard-earned savings and plans weighed heavily on me. At this dire moment, a fellow designer suggested Linux Cyber Security Company as a potential solution. Desperate for a lifeline, I reached out to them, hoping for a miracle. The response from Linux Cyber Security Company was prompt, incredibly professional, and effective. Their team quickly traced the hacker’s activities and recovered most of my funds, alleviating a significant amount of stress and uncertainty. Beyond the recovery, they took the time to educate me on essential practices to secure my Bitcoin holdings better. They emphasized using antivirus software to prevent malware infections, avoiding suspicious downloads, and the added security provided by hardware wallets. This experience served as a critical wake-up call for me. It highlighted the vulnerabilities inherent in digital assets and underscored the importance of robust security measures. Thanks to the guidance and expertise of Linux Cyber Security Company, I now feel more equipped to protect my digital assets proactively. Their insights have empowered me to implement stronger security protocols in my business operations and personal finances alike. With my Bitcoin funds securely recovered and a newfound understanding of digital security best practices, I am more confident in navigating future challenges. This journey has reinforced my commitment to safeguarding my hard-earned assets and leveraging technology responsibly. I am optimistic about the growth opportunities ahead, creatively in graphic design and prudently in investment strategies. In conclusion, while the hacking incident was a setback, it ultimately became a catalyst for enhancing my digital security awareness and resilience. I am grateful to Linux Cyber Security Company for their expertise and support during a challenging time, enabling me to continue pursuing my passion for graphic design with renewed confidence and financial stability. Contact a professional company I am sure they can help you with your case too, Website [www.linuxcybersecurity.com Email the team; info@)(linuxcybersecurity.com
    • https://pastebin.com/B2HnBZTa
    • it was easy villager mate, thanks ill see how to do it without that mod! thanks
  • Topics

×
×
  • Create New...

Important Information

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