Jump to content

[1.3.2] Particle Effect help [SOLVED]


_bau5

Recommended Posts

Looking to add my own custom textured particles to the game. Others have had success, but I can't quite get it.

 

Here's what i've got:

 

My effect that extends EntityFX

 

public TestEffect(World par1World, double par2, double par4, double par6, double par8, double par10, double par12) 
{
	super(par1World, par2, par4, par6, par8, par10, par12);
	this.particleMaxAge = 10000;
	this.worldObj = par1World;
	this.setParticleTextureIndex(48);
	coolDown = 200;
}
public String getTexture()
{
	return Alptraum.baseTextureFile + "/p.png";
}
    public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
    {
    	ForgeHooksClient.bindTexture(getTexture(), 0);
    	float var8 = (float)(this.getParticleTextureIndex() % 16) / 16.0F;
        float var9 = var8 + 0.0624375F;
        float var10 = (float)(this.getParticleTextureIndex() / 16) / 16.0F;
        float var11 = var10 + 0.0624375F;
        float var12 = 0.1F * this.particleScale;
        float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX);
        float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY);
        float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ);
        float var16 = 1.0F;
        par1Tessellator.setColorOpaque_F(this.particleRed * var16, this.particleGreen * var16, this.particleBlue * var16);
        par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 - par5 * var12 - par7 * var12), (double)var9, (double)var11);
        par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 - par5 * var12 + par7 * var12), (double)var9, (double)var10);
        par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 + par5 * var12 + par7 * var12), (double)var8, (double)var10);
        par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 + par5 * var12 - par7 * var12), (double)var8, (double)var11);
    }

 

Adding the effect itself to the game when it is tried to spawn:

 

EntityFX var0 = null;
		Alptraum.mc.effectRenderer.addEffect(var0 = new TestEffect(Alptraum.mc.theWorld, Alptraum.mc.theWorld.getSpawnPoint().posX, Alptraum.mc.theWorld.getSpawnPoint().posY, Alptraum.mc.theWorld.getSpawnPoint().posZ, 0F, 0F, 0F));
		world.spawnEntityInWorld(new TestEffect(world, ep.posX, ep.posY, ep.posZ, 0F, 0F, 0F));

 

Any insight would be awesome, thanks.

 

Also, this is where i followed someone's solution:

http://www.minecraftforum.net/topic/1213462-adding-custom-texture-to-custom-particle-effect/

 

EDIT: Just as a note, they're rendering as white boxes in game. I know the texture is in the right place, already debugged that.

Link to comment
Share on other sites

You shouldn't use world.spawnEntityInWorld for particles. Just use Alptraum.mc.effectRenderer.addEffect

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Works for me, but only on the client in some cases. If I apply some code for the server, the game crashes. Dunno why :/ I have to figure out how to spawn the particles on a server.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Sorry, just clarifying. Once again, the effectRenderer.addEffect will also spawn the particle at the same time?

 

Yup, it's how the vanilla code works.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

You're right, that works! Thanks. The only issue is now that I can't see it at all. I know its spawning and I know it's near me, just can't see it. I also know that it is finding the texture because it's overriding the other particles in the game (I know how to stop that, I was just making sure it was successfully finding my particle sprite sheet).

 

Here's my particle's class. Sorry for the persistent problem guys :P

package _bau5.alptraum;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.FMLClientHandler;

import net.minecraft.src.EntityFX;
import net.minecraft.src.Tessellator;
import net.minecraft.src.World;
import net.minecraftforge.client.ForgeHooksClient;

public class TestEffect extends EntityFX
{

private int coolDown;

public TestEffect(World par1World, double par2, double par4, double par6, double par8, double par10, double par12) 
{
	super(par1World, par2, par4, par6, par8, par10, par12);
	this.particleMaxAge = 100;
	this.worldObj = par1World;
	this.setParticleTextureIndex(0);
	coolDown = 0;
}
public String getTexture()
{
	return Alptraum.particlesTextureFile;
}
    public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
    {
    	Tessellator tessellator1 = new Tessellator();
        tessellator1.startDrawingQuads();
        tessellator1.setBrightness(getBrightnessForRender(par2));
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, Alptraum.mc.renderEngine.getTexture(getTexture()));
        float f = (float)(getParticleTextureIndex() % 16) / 16F;
        float f1 = f + 0.0624375F;
        float f2 = (float)(getParticleTextureIndex() / 16) / 16F;
        float f3 = f2 + 0.0624375F;
        float f4 = 0.1F * particleScale;
        float f5 = (float)((prevPosX + (posX - prevPosX) * (double)par2) - interpPosX);
        float f6 = (float)((prevPosY + (posY - prevPosY) * (double)par2) - interpPosY);
        float f7 = (float)((prevPosZ + (posZ - prevPosZ) * (double)par2) - interpPosZ);
        float f8 = 1.0F;
        tessellator1.setColorOpaque_F(particleRed * f8, particleGreen * f8, particleBlue * f8);
        tessellator1.addVertexWithUV(f5 - par3 * f4 - par6 * f4, f6 - par4 * f4, f7 - par5 * f4 - par7 * f4, f1, f3);
        tessellator1.addVertexWithUV((f5 - par3 * f4) + par6 * f4, f6 + par4 * f4, (f7 - par5 * f4) + par7 * f4, f1, f2);
        tessellator1.addVertexWithUV(f5 + par3 * f4 + par6 * f4, f6 + par4 * f4, f7 + par5 * f4 + par7 * f4, f, f2);
        tessellator1.addVertexWithUV((f5 + par3 * f4) - par6 * f4, f6 - par4 * f4, (f7 + par5 * f4) - par7 * f4, f, f3);
   
        tessellator1.draw();
   
//        GL11.glBindTexture(GL11.GL_TEXTURE_2D, Alptraum.mc.renderEngine.getTexture("/particles.png")); 
    }

    /**
     * Called to update the entity's position/logic.
     */
    public void onUpdate()
    {
    	System.out.println("Alive");
    	double goodsX = WorldSensitiveInfo.locOfGoods[0];
    	double goodsY = WorldSensitiveInfo.locOfGoods[1];
    	double goodsZ = WorldSensitiveInfo.locOfGoods[2];
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;

        coolDown++;
        if(worldObj.getClosestPlayer(posX, posY, posZ, 25D) != null && coolDown >= 50)
        {
        	Alptraum.mc.sndManager.playSoundFX("mods.Alptraum.insanity", 1.0F, 1F);
        	System.out.println("yaya");
        	coolDown = 0;
        }
        if (this.particleAge++ >= this.particleMaxAge)
        {
            this.setDead();
        }
        
        this.motionY += 0.004D;
        this.moveEntity(this.motionX, this.motionY, this.motionZ);

        if (this.posY == this.prevPosY)
        {
            this.motionX *= 1.1D;
            this.motionZ *= 1.1D;
        }

        this.motionX *= 0.9599999785423279D;
        this.motionY *= 0.9599999785423279D;
        this.motionZ *= 0.9599999785423279D;

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

Link to comment
Share on other sites

How do you spawn the particles exactly or better saying what triggers the spawn of particles? Do you have this issue on the Client or do you test on a server?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.