Jump to content

[1.7.10]How to spawn a 3D cube particle?


TominoCZ

Recommended Posts

I want to make my block spawn 3D little cube particles that look similar to this:

(craftland.org custom minecraft client with custom aether mod, multiplayer only).

 

I use a tessellator to draw.

 

here's my FX class:

 

package com.fancyparticles.mod;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_GREATER;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.glAlphaFunc;
import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glDepthMask;
import static org.lwjgl.opengl.GL11.glDisable;

import java.util.Random;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class EntityBreakFX extends EntityFX{

Random r = new Random();

static final ResourceLocation texture = new ResourceLocation(Main.MODID, "textures/particle/texture.png");

protected EntityBreakFX(World world, double x, double y, double z) 
{
	super(world, x, y, z);
	setGravity(1);
	setScale(1);
	setMaxAge(100);
}

@Override
public void renderParticle(Tessellator tess, float partialTicks, float par3, float par4, float par5, float par6, float par7)
{
	Minecraft.getMinecraft().renderEngine.bindTexture(texture);
	GL11.glDepthMask(false);
	GL11.glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glAlphaFunc(GL_GREATER, 0.003921569F);
	tess.startDrawingQuads();
	tess.setBrightness(getBrightnessForRender(partialTicks));
	float scale = 0.0125F * particleScale;
	float x = (float) (prevPosX + (posX - prevPosX) * partialTicks - interpPosX);
	float y = (float) (prevPosY + (posY - prevPosY) * partialTicks - interpPosY);
	float z = (float) (prevPosZ + (posZ - prevPosZ) * partialTicks - interpPosZ);

                //here used to be the part where it was drawing vertexes with UVs. that's 2D. How can I make it 3D?

                //here's my first attempt to render a cube (I was too lazy to keep trying to invert the inverted normal maps...... so they're not translucent...):
                /*
                //Front
	tess.addVertex(x + 1, y + 1, z + 1);
	tess.addVertex(x, y + 1, z + 1);
	tess.addVertex(x, y, z + 1);
	tess.addVertex(x + 1, y, z + 1);

	//Back
	tess.addVertex(x + 1, y + 1, z + 1);
	tess.addVertex(x, y + 1, z + 1);
	tess.addVertex(x, y, z + 1);
	tess.addVertex(x + 1, y, z + 1);

	//Bottom
	tess.addVertex(x + 1, y, z);
	tess.addVertex(x, y, z);
	tess.addVertex(x, y, z + 1);
	tess.addVertex(x + 1, y, z + 1);

	//Top
	tess.addVertex(x, y + 1, z);
	tess.addVertex(x, y + 1, z + 1);
	tess.addVertex(x + 1, y + 1, z + 1);
	tess.addVertex(x + 1, y + 1, z);

	//Left
	tess.addVertex(x, y + 1, z + 1);
	tess.addVertex(x, y, z + 1);
	tess.addVertex(x, y, z);
	tess.addVertex(x, y + 1, z);

	//Right
	tess.addVertex(x + 1, y + 1, z + 1);
	tess.addVertex(x + 1, y + 1, z);
	tess.addVertex(x + 1, y, z);
	tess.addVertex(x + 1, y, z + 1);
                */

	tess.draw();
	glDisable(GL_BLEND);
	glDepthMask(true);
	glAlphaFunc(GL_GREATER, 0.1F);
}

public int getFXLayer()
{
	return 3;
}

public EntityBreakFX setMaxAge (int maxAge)
{
	particleMaxAge = maxAge;
	return this;
}

public EntityBreakFX setGravity (int gravity)
{
	particleGravity = gravity;
	return this;
}

public EntityBreakFX setScale (int scale)
{
	particleScale = scale;
	return this;
}
}

 

Is it possible?

Link to comment
Share on other sites

1.7.10 is no longer supported, but since you gave an example it is obviously possible as it has been done before.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Yeah, but you should look into it using any other means possible, because creating a core mod could cause some errors with other mods.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

well since I don't really play any modpacks, I think it'll be ok with just block particles(breaking, and sprinting particles of the block you sprint on) :D

And another thing is that I don't know how to register the class with the effects and make it a core mod......

Also about that video.. that modpack runs on a minecraft client, that is customized including it'd LWJGL libraries....

 

