diff --git a/src/API/AchievementAPI.php b/src/API/AchievementAPI.php index 5e79a094..7c87656c 100644 --- a/src/API/AchievementAPI.php +++ b/src/API/AchievementAPI.php @@ -81,13 +81,13 @@ class AchievementAPI{ ], ]; - + private $server; function __construct(){ - $this->server = ServerAPI::request(); + $this->server = ServerAPI::request(); } - + /** * Add an achievement * @param string $achievementId @@ -157,47 +157,47 @@ class AchievementAPI{ } } - public function viewAchievements($cmd, $params, $issuer, $alias) - { - if(!($issuer instanceof Player) && !isset($params[0])){ - return "Please enter a nickname."; - } else{ - if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){ - $player = $this->server->api->player->get($params[0]); - if($player instanceof Player){ - $data = $player->data; - } else{ - $data = $this->server->api->player->getOffline(trim($params[0]), false); - } - } else{ - $data = $issuer->achievements; - } - } - if($data === false){ - return "Player {$params[0]} is not found."; - } - if($data instanceof Config){ - $achs = $data->get("achievements"); - }else{ - $achs = $data; - } - - if(count($achs) <= 0){ - return "Player {$params[0]} unlocked 0 achievements"; - } - $output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): "; - foreach($achs as $achievement => $unlocked){ - if($unlocked && isset(self::$achievements[$achievement])){ - $info = self::$achievements[$achievement]; - $output .= "{$info["name"]}, "; - } - } - return substr($output, 0, - 2); - } + public function viewAchievements($cmd, $params, $issuer, $alias) + { + if(!($issuer instanceof Player) && !isset($params[0])){ + return "Please enter a nickname."; + } else{ + if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){ + $player = $this->server->api->player->get($params[0]); + if($player instanceof Player){ + $data = $player->data; + } else{ + $data = $this->server->api->player->getOffline(trim($params[0]), false); + } + } else{ + $data = $issuer->achievements; + } + } + if($data === false){ + return "Player {$params[0]} is not found."; + } + if($data instanceof Config){ + $achs = $data->get("achievements"); + }else{ + $achs = $data; + } + + if(count($achs) <= 0){ + return "Player {$params[0]} unlocked 0 achievements"; + } + $output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): "; + foreach($achs as $achievement => $unlocked){ + if($unlocked && isset(self::$achievements[$achievement])){ + $info = self::$achievements[$achievement]; + $output .= "{$info["name"]}, "; + } + } + return substr($output, 0, - 2); + } public function init(){ - $this->server->api->console->register("ach", "", [$this, "viewAchievements"]); - $this->server->api->console->alias("getplayerachievements", "ach"); - $this->server->api->console->cmdWhitelist("ach"); + $this->server->api->console->register("ach", "", [$this, "viewAchievements"]); + $this->server->api->console->alias("getplayerachievements", "ach"); + $this->server->api->console->cmdWhitelist("ach"); } } diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 886de4a8..d67da604 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -50,7 +50,7 @@ class BanAPI{ * @param string $cmd Command to Whitelist */ public function cmdWhitelist($cmd){ - $this->server->api->console->cmdWhitelist($cmd); + $this->server->api->console->cmdWhitelist($cmd); } /** @@ -67,21 +67,21 @@ class BanAPI{ } break; case "player.block.break": - /** - * @var Player $player - */ - $player = $data["player"]; - if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){ - $t = new Vector2($data["target"]->x, $data["target"]->z); - $s = new Vector2($this->server->spawn->x, $this->server->spawn->z); - if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){ - return false; - } - } - return; + /** + * @var Player $player + */ + $player = $data["player"]; + if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){ + $t = new Vector2($data["target"]->x, $data["target"]->z); + $s = new Vector2($this->server->spawn->x, $this->server->spawn->z); + if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){ + return false; + } + } + return; case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area. - $player = $data["player"]; - if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){ + $player = $data["player"]; + if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){ $t = new Vector2($data["block"]->x, $data["block"]->z); $s = new Vector2($this->server->spawn->x, $this->server->spawn->z); if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){ diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index c4fb980e..efe21123 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -435,7 +435,7 @@ class BlockAPI{ $item = $player->getSlot($player->slot); if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ //If no block exists or not allowed in CREATIVE - if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ + if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ $this->cancelAction($target, $player); return $this->cancelAction($block, $player); } @@ -443,7 +443,7 @@ class BlockAPI{ if($this->server->api->dhandle("player.block.touch", ["type" => "place", "player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){ if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ - return $this->cancelAction($block, $player); + return $this->cancelAction($block, $player); } } $this->blockUpdate($target, BLOCK_UPDATE_TOUCH); @@ -532,7 +532,7 @@ class BlockAPI{ $this->server->api->entity->updateRadius($pos, 1); }elseif($level === BLOCK_UPDATE_RANDOM){ //$this->nextRandomUpdate($pos); old version, change back if any issues will start to happen with this one(please note that old version makes a lot of lag) - $this->scheduleBlockUpdate($pos, (mt_rand(25, 75) + Utils::getRandomUpdateTicks() * 0.05) / 0.05, BLOCK_UPDATE_RANDOM); + $this->scheduleBlockUpdate($pos, (mt_rand(25, 75) + Utils::getRandomUpdateTicks() * 0.05) / 0.05, BLOCK_UPDATE_RANDOM); } return $level; } diff --git a/src/API/ChatAPI.php b/src/API/ChatAPI.php index d656627a..cf7f8272 100644 --- a/src/API/ChatAPI.php +++ b/src/API/ChatAPI.php @@ -12,7 +12,7 @@ class ChatAPI{ $this->server->api->console->register("tell", " ", [$this, "commandHandler"]); $this->server->api->console->register("me", "", [$this, "commandHandler"]); $this->server->api->console->register("say", "", [$this, "commandHandler"]); - $this->server->api->console->cmdWhitelist("tell"); + $this->server->api->console->cmdWhitelist("tell"); $this->server->api->console->cmdWhitelist("me"); $this->server->api->console->alias("msg", "tell"); } diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 13370310..65bc3c36 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -25,13 +25,13 @@ class ConsoleAPI{ $this->cmdWhitelist("help"); $this->cmdWhitelist("status"); } - + /** * Whitelists a CMD so everyone can issue it - Even non OPs. * @param string $cmd Command to Whitelist */ public function cmdWhitelist($cmd){ - $this->server->api->ban->cmdWhitelist[strtolower(trim($cmd))] = true; + $this->server->api->ban->cmdWhitelist[strtolower(trim($cmd))] = true; } public function register($cmd, $help, $callback){ @@ -304,11 +304,11 @@ class ConsoleLoop extends Thread{ } while(!$this->stop){ - $this->line = $this->readLine(); - $this->synchronized(function($t) { - $this->wait(); - $this->line = false; - }, $this); + $this->line = $this->readLine(); + $this->synchronized(function($t) { + $this->wait(); + $this->line = false; + }, $this); } if(!extension_loaded("readline")){ diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 9787ec65..f0f7d6f9 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -1,113 +1,113 @@ entities = []; - $this->server = ServerAPI::request(); - - $this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals"); - $this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs"); - } - - public function init(){ - $this->server->api->console->register("summon", "", [$this, "commandHandler"]); - $this->server->api->console->register("spawnmob", "", [$this, "commandHandler"]); - $this->server->api->console->register("despawn", "", [$this, "CommandHandler"]); - } - - - public function commandHandler($cmd, $args, $issuer, $alias){ - $mob = [ - "chicken" => 10, - "cow" => 11, - "pig" => 12, - "sheep" => 13, - - "zombie" => 32, - "creeper" => 33, - "skeleton" => 34, - "spider" => 35, - "pigman" => 36 - ]; - $output = ""; - switch($cmd){ - case "summon": - case "spawnmob": - if(!($issuer instanceof Player)){ - $output .= "Please run this command in-game."; - break; - } - if((count($args) < 1) or (count($args) > 3)){ - $output .= "Usage: /$cmd [amount] [baby]"; - break; - } - - if(is_int($args[0])) $type = $args[0]; - else $type = $mob[strtolower($args[0])]; - if($type != (10 or 11 or 12 or 13 or 32 or 33 or 34 or 35 or 36)){ - $output .= "Unknown mob."; - break; - } - $mobName = ucfirst(array_flip($mob)[$type]); - - if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){ - $output .= "$mobName cannot be a baby!"; - break; - } - - $x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP); - $y = round($issuer->entity->y, 2, PHP_ROUND_HALF_UP); - $z = round($issuer->entity->z, 2, PHP_ROUND_HALF_UP); - $level = $issuer->entity->level; - $pos = new Position($x, $y, $z, $level); - - if(count($args) === 1){//summon - $this->summon($pos, ENTITY_MOB, $type); - $output .= "$mobName spawned in $x, $y, $z."; - break; - } - elseif(is_numeric($args[1])){//summon [amount] - $amount = (int) $args[1]; - if($amount > 100){ - $output .= "Cannot spawn > 100 mobs"; - break; - } - $isBaby = false; - if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon [amount] [baby] - $isBaby = true; - } - - for($cnt = $amount; $cnt > 0; --$cnt){ - $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]); - } - - $output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z."; - break; - } - elseif(strtolower($args[1]) == "baby"){//summon [baby] - $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]); - $output .= "Baby $mobName spawned in $x, $y, $z."; - break; - } - break; - case "despawn": - $cnt = 0; + public $entities; + private $server; + private $eCnt = 1; + + function __construct(){ + $this->entities = []; + $this->server = ServerAPI::request(); + + $this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals"); + $this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs"); + } + + public function init(){ + $this->server->api->console->register("summon", "", [$this, "commandHandler"]); + $this->server->api->console->register("spawnmob", "", [$this, "commandHandler"]); + $this->server->api->console->register("despawn", "", [$this, "CommandHandler"]); + } + + + public function commandHandler($cmd, $args, $issuer, $alias){ + $mob = [ + "chicken" => 10, + "cow" => 11, + "pig" => 12, + "sheep" => 13, + + "zombie" => 32, + "creeper" => 33, + "skeleton" => 34, + "spider" => 35, + "pigman" => 36 + ]; + $output = ""; + switch($cmd){ + case "summon": + case "spawnmob": + if(!($issuer instanceof Player)){ + $output .= "Please run this command in-game."; + break; + } + if((count($args) < 1) or (count($args) > 3)){ + $output .= "Usage: /$cmd [amount] [baby]"; + break; + } + + if(is_int($args[0])) $type = $args[0]; + else $type = $mob[strtolower($args[0])]; + if($type != (10 or 11 or 12 or 13 or 32 or 33 or 34 or 35 or 36)){ + $output .= "Unknown mob."; + break; + } + $mobName = ucfirst(array_flip($mob)[$type]); + + if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){ + $output .= "$mobName cannot be a baby!"; + break; + } + + $x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP); + $y = round($issuer->entity->y, 2, PHP_ROUND_HALF_UP); + $z = round($issuer->entity->z, 2, PHP_ROUND_HALF_UP); + $level = $issuer->entity->level; + $pos = new Position($x, $y, $z, $level); + + if(count($args) === 1){//summon + $this->summon($pos, ENTITY_MOB, $type); + $output .= "$mobName spawned in $x, $y, $z."; + break; + } + elseif(is_numeric($args[1])){//summon [amount] + $amount = (int) $args[1]; + if($amount > 100){ + $output .= "Cannot spawn > 100 mobs"; + break; + } + $isBaby = false; + if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon [amount] [baby] + $isBaby = true; + } + + for($cnt = $amount; $cnt > 0; --$cnt){ + $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]); + } + + $output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z."; + break; + } + elseif(strtolower($args[1]) == "baby"){//summon [baby] + $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]); + $output .= "Baby $mobName spawned in $x, $y, $z."; + break; + } + break; + case "despawn": + $cnt = 0; if(!isset($args[0])){ $output .= "/despawn "; break; }else{ if($args[0] === "all"){ - $cnt = 0; - foreach($this->entities as $e){ - if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning - $this->remove($e->eid); - $cnt++; - } - } + $cnt = 0; + foreach($this->entities as $e){ + if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning + $this->remove($e->eid); + $cnt++; + } + } }else{ $array = explode(",", strtolower($args[0])); if(count($array) > 4){ @@ -123,173 +123,173 @@ class EntityAPI{ $despawning = substr($list, 0, -4); $l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";"); if($l !== false and $l !== true){ - while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ - $e = $this->get($e["EID"]); - if($e instanceof Entity){ - $this->remove($e->eid); - $cnt++; - } - } + while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ + $e = $this->get($e["EID"]); + if($e instanceof Entity){ + $this->remove($e->eid); + $cnt++; + } + } } } } - - $output = "$cnt entities have been despawned!"; - break; - } - return $output; - } - - public function summon(Position $pos, $class, $type, Array $data = []){ - $entity = $this->add($pos->level, $class, $type, [ - "x" => $pos->x, - "y" => $pos->y, - "z" => $pos->z - ] + $data); - $this->spawnToAll($entity, $pos->level); - } - - public function add(Level $level, $class, $type = 0, $data = []){ - $eid = $this->eCnt++; - $efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class); - if($efl instanceof PropertyEntity){ - $class = $efl->getEntityName(); - $this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data); - }else{ - $this->entities[$eid] = new Entity($level, $eid, $class, $type, $data); - } - $level->entityList[$eid] = &$this->entities[$eid]; - $this->server->handle("entity.add", $this->entities[$eid]); - return $this->entities[$eid]; - } - - public function spawnToAll(Entity $e){ - foreach($this->server->api->player->getAll($e->level) as $player){ - if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){ - $e->spawn($player); - } - } - } - - public function get($eid){ - if(isset($this->entities[$eid])){ - return $this->entities[$eid]; - } - return false; - } - - public function remove($eid){ - if(isset($this->entities[$eid])){ - $this->entities[$eid]->closed = true; + + $output = "$cnt entities have been despawned!"; + break; + } + return $output; + } + + public function summon(Position $pos, $class, $type, Array $data = []){ + $entity = $this->add($pos->level, $class, $type, [ + "x" => $pos->x, + "y" => $pos->y, + "z" => $pos->z + ] + $data); + $this->spawnToAll($entity, $pos->level); + } + + public function add(Level $level, $class, $type = 0, $data = []){ + $eid = $this->eCnt++; + $efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class); + if($efl instanceof PropertyEntity){ + $class = $efl->getEntityName(); + $this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data); + }else{ + $this->entities[$eid] = new Entity($level, $eid, $class, $type, $data); + } + $level->entityList[$eid] = &$this->entities[$eid]; + $this->server->handle("entity.add", $this->entities[$eid]); + return $this->entities[$eid]; + } + + public function spawnToAll(Entity $e){ + foreach($this->server->api->player->getAll($e->level) as $player){ + if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){ + $e->spawn($player); + } + } + } + + public function get($eid){ + if(isset($this->entities[$eid])){ + return $this->entities[$eid]; + } + return false; + } + + public function remove($eid){ + if(isset($this->entities[$eid])){ + $this->entities[$eid]->closed = true; if($this->entities[$eid]->isPlayer()){ - $pk = new RemovePlayerPacket; - $pk->eid = $eid; - $pk->clientID = 0; - $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk); - }else{ - $pk = new RemoveEntityPacket; - $pk->eid = $eid; - $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk); - } - $this->server->api->dhandle("entity.remove", $this->entities[$eid]); + $pk = new RemovePlayerPacket; + $pk->eid = $eid; + $pk->clientID = 0; + $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk); + }else{ + $pk = new RemoveEntityPacket; + $pk->eid = $eid; + $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk); + } + $this->server->api->dhandle("entity.remove", $this->entities[$eid]); unset($this->entities[$eid]->level->entityList[$eid]); - unset($this->entities[$eid]); - $this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";"); - } - } - - public function updateRadius(Position $center, $radius = 15, $class = false){ - $this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;"); - } - - public function getRadius(Position $center, $radius = 15, $class = false){ - $entities = []; - $l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;"); - if($l !== false and $l !== true){ - while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ - $e = $this->get($e["EID"]); - if($e instanceof Entity){ - $entities[$e->eid] = $e; - } - } - } - return $entities; - } - - public function heal($eid, $heal, $cause){ - $this->harm($eid, -$heal, $cause); - } - - public function harm($eid, $attack, $cause, $force = false){ - $e = $this->get($eid); - if($e === false or $e->dead === true){ - return false; - } - $e->setHealth($e->getHealth() - $attack, $cause, $force); - } - - public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){ - if($item->getID() === AIR or $item->count <= 0){ - return; - } - $data = [ - "x" => $pos->x, - "y" => $pos->y, - "z" => $pos->z, - "level" => $pos->level, - "speedX" => $speedX, - "speedY" => $speedY, - "speedZ" => $speedZ, - "item" => $item, - ]; - if($this->server->api->handle("item.drop", $data) !== false){ - for($count = $item->count; $count > 0;){ - $item->count = min($item->getMaxStackSize(), $count); - $count -= $item->count; - $e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data); - $this->spawnToAll($e); - $this->server->api->handle("entity.motion", $e); - } - } - } - - public function drop(Position $pos, Item $item){ - if($item->getID() === AIR or $item->count <= 0){ - return; - } - $data = [ - "x" => $pos->x + mt_rand(-10, 10) / 50, - "y" => $pos->y + 0.19, - "z" => $pos->z + mt_rand(-10, 10) / 50, - "level" => $pos->level, - "speedX" => Utils::randomFloat() * 0.2 - 0.1, - "speedY" => 0.2, - "speedZ" => Utils::randomFloat() * 0.2 - 0.1, - "item" => $item, + unset($this->entities[$eid]); + $this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";"); + } + } + + public function updateRadius(Position $center, $radius = 15, $class = false){ + $this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;"); + } + + public function getRadius(Position $center, $radius = 15, $class = false){ + $entities = []; + $l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;"); + if($l !== false and $l !== true){ + while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ + $e = $this->get($e["EID"]); + if($e instanceof Entity){ + $entities[$e->eid] = $e; + } + } + } + return $entities; + } + + public function heal($eid, $heal, $cause){ + $this->harm($eid, -$heal, $cause); + } + + public function harm($eid, $attack, $cause, $force = false){ + $e = $this->get($eid); + if($e === false or $e->dead === true){ + return false; + } + $e->setHealth($e->getHealth() - $attack, $cause, $force); + } + + public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){ + if($item->getID() === AIR or $item->count <= 0){ + return; + } + $data = [ + "x" => $pos->x, + "y" => $pos->y, + "z" => $pos->z, + "level" => $pos->level, + "speedX" => $speedX, + "speedY" => $speedY, + "speedZ" => $speedZ, + "item" => $item, ]; - if($this->server->api->handle("item.drop", $data) !== false){ - for($count = $item->count; $count > 0;){ - $item->count = min($item->getMaxStackSize(), $count); - $count -= $item->count; - $e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data); - $this->spawnToAll($e); - $this->server->api->handle("entity.motion", $e); - } - } - } - - public function spawnAll(Player $player){ - foreach($this->getAll($player->level) as $e){ - if($e->class !== ENTITY_PLAYER){ - $e->spawn($player); - } - } - } - - public function getAll($level = null){ - if($level instanceof Level){ - return $level->entityList; - } - return $this->entities; - } + if($this->server->api->handle("item.drop", $data) !== false){ + for($count = $item->count; $count > 0;){ + $item->count = min($item->getMaxStackSize(), $count); + $count -= $item->count; + $e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data); + $this->spawnToAll($e); + $this->server->api->handle("entity.motion", $e); + } + } + } + + public function drop(Position $pos, Item $item){ + if($item->getID() === AIR or $item->count <= 0){ + return; + } + $data = [ + "x" => $pos->x + mt_rand(-10, 10) / 50, + "y" => $pos->y + 0.19, + "z" => $pos->z + mt_rand(-10, 10) / 50, + "level" => $pos->level, + "speedX" => Utils::randomFloat() * 0.2 - 0.1, + "speedY" => 0.2, + "speedZ" => Utils::randomFloat() * 0.2 - 0.1, + "item" => $item, + ]; + if($this->server->api->handle("item.drop", $data) !== false){ + for($count = $item->count; $count > 0;){ + $item->count = min($item->getMaxStackSize(), $count); + $count -= $item->count; + $e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data); + $this->spawnToAll($e); + $this->server->api->handle("entity.motion", $e); + } + } + } + + public function spawnAll(Player $player){ + foreach($this->getAll($player->level) as $e){ + if($e->class !== ENTITY_PLAYER){ + $e->spawn($player); + } + } + } + + public function getAll($level = null){ + if($level instanceof Level){ + return $level->entityList; + } + return $this->entities; + } } diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 062738ca..93f6a15f 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -1,10 +1,10 @@ registerCmd("spawn"); $this->registerCmd("ping"); $this->server->api->console->alias("lag", "ping"); - $this->server->api->console->alias("gm", "gamemode"); + $this->server->api->console->alias("gm", "gamemode"); $this->server->api->console->alias("who", "list"); $this->server->api->console->alias("suicide", "kill"); $this->server->api->console->alias("tppos", "tp"); @@ -392,7 +392,7 @@ class PlayerAPI{ $data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default); $data->save(); }else{ - return false; + return false; } } diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index d743fa7b..2726a1dc 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -27,7 +27,7 @@ class PluginAPI extends stdClass{ $this->server->api->console->register("version", "", [$this, "commandHandler"]); $this->server->api->console->cmdWhitelist("version"); if($this->server->extraprops->get("query-plugins")){ //allow players to also view plugins ingame, since query makes names public - $this->server->api->console->cmdWhitelist("plugins"); + $this->server->api->console->cmdWhitelist("plugins"); } $this->server->api->console->alias("pl", "plugins"); $this->server->api->console->alias("ver", "version"); @@ -65,7 +65,7 @@ class PluginAPI extends stdClass{ public function __destruct(){ foreach($this->plugins as $p){ - if(method_exists($p[0], "__destruct")){$p[0]->__destruct();}; + if(method_exists($p[0], "__destruct")){$p[0]->__destruct();}; } unset($this->plugins); } @@ -163,7 +163,7 @@ class PluginAPI extends stdClass{ $aver = CURRENT_API_VERSION; if($pluginInfo["api"] != $aver){ - console("[WARNING] API is not the same as Core, might cause bugs({$pluginInfo["api"]} != {$aver})"); + console("[WARNING] API is not the same as Core, might cause bugs({$pluginInfo["api"]} != {$aver})"); } $phr = "phar://$filePath/"; diff --git a/src/Player.php b/src/Player.php index ab58dc86..060dadf8 100755 --- a/src/Player.php +++ b/src/Player.php @@ -898,14 +898,14 @@ class Player{ } } public function makeInvisibleForOnePlayer(Player $player){ - $pk = new RemoveEntityPacket; - $pk->eid = $this->entity->eid; - $player->dataPacket($pk); + $pk = new RemoveEntityPacket; + $pk->eid = $this->entity->eid; + $player->dataPacket($pk); } public function makeInvisibleForAllPlayers(){ - $pk = new RemoveEntityPacket; - $pk->eid = $this->entity->eid; - $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk); + $pk = new RemoveEntityPacket; + $pk->eid = $this->entity->eid; + $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk); } public function getGamemode(){ switch($this->gamemode){ @@ -959,10 +959,10 @@ class Player{ } if($this->gamemode === SPECTATOR){ - $this->makeInvisibleForAllPlayers(); + $this->makeInvisibleForAllPlayers(); } if($this->gamemode === CREATIVE){ - $this->server->api->player->spawnToAllPlayers($this); + $this->server->api->player->spawnToAllPlayers($this); } $this->inventory = $inv; @@ -1315,17 +1315,17 @@ class Player{ return; } if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ - if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ - $pk = new LoginStatusPacket; - $pk->status = 1; - $this->directDataPacket($pk); - }else{ - $pk = new LoginStatusPacket; - $pk->status = 2; - $this->directDataPacket($pk); - } - $this->close("Incorrect protocol #" . $packet->protocol1, false); - return; + if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ + $pk = new LoginStatusPacket; + $pk->status = 1; + $this->directDataPacket($pk); + }else{ + $pk = new LoginStatusPacket; + $pk->status = 2; + $this->directDataPacket($pk); + } + $this->close("Incorrect protocol #" . $packet->protocol1, false); + return; } if(preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or $this->iusername === "server"){ $this->close("Bad username", false); @@ -1485,7 +1485,7 @@ class Player{ $this->sendArmor(); $array = explode("@n", (string)$this->server->motd); foreach($array as $msg){ - $this->sendChat($msg."\n"); + $this->sendChat($msg."\n"); } $this->sendInventory(); @@ -1799,7 +1799,7 @@ class Player{ $target = $this->server->api->entity->get($packet->target); if($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){ $data["targetentity"] = $packet->target; - $data["entity"] = $this; + $data["entity"] = $this; if($this->server->handle("player.interact", $data) !== false){ $target->interactWith($this->entity, $packet->action); } @@ -1900,18 +1900,18 @@ class Player{ $data["item"] = $packet->item; $data["player"] = $this; if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){ - $f1 = 0.3; - $sX = -sin(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; - $sZ = cos(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; - $sY = -sin(($this->entity->pitch / 180) * M_PI) * $f1 + 0.1; - $f1 = 0.02; - $f3 = $this->entity->random->nextFloat() * M_PI * 2.0; - $f1 *= $this->entity->random->nextFloat(); - $sX += cos($f3) * $f1; - $sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1; - $sZ += sin($f3) * $f1; - - $this->server->api->entity->dropRawPos(new Position($this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $this->level), $packet->item, $sX, $sY, $sZ); + $f1 = 0.3; + $sX = -sin(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; + $sZ = cos(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; + $sY = -sin(($this->entity->pitch / 180) * M_PI) * $f1 + 0.1; + $f1 = 0.02; + $f3 = $this->entity->random->nextFloat() * M_PI * 2.0; + $f1 *= $this->entity->random->nextFloat(); + $sX += cos($f3) * $f1; + $sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1; + $sZ += sin($f3) * $f1; + + $this->server->api->entity->dropRawPos(new Position($this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $this->level), $packet->item, $sX, $sY, $sZ); $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); } if($this->entity->inAction === true){ @@ -2167,20 +2167,20 @@ class Player{ } break; case ProtocolInfo::PLAYER_INPUT_PACKET: - break; //TODO player input- + break; //TODO player input- default: console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2); break; } } - + /** * Get an Item which is currently held by player * @return Item */ public function getHeldItem(){ - return $this->getSlot($this->slot); + return $this->getSlot($this->slot); } public function stopSleep(){ diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 6a00d1cb..6d902fea 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -2,7 +2,7 @@ class PocketMinecraftServer{ - public $tCnt, $ticks; + public $tCnt, $ticks; public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; /** * @var ServerAPI @@ -70,7 +70,7 @@ class PocketMinecraftServer{ console("[INFO] Loading extra.properties..."); $this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [ "version" => "5", - "experemental-mob-features" => false, + "experemental-mob-features" => false, "enable-nether-reactor" => true, "enable-explosions" => true, "enable-rail-connection" => false, @@ -84,7 +84,7 @@ class PocketMinecraftServer{ ]); Entity::$updateOnTick = $this->extraprops->get("experemental-mob-features"); if(Entity::$updateOnTick){ - console("[WARNING] Experemental mob features are enabled. Unpredictable behavior."); + console("[WARNING] Experemental mob features are enabled. Unpredictable behavior."); } Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config @@ -451,31 +451,31 @@ class PocketMinecraftServer{ } } - public function process() - { - $lastLoop = 0; - while($this->stop === false){ - $packet = $this->interface->readPacket(); - if($packet instanceof Packet){ - $this->packetHandler($packet); - $lastLoop = 0; - } elseif($this->tick() > 0){ - $lastLoop = 0; - } else{ - ++ $lastLoop; - if($lastLoop < 16){ - usleep(1); - } elseif($lastLoop < 128){ - usleep(100); - } elseif($lastLoop < 256){ - usleep(512); - } else{ - usleep(10000); - } - } - $this->tick(); - } - } + public function process() + { + $lastLoop = 0; + while($this->stop === false){ + $packet = $this->interface->readPacket(); + if($packet instanceof Packet){ + $this->packetHandler($packet); + $lastLoop = 0; + } elseif($this->tick() > 0){ + $lastLoop = 0; + } else{ + ++ $lastLoop; + if($lastLoop < 16){ + usleep(1); + } elseif($lastLoop < 128){ + usleep(100); + } elseif($lastLoop < 256){ + usleep(512); + } else{ + usleep(10000); + } + } + $this->tick(); + } + } public function packetHandler(Packet $packet){ $data =& $packet; @@ -568,7 +568,7 @@ class PocketMinecraftServer{ unset($this->tickMeasure[key($this->tickMeasure)]); ++$this->ticks; foreach($this->api->level->levels as $l){ - $l->onTick($this); + $l->onTick($this); } return $this->tickerFunction($time); } diff --git a/src/astarnavigator/ArrayList.php b/src/astarnavigator/ArrayList.php index 4f8a2c85..ad6a4a96 100644 --- a/src/astarnavigator/ArrayList.php +++ b/src/astarnavigator/ArrayList.php @@ -1,40 +1,40 @@ arr[$e->__toString()] = $e; - return $this; - } - - public function addAll($es){ - foreach($es as $e){ - $this->add($this->add($e)); - } - } - - public function getFirst(){ - return array_values($this->arr)[0]; - } - - public function remove(IElement $e){ - unset($this->arr[$e->__toString()]); - return $this; - } - - public function __isset($e){ - return isset($this->arr[$e->__toString()]); - } - - public function has(IElement $e){ - return isset($this->arr[$e->__toString()]); - } - - public function sortWith($func){ - return uasort($this->arr, $func); - } - - public function countElements(){ - return count($this->arr); - } + public $arr = []; + public function add(IElement $e){ + $this->arr[$e->__toString()] = $e; + return $this; + } + + public function addAll($es){ + foreach($es as $e){ + $this->add($this->add($e)); + } + } + + public function getFirst(){ + return array_values($this->arr)[0]; + } + + public function remove(IElement $e){ + unset($this->arr[$e->__toString()]); + return $this; + } + + public function __isset($e){ + return isset($this->arr[$e->__toString()]); + } + + public function has(IElement $e){ + return isset($this->arr[$e->__toString()]); + } + + public function sortWith($func){ + return uasort($this->arr, $func); + } + + public function countElements(){ + return count($this->arr); + } } diff --git a/src/astarnavigator/IElement.php b/src/astarnavigator/IElement.php index e88c21ba..4357c6ab 100644 --- a/src/astarnavigator/IElement.php +++ b/src/astarnavigator/IElement.php @@ -2,6 +2,6 @@ interface IElement { - public function __toString(); + public function __toString(); } diff --git a/src/astarnavigator/ITileNavigator.php b/src/astarnavigator/ITileNavigator.php index 89ada4a9..b5b7bc56 100644 --- a/src/astarnavigator/ITileNavigator.php +++ b/src/astarnavigator/ITileNavigator.php @@ -2,6 +2,6 @@ interface ITileNavigator { - public function navigate(PathTile $from, PathTile $to); + public function navigate(PathTile $from, PathTile $to); } diff --git a/src/astarnavigator/PHPUtils.php b/src/astarnavigator/PHPUtils.php index 23dbabca..e220c896 100644 --- a/src/astarnavigator/PHPUtils.php +++ b/src/astarnavigator/PHPUtils.php @@ -2,11 +2,11 @@ class PHPUtils { - public static function removeElementFromArray(&$arr, $element, $reindex = true){ - if (($key = array_search($element, $arr)) !== false) { - unset($arr[$key]); - if($reindex) $arr = array_values($arr); - } - } + public static function removeElementFromArray(&$arr, $element, $reindex = true){ + if (($key = array_search($element, $arr)) !== false) { + unset($arr[$key]); + if($reindex) $arr = array_values($arr); + } + } } diff --git a/src/astarnavigator/PathTile.php b/src/astarnavigator/PathTile.php index bde68fcb..b95c4c73 100644 --- a/src/astarnavigator/PathTile.php +++ b/src/astarnavigator/PathTile.php @@ -2,26 +2,26 @@ class PathTile implements IElement { - public $x, $y; - - public function __construct($x, $y){ - $this->x = $x; - $this->y = $y; - } - - public function equals(PathTile $t){ - return $t->x === $this->x && $t->y === $this->y; - } - - public function addOffset($offset){ - $this->x += $offset[0]; - $this->y += $offset[1]; - return $this; - } - - public function __toString(){ - return $this->x.":".$this->y; - } + public $x, $y; + + public function __construct($x, $y){ + $this->x = $x; + $this->y = $y; + } + + public function equals(PathTile $t){ + return $t->x === $this->x && $t->y === $this->y; + } + + public function addOffset($offset){ + $this->x += $offset[0]; + $this->y += $offset[1]; + return $this; + } + + public function __toString(){ + return $this->x.":".$this->y; + } } diff --git a/src/astarnavigator/PathTileXYZ.php b/src/astarnavigator/PathTileXYZ.php index 4134f3fb..29fcd684 100644 --- a/src/astarnavigator/PathTileXYZ.php +++ b/src/astarnavigator/PathTileXYZ.php @@ -2,37 +2,37 @@ class PathTileXYZ extends PathTile { - public $x, $y, $z; - - /** - * @var Level - */ - public $level; - - public function __construct($x, $y, $z, $level){ - $this->x = floor($x); - $this->y = floor($y); - $this->z = floor($z); - $this->level = $level; - } - - public function equals(PathTile $t){ - return $t->x === $this->x && $t->y === $this->y && $t->z === $this->z; - } - - public function asVector(){ - return new Vector3($this->x, $this->y, $this->z); - } - - public function addOffset($offset){ - $this->x += $offset[0]; - $this->y += $offset[1]; - $this->z += $offset[2]; - return $this; - } - - public function __toString(){ - return $this->x.":".$this->y.":".$this->z; - } + public $x, $y, $z; + + /** + * @var Level + */ + public $level; + + public function __construct($x, $y, $z, $level){ + $this->x = floor($x); + $this->y = floor($y); + $this->z = floor($z); + $this->level = $level; + } + + public function equals(PathTile $t){ + return $t->x === $this->x && $t->y === $this->y && $t->z === $this->z; + } + + public function asVector(){ + return new Vector3($this->x, $this->y, $this->z); + } + + public function addOffset($offset){ + $this->x += $offset[0]; + $this->y += $offset[1]; + $this->z += $offset[2]; + return $this; + } + + public function __toString(){ + return $this->x.":".$this->y.":".$this->z; + } } diff --git a/src/astarnavigator/TileNavigator.php b/src/astarnavigator/TileNavigator.php index 5af74755..380735ee 100644 --- a/src/astarnavigator/TileNavigator.php +++ b/src/astarnavigator/TileNavigator.php @@ -2,15 +2,15 @@ class TileNavigator implements ITileNavigator { - private $blockedProvider, $neighborProvider, $distanceAlgorithm, $heuristicAlgorithm; - public function __construct(IBlockedProvider $blockedProvider, INeighborProvider $neighborProvider, IDistanceAlgorithm $distanceAlgorithm, IDistanceAlgorithm $heuristicAlgorithm){ - $this->blockedProvider = $blockedProvider; - $this->neighborProvider = $neighborProvider; - $this->distanceAlgorithm = $distanceAlgorithm; - $this->heuristicAlgorithm = $heuristicAlgorithm; - } - - public function reconstructPath($path, $current){ + private $blockedProvider, $neighborProvider, $distanceAlgorithm, $heuristicAlgorithm; + public function __construct(IBlockedProvider $blockedProvider, INeighborProvider $neighborProvider, IDistanceAlgorithm $distanceAlgorithm, IDistanceAlgorithm $heuristicAlgorithm){ + $this->blockedProvider = $blockedProvider; + $this->neighborProvider = $neighborProvider; + $this->distanceAlgorithm = $distanceAlgorithm; + $this->heuristicAlgorithm = $heuristicAlgorithm; + } + + public function reconstructPath($path, $current){ $totalPath = [$current]; while (isset($path[(string)$current])) { @@ -20,67 +20,67 @@ class TileNavigator implements ITileNavigator //foreach(array_unique($path) as $k => $p) console($k.":".$p); //foreach($totalPath as $k => $p) console($k.":".$p); array_pop($totalPath); - return array_reverse($totalPath); - } - - public function navigate(PathTile $from, PathTile $to) - { - $closed = new ArrayList(); - $open = new ArrayList(); - $open->add($from); - $path = []; //new Dictionary(); - $gScore = []; //new Dictionary(); - $gScore[(string) $from] = 0; - /** - * @var array[Tile] $fScore - */ - $fScore = [];//new Dictionary(); - $fScore[(string) $from] = $this->heuristicAlgorithm->calculate($from, $to); - if($this->blockedProvider->isBlocked($to)){ - return null; - } - $visited = []; - while($open->countElements() > 0) - { - //sleep(1); - $open->sortWith(function($k, $k1) use ($fScore){ - return $fScore[(string)$k] === $fScore[(string)$k1] ? 0 : ($fScore[(string)$k] > $fScore[(string)$k1] ? 1 : -1); - }); - $current = $open->getFirst(); - if ($current->equals($to)){ - return $this->reconstructPath($path, $current); - } - $open->remove($current); - $closed->add($current); - foreach($this->neighborProvider->getNeighbors($current) as $neighbor) - { - if ($closed->has($neighbor) || $this->blockedProvider->isBlocked($neighbor)) - { - continue; - } - if(in_array($neighbor, $visited)){ - continue; + return array_reverse($totalPath); + } + + public function navigate(PathTile $from, PathTile $to) + { + $closed = new ArrayList(); + $open = new ArrayList(); + $open->add($from); + $path = []; //new Dictionary(); + $gScore = []; //new Dictionary(); + $gScore[(string) $from] = 0; + /** + * @var array[Tile] $fScore + */ + $fScore = [];//new Dictionary(); + $fScore[(string) $from] = $this->heuristicAlgorithm->calculate($from, $to); + if($this->blockedProvider->isBlocked($to)){ + return null; } - $visited[] = $neighbor; - $tentativeG = $gScore[(string) $current] + $this->distanceAlgorithm->calculate($current, $neighbor); - - if (!$open->has($neighbor)) - { - $open->add($neighbor); - } - else if ($tentativeG >= $gScore[(string) $neighbor]) - { - continue; - } - $path[(string) $neighbor] = $current; - $gScore[(string) $neighbor] = $tentativeG; - $fScore[(string) $neighbor] = $gScore[(string) $neighbor] + $this->heuristicAlgorithm->calculate($neighbor, $to); - } - } - - return null; - } + $visited = []; + while($open->countElements() > 0) + { + //sleep(1); + $open->sortWith(function($k, $k1) use ($fScore){ + return $fScore[(string)$k] === $fScore[(string)$k1] ? 0 : ($fScore[(string)$k] > $fScore[(string)$k1] ? 1 : -1); + }); + $current = $open->getFirst(); + if ($current->equals($to)){ + return $this->reconstructPath($path, $current); + } + $open->remove($current); + $closed->add($current); + foreach($this->neighborProvider->getNeighbors($current) as $neighbor) + { + if ($closed->has($neighbor) || $this->blockedProvider->isBlocked($neighbor)) + { + continue; + } + if(in_array($neighbor, $visited)){ + continue; + } + $visited[] = $neighbor; + $tentativeG = $gScore[(string) $current] + $this->distanceAlgorithm->calculate($current, $neighbor); + + if (!$open->has($neighbor)) + { + $open->add($neighbor); + } + else if ($tentativeG >= $gScore[(string) $neighbor]) + { + continue; + } + $path[(string) $neighbor] = $current; + $gScore[(string) $neighbor] = $tentativeG; + $fScore[(string) $neighbor] = $gScore[(string) $neighbor] + $this->heuristicAlgorithm->calculate($neighbor, $to); + } + } + + return null; + } - + } diff --git a/src/astarnavigator/algorithms/IDistanceAlgorithm.php b/src/astarnavigator/algorithms/IDistanceAlgorithm.php index b0eb6848..391c629a 100644 --- a/src/astarnavigator/algorithms/IDistanceAlgorithm.php +++ b/src/astarnavigator/algorithms/IDistanceAlgorithm.php @@ -2,6 +2,6 @@ interface IDistanceAlgorithm { - public function calculate(PathTile $from, PathTile $to); + public function calculate(PathTile $from, PathTile $to); } diff --git a/src/astarnavigator/algorithms/ManhattanHeuristic3D.php b/src/astarnavigator/algorithms/ManhattanHeuristic3D.php index c69831be..2ac95f49 100644 --- a/src/astarnavigator/algorithms/ManhattanHeuristic3D.php +++ b/src/astarnavigator/algorithms/ManhattanHeuristic3D.php @@ -2,13 +2,13 @@ class ManhattanHeuristic3D implements IDistanceAlgorithm { - public function calculate(PathTile $from, PathTile $to) + public function calculate(PathTile $from, PathTile $to) { - if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){ - return Utils::manh_distance($from->asVector(), $to->asVector()); - } - return 666; - } + if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){ + return Utils::manh_distance($from->asVector(), $to->asVector()); + } + return 666; + } } diff --git a/src/astarnavigator/algorithms/ManhattanHeuristicAlgorithm.php b/src/astarnavigator/algorithms/ManhattanHeuristicAlgorithm.php index 744748f4..eb9b71f0 100644 --- a/src/astarnavigator/algorithms/ManhattanHeuristicAlgorithm.php +++ b/src/astarnavigator/algorithms/ManhattanHeuristicAlgorithm.php @@ -2,11 +2,11 @@ class ManhattanHeuristicAlgorithm implements IDistanceAlgorithm { - public function calculate(PathTile $from, PathTile $to) - { - return abs($from->x - $to->x) + abs($from->y - $to->y); - } + public function calculate(PathTile $from, PathTile $to) + { + return abs($from->x - $to->x) + abs($from->y - $to->y); + } - + } diff --git a/src/astarnavigator/algorithms/Pythagoras3D.php b/src/astarnavigator/algorithms/Pythagoras3D.php index aff091fe..c271923b 100644 --- a/src/astarnavigator/algorithms/Pythagoras3D.php +++ b/src/astarnavigator/algorithms/Pythagoras3D.php @@ -2,13 +2,13 @@ class Pythagoras3D implements IDistanceAlgorithm { - public function calculate(PathTile $from, PathTile $to) + public function calculate(PathTile $from, PathTile $to) { - if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){ - return Utils::distance_noroot($from->asVector(), $to->asVector()); - } - return 666; - } + if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){ + return Utils::distance_noroot($from->asVector(), $to->asVector()); + } + return 666; + } } diff --git a/src/astarnavigator/algorithms/PythagorasAlgorithm.php b/src/astarnavigator/algorithms/PythagorasAlgorithm.php index 609ac1d4..7a46f1b5 100644 --- a/src/astarnavigator/algorithms/PythagorasAlgorithm.php +++ b/src/astarnavigator/algorithms/PythagorasAlgorithm.php @@ -2,10 +2,10 @@ class PythagorasAlgorithm implements IDistanceAlgorithm { - public function calculate(PathTile $from, PathTile $to) - { - return sqrt(pow($to->x - $from->x, 2) + pow($to->y - $from->y, 2)); - } + public function calculate(PathTile $from, PathTile $to) + { + return sqrt(pow($to->x - $from->x, 2) + pow($to->y - $from->y, 2)); + } } diff --git a/src/astarnavigator/providers/DiagonalNeighborProvider.php b/src/astarnavigator/providers/DiagonalNeighborProvider.php index 7a0b7808..fa7c891e 100644 --- a/src/astarnavigator/providers/DiagonalNeighborProvider.php +++ b/src/astarnavigator/providers/DiagonalNeighborProvider.php @@ -1,17 +1,17 @@ addOffset($offset); - } - return $result; - } + private static $neighbors = array([ 0, -1 ], [ 1, 0 ], [ 0, 1 ], [ -1, 0 ], [ -1, -1 ], [ 1, -1 ], [ 1, 1 ], [ -1, 1 ]); + + public function getNeighbors(PathTile $tile) + { + $result = []; + foreach(self::$neighbors as $offset){ + $t = clone $tile; + $result[] = $t->addOffset($offset); + } + return $result; + } } diff --git a/src/astarnavigator/providers/EmptyBlockedProvider.php b/src/astarnavigator/providers/EmptyBlockedProvider.php index bf4a0a7e..87d84242 100644 --- a/src/astarnavigator/providers/EmptyBlockedProvider.php +++ b/src/astarnavigator/providers/EmptyBlockedProvider.php @@ -2,9 +2,9 @@ class EmptyBlockedProvider implements IBlockedProvider { - public function isBlocked(PathTile $tile) - { - return false; - } + public function isBlocked(PathTile $tile) + { + return false; + } } diff --git a/src/astarnavigator/providers/IBlockedProvider.php b/src/astarnavigator/providers/IBlockedProvider.php index 5b990f13..40adf01b 100644 --- a/src/astarnavigator/providers/IBlockedProvider.php +++ b/src/astarnavigator/providers/IBlockedProvider.php @@ -2,11 +2,11 @@ interface IBlockedProvider { - /** - * @param Tile $tile - * - * @return boolean - */ - public function isBlocked(PathTile $tile); + /** + * @param Tile $tile + * + * @return boolean + */ + public function isBlocked(PathTile $tile); } diff --git a/src/astarnavigator/providers/INeighborProvider.php b/src/astarnavigator/providers/INeighborProvider.php index 7ae008ac..95b9553e 100644 --- a/src/astarnavigator/providers/INeighborProvider.php +++ b/src/astarnavigator/providers/INeighborProvider.php @@ -2,6 +2,6 @@ interface INeighborProvider { - public function getNeighbors(PathTile $tile); + public function getNeighbors(PathTile $tile); } diff --git a/src/astarnavigator/providers/MCBlockedProvider.php b/src/astarnavigator/providers/MCBlockedProvider.php index 3afbffda..da3bfac1 100644 --- a/src/astarnavigator/providers/MCBlockedProvider.php +++ b/src/astarnavigator/providers/MCBlockedProvider.php @@ -3,14 +3,14 @@ class MCBlockedProvider implements IBlockedProvider { - public function isBlocked(PathTile $tile) + public function isBlocked(PathTile $tile) { - if($tile instanceof PathTileXYZ){ - $b = $tile->level->getBlockWithoutVector($tile->x, $tile->y, $tile->z); - return $b instanceof Block && $b->isSolid; - } - return false; - } + if($tile instanceof PathTileXYZ){ + $b = $tile->level->getBlockWithoutVector($tile->x, $tile->y, $tile->z); + return $b instanceof Block && $b->isSolid; + } + return false; + } } diff --git a/src/astarnavigator/providers/MCDiagonalProvider.php b/src/astarnavigator/providers/MCDiagonalProvider.php index 519b4877..c66be44b 100644 --- a/src/astarnavigator/providers/MCDiagonalProvider.php +++ b/src/astarnavigator/providers/MCDiagonalProvider.php @@ -2,21 +2,21 @@ class MCDiagonalProvider implements INeighborProvider { - private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ], [ -1, 0, -1 ], [ 1, 0, -1 ], [ 1, 0, 1 ], [ -1, 0, 1 ]); - public function getNeighbors(PathTile $tile) + private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ], [ -1, 0, -1 ], [ 1, 0, -1 ], [ 1, 0, 1 ], [ -1, 0, 1 ]); + public function getNeighbors(PathTile $tile) { - - if($tile instanceof PathTileXYZ){ - $result = []; - foreach(self::$neighbors as $offset){ - $t = clone $tile; - $result[] = $t->addOffset($offset); - } - return $result; - } - return []; - } + + if($tile instanceof PathTileXYZ){ + $result = []; + foreach(self::$neighbors as $offset){ + $t = clone $tile; + $result[] = $t->addOffset($offset); + } + return $result; + } + return []; + } - + } diff --git a/src/build/installer.sh b/src/build/installer.sh index e3540ff3..8c043ccb 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -14,46 +14,46 @@ rm bin.7z echo "["$(date +%k:%M)"] Downloading PHP..." arch=$(uname -m) if [[ $arch == x86_64* ]]; then - echo "X64 Architecture" - wget https://owouwu.ru/NC_bin.tar.gz > /dev/null + echo "X64 Architecture" + wget https://owouwu.ru/NC_bin.tar.gz > /dev/null tar -xvf NC_bin.tar.gz rm NC_bin.tar.gz elif [[ $arch == i*86 ]]; then - echo "X32 Architecture" - wget https://owouwu.ru/NC_bin.tar.gz > /dev/null + echo "X32 Architecture" + wget https://owouwu.ru/NC_bin.tar.gz > /dev/null tar -xvf NC_bin.tar.gz rm NC_bin.tar.gz elif [[ $arch == arm* ]] || [[ $arch = aarch* ]]; then - echo "ARM Architecture" - wget https://owouwu.ru/NCArm_bin.tar.gz > /dev/null + echo "ARM Architecture" + wget https://owouwu.ru/NCArm_bin.tar.gz > /dev/null tar -xvf NCArm_bin.tar.gz rm NCArm_bin.tar.gz fi if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then - OPCACHE_PATH="$(find $(pwd) -name opcache.so)" - XDEBUG_PATH="$(find $(pwd) -name xdebug.so)" - echo "" > "./bin/php5/bin/php.ini" - #UOPZ_PATH="$(find $(pwd) -name uopz.so)" - #echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini" - echo "zend_extension=\"$OPCACHE_PATH\"" >> "./bin/php5/bin/php.ini" - echo "zend_extension=\"$XDEBUG_PATH\"" >> "./bin/php5/bin/php.ini" - echo "opcache.enable=1" >> "./bin/php5/bin/php.ini" - echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini" - echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini" - echo "opcache.fast_shutdown=1" >> "./bin/php5/bin/php.ini" - echo "opcache.max_accelerated_files=4096" >> "./bin/php5/bin/php.ini" - echo "opcache.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini" - echo "opcache.memory_consumption=128" >> "./bin/php5/bin/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini" - echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini" - echo "short_open_tag=0" >> "./bin/php5/bin/php.ini" - echo "asp_tags=0" >> "./bin/php5/bin/php.ini" - echo "phar.readonly=0" >> "./bin/php5/bin/php.ini" - echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini" - echo "done" - alldone=yes + OPCACHE_PATH="$(find $(pwd) -name opcache.so)" + XDEBUG_PATH="$(find $(pwd) -name xdebug.so)" + echo "" > "./bin/php5/bin/php.ini" + #UOPZ_PATH="$(find $(pwd) -name uopz.so)" + #echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini" + echo "zend_extension=\"$OPCACHE_PATH\"" >> "./bin/php5/bin/php.ini" + echo "zend_extension=\"$XDEBUG_PATH\"" >> "./bin/php5/bin/php.ini" + echo "opcache.enable=1" >> "./bin/php5/bin/php.ini" + echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini" + echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini" + echo "opcache.fast_shutdown=1" >> "./bin/php5/bin/php.ini" + echo "opcache.max_accelerated_files=4096" >> "./bin/php5/bin/php.ini" + echo "opcache.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini" + echo "opcache.memory_consumption=128" >> "./bin/php5/bin/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini" + echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini" + echo "short_open_tag=0" >> "./bin/php5/bin/php.ini" + echo "asp_tags=0" >> "./bin/php5/bin/php.ini" + echo "phar.readonly=0" >> "./bin/php5/bin/php.ini" + echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini" + echo "done" + alldone=yes else - echo "Invalid PHP build detected" + echo "Invalid PHP build detected" fi echo "Done, starting..." echo "Wait >15 seconds..." diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 00615861..e52d67c8 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -28,12 +28,12 @@ mkdir -p $COMPILEDIR if [ "$COMPILE_LINUX_32BIT" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit - cd $COMPILEDIR/linux/32bit - - CFLAGS=-m32 march=i686 mtune=generic $SCRIPT - - cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ + mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit + cd $COMPILEDIR/linux/32bit + + CFLAGS=-m32 march=i686 mtune=generic $SCRIPT + + cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then exit 1 fi @@ -41,12 +41,12 @@ fi if [ "$COMPILE_LINUX_64BIT" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit - cd $COMPILEDIR/linux/64bit - - $SCRIPT - - cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ + mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit + cd $COMPILEDIR/linux/64bit + + $SCRIPT + + cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then exit 1 fi @@ -54,9 +54,9 @@ fi if [ "$COMPILE_MAC" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/mac - cd $COMPILEDIR/mac - + mkdir -p {$COMPILEDIR,$ARCHIVE}/mac + cd $COMPILEDIR/mac + curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null cd libtool-2.4.2 ./configure --prefix="$COMPILEDIR/mac/libtool" > /dev/null @@ -66,9 +66,9 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" - $SCRIPT mac curl - - cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/ + $SCRIPT mac curl + + cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/ if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then exit 1 fi @@ -76,12 +76,12 @@ fi if [ "$COMPILE_RPI" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi - cd $COMPILEDIR/rpi - - $SCRIPT rpi - - cp -r $COMPILEDIR/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/rpi/ + mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi + cd $COMPILEDIR/rpi + + $SCRIPT rpi + + cp -r $COMPILEDIR/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/rpi/ if [ ! -f $COMPILEDIR/rpi/bin/php5/bin/php ]; then exit 1 fi @@ -89,12 +89,12 @@ fi if [ "$CROSSCOMPILE_ANDROID_ARMV6" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6 - cd $COMPILEDIR/crosscompile/android-armv6 - - $SCRIPT crosscompile android-armv6 - - cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv6/ + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6 + cd $COMPILEDIR/crosscompile/android-armv6 + + $SCRIPT crosscompile android-armv6 + + cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv6/ if [ ! -f $COMPILEDIR/crosscompile/android-armv6/bin/php5/bin/php ]; then exit 1 fi @@ -102,12 +102,12 @@ fi if [ "$CROSSCOMPILE_ANDROID_ARMV7" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7 - cd $COMPILEDIR/crosscompile/android-armv7 - - $SCRIPT crosscompile android-armv7 - - cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv7/ + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7 + cd $COMPILEDIR/crosscompile/android-armv7 + + $SCRIPT crosscompile android-armv7 + + cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv7/ if [ ! -f $COMPILEDIR/crosscompile/android-armv7/bin/php5/bin/php ]; then exit 1 fi @@ -115,8 +115,8 @@ fi if [ "$CROSSCOMPILE_IOS_ARMV6" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6 - cd $COMPILEDIR/crosscompile/ios-armv6 + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6 + cd $COMPILEDIR/crosscompile/ios-armv6 curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null cd libtool-2.4.2 ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv6/libtool" > /dev/null @@ -126,9 +126,9 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize" - PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv6 - - cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/ + PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv6 + + cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/ if [ ! -f $COMPILEDIR/crosscompile/ios-armv6/bin/php5/bin/php ]; then exit 1 fi @@ -136,8 +136,8 @@ fi if [ "$CROSSCOMPILE_IOS_ARMV7" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7 - cd $COMPILEDIR/crosscompile/ios-armv7 + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7 + cd $COMPILEDIR/crosscompile/ios-armv7 curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null cd libtool-2.4.2 ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv7/libtool" > /dev/null @@ -147,9 +147,9 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize" - PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv7 - - cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/ + PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv7 + + cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/ if [ ! -f $COMPILEDIR/crosscompile/ios-armv7/bin/php5/bin/php ]; then exit 1 fi @@ -157,12 +157,12 @@ fi if [ "$CROSSCOMPILE_RPI" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi - cd $COMPILEDIR/crosscompile/rpi - - $SCRIPT crosscompile rpi - - cp -r $COMPILEDIR/crosscompile/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/rpi/ + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi + cd $COMPILEDIR/crosscompile/rpi + + $SCRIPT crosscompile rpi + + cp -r $COMPILEDIR/crosscompile/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/rpi/ if [ ! -f $COMPILEDIR/crosscompile/rpi/bin/php5/bin/php ]; then exit 1 fi @@ -170,12 +170,12 @@ fi if [ "$CROSSCOMPILE_MAC" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac - cd $COMPILEDIR/crosscompile/mac - - $SCRIPT crosscompile mac curl - - cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/ + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac + cd $COMPILEDIR/crosscompile/mac + + $SCRIPT crosscompile mac curl + + cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/ if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then exit 1 fi diff --git a/src/entity/Animal.php b/src/entity/Animal.php index 491be870..d06d9209 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -5,58 +5,58 @@ move methods */ abstract class Animal extends Creature implements Ageable, Breedable{ - public $parent; - public $inLove; //do NOT add it into metadata, it doesnt send it to player - public $age; - public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ - parent::__construct($level, $eid, $class, $type, $data); - $this->setAge(isset($data["Age"]) ? $data["Age"] : 0); - if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){ - $this->setAge(-24000); - } - $this->ai->addTask(new TaskTempt()); - } - + public $parent; + public $inLove; //do NOT add it into metadata, it doesnt send it to player + public $age; + public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ + parent::__construct($level, $eid, $class, $type, $data); + $this->setAge(isset($data["Age"]) ? $data["Age"] : 0); + if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){ + $this->setAge(-24000); + } + $this->ai->addTask(new TaskTempt()); + } + public function isBaby(){ return $this->getAge() < 0; } public function breed(){ - $c = $this->spawnChild(); - if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "child" => $c]) !== false){ - $c->parent = &$this; - $this->server->api->entity->spawnToAll($c); - } + $c = $this->spawnChild(); + if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "child" => $c]) !== false){ + $c->parent = &$this; + $this->server->api->entity->spawnToAll($c); + } } public function update(){ - parent::update(); - $age = $this->getAge() + 1; //100 - fast. debug, 1 - normal - if($age >= 0 && $this->isBaby()){ - $this->setAge($age); - $this->updateMetadata(); - }else{ - $this->setAge($age); - } + parent::update(); + $age = $this->getAge() + 1; //100 - fast. debug, 1 - normal + if($age >= 0 && $this->isBaby()){ + $this->setAge($age); + $this->updateMetadata(); + }else{ + $this->setAge($age); + } } public function getAge(){ - return $this->age; + return $this->age; } public function setAge($i){ - $this->age = $i; + $this->age = $i; } public function spawnChild() { - return $this->server->api->entity->add($this->level, $this->class, $this->type, [ - "x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1), - "y" => $this->y, - "z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1), - "IsBaby" => true, - "Age" => -24000, - ]); + return $this->server->api->entity->add($this->level, $this->class, $this->type, [ + "x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1), + "y" => $this->y, + "z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1), + "IsBaby" => true, + "Age" => -24000, + ]); } public function getMetadata(){ @@ -66,33 +66,33 @@ abstract class Animal extends Creature implements Ageable, Breedable{ } public function createSaveData(){ - $data = parent::createSaveData(); - $data["IsBaby"] = $this->isBaby(); - $data["Age"] = $this->getAge(); - return $data; + $data = parent::createSaveData(); + $data["IsBaby"] = $this->isBaby(); + $data["Age"] = $this->getAge(); + return $data; } public function isInLove(){ - return $this->inLove > 0; + return $this->inLove > 0; } public function interactWith(Entity $e, $action){ - if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ - $slot = $e->player->getHeldItem(); - if($this->isFood($slot->getID())){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1); - $this->inLove = 600; //600 ticks, original mehod from mcpe - return true; - } - } - parent::interactWith($e, $action); + if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ + $slot = $e->player->getHeldItem(); + if($this->isFood($slot->getID())){ + $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1); + $this->inLove = 600; //600 ticks, original mehod from mcpe + return true; + } + } + parent::interactWith($e, $action); } public function counterUpdate(){ - parent::counterUpdate(); - if($this->isInLove()){ - --$this->inLove; - } + parent::counterUpdate(); + if($this->isInLove()){ + --$this->inLove; + } } public function getDrops(){ diff --git a/src/entity/Creature.php b/src/entity/Creature.php index 490df76c..0619a9e5 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -25,30 +25,30 @@ abstract class Creature extends Living{ } public function update(){ - if($this->onGround){ - /*if($this->path === null && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){ - $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y, $this->z + mt_rand(-10, 10), $this->level)); - } - if($this->path != null && (is_array($this->path) && count($this->path) <= 0 || $this->currentIndex >= count($this->path))){ - $this->path = null; - $this->currentIndex = 0; - $this->currentNode = false; - }elseif($this->path != null && ($this->currentNode == false || $this->ai->mobController->moveTo($this->currentNode->x, $this->currentNode->y, $this->currentNode->z) === false)){ - $this->currentNode = $this->path[$this->currentIndex++]; - }*/ - } - parent::update(); - + if($this->onGround){ + /*if($this->path === null && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){ + $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y, $this->z + mt_rand(-10, 10), $this->level)); + } + if($this->path != null && (is_array($this->path) && count($this->path) <= 0 || $this->currentIndex >= count($this->path))){ + $this->path = null; + $this->currentIndex = 0; + $this->currentNode = false; + }elseif($this->path != null && ($this->currentNode == false || $this->ai->mobController->moveTo($this->currentNode->x, $this->currentNode->y, $this->currentNode->z) === false)){ + $this->currentNode = $this->path[$this->currentIndex++]; + }*/ + } + parent::update(); + } public function createSaveData(){ - $data = parent::createSaveData(); - $data["State"] = @$this->getState(); - return $data; + $data = parent::createSaveData(); + $data["State"] = @$this->getState(); + return $data; } public function getSpeedModifer(){ - return $this->speedModifer * ($this->inPanic ? 1.4 : 0.7); + return $this->speedModifer * ($this->inPanic ? 1.4 : 0.7); } public function spawn($player){ diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 85a24316..db574b0e 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -69,7 +69,7 @@ class Entity extends Position public $radius; public $inAction = false; public $hasKnockback; - + public $onGround; function __construct(Level $level, $eid, $class, $type = 0, $data = array()) @@ -624,7 +624,7 @@ class Entity extends Position break; } if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid && $this->isMoving()){ - $this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX); + $this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX); $this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ); $lastY = $this->speedY; $this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY); @@ -638,34 +638,34 @@ class Entity extends Position } if(!$support){ - for($z = $startZ; $z <= $endZ; ++ $z){ - for($x = $startX; $x <= $endX; ++ $x){ - $v = new Vector3($x, $y, $z); - $v1 = new Vector3($x, $yC, $z); - if($this->isSupport($v, $this->width)){ - $b = $this->level->getBlock($v); - if($b->isSolid === true){ - $support = true; - $isFlying = false; - break; - } elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){ - $isFlying = false; - } - } elseif($this->isSupport($v1, $this->width)){ - $b = $this->level->getBlock($v1); - if($b->isSolid === true){ - $support = true; - $isFlying = false; - break; - } elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){ - $isFlying = false; - } - } - } - if($support === true){ - break; - } - } + for($z = $startZ; $z <= $endZ; ++ $z){ + for($x = $startX; $x <= $endX; ++ $x){ + $v = new Vector3($x, $y, $z); + $v1 = new Vector3($x, $yC, $z); + if($this->isSupport($v, $this->width)){ + $b = $this->level->getBlock($v); + if($b->isSolid === true){ + $support = true; + $isFlying = false; + break; + } elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){ + $isFlying = false; + } + } elseif($this->isSupport($v1, $this->width)){ + $b = $this->level->getBlock($v1); + if($b->isSolid === true){ + $support = true; + $isFlying = false; + break; + } elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){ + $isFlying = false; + } + } + } + if($support === true){ + break; + } + } } if($this->speedX != 0){ $this->x += $this->speedX; diff --git a/src/entity/Living.php b/src/entity/Living.php index bb76611e..d4fc352a 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -1,21 +1,21 @@ target = false; - $this->ai = new EntityAI($this); - parent::__construct($level, $eid, $class, $type, $data); - $this->canBeAttacked = true; - $this->hasGravity = true; - $this->hasKnockback = true; - } - - public function update(){ - if($this->idleTime <= 0) { - $this->ai->updateTasks(); - } - parent::update(); - } - + public $target, $ai; + public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ + $this->target = false; + $this->ai = new EntityAI($this); + parent::__construct($level, $eid, $class, $type, $data); + $this->canBeAttacked = true; + $this->hasGravity = true; + $this->hasKnockback = true; + } + + public function update(){ + if($this->idleTime <= 0) { + $this->ai->updateTasks(); + } + parent::update(); + } + } diff --git a/src/entity/WalkingEntity.php b/src/entity/WalkingEntity.php index 29c3972a..592b2ff5 100644 --- a/src/entity/WalkingEntity.php +++ b/src/entity/WalkingEntity.php @@ -1,13 +1,13 @@ entity = $entity; - $this->tasks = []; - $this->mobController = new MobController($entity); - } - - /** - * Add a task for entity - * @param TaskBase $task - */ - public function addTask(TaskBase $task){ - console("[DEBUG] Adding new task...",true, true, 2); - $this->tasks[$task->__toString()] = $task; - } - /** - * - * @param mixed $id classname - * @return TaskBase | false - */ - public function getTask($id){ - return isset($this->tasks[$id]) ? $this->tasks[$id] : false; - } - - public function isStarted($id){ - $task = @$this->getTask($id); - return $task instanceof TaskBase && $task->isStarted; - } + /** + * @var MobController + */ + public $mobController; + /** + * @var Living + */ + public $entity; + + /** + * @var TaskBase[] + */ + protected $tasks; + + public $lastTask; + + public $counter = 0; + + public function __construct($entity){ + $this->entity = $entity; + $this->tasks = []; + $this->mobController = new MobController($entity); + } + + /** + * Add a task for entity + * @param TaskBase $task + */ + public function addTask(TaskBase $task){ + console("[DEBUG] Adding new task...",true, true, 2); + $this->tasks[$task->__toString()] = $task; + } + /** + * + * @param mixed $id classname + * @return TaskBase | false + */ + public function getTask($id){ + return isset($this->tasks[$id]) ? $this->tasks[$id] : false; + } + + public function isStarted($id){ + $task = @$this->getTask($id); + return $task instanceof TaskBase && $task->isStarted; + } - public function updateTasks(){ - if($this->counter % 3 != 0){ - return; - } - foreach($this->tasks as $t){ - if(!$t->isStarted && $t->canBeExecuted($this)){ - $t->isStarted = true; - $t->onStart($this); - } - if($t->isStarted){ - $t->onUpdate($this); - if($t->selfCounter <= 0){ - $t->isStarted = false; - $t->onEnd($this); - } - } - } - } - - public function __destruct(){ - unset($this->entity); - } - + public function updateTasks(){ + if($this->counter % 3 != 0){ + return; + } + foreach($this->tasks as $t){ + if(!$t->isStarted && $t->canBeExecuted($this)){ + $t->isStarted = true; + $t->onStart($this); + } + if($t->isStarted){ + $t->onUpdate($this); + if($t->selfCounter <= 0){ + $t->isStarted = false; + $t->onEnd($this); + } + } + } + } + + public function __destruct(){ + unset($this->entity); + } + } diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index 91413a3d..ada3fa2b 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -2,70 +2,70 @@ class MobController { - /** - * @var Entity - */ - public $entity; - - public function __construct($e){ - $this->entity = $e; - } - - public function moveNonInstant($x, $y, $z){ - if($x == 0 && $y == 0 && $z == 0){ - return false; //failed - } - - $ox = ($x > 0 ? 1 : ($x < 0 ? -1 : 0)); - $oy = ($y > 0 ? 1 : ($y < 0 ? -1 : 0)); - $oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0)); - $this->entity->moveEntityWithOffset($ox, $oy, $oz); - $this->faceEntity($this->entity->add($ox, $oy, $oz)); - $pk = new RotateHeadPacket(); //TODO headYaw auto update - $pk->eid = $this->entity->eid; - $pk->yaw = $this->entity->yaw; - $this->entity->server->api->player->broadcastPacket($this->entity->level->players, $pk); - return true; - } - - public function moveTo($x, $y, $z){ - return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z)); - } - - public function faceEntity(Vector3 $v){ - $d = $v->subtract($this->entity)->normalize(); - $dx = $d->x; - $dz = $d->z; - - $tan = $dz == 0 ? 0 : (90 - rad2deg($dx / $dz)); - $thetaOffset = $dz < 0 ? 90 : 270; - $this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan); - } - - public function lookOffset($x, $y, $z, $pitch = true){ - $tan = $z == 0 ? 0 : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/ - $thetaOffset = $z < 0 ? 90 : 270; - $calcYaw = $tan + $thetaOffset; - $this->entity->yaw = $calcYaw; - if($pitch){ - $diff = sqrt($x * $x + $z * $z); - $calcPitch = rad2deg(atan($y / $diff)); - $this->entity->pitch = $this->entity->type === MOB_CHICKEN ? -$calcPitch : $calcPitch; - } - - $this->entity->server->query("UPDATE entities SET pitch = ".$this->entity->pitch.", yaw = ".$this->entity->yaw." WHERE EID = ".$this->entity->eid.";"); - return true; - } - - public function lookOn($x, $y = 0, $z = 0, $pitch = true){ - if($x instanceof Vector3){ - return $this->lookOn($x->x, $x->y + $x->getEyeHeight(), $x->z, $pitch); - } - return $this->lookOffset($x - $this->entity->x, ($this->entity->y + $this->entity->height) - $y, $z - $this->entity->z, $pitch); - } - - public function __destruct(){ - unset($this->entity); - } + /** + * @var Entity + */ + public $entity; + + public function __construct($e){ + $this->entity = $e; + } + + public function moveNonInstant($x, $y, $z){ + if($x == 0 && $y == 0 && $z == 0){ + return false; //failed + } + + $ox = ($x > 0 ? 1 : ($x < 0 ? -1 : 0)); + $oy = ($y > 0 ? 1 : ($y < 0 ? -1 : 0)); + $oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0)); + $this->entity->moveEntityWithOffset($ox, $oy, $oz); + $this->faceEntity($this->entity->add($ox, $oy, $oz)); + $pk = new RotateHeadPacket(); //TODO headYaw auto update + $pk->eid = $this->entity->eid; + $pk->yaw = $this->entity->yaw; + $this->entity->server->api->player->broadcastPacket($this->entity->level->players, $pk); + return true; + } + + public function moveTo($x, $y, $z){ + return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z)); + } + + public function faceEntity(Vector3 $v){ + $d = $v->subtract($this->entity)->normalize(); + $dx = $d->x; + $dz = $d->z; + + $tan = $dz == 0 ? 0 : (90 - rad2deg($dx / $dz)); + $thetaOffset = $dz < 0 ? 90 : 270; + $this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan); + } + + public function lookOffset($x, $y, $z, $pitch = true){ + $tan = $z == 0 ? 0 : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/ + $thetaOffset = $z < 0 ? 90 : 270; + $calcYaw = $tan + $thetaOffset; + $this->entity->yaw = $calcYaw; + if($pitch){ + $diff = sqrt($x * $x + $z * $z); + $calcPitch = rad2deg(atan($y / $diff)); + $this->entity->pitch = $this->entity->type === MOB_CHICKEN ? -$calcPitch : $calcPitch; + } + + $this->entity->server->query("UPDATE entities SET pitch = ".$this->entity->pitch.", yaw = ".$this->entity->yaw." WHERE EID = ".$this->entity->eid.";"); + return true; + } + + public function lookOn($x, $y = 0, $z = 0, $pitch = true){ + if($x instanceof Vector3){ + return $this->lookOn($x->x, $x->y + $x->getEyeHeight(), $x->z, $pitch); + } + return $this->lookOffset($x - $this->entity->x, ($this->entity->y + $this->entity->height) - $y, $z - $this->entity->z, $pitch); + } + + public function __destruct(){ + unset($this->entity); + } } diff --git a/src/entity/ai/path/PathNavigator.php b/src/entity/ai/path/PathNavigator.php deleted file mode 100644 index ee0a36e3..00000000 --- a/src/entity/ai/path/PathNavigator.php +++ /dev/null @@ -1,73 +0,0 @@ -entity = $entity; - $this->currentPointIndex = 0; - } - - - public function reset(){ - $this->currentPointIndex = 0; - } - /** - * @param Node[] $path - */ - public function followPath($path){ //TODO remove local var - if(!$this->canContinue()){ - console($this->getTo); - console($this->entity); - $diffX = $this->getTo->x - $this->entity->x; - $diffY = 0; //todo ? - $diffZ = $this->getTo->z - $this->entity->z; - - $this->entity->moveEntityWithOffset(Utils::getSign($diffX), Utils::getSign($diffY), Utils::getSign($diffZ)); - return self::PATH_CANT_CONTINUE; - } - $index = $this->currentPointIndex++; - if($index >= count($path)){ - $this->onPathEnd(); - console("COMPLETED"); - return self::PATH_COMPLETED; - } - $node = $path[$index]; - - $this->getTo = $node; - - $diffX = $node->x - $this->entity->x; - $diffY = 0; //todo ? - $diffZ = $node->z - $this->entity->z; - - $this->entity->moveEntityWithOffset(Utils::getSign($diffX), Utils::getSign($diffY), Utils::getSign($diffZ)); - - return self::PATH_CONTINUE; - } - - public function canContinue(){ - return empty($this->getTo) || (floor($this->entity->x) == floor($this->getTo->x) && floor($this->entity->z) == floor($this->getTo->z)); - } - - public function onPathEnd(){ - $this->currentPointIndex = 0; - unset($this->getTo); - } - - public function testLook($pos){ - $x = $pos->x - $this->entity->x; - $y = $pos->y - $this->entity->y; - $z = $pos->z - $this->entity->z; - $this->entity->yaw = -atan2($this->entity->speedX, $this->entity->speedZ) * 180 / M_PI; - $this->entity->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt(pow($x, 2) + pow($z, 2)))); - $this->entity->server->query("UPDATE entities SET pitch = ".$this->entity->pitch.", yaw = ".$this->entity->yaw." WHERE EID = ".$this->entity->eid.";"); - } -} - diff --git a/src/entity/ai/tasks/TaskBase.php b/src/entity/ai/tasks/TaskBase.php index 9e4206f1..a1f00294 100644 --- a/src/entity/ai/tasks/TaskBase.php +++ b/src/entity/ai/tasks/TaskBase.php @@ -2,46 +2,46 @@ abstract class TaskBase { - public $isStarted = false, $selfCounter = 0; - - /** - * Executed when entity starts task. It is recommended to set counter here. - * @param EntityAI $ai - */ - abstract function onStart(EntityAI $ai); - - /** - * Every tick until counter will be not equal to 0. It is recommended to update value of counter here. - * @param EntityAI $ai - */ - abstract function onUpdate(EntityAI $ai); - - /** - * On task end. - * @param EntityAI $ai - */ - abstract function onEnd(EntityAI $ai); - - /** - * Can start the task - * @param EntityAI $ai - */ - abstract function canBeExecuted(EntityAI $ai); - - /** - * @return number ticks - */ - function getIdleTimeAfterEnd(){ - return 0; - } - - function reset(){ - $this->isStarted = false; - $this->selfCounter = 0; - } - - final function __toString(){ - return get_class($this); - } + public $isStarted = false, $selfCounter = 0; + + /** + * Executed when entity starts task. It is recommended to set counter here. + * @param EntityAI $ai + */ + abstract function onStart(EntityAI $ai); + + /** + * Every tick until counter will be not equal to 0. It is recommended to update value of counter here. + * @param EntityAI $ai + */ + abstract function onUpdate(EntityAI $ai); + + /** + * On task end. + * @param EntityAI $ai + */ + abstract function onEnd(EntityAI $ai); + + /** + * Can start the task + * @param EntityAI $ai + */ + abstract function canBeExecuted(EntityAI $ai); + + /** + * @return number ticks + */ + function getIdleTimeAfterEnd(){ + return 0; + } + + function reset(){ + $this->isStarted = false; + $this->selfCounter = 0; + } + + final function __toString(){ + return get_class($this); + } } diff --git a/src/entity/ai/tasks/TaskLookAround.php b/src/entity/ai/tasks/TaskLookAround.php index fa3066d5..9ebfbb37 100644 --- a/src/entity/ai/tasks/TaskLookAround.php +++ b/src/entity/ai/tasks/TaskLookAround.php @@ -2,35 +2,35 @@ class TaskLookAround extends TaskBase { - private $rotation; - public function onStart(EntityAI $ai) - { - $this->selfCounter = 1; - $this->rotation = mt_rand(-120, 120); - } + private $rotation; + public function onStart(EntityAI $ai) + { + $this->selfCounter = 1; + $this->rotation = mt_rand(-120, 120); + } - public function onEnd(EntityAI $ai) - { - $ai->entity->idleTime = mt_rand(20, 40); - } + public function onEnd(EntityAI $ai) + { + $ai->entity->idleTime = mt_rand(20, 40); + } - public function canBeExecuted(EntityAI $ai) - { - return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/ - } + public function canBeExecuted(EntityAI $ai) + { + return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/ + } - public function onUpdate(EntityAI $ai) - { - if($this->rotation === 0){ - $this->selfCounter = 0; - } - $v = min(Utils::getSign($this->rotation) * 10, $this->rotation); - $ai->entity->yaw += $v; - $pk = new RotateHeadPacket(); //TODO headYaw auto update - $pk->eid = $ai->entity->eid; - $pk->yaw = $ai->entity->yaw; - $ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk); - $this->rotation -= $v; - - } + public function onUpdate(EntityAI $ai) + { + if($this->rotation === 0){ + $this->selfCounter = 0; + } + $v = min(Utils::getSign($this->rotation) * 10, $this->rotation); + $ai->entity->yaw += $v; + $pk = new RotateHeadPacket(); //TODO headYaw auto update + $pk->eid = $ai->entity->eid; + $pk->yaw = $ai->entity->yaw; + $ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk); + $this->rotation -= $v; + + } } diff --git a/src/entity/ai/tasks/TaskRandomWalk.php b/src/entity/ai/tasks/TaskRandomWalk.php index 7c34938b..03b88661 100644 --- a/src/entity/ai/tasks/TaskRandomWalk.php +++ b/src/entity/ai/tasks/TaskRandomWalk.php @@ -2,39 +2,39 @@ class TaskRandomWalk extends TaskBase { - private $x, $z; - public function onStart(EntityAI $ai) - { - $this->x = mt_rand(-10, 10); - $this->z = mt_rand(-10, 10); - if($this->x === 0 && $this->z === 0){ - $this->reset(); - return false; - } - $this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z))); - } + private $x, $z; + public function onStart(EntityAI $ai) + { + $this->x = mt_rand(-10, 10); + $this->z = mt_rand(-10, 10); + if($this->x === 0 && $this->z === 0){ + $this->reset(); + return false; + } + $this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z))); + } - public function onEnd(EntityAI $ai) - { - $this->x = $this->z = 0; - } + public function onEnd(EntityAI $ai) + { + $this->x = $this->z = 0; + } - public function onUpdate(EntityAI $ai) - { - if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) { - return false; //TODO Better way: block movement - } - --$this->selfCounter; - $ai->mobController->moveNonInstant($this->x, 0, $this->z); - } + public function onUpdate(EntityAI $ai) + { + if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) { + return false; //TODO Better way: block movement + } + --$this->selfCounter; + $ai->mobController->moveNonInstant($this->x, 0, $this->z); + } - public function canBeExecuted(EntityAI $ai) - { - if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) { - return false; - } - return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0; - } + public function canBeExecuted(EntityAI $ai) + { + if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) { + return false; + } + return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0; + } - + } diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index ab11f461..a2f1a062 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -4,7 +4,7 @@ class Chicken extends Animal{ const TYPE = MOB_CHICKEN; public $timeUntilEgg; function __construct(Level $level, $eid, $class, $type = 0, $data = []){ - $this->timeUntilEgg = mt_rand(0,6000) + 6000; + $this->timeUntilEgg = mt_rand(0,6000) + 6000; parent::__construct($level, $eid, $class, $type, $data); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic"); $this->setName('Chicken'); @@ -17,11 +17,11 @@ class Chicken extends Animal{ } public function update(){ - parent::update(); - if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){ - $this->dropAnEgg(); - $this->timeUntilEgg = mt_rand(0,6000) + 6000; - } + parent::update(); + if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){ + $this->dropAnEgg(); + $this->timeUntilEgg = mt_rand(0,6000) + 6000; + } } public function dropAnEgg(){ diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 6637b8c3..2723153e 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -16,15 +16,15 @@ class Cow extends Animal{ } public function interactWith(Entity $e, $action){ - if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ - $slot = $e->player->getHeldItem(); - if($slot->getID() === BUCKET && $slot->getMetadata() === 0){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket - $e->player->addItem(BUCKET, 1, 1, true); - return true; - } - } - parent::interactWith($e, $action); + if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ + $slot = $e->player->getHeldItem(); + if($slot->getID() === BUCKET && $slot->getMetadata() === 0){ + $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket + $e->player->addItem(BUCKET, 1, 1, true); + return true; + } + } + parent::interactWith($e, $action); } public function getDrops(){ diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index eb849df4..a6d37f37 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -15,47 +15,47 @@ class Pig extends Animal implements Rideable{ * @return boolean */ public function isSaddled(){ - return (boolean) $this->getState(); + return (boolean) $this->getState(); } /** * @param boolean $value */ public function setSaddled($value = null){ - $this->setState($value === null ? !$this->getState() : $value); + $this->setState($value === null ? !$this->getState() : $value); } public function canRide($e){ - return $this->isSaddled() && !($this->linkedEntity instanceof Entity); + return $this->isSaddled() && !($this->linkedEntity instanceof Entity); } - public function interactWith(Entity $e, $action) - { - if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ - $slot = $e->player->getHeldItem(); - if($this->canRide($e)){ - $this->linkedEntity = $e; - $e->isRiding = true; - $this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE); - return true; - } - if($e->isRiding && $this->linkedEntity->eid = $e->eid){ - $this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE); - $e->isRiding = false; - $this->linkedEntity = 0; - return true; - } - if($slot->getID() === SADDLE){ - if(!$this->isSaddled()){ - $e->player->removeItem($slot->getID(), 0, 1); - $this->setSaddled(1); - } - return true; //avoid further interactions - } - - } - return parent::interactWith($e, $action); - } + public function interactWith(Entity $e, $action) + { + if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ + $slot = $e->player->getHeldItem(); + if($this->canRide($e)){ + $this->linkedEntity = $e; + $e->isRiding = true; + $this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE); + return true; + } + if($e->isRiding && $this->linkedEntity->eid = $e->eid){ + $this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE); + $e->isRiding = false; + $this->linkedEntity = 0; + return true; + } + if($slot->getID() === SADDLE){ + if(!$this->isSaddled()){ + $e->player->removeItem($slot->getID(), 0, 1); + $this->setSaddled(1); + } + return true; //avoid further interactions + } + + } + return parent::interactWith($e, $action); + } public function isFood($id){ return $id === POTATO || $id === CARROT || $id === BEETROOT; diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index 4272fd40..57f341bf 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -1,7 +1,7 @@ data["Color"]; - $data["Sheared"] = @$this->data["Sheared"]; - return $data; + $data = parent::createSaveData(); + $data["Color"] = @$this->data["Color"]; + $data["Sheared"] = @$this->data["Sheared"]; + return $data; } public function eatGrass(){ @@ -41,16 +41,16 @@ class Sheep extends Animal{ } public function setSheared($v = null){ - $this->data["Sheared"] = $v === null ? !$this->isSheared() : $v; - $this->updateMetadata(); + $this->data["Sheared"] = $v === null ? !$this->isSheared() : $v; + $this->updateMetadata(); } public function isSheared(){ - return $this->data["Sheared"]; + return $this->data["Sheared"]; } public function getColor(){ - return $this->data["Color"] & 16; //color === 16 -> color = 0, color === 17 -> color = 1 ... + return $this->data["Color"] & 16; //color === 16 -> color = 0, color === 17 -> color = 1 ... } public function getDrops(){ @@ -64,21 +64,21 @@ class Sheep extends Animal{ } public function interactWith(Entity $e, $action){ - if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ - $slot = $e->player->getHeldItem(); - if($slot->getID() === SHEARS){ - if(!$this->isSheared()){ - $this->setSheared(1); - $this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3))); + if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ + $slot = $e->player->getHeldItem(); + if($slot->getID() === SHEARS){ + if(!$this->isSheared()){ + $this->setSheared(1); + $this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3))); //$this->server->schedule(20, [$this, "eatGrass"]); - if($slot->getMetadata() >= $slot->getMaxDurability()){ - $this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); - } - } - return true; - } - } - return parent::interactWith($e, $action); + if($slot->getMetadata() >= $slot->getMaxDurability()){ + $this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); + } + } + return true; + } + } + return parent::interactWith($e, $action); } public function getMetadata(){ @@ -93,19 +93,19 @@ class Sheep extends Animal{ public function sheepColor(){ //a method from 0.8.1 $c = mt_rand(0,100); if($c <= 4){ - return 0xF; //white + return 0xF; //white } if($c <= 9){ - return 0x7; + return 0x7; } if($c <= 14){ - return 0x8; + return 0x8; } if($c <= 17){ - return 0xC; + return 0xC; } if(mt_rand(0, 500)){ - return 0x0; + return 0x0; } return 0x0; } diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index 57e2efef..9a39aed3 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -16,28 +16,28 @@ class Creeper extends Monster{ public function setIgnited($v = null){ - $this->setState($v === null ? !$this->getState() : $v); + $this->setState($v === null ? !$this->getState() : $v); } /** * @return boolean */ public function isIgnited(){ - return (boolean)$this->getState(); + return (boolean)$this->getState(); } public function interactWith(Entity $e, $action){ - if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ - $slot = $e->player->getHeldItem(); - if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){ - if($slot->useOn($e) and $slot->getMetadata() >= $slot->getMaxDurability()){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); - } - $this->ignite(); - return true; - } - } - return parent::interactWith($e, $action); + if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ + $slot = $e->player->getHeldItem(); + if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){ + if($slot->useOn($e) and $slot->getMetadata() >= $slot->getMaxDurability()){ + $e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); + } + $this->ignite(); + return true; + } + } + return parent::interactWith($e, $action); } public function ignite(){ @@ -55,16 +55,16 @@ class Creeper extends Monster{ parent::update(); } - public function explode() - { - if($this->closed){ - return false; - } - $this->setIgnited(0); - $explosion = new Explosion($this, 3); - $explosion->explode(); - $this->close(); - } + public function explode() + { + if($this->closed){ + return false; + } + $this->setIgnited(0); + $explosion = new Explosion($this, 3); + $explosion->explode(); + $this->close(); + } public function getDrops(){ return [ diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index 963923d8..c2e69d8c 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -11,28 +11,28 @@ class Skeleton extends Monster{ } public function updateBurning(){ - if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){ - return false; - } - - for($y = $this->y; $y < 129; $y++){ - $block = $this->level->getBlockWithoutVector($this->x, $y, $this->z); - if($block->isSolid){ - return false; - } - } - if($block->getID() === AIR){ - $this->fire = 160; //Value from 0.8.1 - $this->updateMetadata(); - return true; - }else{ - return false; - } + if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){ + return false; + } + + for($y = $this->y; $y < 129; $y++){ + $block = $this->level->getBlockWithoutVector($this->x, $y, $this->z); + if($block->isSolid){ + return false; + } + } + if($block->getID() === AIR){ + $this->fire = 160; //Value from 0.8.1 + $this->updateMetadata(); + return true; + }else{ + return false; + } } public function update(){ - $this->updateBurning(); - parent::update(); + $this->updateBurning(); + parent::update(); } public function getDrops(){ diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index 0a38a623..d802118f 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -11,28 +11,28 @@ class Zombie extends Monster{ } public function updateBurning(){ - if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){ - return false; - } - - for($y = $this->y; $y < 129; $y++){ - $block = $this->level->getBlockWithoutVector($this->x, $y, $this->z); - if($block->isSolid){ - return false; - } - } - if($block->getID() === AIR){ - $this->fire = 160; //Value from 0.8.1 - $this->updateMetadata(); - return true; - }else{ - return false; - } + if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){ + return false; + } + + for($y = $this->y; $y < 129; $y++){ + $block = $this->level->getBlockWithoutVector($this->x, $y, $this->z); + if($block->isSolid){ + return false; + } + } + if($block->getID() === AIR){ + $this->fire = 160; //Value from 0.8.1 + $this->updateMetadata(); + return true; + }else{ + return false; + } } public function update(){ - $this->updateBurning(); - parent::update(); + $this->updateBurning(); + parent::update(); } public function getDrops(){ diff --git a/src/entity/object/Arrow.php b/src/entity/object/Arrow.php index 6bec5987..7d85145c 100644 --- a/src/entity/object/Arrow.php +++ b/src/entity/object/Arrow.php @@ -20,23 +20,23 @@ class Arrow extends Projectile{ public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3 $f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2); - $d /= $f2; - $d1 /= $f2; - $d2 /= $f2; - $d += $this->random->nextGaussian() * 0.0075 * $f1; //0.0074999998323619366 replaced with 0.0075 - $d1 += $this->random->nextGaussian() * 0.0075 * $f1; - $d2 += $this->random->nextGaussian() * 0.0075 * $f1; - $d *= $f; - $d1 *= $f; - $d2 *= $f; - $this->speedX = $d; - $this->speedY = $d1; - $this->speedZ = $d2; - $f3 = sqrt($d * $d + $d2 * $d2); - $this->yaw = (atan2($d, $d2) * 180) / M_PI; - $this->pitch = (atan2($d1, $f3) * 180) / M_PI; + $d /= $f2; + $d1 /= $f2; + $d2 /= $f2; + $d += $this->random->nextGaussian() * 0.0075 * $f1; //0.0074999998323619366 replaced with 0.0075 + $d1 += $this->random->nextGaussian() * 0.0075 * $f1; + $d2 += $this->random->nextGaussian() * 0.0075 * $f1; + $d *= $f; + $d1 *= $f; + $d2 *= $f; + $this->speedX = $d; + $this->speedY = $d1; + $this->speedZ = $d2; + $f3 = sqrt($d * $d + $d2 * $d2); + $this->yaw = (atan2($d, $d2) * 180) / M_PI; + $this->pitch = (atan2($d1, $f3) * 180) / M_PI; $this->update(); - //TODO i guess? $ticksInGround = 0; + //TODO i guess? $ticksInGround = 0; } public function spawn($player){ diff --git a/src/entity/object/Minecart.php b/src/entity/object/Minecart.php index bb3f13c4..d4bc1915 100644 --- a/src/entity/object/Minecart.php +++ b/src/entity/object/Minecart.php @@ -49,24 +49,24 @@ class Minecart extends Vehicle{ } public function interactWith(Entity $e, $action){ - if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){ - $this->linkedEntity = $e; - $e->isRiding = true; - $this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE); - return true; - } - if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ - $this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE); - $this->linkedEntity = 0; - $e->isRiding = false; - return true; - } - parent::interactWith($e, $action); + if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){ + $this->linkedEntity = $e; + $e->isRiding = true; + $this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE); + return true; + } + if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ + $this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE); + $this->linkedEntity = 0; + $e->isRiding = false; + return true; + } + parent::interactWith($e, $action); } - public function canRide($e) - { - return !($this->linkedEntity instanceof Entity) && !$e->isRiding; - } + public function canRide($e) + { + return !($this->linkedEntity instanceof Entity) && !$e->isRiding; + } } diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index 85d3b46a..3f75d63a 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -20,11 +20,11 @@ class Painting extends Hanging{ } public function createSaveData(){ - $data = parent::createSaveData(); - - $data["Motive"] = $this->data["Motive"]; - - return $data; + $data = parent::createSaveData(); + + $data["Motive"] = $this->data["Motive"]; + + return $data; } public function spawn($player){ diff --git a/src/entity/object/TripodCamera.php b/src/entity/object/TripodCamera.php index d5752f7d..ec4baed9 100644 --- a/src/entity/object/TripodCamera.php +++ b/src/entity/object/TripodCamera.php @@ -9,10 +9,10 @@ class TripodCamera extends Entity{ } public function interactWith(Entity $e, $action){ - if($e->isPlayer() and $action === InteractPacket::ACTION_HOLD){ + if($e->isPlayer() and $action === InteractPacket::ACTION_HOLD){ //todo $this->server->schedule(40, [$this, "close"]); - } - parent::interactWith($e, $action); + } + parent::interactWith($e, $action); } } \ No newline at end of file diff --git a/src/material/Block.php b/src/material/Block.php index 6fa7cb21..37d3b0ee 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -175,7 +175,7 @@ abstract class Block extends Position{ return $this->id; } public function setMetadata($i){ - $this->meta = $i; + $this->meta = $i; } final public function getMetadata(){ return $this->meta & 0x0F; diff --git a/src/material/Item.php b/src/material/Item.php index f6817526..448c30c7 100755 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -153,7 +153,7 @@ class Item{ } public function isPickaxe(){ - return false; + return false; } public function getName(){ @@ -217,11 +217,11 @@ class Item{ public function useOn($object, $force = false){ if($force){ - if(($object instanceof Entity) and !$this->isSword()){ - $this->meta += 2; - }else{ - $this->meta++; - } + if(($object instanceof Entity) and !$this->isSword()){ + $this->meta += 2; + }else{ + $this->meta++; + } return true; } return false; @@ -303,7 +303,7 @@ class Item{ } public function getDamageAgainstOf($e){ - return Item::DEF_DAMAGE; + return Item::DEF_DAMAGE; } public function getDestroySpeed(Block $block, Player $player){ diff --git a/src/material/block/DoorBlock.php b/src/material/block/DoorBlock.php index 1b25b7a9..1218b3b3 100644 --- a/src/material/block/DoorBlock.php +++ b/src/material/block/DoorBlock.php @@ -1,27 +1,27 @@ isSolid = false; } - /** - * @param int $type - * - * @return bool|int - */ - public function onUpdate($type){ + /** + * @param int $type + * + * @return bool|int + */ + public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL){ if($this->getSide(0)->getID() === AIR){ //Replace with common break method $this->level->setBlock($this, new AirBlock(), false); - if($this->getID() == 64) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(324, 0, 1)); - elseif($this->getID() == 71) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(330, 0, 1)); + if($this->getID() == 64) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(324, 0, 1)); + elseif($this->getID() == 71) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(330, 0, 1)); if($this->getSide(1) instanceof DoorBlock){ $this->level->setBlock($this->getSide(1), new AirBlock(), false); } @@ -32,19 +32,19 @@ class DoorBlock extends TransparentBlock{ } - /** - * @param Item $item - * @param Player $player - * @param Block $block - * @param Block $target - * @param integer $face - * @param integer $fx - * @param integer $fy - * @param integer $fz - * - * @return boolean - */ - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + /** + * @param Item $item + * @param Player $player + * @param Block $block + * @param Block $target + * @param integer $face + * @param integer $fx + * @param integer $fy + * @param integer $fz + * + * @return boolean + */ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($face === 1){ $blockUp = $this->getSide(1); $blockDown = $this->getSide(0); @@ -73,13 +73,13 @@ class DoorBlock extends TransparentBlock{ return false; } - /** - * @param Item $item - * @param Player $player - * - * @return boolean - */ - public function onBreak(Item $item, Player $player){ + /** + * @param Item $item + * @param Player $player + * + * @return boolean + */ + public function onBreak(Item $item, Player $player){ if(($this->meta & 0x08) === 0x08){ $down = $this->getSide(0); if($down->getID() === $this->id){ @@ -95,13 +95,13 @@ class DoorBlock extends TransparentBlock{ return true; } - /** - * @param Item $item - * @param Player $player - * - * @return boolean - */ - public function onActivate(Item $item, Player $player){ + /** + * @param Item $item + * @param Player $player + * + * @return boolean + */ + public function onActivate(Item $item, Player $player){ if(($this->meta & 0x08) === 0x08){ //Top $down = $this->getSide(0); if($down->getID() === $this->id){ diff --git a/src/material/block/FallableBlock.php b/src/material/block/FallableBlock.php index f5a35766..856050fa 100644 --- a/src/material/block/FallableBlock.php +++ b/src/material/block/FallableBlock.php @@ -1,29 +1,29 @@ hasPhysics = true; } - /** - * @param Item $item - * @param Player $player - * @param Block $block - * @param Block $target - * @param int $face - * @param int $fx - * @param int $fy - * @param int $fz - * - * @return mixed - */ - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + /** + * @param Item $item + * @param Player $player + * @param Block $block + * @param Block $target + * @param int $face + * @param int $fx + * @param int $fy + * @param int $fz + * + * @return mixed + */ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $ret = $this->level->setBlock($this, $this, true, false, true); ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL); return $ret; diff --git a/src/material/block/FlowableBlock.php b/src/material/block/FlowableBlock.php index 9c97ee48..3c7aba58 100644 --- a/src/material/block/FlowableBlock.php +++ b/src/material/block/FlowableBlock.php @@ -1,12 +1,12 @@ isFlowable = true; $this->isFullBlock = false; diff --git a/src/material/block/GenericBlock.php b/src/material/block/GenericBlock.php index 62fffec2..7fbb33a2 100644 --- a/src/material/block/GenericBlock.php +++ b/src/material/block/GenericBlock.php @@ -2,57 +2,57 @@ class GenericBlock extends Block{ - /** - * @param int $id - * @param int $meta - * @param string $name - */ - public function __construct($id, $meta = 0, $name = "Unknown"){ + /** + * @param int $id + * @param int $meta + * @param string $name + */ + public function __construct($id, $meta = 0, $name = "Unknown"){ parent::__construct($id, $meta, $name); } - /** - * @param Item $item - * @param Player $player - * @param Block $block - * @param Block $target - * @param integer $face - * @param integer $fx - * @param integer $fy - * @param integer $fz - * - * @return mixed - */ - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + /** + * @param Item $item + * @param Player $player + * @param Block $block + * @param Block $target + * @param integer $face + * @param integer $fx + * @param integer $fy + * @param integer $fz + * + * @return mixed + */ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ return $this->level->setBlock($this, $this, true, false, true); } - /** - * @param Item $item - * @param Player $player - * - * @return boolean - */ - public function isBreakable(Item $item, Player $player){ + /** + * @param Item $item + * @param Player $player + * + * @return boolean + */ + public function isBreakable(Item $item, Player $player){ return ($this->breakable); } - /** - * @param Item $item - * @param Player $player - * - * @return mixed - */ - public function onBreak(Item $item, Player $player){ + /** + * @param Item $item + * @param Player $player + * + * @return mixed + */ + public function onBreak(Item $item, Player $player){ return $this->level->setBlock($this, new AirBlock(), true, false, true); } - /** - * @param integer $type - * - * @return boolean - */ - public function onUpdate($type){ + /** + * @param integer $type + * + * @return boolean + */ + public function onUpdate($type){ if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){ $down = $this->getSide(0); if($down->getID() === AIR or ($down instanceof LiquidBlock)){ @@ -73,13 +73,13 @@ class GenericBlock extends Block{ return false; } - /** - * @param Item $item - * @param Player $player - * - * @return boolean - */ - public function onActivate(Item $item, Player $player){ + /** + * @param Item $item + * @param Player $player + * + * @return boolean + */ + public function onActivate(Item $item, Player $player){ return $this->isActivable; } } \ No newline at end of file diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index ddc1d88e..96f7aeac 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -1,12 +1,12 @@ isLiquid = true; $this->breakable = false; diff --git a/src/material/block/SolidBlock.php b/src/material/block/SolidBlock.php index 30bc1876..72c45d2a 100644 --- a/src/material/block/SolidBlock.php +++ b/src/material/block/SolidBlock.php @@ -1,12 +1,12 @@ isSolid = true; $this->isFullBlock = true; diff --git a/src/material/block/StairBlock.php b/src/material/block/StairBlock.php index 66fc8fff..327a90ba 100644 --- a/src/material/block/StairBlock.php +++ b/src/material/block/StairBlock.php @@ -1,12 +1,12 @@ meta & 0x04) === 0x04){ $this->isFullBlock = true; @@ -16,19 +16,19 @@ class StairBlock extends TransparentBlock{ $this->hardness = 30; } - /** - * @param Item $item - * @param Player $player - * @param Block $block - * @param Block $target - * @param int $face - * @param int $fx - * @param int $fy - * @param int $fz - * - * @return bool|mixed - */ - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + /** + * @param Item $item + * @param Player $player + * @param Block $block + * @param Block $target + * @param int $face + * @param int $fx + * @param int $fy + * @param int $fz + * + * @return bool|mixed + */ + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $faces = array( 0 => 0, 1 => 2, @@ -43,13 +43,13 @@ class StairBlock extends TransparentBlock{ return true; } - /** - * @param Item $item - * @param Player $player - * - * @return array - */ - public function getDrops(Item $item, Player $player){ + /** + * @param Item $item + * @param Player $player + * + * @return array + */ + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ return array( array($this->id, 0, 1), diff --git a/src/material/block/TransparentBlock.php b/src/material/block/TransparentBlock.php index 9a8c6314..3c98046b 100644 --- a/src/material/block/TransparentBlock.php +++ b/src/material/block/TransparentBlock.php @@ -1,12 +1,12 @@ isActivable = false; $this->breakable = true; diff --git a/src/material/block/attachable/SignPost.php b/src/material/block/attachable/SignPost.php index b9b5ef5b..3dc7b5d6 100644 --- a/src/material/block/attachable/SignPost.php +++ b/src/material/block/attachable/SignPost.php @@ -1,14 +1,14 @@ 2, - 3 => 3, - 4 => 4, - 5 => 5, - ); - + + private $faces = array( + 2 => 2, + 3 => 3, + 4 => 4, + 5 => 5, + ); + public function __construct($meta = 0){ parent::__construct(SIGN_POST, $meta, "Sign Post"); $this->isSolid = false; @@ -17,13 +17,13 @@ class SignPostBlock extends TransparentBlock{ } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($target->isSolid && $face !== 0){ + if($target->isSolid && $face !== 0){ if(!isset($this->faces[$face])){ $this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F; $this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true); return true; }else{ - $this->meta = $this->faces[$face]; + $this->meta = $this->faces[$face]; $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta, true, false, true)); return true; } diff --git a/src/material/block/attachable/Trapdoor.php b/src/material/block/attachable/Trapdoor.php index 31ffb8ee..8124bb08 100644 --- a/src/material/block/attachable/Trapdoor.php +++ b/src/material/block/attachable/Trapdoor.php @@ -13,8 +13,8 @@ class TrapdoorBlock extends TransparentBlock{ } public function canAttachTo(Block $target){ - $id = $target->getID(); - return $id === SLAB || $id === GLOWSTONE || $id === SLAB || $id === WOOD_SLAB || (!$target->isTransparent || $target instanceof StairBlock); + $id = $target->getID(); + return $id === SLAB || $id === GLOWSTONE || $id === SLAB || $id === WOOD_SLAB || (!$target->isTransparent || $target instanceof StairBlock); } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/liquid/Lava.php b/src/material/block/liquid/Lava.php index a43f83a7..4c9af5f4 100644 --- a/src/material/block/liquid/Lava.php +++ b/src/material/block/liquid/Lava.php @@ -97,8 +97,8 @@ class LavaBlock extends LiquidBlock implements LightingBlock{ $tlevel = $sb->meta & 0x06; if($tlevel != 0x00){ for ($s = 0; $s <= 5; $s++) { - $ssb = $sb->getSide($s); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); + $ssb = $sb->getSide($s); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); } $this->level->setBlock($sb, new AirBlock(), false, false, true); } @@ -107,10 +107,10 @@ class LavaBlock extends LiquidBlock implements LightingBlock{ if($b instanceof LavaBlock){ $tlevel = $b->meta & 0x06; if($tlevel != 0x00){ - for ($s = 0; $s <= 5; $s++) { - $ssb = $sb->getSide($s); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); - } + for ($s = 0; $s <= 5; $s++) { + $ssb = $sb->getSide($s); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); + } $this->level->setBlock($b, new AirBlock(), false, false, true); } } diff --git a/src/material/block/liquid/Water.php b/src/material/block/liquid/Water.php index 2d766ae4..8d39e46d 100644 --- a/src/material/block/liquid/Water.php +++ b/src/material/block/liquid/Water.php @@ -1,126 +1,126 @@ hardness = 500; - } - - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $ret = $this->level->setBlock($this, $this, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); - return $ret; - } - - public function getSourceCount(){ - $count = 0; - for($side = 2; $side <= 5; ++$side){ - if( $this->getSide($side) instanceof WaterBlock ){ - $b = $this->getSide($side); - $level = $b->meta & 0x07; - if($level == 0x00){ - $count++; - } - } - } - return $count; - } - - public function checkLava(){ - for($side = 0; $side <= 5; ++$side){ - if($side == 1){ - continue; - } - $b = $this->getSide($side); - if($b instanceof LavaBlock){ - $level = $b->meta & 0x07; - if($level == 0x00){ - $this->level->setBlock($b, new ObsidianBlock(), false, false, true); - }else{ - $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); - } - return true; - } - } - return false; - } - - public function getFrom(){ - for($side = 0; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - $tlevel = $b->meta & 0x07; - $level = $this->meta & 0x07; - if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ - return $b; - } - } - } - return null; - } - - public function onUpdate($type){ - //return false; - $newId = $this->id; - $level = $this->meta & 0x07; - if($type !== BLOCK_UPDATE_NORMAL){ - return false; - } - - $this->checkLava(); - - $falling = $this->meta >> 3; - $down = $this->getSide(0); - - $from = $this->getFrom(); - //Has Source or Its Source - if($from !== null || $level == 0x00){ - if($down instanceof AirBlock || $down instanceof WaterBlock){ - $this->level->setBlock($down, new WaterBlock(0x00), false, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); - }elseif($level !== 0x07){{ - for($side = 2; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - if( $this->getSourceCount() >= 2 && $level != 0x00){ - $this->level->setBlock($this, new WaterBlock(0), false, false, true); - } - }elseif($b->isFlowable === true){ - $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); - } - } - } - } - }else{ - //Extend Remove for Left Waters - for($side = 2; $side <= 5; ++$side){ - $sb = $this->getSide($side); - if($sb instanceof WaterBlock){ - $tlevel = $sb->meta & 0x07; - if($tlevel != 0x00){ - for ($s = 0; $s <= 5; $s++) { - $ssb = $sb->getSide($s); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); - } - $this->level->setBlock($sb, new AirBlock(), false, false, true); - } - } - $b = $this->getSide(0)->getSide($side); - if($b instanceof WaterBlock){ - $tlevel = $b->meta & 0x07; - if($tlevel != 0x00){ - for ($s = 0; $s <= 5; $s++) { - $ssb = $sb->getSide($s); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); - } - $this->level->setBlock($b, new AirBlock(), false, false, true); - } - } - //ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); - } - $this->level->setBlock($this, new AirBlock(), false, false, true); - } - return false; - } + public function __construct($meta = 0){ + parent::__construct(WATER, $meta, "Water"); + $this->hardness = 500; + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $ret = $this->level->setBlock($this, $this, true, false, true); + ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); + return $ret; + } + + public function getSourceCount(){ + $count = 0; + for($side = 2; $side <= 5; ++$side){ + if( $this->getSide($side) instanceof WaterBlock ){ + $b = $this->getSide($side); + $level = $b->meta & 0x07; + if($level == 0x00){ + $count++; + } + } + } + return $count; + } + + public function checkLava(){ + for($side = 0; $side <= 5; ++$side){ + if($side == 1){ + continue; + } + $b = $this->getSide($side); + if($b instanceof LavaBlock){ + $level = $b->meta & 0x07; + if($level == 0x00){ + $this->level->setBlock($b, new ObsidianBlock(), false, false, true); + }else{ + $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); + } + return true; + } + } + return false; + } + + public function getFrom(){ + for($side = 0; $side <= 5; ++$side){ + $b = $this->getSide($side); + if($b instanceof WaterBlock){ + $tlevel = $b->meta & 0x07; + $level = $this->meta & 0x07; + if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ + return $b; + } + } + } + return null; + } + + public function onUpdate($type){ + //return false; + $newId = $this->id; + $level = $this->meta & 0x07; + if($type !== BLOCK_UPDATE_NORMAL){ + return false; + } + + $this->checkLava(); + + $falling = $this->meta >> 3; + $down = $this->getSide(0); + + $from = $this->getFrom(); + //Has Source or Its Source + if($from !== null || $level == 0x00){ + if($down instanceof AirBlock || $down instanceof WaterBlock){ + $this->level->setBlock($down, new WaterBlock(0x00), false, false, true); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); + }elseif($level !== 0x07){{ + for($side = 2; $side <= 5; ++$side){ + $b = $this->getSide($side); + if($b instanceof WaterBlock){ + if( $this->getSourceCount() >= 2 && $level != 0x00){ + $this->level->setBlock($this, new WaterBlock(0), false, false, true); + } + }elseif($b->isFlowable === true){ + $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); + } + } + } + } + }else{ + //Extend Remove for Left Waters + for($side = 2; $side <= 5; ++$side){ + $sb = $this->getSide($side); + if($sb instanceof WaterBlock){ + $tlevel = $sb->meta & 0x07; + if($tlevel != 0x00){ + for ($s = 0; $s <= 5; $s++) { + $ssb = $sb->getSide($s); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); + } + $this->level->setBlock($sb, new AirBlock(), false, false, true); + } + } + $b = $this->getSide(0)->getSide($side); + if($b instanceof WaterBlock){ + $tlevel = $b->meta & 0x07; + if($tlevel != 0x00){ + for ($s = 0; $s <= 5; $s++) { + $ssb = $sb->getSide($s); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); + } + $this->level->setBlock($b, new AirBlock(), false, false, true); + } + } + //ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); + } + $this->level->setBlock($this, new AirBlock(), false, false, true); + } + return false; + } } \ No newline at end of file diff --git a/src/material/block/misc/NetherReactor.php b/src/material/block/misc/NetherReactor.php index ff860c0f..eb016eae 100644 --- a/src/material/block/misc/NetherReactor.php +++ b/src/material/block/misc/NetherReactor.php @@ -49,12 +49,12 @@ class NetherReactorBlock extends SolidBlock{ } public function getDrops(Item $item, Player $player){ - if($item->getPickaxeLevel() >= 1){ - return array( - [DIAMOND, 0, 3], - [IRON_INGOT, 0, 6], - ); - } + if($item->getPickaxeLevel() >= 1){ + return array( + [DIAMOND, 0, 3], + [IRON_INGOT, 0, 6], + ); + } } private function decay($x, $y, $z, $aOne, $aTwo, $aThree, $bOne, $bTwo, $bThree, $cOne, $cTwo, $cThree) { diff --git a/src/material/block/nonfull/FenceGate.php b/src/material/block/nonfull/FenceGate.php index a493b6a9..b62533cc 100644 --- a/src/material/block/nonfull/FenceGate.php +++ b/src/material/block/nonfull/FenceGate.php @@ -28,7 +28,7 @@ class FenceGateBlock extends TransparentBlock{ ); } public function onActivate(Item $item, Player $player){ - $this->meta ^= 0x04; + $this->meta ^= 0x04; $this->level->setBlock($this, $this, true, false, true); $players = ServerAPI::request()->api->player->getAll($this->level); unset($players[$player->CID]); diff --git a/src/material/block/nonfull/Rail.php b/src/material/block/nonfull/Rail.php index 2ffafd91..ca34b1bc 100644 --- a/src/material/block/nonfull/Rail.php +++ b/src/material/block/nonfull/Rail.php @@ -2,7 +2,7 @@ class RailBlock extends FlowableBlock{ public function __construct($meta = 0){ - parent::__construct(RAIL, $meta, "Rail"); + parent::__construct(RAIL, $meta, "Rail"); $this->hardness = 0.7; $this->isFullBlock = false; $this->isSolid = false; @@ -11,25 +11,25 @@ class RailBlock extends FlowableBlock{ public static $shouldconnectrails = false; private function isRailBlock($id){ - return $id === RAIL || $id === POWERED_RAIL; - } + return $id === RAIL || $id === POWERED_RAIL; + } private function isValidRailMeta($meta){ - return !($meta < 0 || $meta > 10); - } + return !($meta < 0 || $meta > 10); + } private function canConnectRail($block) { - if(!($block instanceof RailBlock)) return null; - if($this->distanceSquared($block) > 2) return null; - $result = $this->checkRail($this); - if(count($result) === 2) return null; - return $result; - } + if(!($block instanceof RailBlock)) return null; + if($this->distanceSquared($block) > 2) return null; + $result = $this->checkRail($this); + if(count($result) === 2) return null; + return $result; + } private function checkRail($rail){//fixed - if(!($rail instanceof RailBlock)) return null; - $damage = $rail->meta; - if ($damage < 0 || $damage > 10) return null; + if(!($rail instanceof RailBlock)) return null; + $damage = $rail->meta; + if ($damage < 0 || $damage > 10) return null; $delta = array( array(array(0, 1), array(0, -1)), array(array(1, 0), array(-1, 0)), @@ -44,70 +44,70 @@ class RailBlock extends FlowableBlock{ array(array(-1, 0), array(0, -1)), array(array(0, -1), array(1, 0)) ); - $deltaY = array(0, 1, -1); - $blocks = $delta[$damage]; - $connected = array(); + $deltaY = array(0, 1, -1); + $blocks = $delta[$damage]; + $connected = array(); - foreach($deltaY as $y){ - $v3 = new Vector3( - $rail->getFloorX() + $blocks[0][0], - $rail->getFloorY() + $y, - $rail->getFloorZ() + $blocks[0][1] - ); - $railBlock = $rail->level->getBlock($v3); - $idToConnect = $railBlock->getID(); - $metaToConnect = $railBlock->getMetadata(); - if (!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue; - $xDiff = $this->getFloorX() - $v3->getFloorX(); - $zDiff = $this->getFloorZ() - $v3->getFloorZ(); - foreach($blocks as $xz) { - if($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue; - $connected[] = $v3; - } - } - foreach($deltaY as $y){ - $v3 = new Vector3( - $rail->getFloorX() + $blocks[1][0], - $rail->getFloorY() + $y, - $rail->getFloorZ() + $blocks[1][1] - ); - $railBlock = $rail->level->getBlock($v3); - $idToConnect = $railBlock->getID(); - $metaToConnect = $railBlock->getMetadata(); - if(!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue; - $xDiff = $this->getFloorX() - $v3->getFloorX(); - $zDiff = $this->getFloorZ() - $v3->getFloorZ(); - foreach($blocks as $xz){ - if ($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue; - $connected[] = $v3; - } - } - return $connected; - } + foreach($deltaY as $y){ + $v3 = new Vector3( + $rail->getFloorX() + $blocks[0][0], + $rail->getFloorY() + $y, + $rail->getFloorZ() + $blocks[0][1] + ); + $railBlock = $rail->level->getBlock($v3); + $idToConnect = $railBlock->getID(); + $metaToConnect = $railBlock->getMetadata(); + if (!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue; + $xDiff = $this->getFloorX() - $v3->getFloorX(); + $zDiff = $this->getFloorZ() - $v3->getFloorZ(); + foreach($blocks as $xz) { + if($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue; + $connected[] = $v3; + } + } + foreach($deltaY as $y){ + $v3 = new Vector3( + $rail->getFloorX() + $blocks[1][0], + $rail->getFloorY() + $y, + $rail->getFloorZ() + $blocks[1][1] + ); + $railBlock = $rail->level->getBlock($v3); + $idToConnect = $railBlock->getID(); + $metaToConnect = $railBlock->getMetadata(); + if(!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue; + $xDiff = $this->getFloorX() - $v3->getFloorX(); + $zDiff = $this->getFloorZ() - $v3->getFloorZ(); + foreach($blocks as $xz){ + if ($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue; + $connected[] = $v3; + } + } + return $connected; + } private function connectRail($rail){ - $connected = $this->canConnectRail($rail); - if ($connected === null || count($connected) === 0) return; - if(count($connected) === 1){ - $v3 = $connected[0]->subtract($this); - $this->meta = ($v3->y !== 1) ? ($v3->x === 0 ? 0 : 1) : (int) ($v3->z === 0 ? ($v3->x / -2) + 2.5 : ($v3->z / 2) + 4.5); - }elseif(count(connected) === 2){ - $subtract = array(new Vector3(0, 0, 0),new Vector3(0, 0, 0)); - for ($i = 0; $i < count($connected); $i++) { - $subtract[$i] = $connected[$i]->subtract($this); - } - if (abs($subtract[0]->x) === abs($subtract[1]->z) && abs($subtract[1]->x) === abs($subtract[0]->z)){ - $v3 = $connected[0]->subtract($this)->add($connected[1]->subtract($this)); - $this->meta = $v3->x === 1 ? ($v3->z === 1 ? 6 : 9) : ($v3->z === 1 ? 7 : 8); - }elseif ($subtract[0]->y === 1 || $subtract[1]->y === 1){ - $v3 = $subtract[0]->y === 1 ? $subtract[0] : $subtract[1]; - $this->meta = $v3->x === 0 ? ($v3->z === -1 ? 4 : 5) : ($v3->x === 1 ? 2 : 3); - }else{ - $this->meta = $subtract[0]->x === 0 ? 0 : 1; - } - } - $this->level->setBlock($rail, new RailBlock($this->meta), true, true); - } + $connected = $this->canConnectRail($rail); + if ($connected === null || count($connected) === 0) return; + if(count($connected) === 1){ + $v3 = $connected[0]->subtract($this); + $this->meta = ($v3->y !== 1) ? ($v3->x === 0 ? 0 : 1) : (int) ($v3->z === 0 ? ($v3->x / -2) + 2.5 : ($v3->z / 2) + 4.5); + }elseif(count(connected) === 2){ + $subtract = array(new Vector3(0, 0, 0),new Vector3(0, 0, 0)); + for ($i = 0; $i < count($connected); $i++) { + $subtract[$i] = $connected[$i]->subtract($this); + } + if (abs($subtract[0]->x) === abs($subtract[1]->z) && abs($subtract[1]->x) === abs($subtract[0]->z)){ + $v3 = $connected[0]->subtract($this)->add($connected[1]->subtract($this)); + $this->meta = $v3->x === 1 ? ($v3->z === 1 ? 6 : 9) : ($v3->z === 1 ? 7 : 8); + }elseif ($subtract[0]->y === 1 || $subtract[1]->y === 1){ + $v3 = $subtract[0]->y === 1 ? $subtract[0] : $subtract[1]; + $this->meta = $v3->x === 0 ? ($v3->z === -1 ? 4 : 5) : ($v3->x === 1 ? 2 : 3); + }else{ + $this->meta = $subtract[0]->x === 0 ? 0 : 1; + } + } + $this->level->setBlock($rail, new RailBlock($this->meta), true, true); + } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); diff --git a/src/material/block/plant/Beetroot.php b/src/material/block/plant/Beetroot.php index d72bac13..034cdeeb 100644 --- a/src/material/block/plant/Beetroot.php +++ b/src/material/block/plant/Beetroot.php @@ -59,9 +59,9 @@ class BeetrootBlock extends FlowableBlock{ $drops[] = array(BEETROOT, 0, 1); } for($i = 0; $i < 3; ++$i){ - if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7 - $drops[] = array(BEETROOT_SEEDS, 0, 1); - } + if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7 + $drops[] = array(BEETROOT_SEEDS, 0, 1); + } } return $drops; } diff --git a/src/material/block/plant/Carrot.php b/src/material/block/plant/Carrot.php index 04f8e637..95bc3452 100644 --- a/src/material/block/plant/Carrot.php +++ b/src/material/block/plant/Carrot.php @@ -60,7 +60,7 @@ class CarrotBlock extends FlowableBlock{ } for($i = 0; $i < 3; ++$i){ if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7 - $drops[] = array(CARROT, 0, 1); + $drops[] = array(CARROT, 0, 1); } } return $drops; diff --git a/src/material/block/plant/TallGrass.php b/src/material/block/plant/TallGrass.php index e624f485..6c959713 100644 --- a/src/material/block/plant/TallGrass.php +++ b/src/material/block/plant/TallGrass.php @@ -17,7 +17,7 @@ class TallGrassBlock extends FlowableBlock{ if($type === BLOCK_UPDATE_NORMAL){ if($this->getSide(0)->isTransparent === true){//Replace with common break method $this->level->setBlock($this, new AirBlock(), false, false, true); - if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(WHEAT_SEEDS)); + if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(WHEAT_SEEDS)); return BLOCK_UPDATE_NORMAL; } } diff --git a/src/material/block/plant/Wheat.php b/src/material/block/plant/Wheat.php index 51f166e5..5dbc36e2 100644 --- a/src/material/block/plant/Wheat.php +++ b/src/material/block/plant/Wheat.php @@ -60,11 +60,11 @@ class WheatBlock extends FlowableBlock{ $drops[] = array(WHEAT, 0, 1); $drops[] = array(WHEAT_SEEDS, 0, mt_rand(0, 3)); }else{ - for($i = 0; $i < 3; ++$i){ - if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7 - $drops[] = array(WHEAT_SEEDS, 0, 1); - } - } + for($i = 0; $i < 3; ++$i){ + if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7 + $drops[] = array(WHEAT_SEEDS, 0, 1); + } + } } return $drops; diff --git a/src/material/block/solid/Dirt.php b/src/material/block/solid/Dirt.php index 976db4a8..d1782057 100644 --- a/src/material/block/solid/Dirt.php +++ b/src/material/block/solid/Dirt.php @@ -40,7 +40,7 @@ class DirtBlock extends SolidBlock{ $x = $this->x; $y = $this->y; $z = $this->z; - + if($this->getBlockID($x+1, $y, $z+1) == 2) return true; if($this->getBlockID($x+1, $y, $z) == 2) return true; if($this->getBlockID($x+1, $y, $z-1) == 2) return true; diff --git a/src/material/block/solid/DoubleSlab.php b/src/material/block/solid/DoubleSlab.php index 054f1fe3..4000199f 100755 --- a/src/material/block/solid/DoubleSlab.php +++ b/src/material/block/solid/DoubleSlab.php @@ -11,7 +11,7 @@ class DoubleSlabBlock extends SolidBlock{ 4 => "Brick", 5 => "Stone Brick", 6 => "Quartz", - 7 => "Smooth Stone", + 7 => "Smooth Stone", ); $this->name = "Double " . $names[$this->meta & 0x07] . " Slab"; $this->hardness = 30; diff --git a/src/material/block/solid/LitPumpkin.php b/src/material/block/solid/LitPumpkin.php index e77ba29f..870e87bc 100644 --- a/src/material/block/solid/LitPumpkin.php +++ b/src/material/block/solid/LitPumpkin.php @@ -10,15 +10,15 @@ class LitPumpkinBlock extends SolidBlock implements LightingBlock{ return 15; } - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $faces = array( - 0 => 1, - 1 => 2, - 2 => 3, - 3 => 0, - ); - $this->meta = $faces[$player->entity->getDirection()]; - $this->level->setBlock($block, $this, true, false, true); - return true; - } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $faces = array( + 0 => 1, + 1 => 2, + 2 => 3, + 3 => 0, + ); + $this->meta = $faces[$player->entity->getDirection()]; + $this->level->setBlock($block, $this, true, false, true); + return true; + } } \ No newline at end of file diff --git a/src/material/item/base/ItemAxe.php b/src/material/item/base/ItemAxe.php index ab5985dd..be8d41f6 100644 --- a/src/material/item/base/ItemAxe.php +++ b/src/material/item/base/ItemAxe.php @@ -2,10 +2,10 @@ abstract class ItemAxe extends ItemTool { - public function isAxe(){ - return true; - } - - + public function isAxe(){ + return true; + } + + } diff --git a/src/material/item/base/ItemHoe.php b/src/material/item/base/ItemHoe.php index 306aa2d9..b9ea33be 100644 --- a/src/material/item/base/ItemHoe.php +++ b/src/material/item/base/ItemHoe.php @@ -2,17 +2,17 @@ abstract class ItemHoe extends ItemTool { - public function isHoe(){ - return true; - } - - public function useOn($object, $force = false){ - if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){ - $this->meta++; - return true; - }else{ - return parent::useOn($object, $force); - } - } + public function isHoe(){ + return true; + } + + public function useOn($object, $force = false){ + if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){ + $this->meta++; + return true; + }else{ + return parent::useOn($object, $force); + } + } } diff --git a/src/material/item/base/ItemPickaxe.php b/src/material/item/base/ItemPickaxe.php index 0bfa441f..ad5c05ae 100644 --- a/src/material/item/base/ItemPickaxe.php +++ b/src/material/item/base/ItemPickaxe.php @@ -2,12 +2,12 @@ abstract class ItemPickaxe extends ItemTool { - public function isTool(){ - return true; - } - - public function isPickaxe(){ - return true; - } + public function isTool(){ + return true; + } + + public function isPickaxe(){ + return true; + } } diff --git a/src/material/item/base/ItemShovel.php b/src/material/item/base/ItemShovel.php index 63b7a867..225f4fa3 100644 --- a/src/material/item/base/ItemShovel.php +++ b/src/material/item/base/ItemShovel.php @@ -2,8 +2,8 @@ class ItemShovel extends ItemTool { - public function isShovel(){ - return true; - } + public function isShovel(){ + return true; + } } diff --git a/src/material/item/base/ItemSword.php b/src/material/item/base/ItemSword.php index 3b42cafb..ab2ddc0a 100644 --- a/src/material/item/base/ItemSword.php +++ b/src/material/item/base/ItemSword.php @@ -3,8 +3,8 @@ abstract class ItemSword extends ItemTool { - public function isSword(){ - return true; - } + public function isSword(){ + return true; + } } diff --git a/src/material/item/base/ItemTool.php b/src/material/item/base/ItemTool.php index 46343433..3ba90125 100644 --- a/src/material/item/base/ItemTool.php +++ b/src/material/item/base/ItemTool.php @@ -2,16 +2,16 @@ abstract class ItemTool extends Item { - public function isTool(){ - return true; - } - public function useOn($object, $force = false){ - if(($object instanceof Entity) and !$this->isSword()){ - $this->meta += 2; - }else{ - $this->meta++; - } - return true; - } + public function isTool(){ + return true; + } + public function useOn($object, $force = false){ + if(($object instanceof Entity) and !$this->isSword()){ + $this->meta += 2; + }else{ + $this->meta++; + } + return true; + } } diff --git a/src/material/item/generic/Painting.php b/src/material/item/generic/Painting.php index 5ddd915f..9be8dc4d 100644 --- a/src/material/item/generic/Painting.php +++ b/src/material/item/generic/Painting.php @@ -29,7 +29,7 @@ class PaintingItem extends Item{ array("Flaming Skull", 4, 4), ); private static $direction = array(2, 0, 1, 3); - private static $right = array(4, 5, 3, 2); + private static $right = array(4, 5, 3, 2); 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){ @@ -56,17 +56,17 @@ class PaintingItem extends Item{ for($y = 0; $y <= $motive[2]; $y++){ if ($target->getSide(PaintingItem::$right[$face - 2], $x)->isTransparent || $target->getSide(1, $y)->isTransparent || $block->getSide(PaintingItem::$right[$face - 2], $x)->isSolid || $block->getSide(1, $y)->isSolid) { - $valid = false; + $valid = false; break; - } + } } if(!$valid){ break; } } if ($valid) { - $validMotives[] = $motive; - } + $validMotives[] = $motive; + } } $motive = $validMotives[array_rand($validMotives)]; $data = array( diff --git a/src/material/item/generic/SignItem.php b/src/material/item/generic/SignItem.php index 226f38ef..66527ce0 100644 --- a/src/material/item/generic/SignItem.php +++ b/src/material/item/generic/SignItem.php @@ -2,7 +2,7 @@ class SignItem extends Item{ public function __construct($meta = 0, $count = 1){ - parent::__construct(SIGN, 0, $count, "Sign"); + parent::__construct(SIGN, 0, $count, "Sign"); $this->block = BlockAPI::get(SIGN_POST); $this->maxStackSize = 16; } diff --git a/src/material/item/generic/SpawnEgg.php b/src/material/item/generic/SpawnEgg.php index 32382ad8..3aac8d9c 100644 --- a/src/material/item/generic/SpawnEgg.php +++ b/src/material/item/generic/SpawnEgg.php @@ -8,18 +8,18 @@ class SpawnEggItem extends Item{ } public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $ageable = $this->meta === MOB_CHICKEN || $this->meta === MOB_COW || $this->meta === MOB_SHEEP || $this->meta === MOB_PIG; - $data = array( - "x" => $block->x + 0.5, - "y" => $block->y, - "z" => $block->z + 0.5, - "IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0 - ); - $e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); - ServerAPI::request()->api->entity->spawnToAll($e); - if(($player->gamemode & 0x01) === 0){ - -- $this->count; - } - return true; + $ageable = $this->meta === MOB_CHICKEN || $this->meta === MOB_COW || $this->meta === MOB_SHEEP || $this->meta === MOB_PIG; + $data = array( + "x" => $block->x + 0.5, + "y" => $block->y, + "z" => $block->z + 0.5, + "IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0 + ); + $e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); + ServerAPI::request()->api->entity->spawnToAll($e); + if(($player->gamemode & 0x01) === 0){ + -- $this->count; + } + return true; } } \ No newline at end of file diff --git a/src/material/item/tool/DiamondAxe.php b/src/material/item/tool/DiamondAxe.php index 67b648ff..7cb03b24 100644 --- a/src/material/item/tool/DiamondAxe.php +++ b/src/material/item/tool/DiamondAxe.php @@ -6,6 +6,6 @@ class DiamondAxeItem extends ItemAxe{ } public function getDamageAgainstOf($e){ - return 6; + return 6; } } \ No newline at end of file diff --git a/src/material/item/tool/DiamondPickaxe.php b/src/material/item/tool/DiamondPickaxe.php index 1177d0e6..b90fc882 100644 --- a/src/material/item/tool/DiamondPickaxe.php +++ b/src/material/item/tool/DiamondPickaxe.php @@ -6,6 +6,6 @@ class DiamondPickaxeItem extends ItemPickaxe{ } public function getDamageAgainstOf($e){ - return 5; + return 5; } } \ No newline at end of file diff --git a/src/material/item/tool/DiamondShovel.php b/src/material/item/tool/DiamondShovel.php index 1154cf2e..9bb4a95b 100644 --- a/src/material/item/tool/DiamondShovel.php +++ b/src/material/item/tool/DiamondShovel.php @@ -5,6 +5,6 @@ class DiamondShovelItem extends ItemShovel{ parent::__construct(DIAMOND_SHOVEL, $meta, $count, "Diamond Shovel"); } public function getDamageAgainstOf($e){ - return 4; + return 4; } } \ No newline at end of file diff --git a/src/material/item/tool/DiamondSword.php b/src/material/item/tool/DiamondSword.php index 64df8e5b..40e4ad4d 100644 --- a/src/material/item/tool/DiamondSword.php +++ b/src/material/item/tool/DiamondSword.php @@ -4,9 +4,9 @@ class DiamondSwordItem extends ItemSword{ public function __construct($meta = 0, $count = 1){ parent::__construct(DIAMOND_SWORD, $meta, $count, "Diamond Sword"); } - public function getDamageAgainstOf($e) - { - return 7; - } + public function getDamageAgainstOf($e) + { + return 7; + } } \ No newline at end of file diff --git a/src/material/item/tool/FlintSteel.php b/src/material/item/tool/FlintSteel.php index 2689eba6..91a4ac14 100644 --- a/src/material/item/tool/FlintSteel.php +++ b/src/material/item/tool/FlintSteel.php @@ -21,11 +21,11 @@ class FlintSteelItem extends ItemTool{ } public function useOn($object, $force = false){ - if(($object instanceof Creeper) and $this->id === FLINT_STEEL){ - $this->meta++; - return true; - }else{ - return parent::useOn($object, $force); - } + if(($object instanceof Creeper) and $this->id === FLINT_STEEL){ + $this->meta++; + return true; + }else{ + return parent::useOn($object, $force); + } } } \ No newline at end of file diff --git a/src/material/item/tool/GoldenAxe.php b/src/material/item/tool/GoldenAxe.php index b2eb771f..0bf1e57e 100755 --- a/src/material/item/tool/GoldenAxe.php +++ b/src/material/item/tool/GoldenAxe.php @@ -5,6 +5,6 @@ class GoldenAxeItem extends ItemAxe{ parent::__construct(GOLDEN_AXE, $meta, $count, "Golden Axe"); } public function getDamageAgainstOf($e){ - return 3; + return 3; } } \ No newline at end of file diff --git a/src/material/item/tool/GoldenPickaxe.php b/src/material/item/tool/GoldenPickaxe.php index dd0705ab..7f0b2cb6 100755 --- a/src/material/item/tool/GoldenPickaxe.php +++ b/src/material/item/tool/GoldenPickaxe.php @@ -6,6 +6,6 @@ class GoldenPickaxeItem extends ItemPickaxe{ } public function getDamageAgainstOf($e){ - return 2; + return 2; } } \ No newline at end of file diff --git a/src/material/item/tool/GoldenSword.php b/src/material/item/tool/GoldenSword.php index a56eb511..c7793bfc 100755 --- a/src/material/item/tool/GoldenSword.php +++ b/src/material/item/tool/GoldenSword.php @@ -4,9 +4,9 @@ class GoldenSwordItem extends ItemSword{ public function __construct($meta = 0, $count = 1){ parent::__construct(GOLDEN_SWORD, $meta, $count, "Golden Sword"); } - public function getDamageAgainstOf($e) - { - return 4; - } + public function getDamageAgainstOf($e) + { + return 4; + } } \ No newline at end of file diff --git a/src/material/item/tool/IronAxe.php b/src/material/item/tool/IronAxe.php index c37daf7e..d8c5dc86 100644 --- a/src/material/item/tool/IronAxe.php +++ b/src/material/item/tool/IronAxe.php @@ -6,6 +6,6 @@ class IronAxeItem extends ItemAxe{ } public function getDamageAgainstOf($e){ - return 5; + return 5; } } \ No newline at end of file diff --git a/src/material/item/tool/IronSword.php b/src/material/item/tool/IronSword.php index 484bcf0f..5da4ff73 100755 --- a/src/material/item/tool/IronSword.php +++ b/src/material/item/tool/IronSword.php @@ -5,6 +5,6 @@ class IronSwordItem extends ItemSword{ parent::__construct(IRON_SWORD, $meta, $count, "Iron Sword"); } public function getDamageAgainstOf($e){ - return 6; + return 6; } } \ No newline at end of file diff --git a/src/material/item/tool/Shears.php b/src/material/item/tool/Shears.php index 65b3150a..059ede72 100755 --- a/src/material/item/tool/Shears.php +++ b/src/material/item/tool/Shears.php @@ -6,10 +6,10 @@ class ShearsItem extends ItemTool{ } public function useOn($object, $force = false){ - if(($object instanceof Sheep) and $this->id === SHEARS){ - $this->meta++; - return true; - } - parent::useOn($object, $force); + if(($object instanceof Sheep) and $this->id === SHEARS){ + $this->meta++; + return true; + } + parent::useOn($object, $force); } } \ No newline at end of file diff --git a/src/material/item/tool/StoneShovel.php b/src/material/item/tool/StoneShovel.php index 42fef521..c23e42c6 100644 --- a/src/material/item/tool/StoneShovel.php +++ b/src/material/item/tool/StoneShovel.php @@ -4,9 +4,9 @@ class StoneShovelItem extends ItemShovel{ public function __construct($meta = 0, $count = 1){ parent::__construct(STONE_SHOVEL, $meta, $count, "Stone Shovel"); } - + public function getDamageAgainstOf($e){ - return 2; + return 2; } } \ No newline at end of file diff --git a/src/material/item/tool/WoodenPickaxe.php b/src/material/item/tool/WoodenPickaxe.php index d956cfc4..a6f9fd21 100644 --- a/src/material/item/tool/WoodenPickaxe.php +++ b/src/material/item/tool/WoodenPickaxe.php @@ -6,6 +6,6 @@ class WoodenPickaxeItem extends ItemPickaxe{ } public function getDamageAgainstOf($e){ - return 2; + return 2; } } diff --git a/src/math/AxisAlignedBB.php b/src/math/AxisAlignedBB.php index e5ed19c6..f32b77ea 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.php @@ -180,7 +180,7 @@ class AxisAlignedBB{ return $z; } - + public function intersectsWith(AxisAlignedBB $bb){ if($bb->maxX > $this->minX and $bb->minX < $this->maxX){ if($bb->maxY > $this->minY and $bb->minY < $this->maxY){ @@ -192,14 +192,14 @@ class AxisAlignedBB{ } public function isXYZInside($x, $y, $z){ - if($x <= $this->minX or $x >= $this->maxX){ - return false; - } - if($y <= $this->minY or $y >= $this->maxY){ - return false; - } - - return $z > $this->minZ and $z < $this->maxZ; + if($x <= $this->minX or $x >= $this->maxX){ + return false; + } + if($y <= $this->minY or $y >= $this->maxY){ + return false; + } + + return $z > $this->minZ and $z < $this->maxZ; } public function isVectorInside(Vector3 $vector){ if($vector->x <= $this->minX or $vector->x >= $this->maxX){ @@ -306,7 +306,7 @@ class AxisAlignedBB{ } public function __toString(){ - return "min: {$this->minX}, {$this->minY}, {$this->minZ}, max: {$this->maxX}, {$this->maxY}, {$this->maxZ}"; + return "min: {$this->minX}, {$this->minY}, {$this->minZ}, max: {$this->maxX}, {$this->maxY}, {$this->maxZ}"; } } \ No newline at end of file diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 0469cfdf..e472039a 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -17,11 +17,11 @@ class Vector3{ } public function copy(){ - return new Vector3($this->x, $this->y, $this->z); + return new Vector3($this->x, $this->y, $this->z); } public function toArray(){ - return ["x" => $this->x, "y" => $this->y, "z" => $this->z]; + return ["x" => $this->x, "y" => $this->y, "z" => $this->z]; } public function getFloorX(){ @@ -72,7 +72,7 @@ class Vector3{ if(($x instanceof Vector3) === true){ return $this->subtract($x->x, $x->y, $x->z); }else{ - return new Vector3($this->x - $x, $this->y - $y, $this->z - $z); + return new Vector3($this->x - $x, $this->y - $y, $this->z - $z); } } @@ -178,9 +178,9 @@ class Vector3{ $this->x * $v->y - $this->y * $v->x ); } - + public static function fromArray($arr){ - return new Vector3($arr[0], $arr[1], $arr[2]); + return new Vector3($arr[0], $arr[1], $arr[2]); } public function __toString(){ diff --git a/src/math/Vector3Pos.php b/src/math/Vector3Pos.php index 5201f709..7edf577f 100644 --- a/src/math/Vector3Pos.php +++ b/src/math/Vector3Pos.php @@ -1,20 +1,20 @@ x = &$x; - $this->y = &$y; - $this->z = &$z; - } - - public function addToValues($v){ - $this->x += $v->x; - $this->y += $v->y; - $this->z += $v->z; - return $this; - } - + public $x, $y, $z; + + public function __construct(&$x, &$y, &$z){ + $this->x = &$x; + $this->y = &$y; + $this->z = &$z; + } + + public function addToValues($v){ + $this->x += $v->x; + $this->y += $v->y; + $this->z += $v->z; + return $this; + } + } diff --git a/src/network/protocol/packet/AnimatePacket.php b/src/network/protocol/packet/AnimatePacket.php index c743db66..6a33b5e5 100644 --- a/src/network/protocol/packet/AnimatePacket.php +++ b/src/network/protocol/packet/AnimatePacket.php @@ -1,11 +1,11 @@ unk1 = $this->getFloat(); - $this->unk2 = $this->getFloat(); - $this->unk3 = $this->getByte(); - $this->unk4 = $this->getByte(); - } - + public function decode() + { + $this->unk1 = $this->getFloat(); + $this->unk2 = $this->getFloat(); + $this->unk3 = $this->getByte(); + $this->unk4 = $this->getByte(); + } + } diff --git a/src/network/protocol/packet/SetEntityLinkPacket.php b/src/network/protocol/packet/SetEntityLinkPacket.php index 2b83f7ba..87917853 100644 --- a/src/network/protocol/packet/SetEntityLinkPacket.php +++ b/src/network/protocol/packet/SetEntityLinkPacket.php @@ -4,22 +4,22 @@ Lets hope it will work */ class SetEntityLinkPacket extends RakNetDataPacket{ - const TYPE_REMOVE = 0; - const TYPE_RIDE = 1; - const TYPE_PASSENGER = 2; + const TYPE_REMOVE = 0; + const TYPE_RIDE = 1; + const TYPE_PASSENGER = 2; - public $rider; - public $riding; - public $type; - public function decode() { + public $rider; + public $riding; + public $type; + public function decode() { - } - public function encode() { - $this->reset(); - $this->putLong($this->rider); - $this->putLong($this->riding); - $this->putByte($this->type); - } + } + public function encode() { + $this->reset(); + $this->putLong($this->rider); + $this->putLong($this->riding); + $this->putByte($this->type); + } public function pid(){ diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index fbfab4f5..c87bef72 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -326,8 +326,8 @@ class RakNetParser{ case ProtocolInfo::SET_ENTITY_LINK_PACKET: $data = new SetEntityLinkPacket; case ProtocolInfo::PLAYER_INPUT_PACKET: - $data = new PlayerInputPacket; - break; + $data = new PlayerInputPacket; + break; default: $data = new UnknownPacket(); $data->packetID = $pid; diff --git a/src/phar/PharUtils.php b/src/phar/PharUtils.php index 674fdb53..6aaea321 100644 --- a/src/phar/PharUtils.php +++ b/src/phar/PharUtils.php @@ -26,7 +26,7 @@ class PharUtils{ } public static function getNameSpaceClass($content){ - return trim(substr(str_replace("/", "\\", $content), 0, -4)); + return trim(substr(str_replace("/", "\\", $content), 0, -4)); } diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 27b3373b..d5787dc2 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -317,9 +317,9 @@ class PMFLevel extends PMF{ return true; } private function report(){ - console("[ERROR] A weird error in PMFLevel just happeneed. Values: "); - var_dump(func_get_args()); - console("[NOTICE] If you see this message, you should send the log with error to the devs."); + console("[ERROR] A weird error in PMFLevel just happeneed. Values: "); + var_dump(func_get_args()); + console("[NOTICE] If you see this message, you should send the log with error to the devs."); } public function getBlockID($x, $y, $z){ if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){ @@ -333,9 +333,9 @@ class PMFLevel extends PMF{ $aZ = $z - ($Z << 4); $aY = $y - ($Y << 4); if(is_array($this->chunks) && is_array($this->chunks[$index]) && is_string($this->chunks[$index][$Y])){ - $b = ord($this->chunks[$index][$Y][(int) ($aY + ($aX << 5) + ($aZ << 9))]); + $b = ord($this->chunks[$index][$Y][(int) ($aY + ($aX << 5) + ($aZ << 9))]); }else{ //php8 fix - $b = 0; + $b = 0; } return $b; @@ -378,9 +378,9 @@ class PMFLevel extends PMF{ $aZ = $z - ($Z << 4); $aY = $y - ($Y << 4); if(is_array($this->chunks) && is_array($this->chunks[$index]) && is_string($this->chunks[$index][$Y])){ - $m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]); + $m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]); }else{ //php8 fix - $m = 0; + $m = 0; } if(($y & 1) === 0){ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 6aed9834..0d09d4ee 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -41,16 +41,16 @@ class Utils{ public static function wrapAngleTo180_float($par0) { - $par0 %= 360.0; - return $par0 >= 180 ? $par0 - 360 : ($par0 + 360); + $par0 %= 360.0; + return $par0 >= 180 ? $par0 - 360 : ($par0 + 360); } public static function getSign($v){ - return $v > 0 ? 1 : ($v < 0 ? -1 : 0); + return $v > 0 ? 1 : ($v < 0 ? -1 : 0); } public static function clampDegrees($v){ - return floor(($v % 360 + 360) % 360); + return floor(($v % 360 + 360) % 360); } public static function hasEmoji($s){ @@ -70,23 +70,23 @@ class Utils{ } public function xrange($start, $limit, $step = 1) { - if ($start <= $limit) { - if ($step <= 0) { - throw new LogicException('Step must be positive'); - } - - for ($i = $start; $i <= $limit; $i += $step) { - yield $i; - } - } else { - if ($step >= 0) { - throw new LogicException('Step must be negative'); - } - - for ($i = $start; $i >= $limit; $i += $step) { - yield $i; - } - } + if ($start <= $limit) { + if ($step <= 0) { + throw new LogicException('Step must be positive'); + } + + for ($i = $start; $i <= $limit; $i += $step) { + yield $i; + } + } else { + if ($step >= 0) { + throw new LogicException('Step must be negative'); + } + + for ($i = $start; $i >= $limit; $i += $step) { + yield $i; + } + } } public static function getUniqueID($raw = false, $extra = ""){ @@ -573,22 +573,22 @@ class Utils{ * @return number */ public static function distance($pos1, $pos2){ - if($pos1 instanceof Vector3){ - $pos1 = $pos1->toArray(); - } - if($pos2 instanceof Vector3){ - $pos2 = $pos2->toArray(); - } + if($pos1 instanceof Vector3){ + $pos1 = $pos1->toArray(); + } + if($pos2 instanceof Vector3){ + $pos2 = $pos2->toArray(); + } return sqrt(pow($pos1["x"] - $pos2["x"], 2) + pow($pos1["y"] - $pos2["y"], 2) + pow($pos1["z"] - $pos2["z"], 2)); } - + public static function angle3D($pos1, $pos2){ - if($pos1 instanceof Vector3){ - $pos1 = $pos1->toArray(); - } - if($pos2 instanceof Vector3){ - $pos2 = $pos2->toArray(); - } + if($pos1 instanceof Vector3){ + $pos1 = $pos1->toArray(); + } + if($pos2 instanceof Vector3){ + $pos2 = $pos2->toArray(); + } $X = $pos1["x"] - $pos2["x"]; $Z = $pos1["z"] - $pos2["z"]; $dXZ = sqrt(pow($X, 2) + pow($Z, 2)); @@ -718,24 +718,24 @@ class Utils{ if(!is_float($value)){ if(strval($value[0] == null ? '' : $value[0]) === "-"){ $negative = true; - $value = bcadd($value, "1"); - if(strval($value[0]) === "-"){ - $value = substr($value, 1); - } - }else{ - $negative = false; - } - while(bccomp($value, "0", 0) > 0){ - $temp = bcmod($value, "16777216"); - $x = chr($temp >> 16) . chr($temp >> 8) . chr($temp) . $x; - $value = bcdiv($value, "16777216", 0); - } - $x = str_pad(substr($x, 0, 8), 8, "\x00", STR_PAD_LEFT); - if($negative === true){ - $x = ~$x; - } - return $x; - } + $value = bcadd($value, "1"); + if(strval($value[0]) === "-"){ + $value = substr($value, 1); + } + }else{ + $negative = false; + } + while(bccomp($value, "0", 0) > 0){ + $temp = bcmod($value, "16777216"); + $x = chr($temp >> 16) . chr($temp >> 8) . chr($temp) . $x; + $value = bcdiv($value, "16777216", 0); + } + $x = str_pad(substr($x, 0, 8), 8, "\x00", STR_PAD_LEFT); + if($negative === true){ + $x = ~$x; + } + return $x; + } } } diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 749a3ac8..fb0e2502 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -54,7 +54,7 @@ class Explosion{ $blockID = $this->level->level->getBlockID($vBlock->x, $vBlock->y, $vBlock->z); $blockMeta = $this->level->level->getBlockDamage($vBlock->x, $vBlock->y, $vBlock->z); if($blockID > 0){ - $block = BlockAPI::get($blockID, $blockMeta); + $block = BlockAPI::get($blockID, $blockMeta); $block->x = $vBlock->x; $block->y = $vBlock->y; $block->z = $vBlock->z; diff --git a/src/world/Level.php b/src/world/Level.php index 4e3adc0c..0b46fc56 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -1,15 +1,15 @@ minX); - $x1 = ceil($aABB->maxX); - $y0 = floor($aABB->minY); - $y1 = round($aABB->maxY); - $z0 = floor($aABB->minZ); - $z1 = ceil($aABB->maxZ); - $x0 = $x0 < 0 ? 0 : $x0; - $y0 = $y0 < 0 ? 0 : $y0; - $z0 = $z0 < 0 ? 0 : $z0; - $x1 = $x1 > 256 ? 256 : $x1; - $y1 = $y1 > 128 ? 128 : $y1; - $z1 = $z1 > 256 ? 256 : $z1; - - for($x = $x0; $x < $x1; ++$x) { - for($y = $y0; $y < $y1; ++$y) { - for($z = $z0; $z < $z1; ++$z) { - $b = $this->getBlockWithoutVector($x, $y, $z); - if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid) { - $aABBs[] = $b->boundingBox; - } - } - } - } - - return $aABBs; + $aABBs = []; + $x0 = floor($aABB->minX); + $x1 = ceil($aABB->maxX); + $y0 = floor($aABB->minY); + $y1 = round($aABB->maxY); + $z0 = floor($aABB->minZ); + $z1 = ceil($aABB->maxZ); + $x0 = $x0 < 0 ? 0 : $x0; + $y0 = $y0 < 0 ? 0 : $y0; + $z0 = $z0 < 0 ? 0 : $z0; + $x1 = $x1 > 256 ? 256 : $x1; + $y1 = $y1 > 128 ? 128 : $y1; + $z1 = $z1 > 256 ? 256 : $z1; + + for($x = $x0; $x < $x1; ++$x) { + for($y = $y0; $y < $y1; ++$y) { + for($z = $z0; $z < $z1; ++$z) { + $b = $this->getBlockWithoutVector($x, $y, $z); + if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid) { + $aABBs[] = $b->boundingBox; + } + } + } + } + + return $aABBs; } public function __destruct(){ @@ -80,7 +80,7 @@ class Level{ } unset($this->mobSpawner->level); } - + public function save($force = false, $extra = true){ if(!isset($this->level)){ return false; @@ -92,9 +92,9 @@ class Level{ if($extra !== false){ $entities = []; foreach($this->entityList as $entity){ - if($entity instanceof Entity){ - $entities[] = $entity->createSaveData(); - } + if($entity instanceof Entity){ + $entities[] = $entity->createSaveData(); + } } $this->entities->setAll($entities); $this->entities->save(); @@ -149,20 +149,20 @@ class Level{ public function freeChunk($X, $Z, Player $player){ unset($this->usedChunks[$X . "." . $Z][$player->CID]); } - + public function checkCollisionsFor(Entity $e){ - if($e->level->getName() != $this->getName()){ - return false; //not the same world - } - foreach($this->entityList as $e1){ - if($e->boundingBox->intersectsWith($e1->boundingBox) && $e1->isCollidable){ - $e->onCollideWith($e1); - $e1->onCollideWith($e); - } - } + if($e->level->getName() != $this->getName()){ + return false; //not the same world + } + foreach($this->entityList as $e1){ + if($e->boundingBox->intersectsWith($e1->boundingBox) && $e1->isCollidable){ + $e->onCollideWith($e1); + $e1->onCollideWith($e); + } + } } public function isObstructed($e){ - + } public function checkThings(){ @@ -258,19 +258,19 @@ class Level{ } return $ret; } - + public function onTick(PocketMinecraftServer $server){ - //$ents = $server->api->entity->getAll($this); - if(!$this->stopTime) ++$this->time; - foreach($this->entityList as $k => $e){ - if(!($e instanceof Entity)){ - unset($this->entityList[$k]); - continue; - } - if($e->needsUpdate){ - $e->update(); - } - } + //$ents = $server->api->entity->getAll($this); + if(!$this->stopTime) ++$this->time; + foreach($this->entityList as $k => $e){ + if(!($e instanceof Entity)){ + unset($this->entityList[$k]); + continue; + } + if($e->needsUpdate){ + $e->update(); + } + } if(Entity::$updateOnTick && $server->ticks % 40 === 0){ //40 ticks delay $this->mobSpawner->handle(); @@ -445,7 +445,7 @@ class Level{ } return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this); } - + /** * @param number $x * @param number $y @@ -454,8 +454,8 @@ class Level{ */ public function getBlockWithoutVector($x, $y, $z){ - $b = $this->level->getBlock($x, $y, $z); - return BlockAPI::get($b[0], $b[1], new Position($x, $y, $z, $this)); + $b = $this->level->getBlock($x, $y, $z); + return BlockAPI::get($b[0], $b[1], new Position($x, $y, $z, $this)); } /** @@ -506,7 +506,7 @@ class Level{ $pk->started = $this->stopTime == false; $this->server->api->player->broadcastPacket($this->players, $pk); }else{ - $this->time -= 20 * 13; + $this->time -= 20 * 13; } } diff --git a/src/world/MobSpawner.php b/src/world/MobSpawner.php index 25f4e42d..1e554d99 100644 --- a/src/world/MobSpawner.php +++ b/src/world/MobSpawner.php @@ -20,7 +20,7 @@ class MobSpawner{ } public function handle(){ - if($this->countEntities() > self::MOB_LIMIT || count($this->level->players) <= 0){ + if($this->countEntities() > self::MOB_LIMIT || count($this->level->players) <= 0){ return false; //not spawning } return $this->spawnMobs(); diff --git a/src/world/MocingObjectPosition.php b/src/world/MocingObjectPosition.php index 91e4eedd..7b495b19 100644 --- a/src/world/MocingObjectPosition.php +++ b/src/world/MocingObjectPosition.php @@ -25,10 +25,10 @@ class MovingObjectPosition{ } /** - * @param int $x - * @param int $y - * @param int $z - * @param int $side + * @param int $x + * @param int $y + * @param int $z + * @param int $side * @param Vector3 $hitVector * * @return MovingObjectPosition diff --git a/src/world/generator/VoidGenerator.php b/src/world/generator/VoidGenerator.php index 2c2a37b4..afa04d02 100644 --- a/src/world/generator/VoidGenerator.php +++ b/src/world/generator/VoidGenerator.php @@ -2,11 +2,11 @@ /** * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by diff --git a/src/world/generator/object/NetherReactorStructure.php b/src/world/generator/object/NetherReactorStructure.php index 484f606c..3ef5908d 100644 --- a/src/world/generator/object/NetherReactorStructure.php +++ b/src/world/generator/object/NetherReactorStructure.php @@ -44,78 +44,78 @@ class NetherReactorStructure{ ], 0 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N ___ N", - "N ___ N", - "N ___ N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N ___ N", + "N ___ N", + "N ___ N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", "NNNNNNNNNNNNNNNNN" ], 1 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N ___ N", - "N ___ N", - "N ___ N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N ___ N", + "N ___ N", + "N ___ N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", "NNNNNNNNNNNNNNNNN" ], 2 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N ___ N", - "N ___ N", - "N ___ N", - "N N", - "N N", - "N N", - "N N", - "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N ___ N", + "N ___ N", + "N ___ N", + "N N", + "N N", + "N N", + "N N", + "N N", "NNNNNNNNNNNNNNNNN" ], 3 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", "NNNNNNNNNNNNNNNNN" ], 4 => [ @@ -139,181 +139,181 @@ class NetherReactorStructure{ ], 5 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", - "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", + "N N", "NNNNNNNNNNNNNNNNN" ], 6 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", + "N N", + "N N", "N NNNNNNNNNNN N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", "N NNNNNNNNNNN N", - "N N", - "N N", + "N N", + "N N", "NNNNNNNNNNNNNNNNN", ], 7 => [ //spaces are required "NNNNNNNNNNNNNNNNN", - "N N", - "N N", + "N N", + "N N", "N NNNNNNNNNNN N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", "N NNNNNNNNNNN N", - "N NN", - "N NNN", + "N NN", + "N NNN", "NNNNNNNNNNNNNNNN ", ], 8 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", + "N N", + "N N", "N NNNNNNNNNNN N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N NN", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N NN", "N NNNNNNNNNNNNNN", - "N NNN ", - "N NNN ", + "N NNN ", + "N NNN ", "NNNNNNNNNNNNNN ", ], 9 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", + "N N", + "N N", "N NNNNNNNNNNN N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N NN", - "N N NNNN", - "N N NNN ", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N NN", + "N N NNNN", + "N N NNN ", "N NNNNNNNNNNNN ", - "N NNN ", - "N NNN ", - "NNNNNNNNNNNN ", + "N NNN ", + "N NNN ", + "NNNNNNNNNNNN ", ], 10 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", + "N N", + "N N", "N NNNNNNNNNNN N", - "N N N N", - "N N N N", - "N N N N", - "N N N N", - "N N N NN", - "N N NNNN", - "N N NNN ", - "N N NNN ", - "N N NNN ", + "N N N N", + "N N N N", + "N N N N", + "N N N N", + "N N N NN", + "N N NNNN", + "N N NNN ", + "N N NNN ", + "N N NNN ", "N NNNNNNNNNNN ", - "N NNN ", - "N NNN ", - "NNNNNNNNNN ", + "N NNN ", + "N NNN ", + "NNNNNNNNNN ", ], 11 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", + "N N", + "N N", "N NNNNNNNNNNN N", - "N N N N", - "N N N N", - "N N N NN", - "N N NNNN", - "N N NNN ", - "N N NNN ", - "N N NNN ", - "N N NNNN ", - "N N NNN N ", + "N N N N", + "N N N N", + "N N N NN", + "N N NNNN", + "N N NNN ", + "N N NNN ", + "N N NNN ", + "N N NNNN ", + "N N NNN N ", "N NNNNNNNNNNN ", - "N NNN ", - "N NNN ", - "NNNNNNNN ", + "N NNN ", + "N NNN ", + "NNNNNNNN ", ], 12 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N N", + "N N", + "N N", "N NNNNNNNNNNN N", - "N N N NN", + "N N N NN", "N N NNNNNNN NNNN", - "N N N N NNN ", - "N N N NNNN ", - "N N N NNN ", - "N N N NNNN ", + "N N N N NNN ", + "N N N NNNN ", + "N N N NNN ", + "N N N NNNN ", "N N N NNN N ", "N N NNNNNNN N ", "N N NNN N ", "N NNNNNNNNNNN ", - "N NNN ", - "N NNN ", - "NNNNNN ", + "N NNN ", + "N NNN ", + "NNNNNN ", ], 13 => [ "NNNNNNNNNNNNNNNNN", - "N N", - "N NN", + "N N", + "N NN", "N NNNNNNNNNNNNNN", - "N N NNN ", + "N N NNN ", "N N NNNNNNNNNN ", - "N N N NNN ", - "N N N NNNN ", + "N N N NNN ", + "N N N NNNN ", "N N N NNN N ", "N N N NNNN N ", "N N N NNN N N ", "N N NNNNNNN N ", - "N N NNN N ", + "N N NNN N ", "N NNNNNNNNNNN ", - "N NNN ", - "N NNN ", - "NNNN ", + "N NNN ", + "N NNN ", + "NNNN ", ], 14 => [ "NNNNNNNNNNNNNNNNN", - "N NNN", - "N NNN ", + "N NNN", + "N NNN ", "N NNNNNNNNNNNN ", - "N NN NNN ", + "N NN NNN ", "N N NNNNNNNNN ", "N N N NNN N ", "N N N NNNN N ", @@ -321,141 +321,141 @@ class NetherReactorStructure{ "N N NNNN N N ", "N N NNN N N ", "N NNNNNNNNN N ", - "N NNN N ", + "N NNN N ", "N NNNNNNNNNNNN ", - "NNNN ", - "NNN ", - "NN ", + "NNNN ", + "NNN ", + "NN ", ], 15 => [ "NNNNNNNNNNNNNNNN ", - "N NNN ", - "N NNN ", - "N NNNNNNNNN ", + "N NNN ", + "N NNN ", + "N NNNNNNNNN ", "N NNN NNN N ", "N NNNNNNNNN N ", "N NNN NNN N N ", "N N NNNN N N ", "N N NNN N N ", - "N NNNN N N ", - "N NNN N N ", + "N NNNN N N ", + "N NNN N N ", "N NNNNNNNNNN N ", - "NNNN N ", + "NNNN N ", "NNNNNNNNNNNNNN ", - "NN ", - "N ", + "NN ", + "N ", ], 16 => [ "NNNNNNNNNNNNNN ", - "N NNN ", - "N NNN ", - "N NNNNNNN ", - "N NNNN N ", - "N NNNNNNN N ", + "N NNN ", + "N NNN ", + "N NNNNNNN ", + "N NNNN N ", + "N NNNNNNN N ", "N NNNN N N ", - "N NNNN N N ", - "N NNN N N ", - "N NNNN N N ", - "NNNN N N N ", + "N NNNN N N ", + "N NNN N N ", + "N NNNN N N ", + "NNNN N N N ", "NNNN NNNNNNN N ", - "NN N N ", + "NN N N ", "N NNNNNNNNNNN ", ], 17 => [ - "NNNNNNNNNNNN ", - "N NNN ", - "N NNN ", - "N NNNNNNNN ", - "N NNNNNN N ", + "NNNNNNNNNNNN ", + "N NNN ", + "N NNN ", + "N NNNNNNNN ", + "N NNNNNN N ", "N NNNNNNNN N ", "N NNNNNN N N ", "N NNNNNN N N ", - "NNNNNNN N N ", - "NNNNNN N N ", - "NN NNN N N ", + "NNNNNNN N N ", + "NNNNNN N N ", + "NN NNN N N ", "N N NNNNNNN N ", - " N N ", + " N N ", " NNNNNNNNNNN ", ], 18 => [ - "NNNNNNNNNN ", - "N NNN ", - "N NNN ", - "N NNN NNN ", - "N NNN NNNN ", + "NNNNNNNNNN ", + "N NNN ", + "N NNN ", + "N NNN NNN ", + "N NNN NNNN ", "N NNNNNNNNNN N ", "NNNN N NNNN N ", "NNN N NNN N N ", "NN NNNN N N ", - "N NNN N N ", - " NNN N N ", + "N NNN N N ", + " NNN N N ", " NNNNNNNNN N ", - " NN N ", + " NN N ", " NNNNNNNNNNN ", ], 19 => [ - "NNNNNNNN ", - "N NNN ", - "N NNN ", - "N NNN N ", - "NNNN NN ", + "NNNNNNNN ", + "N NNN ", + "N NNN ", + "N NNN N ", + "NNNN NN ", "NNN NNNNNNNNN ", - "NN N NNNN ", - "N N NNN N ", - " N NNNN N ", - " N NNN N N ", - " NNNN N N ", - " NNNNNNN N ", - " NNN N ", + "NN N NNNN ", + "N N NNN N ", + " N NNNN N ", + " N NNN N N ", + " NNNN N N ", + " NNNNNNN N ", + " NNN N ", " NNNNNNNNNNN ", ], 20 => [ - "NNNNNN ", - "N NNN ", - "NNNN ", - "NNN ", - "NN ", - "N NNNNNNN N ", - " N NNN ", - " N NNN ", - " N NNNN ", - " N NNN N ", - " N NNNN N ", - " NNNNNNN N ", - " NNN N ", - " NNNNNNNNN ", + "NNNNNN ", + "N NNN ", + "NNNN ", + "NNN ", + "NN ", + "N NNNNNNN N ", + " N NNN ", + " N NNN ", + " N NNNN ", + " N NNN N ", + " N NNNN N ", + " NNNNNNN N ", + " NNN N ", + " NNNNNNNNN ", ], 21 => [ - "NNNN ", - "NNN ", - "NN ", - "N ", + "NNNN ", + "NNN ", + "NN ", + "N ", "", //nothing is here =D - " NNNNNNN ", - " N N ", - " N N N ", - " N NNN ", - " N NNN ", - " N NNNN ", - " NNNNNNN N ", - " NNN N ", - " NNNNNNN ", + " NNNNNNN ", + " N N ", + " N N N ", + " N NNN ", + " N NNN ", + " N NNNN ", + " NNNNNNN N ", + " NNN N ", + " NNNNNNN ", ], 22 => [ - "NN ", - "N ", + "NN ", + "N ", "", "", "", - " NNNNNNN ", - " N N ", - " N N ", - " N N ", - " N N N ", - " N NNN ", - " NNNNNNNNN ", - " NNNN ", - " NNNNN ", + " NNNNNNN ", + " N N ", + " N N ", + " N N ", + " N N N ", + " N NNN ", + " NNNNNNNNN ", + " NNNN ", + " NNNNN ", ], 23 => [ "", @@ -463,15 +463,15 @@ class NetherReactorStructure{ "", "", "", - " NNNNNNN ", - " N N ", - " N N ", - " N N ", - " N N ", - " N N ", - " NNNNNNN N ", - " NN ", - " NNN ", + " NNNNNNN ", + " N N ", + " N N ", + " N N ", + " N N ", + " N N ", + " NNNNNNN N ", + " NN ", + " NNN ", ], 24 => [ "", @@ -479,13 +479,13 @@ class NetherReactorStructure{ "", "", "", - " NNNNNNN ", - " N N ", - " N N ", - " N N ", - " N N ", - " N N ", - " NNNNNNN ", + " NNNNNNN ", + " N N ", + " N N ", + " N N ", + " N N ", + " N N ", + " NNNNNNN ", ], 25 => [ "", @@ -493,13 +493,13 @@ class NetherReactorStructure{ "", "", "", - " NNNNNNN ", - " N N ", - " N N ", - " N N ", - " N N ", - " N N ", - " NNNNNNN ", + " NNNNNNN ", + " N N ", + " N N ", + " N N ", + " N N ", + " N N ", + " NNNNNNN ", ], 26 => [ "", @@ -507,13 +507,13 @@ class NetherReactorStructure{ "", "", "", - " NNNNNNN ", - " N N ", - " N N ", - " N N ", - " N N ", - " N N ", - " NNNNNNN ", + " NNNNNNN ", + " N N ", + " N N ", + " N N ", + " N N ", + " N N ", + " NNNNNNN ", ], 27 => [ "", @@ -521,13 +521,13 @@ class NetherReactorStructure{ "", "", "", - " NNNNNNN ", - " N N ", - " N N ", - " N N ", - " N NN ", - " N NNN ", - " NNNNNN ", + " NNNNNNN ", + " N N ", + " N N ", + " N N ", + " N NN ", + " N NNN ", + " NNNNNN ", ], 28 => [ "", @@ -535,13 +535,13 @@ class NetherReactorStructure{ "", "", "", - " NNNNNNN ", - " N N ", - " N NN ", - " N NNN ", - " N NNN ", - " N NNN ", - " NNNN ", + " NNNNNNN ", + " N N ", + " N NN ", + " N NNN ", + " N NNN ", + " N NNN ", + " NNNN ", ], 29 => [ "", @@ -549,13 +549,13 @@ class NetherReactorStructure{ "", "", "", - " NNNNNNN ", - " N NNN ", - " N NNN ", - " N NNN ", - " NNNN ", - " NNN ", - " NN ", + " NNNNNNN ", + " N NNN ", + " N NNN ", + " N NNN ", + " NNNN ", + " NNN ", + " NN ", ], 30 => [ "", @@ -563,12 +563,12 @@ class NetherReactorStructure{ "", "", "", - " NNNNNN ", - " N NNN ", - " NNNN ", - " NNN ", - " NN ", - " N ", + " NNNNNN ", + " N NNN ", + " NNNN ", + " NNN ", + " NN ", + " N ", ], 31 => [ "", @@ -576,10 +576,10 @@ class NetherReactorStructure{ "", "", "", - " NNNN ", - " NNN ", - " NN ", - " N ", + " NNNN ", + " NNN ", + " NN ", + " N ", ], 32 => [ "", @@ -587,8 +587,8 @@ class NetherReactorStructure{ "", "", "", - " NN ", - " N ", + " NN ", + " N ", ], ];