Jump to content

Recommended Posts

Posted

In am trying to calculate the difference between the player using an item and the entity the item is used on, however the itemInteractionForEntity method i tried using does not include a variable for EntityPlayer. How can i get a variable for the player that is using the item? Thank you!

 

 

 

 

 

Posted

Hey!

maybe you can use onItemRightClick(itemStack, world, entityPlayer) instead.

 

And inside the method body, do like this:

[spoiler=CODE]

float f = 1.0F;
        double d0 = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double)f;
        double d1 = par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double)f + 1.62D - (double)par3EntityPlayer.yOffset;
        double d2 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double)f;
        MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);

        if (movingobjectposition == null)
        {
            return par1ItemStack;
        }
        else if (movingobjectposition.entityHit instanceof EntityLiving)
            {
                // DO STUFF HERE, Entity hit
            }

 

 

This is using the getMovingObjectPositionFromPlayer() method which all items inherit from the Item class.

I got this code by looking at how ItemBucket get's milk from EntityCow upon using the item :)

Hope it helps ^^

If you guys dont get it.. then well ya.. try harder...

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.