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.

Featured Replies

Posted

Thank you all in advance for your help!
I create a simple class for the item, here, if the player makes a right click, he gets a random item, and at the end I want the item to decrease the strength and when the strength is 0, the item is destroyed. But when I right click, the strength goes into the negative numbers and the item doesn't break :

public class DiarubiumWand extends Item {

    public DiarubiumWand(Properties pProperties) {
        super(pProperties);
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {

        if(pLevel.isClientSide) {
            int random = (int) Math.floor(1 + Math.random() * 3);
            pPlayer.sendMessage(new TextComponent("Value: "+ random), pPlayer.getUUID());
            if(random == 1)
                pPlayer.addItem(Items.DIAMOND.getDefaultInstance());
            else if(random == 2)
                pPlayer.addItem(Blocks.DIRT.asItem().getDefaultInstance());
            else if(random == 3)
                pPlayer.addItem(ModItems.DIARUBIUM_RAW.get().getDefaultInstance());
            pPlayer.getItemInHand(InteractionHand.MAIN_HAND).hurt(1, new Random(), null);
        }
        return super.use(pLevel, pPlayer, pUsedHand);
    }
}


This is item registrator: 
 

public static final RegistryObject<Item> DIARUBIUM_WAND = ITEMS.register( 
  "diarubium_wand", 
  () -> new DiarubiumWand(
    new Item.Properties()
    .tab(Diarubium.TAB)
    .durability(10)));

 

Edited by Sniklz

You need a method that checks how much damage your item has taken, and when that damage equals the item's max durability, it gets removed from the item slot.

  • Author

Im found how to make it:

 

pPlayer.getItemInHand(pUsedHand)
                .hurtAndBreak(1,
                        pPlayer,
                        (player -> player.broadcastBreakEvent(player.getUsedItemHand())));


 

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.