Mobs Burning In Daylight

Discussion in 'Resources' started by KylezPro, Feb 23, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    KylezPro

    Okay, so I was searching a while for a solution to this problem, how do I get mobs to not burn in daylight?

    So I found bits of information that didn't really help, but I figured it out, but i'll make a quick little guide to anyone who wants to do this simply.

    So, to start off, we want to get the method. The method is EntityCombustEvent.

    Code:
    @EventHandler
    public void onEntityBurn(EntityCombustEvent event){
    
    }
    Next, we want to make sure the cause of the burn was the sun, so we rule out CombustByBlock and CombustByEntity

    Code:
    @EventHandler
    public void onEntityBurn(EntityCombustEvent event){
        if(!(event instanceof EntityCombustByBlockEvent || event instanceof EntityCombustByEntityEvent)){
    
        }
    }
    Now we know that the sun caused the burn, we can simply cancel the event.

    Code:
    @EventHandler
    public void onEntityBurn(EntityCombustEvent event){
        if(!(event instanceof EntityCombustByBlockEvent || event instanceof EntityCombustByEntityEvent)){
            event.setCancelled(true);
        }
    }
    Okay, that's good! But wait, what if we only want this to be active in a certain world? Well, then we do this.

    Code:
    @EventHandler
    public void onEntityBurn(EntityCombustEvent event){
        if(event.getEntity().getWorld().getName().equalsIgnoreCase("MyWorld")){
            if(!(event instanceof EntityCombustByBlockEvent || event instanceof EntityCombustByEntityEvent)){
                event.setCancelled(true);
            }
        }
    }
    So now this code will only be active in "MyWorld". But what if we shoot a bow and it is on fire? It's still an entity that is combusted, well we just filter out projectiles, like this.

    Code:
    @EventHandler
    public void onEntityBurn(EntityCombustEvent event){
        if(!(event.getEntity() instanceof Projectile)){
            if(event.getEntity().getWorld().getName().equalsIgnoreCase("MyWorld")){
                if(!(event instanceof EntityCombustByBlockEvent || event instanceof EntityCombustByEntityEvent)){
                    event.setCancelled(true);
                }
            }
        }
    }
    And we should be done!

    Thanks, if there is anything I missed please tell me.
     
    ChipDev and BorisTheTerrible like this.
  2. Offline

    ChipDev

    A theorie:
    If you are calling EntityCombustEvent, I don't think EntityCombustByBlockEvent COULD call..
     
  3. Offline

    Regablith

    Is it possible that "EntityCombustEvent" could be called by walking into fire, flame bows, fire swords, AND daylight?
     
    gal0511Dev likes this.
  4. Offline

    KylezPro

    Surely it could be called, isn't it just defining how the entity was combusted?
     
  5. Offline

    ChipDev

    PlayerMoveEvent doesn't call when the join event happens..
    So I don't think it could call, but nice tutorial otherwise.
     
  6. Offline

    teej107

    That's not what he meant. When did he say anything about a join event? He was asking if the EntityCombustEvent would happen if an entity came into contact (or simply walked into) something that will cause it to burn.

    @Regablith Walking into fire I would imagine would call the EntityCombustByBlockEvent since fire is a block. I think the EntityCombustByEntityEvent would still call for fire swords and bows since they do nothing on their own and would need an entity for it to happen but I'm not certain since I have not tried it.
     
    Regablith likes this.
  7. Offline

    ChipDev

    Im making an example...
    Case closed.
     
Thread Status:
Not open for further replies.

Share This Page