Advertisement
Tslat

Example Application for ItemDamageEvent

Jun 15th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import net.minecraft.item.ItemArmor;
  2. import net.minecraftforge.fml.common.Mod;
  3.  
  4. @Mod(modid = "safearmourdrops", version = "1.0")
  5. public class SafeArmourDrops {
  6.     /**
  7.      * Listens to ItemDamageEvent for ItemArmor items.
  8.      * If the item is an ItemArmor item, and the DamageSource is either an explosion or fire, cancel the event.
  9.      * This protects all ItemArmor drops from being destroyed by lava, fire, or explosions.
  10.      */
  11.     @Mod.EventHandler
  12.     public final void onItemDropped(EntityItemDamageEvent event) {
  13.         if (!event.getEntityItem().getItem().isEmpty() && event.getEntityItem().getItem().getItem() instanceof ItemArmor) {
  14.             if (event.getSource().isExplosion() || event.getSource().isFireDamage()) {
  15.                 event.setCanceled(true);
  16.             }
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement