Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Snowball

Comments in 'Plugin Development' started by mclab, Jan 20, 2015.

  1. mclab
    Offline

    mclab Active Member

    Joined:
    Dec 24, 2014
    Posts:
    49
    Minecraft User:
    Dragonflex
    How to set snowball damage?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Listen to EntityDamageEvent, if event instanceof EntityDamageByChildEntityEvent and event child instanceof Snowball, setDamage().
    EvolSoft, iJoshuaHD and mclab like this.
  3. mclab
    Offline

    mclab Active Member

    Joined:
    Dec 24, 2014
    Posts:
    49
    Minecraft User:
    Dragonflex
    I am bad in english, can you give me example? Thanks :)
    Last edited: Jan 20, 2015
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    public function onDamage(EntityDamageEvent $e){
        if(
    $e instanceof EntityDamageByChildEntityEvent and $e->getDamager() instanceof Snowball){
            
    // imitate one of the following:
            
    $e->setDamage(0); // set damage to zero
            
    $e->setDamage($e->getDamage() + 1); // one extra halfheart damage
            
    $e->setDamage($e->getDamage() * (50 100)); // 50% extra damage
        
    }
    }
    EvolSoft and mclab like this.
  5. mclab
    Offline

    mclab Active Member

    Joined:
    Dec 24, 2014
    Posts:
    49
    Minecraft User:
    Dragonflex
    Dont work :/
  6. mclab
    Offline

    mclab Active Member

    Joined:
    Dec 24, 2014
    Posts:
    49
    Minecraft User:
    Dragonflex
    This is good version
    PHP:
    public function onDamage(EntityDamageEvent $event){
            
    $player $event->getEntity();
            if(
    $player instanceof Player && $event->getCause() === EntityDamageEvent::CAUSE_PROJECTILE){
                    
    $event->setDamage(10);
            }
            }
    Thanks! can be closed :)
    EvolSoft and xFlare like this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That applies for arrows too.
    Sorry, it should've been getChild() not getDamager().

Share This Page

Advertisement