Jump to content

[1.7.10] Spawning Particles


NJay

Recommended Posts

I do it for one of my custom entities like this, in the onUpdate() event (or some other event that happens every tick):

 

if (!worldObj.isRemote && rand.nextFloat()<0.1F)

{

double var4 = rand.nextGaussian() * 0.02D;

double var6 = rand.nextGaussian() * 0.02D;

double var8 = rand.nextGaussian() * 0.02D;

EntityFX particleMysterious = new EntityParticleFXMysterious(worldObj, posX + rand.nextFloat() * width * 2.0F - width, posY + 0.5D + rand.nextFloat() * height, posZ + rand.nextFloat() * width * 2.0F - width, var4, var6, var8);

Minecraft.getMinecraft().effectRenderer.addEffect(particleMysterious);

}

 

In this case, EntityParticleFXMysterious is a class I made that extends EntityParticleFX but you can also use the standard particles if you want.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

if (!worldObj.isRemote && rand.nextFloat()<0.1F)

{

//....

Minecraft.getMinecraft().effectRenderer.addEffect(particleMysterious);

}

Aiiieeee {screams of agony as minecraft crashes randomly yet again with a strange error message}  :)

 

that should be

if (worldObj.isRemote)

Slip of the keys I guess?  you must not access Minecraft from the server side.

 

If you have access to a world or even better a worldclient, for a vanilla particle you can also use eg

 

  worldClient.spawnParticle("particlenamehere", spawnXpos, spawnYpos, spawnZpos, 0, 0, 0);

 

 

-TGG

 

 

Link to comment
Share on other sites

NO check for isRemote - Spawning particles at first, then crashing with an exception referring to the particles

Check for isRemote - Not spawning particles

Check for !isRemote - Spawning particles at first, then crashing with an exception referring to a random entity in the world (e.g. a cow, a pig, a villager etc.)

 

I'm also calling this from onUpdate in an entity class

Link to comment
Share on other sites

TGG,  I understand the concern over the running of Minecraft.getMinecraft() on server side.  I think it is odd too.  Some, vanilla code seems to do that when calling the Effect Renderer (from an mc that is found with Minecraft.getMinecraft().  And it doesn't crash and it works fine for me, which surprised me.

 

However, to be safe I switched it to remove the negation and it still works.  So yeah, probably better to do is that way.

 

NJay, can you post your onUpdate() method code as well as the actual error messages?

 

 

 

 

 

 

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

sooo... Meanwhile I put the particle spawning code into a method called by the model when the entity is rendered, but that - of course - doesn't work in multiplayer.

 

My onUpdate method:

 


public void onUpdate() {
    	super.onUpdate();
    	if(this.onGround || this.isInWater()){
    		this.setIsFlying(false); //Updating entity's logic, so the particles are only spawned for the "flying"-boolean true
    	}
    	
    	if(this.getIsFlying()){
    	if(worldObj.isRemote){     // or !worldObj.isRemote
    		EntityFX particle = new EntityReddustFX(this.worldObj, this.posX, posY, this.posZ, 1.0F, 2.0F, 1.0F); // actually, these three lines are repeated six times in a for loop,
		particle.setRBGColorF(colorsR[i], colorsG[i], colorsB[i]); // to change colors and position. I simplified it a little here.
		Mod.proxy.addParticleEffect(particle);   // This method does nothing on server side and is only overridden by client
    	}
    		
    	}
    	
    
    }

 

ClientProxy#addParticleEffect:

 

@Override
public void addParticleEffect(EntityFX particle) {
	Minecraft.getMinecraft().effectRenderer.addEffect(particle);
}

 

 

 

Error logs with no check for isRemote or !isRemote:

 


net.minecraft.util.ReportedException: Ticking Particle
at net.minecraft.client.particle.EffectRenderer.updateEffects(EffectRenderer.java:102) ~[EffectRenderer.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2136) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1029) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
        [...]


 

 

Error with check for !isRemote:

 


at net.minecraft.entity.Entity.moveEntity(Entity.java:723)
at net.minecraft.entity.EntityLivingBase.moveEntityWithHeading(EntityLivingBase.java:1678)
at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2021)
at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:431)
at net.minecraft.entity.EntityAgeable.onLivingUpdate(EntityAgeable.java:138)
at net.minecraft.entity.passive.EntityAnimal.onLivingUpdate(EntityAnimal.java:56)
at net.minecraft.entity.passive.EntitySheep.onLivingUpdate(EntitySheep.java:98)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1814)
at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:250)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2296)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:684)
at net.minecraft.world.World.updateEntity(World.java:2256)

-- Entity being ticked --
Details:
Entity Type: Sheep (net.minecraft.entity.passive.EntitySheep)
Entity ID: 153
Entity Name: Sheep
Entity's Exact location: -200,78, 72,00, 415,77
Entity's Block location: World: (-201,72,415), Chunk: (at 7,4,15 in -13,25; contains blocks -208,0,400 to -193,255,415), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
Entity's Momentum: 0,00, -0,08, 0,00


 

Sometimes Sheep, sometimes Pig, sometimes Villager, sometimes Wolf. lol

Link to comment
Share on other sites

Yes, yes, it was commented out at the time when I copied it, which doesn't change the funcionality of the code, since onUpdate seemingly doesn't get called by client. The getHorseWatchableBoolean worked fine for me, I was able to get / set the right booleans... How would I solve it else?

Link to comment
Share on other sites

Sorry, I don't get it  :( To be honest, I copied that code from the EntityHorse to be able to get the booleans from the model class. Is the 256 the wrong part? I mean, it's over 32, but in the EntityHorse class the method gets called with 128 and 64, so I took 256, because it was the next power of 2... Sorry if I miss something obvious

 

NJay

Link to comment
Share on other sites

It is. When I don't check for isRemote, the particles are actually spawned while flying. Also, accessing the boolean from the model class worked which only spawned the particles in singleplayer worlds. I'm really stuck here.

Link to comment
Share on other sites

I somehow managed the particles to spawn...

Now I know whose fault this was, this.onGround isn't working and returning always false which makes no sense but - somehow - forced my onUpdate to always set isFlyin to false. My problem now is that I don't know how to determine if the Entity is standing on the ground.

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.