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.

Announcements



×
×
  • Create New...

Important Information

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