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

Sword shooting Eggs or Snowballs

Comments in 'Plugin Development' started by SM11, Aug 6, 2015.

  1. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Hey guys, I need a little help with Swords shooting Snowballs or eggs I have some code and Here it is, Please help though

    <?php

    namespace sm11\IronCannon;
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\Plugin;
    use pocketmine\Player;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\event\entity\EntityDamageByEntityEvent;

    class Main extends PluginBase implements Listener{

    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getLogger()->info("IronCannon enabled!");
    }

    public function onDisable(){
    $this->getLogger()->info("IronCannon disabled!");
    }

    public function onDamage(EntityDamageEvent $event){
    if($event instanceof EntityDamageByEntityEvent){
    $a = $event->getDamager();
    $item = $a->getInventory()->getItemInHand();
    if($a instanceof Player){
    if($item == 276){
    $event->setCancelled(true);
    //Code to shoot snowball
    }
    }
    }
    }
    }
  2. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    On Damage?
    Better would be onInteract:
    PHP:
    public function onScreenHold(PlayerInteractEvent $event){
    $player $event->getPlayer();
    $item $this->getPlayer()->getInventory()->getItemInHand();
    (
    $event->getBlock()->getId() === ?: return);
    if(
    $item->getId() == Item::IRON_SWORD){
    // Code to shoot snowball
    // Sorry dont have time for it now :)
    }
    }
    asyven likes this.
  4. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    oh Thanks

Share This Page

Advertisement