Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.