Jump to content

[1.10.2][SOLVED]Creating a method for spawning particles on the server side


Recommended Posts

Posted

I want to spawn particles based on a given item stack (

EnumParticleTypes.ITEM_CRACK

/

EnumParticleTypes.BLOCK_CRACK

), trouble is, particles are client sided and the places in the code where I want the effects are all server sided. I created a method to spawn them so I didn't have to type out the code over and over, but that doesn't help the fact that it's the wrong side. I'm aware of

DataParameter

s, although since I need a given

ItemStack

and they only take booleans, ints, floats etc. (right?), I don't think they will be much use.

 

Here's the method so far, please help improve upon it :)

@SideOnly(Side.CLIENT)
public void spawnEatParticles(ItemStack stack) {
if(stack.getItem() instanceof ItemBlock) {
	Block block = ((ItemBlock)stack.getItem()).getBlock();
	for(int i = 0; i < 20; i++) {
		this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.headPosition.getX() + (double)this.rand.nextFloat() - (this.getPosition().getX() - this.posX) - 0.5, this.headPosition.getY() + (double)this.rand.nextFloat() - (this.getPosition().getY() - this.posY), this.headPosition.getZ() + (double)this.rand.nextFloat() - (this.getPosition().getZ() - this.posZ) - 0.5, (this.rand.nextInt(6) - 3) / 5, 0.1, (this.rand.nextInt(6) - 3) / 5, new int[] {Block.getIdFromBlock(block)});
	}
}
else {
	for(int i = 0; i < 20; i++) {
		this.worldObj.spawnParticle(EnumParticleTypes.ITEM_CRACK, this.headPosition.getX() + (double)this.rand.nextFloat() - (this.getPosition().getX() - this.posX) - 0.5, this.headPosition.getY() + (double)this.rand.nextFloat() - (this.getPosition().getY() - this.posY), this.headPosition.getZ() + (double)this.rand.nextFloat() - (this.getPosition().getZ() - this.posZ) - 0.5, (this.rand.nextInt(6) - 3) / 5, 0.1, (this.rand.nextInt(6) - 3) / 5, new int[] {Item.getIdFromItem(stack.getItem()), stack.getMetadata()});
	}
}
}

IGN: matte006

Played Minecraft since summer 2011.

Modding is my life now.

Please check out my mod :)

https://minecraft.curseforge.com/projects/gadgets-n-goodies-mod?gameCategorySlug=mc-mods&projectID=230028

Posted

If you want code running on the server to trigger something on the client (or vice versa), you need to send a packet.

 

In this case, vanilla already has a method to do this for you:

WorldServer#spawnParticle

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.