Jump to content

[1.7.10][Unsolved]How to damage a tool on right click


jamesc554544

Recommended Posts

I am trying to make it so my sword places redstone, and damages the sword on use.

 

Code:

 

public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_77648_3_, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_)

    {

        if (p_77648_3_.getBlock(p_77648_4_, p_77648_5_, p_77648_6_) != Blocks.snow_layer)

        {

            if (p_77648_7_ == 0)

            {

                --p_77648_5_;

            }

 

            if (p_77648_7_ == 1)

            {

                ++p_77648_5_;

            }

 

            if (p_77648_7_ == 2)

            {

                --p_77648_6_;

            }

 

            if (p_77648_7_ == 3)

            {

                ++p_77648_6_;

            }

 

            if (p_77648_7_ == 4)

            {

                --p_77648_4_;

            }

 

            if (p_77648_7_ == 5)

            {

                ++p_77648_4_;

            }

 

            if (!p_77648_3_.isAirBlock(p_77648_4_, p_77648_5_, p_77648_6_))

            {

                return false;

            }

        }

 

        if (!p_77648_2_.canPlayerEdit(p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_1_))

        {

            return false;

        }

        else

        {

            if (Blocks.redstone_wire.canPlaceBlockAt(p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_))

            {

            p_77648_1_.damageItem(-1, p_77648_2_);

                p_77648_3_.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, Blocks.redstone_wire);

               

            }

 

            return true;

        }

    }

 

Link to comment
Share on other sites

damage is a positive number that increases with each use until maxDamage is reached.

 

P.S.: you should really start renaming your variables to make them more readable for other people and for you in the future, you'll appreciate that later on, An easy way in eclipse is pointing on variable the pressing CTRL + 2 then R then rename to whatever

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.