Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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) {
        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(Main.modtabs);
        ModItems.ITEMS.add(this);
        setMaxDamage(100);
        setMaxStackSize(1);
    }
    @Override
    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);
            worldIn.spawnEntity(enderpearl);
            playerIn.getCooldownTracker().setCooldown(this, 60);
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS,item);
        
    }
    @Override
    public void registerModels() {
        Main.proxy.registerItemRender(this,0,"inventory");
        
    }
    
}
 

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.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.