Hey fellow devs! I wanted to know how I would go about letting the looting enchant work on the drops that I define. What i tried: Code (Text): public class EntityDeathEvents implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onEDeath(EntityDeathEvent e) { if (e.getEntityType() == EntityType.CREEPER && (Math.random() <= 0.15)) { e.getDrops().add(new ItemStack(Material.TNT)); } if (e.getEntityType() == EntityType.IRON_GOLEM) { Iterator<ItemStack> iterator = e.getDrops().iterator(); while (iterator.hasNext()) { ItemStack stack = iterator.next(); switch (stack.getType()) { case RED_ROSE: iterator.remove(); break; default: break; } } } if (e.getEntityType() == EntityType.MUSHROOM_COW) { e.getDrops().clear(); e.getDrops().add(new ItemStack(Material.GOLD_INGOT)); } if (e.getEntityType() == EntityType.MAGMA_CUBE) { e.getDrops().clear(); e.setDroppedExp(20); if (Math.random() <= 0.90) e.getDrops().add(new ItemStack(Material.DIAMOND)); } if (e.getEntityType() == EntityType.VILLAGER) { e.getDrops().clear(); e.getDrops().add(new ItemStack(Material.EMERALD)); } } }
Check if the item in hand of the killer containsEnchantment(Enchantment) in this case you would put looting in that parameter. If you want to check for the level, add that, then make an integer using the item.getEnchantmentLevel(Enchantment) method, to get the level of looting, then drop items based on that by adding items to the drops list of itemstacks.
It takes only like 3 lines of code to make the whole check, including the level variable. I don't think it could get much better than that