Jump to content

Particle FX Tutorial


pro-mole

Recommended Posts

Does anyone know of any tutorial or example code on creating particles and spawning them? I'm having a hard time figuring how to do it from the Javadocs code, and I'd like to use particles to tell the player that one of my blocks is working or has reached a certain state(especifically, that it's consuming some fuel to produce items).

 

Thanks in advance. :)

Link to comment
Share on other sites

Well, as far as I figured from examining Vanilla code, I can only create particles available in the Vanilla build -- they are identified by String arguments and there's no way to access the EntityFX class -- and only via some functions -- so far, only in the displayRandomTick function of the Block. In other words, the whole thing is pretty limited as far as I can see.

 

I'd like to at least be able to play around with what I have, like, for example, flashing green redstone particles over a block.

 

I'm gonna try and use some raw spawnEntityInWorld to do that. Wish me luck.

Link to comment
Share on other sites

I was messing with this the other day because I wanted a small candle flame for a block. I was able to create new particle effects and use them without too much trouble.

 

First I created a new class that extends EntityFX. See something like EntityFlameFX for example. To get my particle to spawn I used the displayRandomTick method on the block and used something similar to this:

 

EntityFX candleFlame = new EntityCandleFX(world, x, y, z, 0.0D, 0.0D, 0.0D);
Minecraft.getMinecraft().effectRenderer.addEffect(candleFlame)

 

My x, y, z values are setup with a switch case that depends on 1 of 4 angles that takes the x, y, z, sent to the randomDisplayTick method and adds those with my desired offsets for each angle.

 

Hopefully that is helpful. Good luck.  :D

Link to comment
Share on other sites

Very good, Nuchaz, that worked! :D I haven't created a new custom EntityFX class yet, but I managed to do some green dust flying from my block. Awesome!

 

But now I'm getting some weird problems... When I have my sparkles running(I put the code inside a Tile Entity, sparkling at random times about 8 times each 10 seconds) I randomly get... this

 

-- Head --
Stacktrace:
at net.minecraft.entity.Entity.moveEntity(Entity.java:769)
at net.minecraft.entity.EntityLiving.moveEntityWithHeading(EntityLiving.java:1535)
at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:1823)
at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:37)
at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:843)
at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:45)
at net.minecraft.entity.monster.EntityCreeper.onUpdate(EntityCreeper.java:173)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2295)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:645)
at net.minecraft.world.World.updateEntity(World.java:2257)

-- Entity being ticked --
Details:
Entity Type: Creeper (net.minecraft.entity.monster.EntityCreeper)
Entity ID: 178
Name: Creeper
Exact location: -89.98, 41.00, 5.49
Block location: World: (-90,41,5), Chunk: (at 6,2,5 in -6,0; contains blocks -96,0,0 to -81,255,15), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
Momentum: 0.00, -0.08, 0.00
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:2103)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:514)

(...)
java.lang.NullPointerException

 

Actually, that's not even the only error I get, sometimes it's sheep, or chicken or... well, anything. It's pretty random. Any idea? Maybe this isn't a good way to go about with particles? :/

 

SUDDEN REALIZATION EDIT: Wait, I should be doing this on Client side only, isn't it?

Link to comment
Share on other sites

Okay, quick update: doing this in randomDisplayTick() works fine. Using addEffect instead of spawnParticle is that I can instantiate the entity and change it before to, say,  make it green instead of the usual red.

 

Now I have other problems to deal with but this is closed. I'll add this to my list of "tutorials to write" and thank you very much. :D

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.