Exemplo n.º 1
1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "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)])]);
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->getId() == Block::MONSTER_SPAWNER) {
         return true;
     } else {
         $entity = null;
         $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
         if (!$chunk instanceof FullChunk) {
             return false;
         }
         $nbt = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
         if ($this->hasCustomName()) {
             $nbt->CustomName = new StringTag("CustomName", $this->getCustomName());
         }
         $entity = Entity::createEntity($this->meta, $chunk, $nbt);
         if ($entity instanceof Entity) {
             if ($player->isSurvival()) {
                 --$this->count;
             }
             $entity->spawnToAll();
             return true;
         }
     }
     return false;
 }
Exemplo n.º 3
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);
             }
         }
     }
 }
Exemplo n.º 4
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 0.8), new DoubleTag("", $block->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return true;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $blockTemp = $level->getBlock($block->add(0, -1, 0));
     //if($blockTemp->getId() != self::RAIL and $blockTemp->getId() != self::POWERED_RAIL) return;
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX()), new Double("", $block->getY() + 1), new Double("", $block->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Exemplo n.º 7
0
 public function getDispenserId(Block $block)
 {
     return $block->getX() . ":" . $block->getY() . ":" . $block->getZ() . ":" . $block->getLevel()->getFolderName();
 }
 public function updateBlock2(Block $block, Level $level, $blockType)
 {
     $players = $level->getPlayers();
     foreach ($players as $p) {
         $pk = new UpdateBlockPacket();
         $pk->x = $block->getX();
         $pk->y = $block->getY();
         $pk->z = $block->getZ();
         $pk->block = $blockType;
         $pk->meta = 0;
         $p->dataPacket($pk);
         $level->setBlockIdAt($block->getX(), $block->getY(), $block->getZ(), $blockType);
         $pos = new Position($block->x, $block->y, $block->z);
         $block = $level->getBlock($pos, true);
         $direct = true;
         $update = true;
         $level->setBlock($pos, $block, $direct, $update);
     }
 }
Exemplo n.º 9
0
 /**
  * @param Block $stump
  * @return int
  */
 public function getTreetop(Block $stump)
 {
     $level = $stump->getLevel();
     $floor = $level->getBlock($stump->getSide(0));
     if (!in_array($floor->getId(), self::FLOORS)) {
         return -1;
     }
     $found = null;
     $maxHeight = $this->getConfig()->get("maxWorldHeight") - $stump->getY();
     for ($height = 0; $height < $maxHeight; $height++) {
         $block = $level->getBlock($stump->add(0, $height, 0));
         if (in_array($block->getId(), self::WOODS)) {
             if ($found === null) {
                 $found = [$block->getId(), $block->getDamage()];
             } elseif ($found[0] !== $block->getId() or $found[1] !== $block->getDamage()) {
                 return -1;
             }
         } elseif ($found !== null and in_array($block->getId(), self::LEAVES)) {
             return $height;
         } else {
             return -1;
         }
     }
     return -1;
 }
 private static function rotateBlockByOne(Block $block)
 {
     return Block::get($block->getID(), $block->getDamage(), new Position($block->getZ(), $block->getY(), -$block->getX(), $block->getLevel()));
 }
Exemplo n.º 11
0
 public function getTeamByBed($arena, Block $block)
 {
     foreach ($this->getTeams($arena) as $team) {
         $config = new Config($this->getDataFolder() . "Arenas/" . $arena . ".yml", Config::YAML);
         $x = $config->getNested("Bed." . $team . ".X");
         $y = $config->getNested("Bed." . $team . ".Y");
         $z = $config->getNested("Bed." . $team . ".Z");
         $x2 = $config->getNested("Bed." . $team . ".X2");
         $y2 = $config->getNested("Bed." . $team . ".Y2");
         $z2 = $config->getNested("Bed." . $team . ".Z2");
         $x3 = $block->getX();
         $y3 = $block->getY();
         $z3 = $block->getZ();
         if ($x == $x3 && $y == $y3 && $z == $z3) {
             return $team;
         }
         if ($x2 == $x3 && $y2 == $y3 && $z2 == $z3) {
             return $team;
         }
     }
     return "WHITE";
 }
Exemplo n.º 12
0
 /**
  * Adds a resettable chest
  * @param Block $chest
  */
 public function addChest(Block $chest)
 {
     $chests = $this->config->chests;
     $chests[count($this->chests)] = ['id' => $chest->getId(), 'x' => $chest->getX(), 'y' => $chest->getY(), 'z' => $chest->getZ(), 'level' => $chest->getLevel()->getId()];
     $this->config->set("chests", $chests);
     $this->config->save();
     array_push($this->chests, $chest);
 }
Exemplo n.º 13
0
 private function destroyTrunk(Block $bl)
 {
     $damage = 0;
     if ($bl->getId() != Block::WOOD) {
         return $damage;
     }
     $down = $bl->getSide(Vector3::SIDE_DOWN);
     if ($down->getId() == Block::WOOD) {
         return $damage;
     }
     $l = $bl->getLevel();
     for ($y = $bl->getY() + 1; $y < 128; ++$y) {
         $x = $bl->getX();
         $z = $bl->getZ();
         $bl = $l->getBlock(new Vector3($x, $y, $z));
         if ($bl->getId() != Block::WOOD) {
             break;
         }
         ++$damage;
         $l->dropItem($bl, new ItemBlock($bl));
         $l->setBlockIdAt($x, $y, $z, 0);
         $l->setBlockDataAt($x, $y, $z, 0);
     }
     return $damage;
 }
Exemplo n.º 14
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (($player->gamemode & 0x1) === 0 and $this->useOn($block) and $this->getDamage() >= $this->getMaxDurability()) {
         $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));
     }
     if ($target->getId() === 49 and $player->getServer()->netherEnabled) {
         //黑曜石 4*5最小 23*23最大
         $level->setBlock($block, new Fire(), true);
         $tx = $target->getX();
         $ty = $target->getY();
         $tz = $target->getZ();
         //x方向
         $x_max = $tx;
         //x最大值
         $x_min = $tx;
         //x最小值
         $count_x = 0;
         //x方向方块
         for ($x = $tx + 1; $level->getBlock(new Vector3($x, $ty, $tz))->getId() == 49; $x++) {
             $x_max++;
         }
         for ($x = $tx - 1; $level->getBlock(new Vector3($x, $ty, $tz))->getId() == 49; $x--) {
             $x_min--;
         }
         $count_x = $x_max - $x_min + 1;
         if ($count_x >= 4 and $count_x <= 23) {
             //4 23
             $x_max_y = $ty;
             //x最大值时的y最大值
             $x_min_y = $ty;
             //x最小值时的y最大值
             for ($y = $ty; $level->getBlock(new Vector3($x_max, $y, $tz))->getId() == 49; $y++) {
                 $x_max_y++;
             }
             for ($y = $ty; $level->getBlock(new Vector3($x_min, $y, $tz))->getId() == 49; $y++) {
                 $x_min_y++;
             }
             $y_max = min($x_max_y, $x_min_y) - 1;
             //y最大值
             $count_y = $y_max - $ty + 2;
             //方向方块
             //Server::getInstance()->broadcastMessage("$y_max $x_max_y $x_min_y $x_max $x_min");
             if ($count_y >= 5 and $count_y <= 23) {
                 //5 23
                 $count_up = 0;
                 //上面
                 for ($ux = $x_min; $level->getBlock(new Vector3($ux, $y_max, $tz))->getId() == 49 and $ux <= $x_max; $ux++) {
                     $count_up++;
                 }
                 //Server::getInstance()->broadcastMessage("$count_up $count_x");
                 if ($count_up == $count_x) {
                     for ($px = $x_min + 1; $px < $x_max; $px++) {
                         for ($py = $ty + 1; $py < $y_max; $py++) {
                             $level->setBlock(new Vector3($px, $py, $tz), new Block(90, 0));
                         }
                     }
                 }
             }
         }
         //z方向
         $z_max = $tz;
         //z最大值
         $z_min = $tz;
         //z最小值
         $count_z = 0;
         //z方向方块
         for ($z = $tz + 1; $level->getBlock(new Vector3($tx, $ty, $z))->getId() == 49; $z++) {
             $z_max++;
         }
         for ($z = $tz - 1; $level->getBlock(new Vector3($tx, $ty, $z))->getId() == 49; $z--) {
             $z_min--;
         }
         $count_z = $z_max - $z_min + 1;
         if ($count_z >= 4 and $count_z <= 23) {
             //4 23
             $z_max_y = $ty;
             //z最大值时的y最大值
             $z_min_y = $ty;
             //z最小值时的y最大值
             for ($y = $ty; $level->getBlock(new Vector3($tx, $y, $z_max))->getId() == 49; $y++) {
                 $z_max_y++;
             }
             for ($y = $ty; $level->getBlock(new Vector3($tx, $y, $z_min))->getId() == 49; $y++) {
                 $z_min_y++;
             }
             $y_max = min($z_max_y, $z_min_y) - 1;
             //y最大值
             $count_y = $y_max - $ty + 2;
             //方向方块
             if ($count_y >= 5 and $count_y <= 23) {
                 //5 23
                 $count_up = 0;
                 //上面
                 for ($uz = $z_min; $level->getBlock(new Vector3($tx, $y_max, $uz))->getId() == 49 and $uz <= $z_max; $uz++) {
                     $count_up++;
                 }
                 //Server::getInstance()->broadcastMessage("$count_up $count_z");
                 if ($count_up == $count_z) {
                     for ($pz = $z_min + 1; $pz < $z_max; $pz++) {
                         for ($py = $ty + 1; $py < $y_max; $py++) {
                             $level->setBlock(new Vector3($tx, $py, $pz), new Block(90, 0));
                         }
                     }
                 }
             }
         }
         return true;
     }
     if ($block->getId() === self::AIR and $target instanceof Solid) {
         $level->setBlock($block, new Fire(), true);
         return true;
     }
     return false;
 }
