Пример #1
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (!$target instanceof Fence) {
         return false;
     }
     foreach ($level->getChunkEntities($target->x >> 4, $target->z >> 4) as $entity) {
         if ($entity->isLeashed()) {
             if ($entity->leadHolder === $player->getId()) {
                 $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
                 $level->addEntity($knot = new LeashKnot($level->getChunkAt($target->x >> 4, $target->z >> 4), $nbt));
                 $entity->setLeashHolder($knot);
             }
         }
     }
 }
Пример #2
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunkAt($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX()), new Double("", $block->getY()), new Double("", $block->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     switch ($this->meta) {
         case Villager::NETWORK_ID:
             $nbt->Health = new Short("Health", 20);
             $entity = new Villager($chunk, $nbt);
             break;
         case Zombie::NETWORK_ID:
             $nbt->Health = new Short("Health", 20);
             $entity = new Zombie($chunk, $nbt);
             break;
             /*
             			//TODO: use entity constants
             			case 10:
             			case 11:
             			case 12:
             			case 13:
             				$data = array(
             					"x" => $block->x + 0.5,
             					"y" => $block->y,
             					"z" => $block->z + 0.5,
             				);
             				//$e = Server::getInstance()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
             				//Server::getInstance()->api->entity->spawnToAll($e);
             				if(($player->gamemode & 0x01) === 0){
             					--$this->count;
             				}
             
             				return true;*/
     }
     if ($entity instanceof Entity) {
         if (($player->gamemode & 0x1) === 0) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }