Posted December 12, 201213 yr Hi, this is my first post and I've just started out with modding with Forge. I'd like to know if there is any way to register when a player has right-clicked on another player on a SMP server? I've come across the "onBlockActivated()" method but I couldn't find anything similar when browsing Entity classes. If possible, I'd like to send out some packets once a player shift+right clicks an other player. Is it possible and if so, how? Thanks!
December 16, 201213 yr I don't know if this works with other players, but in many of the animal class files, there is a boolean that causes something to happen when you right-click on a mob. Right click on wolf makes it sit, dyes it, feeds it, etc. public boolean interact(EntityPlayer par1EntityPlayer) { ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem(); if (this.isTamed()) { if (var2 != null) { if (Item.itemsList[var2.itemID] instanceof ItemFood) { ItemFood var3 = (ItemFood)Item.itemsList[var2.itemID]; if (var3.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectInt(18) < 20) { if (!par1EntityPlayer.capabilities.isCreativeMode) { --var2.stackSize; } this.heal(var3.getHealAmount()); if (var2.stackSize <= 0) { par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null); } return true; } } else if (var2.itemID == Item.dyePowder.shiftedIndex) { int var4 = BlockCloth.getBlockFromDye(var2.getItemDamage()); if (var4 != this.getCollarColor()) { this.setCollarColor(var4); if (!par1EntityPlayer.capabilities.isCreativeMode && --var2.stackSize <= 0) { par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null); } return true; } } } if (par1EntityPlayer.username.equalsIgnoreCase(this.getOwnerName()) && !this.worldObj.isRemote && !this.isBreedingItem(var2)) { this.aiSit.setSitting(!this.isSitting()); this.isJumping = false; this.setPathToEntity((PathEntity)null); } } else if (var2 != null && var2.itemID == Item.bone.shiftedIndex && !this.isAngry()) { if (!par1EntityPlayer.capabilities.isCreativeMode) { --var2.stackSize; } if (var2.stackSize <= 0) { par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null); } if (!this.worldObj.isRemote) { if (this.rand.nextInt(3) == 0) { this.setTamed(true); this.setPathToEntity((PathEntity)null); this.setAttackTarget((EntityLiving)null); this.aiSit.setSitting(true); this.setEntityHealth(20); this.setOwner(par1EntityPlayer.username); this.playTameEffect(true); this.worldObj.setEntityState(this, (byte)7); } else { this.playTameEffect(false); this.worldObj.setEntityState(this, (byte)6); } } return true; } return super.interact(par1EntityPlayer); } http://i.imgur.com/ivK3J.png[/img] I'm a little surprised that I am still ranked as a "Forge Modder," having not posted a single mod since my animals mod... I have to complete Digging Deeper!, fast!
December 18, 201213 yr public boolean interact(EntityPlayer par1EntityPlayer){ // add your code here } you would have to put this in the EntityPlayer.class. The argument par1EntityPlayer is the player that has right clicked the other player http://www.mcportcentral.co.za/add_images/mcportcentral-banner.jpg[/img]
December 19, 201213 yr Or, alternatively, you could use PlayerInteractEvent. Protip: try and find answers yourself before asking on the forum. It's pretty likely that there is an answer. Was I helpful? Give me a thank you! http://bit.ly/HZ03zy[/img] Tired of waiting for mods to port to bukkit? use BukkitForge! (now with a working version of WorldEdit!)
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.