I looked into the source code of the minecraft.jar file (the menu says  it's MC1.8 though) and they use Vector3 and such.. which I don't know how to use here.... one of my friends actually did make 3D particles but not using a core mod(they didn't replace the original ones..). I asked him for the code so I'm still waiting for response..

Link to comment
Share on other sites

Ok.. I did a little bit of research and learned how the vertexes with UV work nad played with it in MCP for a while(not forge, an internal mod - modified base class). This is the result: https://www.youtube.com/watch?v=6osH9bUVpsU

Now all I need is to make this work with forge. And that is by making this a core mod. Just like the NotEnoughItems mod.. But I just couldn't figure out how.

 

thanks  to this method I changed in EntityDiggingFX.class[MCP]:

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_)
    {
        float var8 = ((float)this.particleTextureIndexX + this.particleTextureJitterX / 4.0F) / 16.0F;
        float var9 = var8 + 0.015609375F;
        float var10 = ((float)this.particleTextureIndexY + this.particleTextureJitterY / 4.0F) / 16.0F;
        float var11 = var10 + 0.015609375F;
        float var12 = 0.1F * this.particleScale;

        if (this.particleIcon != null)
        {
        	var8 = this.particleIcon.getInterpolatedU((double)(this.particleTextureJitterX / 4.0F * 16.0F));
            var9 = this.particleIcon.getInterpolatedU((double)((this.particleTextureJitterX + 1.0F) / 4.0F * 16.0F));
            var10 = this.particleIcon.getInterpolatedV((double)(this.particleTextureJitterY / 4.0F * 16.0F));
            var11 = this.particleIcon.getInterpolatedV((double)((this.particleTextureJitterY + 1.0F) / 4.0F * 16.0F));
        }

        float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)p_70539_2_ - interpPosX);
        float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)p_70539_2_ - interpPosY) - var12 / 2;
        float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)p_70539_2_ - interpPosZ);
        p_70539_1_.setColorOpaque_F(1F, 1F, 1F); 
        //TODO
        
        //var8, var9 - X U
        //var 10, var 11 - Y V
        
        //front face
        p_70539_1_.addVertexWithUV(var13,         var14,         var15, (double)var8, (double)var10);
        p_70539_1_.addVertexWithUV(var13,         var14 + var12, var15, (double)var8, (double)var11);
        p_70539_1_.addVertexWithUV(var13 + var12, var14 + var12, var15, (double)var9, (double)var11);
        p_70539_1_.addVertexWithUV(var13 + var12, var14,         var15, (double)var9, (double)var10);
      
        //back face
        p_70539_1_.addVertexWithUV(var13 + var12, var14,         var15 + var12, (double)var8, (double)var10);
        p_70539_1_.addVertexWithUV(var13 + var12, var14 + var12, var15 + var12, (double)var8, (double)var11);
        p_70539_1_.addVertexWithUV(var13,         var14 + var12, var15 + var12, (double)var9, (double)var11);
        p_70539_1_.addVertexWithUV(var13,         var14,         var15 + var12, (double)var9, (double)var10);
        
        //left face
        p_70539_1_.addVertexWithUV(var13, var14,         var15 + var12, (double)var8, (double)var10);
        p_70539_1_.addVertexWithUV(var13, var14 + var12, var15 + var12, (double)var8, (double)var11);
        p_70539_1_.addVertexWithUV(var13, var14 + var12, var15,         (double)var9, (double)var11);
        p_70539_1_.addVertexWithUV(var13, var14,         var15,         (double)var9, (double)var10);
        
        //right face
        p_70539_1_.addVertexWithUV(var13 + var12, var14,         var15,         (double)var8, (double)var10);
        p_70539_1_.addVertexWithUV(var13 + var12, var14 + var12, var15,         (double)var8, (double)var11);
        p_70539_1_.addVertexWithUV(var13 + var12, var14 + var12, var15 + var12, (double)var9, (double)var11);
        p_70539_1_.addVertexWithUV(var13 + var12, var14,         var15 + var12, (double)var9, (double)var10);
        
        //top face
        p_70539_1_.addVertexWithUV(var13,         var14 + var12, var15,         (double)var8, (double)var10);
        p_70539_1_.addVertexWithUV(var13,         var14 + var12, var15 + var12, (double)var8, (double)var11);
        p_70539_1_.addVertexWithUV(var13 + var12, var14 + var12, var15 + var12, (double)var9, (double)var11);
        p_70539_1_.addVertexWithUV(var13 + var12, var14 + var12, var15,         (double)var9, (double)var10);
        
        //bottom face
        p_70539_1_.addVertexWithUV(var13,         var14, var15 + var12, (double)var8, (double)var10);
        p_70539_1_.addVertexWithUV(var13,         var14, var15,         (double)var8, (double)var11);
        p_70539_1_.addVertexWithUV(var13 + var12, var14, var15,         (double)var9, (double)var11);
        p_70539_1_.addVertexWithUV(var13 + var12, var14, var15 + var12, (double)var9, (double)var10);

    }

 

For forge, you add this piece of code to a new class extending EntityFX or EntityDiggingFX...

Spawn it with Minecraft.getMinecraft().addEffect.effectRenderer(new [your Particle Class]([params]))

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.