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

MarbleGateKeeper

Members
  • Posts

    1
  • Joined

  • Last visited

Converted

  • Gender
    Male

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

MarbleGateKeeper's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  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.
×
×
  • Create New...

Important Information

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