How to make lava and cactus not destroy items

Discussion in 'Spigot Plugin Development' started by UnlimitedNinjas, Aug 4, 2018.

  1. Title says it all.
    I want to make it so Lava and Cactus wont break/destroy items.
  2. Try
    • EntityCombustByBlockEvent
    • EntityDamageByBlockEvent
    And see if they are called when you throw an item into lava or fire, for example by printing to console. This will get spammy. Then, see if cancelling the event keeps the item alive.
  3. Tried this with both, didnt work
    public void onEntityDamage(EntityCombustByBlockEvent event) {
  4. Did you register your events lol
    • Agree Agree x 1
  5. Did you register the events in your onEnable? Here's an API reference.

    Edit: Sam ninja'd me. mbad
  6. I just did and it seems to work now to just figure out if i can cancel the event
  7. Any events which extends Cancellable can be cancelled ideally. Both of the events mentioned above do so. Just use setCancelled(true) on the event.
  8. Nope didnt work. Idk what else to use
  9. So i did this:
    Code (Text):
        public void onEntityDamage(EntityDamageByBlockEvent event) {
            if (event.getEntity() instanceof Item) {
    and it sometimes it work sometimes doesnt..
  10. Are you doing something similar with both of the events mentioned at the top? I'd think that the item can be damaged directly by the lava, which that event would cover, but also separately by the fire after it combusts, which wouldn't trigger the DamageByBlock event.

    I'm guessing a bit, but you may need to negate damage done in the combust event, and if it doesn't always cancel the combust event, you may need to find an additional event that can be used to cancel the damage done when an entity is on fire (as I imagine the combust event only covers it's initial catching-on-fire event)