getToolType() публичный Метод

public getToolType ( ) : integer
Результат integer
Пример #1
0
 /**
  * TODO: Move this to each item
  *
  * @param Entity|Block $object
  *
  * @return bool
  */
 public function useOn($object)
 {
     if ($this->isUnbreakable()) {
         return false;
     }
     $break = true;
     if (($ench = $this->getEnchantment(Enchantment::TYPE_MINING_DURABILITY)) != null) {
         $rnd = mt_rand(1, 100);
         if ($rnd <= 100 / ($ench->getLevel() + 1)) {
             $break = false;
         }
     }
     if ($object instanceof Block) {
         if (!$break) {
             return false;
         }
         if ($object->getToolType() === Tool::TYPE_PICKAXE and $this->isPickaxe() or $object->getToolType() === Tool::TYPE_SHOVEL and $this->isShovel() or $object->getToolType() === Tool::TYPE_AXE and $this->isAxe() or $object->getToolType() === Tool::TYPE_SWORD and $this->isSword() or $object->getToolType() === Tool::TYPE_SHEARS and $this->isShears()) {
             $this->meta++;
         } elseif (!$this->isShears() and $object->getBreakTime($this) > 0) {
             $this->meta += 2;
         }
     } elseif ($this->isHoe()) {
         if (!$break) {
             return false;
         }
         if ($object instanceof Block and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)) {
             $this->meta++;
         }
     } elseif ($object instanceof Entity) {
         $return = true;
         if (!$this->isSword()) {
             if ($break) {
                 $this->meta += 2;
                 $return = false;
             }
         } else {
             if ($break) {
                 $this->meta++;
                 $return = false;
             }
             if (!$this->hasEnchantments()) {
                 return $return;
             }
             //TODO: move attacking from player class here
             //$fire = $this->getEnchantment(Enchantment::TYPE_WEAPON_FIRE_ASPECT);
             //$object->setOnFire($fire->getLevel() * 4);
         }
     }
     return true;
 }
 /**
  * @param CommandSender $sender
  * @param Block $block
  */
 public function sendBlockInfo(CommandSender $sender, Block $block)
 {
     $sender->sendMessage("Name: " . $block->getName());
     $sender->sendMessage("XYZ: " . $block->getFloorX() . ":" . $block->getFloorY() . ":" . $block->getFloorZ());
     $sender->sendMessage("Level: " . $block->getLevel()->getName());
     $sender->sendMessage("Block-id: " . $block->getId() . ":" . $block->getDamage());
     $sender->sendMessage("Hardness: " . $block->getHardness());
     $sender->sendMessage("Resistance: " . $block->getResistance());
     $sender->sendMessage("Tool-type: " . $block->getToolType());
     $sender->sendMessage("Friction: " . $block->getFrictionFactor());
     $sender->sendMessage("Light-level: " . $block->getLightLevel());
     //$sender->sendMessage("Is-placeable: ".($block->canBePlaced() ? TextFormat::GREEN."yes" : TextFormat::RED."no"));
     $sender->sendMessage("Is-replaceable: " . ($block->canBeReplaced() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no"));
     $sender->sendMessage("Is-transparent: " . ($block->isTransparent() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no"));
     $sender->sendMessage("Is-solid: " . ($block->isSolid() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no"));
     //$sender->sendMessage("Is-flowable: ".($block->canBeFlowedInto() ? TextFormat::GREEN."yes" : TextFormat::RED."no"));
     //$sender->sendMessage("Is-activateable: ".($block->canBeActivated() ? TextFormat::GREEN."yes" : TextFormat::RED."no"));
     $sender->sendMessage("Is-passable: " . ($block->canPassThrough() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no"));
     $dropCount = 0;
     $dropNames = "";
     foreach ($block->getDrops() as $drop) {
         $dropNames .= $drop->getName() . ", ";
         $dropCount++;
     }
     $sender->sendMessage("Drops (" . $dropCount . "): " . substr($dropNames, 0, -2));
 }
Пример #3
0
 /**
  * TODO: Move this to each item
  *
  * @param Entity|Block $object
  *
  * @return bool
  */
 public function useOn($object)
 {
     if ($this->isUnbreakable()) {
         return true;
     }
     if ($object instanceof Block) {
         if ($object->getToolType() === Tool::TYPE_PICKAXE and $this->isPickaxe() or $object->getToolType() === Tool::TYPE_SHOVEL and $this->isShovel() or $object->getToolType() === Tool::TYPE_AXE and $this->isAxe() or $object->getToolType() === Tool::TYPE_SWORD and $this->isSword() or $object->getToolType() === Tool::TYPE_SHEARS and $this->isShears()) {
             $this->meta++;
         } elseif (!$this->isShears() and $object->getBreakTime($this) > 0) {
             $this->meta += 2;
         }
     } elseif ($this->isHoe()) {
         if ($object instanceof Block and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)) {
             $this->meta++;
         }
     } elseif ($object instanceof Entity and !$this->isSword()) {
         $this->meta += 2;
     } else {
         $this->meta++;
     }
     return true;
 }
 /**
  * TODO: Move this to each item
  *
  * @param Entity|Block $object
  * @param 1 for break|2 for Touch $type
  *
  * @return bool
  */
 public function useOn($object, $type = 1)
 {
     if ($this->isUnbreakable()) {
         return true;
     }
     $unbreakingl = $this->getEnchantmentLevel(Enchantment::TYPE_MINING_DURABILITY);
     $unbreakingl = $unbreakingl > 3 ? 3 : $unbreakingl;
     if (mt_rand(1, $unbreakingl + 1) !== 1) {
         return true;
     }
     if ($type === 1) {
         if ($object instanceof Entity) {
             if ($this->isHoe() !== false or $this->isSword() !== false) {
                 //Hoe and Sword
                 $this->meta++;
                 return true;
             } elseif ($this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false) {
                 //Pickaxe Axe and Shovel
                 $this->meta += 2;
                 return true;
             }
             return true;
             //Other tool do not lost durability white hitting
         } elseif ($object instanceof Block) {
             if ($this->isShears() !== false) {
                 if ($object->getToolType() === Tool::TYPE_SHEARS) {
                     //This should be checked in each block
                     $this->meta++;
                 }
                 return true;
             } elseif ($object->getHardness() > 0) {
                 //Sword Pickaxe Axe and Shovel
                 if ($this->isSword() !== false) {
                     $this->meta += 2;
                     return true;
                 } elseif ($this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false) {
                     $this->meta += 1;
                     return true;
                 }
             }
         }
     } elseif ($type === 2) {
         //For Touch. only trigger when OnActivate return true
         if ($this->isHoe() !== false or $this->id === self::FLINT_STEEL or $this->isShovel() !== false) {
             $this->meta++;
             return true;
         }
     }
     return true;
 }