Jump to content

Item.itemInteractionForEntity on both client and server


Fizzixnerd

Recommended Posts

I have the following class (Scala).

 

class ItemMyItem extends Item {
  setRegistryName("my_item")
  setUnlocalizedName("my_item")
  maxStackSize = 1
  setCreativeTab(CreativeTabs.TOOLS)

  def spawnParticles(world: World, pos: BlockPos): Unit = {
    for (_ <- 1 to 50000) {
      val randX = Random.nextDouble()
      val randZ = Random.nextDouble()
      val randPlusX = Random.nextBoolean()
      val randPlusY = Random.nextBoolean()
      val randPlusZ = Random.nextBoolean()
      val d0 = pos.getX + 20.0 * (if (randPlusX) randX else -randX)
      val d1 = pos.getY + (if (randPlusY) randX else -randX) * 6.0 / 16.0
      val d2 = pos.getZ + 20.0 * (if (randPlusZ) randZ else -randZ)
      world.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, 20.0 * (if (randPlusX) randX else -randX), 1.0, 20.0 * (if (randPlusZ) randZ else -randZ))
    }
  }

  override
  def itemInteractionForEntity(stack: ItemStack, playerIn: EntityPlayer, target: EntityLivingBase, hand: EnumHand): Boolean = {
    super.itemInteractionForEntity(stack, playerIn, target, hand)
    playerIn.playSound(MyMod.mySound, 1.0F, 1.0F)
    spawnParticles(playerIn.getEntityWorld, playerIn.getPosition)
    true
  }
}

 

The problem is that when I test in multiplayer, only the person using the item can see the particles and hear the sound.  They can see the arm swing animation on use.  I was wondering why that was, and how I could get other players to see/hear them.

 

Only on the client proxy do I register the sound.  I am using vanilla particles, so I don't ever register those.

 

I checked the docs and they seem to suggest it should be run on both sides automatically.  Any help would be appreciated.

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.