Exemplo n.º 15
0
 public function DestroyBlock(Block $Block, Player $Destroyer)
 {
     $X = $Block->GetX();
     $Y = $Block->GetY();
     $Z = $Block->GetZ();
     if ($Team = $this->getTeamByPlayer($Destroyer)) {
         if ($X == $Team->Bed[0]->getX() && $Y == $Team->Bed[0]->getY() && $Z == $Team->Bed[0]->getZ() || $X == $Team->Bed[1]->getX() && $Y == $Team->Bed[1]->getY() && $Z == $Team->Bed[1]->getZ()) {
             return true;
         }
     }
     foreach ($this->Teams as $name => $Team) {
         if ($X == $Team->Bed[0]->getX() && $Y == $Team->Bed[0]->getY() && $Z == $Team->Bed[0]->getZ() || $X == $Team->Bed[1]->getX() && $Y == $Team->Bed[1]->getY() && $Z == $Team->Bed[1]->getZ()) {
             $Team->BedStatus = 0;
             $this->sendMessageToAll(TextFormat::RED . $this->plugin->getMessage("bedwars.team.destroyed", $name));
             $this->updateTeams();
             $this->Level->setBlock(new Vector3($Team->Bed[0]->getX(), $Team->Bed[0]->getY(), $Team->Bed[0]->getZ()), Block::get(0), true, true);
             $this->Level->setBlock(new Vector3($Team->Bed[1]->getX(), $Team->Bed[1]->getY(), $Team->Bed[1]->getZ()), Block::get(0), true, true);
             return false;
         }
     }
     foreach ($this->BlocksPlaced as $Block) {
         if ($X == $Block->getX() && $Y == $Block->getY() && $Z == $Block->getZ()) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 16
0
 /**
  * @param Block $block
  * @param string $token
  * @return string
  */
 public function getAxisKey(Block $block, $token)
 {
     return $block->getX() . $token . $block->getY() . $token . $block->getZ();
 }
Exemplo n.º 17
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "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)])]);
     if ($this->hasCustomName()) {
         $nbt->CustomName = new String("CustomName", $this->getCustomName());
     }
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         $entity->setDataProperty(15, Entity::DATA_TYPE_BYTE, 1);
         $entity->getLevel()->getServer()->broadcastPopup(TextFormat::RED . "Mob AI isn't implemented yet!");
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
Exemplo n.º 18
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->getId() === Block::OBSIDIAN and $player->getServer()->netherEnabled) {
         //黑曜石 4*5最小 23*23最大
         //$level->setBlock($block, new Fire(), true);
         $tx = $target->getX();
         $ty = $target->getY();
         $tz = $target->getZ();
         //x方向
         $x_max = $tx;
         //x最大值
         $x_min = $tx;
         //x最小值
         for ($x = $tx + 1; $level->getBlock($this->temporalVector->setComponents($x, $ty, $tz))->getId() == Block::OBSIDIAN; $x++) {
             $x_max++;
         }
         for ($x = $tx - 1; $level->getBlock($this->temporalVector->setComponents($x, $ty, $tz))->getId() == Block::OBSIDIAN; $x--) {
             $x_min--;
         }
         $count_x = $x_max - $x_min + 1;
         //x方向方块
         if ($count_x >= 4 and $count_x <= 23) {
             //4 23
             $x_max_y = $ty;
             //x最大值时的y最大值
             $x_min_y = $ty;
             //x最小值时的y最大值
             for ($y = $ty; $level->getBlock($this->temporalVector->setComponents($x_max, $y, $tz))->getId() == Block::OBSIDIAN; $y++) {
                 $x_max_y++;
             }
             for ($y = $ty; $level->getBlock($this->temporalVector->setComponents($x_min, $y, $tz))->getId() == Block::OBSIDIAN; $y++) {
                 $x_min_y++;
             }
             $y_max = min($x_max_y, $x_min_y) - 1;
             //y最大值
             $count_y = $y_max - $ty + 2;
             //方向方块
             //Server::getInstance()->broadcastMessage("$y_max $x_max_y $x_min_y $x_max $x_min");
             if ($count_y >= 5 and $count_y <= 23) {
                 //5 23
                 $count_up = 0;
                 //上面
                 for ($ux = $x_min; $level->getBlock($this->temporalVector->setComponents($ux, $y_max, $tz))->getId() == Block::OBSIDIAN and $ux <= $x_max; $ux++) {
                     $count_up++;
                 }
                 //Server::getInstance()->broadcastMessage("$count_up $count_x");
                 if ($count_up == $count_x) {
                     for ($px = $x_min + 1; $px < $x_max; $px++) {
                         for ($py = $ty + 1; $py < $y_max; $py++) {
                             $level->setBlock($this->temporalVector->setComponents($px, $py, $tz), new Portal());
                         }
                     }
                     if ($player->isSurvival()) {
                         $this->useOn($block, 2);
                         $player->getInventory()->setItemInHand($this);
                     }
                     return true;
                 }
             }
         }
         //z方向
         $z_max = $tz;
         //z最大值
         $z_min = $tz;
         //z最小值
         $count_z = 0;
         //z方向方块
         for ($z = $tz + 1; $level->getBlock($this->temporalVector->setComponents($tx, $ty, $z))->getId() == Block::OBSIDIAN; $z++) {
             $z_max++;
         }
         for ($z = $tz - 1; $level->getBlock($this->temporalVector->setComponents($tx, $ty, $z))->getId() == Block::OBSIDIAN; $z--) {
             $z_min--;
         }
         $count_z = $z_max - $z_min + 1;
         if ($count_z >= 4 and $count_z <= 23) {
             //4 23
             $z_max_y = $ty;
             //z最大值时的y最大值
             $z_min_y = $ty;
             //z最小值时的y最大值
             for ($y = $ty; $level->getBlock($this->temporalVector->setComponents($tx, $y, $z_max))->getId() == Block::OBSIDIAN; $y++) {
                 $z_max_y++;
             }
             for ($y = $ty; $level->getBlock($this->temporalVector->setComponents($tx, $y, $z_min))->getId() == Block::OBSIDIAN; $y++) {
                 $z_min_y++;
             }
             $y_max = min($z_max_y, $z_min_y) - 1;
             //y最大值
             $count_y = $y_max - $ty + 2;
             //方向方块
             if ($count_y >= 5 and $count_y <= 23) {
                 //5 23
                 $count_up = 0;
                 //上面
                 for ($uz = $z_min; $level->getBlock($this->temporalVector->setComponents($tx, $y_max, $uz))->getId() == Block::OBSIDIAN and $uz <= $z_max; $uz++) {
                     $count_up++;
                 }
                 //Server::getInstance()->broadcastMessage("$count_up $count_z");
                 if ($count_up == $count_z) {
                     for ($pz = $z_min + 1; $pz < $z_max; $pz++) {
                         for ($py = $ty + 1; $py < $y_max; $py++) {
                             $level->setBlock($this->temporalVector->setComponents($tx, $py, $pz), new Portal());
                         }
                     }
                     if ($player->isSurvival()) {
                         $this->useOn($block, 2);
                         $player->getInventory()->setItemInHand($this);
                     }
                     return true;
                 }
             }
         }
         //return true;
     }
     if ($block->getId() === self::AIR and $target instanceof Solid) {
         $level->setBlock($block, new Fire(), true);
         /** @var Fire $block */
         $block = $level->getBlock($block);
         if ($block->getSide(Vector3::SIDE_DOWN)->isTopFacingSurfaceSolid() or $block->canNeighborBurn()) {
             $level->scheduleUpdate($block, $block->getTickRate() + mt_rand(0, 10));
             //	return true;
         }
         if ($player->isSurvival()) {
             $this->useOn($block, 2);
             //耐久跟报废分别写在 tool 跟 level 了
             $player->getInventory()->setItemInHand($this);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 19
-2
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $blockTemp = $level->getBlock($block->add(0, -1, 0));
     //if(!$block instanceof RailBlock || !$block instanceof Rail) return false; in previuos version IM
     //if($blockTemp->getId() != self::RAIL and $blockTemp->getId() != self::POWERED_RAIL) return; in previuos version Genisys
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new CompoundTag("", array("Pos" => new ListTag("Pos", array(new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 1), new DoubleTag("", $block->getZ()))), "Motion" => new ListTag("Motion", array(new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0))), "Rotation" => new ListTag("Rotation", array(new FloatTag("", 0), new FloatTag("", 0))))));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }