Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Help Consuming Items When the Durability of the Held Item Reaches 0. Minecraft 1.12.2


Recommended Posts

Hello, i need some help/suggestions on implementing a method. I have created a class that allows the player to summon ender pearls via a staff. I want to make it so when the items durability reaches 0, instead of the item breaking, the class searches the players inventory for ender pearls if it finds some it then removes a certain amount and it replenishes the objects durability. Any suggestions?  Below is the staff class.


package com.aww_man.Teleportation.items;

import com.aww_man.Teleportation.Main;
import com.aww_man.Teleportation.init.ModItems;
import com.aww_man.Teleportation.util.IHasModel;
import com.mojang.realmsclient.dto.PlayerInfo;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.item.EntityEnderPearl;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.client.event.sound.PlaySoundEvent;

public class VoidStaff extends Item implements IHasModel{
    public VoidStaff(String name) {
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        ItemStack enderpearls = playerIn.getHeldItemOffhand();
        ItemStack item = playerIn.getHeldItem(handIn);
            Vec3d Look = playerIn.getLookVec();
            item.damageItem(5, playerIn);
            EntityEnderPearl enderpearl = new  EntityEnderPearl(worldIn, playerIn);
            enderpearl.setPosition(playerIn.posX+Look.x*30d, playerIn.posY+Look.y*30d, playerIn.posZ+Look.z*30d);
            playerIn.getCooldownTracker().setCooldown(this, 60);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS,item);
    public void registerModels() {

Link to comment
Share on other sites

For the damage, you can check/set the ItemStack's damage with ItemStack#getDamage() and ItemStack#setDamage().

For the inventory searching, you can get the player's inventory through the EntityPlayer object, use that to check for the ender pearls, and get an ItemStack of them to interact with and change.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

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.

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.


  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.