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; }
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; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($target->isTransparent() === false and $face > 1 and $block->isSolid() === false) { $faces = [2 => 0, 3 => 2, 4 => 1, 5 => 3]; $motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]]; $motive = $motives[mt_rand(0, count($motives) - 1)]; $data = ["x" => $target->x, "y" => $target->y + 0.4, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]]; $nbt = new CompoundTag("", ["Motive" => new StringTag("Motive", $data["Motive"]), "Pos" => new EnumTag("Pos", [new DoubleTag("", $data["x"]), new DoubleTag("", $data["y"]), new DoubleTag("", $data["z"])]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", $data["yaw"]), new FloatTag("", 0)])]); $painting = new PaintingEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt); $painting->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); } //TODO //$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data); //$e->spawnToAll(); /*if(($player->gamemode & 0x01) === 0x00){ $player->removeItem(Item::get($this->getId(), $this->getDamage(), 1)); }*/ return true; } return false; }
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; }
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; }
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; }
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); } } } }
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); } }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($target->isTransparent() === false and $face !== 0 and $face !== 1 and $block->isSolid() === false) { $faces = [2 => 1, 3 => 3, 4 => 0, 5 => 2]; $motives = PaintingEntity::MOTIVES; $face2side = [4, 5, 3, 2]; $foundApplicableMotive = false; $searchedMotives = []; while (!$foundApplicableMotive) { if (count($searchedMotives) == count($motives)) { break; } $rand = -1; while (!isset($motives[$rand])) { $rand = mt_rand(0, count($motives) - 1); } $motive = $motives[$rand]; $foundApplicableMotive = true; $searchedMotives[$rand] = true; for ($x = 0; $x < $motive[1] && $foundApplicableMotive; $x++) { for ($z = 0; $z < $motive[2] && $foundApplicableMotive; $z++) { if ($target->getSide($face2side[$face - 2], $x)->isTransparent() || $target->getSide(Vector3::SIDE_UP, $z)->isTransparent() || $block->getSide($face2side[$face - 2], $x)->isSolid() || $block->getSide(Vector3::SIDE_UP, $z)->isSolid()) { $foundApplicableMotive = false; } } } } if (!$foundApplicableMotive) { return false; } //WIP overlapping calculation AND BTW: EVEN MCPE DOESN'T DO THIS! /* for($x = 0; $x < $motive[1] && $valid; $x++){ for($z = 0; $z < $motive[2] && $valid; $z++){ $entPos = $target->getSide($right[$face - 2], $x); //getEntitiesAtThatPos (high intensive calculation) if($entity instanceof PaintingEntity){ return false; } } } */ $data = ["x" => $target->x, "y" => $target->y - 0.1, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]]; if ($motive[2] <= 1) { $data["y"] = $data["y"] + 1; } if ($motive[2] >= 2) { $data["y"] = $data["y"] + 0.4; } if ($motive[2] >= 3) { $data["y"] = $data["y"] + 0.1; } switch ($face2side[$face - 2]) { case Vector3::SIDE_NORTH: $data["z"] = $data["z"] + 0.1; break; case Vector3::SIDE_SOUTH: $data["z"] = $data["z"] - 0.1; break; case Vector3::SIDE_WEST: $data["x"] = $data["x"] + 0.1; break; case Vector3::SIDE_EAST: $data["x"] = $data["x"] - 0.1; break; } $nbt = new CompoundTag("", ["Motive" => new StringTag("Motive", $data["Motive"]), "Pos" => new ListTag("Pos", [new DoubleTag("", $data["x"]), new DoubleTag("", $data["y"]), new DoubleTag("", $data["z"])]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", $data["yaw"]), new FloatTag("", 0)])]); $painting = new PaintingEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt); $painting->spawnToAll(); unset($player->getLevel()->updateEntities[$painting->getId()]); if ($player->isSurvival()) { $item = $player->getInventory()->getItemInHand(); $count = $item->getCount(); if (--$count <= 0) { $player->getInventory()->setItemInHand(Item::get(Item::AIR)); } $item->setCount($count); $player->getInventory()->setItemInHand($item); } return true; } return false; }
private static function rotateBlockByOne(Block $block) { return Block::get($block->getID(), $block->getDamage(), new Position($block->getZ(), $block->getY(), -$block->getX(), $block->getLevel())); }
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"; }
/** * 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); }
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; }
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; }
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; }
/** * @param Block $block * @param string $token * @return string */ public function getAxisKey(Block $block, $token) { return $block->getX() . $token . $block->getY() . $token . $block->getZ(); }
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; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($target->isTransparent() === false and $face > 1 and $block->isSolid() === false) { $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4); $faces = [2 => 1, 3 => 3, 4 => 0, 5 => 2]; $motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]]; if ($this->hasCustomName()) { $nbt->CustomName = new String("CustomName", $this->getCustomName()); } $motive = $motives[mt_rand(0, count($motives) - 1)]; $data = ["x" => $target->x, "y" => $target->y, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]]; $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $target->x), new Double("", $target->y), new Double("", $target->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", $faces[$face] * 90), new Float("", 0)])]); $entity = Entity::createEntity($this->meta, $chunk, $nbt, $data); if ($entity instanceof Entity) { if ($player->isSurvival()) { --$this->count; } $entity->spawnToAll(); return true; } return true; } return false; }
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; }
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; }