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.

MarbleGateKeeper

Members
  • Joined

  • Last visited

  1. Hello everyone. Greeting. My situation is: I need to stop an ItemStack (such as armors, tools) from break under certain condition (such as having certain Enchantment/tag value). I've tried LivingEntityUseItemEvent and PlayerDestroyItemEvent. LivingEntityUseItemEvent didn't get fired when my 1-durability sword broke. PlayerDestroyItemEvent only got fired at the first try for unknown-reason, and here is my code for it: @SubscribeEvent public static void doToolsFindTheWayEnchantmentEvent(PlayerDestroyItemEvent event){ if(!event.getEntityLiving().world.isRemote()){ if(ItemUtil.isItemEnchanted(event.getOriginal(),EnchantmentRegistry.tools_find_the_way_enchantment.get())) { int expTotal = ((PlayerEntity) event.getEntityLiving()).experienceTotal; if (expTotal > 1) { int expNeeded = event.getOriginal().getMaxDamage() * 2; ItemStack itemStack = event.getOriginal().copy(); if (expNeeded <= expTotal) { itemStack.setDamage(0); ((PlayerEntity) event.getEntityLiving()).giveExperiencePoints(-expNeeded); } else { itemStack.setDamage(itemStack.getMaxDamage() - (expTotal / 2)); if (expTotal % 2 == 1) ((PlayerEntity) event.getEntityLiving()).giveExperiencePoints(-expTotal + 1); else ((PlayerEntity) event.getEntityLiving()).giveExperiencePoints(-expTotal); } event.getPlayer().world.addEntity(new ItemEntity(event.getPlayer().world, event.getPlayer().getPosX(), event.getPlayer().getPosY(), event.getPlayer().getPosZ(), itemStack.copy())); } } } } PlayerDestroyItemEvent only got fired at the first time I run the code and then no matter how I try (when I did not change the code) it never reach line 3. Seem like PlayerDestroyItemEvent did not got called. Ok, back to the question: I got a idea that I can use PlayerTickEvent to scan the whole PlayerEntity's Inventory and check every ItemStack. But this solution seems so efficiency-expensive, Is there any solution or idea I can you? Thank you so much! My English might not be so accurate but thank you.

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.