Jump to content

[1.12.2] Trying to check certain item in either hand of player


NovaViper

Recommended Posts

Hi, I'm trying to figure out how I can check for a player holding a certain item either in the main hand or in the offhand; and if that player has that item, the method will return a number to execute a certain task for the entity im making this for. So far I have only checked for the active hand, but not the offhand.

 

My original code is this:

    public int masterOrder() {
    	int order = 0;
    	
        EntityPlayer player = (EntityPlayer)this.getOwner();
    	
        if(player != null) {
            float distanceAway = player.getDistance(this);
            ItemStack itemstack = player.inventory.getCurrentItem();
            
            
            if(itemstack != null && (itemstack.getItem() instanceof ItemTool) && distanceAway <= 20F)
                order = 1;

            if(itemstack != null && ((itemstack.getItem() instanceof ItemSword) || (itemstack.getItem() instanceof ItemBow)))
                order = 2;

            if(itemstack != null && itemstack.getItem() == Items.WHEAT) //Round up Talent
                order = 3;
            
            if(itemstack != null && itemstack.getItem() == Items.BONE) //Roar Talent
            	order = 4;
        }

        return order;
    }

 

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

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.