diff --git a/src/API/AchievementAPI.php b/src/API/AchievementAPI.php index beabe308..526da14d 100644 --- a/src/API/AchievementAPI.php +++ b/src/API/AchievementAPI.php @@ -1,7 +1,7 @@ array( "name" => "Taking Inventory", @@ -79,20 +79,19 @@ class AchievementAPI{ "buildSword", ], ], - + ]; - + private $server; - + function __construct(){ $this->server = ServerAPI::request(); } - + /** * Add an achievement * @param string $achievementId * @param string $achievementName - * @param array $requires * @return boolean */ public static function addAchievement($achievementId, $achievementName, array $requires = []){ @@ -105,7 +104,7 @@ class AchievementAPI{ } return false; } - + public static function grantAchievement(Player $player, $achievementId){ if(isset(self::$achievements[$achievementId]) and !self::hasAchievement($player, $achievementId)){ foreach(self::$achievements[$achievementId]["requires"] as $requerimentId){ @@ -123,19 +122,19 @@ class AchievementAPI{ } return false; } - + public static function hasAchievement(Player $player, $achievementId){ if(!isset(self::$achievements[$achievementId]) or !isset($player->achievements)){ $player->achievements = []; return false; } - + if(!isset($player->achievements[$achievementId]) or !$player->achievements[$achievementId]){ return false; } return true; } - + public static function broadcastAchievement(Player $player, $achievementId){ if(isset(self::$achievements[$achievementId])){ $result = ServerAPI::request()->api->dhandle("achievement.broadcast", ["player" => $player, "achievementId" => $achievementId]); @@ -150,13 +149,13 @@ class AchievementAPI{ } return false; } - + public static function removeAchievement(Player $player, $achievementId){ if(self::hasAchievement($player, $achievementId)){ $player->achievements[$achievementId] = false; } } - + public function viewAchievements($cmd, $params, $issuer, $alias) { if(!isset($params[0])){ @@ -171,30 +170,30 @@ class AchievementAPI{ }else{ return false; } - + if(!$data){ return "Player 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)."): "; + $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); + return substr($output, 0, -2); } - + public function init(){ $this->server->api->console->register("ach", "", [$this, "viewAchievements"]); $this->server->api->console->alias("getplayerachievements", "ach"); diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 7ab128b6..bab63ec3 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -14,7 +14,7 @@ class BanAPI{ private $ops; /** @var Config */ private $bannedIPs; - + public $cmdWhitelist = [];//Command WhiteList function __construct(){ diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index ddd309d9..42f2f34d 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -235,7 +235,7 @@ class BlockAPI{ break; } $itemheld = $issuer->getSlot($issuer->slot); - $output = self::getItem($itemheld->getID(), $itemheld->getMetadata()).""; + $output = self::getItem($itemheld->getID(), $itemheld->getMetadata()) . ""; break; case "setblock": if(!($issuer instanceof Player)){ @@ -259,7 +259,7 @@ class BlockAPI{ $output .= "Usage: /setblock "; break; } - + $level = $issuer->entity->level; $block = self::fromString($args[3])->getBlock(); } @@ -289,13 +289,13 @@ class BlockAPI{ break; }else{ $level->setBlock($pos, $block, true, false, true); - $output .= "Placed $block in ".implode(", ", $coords).", w:".$level->getName(); + $output .= "Placed $block in " . implode(", ", $coords) . ", w:" . $level->getName(); } break; case "give": $player = $this->server->api->player->get($args[0] ?? ""); - - if($player instanceof Player){ + + if($player instanceof Player){ $item = self::fromString($args[1] ?? ""); if(($player->gamemode & 0x01) === 0x01){ return "Player is in creative mode."; @@ -303,18 +303,18 @@ class BlockAPI{ if($item->getID() === 0){ return "You cannot give an air block to a player."; } - + if(!isset($args[2])){ $item->count = $item->getMaxStackSize(); }else{ $item->count = (int) $args[2]; } - + $player->addItem($item->getID(), $item->getMetadata(), $item->count); - $output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username; + $output .= "Giving " . $item->count . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $player->username; break; }else{ - $item = self::fromString($args[0] ?? ""); + $item = self::fromString($args[0] ?? ""); if(!($issuer instanceof Player)){ return "You cant give an item to a non-player."; } @@ -334,7 +334,7 @@ class BlockAPI{ } $issuer->addItem($item->getID(), $item->getMetadata(), $item->count); - $output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$issuer->username; + $output .= "Giving " . $item->count . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $issuer->username; break; } } @@ -412,7 +412,6 @@ class BlockAPI{ return $this->cancelAction($target, $player, false); } - if(is_array($drops) && ($player->gamemode & 0x01) === 0x00 and count($drops) > 0){ foreach($drops as $drop){ $this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2])); @@ -456,7 +455,7 @@ class BlockAPI{ return $this->cancelAction($block, $player); } } - + StaticBlock::getBlock($target->getID())::interact($target->level, $target->x, $target->y, $target->z, $player); if($target->isActivable === true){ @@ -501,14 +500,14 @@ class BlockAPI{ $hand->position($block); //$face = -1; } - + if($hand->isSolid === true && ($hand->getID() != BED_BLOCK && $hand->getID() != CARPET)){ $aabb = $hand->getAABB($block->level, $block->x, $block->y, $block->z); $playerbb = $player->entity->boundingBox; - if(($aabb->maxX > $playerbb->minX && $aabb->minX < $playerbb->maxX) && ($aabb->maxY > ($playerbb->minY+0.21) && $aabb->minY < $playerbb->maxY) && ($aabb->maxZ > $playerbb->minZ && $aabb->minZ < $playerbb->maxZ)){ + if(($aabb->maxX > $playerbb->minX && $aabb->minX < $playerbb->maxX) && ($aabb->maxY > ($playerbb->minY + 0.21) && $aabb->minY < $playerbb->maxY) && ($aabb->maxZ > $playerbb->minZ && $aabb->minZ < $playerbb->maxZ)){ return $this->cancelAction($block, $player, false); //Entity in block } - + } if($this->server->api->dhandle("player.block.place", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){ @@ -537,14 +536,12 @@ class BlockAPI{ return false; } $level = $block::onUpdate($pos->level, $pos->x, $pos->y, $pos->z, $type); - + return $level; } - - public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){ - + if($type == BLOCK_UPDATE_NORMAL){ try{ throw new Exception("Deprecated: tried updating $pos using BLOCK_UPDATE_NORMAL."); @@ -554,7 +551,7 @@ class BlockAPI{ } return; } - + if($delay !== false){ $this->scheduleBlockUpdate($pos->getSide(0), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(1), $delay, $type); @@ -576,7 +573,7 @@ class BlockAPI{ if($delay < 0){ return false; } - + $index = $x . "." . $y . "." . $z . "." . $level->getName() . "." . $type; $delay = microtime(true) + $delay * 0.05; if(!isset($this->scheduledUpdates[$index])){ @@ -586,7 +583,7 @@ class BlockAPI{ } return false; } - + public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){ $type = (int) $type; if($delay < 0){ diff --git a/src/API/ChatAPI.php b/src/API/ChatAPI.php index 9f2bfac3..09cd9b7a 100644 --- a/src/API/ChatAPI.php +++ b/src/API/ChatAPI.php @@ -103,8 +103,6 @@ class ChatAPI{ /** * @param mixed $owner Can be either Player object or string username. Boolean false for broadcast. * @param string $text - * @param $whitelist - * @param $blacklist */ public function send($owner, $text, $whitelist = false, $blacklist = false){ $message = [ diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 1efb0943..56f7624b 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -24,12 +24,12 @@ class ConsoleAPI{ $this->register("defaultgamemode", "", [$this, "defaultCommands"]); $this->server->api->console->alias("tps", "status"); - + $this->cmdWhitelist("help"); $this->cmdWhitelist("status"); $this->cmdWhitelist("?"); } - + /** * Whitelists a CMD so everyone can issue it - Even non OPs. * @param string $cmd Command to Whitelist @@ -37,7 +37,7 @@ class ConsoleAPI{ public function cmdWhitelist($cmd){ $this->server->api->ban->cmdWhitelist[strtolower(trim($cmd))] = true; } - + public function register($cmd, $help, $callback){ if(!is_callable($callback)){ return false; @@ -272,19 +272,19 @@ class ConsoleAPI{ } public static function debug($msg){ - console("[DEBUG] ".$msg, true, true, 2); + console("[DEBUG] " . $msg, true, true, 2); } public static function info($msg){ - console("[INFO] ".$msg); + console("[INFO] " . $msg); } public static function notice($msg){ - console("[NOTICE] ".$msg); + console("[NOTICE] " . $msg); } public static function warn($msg){ - console("[WARNING] ".$msg); + console("[WARNING] " . $msg); } public static function error($msg){ - console("[ERROR] ".$msg); + console("[ERROR] " . $msg); } } diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 6d64f453..b9978dca 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -8,26 +8,25 @@ class EntityAPI{ 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"]); $this->server->api->console->register("entcnt", "", [$this, "CommandHandler"]); } - - + public function commandHandler($cmd, $args, $issuer, $alias){ $mob = [ "chicken" => 10, "cow" => 11, "pig" => 12, "sheep" => 13, - + "zombie" => 32, "creeper" => 33, "skeleton" => 34, @@ -37,7 +36,7 @@ class EntityAPI{ $output = ""; switch($cmd){ case "entcnt": - return "Total amount of entities: ". count($this->entities); + return "Total amount of entities: " . count($this->entities); case "summon": case "spawnmob": if(!($issuer instanceof Player)){ @@ -46,24 +45,24 @@ class EntityAPI{ if((count($args) < 1) or (count($args) > 3)){ return "Usage: /$cmd [amount] [baby]"; } - + if(is_int($args[0])) $type = $args[0]; else $type = $mob[strtolower($args[0])] ?? 0; if($type < 10 || $type > 36){ return "Unknown mob."; } $mobName = ucfirst(array_flip($mob)[$type]); - + if(((isset($args[1]) && strtolower($args[1]) === "baby") || (isset($args[2]) && strtolower($args[2]) === "baby")) && !Utils::in_range($type, 10, 13)){ return "$mobName cannot be a baby!"; } - + $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); return "$mobName spawned in $x, $y, $z."; @@ -77,12 +76,12 @@ class EntityAPI{ 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]); } - - return "$amount ".($isBaby ? "Baby " : "")."$mobName(s) spawned in $x, $y, $z."; + + return "$amount " . ($isBaby ? "Baby " : "") . "$mobName(s) spawned in $x, $y, $z."; } elseif(strtolower($args[1]) == "baby"){//summon [baby] $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]); @@ -94,7 +93,7 @@ class EntityAPI{ if(!isset($args[0])){ return "/despawn "; } - + $despawnclass = 0; $despawntype = 0; switch($args[0]){ @@ -138,12 +137,12 @@ class EntityAPI{ } } } - + return "$cnt entities have been despawned!"; } return $output; } - + public function summon(Position $pos, $class, $type, array $data = []){ $entity = $this->add($pos->level, $class, $type, [ "x" => $pos->x, @@ -152,16 +151,16 @@ class EntityAPI{ ] + $data); $this->spawnToAll($entity); } - + public function getNextEID(){ return $this->eCnt++; } - + public function addRaw(Entity $e){ $eid = $e->eid; $this->entities[$eid] = $e; - $cX = (int)$this->entities[$eid]->x >> 4; - $cZ = (int)$this->entities[$eid]->z >> 4; + $cX = (int) $this->entities[$eid]->x >> 4; + $cZ = (int) $this->entities[$eid]->z >> 4; $e->level->entityListPositioned["$cX $cZ"][$eid] = $eid; $e->level->entityList[$eid] = &$this->entities[$eid]; $this->server->handle("entity.add", $this->entities[$eid]); @@ -178,7 +177,7 @@ class EntityAPI{ } return $this->addRaw($e); } - + 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){ @@ -186,18 +185,18 @@ class EntityAPI{ } } } - + public function get($eid){ return $this->entities[$eid] ?? false; } - + public function remove($eid){ if(isset($this->entities[$eid])){ $level = $this->entities[$eid]->level; $this->entities[$eid]->closed = true; if($level instanceof Level){ - $cX = (int)$this->entities[$eid]->x >> 4; - $cZ = (int)$this->entities[$eid]->z >> 4; + $cX = (int) $this->entities[$eid]->x >> 4; + $cZ = (int) $this->entities[$eid]->z >> 4; $index = "$cX $cZ"; unset($level->entityListPositioned[$index][$eid]); if(isset($level->mobSpawner->entityAffectedPlayers[$eid])){ @@ -221,12 +220,12 @@ class EntityAPI{ unset($this->entities[$eid]); } } - + public function getRadius(Position $center, $radius = 15, $class = false){ - $minChunkX = ((int)($center->x - $radius)) >> 4; - $minChunkZ = ((int)($center->z - $radius)) >> 4; - $maxChunkX = ((int)($center->x + $radius)) >> 4; - $maxChunkZ = ((int)($center->z + $radius)) >> 4; + $minChunkX = ((int) ($center->x - $radius)) >> 4; + $minChunkZ = ((int) ($center->z - $radius)) >> 4; + $maxChunkX = ((int) ($center->x + $radius)) >> 4; + $maxChunkZ = ((int) ($center->z + $radius)) >> 4; $ents = []; //TODO also index by chunkY? for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){ @@ -244,11 +243,11 @@ class EntityAPI{ } return $ents; } - + 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){ @@ -256,7 +255,7 @@ class EntityAPI{ } $e->setHealth($e->getHealth() - $attack, $cause, $force); } - + public function dropRawPos(Level $level, $x, $y, $z, $item, $speedX, $speedY, $speedZ){ if($item->getID() === AIR or $item->count <= 0){ return; @@ -272,7 +271,7 @@ class EntityAPI{ "item" => $item, "itemID" => $item->getID() ]; - + if($this->server->api->handle("item.drop", $data) !== false){ for($count = $item->count; $count > 0;){ $item->count = min($item->getMaxStackSize(), $count); @@ -283,7 +282,7 @@ class EntityAPI{ } } } - + public function drop(Position $pos, Item $item, $pickupDelay = 10){ if($item->getID() === AIR or $item->count <= 0){ return; @@ -310,7 +309,7 @@ class EntityAPI{ } } } - + public function spawnAll(Player $player){ foreach($player->level->entityList as $e){ if($e->class !== ENTITY_PLAYER){ @@ -318,18 +317,18 @@ class EntityAPI{ } } } - + public function getAll($level = null){ if($level instanceof Level){ return $level->entityList; } return $this->entities; } - + /** * @deprecated this function doesnt do anything */ public function updateRadius(Position $center, $radius = 15, $class = false){ - + } } diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 3784363a..8f5edd9f 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -40,7 +40,7 @@ class LevelAPI{ console("[ERROR] Could not load level \"" . $name . "\""); return false; } - + if(PocketMinecraftServer::$KEEP_CHUNKS_LOADED){ for($X = 0; $X < 16; ++$X){ for($Z = 0; $Z < 16; ++$Z){ @@ -48,8 +48,7 @@ class LevelAPI{ } } } - - + $entities = new Config($path . "entities.yml", CONFIG_YAML); if(file_exists($path . "tileEntities.yml")){ @rename($path . "tileEntities.yml", $path . "tiles.yml"); @@ -61,13 +60,13 @@ class LevelAPI{ if(!isset($entity["id"])){ break; } - + $entity["x"] = $entity["Pos"][0]; $entity["y"] = $entity["Pos"][1]; $entity["z"] = $entity["Pos"][2]; $entity["yaw"] = $entity["Rotation"][0]; $entity["pitch"] = $entity["Rotation"][1]; - + if($entity["id"] === 64){ //Item Drop $e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, ENTITY_ITEM_TYPE, [ "meta" => $entity["Item"]["Damage"], @@ -105,7 +104,7 @@ class LevelAPI{ foreach($blockUpdates->getAll() as $bupdate){ if($bupdate["type"] !== BLOCK_UPDATE_RANDOM) $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"], (int) $bupdate["y"], (int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]); } - + return true; } /** diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 373f3c70..dcaeeb23 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -19,7 +19,7 @@ class PlayerAPI{ $this->registerCmd("ping"); $this->registerCmd("loc"); $this->registerCmd("hotbar", ""); - + $this->server->api->console->alias("lag", "ping"); $this->server->api->console->alias("gm", "gamemode"); $this->server->api->console->alias("who", "list"); @@ -49,9 +49,9 @@ class PlayerAPI{ if($e->shotByEntity && isset($this->server->api->entity->entities[$e->shooterEID]) && $this->server->api->entity->entities[$e->shooterEID] instanceof Entity){ $message = " was shot by {$this->server->api->entity->entities[$e->shooterEID]->name}"; }else{ - $message = " was shot"; + $message = " was shot"; } - + }else{ $message = " was killed by {$e->name}"; } @@ -104,12 +104,12 @@ class PlayerAPI{ case "hotbar": if(!($issuer instanceof Player)) return "Please run this command in-game."; if(count($args) < 1) return "Slots in hotbar on server: {$issuer->slotCount}"; - + $scrw = $args[0]; if(is_numeric($scrw)){ - $sc = (int)$scrw; + $sc = (int) $scrw; if($sc < 5 || $sc > 9) return "Slot count must be between 5 and 9."; - + $issuer->setSlotCount($sc); $issuer->sendInventory(); return "Changed slot count to $sc"; @@ -235,10 +235,10 @@ class PlayerAPI{ $level = $issuer->entity->level->getName(); $compass = [0 => "X+", 1 => "Z+", 2 => "X-", 3 => "Z-", null => "null"]; $direction = $compass[$issuer->entity->getDirection()]; - + $xChunk = $x >> 4; $zChunk = $z >> 4; - + return "Your coordinates: X: $x ($xChunk), Y: $y, Z: $z ($zChunk), world: $level.\nDirection: $direction"; } return $output; @@ -462,7 +462,7 @@ class PlayerAPI{ unset($player->entity->player); //unset($player->entity); } - + $player = null; unset($player); } diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 5e98b6ce..6596c783 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -139,8 +139,8 @@ class PluginAPI extends stdClass{ if($ext2 === "phar"){ ++$pharCnt; $pluginInfo = []; //TODO: A PluginInfo class? - $filePath = $this->pluginsPath().$file; - $p = new Phar($this->pluginsPath().$file, 0); + $filePath = $this->pluginsPath() . $file; + $p = new Phar($this->pluginsPath() . $file, 0); foreach (new RecursiveIteratorIterator($p) as $file) { $name = $file->getFileName(); $content = file_get_contents($file->getPathName()); @@ -149,23 +149,23 @@ class PluginAPI extends stdClass{ break; } } - console("[INFO] Loading PHAR plugin \"".FORMAT_GREEN.$pluginInfo["name"].FORMAT_RESET."\" ".FORMAT_AQUA.$pluginInfo["version"].FORMAT_RESET." by ".FORMAT_AQUA.$pluginInfo["author"].FORMAT_RESET); - + console("[INFO] Loading PHAR plugin \"" . FORMAT_GREEN . $pluginInfo["name"] . FORMAT_RESET . "\" " . FORMAT_AQUA . $pluginInfo["version"] . FORMAT_RESET . " by " . FORMAT_AQUA . $pluginInfo["author"] . FORMAT_RESET); + $aver = CURRENT_API_VERSION; - if(!in_array((string) CURRENT_API_VERSION, $pluginInfo["api"])){ + if(!in_array((string) CURRENT_API_VERSION, $pluginInfo["api"])){ if(is_array($pluginInfo)) $s = implode(",",$pluginInfo["api"]); else $s = $pluginInfo["api"]; console("[WARNING] API is not the same as Core, might cause bugs({$s} != {$aver})"); } - + $phr = "phar://$filePath/"; - include($phr."/src/".$pluginInfo["classLoader"]); + include($phr . "/src/" . $pluginInfo["classLoader"]); $class = $pluginInfo["CLClass"]; $loader = new $class(); $loader->loadAll($phr); - + $pluginName = PharUtils::getNameSpaceClass($pluginInfo["mainFile"]); - include($phr."/src/".$pluginInfo["mainFile"]); + include($phr . "/src/" . $pluginInfo["mainFile"]); $plugin = new $pluginName($this->server->api, false); if(!($plugin instanceof Plugin)){ console("[ERROR] Plugin \"" . $pluginInfo["name"] . "\" doesn't use the Plugin Interface"); @@ -268,7 +268,7 @@ class PluginAPI extends stdClass{ $names[] = $p[1]["name"]; $versions[] = $p[1]["version"]; } - + foreach($this->plugins as $p){ if($p[0] instanceof OtherPluginRequirement){ foreach($p[0]->getRequiredPlugins() as $required){ @@ -312,4 +312,3 @@ class RequiredPluginEntry{ //Use this as object of requirements array } } - diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index b990a8c6..2fd9ae4c 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -4,7 +4,7 @@ class ServerAPI{ private static $serverRequest = false; public $restart = false; - + /** * @var QueryAPI */ @@ -59,7 +59,7 @@ class ServerAPI{ * @var QueryHandler */ public $query; - + private $asyncCalls = []; private $server; private $config; diff --git a/src/API/TileAPI.php b/src/API/TileAPI.php index a5a48118..c4bbdbe6 100644 --- a/src/API/TileAPI.php +++ b/src/API/TileAPI.php @@ -17,7 +17,7 @@ class TileAPI{ } return false; } - + public function invalidateAll(Level $level, $x, $y, $z){ $x = (int) $x; $y = (int) $y; @@ -31,14 +31,14 @@ class TileAPI{ ++$invcnt; $tl->close(); } - + if($invcnt > 1){ ConsoleAPI::warn("{$level->getName()}: ($x $y $z) has more than 1 tile entity! Invalidated ID {$t["ID"]} (Total invaliated: $invcnt)"); } } } } - + public function get(Position $pos){ $tile = $this->server->query("SELECT * FROM tiles WHERE level = '" . $pos->level->getName() . "' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true); if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){ diff --git a/src/API/TimeAPI.php b/src/API/TimeAPI.php index e8e9f54e..d7e0cd66 100644 --- a/src/API/TimeAPI.php +++ b/src/API/TimeAPI.php @@ -175,5 +175,4 @@ class TimeAPI{ return $this->set("sunset"); } - } diff --git a/src/Deprecation.php b/src/Deprecation.php index 7d8e66cd..c0e07788 100644 --- a/src/Deprecation.php +++ b/src/Deprecation.php @@ -1,6 +1,5 @@ bigCnt = 0; $this->MTU = min($MTU, 1492); $this->server = ServerAPI::request(); @@ -111,42 +113,41 @@ class Player{ $this->slot = 0; $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; $this->packetStats = [0, 0]; - + $this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->buffer->data = []; - + $this->entityMovementQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->entityMovementQueue->data = []; - + $this->blockUpdateQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->blockUpdateQueue->data = []; - + //$this->server->schedule(20 * 60, [$this, "clearQueue"], [], true); - + $this->evid[] = $this->server->event("server.close", [$this, "close"]); console("[DEBUG] New Session started with " . $ip . ":" . $port . ". MTU " . $this->MTU . ", Client ID " . $this->clientID, true, true, 2); } - public function __get($name){ - if(isset($this->{$name})){ + public function __get($name) { + if(isset($this->{$name})) { return ($this->{$name}); } return null; } - public function getSpawn(){ + public function getSpawn() { return $this->spawnPosition; } /** - * @param Vector3 $pos * * @return boolean */ - public function sleepOn(Vector3 $pos){ - foreach($this->server->api->player->getAll($this->level) as $p){ - if($p->isSleeping instanceof Vector3){ - if($pos->distance($p->isSleeping) <= 0.1){ + public function sleepOn(Vector3 $pos) { + foreach($this->server->api->player->getAll($this->level) as $p) { + if($p->isSleeping instanceof Vector3) { + if($pos->distance($p->isSleeping) <= 0.1) { return false; } } @@ -155,27 +156,27 @@ class Player{ $this->sleepingTime = 0; $this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level), false, false, false, false); //TODO change player hitbox size after he starts sleeping - if($this->entity instanceof Entity){ + if($this->entity instanceof Entity) { $this->entity->updateMetadata(); } - + $spawnPoint = BedBlock::findStandUpPosition($this->level, $pos->x, $pos->y, $pos->z); - if($spawnPoint == null) $spawnPoint = $pos->add(0.5, 1, 0.5); - else{ + if($spawnPoint == null) { + $spawnPoint = $pos->add(0.5, 1, 0.5); + } else { $spawnPoint->x += 0.5; $spawnPoint->z += 0.5; } $this->setSpawn($spawnPoint); return true; } - - public function setSlotCount($cnt){ + + public function setSlotCount($cnt) { $this->slotCount = $cnt; $this->data->set("slot-count", $this->slotCount); } - + /** - * @param Vector3 $pos * @param float|boolean $yaw * @param float|boolean $pitch * @param float|boolean $terrain @@ -183,29 +184,29 @@ class Player{ * * @return boolean */ - public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = true, $force = true){ - if($this->entity instanceof Entity and $this->level instanceof Level){ + public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = true, $force = true) { + if($this->entity instanceof Entity and $this->level instanceof Level) { $this->entity->check = false; - if($yaw === false){ + if($yaw === false) { $yaw = $this->entity->yaw; } - if($pitch === false){ + if($pitch === false) { $pitch = $this->entity->pitch; } - if($this->server->api->dhandle("player.teleport", ["player" => $this, "target" => $pos]) === false){ + if($this->server->api->dhandle("player.teleport", ["player" => $this, "target" => $pos]) === false) { $this->entity->check = true; return false; } - if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level){ - if($this->server->api->dhandle("player.teleport.level", ["player" => $this, "origin" => $this->level, "target" => $pos->level]) === false){ + if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level) { + if($this->server->api->dhandle("player.teleport.level", ["player" => $this, "origin" => $this->level, "target" => $pos->level]) === false) { $this->entity->check = true; return false; } - foreach($this->level->entityList as $e){ - if($e->eid !== $this->entity->eid){ - if($e->isPlayer()){ + foreach($this->level->entityList as $e) { + if($e->eid !== $this->entity->eid) { + if($e->isPlayer()) { $pk = new MovePlayerPacket(); $pk->eid = $this->entity->eid; $pk->x = -256; @@ -215,7 +216,7 @@ class Player{ $pk->pitch = 0; $pk->bodyYaw = 0; $e->player->dataPacket($pk); - + $pk = new MovePlayerPacket(); $pk->eid = $e->eid; $pk->x = -256; @@ -225,8 +226,8 @@ class Player{ $pk->pitch = 0; $pk->bodyYaw = 0; $this->dataPacket($pk); - - }else{ + + } else { $pk = new MoveEntityPacket_PosRot(); $pk->eid = $e->eid; $pk->x = -256; @@ -250,9 +251,9 @@ class Player{ $this->chunksLoaded = []; $this->server->api->entity->spawnToAll($this->entity); //$this->server->api->entity->spawnAll($this); - foreach($this->level->entityList as $e){ - if($e->eid !== $this->entity->eid){ - if(!$e->isPlayer()){ + foreach($this->level->entityList as $e) { + if($e->eid !== $this->entity->eid) { + if(!$e->isPlayer()) { $pk = new MoveEntityPacket_PosRot(); $pk->eid = $e->eid; $pk->x = $e->x; @@ -264,13 +265,13 @@ class Player{ } } } - + $pk = new SetTimePacket; $pk->time = $this->level->getTime(); $this->dataPacket($pk); $terrain = true; - foreach($this->level->players as $player){ - if($player !== $this and $player->entity instanceof Entity){ + foreach($this->level->players as $player) { + if($player !== $this and $player->entity instanceof Entity) { $pk = new MoveEntityPacket_PosRot; $pk->eid = $player->entity->eid; $pk->x = $player->entity->x; @@ -297,12 +298,12 @@ class Player{ $player->sendArmor($this); } } - + $resyncpos = new Position($pos->x, $pos->y, $pos->z, $pos->level); - }else{ + } else { $resyncpos = new Vector3($pos->x, $pos->y, $pos->z); } - + $this->lastCorrect = $resyncpos; $this->entity->fallY = false; $this->entity->fallStart = false; @@ -311,23 +312,25 @@ class Player{ $this->entity->resetSpeed(); $this->entity->updateLast(); $this->entity->calculateVelocity(); - if($terrain === true){ + if($terrain === true) { $this->orderChunks(); - if($this->spawned) $this->getNextChunk($this->level); + if($this->spawned) { + $this->getNextChunk($this->level); + } } $this->entity->check = true; - if($force === true){ + if($force === true) { $this->forceMovement = $resyncpos; } } - + $pk = new SetEntityMotionPacket(); $pk->eid = 0; $pk->speedX = 0; $pk->speedY = 0; $pk->speedZ = 0; $this->dataPacket($pk); - + $pk = new MovePlayerPacket; $pk->eid = 0; $pk->x = $pos->x; @@ -340,28 +343,26 @@ class Player{ } /** - * @param integer $id - * @param array $data * * @return array|bool */ - public function dataPacket(RakNetDataPacket $packet){ - if($this->connected === false){ + public function dataPacket(RakNetDataPacket $packet) { + if($this->connected === false) { return false; } - if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ + if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) { return; } - + $packet->encode(); $len = strlen($packet->buffer) + 1; $MTU = $this->MTU - 24; - if($len > $MTU){ + if($len > $MTU) { return $this->directBigRawPacket($packet); } - - if(($this->bufferLen + $len) >= $MTU){ + + if(($this->bufferLen + $len) >= $MTU) { $this->sendBuffer(); } @@ -372,21 +373,23 @@ class Player{ return []; } - private function directBigRawPacket(RakNetDataPacket $packet){ - if($this->connected === false){ + private function directBigRawPacket(RakNetDataPacket $packet) { + if($this->connected === false) { return false; } $sendtime = microtime(true); $size = $this->MTU - 34; - if($size <= 0) return false; + if($size <= 0) { + return false; + } $buffer = str_split($packet->buffer, $size); $bigCnt = $this->bigCnt; $this->bigCnt = ($this->bigCnt + 1) % 0x10000; $cnts = []; $bufCount = count($buffer); - foreach($buffer as $i => $buf){ + foreach($buffer as $i => $buf) { $cnts[] = $count = $this->counter[0]++; $pk = new UnknownPacket; @@ -409,16 +412,16 @@ class Player{ return $cnts; } - public function send(RakNetPacket $packet){ - if($this->connected === true){ + public function send(RakNetPacket $packet) { + if($this->connected === true) { $packet->ip = $this->ip; $packet->port = $this->port; $this->bandwidthRaw += $this->server->send($packet); } } - public function sendBuffer(){ - if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket){ + public function sendBuffer() { + if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket) { $this->buffer->seqNumber = $this->counter[0]++; $this->recoveryQueue[$this->buffer->seqNumber] = $this->buffer; $this->buffer->sendtime = microtime(true); @@ -435,20 +438,19 @@ class Player{ * * @return Item */ - public function getSlot($slot){ - return $this->inventory[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); + public function getSlot($slot) { + return $this->inventory[(int) $slot] ?? BlockAPI::getItem(AIR, 0, 0); } /** * @param integer $slot - * @param Item $item * @param boolean $send * * @return boolean */ - public function setSlot($slot, Item $item, $send = true){ + public function setSlot($slot, Item $item, $send = true) { $this->inventory[(int) $slot] = $item; - if($send === true){ + if($send === true) { $this->sendInventorySlot((int) $slot); } return true; @@ -457,92 +459,92 @@ class Player{ /** * @param Player|string|boolean|void $player */ - public function sendArmor($player = false){ + public function sendArmor($player = false) { $data = [ "player" => $this, "eid" => $this->eid, "slots" => [] ]; - for($i = 0; $i < 4; ++$i){ - if(isset($this->armor[$i]) and ($this->armor[$i] instanceof Item) and $this->armor[$i]->getID() > AIR){ + for($i = 0; $i < 4; ++$i) { + if(isset($this->armor[$i]) and ($this->armor[$i] instanceof Item) and $this->armor[$i]->getID() > AIR) { $data["slots"][$i] = $this->armor[$i]->getID() !== AIR ? $this->armor[$i]->getID() - 256 : 0; - }else{ + } else { $this->armor[$i] = BlockAPI::getItem(AIR, 0, 0); $data["slots"][$i] = 255; } } - if($player instanceof Player){ - if($player === $this){ + if($player instanceof Player) { + if($player === $this) { $pk = new ContainerSetContentPacket; $pk->windowid = 0x78; //Armor window id $pk->slots = $this->armor; $this->dataPacket($pk); - }else{ + } else { $pk = new PlayerArmorEquipmentPacket; $pk->eid = $this->eid; $pk->slots = $data["slots"]; $player->dataPacket($pk); } - }else{ + } else { $this->server->api->dhandle("player.armor", $data); } } public $lastOrderX = 0; public $lastOrderZ = 0; - - public function orderChunks(){ - if(!($this->entity instanceof Entity) or $this->connected === false){ + + public function orderChunks() { + if(!($this->entity instanceof Entity) or $this->connected === false) { return false; } - $X = ((int)$this->entity->x) >> 4; - $Z = ((int)$this->entity->z) >> 4; + $X = ((int) $this->entity->x) >> 4; + $Z = ((int) $this->entity->z) >> 4; $this->chunksOrder = []; $this->lastOrderX = $X; $this->lastOrderZ = $Z; - if(self::$smallChunks){ - $Y = ((int)$this->entity->y) >> 4; + if(self::$smallChunks) { + $Y = ((int) $this->entity->y) >> 4; $v = new Vector3($X, $Y, $Z); - for($x = 0; $x < 16; ++$x){ - for($z = 0; $z < 16; ++$z){ - for($y = 0; $y < 8; ++$y){ + for($x = 0; $x < 16; ++$x) { + for($z = 0; $z < 16; ++$z) { + for($y = 0; $y < 8; ++$y) { $dist = $v->distance(new Vector3($x, $y, $z)); $d = $x . ":" . $y . ":" . $z; - if(!isset($this->chunksLoaded[$d])){ + if(!isset($this->chunksLoaded[$d])) { $this->chunksOrder[$d] = $dist; } } } } - }else{ + } else { $v = new Vector2($X, $Z); - for($x = 0; $x < 16; ++$x){ - for($z = 0; $z < 16; ++$z){ + for($x = 0; $x < 16; ++$x) { + for($z = 0; $z < 16; ++$z) { $dist = $v->distance(new Vector2($x, $z)); - for($y = 0; $y < 8; ++$y){ + for($y = 0; $y < 8; ++$y) { $d = $x . ":" . $y . ":" . $z; - if(!isset($this->chunksLoaded[$d])){ + if(!isset($this->chunksLoaded[$d])) { $this->chunksOrder[$d] = $dist; } } } } } - + asort($this->chunksOrder); } - - public function loaddAllChunks(){ - for($x = 0; $x < 16; $x++){ - for($z = 0; $z < 16; $z++){ + + public function loaddAllChunks() { + for($x = 0; $x < 16; $x++) { + for($z = 0; $z < 16; $z++) { $this->useChunk($x, $z); } } } - - public function useChunk($X, $Z){ + + public function useChunk($X, $Z) { $Yndex = 0; - for($iY = 0; $iY < 8; ++$iY){ - if(isset($this->chunksOrder["$X:$iY:$Z"])){ + for($iY = 0; $iY < 8; ++$iY) { + if(isset($this->chunksOrder["$X:$iY:$Z"])) { unset($this->chunksOrder["$X:$iY:$Z"]); $this->chunksLoaded["$X:$iY:$Z"] = true; $Yndex |= 1 << $iY; @@ -552,7 +554,7 @@ class Player{ $maxX = (($X << 4) + 15); $minZ = ($Z << 4); $maxZ = (($Z << 4) + 15); - + $pk = new ChunkDataPacket; $pk->chunkX = $X; $pk->chunkZ = $Z; @@ -561,44 +563,44 @@ class Player{ $tiles = $this->server->query("SELECT ID FROM tiles WHERE spawnable = 1 AND level = '{$this->level->getName()}' AND x >= $minX AND x <= $maxX AND z >= $minZ AND z <= $maxZ;"); $this->lastChunk = false; - if($tiles !== false and $tiles !== true){ - while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){ + if($tiles !== false and $tiles !== true) { + while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false) { $tile = $this->server->api->tile->getByID($tile["ID"]); - if($tile instanceof Tile){ + if($tile instanceof Tile) { $tile->spawn($this); } } } - - if($cnt === false){ + + if($cnt === false) { return false; } } - - public function getNextChunk($world){ - if($this->connected === false or $world != $this->level){ + + public function getNextChunk($world) { + if($this->connected === false or $world != $this->level) { return false; } - foreach($this->chunkCount as $count => $t){ - if(isset($this->recoveryQueue[$count]) or isset($this->resendQueue[$count])){ + foreach($this->chunkCount as $count => $t) { + if(isset($this->recoveryQueue[$count]) or isset($this->resendQueue[$count])) { $this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world); return; - }else{ + } else { unset($this->chunkCount[$count]); } } - if(is_array($this->lastChunk)){ + if(is_array($this->lastChunk)) { $minX = $this->lastChunk[0]; $maxX = $this->lastChunk[0] + 15; $minZ = $this->lastChunk[1]; $maxZ = $this->lastChunk[1] + 15; $tiles = $this->server->query("SELECT ID, x, y, z FROM tiles WHERE level = '{$this->level->getName()}' AND x >= $minX AND x <= $maxX AND z >= $minZ AND z <= $maxZ;"); $this->lastChunk = false; - if($tiles !== false and $tiles !== true){ - while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){ + if($tiles !== false and $tiles !== true) { + while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false) { $tile = $this->server->api->tile->getByID($tile["ID"]); - if($tile instanceof Tile){ + if($tile instanceof Tile) { $tile->spawn($this); } } @@ -607,7 +609,7 @@ class Player{ $c = key($this->chunksOrder); $d = $c != null ? $this->chunksOrder[$c] : null; - if($c === null or $d === null){ + if($c === null or $d === null) { $this->server->schedule(40, [$this, "getNextChunk"], $world); return false; } @@ -623,8 +625,8 @@ class Player{ $y = $Y << 4; $this->level->useChunk($X, $Z, $this); $Yndex = 1 << $Y; - for($iY = 0; $iY < 8; ++$iY){ - if(isset($this->chunksOrder["$X:$iY:$Z"])){ + for($iY = 0; $iY < 8; ++$iY) { + if(isset($this->chunksOrder["$X:$iY:$Z"])) { unset($this->chunksOrder["$X:$iY:$Z"]); $this->chunksLoaded["$X:$iY:$Z"] = true; $Yndex |= 1 << $iY; @@ -635,28 +637,25 @@ class Player{ $pk->chunkZ = $Z; $pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex); $cnt = $this->dataPacket($pk); - if($cnt === false){ + if($cnt === false) { return false; } $this->chunkCount = []; - foreach($cnt as $i => $count){ + foreach($cnt as $i => $count) { $this->chunkCount[$count] = true; } $this->lastChunk = [$x, $z]; - if($this->lastOrderX != ($this->entity->x >> 4) || $this->lastOrderZ != ($this->entity->z >> 4)){ + if($this->lastOrderX != ($this->entity->x >> 4) || $this->lastOrderZ != ($this->entity->z >> 4)) { $this->orderChunks(); } $this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world); } - /** - * @param Vector3 $pos - */ - public function setSpawn(Vector3 $pos){ - if(!($pos instanceof Position)){ + public function setSpawn(Vector3 $pos) { + if(!($pos instanceof Position)) { $level = $this->entity->level; - }else{ + } else { $level = $pos->level; } $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level); @@ -667,17 +666,17 @@ class Player{ $this->dataPacket($pk); } - public function sendInventorySlot($s){ + public function sendInventorySlot($s) { $this->sendInventory(); return true; } - public function sendInventory(){ - if(($this->gamemode & 0x01) === CREATIVE){ + public function sendInventory() { + if(($this->gamemode & 0x01) === CREATIVE) { return; } $hotbar = []; - foreach($this->hotbar as $slot){ + foreach($this->hotbar as $slot) { $hotbar[] = $slot <= -1 ? -1 : $slot + 9; } $pk = new ContainerSetContentPacket; @@ -687,32 +686,29 @@ class Player{ $this->dataPacket($pk); } /** - * @param $type - * @param $damage - * @param $count * * @return boolean */ - public function hasSpace($type, $damage, $count){ + public function hasSpace($type, $damage, $count) { $inv = $this->inventory; - while($count > 0){ + while($count > 0) { $add = 0; - foreach($inv as $s => $item){ - if($item->getID() === AIR){ + foreach($inv as $s => $item) { + if($item->getID() === AIR) { $add = min($item->getMaxStackSize(), $count); $inv[$s] = BlockAPI::getItem($type, $damage, $add); break; - }elseif($item->getID() === $type and $item->getMetadata() === $damage){ + } elseif($item->getID() === $type and $item->getMetadata() === $damage) { $add = min($item->getMaxStackSize() - $item->count, $count); - - if($add <= 0){ + + if($add <= 0) { continue; } $inv[$s] = BlockAPI::getItem($type, $damage, $item->count + $add); break; } } - if($add <= 0){ + if($add <= 0) { return false; } $count -= $add; @@ -725,13 +721,13 @@ class Player{ * * @return Item */ - public function getArmor($slot){ - return $this->armor[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); + public function getArmor($slot) { + return $this->armor[(int) $slot] ?? BlockAPI::getItem(AIR, 0, 0); } - public function setArmor($slot, Item $armor, $send = true){ + public function setArmor($slot, Item $armor, $send = true) { $this->armor[(int) $slot] = $armor; - if($send === true){ + if($send === true) { $this->sendArmor($this); } return true; @@ -741,8 +737,8 @@ class Player{ * @param mixed $data * @param string $event */ - public function eventHandler($data, $event){ - switch($event){ + public function eventHandler($data, $event) { + switch($event) { case "entity.link": $pk = new SetEntityLinkPacket(); $pk->rider = $data["rider"] == $this->entity->eid ? 0 : $data["rider"]; @@ -751,10 +747,10 @@ class Player{ $this->dataPacket($pk); break; case "tile.update": - if($data->level === $this->level){ - if($data->class === TILE_FURNACE){ - foreach($this->windows as $id => $w){ - if($w === $data){ + if($data->level === $this->level) { + if($data->class === TILE_FURNACE) { + foreach($this->windows as $id => $w) { + if($w === $data) { $pk = new ContainerSetDataPacket; $pk->windowid = $id; $pk->property = 0; //Smelting @@ -772,9 +768,9 @@ class Player{ } break; case "tile.container.slot": - if($data["tile"]->level === $this->level){ - foreach($this->windows as $id => $w){ - if($w === $data["tile"]){ + if($data["tile"]->level === $this->level) { + foreach($this->windows as $id => $w) { + if($w === $data["tile"]) { $pk = new ContainerSetSlotPacket; $pk->windowid = $id; $pk->slot = $data["slot"] + ($data["offset"] ?? 0); @@ -785,8 +781,8 @@ class Player{ } break; case "player.armor": - if($data["player"]->level === $this->level){ - if($data["eid"] === $this->eid){ + if($data["player"]->level === $this->level) { + if($data["eid"] === $this->eid) { $this->sendArmor($this); break; } @@ -797,16 +793,16 @@ class Player{ } break; case "player.pickup": - if($data["eid"] === $this->eid){ + if($data["eid"] === $this->eid) { $data["eid"] = 0; $pk = new TakeItemEntityPacket; $pk->eid = 0; $pk->target = $data["entity"]->eid; $this->dataPacket($pk); - if(($this->gamemode & 0x01) === 0x00){ + if(($this->gamemode & 0x01) === 0x00) { $this->addItem($data["entity"]->itemID, $data["entity"]->meta, $data["entity"]->stack, false); } - switch($data["entity"]->itemID){ + switch($data["entity"]->itemID) { case WOOD: AchievementAPI::grantAchievement($this, "mineWood"); break; @@ -817,7 +813,7 @@ class Player{ AchievementAPI::grantAchievement($this, "leather"); break; } - }elseif($data["entity"]->level === $this->level){ + } elseif($data["entity"]->level === $this->level) { $pk = new TakeItemEntityPacket; $pk->eid = $data["eid"]; $pk->target = $data["entity"]->eid; @@ -825,7 +821,7 @@ class Player{ } break; case "player.equipment.change": - if($data["eid"] === $this->eid or $data["player"]->level !== $this->level){ + if($data["eid"] === $this->eid or $data["player"]->level !== $this->level) { break; } $data["slot"] = 0; @@ -839,10 +835,10 @@ class Player{ break; case "entity.motion": - if($data->eid === $this->eid or $data->level !== $this->level){ + if($data->eid === $this->eid or $data->level !== $this->level) { break; } - if(($data->speedX === 0 && $data->speedY === 0 && $data->speedZ === 0) || ($data->speedX === $data->lastSpeedX && $data->speedY === $data->lastSpeedY && $data->lastSpeedZ === $data->speedZ)){ + if(($data->speedX === 0 && $data->speedY === 0 && $data->speedZ === 0) || ($data->speedX === $data->lastSpeedX && $data->speedY === $data->lastSpeedY && $data->lastSpeedZ === $data->speedZ)) { break; } $pk = new SetEntityMotionPacket; @@ -860,12 +856,12 @@ class Player{ $this->dataPacket($pk); break; case "entity.metadata": - if($data->eid === $this->eid){ + if($data->eid === $this->eid) { $eid = 0; - }else{ + } else { $eid = $data->eid; } - if($data->level === $this->level){ + if($data->level === $this->level) { $pk = new SetEntityDataPacket; $pk->eid = $eid; $pk->metadata = $data->getMetadata(); @@ -873,12 +869,12 @@ class Player{ } break; case "entity.event": - if($data["entity"]->eid === $this->eid){ + if($data["entity"]->eid === $this->eid) { $eid = 0; - }else{ + } else { $eid = $data["entity"]->eid; } - if($data["entity"]->level === $this->level){ + if($data["entity"]->level === $this->level) { $pk = new EntityEventPacket; $pk->eid = $eid; $pk->event = $data["event"]; @@ -886,14 +882,14 @@ class Player{ } break; case "server.chat": - if(($data instanceof Container) === true){ - if(!$data->check($this->username) and !$data->check($this->iusername)){ + if(($data instanceof Container) === true) { + if(!$data->check($this->username) and !$data->check($this->iusername)) { return; - }else{ + } else { $message = $data->get(); $this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", $message["message"]), $message["player"]); //Remove ANSI codes from chat } - }else{ + } else { $message = (string) $data; $this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", (string) $data)); //Remove ANSI codes from chat } @@ -902,40 +898,48 @@ class Player{ } /** - * @param $type - * @param $damage * @param integer $count * @param boolean $send * * @return boolean */ - public function addItem($type, $damage, $count, $send = true){ - - foreach($this->inventory as $s => $item){ //force check the inventory for non-full stacks of this item first - if($item->getID() === $type and $item->getMetadata() === $damage){ + public function addItem($type, $damage, $count, $send = true) { + + foreach($this->inventory as $s => $item) { //force check the inventory for non-full stacks of this item first + if($item->getID() === $type and $item->getMetadata() === $damage) { $add = min($item->getMaxStackSize() - $item->count, $count); - - if($add <= 0){ + + if($add <= 0) { continue; } $item->count += $add; - if($send) $this->sendInventorySlot($s); - + if($send) { + $this->sendInventorySlot($s); + } + $count -= $add; - if($count <= 0) return true; + if($count <= 0) { + return true; + } } } $toadd = BlockAPI::getItem($type, $damage, $count); - foreach($this->inventory as $s => $item){ - if($item->getID() === AIR){ + foreach($this->inventory as $s => $item) { + if($item->getID() === AIR) { $add = min($toadd->getMaxStackSize(), $count); $this->inventory[$s] = BlockAPI::getItem($type, $damage, $add); - if($send) $this->sendInventorySlot($s); + if($send) { + $this->sendInventorySlot($s); + } $count -= $add; - if($count <= 0) return true; + if($count <= 0) { + return true; + } } } - if($count <= 0) return true; + if($count <= 0) { + return true; + } return false; } @@ -943,18 +947,18 @@ class Player{ * @param string $message * @param string $author */ - public function sendChat($message, $author = ""){ + public function sendChat($message, $author = "") { $mes = explode("\n", $message); - foreach($mes as $m){ - if(preg_match_all('#@([@A-Za-z_]{1,})#', $m, $matches, PREG_OFFSET_CAPTURE) > 0){ + foreach($mes as $m) { + if(preg_match_all('#@([@A-Za-z_]{1,})#', $m, $matches, PREG_OFFSET_CAPTURE) > 0) { $offsetshift = 0; - foreach($matches[1] as $selector){ - if($selector[0][0] === "@"){ //Escape! + foreach($matches[1] as $selector) { + if($selector[0][0] === "@") { //Escape! $m = substr_replace($m, $selector[0], $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1); --$offsetshift; continue; } - switch(strtolower($selector[0])){ + switch(strtolower($selector[0])) { case "player": case "username": $m = substr_replace($m, $this->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1); @@ -964,7 +968,7 @@ class Player{ } } - if($m !== ""){ + if($m !== "") { $pk = new MessagePacket; $pk->source = ($author instanceof Player) ? $author->username : $author; $pk->message = TextFormat::clean($m); //Colors not implemented :( @@ -972,18 +976,18 @@ class Player{ } } } - public function makeInvisibleForOnePlayer(Player $player){ + public function makeInvisibleForOnePlayer(Player $player) { $pk = new RemoveEntityPacket; $pk->eid = $this->entity->eid; $player->dataPacket($pk); } - public function makeInvisibleForAllPlayers(){ + public function makeInvisibleForAllPlayers() { $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){ + public function getGamemode() { + switch($this->gamemode) { case SURVIVAL: return "survival"; case CREATIVE: @@ -994,31 +998,33 @@ class Player{ return "view"; } } - - public function checkSpawnPosition(){ - if($this->server->api->dhandle("player.checkspawnpos", ["player" => $this]) === false) return; + + public function checkSpawnPosition() { + if($this->server->api->dhandle("player.checkspawnpos", ["player" => $this]) === false) { + return; + } $level = $this->spawnPosition->level; - if(!isset($this->server->api->level->levels[$level->getName()])){ + if(!isset($this->server->api->level->levels[$level->getName()])) { ConsoleAPI::warn("Level to respawn {$this->iusername} was unloaded, changing spawnpoint to default."); $level = $this->server->api->level->getDefault(); $this->spawnPosition = $level->getSpawn(); - }else{ - $x0 = floor($this->spawnPosition->x - $this->entity->width/2); - $x1 = floor($this->spawnPosition->x + $this->entity->width/2 + 1); + } else { + $x0 = floor($this->spawnPosition->x - $this->entity->width / 2); + $x1 = floor($this->spawnPosition->x + $this->entity->width / 2 + 1); $y0 = floor($this->spawnPosition->y); $y1 = floor($this->spawnPosition->y + $this->entity->height + 1); - $z0 = floor($this->spawnPosition->z - $this->entity->width/2); - $z1 = floor($this->spawnPosition->z + $this->entity->width/2 + 1); - + $z0 = floor($this->spawnPosition->z - $this->entity->width / 2); + $z1 = floor($this->spawnPosition->z + $this->entity->width / 2 + 1); + for($x = $x0; $x < $x1; ++$x) { for($z = $z0; $z < $z1; ++$z) { for($y = $y0; $y < $y1; ++$y) { $bid = $this->entity->level->level->getBlockID($x, $y, $z); - if($bid > 0 && StaticBlock::getIsSolid($bid)){ + if($bid > 0 && StaticBlock::getIsSolid($bid)) { $blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this->entity->level, $x, $y, $z, $this->entity); - - foreach($blockBounds as $blockBound){ - if($this->entity->boundingBox->intersectsWith($blockBound)){ + + foreach($blockBounds as $blockBound) { + if($this->entity->boundingBox->intersectsWith($blockBound)) { $this->sendChat("Your spawn positon is obstructed."); goto reset_spawn_pos; } @@ -1032,61 +1038,61 @@ class Player{ $this->spawnPosition = $this->server->api->level->getDefault()->getSpawn(); } } - - public function setGamemode($gm){ - if($gm < 0 or $gm > 3 or $this->gamemode === $gm){ + + public function setGamemode($gm) { + if($gm < 0 or $gm > 3 or $this->gamemode === $gm) { return false; } - if($this->server->api->dhandle("player.gamemode.change", ["player" => $this, "gamemode" => $gm]) === false){ + if($this->server->api->dhandle("player.gamemode.change", ["player" => $this, "gamemode" => $gm]) === false) { return false; } $inv = &$this->inventory; - if($gm === VIEW){ + if($gm === VIEW) { $this->armor = []; $this->sendArmor(); } - if(($this->gamemode & 0x01) === ($gm & 0x01)){ - if(($gm & 0x01) === 0x01 and ($gm & 0x02) === 0x02){ + if(($this->gamemode & 0x01) === ($gm & 0x01)) { + if(($gm & 0x01) === 0x01 and ($gm & 0x02) === 0x02) { $inv = []; - foreach(BlockAPI::$creative as $item){ + foreach(BlockAPI::$creative as $item) { $inv[] = BlockAPI::getItem(0, 0, 1); } - }elseif(($gm & 0x01) === 0x01){ + } elseif(($gm & 0x01) === 0x01) { $inv = []; - foreach(BlockAPI::$creative as $item){ + foreach(BlockAPI::$creative as $item) { $inv[] = BlockAPI::getItem($item[0], $item[1], 1); } } $this->gamemode = $gm; $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ".\n"); - }else{ - foreach($this->inventory as $slot => $item){ + } else { + foreach($this->inventory as $slot => $item) { $inv[$slot] = BlockAPI::getItem(AIR, 0, 0); } $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; $this->lastCorrect = $this->entity->copy(); - $this->blocked = true; + $this->blocked = true; $this->gamemode = $gm; $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ", you've to do a forced reconnect.\n"); $this->server->schedule(30, [$this, "close"], "gamemode change", false, true); //Forces a kick } - - if($this->gamemode === SPECTATOR){ + + if($this->gamemode === SPECTATOR) { $this->makeInvisibleForAllPlayers(); } - if($this->gamemode === CREATIVE){ + if($this->gamemode === CREATIVE) { $this->server->api->player->spawnToAllPlayers($this); } - + $this->inventory = $inv; $this->sendSettings(); $this->sendInventory(); return true; } - public function sendSettings($nametags = true){ + public function sendSettings($nametags = true) { /* bit mask | flag name 0b00000001 allowInteract @@ -1099,29 +1105,29 @@ class Player{ 0b10000000 - unused */ $flags = 0; - if(($this->gamemode & 0x02) === 0x02){ + if(($this->gamemode & 0x02) === 0x02) { $flags |= 0x01; //Do not allow placing/breaking blocks, adventure mode } - if($nametags !== false){ + if($nametags !== false) { $flags |= 0x20; //Show Nametags } - + //$flags |= 0x2; //pvp //$flags |= 0x4; //pve - + $pk = new AdventureSettingsPacket; $pk->flags = $flags; $this->dataPacket($pk); } - public function measureLag(){ - if($this->connected === false){ + public function measureLag() { + if($this->connected === false) { return false; } - if($this->packetStats[1] > 2){ + if($this->packetStats[1] > 2) { $this->packetLoss = $this->packetStats[1] / max(1, $this->packetStats[0] + $this->packetStats[1]); - }else{ + } else { $this->packetLoss = 0; } $this->packetStats = [0, 0]; @@ -1134,53 +1140,53 @@ class Player{ $this->lastMeasure = microtime(true); } - public function getLag(){ + public function getLag() { return $this->lagStat * 1000; } - public function getPacketLoss(){ + public function getPacketLoss() { return $this->packetLoss; } - public function getBandwidth(){ + public function getBandwidth() { return array_sum($this->bandwidthStats) / max(1, count($this->bandwidthStats)); } - public function clearQueue(){ - if($this->connected === false){ + public function clearQueue() { + if($this->connected === false) { return false; } - if(($cnt = count($this->received)) > PLAYER_MAX_QUEUE){ + if(($cnt = count($this->received)) > PLAYER_MAX_QUEUE) { ksort($this->received); - foreach($this->received as $c => $t){ + foreach($this->received as $c => $t) { unset($this->received[$c]); --$cnt; - if($cnt <= PLAYER_MAX_QUEUE){ + if($cnt <= PLAYER_MAX_QUEUE) { break; } } } } - public function handlePacketQueues(){ - if($this->connected === false){ + public function handlePacketQueues() { + if($this->connected === false) { return false; } $time = microtime(true); - if($time > $this->timeout){ + if($time > $this->timeout) { $this->close("timeout"); return false; } - if(($ackCnt = count($this->ackQueue)) > 0){ + if(($ackCnt = count($this->ackQueue)) > 0) { rsort($this->ackQueue); $safeCount = (int) (($this->MTU - 1) / 4); $packetCnt = (int) ($ackCnt / $safeCount + 1); - for($p = 0; $p < $packetCnt; ++$p){ + for($p = 0; $p < $packetCnt; ++$p) { $pk = new RakNetPacket(RakNetInfo::ACK); $pk->packets = []; - for($c = 0; $c < $safeCount; ++$c){ - if(($k = array_pop($this->ackQueue)) === null){ + for($c = 0; $c < $safeCount; ++$c) { + if(($k = array_pop($this->ackQueue)) === null) { break; } $pk->packets[] = $k; @@ -1190,20 +1196,20 @@ class Player{ $this->ackQueue = []; } - if(($receiveCnt = count($this->receiveQueue)) > 0){ + if(($receiveCnt = count($this->receiveQueue)) > 0) { ksort($this->receiveQueue); - foreach($this->receiveQueue as $count => $packets){ + foreach($this->receiveQueue as $count => $packets) { unset($this->receiveQueue[$count]); - foreach($packets as $p){ - if($p instanceof RakNetDataPacket and $p->hasSplit === false){ - if(isset($p->messageIndex) and $p->messageIndex !== false){ - if($p->messageIndex > $this->receiveCount){ + foreach($packets as $p) { + if($p instanceof RakNetDataPacket and $p->hasSplit === false) { + if(isset($p->messageIndex) and $p->messageIndex !== false) { + if($p->messageIndex > $this->receiveCount) { $this->receiveCount = $p->messageIndex; - }elseif($p->messageIndex !== 0){ - if(isset($this->received[$p->messageIndex])){ + } elseif($p->messageIndex !== 0) { + if(isset($this->received[$p->messageIndex])) { continue; } - switch($p->pid()){ + switch($p->pid()) { case 0x01: case ProtocolInfo::PING_PACKET: case ProtocolInfo::PONG_PACKET: @@ -1223,37 +1229,38 @@ class Player{ } } - if($this->bufferLen > 0){ + if($this->bufferLen > 0) { $this->sendBuffer(); } $limit = $time - 5; //max lag - foreach($this->recoveryQueue as $count => $data){ - if($data->sendtime > $limit){ + foreach($this->recoveryQueue as $count => $data) { + if($data->sendtime > $limit) { break; } unset($this->recoveryQueue[$count]); $this->resendQueue[$count] = $data; } - if(($resendCnt = count($this->resendQueue)) > 0){ - foreach($this->resendQueue as $count => $data){ + if(($resendCnt = count($this->resendQueue)) > 0) { + foreach($this->resendQueue as $count => $data) { unset($this->resendQueue[$count]); $this->packetStats[1]++; $this->lag[] = $time - $data->sendtime; $data->sendtime = $time; $cnt = $this->send($data); - if(isset($this->chunkCount[$count])){ + if(isset($this->chunkCount[$count])) { unset($this->chunkCount[$count]); - if(!is_null($cnt) and !is_null($cnt[0])) + if(!is_null($cnt) and !is_null($cnt[0])) { $this->chunkCount[$cnt[0]] = true; + } } } } } - public function sendEntityMovementUpdateQueue(){ - if($this->entityMovementQueueLength > 0 && $this->entityMovementQueue instanceof RakNetPacket){ + public function sendEntityMovementUpdateQueue() { + if($this->entityMovementQueueLength > 0 && $this->entityMovementQueue instanceof RakNetPacket) { $this->entityMovementQueue->seqNumber = $this->counter[0]++; $this->send($this->entityMovementQueue); } @@ -1261,9 +1268,9 @@ class Player{ $this->entityMovementQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->entityMovementQueue->data = []; } - - public function sendBlockUpdateQueue(){ - if($this->blockUpdateQueueLength > 0 && $this->blockUpdateQueue instanceof RakNetPacket){ + + public function sendBlockUpdateQueue() { + if($this->blockUpdateQueueLength > 0 && $this->blockUpdateQueue instanceof RakNetPacket) { $this->blockUpdateQueue->seqNumber = $this->counter[0]++; $this->recoveryQueue[$this->blockUpdateQueue->seqNumber] = $this->blockUpdateQueue; $this->blockUpdateQueue->sendtime = microtime(true); @@ -1273,8 +1280,8 @@ class Player{ $this->blockUpdateQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->blockUpdateQueue->data = []; } - - public function addBlockUpdateIntoQueue($x, $y, $z, $id, $meta){ + + public function addBlockUpdateIntoQueue($x, $y, $z, $id, $meta) { $packet = new UpdateBlockPacket(); $packet->x = $x; $packet->y = $y; @@ -1282,32 +1289,32 @@ class Player{ $packet->block = $id; $packet->meta = $meta; $packet->encode(); - + $len = 1 + strlen($packet->buffer); $MTU = $this->MTU - 24; - - if(($this->blockUpdateQueueLength + $len) >= $MTU){ + + if(($this->blockUpdateQueueLength + $len) >= $MTU) { $this->sendBlockUpdateQueue(); } - + $packet->messageIndex = $this->counter[3]++; $packet->reliability = 2; @$this->blockUpdateQueue->data[] = $packet; $this->blockUpdateQueueLength += 6 + $len; } - - public function addEntityMovementUpdateToQueue(Entity $e){ + + public function addEntityMovementUpdateToQueue(Entity $e) { $len = 0; $packets = 0; $motionSent = false; $moveSent = false; $headSent = false; $svdYSpeed = $e->speedY; - if($e->modifySpeedY){ + if($e->modifySpeedY) { $e->speedY = $e->modifedSpeedY; } - if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ - if(!($e->speedY < 0 && $e->onGround) || $e->speedX != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ + if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ) { + if(!($e->speedY < 0 && $e->onGround) || $e->speedX != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ) { $motion = new SetEntityMotionPacket(); $motion->eid = $e->eid; $motion->speedX = $e->speedX; @@ -1319,13 +1326,13 @@ class Player{ $motionSent = true; } } - if($e->modifySpeedY){ + if($e->modifySpeedY) { $e->speedY = $svdYSpeed; $e->modifySpeedY = false; } - - if($e->x != $e->lastX || $e->y != $e->lastY || $e->z != $e->lastZ || $e->yaw != $e->lastYaw || $e->pitch != $e->lastPitch){ - if($e->headYaw != $e->lastHeadYaw){ + + if($e->x != $e->lastX || $e->y != $e->lastY || $e->z != $e->lastZ || $e->yaw != $e->lastYaw || $e->pitch != $e->lastPitch) { + if($e->headYaw != $e->lastHeadYaw) { $move = new MovePlayerPacket(); $move->eid = $e->eid; $move->x = $e->x; @@ -1335,7 +1342,7 @@ class Player{ $move->pitch = $e->pitch; $move->bodyYaw = $e->headYaw; $move->encode(); - }else{ + } else { $move = new MoveEntityPacket_PosRot(); $move->eid = $e->eid; $move->x = $e->x; @@ -1345,11 +1352,11 @@ class Player{ $move->pitch = $e->pitch; $move->encode(); } - + $len += strlen($move->buffer) + 1; ++$packets; $moveSent = true; - }else if($e->headYaw != $e->lastHeadYaw){ + } elseif($e->headYaw != $e->lastHeadYaw) { $headyaw = new RotateHeadPacket(); $headyaw->eid = $e->eid; $headyaw->yaw = $e->headYaw; @@ -1358,41 +1365,43 @@ class Player{ ++$packets; $headSent = true; } - if($packets <= 0) return; + if($packets <= 0) { + return; + } //console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent"); $MTU = $this->MTU - 24; - if(($this->entityMovementQueueLength + $len) >= $MTU){ + if(($this->entityMovementQueueLength + $len) >= $MTU) { $this->sendEntityMovementUpdateQueue(); } - if($motionSent){ + if($motionSent) { $motion->messageIndex = 0; //force 0 cuz reliability 0 $motion->reliability = 0; $this->entityMovementQueue->data[] = $motion; } - if($moveSent){ + if($moveSent) { $move->messageIndex = 0; $move->reliability = 0; $this->entityMovementQueue->data[] = $move; } - if($headSent){ + if($headSent) { $headyaw->messageIndex = 0; $headyaw->reliability = 0; $this->entityMovementQueue->data[] = $headyaw; } - - $this->entityMovementQueueLength += 6*$packets + $len; + + $this->entityMovementQueueLength += 6 * $packets + $len; } - + /** * @param string $reason Reason for closing connection * @param boolean $msg Set to false to silently disconnect player. No broadcast. */ - public function close($reason = "", $msg = true){ - if($this->connected === true){ - foreach($this->evid as $ev){ + public function close($reason = "", $msg = true) { + if($this->connected === true) { + foreach($this->evid as $ev) { $this->server->deleteEvent($ev); } - if($this->username != ""){ + if($this->username != "") { $this->server->api->handle("player.quit", $this); $this->save(); } @@ -1410,7 +1419,7 @@ class Player{ $this->resendQueue = []; $this->ackQueue = []; $this->server->api->player->remove($this->CID); - if($msg === true and $this->username != "" and $this->spawned !== false){ + if($msg === true and $this->username != "" and $this->spawned !== false) { $this->server->api->chat->broadcast($this->username . " left the game: " . $reason); } $this->spawned = false; @@ -1427,8 +1436,8 @@ class Player{ } } - public function save(){ - if($this->entity instanceof Entity){ + public function save() { + if($this->entity instanceof Entity) { $this->data->set("achievements", $this->achievements); $this->data->set("position", [ "level" => $this->entity->level->getName(), @@ -1445,9 +1454,9 @@ class Player{ "z" => $this->spawnPosition->z ]); $inv = []; - foreach($this->inventory as $slot => $item){ - if($item instanceof Item){ - if($slot < (($this->gamemode & 0x01) === 0 ? PLAYER_SURVIVAL_SLOTS : PLAYER_CREATIVE_SLOTS)){ + foreach($this->inventory as $slot => $item) { + if($item instanceof Item) { + if($slot < (($this->gamemode & 0x01) === 0 ? PLAYER_SURVIVAL_SLOTS : PLAYER_CREATIVE_SLOTS)) { $inv[$slot] = [$item->getID(), $item->getMetadata(), $item->count]; } } @@ -1456,25 +1465,25 @@ class Player{ $this->data->set("hotbar", $this->hotbar); $armor = []; - foreach($this->armor as $slot => $item){ - if($item instanceof Item){ + foreach($this->armor as $slot => $item) { + if($item instanceof Item) { $armor[$slot] = [$item->getID(), $item->getMetadata()]; } } $this->data->set("armor", $armor); - if($this->entity instanceof Entity){ + if($this->entity instanceof Entity) { $this->data->set("health", $this->entity->getHealth()); } $this->data->set("gamemode", $this->gamemode); } } - public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $recover = true){ - if($this->connected === false){ + public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $recover = true) { + if($this->connected === false) { return false; } - if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ + if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) { return []; } @@ -1483,22 +1492,24 @@ class Player{ $pk->data[] = $packet; $pk->seqNumber = $this->counter[0]++; $pk->sendtime = microtime(true); - if($recover !== false){ + if($recover !== false) { $this->recoveryQueue[$pk->seqNumber] = $pk; } $this->send($pk); return [$pk->seqNumber]; } - public function entityTick(){ - if($this->isSleeping) ++$this->sleepingTime; - - if($this->server->difficulty == 0 && $this->entity->counter % (20 * 15) == 0){ - if($this->entity->health < 20 && $this->entity->health > 0){ + public function entityTick() { + if($this->isSleeping) { + ++$this->sleepingTime; + } + + if($this->server->difficulty == 0 && $this->entity->counter % (20 * 15) == 0) { + if($this->entity->health < 20 && $this->entity->health > 0) { $this->entity->setHealth(min(20, $this->entity->health + 1), "regeneration"); } } - + } public function sendPing() { @@ -1511,21 +1522,21 @@ class Player{ return $this->lastPing; } - public function handleDataPacket(RakNetDataPacket $packet){ - if($this->connected === false){ + public function handleDataPacket(RakNetDataPacket $packet) { + if($this->connected === false) { return; } - if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){ + if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY) { return; } - switch($packet->pid()){ + switch($packet->pid()) { case 0x01: break; case ProtocolInfo::PONG_PACKET: $currentTime = intdiv(hrtime(true), 1_000_000); - if($currentTime > $packet->ptime){ + if($currentTime > $packet->ptime) { $this->lastPing = $currentTime - $packet->ptime; } break; @@ -1539,7 +1550,7 @@ class Player{ $this->close("client disconnect"); break; case ProtocolInfo::CLIENT_CONNECT_PACKET: - if($this->loggedIn === true){ + if($this->loggedIn === true) { break; } $pk = new ServerHandshakePacket; @@ -1549,27 +1560,27 @@ class Player{ $this->dataPacket($pk); break; case ProtocolInfo::CLIENT_HANDSHAKE_PACKET: - if($this->loggedIn === true){ + if($this->loggedIn === true) { break; } break; case ProtocolInfo::LOGIN_PACKET: - if($this->loggedIn === true){ + if($this->loggedIn === true) { break; } $this->username = $packet->username; $this->iusername = strtolower($this->username); $this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData]; - if(count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){ + if(count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)) { $this->close("server is full!", false); return; } - if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ - if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ + if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL) { + if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) { $pk = new LoginStatusPacket; $pk->status = 1; $this->directDataPacket($pk); - }else{ + } else { $pk = new LoginStatusPacket; $pk->status = 2; $this->directDataPacket($pk); @@ -1577,55 +1588,55 @@ class Player{ $this->close("Incorrect protocol #" . $packet->protocol1, false); return; } - if(preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 || $this->username === "" || $this->iusername === "rcon" || $this->iusername === "console" || $this->iusername === "server" || strlen($this->iusername) > 16){ + if(preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 || $this->username === "" || $this->iusername === "rcon" || $this->iusername === "console" || $this->iusername === "server" || strlen($this->iusername) > 16) { $this->close("Bad username", false); return; } - if($this->server->api->handle("player.connect", $this) === false){ + if($this->server->api->handle("player.connect", $this) === false) { $this->close("Unknown reason", false); return; } - if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)){ + if($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)) { $this->close("Server is white-listed", false); return; - }elseif($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)){ + } elseif($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)) { $this->close("You are banned!", false); return; } $this->loggedIn = true; - if(!isset($this->CID) or $this->CID == null){ + if(!isset($this->CID) or $this->CID == null) { console("[DEBUG] Player " . $this->username . " does not have a CID", true, true, 2); $this->CID = Utils::readLong(Utils::getRandomBytes(8, false)); } $u = $this->server->api->player->get($this->iusername, false); - if($u !== false){ + if($u !== false) { $u = $this->server->clients[$this->CID]; $u->close("this player already in game"); } $this->server->api->player->add($this->CID); - if($this->server->api->handle("player.join", $this) === false){ + if($this->server->api->handle("player.join", $this) === false) { $this->close("join cancelled", false); return; } - if(!($this->data instanceof Config)){ + if(!($this->data instanceof Config)) { $this->close("no config created", false); return; } $this->auth = true; - if(!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01){ - if(($this->gamemode & 0x01) === 0x01){ + if(!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01) { + if(($this->gamemode & 0x01) === 0x01) { $inv = []; - if(($this->gamemode & 0x02) === 0x02){ - foreach(BlockAPI::$creative as $item){ + if(($this->gamemode & 0x02) === 0x02) { + foreach(BlockAPI::$creative as $item) { $inv[] = [0, 0, 1]; } - }else{ - foreach(BlockAPI::$creative as $item){ + } else { + foreach(BlockAPI::$creative as $item) { $inv[] = [$item[0], $item[1], 1]; } } @@ -1635,15 +1646,15 @@ class Player{ $this->achievements = $this->data->get("achievements"); $this->data->set("caseusername", $this->username); $this->inventory = []; - foreach($this->data->get("inventory") as $slot => $item){ - if(!is_array($item) or count($item) < 3){ + foreach($this->data->get("inventory") as $slot => $item) { + if(!is_array($item) or count($item) < 3) { $item = [AIR, 0, 0]; } $this->inventory[$slot] = BlockAPI::getItem($item[0], $item[1], $item[2]); } $this->armor = []; - foreach($this->data->get("armor") as $slot => $item){ + foreach($this->data->get("armor") as $slot => $item) { $this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], $item[0] === 0 ? 0 : 1); } @@ -1652,7 +1663,6 @@ class Player{ $this->server->api->player->saveOffline($this->data); - $pk = new LoginStatusPacket; $pk->status = 0; $this->dataPacket($pk); @@ -1667,33 +1677,37 @@ class Player{ $pk->eid = 0; $this->dataPacket($pk); - if(($this->gamemode & 0x01) === 0x01){ + if(($this->gamemode & 0x01) === 0x01) { $this->slot = 0; $this->hotbar = []; - }elseif($this->data->exists("hotbar")){ + } elseif($this->data->exists("hotbar")) { $this->hotbar = $this->data->get("hotbar"); $this->slot = $this->hotbar[0]; - }else{ + } else { $this->slot = 0; $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; } - for($i = 0; $i < count($this->hotbar); ++$i){ - if($this->hotbar[$i] > 36) $this->hotbar[$i] = -1; //XXX unsafe? - if($this->hotbar[$i] < -1) $this->hotbar[$i] = -1; + for($i = 0; $i < count($this->hotbar); ++$i) { + if($this->hotbar[$i] > 36) { + $this->hotbar[$i] = -1; + } //XXX unsafe? + if($this->hotbar[$i] < -1) { + $this->hotbar[$i] = -1; + } } - if($this->data->exists("slot-count")){ + if($this->data->exists("slot-count")) { $this->slotCount = $this->data->get("slot-count"); - }else{ + } else { $this->data->set("slot-count", $this->slotCount); } - + $this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, ["player" => $this]); $this->eid = $this->entity->eid; $this->server->query("UPDATE players SET EID = " . $this->eid . " WHERE CID = " . $this->CID . ";"); $this->entity->x = $this->data->get("position")["x"]; $this->entity->y = $this->data->get("position")["y"]; $this->entity->z = $this->data->get("position")["z"]; - if(($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false){ + if(($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false) { $this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level); $pk = new SetSpawnPositionPacket; @@ -1718,25 +1732,24 @@ class Player{ $this->evid[] = $this->server->event("tile.update", [$this, "eventHandler"]); $this->lastMeasure = microtime(true); $this->server->schedule(50, [$this, "measureLag"], [], true); - + $pk = new SetTimePacket; $pk->time = $this->level->getTime(); $pk->started = !$this->level->isTimeStopped(); $this->dataPacket($pk); - - + console("[INFO] " . FORMAT_AQUA . $this->username . FORMAT_RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->eid . " at (" . $this->entity->level->getName() . ", " . round($this->entity->x, 2) . ", " . round($this->entity->y, 2) . ", " . round($this->entity->z, 2) . ")"); break; case ProtocolInfo::READY_PACKET: - if($this->loggedIn === false){ + if($this->loggedIn === false) { break; } - switch($packet->status){ + switch($packet->status) { case 1: //Spawn!! - if($this->spawned !== false){ + if($this->spawned !== false) { break; } - + $pos = new Position($this->entity->x, $this->entity->y, $this->entity->z, $this->level); $pData = $this->data->get("position"); $this->entity->setHealth($this->data->get("health"), "spawn", true, false); @@ -1750,9 +1763,9 @@ class Player{ //$this->server->schedule(5, [$this->entity, "update"], [], true); //$this->server->schedule(2, [$this->entity, "updateMovement"], [], true); $this->sendArmor(); - $array = explode("@n", (string)$this->server->motd); - foreach($array as $msg){ - $this->sendChat($msg."\n"); + $array = explode("@n", (string) $this->server->motd); + foreach($array as $msg) { + $this->sendChat($msg . "\n"); } $this->sendInventory(); @@ -1768,48 +1781,50 @@ class Player{ } break; case ProtocolInfo::ROTATE_HEAD_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } - if(($this->entity instanceof Entity)){ - if($this->blocked === true or $this->server->api->handle("player.move", $this->entity) === false){ - if($this->lastCorrect instanceof Vector3 && !$this->entity->dead){ + if(($this->entity instanceof Entity)) { + if($this->blocked === true or $this->server->api->handle("player.move", $this->entity) === false) { + if($this->lastCorrect instanceof Vector3 && !$this->entity->dead) { $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); } - }else{ + } else { $this->entity->setPosition($this->entity, $packet->yaw, $this->entity->pitch); } } break; case ProtocolInfo::MOVE_PLAYER_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } - if($this->isSleeping) break; - if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){ + if($this->isSleeping) { + break; + } + if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement) { $this->lastMovement = $packet->messageIndex; $newPos = new Vector3($packet->x, $packet->y, $packet->z); - if($this->forceMovement instanceof Vector3){ - if($this->forceMovement->distance($newPos) <= 0.7){ + if($this->forceMovement instanceof Vector3) { + if($this->forceMovement->distance($newPos) <= 0.7) { $this->forceMovement = false; - }else{ + } else { $this->teleport($this->forceMovement, $this->entity->yaw, $this->entity->pitch, false); break; } } $speed = $this->entity->getSpeedMeasure(); - if($this->blocked === true or ($this->server->api->getProperty("allow-flight") !== true and (($speed > 9 and ($this->gamemode & 0x01) === 0x00) or $speed > 20 or $this->entity->distance($newPos) > 7)) or $this->server->api->handle("player.move", $this->entity) === false){ - if($this->lastCorrect instanceof Vector3 && !$this->entity->dead){ + if($this->blocked === true or ($this->server->api->getProperty("allow-flight") !== true and (($speed > 9 and ($this->gamemode & 0x01) === 0x00) or $speed > 20 or $this->entity->distance($newPos) > 7)) or $this->server->api->handle("player.move", $this->entity) === false) { + if($this->lastCorrect instanceof Vector3 && !$this->entity->dead) { $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); } - }else{ + } else { $this->entity->setPosition($newPos, $packet->yaw, $packet->pitch, $packet->bodyYaw); } $this->entity->updateAABB(); } break; case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } $packet->eid = $this->eid; @@ -1818,79 +1833,84 @@ class Player{ $data["eid"] = $packet->eid; $data["player"] = $this; - if($packet->slot === 0){ + if($packet->slot === 0) { $data["slot"] = -1; $data["item"] = BlockAPI::getItem(AIR, 0, 0); - if($this->server->handle("player.equipment.change", $data) !== false){ + if($this->server->handle("player.equipment.change", $data) !== false) { $this->slot = -1; } break; - }else if($packet->slot > 0){ + } elseif($packet->slot > 0) { $packet->slot -= 9; } - - if(($this->gamemode & 0x01) === SURVIVAL){ + if(($this->gamemode & 0x01) === SURVIVAL) { $data["item"] = $this->getSlot($packet->slot); - if(!($data["item"] instanceof Item)){ + if(!($data["item"] instanceof Item)) { break; } - }elseif(($this->gamemode & 0x01) === CREATIVE){ + } elseif(($this->gamemode & 0x01) === CREATIVE) { $packet->slot = false; - foreach(BlockAPI::$creative as $i => $d){ - if($d[0] === $packet->item and $d[1] === $packet->meta){ + foreach(BlockAPI::$creative as $i => $d) { + if($d[0] === $packet->item and $d[1] === $packet->meta) { $packet->slot = $i; } } - if($packet->slot !== false){ + if($packet->slot !== false) { $data["item"] = $this->getSlot($packet->slot); - }else{ + } else { break; } - }else{ + } else { break;//????? } $data["slot"] = $packet->slot; - if($this->server->handle("player.equipment.change", $data) !== false){ - if(!Player::$experimentalHotbar) $this->slot = $packet->slot; - if(($this->gamemode & 0x01) === SURVIVAL){ + if($this->server->handle("player.equipment.change", $data) !== false) { + if(!Player::$experimentalHotbar) { + $this->slot = $packet->slot; + } + if(($this->gamemode & 0x01) === SURVIVAL) { $has = false; $slotPos = 0; $packetSlotPos = 0; - for($i = 0; $i < $this->slotCount; ++$i){ - if($this->slot == $this->hotbar[$i]) $slotPos = $i; - if($packet->slot == $this->hotbar[$i]){ + for($i = 0; $i < $this->slotCount; ++$i) { + if($this->slot == $this->hotbar[$i]) { + $slotPos = $i; + } + if($packet->slot == $this->hotbar[$i]) { $packetSlotPos = $i; $has = true; break; } } - + if(Player::$experimentalHotbar && $has) { $this->slot = $packet->slot; $this->curHotbarIndex = $packetSlotPos; } - if(!$has){ + if(!$has) { if(Player::$experimentalHotbar) { $this->slot = $packet->slot; $this->hotbar[$this->curHotbarIndex] = $packet->slot; - }else{ + } else { $this->curHotbarIndex = 0; array_pop($this->hotbar); array_unshift($this->hotbar, $this->slot); } } - if(Player::$experimentalHotbar) $this->sendInventory(); - }else{ + if(Player::$experimentalHotbar) { + $this->sendInventory(); + } + } else { $this->slot = $packet->slot; } - }else{ + } else { //$this->sendInventorySlot($packet->slot); $this->sendInventory(); } - if($this->entity->inAction === true){ + if($this->entity->inAction === true) { $this->entity->inAction = false; $this->entity->inActionCounter = 0; $this->entity->updateMetadata(); @@ -1902,13 +1922,13 @@ class Player{ //$this->lastChunk = [$packet->chunkX, $packet->chunkZ]; break; case ProtocolInfo::USE_ITEM_PACKET: - if(!($this->entity instanceof Entity)){ + if(!($this->entity instanceof Entity)) { break; } $blockVector = new Vector3($packet->x, $packet->y, $packet->z); - - if(($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5){ + + if(($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5) { $target = $this->level->getBlock($blockVector); $block = $target->getSide($packet->face); @@ -1948,18 +1968,18 @@ class Player{ $data["posY"] = $packet->posY; $data["posZ"] = $packet->posZ; - if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place - if($this->entity->inAction === true){ + if($packet->face >= 0 and $packet->face <= 5) { //Use Block, place + if($this->entity->inAction === true) { $this->entity->inAction = false; $this->entity->inActionCounter = 0; $this->entity->updateMetadata(); } - if($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 10)){ + if($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 10)) { - }elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){ + } elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)) { $this->sendInventorySlot($this->slot); - }else{ + } else { $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz); break; } @@ -1982,21 +2002,21 @@ class Player{ $pk->meta = $block->getMetadata(); $this->dataPacket($pk); break; - }elseif($packet->face === 0xff){ - + } elseif($packet->face === 0xff) { + $slotItem = $this->getHeldItem(); - if($slotItem->getID() == SNOWBALL || $slotItem->getID() == EGG){ //TODO better way + if($slotItem->getID() == SNOWBALL || $slotItem->getID() == EGG) { //TODO better way $x = $packet->x * 0.000030518; $y = $packet->y * 0.000030518; $z = $packet->z * 0.000030518; - - $d = sqrt($x*$x + $y*$y + $z*$z); - - if($d >= 0.0001){ + + $d = sqrt($x * $x + $y * $y + $z * $z); + + if($d >= 0.0001) { $shootX = $x / $d; $shootY = $y / $d; $shootZ = $z / $d; - + $data = [ "x" => $this->entity->x, "y" => $this->entity->y + $this->entity->getEyeHeight(), @@ -2008,26 +2028,29 @@ class Player{ "shootY" => $shootY, "shootZ" => $shootZ ]; - - if($slotItem->getID() == EGG){ + + if($slotItem->getID() == EGG) { $e = $this->server->api->entity->add($this->entity->level, ENTITY_OBJECT, OBJECT_EGG, $data); - }else{ + } else { $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_SNOWBALL, $data); } - + if(($this->gamemode & 0x01) == 0x0) { - if($slotItem !== false){ - if($slotItem->count == 1) $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0); - else $slotItem->count -= 1; + if($slotItem !== false) { + if($slotItem->count == 1) { + $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0); + } else { + $slotItem->count -= 1; + } //$this->sendInventory(); } } - + $this->server->api->entity->spawnToAll($e); } - - }else{ - if($this->server->handle("player.action", $data) !== false){ + + } else { + if($this->server->handle("player.action", $data) !== false) { $this->entity->inAction = true; $this->entity->inActionCounter = 0; $this->startAction = microtime(true); @@ -2037,29 +2060,31 @@ class Player{ } break; case ProtocolInfo::PLAYER_ACTION_PACKET: - if($this->spawned === false or $this->blocked === true){ + if($this->spawned === false or $this->blocked === true) { break; } $packet->eid = $this->eid; $this->craftingItems = []; $this->toCraft = []; - switch($packet->action){ + switch($packet->action) { case 5: //Shot arrow - if($this->entity->inAction){ + if($this->entity->inAction) { $arrowSlot = $this->hasItem(ARROW); - if($this->getSlot($this->slot)->getID() === BOW && (($this->gamemode & 0x01) == 0x1 || $arrowSlot !== false)){ - if($this->startAction !== false){ + if($this->getSlot($this->slot)->getID() === BOW && (($this->gamemode & 0x01) == 0x1 || $arrowSlot !== false)) { + if($this->startAction !== false) { $initalPower = $this->entity->inActionCounter; $power = $initalPower / 20; $power = ($power * $power + $power * 2) / 3; - if($power >= 0.1){ - if($power > 1) $power = 1; + if($power >= 0.1) { + if($power > 1) { + $power = 1; + } $this->server->dhandle("player.shoot", [ "player" => $this, "power" => &$power, ]); - + $d = [ "x" => $this->entity->x, "y" => $this->entity->y + 1.6, @@ -2083,11 +2108,11 @@ class Player{ * args: xvel, yvel, zvel, (power+power)*1.5, 1.0 */ $e->critical = ($power == 1); - $e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0); + $e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power + $power) * 1.5, 1.0); $this->server->api->entity->spawnToAll($e); if(($this->gamemode & 0x01) == 0x0) { $bow = $this->getSlot($this->slot); - if(++$bow->meta >= $bow->getMaxDurability()){ + if(++$bow->meta >= $bow->getMaxDurability()) { $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0); } $this->removeItem(ARROW, 0, 1, false); @@ -2095,7 +2120,7 @@ class Player{ } } } - }else{ //inv desynced, resend + } else { //inv desynced, resend $this->sendInventory(); } } @@ -2110,7 +2135,7 @@ class Player{ break; case ProtocolInfo::REMOVE_BLOCK_PACKET: $blockVector = new Vector3($packet->x, $packet->y, $packet->z); - if($this->spawned === false or $this->blocked === true or $this->entity->distance($blockVector) > 8){ + if($this->spawned === false or $this->blocked === true or $this->entity->distance($blockVector) > 8) { $target = $this->level->getBlock($blockVector); $pk = new UpdateBlockPacket; @@ -2127,46 +2152,46 @@ class Player{ $this->server->api->block->playerBlockBreak($this, $blockVector); break; case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: - if($this->spawned === false or $this->blocked === true){ + if($this->spawned === false or $this->blocked === true) { break; } $this->craftingItems = []; $this->toCraft = []; $packet->eid = $this->eid; - for($i = 0; $i < 4; ++$i){ + for($i = 0; $i < 4; ++$i) { $s = $packet->slots[$i]; - if($s === 0 or $s === 255){ + if($s === 0 or $s === 255) { $s = BlockAPI::getItem(AIR, 0, 0); - }else{ + } else { $s = BlockAPI::getItem($s + 256, 0, 1); } $slot = $this->armor[$i]; - if($slot->getID() !== AIR and $s->getID() === AIR){ + if($slot->getID() !== AIR and $s->getID() === AIR) { $this->addItem($slot->getID(), $slot->getMetadata(), 1, false); $this->armor[$i] = BlockAPI::getItem(AIR, 0, 0); $packet->slots[$i] = 255; - }elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false){ + } elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false) { $this->armor[$i] = $this->getSlot($sl); $this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0), false); - }elseif($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false){ + } elseif($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false) { $item = $this->armor[$i]; $this->armor[$i] = $this->getSlot($sl); $this->setSlot($sl, $item, false); - }else{ + } else { $packet->slots[$i] = 255; } } $this->sendArmor(); - if($this->entity->inAction === true){ + if($this->entity->inAction === true) { $this->entity->inAction = false; $this->entity->inActionCounter = 0; $this->entity->updateMetadata(); } break; case ProtocolInfo::INTERACT_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } $packet->eid = $this->eid; @@ -2177,36 +2202,36 @@ class Player{ $this->craftingItems = []; $this->toCraft = []; $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){ + 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->entity; $data["player"] = $this; - if($this->server->handle("player.interact", $data) !== false){ + if($this->server->handle("player.interact", $data) !== false) { $target->interactWith($this->entity, $packet->action); } } break; case ProtocolInfo::ANIMATE_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } $packet->eid = $this->eid; $this->server->api->dhandle("entity.animate", ["eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action]); break; case ProtocolInfo::RESPAWN_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } - if(@$this->entity->dead === false){ + if(@$this->entity->dead === false) { break; } $this->craftingItems = []; $this->toCraft = []; - + $this->checkSpawnPosition(); $this->teleport($this->spawnPosition, false, false, true, false); - + $pk = new MovePlayerPacket(); $pk->eid = $this->entity->eid; $pk->x = $this->entity->x; @@ -2215,18 +2240,18 @@ class Player{ $pk->yaw = $this->entity->yaw; $pk->pitch = $this->entity->pitch; $pk->bodyYaw = $this->entity->headYaw; - foreach($this->entity->level->players as $player){ - if($player->entity->eid != $this->entity->eid){ + foreach($this->entity->level->players as $player) { + if($player->entity->eid != $this->entity->eid) { $player->dataPacket(clone $pk); } } - - if($this->entity instanceof Entity){ + + if($this->entity instanceof Entity) { $this->entity->fire = 0; $this->entity->air = $this->entity->maxAir; $this->entity->setHealth(20, "respawn", true); $this->entity->updateMetadata(); - }else{ + } else { break; } $this->sendInventory(); @@ -2236,22 +2261,22 @@ class Player{ case ProtocolInfo::SET_HEALTH_PACKET: //Not used break; case ProtocolInfo::ENTITY_EVENT_PACKET: - if($this->spawned === false or $this->blocked === true){ + if($this->spawned === false or $this->blocked === true) { break; } $this->craftingItems = []; $this->toCraft = []; $packet->eid = $this->eid; - if($this->entity->inAction === true){ + if($this->entity->inAction === true) { $this->entity->inAction = false; $this->entity->inActionCounter = 0; $this->entity->updateMetadata(); } - switch($packet->event){ + switch($packet->event) { case 9: //Eating $slot = $this->getSlot($this->slot); $foodHeal = Item::getFoodHeal($slot->getID()); - if($this->entity->getHealth() < 20 && $foodHeal != 0){ + if($this->entity->getHealth() < 20 && $foodHeal != 0) { $pk = new EntityEventPacket; $pk->eid = 0; $pk->event = 9; @@ -2259,10 +2284,10 @@ class Player{ $this->entity->heal($foodHeal, "eating"); --$slot->count; - if($slot->count <= 0){ + if($slot->count <= 0) { $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); } - if($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP){ + if($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP) { $this->addItem(BOWL, 0, 1, false); } } @@ -2270,43 +2295,45 @@ class Player{ } break; case ProtocolInfo::DROP_ITEM_PACKET: - if($this->spawned === false or $this->blocked === true){ + if($this->spawned === false or $this->blocked === true) { break; } - - if($this->gamemode & 0x01 == 1){ + + if($this->gamemode & 0x01 == 1) { ConsoleAPI::warn("{$this->iusername} tried dropping item while in creative!"); return; } - + $packet->eid = $this->eid; $prevItem = $packet->item; $packet->item = $this->getSlot($this->slot); $sendOnDrop = false; - - if($prevItem->getID() != $packet->item->getID() || $prevItem->getMetadata() != $packet->item->getMetadata()){ - if(count($this->inventory) >= 36){ - foreach($this->inventory as $slot => $item){ - if($item->getID() == 0) goto inv_desync_on_drop; + + if($prevItem->getID() != $packet->item->getID() || $prevItem->getMetadata() != $packet->item->getMetadata()) { + if(count($this->inventory) >= 36) { + foreach($this->inventory as $slot => $item) { + if($item->getID() == 0) { + goto inv_desync_on_drop; + } } - + $this->toCraft[] = $prevItem; //vanilla drops only result? $this->lastCraft = microtime(true); break; - }else{ + } else { inv_desync_on_drop: ConsoleAPI::debug("Inventory desync on drop({$this->iusername})"); $sendOnDrop = true; } } - + $this->craftingItems = []; $this->toCraft = []; $data["eid"] = $packet->eid; $data["unknown"] = $packet->unknown; $data["item"] = $packet->item; $data["player"] = $this; - if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){ + 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; @@ -2319,46 +2346,46 @@ class Player{ $sZ += sin($f3) * $f1; $this->server->api->entity->dropRawPos($this->level, $this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $packet->item, $sX, $sY, $sZ); $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), $sendOnDrop); - }else{ + } else { $this->sendInventory(); //send if blocked } - if($this->entity->inAction === true){ + if($this->entity->inAction === true) { $this->entity->inAction = false; $this->entity->inActionCounter = 0; $this->entity->updateMetadata(); } break; case ProtocolInfo::MESSAGE_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } $this->craftingItems = []; $this->toCraft = []; - if(trim($packet->message) != "" and strlen($packet->message) <= 255){ + if(trim($packet->message) != "" and strlen($packet->message) <= 255) { $message = $packet->message; - if($message[0] === "/"){ //Command - if($this instanceof Player){ + if($message[0] === "/") { //Command + if($this instanceof Player) { console("[DEBUG] " . FORMAT_AQUA . $this->username . FORMAT_RESET . " issued server command: " . $message); - }else{ + } else { console("[DEBUG] " . FORMAT_YELLOW . "*" . $this . FORMAT_RESET . " issued server command: " . $message); } $this->server->api->console->run(substr($message, 1), $this); - }else{ + } else { $data = ["player" => $this, "message" => $message]; - if(Utils::hasEmoji($data["message"])){ + if(Utils::hasEmoji($data["message"])) { $this->sendChat("Your message contains illegal characters"); break; } - + //if($message == "pf"){ // Living::$pathfind = !Living::$pathfind; //} - - if($this->server->api->handle("player.chat", $data) !== false){ + + if($this->server->api->handle("player.chat", $data) !== false) { $this->server->send2Discord("<" . $this->username . "> " . $message); - if(isset($data["message"])){ + if(isset($data["message"])) { $this->server->api->chat->send($this, $data["message"]); - }else{ + } else { $this->server->api->chat->send($this, $message); } } @@ -2366,14 +2393,14 @@ class Player{ } break; case ProtocolInfo::CONTAINER_CLOSE_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } $this->craftingItems = []; $this->toCraft = []; - if(isset($this->windows[$packet->windowid])){ - if(is_array($this->windows[$packet->windowid])){ - foreach($this->windows[$packet->windowid] as $ob){ + if(isset($this->windows[$packet->windowid])) { + if(is_array($this->windows[$packet->windowid])) { + foreach($this->windows[$packet->windowid] as $ob) { $pk = new TileEventPacket; $pk->x = $ob->x; $pk->y = $ob->y; @@ -2382,7 +2409,7 @@ class Player{ $pk->case2 = 0; $this->server->api->player->broadcastPacket($this->level->players, $pk); } - }elseif($this->windows[$packet->windowid]->class === TILE_CHEST){ + } elseif($this->windows[$packet->windowid]->class === TILE_CHEST) { $pk = new TileEventPacket; $pk->x = $this->windows[$packet->windowid]->x; $pk->y = $this->windows[$packet->windowid]->y; @@ -2399,36 +2426,36 @@ class Player{ $this->dataPacket($pk); break; case ProtocolInfo::CONTAINER_SET_SLOT_PACKET: - if($this->spawned === false or $this->blocked === true){ + if($this->spawned === false or $this->blocked === true) { break; } - if($this->lastCraft <= (microtime(true) - 1)){ - if(isset($this->toCraft[-1])){ + if($this->lastCraft <= (microtime(true) - 1)) { + if(isset($this->toCraft[-1])) { $this->toCraft = [-1 => $this->toCraft[-1]]; - }else{ + } else { $this->toCraft = []; } $this->craftingItems = []; } - if($packet->windowid === 0){ + if($packet->windowid === 0) { $craft = false; $slot = $this->getSlot($packet->slot); - if($slot->count >= $packet->item->count and (($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()) or ($packet->item->getID() === AIR and $packet->item->count === 0)) and !isset($this->craftingItems[$packet->slot])){ //Crafting recipe + if($slot->count >= $packet->item->count and (($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()) or ($packet->item->getID() === AIR and $packet->item->count === 0)) and !isset($this->craftingItems[$packet->slot])) { //Crafting recipe $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count - $packet->item->count); $this->craftingItems[$packet->slot] = $use; $craft = true; - }elseif($slot->count <= $packet->item->count and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))){ //Crafting final + } elseif($slot->count <= $packet->item->count and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))) { //Crafting final $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count - $slot->count); - if(count($this->toCraft) === 0){ + if(count($this->toCraft) === 0) { $this->toCraft[-1] = 0; } $this->toCraft[$packet->slot] = $craftItem; $craft = true; - }elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->count > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())){ //Crafting final + } elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->count > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())) { //Crafting final $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); - if(count($this->toCraft) === 0){ + if(count($this->toCraft) === 0) { $this->toCraft[-1] = 0; } $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count); @@ -2437,38 +2464,38 @@ class Player{ $craft = true; } - if($craft === true){ + if($craft === true) { $this->lastCraft = microtime(true); } - if($craft === true and count($this->craftingItems) > 0 and count($this->toCraft) > 0 and ($recipe = $this->craftItems($this->toCraft, $this->craftingItems, $this->toCraft[-1])) !== true){ - if($recipe === false){ + if($craft === true and count($this->craftingItems) > 0 and count($this->toCraft) > 0 and ($recipe = $this->craftItems($this->toCraft, $this->craftingItems, $this->toCraft[-1])) !== true) { + if($recipe === false) { $this->sendInventory(); $this->toCraft = []; - }else{ + } else { $this->toCraft = [-1 => $this->toCraft[-1]]; } $this->craftingItems = []; } - }else{ + } else { $this->toCraft = []; $this->craftingItems = []; } - if(!isset($this->windows[$packet->windowid])){ + if(!isset($this->windows[$packet->windowid])) { break; } - if(is_array($this->windows[$packet->windowid])){ + if(is_array($this->windows[$packet->windowid])) { $tiles = $this->windows[$packet->windowid]; - if($packet->slot >= 0 and $packet->slot < CHEST_SLOTS){ + if($packet->slot >= 0 and $packet->slot < CHEST_SLOTS) { $tile = $tiles[0]; $slotn = $packet->slot; $offset = 0; - }elseif($packet->slot >= CHEST_SLOTS and $packet->slot <= (CHEST_SLOTS << 1)){ + } elseif($packet->slot >= CHEST_SLOTS and $packet->slot <= (CHEST_SLOTS << 1)) { $tile = $tiles[1]; $slotn = $packet->slot - CHEST_SLOTS; $offset = CHEST_SLOTS; - }else{ + } else { break; } @@ -2476,13 +2503,13 @@ class Player{ $slot = $tile->getSlot($slotn); if($this->server->api->dhandle("player.container.slot", [ - "tile" => $tile, - "slot" => $packet->slot, - "offset" => $offset, - "slotdata" => $slot, - "itemdata" => $item, - "player" => $this - ]) === false){ + "tile" => $tile, + "slot" => $packet->slot, + "offset" => $offset, + "slotdata" => $slot, + "itemdata" => $item, + "player" => $this + ]) === false) { $pk = new ContainerSetSlotPacket; $pk->windowid = $packet->windowid; $pk->slot = $packet->slot; @@ -2490,37 +2517,37 @@ class Player{ $this->dataPacket($pk); break; } - - if($item->getID() !== AIR and $slot->getID() == $item->getID()){ - if($slot->count < $item->count){ - if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ + + if($item->getID() !== AIR and $slot->getID() == $item->getID()) { + if($slot->count < $item->count) { + if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false) { break; } - }elseif($slot->count > $item->count){ + } elseif($slot->count > $item->count) { $this->addItem($item->getID(), $item->getMetadata(), $slot->count - $item->count, false); } - }else{ - if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){ + } else { + if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false) { break; } $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); } $tile->setSlot($slotn, $item, true, $offset); - }else{ + } else { $tile = $this->windows[$packet->windowid]; - if(($tile->class !== TILE_CHEST and $tile->class !== TILE_FURNACE) or $packet->slot < 0 or ($tile->class === TILE_CHEST and $packet->slot >= CHEST_SLOTS) or ($tile->class === TILE_FURNACE and $packet->slot >= FURNACE_SLOTS)){ + if(($tile->class !== TILE_CHEST and $tile->class !== TILE_FURNACE) or $packet->slot < 0 or ($tile->class === TILE_CHEST and $packet->slot >= CHEST_SLOTS) or ($tile->class === TILE_FURNACE and $packet->slot >= FURNACE_SLOTS)) { break; } $item = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); $slot = $tile->getSlot($packet->slot); if($this->server->api->dhandle("player.container.slot", [ - "tile" => $tile, - "slot" => $packet->slot, - "slotdata" => $slot, - "itemdata" => $item, - "player" => $this, - ]) === false){ + "tile" => $tile, + "slot" => $packet->slot, + "slotdata" => $slot, + "itemdata" => $item, + "player" => $this, + ]) === false) { $pk = new ContainerSetSlotPacket; $pk->windowid = $packet->windowid; $pk->slot = $packet->slot; @@ -2529,24 +2556,24 @@ class Player{ break; } - if($tile->class === TILE_FURNACE and $packet->slot == 2){ - switch($slot->getID()){ + if($tile->class === TILE_FURNACE and $packet->slot == 2) { + switch($slot->getID()) { case IRON_INGOT: AchievementAPI::grantAchievement($this, "acquireIron"); break; } } - if($item->getID() !== AIR and $slot->getID() == $item->getID()){ - if($slot->count < $item->count){ - if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ + if($item->getID() !== AIR and $slot->getID() == $item->getID()) { + if($slot->count < $item->count) { + if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false) { break; } - }elseif($slot->count > $item->count){ + } elseif($slot->count > $item->count) { $this->addItem($item->getID(), $item->getMetadata(), $slot->count - $item->count, false); } - }else{ - if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){ + } else { + if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false) { break; } $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); @@ -2556,27 +2583,27 @@ class Player{ } break; case ProtocolInfo::SEND_INVENTORY_PACKET: - if($this->spawned === false){ + if($this->spawned === false) { break; } break; case ProtocolInfo::ENTITY_DATA_PACKET: - if($this->spawned === false or $this->blocked === true){ + if($this->spawned === false or $this->blocked === true) { break; } $this->craftingItems = []; $this->toCraft = []; $t = $this->server->api->tile->get(new Position($packet->x, $packet->y, $packet->z, $this->level)); - if(($t instanceof Tile) and $t->class === TILE_SIGN){ - if($t->data["creator"] !== $this->username){ + if(($t instanceof Tile) and $t->class === TILE_SIGN) { + if($t->data["creator"] !== $this->username) { $t->spawn($this); - }else{ + } else { $nbt = new NBT(); $nbt->load($packet->namedtag); $d = array_shift($nbt->tree); - if($d["id"] !== TILE_SIGN){ + if($d["id"] !== TILE_SIGN) { $t->spawn($this); - }else{ + } else { $t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]); } } @@ -2587,12 +2614,12 @@ class Player{ $this->isSneaking = $packet->isSneaking; $this->entity->moveForward = $packet->moveForward; $this->entity->moveStrafing = $packet->moveStrafe; - - if(strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity != 0){ + + if(strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity != 0) { $this->entity->stopRiding(); break; } - if($this->entity->linkedEntity != 0){ //TODO better riding + if($this->entity->linkedEntity != 0) { //TODO better riding $e = $this->entity->level->entityList[$this->entity->linkedEntity] ?? false; if($e === false) { ConsoleAPI::warn("Player is riding on entity that doesnt exist in world! ({$this->iusername}, {$this->entity->linkedEntity})"); @@ -2612,58 +2639,58 @@ class Player{ console("{$e} {$this->entity}"); //$this->entity->linkedEntity->moveFlying($packet->moveStrafe, $packet->moveForward, 1);*/ } - + break; 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(){ + + public function getHeldItem() { return $this->getSlot($this->slot); } - - public function stopSleep(){ + + public function stopSleep() { $this->isSleeping = false; $this->sleepingTime = 0; - if($this->entity instanceof Entity){ + if($this->entity instanceof Entity) { $this->entity->updateMetadata(); } } - public function hasItem($type, $damage = false){ - foreach($this->inventory as $s => $item){ - if($item->getID() === $type and ($item->getMetadata() === $damage or $damage === false) and $item->count > 0){ + public function hasItem($type, $damage = false) { + foreach($this->inventory as $s => $item) { + if($item->getID() === $type and ($item->getMetadata() === $damage or $damage === false) and $item->count > 0) { return $s; } } return false; } - public function removeItem($type, $damage, $count, $send = true){ - while($count > 0){ + public function removeItem($type, $damage, $count, $send = true) { + while($count > 0) { $remove = 0; - foreach($this->inventory as $s => $item){ - if($item->getID() === $type and $item->getMetadata() === $damage){ + foreach($this->inventory as $s => $item) { + if($item->getID() === $type and $item->getMetadata() === $damage) { $remove = min($count, $item->count); - if($remove < $item->count){ + if($remove < $item->count) { $item->count -= $remove; - }else{ + } else { $this->inventory[$s] = BlockAPI::getItem(AIR, 0, 0); } - if($send === true){ + if($send === true) { $this->sendInventorySlot($s); } break; } } - if($remove <= 0){ + if($remove <= 0) { return false; } $count -= $remove; @@ -2672,22 +2699,19 @@ class Player{ } /** - * @param array $craft - * @param array $recipe - * @param $type * * @return array|bool */ - public function craftItems(array $craft, array $recipe, $type){ + public function craftItems(array $craft, array $recipe, $type) { $craftItem = [0, true, 0]; unset($craft[-1]); - - foreach($craft as $slot => $item){ - if($item instanceof Item){ + + foreach($craft as $slot => $item) { + if($item instanceof Item) { $craftItem[0] = $item->getID(); - if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true){ + if($item->getMetadata() !== $craftItem[1] and $craftItem[1] !== true) { $craftItem[1] = false; - }else{ + } else { $craftItem[1] = $item->getMetadata(); } $craftItem[2] += $item->count; @@ -2696,11 +2720,11 @@ class Player{ } $recipeItems = []; - foreach($recipe as $slot => $item){ - if(!isset($recipeItems[$item->getID()])){ + foreach($recipe as $slot => $item) { + if(!isset($recipeItems[$item->getID()])) { $recipeItems[$item->getID()] = [$item->getID(), $item->getMetadata(), $item->count]; - }else{ - if($item->getMetadata() !== $recipeItems[$item->getID()][1]){ + } else { + if($item->getMetadata() !== $recipeItems[$item->getID()][1]) { $recipeItems[$item->getID()][1] = false; } $recipeItems[$item->getID()][2] += $item->count; @@ -2709,31 +2733,31 @@ class Player{ $res = CraftingRecipes::canCraft($craftItem, $recipeItems, $type); - if(!is_array($res) and $type === 1){ + if(!is_array($res) and $type === 1) { $res2 = CraftingRecipes::canCraft($craftItem, $recipeItems, 0); - if(is_array($res2)){ + if(is_array($res2)) { $res = $res2; } } - if(is_array($res)){ - if($this->server->api->dhandle("player.craft", ["player" => $this, "recipe" => $recipe, "craft" => $craft, "type" => $type]) === false){ + if(is_array($res)) { + if($this->server->api->dhandle("player.craft", ["player" => $this, "recipe" => $recipe, "craft" => $craft, "type" => $type]) === false) { return false; } - foreach($recipe as $slot => $item){ + foreach($recipe as $slot => $item) { $s = $this->getSlot($slot); $s->count -= $item->count; - if($s->count <= 0){ + if($s->count <= 0) { $this->setSlot($slot, BlockAPI::getItem(AIR, 0, 0), false); } } - foreach($craft as $slot => $item){ + foreach($craft as $slot => $item) { $s = $this->getSlot($slot); - if($s->count <= 0 or $s->getID() === AIR){ + if($s->count <= 0 or $s->getID() === AIR) { $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $item->count), false); - }else if($s->getID() == $item->getID() && $s->getMetadata() == $item->getMetadata() && ($s->count + $item->count) <= $s->getMaxStackSize()){ + } elseif($s->getID() == $item->getID() && $s->getMetadata() == $item->getMetadata() && ($s->count + $item->count) <= $s->getMaxStackSize()) { $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->count + $item->count), false); - }else{ + } else { $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; @@ -2746,10 +2770,10 @@ class Player{ $sZ += sin($f3) * $f1; $this->server->api->entity->dropRawPos($this->level, $this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $item, $sX, $sY, $sZ); } - + $this->sendInventory(); //force send on crafting - - switch($item->getID()){ + + switch($item->getID()) { case WORKBENCH: AchievementAPI::grantAchievement($this, "buildWorkBench"); break; @@ -2788,26 +2812,26 @@ class Player{ return $res; } - public function handlePacket(RakNetPacket $packet){ - if($this->connected === true){ + public function handlePacket(RakNetPacket $packet) { + if($this->connected === true) { $time = microtime(true); $this->timeout = $time + 20; - switch($packet->pid()){ + switch($packet->pid()) { case RakNetInfo::NACK: - foreach($packet->packets as $count){ - if(isset($this->recoveryQueue[$count])){ - $this->resendQueue[$count] =& $this->recoveryQueue[$count]; + foreach($packet->packets as $count) { + if(isset($this->recoveryQueue[$count])) { + $this->resendQueue[$count] = &$this->recoveryQueue[$count]; $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); - }else{ + } else { ++$this->packetStats[1]; //lost and wont be recovered } } break; case RakNetInfo::ACK: - foreach($packet->packets as $count){ - if(isset($this->recoveryQueue[$count])){ + foreach($packet->packets as $count) { + if(isset($this->recoveryQueue[$count])) { $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); unset($this->resendQueue[$count]); @@ -2834,7 +2858,7 @@ class Player{ case RakNetInfo::DATA_PACKET_F: $this->ackQueue[] = $packet->seqNumber; $this->receiveQueue[$packet->seqNumber] = []; - foreach($packet->data as $pk){ + foreach($packet->data as $pk) { $this->receiveQueue[$packet->seqNumber][] = $pk; } break; @@ -2842,9 +2866,9 @@ class Player{ } } - public function damageArmorPart($slot, $part){ + public function damageArmorPart($slot, $part) { $part->useOn($this->entity, true); - if($part->getMetadata() >= $part->getMaxDurability()){ + if($part->getMetadata() >= $part->getMaxDurability()) { $this->setArmor($slot, BlockAPI::getItem(AIR, 0, 0), false); return; } @@ -2854,8 +2878,8 @@ class Player{ /** * @return string */ - function __toString(){ - if($this->username != ""){ + public function __toString() { + if($this->username != "") { return $this->username; } return $this->clientID; @@ -2863,9 +2887,9 @@ class Player{ } -class PlayerNull extends Player{ +class PlayerNull extends Player { public static $INSTANCE; - public function __construct(){ + public function __construct() { } } diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 1b281cfc..ae369d6e 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -1,18 +1,69 @@ port = (int) $port; $this->doTick = true; $this->gamemode = (int) $gamemode; @@ -23,11 +74,10 @@ class PocketMinecraftServer{ $this->serverip = $serverip; $this->load(); } - + public static $SAVE_PLAYER_DATA = true; - - - private function load(){ + + private function load() { global $dolog; /*if(defined("DEBUG") and DEBUG >= 0){ @cli_set_process_title("NostalgiaCore ".MAJOR_VERSION); @@ -70,7 +120,7 @@ class PocketMinecraftServer{ $this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip); $this->stop = false; $this->ticks = 0; - if(!defined("NO_THREADS")){ + if(!defined("NO_THREADS")) { $this->asyncThread = new AsyncMultipleQueue(); } console("[INFO] Loading extra.properties..."); @@ -85,10 +135,10 @@ class PocketMinecraftServer{ "discord-ru-smiles" => false, "discord-webhook-url" => "none", "discord-bot-name" => "NostalgiaCore Logger", - "despawn-mobs" => true, + "despawn-mobs" => true, "mob-despawn-ticks" => 18000, "16x16x16_chunk_sending" => false, - "experimental-mob-ai" => false, + "experimental-mob-ai" => false, "force-20-tps" => false, "enable-mob-pushing" => Living::$entityPushing, "keep-chunks-loaded" => self::$KEEP_CHUNKS_LOADED, @@ -107,24 +157,24 @@ class PocketMinecraftServer{ MobController::$ADVANCED = $this->extraprops->get("experimental-mob-ai"); Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor"); - if(self::$FORCE_20_TPS){ + if(self::$FORCE_20_TPS) { ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!"); } - if($this->extraprops->get("discord-msg")){ - if($this->extraprops->get("discord-webhook-url") !== "none"){ + if($this->extraprops->get("discord-msg")) { + if($this->extraprops->get("discord-webhook-url") !== "none") { console("[INFO] Discord Logger is enabled."); - }else{ + } else { console("[WARNING] Discord Logger is enabled in extra.properties,"); console("[WARNING] but you didn't put the webhook url, so it won't work."); } - }elseif($this->extraprops->get("version") == null){ + } elseif($this->extraprops->get("version") == null) { console("[WARNING] Your extra.properties file is corrupted!"); console("[WARNING] To fix it - just remove it! Server will generate it again automatically."); } $dolog = $this->extraprops->get("save-console-data"); } - public function onShutdown(){ + public function onShutdown() { console("[INFO] Saving..."); $save = $this->saveEnabled; $this->saveEnabled = true; @@ -132,7 +182,7 @@ class PocketMinecraftServer{ $this->saveEnabled = $save; } - public function startDatabase(){ + public function startDatabase() { $this->preparedSQL = new stdClass(); $this->preparedSQL->entity = new stdClass(); $this->database = new SQLite3(":memory:"); @@ -154,16 +204,16 @@ class PocketMinecraftServer{ $this->preparedSQL->entity->setLevel = $this->database->prepare("UPDATE entities SET level = :level WHERE EID = :eid ;"); } - public function query($sql, $fetch = false){ + public function query($sql, $fetch = false) { $result = $this->database->query($sql) or console("[ERROR] [SQL Error] " . $this->database->lastErrorMsg() . ". Query: " . $sql, true, true, 0); - if($fetch === true and ($result instanceof SQLite3Result)){ + if($fetch === true and ($result instanceof SQLite3Result)) { $result = $result->fetchArray(SQLITE3_ASSOC); } return $result; } - public function setType($type = "normal"){ - switch(trim(strtolower($type))){ + public function setType($type = "normal") { + switch(trim(strtolower($type))) { case "normal": case "demo": $this->serverType = "MCCPP;Demo;"; @@ -174,9 +224,9 @@ class PocketMinecraftServer{ } } - public function titleTick(){ + public function titleTick() { $time = microtime(true); - if(defined("DEBUG") and DEBUG >= 0){ + if(defined("DEBUG") and DEBUG >= 0) { //echo "\x1b]0;NostalgiaCore " . MAJOR_VERSION . " | Online " . count($this->clients) . "/" . $this->maxClients . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "MB | U " . round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " D " . round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " kB/s | TPS " . $this->getTPS() . "\x07"; } @@ -186,18 +236,18 @@ class PocketMinecraftServer{ /** * @return float */ - public function getTPS(){ + public function getTPS() { $v = array_values($this->tickMeasure); $divval = ($v[39] - $v[0]); - if($divval === 0){ + if($divval === 0) { return 0; } $tps = 40 / $divval; return round($tps, 4); } - public function checkTicks(){ - if($this->getTPS() < 12){ + public function checkTicks() { + if($this->getTPS() < 12) { console("[WARNING] Can't keep up! Is the server overloaded?"); } } @@ -205,14 +255,14 @@ class PocketMinecraftServer{ /** * @param string $reason */ - public function close($reason = "server stop"){ + public function close($reason = "server stop") { $this->onShutdown(); - if($this->stop !== true){ - if(is_int($reason)){ + if($this->stop !== true) { + if(is_int($reason)) { $reason = "signal stop"; } - if(($this->api instanceof ServerAPI) === true){ - if(($this->api->chat instanceof ChatAPI) === true){ + if(($this->api instanceof ServerAPI) === true) { + if(($this->api->chat instanceof ChatAPI) === true) { $this->api->chat->send(false, "Stopping server..."); self::$_tmp = new StopMessageThread($this, "[INFO] Stopping server..."); //broadcast didnt want to send message to discord for some reason } @@ -220,8 +270,8 @@ class PocketMinecraftServer{ $this->stop = true; $this->trigger("server.close", $reason); $this->interface->close(); - if(!defined("NO_THREADS")){ - $this->asyncThread->synchronized(function ($t){ + if(!defined("NO_THREADS")) { + $this->asyncThread->synchronized(function ($t) { $t->stop = true; $t->notify(); }, $this->asyncThread); @@ -229,9 +279,9 @@ class PocketMinecraftServer{ } release_lock(); } - - public function send2Discord($msg){ - if($this->extraprops->get("discord-msg") and $this->extraprops->get("discord-webhook-url") !== "none"){ + + public function send2Discord($msg) { + if($this->extraprops->get("discord-msg") and $this->extraprops->get("discord-webhook-url") !== "none") { $url = $this->extraprops->get("discord-webhook-url"); $name = $this->extraprops->get("discord-bot-name"); $this->asyncOperation(ASYNC_CURL_POST, [ @@ -243,16 +293,16 @@ class PocketMinecraftServer{ ], null); } } - - public function asyncOperation($type, array $data, callable $callable = null){ - if(defined("NO_THREADS")){ + + public function asyncOperation($type, array $data, callable $callable = null) { + if(defined("NO_THREADS")) { return false; } $d = ""; $type = (int) $type; - switch($type){ + switch($type) { case ASYNC_CURL_GET: - if(isset($data["headers"])){ + if(isset($data["headers"])) { $jsstr = json_encode($data["headers"]); } $d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10)) . (isset($data["headers"]) ? Utils::writeShort(strlen($jsstr)) . $jsstr : Utils::writeShort(1) . " "); @@ -260,7 +310,7 @@ class PocketMinecraftServer{ case ASYNC_CURL_POST: $d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10)); $d .= Utils::writeShort(count($data["data"])); - foreach($data["data"] as $key => $value){ + foreach($data["data"] as $key => $value) { $d .= Utils::writeShort(strlen($key)) . $key . Utils::writeInt(strlen($value)) . $value; } break; @@ -273,55 +323,55 @@ class PocketMinecraftServer{ return $ID; } - public function trigger($event, $data = ""){ - if(isset($this->events[$event])){ - foreach($this->events[$event] as $evid => $ev){ - if(!is_callable($ev)){ + public function trigger($event, $data = "") { + if(isset($this->events[$event])) { + foreach($this->events[$event] as $evid => $ev) { + if(!is_callable($ev)) { $this->deleteEvent($evid); continue; } - if(is_array($ev)){ + if(is_array($ev)) { $method = $ev[1]; $ev[0]->$method($data, $event); - }else{ + } else { $ev($data, $event); } } - }elseif(isset(Deprecation::$events[$event])){ + } elseif(isset(Deprecation::$events[$event])) { $sub = ""; - if(Deprecation::$events[$event] !== false){ + if(Deprecation::$events[$event] !== false) { $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found."; } console("[ERROR] Event \"$event\" has been deprecated.$sub [Trigger]"); } } - public function deleteEvent($id){ + public function deleteEvent($id) { $id = (int) $id; - if(isset($this->eventsID[$id])){ + if(isset($this->eventsID[$id])) { $ev = $this->eventsID[$id]; $this->eventsID[$id] = null; unset($this->eventsID[$id]); $this->events[$ev][$id] = null; unset($this->events[$ev][$id]); - if(count($this->events[$ev]) === 0){ + if(count($this->events[$ev]) === 0) { unset($this->events[$ev]); } } } - public function asyncOperationChecker(){ - if(defined("NO_THREADS")){ + public function asyncOperationChecker() { + if(defined("NO_THREADS")) { return false; } - if(isset($this->asyncThread->output[5])){ + if(isset($this->asyncThread->output[5])) { $offset = 0; $ID = Utils::readInt(substr($this->asyncThread->output, $offset, 4)); $offset += 4; $type = Utils::readShort(substr($this->asyncThread->output, $offset, 2)); $offset += 2; $data = []; - switch($type){ + switch($type) { case ASYNC_CURL_GET: case ASYNC_CURL_POST: $len = Utils::readInt(substr($this->asyncThread->output, $offset, 4)); @@ -333,11 +383,11 @@ class PocketMinecraftServer{ } $this->asyncThread->output = substr($this->asyncThread->output, $offset); - if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){ - if(is_array($this->async[$ID])){ + if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])) { + if(is_array($this->async[$ID])) { $method = $this->async[$ID][1]; $result = $this->async[$ID][0]->$method($data, $type, $ID); - }else{ + } else { $result = $this->async[$ID]($data, $type, $ID); } } @@ -347,17 +397,16 @@ class PocketMinecraftServer{ /** * @param string $event - * @param callable $callable * @param integer $priority * * @return boolean */ - public function addHandler($event, callable $callable, $priority = 5){ - if(!is_callable($callable)){ + public function addHandler($event, callable $callable, $priority = 5) { + if(!is_callable($callable)) { return false; - }elseif(isset(Deprecation::$events[$event])){ + } elseif(isset(Deprecation::$events[$event])) { $sub = ""; - if(Deprecation::$events[$event] !== false){ + if(Deprecation::$events[$event] !== false) { $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found."; } console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to " . (is_array($callable) ? get_class($callable[0]) . "::" . $callable[1] : $callable) . "]"); @@ -370,77 +419,77 @@ class PocketMinecraftServer{ return $hnid; } - public function dhandle($e, $d){ + public function dhandle($e, $d) { return $this->handle($e, $d); } - public function handle($event, &$data){ + public function handle($event, &$data) { $this->preparedSQL->selectHandlers->reset(); $this->preparedSQL->selectHandlers->clear(); $this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT); $handlers = $this->preparedSQL->selectHandlers->execute(); $result = null; - if($handlers instanceof SQLite3Result){ + if($handlers instanceof SQLite3Result) { $call = []; - while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){ + while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false) { $call[(int) $hn["ID"]] = true; } $handlers->finalize(); - foreach($call as $hnid => $boolean){ - if($result !== false and $result !== true){ + foreach($call as $hnid => $boolean) { + if($result !== false and $result !== true) { $called[$hnid] = true; $handler = $this->handlers[$hnid]; - if(is_array($handler)){ + if(is_array($handler)) { $method = $handler[1]; $result = $handler[0]->$method($data, $event); - }else{ + } else { $result = $handler($data, $event); } - }else{ + } else { break; } } - }elseif(isset(Deprecation::$events[$event])){ + } elseif(isset(Deprecation::$events[$event])) { $sub = ""; - if(Deprecation::$events[$event] !== false){ + if(Deprecation::$events[$event] !== false) { $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found."; } console("[ERROR] Event \"$event\" has been deprecated.$sub [Handler]"); } - if($result !== false){ + if($result !== false) { $this->trigger($event, $data); } return $result; } - public function eventHandler($data, $event){ - switch($event){ + public function eventHandler($data, $event) { + switch($event) { } } - public function init(){ + public function init() { register_tick_function([$this, "tick"]); declare(ticks=5000); //Minimum TPS for main thread locks $this->loadEvents(); register_shutdown_function([$this, "dumpError"]); register_shutdown_function([$this, "close"]); - if(function_exists("pcntl_signal")){ + if(function_exists("pcntl_signal")) { pcntl_signal(SIGTERM, [$this, "close"]); pcntl_signal(SIGINT, [$this, "close"]); pcntl_signal(SIGHUP, [$this, "close"]); } - + console("[INFO] Default game type: " . strtoupper($this->getGamemode())); $this->trigger("server.start", microtime(true)); console('[INFO] Done (' . round(microtime(true) - START_TIME, 3) . 's)! For help, type "help" or "?"'); $this->process(); } - public function loadEvents(){ - if(ENABLE_ANSI === true){ + public function loadEvents() { + if(ENABLE_ANSI === true) { $this->schedule(30, [$this, "titleTick"], [], true); } $this->schedule(20 * 15, [$this, "checkTicks"], [], true); @@ -448,11 +497,11 @@ class PocketMinecraftServer{ $this->schedule(20, [$this, "asyncOperationChecker"], [], true); } - public function schedule($ticks, callable $callback, $data = [], $repeat = false, $eventName = "server.schedule"){ - if(!is_callable($callback)){ + public function schedule($ticks, callable $callback, $data = [], $repeat = false, $eventName = "server.schedule") { + if(!is_callable($callback)) { return false; } - + $chcnt = $this->scheduleCnt++; $this->schedule[$chcnt] = [$callback, $data, $eventName]; $this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(" . $chcnt . ", " . ($ticks / 20) . ", " . microtime(true) . ", " . (((bool) $repeat) === true ? 1 : 0) . ");"); @@ -462,8 +511,8 @@ class PocketMinecraftServer{ /** * @return string */ - public function getGamemode(){ - switch($this->gamemode){ + public function getGamemode() { + switch($this->gamemode) { case SURVIVAL: return "survival"; case CREATIVE: @@ -475,71 +524,69 @@ class PocketMinecraftServer{ } } - public function process() - { + public function process() { $lastLoop = 0; - if(self::$FORCE_20_TPS){ - while($this->stop === false){ + if(self::$FORCE_20_TPS) { + while($this->stop === false) { $packetcnt = 0; - while($packet = $this->interface->readPacket()){ + while($packet = $this->interface->readPacket()) { if($packet instanceof Packet) { $this->packetHandler($packet); - if(++$packetcnt > self::$PACKET_READING_LIMIT){ - ConsoleAPI::warn("Reading more than ".self::$PACKET_READING_LIMIT." packets per tick! Forcing ticking!"); + if(++$packetcnt > self::$PACKET_READING_LIMIT) { + ConsoleAPI::warn("Reading more than " . self::$PACKET_READING_LIMIT . " packets per tick! Forcing ticking!"); break; } } } - + $this->tick(); } - }else{ - while($this->stop === false){ + } else { + while($this->stop === false) { $packetcnt = 0; startReadingAgain: $packet = $this->interface->readPacket(); - if($packet instanceof Packet){ + if($packet instanceof Packet) { $this->packetHandler($packet); $lastLoop = 0; - if(++$packetcnt > self::$PACKET_READING_LIMIT){ - ConsoleAPI::warn("Reading more than ".self::$PACKET_READING_LIMIT." packets per tick! Forcing ticking!"); - }else{ + if(++$packetcnt > self::$PACKET_READING_LIMIT) { + ConsoleAPI::warn("Reading more than " . self::$PACKET_READING_LIMIT . " packets per tick! Forcing ticking!"); + } else { goto startReadingAgain; } - } elseif($this->tick() > 0){ + } elseif($this->tick() > 0) { $lastLoop = 0; - } else{ + } else { ++$lastLoop; - if($lastLoop < 16){ + if($lastLoop < 16) { usleep(1); - } elseif($lastLoop < 128){ + } elseif($lastLoop < 128) { usleep(100); - } elseif($lastLoop < 256){ + } elseif($lastLoop < 256) { usleep(512); - } else{ + } else { usleep(10000); } } $this->tick(); } } - - + } - public function packetHandler(Packet $packet){ - $data =& $packet; + public function packetHandler(Packet $packet) { + $data = &$packet; $CID = PocketMinecraftServer::clientID($packet->ip, $packet->port); - if(isset($this->clients[$CID])){ + if(isset($this->clients[$CID])) { $this->clients[$CID]->handlePacket($packet); - }else{ - if($this->handle("server.noauthpacket." . $packet->pid(), $packet) === false){ + } else { + if($this->handle("server.noauthpacket." . $packet->pid(), $packet) === false) { return; } - switch($packet->pid()){ + switch($packet->pid()) { case RakNetInfo::UNCONNECTED_PING: case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS: - if($this->invisible === true){ + if($this->invisible === true) { $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG); $pk->pingID = $packet->pingID; $pk->serverID = $this->serverID; @@ -549,11 +596,11 @@ class PocketMinecraftServer{ $this->send($pk); break; } - if(!isset($this->custom["times_" . $CID])){ + if(!isset($this->custom["times_" . $CID])) { $this->custom["times_" . $CID] = 0; } $ln = 15; - if($this->description == "" or !str_ends_with($this->description, " ")){ + if($this->description == "" or !str_ends_with($this->description, " ")) { $this->description .= " "; } $txt = substr($this->description, $this->custom["times_" . $CID], $ln); @@ -568,14 +615,14 @@ class PocketMinecraftServer{ $this->custom["times_" . $CID] = ($this->custom["times_" . $CID] + 1) % strlen($this->description); break; case RakNetInfo::OPEN_CONNECTION_REQUEST_1: - if($packet->structure !== RakNetInfo::STRUCTURE){ + if($packet->structure !== RakNetInfo::STRUCTURE) { console("[DEBUG] Incorrect structure #" . $packet->structure . " from " . $packet->ip . ":" . $packet->port, true, true, 2); $pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION); $pk->serverID = $this->serverID; $pk->ip = $packet->ip; $pk->port = $packet->port; $this->send($pk); - }else{ + } else { $pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1); $pk->serverID = $this->serverID; $pk->mtuSize = strlen($packet->buffer); @@ -585,7 +632,7 @@ class PocketMinecraftServer{ } break; case RakNetInfo::OPEN_CONNECTION_REQUEST_2: - if($this->invisible === true){ + if($this->invisible === true) { break; } @@ -601,30 +648,30 @@ class PocketMinecraftServer{ } } - public static function clientID($ip, $port){ + public static function clientID($ip, $port) { return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM); //return $ip . ":" . $port; } - public function send(Packet $packet){ + public function send(Packet $packet) { return $this->interface->writePacket($packet); } - public function tick(){ + public function tick() { $time = microtime(true); - if($this->lastTick <= ($time - 0.05)){ + if($this->lastTick <= ($time - 0.05)) { $this->tickMeasure[] = $this->lastTick = $time; unset($this->tickMeasure[key($this->tickMeasure)]); ++$this->ticks; - - foreach($this->clients as $client){ + + foreach($this->clients as $client) { $client->handlePacketQueues(); - if($this->ticks % 40 == 0){ //2s + if($this->ticks % 40 == 0) { //2s $client->sendPing(); } } - - foreach($this->api->level->levels as $l){ + + foreach($this->api->level->levels as $l) { $l->onTick($this, $time); } $r = $this->tickerFunction($time); @@ -633,34 +680,34 @@ class PocketMinecraftServer{ return 0; } - public function tickerFunction($time){ + public function tickerFunction($time) { //actions that repeat every x time will go here $this->preparedSQL->selectActions->reset(); $this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT); $actions = $this->preparedSQL->selectActions->execute(); $actionCount = 0; - if($actions instanceof SQLite3Result){ - while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){ + if($actions instanceof SQLite3Result) { + while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false) { $cid = $action["ID"]; $this->preparedSQL->updateAction->reset(); $this->preparedSQL->updateAction->bindValue(":time", $time, SQLITE3_FLOAT); $this->preparedSQL->updateAction->bindValue(":id", $cid, SQLITE3_INTEGER); $this->preparedSQL->updateAction->execute(); - if(isset($this->schedule[$cid]) && is_array($this->schedule[$cid]) && isset($this->schedule[$cid][0]) && is_callable($this->schedule[$cid][0])){ + if(isset($this->schedule[$cid]) && is_array($this->schedule[$cid]) && isset($this->schedule[$cid][0]) && is_callable($this->schedule[$cid][0])) { ++$actionCount; - try{ - $return = @call_user_func($this->schedule[$cid][0] ?? function(){}, $this->schedule[$cid][1], $this->schedule[$cid][2]); //somehow args can be null - }catch(TypeError $e){ - $m = $e->getMessage()."\nStack trace:\n".$e->getTraceAsString(); + try { + $return = @call_user_func($this->schedule[$cid][0] ?? function () {}, $this->schedule[$cid][1], $this->schedule[$cid][2]); //somehow args can be null + } catch(TypeError $e) { + $m = $e->getMessage() . "\nStack trace:\n" . $e->getTraceAsString(); ConsoleAPI::error($m); $return = false; } - }else{ + } else { $return = false; } - if($action["repeat"] == 0 or $return === false){ + if($action["repeat"] == 0 or $return === false) { $this->query("DELETE FROM actions WHERE ID = " . $action["ID"] . ";"); $this->schedule[$cid] = null; unset($this->schedule[$cid]); @@ -671,8 +718,8 @@ class PocketMinecraftServer{ return $actionCount; } - public function dumpError(){ - if($this->stop === true){ + public function dumpError() { + if($this->stop === true) { return; } ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems @@ -698,18 +745,18 @@ class PocketMinecraftServer{ ]; $er["type"] = $errorConversion[$er["type"]] ?? $er["type"]; $dump .= "Error: " . var_export($er, true) . "\r\n\r\n"; - if(stripos($er["file"], "plugin") !== false){ + if(stripos($er["file"], "plugin") !== false) { $dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n"; } $dump .= "Code: \r\n"; $file = @file($er["file"], FILE_IGNORE_NEW_LINES); - for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){ + for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l) { $dump .= "[" . ($l + 1) . "] " . @$file[$l] . "\r\n"; } $dump .= "\r\n\r\n"; $dump .= "Backtrace: \r\n"; - foreach(getTrace() as $line){ + foreach(getTrace() as $line) { $dump .= "$line\r\n"; } $dump .= "\r\n\r\n"; @@ -724,21 +771,21 @@ class PocketMinecraftServer{ global $arguments; $dump .= "Parameters: " . var_export($arguments, true) . "\r\n\r\n\r\n"; $p = $this->api->getProperties(); - if($p["rcon.password"] != ""){ + if($p["rcon.password"] != "") { $p["rcon.password"] = "******"; } $dump .= "server.properties: " . var_export($p, true) . "\r\n\r\n\r\n"; - if($this->api->plugin instanceof PluginAPI){ + if($this->api->plugin instanceof PluginAPI) { $plist = $this->api->plugin->getList(); $dump .= "Loaded plugins:\r\n"; - foreach($plist as $p){ + foreach($plist as $p) { $dump .= $p["name"] . " " . $p["version"] . " by " . $p["author"] . "\r\n"; } $dump .= "\r\n\r\n"; } $extensions = []; - foreach(get_loaded_extensions() as $ext){ + foreach(get_loaded_extensions() as $ext) { $extensions[$ext] = phpversion($ext); } @@ -759,7 +806,7 @@ class PocketMinecraftServer{ console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0); } - public function debugInfo($console = false){ + public function debugInfo($console = false) { $info = []; $info["tps"] = $this->getTPS(); $info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2) . "MB"; @@ -773,33 +820,33 @@ class PocketMinecraftServer{ $info["actions"] = $info["actions"]["count"]; $info["garbage"] = gc_collect_cycles(); $this->handle("server.debug", $info); - if($console === true){ + if($console === true) { console("[INFO] TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . "), Entities: " . $info["entities"] . ", Events: " . $info["events"] . ", Handlers: " . $info["handlers"] . ", Actions: " . $info["actions"] . ", Garbage: " . $info["garbage"], true, true); } return $info; } - public function checkMemory(){ + public function checkMemory() { $info = $this->debugInfo(); $data = $info["memory_usage"] . "," . $info["players"] . "," . $info["entities"]; $i = count($this->memoryStats) - 1; - if($i < 0 or $this->memoryStats[$i] !== $data){ + if($i < 0 or $this->memoryStats[$i] !== $data) { $this->memoryStats[] = $data; } } - public function event($event, callable $func){ - if(!is_callable($func)){ + public function event($event, callable $func) { + if(!is_callable($func)) { return false; - }elseif(isset(Deprecation::$events[$event])){ + } elseif(isset(Deprecation::$events[$event])) { $sub = ""; - if(Deprecation::$events[$event] !== false){ + if(Deprecation::$events[$event] !== false) { $sub = " Substitute \"" . Deprecation::$events[$event] . "\" found."; } console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . "]"); } $evid = $this->evCnt++; - if(!isset($this->events[$event])){ + if(!isset($this->events[$event])) { $this->events[$event] = []; } $this->events[$event][$evid] = $func; diff --git a/src/astarnavigator/TileNavigator.php b/src/astarnavigator/TileNavigator.php index c29c4fec..24769b51 100644 --- a/src/astarnavigator/TileNavigator.php +++ b/src/astarnavigator/TileNavigator.php @@ -1,14 +1,15 @@ entity = $entity; $this->tall = $entity->height > 1; } - + public function reconstructPath($path, $current){ console("path built"); $totalPath = [$current]; - while (isset($path[(string)$current])) + while (isset($path[(string) $current])) { - $current = $path[(string)$current]; + $current = $path[(string) $current]; $totalPath[] = $current; } //foreach(array_unique($path) as $k => $p) console($k.":".$p); @@ -33,17 +34,17 @@ class TileNavigator } public function isLocBlocked(PMFLevel $level, $loc){ - + $chunkX = $loc >> 20 & 0xf; $chunkZ = $loc >> 12 & 0xf; $chunkY = $loc >> 4 & 0xf; - + $index = $chunkZ << 4 | $chunkX; - + $blockX = $loc >> 16 & 0xf; $blockZ = $loc >> 8 & 0xf; $blockY = $loc & 0xf; - + $id = $level->fastGetBlockID($chunkX, $chunkY, $chunkZ, $blockX, $blockY, $blockZ, $index); $b = StaticBlock::getIsSolid($id); if($this->tall){ @@ -53,33 +54,32 @@ class TileNavigator $id = $level->fastGetBlockID($chunkX, $chunkY, $chunkZ, $blockX, $blockY, $blockZ, $index); return $b || StaticBlock::getIsSolid($id); } - + return $b; } - - + public function navigate(Level $level, $fromX, $fromY, $fromZ, $toX, $toY, $toZ, $maxDist) { $from = $fromX << 16 | $fromZ << 8 | $fromY; $to = $toX << 16 | $toZ << 8 | $toY; - + $pmfLevel = $level->level; - + $open = new SplPriorityQueue(); //$open->insert(, 0); $open->insert($from, 0); $path = []; $gScore = []; $gScore[(string) $from] = 0; - $has = [(string)$from, true]; + $has = [(string) $from, true]; if($this->isLocBlocked($pmfLevel, $to)){ return null; } $visited = []; - $maxDist*=$maxDist; //no square root + $maxDist *= $maxDist; //no square root $closestToTarget = null; $closestToTargetDist = INF; - + while(!$open->isEmpty()) { $current = $open->top(); @@ -90,7 +90,7 @@ class TileNavigator if ($current == $to){ return $this->reconstructPath($path, $current); } - + $points = []; foreach(self::OFFSETS as $offset){ $newX = $offset[0] + $currentX; @@ -98,7 +98,7 @@ class TileNavigator $newZ = $offset[2] + $currentZ; if($newX < 0 || $newX > 255 || $newY < 0 || $newY > 255 || $newZ < 0 || $newZ > 255) continue; $new = $newX << 16 | $newZ << 8 | $newY; - + if(!$this->isLocBlocked($pmfLevel, $new)){ if($newY > 0 && !$this->isLocBlocked($pmfLevel, $new - 1)){ if(!$this->avoidFallDamage){ @@ -108,60 +108,59 @@ class TileNavigator if($this->isLocBlocked($pmfLevel, $new - 2)){ $new -= 1; $newY -= 1; - }else if($this->isLocBlocked($pmfLevel, $new - 3)){ + }elseif($this->isLocBlocked($pmfLevel, $new - 3)){ $new -= 2; $newY -= 2; - }else if($this->isLocBlocked($pmfLevel, $new - 4)){ + }elseif($this->isLocBlocked($pmfLevel, $new - 4)){ $new -= 3; $newY -= 3; }else{ - continue; + continue; } } } - $dist = ($fromX - $newX)*($fromX - $newX) + ($fromY - $newY)*($fromY - $newY) + ($fromZ - $newZ)*($fromZ - $newZ); + $dist = ($fromX - $newX) * ($fromX - $newX) + ($fromY - $newY) * ($fromY - $newY) + ($fromZ - $newZ) * ($fromZ - $newZ); if($dist < -$maxDist || $dist > $maxDist){ continue; } - + $points[] = $new; - }else if(!$this->isLocBlocked($pmfLevel, $current+1) && !$this->isLocBlocked($pmfLevel, $new+1)){ + }elseif(!$this->isLocBlocked($pmfLevel, $current + 1) && !$this->isLocBlocked($pmfLevel, $new + 1)){ $new += 1; $newY += 1; - - $dist = ($fromX - $newX)*($fromX - $newX) + ($fromY - $newY)*($fromY - $newY) + ($fromZ - $newZ)*($fromZ - $newZ); + + $dist = ($fromX - $newX) * ($fromX - $newX) + ($fromY - $newY) * ($fromY - $newY) + ($fromZ - $newZ) * ($fromZ - $newZ); if($dist < -$maxDist || $dist > $maxDist){ continue; } - + $points[] = $new; } } - + foreach($points as $neighbor) { if(isset($visited[$neighbor])){ continue; } $visited[$neighbor] = true; - + $diffX = ($toX - ($neighbor >> 16 & 0xff)); $diffY = ($toY - ($neighbor & 0xff)); $diffZ = ($toZ - ($neighbor >> 8 & 0xff)); - $targetDist = $diffX*$diffX + $diffY*$diffY + $diffZ*$diffZ; - - + $targetDist = $diffX * $diffX + $diffY * $diffY + $diffZ * $diffZ; + $diffX = ($currentX - ($neighbor >> 16 & 0xff)); $diffY = ($currentY - ($neighbor & 0xff)); $diffZ = ($currentZ - ($neighbor >> 8 & 0xff)); - - $distbetweenCost = $diffX*$diffX + $diffY*$diffY + $diffZ*$diffZ; + + $distbetweenCost = $diffX * $diffX + $diffY * $diffY + $diffZ * $diffZ; $tentativeG = $gScore[$current] + $distbetweenCost; if (!isset($has[$neighbor])) - { + { //if(isset($open[-$tentativeG])) console("overwriting $tentativeG"); //$open[-$tentativeG] = $neighbor; - + $open->insert($neighbor, -$tentativeG); $has[$neighbor] = true; } @@ -171,26 +170,25 @@ class TileNavigator } if(!isset($gScore[$neighbor]) || $distbetweenCost < $gScore[$neighbor]){ $path[$neighbor] = $current; - + if($targetDist < $closestToTargetDist){ //console("found new best to target: $neighbor($closestToTargetDist -> $targetDist)"); - + $closestToTarget = $neighbor; - $closestToTargetDist = $targetDist; + $closestToTargetDist = $targetDist; } } - + $gScore[$neighbor] = $tentativeG; } } - + if($closestToTarget != null){ return $this->reconstructPath($path, $closestToTarget); } - + return null; } - -} + } diff --git a/src/config.php b/src/config.php index b592e4d7..f199ba71 100644 --- a/src/config.php +++ b/src/config.php @@ -1,4 +1,5 @@ true, MOB_PIG => true, MOB_SHEEP => true, - + MOB_ZOMBIE => true, MOB_SKELETON => true, MOB_SPIDER => true, @@ -64,5 +64,5 @@ const CORRECT_ENTITY_CLASSES = [ ENTITY_FALLING => [ FALLING_SAND => true ] - + ]; diff --git a/src/dependencies.php b/src/dependencies.php index 5af85a1c..54260b95 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -103,7 +103,6 @@ require_once(FILE_PATH . "/src/pmf/PMF.php"); require_once(FILE_PATH . "/src/astarnavigator/TileNavigator.php"); - require_once(FILE_PATH . "/src/entity/ai/tasks/TaskBase.php"); require_once(FILE_PATH . "/src/entity/Rideable.php"); @@ -138,8 +137,6 @@ require_once(FILE_PATH . "/src/world/generator/vanilla/feature/Feature.php"); require_all(FILE_PATH . "src/"); - - $inc = get_included_files(); $inc[] = array_shift($inc); $srcdir = realpath(FILE_PATH . "src/"); diff --git a/src/entity/Animal.php b/src/entity/Animal.php index b21aab0d..f9ccf9be 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -1,17 +1,15 @@ setAge($data["Age"] ?? 0); @@ -20,11 +18,11 @@ abstract class Animal extends Creature implements Ageable, Breedable{ } $this->searchForClosestPlayers = true; } - + public function isPlayerValid(Player $player){ return $player->spawned && $this->isFood($player->getHeldItem()->id) && !$player->entity->dead; } - + public function handlePrePlayerSearcher(){ parent::handlePrePlayerSearcher(); if($this->closestPlayerThatCanFeedEID !== false){ @@ -33,15 +31,15 @@ abstract class Animal extends Creature implements Ageable, Breedable{ $this->closestPlayerThatCanFeedEID = false; $this->closestPlayerThatCanFeedDist = INF; }else{ - $dist = ($this->x - $player->x)*($this->x - $player->x) + ($this->y - $player->y)*($this->y - $player->y) + ($this->z - $player->z)*($this->z - $player->z); + $dist = ($this->x - $player->x) * ($this->x - $player->x) + ($this->y - $player->y) * ($this->y - $player->y) + ($this->z - $player->z) * ($this->z - $player->z); $this->closestPlayerThatCanFeedDist = $dist; } } } - + public function handlePlayerSearcher(Player $player, $dist){ parent::handlePlayerSearcher($player, $dist); - + if($this->closestPlayerThatCanFeedDist >= $dist){ if($this->isPlayerValid($player)){ $this->closestPlayerThatCanFeedDist = $dist; @@ -49,18 +47,18 @@ abstract class Animal extends Creature implements Ageable, Breedable{ } } } - + public function harm($dmg, $cause = "generic", $force = false){ $ret = parent::harm($dmg, $cause, $force); $this->inPanic |= ($ret && is_numeric($cause)); $this->inLove = false; return $ret; } - + public function isBaby(){ return $this->getAge() < 0; } - + public function breed(){ if($this->server->dhandle("entity.animal.breed", ["parent" => $this]) !== false){ $c = $this->spawnChild(); @@ -70,22 +68,22 @@ abstract class Animal extends Creature implements Ageable, Breedable{ } return false; } - + public function resetInLove(){ $this->inLove = 0; } - + public function canMate($ent){ return $ent->eid != $this->eid && $this->type === $ent->type && $this->isInLove() && $ent->isInLove(); } - + public function update($now){ parent::update($now); - + if($this->loveTimeout > 0){ --$this->loveTimeout; } - + $age = $this->getAge() + 1; //100 - fast. debug, 1 - normal if($age >= 0 && $this->isBaby()){ $this->setAge($age); @@ -99,15 +97,15 @@ abstract class Animal extends Creature implements Ageable, Breedable{ unset($this->level->entitiesInLove[$this->eid]); } } - + public function getAge(){ return $this->age; } - + public function setAge($i){ $this->age = $i; } - + public function spawnChild() { return $this->server->api->entity->add($this->level, $this->class, $this->type, [ @@ -118,24 +116,24 @@ abstract class Animal extends Creature implements Ageable, Breedable{ "Age" => -24000, ]); } - + public function getMetadata(){ $d = parent::getMetadata(); $d[14]["value"] = $this->isBaby(); return $d; } - + public function createSaveData(){ $data = parent::createSaveData(); $data["IsBaby"] = $this->isBaby(); $data["Age"] = $this->getAge(); return $data; } - + public function isInLove(){ return $this->inLove > 0; } - + public function interactWith(Entity $e, $action){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ $slot = $e->player->getHeldItem(); @@ -149,14 +147,14 @@ abstract class Animal extends Creature implements Ageable, Breedable{ } parent::interactWith($e, $action); } - + public function counterUpdate(){ parent::counterUpdate(); if($this->isInLove()){ --$this->inLove; } } - + public function getDrops(){ if($this->isBaby()){ return []; diff --git a/src/entity/Breedable.php b/src/entity/Breedable.php index 59cc21ec..211c6c7e 100644 --- a/src/entity/Breedable.php +++ b/src/entity/Breedable.php @@ -2,8 +2,8 @@ interface Breedable{ public function isFood($id); //original name - + public function spawnChild(); - + public function isInLove(); } \ No newline at end of file diff --git a/src/entity/Creature.php b/src/entity/Creature.php index a8e97972..be41e0e5 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -2,12 +2,11 @@ abstract class Creature extends Living{ const CLASS_TYPE = ENTITY_MOB; - + public $inPanic; public $closestPlayerEID = false; public $closestPlayerDist = INF; - - + public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->inPanic = false; //force for now parent::__construct($level, $eid, $class, $type, $data); @@ -15,13 +14,12 @@ abstract class Creature extends Living{ $this->enableAutojump = true; $this->searchForClosestPlayers = true; } - + public function update($now){ $this->handlePrePlayerSearcher(); return parent::update($now); } - - + public function handlePrePlayerSearcher(){ parent::handlePrePlayerSearcher(); if($this->closestPlayerEID !== false){ @@ -30,12 +28,12 @@ abstract class Creature extends Living{ $this->closestPlayerEID = false; $this->closestPlayerDist = INF; }else{ - $dist = ($this->x - $player->x)*($this->x - $player->x) + ($this->y - $player->y)*($this->y - $player->y) + ($this->z - $player->z)*($this->z - $player->z); + $dist = ($this->x - $player->x) * ($this->x - $player->x) + ($this->y - $player->y) * ($this->y - $player->y) + ($this->z - $player->z) * ($this->z - $player->z); $this->closestPlayerDist = $dist; } } } - + public function handlePlayerSearcher(Player $player, $dist){ parent::handlePlayerSearcher($player, $dist); if($this->closestPlayerDist >= $dist){ @@ -43,13 +41,13 @@ abstract class Creature extends Living{ $this->closestPlayerDist = $dist; } } - + public function createSaveData(){ $data = parent::createSaveData(); $data["State"] = @$this->getState(); return $data; } - + public function getSpeedModifer(){ return 0.7; } @@ -71,19 +69,19 @@ abstract class Creature extends Living{ $pk->z = $this->z; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; - $pk->metadata = $this->getMetadata(); + $pk->metadata = $this->getMetadata(); $player->dataPacket($pk); - + $pk = new SetEntityMotionPacket; $pk->eid = $this->eid; $pk->speedX = $this->speedX; $pk->speedY = $this->speedY; $pk->speedZ = $this->speedZ; $player->dataPacket($pk); - + if($this->linkedEntity != 0 && $this->isRider){ $player->eventHandler(["rider" => $this->eid, "riding" => $this->linkedEntity, "type" => 0], "entity.link"); } } - + } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index e4f5383c..82678e6f 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -3,10 +3,10 @@ class Entity extends Position { - const TYPE = - 1; - const CLASS_TYPE = - 1; - const MIN_POSSIBLE_SPEED = 1/8000; //anything below will send 0 to player - + const TYPE = -1; + const CLASS_TYPE = -1; + const MIN_POSSIBLE_SPEED = 1 / 8000; //anything below will send 0 to player + public $searchForClosestPlayers = false; public $modifySpeedY = false; public $modifedSpeedY = 0.0; @@ -36,17 +36,17 @@ class Entity extends Position public $delayBeforePickup; public $x, $y, $z; public $speedX, $speedY, $speedZ, $speed; - public $lastX = 0, $lastY = 0, $lastZ = 0, $lastYaw = 0, $lastPitch = 0, $lastTime = 0, $lastHeadYaw = 0, $lastSpeedX = 0, $lastSpeedY = 0, $lastSpeedZ = 0; + public $lastX = 0, $lastY = 0, $lastZ = 0, $lastYaw = 0, $lastPitch = 0, $lastTime = 0, $lastHeadYaw = 0, $lastSpeedX = 0, $lastSpeedY = 0, $lastSpeedZ = 0; /** - * 0 = lastX, - * 1 = lastY, - * 2 = lastZ, - * 3 = lastYaw, - * 4 = lastPitch, - * 5 = lastTime. - * + * 0 = lastX, + * 1 = lastY, + * 2 = lastZ, + * 3 = lastYaw, + * 4 = lastPitch, + * 5 = lastTime. + * * It is not recommended to use this and it is left as a backwards compability. - * + * * @var array */ public $last; @@ -65,7 +65,7 @@ class Entity extends Position public $fallStart; private $state; private $tickCounter; - private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0); + private $speedMeasure = [0, 0, 0, 0, 0, 0, 0]; public $server; private $isStatic; public $level; @@ -87,30 +87,30 @@ class Entity extends Position public $onGround, $inWater; public $carryoverDamage; public $gravity; - + public $stepHeight = 0.5; public $enableAutojump = false; public $yOffset = 0.0; public $noClip = false; - + public $chunkX = 0; public $chunkZ = 0; - + public $isCollidedHorizontally, $isCollidedVertically, $isCollided; /** * Amount of ticks you can be in fire until you start receiving damage * @var integer */ public $fireResistance = 1; - + public $isImmuneToFire = false; - + public $inWeb; public $inLava; public $notOnGroundTicks = 0; - + public $moveStrafing, $moveForward; - + function __construct(Level $level, $eid, $class, $type = 0, $data = []) { $this->random = new Random(); @@ -131,7 +131,7 @@ class Entity extends Position $this->status = 0; $this->health = 20; $this->hasGravity = false; - $this->dmgcounter = array(0, 0, 0); + $this->dmgcounter = [0, 0, 0]; $this->air = $this->maxAir; $this->fire = 0; $this->crouched = false; @@ -154,14 +154,14 @@ class Entity extends Position $this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"] : 0; $this->headYaw = $this->data["headYaw"] ?? $this->yaw; $this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"] : 0; - $this->position = array( + $this->position = [ "level" => $this->level, "x" => &$this->x, "y" => &$this->y, "z" => &$this->z, "yaw" => &$this->yaw, "pitch" => &$this->pitch - ); + ]; $this->moveTime = 0; $this->lookTime = 0; $this->onGround = false; @@ -176,7 +176,7 @@ class Entity extends Position $this->hasGravity = true; $this->canBeAttacked = true; $this->fireResistance = 20; - + break; case ENTITY_OBJECT: if($this->type == OBJECT_PAINTING) break; @@ -197,7 +197,7 @@ class Entity extends Position } } public function handlePrePlayerSearcher(){ - + } public function isType(){ return in_array($this->type, func_get_args()); @@ -210,12 +210,12 @@ class Entity extends Position public function attackEntity($entity, $distance){ return false; } - + public function setInWeb(){ $this->inWeb = true; $this->fallDistance = 0; } - + public function addVelocity($vX, $vY = 0, $vZ = 0) { if($vX instanceof Vector3){ @@ -225,11 +225,11 @@ class Entity extends Position $this->speedY += $vY; $this->speedZ += $vZ; } - + public function isPushable(){ return $this->isPlayer(); } - + public function applyCollision(Entity $collided){ if(!($this->isPlayer() && $collided->isPlayer()) && $this->eid != $collided->eid){ $diffX = $collided->x - $this->x; @@ -239,7 +239,7 @@ class Entity extends Position $sqrtMax = sqrt($maxDiff); $diffX /= $sqrtMax; $diffZ /= $sqrtMax; - + $col = (($v = 1 / $sqrtMax) > 1 ? 1 : $v); $diffX *= $col; $diffZ *= $col; @@ -250,7 +250,7 @@ class Entity extends Position } } } - + public function isMovingHorizontally() { return ($this->speedX >= self::MIN_POSSIBLE_SPEED || $this->speedX <= -self::MIN_POSSIBLE_SPEED) || ($this->speedZ >= self::MIN_POSSIBLE_SPEED || $this->speedZ <= -self::MIN_POSSIBLE_SPEED); @@ -345,26 +345,26 @@ class Entity extends Position if(self::$keepInventory){ return []; } - for($i = 0; $i < PLAYER_SURVIVAL_SLOTS; ++ $i){ + for($i = 0; $i < PLAYER_SURVIVAL_SLOTS; ++$i){ $slot = $this->player->getSlot($i); $this->player->setSlot($i, BlockAPI::getItem(AIR, 0, 0)); if($slot->getID() !== AIR and $slot->count > 0){ - $inv[] = array( + $inv[] = [ $slot->getID(), $slot->getMetadata(), $slot->count - ); + ]; } } - for($re = 0; $re < 4; $re ++){ + for($re = 0; $re < 4; $re++){ $slot = $this->player->getArmor($re); $this->player->setArmor($re, BlockAPI::getItem(AIR, 0, 0)); if($slot->getID() !== AIR and $slot->count > 0){ - $inv[] = array( + $inv[] = [ $slot->getID(), $slot->getMetadata(), $slot->count - ); + ]; } } return $inv; @@ -378,11 +378,11 @@ class Entity extends Position $this->server->api->entity->drop($this, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF)); } } - + public function canSee(Entity $e){ return $this->level->rayTraceBlocks(new Vector3($this->x, $this->y + $this->getEyeHeight(), $this->z), new Vector3($e->x, $e->y + $e->getEyeHeight(), $e->z)) == null; } - + /** * Can entity be collided with or not * @return boolean @@ -390,12 +390,12 @@ class Entity extends Position public function isPickable(){ return $this->isPlayer() && !$this->dead; } - + public function handleLavaMovement(){ //TODO maybe try merging with water? $this->inLava = $this->level->isLavaInBB($this->boundingBox->expand(-0.1, -0.4, -0.1)); return $this->inLava; } - + public function handleWaterMovement(){ if($this->level->handleMaterialAcceleration($this->boundingBox->expand(0, -0.4, 0)->contract(0.001, 0.001, 0.001), 0, $this)){ $this->fallDistance = 0; @@ -406,39 +406,39 @@ class Entity extends Position }else{ $this->fire = 0; } - + }else{ $this->inWater = false; } - + return $this->inWater; } - + public function environmentUpdate($time) { $hasUpdate = $this->class === ENTITY_MOB; // force true for mobs - + $tickDiff = ($time - $this->lastUpdate) / 0.05; if($this->attackTimeout > 0) $this->attackTimeout -= $tickDiff; if($this->attackTimeout < 0) $this->attackTimeout = 0; - + if($this->isPlayer() && $this->player->spawned === true && $this->player->blocked !== true && !$this->dead){ $myBB = $this->boundingBox->grow(1, 0.5, 1); foreach($this->server->api->entity->getRadius($this, 2, false) as $item){ if($item->class === ENTITY_ITEM && !$item->closed && $item->spawntime > 0 && $item->delayBeforePickup <= 0){ - if($item->boundingBox->intersectsWith($myBB)){ - if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->itemID, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array( + if($item->boundingBox->intersectsWith($myBB)){ + if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->itemID, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", [ "eid" => $this->player->eid, "player" => $this->player, "entity" => $item, "block" => $item->itemID, "meta" => $item->meta, "target" => $item->eid - )) !== false){ + ]) !== false){ $item->close(); } } - }else if($item->class == ENTITY_OBJECT && !$item->closed && $item->type == OBJECT_ARROW && $item->shotByPlayer && $item->inGround && $item->shake <= 0 && $item->boundingBox->intersectsWith($myBB)){ + }elseif($item->class == ENTITY_OBJECT && !$item->closed && $item->type == OBJECT_ARROW && $item->shotByPlayer && $item->inGround && $item->shake <= 0 && $item->boundingBox->intersectsWith($myBB)){ if(($this->player->gamemode & 0x01) == 1 || $this->player->hasSpace(ARROW, 0, 1)){ $this->player->addItem(ARROW, 0, 1); $item->close(); @@ -463,7 +463,7 @@ class Entity extends Position $this->air = $this->maxAir; return false; } - + $this->handleWaterMovement(); if($this->fire > 0){ //TODO move somewhere if(!$this->isImmuneToFire){ @@ -475,7 +475,7 @@ class Entity extends Position $this->fire -= 4; if($this->fire <= 0) $this->fire = 0; } - + if($this->fire <= 0){ $this->updateMetadata(); } else{ @@ -487,16 +487,16 @@ class Entity extends Position if(!$this->isImmuneToFire){ $this->harm(4, "fire"); $oldOnFire = $this->fire; - if($oldOnFire < 20*30) $this->fire = 20*30; //30 seconds + if($oldOnFire < 20 * 30) $this->fire = 20 * 30; //30 seconds } } - + if($this->isInVoid()){ $this->outOfWorld(); $hasUpdate = true; } - - if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix + + if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix $x = floor($this->x); $y = floor($this->y + $this->getEyeHeight()); $z = floor($this->z); @@ -504,14 +504,14 @@ class Entity extends Position $this->harm(1, "suffocation"); } } - + //air damage if($this->isPlayer() || $this instanceof Living){ $d = $this->y + $this->getEyeHeight(); $x = floor($this->x); $y = floor($d); $z = floor($this->z); - + $id = $this->level->level->getBlockID($x, $y, $z); if($id == WATER || $id == STILL_WATER){ $f = LiquidBlock::getPercentAir($this->level->level->getBlockDamage($x, $y, $z)) - 0.1111111; @@ -531,28 +531,28 @@ class Entity extends Position } return $hasUpdate; } - + public function moveFlying($strafe, $forward, $speed){ //TODO rename? - $v4 = $strafe*$strafe + $forward*$forward; - + $v4 = $strafe * $strafe + $forward * $forward; + if($v4 >= 0.0001){ $v4 = sqrt($v4); if($v4 < 1) $v4 = 1; - + $v4 = $speed / $v4; $strafe *= $v4; $forward *= $v4; - - $v5 = sin($this->yaw * M_PI/180); - $v6 = cos($this->yaw * M_PI/180); - - $this->speedX += $strafe*$v6 - $forward*$v5; - $this->speedZ += $forward*$v6 + $strafe*$v5; + + $v5 = sin($this->yaw * M_PI / 180); + $v6 = cos($this->yaw * M_PI / 180); + + $this->speedX += $strafe * $v6 - $forward * $v5; + $this->speedZ += $forward * $v6 + $strafe * $v5; } } - + public function updateEntityMovement(){} - + public function doBlocksCollision(){ $minY = floor($this->boundingBox->minY + 0.001); $maxY = floor($this->boundingBox->maxY - 0.001); @@ -560,91 +560,88 @@ class Entity extends Position $minZ = floor($this->boundingBox->minZ + 0.001); $maxX = floor($this->boundingBox->maxX - 0.001); $maxZ = floor($this->boundingBox->maxZ - 0.001); - + for($x = $minX; $x <= $maxX; ++$x){ for($y = $minY; $y <= $maxY; ++$y){ for($z = $minZ; $z <= $maxZ; ++$z){ $id = $this->level->level->getBlockID($x, $y, $z); - + if($id > 0){ StaticBlock::$prealloc[$id]::onEntityCollidedWithBlock($this->level, $x, $y, $z, $this); } } } } - + } - + public function move($dx, $dy, $dz){ $movX = $this->x; $movY = $this->y; $movZ = $this->z; - + if($this->inWeb){ $this->inWeb = false; $dx *= 0.25; $dy *= 0.05; $dz *= 0.25; - + $this->speedX = $this->speedY = $this->speedZ = 0; } - - + $savedDX = $dx; $savedDY = $dy; $savedDZ = $dz; - + $oldBB = clone $this->boundingBox; - - + $aaBBs = $this->level->getCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz)); foreach($aaBBs as $bb){ $dy = $bb->calculateYOffset($this->boundingBox, $dy); } $this->boundingBox->offset(0, $dy, 0); - + foreach($aaBBs as $bb){ $dx = $bb->calculateXOffset($this->boundingBox, $dx); } $this->boundingBox->offset($dx, 0, 0); - + foreach($aaBBs as $bb){ $dz = $bb->calculateZOffset($this->boundingBox, $dz); } $this->boundingBox->offset(0, 0, $dz); - - + $fallingFlag = $this->onGround || $savedDY != $dy && $savedDY < 0; - + if($this->stepHeight > 0 && $fallingFlag && ($savedDX != $dx || $savedDZ != $dz)){ $cx = $dx; $cy = $dy; $cz = $dz; - + $dx = $savedDX; $dy = $this->stepHeight; $dz = $savedDZ; $aabb1 = clone $this->boundingBox; $this->boundingBox->setBB($oldBB); - + $aaBBs = $this->level->getCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz)); - + foreach($aaBBs as $bb){ $dy = $bb->calculateYOffset($this->boundingBox, $dy); } $this->boundingBox->offset(0, $dy, 0); - + foreach($aaBBs as $bb){ $dx = $bb->calculateXOffset($this->boundingBox, $dx); } $this->boundingBox->offset($dx, 0, 0); - + foreach($aaBBs as $bb){ $dz = $bb->calculateZOffset($this->boundingBox, $dz); } $this->boundingBox->offset(0, 0, $dz); - - if ($cx*$cx + $cz*$cz >= $dx*$dx + $dz*$dz) + + if ($cx * $cx + $cz * $cz >= $dx * $dx + $dz * $dz) { $dx = $cx; $dy = $cy; @@ -655,7 +652,7 @@ class Entity extends Position $this->modifedSpeedY = 0.5; } } - + $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2; $this->y = $this->boundingBox->minY + $this->yOffset; $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2; @@ -664,49 +661,46 @@ class Entity extends Position $this->onGround = $savedDY != $dy && $savedDY < 0.0; $this->isCollided = $this->isCollidedHorizontally || $this->isCollidedVertically; $this->updateFallState($this->speedY); - - + if($savedDX != $dx) $this->speedX = 0; if($savedDY != $dy) $this->speedY = 0; if($savedDZ != $dz) $this->speedZ = 0; - - - + //TODO more stuff -> onEntityWalking - + $this->doBlocksCollision(); - + $oldFire = $this->fire; if($this->level->isBoundingBoxOnFire($this->boundingBox->contract(0.001, 0.001, 0.001))){ $this->harm(1, "fire"); if(!$this->inWater){ ++$this->fire; - if($this->fire == 0) $this->fire = 8*20; + if($this->fire == 0) $this->fire = 8 * 20; } }elseif($this->fire <= 0){ $this->fire = -$this->fireResistance; } - + if($this->inWater && $this->fire > 0){ $this->fire = -$this->fireResistance; } - + if(($oldFire > 0 && $this->fire <= 0) || ($oldFire <= 0 && $this->fire > 0)){ $this->updateMetadata(); //TODO rewrite metadata } } - + //in MCP it is called isOffsetPositionInLiquid, in 0.8 - isFree public function isFree($offsetX, $offsetY, $offsetZ){ $offsetBB = $this->boundingBox->getOffsetBoundingBox($offsetX, $offsetY, $offsetZ); - + $minX = floor($offsetBB->minX); $minY = floor($offsetBB->minY); $minZ = floor($offsetBB->minZ); $maxX = floor($offsetBB->maxX + 1); $maxY = floor($offsetBB->maxY + 1); $maxZ = floor($offsetBB->maxZ + 1); - + $hasLiquid = false; $result = false; for($x = $minX; $x < $maxX; ++$x){ @@ -724,20 +718,20 @@ class Entity extends Position if($result) return !$hasLiquid; return false; } - + public function isInVoid(){ return $this->y < -1.6; } - + public function handlePlayerSearcher(Player $player, $dist){ - + } - + public function update($now){ if($this->closed === true){ return false; } - + if($this->check === false){ $this->lastUpdate = $now; return; @@ -748,7 +742,7 @@ class Entity extends Position return false; } ++$this->counter; - + if($this->isStatic === false){ if(!$this->isPlayer()){ $this->updateLast(); @@ -761,18 +755,18 @@ class Entity extends Position }elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch || $this->lastHeadYaw != $this->headYaw) { $update = true; } - + if($update === true){ $hasUpdate = true; } - + } else{ $prevGroundState = $this->onGround; $this->onGround = false; $this->speedX = -($this->lastX - $this->x); $this->speedY = -($this->lastY - $this->y); $this->speedZ = -($this->lastZ - $this->z); - + $contractedCollisionBB = $this->boundingBox->contract(0.001, 0.001, 0.001); $fireMinX = floor($contractedCollisionBB->minX); $fireMinY = floor($contractedCollisionBB->minY); @@ -780,13 +774,13 @@ class Entity extends Position $fireMaxX = floor($contractedCollisionBB->maxX + 1); $fireMaxY = floor($contractedCollisionBB->maxY + 1); $fireMaxZ = floor($contractedCollisionBB->maxZ + 1); - + $bbbottom = $this->boundingBox->addCoord(0, -0.05, 0); $bbbottom->minX = round($this->x, 3) - $this->radius; $bbbottom->maxX = round($this->x, 3) + $this->radius; $bbbottom->minZ = round($this->z, 3) - $this->radius; $bbbottom->maxZ = round($this->z, 3) + $this->radius; - + $handleFire = false; $handleCactus = false; for($x = floor($this->boundingBox->minX); $x < ceil($this->boundingBox->maxX); ++$x){ @@ -800,11 +794,11 @@ class Entity extends Position ++$intersects; } } - - if($id == WATER || $id === STILL_WATER || $id === COBWEB || $id == LAVA || $id === STILL_LAVA){ + + if($id == WATER || $id === STILL_WATER || $id === COBWEB || $id == LAVA || $id === STILL_LAVA){ $this->notOnGroundTicks = 0; } - + intersects: if($y <= floor($this->boundingBox->minY) && !$this->onGround){ if($intersects > 0) $this->onGround = count($bounds) > 0; @@ -815,23 +809,23 @@ class Entity extends Position $meta = $block[1]; $handleFire = $handleFire || (($id == FIRE || $id == STILL_LAVA || $id == LAVA) && $x >= $fireMinX && $x < $fireMaxX && $y >= $fireMinY && $y < $fireMaxY && $z >= $fireMinZ && $z < $fireMaxZ); $handleCactus = $handleCactus || ($id == CACTUS && $x >= $fireMinX && $x < $fireMaxX && $y >= $fireMinY && $y < $fireMaxY && $z >= $fireMinZ && $z < $fireMaxZ); - + if($id === WATER || $id === STILL_WATER || $id === COBWEB){ $this->fallDistance = 0; $this->fallStart = $this->y; } } - + } } } - + if($prevGroundState == $this->onGround && !$this->onGround && $this->player->isSleeping == false && !$this->dead){ //isSleeping may be a vector ++$this->notOnGroundTicks; - }else if($this->onGround){ + }elseif($this->onGround){ $this->notOnGroundTicks = 0; } - + if($this->notOnGroundTicks > 80){ //~70 ticks is needed to reach from 127 to 0 if(($this->player->gamemode & 1) != CREATIVE && !$this->player->blocked && $this->player->spawned){ //survival(0), adventure(2) if(!Entity::$allowFly){ @@ -839,21 +833,20 @@ class Entity extends Position } } } - - + if($this->isOnLadder()){ $this->fallDistance = 0; $this->notOnGroundTicks = 0; $this->fallStart = $this->y; } - + if(!$this->onGround && $prevGroundState){ $this->fallStart = $this->y; } - - $this->updateFallState(($this->speedY <=> 0)*0.1); + + $this->updateFallState(($this->speedY <=> 0) * 0.1); if($this->onGround) $this->fallDistance = 0; - + if($handleCactus){ $this->harm(1, "cactus"); } @@ -862,48 +855,47 @@ class Entity extends Position $this->harm(1, "fire"); if(!$this->inWater){ ++$this->fire; - if($this->fire == 0) $this->fire = 8*20; + if($this->fire == 0) $this->fire = 8 * 20; } }elseif($this->fire <= 0){ $this->fire = -$this->fireResistance; } - + if($this->inWater && $this->fire > 0){ $this->fire = -$this->fireResistance; } - + if(($oldFire > 0 && $this->fire <= 0) || ($oldFire <= 0 && $this->fire > 0)){ $this->updateMetadata(); //TODO rewrite metadata } - - $hasUpdate = true; + + $hasUpdate = true; } } - - + $this->counterUpdate(); - + if($this->isPlayer()){ $this->updateMovement(); } - + if($this->isPlayer()){ $this->player->entityTick(); } - + $this->needsUpdate = $hasUpdate; $this->lastUpdate = $now; } public function isOnLadder(){ - $x = (int)$this->x; - $y = (int)$this->boundingBox->minY; - $z = (int)$this->z; + $x = (int) $this->x; + $y = (int) $this->boundingBox->minY; + $z = (int) $this->z; return $this->level->level->getBlockID($x, $y, $z) === LADDER; } - + public function fall(){ if($this->isPlayer()){ - + $x = floor($this->x); $y = floor($this->y - 1); //TODO not 1 $z = floor($this->z); @@ -912,18 +904,18 @@ class Entity extends Position $clz = StaticBlock::getBlock($bid); $clz::fallOn($this->level, $x, $y, $z, $this, ceil($this->fallStart - $this->y)); } - + $dmg = ceil($this->fallStart - $this->y - 3); if($dmg > 0){ $this->harm($dmg, "fall"); } } } - + public function canBeShot(){ return $this->isPlayer(); } - + public function updateFallState($fallTick){ if($this->onGround && $this->fallDistance > 0){ $this->fall(); @@ -931,9 +923,9 @@ class Entity extends Position }elseif($fallTick < 0){ $this->fallDistance -= $fallTick; } - + } - + public function updateMovement() { if($this->closed === true){ @@ -966,7 +958,7 @@ class Entity extends Position } $this->lastUpdate = $now; } - + /** * Handle fall out of world */ @@ -978,11 +970,11 @@ class Entity extends Position $this->close(); } } - + public function getEyeHeight(){ //TODO in vanilla player's eyeHeight is 0.12 return $this->isPlayer() ? $this->height - 0.12 : $this->height * 0.85; } - + public function interactWith(Entity $e, $action) { if($this->isPlayer() and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($this->player->gamemode & 0x01) === 0x01)){ @@ -1059,7 +1051,7 @@ class Entity extends Position ], 1 => [ "type" => 1, - "value" => (int)$this->air + "value" => (int) $this->air ], 14 => [ "type" => 0, @@ -1099,7 +1091,7 @@ class Entity extends Position public function spawn($player) { - if(! ($player instanceof Player)){ + if(!($player instanceof Player)){ $player = $this->server->api->player->get($player); } if($player->eid === $this->eid or $this->closed !== false or ($player->level !== $this->level and $this->class !== ENTITY_PLAYER)){ @@ -1155,13 +1147,13 @@ class Entity extends Position $pk->did = -$this->data["Tile"]; $player->dataPacket($pk); } - + if($this->linkedEntity != 0 && $this->isRider){ $player->eventHandler(["rider" => $this->eid, "riding" => $this->linkedEntity, "type" => 0], "entity.link"); //TODO fix it } - + } - + public function counterUpdate(){ if($this->knockbackTime > 0){ --$this->knockbackTime; @@ -1178,13 +1170,12 @@ class Entity extends Position if($this->idleTime > 0){ --$this->idleTime; } - - + if($this->inAction){ ++$this->inActionCounter; } } - + public function close() { if($this->closed === false){ @@ -1224,7 +1215,7 @@ class Entity extends Position public function updateAABB() { $this->boundingBox->setBounds( - $this->x - $this->radius, $this->y - $this->yOffset, $this->z - $this->radius, + $this->x - $this->radius, $this->y - $this->yOffset, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height - $this->yOffset, $this->z + $this->radius ); } @@ -1234,7 +1225,7 @@ class Entity extends Position $this->sendMoveUpdate(); $this->updateAABB(); } - + public function setPosition(Vector3 $pos, $yaw = false, $pitch = false, $headYaw = false) { $this->x = $pos->x; @@ -1246,12 +1237,12 @@ class Entity extends Position if($pitch !== false){ $this->pitch = $pitch; } - + if($headYaw !== false) $this->headYaw = $headYaw; } public function inBlockNonVector($x, $y, $z, $radius = 0.8) { - return $y == ceil($this->y) || $y == (ceil($this->y)+1) && max(abs($x - ($this->x-0.5)), abs($z - ($this->z-0.5))); + return $y == ceil($this->y) || $y == (ceil($this->y) + 1) && max(abs($x - ($this->x - 0.5)), abs($z - ($this->z - 0.5))); } public function inBlock(Vector3 $block, $radius = 0.8) { @@ -1275,7 +1266,7 @@ class Entity extends Position { $me = new Vector2($this->x - 0.5, $this->z - 0.5); $diff = $this->y - $pos->y; - if($me->distance(new Vector2($pos->x, $pos->z)) < $radius and $diff > - 0.7 and $diff < 1.6){ + if($me->distance(new Vector2($pos->x, $pos->z)) < $radius and $diff > -0.7 and $diff < 1.6){ return true; } return false; @@ -1283,7 +1274,7 @@ class Entity extends Position public function resetSpeed() { - $this->speedMeasure = array(0, 0, 0, 0, 0, 0, 0); + $this->speedMeasure = [0, 0, 0, 0, 0, 0, 0]; } public function getSpeed() @@ -1333,7 +1324,7 @@ class Entity extends Position "speedX" => $this->speedX, "speedY" => $this->speedY, "speedZ" => $this->speedZ, - + ]; if($this->class === ENTITY_OBJECT){ $data["TileX"] = $this->x; @@ -1349,12 +1340,12 @@ class Entity extends Position "Damage" => $this->meta, "Count" => $this->stack, ]; - + $data["id"] = 64; //ty shoghicp } return $data; } - + public function updateLast() { $this->lastX = $this->x; @@ -1387,30 +1378,30 @@ class Entity extends Position // $dmg = 0; // break; case 1: - $dmg = (int)($dmg / 3) + 1; + $dmg = (int) ($dmg / 3) + 1; break; case 3: - $dmg = 3 * (int)($dmg / 2); + $dmg = 3 * (int) ($dmg / 2); break; } } } - + $dmg = $this->applyArmor($dmg, $cause); - $ret = $this->setHealth(max(- 128, $this->getHealth() - ((int) $dmg)), $cause, $force); - + $ret = $this->setHealth(max(-128, $this->getHealth() - ((int) $dmg)), $cause, $force); + if($ret && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false){ //TODO simplify $this->attackTimeout = 10; } - + if ($ret != false && $this->hasKnockback && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false) { - + $d = $entity->x - $this->x; for ($d1 = $entity->z - $this->z; $d * $d + $d1 * $d1 < 0.0001; $d1 = (lcg_value() - lcg_value()) * 0.01) { $d = (lcg_value() - lcg_value()) * 0.01; } - + $this->knockBack($d, $d1); if($this->isPlayer()){ $pk = new SetEntityMotionPacket(); @@ -1442,7 +1433,7 @@ class Entity extends Position { return $this->setHealth(min(20, $this->getHealth() + ((int) $health)), $cause); } - + public function stopRiding(){ if(isset($this->level->entityList[$this->linkedEntity])){ $e = $this->level->entityList[$this->linkedEntity]; @@ -1457,28 +1448,28 @@ class Entity extends Position $this->linkedEntity = 0; } } - + public function setPos($x, $y, $z){ $this->x = $x; $this->y = $y; $this->z = $z; - + $this->boundingBox->minX = $x - $this->radius; $this->boundingBox->minY = ($y - $this->yOffset); //TODO what is this + $this->ySize; $this->boundingBox->minZ = $z - $this->radius; - + $this->boundingBox->maxX = $x + $this->radius; $this->boundingBox->maxY = $this->boundingBox->minY + $this->height; $this->boundingBox->maxZ = $z + $this->radius; } - + public function setRiding(Entity $e, $type = 0) { if(!isset($this->level->entityList[$e->eid])){ ConsoleAPI::warn("Tried linking $this with $e that doesnt exist in the world!"); return; } - + if($this->linkedEntity == $e->eid || $e->eid == $this->eid){ $this->linkedEntity = 0; $e->linkedEntity = 0; @@ -1489,8 +1480,7 @@ class Entity extends Position $this->isRider = true; $this->server->api->dhandle("entity.link", ["rider" => $this->eid, "riding" => $e->eid, "type" => 0]); } - - + } public function isPlayer() @@ -1539,7 +1529,7 @@ class Entity extends Position } return $damage; } - + public function setHealth($health, $cause = "generic", $force = false, $allowHarm = true) { $health = (int) $health; @@ -1556,14 +1546,14 @@ class Entity extends Position }elseif($health === $this->health and !$this->dead){ $harm = true; } - - if($this->server->api->dhandle("entity.health.change", array( + + if($this->server->api->dhandle("entity.health.change", [ "entity" => $this, "eid" => $this->eid, "health" => $health, "cause" => $cause - )) !== false or $force === true){ - $this->health = min(127, max(- 127, $health)); + ]) !== false or $force === true){ + $this->health = min(127, max(-127, $health)); if($harm === true && $allowHarm){ $pk = new EntityEventPacket; $pk->eid = $this->eid; @@ -1599,7 +1589,7 @@ class Entity extends Position $this->height = $h; $this->radius = $w / 2; } - + public function makeDead($cause){ if($this->server->api->dhandle("entity.death", ["entity" => $this, "cause" => $cause]) === false) return false; $this->spawnDrops(); @@ -1644,11 +1634,11 @@ class Entity extends Position } } } - + public function getAttackDamage(){ return 0; } - + public function setSpeed($s) { $this->speed = $s; @@ -1681,14 +1671,14 @@ class Entity extends Position { return "Entity(x={$this->x},y={$this->y},z={$this->z},level=" . $this->level->getName() . ",class={$this->class},type={$this->type})"; } - + /** * Debug */ public function printSpeed($add = ""){ ConsoleAPI::debug("$add {$this->speedX}:{$this->speedY}:{$this->speedZ}"); } - + /* * Deprecated methods. * Those methods were left only for compability with older plugins @@ -1702,8 +1692,7 @@ class Entity extends Position { throw new Exception("Use getHeightOf or getWidthOf method instead of this."); } - - + /** * * @deprecated Use {@link getHeight} or {@link getWidth} instead diff --git a/src/entity/Living.php b/src/entity/Living.php index d00f9bfb..90735cc5 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -1,12 +1,11 @@ target = false; $this->ai = new EntityAI($this); $this->pathFinder = new TileNavigator($this); @@ -30,43 +29,43 @@ abstract class Living extends Entity implements Pathfindable{ $this->canBeAttacked = true; $this->hasGravity = true; $this->hasKnockback = true; - + //if(self::$despawnMobs) $this->server->schedule(self::$despawnTimer, [$this, "close"]); //900*20 } - + public function isPickable(){ return !$this->dead; } - + public function fall(){ $dmg = ceil($this->fallDistance - 3); if($dmg > 0){ $this->harm($dmg, "fall"); } } - + public function handlePlayerSearcher(Player $player, $dist){ - + } - + public function getAIMoveSpeed(){ return $this->aiMoveSpeed; } - + public function getVerticalFaceSpeed(){ return 40; //unused in 0.8 but may be useful in 0.9/0.10 } - + public function setAIMoveSpeed($speed){ $this->aiMoveSpeed = $speed; $this->moveForward = $speed; } - + public function hasPath(){ return $this->path != null; } public function eatGrass(){} - + public function close(){ parent::close(); unset($this->pathFollower->entity); @@ -76,22 +75,22 @@ abstract class Living extends Entity implements Pathfindable{ unset($this->parent); unset($this->pathFinder->entity); } - + public function canBeShot(){ return true; } - + public function isPushable(){ return !$this->dead; } - + public function collideHandler(){ $bb = $this->boundingBox->expand(0.2, 0, 0.2); - $minChunkX = ((int)($bb->minX)) >> 4; - $minChunkZ = ((int)($bb->minZ)) >> 4; - $maxChunkX = ((int)($bb->minX)) >> 4; - $maxChunkZ = ((int)($bb->minZ)) >> 4; - + $minChunkX = ((int) ($bb->minX)) >> 4; + $minChunkZ = ((int) ($bb->minZ)) >> 4; + $maxChunkX = ((int) ($bb->minX)) >> 4; + $maxChunkZ = ((int) ($bb->minZ)) >> 4; + //TODO also index by chunkY? for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){ for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){ @@ -106,14 +105,14 @@ abstract class Living extends Entity implements Pathfindable{ } } } - + public function update($now){ if(self::$despawnMobs && ++$this->ticksExisted > self::$despawnTimer){ $this->close(); return; } if($this->closed) return; - + $check = $this->level->mobSpawner->checkDespawn($this); if($check){ $this->close(); @@ -121,7 +120,7 @@ abstract class Living extends Entity implements Pathfindable{ } parent::update($now); } - + public $pathEIDS = []; private static $lastPathEID = 10000000; public static $pathfind = true; @@ -139,22 +138,21 @@ abstract class Living extends Entity implements Pathfindable{ } if(self::$pathfind){ $this->path = $this->pathFinder->navigate( - $this->level, - (int)$this->x, (int)$this->y, (int)$this->z, - //(int)$pl->entity->x, (int)$pl->entity->y, (int)$pl->entity->z, - (int)$this->x + mt_rand(-16, 16), (int)$this->y, (int)$this->z + mt_rand(-16, 16), + $this->level, + (int) $this->x, (int) $this->y, (int) $this->z, + //(int)$pl->entity->x, (int)$pl->entity->y, (int)$pl->entity->z, + (int) $this->x + mt_rand(-16, 16), (int) $this->y, (int) $this->z + mt_rand(-16, 16), 16 ); } - - + /*if($this->path){ console("Found path of length ".count($this->path)); - + foreach($this->path as $node){ $eid = self::$lastPathEID++; $this->pathEIDS[] = $eid; - + $pk = new AddItemEntityPacket(); $pk->eid = $eid; $pk->item = BlockAPI::getItem(GOLD_BLOCK, 0, 1); @@ -171,8 +169,7 @@ abstract class Living extends Entity implements Pathfindable{ } $this->pathFollower->followPath(); } - - + //not exactly here if($this->jumping){ if(!$this->inWater && !$this->inLava){ @@ -186,12 +183,11 @@ abstract class Living extends Entity implements Pathfindable{ }else{ $this->jumpTicks = 0; } - - + $this->ai->mobController->movementTick(); $this->ai->mobController->rotateTick(); $this->ai->mobController->jumpTick(); - + if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0; if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0; if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0; @@ -203,24 +199,23 @@ abstract class Living extends Entity implements Pathfindable{ $this->landMovementFactor = $savedLandFactor; //Yaw rotation in 1.5 is handled in a bit different place but hopefully this will work too $this->ai->mobController->updateHeadYaw(); - + if(self::$entityPushing){ $this->collideHandler(); } } - + public function jump(){ $this->speedY = 0.42; - + //TODO also set AirBorne? } - + public function counterUpdate(){ parent::counterUpdate(); if($this->jumpTicks > 0) --$this->jumpTicks; } - - + public function moveEntityWithHeading($strafe, $forward){ if($this->inWater){ //also check is player, and can it fly or not $prevPosY = $this->y; @@ -230,8 +225,7 @@ abstract class Living extends Entity implements Pathfindable{ $this->speedY *= 0.8; $this->speedZ *= 0.8; $this->speedY -= 0.02; - - + if($this->isCollidedHorizontally && $this->isFree($this->speedX, $this->speedY + 0.6 - $this->y + $prevPosY, $this->speedZ)){ $this->speedY = 0.3; } @@ -243,69 +237,69 @@ abstract class Living extends Entity implements Pathfindable{ $this->speedY *= 0.5; $this->speedZ *= 0.5; $this->speedY -= 0.02; - + if($this->isCollidedHorizontally && $this->isFree($this->speedX, $this->speedY + 0.6 - $this->y + $prevPosY, $this->speedZ)){ $this->speedY = 0.3; } }else{ $friction = 0.91; - + if($this->onGround){ $friction = 0.546; $blockAt = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minY) - 1, floor($this->z)); - + if($blockAt > 0) $friction = StaticBlock::getSlipperiness($blockAt) * 0.91; } - - $var8 = 0.16277 / ($friction*$friction*$friction); - + + $var8 = 0.16277 / ($friction * $friction * $friction); + if($this->onGround){ $var5 = $this->getAIMoveSpeed(); //in vanilla it returns either this.seed or calls getBaseSpeed(depending on useNewAi) $var5 *= $var8; //in vanilla it also multiplies by speedModifer }else{ $var5 = $this->jumpMovementFactor; } - + $this->moveFlying($strafe, $forward, $var5); //recalculating friction, might be not neccessary $friction = 0.91; - + if($this->onGround){ $friction = 0.546; $blockAt = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minY) - 1, floor($this->z)); - + if($blockAt > 0) $friction = StaticBlock::getSlipperiness($blockAt) * 0.91; } - + if($this->isOnLadder()){ $speedY = $this->speedY; $this->fallDistance = 0; if($speedY < -0.15) $this->speedY = -0.15; } - + $this->move($this->speedX, $this->speedY, $this->speedZ); - + if($this->isOnLadder() && $this->isCollidedHorizontally){ $this->speedY = 0.2; } - + $this->speedY -= 0.08; //gravity - + $this->speedY *= 0.98; $this->speedX *= $friction; $this->speedZ *= $friction; - + if($this->isCollidedHorizontally && $this->enableAutojump){ $this->ai->mobController->setJumping(true); //non vanilla } } } - + public function sendMoveUpdate(){ if($this->counter % 3 != 0){ return; } parent::sendMoveUpdate(); - + } } diff --git a/src/entity/Monster.php b/src/entity/Monster.php index be046207..6e4468e2 100644 --- a/src/entity/Monster.php +++ b/src/entity/Monster.php @@ -1,17 +1,18 @@ spawned && !$player->entity->dead; } - + public function handlePrePlayerSearcher(){ parent::handlePrePlayerSearcher(); if($this->closestPlayerToAttackEID !== false){ @@ -35,15 +36,15 @@ class Monster extends Creature{ $this->closestPlayerToAttackEID = false; $this->closestPlayerToAttackDist = INF; }else{ - $dist = ($this->x - $player->x)*($this->x - $player->x) + ($this->y - $player->y)*($this->y - $player->y) + ($this->z - $player->z)*($this->z - $player->z); + $dist = ($this->x - $player->x) * ($this->x - $player->x) + ($this->y - $player->y) * ($this->y - $player->y) + ($this->z - $player->z) * ($this->z - $player->z); $this->closestPlayerToAttackDist = $dist; } } } - + public function handlePlayerSearcher(Player $player, $dist){ parent::handlePlayerSearcher($player, $dist); - + if($this->closestPlayerToAttackDist >= $dist){ if($this->isPlayerValid($player)){ $this->closestPlayerToAttackDist = $dist; @@ -51,5 +52,5 @@ class Monster extends Creature{ } } } - + } diff --git a/src/entity/Projectile.php b/src/entity/Projectile.php index 3c37424b..ed9df100 100644 --- a/src/entity/Projectile.php +++ b/src/entity/Projectile.php @@ -1,4 +1,5 @@ gravity = 0.03; $this->setSize(0.25, 0.25); - + $this->x -= cos($this->yaw / 180 * M_PI) * 0.16; $this->y -= 0.1; $this->z -= cos($this->yaw / 180 * M_PI) * 0.16; @@ -25,7 +26,7 @@ abstract class Projectile extends Entity{ $this->xTile = $data["xTile"] ?? $this->xTile; $this->yTile = $data["yTile"] ?? $this->yTile; $this->zTile = $data["zTile"] ?? $this->zTile; - + if($shooter instanceof Entity){ $this->shooterEID = $shooter->eid; if($shooter->isPlayer()){ @@ -44,9 +45,9 @@ abstract class Projectile extends Entity{ $this->shoot(, , , $throwPower, 1.0);*/ } } - + } - + public function shoot($d, $d1, $d2, $f, $f1){ //unchecked, may be not same as arrow $f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2); $d /= $f2; @@ -66,7 +67,7 @@ abstract class Projectile extends Entity{ $this->pitch = (atan2($d1, $f3) * 180) / M_PI; $this->updatePosition(); } - + public function update($now){ $this->lastX = $this->x; $this->lastY = $this->y; @@ -88,32 +89,32 @@ abstract class Projectile extends Entity{ $this->fire -= 4; if($this->fire <= 0) $this->fire = 0; } - + if($this->fire <= 0){ $this->updateMetadata(); } } - + if($this->handleLavaMovement()){ if(!$this->isImmuneToFire){ $this->harm(4, "fire"); $oldOnFire = $this->fire; - if($oldOnFire < 20*30) $this->fire = 20*30; //30 seconds + if($oldOnFire < 20 * 30) $this->fire = 20 * 30; //30 seconds } } - + if($this->isInVoid()){ $this->outOfWorld(); } //Entity::update end - + if($this->shake > 0) --$this->shake; - + if(!$this->inGround){ ++$this->ticksInAir; goto CHECK_COLLISIONS; //TODO dont use gotos } - + $blockID = $this->level->level->getBlockID($this->xTile, $this->yTile, $this->zTile); if($this->inTile != $blockID){ $this->speedX += (lcg_value() * 0.2); @@ -122,7 +123,7 @@ abstract class Projectile extends Entity{ $this->inGround = false; $this->ticksInAir = $this->ticksInGround = 0; CHECK_COLLISIONS: - + $start = new Vector3($this->x, $this->y, $this->z); $end = new Vector3($this->x + $this->speedX, $this->y + $this->speedY, $this->z + $this->speedZ); /** @@ -135,44 +136,44 @@ abstract class Projectile extends Entity{ }else{ $end = new Vector3($this->x + $this->speedX, $this->y + $this->speedY, $this->z + $this->speedZ); } - + $entities = $this->level->getEntitiesInAABB($this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ)->expand(1, 1, 1)); $bestDist = 0; $bestEnt = null; - + foreach($entities as $eid => $ent){ if($eid != $this->eid && $ent->isPickable() && ($eid != $this->shooterEID || $this->ticksInAir >= 5)){ - + $v12 = $ent->boundingBox->expand(0.3, 0.3, 0.3); $v13 = $v12->calculateIntercept($start, $end); - + if($v13 != null){ $dist = $start->distance($v13->hitVector); - + if($dist < $bestDist || $bestDist == 0){ $bestEnt = $ent; } } } } - + if($bestEnt != null){ $v4 = MovingObjectPosition::fromEntity($bestEnt); } - + if($v4 != null){ $this->onHit($v4); } $this->x += $this->speedX; $this->y += $this->speedY; $this->z += $this->speedZ; - $v21 = sqrt($this->speedX*$this->speedX + $this->speedZ*$this->speedZ); + $v21 = sqrt($this->speedX * $this->speedX + $this->speedZ * $this->speedZ); $this->yaw = atan2($this->speedX, $this->speedZ) * 180 / M_PI; $this->pitch = atan2($this->speedY, $v21) * 180 / M_PI; - + $this->pitch = $this->lastPitch + ($this->pitch - $this->lastPitch) * 0.2; $this->yaw = $this->lastYaw + ($this->yaw - $this->lastYaw) * 0.2; - + $v24 = $this->inWater ? 0.8 : 0.99; $this->speedX *= $v24; $this->speedY *= $v24; @@ -183,19 +184,19 @@ abstract class Projectile extends Entity{ $this->boundingBox->setBounds($this->x - $v7, $this->y - $this->yOffset /*+ $this->ySize*/, $this->z - $v7, $this->x + $v7, $this->y - $this->yOffset + $v8 /*+ $this->ySize*/, $this->z + $v7); } } - + public function onHit(MovingObjectPosition $hitResult){ - + } public function createSaveData(){ $data = parent::createSaveData(); - + $data["inTile"] = $this->inTile; $data["inGround"] = $this->inGround; $data["xTile"] = $this->xTile; $data["yTile"] = $this->yTile; $data["zTile"] = $this->zTile; - + return $data; } public function spawn($player) @@ -212,5 +213,5 @@ abstract class Projectile extends Entity{ $pk->did = 0; $player->dataPacket($pk); } - + } \ No newline at end of file diff --git a/src/entity/ai/EntityAI.php b/src/entity/ai/EntityAI.php index a8c9d883..d7f1d820 100644 --- a/src/entity/ai/EntityAI.php +++ b/src/entity/ai/EntityAI.php @@ -10,29 +10,27 @@ class EntityAI * @var Living */ public $entity; - + /** * @var TaskBase[] */ protected $tasks; - + public $lastTask; - + public function __construct($entity){ $this->entity = $entity; $this->tasks = []; $this->mobController = new MobController($entity); } - - + public function canSee(Entity $entity){ //TODO caches return $this->entity->canSee($entity); } - + /** * Add a task for entity - * @param TaskBase $task */ public function addTask(TaskBase $task){ $this->tasks[$task->__toString()] = $task; @@ -44,16 +42,16 @@ class EntityAI } return false; } - + /** - * + * * @param mixed $id classname * @return TaskBase | false */ public function getTask($id){ return $this->tasks[$id] ?? false; } - + public function isStarted($id){ $task = $this->getTask($id); return $task instanceof TaskBase && $task->isStarted; @@ -75,10 +73,10 @@ class EntityAI } } } - + public function __destruct(){ unset($this->entity); } - + } diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index fd6d772e..13b4efa0 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -14,24 +14,24 @@ class MobController * @var Living */ public $entity; - + public $finalYaw, $finalPitch, $finalHeadYaw; - + public $headYaw; public $someTicker = 0; - + protected $jumping; - + public $moveToX, $moveToY, $moveToZ; public $speedMultiplier; public $updateMove = false; - + public $lookX, $lookY, $lookZ; public $deltaLookYaw, $deltaLookPitch; public $isLooking = false; - + public $headYawIsYaw = false; - + public function __construct($e){ $this->entity = $e; } @@ -41,11 +41,11 @@ class MobController public function isJumping(){ return $this->jumping; } - + public function setJumping($b){ $this->jumping = $b; } - + public function isRotationCompleted(){ return $this->finalHeadYaw === $this->entity->headYaw; } @@ -56,7 +56,7 @@ class MobController $this->speedMultiplier = $speed; $this->updateMove = true; } - + public function setMovingOffset($x, $y, $z, $speed){ $this->moveToX = $this->entity->x + ($x); $this->moveToY = $this->entity->y + ($y); @@ -64,50 +64,50 @@ class MobController $this->speedMultiplier = $speed; $this->updateMove = true; } - + public function canJump(){ return $this->isJumping() && $this->jumpTimeout <= 0 && $this->entity->onGround; } public static function limitAngle2($old, $newA, $limit){ $v4 = Utils::wrapAngleTo180($old - $newA); - + if($v4 < -$limit) $v4 = -$limit; if($v4 >= $limit) $v4 = $limit; - + return $old - $v4; } public static function limitAngle($old, $newA, $limit){ $v4 = Utils::wrapAngleTo180($newA - $old); - + if($v4 > $limit) $v4 = $limit; if($v4 < -$limit) $v4 = -$limit; - + return $old + $v4; } - + public function jumpTick(){ $this->entity->jumping = $this->jumping; $this->jumping = false; } - + public function movementTick(){ $this->entity->moveForward = 0; if($this->updateMove){ $this->updateMove = false; $v1 = floor($this->entity->boundingBox->minY + 0.5); - + $diffX = $this->moveToX - $this->entity->x; $diffZ = $this->moveToZ - $this->entity->z; $diffY = $this->moveToY - $v1; - - $v8 = $diffX*$diffX + $diffY*$diffY + $diffZ*$diffZ; - + + $v8 = $diffX * $diffX + $diffY * $diffY + $diffZ * $diffZ; + if($v8 >= 0.00000025){ $v10 = (atan2($diffZ, $diffX) * 180 / M_PI) - 90; $this->entity->yaw = self::limitAngle($this->entity->yaw, $v10, 30); $this->entity->setAIMoveSpeed($this->speedMultiplier * $this->entity->getSpeed() * $this->entity->getSpeedModifer()); - - if($diffY > 0 && $diffX*$diffX + $diffZ*$diffZ < 1) $this->setJumping(true); + + if($diffY > 0 && $diffX * $diffX + $diffZ * $diffZ < 1) $this->setJumping(true); } } //TODO handle jumps somewhere @@ -117,11 +117,11 @@ class MobController //} //if($this->jumpTimeout > 0) --$this->jumpTimeout; } - + public function updateHeadYaw(){ $diffX = $this->entity->x - $this->entity->lastX; $diffZ = $this->entity->z - $this->entity->lastZ; - if(($diffX*$diffX + $diffZ*$diffZ) > 0.00000025){ + if(($diffX * $diffX + $diffZ * $diffZ) > 0.00000025){ $this->entity->renderYawOffset = $this->entity->yaw; $this->entity->headYaw = self::limitAngle2($this->entity->renderYawOffset, $this->entity->headYaw, 75); $this->headYaw = $this->entity->headYaw; @@ -133,7 +133,7 @@ class MobController $this->headYaw = $this->entity->headYaw; }else{ ++$this->someTicker; - + if($this->someTicker > 10){ $v5 = max(1 - ($this->someTicker - 10) / 10, 0) * 75; } @@ -141,53 +141,53 @@ class MobController $this->entity->renderYawOffset = self::limitAngle2($this->entity->headYaw, $this->entity->renderYawOffset, $v5); } } - + public function rotateTick(){ //TODO handle more rotation - + $this->entity->pitch = 0; if($this->isLooking){ $this->isLooking = false; - + $diffX = $this->lookX - $this->entity->x; $diffY = $this->lookY - ($this->entity->y + $this->entity->getEyeHeight()); $diffZ = $this->lookZ - $this->entity->z; - $distance = sqrt($diffX*$diffX + $diffZ*$diffZ); - - $v9 = (atan2($diffZ, $diffX)*180 / M_PI) - 90; - $v10 = -(atan2($diffY, $distance)*180 / M_PI); - + $distance = sqrt($diffX * $diffX + $diffZ * $diffZ); + + $v9 = (atan2($diffZ, $diffX) * 180 / M_PI) - 90; + $v10 = -(atan2($diffY, $distance) * 180 / M_PI); + $this->entity->pitch = self::limitAngle($this->entity->pitch, $v10, $this->deltaLookPitch); $this->entity->headYaw = self::limitAngle($this->entity->headYaw, $v9, $this->deltaLookYaw); }else{ $this->entity->headYaw = self::limitAngle($this->entity->headYaw, $this->entity->renderYawOffset, 10); } - + if($this->headYawIsYaw) $this->entity->yaw = $this->entity->headYaw; $this->headYawIsYaw = false; - + /* Some stuff for pathfinder - nc doesnt have it now * float var11 = MathHelper.wrapAngleTo180_float(this.entity.rotationYawHead - this.entity.renderYawOffset); - if (!this.entity.getNavigator().noPath()) - { - if (var11 < -75.0F) - { - this.entity.rotationYawHead = this.entity.renderYawOffset - 75.0F; - } + if (!this.entity.getNavigator().noPath()) + { + if (var11 < -75.0F) + { + this.entity.rotationYawHead = this.entity.renderYawOffset - 75.0F; + } - if (var11 > 75.0F) - { - this.entity.rotationYawHead = this.entity.renderYawOffset + 75.0F; - } - } + if (var11 > 75.0F) + { + this.entity.rotationYawHead = this.entity.renderYawOffset + 75.0F; + } + } */ - + //$this->entity->lastHeadYaw = $this->entity->headYaw; - //$w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw); + //$w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw); //$w180min = min(abs($w180), 20)*Utils::getSign($w180); //$this->entity->headYaw = Utils::wrapAngleTo360($this->entity->headYaw + $w180min); } - + public function setLookPosition($posX, $posY, $posZ, $lookYaw, $lookPitch){ $this->lookX = $posX; $this->lookY = $posY; @@ -196,9 +196,9 @@ class MobController $this->deltaLookPitch = $lookPitch; $this->isLooking = true; } - + public function faceEntity($x, $y, $z){ - $len = sqrt($x*$x + $z*$z + $y*$y); + $len = sqrt($x * $x + $z * $z + $y * $y); //$d = $len == 0 ?//$v->subtract($this->entity)->normalize(); if($len == 0){ $dx = 0; @@ -207,38 +207,37 @@ class MobController $dx = $x / $len; $dz = $z / $len; } - - - $tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg(atan($dx / $dz))); + + $tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg(atan($dx / $dz))); $thetaOffset = $dz < 0 ? 90 : 270; $calcYaw = ($thetaOffset + $tan); $this->finalHeadYaw = $this->entity->yaw = Utils::wrapAngleTo360($calcYaw); } - + public function lookOffset($x, $y, $z, $pitch = true){ $tan = $z == 0 ? ($x < 0 ? 180 : 0) : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/ $thetaOffset = $z < 0 ? 90 : 270; $calcYaw = $tan + $thetaOffset; - + $this->entity->yaw = $this->finalHeadYaw = Utils::wrapAngleTo360($calcYaw); - + if($pitch){ $diff = sqrt($x * $x + $z * $z); $calcPitch = $diff == 0 ? ($y < 0 ? -90 : 90) : rad2deg(atan($y / $diff)); $this->entity->pitch = $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/PathFollower.php b/src/entity/ai/path/PathFollower.php index c17cde93..3066c4fe 100644 --- a/src/entity/ai/path/PathFollower.php +++ b/src/entity/ai/path/PathFollower.php @@ -5,16 +5,16 @@ class PathFollower{ * @var Living */ public $entity; - + public function __construct(Living $entity){ $this->entity = $entity; } - + public function followPath(){ - + if(!isset($this->entity) || !($this->entity instanceof Living)) return; if(!$this->entity->hasPath()) return; - + if($this->entity->currentNode == null){ $this->entity->currentNode = $this->entity->path[$this->entity->currentIndex]; } @@ -27,14 +27,13 @@ class PathFollower{ //console("next"); $this->entity->currentNode = null; } - - + if($this->entity->currentIndex >= count($this->entity->path)){ console("path finished."); $this->entity->currentNode = null; $this->entity->path = null; $this->entity->currentIndex = 0; - + /*foreach($this->entity->pathEIDS as $eid){ $pk = new RemoveEntityPacket(); $pk->eid = $eid; @@ -42,9 +41,9 @@ class PathFollower{ $player->dataPacket($pk); } }*/ - + } } - + } diff --git a/src/entity/ai/tasks/TaskAttackPlayer.php b/src/entity/ai/tasks/TaskAttackPlayer.php index 8760cd11..213a0eb2 100644 --- a/src/entity/ai/tasks/TaskAttackPlayer.php +++ b/src/entity/ai/tasks/TaskAttackPlayer.php @@ -4,20 +4,19 @@ class TaskAttackPlayer extends TaskBase { public $speedMultiplier; public $rangeSquared; - + public $attackCounter; - + public function __construct($speed, $range){ $this->speedMultiplier = $speed; - $this->rangeSquared = $range*$range; + $this->rangeSquared = $range * $range; } - + public function onStart(EntityAI $ai) { $this->selfCounter = 1; } - - + public function onUpdate(EntityAI $ai) { if(!$this->isTargetValid($ai)){ @@ -27,7 +26,7 @@ class TaskAttackPlayer extends TaskBase } $ai->mobController->setMovingTarget($ai->entity->target->x, $ai->entity->target->y, $ai->entity->target->z, $this->speedMultiplier); $ai->mobController->setLookPosition($ai->entity->target->x, $ai->entity->target->y + 0.12, $ai->entity->target->z, 10, $ai->entity->getVerticalFaceSpeed()); - + --$this->attackCounter; $v1 = $ai->entity->width * $ai->entity->width * 4; if($ai->entity instanceof Creeper){ @@ -38,16 +37,15 @@ class TaskAttackPlayer extends TaskBase $xDiff = ($t->x - $e->x); $yDiff = ($t->y - $e->y); $zDiff = ($t->z - $e->z); - $dist = ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff); + $dist = ($xDiff * $xDiff + $yDiff * $yDiff + $zDiff * $zDiff); if($dist <= $v1){ if($this->attackCounter <= 0){ $this->attackCounter = $e->attackEntity($t, sqrt($dist)) ? 20 : 0; } } - + } - - + public function isTargetValid(EntityAI $ai){ $e = $ai->entity; if($e->target instanceof Entity && !$e->target->closed && !$e->target->dead){ @@ -55,11 +53,11 @@ class TaskAttackPlayer extends TaskBase $xDiff = ($t->x - $e->x); $yDiff = ($t->y - $e->y); $zDiff = ($t->z - $e->z); - return ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= $this->rangeSquared; + return ($xDiff * $xDiff + $yDiff * $yDiff + $zDiff * $zDiff) <= $this->rangeSquared; } return false; } - + public function tryTargeting(EntityAI $ai){ $e = $ai->entity; if($e->target instanceof Entity){ @@ -67,25 +65,25 @@ class TaskAttackPlayer extends TaskBase $xDiff = ($t->x - $e->x); $yDiff = ($t->y - $e->y); $zDiff = ($t->z - $e->z); - if(($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= $this->rangeSquared){ + if(($xDiff * $xDiff + $yDiff * $yDiff + $zDiff * $zDiff) <= $this->rangeSquared){ return true; } } - + $closestTarget = $e->closestPlayerToAttackDist <= $this->rangeSquared ? $e->level->entityList[$e->closestPlayerToAttackEID] : null; - + if($closestTarget != null){ $e->target = $closestTarget; //TODO dont save entity object ? return true; } return false; } - + public function canBeExecuted(EntityAI $ai) { return $this->tryTargeting($ai); } - + public function onEnd(EntityAI $ai) { $ai->entity->target = false; diff --git a/src/entity/ai/tasks/TaskBase.php b/src/entity/ai/tasks/TaskBase.php index 14f776eb..dd2eba25 100644 --- a/src/entity/ai/tasks/TaskBase.php +++ b/src/entity/ai/tasks/TaskBase.php @@ -3,45 +3,41 @@ abstract class TaskBase { public $isStarted = false, $selfCounter = 0; - + public function __construct(){} - + /** * 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/TaskEatTileGoal.php b/src/entity/ai/tasks/TaskEatTileGoal.php index 5af5d21e..4f69a7a8 100644 --- a/src/entity/ai/tasks/TaskEatTileGoal.php +++ b/src/entity/ai/tasks/TaskEatTileGoal.php @@ -10,7 +10,7 @@ class TaskEatTileGoal extends TaskBase public function onEnd(EntityAI $ai) { - + } public function onUpdate(EntityAI $ai) @@ -18,7 +18,7 @@ class TaskEatTileGoal extends TaskBase if($ai->isStarted("TaskPanic")){ $this->reset(); return false; - } + } if (--$this->selfCounter == 4) { @@ -27,7 +27,7 @@ class TaskEatTileGoal extends TaskBase if($id === TALL_GRASS){ $ai->entity->level->fastSetBlockUpdate($ai->entity->x, $ai->entity->y, $ai->entity->z, AIR, 0); $ai->entity->eatGrass(); - + }elseif($idb === GRASS){ $ai->entity->level->fastSetBlockUpdate($ai->entity->x, $ai->entity->y - 1, $ai->entity->z, DIRT, 0); $ai->entity->eatGrass(); diff --git a/src/entity/ai/tasks/TaskFollowParent.php b/src/entity/ai/tasks/TaskFollowParent.php index 99dcdbe6..9c5a989d 100644 --- a/src/entity/ai/tasks/TaskFollowParent.php +++ b/src/entity/ai/tasks/TaskFollowParent.php @@ -5,7 +5,7 @@ class TaskFollowParent extends TaskBase public function __construct($speed){ $this->speedMultiplier = $speed; } - + public function onStart(EntityAI $ai) { $this->selfCounter = 1; @@ -23,19 +23,19 @@ class TaskFollowParent extends TaskBase $ai->entity->parent = null; return false; } - + $dist = $ai->entity->distanceSquared($ai->entity->parent); - + if($dist > 256 || $dist < 9){ //3-16 blocks $this->reset(); return false; } $parent = $ai->entity->parent; - + $ai->mobController->setLookPosition($parent->x, $parent->y + $parent->getEyeHeight(), $parent->z, 10, $ai->entity->getVerticalFaceSpeed()); $ai->mobController->setMovingTarget($parent->x, $parent->y, $parent->z, $this->speedMultiplier); } - + public function canBeExecuted(EntityAI $ai) { return $ai->entity->isBaby() && ($ai->entity->parent instanceof Entity) && !$ai->entity->parent->dead; //TODO find a new parent if the current one is dead diff --git a/src/entity/ai/tasks/TaskLookAround.php b/src/entity/ai/tasks/TaskLookAround.php index a931d98a..6463503a 100644 --- a/src/entity/ai/tasks/TaskLookAround.php +++ b/src/entity/ai/tasks/TaskLookAround.php @@ -3,7 +3,7 @@ class TaskLookAround extends TaskBase { public $lookOffsetX, $lookOffsetZ; - + public function onStart(EntityAI $ai) { $this->selfCounter = 20 + lcg_value(); @@ -19,9 +19,9 @@ class TaskLookAround extends TaskBase public function canBeExecuted(EntityAI $ai) { - return !$ai->entity->inPanic && !$ai->entity->isMoving() && lcg_value() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskAttackPlayer") && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath(); /*Vanilla value*/ + return !$ai->entity->inPanic && !$ai->entity->isMoving() && lcg_value() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskAttackPlayer") && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath(); /*Vanilla value*/ } - + public function onUpdate(EntityAI $ai) { --$this->selfCounter; diff --git a/src/entity/ai/tasks/TaskLookAtPlayer.php b/src/entity/ai/tasks/TaskLookAtPlayer.php index 174304a9..7fa7b816 100644 --- a/src/entity/ai/tasks/TaskLookAtPlayer.php +++ b/src/entity/ai/tasks/TaskLookAtPlayer.php @@ -6,13 +6,13 @@ class TaskLookAtPlayer extends TaskBase{ public function __construct($distance){ $this->distance = $distance; } - + public function canBeExecuted(EntityAI $ai){ - return !$ai->entity->inPanic && lcg_value() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->isStarted("TaskPanic") && !$ai->entity->hasPath(); + return !$ai->entity->inPanic && lcg_value() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->isStarted("TaskPanic") && !$ai->entity->hasPath(); } protected function findTarget(Creature $e, $r){ - return $e->closestPlayerDist > $r*$r ? null : $e->level->entityList[$e->closestPlayerEID]; + return $e->closestPlayerDist > $r * $r ? null : $e->level->entityList[$e->closestPlayerEID]; } public function onStart(EntityAI $ai){ @@ -22,7 +22,7 @@ class TaskLookAtPlayer extends TaskBase{ $this->onEnd($ai); return; } - + $this->selfCounter = mt_rand(20, 60); } @@ -35,7 +35,7 @@ class TaskLookAtPlayer extends TaskBase{ $ai->mobController->setLookPosition($this->target->x, $this->target->y + $this->target->getEyeHeight(), $this->target->z, 10, $ai->entity->getVerticalFaceSpeed()); $this->selfCounter--; } - + public function onEnd(EntityAI $ai){ unset($this->target); $ai->entity->pitch = 0; diff --git a/src/entity/ai/tasks/TaskMate.php b/src/entity/ai/tasks/TaskMate.php index 5bfdd26b..d073bd1a 100644 --- a/src/entity/ai/tasks/TaskMate.php +++ b/src/entity/ai/tasks/TaskMate.php @@ -5,9 +5,9 @@ class TaskMate extends TaskBase public function __construct($speed){ $this->speedMultiplier = $speed; } - + public $targetMateID; - + public function onStart(EntityAI $ai) { $this->selfCounter = 60; @@ -27,17 +27,16 @@ class TaskMate extends TaskBase $this->onEnd($ai); return; } - - + $ai->mobController->setLookPosition($movTo->x, $movTo->y + $movTo->getEyeHeight(), $movTo->z, 10, $ai->entity->getVerticalFaceSpeed()); $ai->mobController->setMovingTarget($movTo->x, $movTo->y, $movTo->z, $this->speedMultiplier); - + --$this->selfCounter; if($this->selfCounter <= 0 && $ai->entity->distanceSquared($movTo) < 9){ $this->createBaby($ai, $movTo); } } - + public function createBaby(EntityAI $ai, Entity $entpar2){ /** * @var Animal $baby @@ -45,20 +44,20 @@ class TaskMate extends TaskBase $baby = $ai->entity->breed(); //this.theAnimal.setGrowingAge(6000); TODO growing age? //this.targetMate.setGrowingAge(6000); - + $ai->entity->loveTimeout = 6000; $entpar2->loveTimeout = 6000; - + $ai->entity->resetInLove(); $entpar2->resetInLove(); $baby->setAge(-24000); } - + public function findMate(EntityAI $ai){ - $distance = 8.0*8.0; + $distance = 8.0 * 8.0; $minDist = $distance; //TODO check bb intersection? $matedEID = null; - + foreach($ai->entity->level->entitiesInLove as $eid => $_){ $e = $ai->entity->level->entityList[$eid] ?? false; if($e instanceof Entity){ @@ -71,7 +70,7 @@ class TaskMate extends TaskBase } return $matedEID; } - + public function canBeExecuted(EntityAI $ai) { return $ai->entity->isInLove() && ($this->targetMateID = $this->findMate($ai)) != null; diff --git a/src/entity/ai/tasks/TaskPanic.php b/src/entity/ai/tasks/TaskPanic.php index a010802d..a906ec3f 100644 --- a/src/entity/ai/tasks/TaskPanic.php +++ b/src/entity/ai/tasks/TaskPanic.php @@ -3,12 +3,12 @@ class TaskPanic extends TaskBase { protected $randX = 2, $randZ = 2; - + public $speedMultiplier; public function __construct($speedMultiplier){ $this->speedMultiplier = $speedMultiplier; } - + public function onStart(EntityAI $ai) { $this->selfCounter = 60; @@ -20,16 +20,16 @@ class TaskPanic extends TaskBase $ai->entity->inPanic = false; $this->reset(); } - + public function regenerateRandXZ(){ $this->randX = (mt_rand(0, 1) ? -1 : 1); $this->randZ = (mt_rand(0, 1) ? -1 : 1); } - + public function reset(){ $this->randX = $this->randZ = 2; } - + public function onUpdate(EntityAI $ai) { --$this->selfCounter; @@ -42,6 +42,5 @@ class TaskPanic extends TaskBase return $ai->entity instanceof Animal && $ai->entity->inPanic && $ai->entity->knockbackTime <= 0; } - -} + } diff --git a/src/entity/ai/tasks/TaskRandomWalk.php b/src/entity/ai/tasks/TaskRandomWalk.php index 4b68a746..e81d2263 100644 --- a/src/entity/ai/tasks/TaskRandomWalk.php +++ b/src/entity/ai/tasks/TaskRandomWalk.php @@ -7,7 +7,7 @@ class TaskRandomWalk extends TaskBase public function __construct($speedMultiplier){ $this->speedMultiplier = $speedMultiplier; } - + public function onStart(EntityAI $ai) { $this->x = mt_rand(-1, 1); @@ -30,7 +30,7 @@ class TaskRandomWalk extends TaskBase $this->reset(); return false; //TODO Better way: block movement } - + --$this->selfCounter; $ai->mobController->setMovingOffset($this->x, 0, $this->z, $this->speedMultiplier); } @@ -40,8 +40,7 @@ class TaskRandomWalk extends TaskBase if(($ai->entity instanceof Creeper && $ai->entity->isIgnited()) || $ai->entity->hasPath() || $ai->isStarted("TaskTempt") || $ai->isStarted("TaskAttackPlayer") || $ai->isStarted("TaskRangedAttack")) { return false; } // i really need mutexBits - return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskEatTileGoal") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskFollowParent") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0; + return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskEatTileGoal") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskFollowParent") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0; } - -} + } diff --git a/src/entity/ai/tasks/TaskRangedAttack.php b/src/entity/ai/tasks/TaskRangedAttack.php index 04d53630..dfe2dee1 100644 --- a/src/entity/ai/tasks/TaskRangedAttack.php +++ b/src/entity/ai/tasks/TaskRangedAttack.php @@ -7,10 +7,10 @@ class TaskRangedAttack extends \TaskBase public $seenTicks = 0; public function __construct($speed, $range){ $this->speedMultiplier = $speed; - $this->rangeSquared = $range*$range; + $this->rangeSquared = $range * $range; $this->server = ServerAPI::request(); } - + public function onStart(EntityAI $ai) { $this->selfCounter = 1; @@ -20,7 +20,7 @@ class TaskRangedAttack extends \TaskBase public function onEnd(EntityAI $ai) { $ai->entity->target = false; - + } public function onUpdate(EntityAI $ai) @@ -36,24 +36,23 @@ class TaskRangedAttack extends \TaskBase }else{ $this->seenTicks = 0; } - - + $dist = $ai->entity->distanceSquared($ai->entity->target); - + if($dist > 100 || $this->seenTicks < 20){ $ai->mobController->setMovingTarget($ai->entity->target->x, $ai->entity->target->y, $ai->entity->target->z, $this->speedMultiplier); }else{ $ai->mobController->headYawIsYaw = true; } - + $ai->mobController->setLookPosition($ai->entity->target->x, $ai->entity->target->y + 0.12, $ai->entity->target->z, 10, $ai->entity->getVerticalFaceSpeed()); - + if($this->attackCounter <= 0 && $this->seenTicks > 0){ $this->rangedAttack($ai->entity, $ai->entity->target); $this->attackCounter = 60; } } - + public function rangedAttack($selfEntity, $target){ $d = [ "x" => $selfEntity->x, @@ -88,8 +87,7 @@ class TaskRangedAttack extends \TaskBase $this->server->api->entity->spawnToAll($arrow); } } - - + public function isTargetValid(EntityAI $ai){ $e = $ai->entity; if($e->target instanceof Entity && !$e->target->closed && !$e->target->dead){ @@ -97,11 +95,11 @@ class TaskRangedAttack extends \TaskBase $xDiff = ($t->x - $e->x); $yDiff = ($t->y - $e->y); $zDiff = ($t->z - $e->z); - return ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= $this->rangeSquared; + return ($xDiff * $xDiff + $yDiff * $yDiff + $zDiff * $zDiff) <= $this->rangeSquared; } return false; } - + public function tryTargeting(EntityAI $ai){ $e = $ai->entity; if($e->target instanceof Entity){ @@ -109,21 +107,20 @@ class TaskRangedAttack extends \TaskBase $xDiff = ($t->x - $e->x); $yDiff = ($t->y - $e->y); $zDiff = ($t->z - $e->z); - if(($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= $this->rangeSquared){ + if(($xDiff * $xDiff + $yDiff * $yDiff + $zDiff * $zDiff) <= $this->rangeSquared){ return true; } } $closestTarget = $e->closestPlayerToAttackDist <= $this->rangeSquared ? $e->level->entityList[$e->closestPlayerToAttackEID] : null; - + if($closestTarget != null){ $e->target = $closestTarget; //TODO dont save entity object ? return true; } return false; } - - + public function canBeExecuted(EntityAI $ai) { return $this->tryTargeting($ai); diff --git a/src/entity/ai/tasks/TaskSwimming.php b/src/entity/ai/tasks/TaskSwimming.php index 61842afb..ad9ecdc7 100644 --- a/src/entity/ai/tasks/TaskSwimming.php +++ b/src/entity/ai/tasks/TaskSwimming.php @@ -9,7 +9,7 @@ class TaskSwimming extends TaskBase public function onEnd(EntityAI $ai) { - + } public function onUpdate(EntityAI $ai) @@ -18,12 +18,12 @@ class TaskSwimming extends TaskBase $this->reset(); return; } - + if(lcg_value() < 0.8){ #1.5.2 method $ai->mobController->setJumping(true); } } - + public function canBeExecuted(EntityAI $ai) { return $ai->entity->inWater || $ai->entity->inLava; diff --git a/src/entity/ai/tasks/TaskTempt.php b/src/entity/ai/tasks/TaskTempt.php index eee2f39a..5dd67c66 100644 --- a/src/entity/ai/tasks/TaskTempt.php +++ b/src/entity/ai/tasks/TaskTempt.php @@ -4,19 +4,19 @@ class TaskTempt extends TaskBase { public function __construct($speed){ $this->speedMultiplier = $speed; - $this->targetDistance = 10*10; + $this->targetDistance = 10 * 10; } - + public function onStart(EntityAI $ai) { $this->selfCounter = 1; } - + public function onEnd(EntityAI $ai) { $ai->entity->target = false; } - + public function onUpdate(EntityAI $ai) { if(!$this->isTargetValid($ai) || $ai->entity->inPanic || $ai->isStarted("TaskMate")){ @@ -24,22 +24,21 @@ class TaskTempt extends TaskBase $this->onEnd($ai); return false; } - + $target = $ai->entity->target; $xdiff = ($target->x - $ai->entity->x); $ydiff = ($target->y - $ai->entity->y); $zdiff = ($target->z - $ai->entity->z); - $dist = $xdiff*$xdiff + $ydiff*$ydiff + $zdiff*$zdiff; + $dist = $xdiff * $xdiff + $ydiff * $ydiff + $zdiff * $zdiff; $ai->mobController->setLookPosition($target->x, $target->y + $target->getEyeHeight(), $target->z, 30, $ai->entity->getVerticalFaceSpeed()); if($dist >= 6.25){ $ai->mobController->setMovingTarget($target->x, $target->y, $target->z, $this->speedMultiplier); }else{ $ai->mobController->headYawIsYaw = true; } - - + } - + public function isTargetValid(EntityAI $ai){ $e = $ai->entity; if($e->target instanceof Entity && !$e->target->closed && $e->isFood($e->target->player->getHeldItem()->id)){ @@ -47,16 +46,16 @@ class TaskTempt extends TaskBase $xDiff = ($t->x - $e->x); $yDiff = ($t->y - $e->y); $zDiff = ($t->z - $e->z); - return ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= $this->targetDistance; + return ($xDiff * $xDiff + $yDiff * $yDiff + $zDiff * $zDiff) <= $this->targetDistance; } return false; } - + public function canBeExecuted(EntityAI $ai) { return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && $this->tryTargeting($ai); } - + public function tryTargeting(EntityAI $ai){ $e = $ai->entity; if($e->target instanceof Entity){ @@ -64,13 +63,13 @@ class TaskTempt extends TaskBase $xDiff = ($t->x - $e->x); $yDiff = ($t->y - $e->y); $zDiff = ($t->z - $e->z); - if(($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= $this->targetDistance){ + if(($xDiff * $xDiff + $yDiff * $yDiff + $zDiff * $zDiff) <= $this->targetDistance){ return true; } } - + $closestTarget = $e->closestPlayerThatCanFeedDist <= $this->targetDistance ? $e->level->entityList[$e->closestPlayerThatCanFeedEID] : null; - + if($closestTarget != null){ $e->target = $closestTarget; //TODO dont save entity object ? return true; diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 2b19cd1a..8f66e5f8 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -10,7 +10,7 @@ class Chicken extends Animal{ $this->setHealth($this->data["Health"] ?? 4, "generic"); $this->setName('Chicken'); $this->setSpeed(0.25); - + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(1.5)); @@ -23,27 +23,27 @@ class Chicken extends Animal{ public function isFood($id){ return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS; } - + public function updateEntityMovement(){ parent::updateEntityMovement(); - + if(!$this->onGround && $this->speedY < 0) $this->speedY *= 0.6; - + if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){ $this->dropAnEgg(); $this->timeUntilEgg = mt_rand(0,6000) + 6000; } } - + public function fall(){} //chickens have no fall dmg? - + public function dropAnEgg(){ if($this->closed){ return; } ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(EGG, 0, 1)); } - + public function getDrops(){ return $this->isBaby() ? parent::getDrops() : [ [FEATHER, 0, mt_rand(0,2)], diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 441ff126..86a5358a 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -17,11 +17,11 @@ class Cow extends Animal{ $this->ai->addTask(new TaskMate(1.0)); $this->ai->addTask(new TaskFollowParent(1.1)); } - + public function isFood($id){ return $id === WHEAT; } - + public function interactWith(Entity $e, $action){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ $slot = $e->player->getHeldItem(); @@ -33,9 +33,9 @@ class Cow extends Animal{ } parent::interactWith($e, $action); } - + public function getDrops(){ - return $this->isBaby() ? parent::getDrops() : [ + return $this->isBaby() ? parent::getDrops() : [ [LEATHER, 0, mt_rand(0,2)], [($this->fire > 0 ? STEAK : BEEF), 0, mt_rand(0, 3)] ]; diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index d8bfe219..9b48b6f8 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -1,7 +1,8 @@ setSize(0.9, 0.9); parent::__construct($level, $eid, $class, $type, $data); @@ -9,7 +10,7 @@ class Pig extends Animal implements Rideable{ $this->server = ServerAPI::request(); $this->setName("Pig"); $this->setSpeed(0.25); - + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(1.5)); @@ -25,18 +26,18 @@ class Pig extends Animal implements Rideable{ public function isSaddled(){ return (boolean) $this->getState(); } - + /** * @param boolean $value */ public function setSaddled($value = null){ $this->setState($value === null ? !$this->getState() : $value); } - + public function canRide($e){ return $this->isSaddled() && $this->linkedEntity == 0 && $e->linkedEntity == 0; } - + public function updateEntityMovement(){ /*if($this->linkedEntity != 0){ $e = $this->level->entityList[$this->linkedEntity] ?? false; @@ -47,10 +48,10 @@ class Pig extends Animal implements Rideable{ $this->yaw = $e->headYaw; } }*/ - + parent::updateEntityMovement(); } - + public function interactWith(Entity $e, $action) { if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ @@ -59,7 +60,7 @@ class Pig extends Animal implements Rideable{ $e->setRiding($this); return true; } - + if($slot->getID() === SADDLE){ if(!$this->isSaddled()){ $e->player->removeItem($slot->getID(), 0, 1); @@ -67,15 +68,15 @@ class Pig extends Animal implements Rideable{ } return true; //avoid further interactions } - + } return parent::interactWith($e, $action); } - + public function isFood($id){ return $id === POTATO || $id === CARROT || $id === BEETROOT; } - + public function getDrops(){ return $this->isBaby() ? parent::getDrops() : ($this->isSaddled() ? [ [($this->fire > 0 ? COOKED_PORKCHOP : RAW_PORKCHOP), 0, mt_rand(0,2)], diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index d79c8701..5cd80c1b 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -3,7 +3,7 @@ class Sheep extends Animal{ public $color; const TYPE = MOB_SHEEP; - + function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.9, 1.3); parent::__construct($level, $eid, $class, $type, $data); @@ -12,7 +12,7 @@ class Sheep extends Animal{ $this->data["Sheared"] = $this->data["Sheared"] ?? 0; $this->data["Color"] = $this->data["Color"] ?? $this->sheepColor(); $this->setSpeed(0.25); - + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(1.5)); @@ -23,14 +23,14 @@ class Sheep extends Animal{ $this->ai->addTask(new TaskMate(1.0)); $this->ai->addTask(new TaskFollowParent(1.0)); } - + public function createSaveData(){ $data = parent::createSaveData(); $data["Color"] = @$this->data["Color"]; $data["Sheared"] = @$this->data["Sheared"]; return $data; } - + public function eatGrass(){ $this->setSheared(0); if($this->isBaby()){ @@ -39,24 +39,24 @@ class Sheep extends Animal{ $this->setAge($age); } } - + public function setSheared($v = null){ $this->data["Sheared"] = $v === null ? !$this->isSheared() : $v; $this->updateMetadata(); } - + public function isSheared(){ return $this->data["Sheared"]; } - + public function getColor(){ return $this->data["Color"]; //color === 16 -> color = 0, color === 17 -> color = 1 ... } - + public function switchColorMeta($meta){ return abs($meta - 15); } - + public function setColor($meta){ $this->data["Color"] = $meta; } @@ -65,11 +65,11 @@ class Sheep extends Animal{ [WOOL, $this->getColor(), 1] ]; } - + public function isFood($id){ return $id === WHEAT; } - + public function interactWith(Entity $e, $action){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ $slot = $e->player->getHeldItem(); @@ -79,7 +79,7 @@ class Sheep extends Animal{ $this->setSheared(1); $speedX = (lcg_value() * 0.2 - 0.1) + (lcg_value() - lcg_value()) * 0.1; $speedZ = (lcg_value() * 0.2 - 0.1) + (lcg_value() - lcg_value()) * 0.1; - $speedY = 0.2 + (lcg_value()) * 0.05; + $speedY = 0.2 + (lcg_value()) * 0.05; $this->server->api->entity->dropRawPos($this->level, $this->x, $this->y + 1, $this->z, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3)), $speedX, $speedY, $speedZ); if($slot->getMetadata() >= $slot->getMaxDurability()){ $e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); @@ -90,7 +90,7 @@ class Sheep extends Animal{ return true; }elseif($slot->getID() === DYE){ $this->setColor($this->switchColorMeta($slot->getMetadata())); - + if(($e->player->gamemode & 0x01) === SURVIVAL){ $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); } @@ -98,7 +98,7 @@ class Sheep extends Animal{ } return parent::interactWith($e, $action); } - + public function getMetadata(){ $d = parent::getMetadata(); if(!isset($this->data["Sheared"])){ @@ -107,7 +107,7 @@ class Sheep extends Animal{ $d[16]["value"] = ($this->data["Sheared"] << 4) | ($this->getColor() & 0x0F); return $d; } - + public function sheepColor(){ //a method from 0.8.1 $c = mt_rand(0,100); if($c <= 4){ diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index b1279f9c..a8539b11 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -1,4 +1,5 @@ ignited = 0; $this->setSpeed(0.25); $this->timeUntilExplode = $this->isIgnited() ? self::EXPL_TIME : 0; - + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskAttackPlayer(1.25, 16)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); } - + public function getAttackDamage(){ return 0; } - + 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 $this->getState() > 0; } - + public function interactWith(Entity $e, $action){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ $slot = $e->player->getHeldItem(); @@ -51,12 +50,12 @@ class Creeper extends Monster{ } return parent::interactWith($e, $action); } - + public function ignite(){ $this->setIgnited(1); $this->timeUntilExplode = self::EXPL_TIME; } - + public function attackEntity($entity, $distance){ if(Utils::distance_noroot($entity, $this) <= 49 && !$this->isIgnited() && $this->ai->canSee($entity)){ $this->ignite(); @@ -88,7 +87,7 @@ class Creeper extends Monster{ $this->close(); $explosion->explode(); } - + public function getDrops(){ return [ [GUNPOWDER, 0, mt_rand(0,2)] diff --git a/src/entity/monster/PigZombie.php b/src/entity/monster/PigZombie.php index 812901ce..c508d1a8 100644 --- a/src/entity/monster/PigZombie.php +++ b/src/entity/monster/PigZombie.php @@ -1,4 +1,5 @@ setName("Skeleton"); $this->ai->removeTask("TaskAttackPlayer"); $this->setSpeed(0.25); - + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); $this->ai->addTask(new TaskRangedAttack(1.0, 16)); } - + public function getAttackDamage(){ return 0; } - + public function updateBurning(){ if($this->fire > 0 || !$this->level->isDay() || $this->inWater){ return false; } //bad fix for burning in water - [$block, $meta] = $this->level->level->getBlock((int)$this->x, (int)$this->y, (int)$this->z); + [$block, $meta] = $this->level->level->getBlock((int) $this->x, (int) $this->y, (int) $this->z); if($block == WATER || $block == STILL_WATER){ - $v16 = ((int)$this->y + 1) - LiquidBlock::getPercentAir($meta); - if($this->boundingBox->intersectsWith(new AxisAlignedBB((int)$this->x, (int)$this->y, (int)$this->z, (int)$this->x + 1, $v16, (int)$this->z + 1))){ + $v16 = ((int) $this->y + 1) - LiquidBlock::getPercentAir($meta); + if($this->boundingBox->intersectsWith(new AxisAlignedBB((int) $this->x, (int) $this->y, (int) $this->z, (int) $this->x + 1, $v16, (int) $this->z + 1))){ return false; } } - - for($y = (int)$this->y; $y < 129; $y++){ + + for($y = (int) $this->y; $y < 129; $y++){ $block = $this->level->level->getBlockID($this->x, $y, $this->z); if(StaticBlock::getIsSolid($block)){ return false; @@ -49,12 +50,12 @@ class Skeleton extends Monster{ return false; } } - + public function updateEntityMovement(){ $this->updateBurning(); return parent::updateEntityMovement(); } - + public function getDrops(){ return [ [ARROW, 0, mt_rand(0,2)], diff --git a/src/entity/monster/Spider.php b/src/entity/monster/Spider.php index 1752638f..081187fb 100644 --- a/src/entity/monster/Spider.php +++ b/src/entity/monster/Spider.php @@ -1,8 +1,9 @@ setSize(1.4, 0.9); parent::__construct($level, $eid, $class, $type, $data); $this->setHealth($this->data["Health"] ?? 8, "generic"); @@ -11,35 +12,35 @@ class Spider extends Monster{ $this->ai->addTask(new TaskRandomWalk(1.2)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); - $this->ai->addTask(new TaskAttackPlayer(1.2, 16)); + $this->ai->addTask(new TaskAttackPlayer(1.2, 16)); } - + public function getAttackDamage(){ return 2; } - + public function attackEntity($entity, $distance){ if($distance > 2.0 && $distance < 6.0){ if($this->onGround){ $diffX = $entity->x - $this->x; $diffZ = $entity->z - $this->z; - $dist = sqrt($diffX*$diffX + $diffZ*$diffZ); - - $this->speedX = $diffX / $dist*0.5*0.8 + $this->speedX*0.2; - $this->speedZ = $diffZ / $dist*0.5*0.8 + $this->speedZ*0.2; + $dist = sqrt($diffX * $diffX + $diffZ * $diffZ); + + $this->speedX = $diffX / $dist * 0.5 * 0.8 + $this->speedX * 0.2; + $this->speedZ = $diffZ / $dist * 0.5 * 0.8 + $this->speedZ * 0.2; $this->speedY = 0.4; } return false; }else{ return parent::attackEntity($entity, $distance); } - + } - + public function isOnLadder(){ return $this->isCollidedHorizontally; } - + public function getDrops(){ return [ [STRING, 0, mt_rand(0,2)] diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index bc38cf3a..7cfb4885 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -1,37 +1,38 @@ setSize(0.6, 1.85); parent::__construct($level, $eid, $class, $type, $data); $this->setHealth($this->data["Health"] ?? 12, "generic"); $this->setName("Zombie"); $this->setSpeed(0.23); - + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); $this->ai->addTask(new TaskAttackPlayer(1.0, 16)); } - + public function getArmorValue(){ return 2; } - + public function updateBurning(){ if($this->fire > 0 || !$this->level->isDay() || $this->inWater){ return false; } //bad fix for burning in water - [$block, $meta] = $this->level->level->getBlock((int)$this->x, (int)$this->y, (int)$this->z); + [$block, $meta] = $this->level->level->getBlock((int) $this->x, (int) $this->y, (int) $this->z); if($block == WATER || $block == STILL_WATER){ - $v16 = ((int)$this->y + 1) - LiquidBlock::getPercentAir($meta); - if($this->boundingBox->intersectsWith(new AxisAlignedBB((int)$this->x, (int)$this->y, (int)$this->z, (int)$this->x + 1, $v16, (int)$this->z + 1))){ + $v16 = ((int) $this->y + 1) - LiquidBlock::getPercentAir($meta); + if($this->boundingBox->intersectsWith(new AxisAlignedBB((int) $this->x, (int) $this->y, (int) $this->z, (int) $this->x + 1, $v16, (int) $this->z + 1))){ return false; } } - - for($y = (int)$this->y; $y < 129; $y++){ + + for($y = (int) $this->y; $y < 129; $y++){ $block = $this->level->level->getBlockID($this->x, $y, $this->z); if(StaticBlock::getIsSolid($block)){ return false; @@ -48,7 +49,7 @@ class Zombie extends Monster{ return false; } } - + public function getAttackDamage(){ return 4; } @@ -57,7 +58,7 @@ class Zombie extends Monster{ $this->updateBurning(); return parent::updateEntityMovement(); } - + public function getDrops(){ return [ [CARROT, 0, Utils::chance(0.83) ? 1 : 0], diff --git a/src/entity/object/Arrow.php b/src/entity/object/Arrow.php index d671113e..cac786cf 100644 --- a/src/entity/object/Arrow.php +++ b/src/entity/object/Arrow.php @@ -3,7 +3,7 @@ class Arrow extends Entity{ const TYPE = OBJECT_ARROW; const CLASS_TYPE = ENTITY_OBJECT; - + public $shooterEID = 0; public $xTile, $yTile, $zTile; public $inTile, $inData; @@ -13,7 +13,7 @@ class Arrow extends Entity{ public $criticial = false; public $groundTicks = 0; public $shotByPlayer = false; - + function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->gravity = 0.05; @@ -32,12 +32,12 @@ class Arrow extends Entity{ $this->yTile = $data["yTile"] ?? $this->yTile; $this->zTile = $data["zTile"] ?? $this->zTile; $this->shotByPlayer = $data["shotByPlayer"] ?? $this->shotByPlayer; - + //$this->server->schedule(1210, array($this, "update")); //Despawn } public function createSaveData(){ $data = parent::createSaveData(); - + $data["inTile"] = $this->inTile; $data["inData"] = $this->inData; $data["inGround"] = $this->inGround; @@ -57,7 +57,7 @@ class Arrow extends Entity{ $pk->pitch = $this->pitch; $this->server->api->player->broadcastPacket($this->level->players, $pk); } - + 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; @@ -79,7 +79,7 @@ class Arrow extends Entity{ //$this->update(); $this->groundTicks = 0; } - + public function update($now){ $this->lastX = $this->x; $this->lastY = $this->y; @@ -101,40 +101,39 @@ class Arrow extends Entity{ $this->fire -= 4; if($this->fire <= 0) $this->fire = 0; } - + if($this->fire <= 0){ $this->updateMetadata(); } } - + if($this->handleLavaMovement()){ if(!$this->isImmuneToFire){ $this->harm(4, "fire"); $oldOnFire = $this->fire; - if($oldOnFire < 20*30) $this->fire = 20*30; //30 seconds + if($oldOnFire < 20 * 30) $this->fire = 20 * 30; //30 seconds } } - + if($this->isInVoid()){ $this->outOfWorld(); } //Entity::update end - - + if($this->lastPitch == $this->lastYaw && $this->lastYaw == 0){ - $v1 = sqrt($this->speedX*$this->speedX + $this->speedZ*$this->speedZ); + $v1 = sqrt($this->speedX * $this->speedX + $this->speedZ * $this->speedZ); $this->lastYaw = $this->yaw = atan2($this->speedX, $this->speedZ) * 180 / M_PI; $this->lastPitch = $this->pitch = atan2($this->speedY, $v1) * 180 / M_PI; } - + if($this->shake > 0){ --$this->shake; } - + if($this->inGround){ [$blockID, $blockMeta] = $this->level->level->getBlock($this->xTile, $this->yTile, $this->zTile); $this->speedZ = $this->speedX = $this->speedY = 0; - + if($blockID == $this->inTile && $blockMeta == $this->inData){ ++$this->groundTicks; if($this->groundTicks >= 1200){ //TODO customizeable? @@ -147,7 +146,7 @@ class Arrow extends Entity{ $this->speedZ *= lcg_value() * 0.2; $this->groundTicks = $this->airTicks = 0; } - + }else{ ++$this->airTicks; $start = new Vector3($this->x, $this->y, $this->z); @@ -162,42 +161,40 @@ class Arrow extends Entity{ }else{ $end = new Vector3($this->x + $this->speedX, $this->y + $this->speedY, $this->z + $this->speedZ); } - - + $entities = $this->level->getEntitiesInAABB($this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ)->expand(1, 1, 1)); $bestDist = 0; $bestEnt = null; - + foreach($entities as $eid => $ent){ if($eid != $this->eid && $ent->isPickable() && ($eid != $this->shooterEID || $this->airTicks >= 5)){ - + $v12 = $ent->boundingBox->expand(0.3, 0.3, 0.3); $v13 = $v12->calculateIntercept($start, $end); - + if($v13 != null){ $dist = $start->distance($v13->hitVector); - + if($dist < $bestDist || $bestDist == 0){ $bestEnt = $ent; } } } } - + if($bestEnt != null){ $v4 = MovingObjectPosition::fromEntity($bestEnt); } - + if($v4 != null){ if($v4->entityHit != null){ - $v49 = sqrt($this->speedY*$this->speedY + $this->speedX*$this->speedX + $this->speedZ*$this->speedZ); - $damage = ceil($v49+$v49); - + $v49 = sqrt($this->speedY * $this->speedY + $this->speedX * $this->speedX + $this->speedZ * $this->speedZ); + $damage = ceil($v49 + $v49); + if($this->criticial){ $damage += mt_rand(0, $damage / 2 + 1); } - - + if($v4->entityHit->harm($damage, $this->eid)){ //vanilla seems to increase arrow count if $v4->entity is mob $this->close(); @@ -213,36 +210,36 @@ class Arrow extends Entity{ $this->xTile = $v4->blockX; $this->yTile = $v4->blockY; $this->zTile = $v4->blockZ; - + [$this->inTile, $this->inData] = $this->level->level->getBlock($this->xTile, $this->yTile, $this->zTile); - + $this->speedX = $v4->hitVector->x - $this->x; $this->speedY = $v4->hitVector->y - $this->y; $this->speedZ = $v4->hitVector->z - $this->z; - - $v21 = sqrt($this->speedX*$this->speedX + $this->speedY*$this->speedY + $this->speedZ*$this->speedZ); + + $v21 = sqrt($this->speedX * $this->speedX + $this->speedY * $this->speedY + $this->speedZ * $this->speedZ); if($v21 != 0){ $this->x -= $this->speedX / $v21 * 0.05; $this->y -= $this->speedY / $v21 * 0.05; $this->z -= $this->speedZ / $v21 * 0.05; } - + $this->inGround = true; $this->shake = 7; $this->criticial = false; } } - + $this->x += $this->speedX; $this->y += $this->speedY; $this->z += $this->speedZ; - $v21 = sqrt($this->speedX*$this->speedX + $this->speedZ*$this->speedZ); + $v21 = sqrt($this->speedX * $this->speedX + $this->speedZ * $this->speedZ); $this->yaw = atan2($this->speedX, $this->speedZ) * 180 / M_PI; $this->pitch = atan2($this->speedY, $v21) * 180 / M_PI; - + $this->pitch = $this->lastPitch + ($this->pitch - $this->lastPitch) * 0.2; $this->yaw = $this->lastYaw + ($this->yaw - $this->lastYaw) * 0.2; - + $v24 = $this->inWater ? 0.8 : 0.99; $this->speedX *= $v24; $this->speedY *= $v24; @@ -252,14 +249,12 @@ class Arrow extends Entity{ $v7 = $this->width / 2; $v8 = $this->height; $this->boundingBox->setBounds($this->x - $v7, $this->y - $this->yOffset /*+ $this->ySize*/, $this->z - $v7, $this->x + $v7, $this->y - $this->yOffset + $v8 /*+ $this->ySize*/, $this->z + $v7); - + $this->doBlocksCollision(); } - - - + } - + public function spawn($player){ if($this->type === OBJECT_ARROW){ $pk = new AddEntityPacket; @@ -268,7 +263,7 @@ class Arrow extends Entity{ $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; - $pk->did = 1; + $pk->did = 1; $pk->speedX = $this->speedX; $pk->speedY = $this->speedY; $pk->speedZ = $this->speedZ; diff --git a/src/entity/object/FallingSand.php b/src/entity/object/FallingSand.php index 517d4ca7..745d289b 100644 --- a/src/entity/object/FallingSand.php +++ b/src/entity/object/FallingSand.php @@ -3,9 +3,9 @@ class FallingSand extends Entity{ const TYPE = FALLING_SAND; const CLASS_TYPE = ENTITY_FALLING; - + public $fallTime = 0; - + public function __construct($level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->setHealth(PHP_INT_MAX, "generic"); @@ -15,14 +15,14 @@ class FallingSand extends Entity{ $this->hasGravity = true; $this->gravity = 0.04; } - + public function isPickable(){ return !$this->dead; } - + public function update($now){ if($this->closed) return; - + if( $this->data["Tile"] == AIR) { $this->close(); return; @@ -33,15 +33,15 @@ class FallingSand extends Entity{ ++$this->fallTime; $this->speedY -= 0.04; $this->move($this->speedX, $this->speedY, $this->speedZ); - + $this->speedX *= 0.98; $this->speedY *= 0.98; $this->speedZ *= 0.98; - + $x = floor($this->x); $y = floor($this->y); $z = floor($this->z); - + if($this->onGround){ $this->speedX *= 0.7; $this->speedZ *= 0.7; diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 9af57bee..f290fe07 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -4,10 +4,10 @@ class ItemEntity extends Entity{ const TYPE = ENTITY_ITEM_TYPE; const CLASS_TYPE = ENTITY_ITEM; public static $searchRadiusX = 0.5, $searchRadiusY = 0.0, $searchRadiusZ = 0.5; - + public $meta, $stack, $itemID; - - public function __construct(Level $level, $eid, $class, $type = 0, $data = array()) + + public function __construct(Level $level, $eid, $class, $type = 0, $data = []) { parent::__construct($level, $eid, $class, $type, $data); $this->setSize(0.25, 0.25); @@ -27,21 +27,21 @@ class ItemEntity extends Entity{ $this->delayBeforePickup = 40; //in vanilla it is 0 by default $this->stepHeight = 0; } - + public function counterUpdate(){ parent::counterUpdate(); if($this->delayBeforePickup > 0) --$this->delayBeforePickup; } - + public function searchForOtherItemsNearby(){ $ents = $this->level->getEntitiesInAABBOfType($this->boundingBox->expand(self::$searchRadiusX, self::$searchRadiusY, self::$searchRadiusZ), ENTITY_ITEM); - + foreach($ents as $e){ $this->tryCombining($e); } - + } - + public function spawn($player) { $pk = new AddItemEntityPacket(); @@ -55,7 +55,7 @@ class ItemEntity extends Entity{ $pk->item = BlockAPI::getItem($this->itemID, $this->meta, $this->stack); $pk->metadata = $this->getMetadata(); $player->dataPacket($pk); - + $pk = new SetEntityMotionPacket(); $pk->eid = $this->eid; $pk->speedX = $this->speedX; @@ -63,16 +63,15 @@ class ItemEntity extends Entity{ $pk->speedZ = $this->speedZ; $player->dataPacket($pk); } - - + public function tryCombining(Entity $another){ - + if($another->eid == $this->eid) return false; - + if(!$another->closed && !$this->closed){ if($another->itemID == $this->itemID && $another->meta == $this->meta){ if(($another->stack + $this->stack) > 64) return false; //TODO dynamic stack size - + $another->stack += $this->stack; $another->age = min($this->age, $another->age); $this->close(); @@ -84,29 +83,29 @@ class ItemEntity extends Entity{ $xFloor = floor($x); $yFloor = floor($y); $zFloor = floor($z); - + $id = $this->level->level->getBlockID($xFloor, $yFloor, $zFloor); - + if(StaticBlock::getIsSolid($id)){ $xDiff = $x - $xFloor; - + $id = $this->level->level->getBlockID($xFloor - 1, $yFloor, $zFloor); $xNeg = StaticBlock::getIsSolid($id); - + $id = $this->level->level->getBlockID($xFloor + 1, $yFloor, $zFloor); $xPos = StaticBlock::getIsSolid($id); - + $id = $this->level->level->getBlockID($xFloor, $yFloor - 1, $zFloor); $yNeg = StaticBlock::getIsSolid($id); - + $id = $this->level->level->getBlockID($xFloor, $yFloor + 1, $zFloor); $yPos = StaticBlock::getIsSolid($id); - + $id = $this->level->level->getBlockID($xFloor - 1, $yFloor, $zFloor - 1); $zNeg = StaticBlock::getIsSolid($id); - + $zPos = $this->level->level->getBlockID($xFloor + 1, $yFloor, $zFloor + 1); - + if($xNeg || $xDiff >= 9999.0){ //TODO not needed check? $v15 = 9999.0; $v16 = -1; @@ -114,22 +113,22 @@ class ItemEntity extends Entity{ $v15 = $xDiff; $v16 = 0; } - + if(!$xPos){ $v17 = 1 - $xDiff; - + if($v17 < $v15){ $v15 = $v17; $v16 = 1; } } - + $yDiff = $y - $yFloor; if(!$yNeg && $yDiff < $v15){ $v15 = $yDiff; $v16 = 2; } - + if(!$yPos){ $v19 = 1.0 - $yDiff; if($v19 < $v15){ @@ -137,17 +136,17 @@ class ItemEntity extends Entity{ $v16 = 3; } } - + $zDiff = $z - $zFloor; if(!$zNeg && $zDiff < $v15){ $v15 = $zDiff; $v16 = 4; } - + if(!StaticBlock::getIsSolid($zPos) && ((1.0 - $zDiff) < $v15)){ $v16 = 5; } - + $v21 = lcg_value() * 0.2 + 0.1; switch($v16){ case 0: @@ -166,24 +165,24 @@ class ItemEntity extends Entity{ $this->speedZ = $v21; return 0; } - + return 0; } } - + public function handleWaterMovement(){ return $this->level->handleMaterialAcceleration($this->boundingBox, 0, $this); } - + public function updateEntityMovement(){ //TODO custom update( method $this->speedY -= 0.04; //$this->noClip = false; $this->checkInTile($this->x, $this->y, $this->z); $this->move($this->speedX, $this->speedY, $this->speedZ); - - $var1 = (int)$this->x != (int)$this->lastX || (int)$this->y != (int)$this->lastY || (int)$this->z != (int)$this->lastZ; - + + $var1 = (int) $this->x != (int) $this->lastX || (int) $this->y != (int) $this->lastY || (int) $this->z != (int) $this->lastZ; + if($var1 || $this->counter % 25 == 0){ $blockIDAt = $this->level->level->getBlockID(floor($this->x), floor($this->y), floor($this->z)); if($blockIDAt == LAVA || $blockIDAt == STILL_LAVA){ @@ -191,30 +190,30 @@ class ItemEntity extends Entity{ $this->speedX = (lcg_value() - lcg_value()) * 0.2; $this->speedZ = (lcg_value() - lcg_value()) * 0.2; } - + //$this->searchForOtherItemsNearby(); //not in vanilla 0.8.1 } - + if($this->closed) return; - + $friction = 0.98; if($this->onGround){ $friction = 0.588; $v3 = $this->level->level->getBlockID($this->x, floor($this->boundingBox->minY) - 1, $this->z); if($v3 > 0) $friction = StaticBlock::getSlipperiness($v3); } - + $this->speedX *= $friction; $this->speedY *= 0.98; $this->speedZ *= $friction; - + if($this->onGround) $this->speedY *= -0.5; - + if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0; if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0; if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0; - + ++$this->age; - //TODO despawn after age >= 6000 ?; + //TODO despawn after age >= 6000 ?; } } diff --git a/src/entity/object/Minecart.php b/src/entity/object/Minecart.php index f10ab47e..5361e47e 100644 --- a/src/entity/object/Minecart.php +++ b/src/entity/object/Minecart.php @@ -4,7 +4,7 @@ class Minecart extends Vehicle{ const TYPE = OBJECT_MINECART; /** * A minecart rotation matrix - * @var int[][][] + * @var int[][][] */ private static $matrix = [ [ @@ -48,14 +48,14 @@ class Minecart extends Vehicle{ [1, 0, 0] ] ]; - + private $hurtTime = 0; //syncentdata 17 int private $damage = 0; //syncentdata 19 float - + private $minecartX = 0, $minecartY = 0, $minecartZ = 0; private $turnProgress = 0; public $isInReverse = false; - + function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->canBeAttacked = true; @@ -67,76 +67,76 @@ class Minecart extends Vehicle{ $this->yOffset = $this->height / 2; $this->stepHeight = 0; } - + public function isPickable(){ return !$this->dead; } - + public function getDrops(){ return [ [MINECART, 0, 1] ]; } - + public function getPos($x, $y, $z){ $blockX = floor($x); $blockY = floor($y); $blockZ = floor($z); - + if(RailBaseBlock::isRailBlock($this->level, $blockX, $blockY - 1, $blockZ)) --$blockY; - + [$id, $meta] = $this->level->level->getBlock($blockX, $blockY, $blockZ); if(RailBaseBlock::isRailID($id)){ - + if($id == POWERED_RAIL) $meta &= 7; - + $mat = self::$matrix[$meta]; $v13 = 0; $v15 = $blockX + 0.5 + $mat[0][0] * 0.5; $v17 = $blockY + 0.5 + $mat[0][1] * 0.5; $v19 = $blockZ + 0.5 + $mat[0][2] * 0.5; - + $v21 = $blockX + 0.5 + $mat[1][0] * 0.5; $v23 = $blockY + 0.5 + $mat[1][1] * 0.5; $v25 = $blockZ + 0.5 + $mat[1][2] * 0.5; - + $v27 = $v21 - $v15; $v29 = ($v23 - $v17) * 2; $v31 = $v25 - $v19; - + if($v27 == 0){ $x = $blockX + 0.5; $v13 = $z - $blockZ; - }else if($v31 == 0){ + }elseif($v31 == 0){ $z = $blockZ + 0.5; $v13 = $x - $blockX; }else{ $v33 = $x - $v15; $v35 = $z - $v19; - $v13 = ($v33*$v27 + $v35*$v31) * 2; + $v13 = ($v33 * $v27 + $v35 * $v31) * 2; } - + $x = $v15 + $v27 * $v13; $y = $v17 + $v29 * $v13; $z = $v19 + $v31 * $v13; - + if($v29 < 0) ++$y; if($v29 > 0) $y += 0.5; return [$x, $y, $z]; } - + return false; } - + public function moveAlongTrack($x, $y, $z, $maxSpeed, $boost, $id, $meta){ $this->fallDistance = 0; $vec = $this->getPos($this->x, $this->y, $this->z); $this->y = $y; - + if($id == POWERED_RAIL) $meta &= 7; - + if($meta >= 2 && $meta <= 5) $this->y = $y + 1; - + switch($meta){ case 2: $this->speedX -= $boost; @@ -151,53 +151,53 @@ class Minecart extends Vehicle{ $this->speedZ -= $boost; break; } - + $mat = self::$matrix[$meta]; $matXDiff = $mat[1][0] - $mat[0][0]; $matZDiff = $mat[1][2] - $mat[0][2]; - $matDiffTotal = sqrt($matXDiff*$matXDiff + $matZDiff*$matZDiff); - + $matDiffTotal = sqrt($matXDiff * $matXDiff + $matZDiff * $matZDiff); + if(($this->speedZ * $matZDiff + $this->speedX * $matXDiff) < 0){ $matXDiff = -$matXDiff; $matZDiff = -$matZDiff; } - $speedTotal = sqrt($this->speedZ*$this->speedZ + $this->speedX*$this->speedX); + $speedTotal = sqrt($this->speedZ * $this->speedZ + $this->speedX * $this->speedX); if($speedTotal > 2) $speedTotal = 2; $this->speedX = ($speedTotal * $matXDiff) / $matDiffTotal; $this->speedZ = ($speedTotal * $matZDiff) / $matDiffTotal; - + if($this->linkedEntity != 0 && !$this->isRider){ $rider = $this->level->entityList[$this->linkedEntity] ?? false; if($rider instanceof Entity && ($rider->isPlayer() || $rider->class == ENTITY_MOB)){ if($rider->moveForward > 0){ $v32 = sin($this->yaw * M_PI / 180); $v33 = cos($this->yaw * M_PI / 180); - - if($this->speedZ*$this->speedZ + $this->speedX*$this->speedX < 0.01){ - $this->speedX -= $v32*0.1; - $this->speedZ += $v33*0.1; + + if($this->speedZ * $this->speedZ + $this->speedX * $this->speedX < 0.01){ + $this->speedX -= $v32 * 0.1; + $this->speedZ += $v33 * 0.1; } } } } - + $v38 = ($x + 0.5) + ($mat[0][0] * 0.5); $v39 = ($z + 0.5) + ($mat[0][2] * 0.5); $v40 = (($x + 0.5) + ($mat[1][0] * 0.5)) - $v38; $v41 = (($z + 0.5) + ($mat[1][2] * 0.5)) - $v39; - + if($v40 == 0){ $v42 = $this->z - $z; - }else if($v41 == 0){ + }elseif($v41 == 0){ $v42 = $this->x - $x; }else{ $v44 = (($this->z - $v39) * $v41) + (($this->x - $v38) * $v40); $v42 = $v44 + $v44; } - + $this->x = $v38 + ($v40 * $v42); $this->z = $v39 + ($v41 * $v42); - + $this->setPos($this->x, $this->y + $this->yOffset + 0.00001, $this->z); $dx = $this->speedX; $dz = $this->speedZ; @@ -205,55 +205,55 @@ class Minecart extends Vehicle{ $dx *= 0.75; $dz *= 0.75; } - + if($dx < -$maxSpeed) $dx = -$maxSpeed; - else if($dx > $maxSpeed) $dx = $maxSpeed; - + elseif($dx > $maxSpeed) $dx = $maxSpeed; + if($dz < -$maxSpeed) $dz = -$maxSpeed; - else if($dz > $maxSpeed) $dz = $maxSpeed; - + elseif($dz > $maxSpeed) $dz = $maxSpeed; + $this->move($dx, 0, $dz); - + if($mat[0][1]){ if((floor($this->x) - $x) == $mat[0][0] && (floor($this->z) - $z) == $mat[0][2]){ $this->setPos($this->x, $mat[0][1] + $this->y, $this->z); - }else if($mat[1][1]){ + }elseif($mat[1][1]){ goto mat_1_1; } - }else if($mat[1][1]){ + }elseif($mat[1][1]){ mat_1_1: if((floor($this->x) - $x) == $mat[1][0] && (floor($this->z) - $z) == $mat[1][2]){ $this->setPos($this->x, $mat[1][1] + $this->y, $this->z); } } - + $this->applyNaturalSlowdown(); $vec2 = $this->getPos($this->x, $this->y, $this->z); if($vec2 !== false && $vec !== false){ $yDiff = ($vec[1] - $vec2[1]) * 0.05; - $totalSpeed = sqrt($this->speedZ*$this->speedZ + $this->speedX*$this->speedX); - + $totalSpeed = sqrt($this->speedZ * $this->speedZ + $this->speedX * $this->speedX); + if($totalSpeed > 0){ $this->speedX = ($this->speedX / $totalSpeed) * ($totalSpeed + $yDiff); - $this->speedZ = ($this->speedZ / $totalSpeed) * ($totalSpeed + $yDiff); + $this->speedZ = ($this->speedZ / $totalSpeed) * ($totalSpeed + $yDiff); } $this->setPos($this->x, $vec2[1], $this->z); } - + if(floor($this->x) != $x || floor($this->z) != $z){ //this breaks everything - $totalSpeed = sqrt($this->speedZ*$this->speedZ + $this->speedX*$this->speedX); + $totalSpeed = sqrt($this->speedZ * $this->speedZ + $this->speedX * $this->speedX); $this->speedX = (floor($this->x) - $x) * $totalSpeed; $this->speedZ = (floor($this->z) - $z) * $totalSpeed; } - + if($id == POWERED_RAIL){ - $totalSpeed = sqrt($this->speedZ*$this->speedZ + $this->speedX*$this->speedX); + $totalSpeed = sqrt($this->speedZ * $this->speedZ + $this->speedX * $this->speedX); if($totalSpeed > 0.01){ $this->speedX += (($this->speedX / $totalSpeed) * 0.06); $this->speedZ += (($this->speedZ / $totalSpeed) * 0.06); return; } - + if($meta == 1){ //TODO Level::isSolidBlockingTile if(StaticBlock::getIsSolid($this->level->level->getBlockID($x - 1, $y, $z))){ @@ -265,7 +265,7 @@ class Minecart extends Vehicle{ $v63 = -0.02; } $this->speedX = $v63; - }else if($meta == 0){ + }elseif($meta == 0){ //TODO Level::isSolidBlockingTile if(StaticBlock::getIsSolid($this->level->level->getBlockID($x, $y, $z - 1))){ return; @@ -278,58 +278,57 @@ class Minecart extends Vehicle{ $this->speedZ = $v64; } } - + } - - + public function applyNaturalSlowdown(){ $mult = $this->linkedEntity != 0 && !$this->isRider ? 0.997 : 0.96; - + $this->speedX *= $mult; $this->speedY = 0; $this->speedZ *= $mult; } - + public function comeOffTrack($topSpeed){ if($this->speedX < -$topSpeed) $this->speedX = -$topSpeed; - else if($this->speedX > $topSpeed) $this->speedX = $topSpeed; - + elseif($this->speedX > $topSpeed) $this->speedX = $topSpeed; + if($this->speedZ < -$topSpeed) $this->speedZ = -$topSpeed; - else if($this->speedZ > $topSpeed) $this->speedZ = $topSpeed; - + elseif($this->speedZ > $topSpeed) $this->speedZ = $topSpeed; + if($this->onGround){ $this->speedX *= 0.5; $this->speedY *= 0.5; $this->speedZ *= 0.5; } - + $this->move($this->speedX, $this->speedY, $this->speedZ); - + if(!$this->onGround){ $this->speedX *= 0.95; $this->speedY *= 0.95; $this->speedZ *= 0.95; } - + } public function applyCollision(Entity $collided){ $diffX = $collided->x - $this->x; $diffZ = $collided->z - $this->z; - $dist = $diffX*$diffX + $diffZ*$diffZ; + $dist = $diffX * $diffX + $diffZ * $diffZ; if($dist >= 0.0001){ $sqrtMax = sqrt($dist); $diffX /= $sqrtMax; $diffZ /= $sqrtMax; - + $col = (($v = 1 / $sqrtMax) > 1 ? 1 : $v); $diffX *= $col; $diffZ *= $col; $diffX *= 0.1; $diffZ *= 0.1; - + $diffX *= 0.5; $diffZ *= 0.5; - + $this->addVelocity(-$diffX, 0, -$diffZ); $collided->addVelocity($diffX / 4, 0, $diffZ / 4); } @@ -341,18 +340,18 @@ class Minecart extends Vehicle{ } $this->updateLast(); //$this->updatePosition(); - + $this->speedY -= 0.04; //TODO port stuff - + $blockX = floor($this->x); $blockY = floor($this->y); $blockZ = floor($this->z); - + if(RailBaseBlock::isRailBlock($this->level, $blockX, $blockY - 1, $blockZ)){ --$blockY; } - + [$id, $meta] = $this->level->level->getBlock($blockX, $blockY, $blockZ); if(RailBaseBlock::isRailID($id)){ $this->moveAlongTrack($blockX, $blockY, $blockZ, 0.4, 0.0078125, $id, $meta); @@ -362,32 +361,32 @@ class Minecart extends Vehicle{ } $this->doBlocksCollision(); - + $this->pitch = 0; $diffX = $this->lastX - $this->x; $diffZ = $this->lastZ - $this->z; - - if($diffX*$diffX + $diffZ*$diffZ > 0.001){ + + if($diffX * $diffX + $diffZ * $diffZ > 0.001){ $this->yaw = atan2($diffZ, $diffX) * 180 / M_PI; - + if($this->isInReverse) $this->yaw += 180; } - + $yw = fmod($this->yaw - $this->lastYaw, 360); if($yw >= 180) $yw -= 360; if($yw < 180) $yw += 360; - + if($yw < -170 || $yw >= 170){ $this->isInReverse = !$this->isInReverse; $this->yaw = $this->yaw + 180; } - + $bb = $this->boundingBox->expand(0.2, 0, 0.2); - $minChunkX = ((int)($bb->minX - 2)) >> 4; - $minChunkZ = ((int)($bb->minZ - 2)) >> 4; - $maxChunkX = ((int)($bb->minX + 2)) >> 4; - $maxChunkZ = ((int)($bb->minZ + 2)) >> 4; - + $minChunkX = ((int) ($bb->minX - 2)) >> 4; + $minChunkZ = ((int) ($bb->minZ - 2)) >> 4; + $maxChunkX = ((int) ($bb->minX + 2)) >> 4; + $maxChunkZ = ((int) ($bb->minZ + 2)) >> 4; + //TODO also index by chunkY? for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){ for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){ @@ -401,14 +400,14 @@ class Minecart extends Vehicle{ }else{ $e->applyCollision($this); } - + } } } } } } - + public function close() { parent::close(); @@ -421,11 +420,11 @@ class Minecart extends Vehicle{ } } } - + public function isPushable(){ return false; //TODO replace with true } - + public function spawn($player){ $pk = new AddEntityPacket; $pk->eid = $this->eid; @@ -436,7 +435,7 @@ class Minecart extends Vehicle{ $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $player->dataPacket($pk); - + $pk = new SetEntityMotionPacket; $pk->eid = $this->eid; $pk->speedX = $this->speedX; @@ -444,7 +443,7 @@ class Minecart extends Vehicle{ $pk->speedZ = $this->speedZ; $player->dataPacket($pk); } - + public function interactWith(Entity $e, $action){ if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){ $e->setRiding($this); diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index 21f30927..a0e7b99e 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -3,23 +3,23 @@ class Painting extends Entity{ const CLASS_TYPE = ENTITY_OBJECT; const TYPE = OBJECT_PAINTING; - + public $motive; public $direction; public $xPos, $yPos, $zPos; - + public $isValid = true; - + public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->x = $this->data["TileX"] ?? $this->x; $this->y = $this->data["TileY"] ?? $this->y; $this->z = $this->data["TileZ"] ?? $this->z; - - $this->xPos = $this->data["xPos"] ?? (int)$this->x; - $this->zPos = $this->data["zPos"] ?? (int)$this->z; - $this->yPos = $this->data["yPos"] ?? (int)$this->y; - + + $this->xPos = $this->data["xPos"] ?? (int) $this->x; + $this->zPos = $this->data["zPos"] ?? (int) $this->z; + $this->yPos = $this->data["yPos"] ?? (int) $this->y; + $this->health = 1; $this->canBeAttacked = true; $this->width = 1; @@ -30,30 +30,30 @@ class Painting extends Entity{ if($dir === false){ $dir = floor($this->yaw / 90); } - + if($mot === false){ $this->setRandomMotive($dir); - + }else{ $this->motive = $mot; $this->direction = $dir; $this->setDirection($dir); } } - + public $counter = 0; public function update($now){ - if($this->closed === true){ - return false; - } - + if($this->closed === true){ + return false; + } + if(++$this->counter >= 100){ $this->counter = 0; if(!$this->survives() && !$this->dead){ //maybe dont check entity collision? $this->makeDead("nosurvive"); } } - + return true; } @@ -62,34 +62,34 @@ class Painting extends Entity{ foreach(PaintingItem::$motives as $name => $motive){ $this->motive = $name; $this->setDirection($dir); - + if($this->survives()){ $tochoose[] = $name; } } if(count($tochoose) > 0){ - $ind = mt_rand(0, count($tochoose)-1); + $ind = mt_rand(0, count($tochoose) - 1); }else{ $this->isValid = false; return; } - + $this->motive = $tochoose[$ind]; $this->setDirection($dir); } - + public static function offs($n){ if($n == 32 || $n == 64) return 0.5; return 0; } - + const DIRECTION_OPPOSITE = [2, 3, 0, 1]; public function setDirection($dir){ $this->direction = $dir; $this->lastYaw = $this->yaw = $dir * 90; - $size = PaintingItem::$motives[$this->motive] ?? array(1, 1); - $width = $size[0]*16; - $height = $size[1]*16; + $size = PaintingItem::$motives[$this->motive] ?? [1, 1]; + $width = $size[0] * 16; + $height = $size[1] * 16; if($dir == 2 || $dir == 0){ $v10 = 2; $v9 = $width; @@ -98,28 +98,28 @@ class Painting extends Entity{ $v9 = 2; $v10 = $width; } - + $v12 = $v9 * 0.03125; $v13 = $height * 0.03125; $v14 = $v10 * 0.03125; $v15 = $this->xPos + 0.5; $v16 = $this->yPos + 0.5; $v17 = $this->zPos + 0.5; //XXX check - + if($dir == 2){ $v17 = $v17 - 0.5625; $v15 = $v15 - self::offs($width); - }else if($dir == 1){ + }elseif($dir == 1){ $v15 = $v15 - 0.5625; $v17 = $v17 + self::offs($width); - }else if($dir == 3){ + }elseif($dir == 3){ $v15 = $v15 + 0.5625; $v17 = $v17 - self::offs($width); }else{ $v17 = $v17 + 0.5625; $v15 = $v15 + self::offs($width); } - + $v23 = $v16 + self::offs($height); $this->setPos($v15, $v23, $v17); $this->boundingBox->minX = ($v15 - $v12) + 0.03125; @@ -129,35 +129,35 @@ class Painting extends Entity{ $this->boundingBox->maxY = ($v23 + $v13) - 0.03125; $this->boundingBox->maxZ = ($v17 + $v14) - 0.03125; } - + public function getDrops(){ return [ [PAINTING, 0, 1] ]; } - + public function isPickable(){ return true; } - + public function survives(){ $cubes = $this->level->getCubes($this, $this->boundingBox); if(count($cubes) == 0){ - - $size = PaintingItem::$motives[$this->motive] ?? array(1, 1); + + $size = PaintingItem::$motives[$this->motive] ?? [1, 1]; $width = $size[0]; - $width2 = $width*16/32; + $width2 = $width * 16 / 32; $height = $size[1]; - $height2 = $height*16/32; + $height2 = $height * 16 / 32; if($width < 1) $width = 1; if($height < 1) $height = 1; $positionX = $this->xPos; $positionZ = $this->zPos; if($this->direction == 2 || $this->direction == 0) $positionX = floor($this->x - $width2); if($this->direction == 1 || $this->direction == 3) $positionZ = floor($this->z - $width2); - + $minY = floor($this->y - $height2); - + for($off = 0; $off < $width; ++$off){ for($yoff = 0; $yoff < $height; ++$yoff){ $y = $minY + $yoff; @@ -166,13 +166,13 @@ class Painting extends Entity{ }else{ $id = $this->level->level->getBlockId($positionX + $off, $y, $this->zPos); } - + if(!StaticBlock::getIsSolid($id)){ return false; } } } - + $ents = $this->level->getEntitiesInAABBOfType($this->boundingBox, ENTITY_OBJECT); foreach($ents as $e){ if($e->eid == $this->eid) continue; @@ -182,13 +182,13 @@ class Painting extends Entity{ } return true; } - + return false; } - + public function createSaveData(){ $data = parent::createSaveData(); - + $data["Motive"] = $this->motive; $data["Direction"] = $this->direction; $data["xPos"] = $this->xPos; diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index f88adb7e..b6be4d6c 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -14,11 +14,11 @@ class PrimedTNT extends Entity{ $this->yOffset = $this->height / 2; $this->setHealth(10000000, "generic"); } - + public function isPickable(){ return !$this->dead; } - + public function getMetadata(){ $d = parent::getMetadata(); $d[16]["value"] = (int) $this->data["fuse"]; @@ -26,34 +26,34 @@ class PrimedTNT extends Entity{ } public function createSaveData(){ $data = parent::createSaveData(); - + $data["fuse"] = $this->data["fuse"]; $data["power"] = $this->data["power"]; - + return $data; } - + public function update($now){ if($this->closed) return; $this->lastX = $this->x; $this->lastY = $this->y; $this->lastZ = $this->z; - + $this->speedY -= 0.04; $this->move($this->speedX, $this->speedY, $this->speedZ); - $this->speedX *- 0.98; + $this->speedX * -0.98; $this->speedY *= 0.98; $this->speedZ *= 0.98; - + if($this->onGround){ $this->speedX *= 0.7; $this->speedZ *= 0.7; - + $this->speedY *= -0.5; } - + $tickDiff = ($now - $this->lastUpdate) / 0.05; - + $this->data["fuse"] -= $tickDiff; $this->updateMetadata(); if($this->data["fuse"] <= 0){ @@ -61,10 +61,10 @@ class PrimedTNT extends Entity{ $explosion = new Explosion($this, $this->data["power"]); $explosion->explode(); } - + $this->lastUpdate = $now; } - + public function spawn($player){ $pk = new AddEntityPacket; $pk->eid = $this->eid; diff --git a/src/entity/object/ThrownEgg.php b/src/entity/object/ThrownEgg.php index 661bbe0f..98794845 100644 --- a/src/entity/object/ThrownEgg.php +++ b/src/entity/object/ThrownEgg.php @@ -1,32 +1,32 @@ typeOfHit == 1){ $hitResult->entityHit->harm(0, $this->eid); } - + $rand = mt_rand(0, 7); if($rand == 0){ $count = mt_rand(0, 31) == 0 ? 4 : 1; $data = [ "x" => $this->x, "y" => $this->y, - "z" => $this->z, + "z" => $this->z, "yaw" => $this->yaw, "pitch" => 0, "IsBaby" => true ]; for($i = 0; $i < $count; ++$i){ $chicken = $this->server->api->entity->add($this->level, ENTITY_MOB, MOB_CHICKEN, $data); - + $this->server->api->entity->spawnToAll($chicken); } } - + $this->close(); } - - -} \ No newline at end of file + + } \ No newline at end of file diff --git a/src/entity/object/ThrownSnowball.php b/src/entity/object/ThrownSnowball.php index a6758cd3..81104061 100644 --- a/src/entity/object/ThrownSnowball.php +++ b/src/entity/object/ThrownSnowball.php @@ -1,11 +1,12 @@ typeOfHit == 1){ $hitResult->entityHit->harm(0, $this->eid); } - + $this->close(); } } \ No newline at end of file diff --git a/src/entity/object/TripodCamera.php b/src/entity/object/TripodCamera.php index 6855cd3c..f69339d8 100644 --- a/src/entity/object/TripodCamera.php +++ b/src/entity/object/TripodCamera.php @@ -2,16 +2,16 @@ class TripodCamera extends Entity{ const TYPE = OBJECT_TRIPOD_CAMERA; - + function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->setHealth(PHP_INT_MAX, "generic"); } - + public function isPickable(){ return !$this->dead; } - + public function interactWith(Entity $e, $action){ if($e->isPlayer() and $action === InteractPacket::ACTION_HOLD){ //todo diff --git a/src/entity/registry/EntityRegistry.php b/src/entity/registry/EntityRegistry.php index 565c65b2..b2a8641d 100644 --- a/src/entity/registry/EntityRegistry.php +++ b/src/entity/registry/EntityRegistry.php @@ -1,8 +1,8 @@ isAbstract()){ //self::$entityList[$className::TYPE] = $className; - + self::$entityList->addEntity(new PropertyEntity($className::CLASS_TYPE, $className::TYPE, $className)); //self::$shortNames[$className] = $class->getShortName(); what is this even supposed to do? //console("[INFO] Registered a ".$className); diff --git a/src/entity/registry/PropertyEntity.php b/src/entity/registry/PropertyEntity.php index d2cf972b..999620be 100644 --- a/src/entity/registry/PropertyEntity.php +++ b/src/entity/registry/PropertyEntity.php @@ -2,13 +2,13 @@ class PropertyEntity{ private $class,$type,$name; - + function __construct($class, $type, $name){ $this->class = $class; $this->type = $type; $this->name = $name; } - + public function getEntityClass(){ return $this->class; } diff --git a/src/event/EventHandler.php b/src/event/EventHandler.php index 7751306c..96f5b7d3 100644 --- a/src/event/EventHandler.php +++ b/src/event/EventHandler.php @@ -16,7 +16,7 @@ abstract class EventHandler{ }else{ return BaseEvent::ALLOW; } - } + } } } diff --git a/src/event/EventPriority.php b/src/event/EventPriority.php index f42e8d73..6de6a27e 100644 --- a/src/event/EventPriority.php +++ b/src/event/EventPriority.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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -44,9 +44,9 @@ abstract class EventPriority{ const HIGHEST = 1; /** * Event is listened to purely for monitoring the outcome of an event. - * + * * No modifications to the event should be made under this priority */ const MONITOR = 0; - + } \ No newline at end of file diff --git a/src/event/PluginEvent.php b/src/event/PluginEvent.php index 3887bb0d..0796e7bb 100644 --- a/src/event/PluginEvent.php +++ b/src/event/PluginEvent.php @@ -1,6 +1,5 @@ packet = $packet; $this->player = $player; } - + public function getPacket(){ return $this->packet; } - + public function getPlayer(){ return $this->player; } diff --git a/src/event/server/DataPacketSendEvent.php b/src/event/server/DataPacketSendEvent.php index 5e55a29b..62f2e6a0 100644 --- a/src/event/server/DataPacketSendEvent.php +++ b/src/event/server/DataPacketSendEvent.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 @@ -15,26 +15,26 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ class DataPacketSendEvent extends ServerEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; - + private $packet; - private $player; - + private $player; + public function __construct(Player $player, RakNetDataPacket $packet){ $this->packet = $packet; $this->player = $player; } - + public function getPacket(){ return $this->packet; } - + public function getPlayer(){ return $this->player; } diff --git a/src/event/server/PacketReceiveEvent.php b/src/event/server/PacketReceiveEvent.php index cb26cbf0..60b8b354 100644 --- a/src/event/server/PacketReceiveEvent.php +++ b/src/event/server/PacketReceiveEvent.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 @@ -15,21 +15,20 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ class PacketReceiveEvent extends ServerEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; - + private $packet; - - + public function __construct(Packet $packet){ $this->packet = $packet; } - + public function getPacket(){ return $this->packet; } diff --git a/src/event/server/PacketSendEvent.php b/src/event/server/PacketSendEvent.php index becb15e4..cea83d3d 100644 --- a/src/event/server/PacketSendEvent.php +++ b/src/event/server/PacketSendEvent.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 @@ -15,21 +15,20 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ class PacketSendEvent extends ServerEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; - + private $packet; - - + public function __construct(Packet $packet){ $this->packet = $packet; } - + public function getPacket(){ return $this->packet; } diff --git a/src/functions.php b/src/functions.php index 1838b9a3..3a937596 100644 --- a/src/functions.php +++ b/src/functions.php @@ -11,7 +11,6 @@ if(!function_exists("cli_set_process_title")){ } } - function dummy(){ } @@ -69,8 +68,6 @@ function nullsafe(&$a, $null){ return $a ?? $null; } - - function require_all($path, &$count = 0){ $dir = dir($path . "/"); $dirs = []; diff --git a/src/installer/Installer.php b/src/installer/Installer.php index d732b689..fe4ec2c4 100644 --- a/src/installer/Installer.php +++ b/src/installer/Installer.php @@ -8,7 +8,7 @@ const DEFAULT_MEMORY = 128; const DEFAULT_PLAYERS = 20; const DEFAULT_GAMEMODE = SURVIVAL; - + private $lang, $config; public function __construct(){ echo "[*] NostalgiaCore set-up wizard\n"; @@ -25,8 +25,8 @@ } }while($lang == false); $this->lang = new InstallerLang($lang); - echo "[*] ".$this->lang->language_has_been_selected."\n"; - echo "[?] ".$this->lang->skip_installer." (y/N): "; + echo "[*] " . $this->lang->language_has_been_selected . "\n"; + echo "[?] " . $this->lang->skip_installer . " (y/N): "; if(strtolower($this->getInput()) === "y"){ return; } @@ -34,14 +34,14 @@ $this->welcome(); $this->generateBaseConfig(); $this->generateUserFiles(); - + $this->networkFunctions(); - + $this->endWizard(); } - + private function welcome(){ - echo $this->lang->welcome_to_pocketmine."\n"; + echo $this->lang->welcome_to_pocketmine . "\n"; echo <<lang->accept_license." (y/N): "; + echo "\n[?] " . $this->lang->accept_license . " (y/N): "; if(strtolower($this->getInput("n")) != "y"){ - echo "[!] ".$this->lang->you_have_to_accept_the_license."\n"; + echo "[!] " . $this->lang->you_have_to_accept_the_license . "\n"; sleep(5); exit(0); } - echo "[*] ".$this->lang->setting_up_server_now."\n"; - echo "[*] ".$this->lang->default_values_info."\n"; - echo "[*] ".$this->lang->server_properties."\n"; - + echo "[*] " . $this->lang->setting_up_server_now . "\n"; + echo "[*] " . $this->lang->default_values_info . "\n"; + echo "[*] " . $this->lang->server_properties . "\n"; + } - + private function generateBaseConfig(){ $config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES); - echo "[?] ".$this->lang->name_your_server." (".self::DEFAULT_NAME."): "; + echo "[?] " . $this->lang->name_your_server . " (" . self::DEFAULT_NAME . "): "; $config->set("server-name", $this->getInput(self::DEFAULT_NAME)); - echo "[*] ".$this->lang->port_warning."\n"; + echo "[*] " . $this->lang->port_warning . "\n"; do{ - echo "[?] ".$this->lang->server_port." (".self::DEFAULT_PORT."): "; + echo "[?] " . $this->lang->server_port . " (" . self::DEFAULT_PORT . "): "; $port = (int) $this->getInput(self::DEFAULT_PORT); if($port <= 0 or $port > 65535){ - echo "[!] ".$this->lang->invalid_port."\n"; + echo "[!] " . $this->lang->invalid_port . "\n"; } }while($port <= 0 or $port > 65535); $config->set("server-port", $port); - echo "[*] ".$this->lang->ram_warning."\n"; - echo "[?] ".$this->lang->server_ram." (".self::DEFAULT_MEMORY."): "; - $config->set("memory-limit", ((int) $this->getInput(self::DEFAULT_MEMORY))."M"); - echo "[*] ".$this->lang->gamemode_info."\n"; + echo "[*] " . $this->lang->ram_warning . "\n"; + echo "[?] " . $this->lang->server_ram . " (" . self::DEFAULT_MEMORY . "): "; + $config->set("memory-limit", ((int) $this->getInput(self::DEFAULT_MEMORY)) . "M"); + echo "[*] " . $this->lang->gamemode_info . "\n"; do{ - echo "[?] ".$this->lang->default_gamemode.": (".self::DEFAULT_GAMEMODE."): "; + echo "[?] " . $this->lang->default_gamemode . ": (" . self::DEFAULT_GAMEMODE . "): "; $gamemode = (int) $this->getInput(self::DEFAULT_GAMEMODE); }while($gamemode < 0 or $gamemode > 3); $config->set("gamemode", $gamemode); - echo "[?] ".$this->lang->max_players." (".self::DEFAULT_PLAYERS."): "; + echo "[?] " . $this->lang->max_players . " (" . self::DEFAULT_PLAYERS . "): "; $config->set("max-players", (int) $this->getInput(self::DEFAULT_PLAYERS)); - echo "[*] ".$this->lang->spawn_protection_info."\n"; - echo "[?] ".$this->lang->spawn_protection." (Y/n): "; + echo "[*] " . $this->lang->spawn_protection_info . "\n"; + echo "[?] " . $this->lang->spawn_protection . " (Y/n): "; if(strtolower($this->getInput("y")) == "n"){ $config->set("spawn-protection", -1); }else{ @@ -95,82 +95,80 @@ LICENSE; } $config->save(); } - + private function generateUserFiles(){ - echo "[*] ".$this->lang->op_info."\n"; - echo "[?] ".$this->lang->op_who.": "; + echo "[*] " . $this->lang->op_info . "\n"; + echo "[?] " . $this->lang->op_who . ": "; $op = strtolower($this->getInput("")); if($op === ""){ - echo "[!] ".$this->lang->op_warning."\n"; + echo "[!] " . $this->lang->op_warning . "\n"; }else{ - $ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST); + $ops = new Config(DATA_PATH . "ops.txt", CONFIG_LIST); $ops->set($op, true); $ops->save(); } - echo "[*] ".$this->lang->whitelist_info."\n"; - echo "[?] ".$this->lang->whitelist_enable." (y/N): "; + echo "[*] " . $this->lang->whitelist_info . "\n"; + echo "[?] " . $this->lang->whitelist_enable . " (y/N): "; $config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES); if(strtolower($this->getInput("n")) === "y"){ - echo "[!] ".$this->lang->whitelist_warning."\n"; + echo "[!] " . $this->lang->whitelist_warning . "\n"; $config->set("white-list", true); }else{ $config->set("white-list", false); } $config->save(); } - + private function networkFunctions(){ $config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES); - echo "[!] ".$this->lang->query_warning1."\n"; - echo "[!] ".$this->lang->query_warning2."\n"; - echo "[?] ".$this->lang->query_disable." (y/N): "; + echo "[!] " . $this->lang->query_warning1 . "\n"; + echo "[!] " . $this->lang->query_warning2 . "\n"; + echo "[?] " . $this->lang->query_disable . " (y/N): "; if(strtolower($this->getInput("n")) === "y"){ $config->set("enable-query", false); }else{ $config->set("enable-query", true); } - - echo "[*] ".$this->lang->rcon_info."\n"; - echo "[?] ".$this->lang->rcon_enable." (y/N): "; + + echo "[*] " . $this->lang->rcon_info . "\n"; + echo "[?] " . $this->lang->rcon_enable . " (y/N): "; if(strtolower($this->getInput("n")) === "y"){ $config->set("enable-rcon", true); $password = substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10); $config->set("rcon.password", $password); - echo "[*] ".$this->lang->rcon_password.": ".$password."\n"; + echo "[*] " . $this->lang->rcon_password . ": " . $password . "\n"; }else{ $config->set("enable-rcon", false); } $config->save(); - - - echo "[*] ".$this->lang->ip_get."\n"; - + + echo "[*] " . $this->lang->ip_get . "\n"; + $externalIP = Utils::getIP(); $internalIP = gethostbyname(trim(`hostname`)); - - echo "[!] ".$this->lang->get("ip_warning", array("{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"), array($externalIP, $internalIP))."\n"; - echo "[!] ".$this->lang->ip_confirm; + + echo "[!] " . $this->lang->get("ip_warning", ["{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"], [$externalIP, $internalIP]) . "\n"; + echo "[!] " . $this->lang->ip_confirm; $this->getInput(); } - + private function endWizard(){ - echo "[*] ".$this->lang->you_have_finished."\n"; - echo "[*] ".$this->lang->pocketmine_plugins."\n"; - echo "[*] ".$this->lang->pocketmine_will_start."\n\n\n"; + echo "[*] " . $this->lang->you_have_finished . "\n"; + echo "[*] " . $this->lang->pocketmine_plugins . "\n"; + echo "[*] " . $this->lang->pocketmine_will_start . "\n\n\n"; sleep(4); } - + private function getInput($default = ""){ $input = trim(fgets(STDIN)); return $input === "" ? $default:$input; } - } class InstallerLang{ - public static $languages = array( + public static $languages = [ "ru" => "Pyccĸий", "en" => "English", "es" => "Español", @@ -180,7 +178,7 @@ LICENSE; //"vi" => "Tiếng Việt", "ko" => "한국어", "fr" => "Français", - "it" => "Italiano", + "it" => "Italiano", //"lv" => "Latviešu", "nl" => "Nederlands", //"pt" => "Português", @@ -189,18 +187,18 @@ LICENSE; "tr" => "Türkçe", "uk" => "Український" //"et" => "Eesti", - ); - private $texts = array(); + ]; + private $texts = []; private $lang; private $langfile; public function __construct($lang = ""){ - if(file_exists(FILE_PATH."src/lang/Installer/".$lang.".ini")){ + if(file_exists(FILE_PATH . "src/lang/Installer/" . $lang . ".ini")){ $this->lang = $lang; - $this->langfile = FILE_PATH."src/lang/Installer/".$lang.".ini"; + $this->langfile = FILE_PATH . "src/lang/Installer/" . $lang . ".ini"; }else{ - $l = glob(FILE_PATH."src/lang/Installer/".$lang."_*.ini"); + $l = glob(FILE_PATH . "src/lang/Installer/" . $lang . "_*.ini"); if(count($l) > 0){ - $files = array(); + $files = []; foreach($l as $file){ $files[$file] = filesize($file); } @@ -209,38 +207,38 @@ LICENSE; $l = key($files); $l = substr($l, strrpos($l, "/") + 1, -4); $this->lang = isset(self::$languages[$l]) ? $l:$lang; - $this->langfile = FILE_PATH."src/lang/Installer/".$l.".ini"; + $this->langfile = FILE_PATH . "src/lang/Installer/" . $l . ".ini"; }else{ $this->lang = "en"; - $this->langfile = FILE_PATH."src/lang/Installer/en.ini"; + $this->langfile = FILE_PATH . "src/lang/Installer/en.ini"; } } - - $this->loadLang(FILE_PATH."src/lang/Installer/en.ini", "en"); + + $this->loadLang(FILE_PATH . "src/lang/Installer/en.ini", "en"); if($this->lang !== "en"){ $this->loadLang($this->langfile, $this->lang); } } - + public function getLang(){ return ($this->lang); } - + public function loadLang($langfile, $lang = "en"){ - $this->texts[$lang] = array(); - $texts = explode("\n", str_replace(array("\r", "\/\/"), array("", "//"), file_get_contents($langfile))); + $this->texts[$lang] = []; + $texts = explode("\n", str_replace(["\r", "\/\/"], ["", "//"], file_get_contents($langfile))); foreach($texts as $line){ $line = trim($line); if($line === ""){ continue; } $line = explode("=", $line); - $this->texts[$lang][array_shift($line)] = str_replace(array("\\n", "\\N",), "\n", implode("=", $line)); + $this->texts[$lang][array_shift($line)] = str_replace(["\\n", "\\N",], "\n", implode("=", $line)); } } - - public function get($name, $search = array(), $replace = array()){ + + public function get($name, $search = [], $replace = []){ if(!isset($this->texts[$this->lang][$name])){ if($this->lang !== "en" and isset($this->texts["en"][$name])){ return $this->texts["en"][$name]; @@ -253,10 +251,10 @@ LICENSE; return $this->texts[$this->lang][$name]; } } - + public function __get($name){ return $this->get($name); } - } + } /***REM_END***/ diff --git a/src/material/Block.php b/src/material/Block.php index 459c1e91..e83a913f 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -1,138 +1,138 @@ "AirBlock", - STONE => "StoneBlock", - GRASS => "GrassBlock", - DIRT => "DirtBlock", - COBBLESTONE => "CobblestoneBlock", - PLANKS => "PlanksBlock", - SAPLING => "SaplingBlock", - BEDROCK => "BedrockBlock", - WATER => "WaterBlock", - STILL_WATER => "StillWaterBlock", - LAVA => "LavaBlock", - STILL_LAVA => "StillLavaBlock", - SAND => "SandBlock", - GRAVEL => "GravelBlock", - GOLD_ORE => "GoldOreBlock", - IRON_ORE => "IronOreBlock", - COAL_ORE => "CoalOreBlock", - WOOD => "WoodBlock", - LEAVES => "LeavesBlock", - SPONGE => "SpongeBlock", - GLASS => "GlassBlock", - LAPIS_ORE => "LapisOreBlock", - LAPIS_BLOCK => "LapisBlock", - SANDSTONE => "SandstoneBlock", - BED_BLOCK => "BedBlock", - POWERED_RAIL => "PoweredRailBlock", - COBWEB => "CobwebBlock", - TALL_GRASS => "TallGrassBlock", - DEAD_BUSH => "DeadBushBlock", - WOOL => "WoolBlock", - DANDELION => "DandelionBlock", - CYAN_FLOWER => "CyanFlowerBlock", - BROWN_MUSHROOM => "BrownMushroomBlock", - RED_MUSHROOM => "RedMushRoomBlock", - GOLD_BLOCK => "GoldBlock", - IRON_BLOCK => "IronBlock", - DOUBLE_SLAB => "DoubleSlabBlock", - SLAB => "SlabBlock", - BRICKS_BLOCK => "BricksBlock", - TNT => "TNTBlock", - BOOKSHELF => "BookshelfBlock", - MOSS_STONE => "MossStoneBlock", - OBSIDIAN => "ObsidianBlock", - TORCH => "TorchBlock", - FIRE => "FireBlock", + public static $class = [ + AIR => "AirBlock", + STONE => "StoneBlock", + GRASS => "GrassBlock", + DIRT => "DirtBlock", + COBBLESTONE => "CobblestoneBlock", + PLANKS => "PlanksBlock", + SAPLING => "SaplingBlock", + BEDROCK => "BedrockBlock", + WATER => "WaterBlock", + STILL_WATER => "StillWaterBlock", + LAVA => "LavaBlock", + STILL_LAVA => "StillLavaBlock", + SAND => "SandBlock", + GRAVEL => "GravelBlock", + GOLD_ORE => "GoldOreBlock", + IRON_ORE => "IronOreBlock", + COAL_ORE => "CoalOreBlock", + WOOD => "WoodBlock", + LEAVES => "LeavesBlock", + SPONGE => "SpongeBlock", + GLASS => "GlassBlock", + LAPIS_ORE => "LapisOreBlock", + LAPIS_BLOCK => "LapisBlock", + SANDSTONE => "SandstoneBlock", + BED_BLOCK => "BedBlock", + POWERED_RAIL => "PoweredRailBlock", + COBWEB => "CobwebBlock", + TALL_GRASS => "TallGrassBlock", + DEAD_BUSH => "DeadBushBlock", + WOOL => "WoolBlock", + DANDELION => "DandelionBlock", + CYAN_FLOWER => "CyanFlowerBlock", + BROWN_MUSHROOM => "BrownMushroomBlock", + RED_MUSHROOM => "RedMushRoomBlock", + GOLD_BLOCK => "GoldBlock", + IRON_BLOCK => "IronBlock", + DOUBLE_SLAB => "DoubleSlabBlock", + SLAB => "SlabBlock", + BRICKS_BLOCK => "BricksBlock", + TNT => "TNTBlock", + BOOKSHELF => "BookshelfBlock", + MOSS_STONE => "MossStoneBlock", + OBSIDIAN => "ObsidianBlock", + TORCH => "TorchBlock", + FIRE => "FireBlock", - WOOD_STAIRS => "WoodStairsBlock", - CHEST => "ChestBlock", + WOOD_STAIRS => "WoodStairsBlock", + CHEST => "ChestBlock", - DIAMOND_ORE => "DiamondOreBlock", - DIAMOND_BLOCK => "DiamondBlock", - WORKBENCH => "WorkbenchBlock", - WHEAT_BLOCK => "WheatBlock", - FARMLAND => "FarmlandBlock", - FURNACE => "FurnaceBlock", - BURNING_FURNACE => "BurningFurnaceBlock", - SIGN_POST => "SignPostBlock", - WOOD_DOOR_BLOCK => "WoodDoorBlock", - LADDER => "LadderBlock", - RAIL => "RailBlock", - COBBLESTONE_STAIRS => "CobblestoneStairsBlock", - WALL_SIGN => "WallSignBlock", + DIAMOND_ORE => "DiamondOreBlock", + DIAMOND_BLOCK => "DiamondBlock", + WORKBENCH => "WorkbenchBlock", + WHEAT_BLOCK => "WheatBlock", + FARMLAND => "FarmlandBlock", + FURNACE => "FurnaceBlock", + BURNING_FURNACE => "BurningFurnaceBlock", + SIGN_POST => "SignPostBlock", + WOOD_DOOR_BLOCK => "WoodDoorBlock", + LADDER => "LadderBlock", + RAIL => "RailBlock", + COBBLESTONE_STAIRS => "CobblestoneStairsBlock", + WALL_SIGN => "WallSignBlock", - IRON_DOOR_BLOCK => "IronDoorBlock", - REDSTONE_ORE => "RedstoneOreBlock", - GLOWING_REDSTONE_ORE => "GlowingRedstoneOreBlock", + IRON_DOOR_BLOCK => "IronDoorBlock", + REDSTONE_ORE => "RedstoneOreBlock", + GLOWING_REDSTONE_ORE => "GlowingRedstoneOreBlock", - SNOW_LAYER => "SnowLayerBlock", - ICE => "IceBlock", - SNOW_BLOCK => "SnowBlock", - CACTUS => "CactusBlock", - CLAY_BLOCK => "ClayBlock", - SUGARCANE_BLOCK => "SugarcaneBlock", + SNOW_LAYER => "SnowLayerBlock", + ICE => "IceBlock", + SNOW_BLOCK => "SnowBlock", + CACTUS => "CactusBlock", + CLAY_BLOCK => "ClayBlock", + SUGARCANE_BLOCK => "SugarcaneBlock", - FENCE => "FenceBlock", - PUMPKIN => "PumpkinBlock", - NETHERRACK => "NetherrackBlock", - SOUL_SAND => "SoulSandBlock", - GLOWSTONE_BLOCK => "GlowstoneBlock", + FENCE => "FenceBlock", + PUMPKIN => "PumpkinBlock", + NETHERRACK => "NetherrackBlock", + SOUL_SAND => "SoulSandBlock", + GLOWSTONE_BLOCK => "GlowstoneBlock", - LIT_PUMPKIN => "LitPumpkinBlock", - INVISIBLE_BEDROCK => "InvisibleBedrockBlock", - - CAKE_BLOCK => "CakeBlock", - - TRAPDOOR => "TrapdoorBlock", + LIT_PUMPKIN => "LitPumpkinBlock", + INVISIBLE_BEDROCK => "InvisibleBedrockBlock", - STONE_BRICKS => "StoneBricksBlock", + CAKE_BLOCK => "CakeBlock", - IRON_BARS => "IronBarsBlock", - GLASS_PANE => "GlassPaneBlock", - MELON_BLOCK => "MelonBlock", - PUMPKIN_STEM => "PumpkinStemBlock", - MELON_STEM => "MelonStemBlock", + TRAPDOOR => "TrapdoorBlock", - FENCE_GATE => "FenceGateBlock", - BRICK_STAIRS => "BrickStairsBlock", - STONE_BRICK_STAIRS => "StoneBrickStairsBlock", + STONE_BRICKS => "StoneBricksBlock", - NETHER_BRICKS => "NetherBricksBlock", + IRON_BARS => "IronBarsBlock", + GLASS_PANE => "GlassPaneBlock", + MELON_BLOCK => "MelonBlock", + PUMPKIN_STEM => "PumpkinStemBlock", + MELON_STEM => "MelonStemBlock", - NETHER_BRICKS_STAIRS => "NetherBricksStairsBlock", + FENCE_GATE => "FenceGateBlock", + BRICK_STAIRS => "BrickStairsBlock", + STONE_BRICK_STAIRS => "StoneBrickStairsBlock", - SANDSTONE_STAIRS => "SandstoneStairsBlock", - - SPRUCE_WOOD_STAIRS => "SpruceWoodStairsBlock", - BIRCH_WOOD_STAIRS => "BirchWoodStairsBlock", - JUNGLE_WOOD_STAIRS => "JungleWoodStairsBlock", - STONE_WALL => "StoneWallBlock", - - CARROT_BLOCK => "CarrotBlock", - POTATO_BLOCK => "PotatoBlock", + NETHER_BRICKS => "NetherBricksBlock", - QUARTZ_BLOCK => "QuartzBlock", - QUARTZ_STAIRS => "QuartzStairsBlock", - DOUBLE_WOOD_SLAB => "DoubleWoodSlabBlock", - WOOD_SLAB => "WoodSlabBlock", - - HAY_BALE => "HayBaleBlock", - CARPET => "CarpetBlock", - - COAL_BLOCK => "CoalBlock", - - BEETROOT_BLOCK => "BeetrootBlock", - STONECUTTER => "StonecutterBlock", - GLOWING_OBSIDIAN => "GlowingObsidianBlock", - NETHER_REACTOR => "NetherReactorBlock", - INFO_UPDATE => "InfoUpdateBlock", - INFO_UPDATE2 => "InfoUpdate2Block", - RESERVED6 => "Reserved6Block", - ); + NETHER_BRICKS_STAIRS => "NetherBricksStairsBlock", + + SANDSTONE_STAIRS => "SandstoneStairsBlock", + + SPRUCE_WOOD_STAIRS => "SpruceWoodStairsBlock", + BIRCH_WOOD_STAIRS => "BirchWoodStairsBlock", + JUNGLE_WOOD_STAIRS => "JungleWoodStairsBlock", + STONE_WALL => "StoneWallBlock", + + CARROT_BLOCK => "CarrotBlock", + POTATO_BLOCK => "PotatoBlock", + + QUARTZ_BLOCK => "QuartzBlock", + QUARTZ_STAIRS => "QuartzStairsBlock", + DOUBLE_WOOD_SLAB => "DoubleWoodSlabBlock", + WOOD_SLAB => "WoodSlabBlock", + + HAY_BALE => "HayBaleBlock", + CARPET => "CarpetBlock", + + COAL_BLOCK => "CoalBlock", + + BEETROOT_BLOCK => "BeetrootBlock", + STONECUTTER => "StonecutterBlock", + GLOWING_OBSIDIAN => "GlowingObsidianBlock", + NETHER_REACTOR => "NetherReactorBlock", + INFO_UPDATE => "InfoUpdateBlock", + INFO_UPDATE2 => "InfoUpdate2Block", + RESERVED6 => "Reserved6Block", + ]; public $id; public $meta; public $name; @@ -155,50 +155,50 @@ abstract class Block extends Position{ public $z = 0; public $slipperiness; public static function interact(Level $level, $x, $y, $z, Player $player){} - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){} - + public static function getAABB(Level $level, $x, $y, $z){ return StaticBlock::getAABB(static::$blockID, $x, $y, $z); } - + public static function containsX($id, $v){ return !($v == null) && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; } - + public static function containsY($id, $v){ return !($v == null) && $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; } - + public static function containsZ($id, $v){ return !($v == null) && $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id]; } - + public static function updateShape(Level $level, $x, $y, $z){ - + } - + public static function clip(Level $level, $x, $y, $z, Vector3 $start, Vector3 $end){ static::updateShape($level, $x, $y, $z); $id = $level->level->getBlockID($x, $y, $z); - + $start = $start->subtract($x, $y, $z); $end = $end->subtract($x, $y, $z); - + $v7 = $start->clipX($end, StaticBlock::$minXs[$id]); $v8 = $start->clipX($end, StaticBlock::$maxXs[$id]); $v9 = $start->clipY($end, StaticBlock::$minYs[$id]); $v10 = $start->clipY($end, StaticBlock::$maxYs[$id]); $v11 = $start->clipZ($end, StaticBlock::$minZs[$id]); $v12 = $start->clipZ($end, StaticBlock::$maxZs[$id]); - + if(!self::containsX($id, $v7)) $v7 = null; if(!self::containsX($id, $v8)) $v8 = null; if(!self::containsY($id, $v9)) $v9 = null; if(!self::containsY($id, $v10)) $v10 = null; if(!self::containsZ($id, $v11)) $v11 = null; if(!self::containsZ($id, $v12)) $v12 = null; - + $v13 = null; if($v7 != null && ($v13 == null || $start->distanceSquared($v7) < $start->distanceSquared($v13))) $v13 = $v7; if($v8 != null && ($v13 == null || $start->distanceSquared($v8) < $start->distanceSquared($v13))) $v13 = $v8; @@ -206,9 +206,9 @@ abstract class Block extends Position{ if($v10 != null && ($v13 == null || $start->distanceSquared($v10) < $start->distanceSquared($v13))) $v13 = $v10; if($v11 != null && ($v13 == null || $start->distanceSquared($v11) < $start->distanceSquared($v13))) $v13 = $v11; if($v12 != null && ($v13 == null || $start->distanceSquared($v12) < $start->distanceSquared($v13))) $v13 = $v12; - + if($v13 == null) return null; - + $v14 = -1; if($v13 == $v7) $v14 = 4; if($v13 == $v8) $v14 = 5; @@ -216,10 +216,10 @@ abstract class Block extends Position{ if($v13 == $v10) $v14 = 1; if($v13 == $v11) $v14 = 2; if($v13 == $v12) $v14 = 3; - + return MovingObjectPosition::fromBlock($x, $y, $z, $v14, $v13->add($x, $y, $z)); } - + public static function onPlace(Level $level, $x, $y, $z){} public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){} public static function onRandomTick(Level $level, $x, $y, $z){} @@ -229,8 +229,7 @@ abstract class Block extends Position{ return [static::getAABB($level, $x, $y, $z)]; } public static function onEntityCollidedWithBlock(Level $level, $x, $y, $z, Entity $entity){} - - + public function __construct($id, $meta = 0, $name = "Unknown"){ $this->id = (int) $id; $this->meta = (int) $meta; @@ -240,15 +239,15 @@ abstract class Block extends Position{ $this->slipperiness = 0.6; $this->boundingBox = new AxisAlignedBB($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1); } - + final public function getHardness(){ return ($this->hardness); } - + final public function getName(){ return $this->name; } - + final public function getID(){ return $this->id; } @@ -258,7 +257,7 @@ abstract class Block extends Position{ final public function getMetadata(){ return $this->meta & 0x0F; } - + final public function position(Position $v){ $this->level = $v->level; $this->x = (int) $v->x; @@ -266,24 +265,24 @@ abstract class Block extends Position{ $this->z = (int) $v->z; $this->boundingBox->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1); } - + public function getDrops(Item $item, Player $player){ if(!isset(Block::$class[$this->id])){ //Unknown blocks - return array(); + return []; }else{ - return array( - array($this->id, $this->meta, 1), - ); + return [ + [$this->id, $this->meta, 1], + ]; } } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.15; } return $this->breakTime; } - + public function getSide($side, $step = 1){ $v = parent::getSide($side, $step); if($this->level instanceof Level){ @@ -291,17 +290,17 @@ abstract class Block extends Position{ } return $v; } - + final public function __toString(){ - return "Block ". $this->name ." (".$this->id.":".$this->meta.")"; + return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")"; } - + abstract function isBreakable(Item $item, Player $player); - + abstract function onBreak(Item $item, Player $player); - + abstract function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz); - + abstract function onActivate(Item $item, Player $player); } diff --git a/src/material/Item.php b/src/material/Item.php index b7997318..91aaf975 100755 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -5,12 +5,12 @@ class Item{ const TOOL_PICKAXE = 1; const TOOL_AXE = 2; const TOOL_SHOVEL = 3; - const TOOL_HOE = 4; - + const TOOL_HOE = 4; + const DEF_DAMAGE = 1; - - public static $class = array( - + + public static $class = [ + //armor LEATHER_CAP => "LeatherCapItem", LEATHER_TUNIC => "LeatherTunicItem", @@ -32,7 +32,7 @@ class Item{ GOLDEN_CHESTPLATE => "GoldenChestplateItem", GOLDEN_LEGGINGS => "GoldenLeggingsItem", GOLDEN_BOOTS => "GoldenBootsItem", - + //food APPLE => "AppleItem", MUSHROOM_STEW => "MushroomStewItem", @@ -51,7 +51,7 @@ class Item{ PUMPKIN_PIE => "PumpkinPieItem", BEETROOT => "BeetrootItem", BEETROOT_SOUP => "BeetrootSoupItem", - + //generic ARROW => "ArrowItem", COAL => "CoalItem", @@ -95,7 +95,7 @@ class Item{ QUARTZ => "QuartzItem", CAMERA => "CameraItem", BEETROOT_SEEDS => "BeetrootSeedsItem", - + //tool IRON_SHOVEL => "IronShovelItem", IRON_PICKAXE => "IronPickaxeItem", @@ -127,21 +127,21 @@ class Item{ COMPASS => "CompassItem", CLOCK => "ClockItem", SHEARS => "ShearsItem", - - ); + + ]; public $block; public $id; public $meta; public $count; /** - * @var int + * @var int * Max stack size of the item. Use Item::getMaxStackSize to get stack size for specific item. */ public $maxStackSize = 64; public $durability = 0; public $name; public $isActivable = false; - + public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){ $this->id = (int) $id; $this->meta = (int) $meta; @@ -155,19 +155,19 @@ class Item{ $this->maxStackSize = 1; } } - + public function isPickaxe(){ return false; } - + public function getName(){ return $this->name; } - + public function isPlaceable(){ return (($this->block instanceof Block) and $this->block->isPlaceable === true); } - + public function getBlock(){ if($this->block instanceof Block){ return $this->block; @@ -175,23 +175,23 @@ class Item{ return BlockAPI::get(AIR); } } - + public function getID(){ return $this->id; } - + public function getMetadata(){ return $this->meta; - } - + } + public function isArmor(){ return false; } - + public function getMaxStackSize(){ return $this->maxStackSize; } - + public function getFuelTime(){ if(!isset(FuelData::$duration[$this->id])){ return false; @@ -201,24 +201,24 @@ class Item{ } return false; } - + public function getSmeltItem(){ if(!isset(SmeltingData::$product[$this->id])){ return false; } - + if(isset(SmeltingData::$product[$this->id][0]) and !is_array(SmeltingData::$product[$this->id][0])){ return BlockAPI::getItem(SmeltingData::$product[$this->id][0], SmeltingData::$product[$this->id][1]); } - + if(!isset(SmeltingData::$product[$this->id][$this->meta])){ return false; } - + return BlockAPI::getItem(SmeltingData::$product[$this->id][$this->meta][0], SmeltingData::$product[$this->id][$this->meta][1]); - + } - + public function useOn($object, $force = false){ if($force){ if(($object instanceof Entity) and !$this->isSword()){ @@ -230,16 +230,16 @@ class Item{ } return false; } - + public function isTool(){ return false; } - + public function getMaxDurability(){ if(!$this->isTool() and $this->id !== BOW){ return false; } - + $levels = [ //TODO rewrite(item usage too) 2 => 33, //GOLD 1 => 60, //WOODEN @@ -256,14 +256,14 @@ class Item{ } return $levels[$type]; } - + public function getLevel(){ return false; } - + //TODO remove? public function getPickaxeLevel(){ //Returns false or level of the pickaxe - return match ($this->id) { + return match ($this->id) { WOODEN_PICKAXE => 1, GOLDEN_PICKAXE => 2, STONE_PICKAXE => 3, @@ -272,7 +272,7 @@ class Item{ default => false, }; } - + public function isAxe(){ return false; } @@ -280,11 +280,11 @@ class Item{ public function isSword(){ return false; } - + public function isShovel(){ return false; } - + public function isHoe(){ return false; } @@ -292,23 +292,23 @@ class Item{ public function isShears(){ return ($this->id === SHEARS); } - + public function __toString(){ - return "Item ". $this->name ." (".$this->id.":".$this->meta.")"; + return "Item " . $this->name . " (" . $this->id . ":" . $this->meta . ")"; } - + public function getDamageAgainstOf($e){ return Item::DEF_DAMAGE; } - + public function getDestroySpeed(Block $block, Player $player){ return 1; } - + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ return false; } - + public static function getFoodHeal($id){ return match($id){ APPLE => 4, @@ -328,9 +328,9 @@ class Item{ POTATO => 1, BAKED_POTATO => 6, BEETROOT => 1, - + default => 0 }; } - + } diff --git a/src/material/Material.php b/src/material/Material.php index 674ce90b..0608a472 100644 --- a/src/material/Material.php +++ b/src/material/Material.php @@ -1,4 +1,5 @@ getID()] = $b->isSolid; self::$isTransparent[$b->getID()] = $b->isTransparent; self::$isFlowable[$b->getID()] = $b->isFlowable; @@ -45,7 +45,7 @@ class StaticBlock FireBlock::setFlammabilityAndCatchingChance($b->getID(), 0, 0); self::setBlockBounds($b->getID(), 0, 0, 0, 1, 1, 1); } - + self::setBlockBounds(BED_BLOCK, 0, 0, 0, 1, 0.5625, 1); //Cake: has bounds based on world state //Chest: has bounds based on world state @@ -68,16 +68,16 @@ class StaticBlock self::setBlockBounds(SLAB, 0, 0, 0, 1, 0.5, 1); self::setBlockBounds(RAIL, 0, 0, 0, 1, 0.125, 1); self::setBlockBounds(POWERED_RAIL, 0, 0, 0, 1, 0.125, 1); - + self::setBlockBounds(DANDELION, 0.3, 0.0, 0.3, 0.7, 0.6, 0.7); //extends Bush self::setBlockBounds(ROSE, 0.3, 0.0, 0.3, 0.7, 0.6, 0.7); //extends Bush - + self::setBlockBounds(SUGARCANE_BLOCK, 0.5 - 0.375, 0, 0.5 - 0.375, 0.5 + 0.375, 1, 0.5 + 0.375); self::setBlockBounds(SNOW_LAYER, 0, 0, 0, 1, 0.125, 1); self::setBlockBounds(CARPET, 0, 0, 0, 1, 0, 1); //Stairs: based on different factors //Stone wall: based on state - + //Fire related stuff FireBlock::setFlammabilityAndCatchingChance(PLANKS, 5, 20); FireBlock::setFlammabilityAndCatchingChance(DOUBLE_WOOD_SLAB, 5, 20); @@ -101,29 +101,29 @@ class StaticBlock FireBlock::setFlammabilityAndCatchingChance(HAY_BALE, 60, 20); FireBlock::setFlammabilityAndCatchingChance(SPONGE, 30, 60); } - + public static function setBlockBounds($blockID, $minX, $minY, $minZ, $maxX, $maxY, $maxZ){ self::$maxXs[$blockID] = $maxX; self::$maxYs[$blockID] = $maxY; self::$maxZs[$blockID] = $maxZ; - + self::$minXs[$blockID] = $minX; self::$minYs[$blockID] = $minY; self::$minZs[$blockID] = $minZ; } - + public static function getAABB($id, $x, $y, $z){ return new AxisAlignedBB(self::$minXs[$id] + $x, self::$minYs[$id] + $y, self::$minZs[$id] + $z, self::$maxXs[$id] + $x, self::$maxYs[$id] + $y, self::$maxZs[$id] + $z); //TODO get bb from self::$boundingBoxes ? } - + public static function getBlock($id){ return self::$prealloc[$id] ?? self::$prealloc[0]; //accessing preallocated instances is faster Block::$class[$id] ?? Block::$class[0]; } - + public static function getHardness($id){ - return self::$hardness[$id] ?? StaticBlock::DEFAULT_HARDNESS; + return self::$hardness[$id] ?? StaticBlock::DEFAULT_HARDNESS; } - + //TODO: use static block min/max public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){ /**@var AxisAlignedBB $bb*/ @@ -134,40 +134,39 @@ class StaticBlock $bb = clone $bb; return $bb->setBounds($x + $bb->minX, $y + $bb->minY, $z + $bb->minZ, $x + $bb->maxX, $y + $bb->maxY, $z + $bb->maxZ); } - - + public static function getSlipperiness($id){ return self::$slipperiness[$id] ?? StaticBlock::DEFAULT_SLIPPERINESS; } - + public static function getIsSolid($id){ return self::$isSolid[$id] ?? false; } - + public static function getIsTransparent($id){ return self::$isTransparent[$id] ?? false; } - + public static function getIsFlowable($id){ return self::$isFlowable[$id] ?? false; } - + public static function getIsReplaceable($id){ return self::$isReplaceable[$id] ?? false; } - + public static function getIsPlaceable($id){ return self::$isPlaceable[$id] ?? false; } - + public static function getHasPhysics($id){ - return self::$hasPhysics[$id] ?? false; + return self::$hasPhysics[$id] ?? false; } - + public static function getIsLiquid($id){ return self::$isLiquid[$id] ?? false; } - + public static function getIsFullBlock($id){ return self::$isFullBlock[$id] ?? false; } diff --git a/src/material/block/DoorBlock.php b/src/material/block/DoorBlock.php index abfe20a6..fdfdb0c6 100644 --- a/src/material/block/DoorBlock.php +++ b/src/material/block/DoorBlock.php @@ -86,14 +86,13 @@ class DoorBlock extends TransparentBlock{ } break; } - - + return [$aabb->offset($x, $y, $z)]; } - + public static function getCompositeData(Level $level, $x, $y, $z){ $myMeta = $level->level->getBlockDamage($x, $y, $z); - + if(($myMeta & 8) != 0){ $metaLower = $level->level->getBlockDamage($x, $y - 1, $z); $metaUpper = $myMeta; @@ -101,19 +100,18 @@ class DoorBlock extends TransparentBlock{ $metaLower = $myMeta; $metaUpper = $level->level->getBlockDamage($x, $y + 1, $z); } - + return $metaLower & 7 | (($myMeta & 8) != 0 ? 8 : 0) | (($metaUpper & 1 != 0) ? 16 : 0); } - public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method $level->fastSetBlockUpdate($x, $y, $z, 0, 0); $id = $level->level->getBlockID($x, $y, $z); - - if($id == 64) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(324, 0, 1)); - elseif($id == 71) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(330, 0, 1)); - + + if($id == 64) ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(324, 0, 1)); + elseif($id == 71) ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(330, 0, 1)); + $top = $level->level->getBlockID($x, $y + 1, $z); if($top == IRON_DOOR_BLOCK || $top == DOOR_BLOCK){ $level->fastSetBlockUpdate($x, $y + 1, $z, 0, 0); @@ -121,12 +119,7 @@ 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 @@ -142,12 +135,12 @@ class DoorBlock extends TransparentBlock{ return false; } $direction = $player->entity->getDirection(); - $face = array( + $face = [ 0 => 3, 1 => 4, 2 => 2, 3 => 5, - ); + ]; $next = $this->getSide($face[(($direction + 2) % 4)]); $next2 = $this->getSide($face[$direction]); $metaUp = 0x08; @@ -155,17 +148,15 @@ class DoorBlock extends TransparentBlock{ $metaUp |= 0x01; } $this->level->setBlock($blockUp, BlockAPI::get($this->id, $metaUp), true, false, true); //Top - + $this->meta = $direction & 0x03; $this->level->setBlock($block, $this, true, false, true); //Bottom - return true; + return true; } return false; } /** - * @param Item $item - * @param Player $player * * @return boolean */ @@ -186,8 +177,6 @@ class DoorBlock extends TransparentBlock{ } /** - * @param Item $item - * @param Player $player * * @return boolean */ diff --git a/src/material/block/FallableBlock.php b/src/material/block/FallableBlock.php index ca8113db..32a0051f 100644 --- a/src/material/block/FallableBlock.php +++ b/src/material/block/FallableBlock.php @@ -12,10 +12,6 @@ class FallableBlock extends SolidBlock{ } /** - * @param Item $item - * @param Player $player - * @param Block $block - * @param Block $target * @param int $face * @param int $fx * @param int $fy diff --git a/src/material/block/GenericBlock.php b/src/material/block/GenericBlock.php index e0780dd1..cd707a57 100644 --- a/src/material/block/GenericBlock.php +++ b/src/material/block/GenericBlock.php @@ -1,6 +1,5 @@ level->getBlock($x, $y, $z); $down = $level->level->getBlockID($x, $y - 1, $z); if($down == AIR || StaticBlock::getIsLiquid($down)){ - $data = array( + $data = [ "x" => $x + 0.5, "y" => $y - 0.5, "z" => $z + 0.5, "Tile" => $id, - ); + ]; $server = ServerAPI::request(); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); $e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data); $server->api->entity->spawnToAll($e); } } - + /** - * @param integer $type * * @return boolean */ @@ -86,8 +76,6 @@ class GenericBlock extends Block{ } /** - * @param Item $item - * @param Player $player * * @return boolean */ diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index feafe045..99367580 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -21,14 +21,14 @@ class LiquidBlock extends TransparentBlock{ return match(static::$blockID){ WATER, STILL_WATER => $id == WATER || $id == STILL_WATER ? $meta : -1, LAVA, STILL_LAVA => $id == LAVA || $id == STILL_LAVA ? $meta : -1, - default=> -1 + default => -1 }; } - + public static function onPlace(Level $level, $x, $y, $z){ static::updateLiquid($level, $x, $y, $z); } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ static::updateLiquid($level, $x, $y, $z); } @@ -40,10 +40,10 @@ class LiquidBlock extends TransparentBlock{ $f = ($meta + 1) / 9; return $f; } - + public static function getRenderedDepth(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); - + $cond = match($id){ WATER, STILL_WATER => static::$blockID == WATER || static::$blockID == STILL_WATER, LAVA, STILL_LAVA => static::$blockID == LAVA || static::$blockID == STILL_LAVA, @@ -52,23 +52,23 @@ class LiquidBlock extends TransparentBlock{ if(!$cond) return -1; return $meta >= 8 ? 0 : $meta; } - + public static function shouldRenderFace(Level $level, $x, $y, $z, $face){ $id = $level->level->getBlockID($x, $y, $z); - + if($id == ICE) return false; if((($id == WATER || $id == STILL_WATER) && (static::$blockID == WATER || static::$blockID == STILL_WATER))) return false; if((($id == LAVA || $id == STILL_LAVA) && (static::$blockID == LAVA || static::$blockID == STILL_LAVA))) return false; - + if($face == 1) return true; return StaticBlock::getIsSolid($id); //return parent::shouldRenderFace($level, $x, $y, $z, $face); } - + public static function getFlow(Level $level, $x, $y, $z){ $flowVector = new Vector3(0, 0, 0); $v6 = static::getRenderedDepth($level, $x, $y, $z); - + for($v7 = 0; $v7 < 4; ++$v7){ $v8 = $x; $v10 = $z; @@ -86,12 +86,12 @@ class LiquidBlock extends TransparentBlock{ ++$v10; break; } - + $v11 = static::getRenderedDepth($level, $v8, $y, $v10); if($v11 < 0){ if(!StaticBlock::getIsSolid($level->level->getBlockID($v8, $y, $v10))){ //TODO material.blocksMovement $v11 = static::getRenderedDepth($level, $v8, $y - 1, $v10); - + if($v11 >= 0){ $v12 = $v11 - ($v6 - 8); $flowVector->x += ($v8 - $x) * $v12; @@ -99,29 +99,29 @@ class LiquidBlock extends TransparentBlock{ $flowVector->z += ($v10 - $z) * $v12; } } - }else if($v11 >= 0){ + }elseif($v11 >= 0){ $v12 = $v11 - $v6; $flowVector->x += ($v8 - $x) * $v12; $flowVector->y += ($y - $y) * $v12; $flowVector->z += ($v10 - $z) * $v12; } } - + $meta = $level->level->getBlockDamage($x, $y, $z); - + if($meta >= 8){ $v13 = //TODO more vanilla way to do it static::shouldRenderFace($level, $x, $y, $z - 1, 2) || static::shouldRenderFace($level, $x, $y, $z + 1, 3) || static::shouldRenderFace($level, $x - 1, $y, $z, 4) || static::shouldRenderFace($level, $x + 1, $y, $z, 5) || - + static::shouldRenderFace($level, $x, $y + 1, $z - 1, 2) || static::shouldRenderFace($level, $x, $y + 1, $z + 1, 3) || static::shouldRenderFace($level, $x - 1, $y + 1, $z, 4) || static::shouldRenderFace($level, $x + 1, $y + 1, $z, 5) ; - + if($v13){ $ln = $flowVector->length(); if($ln){ @@ -141,37 +141,37 @@ class LiquidBlock extends TransparentBlock{ }else{ $flowVector->x = $flowVector->y = $flowVector->z = 0; } - + return $flowVector; } - + public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){ $flow = static::getFlow($level, $x, $y, $z); $velocityVector->x += $flow->x * 0.5; $velocityVector->y += $flow->y * 0.5; $velocityVector->z += $flow->z * 0.5; } - + public static function getTickDelay(){ throw new RuntimeException("If you see this, something bad happened"); } - + public static function updateLiquid(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); if($id != LAVA && $id != STILL_LAVA) return; - + $zNeg = $level->level->getBlockID($x, $y, $z - 1); $zPos = $level->level->getBlockID($x, $y, $z + 1); $xNeg = $level->level->getBlockID($x - 1, $y, $z); $xPos = $level->level->getBlockID($x + 1, $y, $z); $yPos = $level->level->getBlockID($x, $y + 1, $z); - + if( $zNeg == WATER || $zNeg == STILL_WATER - || $zPos == WATER || $zPos == STILL_WATER - || $xNeg == WATER || $xNeg == STILL_WATER - || $xPos == WATER || $xPos == STILL_WATER - || $yPos == WATER || $yPos == STILL_WATER + || $zPos == WATER || $zPos == STILL_WATER + || $xNeg == WATER || $xNeg == STILL_WATER + || $xPos == WATER || $xPos == STILL_WATER + || $yPos == WATER || $yPos == STILL_WATER ) { if($meta){ //if($meta > 4) -> fizz & ret @@ -179,17 +179,16 @@ class LiquidBlock extends TransparentBlock{ }else{ $replacement = OBSIDIAN; } - + $level->fastSetBlockUpdate($x, $y, $z, $replacement, true); } } - - + public function getDrops(Item $item, Player $player){ - return array(); + return []; } - + public function getLiquidHeight(){ - return (($this->meta >= 8 ? 0 : $this->meta)+1) / 9; + return (($this->meta >= 8 ? 0 : $this->meta) + 1) / 9; } } \ No newline at end of file diff --git a/src/material/block/SolidBlock.php b/src/material/block/SolidBlock.php index 9fddfcee..8ca26113 100644 --- a/src/material/block/SolidBlock.php +++ b/src/material/block/SolidBlock.php @@ -11,7 +11,7 @@ class SolidBlock extends GenericBlock{ $this->isSolid = true; $this->isFullBlock = true; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; } diff --git a/src/material/block/StairBlock.php b/src/material/block/StairBlock.php index 9af56b50..f5a69373 100644 --- a/src/material/block/StairBlock.php +++ b/src/material/block/StairBlock.php @@ -15,26 +15,26 @@ class StairBlock extends TransparentBlock{ } $this->hardness = 30; } - + public static function isBlocksStairsID($id){ return $id > 0 && StaticBlock::getBlock($id) instanceof StairBlock; } - + public static function isStairsAtXYZAndAreTheirMetadataSame(Level $level, $x, $y, $z, $meta){ $block = $level->level->getBlock($x, $y, $z); return self::isBlocksStairsID($block[0]) && $block[1] == $meta; } - + public static function setBaseShape(Level $level, $x, $y, $z){ $meta = $level->level->getBlockDamage($x, $y, $z); - + if(($meta & 4) != 0){ return new AxisAlignedBB(0, 0.5, 0, 1, 1, 1); }else{ return new AxisAlignedBB(0, 0, 0, 1, 0.5, 1); } } - + const DEAD_SAPCES = [ [2, 6], [3, 7], @@ -45,72 +45,72 @@ class StairBlock extends TransparentBlock{ [0, 1], [4, 5] ]; - + public static function updateShape(Level $level, $x, $y, $z){ if(self::$complexState){ $id = $level->level->getBlockID($x, $y, $z); $cid = self::$complexStateID; - StaticBlock::setBlockBounds($id, + StaticBlock::setBlockBounds($id, 0.5 * ($cid % 2), - 0.5 * ((int)($cid / 2) % 2), - 0.5 * ((int)($cid / 4) % 2), + 0.5 * ((int) ($cid / 2) % 2), + 0.5 * ((int) ($cid / 4) % 2), 0.5 + 0.5 * ($cid % 2), - 0.5 + 0.5 * ((int)($cid / 2) % 2), - 0.5 + 0.5 * ((int)($cid / 4) % 2) + 0.5 + 0.5 * ((int) ($cid / 2) % 2), + 0.5 + 0.5 * ((int) ($cid / 4) % 2) ); }else{ StaticBlock::setBlockBounds($level->level->getBlockID($x, $y, $z), 0, 0, 0, 1, 1, 1); } } - + static $complexState = false; static $complexStateID = 0; public static function clip(Level $level, $x, $y, $z, Vector3 $start, Vector3 $end){ $v7 = []; - + $v8 = $level->level->getBlockDamage($x, $y, $z); $v9 = $v8 & 3; $v10 = ($v8 & 4) == 4; $v11 = self::DEAD_SAPCES[$v9 + ($v10 ? 4 : 0)]; self::$complexState = true; - + for($v12 = 0; $v12 < 8; ++$v12){ self::$complexStateID = $v12; - + for($v15 = 0; $v15 < /*count($v11}*/ 2; ++$v15){ $v16 = $v11[$v15]; if($v16 == $v12){ //wat } } - + $v7[$v12] = parent::clip($level, $x, $y, $z, $start, $end); } - + for($v14 = 0; $v14 < /*count($v11}*/ 2; ++$v14){ $v15 = $v11[$v14]; $v7[$v15] = null; } - + $v24 = 0; $v22 = null; - + for($v17 = 0; $v17 < count($v7); ++$v17){ $v18 = $v7[$v17]; - + if($v18 != null){ $v19 = $v18->hitVector->distanceSquared($end); - + if($v19 > $v24){ $v22 = $v18; $v24 = $v19; } } } - + return $v22; } - + public static function setStepShape(Level $level, $x, $y, $z){ $blockMeta = $level->level->getBlockDamage($x, $y, $z); $metaAnd3 = $blockMeta & 3; @@ -120,13 +120,13 @@ class StairBlock extends TransparentBlock{ $minY = 0.0; $maxY = 0.5; } - + $minX = 0; $maxX = 1; $minZ = 0; $maxZ = 0.5; $v13 = true; - + switch($metaAnd3){ case 0: $minX = 0.5; @@ -134,10 +134,10 @@ class StairBlock extends TransparentBlock{ $blockNearby = $level->level->getBlock($x + 1, $y, $z); $blockIDNearby = $blockNearby[0]; $blockMetaNearby = $blockNearby[1]; - + if(self::isBlocksStairsID($blockIDNearby) && (($blockMeta & 4) == ($blockMetaNearby & 4))){ $blockMetaNearbyAnd3 = $blockMetaNearby & 3; - + if($blockMetaNearbyAnd3 == 3 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x, $y, $z + 1, $blockMeta)){ $maxZ = 0.5; $v13 = false; @@ -153,10 +153,10 @@ class StairBlock extends TransparentBlock{ $blockNearby = $level->level->getBlock($x - 1, $y, $z); $blockIDNearby = $blockNearby[0]; $blockMetaNearby = $blockNearby[1]; - + if(self::isBlocksStairsID($blockIDNearby) && (($blockMeta & 4) == ($blockMetaNearby & 4))){ $blockMetaNearbyAnd3 = $blockMetaNearby & 3; - + if($blockMetaNearbyAnd3 == 3 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x, $y, $z + 1, $blockMeta)){ $maxZ = 0.5; $v13 = false; @@ -172,10 +172,10 @@ class StairBlock extends TransparentBlock{ $blockNearby = $level->level->getBlock($x, $y, $z + 1); $blockIDNearby = $blockNearby[0]; $blockMetaNearby = $blockNearby[1]; - + if(self::isBlocksStairsID($blockIDNearby) && (($blockMeta & 4) == ($blockMetaNearby & 4))){ $blockMetaNearbyAnd3 = $blockMetaNearby & 3; - + if($blockMetaNearbyAnd3 == 1 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x + 1, $y, $z, $blockMeta)){ $maxX = 0.5; $v13 = false; @@ -191,7 +191,7 @@ class StairBlock extends TransparentBlock{ $blockMetaNearby = $blockNearby[1]; if(self::isBlocksStairsID($blockIDNearby) && (($blockMeta & 4) == ($blockMetaNearby & 4))){ $blockMetaNearbyAnd3 = $blockMetaNearby & 3; - + if($blockMetaNearbyAnd3 == 1 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x + 1, $y, $z, $blockMeta)){ $maxX = 0.5; $v13 = false; @@ -203,34 +203,34 @@ class StairBlock extends TransparentBlock{ break; } return [new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ), $v13]; - + } - + public static function setInnerPieceShape(Level $level, $x, $y, $z){ $meta = $level->level->getBlockDamage($x, $y, $z); $metaAnd3 = $meta & 3; $minY = 0.5; $maxY = 1.0; - + if(($meta & 4) != 0){ $minY = 0.0; $maxY = 0.5; } - + $minX = 0.0; $maxX = 0.5; $minZ = 0.5; $maxZ = 1.0; $v13 = false; - + switch($metaAnd3){ case 0: $idNearby = $level->level->getBlockID($x - 1, $y, $z); $metaNearby = $level->level->getBlockDamage($x - 1, $y, $z); - + if(self::isBlocksStairsID($idNearby) && ($meta & 4) == ($metaNearby & 4)){ $metaNearbyAnd3 = $metaNearby & 3; - + if($metaNearbyAnd3 == 3 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x, $y, $z - 1, $meta)){ $minZ = 0; $maxZ = 0.5; @@ -245,7 +245,7 @@ class StairBlock extends TransparentBlock{ case 1: $idNearby = $level->level->getBlockID($x + 1, $y, $z); $metaNearby = $level->level->getBlockDamage($x + 1, $y, $z); - + if(self::isBlocksStairsID($idNearby) && ($meta & 4) == ($metaNearby & 4)){ $minX = 0.5; $maxX = 1.0; @@ -261,17 +261,17 @@ class StairBlock extends TransparentBlock{ $v13 = true; } } - + break; case 2: $idNearby = $level->level->getBlockID($x, $y, $z - 1); $metaNearby = $level->level->getBlockDamage($x, $y, $z - 1); - + if(self::isBlocksStairsID($idNearby) && ($meta & 4) == ($metaNearby & 4)){ $minZ = 0; $maxZ = 0.5; $metaNearbyAnd3 = $metaNearby & 3; - + if($metaNearbyAnd3 == 1 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x - 1, $y, $z, $meta)){ $v13 = true; }elseif($metaNearbyAnd3 == 0 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x + 1, $y, $z, $meta)){ @@ -280,16 +280,16 @@ class StairBlock extends TransparentBlock{ $v13 = true; } } - + break; case 3: - + $idNearby = $level->level->getBlockID($x, $y, $z + 1); $metaNearby = $level->level->getBlockDamage($x, $y, $z + 1); - + if(self::isBlocksStairsID($idNearby) && ($meta & 4) == ($metaNearby & 4)){ $metaNearbyAnd3 = $metaNearby & 3; - + if($metaNearbyAnd3 == 1 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x - 1, $y, $z, $meta)){ $v13 = true; }elseif($metaNearbyAnd3 == 0 && !self::isStairsAtXYZAndAreTheirMetadataSame($level, $x + 1, $y, $z, $meta)){ @@ -300,10 +300,10 @@ class StairBlock extends TransparentBlock{ } break; } - + return [new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ), $v13]; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ $bbs = [self::setBaseShape($level, $x, $y, $z)->offset($x, $y, $z)]; $ret = self::setStepShape($level, $x, $y, $z); @@ -314,15 +314,11 @@ class StairBlock extends TransparentBlock{ $bbs[] = $ret2[0]->offset($x, $y, $z); } } - + return $bbs; } - + /** - * @param Item $item - * @param Player $player - * @param Block $block - * @param Block $target * @param int $face * @param int $fx * @param int $fy @@ -331,12 +327,12 @@ class StairBlock extends TransparentBlock{ * @return bool|mixed */ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $faces = array( + $faces = [ 0 => 0, 1 => 2, 2 => 1, 3 => 3, - ); + ]; $this->meta = $faces[$player->entity->getDirection()] & 0x03; if(($fy > 0.5 and $face !== 1) or $face === 0){ $this->meta |= 0x04; //Upside-down stairs @@ -346,18 +342,16 @@ class StairBlock extends TransparentBlock{ } /** - * @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), - ); + return [ + [$this->id, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/TransparentBlock.php b/src/material/block/TransparentBlock.php index 16b8ffc3..678dbb1f 100644 --- a/src/material/block/TransparentBlock.php +++ b/src/material/block/TransparentBlock.php @@ -13,11 +13,11 @@ class TransparentBlock extends GenericBlock{ $this->isFlowable = false; $this->isTransparent = true; $this->isReplaceable = false; - $this->isPlaceable = true; + $this->isPlaceable = true; $this->isSolid = true; $this->boundingBox->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1); } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return []; } diff --git a/src/material/block/attachable/LadderBlock.php b/src/material/block/attachable/LadderBlock.php index 82ef14b3..571d18d4 100644 --- a/src/material/block/attachable/LadderBlock.php +++ b/src/material/block/attachable/LadderBlock.php @@ -4,7 +4,7 @@ class LadderBlock extends TransparentBlock{ public static $blockID; public static function getAABB(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); - + switch($meta){ case 2: StaticBlock::setBlockBounds($id, 0.0, 0.0, 0.875, 1.0, 1.0, 1.0); @@ -18,9 +18,9 @@ class LadderBlock extends TransparentBlock{ case 5: StaticBlock::setBlockBounds($id, 0, 0.0, 0.0, 0.125, 1.0, 1.0); break; - + } - + return parent::getAABB($level, $x, $y, $z); } public function __construct($meta = 0){ @@ -43,7 +43,7 @@ class LadderBlock extends TransparentBlock{ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $side = $level->level->getBlockDamage($x, $y, $z); - + $attached = match($side){ 3 => $level->level->getBlockID($x, $y, $z - 1), 2 => $level->level->getBlockID($x, $y, $z + 1), @@ -51,7 +51,7 @@ class LadderBlock extends TransparentBlock{ 4 => $level->level->getBlockID($x + 1, $y, $z), default => 0 //TODO }; - + if($attached == AIR){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(LADDER, 0, 1)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); @@ -59,8 +59,8 @@ class LadderBlock extends TransparentBlock{ } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); - } + return [ + [$this->id, 0, 1], + ]; + } } diff --git a/src/material/block/attachable/SignPostBlock.php b/src/material/block/attachable/SignPostBlock.php index a635eccc..ea7e15b2 100644 --- a/src/material/block/attachable/SignPostBlock.php +++ b/src/material/block/attachable/SignPostBlock.php @@ -17,7 +17,7 @@ class SignPostBlock extends TransparentBlock{ $this->isFullBlock = false; $this->hardness = 5; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if(($target->isSolid || $target->getID() === SIGN_POST || $target->getID() === WALL_SIGN) && $face !== 0){ if(!isset(self::$faces[$face])){ @@ -32,7 +32,7 @@ class SignPostBlock extends TransparentBlock{ } return false; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if($level->level->getBlockID($x, $y - 1, $z) === AIR){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SIGN, 0, 1)); @@ -40,15 +40,15 @@ class SignPostBlock extends TransparentBlock{ $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true); } } - + public function onBreak(Item $item, Player $player){ $this->level->setBlock($this, new AirBlock(), true, true, true); return true; } public function getDrops(Item $item, Player $player){ - return array( - array(SIGN, 0, 1), - ); - } + return [ + [SIGN, 0, 1], + ]; + } } \ No newline at end of file diff --git a/src/material/block/attachable/TorchBlock.php b/src/material/block/attachable/TorchBlock.php index 761ba9d7..69c0f5be 100644 --- a/src/material/block/attachable/TorchBlock.php +++ b/src/material/block/attachable/TorchBlock.php @@ -6,15 +6,15 @@ class TorchBlock extends FlowableBlock implements LightingBlock{ parent::__construct(TORCH, $meta, "Torch"); $this->hardness = 0; } - + public function getMaxLightValue(){ return 15; } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $side = $level->level->getBlockDamage($x, $y, $z); $attach = match($side){ @@ -22,9 +22,9 @@ class TorchBlock extends FlowableBlock implements LightingBlock{ 2 => $level->level->getBlockID($x + 1, $y, $z), 3 => $level->level->getBlockID($x, $y, $z - 1), 4 => $level->level->getBlockID($x, $y, $z + 1), - default => $level->level->getBlockID($x, $y - 1, $z) + default => $level->level->getBlockID($x, $y - 1, $z) }; - + if(StaticBlock::getIsTransparent($attach) && !($side === 0 && $attach === FENCE)){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); @@ -33,13 +33,13 @@ class TorchBlock extends FlowableBlock implements LightingBlock{ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->isTransparent === false and $face !== 0){ - $faces = array( + $faces = [ 1 => 5, 2 => 4, 3 => 3, 4 => 2, 5 => 1, - ); + ]; $this->meta = $faces[$face]; $this->level->setBlock($block, $this, true, false, true); return true; @@ -51,8 +51,8 @@ class TorchBlock extends FlowableBlock implements LightingBlock{ return false; } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } } \ No newline at end of file diff --git a/src/material/block/attachable/TrapdoorBlock.php b/src/material/block/attachable/TrapdoorBlock.php index 6e932bde..48d2de84 100644 --- a/src/material/block/attachable/TrapdoorBlock.php +++ b/src/material/block/attachable/TrapdoorBlock.php @@ -17,25 +17,25 @@ class TrapdoorBlock extends TransparentBlock{ $id = $target->getID(); return $id === SLAB || $id === GLOWSTONE || $id === SLAB || $id === WOOD_SLAB || (!$target->isTransparent || $target instanceof StairBlock); } - + public static function isOpen($meta){ return ($meta >> 2) & 1; } - + public static function getAABB(Level $level, $x, $y, $z){ static::updateShape($level, $x, $y, $z); return StaticBlock::getAABB(static::$blockID, $x, $y, $z); } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [static::getAABB($level, $x, $y, $z)]; } - + public static function updateShape(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); - + StaticBlock::setBlockBounds($id, 0.0, 0.0, 0.0, 1.0, 0.1875, 1.0); - + if(static::isOpen($meta)){ $facing = $meta & 3; switch($facing){ @@ -56,24 +56,24 @@ class TrapdoorBlock extends TransparentBlock{ } } } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if(($this->canAttachTo($target)) and $face !== 0 and $face !== 1){ - $faces = array( + $faces = [ 2 => 0, 3 => 1, 4 => 2, 5 => 3, - ); + ]; $this->meta = $faces[$face] & 0x03; $this->level->setBlock($block, $this, true, false, true); return true; } } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $attach = match($level->level->getBlockDamage($x, $y, $z)){ @@ -83,13 +83,13 @@ class TrapdoorBlock extends TransparentBlock{ 3, 7 => $level->level->getBlockID($x - 1, $y, $z), default => 0 }; - + if($attach == AIR){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TRAPDOOR, 0, 1)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } } - + public function onActivate(Item $item, Player $player){ $this->meta ^= 0x04; $this->level->setBlock($this, $this, true, false, true); diff --git a/src/material/block/attachable/WallSignBlock.php b/src/material/block/attachable/WallSignBlock.php index 02ca1aa5..1a61c615 100644 --- a/src/material/block/attachable/WallSignBlock.php +++ b/src/material/block/attachable/WallSignBlock.php @@ -10,7 +10,7 @@ class WallSignBlock extends SignPostBlock{ TransparentBlock::__construct(WALL_SIGN, $meta, "Wall Sign"); $this->isSolid = false; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $attached = match($level->level->getBlockDamage($x, $y, $z)){ 2 => $level->level->getBlockID($x, $y, $z + 1), @@ -19,7 +19,7 @@ class WallSignBlock extends SignPostBlock{ 5 => $level->level->getBlockID($x - 1, $y, $z), default => WALL_SIGN }; - + if(!StaticBlock::getIsSolid($attached) && $attached != SIGN_POST && $attached != WALL_SIGN){ $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true); (ServerAPI::request())->api->entity->drop(new Position($x + 0.5, $y + 0.5, $z + 0.5, $level), BlockAPI::getItem(SIGN, 0, 1)); diff --git a/src/material/block/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index 9329d736..ed80bbf1 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -1,4 +1,5 @@ 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); return $ret; } - + public static function getTickDelay(){ return 30; } - + public function getMaxLightValue(){ return 15; } diff --git a/src/material/block/liquid/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php index c4028f30..5d35973b 100644 --- a/src/material/block/liquid/LiquidBlockDynamic.php +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -4,55 +4,55 @@ class LiquidBlockDynamic extends LiquidBlock{ public function __construct($id, $meta = 0, $name = "Unknown"){ parent::__construct($id, $meta, $name); } - + public static $blockID = 0; public static $sourcesAround = 0; public static $spread = [0, 0, 0, 0]; - + public static function getHighest(Level $level, $x, $y, $z, $highest){ $depth = static::getDepth($level, $x, $y, $z); if($depth < 0) return $highest; if($depth == 0) ++static::$sourcesAround; if($depth >= 8) $depth = 0; - + return $highest >= 0 && $depth >= $highest ? $highest : $depth; } - + public static function setStatic(Level $level, $x, $y, $z){ $meta = $level->level->getBlockDamage($x, $y, $z); - + $level->fastSetBlockUpdate($x, $y, $z, static::$blockID + 1, $meta); } - + public static function isWaterBlocking(Level $level, $x, $y, $z){ $id = $level->level->getBlockID($x, $y, $z); - + if($id == AIR) return false; - + if($id == DOOR_BLOCK || $id == SIGN_POST || $id == WALL_SIGN || $id == LADDER || $id == SUGARCANE_BLOCK) return true; - + if($id == CARPET || $id == SNOW_LAYER || $id == RAIL || $id == POWERED_RAIL) return false; //TODO Tile::getThickness() > 0 - + //TODO materials //if(!StaticBlock::getIsFlowable($id)) return true; return StaticBlock::getIsSolid($id); } - + public static function canSpreadTo(Level $level, $x, $y, $z){ $id = $level->level->getBlockID($x, $y, $z); if($id == LAVA || $id == STILL_LAVA) return false; if((static::$blockID == WATER) && ($id == WATER || $id == STILL_WATER)) return false; - + return static::isWaterBlocking($level, $x, $y, $z) ^ 1; } - + public static function getSpread(Level $level, $x, $y, $z){ for($i = 0; $i < 4; ++$i){ static::$spread[$i] = 1000; $xs = $x; $ys = $y; $zs = $z; - + switch($i){ case 0: --$xs; @@ -67,13 +67,13 @@ class LiquidBlockDynamic extends LiquidBlock{ ++$zs; break; } - + if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue; [$id, $meta] = $level->level->getBlock($xs, $ys, $zs); if(((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && $meta == 0){ continue; } - + if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) static::$spread[$i] = 0; else static::$spread[$i] = static::getSlopeDistance($level, $xs, $ys, $zs, 1, $i); } @@ -85,18 +85,18 @@ class LiquidBlockDynamic extends LiquidBlock{ for($i = 0; $i < 4; ++$i) $ba[$i] = ($i1 == static::$spread[$i]); return $ba; } - + public static function getSlopeDistance(Level $level, $x, $y, $z, $l, $i1){ $j1 = 1000; for($k1 = 0; $k1 < 4; ++$k1){ - if($k1 == 0 && $i1 == 1 || $k1 == 1 && $i1 == 0 || $k1 == 2 && $i1 == 3 || $k1 == 3 && $i1 == 2){ + if($k1 == 0 && $i1 == 1 || $k1 == 1 && $i1 == 0 || $k1 == 2 && $i1 == 3 || $k1 == 3 && $i1 == 2){ continue; } - + $xs = $x; $ys = $y; $zs = $z; - + switch($k1){ case 0: --$xs; @@ -111,10 +111,10 @@ class LiquidBlockDynamic extends LiquidBlock{ ++$zs; break; } - + if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue; [$id, $meta] = $level->level->getBlock($xs, $ys, $zs); - + if( ((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && @@ -122,20 +122,20 @@ class LiquidBlockDynamic extends LiquidBlock{ ){ continue; } - + if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) return $l; - + if($l >= 4) continue; $k2 = static::getSlopeDistance($level, $xs, $ys, $zs, $l + 1, $k1); if($k2 < $j1) $j1 = $k2; } return $j1; } - + public static function trySpreadTo(Level $level, $x, $y, $z, $meta){ if(static::canSpreadTo($level, $x, $y, $z)){ [$id, $meta2] = $level->level->getBlock($x, $y, $z); - + if($id > 0){ if(($id == LAVA || $id == STILL_LAVA) && (static::$blockID == LAVA || static::$blockID == STILL_LAVA)); //fizz else{ @@ -147,23 +147,23 @@ class LiquidBlockDynamic extends LiquidBlock{ } } } - + $level->fastSetBlockUpdate($x, $y, $z, static::$blockID, $meta, true); } } - + public static function onPlace(Level $level, $x, $y, $z){ static::updateLiquid($level, $x, $y, $z); $id = $level->level->getBlockID($x, $y, $z); if($id == static::$blockID) ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, static::getTickDelay()); } - + public static function onUpdate(Level $level, $x, $y, $z, $type){ $id = $level->level->getBlockID($x, $y, $z); $depth = static::getDepth($level, $x, $y, $z); $flowAdd = (static::$blockID == LAVA) ? 2 : 1; $flag = true; - + if($depth > 0){ static::$sourcesAround = 0; $highest = static::getHighest($level, $x - 1, $y, $z, -100); @@ -174,19 +174,19 @@ class LiquidBlockDynamic extends LiquidBlock{ if($j1 >= 8 || $highest < 0) $j1 = -1; $l1 = static::getDepth($level, $x, $y + 1, $z); if($l1 >= 0) $j1 = ($l1 >= 8 ? $l1 : $l1 + 8); - + if(static::$sourcesAround >= 2 && static::$blockID == WATER){ $idBot = $level->level->getBlockID($x, $y - 1, $z); if($idBot > 0){ if(StaticBlock::getIsSolid($idBot) || (($idBot == WATER || $idBot == STILL_WATER) && $level->level->getBlockDamage($x, $y, $z) == 0)) $j1 = 0; } } - + //if(static::$blockID == LAVA && $depth < 8 && $j1 < 8 && $j1 > $depth && mt_rand(0, 4) != 0){ TODO fix later // $j1 = $depth; // $flag = false; //} - + if($j1 != $depth){ $depth = $j1; if($depth < 0) $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); @@ -195,16 +195,16 @@ class LiquidBlockDynamic extends LiquidBlock{ ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, static::getTickDelay()); $level->updateNeighborsAt($x, $y, $z, static::$blockID); //TODO check is needed } - }else if($flag){ + }elseif($flag){ static::setStatic($level, $x, $y, $z); } }else{ static::setStatic($level, $x, $y, $z); } - + if(static::canSpreadTo($level, $x, $y - 1, $z)){ $level->fastSetBlockUpdate($x, $y - 1, $z, static::$blockID, ($depth >= 8 ? $depth : $depth + 8) & 0xf, true); - }else if($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){ + }elseif($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){ $flags = static::getSpread($level, $x, $y, $z); $k1 = $depth >= 8 ? 1 : ($depth + $flowAdd); if($k1 >= 8) return; diff --git a/src/material/block/liquid/LiquidBlockStatic.php b/src/material/block/liquid/LiquidBlockStatic.php index 552c08eb..12265b5d 100644 --- a/src/material/block/liquid/LiquidBlockStatic.php +++ b/src/material/block/liquid/LiquidBlockStatic.php @@ -6,13 +6,13 @@ class LiquidBlockStatic extends LiquidBlock{ } public static $blockID = 0; //TODO: tick: try spread fire if lava - + public static function setDynamic(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); $dynamicID = $id - 1; //very unsafe - $level->fastSetBlockUpdate($x, $y, $z, $dynamicID, $meta); + $level->fastSetBlockUpdate($x, $y, $z, $dynamicID, $meta); } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $oldID = $level->level->getBlockID($x, $y, $z); static::updateLiquid($level, $x, $y, $z); @@ -21,6 +21,5 @@ class LiquidBlockStatic extends LiquidBlock{ static::setDynamic($level, $x, $y, $z); } } - - -} \ No newline at end of file + + } \ No newline at end of file diff --git a/src/material/block/liquid/StillLavaBlock.php b/src/material/block/liquid/StillLavaBlock.php index 2a8e89cf..2ca2daa2 100644 --- a/src/material/block/liquid/StillLavaBlock.php +++ b/src/material/block/liquid/StillLavaBlock.php @@ -1,4 +1,5 @@ hardness = 500; } - + public static function getTickDelay(){ return 30; } - + } \ No newline at end of file diff --git a/src/material/block/liquid/StillWaterBlock.php b/src/material/block/liquid/StillWaterBlock.php index 632177a3..9e79836b 100644 --- a/src/material/block/liquid/StillWaterBlock.php +++ b/src/material/block/liquid/StillWaterBlock.php @@ -1,6 +1,5 @@ hardness = 500; } - + public static function getTickDelay(){ return 5; } diff --git a/src/material/block/liquid/WaterBlock.php b/src/material/block/liquid/WaterBlock.php index c9e5c3e9..3356ca72 100644 --- a/src/material/block/liquid/WaterBlock.php +++ b/src/material/block/liquid/WaterBlock.php @@ -1,19 +1,20 @@ 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); return $ret; } - + public static function getTickDelay(){ return 5; } diff --git a/src/material/block/misc/AirBlock.php b/src/material/block/misc/AirBlock.php index 9d6545b9..defdaf3f 100644 --- a/src/material/block/misc/AirBlock.php +++ b/src/material/block/misc/AirBlock.php @@ -2,7 +2,7 @@ class AirBlock extends TransparentBlock{ public static $blockID; - + public function __construct(){ parent::__construct(AIR, 0, "Air"); $this->isActivable = false; @@ -15,7 +15,7 @@ class AirBlock extends TransparentBlock{ $this->isSolid = false; $this->isFullBlock = true; $this->hardness = 0; - + } - + } \ No newline at end of file diff --git a/src/material/block/misc/BedBlock.php b/src/material/block/misc/BedBlock.php index dcfb3729..db72ca0c 100644 --- a/src/material/block/misc/BedBlock.php +++ b/src/material/block/misc/BedBlock.php @@ -20,37 +20,37 @@ class BedBlock extends TransparentBlock{ $this->isFullBlock = false; $this->hardness = 1; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [static::getAABB($level, $x, $y, $z)]; } public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ - + $meta = $level->level->getBlockDamage($x, $y, $z); $dir = $meta & 3; $isHead = ($meta >> 3) & 1; - + $offX = self::HEAD_DIRECTION_OFFSETS[$dir][0]; $offZ = self::HEAD_DIRECTION_OFFSETS[$dir][1]; - + if($isHead){ if($level->level->getBlockID($x - $offX, $y, $z - $offZ) != BED_BLOCK){ $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } - }else if($level->level->getBlockID($x + $offX, $y, $z + $offZ) != BED_BLOCK){ + }elseif($level->level->getBlockID($x + $offX, $y, $z + $offZ) != BED_BLOCK){ $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - + ServerAPI::request()->api->entity->dropRawPos( - $level, - $x + (lcg_value() * 0.7) + 0.15, - $y + (lcg_value() * 0.7) + 0.15, - $z + (lcg_value() * 0.7) + 0.15, - BlockAPI::getItem(BED, 0, 1), + $level, + $x + (lcg_value() * 0.7) + 0.15, + $y + (lcg_value() * 0.7) + 0.15, + $z + (lcg_value() * 0.7) + 0.15, + BlockAPI::getItem(BED, 0, 1), lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1 ); - + } - + } public static function findStandUpPosition(Level $level, $x, $y, $z){ $blockMeta = $level->level->getBlockDamage($x, $y, $z); @@ -60,7 +60,7 @@ class BedBlock extends TransparentBlock{ $minZ = $z - self::HEAD_DIRECTION_OFFSETS[$direction][1] * $v7 - 1; $maxX = $minX + 2; $maxZ = $minZ + 2; - + for($xCheck = $minX; $xCheck <= $maxX; ++$xCheck){ for($zCheck = $minZ; $zCheck <= $maxZ; ++$zCheck){ $idCheck = $level->level->getBlockID($xCheck, $y - 1, $zCheck); @@ -70,10 +70,10 @@ class BedBlock extends TransparentBlock{ } } } - + return null; } - + public function onActivate(Item $item, Player $player){ if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){ $pk = new ChatPacket; @@ -81,12 +81,12 @@ class BedBlock extends TransparentBlock{ $player->dataPacket($pk); return true; } - + $blockNorth = $this->getSide(2); //Gets the blocks around them $blockSouth = $this->getSide(3); $blockEast = $this->getSide(5); $blockWest = $this->getSide(4); - if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed + if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed $b = $this; }else{ //Bottom Part of Bed if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ @@ -112,11 +112,11 @@ class BedBlock extends TransparentBlock{ } return true; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->isTransparent === false){ - + $d = $player->entity->getDirection(); $next = $this->getSide(self::$faces[(($d + 3) % 4)]); $downNext = $next->getSide(0); @@ -128,15 +128,15 @@ class BedBlock extends TransparentBlock{ } } return false; - } - + } + public function onBreak(Item $item, Player $player){ $blockNorth = $this->getSide(2); //Gets the blocks around them $blockSouth = $this->getSide(3); $blockEast = $this->getSide(5); $blockWest = $this->getSide(4); - - if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed + + if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed switch($this->meta & 0x7){ case 0: if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), true, false, true); @@ -170,11 +170,11 @@ class BedBlock extends TransparentBlock{ $this->level->setBlock($this, new AirBlock(), true, false, true); return true; } - + public function getDrops(Item $item, Player $player){ - return array( - array(BED, 0, 1), - ); + return [ + [BED, 0, 1], + ]; } - + } \ No newline at end of file diff --git a/src/material/block/misc/FireBlock.php b/src/material/block/misc/FireBlock.php index 8e3b9365..778f1f29 100644 --- a/src/material/block/misc/FireBlock.php +++ b/src/material/block/misc/FireBlock.php @@ -4,7 +4,7 @@ class FireBlock extends FlowableBlock implements LightingBlock{ public static $blockID; public static $flammability = []; public static $fireCatchingChance = []; - + public function __construct($meta = 0){ parent::__construct(FIRE, $meta, "Fire"); $this->isReplaceable = true; @@ -19,39 +19,39 @@ class FireBlock extends FlowableBlock implements LightingBlock{ self::$flammability[$blockID] = $flammability; self::$fireCatchingChance[$blockID] = $v; } - + public static function canBurn(Level $level, $x, $y, $z){ return self::$flammability[$level->level->getBlockID($x, $y, $z)] > 0; } - + public static function onRandomTick(Level $level, $x, $y, $z){ if($level->level->getBlockID($x, $y - 1, $z) !== NETHERRACK){ $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } } - + public static function onPlace(Level $level, $x, $y, $z){ ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, 30); } - + public function getDrops(Item $item, Player $player){ - return array(); + return []; } public function getMaxLightValue(){ return 15; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $b = $level->level->getBlockID($x, $y - 1, $z); if(!StaticBlock::getIsSolid($b)) $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); //TODO more vanilla later? } - + public static function onUpdate(Level $level, $x, $y, $z, $type){ if($type === BLOCK_UPDATE_SCHEDULED){ $idBelow = $level->level->getBlockID($x, $y - 1, $z); [$id, $meta] = $level->level->getBlock($x, $y, $z); $alwaysBurn = $idBelow == NETHERRACK; - + if($meta < 15){ $newMeta = $meta + 1; //TODO better formula if($newMeta > 15) $newMeta = 15; @@ -65,20 +65,19 @@ class FireBlock extends FlowableBlock implements LightingBlock{ } } $chance = self::$fireCatchingChance[$idBelow]; - + if(mt_rand(0, 249) < $chance){ //TODO ignite tnt $level->fastSetBlockUpdate($x, $y - 1, $z, 0, 0, true); goto REMOVE_FIRE; } - + ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, 30); //TODO looks like it also adds mt_rand(0, 9) to it } } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ parent::place($item, $player, $block, $target, $face, $fx, $fy, $fz); $this->level->scheduleBlockUpdate($this, 30, BLOCK_UPDATE_SCHEDULED); - - + } } \ No newline at end of file diff --git a/src/material/block/misc/NetherReactorBlock.php b/src/material/block/misc/NetherReactorBlock.php index 8c1ff0d0..52d79589 100644 --- a/src/material/block/misc/NetherReactorBlock.php +++ b/src/material/block/misc/NetherReactorBlock.php @@ -7,7 +7,7 @@ class NetherReactorBlock extends SolidBlock{ parent::__construct(NETHER_REACTOR, $meta, "Nether Reactor"); $this->isActivable = true; } - + public function onActivate(Item $item, Player $player){ //if(($item->getID() === IRON_SWORD || $item->getID() === WOODEN_SWORD || $item->getID() === STONE_SWORD || $item->getID() === DIAMOND_SWORD || $item->getID() === GOLD_SWORD) /*&& $player->gamemode === 0*/){ if($this->getMetadata() === 0 && $this->isCorrect($this->getX(),$this->getY(),$this->getZ()) && $this->getY() < 101 && NetherReactorBlock::$enableReactor){ @@ -15,58 +15,58 @@ class NetherReactorBlock extends SolidBlock{ $this->meta = 1; $this->level->setBlock($this,$this); $server = ServerAPI::request(); - $server->schedule(40, array($this, "glow"), 1); - $server->schedule(60, array($this, "glow"), 2); - $server->schedule(80, array($this, "glow"), 3); - $server->schedule(140, array($this, "glow"), 4); - $server->schedule(200, array($this, "spawnItems"), [0,15,2,true]); //200 - $server->schedule(260, array($this, "spawnItems"), [0,15,"checkPigmen",true]); - $server->schedule(300, array($this, "spawnItems"), [0,15,"checkPigmen",true]); - $server->schedule(340, array($this, "spawnItems"), [11,20,"checkPigmen",false]); - $server->schedule(400, array($this, "spawnItems"), [0,10,"checkPigmen",false]); - $server->schedule(500, array($this, "spawnItems"), [17,32, "checkPigmen",false]); //500 - $server->schedule(580, array($this, "spawnItems"), [17,32, "checkPigmen",false]); - $server->schedule(620, array($this, "spawnItems"), [1,32, "checkPigmen",false]); - $server->schedule(660, array($this, "spawnItems"), [1,32,"checkPigmen",false]); - $server->schedule(700, array($this, "spawnItems"), [1,32,"checkPigmen",false]); - $server->schedule(860, array($this, "glow"), 5); - $server->schedule(880, array($this, "glow"), 6); - $server->schedule(900, array($this, "glow"), 7); - $server->schedule(920, array($this, "destroy")); + $server->schedule(40, [$this, "glow"], 1); + $server->schedule(60, [$this, "glow"], 2); + $server->schedule(80, [$this, "glow"], 3); + $server->schedule(140, [$this, "glow"], 4); + $server->schedule(200, [$this, "spawnItems"], [0,15,2,true]); //200 + $server->schedule(260, [$this, "spawnItems"], [0,15,"checkPigmen",true]); + $server->schedule(300, [$this, "spawnItems"], [0,15,"checkPigmen",true]); + $server->schedule(340, [$this, "spawnItems"], [11,20,"checkPigmen",false]); + $server->schedule(400, [$this, "spawnItems"], [0,10,"checkPigmen",false]); + $server->schedule(500, [$this, "spawnItems"], [17,32, "checkPigmen",false]); //500 + $server->schedule(580, [$this, "spawnItems"], [17,32, "checkPigmen",false]); + $server->schedule(620, [$this, "spawnItems"], [1,32, "checkPigmen",false]); + $server->schedule(660, [$this, "spawnItems"], [1,32,"checkPigmen",false]); + $server->schedule(700, [$this, "spawnItems"], [1,32,"checkPigmen",false]); + $server->schedule(860, [$this, "glow"], 5); + $server->schedule(880, [$this, "glow"], 6); + $server->schedule(900, [$this, "glow"], 7); + $server->schedule(920, [$this, "destroy"]); return true; } //} - + } - + public function destroy(){ $this->level->setBlock(new Vector3($this->x, $this->y, $this->z),new NetherReactorBlock(2)); - $this->decay($this->x-8, $this->y-3, $this->z-8, 0, 17, 16, 2, 34, 1, 0, 17, 1); - $this->decay($this->x-8, $this->y-3, $this->z-8, 1, 16, 1, 2, 34, 1, 0, 17, 16); - $this->decay($this->x-8, $this->y-3, $this->z-8, 3, 14, 10, 8, 34, 1, 3, 14, 1); - $this->decay($this->x-8, $this->y-3, $this->z-8, 4, 13, 1, 8, 34, 1, 3, 14, 10); - $this->decay($this->x-8, $this->y-3, $this->z-8, 5, 12, 6, 14, 34, 1, 5, 12, 1); - $this->decay($this->x-8, $this->y-3, $this->z-8, 6, 11, 1, 14, 34, 1, 5, 12, 16); + $this->decay($this->x - 8, $this->y - 3, $this->z - 8, 0, 17, 16, 2, 34, 1, 0, 17, 1); + $this->decay($this->x - 8, $this->y - 3, $this->z - 8, 1, 16, 1, 2, 34, 1, 0, 17, 16); + $this->decay($this->x - 8, $this->y - 3, $this->z - 8, 3, 14, 10, 8, 34, 1, 3, 14, 1); + $this->decay($this->x - 8, $this->y - 3, $this->z - 8, 4, 13, 1, 8, 34, 1, 3, 14, 10); + $this->decay($this->x - 8, $this->y - 3, $this->z - 8, 5, 12, 6, 14, 34, 1, 5, 12, 1); + $this->decay($this->x - 8, $this->y - 3, $this->z - 8, 6, 11, 1, 14, 34, 1, 5, 12, 16); } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ return [[NETHER_REACTOR, 0, 1]]; } } - + private function decay($x, $y, $z, $aOne, $aTwo, $aThree, $bOne, $bTwo, $bThree, $cOne, $cTwo, $cThree) { for($a = $aOne; $a < $aTwo; $a += $aThree) { for($b = $bOne; $b < $bTwo; $b += $bThree) { for($c = $cOne; $c < $cTwo; $c += $cThree) { - if ($this->level->level->getBlockID($x+$a, $y+$b, $z+$c) === NETHERRACK && lcg_value() > 0.75){ - $this->level->fastSetBlockUpdate($x+$a, $y+$b, $z+$c, 0, 0); + if ($this->level->level->getBlockID($x + $a, $y + $b, $z + $c) === NETHERRACK && lcg_value() > 0.75){ + $this->level->fastSetBlockUpdate($x + $a, $y + $b, $z + $c, 0, 0); } } } } } - + private function pigmenCheck($x,$y,$z) { $pigCount = 0; $server = ServerAPI::request(); @@ -88,28 +88,28 @@ class NetherReactorBlock extends SolidBlock{ $forceAmount = $data[3]; $server = ServerAPI::request(); if(!$forceAmount){ - $spawnNumber = $minAmount + floor(lcg_value()*($maxAmount-$minAmount+1)); + $spawnNumber = $minAmount + floor(lcg_value() * ($maxAmount - $minAmount + 1)); } else{ $spawnNumber = $maxAmount; } for($i = 0; $i < $spawnNumber; $i++) { - $randomRange = floor(lcg_value()*5+3); - $shiftX = cos(floor(lcg_value()*360)*(pi()/180)); - $shiftZ = sin(floor(lcg_value()*360)*(pi()/180)); + $randomRange = floor(lcg_value() * 5 + 3); + $shiftX = cos(floor(lcg_value() * 360) * (pi() / 180)); + $shiftZ = sin(floor(lcg_value() * 360) * (pi() / 180)); if(Utils::chance(5)) $randomID = $this->rarePossibleLoot[array_rand($this->rarePossibleLoot)]; else $randomID = $this->possibleLoot[array_rand($this->possibleLoot)]; - $server->api->entity->drop(new Position($x+($shiftX*$randomRange)+0.5, $y, $z+($shiftZ*$randomRange)+0.5, $this->level), BlockAPI::getItem($randomID, 0, 1)); + $server->api->entity->drop(new Position($x + ($shiftX * $randomRange) + 0.5, $y, $z + ($shiftZ * $randomRange) + 0.5, $this->level), BlockAPI::getItem($randomID, 0, 1)); } for($i = 0; $i < $pigmen; $i++) { - $randomRange = floor(lcg_value()*5+3); - $shiftX = cos(floor(lcg_value()*360)*(pi()/180)); - $shiftZ = sin(floor(lcg_value()*360)*(pi()/180)); - $data = array( - "x" => $x+($shiftX*$randomRange)+0.5, - "y" => $y, - "z" => $z+($shiftZ*$randomRange)+0.5, - ); + $randomRange = floor(lcg_value() * 5 + 3); + $shiftX = cos(floor(lcg_value() * 360) * (pi() / 180)); + $shiftZ = sin(floor(lcg_value() * 360) * (pi() / 180)); + $data = [ + "x" => $x + ($shiftX * $randomRange) + 0.5, + "y" => $y, + "z" => $z + ($shiftZ * $randomRange) + 0.5, + ]; $e = $server->api->entity->add($this->level, ENTITY_MOB, MOB_PIGMAN, $data); $server->api->entity->spawnToAll($e); } @@ -120,63 +120,63 @@ class NetherReactorBlock extends SolidBlock{ $z = $this->z; switch($part){ case 1: - $this->level->setBlock(new Vector3($x, $y-1, $z),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y-1, $z),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y-1, $z),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x, $y-1, $z+1),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x, $y-1, $z-1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y - 1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y - 1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y - 1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y - 1, $z + 1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y - 1, $z - 1),new GlowingObsidianBlock); break; case 2: - $this->level->setBlock(new Vector3($x+1, $y, $z+1),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y, $z-1),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y, $z+1),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y, $z-1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y, $z + 1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y, $z - 1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y, $z + 1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y, $z - 1),new GlowingObsidianBlock); break; case 3: - $this->level->setBlock(new Vector3($x, $y+1, $z),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y+1, $z),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y+1, $z),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x, $y+1, $z+1),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x, $y+1, $z-1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y + 1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y + 1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y + 1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y + 1, $z + 1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y + 1, $z - 1),new GlowingObsidianBlock); break; case 4: - $this->level->setBlock(new Vector3($x+1, $y-1, $z+1),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y-1, $z-1),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y-1, $z+1),new GlowingObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y-1, $z-1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y - 1, $z + 1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y - 1, $z - 1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y - 1, $z + 1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y - 1, $z - 1),new GlowingObsidianBlock); break; case 5: - $this->level->setBlock(new Vector3($x, $y+1, $z),new ObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y+1, $z),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y+1, $z),new ObsidianBlock); - $this->level->setBlock(new Vector3($x, $y+1, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x, $y+1, $z-1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y+1, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y+1, $z-1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y+1, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y+1, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y + 1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y + 1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y + 1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y + 1, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y + 1, $z - 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y + 1, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y + 1, $z - 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y + 1, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y + 1, $z - 1),new ObsidianBlock); break; case 6: $this->level->setBlock(new Vector3($x, $y, $z), new NetherReactorBlock(2)); - $this->level->setBlock(new Vector3($x+1, $y, $z),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y, $z),new ObsidianBlock); - $this->level->setBlock(new Vector3($x, $y, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x, $y, $z-1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y, $z-1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y, $z - 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y, $z - 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y, $z - 1),new ObsidianBlock); break; case 7: - $this->level->setBlock(new Vector3($x, $y-1, $z),new ObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y-1, $z),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y-1, $z),new ObsidianBlock); - $this->level->setBlock(new Vector3($x, $y-1, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x, $y-1, $z-1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y-1, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x+1, $y-1, $z-1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y-1, $z+1),new ObsidianBlock); - $this->level->setBlock(new Vector3($x-1, $y-1, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y - 1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y - 1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y - 1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y - 1, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y - 1, $z - 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y - 1, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x + 1, $y - 1, $z - 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y - 1, $z + 1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x - 1, $y - 1, $z - 1),new ObsidianBlock); break; } } @@ -218,18 +218,18 @@ class NetherReactorBlock extends SolidBlock{ } return true; } - + private $possibleLoot = [ GLOWSTONE_DUST, QUARTZ, CACTUS, SUGARCANE, BROWN_MUSHROOM, RED_MUSHROOM, PUMPKIN_SEEDS, MELON_SEEDS ]; - + private $rarePossibleLoot = [ BOW, BED, BOWL, ARROW, WOODEN_DOOR, FEATHER, PAINTING, BONE, DANDELION ]; - + private $core = [ -1 => ["GCG", "CCC", "GCG"], 0 => ["C C", " R ", "C C",], - 1 =>[" C ", "CCC", " C "] + 1 => [" C ", "CCC", " C "] ]; } diff --git a/src/material/block/misc/TNTBlock.php b/src/material/block/misc/TNTBlock.php index aeef0412..80018057 100644 --- a/src/material/block/misc/TNTBlock.php +++ b/src/material/block/misc/TNTBlock.php @@ -7,19 +7,19 @@ class TNTBlock extends SolidBlock{ $this->hardness = 0; $this->isActivable = true; } - + public function onActivate(Item $item, Player $player){ if($item->getID() === FLINT_STEEL){ if(($player->gamemode & 0x01) === 0){ $item->useOn($this); } - $data = array( + $data = [ "x" => $this->x + 0.5, "y" => $this->y, "z" => $this->z + 0.5, "power" => 3, "fuse" => 20 * 4, //4 seconds - ); + ]; $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, 0, 0, true); $e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); ServerAPI::request()->api->entity->spawnToAll($e); diff --git a/src/material/block/nonfull/CakeBlock.php b/src/material/block/nonfull/CakeBlock.php index f7eded78..fc9740e9 100644 --- a/src/material/block/nonfull/CakeBlock.php +++ b/src/material/block/nonfull/CakeBlock.php @@ -9,18 +9,18 @@ class CakeBlock extends TransparentBlock{ $this->meta = $meta & 0x07; $this->hardness = 2.5; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ $data = $level->level->getBlockDamage($x, $y, $z); - return [new AxisAlignedBB($x + (2*$data + 1) * 0.0625, $y, $z + 0.0625, $x + 0.9375, $y + 0.5, $z + 0.9375)]; + return [new AxisAlignedBB($x + (2 * $data + 1) * 0.0625, $y, $z + 0.0625, $x + 0.9375, $y + 0.5, $z + 0.9375)]; } - + public static function updateShape(Level $level, $x, $y, $z){ [$id, $data] = $level->level->getBlock($x, $y, $z); - + StaticBlock::setBlockBounds($id, (2 * $data + 1) * 0.0625, 0.0, 0.0625, 0.9375, 0.5, 0.9375); } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() !== AIR){ @@ -29,17 +29,17 @@ class CakeBlock extends TransparentBlock{ } return false; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } } - + public function getDrops(Item $item, Player $player){ - return array(); + return []; } - + public function onActivate(Item $item, Player $player){ if($player->entity->getHealth() < 20){ ++$this->meta; @@ -53,5 +53,5 @@ class CakeBlock extends TransparentBlock{ } return false; } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/CarpetBlock.php b/src/material/block/nonfull/CarpetBlock.php index 60b93a98..bfe18df4 100644 --- a/src/material/block/nonfull/CarpetBlock.php +++ b/src/material/block/nonfull/CarpetBlock.php @@ -4,7 +4,7 @@ class CarpetBlock extends FlowableBlock{ public static $blockID; public function __construct($meta = 0){ parent::__construct(CARPET, $meta, "Carpet"); - $names = array( + $names = [ 0 => "White Carpet", 1 => "Orange Carpet", 2 => "Magenta Carpet", @@ -21,10 +21,10 @@ class CarpetBlock extends FlowableBlock{ 13 => "Green Carpet", 14 => "Red Carpet", 15 => "Black Carpet", - ); + ]; $this->name = $names[$this->meta]; $this->hardness = 0; - $this->isFullBlock = false; + $this->isFullBlock = false; $this->isSolid = true; } public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ diff --git a/src/material/block/nonfull/ChestBlock.php b/src/material/block/nonfull/ChestBlock.php index 344daff4..b3a3422d 100644 --- a/src/material/block/nonfull/ChestBlock.php +++ b/src/material/block/nonfull/ChestBlock.php @@ -11,19 +11,19 @@ class ChestBlock extends TransparentBlock{ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x + 0.025, $y, $z + 0.025, $x + 0.975, $y + 0.95, $z + 0.975)]; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $server = ServerAPI::request(); - $faces = array( + $faces = [ 0 => 4, 1 => 2, 2 => 5, 3 => 3, - ); + ]; $chest = false; $this->meta = $faces[$player->entity->getDirection()]; - + for($side = 2; $side <= 5; ++$side){ if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){ continue; @@ -40,22 +40,22 @@ class ChestBlock extends TransparentBlock{ } $this->level->setBlock($block, $this, true, false, true); - $tile = $server->api->tile->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array( - "Items" => array(), + $tile = $server->api->tile->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, [ + "Items" => [], "id" => TILE_CHEST, "x" => $this->x, "y" => $this->y, "z" => $this->z - )); + ]); $server->api->tile->spawnToAll($tile); - + if($chest instanceof Tile){ $chest->pairWith($tile); $tile->pairWith($chest); } return true; } - + public function onBreak(Item $item, Player $player){ $t = ServerAPI::request()->api->tile->get($this); if($t !== false){ @@ -64,48 +64,46 @@ class ChestBlock extends TransparentBlock{ $this->level->setBlock($this, new AirBlock(), true, true, true); return true; } - + public function onActivate(Item $item, Player $player){ $top = $this->getSide(1); if($top->isTransparent !== true){ return true; } - + $server = ServerAPI::request(); $t = $server->api->tile->get($this); $chest = false; if($t !== false){ $chest = $t; }else{ - $chest = $server->api->tile->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, array( - "Items" => array(), + $chest = $server->api->tile->add($this->level, TILE_CHEST, $this->x, $this->y, $this->z, [ + "Items" => [], "id" => TILE_CHEST, "x" => $this->x, "y" => $this->y, - "z" => $this->z - )); + "z" => $this->z + ]); } - - - + if(($player->gamemode & 0x01) === 0x01){ return true; } - - $chest->openInventory($player); + + $chest->openInventory($player); return true; } public function getDrops(Item $item, Player $player){ - $drops = array( - array($this->id, 0, 1), - ); + $drops = [ + [$this->id, 0, 1], + ]; $t = ServerAPI::request()->api->tile->get($this); if($t !== false and $t->class === TILE_CHEST){ for($s = 0; $s < CHEST_SLOTS; ++$s){ $slot = $t->getSlot($s); if($slot->getID() > AIR and $slot->count > 0){ - $drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count); + $drops[] = [$slot->getID(), $slot->getMetadata(), $slot->count]; } } } diff --git a/src/material/block/nonfull/CobwebBlock.php b/src/material/block/nonfull/CobwebBlock.php index 4b6a9226..558dbd69 100644 --- a/src/material/block/nonfull/CobwebBlock.php +++ b/src/material/block/nonfull/CobwebBlock.php @@ -3,16 +3,16 @@ class CobwebBlock extends FlowableBlock{ public static $blockID; public function __construct(){ - parent::__construct(COBWEB, 0, "Cobweb"); + parent::__construct(COBWEB, 0, "Cobweb"); $this->isSolid = true; $this->isFullBlock = false; $this->hardness = 25; } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } - + public function getDrops(Item $item, Player $player){ if ($item->isSword()){ return [ @@ -21,11 +21,11 @@ class CobwebBlock extends FlowableBlock{ } elseif ($item->isShears()){ return [ - array(COBWEB, 0, 1), + [COBWEB, 0, 1], ]; } } - + public static function onEntityCollidedWithBlock(Level $level, $x, $y, $z, Entity $entity){ $entity->setInWeb(); } diff --git a/src/material/block/nonfull/FarmlandBlock.php b/src/material/block/nonfull/FarmlandBlock.php index 580f78d3..dac2bdf6 100644 --- a/src/material/block/nonfull/FarmlandBlock.php +++ b/src/material/block/nonfull/FarmlandBlock.php @@ -7,27 +7,27 @@ class FarmlandBlock extends TransparentBlock{ $this->hardness = 3; } public function getDrops(Item $item, Player $player){ - return array( - array(DIRT, 0, 1), - ); + return [ + [DIRT, 0, 1], + ]; } public function hasCrops(){ //TODO vanilla 0.8.1 detection method $b = $this->getSide(1); return $b->isTransparent && $b->id != 0; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; } - + public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){ $rv = lcg_value(); if($rv < ($fallDistance - 0.5)){ $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0); } } - + public static function onRandomTick(Level $level, $x, $y, $z){ $meta = $level->level->getBlockDamage($x, $y, $z); $b = $level->level->getBlockID($x, $y + 1, $z); @@ -41,8 +41,7 @@ class FarmlandBlock extends TransparentBlock{ $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true); } } - - + } public static function checkWaterStatic(Level $level, $x, $y, $z) @@ -58,7 +57,7 @@ class FarmlandBlock extends TransparentBlock{ } } } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z))){ $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true); diff --git a/src/material/block/nonfull/FenceBlock.php b/src/material/block/nonfull/FenceBlock.php index 98442208..47b17932 100644 --- a/src/material/block/nonfull/FenceBlock.php +++ b/src/material/block/nonfull/FenceBlock.php @@ -7,16 +7,16 @@ class FenceBlock extends TransparentBlock{ $this->isFullBlock = false; $this->hardness = 15; } - + public static function canConnectTo(Level $level, $x, $y, $z){ $id = $level->level->getBlockID($x, $y, $z); - + if($id != FENCE && $id != FENCE_GATE){ return StaticBlock::getIsSolid($id) && $id != PUMPKIN; //TODO check var6 != null && var6.blockMaterial.isOpaque() && var6.renderAsNormalBlock() ? var6.blockMaterial != Material.pumpkin : false; } return true; } - + public static function getAABB(Level $level, $x, $y, $z){ $v9 = self::canConnectTo($level, $x, $y, $z - 1); $v10 = self::canConnectTo($level, $x, $y, $z + 1); @@ -29,7 +29,7 @@ class FenceBlock extends TransparentBlock{ StaticBlock::setBlockBounds(static::$blockID, $minX, 0, $minZ, $maxX, 1.5, $maxZ); return parent::getAABB($level, $x, $y, $z); } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ $v8 = self::canConnectTo($level, $x, $y, $z - 1); $v9 = self::canConnectTo($level, $x, $y, $z + 1); @@ -47,11 +47,11 @@ class FenceBlock extends TransparentBlock{ $v15 = 0.625; if($v10) $v12 = 0; if($v11) $v13 = 1; - + if($v10 || $v11 || !$v8 && !$v9){ $arr[] = new AxisAlignedBB($x + $v12, $y + 0, $z + $v14, $x + $v13, $y + 1.5, $z + $v15); } return $arr; } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/FenceGateBlock.php b/src/material/block/nonfull/FenceGateBlock.php index be286bf9..0de9a354 100644 --- a/src/material/block/nonfull/FenceGateBlock.php +++ b/src/material/block/nonfull/FenceGateBlock.php @@ -7,21 +7,21 @@ class FenceGateBlock extends TransparentBlock{ if($aabb == null) return []; return [$aabb]; } - + public static function getAABB(Level $level, $x, $y, $z){ $data = $level->level->getBlockDamage($x, $y, $z); - + if($data & 4){ return null; } - + if($data != 2 && $data != 0){ return new AxisAlignedBB($x + 0.375, $y, $z, $x + 0.625, $y + 1.5, $z + 1.0); }else{ return new AxisAlignedBB($x, $y, $z + 0.375, $x + 1, $y + 1.5, $z + 0.625); } } - + public function __construct($meta = 0){ parent::__construct(FENCE_GATE, $meta, "Fence Gate"); $this->isActivable = true; @@ -33,29 +33,29 @@ class FenceGateBlock extends TransparentBlock{ $this->hardness = 15; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $faces = array( + $faces = [ 0 => 3, 1 => 0, 2 => 1, 3 => 2, - ); + ]; $this->meta = $faces[$player->entity->getDirection()] & 0x03; $this->level->setBlock($block, $this, true, false, true); return true; } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } public function onActivate(Item $item, Player $player){ - + $meta = $this->meta; if(($meta & 4) != 0){ $meta ^= 4; }else{ $direction = ($player->entity->yaw * 4 / 360) + 0.5; - $blockDirection = (int)$direction; + $blockDirection = (int) $direction; if($direction < $blockDirection) --$blockDirection; $blockDirection &= 3; if(($meta & 3) == (($blockDirection + 2) & 3)){ @@ -63,7 +63,7 @@ class FenceGateBlock extends TransparentBlock{ } $meta |= 4; } - + $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->id, $meta); $players = $this->level->players; unset($players[$player->CID]); diff --git a/src/material/block/nonfull/GlassPaneBlock.php b/src/material/block/nonfull/GlassPaneBlock.php index 0af71ac4..959cdd22 100644 --- a/src/material/block/nonfull/GlassPaneBlock.php +++ b/src/material/block/nonfull/GlassPaneBlock.php @@ -9,33 +9,33 @@ class GlassPaneBlock extends TransparentBlock{ } public static function updateShape(Level $level, $x, $y, $z){ $id = $level->level->getBlockID($x, $y, $z); - + $minX = 0.4375; $maxX = 0.5625; $minZ = 0.4375; $maxZ = 0.5625; - + $var9 = self::canConnectTo($level->level->getBlockID($x, $y, $z - 1)); $var10 = self::canConnectTo($level->level->getBlockID($x, $y, $z + 1)); $var11 = self::canConnectTo($level->level->getBlockID($x - 1, $y, $z)); $var12 = self::canConnectTo($level->level->getBlockID($x + 1, $y, $z)); - + if((!$var11 || !$var12) && ($var11 || $var12 || $var9 || $var10)){ if($var11 && !$var12) $minX = 0; - else if(!$var11 && $var12) $maxX = 1; + elseif(!$var11 && $var12) $maxX = 1; }else{ $minX = 0; $maxX = 1; } - + if((!$var9 || !$var10) && ($var11 || $var12 || $var9 || $var10)){ if($var9 && !$var10) $minZ = 0; - else if(!$var9 && $var10) $maxZ = 1; + elseif(!$var9 && $var10) $maxZ = 1; }else{ $minZ = 0; $maxZ = 1; } - + StaticBlock::setBlockBounds($id, $minX, 0, $minZ, $maxX, 1, $maxZ); } public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ @@ -51,7 +51,7 @@ class GlassPaneBlock extends TransparentBlock{ }else{ $arr[] = $aabb->addMinMax(0, 0, 0.4375, 1, 1, 0.5625); } - + if((!$var8 || !$var9) && ($var10 || $var11 || $var8 || $var9)){ if($var8 && !$var9) $arr[] = $aabb->addMinMax(0.4375, 0, 0, 0.5625, 1, 0.5); elseif(!$var8 && $var9) $arr[] = $aabb->addMinMax(0.4375, 0, 0.5, 0.5625, 1, 1); @@ -60,14 +60,14 @@ class GlassPaneBlock extends TransparentBlock{ } return $arr; } - + public static function canConnectTo($blockID) : bool{ return StaticBlock::getIsSolid($blockID) || $blockID == GLASS_PANE || $blockID == GLASS; } - + public function getDrops(Item $item, Player $player){ - return array( - array(GLASS_PANE, 0, 0), - ); + return [ + [GLASS_PANE, 0, 0], + ]; } } \ No newline at end of file diff --git a/src/material/block/nonfull/IronBarsBlock.php b/src/material/block/nonfull/IronBarsBlock.php index feeca1cc..3666bc6f 100644 --- a/src/material/block/nonfull/IronBarsBlock.php +++ b/src/material/block/nonfull/IronBarsBlock.php @@ -7,39 +7,39 @@ class IronBarsBlock extends TransparentBlock{ $this->isFullBlock = false; $this->isSolid = false; } - + public static function updateShape(Level $level, $x, $y, $z){ $id = $level->level->getBlockID($x, $y, $z); - + $minX = 0.4375; $maxX = 0.5625; $minZ = 0.4375; $maxZ = 0.5625; - + $var9 = self::canConnectTo($level->level->getBlockID($x, $y, $z - 1)); $var10 = self::canConnectTo($level->level->getBlockID($x, $y, $z + 1)); $var11 = self::canConnectTo($level->level->getBlockID($x - 1, $y, $z)); $var12 = self::canConnectTo($level->level->getBlockID($x + 1, $y, $z)); - + if((!$var11 || !$var12) && ($var11 || $var12 || $var9 || $var10)){ if($var11 && !$var12) $minX = 0; - else if(!$var11 && $var12) $maxX = 1; + elseif(!$var11 && $var12) $maxX = 1; }else{ $minX = 0; $maxX = 1; } - + if((!$var9 || !$var10) && ($var11 || $var12 || $var9 || $var10)){ if($var9 && !$var10) $minZ = 0; - else if(!$var9 && $var10) $maxZ = 1; + elseif(!$var9 && $var10) $maxZ = 1; }else{ $minZ = 0; $maxZ = 1; } - + StaticBlock::setBlockBounds($id, $minX, 0, $minZ, $maxX, 1, $maxZ); } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ $var8 = self::canConnectTo($level->level->getBlockID($x, $y, $z - 1)); $var9 = self::canConnectTo($level->level->getBlockID($x, $y, $z + 1)); @@ -53,7 +53,7 @@ class IronBarsBlock extends TransparentBlock{ }else{ $arr[] = $aabb->addMinMax(0, 0, 0.4375, 1, 1, 0.5625); } - + if((!$var8 || !$var9) && ($var10 || $var11 || $var8 || $var9)){ if($var8 && !$var9) $arr[] = $aabb->addMinMax(0.4375, 0, 0, 0.5625, 1, 0.5); elseif(!$var8 && $var9) $arr[] = $aabb->addMinMax(0.4375, 0, 0.5, 0.5625, 1, 1); @@ -62,9 +62,9 @@ class IronBarsBlock extends TransparentBlock{ } return $arr; } - + public static function canConnectTo($blockID) : bool{ return StaticBlock::getIsSolid($blockID) || $blockID == IRON_BARS || $blockID == GLASS; } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/IronDoorBlock.php b/src/material/block/nonfull/IronDoorBlock.php index 5ac59aae..fd3b24f3 100644 --- a/src/material/block/nonfull/IronDoorBlock.php +++ b/src/material/block/nonfull/IronDoorBlock.php @@ -21,14 +21,14 @@ class IronDoorBlock extends DoorBlock{ default => 25, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(IRON_DOOR, 0, 1), - ); + return [ + [IRON_DOOR, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/nonfull/PoweredRailBlock.php b/src/material/block/nonfull/PoweredRailBlock.php index 0fd8a32a..0de0c7cd 100644 --- a/src/material/block/nonfull/PoweredRailBlock.php +++ b/src/material/block/nonfull/PoweredRailBlock.php @@ -1,12 +1,13 @@ hardness = 0.7; - $this->isFullBlock = false; + $this->isFullBlock = false; $this->isSolid = false; } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/RailBaseBlock.php b/src/material/block/nonfull/RailBaseBlock.php index f74a085c..c6886596 100644 --- a/src/material/block/nonfull/RailBaseBlock.php +++ b/src/material/block/nonfull/RailBaseBlock.php @@ -2,24 +2,24 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here { - + public static function isRailBlock(Level $l, $x, $y, $z){ $id = $l->level->getBlockID($x, $y, $z); return $id === POWERED_RAIL || $id === RAIL; } - + public static function isRailID($id){ return $id == POWERED_RAIL || $id == RAIL; } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() !== AIR and $down instanceof SolidBlock){ - + $this->level->setBlock($block, $this, true, false, true); $logic = new RailLogic($this); $logic->place(false, true); @@ -27,16 +27,16 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here } return false; } - + public function updateState(){} - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ [$id, $meta] = $level->level->getBlock($x, $y, $z); if($id === POWERED_RAIL){ $meta &= 7; } if( - ($level->level->getBlockID($x, $y - 1, $z) === 0) || + ($level->level->getBlockID($x, $y - 1, $z) === 0) || (($meta == 2) && $level->level->getBlockID($x + 1, $y, $z) === 0) || (($meta == 3) && $level->level->getBlockID($x - 1, $y, $z) === 0) || (($meta == 4) && $level->level->getBlockID($x, $y, $z - 1) === 0) || @@ -45,7 +45,7 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem($id, $meta, 1)); }else{ - //TODO fix me pls $this->updateState(); + //TODO fix me pls $this->updateState(); } } } diff --git a/src/material/block/nonfull/RailBlock.php b/src/material/block/nonfull/RailBlock.php index 9d63e231..b129d8af 100644 --- a/src/material/block/nonfull/RailBlock.php +++ b/src/material/block/nonfull/RailBlock.php @@ -1,19 +1,20 @@ hardness = 0.7; - $this->isFullBlock = false; + $this->isFullBlock = false; $this->isSolid = false; } - + public function updateState(){ $logic = (new RailLogic($this)); if($logic->countPotentialConnections() == 3){ $logic->place(false, false); } } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/SlabBlock.php b/src/material/block/nonfull/SlabBlock.php index 3319bb7b..9a6cec6d 100644 --- a/src/material/block/nonfull/SlabBlock.php +++ b/src/material/block/nonfull/SlabBlock.php @@ -12,19 +12,19 @@ class SlabBlock extends TransparentBlock{ 6 => "Quartz", 7 => "", ]; - + public function __construct($meta = 0){ parent::__construct(SLAB, $meta, "Slab"); - $this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . self::$NAMES[$this->meta & 0x07] . " Slab"; + $this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . self::$NAMES[$this->meta & 0x07] . " Slab"; if(($this->meta & 0x08) === 0x08){ $this->isFullBlock = true; }else{ $this->isFullBlock = false; - } + } $this->hardness = 30; } public static function updateShape(Level $level, $x, $y, $z){ - + [$id, $meta] = $level->level->getBlock($x, $y, $z); if($meta & 0x08 == 0x08){ @@ -35,11 +35,11 @@ class SlabBlock extends TransparentBlock{ else StaticBlock::setBlockBounds($id, 0, 0.5, 0, 1, 1, 1); } } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ self::updateShape($level, $x, $y, $z); $id = $level->level->getBlockID($x, $y, $z); - + return [ new AxisAlignedBB( $x + StaticBlock::$minXs[$id], $y + StaticBlock::$minYs[$id], $z + StaticBlock::$minZs[$id], @@ -47,7 +47,7 @@ class SlabBlock extends TransparentBlock{ ) ]; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $this->meta &= 0x07; if($face === 0){ @@ -103,14 +103,14 @@ class SlabBlock extends TransparentBlock{ default => 10, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array($this->id, $this->meta & 0x07, 1), - ); + return [ + [$this->id, $this->meta & 0x07, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/nonfull/SnowLayerBlock.php b/src/material/block/nonfull/SnowLayerBlock.php index 3e9961a3..16807094 100644 --- a/src/material/block/nonfull/SnowLayerBlock.php +++ b/src/material/block/nonfull/SnowLayerBlock.php @@ -20,20 +20,20 @@ class SnowLayerBlock extends FlowableBlock{ } return false; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } } - + public function getDrops(Item $item, Player $player){ if($item->isShovel() !== false){ - return array( - array(SNOWBALL, 0, 1), - ); + return [ + [SNOWBALL, 0, 1], + ]; } - - return array(); + + return []; } } \ No newline at end of file diff --git a/src/material/block/nonfull/StoneWallBlock.php b/src/material/block/nonfull/StoneWallBlock.php index 730bc480..16f41faa 100644 --- a/src/material/block/nonfull/StoneWallBlock.php +++ b/src/material/block/nonfull/StoneWallBlock.php @@ -15,45 +15,45 @@ class StoneWallBlock extends TransparentBlock{ } return []; } - + public static function connectsTo(Level $level, $x, $y, $z){ $id = $level->level->getBlockID($x, $y, $z); - + if($id == STONE_WALL || $id == FENCE_GATE) return true; if($id == 0) return false; - + if(StaticBlock::getIsSolid($id) && !StaticBlock::getIsTransparent($id)){ //XXX in vanilla it uses Material->isSolidBlocking() and Tile->isCubeShaped() return true; //XXX in vanilla it returns v7->material != Material::vegetable; } return false; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [static::getAABB($level, $x, $y, $z)]; } - + public static function getAABB(Level $level, $x, $y, $z){ static::updateShape($level, $x, $y, $z); StaticBlock::$maxYs[$level->level->getBlockID($x, $y, $z)] = 1.5; return parent::getAABB($level, $x, $y, $z); } - + public static function updateShape(Level $level, $x, $y, $z){ $zNeg = self::connectsTo($level, $x, $y, $z - 1); $zPos = self::connectsTo($level, $x, $y, $z + 1); $xNeg = self::connectsTo($level, $x - 1, $y, $z); $xPos = self::connectsTo($level, $x + 1, $y, $z); - + $minX = 0.25; $maxY = 1.0; $maxX = 0.75; - + $minZ = $zNeg ? 0 : 0.25; $maxZ = $zPos ? 1.0 : 0.75; - + if($xNeg) $minX = 0; if($xPos) $maxX = 1.0; - + if($zNeg){ if($zPos && !$xNeg){ if(!$xPos){ @@ -62,7 +62,7 @@ class StoneWallBlock extends TransparentBlock{ $minX = 0.3125; } } - }else if(!$zPos && $zNeg){ + }elseif(!$zPos && $zNeg){ if($xPos){ $maxY = 0.8125; $maxZ = 0.6875; diff --git a/src/material/block/nonfull/WoodDoorBlock.php b/src/material/block/nonfull/WoodDoorBlock.php index 7109a6b6..43c5827f 100644 --- a/src/material/block/nonfull/WoodDoorBlock.php +++ b/src/material/block/nonfull/WoodDoorBlock.php @@ -7,10 +7,10 @@ class WoodDoorBlock extends DoorBlock{ $this->isActivable = true; $this->hardness = 15; } - + public function getDrops(Item $item, Player $player){ - return array( - array(WOODEN_DOOR, 0, 1), - ); + return [ + [WOODEN_DOOR, 0, 1], + ]; } } diff --git a/src/material/block/nonfull/WoodSlabBlock.php b/src/material/block/nonfull/WoodSlabBlock.php index d39f0931..e2f6c84e 100644 --- a/src/material/block/nonfull/WoodSlabBlock.php +++ b/src/material/block/nonfull/WoodSlabBlock.php @@ -1,28 +1,29 @@ "Oak", 1 => "Spruce", 2 => "Birch", 3 => "Jungle", - ); - $this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Wooden Slab"; + ]; + $this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Wooden Slab"; if(($this->meta & 0x08) === 0x08){ $this->isFullBlock = true; }else{ $this->isFullBlock = false; - } + } $this->hardness = 15; } - + public static function updateShape(Level $level, $x, $y, $z){ - + [$id, $meta] = $level->level->getBlock($x, $y, $z); - + if($meta & 0x08 == 0x08){ StaticBlock::setBlockBounds($id, 0, 0, 0, 1, 1, 1); }else{ @@ -31,11 +32,11 @@ class WoodSlabBlock extends TransparentBlock{ else StaticBlock::setBlockBounds($id, 0, 0.5, 0, 1, 1, 1); } } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ self::updateShape($level, $x, $y, $z); $id = $level->level->getBlockID($x, $y, $z); - + return [ new AxisAlignedBB( $x + StaticBlock::$minXs[$id], $y + StaticBlock::$minYs[$id], $z + StaticBlock::$minZs[$id], @@ -43,7 +44,7 @@ class WoodSlabBlock extends TransparentBlock{ ) ]; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $this->meta &= 0x07; if($face === 0){ @@ -99,10 +100,10 @@ class WoodSlabBlock extends TransparentBlock{ default => 3, }; } - + public function getDrops(Item $item, Player $player){ - return array( - array($this->id, $this->meta & 0x07, 1), - ); + return [ + [$this->id, $this->meta & 0x07, 1], + ]; } } diff --git a/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php b/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php index 619208b7..5cebc8dd 100644 --- a/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php @@ -7,8 +7,8 @@ class BirchWoodStairsBlock extends StairBlock{ } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/BrickStairsBlock.php b/src/material/block/nonfull/stairs/BrickStairsBlock.php index 133a5f0b..52ee5a7f 100644 --- a/src/material/block/nonfull/stairs/BrickStairsBlock.php +++ b/src/material/block/nonfull/stairs/BrickStairsBlock.php @@ -5,5 +5,5 @@ class BrickStairsBlock extends StairBlock{ public function __construct($meta = 0){ parent::__construct(BRICK_STAIRS, $meta, "Brick Stairs"); } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/CobblestoneStairsBlock.php b/src/material/block/nonfull/stairs/CobblestoneStairsBlock.php index 54d1710a..dbe84da3 100644 --- a/src/material/block/nonfull/stairs/CobblestoneStairsBlock.php +++ b/src/material/block/nonfull/stairs/CobblestoneStairsBlock.php @@ -5,5 +5,5 @@ class CobblestoneStairsBlock extends StairBlock{ public function __construct($meta = 0){ parent::__construct(COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs"); } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/JungleWoodStairsBlock.php b/src/material/block/nonfull/stairs/JungleWoodStairsBlock.php index 76c4bc68..c466fda2 100644 --- a/src/material/block/nonfull/stairs/JungleWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/JungleWoodStairsBlock.php @@ -7,8 +7,8 @@ class JungleWoodStairsBlock extends StairBlock{ } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/NetherBricksStairsBlock.php b/src/material/block/nonfull/stairs/NetherBricksStairsBlock.php index 0b984590..d798d1e5 100644 --- a/src/material/block/nonfull/stairs/NetherBricksStairsBlock.php +++ b/src/material/block/nonfull/stairs/NetherBricksStairsBlock.php @@ -5,5 +5,5 @@ class NetherBricksStairsBlock extends StairBlock{ public function __construct($meta = 0){ parent::__construct(NETHER_BRICKS_STAIRS, $meta, "Nether Bricks Stairs"); } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/QuartzStairsBlock.php b/src/material/block/nonfull/stairs/QuartzStairsBlock.php index 062b60d0..b9f7ac8d 100644 --- a/src/material/block/nonfull/stairs/QuartzStairsBlock.php +++ b/src/material/block/nonfull/stairs/QuartzStairsBlock.php @@ -5,5 +5,5 @@ class QuartzStairsBlock extends StairBlock{ public function __construct($meta = 0){ parent::__construct(QUARTZ_STAIRS, $meta, "Quartz Stairs"); } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/SandstoneStairsBlock.php b/src/material/block/nonfull/stairs/SandstoneStairsBlock.php index 8512e628..89e44b6d 100644 --- a/src/material/block/nonfull/stairs/SandstoneStairsBlock.php +++ b/src/material/block/nonfull/stairs/SandstoneStairsBlock.php @@ -5,5 +5,5 @@ class SandstoneStairsBlock extends StairBlock{ public function __construct($meta = 0){ parent::__construct(SANDSTONE_STAIRS, $meta, "Sandstone Stairs"); } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/SpruceWoodStairsBlock.php b/src/material/block/nonfull/stairs/SpruceWoodStairsBlock.php index f001a888..8468e0e2 100644 --- a/src/material/block/nonfull/stairs/SpruceWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/SpruceWoodStairsBlock.php @@ -7,8 +7,8 @@ class SpruceWoodStairsBlock extends StairBlock{ } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/StoneBrickStairsBlock.php b/src/material/block/nonfull/stairs/StoneBrickStairsBlock.php index b43efbb7..0a13b42b 100644 --- a/src/material/block/nonfull/stairs/StoneBrickStairsBlock.php +++ b/src/material/block/nonfull/stairs/StoneBrickStairsBlock.php @@ -5,5 +5,5 @@ class StoneBrickStairsBlock extends StairBlock{ public function __construct($meta = 0){ parent::__construct(STONE_BRICK_STAIRS, $meta, "Stone Brick Stairs"); } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/stairs/WoodStairsBlock.php b/src/material/block/nonfull/stairs/WoodStairsBlock.php index 0421dac4..d3cc9e10 100644 --- a/src/material/block/nonfull/stairs/WoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/WoodStairsBlock.php @@ -21,8 +21,8 @@ class WoodStairsBlock extends StairBlock{ } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } } diff --git a/src/material/block/ore/CoalOreBlock.php b/src/material/block/ore/CoalOreBlock.php index 12e5c262..8bc6ce59 100644 --- a/src/material/block/ore/CoalOreBlock.php +++ b/src/material/block/ore/CoalOreBlock.php @@ -6,7 +6,7 @@ class CoalOreBlock extends SolidBlock{ parent::__construct(COAL_ORE, 0, "Coal Ore"); $this->hardness = 15; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -20,15 +20,15 @@ class CoalOreBlock extends SolidBlock{ default => 15, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(COAL, 0, 1), - ); + return [ + [COAL, 0, 1], + ]; }else{ - return array(); + return []; } } - + } diff --git a/src/material/block/ore/DiamondOreBlock.php b/src/material/block/ore/DiamondOreBlock.php index dec08e78..8b4fc682 100644 --- a/src/material/block/ore/DiamondOreBlock.php +++ b/src/material/block/ore/DiamondOreBlock.php @@ -6,7 +6,7 @@ class DiamondOreBlock extends SolidBlock{ parent::__construct(DIAMOND_ORE, 0, "Diamond Ore"); $this->hardness = 15; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -17,14 +17,14 @@ class DiamondOreBlock extends SolidBlock{ default => 15, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 4){ - return array( - array(DIAMOND, 0, 1), - ); + return [ + [DIAMOND, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/ore/GlowingRedstoneOreBlock.php b/src/material/block/ore/GlowingRedstoneOreBlock.php index 33dd8e0c..ed9ad90e 100644 --- a/src/material/block/ore/GlowingRedstoneOreBlock.php +++ b/src/material/block/ore/GlowingRedstoneOreBlock.php @@ -6,11 +6,11 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{ parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore"); $this->hardness = 15; } - + public static function onRandomTick(Level $level, $x, $y, $z){ $level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0); } - + public function getMaxLightValue(){ return 9; } @@ -25,15 +25,15 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{ default => 15, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 4){ - return array( - array(REDSTONE_DUST, 0, mt_rand(4, 5)), - ); + return [ + [REDSTONE_DUST, 0, mt_rand(4, 5)], + ]; }else{ - return array(); + return []; } } - + } diff --git a/src/material/block/ore/GoldOreBlock.php b/src/material/block/ore/GoldOreBlock.php index c835dbc1..2de507f6 100644 --- a/src/material/block/ore/GoldOreBlock.php +++ b/src/material/block/ore/GoldOreBlock.php @@ -17,14 +17,14 @@ class GoldOreBlock extends SolidBlock{ default => 15, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 4){ - return array( - array(GOLD_ORE, 0, 1), - ); + return [ + [GOLD_ORE, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/ore/IronOreBlock.php b/src/material/block/ore/IronOreBlock.php index d8d001ff..abb023de 100644 --- a/src/material/block/ore/IronOreBlock.php +++ b/src/material/block/ore/IronOreBlock.php @@ -18,14 +18,14 @@ class IronOreBlock extends SolidBlock{ default => 15, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= ItemTool::STONE_LEVEL){ - return array( - array(IRON_ORE, 0, 1), - ); + return [ + [IRON_ORE, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/ore/LapisOreBlock.php b/src/material/block/ore/LapisOreBlock.php index ecb3e83f..5130db86 100644 --- a/src/material/block/ore/LapisOreBlock.php +++ b/src/material/block/ore/LapisOreBlock.php @@ -6,7 +6,7 @@ class LapisOreBlock extends SolidBlock{ parent::__construct(LAPIS_ORE, 0, "Lapis Ore"); $this->hardness = 15; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -21,12 +21,12 @@ class LapisOreBlock extends SolidBlock{ public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 3){ - return array( - array(DYE, 4, mt_rand(4, 8)), - ); + return [ + [DYE, 4, mt_rand(4, 8)], + ]; }else{ - return array(); + return []; } } - + } diff --git a/src/material/block/ore/RedstoneOreBlock.php b/src/material/block/ore/RedstoneOreBlock.php index 471f87ae..dfe5c77e 100644 --- a/src/material/block/ore/RedstoneOreBlock.php +++ b/src/material/block/ore/RedstoneOreBlock.php @@ -6,18 +6,18 @@ class RedstoneOreBlock extends SolidBlock{ parent::__construct(REDSTONE_ORE, 0, "Redstone Ore"); $this->hardness = 15; } - + public static function interact(Level $level, $x, $y, $z, Player $player){ $level->fastSetBlockUpdate($x, $y, $z, GLOWING_REDSTONE_ORE, 0); } public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 4){ - return array( - array(REDSTONE_DUST, 0, mt_rand(4, 5)), - ); + return [ + [REDSTONE_DUST, 0, mt_rand(4, 5)], + ]; }else{ - return array(); + return []; } } } \ No newline at end of file diff --git a/src/material/block/plant/BeetrootBlock.php b/src/material/block/plant/BeetrootBlock.php index c1b51d73..423ed15f 100644 --- a/src/material/block/plant/BeetrootBlock.php +++ b/src/material/block/plant/BeetrootBlock.php @@ -46,7 +46,7 @@ class BeetrootBlock extends FlowableBlock{ $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function getDrops(Item $item, Player $player){ $drops = []; if($this->meta >= 0x07){ diff --git a/src/material/block/plant/BrownMushroomBlock.php b/src/material/block/plant/BrownMushroomBlock.php index 495d8a73..aae803a7 100644 --- a/src/material/block/plant/BrownMushroomBlock.php +++ b/src/material/block/plant/BrownMushroomBlock.php @@ -9,11 +9,11 @@ class BrownMushroomBlock extends FlowableBlock{ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(BROWN_MUSHROOM)); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(BROWN_MUSHROOM)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->isTransparent === false){ @@ -21,5 +21,5 @@ class BrownMushroomBlock extends FlowableBlock{ return true; } return false; - } + } } \ No newline at end of file diff --git a/src/material/block/plant/CactusBlock.php b/src/material/block/plant/CactusBlock.php index 4dd97196..debb3dc2 100644 --- a/src/material/block/plant/CactusBlock.php +++ b/src/material/block/plant/CactusBlock.php @@ -7,14 +7,14 @@ class CactusBlock extends TransparentBlock{ $this->isFullBlock = false; $this->hardness = 2; } - + public static function onEntityCollidedWithBlock(Level $level, $x, $y, $z, Entity $entity){ $entity->harm(1, "cactus"); } public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x + 0.0625, $y, $z + 0.0625, $x + 1 - 0.0625, $y + 1 - 0.0625, $z + 1 - 0.0625)]; } - + public static function onRandomTick(Level $level, $x, $y, $z){ //$b = $level->level->getBlock($x, $y - 1, $z); $underID = $level->level->getBlockID($x, $y - 1, $z); @@ -38,7 +38,7 @@ class CactusBlock extends TransparentBlock{ return BLOCK_UPDATE_RANDOM; } } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $down = $level->level->getBlockID($x, $y - 1, $z); $b0 = $level->level->getBlockID($x, $y, $z - 1); @@ -50,7 +50,7 @@ class CactusBlock extends TransparentBlock{ ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CACTUS)); } } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() === SAND or $down->getID() === CACTUS){ @@ -67,10 +67,10 @@ class CactusBlock extends TransparentBlock{ } return false; } - + public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } } \ No newline at end of file diff --git a/src/material/block/plant/CarrotBlock.php b/src/material/block/plant/CarrotBlock.php index 498399f4..b7fe8619 100644 --- a/src/material/block/plant/CarrotBlock.php +++ b/src/material/block/plant/CarrotBlock.php @@ -17,7 +17,7 @@ class CarrotBlock extends FlowableBlock{ } return false; } - + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta += mt_rand(0, 3) + 2; @@ -48,7 +48,7 @@ class CarrotBlock extends FlowableBlock{ $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function getDrops(Item $item, Player $player){ $drops = []; if($this->meta >= 0x07){ diff --git a/src/material/block/plant/CyanFlowerBlock.php b/src/material/block/plant/CyanFlowerBlock.php index 8486ede6..60de9639 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -7,7 +7,7 @@ class CyanFlowerBlock extends FlowableBlock{ $this->isActivable = true; $this->hardness = 0; } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } @@ -21,17 +21,14 @@ class CyanFlowerBlock extends FlowableBlock{ return false; } - public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $downId = $level->level->getBlockID($x, $y - 1, $z); if(StaticBlock::getIsTransparent($downId) and $downId !== FARMLAND){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(CYAN_FLOWER)); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CYAN_FLOWER)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - - public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ if(($player->gamemode & 0x01) === 0){ diff --git a/src/material/block/plant/DandelionBlock.php b/src/material/block/plant/DandelionBlock.php index 57f5ef64..69f39eef 100644 --- a/src/material/block/plant/DandelionBlock.php +++ b/src/material/block/plant/DandelionBlock.php @@ -22,7 +22,7 @@ class DandelionBlock extends FlowableBlock{ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $downId = $level->level->getBlockID($x, $y - 1, $z); if(StaticBlock::getIsTransparent($downId) and $downId !== FARMLAND){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(CYAN_FLOWER)); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CYAN_FLOWER)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } diff --git a/src/material/block/plant/DeadBushBlock.php b/src/material/block/plant/DeadBushBlock.php index 4f7d49b7..b3be7cdc 100644 --- a/src/material/block/plant/DeadBushBlock.php +++ b/src/material/block/plant/DeadBushBlock.php @@ -7,33 +7,33 @@ class DeadBushBlock extends FlowableBlock{ //$this->isReplaceable = true; $this->hardness = 0; } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() == 12){ $this->level->setBlock($block, $this, true, false, true); return true; - } + } return false; } - + public function getDrops(Item $item, Player $player){ if($item->isShears()){ return [ [DEAD_BUSH, 0, 1], ]; } - + return []; } } \ No newline at end of file diff --git a/src/material/block/plant/MelonStemBlock.php b/src/material/block/plant/MelonStemBlock.php index a9e3c542..4dee856f 100644 --- a/src/material/block/plant/MelonStemBlock.php +++ b/src/material/block/plant/MelonStemBlock.php @@ -24,7 +24,7 @@ class MelonStemBlock extends FlowableBlock{ //$this->level->setBlock($this, $this, true, false, true); $level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1); }else{ - + $position = new AirBlock(); //feke block $position->x = $x; $position->y = $y; @@ -46,11 +46,11 @@ class MelonStemBlock extends FlowableBlock{ } public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2))); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2))); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta += mt_rand(0, 3) + 2; @@ -65,7 +65,7 @@ class MelonStemBlock extends FlowableBlock{ } return false; } - + public function getDrops(Item $item, Player $player){ $drops = []; if($this->meta >= 0x07){ diff --git a/src/material/block/plant/PotatoBlock.php b/src/material/block/plant/PotatoBlock.php index 3ab969fe..62d44ac6 100644 --- a/src/material/block/plant/PotatoBlock.php +++ b/src/material/block/plant/PotatoBlock.php @@ -48,7 +48,7 @@ class PotatoBlock extends FlowableBlock{ $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function getDrops(Item $item, Player $player){ $drops = []; if($this->meta >= 0x07){ diff --git a/src/material/block/plant/PumpkinStemBlock.php b/src/material/block/plant/PumpkinStemBlock.php index c7492623..00eed1cb 100644 --- a/src/material/block/plant/PumpkinStemBlock.php +++ b/src/material/block/plant/PumpkinStemBlock.php @@ -24,7 +24,7 @@ class PumpkinStemBlock extends FlowableBlock{ //$this->level->setBlock($this, $this, true, false, true); $level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1); }else{ - + $position = new AirBlock(); //feke block $position->x = $x; $position->y = $y; @@ -46,11 +46,11 @@ class PumpkinStemBlock extends FlowableBlock{ } public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2))); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2))); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta += mt_rand(0, 3) + 2; @@ -65,7 +65,7 @@ class PumpkinStemBlock extends FlowableBlock{ } return false; } - + public function getDrops(Item $item, Player $player){ $drops = []; if($this->meta >= 0x07){ diff --git a/src/material/block/plant/RedMushroomBlock.php b/src/material/block/plant/RedMushroomBlock.php index 29bdc225..3ba418b5 100644 --- a/src/material/block/plant/RedMushroomBlock.php +++ b/src/material/block/plant/RedMushroomBlock.php @@ -9,7 +9,7 @@ class RedMushroomBlock extends FlowableBlock{ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(RED_MUSHROOM)); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(RED_MUSHROOM)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } @@ -21,5 +21,5 @@ class RedMushroomBlock extends FlowableBlock{ return true; } return false; - } + } } \ No newline at end of file diff --git a/src/material/block/plant/SaplingBlock.php b/src/material/block/plant/SaplingBlock.php index a6acde15..fd830844 100644 --- a/src/material/block/plant/SaplingBlock.php +++ b/src/material/block/plant/SaplingBlock.php @@ -7,16 +7,16 @@ class SaplingBlock extends FlowableBlock{ const BIRCH = 2; const JUNGLE = 3; const BURN_TIME = 5; - + public function __construct($meta = SaplingBlock::OAK){ parent::__construct(SAPLING, $meta, "Sapling"); $this->isActivable = true; - $names = array( + $names = [ 0 => "Oak Sapling", 1 => "Spruce Sapling", 2 => "Birch Sapling", 3 => "Jungle Sapling", - ); + ]; $this->name = $names[$this->meta & 0x03]; $this->hardness = 0; } @@ -32,7 +32,7 @@ class SaplingBlock extends FlowableBlock{ } return false; } - + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03); @@ -47,7 +47,7 @@ class SaplingBlock extends FlowableBlock{ $downID = $level->level->getBlockID($x, $y - 1, $z); if(StaticBlock::getIsTransparent($downID) && $downID !== FARMLAND){ //Replace with common break method [$id, $meta] = $level->level->getBlock($x, $y, $z); - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem($id, $meta)); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem($id, $meta)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } @@ -64,8 +64,8 @@ class SaplingBlock extends FlowableBlock{ } } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, $this->meta & 0x03, 1), - ); + return [ + [$this->id, $this->meta & 0x03, 1], + ]; } } diff --git a/src/material/block/plant/SugarcaneBlock.php b/src/material/block/plant/SugarcaneBlock.php index d4928460..660f1393 100644 --- a/src/material/block/plant/SugarcaneBlock.php +++ b/src/material/block/plant/SugarcaneBlock.php @@ -7,7 +7,7 @@ class SugarcaneBlock extends FlowableBlock{ $this->isActivable = true; $this->hardness = 0; } - + public function getDrops(Item $item, Player $player){ return [ [SUGARCANE, 0, 1], @@ -28,7 +28,7 @@ class SugarcaneBlock extends FlowableBlock{ $this->meta = 0; $this->level->fastSetBlockUpdateMeta($this->x, $this->y, $this->z, $this->meta, true); } - + if(($player->gamemode & 0x01) === 0){ $player->removeItem(DYE,0x0F,1); } @@ -50,7 +50,7 @@ class SugarcaneBlock extends FlowableBlock{ } } if(StaticBlock::getIsTransparent($down) && $down != SUGARCANE_BLOCK){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(SUGARCANE)); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(SUGARCANE)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } } @@ -80,7 +80,7 @@ class SugarcaneBlock extends FlowableBlock{ $x = $this->x; $y = $this->y; $z = $this->z; - + $b0 = $level->level->getBlockID($x, $y - 1, $z - 1); $b1 = $level->level->getBlockID($x, $y - 1, $z + 1); $b2 = $level->level->getBlockID($x - 1, $y - 1, $z); diff --git a/src/material/block/plant/TallGrassBlock.php b/src/material/block/plant/TallGrassBlock.php index df8ce39f..94ec709d 100644 --- a/src/material/block/plant/TallGrassBlock.php +++ b/src/material/block/plant/TallGrassBlock.php @@ -5,11 +5,11 @@ class TallGrassBlock extends FlowableBlock{ public function __construct($meta = 1){ parent::__construct(TALL_GRASS, $meta, "Tall Grass"); $this->isReplaceable = true; - $names = array( + $names = [ 0 => "Dead Shrub", 1 => "Tall Grass", 2 => "Fern", - ); + ]; $this->name = $names[$this->meta & 0x03]; $this->hardness = 0; } @@ -17,28 +17,28 @@ class TallGrassBlock extends FlowableBlock{ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $downID = $level->level->getBlockID($x, $y - 1, $z); if(StaticBlock::getIsTransparent($downID) && $downID !== FARMLAND){ //Replace with common break method - if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(WHEAT_SEEDS)); + if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(WHEAT_SEEDS)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } - + public function getDrops(Item $item, Player $player){ - $drops = array(); - if($item->isShears()) $drops[] = array($this->id, $this->meta & 0x03, 1); - elseif(Utils::chance(15)) $drops[] = array(WHEAT_SEEDS, 0, 1); + $drops = []; + if($item->isShears()) $drops[] = [$this->id, $this->meta & 0x03, 1]; + elseif(Utils::chance(15)) $drops[] = [WHEAT_SEEDS, 0, 1]; return $drops; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() == GRASS or $down->getID() == DIRT || $down->getID() == FARMLAND){ $this->level->setBlock($block, $this, true, false, true); return true; - } + } return false; } diff --git a/src/material/block/plant/WheatBlock.php b/src/material/block/plant/WheatBlock.php index 53bf67f4..36f8d247 100644 --- a/src/material/block/plant/WheatBlock.php +++ b/src/material/block/plant/WheatBlock.php @@ -17,7 +17,7 @@ class WheatBlock extends FlowableBlock{ } return false; } - + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta += mt_rand(0, 3) + 2; @@ -48,7 +48,7 @@ class WheatBlock extends FlowableBlock{ $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function getDrops(Item $item, Player $player){ $drops = []; if($this->meta >= 0x07){ @@ -59,7 +59,7 @@ class WheatBlock extends FlowableBlock{ $drops[] = [WHEAT_SEEDS, 0, 1]; } } - + return $drops; } } \ No newline at end of file diff --git a/src/material/block/solid/BedrockBlock.php b/src/material/block/solid/BedrockBlock.php index 8974deae..d214a6d8 100644 --- a/src/material/block/solid/BedrockBlock.php +++ b/src/material/block/solid/BedrockBlock.php @@ -7,12 +7,12 @@ class BedrockBlock extends SolidBlock{ $this->breakable = false; $this->hardness = 18000000; } - + public function isBreakable(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return true; } return false; } - + } \ No newline at end of file diff --git a/src/material/block/solid/BookshelfBlock.php b/src/material/block/solid/BookshelfBlock.php index 8f19b6fe..4e501fe0 100644 --- a/src/material/block/solid/BookshelfBlock.php +++ b/src/material/block/solid/BookshelfBlock.php @@ -6,5 +6,5 @@ class BookshelfBlock extends SolidBlock{ parent::__construct(BOOKSHELF, 0, "Bookshelf"); $this->hardness = 7.5; } - + } \ No newline at end of file diff --git a/src/material/block/solid/BricksBlock.php b/src/material/block/solid/BricksBlock.php index 97f448b2..653d398e 100644 --- a/src/material/block/solid/BricksBlock.php +++ b/src/material/block/solid/BricksBlock.php @@ -20,14 +20,14 @@ class BricksBlock extends SolidBlock{ default => 10, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(BRICKS_BLOCK, 0, 1), - ); + return [ + [BRICKS_BLOCK, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/BurningFurnaceBlock.php b/src/material/block/solid/BurningFurnaceBlock.php index 0adb007c..1cfc3039 100644 --- a/src/material/block/solid/BurningFurnaceBlock.php +++ b/src/material/block/solid/BurningFurnaceBlock.php @@ -9,12 +9,12 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{ } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $faces = array( + $faces = [ 0 => 4, 1 => 2, 2 => 5, 3 => 3, - ); + ]; $this->meta = $faces[$player->entity->getDirection()]; $this->level->setBlock($block, $this, true, false, true); return true; @@ -35,23 +35,23 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{ if($t !== false){ $furnace = $t; }else{ - $furnace = $server->api->tile->add($this->level, TILE_FURNACE, $this->x, $this->y, $this->z, array( - "Items" => array(), + $furnace = $server->api->tile->add($this->level, TILE_FURNACE, $this->x, $this->y, $this->z, [ + "Items" => [], "id" => TILE_FURNACE, "x" => $this->x, "y" => $this->y, - "z" => $this->z - )); + "z" => $this->z + ]); } - + if(($player->gamemode & 0x01) === 0x01){ return true; } - + $furnace->openInventory($player); return true; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -65,18 +65,18 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{ default => 17.5, }; } - + public function getDrops(Item $item, Player $player){ - $drops = array(); + $drops = []; if($item->getPickaxeLevel() >= 1){ - $drops[] = array(FURNACE, 0, 1); + $drops[] = [FURNACE, 0, 1]; } $t = ServerAPI::request()->api->tile->get($this); if($t !== false and $t->class === TILE_FURNACE){ for($s = 0; $s < FURNACE_SLOTS; ++$s){ $slot = $t->getSlot($s); if($slot->getID() > AIR and $slot->count > 0){ - $drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count); + $drops[] = [$slot->getID(), $slot->getMetadata(), $slot->count]; } } } diff --git a/src/material/block/solid/ClayBlock.php b/src/material/block/solid/ClayBlock.php index 3ca8b2a4..7ce626de 100644 --- a/src/material/block/solid/ClayBlock.php +++ b/src/material/block/solid/ClayBlock.php @@ -8,8 +8,8 @@ class ClayBlock extends SolidBlock{ } public function getDrops(Item $item, Player $player){ - return array( - array(CLAY, 0, 4), - ); + return [ + [CLAY, 0, 4], + ]; } } \ No newline at end of file diff --git a/src/material/block/solid/CoalBlock.php b/src/material/block/solid/CoalBlock.php index cf7a252e..0995aa26 100644 --- a/src/material/block/solid/CoalBlock.php +++ b/src/material/block/solid/CoalBlock.php @@ -20,14 +20,14 @@ class CoalBlock extends SolidBlock{ default => 25, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(COAL_BLOCK, 0, 1), - ); + return [ + [COAL_BLOCK, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/CobblestoneBlock.php b/src/material/block/solid/CobblestoneBlock.php index 895953d1..0990c10d 100644 --- a/src/material/block/solid/CobblestoneBlock.php +++ b/src/material/block/solid/CobblestoneBlock.php @@ -20,14 +20,14 @@ class CobblestoneBlock extends SolidBlock{ default => 10, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(COBBLESTONE, 0, 1), - ); + return [ + [COBBLESTONE, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/DiamondBlock.php b/src/material/block/solid/DiamondBlock.php index 2ffeed39..7f073778 100644 --- a/src/material/block/solid/DiamondBlock.php +++ b/src/material/block/solid/DiamondBlock.php @@ -6,7 +6,7 @@ class DiamondBlock extends SolidBlock{ parent::__construct(DIAMOND_BLOCK, 0, "Diamond Block"); $this->hardness = 30; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -17,14 +17,14 @@ class DiamondBlock extends SolidBlock{ default => 25, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 4){ - return array( - array(DIAMOND_BLOCK, 0, 1), - ); + return [ + [DIAMOND_BLOCK, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/DirtBlock.php b/src/material/block/solid/DirtBlock.php index bf96b7c2..64b43604 100644 --- a/src/material/block/solid/DirtBlock.php +++ b/src/material/block/solid/DirtBlock.php @@ -32,33 +32,33 @@ class DirtBlock extends SolidBlock{ } public static function getGrassInRadius(Level $level, $x, $y, $z){ //umwut (although kinda faster than for loop =D) - if($level->level->getBlockID($x+1, $y, $z+1) == 2) return true; - if($level->level->getBlockID($x+1, $y, $z) == 2) return true; - if($level->level->getBlockID($x+1, $y, $z-1) == 2) return true; - if($level->level->getBlockID($x, $y, $z+1) == 2) return true; - if($level->level->getBlockID($x, $y, $z-1) == 2) return true; - if($level->level->getBlockID($x-1, $y, $z+1) == 2) return true; - if($level->level->getBlockID($x-1, $y, $z) == 2) return true; - if($level->level->getBlockID($x-1, $y, $z-1) == 2) return true; + if($level->level->getBlockID($x + 1, $y, $z + 1) == 2) return true; + if($level->level->getBlockID($x + 1, $y, $z) == 2) return true; + if($level->level->getBlockID($x + 1, $y, $z - 1) == 2) return true; + if($level->level->getBlockID($x, $y, $z + 1) == 2) return true; + if($level->level->getBlockID($x, $y, $z - 1) == 2) return true; + if($level->level->getBlockID($x - 1, $y, $z + 1) == 2) return true; + if($level->level->getBlockID($x - 1, $y, $z) == 2) return true; + if($level->level->getBlockID($x - 1, $y, $z - 1) == 2) return true; - if($level->level->getBlockID($x+1, $y-1, $z+1) == 2) return true; - if($level->level->getBlockID($x+1, $y-1, $z) == 2) return true; - if($level->level->getBlockID($x+1, $y-1, $z-1) == 2) return true; - if($level->level->getBlockID($x, $y-1, $z+1) == 2) return true; - if($level->level->getBlockID($x, $y-1, $z) == 2) return true; - if($level->level->getBlockID($x, $y-1, $z-1) == 2) return true; - if($level->level->getBlockID($x-1, $y-1, $z+1) == 2) return true; - if($level->level->getBlockID($x-1, $y-1, $z) == 2) return true; - if($level->level->getBlockID($x-1, $y-1, $z-1) == 2) return true; + if($level->level->getBlockID($x + 1, $y - 1, $z + 1) == 2) return true; + if($level->level->getBlockID($x + 1, $y - 1, $z) == 2) return true; + if($level->level->getBlockID($x + 1, $y - 1, $z - 1) == 2) return true; + if($level->level->getBlockID($x, $y - 1, $z + 1) == 2) return true; + if($level->level->getBlockID($x, $y - 1, $z) == 2) return true; + if($level->level->getBlockID($x, $y - 1, $z - 1) == 2) return true; + if($level->level->getBlockID($x - 1, $y - 1, $z + 1) == 2) return true; + if($level->level->getBlockID($x - 1, $y - 1, $z) == 2) return true; + if($level->level->getBlockID($x - 1, $y - 1, $z - 1) == 2) return true; - if($level->level->getBlockID($x+1, $y+1, $z+1) == 2) return true; - if($level->level->getBlockID($x+1, $y+1, $z) == 2) return true; - if($level->level->getBlockID($x+1, $y+1, $z-1) == 2) return true; - if($level->level->getBlockID($x, $y+1, $z+1) == 2) return true; - if($level->level->getBlockID($x, $y+1, $z-1) == 2) return true; - if($level->level->getBlockID($x-1, $y+1, $z+1) == 2) return true; - if($level->level->getBlockID($x-1, $y+1, $z) == 2) return true; - if($level->level->getBlockID($x-1, $y+1, $z-1) == 2) return true; + if($level->level->getBlockID($x + 1, $y + 1, $z + 1) == 2) return true; + if($level->level->getBlockID($x + 1, $y + 1, $z) == 2) return true; + if($level->level->getBlockID($x + 1, $y + 1, $z - 1) == 2) return true; + if($level->level->getBlockID($x, $y + 1, $z + 1) == 2) return true; + if($level->level->getBlockID($x, $y + 1, $z - 1) == 2) return true; + if($level->level->getBlockID($x - 1, $y + 1, $z + 1) == 2) return true; + if($level->level->getBlockID($x - 1, $y + 1, $z) == 2) return true; + if($level->level->getBlockID($x - 1, $y + 1, $z - 1) == 2) return true; return false; } diff --git a/src/material/block/solid/DoubleSlabBlock.php b/src/material/block/solid/DoubleSlabBlock.php index 4b6f28db..8211f796 100755 --- a/src/material/block/solid/DoubleSlabBlock.php +++ b/src/material/block/solid/DoubleSlabBlock.php @@ -4,7 +4,7 @@ class DoubleSlabBlock extends SolidBlock{ public static $blockID; public function __construct($meta = 0){ parent::__construct(DOUBLE_SLAB, $meta, "Double Slab"); - $names = array( + $names = [ 0 => "Stone", 1 => "Sandstone", 2 => "Wooden", @@ -13,7 +13,7 @@ class DoubleSlabBlock extends SolidBlock{ 5 => "Stone Brick", 6 => "Quartz", 7 => "Smooth Stone", - ); + ]; $this->name = "Double " . $names[$this->meta & 0x07] . " Slab"; $this->hardness = 30; } @@ -31,15 +31,15 @@ class DoubleSlabBlock extends SolidBlock{ default => 10, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(SLAB, $this->meta & 0x07, 2), - ); + return [ + [SLAB, $this->meta & 0x07, 2], + ]; }else{ - return array(); + return []; } } - + } diff --git a/src/material/block/solid/DoubleWoodSlabBlock.php b/src/material/block/solid/DoubleWoodSlabBlock.php index 7ff69ef1..61b4648f 100644 --- a/src/material/block/solid/DoubleWoodSlabBlock.php +++ b/src/material/block/solid/DoubleWoodSlabBlock.php @@ -4,12 +4,12 @@ class DoubleWoodSlabBlock extends SolidBlock{ public static $blockID; public function __construct($meta = 0){ parent::__construct(DOUBLE_WOOD_SLAB, $meta, "Double Wooden Slab"); - $names = array( + $names = [ 0 => "Oak", 1 => "Spruce", 2 => "Birch", 3 => "Jungle", - ); + ]; $this->name = "Double " . $names[$this->meta & 0x07] . " Wooden Slab"; $this->hardness = 15; } @@ -27,11 +27,11 @@ class DoubleWoodSlabBlock extends SolidBlock{ default => 3, }; } - + public function getDrops(Item $item, Player $player){ - return array( - array(WOOD_SLAB, $this->meta & 0x07, 2), - ); + return [ + [WOOD_SLAB, $this->meta & 0x07, 2], + ]; } - + } diff --git a/src/material/block/solid/FurnaceBlock.php b/src/material/block/solid/FurnaceBlock.php index 06f2db28..bbe31df5 100644 --- a/src/material/block/solid/FurnaceBlock.php +++ b/src/material/block/solid/FurnaceBlock.php @@ -4,7 +4,6 @@ require_once("BurningFurnaceBlock.php"); /***REM_END***/ - class FurnaceBlock extends BurningFurnaceBlock{ public static $blockID; public function __construct($meta = 0){ diff --git a/src/material/block/solid/GlassBlock.php b/src/material/block/solid/GlassBlock.php index a6149c59..6b133b3e 100644 --- a/src/material/block/solid/GlassBlock.php +++ b/src/material/block/solid/GlassBlock.php @@ -6,11 +6,11 @@ class GlassBlock extends TransparentBlock{ parent::__construct(GLASS, 0, "Glass"); $this->hardness = 1.5; } - + public function getDrops(Item $item, Player $player){ - return array(); + return []; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; } diff --git a/src/material/block/solid/GlowingObsidianBlock.php b/src/material/block/solid/GlowingObsidianBlock.php index ea88b779..47411822 100644 --- a/src/material/block/solid/GlowingObsidianBlock.php +++ b/src/material/block/solid/GlowingObsidianBlock.php @@ -5,9 +5,9 @@ class GlowingObsidianBlock extends SolidBlock implements LightingBlock{ public function __construct($meta = 0){ parent::__construct(GLOWING_OBSIDIAN, $meta, "Glowing Obsidian"); } - + public function getMaxLightValue(){ return 12; } - + } \ No newline at end of file diff --git a/src/material/block/solid/GlowstoneBlock.php b/src/material/block/solid/GlowstoneBlock.php index 177cbb3f..531ed733 100644 --- a/src/material/block/solid/GlowstoneBlock.php +++ b/src/material/block/solid/GlowstoneBlock.php @@ -6,17 +6,17 @@ class GlowstoneBlock extends TransparentBlock implements LightingBlock{ parent::__construct(GLOWSTONE_BLOCK, 0, "Glowstone"); $this->hardness = 1.5; } - + public function getMaxLightValue(){ return 15; } - + public function getDrops(Item $item, Player $player){ - return array( - array(GLOWSTONE_DUST, 0, mt_rand(2, 4)), - ); + return [ + [GLOWSTONE_DUST, 0, mt_rand(2, 4)], + ]; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; } diff --git a/src/material/block/solid/GoldBlock.php b/src/material/block/solid/GoldBlock.php index 80006170..460c2b02 100644 --- a/src/material/block/solid/GoldBlock.php +++ b/src/material/block/solid/GoldBlock.php @@ -17,14 +17,14 @@ class GoldBlock extends SolidBlock{ default => 15, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 4){ - return array( - array(GOLD_BLOCK, 0, 1), - ); + return [ + [GOLD_BLOCK, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/GrassBlock.php b/src/material/block/solid/GrassBlock.php index 9b689ff6..47ae9f0d 100644 --- a/src/material/block/solid/GrassBlock.php +++ b/src/material/block/solid/GrassBlock.php @@ -9,9 +9,9 @@ class GrassBlock extends SolidBlock{ } public function getDrops(Item $item, Player $player){ - return array( - array(DIRT, 0, 1), - ); + return [ + [DIRT, 0, 1], + ]; } public function onActivate(Item $item, Player $player){ @@ -34,13 +34,13 @@ class GrassBlock extends SolidBlock{ } return false; } - + public function seedsDrop(){ $chance = lcg_value() * 100; if($chance <= 1){ - ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(BEETROOT_SEEDS,0,1), 10); + ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y + 1, $this->z + 0.5, $this->level), BlockAPI::getItem(BEETROOT_SEEDS,0,1), 10); }elseif($chance > 1 and $chance <= 16){ - ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(SEEDS,0,1), 10); + ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y + 1, $this->z + 0.5, $this->level), BlockAPI::getItem(SEEDS,0,1), 10); } } public static function onRandomTick(Level $level, $x, $y, $z){ @@ -51,12 +51,12 @@ class GrassBlock extends SolidBlock{ $x = $x + mt_rand(0, 2) - 1; $y = $y + mt_rand(0, 4) - 3; $z = $z + mt_rand(0, 2) - 1; - + $blockUp = $level->level->getBlockID($x, $y + 1, $z); if(StaticBlock::getIsTransparent($blockUp) && !StaticBlock::getIsLiquid($blockUp) && !($blockUp === 60) && $level->level->getBlockID($x, $y, $z) === DIRT){ $level->fastSetBlockUpdate($x, $y, $z, GRASS, 0); } - + } } } diff --git a/src/material/block/solid/GravelBlock.php b/src/material/block/solid/GravelBlock.php index f35adb53..144792f3 100644 --- a/src/material/block/solid/GravelBlock.php +++ b/src/material/block/solid/GravelBlock.php @@ -6,11 +6,11 @@ class GravelBlock extends FallableBlock{ parent::__construct(GRAVEL, 0, "Gravel"); $this->hardness = 3; } - + public function getDrops(Item $item, Player $player){ return [ [mt_rand(1,10) == 1 ? FLINT : GRAVEL, 0, 1], ]; } - + } \ No newline at end of file diff --git a/src/material/block/solid/HayBaleBlock.php b/src/material/block/solid/HayBaleBlock.php index 869eebe5..dd6d52a8 100644 --- a/src/material/block/solid/HayBaleBlock.php +++ b/src/material/block/solid/HayBaleBlock.php @@ -6,16 +6,16 @@ class HayBaleBlock extends SolidBlock{ parent::__construct(HAY_BALE, $meta, "Hay Bale"); $this->hardness = 10; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $faces = array( + $faces = [ 0 => 0, 1 => 0, 2 => 0b1000, 3 => 0b1000, 4 => 0b0100, 5 => 0b0100, - ); + ]; $this->meta = ($this->meta & 0x03) | $faces[$face]; $this->level->setBlock($block, $this, true, false, true); @@ -23,9 +23,9 @@ class HayBaleBlock extends SolidBlock{ } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } - + } \ No newline at end of file diff --git a/src/material/block/solid/IceBlock.php b/src/material/block/solid/IceBlock.php index e5e7860d..28701ad6 100644 --- a/src/material/block/solid/IceBlock.php +++ b/src/material/block/solid/IceBlock.php @@ -7,17 +7,17 @@ class IceBlock extends TransparentBlock{ $this->hardness = 2.5; $this->slipperiness = 0.98; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $ret = $this->level->setBlock($this, $this, true, false, true); $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); return $ret; } - + public function onBreak(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0){ $this->level->setBlock($this, new WaterBlock(), true, false, true); @@ -27,20 +27,20 @@ class IceBlock extends TransparentBlock{ } return true; } - - private function scanForNearbyLightSources($offsetX, $offsetY, $offsetZ){ + + private function scanForNearbyLightSources($offsetX, $offsetY, $offsetZ){ for($x = -$offsetX; $x <= $offsetX; ++$x){ //i hope it is possible to optimize it for($z = -$offsetZ; $z <= $offsetZ; ++$z){ for($y = -$offsetY; $y <= $offsetY; ++$y){ - $pX = $this->x+$x; - $pY = $this->y+$y; - $pZ = $this->z+$z; + $pX = $this->x + $x; + $pY = $this->y + $y; + $pZ = $this->z + $z; $block = $this->level->getBlock(new Vector3($pX, $pY, $pZ)); //D= slow what was u thinking of gameherobrine from 2022 if($block instanceof LightingBlock){ //idk is it possible to make it better return $block; } - } - } + } + } } } //public static function onUpdate(Level $level, $x, $y, $z, $type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/ @@ -69,6 +69,6 @@ class IceBlock extends TransparentBlock{ } public function getDrops(Item $item, Player $player){ - return array(); + return []; } } diff --git a/src/material/block/solid/InfoUpdate2Block.php b/src/material/block/solid/InfoUpdate2Block.php index 0497b861..1d9a45ea 100755 --- a/src/material/block/solid/InfoUpdate2Block.php +++ b/src/material/block/solid/InfoUpdate2Block.php @@ -7,5 +7,5 @@ class InfoUpdate2Block extends SolidBlock{ $this->breakable = true; $this->hardness = 0; } - + } \ No newline at end of file diff --git a/src/material/block/solid/InfoUpdateBlock.php b/src/material/block/solid/InfoUpdateBlock.php index 8b088190..81af7276 100755 --- a/src/material/block/solid/InfoUpdateBlock.php +++ b/src/material/block/solid/InfoUpdateBlock.php @@ -7,5 +7,5 @@ class InfoUpdateBlock extends SolidBlock{ $this->breakable = true; $this->hardness = 0; } - + } \ No newline at end of file diff --git a/src/material/block/solid/InvisibleBedrockBlock.php b/src/material/block/solid/InvisibleBedrockBlock.php index dede980e..2fd0843d 100755 --- a/src/material/block/solid/InvisibleBedrockBlock.php +++ b/src/material/block/solid/InvisibleBedrockBlock.php @@ -7,12 +7,12 @@ class InvisibleBedrockBlock extends SolidBlock{ $this->breakable = false; $this->hardness = 3600000; } - + public function isBreakable(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return true; } return false; } - + } \ No newline at end of file diff --git a/src/material/block/solid/IronBlock.php b/src/material/block/solid/IronBlock.php index 504b94a1..5db4b364 100644 --- a/src/material/block/solid/IronBlock.php +++ b/src/material/block/solid/IronBlock.php @@ -18,14 +18,14 @@ class IronBlock extends SolidBlock{ default => 25, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 3){ - return array( - array(IRON_BLOCK, 0, 1), - ); + return [ + [IRON_BLOCK, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/LapisBlock.php b/src/material/block/solid/LapisBlock.php index 1d4c4dc6..7d0e790c 100644 --- a/src/material/block/solid/LapisBlock.php +++ b/src/material/block/solid/LapisBlock.php @@ -18,14 +18,14 @@ class LapisBlock extends SolidBlock{ default => 15, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 3){ - return array( - array(LAPIS_BLOCK, 0, 1), - ); + return [ + [LAPIS_BLOCK, 0, 1], + ]; }else{ - return array(); + return []; } } diff --git a/src/material/block/solid/LeavesBlock.php b/src/material/block/solid/LeavesBlock.php index 35391300..c4e3dc3e 100644 --- a/src/material/block/solid/LeavesBlock.php +++ b/src/material/block/solid/LeavesBlock.php @@ -7,22 +7,22 @@ class LeavesBlock extends TransparentBlock{ const BIRCH = 2; public function __construct($meta = 0){ parent::__construct(LEAVES, $meta, "Leaves"); - $names = array( + $names = [ LeavesBlock::OAK => "Oak Leaves", LeavesBlock::SPRUCE => "Spruce Leaves", LeavesBlock::BIRCH => "Birch Leaves", 3 => "", - ); + ]; $this->name = $names[$this->meta & 0x03]; $this->hardness = 1; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; } - + public static function createIndex($x, $y, $z){ - return $x.".".$y.".".$z; + return $x . "." . $y . "." . $z; } public static function findLog(Level $level, $x, $y, $z, array $visited, $distance){ //port from newest pocketmine $index = self::createIndex($x, $y, $z); @@ -50,7 +50,7 @@ class LeavesBlock extends TransparentBlock{ $meta = $b[1]; if(($meta & 0b00001100) === 0x08){ $meta &= 0x03; - $visited = array(); + $visited = []; if(!self::findLog($level, $x, $y, $z, $visited, 0)){ //$this->level->setBlock($this, new AirBlock(), false, false, true); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); @@ -72,22 +72,22 @@ class LeavesBlock extends TransparentBlock{ $level->fastSetBlockUpdate($x, $y, $z, $id, $meta); //TODO maybe use $level->level->setBlock directly, the client doesnt need to know thism info. } } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $this->meta |= 0x04; $this->level->setBlock($this, $this, true, false, true); } - + public function getDrops(Item $item, Player $player){ - $drops = array(); + $drops = []; if($item->isShears()){ - $drops[] = array(LEAVES, $this->meta & 0x03, 1); + $drops[] = [LEAVES, $this->meta & 0x03, 1]; }else{ if(mt_rand(1,20) === 1){ //Saplings - $drops[] = array(SAPLING, $this->meta & 0x03, 1); + $drops[] = [SAPLING, $this->meta & 0x03, 1]; } if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,100) === 1){ //Apples - $drops[] = array(APPLE, 0, 1); + $drops[] = [APPLE, 0, 1]; } } return $drops; diff --git a/src/material/block/solid/LitPumpkinBlock.php b/src/material/block/solid/LitPumpkinBlock.php index 6775794a..2edd0c11 100644 --- a/src/material/block/solid/LitPumpkinBlock.php +++ b/src/material/block/solid/LitPumpkinBlock.php @@ -8,17 +8,16 @@ class LitPumpkinBlock extends SolidBlock implements LightingBlock{ 2 => 3, 3 => 0, ]; - - + public function __construct($meta = 0){ parent::__construct(LIT_PUMPKIN, $meta, "Jack o'Lantern"); $this->hardness = 5; } - + public function getMaxLightValue(){ return 15; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $id = $this->level->level->getBlockID($this->x, $this->y, $this->z); if(($id == 0 || $id == SNOW_LAYER) && $this->level->isTopSolidBlocking($this->x, $this->y - 1, $this->z)){ @@ -28,12 +27,11 @@ class LitPumpkinBlock extends SolidBlock implements LightingBlock{ } return false; } - + public function getDrops(Item $item, Player $player){ return [ [JACK_O_LANTERN, 0, 1] ]; } - - -} \ No newline at end of file + + } \ No newline at end of file diff --git a/src/material/block/solid/MelonBlock.php b/src/material/block/solid/MelonBlock.php index 4b46e393..3eaa724e 100644 --- a/src/material/block/solid/MelonBlock.php +++ b/src/material/block/solid/MelonBlock.php @@ -7,11 +7,11 @@ class MelonBlock extends TransparentBlock{ $this->hardness = 5; } public function getDrops(Item $item, Player $player){ - return array( - array(MELON_SLICE, 0, mt_rand(3, 7)), - ); + return [ + [MELON_SLICE, 0, mt_rand(3, 7)], + ]; } - + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; } diff --git a/src/material/block/solid/MossStoneBlock.php b/src/material/block/solid/MossStoneBlock.php index 495de40d..c738c615 100644 --- a/src/material/block/solid/MossStoneBlock.php +++ b/src/material/block/solid/MossStoneBlock.php @@ -20,14 +20,14 @@ class MossStoneBlock extends SolidBlock{ default => 10, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(MOSS_STONE, 0, 1), - ); + return [ + [MOSS_STONE, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/NetherBricksBlock.php b/src/material/block/solid/NetherBricksBlock.php index bf1c7947..8211ad7b 100644 --- a/src/material/block/solid/NetherBricksBlock.php +++ b/src/material/block/solid/NetherBricksBlock.php @@ -20,14 +20,14 @@ class NetherBricksBlock extends SolidBlock{ default => 10, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(NETHER_BRICKS, 0, 1), - ); + return [ + [NETHER_BRICKS, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/NetherrackBlock.php b/src/material/block/solid/NetherrackBlock.php index 4700a083..f93af992 100644 --- a/src/material/block/solid/NetherrackBlock.php +++ b/src/material/block/solid/NetherrackBlock.php @@ -6,7 +6,7 @@ class NetherrackBlock extends SolidBlock{ parent::__construct(NETHERRACK, 0, "Netherrack"); $this->hardness = 2; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -23,11 +23,11 @@ class NetherrackBlock extends SolidBlock{ public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(NETHERRACK, 0, 1), - ); + return [ + [NETHERRACK, 0, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/ObsidianBlock.php b/src/material/block/solid/ObsidianBlock.php index dc0ff733..71453cc2 100644 --- a/src/material/block/solid/ObsidianBlock.php +++ b/src/material/block/solid/ObsidianBlock.php @@ -4,9 +4,9 @@ class ObsidianBlock extends SolidBlock{ public static $blockID; public function __construct(){ parent::__construct(OBSIDIAN, 0, "Obsidian"); - $this->hardness = 6000; + $this->hardness = 6000; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -17,7 +17,7 @@ class ObsidianBlock extends SolidBlock{ return 250; } } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 5){ return [ diff --git a/src/material/block/solid/PlanksBlock.php b/src/material/block/solid/PlanksBlock.php index ed0ba041..2380c10f 100644 --- a/src/material/block/solid/PlanksBlock.php +++ b/src/material/block/solid/PlanksBlock.php @@ -4,14 +4,14 @@ class PlanksBlock extends SolidBlock{ public static $blockID; public function __construct($meta = 0){ parent::__construct(PLANKS, $meta, "Wooden Planks"); - $names = array( + $names = [ WoodBlock::OAK => "Oak Wooden Planks", WoodBlock::SPRUCE => "Spruce Wooden Planks", WoodBlock::BIRCH => "Birch Wooden Planks", WoodBlock::JUNGLE => "Jungle Wooden Planks", - ); + ]; $this->name = $names[$this->meta & 0x03]; $this->hardness = 15; } - + } \ No newline at end of file diff --git a/src/material/block/solid/PumpkinBlock.php b/src/material/block/solid/PumpkinBlock.php index 25239421..cfba83d3 100644 --- a/src/material/block/solid/PumpkinBlock.php +++ b/src/material/block/solid/PumpkinBlock.php @@ -6,17 +6,17 @@ class PumpkinBlock extends SolidBlock{ parent::__construct(PUMPKIN, $meta, "Pumpkin"); $this->hardness = 5; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $faces = array( + $faces = [ 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/block/solid/QuartzBlock.php b/src/material/block/solid/QuartzBlock.php index 1c7bcfb7..7eeb9fb1 100644 --- a/src/material/block/solid/QuartzBlock.php +++ b/src/material/block/solid/QuartzBlock.php @@ -4,12 +4,12 @@ class QuartzBlock extends SolidBlock{ public static $blockID; public function __construct($meta = 0){ parent::__construct(QUARTZ_BLOCK, $meta, "Quartz Block"); - $names = array( + $names = [ 0 => "Quartz Block", 1 => "Chiseled Quartz Block", 2 => "Quartz Pillar", 3 => "Quartz Pillar", - ); + ]; $this->name = $names[$this->meta & 0x03]; } @@ -26,14 +26,14 @@ class QuartzBlock extends SolidBlock{ default => 4, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(QUARTZ_BLOCK, $this->meta & 0x03, 1), - ); + return [ + [QUARTZ_BLOCK, $this->meta & 0x03, 1], + ]; }else{ - return array(); + return []; } } } diff --git a/src/material/block/solid/Reserved6Block.php b/src/material/block/solid/Reserved6Block.php index 1a9d6bd6..65117a4e 100644 --- a/src/material/block/solid/Reserved6Block.php +++ b/src/material/block/solid/Reserved6Block.php @@ -7,5 +7,5 @@ class Reserved6Block extends SolidBlock{ $this->breakable = true; $this->hardness = 0; } - + } \ No newline at end of file diff --git a/src/material/block/solid/SandBlock.php b/src/material/block/solid/SandBlock.php index fa41be00..67f92029 100644 --- a/src/material/block/solid/SandBlock.php +++ b/src/material/block/solid/SandBlock.php @@ -6,5 +6,5 @@ class SandBlock extends FallableBlock{ parent::__construct(SAND, 0, "Sand"); $this->hardness = 2.5; } - + } \ No newline at end of file diff --git a/src/material/block/solid/SandstoneBlock.php b/src/material/block/solid/SandstoneBlock.php index c6533998..790ebe24 100644 --- a/src/material/block/solid/SandstoneBlock.php +++ b/src/material/block/solid/SandstoneBlock.php @@ -4,15 +4,15 @@ class SandstoneBlock extends SolidBlock{ public static $blockID; public function __construct($meta = 0){ parent::__construct(SANDSTONE, $meta, "Sandstone"); - $names = array( + $names = [ 0 => "Sandstone", 1 => "Chiseled Sandstone", 2 => "Smooth Sandstone", - ); - $this->name = $names[$this->meta & 0x03]; + ]; + $this->name = $names[$this->meta & 0x03]; $this->hardness = 4; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -29,12 +29,12 @@ class SandstoneBlock extends SolidBlock{ public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(SANDSTONE, $this->meta & 0x03, 1), - ); + return [ + [SANDSTONE, $this->meta & 0x03, 1], + ]; }else{ - return array(); + return []; } } - + } diff --git a/src/material/block/solid/SnowBlock.php b/src/material/block/solid/SnowBlock.php index 2e024c8f..8fdea37a 100644 --- a/src/material/block/solid/SnowBlock.php +++ b/src/material/block/solid/SnowBlock.php @@ -15,5 +15,5 @@ class SnowBlock extends SolidBlock{ } return []; } - + } \ No newline at end of file diff --git a/src/material/block/solid/SoulSandBlock.php b/src/material/block/solid/SoulSandBlock.php index f5ff6e20..cb4d30aa 100644 --- a/src/material/block/solid/SoulSandBlock.php +++ b/src/material/block/solid/SoulSandBlock.php @@ -6,5 +6,5 @@ class SoulSandBlock extends SolidBlock{ parent::__construct(SOUL_SAND, 0, "Soul Sand"); $this->hardness = 2.5; } - + } \ No newline at end of file diff --git a/src/material/block/solid/SpongeBlock.php b/src/material/block/solid/SpongeBlock.php index 39b4c237..25a7c060 100644 --- a/src/material/block/solid/SpongeBlock.php +++ b/src/material/block/solid/SpongeBlock.php @@ -6,5 +6,5 @@ class SpongeBlock extends SolidBlock{ parent::__construct(SPONGE, 0, "Sponge"); $this->hardness = 3; } - + } diff --git a/src/material/block/solid/StoneBlock.php b/src/material/block/solid/StoneBlock.php index 51504b66..3f56c022 100644 --- a/src/material/block/solid/StoneBlock.php +++ b/src/material/block/solid/StoneBlock.php @@ -20,15 +20,15 @@ class StoneBlock extends SolidBlock{ default => 7.5, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(COBBLESTONE, 0, 1), - ); + return [ + [COBBLESTONE, 0, 1], + ]; }else{ - return array(); + return []; } } - + } diff --git a/src/material/block/solid/StoneBricksBlock.php b/src/material/block/solid/StoneBricksBlock.php index 58299703..741ac21f 100644 --- a/src/material/block/solid/StoneBricksBlock.php +++ b/src/material/block/solid/StoneBricksBlock.php @@ -4,12 +4,12 @@ class StoneBricksBlock extends SolidBlock{ public static $blockID; public function __construct($meta = 0){ parent::__construct(STONE_BRICKS, $meta, "Stone Bricks"); - $names = array( + $names = [ 0 => "Stone Bricks", 1 => "Mossy Stone Bricks", 2 => "Cracked Stone Bricks", 3 => "Chiseled Stone Bricks", - ); + ]; $this->name = $names[$this->meta & 0x03]; $this->hardness = 30; } @@ -27,15 +27,15 @@ class StoneBricksBlock extends SolidBlock{ default => 7.5, }; } - + public function getDrops(Item $item, Player $player){ if($item->getPickaxeLevel() >= 1){ - return array( - array(STONE_BRICKS, $this->meta & 0x03, 1), - ); + return [ + [STONE_BRICKS, $this->meta & 0x03, 1], + ]; }else{ - return array(); + return []; } } - + } diff --git a/src/material/block/solid/StonecutterBlock.php b/src/material/block/solid/StonecutterBlock.php index b5fc3fe7..6a75f9dd 100644 --- a/src/material/block/solid/StonecutterBlock.php +++ b/src/material/block/solid/StonecutterBlock.php @@ -6,7 +6,7 @@ class StonecutterBlock extends SolidBlock{ parent::__construct(STONECUTTER, $meta, "Stonecutter"); $this->isActivable = true; } - + public function onActivate(Item $item, Player $player){ $player->toCraft[-1] = 2; return true; @@ -20,6 +20,6 @@ class StonecutterBlock extends SolidBlock{ }else{ return []; } - - } + + } } \ No newline at end of file diff --git a/src/material/block/solid/WoodBlock.php b/src/material/block/solid/WoodBlock.php index e9711141..369b7483 100644 --- a/src/material/block/solid/WoodBlock.php +++ b/src/material/block/solid/WoodBlock.php @@ -6,28 +6,28 @@ class WoodBlock extends SolidBlock{ const SPRUCE = 1; const BIRCH = 2; const JUNGLE = 3; - + public function __construct($meta = 0){ parent::__construct(WOOD, $meta, "Wood"); - $names = array( + $names = [ WoodBlock::OAK => "Oak Wood", WoodBlock::SPRUCE => "Spruce Wood", WoodBlock::BIRCH => "Birch Wood", WoodBlock::JUNGLE => "Jungle Wood", - ); + ]; $this->name = $names[$this->meta & 0x03]; $this->hardness = 10; } - + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $faces = array( + $faces = [ 0 => 0, 1 => 0, 2 => 0b1000, 3 => 0b1000, 4 => 0b0100, 5 => 0b0100, - ); + ]; $this->meta = ($this->meta & 0x03) | $faces[$face]; $this->level->setBlock($block, $this, true, false, true); @@ -51,8 +51,8 @@ class WoodBlock extends SolidBlock{ } } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, $this->meta & 0x03, 1), - ); + return [ + [$this->id, $this->meta & 0x03, 1], + ]; } } \ No newline at end of file diff --git a/src/material/block/solid/WoolBlock.php b/src/material/block/solid/WoolBlock.php index 3bfb0de8..c4a370e1 100644 --- a/src/material/block/solid/WoolBlock.php +++ b/src/material/block/solid/WoolBlock.php @@ -4,7 +4,7 @@ class WoolBlock extends SolidBlock{ public static $blockID; public function __construct($meta = 0){ parent::__construct(WOOL, $meta, "Wool"); - $names = array( + $names = [ 0 => "White Wool", 1 => "Orange Wool", 2 => "Magenta Wool", @@ -21,9 +21,9 @@ class WoolBlock extends SolidBlock{ 13 => "Green Wool", 14 => "Red Wool", 15 => "Black Wool", - ); + ]; $this->name = $names[$this->meta]; $this->hardness = 4; } - + } \ No newline at end of file diff --git a/src/material/block/solid/WorkbenchBlock.php b/src/material/block/solid/WorkbenchBlock.php index db605a65..ba8720bc 100644 --- a/src/material/block/solid/WorkbenchBlock.php +++ b/src/material/block/solid/WorkbenchBlock.php @@ -7,15 +7,15 @@ class WorkbenchBlock extends SolidBlock{ $this->isActivable = true; $this->hardness = 15; } - + public function onActivate(Item $item, Player $player){ $player->toCraft[-1] = 1; return true; } public function getDrops(Item $item, Player $player){ - return array( - array($this->id, 0, 1), - ); + return [ + [$this->id, 0, 1], + ]; } } \ No newline at end of file diff --git a/src/material/item/armor/ArmorItem.php b/src/material/item/armor/ArmorItem.php index ebb5536d..a9078948 100644 --- a/src/material/item/armor/ArmorItem.php +++ b/src/material/item/armor/ArmorItem.php @@ -1,17 +1,17 @@ getMaterialDurability() * $this->getBaseDurability(); } diff --git a/src/material/item/armor/ChainBootsItem.php b/src/material/item/armor/ChainBootsItem.php index 73083238..afd02dcd 100644 --- a/src/material/item/armor/ChainBootsItem.php +++ b/src/material/item/armor/ChainBootsItem.php @@ -5,11 +5,11 @@ class ChainBootsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(CHAIN_BOOTS, $meta, $count, "Chain Boots"); } - + public function getMaterialDurability(){ return Material::CHAIN; } - + public function getBaseDurability(){ return 13; } @@ -18,5 +18,4 @@ class ChainBootsItem extends ArmorItem{ return 1; } - -} \ No newline at end of file + } \ No newline at end of file diff --git a/src/material/item/armor/ChainChestplateItem.php b/src/material/item/armor/ChainChestplateItem.php index ae28d0c5..19a6d9bd 100644 --- a/src/material/item/armor/ChainChestplateItem.php +++ b/src/material/item/armor/ChainChestplateItem.php @@ -5,11 +5,11 @@ class ChainChestplateItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(CHAIN_CHESTPLATE, $meta, $count, "Chain Chestplate"); } - + public function getMaterialDurability(){ return Material::CHAIN; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/armor/ChainHelmetItem.php b/src/material/item/armor/ChainHelmetItem.php index df7c83d9..b78cb920 100644 --- a/src/material/item/armor/ChainHelmetItem.php +++ b/src/material/item/armor/ChainHelmetItem.php @@ -5,11 +5,11 @@ class ChainHelmetItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(CHAIN_HELMET, $meta, $count, "Chain Helmet"); } - + public function getMaterialDurability(){ return Material::CHAIN; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/ChainLeggingsItem.php b/src/material/item/armor/ChainLeggingsItem.php index 9d1800b1..de13dc83 100644 --- a/src/material/item/armor/ChainLeggingsItem.php +++ b/src/material/item/armor/ChainLeggingsItem.php @@ -5,11 +5,11 @@ class ChainLeggingsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(CHAIN_LEGGINGS, $meta, $count, "Chain Leggings"); } - + public function getMaterialDurability(){ return Material::CHAIN; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/DiamondBootsItem.php b/src/material/item/armor/DiamondBootsItem.php index 4591f9d8..75d8c129 100644 --- a/src/material/item/armor/DiamondBootsItem.php +++ b/src/material/item/armor/DiamondBootsItem.php @@ -5,11 +5,11 @@ class DiamondBootsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(DIAMOND_BOOTS, $meta, $count, "Diamond Boots"); } - + public function getMaterialDurability(){ return Material::DIAMOND; } - + public function getBaseDurability(){ return 13; } diff --git a/src/material/item/armor/DiamondChestplateItem.php b/src/material/item/armor/DiamondChestplateItem.php index fad4edce..3a6b8a05 100644 --- a/src/material/item/armor/DiamondChestplateItem.php +++ b/src/material/item/armor/DiamondChestplateItem.php @@ -5,11 +5,11 @@ class DiamondChestplateItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(DIAMOND_CHESTPLATE, $meta, $count, "Diamond Chestplate"); } - + public function getMaterialDurability(){ return Material::DIAMOND; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/armor/DiamondHelmetItem.php b/src/material/item/armor/DiamondHelmetItem.php index b0e53cbc..514986f0 100644 --- a/src/material/item/armor/DiamondHelmetItem.php +++ b/src/material/item/armor/DiamondHelmetItem.php @@ -5,11 +5,11 @@ class DiamondHelmetItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(DIAMOND_HELMET, $meta, $count, "Diamond Helmet"); } - + public function getMaterialDurability(){ return Material::DIAMOND; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/DiamondLeggingsItem.php b/src/material/item/armor/DiamondLeggingsItem.php index ef2e005d..55eb9356 100644 --- a/src/material/item/armor/DiamondLeggingsItem.php +++ b/src/material/item/armor/DiamondLeggingsItem.php @@ -5,11 +5,11 @@ class DiamondLeggingsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(DIAMOND_LEGGINGS, $meta, $count, "Diamond Leggings"); } - + public function getMaterialDurability(){ return Material::DIAMOND; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/GoldenBootsItem.php b/src/material/item/armor/GoldenBootsItem.php index 1ac0f9a4..8f9b7581 100644 --- a/src/material/item/armor/GoldenBootsItem.php +++ b/src/material/item/armor/GoldenBootsItem.php @@ -5,11 +5,11 @@ class GoldenBootsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(GOLDEN_BOOTS, $meta, $count, "Golden Boots"); } - + public function getMaterialDurability(){ return Material::GOLD; } - + public function getBaseDurability(){ return 13; } diff --git a/src/material/item/armor/GoldenChestplateItem.php b/src/material/item/armor/GoldenChestplateItem.php index 739617b6..05b3aed0 100644 --- a/src/material/item/armor/GoldenChestplateItem.php +++ b/src/material/item/armor/GoldenChestplateItem.php @@ -5,11 +5,11 @@ class GoldenChestplateItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(GOLDEN_CHESTPLATE, $meta, $count, "Golden Chestplate"); } - + public function getMaterialDurability(){ return Material::GOLD; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/armor/GoldenHelmetItem.php b/src/material/item/armor/GoldenHelmetItem.php index c7ee4711..11a94256 100644 --- a/src/material/item/armor/GoldenHelmetItem.php +++ b/src/material/item/armor/GoldenHelmetItem.php @@ -5,11 +5,11 @@ class GoldenHelmetItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(GOLDEN_HELMET, $meta, $count, "Golden Helmet"); } - + public function getMaterialDurability(){ return Material::GOLD; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/GoldenLeggingsItem.php b/src/material/item/armor/GoldenLeggingsItem.php index ee9dd964..d2fb35a0 100644 --- a/src/material/item/armor/GoldenLeggingsItem.php +++ b/src/material/item/armor/GoldenLeggingsItem.php @@ -5,11 +5,11 @@ class GoldenLeggingsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(GOLDEN_LEGGINGS, $meta, $count, "Golden Leggings"); } - + public function getMaterialDurability(){ return Material::GOLD; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/IronBootsItem.php b/src/material/item/armor/IronBootsItem.php index 7f548bb9..6ed18894 100644 --- a/src/material/item/armor/IronBootsItem.php +++ b/src/material/item/armor/IronBootsItem.php @@ -5,11 +5,11 @@ class IronBootsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_BOOTS, $meta, $count, "Iron Boots"); } - + public function getMaterialDurability(){ return Material::IRON; } - + public function getBaseDurability(){ return 13; } diff --git a/src/material/item/armor/IronChestplateItem.php b/src/material/item/armor/IronChestplateItem.php index 05ca1086..d7229d4b 100644 --- a/src/material/item/armor/IronChestplateItem.php +++ b/src/material/item/armor/IronChestplateItem.php @@ -5,11 +5,11 @@ class IronChestplateItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_CHESTPLATE, $meta, $count, "Iron Chestplate"); } - + public function getMaterialDurability(){ return Material::IRON; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/armor/IronHelmetItem.php b/src/material/item/armor/IronHelmetItem.php index 70c85f5e..78300ed4 100644 --- a/src/material/item/armor/IronHelmetItem.php +++ b/src/material/item/armor/IronHelmetItem.php @@ -5,11 +5,11 @@ class IronHelmetItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_HELMET, $meta, $count, "Iron Helmet"); } - + public function getMaterialDurability(){ return Material::IRON; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/IronLeggingsItem.php b/src/material/item/armor/IronLeggingsItem.php index f646899d..a7734651 100644 --- a/src/material/item/armor/IronLeggingsItem.php +++ b/src/material/item/armor/IronLeggingsItem.php @@ -5,11 +5,11 @@ class IronLeggingsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_LEGGINGS, $meta, $count, "Iron Leggings"); } - + public function getMaterialDurability(){ return Material::IRON; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/LeatherBootsItem.php b/src/material/item/armor/LeatherBootsItem.php index 6ec78a24..8bbf9ed5 100644 --- a/src/material/item/armor/LeatherBootsItem.php +++ b/src/material/item/armor/LeatherBootsItem.php @@ -5,11 +5,11 @@ class LeatherBootsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(LEATHER_BOOTS, $meta, $count, "Leather Boots"); } - + public function getMaterialDurability(){ return Material::LEATHER; } - + public function getBaseDurability(){ return 13; } diff --git a/src/material/item/armor/LeatherCapItem.php b/src/material/item/armor/LeatherCapItem.php index 9a146839..2950c741 100755 --- a/src/material/item/armor/LeatherCapItem.php +++ b/src/material/item/armor/LeatherCapItem.php @@ -5,11 +5,11 @@ class LeatherCapItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(LEATHER_CAP, $meta, $count, "Leather Cap"); } - + public function getMaterialDurability(){ return Material::LEATHER; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/LeatherPantsItem.php b/src/material/item/armor/LeatherPantsItem.php index 4fc3bc74..a1ad3b88 100644 --- a/src/material/item/armor/LeatherPantsItem.php +++ b/src/material/item/armor/LeatherPantsItem.php @@ -5,11 +5,11 @@ class LeatherPantsItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(LEATHER_PANTS, $meta, $count, "Leather Pants"); } - + public function getMaterialDurability(){ return Material::LEATHER; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/LeatherTunicItem.php b/src/material/item/armor/LeatherTunicItem.php index ceaa939a..2be71577 100644 --- a/src/material/item/armor/LeatherTunicItem.php +++ b/src/material/item/armor/LeatherTunicItem.php @@ -5,11 +5,11 @@ class LeatherTunicItem extends ArmorItem{ public function __construct($meta = 0, $count = 1){ parent::__construct(LEATHER_TUNIC, $meta, $count, "Leather Tunic"); } - + public function getMaterialDurability(){ return Material::LEATHER; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/base/ItemAxe.php b/src/material/item/base/ItemAxe.php index 5efc1d5b..d911950f 100644 --- a/src/material/item/base/ItemAxe.php +++ b/src/material/item/base/ItemAxe.php @@ -5,7 +5,7 @@ abstract class ItemAxe extends ItemTool public function isAxe(){ return true; } - + public function getLevel(){ return match ($this->id) { WOODEN_AXE => 1, diff --git a/src/material/item/base/ItemHoe.php b/src/material/item/base/ItemHoe.php index 277b75fb..09675cca 100644 --- a/src/material/item/base/ItemHoe.php +++ b/src/material/item/base/ItemHoe.php @@ -5,7 +5,7 @@ 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++; diff --git a/src/material/item/base/ItemPickaxe.php b/src/material/item/base/ItemPickaxe.php index 91666c54..87ed2025 100644 --- a/src/material/item/base/ItemPickaxe.php +++ b/src/material/item/base/ItemPickaxe.php @@ -2,7 +2,7 @@ abstract class ItemPickaxe extends ItemTool { - + public function isTool(){ return true; } diff --git a/src/material/item/base/ItemTool.php b/src/material/item/base/ItemTool.php index e5a3af25..8875cca6 100644 --- a/src/material/item/base/ItemTool.php +++ b/src/material/item/base/ItemTool.php @@ -7,15 +7,15 @@ abstract class ItemTool extends Item const STONE_LEVEL = 3; const IRON_LEVEL = 4; const DIAMOND_LEVEL = 5; - + public function isTool(){ return true; } public function useOn($object, $force = false){ - + if($this->isSword() && !($object instanceof Entity)){ $this->meta += 2; - }else if(($object instanceof Entity) && !$this->isSword()){ + }elseif(($object instanceof Entity) && !$this->isSword()){ $this->meta += 2; }else{ $this->meta++; diff --git a/src/material/item/food/CookedPorkchopItem.php b/src/material/item/food/CookedPorkchopItem.php index 6e5fe0fa..9c12d603 100644 --- a/src/material/item/food/CookedPorkchopItem.php +++ b/src/material/item/food/CookedPorkchopItem.php @@ -4,5 +4,5 @@ class CookedPorkchopItem extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(COOKED_PORKCHOP, 0, $count, "Cooked Porkchop"); } - + } \ No newline at end of file diff --git a/src/material/item/food/PotatoItem.php b/src/material/item/food/PotatoItem.php index 9aaa46a1..5ca017cc 100755 --- a/src/material/item/food/PotatoItem.php +++ b/src/material/item/food/PotatoItem.php @@ -5,5 +5,5 @@ class PotatoItem extends Item{ $this->block = BlockAPI::get(POTATO_BLOCK); parent::__construct(POTATO, 0, $count, "Potato"); } - + } \ No newline at end of file diff --git a/src/material/item/generic/BoneItem.php b/src/material/item/generic/BoneItem.php index 3a30ebfa..098c0803 100755 --- a/src/material/item/generic/BoneItem.php +++ b/src/material/item/generic/BoneItem.php @@ -4,5 +4,5 @@ class BoneItem extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(BONE, 0, $count, "Bone"); } - + } \ No newline at end of file diff --git a/src/material/item/generic/BucketItem.php b/src/material/item/generic/BucketItem.php index 79e9d765..18823a31 100644 --- a/src/material/item/generic/BucketItem.php +++ b/src/material/item/generic/BucketItem.php @@ -1,24 +1,24 @@ "Bucket", 1 => "Milk Bucket", 8 => "Water Bucket", 10 => "Lava Bucket" - ); + ]; public function __construct($meta = 0, $count = 1){ parent::__construct(BUCKET, $meta, $count, "Bucket"); $this->isActivable = true; $this->maxStackSize = 16; $this->name = BucketItem::$possiblenames[$this->meta]; } - + public function getMaxStackSize(){ if($this->getMetadata() == 0) return 16; return 1; } - + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($this->meta === AIR){ if($target instanceof LiquidBlock && $target->getMetadata() == 0){ diff --git a/src/material/item/generic/DyeItem.php b/src/material/item/generic/DyeItem.php index 10ca822e..e2630745 100755 --- a/src/material/item/generic/DyeItem.php +++ b/src/material/item/generic/DyeItem.php @@ -3,7 +3,7 @@ class DyeItem extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(DYE, $meta, $count, "Dye"); - $names = array( + $names = [ 0 => "Inc Sac", 1 => "Rose Red", 2 => "Cactus Green", @@ -20,7 +20,7 @@ class DyeItem extends Item{ 13 => "Magenta Dye", 14 => "Orange Dye", 15 => "Bone Meal", - ); + ]; $this->name = $names[$this->meta]; } } \ No newline at end of file diff --git a/src/material/item/generic/MinecartItem.php b/src/material/item/generic/MinecartItem.php index b8923748..d3807928 100755 --- a/src/material/item/generic/MinecartItem.php +++ b/src/material/item/generic/MinecartItem.php @@ -12,8 +12,8 @@ class MinecartItem extends Item{ } $server = ServerAPI::request(); $data = [ - "x" => $target->getX() + 0.5, - "y" => $target->getY() + 0.5, + "x" => $target->getX() + 0.5, + "y" => $target->getY() + 0.5, "z" => $target->getZ() + 0.5, ]; $e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_MINECART, $data); diff --git a/src/material/item/generic/PaintingItem.php b/src/material/item/generic/PaintingItem.php index 4ce688c8..f8e134be 100644 --- a/src/material/item/generic/PaintingItem.php +++ b/src/material/item/generic/PaintingItem.php @@ -5,44 +5,44 @@ class PaintingItem extends Item{ parent::__construct(PAINTING, 0, $count, "Painting"); $this->isActivable = true; } - public static $motives = array( + public static $motives = [ // Motive Width Height - "Kebab" => array(1, 1), - "Aztec" => array(1, 1), - "Alban" => array(1, 1), - "Aztec2" => array(1, 1), - "Bomb" => array(1, 1), - "Plant" => array(1, 1), - "Wasteland" => array(1, 1), - "Wanderer" => array(1, 2), - "Graham" => array(1, 2), - "Pool" => array(2, 1), - "Courbet" => array(2, 1), - "Sunset" => array(2, 1), - "Sea" => array(2, 1), - "Creebet" => array(2, 1), - "Match" => array(2, 2), - "Bust" => array(2, 2), - "Stage" => array(2, 2), - "Void" => array(2, 2), - "SkullAndRoses" => array(2, 2), + "Kebab" => [1, 1], + "Aztec" => [1, 1], + "Alban" => [1, 1], + "Aztec2" => [1, 1], + "Bomb" => [1, 1], + "Plant" => [1, 1], + "Wasteland" => [1, 1], + "Wanderer" => [1, 2], + "Graham" => [1, 2], + "Pool" => [2, 1], + "Courbet" => [2, 1], + "Sunset" => [2, 1], + "Sea" => [2, 1], + "Creebet" => [2, 1], + "Match" => [2, 2], + "Bust" => [2, 2], + "Stage" => [2, 2], + "Void" => [2, 2], + "SkullAndRoses" => [2, 2], //"Wither" => array(2, 2), - "Fighters" => array(4, 2), - "Skeleton" => array(4, 3), - "DonkeyKong" => array(4, 3), - "Pointer" => array(4, 4), - "Pigscene" => array(4, 4), - "BurningSkull" => array(4, 4), - ); - private static $direction = array(2, 0, 1, 3); - private static $right = array(4, 5, 3, 2); - + "Fighters" => [4, 2], + "Skeleton" => [4, 3], + "DonkeyKong" => [4, 3], + "Pointer" => [4, 4], + "Pigscene" => [4, 4], + "BurningSkull" => [4, 4], + ]; + private static $direction = [2, 0, 1, 3]; + private static $right = [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){ $server = ServerAPI::request(); - + if($face < 2 || $face > 5) return; - $data = array( + $data = [ "x" => $target->x, "y" => $target->y, "z" => $target->z, @@ -55,8 +55,8 @@ class PaintingItem extends Item{ "xPos" => $target->x, "yPos" => $target->y, "zPos" => $target->z, - ); - + ]; + $painting = new Painting($level, 0, ENTITY_OBJECT, OBJECT_PAINTING, $data); if(!$painting->isValid){ $player->sendInventory(); //force resync diff --git a/src/material/item/generic/SpawnEggItem.php b/src/material/item/generic/SpawnEggItem.php index f41e9a01..7d755b4f 100644 --- a/src/material/item/generic/SpawnEggItem.php +++ b/src/material/item/generic/SpawnEggItem.php @@ -6,19 +6,19 @@ class SpawnEggItem extends Item{ $this->meta = $meta; $this->isActivable = true; } - + 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( + $data = [ "x" => $block->x + 0.5, "y" => $block->y, "z" => $block->z + 0.5, "IsBaby" => $ageable ? mt_rand(0, 5) == 0 ? 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; + --$this->count; } return true; } diff --git a/src/material/item/tool/CompassItem.php b/src/material/item/tool/CompassItem.php index 9c2e1f83..f462f941 100755 --- a/src/material/item/tool/CompassItem.php +++ b/src/material/item/tool/CompassItem.php @@ -5,5 +5,5 @@ class CompassItem extends Item{ parent::__construct(COMPASS, 0, $count, "Compass"); $this->maxStackSize = 1; } - + } \ No newline at end of file diff --git a/src/material/item/tool/DiamondAxeItem.php b/src/material/item/tool/DiamondAxeItem.php index 7cb03b24..f602c05b 100644 --- a/src/material/item/tool/DiamondAxeItem.php +++ b/src/material/item/tool/DiamondAxeItem.php @@ -4,7 +4,7 @@ class DiamondAxeItem extends ItemAxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(DIAMOND_AXE, $meta, $count, "Diamond Axe"); } - + public function getDamageAgainstOf($e){ return 6; } diff --git a/src/material/item/tool/DiamondPickaxeItem.php b/src/material/item/tool/DiamondPickaxeItem.php index b90fc882..608f26fc 100644 --- a/src/material/item/tool/DiamondPickaxeItem.php +++ b/src/material/item/tool/DiamondPickaxeItem.php @@ -4,7 +4,7 @@ class DiamondPickaxeItem extends ItemPickaxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(DIAMOND_PICKAXE, $meta, $count, "Diamond Pickaxe"); } - + public function getDamageAgainstOf($e){ return 5; } diff --git a/src/material/item/tool/FlintSteelItem.php b/src/material/item/tool/FlintSteelItem.php index 134b160a..9de35dbb 100644 --- a/src/material/item/tool/FlintSteelItem.php +++ b/src/material/item/tool/FlintSteelItem.php @@ -6,19 +6,19 @@ class FlintSteelItem extends ItemTool{ $this->isActivable = true; $this->maxStackSize = 1; } - + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){ $player->setSlot($player->slot, new Item(AIR, 0, 0), false); } - + if($block->getID() === AIR && $target->isSolid){ $level->fastSetBlockUpdate($block->x, $block->y, $block->z, FIRE, 0, true); return true; } return false; } - + public function useOn($object, $force = false){ ++$this->meta; return true; diff --git a/src/material/item/tool/GoldenPickaxeItem.php b/src/material/item/tool/GoldenPickaxeItem.php index 7f0b2cb6..a8d41066 100755 --- a/src/material/item/tool/GoldenPickaxeItem.php +++ b/src/material/item/tool/GoldenPickaxeItem.php @@ -4,7 +4,7 @@ class GoldenPickaxeItem extends ItemPickaxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(GOLDEN_PICKAXE, $meta, $count, "Golden Pickaxe"); } - + public function getDamageAgainstOf($e){ return 2; } diff --git a/src/material/item/tool/IronAxeItem.php b/src/material/item/tool/IronAxeItem.php index d8c5dc86..3a374466 100644 --- a/src/material/item/tool/IronAxeItem.php +++ b/src/material/item/tool/IronAxeItem.php @@ -4,7 +4,7 @@ class IronAxeItem extends ItemAxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_AXE, $meta, $count, "Iron Axe"); } - + public function getDamageAgainstOf($e){ return 5; } diff --git a/src/material/item/tool/IronPickaxeItem.php b/src/material/item/tool/IronPickaxeItem.php index 620e5ea4..0e6332a2 100644 --- a/src/material/item/tool/IronPickaxeItem.php +++ b/src/material/item/tool/IronPickaxeItem.php @@ -4,7 +4,7 @@ class IronPickaxeItem extends ItemPickaxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_PICKAXE, $meta, $count, "Iron Pickaxe"); } - + public function getDamageAgainstOf($e){ return 4; } diff --git a/src/material/item/tool/IronShovelItem.php b/src/material/item/tool/IronShovelItem.php index 321a714f..6f4cffda 100644 --- a/src/material/item/tool/IronShovelItem.php +++ b/src/material/item/tool/IronShovelItem.php @@ -4,7 +4,7 @@ class IronShovelItem extends ItemShovel{ public function __construct($meta = 0, $count = 1){ parent::__construct(IRON_SHOVEL, $meta, $count, "Iron Shovel"); } - + public function getDamageAgainstOf($e){ return 3; } diff --git a/src/material/item/tool/ShearsItem.php b/src/material/item/tool/ShearsItem.php index 059ede72..53ff3a11 100755 --- a/src/material/item/tool/ShearsItem.php +++ b/src/material/item/tool/ShearsItem.php @@ -4,7 +4,7 @@ class ShearsItem extends ItemTool{ public function __construct($meta = 0, $count = 1){ parent::__construct(SHEARS, $meta, $count, "Shears"); } - + public function useOn($object, $force = false){ if(($object instanceof Sheep) and $this->id === SHEARS){ $this->meta++; diff --git a/src/material/item/tool/StoneAxeItem.php b/src/material/item/tool/StoneAxeItem.php index b3f948f7..791e26f3 100644 --- a/src/material/item/tool/StoneAxeItem.php +++ b/src/material/item/tool/StoneAxeItem.php @@ -4,7 +4,7 @@ class StoneAxeItem extends ItemAxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(STONE_AXE, $meta, $count, "Stone Axe"); } - + public function getDamageAgainstOf($e){ return 4; } diff --git a/src/material/item/tool/StonePickaxeItem.php b/src/material/item/tool/StonePickaxeItem.php index d7428123..22890581 100644 --- a/src/material/item/tool/StonePickaxeItem.php +++ b/src/material/item/tool/StonePickaxeItem.php @@ -4,7 +4,7 @@ class StonePickaxeItem extends ItemPickaxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(STONE_PICKAXE, $meta, $count, "Stone Pickaxe"); } - + public function getDamageAgainstOf($e){ return 3; } diff --git a/src/material/item/tool/StoneShovelItem.php b/src/material/item/tool/StoneShovelItem.php index c23e42c6..d780f961 100644 --- a/src/material/item/tool/StoneShovelItem.php +++ b/src/material/item/tool/StoneShovelItem.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; } - + } \ No newline at end of file diff --git a/src/material/item/tool/WoodenAxeItem.php b/src/material/item/tool/WoodenAxeItem.php index c5f5f49d..b573d1bf 100644 --- a/src/material/item/tool/WoodenAxeItem.php +++ b/src/material/item/tool/WoodenAxeItem.php @@ -4,7 +4,7 @@ class WoodenAxeItem extends ItemAxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(WOODEN_AXE, $meta, $count, "Wooden Axe"); } - + public function getDamageAgainstOf($e){ return 3; } diff --git a/src/material/item/tool/WoodenPickaxeItem.php b/src/material/item/tool/WoodenPickaxeItem.php index a6f9fd21..e173e3c6 100644 --- a/src/material/item/tool/WoodenPickaxeItem.php +++ b/src/material/item/tool/WoodenPickaxeItem.php @@ -4,7 +4,7 @@ class WoodenPickaxeItem extends ItemPickaxe{ public function __construct($meta = 0, $count = 1){ parent::__construct(WOODEN_PICKAXE, $meta, $count, "Wooden Pickaxe"); } - + public function getDamageAgainstOf($e){ return 2; } diff --git a/src/math/AxisAlignedBB.php b/src/math/AxisAlignedBB.php index 187700ca..d778842b 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.php @@ -1,4 +1,5 @@ minX = $minX; $this->minY = $minY; @@ -30,7 +31,7 @@ class AxisAlignedBB{ public function addMinMax($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ return new AxisAlignedBB($this->minX + $minX, $this->minY + $minY, $this->minZ + $minZ, $this->maxX + $maxX, $this->maxY + $maxY, $this->maxZ + $maxZ); } - + public function addCoord($x, $y, $z){ $minX = $this->minX; $minY = $this->minY; @@ -169,7 +170,7 @@ class AxisAlignedBB{ return $z; } - + public function intersectsWith(AxisAlignedBB $bb){ return $bb->maxX >= $this->minX && $bb->minX <= $this->maxX && $bb->maxZ >= $this->minZ && $bb->minZ <= $this->maxZ && $bb->maxY >= $this->minY && $bb->minY <= $this->maxY; } @@ -180,7 +181,7 @@ class AxisAlignedBB{ if($y < $this->minY or $y > $this->maxY){ return false; } - + return $z > $this->minZ and $z < $this->maxZ; } public function isXYZInside($x, $y, $z){ @@ -190,7 +191,7 @@ class AxisAlignedBB{ if($y < $this->minY or $y > $this->maxY){ return false; } - + return $z > $this->minZ and $z < $this->maxZ; } public function isVectorInside(Vector3 $vector){ @@ -219,10 +220,8 @@ class AxisAlignedBB{ public function isVectorInXY(Vector3 $vector){ return $vector->x >= $this->minX and $vector->x <= $this->maxX and $vector->y >= $this->minY and $vector->y <= $this->maxY; } - + /** - * @param Vector3 $pos1 - * @param Vector3 $pos2 * @return NULL|MovingObjectPosition */ public function calculateIntercept(Vector3 $pos1, Vector3 $pos2){ @@ -301,9 +300,9 @@ class AxisAlignedBB{ return MovingObjectPosition::fromBlock(0, 0, 0, $f, $vector); } - + public function __toString(){ return "AABB 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/Matrix.php b/src/math/Matrix.php index d2f3b245..8d74c09f 100644 --- a/src/math/Matrix.php +++ b/src/math/Matrix.php @@ -148,7 +148,6 @@ class Matrix implements ArrayAccess{ }; } - //Computation of the determinant of 2x2 and 3x3 matrices public function isSquare(){ diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 03dcb015..eff4b30d 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -2,27 +2,27 @@ class Vector3{ public $x, $y, $z; - + public function __construct($x = 0, $y = 0, $z = 0){ $this->x = $x; $this->y = $y; $this->z = $z; } - + public function setXYZ($x, $y, $z){ $this->x = $x; $this->y = $y; $this->z = $z; } - + public function copy(){ return new Vector3($this->x, $this->y, $this->z); } - + public function toArray(){ return ["x" => $this->x, "y" => $this->y, "z" => $this->z]; } - + public function getFloorX(){ return (int) $this->x; } @@ -104,7 +104,7 @@ class Vector3{ } public function getSide($side, $step = 1){ - return match ((int)$side) { + return match ((int) $side) { 0 => new Vector3($this->x, $this->y - $step, $this->z), 1 => new Vector3($this->x, $this->y + $step, $this->z), 2 => new Vector3($this->x, $this->y, $this->z - $step), @@ -127,7 +127,7 @@ class Vector3{ if($x instanceof Vector3){ return $this->distanceSquared($x->x, $x->y, $x->z); }else{ - return ($this->x - $x)*($this->x - $x) + ($this->y - $y)*($this->y - $y) + ($this->z - $z)*($this->z - $z); + return ($this->x - $x) * ($this->x - $x) + ($this->y - $y) * ($this->y - $y) + ($this->z - $z) * ($this->z - $z); } } @@ -170,21 +170,19 @@ class Vector3{ $this->x * $v->y - $this->y * $v->x ); } - + public static function fromArray($arr){ return new Vector3($arr[0], $arr[1], $arr[2]); } - + public function __toString(){ return "Vector3(x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; } - - + /** * Returns a new vector with x value equal to the second parameter, along the line between this vector and the * passed in vector, or null if not possible. * - * @param Vector3 $v * @param float $x * * @return Vector3 @@ -193,13 +191,13 @@ class Vector3{ $xDiff = $v->x - $this->x; $yDiff = $v->y - $this->y; $zDiff = $v->z - $this->z; - + if(($xDiff * $xDiff) < 0.0000001){ return null; } - + $f = ($x - $this->x) / $xDiff; - + if($f < 0 or $f > 1){ return null; }else{ @@ -209,12 +207,11 @@ class Vector3{ public function getIntermediateWithXValue(Vector3 $v, $y){ return $this->clipX($v, $y); } - + /** * Returns a new vector with y value equal to the second parameter, along the line between this vector and the * passed in vector, or null if not possible. * - * @param Vector3 $v * @param float $y * * @return Vector3 @@ -223,20 +220,20 @@ class Vector3{ $xDiff = $v->x - $this->x; $yDiff = $v->y - $this->y; $zDiff = $v->z - $this->z; - + if(($yDiff * $yDiff) < 0.0000001){ return null; } - + $f = ($y - $this->y) / $yDiff; - + if($f < 0 or $f > 1){ return null; }else{ return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } - + public function getIntermediateWithYValue(Vector3 $v, $y){ return $this->clipY($v, $y); } @@ -244,7 +241,6 @@ class Vector3{ * Returns a new vector with z value equal to the second parameter, along the line between this vector and the * passed in vector, or null if not possible. * - * @param Vector3 $v * @param float $z * * @return Vector3 @@ -253,20 +249,20 @@ class Vector3{ $xDiff = $v->x - $this->x; $yDiff = $v->y - $this->y; $zDiff = $v->z - $this->z; - + if(($zDiff * $zDiff) < 0.0000001){ return null; } - + $f = ($z - $this->z) / $zDiff; - + if($f < 0 or $f > 1){ return null; }else{ return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f); } } - + public function getIntermediateWithZValue(Vector3 $v, $y){ return $this->clipZ($v, $y); } diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index ad91322e..f3c084a9 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -55,7 +55,7 @@ class MinecraftInterface{ $packet = new QueryPacket; $packet->ip = $source; $packet->port = $port; - $packet->buffer =& $buffer; + $packet->buffer = &$buffer; if(EventHandler::callEvent(new PacketReceiveEvent($packet)) === BaseEvent::DENY){ return false; } @@ -64,7 +64,7 @@ class MinecraftInterface{ $packet = new Packet(); $packet->ip = $source; $packet->port = $port; - $packet->buffer =& $buffer; + $packet->buffer = &$buffer; EventHandler::callEvent(new PacketReceiveEvent($packet)); return false; } diff --git a/src/network/RCON.php b/src/network/RCON.php index 60f41149..9492cc57 100644 --- a/src/network/RCON.php +++ b/src/network/RCON.php @@ -10,7 +10,7 @@ class RCON{ * @var Array[RCONInstance] */ private $workers; - + private $socket, $password, $threads, $clientsPerThread; public function __construct($password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){ @@ -83,7 +83,7 @@ class RCONInstance extends Thread{ $this->maxClients = (int) $maxClients; $this->start(); } - + public function close(){ $this->stop = true; } @@ -108,7 +108,7 @@ class RCONInstance extends Thread{ }else{ socket_set_nonblock($client); socket_set_option($client, SOL_SOCKET, SO_KEEPALIVE, 1); - + $id = $nextClientId++; $clients[$id] = $client; $authenticated[$id] = false; @@ -121,7 +121,7 @@ class RCONInstance extends Thread{ $disconnect[$id] = $sock; continue; } - + switch($packetType){ case 3: //Login if($authenticated[$id]){ @@ -160,19 +160,18 @@ class RCONInstance extends Thread{ } } } - + foreach($authenticated as $id => $status){ if(!isset($disconnect[$id]) and !$authenticated[$id] and $timeouts[$id] < microtime(true)){ //Timeout $disconnect[$id] = $clients[$id]; } } - + foreach($disconnect as $id => $client){ $this->disconnectClient($client); unset($clients[$id], $authenticated[$id], $timeouts[$id]); } - - + } foreach($clients as $client){ $this->disconnectClient($client); @@ -180,7 +179,7 @@ class RCONInstance extends Thread{ unset($this->socket, $this->cmd, $this->response, $this->stop); exit(0); } - + private function disconnectClient($client){ socket_getpeername($client, $ip, $port); @socket_set_option($client, SOL_SOCKET, SO_LINGER, ["l_onoff" => 1, "l_linger" => 1]); @@ -190,7 +189,7 @@ class RCONInstance extends Thread{ @socket_close($client); console("Disconnected client: /$ip:$port"); } - + private function readPacket($client, &$size, &$requestID, &$packetType, &$payload){ @socket_set_nonblock($client); $d = @socket_read($client, 4); diff --git a/src/network/UDPSocket.php b/src/network/UDPSocket.php index 15cf0b3c..772df211 100644 --- a/src/network/UDPSocket.php +++ b/src/network/UDPSocket.php @@ -3,7 +3,7 @@ class UDPSocket{ public $connected, $sock, $server, $port; - + function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){ $this->server = $server; $this->port = $port; diff --git a/src/network/protocol/ProtocolInfo.php b/src/network/protocol/ProtocolInfo.php index fc6c6b8f..e20f7461 100644 --- a/src/network/protocol/ProtocolInfo.php +++ b/src/network/protocol/ProtocolInfo.php @@ -1,6 +1,5 @@ reset(); $this->putInt($this->eid); @@ -28,9 +28,9 @@ class AddEntityPacket extends RakNetDataPacket{ $this->putFloat($this->z); $this->putInt($this->did); if($this->did > 0){ - $this->putShort((int)($this->speedX * 8000)); - $this->putShort((int)($this->speedY * 8000)); - $this->putShort((int)($this->speedZ * 8000)); + $this->putShort((int) ($this->speedX * 8000)); + $this->putShort((int) ($this->speedY * 8000)); + $this->putShort((int) ($this->speedZ * 8000)); } } diff --git a/src/network/protocol/packet/AddItemEntityPacket.php b/src/network/protocol/packet/AddItemEntityPacket.php index fb68f60a..60cd6143 100644 --- a/src/network/protocol/packet/AddItemEntityPacket.php +++ b/src/network/protocol/packet/AddItemEntityPacket.php @@ -9,15 +9,15 @@ class AddItemEntityPacket extends RakNetDataPacket{ public $yaw; public $pitch; public $roll; - + public function pid(){ return ProtocolInfo::ADD_ITEM_ENTITY_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/AddMobPacket.php b/src/network/protocol/packet/AddMobPacket.php index 5b2d9a90..4a469196 100644 --- a/src/network/protocol/packet/AddMobPacket.php +++ b/src/network/protocol/packet/AddMobPacket.php @@ -9,15 +9,15 @@ class AddMobPacket extends RakNetDataPacket{ public $pitch; public $yaw; public $metadata; - + public function pid(){ return ProtocolInfo::ADD_MOB_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/AddPaintingPacket.php b/src/network/protocol/packet/AddPaintingPacket.php index bd50ab0a..96d8af2f 100644 --- a/src/network/protocol/packet/AddPaintingPacket.php +++ b/src/network/protocol/packet/AddPaintingPacket.php @@ -7,15 +7,15 @@ class AddPaintingPacket extends RakNetDataPacket{ public $z; public $direction; public $title; - + public function pid(){ return ProtocolInfo::ADD_PAINTING_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/AddPlayerPacket.php b/src/network/protocol/packet/AddPlayerPacket.php index 044f119a..709c1a30 100644 --- a/src/network/protocol/packet/AddPlayerPacket.php +++ b/src/network/protocol/packet/AddPlayerPacket.php @@ -23,15 +23,15 @@ class AddPlayerPacket extends RakNetDataPacket{ *@var array */ public $metadata; - + public function pid(){ return ProtocolInfo::ADD_PLAYER_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putLong($this->clientID); diff --git a/src/network/protocol/packet/AdventureSettingsPacket.php b/src/network/protocol/packet/AdventureSettingsPacket.php index b395975c..9cf23907 100644 --- a/src/network/protocol/packet/AdventureSettingsPacket.php +++ b/src/network/protocol/packet/AdventureSettingsPacket.php @@ -2,15 +2,15 @@ class AdventureSettingsPacket extends RakNetDataPacket{ public $flags; - + public function pid(){ return ProtocolInfo::ADVENTURE_SETTINGS_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->flags); diff --git a/src/network/protocol/packet/AnimatePacket.php b/src/network/protocol/packet/AnimatePacket.php index a8ea6820..3f537d26 100644 --- a/src/network/protocol/packet/AnimatePacket.php +++ b/src/network/protocol/packet/AnimatePacket.php @@ -3,19 +3,19 @@ class AnimatePacket extends RakNetDataPacket{ const ANIM_SWING_HAND = 0x1; const ANIM_STOP_SLEEP = 0x3; - + public $action; public $eid; - + public function pid(){ return ProtocolInfo::ANIMATE_PACKET; } - + public function decode(){ $this->action = $this->getByte(); $this->eid = $this->getInt(); } - + public function encode(){ $this->reset(); $this->putByte($this->action); diff --git a/src/network/protocol/packet/ChatPacket.php b/src/network/protocol/packet/ChatPacket.php index cbe5998a..183bbae3 100644 --- a/src/network/protocol/packet/ChatPacket.php +++ b/src/network/protocol/packet/ChatPacket.php @@ -2,15 +2,15 @@ class ChatPacket extends RakNetDataPacket{ public $message; - + public function pid(){ return ProtocolInfo::CHAT_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putString($this->message); diff --git a/src/network/protocol/packet/ChunkDataPacket.php b/src/network/protocol/packet/ChunkDataPacket.php index 024bebbb..77d61816 100644 --- a/src/network/protocol/packet/ChunkDataPacket.php +++ b/src/network/protocol/packet/ChunkDataPacket.php @@ -4,15 +4,15 @@ class ChunkDataPacket extends RakNetDataPacket{ public $chunkX; public $chunkZ; public $data; - + public function pid(){ return ProtocolInfo::CHUNK_DATA_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->chunkX); diff --git a/src/network/protocol/packet/ClientConnectPacket.php b/src/network/protocol/packet/ClientConnectPacket.php index f4a95243..b71e80e6 100644 --- a/src/network/protocol/packet/ClientConnectPacket.php +++ b/src/network/protocol/packet/ClientConnectPacket.php @@ -8,13 +8,13 @@ class ClientConnectPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::CLIENT_CONNECT_PACKET; } - + public function decode(){ $this->clientID = $this->getLong(); $this->session = $this->getLong(); $this->unknown1 = $this->get(1); - } - + } + public function encode(){ } diff --git a/src/network/protocol/packet/ClientHandshakePacket.php b/src/network/protocol/packet/ClientHandshakePacket.php index 7d807d9c..9cce1aa2 100644 --- a/src/network/protocol/packet/ClientHandshakePacket.php +++ b/src/network/protocol/packet/ClientHandshakePacket.php @@ -13,7 +13,7 @@ class ClientHandshakePacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::CLIENT_HANDSHAKE_PACKET; } - + public function decode(){ $this->cookie = $this->get(4); $this->security = $this->get(1); @@ -23,10 +23,10 @@ class ClientHandshakePacket extends RakNetDataPacket{ $this->timestamp = $this->get(2); $this->session2 = $this->getLong(); $this->session = $this->getLong(); - } - + } + public function encode(){ - + } } \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerClosePacket.php b/src/network/protocol/packet/ContainerClosePacket.php index 008d8097..77623187 100644 --- a/src/network/protocol/packet/ContainerClosePacket.php +++ b/src/network/protocol/packet/ContainerClosePacket.php @@ -2,15 +2,15 @@ class ContainerClosePacket extends RakNetDataPacket{ public $windowid; - + public function pid(){ return ProtocolInfo::CONTAINER_CLOSE_PACKET; } - + public function decode(){ $this->windowid = $this->getByte(); } - + public function encode(){ $this->reset(); $this->putByte($this->windowid); diff --git a/src/network/protocol/packet/ContainerOpenPacket.php b/src/network/protocol/packet/ContainerOpenPacket.php index 92eecd78..b1d8a9df 100644 --- a/src/network/protocol/packet/ContainerOpenPacket.php +++ b/src/network/protocol/packet/ContainerOpenPacket.php @@ -7,15 +7,15 @@ class ContainerOpenPacket extends RakNetDataPacket{ public $x; public $y; public $z; - + public function pid(){ return ProtocolInfo::CONTAINER_OPEN_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putByte($this->windowid); diff --git a/src/network/protocol/packet/ContainerSetContentPacket.php b/src/network/protocol/packet/ContainerSetContentPacket.php index a4afe1db..d27c9b61 100644 --- a/src/network/protocol/packet/ContainerSetContentPacket.php +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -2,13 +2,13 @@ class ContainerSetContentPacket extends RakNetDataPacket{ public $windowid; - public $slots = array(); - public $hotbar = array(); - + public $slots = []; + public $hotbar = []; + public function pid(){ return ProtocolInfo::CONTAINER_SET_CONTENT_PACKET; } - + public function decode(){ $this->windowid = $this->getByte(); $count = $this->getShort(); @@ -22,7 +22,7 @@ class ContainerSetContentPacket extends RakNetDataPacket{ } } } - + public function encode(){ $this->reset(); $this->putByte($this->windowid); diff --git a/src/network/protocol/packet/ContainerSetDataPacket.php b/src/network/protocol/packet/ContainerSetDataPacket.php index 0d93c4e1..f6e4c967 100644 --- a/src/network/protocol/packet/ContainerSetDataPacket.php +++ b/src/network/protocol/packet/ContainerSetDataPacket.php @@ -4,15 +4,15 @@ class ContainerSetDataPacket extends RakNetDataPacket{ public $windowid; public $property; public $value; - + public function pid(){ return ProtocolInfo::CONTAINER_SET_DATA_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putByte($this->windowid); diff --git a/src/network/protocol/packet/ContainerSetSlotPacket.php b/src/network/protocol/packet/ContainerSetSlotPacket.php index fab25153..b258408e 100644 --- a/src/network/protocol/packet/ContainerSetSlotPacket.php +++ b/src/network/protocol/packet/ContainerSetSlotPacket.php @@ -4,17 +4,17 @@ class ContainerSetSlotPacket extends RakNetDataPacket{ public $windowid; public $slot; public $item; - + public function pid(){ return ProtocolInfo::CONTAINER_SET_SLOT_PACKET; } - + public function decode(){ $this->windowid = $this->getByte(); $this->slot = $this->getShort(); $this->item = $this->getSlot(); } - + public function encode(){ $this->reset(); $this->putByte($this->windowid); diff --git a/src/network/protocol/packet/DisconnectPacket.php b/src/network/protocol/packet/DisconnectPacket.php index f0cc9fe8..17a4effb 100644 --- a/src/network/protocol/packet/DisconnectPacket.php +++ b/src/network/protocol/packet/DisconnectPacket.php @@ -4,13 +4,13 @@ class DisconnectPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::DISCONNECT_PACKET; } - + public function decode(){ - } - + } + public function encode(){ - $this->reset(); + $this->reset(); } } \ No newline at end of file diff --git a/src/network/protocol/packet/DropItemPacket.php b/src/network/protocol/packet/DropItemPacket.php index 41531160..12e1acc6 100644 --- a/src/network/protocol/packet/DropItemPacket.php +++ b/src/network/protocol/packet/DropItemPacket.php @@ -4,17 +4,17 @@ class DropItemPacket extends RakNetDataPacket{ public $eid; public $unknown; public $item; - + public function pid(){ return ProtocolInfo::DROP_ITEM_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->unknown = $this->getByte(); $this->item = $this->getSlot(); } - + public function encode(){ } diff --git a/src/network/protocol/packet/EntityDataPacket.php b/src/network/protocol/packet/EntityDataPacket.php index 01b2cafb..e834aa17 100644 --- a/src/network/protocol/packet/EntityDataPacket.php +++ b/src/network/protocol/packet/EntityDataPacket.php @@ -5,18 +5,18 @@ class EntityDataPacket extends RakNetDataPacket{ public $y; public $z; public $namedtag; - + public function pid(){ return ProtocolInfo::ENTITY_DATA_PACKET; } - + public function decode(){ $this->x = $this->getShort(); $this->y = $this->getByte(); $this->z = $this->getShort(); $this->namedtag = $this->get(true); } - + public function encode(){ $this->reset(); $this->putShort($this->x); diff --git a/src/network/protocol/packet/EntityEventPacket.php b/src/network/protocol/packet/EntityEventPacket.php index 05cf7770..24ae3442 100644 --- a/src/network/protocol/packet/EntityEventPacket.php +++ b/src/network/protocol/packet/EntityEventPacket.php @@ -3,25 +3,25 @@ class EntityEventPacket extends RakNetDataPacket{ public $eid; public $event; - + const ENTITY_DAMAGE = 2; const ENTITY_DEAD = 3; const ENTITY_ANIM_10 = 10; - + public function __construct($eid = null, $event = null){ $this->eid = $eid; $this->event = $event; } - + public function pid(){ return ProtocolInfo::ENTITY_EVENT_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->event = $this->getByte(); } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/ExplodePacket.php b/src/network/protocol/packet/ExplodePacket.php index 1d60b72a..4a70d00e 100644 --- a/src/network/protocol/packet/ExplodePacket.php +++ b/src/network/protocol/packet/ExplodePacket.php @@ -6,15 +6,15 @@ class ExplodePacket extends RakNetDataPacket{ public $z; public $radius; public $records; - + public function pid(){ return ProtocolInfo::EXPLODE_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putFloat($this->x); diff --git a/src/network/protocol/packet/HurtArmorPacket.php b/src/network/protocol/packet/HurtArmorPacket.php index e23aac3e..1473c4f7 100644 --- a/src/network/protocol/packet/HurtArmorPacket.php +++ b/src/network/protocol/packet/HurtArmorPacket.php @@ -2,15 +2,15 @@ class HurtArmorPacket extends RakNetDataPacket{ public $health; - + public function pid(){ return ProtocolInfo::HURT_ARMOR_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putByte($this->health); diff --git a/src/network/protocol/packet/InteractPacket.php b/src/network/protocol/packet/InteractPacket.php index 2d33773d..de954ccd 100644 --- a/src/network/protocol/packet/InteractPacket.php +++ b/src/network/protocol/packet/InteractPacket.php @@ -11,13 +11,13 @@ class InteractPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::INTERACT_PACKET; } - + public function decode(){ $this->action = $this->getByte(); $this->eid = $this->getInt(); $this->target = $this->getInt(); } - + public function encode(){ $this->reset(); $this->putByte($this->action); diff --git a/src/network/protocol/packet/LevelEventPacket.php b/src/network/protocol/packet/LevelEventPacket.php index 50727e45..f38304d9 100644 --- a/src/network/protocol/packet/LevelEventPacket.php +++ b/src/network/protocol/packet/LevelEventPacket.php @@ -1,24 +1,24 @@ reset(); $this->putShort($this->evid); diff --git a/src/network/protocol/packet/LoginPacket.php b/src/network/protocol/packet/LoginPacket.php index 34f04955..e5f23dfb 100644 --- a/src/network/protocol/packet/LoginPacket.php +++ b/src/network/protocol/packet/LoginPacket.php @@ -6,21 +6,21 @@ class LoginPacket extends RakNetDataPacket{ public $protocol2; public $clientId; public $loginData; - + public function pid(){ return ProtocolInfo::LOGIN_PACKET; } - + public function decode(){ $this->username = $this->getString(); $this->protocol1 = $this->getInt(); $this->protocol2 = $this->getInt(); $this->clientId = $this->getInt(); $this->loginData = $this->getString(); - } - + } + public function encode(){ - + } } \ No newline at end of file diff --git a/src/network/protocol/packet/LoginStatusPacket.php b/src/network/protocol/packet/LoginStatusPacket.php index bd501917..ef02b0d2 100644 --- a/src/network/protocol/packet/LoginStatusPacket.php +++ b/src/network/protocol/packet/LoginStatusPacket.php @@ -2,15 +2,15 @@ class LoginStatusPacket extends RakNetDataPacket{ public $status; - + public function pid(){ return ProtocolInfo::LOGIN_STATUS_PACKET; } - + public function decode(){ - } - + } + public function encode(){ $this->reset(); $this->putInt($this->status); diff --git a/src/network/protocol/packet/MessagePacket.php b/src/network/protocol/packet/MessagePacket.php index dcb1b0bb..ab29f912 100644 --- a/src/network/protocol/packet/MessagePacket.php +++ b/src/network/protocol/packet/MessagePacket.php @@ -3,16 +3,16 @@ class MessagePacket extends RakNetDataPacket{ public $source; public $message; - + public function pid(){ return ProtocolInfo::MESSAGE_PACKET; } - + public function decode(){ $this->source = $this->getString(); $this->message = $this->getString(); - } - + } + public function encode(){ $this->reset(); $this->putString($this->source); diff --git a/src/network/protocol/packet/MoveEntityPacket.php b/src/network/protocol/packet/MoveEntityPacket.php index be59077c..76f62187 100644 --- a/src/network/protocol/packet/MoveEntityPacket.php +++ b/src/network/protocol/packet/MoveEntityPacket.php @@ -5,11 +5,11 @@ class MoveEntityPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::MOVE_ENTITY_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); } diff --git a/src/network/protocol/packet/MoveEntityPacket_PosRot.php b/src/network/protocol/packet/MoveEntityPacket_PosRot.php index c2143c18..ef92f985 100644 --- a/src/network/protocol/packet/MoveEntityPacket_PosRot.php +++ b/src/network/protocol/packet/MoveEntityPacket_PosRot.php @@ -7,11 +7,11 @@ class MoveEntityPacket_PosRot extends RakNetDataPacket{ public $z; public $yaw; public $pitch; - + public function pid(){ return ProtocolInfo::MOVE_ENTITY_PACKET_POSROT; } - + public function decode(){ $this->get(7); $this->eid = $this->getInt(); @@ -21,7 +21,7 @@ class MoveEntityPacket_PosRot extends RakNetDataPacket{ $this->yaw = $this->getFloat(); $this->pitch = $this->getFloat(); } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/MovePlayerPacket.php b/src/network/protocol/packet/MovePlayerPacket.php index 5325cf76..57d71021 100644 --- a/src/network/protocol/packet/MovePlayerPacket.php +++ b/src/network/protocol/packet/MovePlayerPacket.php @@ -8,11 +8,11 @@ class MovePlayerPacket extends RakNetDataPacket{ public $yaw; public $pitch; public $bodyYaw; - + public function pid(){ return ProtocolInfo::MOVE_PLAYER_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->x = $this->getFloat(); @@ -22,7 +22,7 @@ class MovePlayerPacket extends RakNetDataPacket{ $this->pitch = $this->getFloat(); $this->bodyYaw = $this->getFloat(); } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/PingPacket.php b/src/network/protocol/packet/PingPacket.php index 77e380dc..92eefb03 100644 --- a/src/network/protocol/packet/PingPacket.php +++ b/src/network/protocol/packet/PingPacket.php @@ -6,11 +6,11 @@ class PingPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::PING_PACKET; } - + public function decode(){ $this->time = $this->getLong(); - } - + } + public function encode(){ $this->reset(); $this->putLong($this->time); diff --git a/src/network/protocol/packet/PlayerActionPacket.php b/src/network/protocol/packet/PlayerActionPacket.php index cdcc64ad..2f8cff20 100644 --- a/src/network/protocol/packet/PlayerActionPacket.php +++ b/src/network/protocol/packet/PlayerActionPacket.php @@ -7,11 +7,11 @@ class PlayerActionPacket extends RakNetDataPacket{ public $z; public $face; public $eid; - + public function pid(){ return ProtocolInfo::PLAYER_ACTION_PACKET; } - + public function decode(){ $this->action = $this->getInt(); $this->x = $this->getInt(); @@ -20,7 +20,7 @@ class PlayerActionPacket extends RakNetDataPacket{ $this->face = $this->getInt(); $this->eid = $this->getInt(); } - + public function encode(){ } diff --git a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php index d32be316..faa519f7 100644 --- a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php @@ -2,20 +2,20 @@ class PlayerArmorEquipmentPacket extends RakNetDataPacket{ public $eid; - public $slots = array(); - + public $slots = []; + public function pid(){ return ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET; } - + public function decode(){ - $this->eid = $this->getInt(); + $this->eid = $this->getInt(); $this->slots[0] = $this->getByte(); $this->slots[1] = $this->getByte(); $this->slots[2] = $this->getByte(); $this->slots[3] = $this->getByte(); } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/PlayerEquipmentPacket.php b/src/network/protocol/packet/PlayerEquipmentPacket.php index 06e65fee..b9596f64 100644 --- a/src/network/protocol/packet/PlayerEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerEquipmentPacket.php @@ -5,18 +5,18 @@ class PlayerEquipmentPacket extends RakNetDataPacket{ public $item; public $meta; public $slot; - + public function pid(){ return ProtocolInfo::PLAYER_EQUIPMENT_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->item = $this->getShort(); $this->meta = $this->getShort(); $this->slot = $this->getSignedByte(); } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/PlayerInputPacket.php b/src/network/protocol/packet/PlayerInputPacket.php index f80f18bc..fdc79731 100644 --- a/src/network/protocol/packet/PlayerInputPacket.php +++ b/src/network/protocol/packet/PlayerInputPacket.php @@ -1,9 +1,10 @@ isJumping = $this->getByte() != 0; $this->isSneaking = $this->getByte() != 0; } - + } diff --git a/src/network/protocol/packet/PongPacket.php b/src/network/protocol/packet/PongPacket.php index ab1a1948..ab9da4fa 100644 --- a/src/network/protocol/packet/PongPacket.php +++ b/src/network/protocol/packet/PongPacket.php @@ -7,12 +7,12 @@ class PongPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::PONG_PACKET; } - + public function decode(){ $this->ptime = $this->getLong(); $this->time = $this->getLong(); - } - + } + public function encode(){ $this->reset(); $this->putLong($this->ptime); diff --git a/src/network/protocol/packet/ReadyPacket.php b/src/network/protocol/packet/ReadyPacket.php index 2fa12b5e..08cd53a1 100644 --- a/src/network/protocol/packet/ReadyPacket.php +++ b/src/network/protocol/packet/ReadyPacket.php @@ -2,15 +2,15 @@ class ReadyPacket extends RakNetDataPacket{ public $status; - + public function pid(){ return ProtocolInfo::READY_PACKET; } - + public function decode(){ $this->status = $this->getByte(); - } - + } + public function encode(){ } diff --git a/src/network/protocol/packet/RemoveBlockPacket.php b/src/network/protocol/packet/RemoveBlockPacket.php index d3e3a969..2f77ea64 100644 --- a/src/network/protocol/packet/RemoveBlockPacket.php +++ b/src/network/protocol/packet/RemoveBlockPacket.php @@ -5,18 +5,18 @@ class RemoveBlockPacket extends RakNetDataPacket{ public $x; public $y; public $z; - + public function pid(){ return ProtocolInfo::REMOVE_BLOCK_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->x = $this->getInt(); $this->z = $this->getInt(); $this->y = $this->getByte(); } - + public function encode(){ } diff --git a/src/network/protocol/packet/RemoveEntityPacket.php b/src/network/protocol/packet/RemoveEntityPacket.php index 27d6c42b..edeef1ea 100644 --- a/src/network/protocol/packet/RemoveEntityPacket.php +++ b/src/network/protocol/packet/RemoveEntityPacket.php @@ -6,11 +6,11 @@ class RemoveEntityPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::REMOVE_ENTITY_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/RemovePlayerPacket.php b/src/network/protocol/packet/RemovePlayerPacket.php index f23cd4df..553a46b7 100644 --- a/src/network/protocol/packet/RemovePlayerPacket.php +++ b/src/network/protocol/packet/RemovePlayerPacket.php @@ -3,15 +3,15 @@ class RemovePlayerPacket extends RakNetDataPacket{ public $eid; public $clientID; - + public function pid(){ return ProtocolInfo::REMOVE_PLAYER_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/RequestChunkPacket.php b/src/network/protocol/packet/RequestChunkPacket.php index d0650748..dad75477 100644 --- a/src/network/protocol/packet/RequestChunkPacket.php +++ b/src/network/protocol/packet/RequestChunkPacket.php @@ -3,16 +3,16 @@ class RequestChunkPacket extends RakNetDataPacket{ public $chunkX; public $chunkZ; - + public function pid(){ return ProtocolInfo::REQUEST_CHUNK_PACKET; } - + public function decode(){ $this->chunkX = $this->getInt(); $this->chunkZ = $this->getInt(); } - + public function encode(){ } diff --git a/src/network/protocol/packet/RespawnPacket.php b/src/network/protocol/packet/RespawnPacket.php index 1d3c208e..51c6eab1 100644 --- a/src/network/protocol/packet/RespawnPacket.php +++ b/src/network/protocol/packet/RespawnPacket.php @@ -5,18 +5,18 @@ class RespawnPacket extends RakNetDataPacket{ public $x; public $y; public $z; - + public function pid(){ return ProtocolInfo::RESPAWN_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->x = $this->getFloat(); $this->y = $this->getFloat(); $this->z = $this->getFloat(); } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/RotateHeadPacket.php b/src/network/protocol/packet/RotateHeadPacket.php index 21cc7cf0..3a77c468 100644 --- a/src/network/protocol/packet/RotateHeadPacket.php +++ b/src/network/protocol/packet/RotateHeadPacket.php @@ -13,13 +13,13 @@ class RotateHeadPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::ROTATE_HEAD_PACKET; } - + public function decode(){ $this->get(7); //id + data $this->eid = $this->getInt(); $this->yaw = $this->getByte(); } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/SendInventoryPacket.php b/src/network/protocol/packet/SendInventoryPacket.php index 1bddca97..79b931ea 100644 --- a/src/network/protocol/packet/SendInventoryPacket.php +++ b/src/network/protocol/packet/SendInventoryPacket.php @@ -3,13 +3,13 @@ class SendInventoryPacket extends RakNetDataPacket{ public $eid; public $windowid; - public $slots = array(); - public $armor = array(); - + public $slots = []; + public $armor = []; + public function pid(){ return ProtocolInfo::SEND_INVENTORY_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->windowid = $this->getByte(); @@ -23,7 +23,7 @@ class SendInventoryPacket extends RakNetDataPacket{ } } } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/ServerHandshakePacket.php b/src/network/protocol/packet/ServerHandshakePacket.php index 4931aa23..2b1a9384 100644 --- a/src/network/protocol/packet/ServerHandshakePacket.php +++ b/src/network/protocol/packet/ServerHandshakePacket.php @@ -8,17 +8,17 @@ class ServerHandshakePacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::SERVER_HANDSHAKE_PACKET; } - + public function decode(){ - } - + } + public function encode(){ $this->reset(); $this->put("\x04\x3f\x57\xfe"); //cookie $this->put("\xcd"); //Security flags $this->putShort($this->port); - $this->putDataArray(array( + $this->putDataArray([ "\xf5\xff\xff\xf5", "\xff\xff\xff\xff", "\xff\xff\xff\xff", @@ -29,7 +29,7 @@ class ServerHandshakePacket extends RakNetDataPacket{ "\xff\xff\xff\xff", "\xff\xff\xff\xff", "\xff\xff\xff\xff", - )); + ]); $this->put("\x00\x00"); $this->putLong($this->session); $this->putLong($this->session2); diff --git a/src/network/protocol/packet/SetEntityDataPacket.php b/src/network/protocol/packet/SetEntityDataPacket.php index 8626885d..886721ae 100644 --- a/src/network/protocol/packet/SetEntityDataPacket.php +++ b/src/network/protocol/packet/SetEntityDataPacket.php @@ -3,15 +3,15 @@ class SetEntityDataPacket extends RakNetDataPacket{ public $eid; public $metadata; - + public function pid(){ return ProtocolInfo::SET_ENTITY_DATA_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/SetEntityLinkPacket.php b/src/network/protocol/packet/SetEntityLinkPacket.php index 34de37c1..5c066c82 100644 --- a/src/network/protocol/packet/SetEntityLinkPacket.php +++ b/src/network/protocol/packet/SetEntityLinkPacket.php @@ -21,7 +21,6 @@ class SetEntityLinkPacket extends RakNetDataPacket{ $this->putInt($this->type); } - public function pid(){ return ProtocolInfo::SET_ENTITY_LINK_PACKET; } diff --git a/src/network/protocol/packet/SetEntityMotionPacket.php b/src/network/protocol/packet/SetEntityMotionPacket.php index e4cf70b9..e375fd2c 100644 --- a/src/network/protocol/packet/SetEntityMotionPacket.php +++ b/src/network/protocol/packet/SetEntityMotionPacket.php @@ -5,15 +5,15 @@ class SetEntityMotionPacket extends RakNetDataPacket{ public $speedX; public $speedY; public $speedZ; - + public function pid(){ return ProtocolInfo::SET_ENTITY_MOTION_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/SetHealthPacket.php b/src/network/protocol/packet/SetHealthPacket.php index 42e52f81..0d63fdff 100644 --- a/src/network/protocol/packet/SetHealthPacket.php +++ b/src/network/protocol/packet/SetHealthPacket.php @@ -2,15 +2,15 @@ class SetHealthPacket extends RakNetDataPacket{ public $health; - + public function pid(){ return ProtocolInfo::SET_HEALTH_PACKET; } - + public function decode(){ $this->health = $this->getByte(); } - + public function encode(){ $this->reset(); $this->putByte($this->health); diff --git a/src/network/protocol/packet/SetSpawnPositionPacket.php b/src/network/protocol/packet/SetSpawnPositionPacket.php index 3da187ea..02808bcf 100644 --- a/src/network/protocol/packet/SetSpawnPositionPacket.php +++ b/src/network/protocol/packet/SetSpawnPositionPacket.php @@ -4,15 +4,15 @@ class SetSpawnPositionPacket extends RakNetDataPacket{ public $x; public $z; public $y; - + public function pid(){ return ProtocolInfo::SET_SPAWN_POSITION_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->x); diff --git a/src/network/protocol/packet/SetTimePacket.php b/src/network/protocol/packet/SetTimePacket.php index 302afd9e..6e07e072 100644 --- a/src/network/protocol/packet/SetTimePacket.php +++ b/src/network/protocol/packet/SetTimePacket.php @@ -3,15 +3,15 @@ class SetTimePacket extends RakNetDataPacket{ public $time; public $started = true; - + public function pid(){ return ProtocolInfo::SET_TIME_PACKET; } - + public function decode(){ - } - + } + public function encode(){ $this->reset(); $this->putInt($this->time); diff --git a/src/network/protocol/packet/StartGamePacket.php b/src/network/protocol/packet/StartGamePacket.php index a746ea3a..32aa8990 100644 --- a/src/network/protocol/packet/StartGamePacket.php +++ b/src/network/protocol/packet/StartGamePacket.php @@ -8,15 +8,15 @@ class StartGamePacket extends RakNetDataPacket{ public $x; public $y; public $z; - + public function pid(){ return ProtocolInfo::START_GAME_PACKET; } - + public function decode(){ - } - + } + public function encode(){ $this->reset(); $this->putInt($this->seed); diff --git a/src/network/protocol/packet/TakeItemEntityPacket.php b/src/network/protocol/packet/TakeItemEntityPacket.php index 85221c38..cd0af938 100644 --- a/src/network/protocol/packet/TakeItemEntityPacket.php +++ b/src/network/protocol/packet/TakeItemEntityPacket.php @@ -7,11 +7,11 @@ class TakeItemEntityPacket extends RakNetDataPacket{ public function pid(){ return ProtocolInfo::TAKE_ITEM_ENTITY_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->target); diff --git a/src/network/protocol/packet/TileEventPacket.php b/src/network/protocol/packet/TileEventPacket.php index e2266896..f0d75d37 100644 --- a/src/network/protocol/packet/TileEventPacket.php +++ b/src/network/protocol/packet/TileEventPacket.php @@ -6,15 +6,15 @@ class TileEventPacket extends RakNetDataPacket{ public $z; public $case1; public $case2; - + public function pid(){ return ProtocolInfo::TILE_EVENT_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->x); diff --git a/src/network/protocol/packet/UnknownPacket.php b/src/network/protocol/packet/UnknownPacket.php index 08b89139..d85cb81c 100644 --- a/src/network/protocol/packet/UnknownPacket.php +++ b/src/network/protocol/packet/UnknownPacket.php @@ -2,19 +2,19 @@ class UnknownPacket extends RakNetDataPacket{ public $packetID = -1; - + public function __construct($pid = -1){ $this->packetID = $pid; } - + public function pid(){ return $this->packetID; } - + public function decode(){ } - + public function encode(){ } diff --git a/src/network/protocol/packet/UpdateBlockPacket.php b/src/network/protocol/packet/UpdateBlockPacket.php index 020fc63b..43e3e301 100644 --- a/src/network/protocol/packet/UpdateBlockPacket.php +++ b/src/network/protocol/packet/UpdateBlockPacket.php @@ -6,15 +6,15 @@ class UpdateBlockPacket extends RakNetDataPacket{ public $y; public $block; public $meta; - + public function pid(){ return ProtocolInfo::UPDATE_BLOCK_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->x); diff --git a/src/network/protocol/packet/UseItemPacket.php b/src/network/protocol/packet/UseItemPacket.php index 0136ed5b..94d9ac9f 100644 --- a/src/network/protocol/packet/UseItemPacket.php +++ b/src/network/protocol/packet/UseItemPacket.php @@ -14,11 +14,11 @@ class UseItemPacket extends RakNetDataPacket{ public $posX; public $posY; public $posZ; - + public function pid(){ return ProtocolInfo::USE_ITEM_PACKET; } - + public function decode(){ $this->x = $this->getInt(); $this->y = $this->getInt(); @@ -32,9 +32,9 @@ class UseItemPacket extends RakNetDataPacket{ $this->fz = $this->getFloat(); $this->posX = $this->getFloat(); $this->posY = $this->getFloat(); - $this->posZ = $this->getFloat(); + $this->posZ = $this->getFloat(); } - + public function encode(){ } diff --git a/src/network/query/QueryHandler.php b/src/network/query/QueryHandler.php index 7530d3b6..41bb81aa 100644 --- a/src/network/query/QueryHandler.php +++ b/src/network/query/QueryHandler.php @@ -19,7 +19,7 @@ class QueryHandler{ The Query protocol is built on top of the existing Minecraft PE UDP network stack. Because the 0xFE packet does not exist in the MCPE protocol, we can identify Query packets and remove them from the packet queue. - + Then, the Query class handles itself sending the packets in raw form, because packets can conflict with the MCPE ones. */ diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php index 5f64ac47..ada14791 100755 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -12,7 +12,7 @@ abstract class RakNetDataPacket extends stdClass{ public $splitID; public $splitIndex; private $offset = 0; - + abstract public function encode(); abstract public function decode(); @@ -20,11 +20,11 @@ abstract class RakNetDataPacket extends stdClass{ public function getBuffer(){ return $this->buffer; } - + public function getOffset(){ return $this->offset; } - + public function setBuffer($buffer = ""){ $this->buffer = $buffer; $this->offset = 0; @@ -123,12 +123,12 @@ abstract class RakNetDataPacket extends stdClass{ protected function getShort($unsigned = false){ return Utils::readShort($this->get(2), $unsigned); } - + public function getSignedByte(){ $b = ord($this->get(1)); - return $b >= 0x80 ? ($b-256) : $b; + return $b >= 0x80 ? ($b - 256) : $b; } - + protected function getByte(){ return ord($this->get(1)); } @@ -144,7 +144,7 @@ abstract class RakNetDataPacket extends stdClass{ } protected function putByte($v){ - $this->buffer .= chr((int)$v); + $this->buffer .= chr((int) $v); } protected function getString(){ diff --git a/src/network/raknet/RakNetInfo.php b/src/network/raknet/RakNetInfo.php index 634e2e76..dabb8b75 100644 --- a/src/network/raknet/RakNetInfo.php +++ b/src/network/raknet/RakNetInfo.php @@ -38,7 +38,7 @@ abstract class RakNetInfo{ const ACK = 0xc0; public static function isValid($pid){ - return match ((int)$pid) { + return match ((int) $pid) { RakNetInfo::UNCONNECTED_PING, RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS, RakNetInfo::OPEN_CONNECTION_REQUEST_1, RakNetInfo::OPEN_CONNECTION_REPLY_1, RakNetInfo::OPEN_CONNECTION_REQUEST_2, RakNetInfo::OPEN_CONNECTION_REPLY_2, RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION, RakNetInfo::UNCONNECTED_PONG, RakNetInfo::ADVERTISE_SYSTEM, RakNetInfo::DATA_PACKET_0, RakNetInfo::DATA_PACKET_1, RakNetInfo::DATA_PACKET_2, RakNetInfo::DATA_PACKET_3, RakNetInfo::DATA_PACKET_4, RakNetInfo::DATA_PACKET_5, RakNetInfo::DATA_PACKET_6, RakNetInfo::DATA_PACKET_7, RakNetInfo::DATA_PACKET_8, RakNetInfo::DATA_PACKET_9, RakNetInfo::DATA_PACKET_A, RakNetInfo::DATA_PACKET_B, RakNetInfo::DATA_PACKET_C, RakNetInfo::DATA_PACKET_D, RakNetInfo::DATA_PACKET_E, RakNetInfo::DATA_PACKET_F, RakNetInfo::NACK, RakNetInfo::ACK => true, default => false, }; diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index 1b346cf3..6dc14659 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -7,7 +7,7 @@ class RakNetParser{ private $offset; public function __construct(&$buffer){ - $this->buffer =& $buffer; + $this->buffer = &$buffer; $this->offset = 0; if(strlen($this->buffer) > 0){ $this->parse(); @@ -18,7 +18,7 @@ class RakNetParser{ private function parse(){ $this->packet = new RakNetPacket(ord($this->get(1))); - $this->packet->buffer =& $this->buffer; + $this->packet->buffer = &$this->buffer; $this->packet->length = strlen($this->buffer); switch($this->packet->pid()){ case RakNetInfo::UNCONNECTED_PING: @@ -163,7 +163,7 @@ class RakNetParser{ if(strlen($buffer) < ($length - 1)){ return false; } - + $data = match($pid){ ProtocolInfo::PING_PACKET => new PingPacket(), ProtocolInfo::PONG_PACKET => new PongPacket(), @@ -222,7 +222,7 @@ class RakNetParser{ ProtocolInfo::PLAYER_INPUT_PACKET => new PlayerInputPacket(), default => new UnknownPacket($pid) }; - + $data->reliability = $reliability; $data->hasSplit = $hasSplit; $data->messageIndex = $messageIndex; diff --git a/src/plugin/DummyPlugin.php b/src/plugin/DummyPlugin.php index 34d8abcc..6ab9554a 100644 --- a/src/plugin/DummyPlugin.php +++ b/src/plugin/DummyPlugin.php @@ -1,13 +1,13 @@ fp)){ if(($this->fp = @fopen($file, "c+b")) === false){ return false; diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index f00388e6..0439b5bb 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -40,7 +40,7 @@ class PMFLevel extends PMF{ if(!is_dir($dirname)){ @mkdir($dirname , 0755); } - + for($index = 0; $index < $cnt; ++$index){ $this->chunks[$index] = false; $this->chunkChange[$index] = false; @@ -94,14 +94,14 @@ class PMFLevel extends PMF{ $this->backupLocTable(); } - + public function backupLocTable(){ $dir = dirname($this->file); if(is_file("$dir/loctable.pmf")){ $val = copy("$dir/loctable.pmf", "$dir/loctable.pmf.old"); if($val === false) ConsoleAPI::warn("Failed to backup loctable data!"); } - + $file = fopen("$dir/loctable.pmf", "wb"); try{ $cnt = pow($this->levelData["width"], 2); @@ -111,7 +111,7 @@ class PMFLevel extends PMF{ }finally{ fclose($file); } - + } public function getXZ($index, &$X = null, &$Z = null){ @@ -212,7 +212,7 @@ class PMFLevel extends PMF{ unset($this->chunks[$index], $this->chunkChange[$index]); return true; } - + public function isChunkLoaded($X, $Z){ $index = self::getIndex($X, $Z); if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ @@ -351,16 +351,16 @@ class PMFLevel extends PMF{ public function fastGetBlockID($chunkX, $chunkY, $chunkZ, $blockX, $blockY, $blockZ, $index){ return ($this->chunks[$index][$chunkY] === false) ? 0 : ord($this->chunks[$index][$chunkY][$blockY + ($blockX << 5) + ($blockZ << 9)]); } - + public function getBlockID($x, $y, $z){ if($y > 127 || $y < 0){ return 0; } - + if($x < 0 || $x > 255 || $z < 0 || $z > 255){ return INVISIBLE_BEDROCK; } - + $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; @@ -371,9 +371,9 @@ class PMFLevel extends PMF{ $aX = $x & 0xf; $aZ = $z & 0xf; $aY = $y & 0xf; - + $b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]); - + return $b; } @@ -381,12 +381,12 @@ class PMFLevel extends PMF{ if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){ return false; } - + $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; $block &= 0xFF; - + $index = self::getIndex($X, $Z); $aX = $x & 0xf; $aZ = $z & 0xf; @@ -398,7 +398,7 @@ class PMFLevel extends PMF{ $this->chunks[$index][$Y][$bind] = chr($block); if($block > 0) StaticBlock::getBlock($block)::onPlace($this->level, $x, $y, $z); } - + if(!isset($this->chunkChange[$index][$Y])){ $this->chunkChange[$index][$Y] = 1; }else{ @@ -434,7 +434,7 @@ class PMFLevel extends PMF{ $Z = $z >> 4; $Y = $y >> 4; $damage &= 0x0F; - + $index = self::getIndex($X, $Z); $aX = $x & 0xf; $aZ = $z & 0xf; @@ -467,11 +467,11 @@ class PMFLevel extends PMF{ if($x < 0 || $x > 255 || $z < 0 || $z > 255){ return [INVISIBLE_BEDROCK, 0]; } - + $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; - + $index = self::getIndex($X, $Z); if(!isset($this->chunks[$index]) || $this->chunks[$index] === false){ if($this->loadChunk($X, $Z) === false){ @@ -484,12 +484,12 @@ class PMFLevel extends PMF{ $aX = $x & 0xf; $aZ = $z & 0xf; $aY = $y & 0xf; - + $b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]); - + $m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]); $m = ($y & 1) ? $m >> 4 : $m & 0xf; - + return [$b, $m]; } @@ -517,7 +517,7 @@ class PMFLevel extends PMF{ $mindex = (int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9)); $old_b = ord($this->chunks[$index][$Y][$bindex]); $old_m = ord($this->chunks[$index][$Y][$mindex]); - + $m = ($y & 1) ? (($meta << 4) | ($old_m & 0x0F)) : (($old_m & 0xF0) | $meta); if($old_b !== $block or $old_m !== $m){ @@ -529,7 +529,7 @@ class PMFLevel extends PMF{ ++$this->chunkChange[$index][$Y]; } $this->chunkChange[$index][-1] = true; - + if($block > 0) StaticBlock::getBlock($block)::onPlace($this->level, $x, $y, $z); return true; } diff --git a/src/recipes/CraftingRecipes.php b/src/recipes/CraftingRecipes.php index 47064577..ef976bac 100644 --- a/src/recipes/CraftingRecipes.php +++ b/src/recipes/CraftingRecipes.php @@ -1,9 +1,9 @@ CLAY_BLOCK:0x1", "WOODEN_PLANKS:?x4=>WORKBENCH:0x1", "GLOWSTONE_DUST:?x4=>GLOWSTONE_BLOCK:0x1", @@ -73,7 +73,7 @@ class CraftingRecipes{ ]; private static $big = [ // Probably means only craftable on crafting bench. Name it better! - // Building + // Building "WOOL:?x3,WOODEN_PLANKS:?x3=>BED:0x1", "WOODEN_PLANKS:?x8=>CHEST:0x1", "STICK:?x6=>FENCE:0x2", @@ -199,47 +199,47 @@ class CraftingRecipes{ private static $recipes = []; - public static function init(){ + public static function init() { $server = ServerAPI::request(); $id = 1; - foreach(CraftingRecipes::$small as $recipe){ + foreach(CraftingRecipes::$small as $recipe) { $recipe = CraftingRecipes::parseRecipe($recipe); $recipe[3] = 0; //Type CraftingRecipes::$recipes[$id] = $recipe; ++$id; } - foreach(CraftingRecipes::$big as $recipe){ + foreach(CraftingRecipes::$big as $recipe) { $recipe = CraftingRecipes::parseRecipe($recipe); $recipe[3] = 1; CraftingRecipes::$recipes[$id] = $recipe; ++$id; } - foreach(CraftingRecipes::$stone as $recipe){ + foreach(CraftingRecipes::$stone as $recipe) { $recipe = CraftingRecipes::parseRecipe($recipe); $recipe[3] = 2; CraftingRecipes::$recipes[$id] = $recipe; ++$id; } - foreach(CraftingRecipes::$recipes as $id => $recipe){ + foreach(CraftingRecipes::$recipes as $id => $recipe) { $server->query("INSERT INTO recipes (id, type, recipe) VALUES (" . $id . ", " . $recipe[3] . ", '" . $recipe[2] . "');"); } } - private static function parseRecipe($recipe){ + private static function parseRecipe($recipe) { $recipe = explode("=>", $recipe); $recipeItems = []; - foreach(explode(",", $recipe[0]) as $item){ + foreach(explode(",", $recipe[0]) as $item) { $item = explode("x", $item); $id = explode(":", $item[0]); $meta = array_pop($id); $id = $id[0]; $it = BlockAPI::fromString($id); - if(!isset($recipeItems[$it->getID()])){ + if(!isset($recipeItems[$it->getID()])) { $recipeItems[$it->getID()] = [$it->getID(), $meta === "?" ? false : intval($meta) & 0xFFFF, intval($item[1])]; - }else{ - if($it->getMetadata() !== $recipeItems[$it->getID()][1]){ + } else { + if($it->getMetadata() !== $recipeItems[$it->getID()][1]) { $recipeItems[$it->getID()][1] = false; } $recipeItems[$it->getID()][2] += $it->count; @@ -256,7 +256,7 @@ class CraftingRecipes{ $craftItem = [$it->getID(), intval($meta) & 0xFFFF, intval($item[1])]; $recipeString = ""; - foreach($recipeItems as $item){ + foreach($recipeItems as $item) { $recipeString .= $item[0] . "x" . $item[2] . ","; } $recipeString = substr($recipeString, 0, -1) . "=>" . $craftItem[0] . "x" . $craftItem[2]; @@ -264,11 +264,11 @@ class CraftingRecipes{ return [$recipeItems, $craftItem, $recipeString]; } - public static function canCraft(array $craftItem, array $recipeItems, $type){ + public static function canCraft(array $craftItem, array $recipeItems, $type) { ksort($recipeItems); $recipeString = ""; - foreach($recipeItems as $item){ - if($craftItem[0] === CAKE && $item[0] === BUCKET && $item[1] === 1){ //some dark magic with recipe happened in mcpe, pmmp restores it back to normal + foreach($recipeItems as $item) { + if($craftItem[0] === CAKE && $item[0] === BUCKET && $item[1] === 1) { //some dark magic with recipe happened in mcpe, pmmp restores it back to normal $item[2] = 3; } $recipeString .= $item[0] . "x" . $item[2] . ","; @@ -276,33 +276,33 @@ class CraftingRecipes{ $recipeString = substr($recipeString, 0, -1) . "=>" . $craftItem[0] . "x" . $craftItem[2]; $server = ServerAPI::request(); $result = $server->query("SELECT id FROM recipes WHERE type == " . $type . " AND recipe == '" . $recipeString . "';"); - if($result instanceof SQLite3Result){ + if($result instanceof SQLite3Result) { $continue = true; - while(($r = $result->fetchArray(SQLITE3_NUM)) !== false){ + while(($r = $result->fetchArray(SQLITE3_NUM)) !== false) { $continue = true; $recipe = CraftingRecipes::$recipes[$r[0]]; - foreach($recipe[0] as $item){ - if(!isset($recipeItems[$item[0]])){ + foreach($recipe[0] as $item) { + if(!isset($recipeItems[$item[0]])) { $continue = false; break; } $oitem = $recipeItems[$item[0]]; - if($craftItem[0] === CAKE && $oitem[0] === BUCKET && $item[1] === 1){ //some dark magic with recipe happened in mcpe, pmmp restores it back to normal x2 + if($craftItem[0] === CAKE && $oitem[0] === BUCKET && $item[1] === 1) { //some dark magic with recipe happened in mcpe, pmmp restores it back to normal x2 $oitem[2] = 3; } - if(($oitem[1] !== $item[1] and $item[1] !== false) or $oitem[2] !== $item[2]){ + if(($oitem[1] !== $item[1] and $item[1] !== false) or $oitem[2] !== $item[2]) { $continue = false; break; } } - if($continue === false or $craftItem[0] !== $recipe[1][0]){ + if($continue === false or $craftItem[0] !== $recipe[1][0]) { $continue = false; continue; } $continue = $recipe; break; } - }else{ + } else { return true; } return $continue; diff --git a/src/recipes/FuelData.php b/src/recipes/FuelData.php index e0c61bab..d9025730 100644 --- a/src/recipes/FuelData.php +++ b/src/recipes/FuelData.php @@ -1,6 +1,6 @@ 80, @@ -27,4 +27,4 @@ class FuelData{ BUCKET => 1000, ]; -} \ No newline at end of file +} diff --git a/src/recipes/SmeltingData.php b/src/recipes/SmeltingData.php index 1dd447d3..544abd5b 100644 --- a/src/recipes/SmeltingData.php +++ b/src/recipes/SmeltingData.php @@ -1,6 +1,6 @@ [STONE, 0], @@ -17,4 +17,4 @@ class SmeltingData{ RAW_CHICKEN => [COOKED_CHICKEN, 0], POTATO => [BAKED_POTATO, 0], ]; -} \ No newline at end of file +} diff --git a/src/structure/Structure.php b/src/structure/Structure.php index eaa51259..c7bc25c0 100644 --- a/src/structure/Structure.php +++ b/src/structure/Structure.php @@ -11,7 +11,7 @@ abstract class Structure{ private $structure; public $api, $pm; public $mapSymToID, $width, $radius; - + public function __construct($struct, $width, $symToID = []){ $this->structure = $struct; $this->mapSymToID = $symToID; @@ -19,16 +19,16 @@ abstract class Structure{ $this->api = $this->pm->api; $this->width = $width; $this->radius = $width / 2; - + } - + public function addMapping($sym, $id){ $this->mapSymToID[$sym] = $id; } public function getMappingFor($sym){ return $this->mapSymToID[$sym] ?? Structure::MAP_NO_KEY; } - + protected function placeBlock($level, $sym, $tv){ if($level instanceof Level){ $idm = $this->getMappingFor($sym); @@ -39,9 +39,9 @@ abstract class Structure{ $block = $this->api->block->get($idm[0], $idm[1], $tv); $level->setBlock($tv, $block, true, false, true); } - + } - + public function build($level, $centerX, $centerY, $centerZ){ $tempVector = new Vector3(0,0,0); $x = $centerX - $this->radius; @@ -56,8 +56,8 @@ abstract class Structure{ ++$z; $x = $centerX - $this->radius; } - $z = $centerZ - $this->radius; + $z = $centerZ - $this->radius; } } - + } \ No newline at end of file diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index e033c274..0762ec4d 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -1,4 +1,5 @@ getGamemode(), "survival"); - //Everything done! $server->close(); } diff --git a/src/utils/AsyncMultipleQueue.php b/src/utils/AsyncMultipleQueue.php index 5581a63b..f43cee27 100644 --- a/src/utils/AsyncMultipleQueue.php +++ b/src/utils/AsyncMultipleQueue.php @@ -111,8 +111,8 @@ class Async extends Thread{ } } } - + public function __destruct(){} - + public function run(){} }*/ diff --git a/src/utils/Config.php b/src/utils/Config.php index 23b3c153..a196879a 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -168,9 +168,6 @@ class Config{ return $content; } - /** - * @param $content - */ private function parseProperties($content){ if(preg_match_all('/([a-zA-Z0-9\-_\.]*)=([^\r\n]*)/u', $content, $matches) > 0){ //false or 0 matches foreach($matches[1] as $i => $k){ @@ -199,9 +196,6 @@ class Config{ return preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", $str); } - /** - * @param $content - */ private function parseList($content){ foreach(explode("\n", trim(str_replace("\r\n", "\n", $content))) as $v){ $v = trim($v); @@ -213,8 +207,6 @@ class Config{ } /** - * @param $default - * @param $data * * @return integer */ @@ -250,7 +242,6 @@ class Config{ } /** - * @param $k * * @return boolean|mixed */ @@ -258,16 +249,11 @@ class Config{ return $this->get($k); } - /** - * @param $k - * @param $v - */ public function __set($k, $v){ $this->set($k, $v); } /** - * @param $k * * @return boolean|mixed */ @@ -280,7 +266,6 @@ class Config{ } /** - * @param $k * @param bool $v */ public function set($k, $v = true){ @@ -288,7 +273,6 @@ class Config{ } /** - * @param $k * * @return boolean */ @@ -297,7 +281,6 @@ class Config{ } /** - * @param $k * @param bool $lowercase If set, searches Config in single-case / lowercase. * * @return boolean @@ -312,16 +295,10 @@ class Config{ } } - /** - * @param $k - */ public function __unset($k){ $this->remove($k); } - /** - * @param $k - */ public function remove($k){ unset($this->config[$k]); } diff --git a/src/utils/Container.php b/src/utils/Container.php index 0d22f2c0..36cfb41a 100644 --- a/src/utils/Container.php +++ b/src/utils/Container.php @@ -43,7 +43,6 @@ class Container{ return true; } - public function __toString(){ return $this->payload; } diff --git a/src/utils/LightUtils.php b/src/utils/LightUtils.php index 83820d8f..253d7834 100644 --- a/src/utils/LightUtils.php +++ b/src/utils/LightUtils.php @@ -13,7 +13,7 @@ class LightUtils{ $diffX = ($source->x - $block->x); $diffY = ($source->y - $block->y); $diffZ = ($source->z - $block->z); - $distance = $diffX*$diffX + $diffY*$diffY + $diffZ*$diffZ; + $distance = $diffX * $diffX + $diffY * $diffY + $diffZ * $diffZ; $result = floor($source->getMaxLightValue() - $distance); return max($result, 0); } diff --git a/src/utils/MTRandom.php b/src/utils/MTRandom.php index 5cc5d5c3..462f4075 100644 --- a/src/utils/MTRandom.php +++ b/src/utils/MTRandom.php @@ -8,35 +8,35 @@ class MTRandom public $mt; public $index = 0; public function __construct($seed = null){ - $this->setSeed($seed == null ? (int)microtime(1) : $seed); + $this->setSeed($seed == null ? (int) microtime(1) : $seed); } - + public function setSeed($seed){ $this->mt[0] = $seed & 0xffffffff; for($this->index = 1; $this->index < 624; ++$this->index){ - $this->mt[$this->index] = (0x6c078965 * ($this->mt[$this->index-1] >> 30 ^ $this->mt[$this->index - 1]) + $this->index) & 0xffffffff; + $this->mt[$this->index] = (0x6c078965 * ($this->mt[$this->index - 1] >> 30 ^ $this->mt[$this->index - 1]) + $this->index) & 0xffffffff; } } public function genRandInt(){ if($this->index >= 624 || $this->index < 0){ if($this->index >= 625 || $this->index < 0) $this->setSeed(4357); - + for($kk = 0; $kk < 227; ++$kk){ $y = ($this->mt[$kk] & 0x80000000) | ($this->mt[$kk + 1] & 0x7fffffff); - $this->mt[$kk] = $this->mt[$kk+397] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; + $this->mt[$kk] = $this->mt[$kk + 397] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; } - + for(;$kk < 623; ++$kk){ $y = ($this->mt[$kk] & 0x80000000) | ($this->mt[$kk + 1] & 0x7fffffff); - $this->mt[$kk] = $this->mt[$kk-227] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; + $this->mt[$kk] = $this->mt[$kk - 227] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; } - + $y = ($this->mt[623] & 0x80000000) | ($this->mt[0] & 0x7fffffff); $this->mt[623] = $this->mt[396] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; $this->index = 0; } - + $y = $this->mt[$this->index++]; $y ^= ($y >> 11); $y ^= ($y << 7) & 0x9d2c5680; @@ -44,11 +44,11 @@ class MTRandom $y ^= ($y >> 18); return $y; } - + public function nextInt($bound = null){ return $bound == null ? $this->genRandInt() >> 1 : $this->genRandInt() % $bound; } - + public function nextFloat(){ return $this->genRandInt() / 0xffffffff; } diff --git a/src/utils/MersenneTwister.php b/src/utils/MersenneTwister.php index e35c7f25..bc521acf 100644 --- a/src/utils/MersenneTwister.php +++ b/src/utils/MersenneTwister.php @@ -17,10 +17,10 @@ and floats when we must. Only the class `twister' is part of the API; everything else is private. - + http://kingfisher.nfshost.com/sw/twister/ - - + + Who made such a weird names? - GameHerobrine */ const N = 624; @@ -42,16 +42,14 @@ foreach([16, 31, 32] as $n){ $val = MASK31 | (MASK31 << 1); define("MASK32", $val); - class MersenneTwister{ - - + static $MAG_01 = [0, MATRIX_A]; - + const N = N; //the class constant is not used anywhere in this namespace, //but it makes the API cleaner. - + //^^ u probably wanted to say makes code look weirder function __construct(){ @@ -191,7 +189,7 @@ class MersenneTwister{ return $y & 0xFFFFFFFF; } - + /* generates a random number on [0,1]-real-interval */ function real_closed(){ @@ -325,15 +323,15 @@ class MersenneTwister{ function nextInt($bound = null){ return $bound == null ? ($this->int32() >> 1) : ($this->int32() % $bound); } - + function nextFloat(){ return $this->int32() * 2.32830644e-10; } - + function setSeed($seed){ $this->init_with_integer($seed); } - + } function signed2unsigned($signed_integer){ @@ -389,7 +387,7 @@ function force_32_bit_int($x){ /* takes 2 integers, treats them as unsigned 32-bit integers, and adds them. - + it works by splitting each integer into 2 "half-integers", then adding the high and low half-integers separately. diff --git a/src/utils/RailLogic.php b/src/utils/RailLogic.php index 92eb05ab..1966b7c5 100644 --- a/src/utils/RailLogic.php +++ b/src/utils/RailLogic.php @@ -1,16 +1,17 @@ getID(); $meta = $rail->getMetadata(); $this->level = $rail->level; @@ -18,190 +19,251 @@ class RailLogic $this->y = $rail->y; $this->z = $rail->z; $this->isStraight = $id === POWERED_RAIL; - + $this->updateConnections($meta); } - public function getRail($v){ - if(($b = $this->level->getBlock($v)) instanceof RailBaseBlock){ //TODO git rid of getBlock + public function getRail($v) { + if(($b = $this->level->getBlock($v)) instanceof RailBaseBlock) { //TODO git rid of getBlock return new RailLogic($b); - }elseif(($b = $this->level->getBlockWithoutVector($v->x, $v->y + 1, $v->z)) instanceof RailBaseBlock){ + } elseif(($b = $this->level->getBlockWithoutVector($v->x, $v->y + 1, $v->z)) instanceof RailBaseBlock) { return new RailLogic($b); - }elseif(($b = $this->level->getBlockWithoutVector($v->x, $v->y - 1, $v->z)) instanceof RailBaseBlock){ + } elseif(($b = $this->level->getBlockWithoutVector($v->x, $v->y - 1, $v->z)) instanceof RailBaseBlock) { return new RailLogic($b); } - + return null; } - - public function hasRail($x, $y, $z){ + + public function hasRail($x, $y, $z) { return RailBaseBlock::isRailBlock($this->level, $x, $y, $z) || RailBaseBlock::isRailBlock($this->level, $x, $y + 1, $z) || RailBaseBlock::isRailBlock($this->level, $x, $y - 1, $z); } - - public function countPotentialConnections(){ + + public function countPotentialConnections() { return $this->hasRail($this->x, $this->y, $this->z - 1) + $this->hasRail($this->x, $this->y, $this->z + 1) + $this->hasRail($this->x - 1, $this->y, $this->z) + $this->hasRail($this->x + 1, $this->y, $this->z); } - - public function removeSoftConnections(){ - for($ind = 0; $ind < count($this->railPositions); ++$ind){ + + public function removeSoftConnections() { + for($ind = 0; $ind < count($this->railPositions); ++$ind) { $logic = $this->getRail($this->railPositions[$ind]); - if($logic != null && $this->connectsTo($logic)){ + if($logic != null && $this->connectsTo($logic)) { $this->railPositions[$ind] = new Vector3($logic->x, $logic->y, $logic->z); - }else{ + } else { unset($this->railPositions[$ind--]); $this->railPositions = array_values($this->railPositions); //reindexing } } } - - public function connectsTo(RailLogic $logic){ - foreach($this->railPositions as $rpos){ - if(($rpos->x === $logic->x) && ($rpos->z === $logic->z)){ + + public function connectsTo(RailLogic $logic) { + foreach($this->railPositions as $rpos) { + if(($rpos->x === $logic->x) && ($rpos->z === $logic->z)) { return true; } } return false; } - - public function canConnectTo(RailLogic $rail){ + + public function canConnectTo(RailLogic $rail) { return $this->connectsTo($rail) || !(count($this->railPositions) == 2); } - - public function hasNeighborRail($x, $y, $z){ + + public function hasNeighborRail($x, $y, $z) { $logic = $this->getRail(new Vector3($x, $y, $z)); - if($logic === null){ + if($logic === null) { return false; - }else{ + } else { $logic->removeSoftConnections(); //i place $this here and was searching why isnt it working correctly for 2 hours return $logic->canConnectTo($this); } - + } - - public function place($b, $b1){ + + public function place($b, $b1) { $hasZneg = $this->hasNeighborRail($this->x, $this->y, $this->z - 1); $hasZpos = $this->hasNeighborRail($this->x, $this->y, $this->z + 1); $hasXneg = $this->hasNeighborRail($this->x - 1, $this->y, $this->z); $hasXpos = $this->hasNeighborRail($this->x + 1, $this->y, $this->z); $state = -1; - if(($hasZneg || $hasZpos) && !($hasXneg && $hasXpos)){ + if(($hasZneg || $hasZpos) && !($hasXneg && $hasXpos)) { $state = 0; } - if(($hasXneg || $hasXpos) && !($hasZneg && $hasZpos)){ + if(($hasXneg || $hasXpos) && !($hasZneg && $hasZpos)) { $state = 1; } - - if(!$this->isStraight){ - if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) $state = 6; - if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) $state = 7; - if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) $state = 8; - if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) $state = 9; + + if(!$this->isStraight) { + if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) { + $state = 6; + } + if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) { + $state = 7; + } + if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) { + $state = 8; + } + if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) { + $state = 9; + } } - - if($state === -1){ - if($hasZneg || $hasZpos) $state = 0; - if($hasXneg || $hasXpos) $state = 1; - - if(!$this->isStraight){ - if($b){ - if($hasZpos && $hasXpos) $state = 6; - if($hasXneg && $hasZpos) $state = 7; - if($hasXpos && $hasZneg) $state = 9; - if($hasZneg && $hasXneg) $state = 8; - }else{ - if($hasZneg && $hasXneg) $state = 8; - if($hasXpos && $hasZneg) $state = 9; - if($hasXneg && $hasZpos) $state = 7; - if($hasZpos && $hasXpos) $state = 6; + + if($state === -1) { + if($hasZneg || $hasZpos) { + $state = 0; + } + if($hasXneg || $hasXpos) { + $state = 1; + } + + if(!$this->isStraight) { + if($b) { + if($hasZpos && $hasXpos) { + $state = 6; + } + if($hasXneg && $hasZpos) { + $state = 7; + } + if($hasXpos && $hasZneg) { + $state = 9; + } + if($hasZneg && $hasXneg) { + $state = 8; + } + } else { + if($hasZneg && $hasXneg) { + $state = 8; + } + if($hasXpos && $hasZneg) { + $state = 9; + } + if($hasXneg && $hasZpos) { + $state = 7; + } + if($hasZpos && $hasXpos) { + $state = 6; + } } } } - - if($state === 0){ - if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4; - if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) $state = 5; - }elseif($state === 1){ - if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) $state = 2; - if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) $state = 3; - }elseif($state < 0) $state = 0; - + if($state === 0) { + if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) { + $state = 4; + } + if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) { + $state = 5; + } + } elseif($state === 1) { + if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) { + $state = 2; + } + if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) { + $state = 3; + } + } elseif($state < 0) { + $state = 0; + } + $this->updateConnections($state); $meta = $state; - if($this->isStraight){ + if($this->isStraight) { $meta = $this->level->level->getBlockDamage($this->x, $this->x, $this->z) & 8 | $state; } - - if($b1 || $this->level->level->getBlockDamage($this->x, $this->y, $this->z)){ + + if($b1 || $this->level->level->getBlockDamage($this->x, $this->y, $this->z)) { //this.logicWorld.setBlockMetadataWithNotify(this.railX, this.railY, this.railZ, var8, 3); $bl = $this->level->getBlockWithoutVector($this->x, $this->y, $this->z); $bl->setMetadata($meta); $this->level->setBlock(new Vector3($this->x, $this->y, $this->z), $bl, true, false, true); - foreach($this->railPositions as $rpos){ + foreach($this->railPositions as $rpos) { $logic = $this->getRail($rpos); - if($logic !== null){ + if($logic !== null) { $logic->removeSoftConnections(); - if($logic->canConnectTo($this)){ + if($logic->canConnectTo($this)) { $logic->connectTo($this); } - + } } - + } - + } - - public function hasConnection($x, $y, $z){ - foreach($this->railPositions as $rpos){ - if($rpos->x === $x && $rpos->z === $z) return true; + + public function hasConnection($x, $y, $z) { + foreach($this->railPositions as $rpos) { + if($rpos->x === $x && $rpos->z === $z) { + return true; + } } return false; } - - public function connectTo(RailLogic $logic){ + + public function connectTo(RailLogic $logic) { $this->railPositions[] = new Vector3($logic->x, $logic->y, $logic->z); - + $hasZneg = $this->hasConnection($this->x, $this->y, $this->z - 1); $hasZpos = $this->hasConnection($this->x, $this->y, $this->z + 1); $hasXneg = $this->hasConnection($this->x - 1, $this->y, $this->z); $hasXpos = $this->hasConnection($this->x + 1, $this->y, $this->z); $state = -1; - - if($hasZneg || $hasZpos) $state = 0; - if($hasXneg || $hasXpos) $state = 1; - - if(!$this->isStraight){ - if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) $state = 6; - if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) $state = 7; - if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) $state = 8; - if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) $state = 9; + + if($hasZneg || $hasZpos) { + $state = 0; + } + if($hasXneg || $hasXpos) { + $state = 1; + } + + if(!$this->isStraight) { + if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) { + $state = 6; + } + if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) { + $state = 7; + } + if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) { + $state = 8; + } + if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) { + $state = 9; + } + } + + if($state == 0) { + if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) { + $state = 4; + } + if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) { + $state = 5; + } + } elseif($state == 1) { + if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) { + $state = 2; + } + if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) { + $state = 3; + } + } elseif($state < 0) { + $state = 0; } - if($state == 0){ - if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4; - if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) $state = 5; - }elseif($state == 1){ - if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) $state = 2; - if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) $state = 3; - }elseif($state < 0) $state = 0; - $meta = $state; - - if($this->isStraight){ + + if($this->isStraight) { $meta = $this->level->level->getBlockDamage($this->x, $this->x, $this->z) & 8 | $state; } - + //$b = $this->level->getBlockWithoutVector($this->x, $this->y, $this->z); //$b->setMetadata($meta); //$this->level->setBlock(new Vector3($this->x, $this->y, $this->z), $b, true, false, true); $this->level->fastSetBlockUpdateMeta($this->x, $this->y, $this->z, $meta, true); } - - public function updateConnections($meta){ - + + public function updateConnections($meta) { + $this->railPositions = []; - - switch($meta){ + + switch($meta) { case 0: $this->railPositions[] = new Vector3($this->x, $this->y, $this->z - 1); $this->railPositions[] = new Vector3($this->x, $this->y, $this->z + 1); @@ -245,4 +307,3 @@ class RailLogic } } } - diff --git a/src/utils/Random.php b/src/utils/Random.php index f2b146df..b0011fef 100644 --- a/src/utils/Random.php +++ b/src/utils/Random.php @@ -6,7 +6,7 @@ class Random{ private $x, $y, $z, $w; private $haveNextNextGaussian = false; private $nextNextGaussian = 0; - + public $state; public $i, $j; public function __construct($seed = false){ diff --git a/src/utils/StopMessageThread.php b/src/utils/StopMessageThread.php index 2c07172e..fff741bb 100644 --- a/src/utils/StopMessageThread.php +++ b/src/utils/StopMessageThread.php @@ -9,9 +9,9 @@ class StopMessageThread extends Thread $this->name = $server->extraprops->get("discord-bot-name"); $this->start(); } - + } - + public function run(){ Utils::curl_post($this->page, [ "username" => $this->name, diff --git a/src/utils/Utils.php b/src/utils/Utils.php index a6f8a08c..42a6f8b0 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -21,25 +21,25 @@ class Utils{ default => $id, }; } - + public static function wrapAngleTo360($angle) { $angle = fmod($angle, 360); return $angle < 0 ? $angle + 360 : $angle; } - + public static function getSeedNumeric($seed){ if($seed === "") return false; - elseif(is_int($seed)) return (int)$seed; + elseif(is_int($seed)) return (int) $seed; else{ $i = 0; for($j = 0; $j < strlen($seed); ++$j){ $i = $i * 31 + ord($seed[$j]); } - return (int)$i; + return (int) $i; } } - + public static function sint32($r){ $r &= 0xFFFFFFFF; if ($r & 0x80000000) @@ -49,11 +49,11 @@ class Utils{ } return $r; } - + public static function wrapAngleTo180($angle) { $angle = fmod($angle, 360); - + if($angle >= 180) $angle -= 360; if($angle < -180) $angle += 360; return $angle; @@ -61,22 +61,22 @@ class Utils{ public static function getSign($v){ return $v <=> 0; } - + public static function clampDegrees($v){ return floor(($v % 360 + 360) % 360); } - + /** * PHP8 has internal function for doing it: {@link str_ends_with} */ public static function endsWith($str, $check) { return str_ends_with($str, $check); } - + public static function hasEmoji($s){ return preg_match(Utils::emojiRegex, $s); } - + public static function getCallableIdentifier(callable $variable){ if(is_array($variable)){ return sha1(strtolower(get_class($variable[0])) . "::" . strtolower($variable[1])); @@ -84,11 +84,11 @@ class Utils{ return sha1(strtolower($variable)); } } - + public static function in_range($num, $min, $max){ return $num >= $min && $num <= $max; } - + public static function getUniqueID($raw = false, $extra = ""){ $machine = php_uname("a"); $machine .= file_exists("/proc/cpuinfo") ? `cat /proc/cpuinfo | grep "model name"` : ""; @@ -181,21 +181,21 @@ class Utils{ return Utils::$ip; } - + public static function makeHeaders($json){ $arr = json_decode($json); $rarr = []; foreach ($arr as $key => $value){ - $rarr[] = $key.": ".$value; + $rarr[] = $key . ": " . $value; } return $rarr; } - + public static function curl_get($page, $timeout = 10, $headers = " "){ if(Utils::$online === false){ return false; } - + if($headers != " "){ $headers = Utils::makeHeaders($headers); }else{ @@ -431,7 +431,7 @@ class Utils{ } return $data; } - + public static function readTriad($str){ return strlen($str) < 3 ? false : @unpack("N", "\x00$str")[1]; } @@ -444,11 +444,11 @@ class Utils{ } return $raw; } - + public static function writeLTriad($value){ return substr(pack("V", $value), 0, -1); } - + public static function writeTriad($value){ return substr(pack("N", $value), 1); } @@ -456,11 +456,11 @@ class Utils{ public static function getRandomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0){ return $raw ? random_bytes($length) : bin2hex(random_bytes($length)); //nobody would ever notice other parameters } - + public static function chance($i){//GameHerobrine's code return lcg_value() <= $i / 100; } - + /** * @deprecated use lcg_value instead */ @@ -481,10 +481,10 @@ class Utils{ if($pos2 instanceof Vector3){ $pos2 = $pos2->toArray(); } - + return abs($pos2["x"] - $pos1["x"]) + abs($pos2["y"] - $pos1["y"]) + abs($pos2["z"] - $pos1["z"]); } - + /** * Euclidian distance, but without square roots */ @@ -498,13 +498,11 @@ class Utils{ $pX = ($pos1["x"] - $pos2["x"]); $pY = ($pos1["y"] - $pos2["y"]); $pZ = ($pos1["z"] - $pos2["z"]); - return ($pX*$pX) + ($pY*$pY) + ($pZ*$pZ); + return ($pX * $pX) + ($pY * $pY) + ($pZ * $pZ); } - + /** - * - * @param $pos1 - * @param $pos2 + * * @return number */ public static function distance($pos1, $pos2){ @@ -514,9 +512,9 @@ class Utils{ if($pos2 instanceof Vector3){ $pos2 = $pos2->toArray(); } - return sqrt(($pos1["x"] - $pos2["x"])*($pos1["x"] - $pos2["x"]) + ($pos1["y"] - $pos2["y"])*($pos1["y"] - $pos2["y"]) + ($pos1["z"] - $pos2["z"])*($pos1["z"] - $pos2["z"])); + return sqrt(($pos1["x"] - $pos2["x"]) * ($pos1["x"] - $pos2["x"]) + ($pos1["y"] - $pos2["y"]) * ($pos1["y"] - $pos2["y"]) + ($pos1["z"] - $pos2["z"]) * ($pos1["z"] - $pos2["z"])); } - + public static function angle3D($pos1, $pos2){ if($pos1 instanceof Vector3){ $pos1 = $pos1->toArray(); @@ -572,8 +570,8 @@ class Utils{ } public static function readInt($str){ - if(strlen($str) <= 0) return; - + if(strlen($str) <= 0) return; + return @unpack("N", $str)[1] << 32 >> 32; //php has no signed long unpack } diff --git a/src/world/Explosion.php b/src/world/Explosion.php index e44c7bd3..b92e614d 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -1,7 +1,7 @@ DIRT, STONE => COBBLESTONE, @@ -18,7 +18,7 @@ class Explosion{ private $rays = 16; private $air; private $nullPlayer; - + public function __construct(Position $center, $size){ $this->level = $center->level; $this->source = $center; @@ -26,12 +26,12 @@ class Explosion{ $this->air = BlockAPI::getItem(AIR, 0, 1); $this->nullPlayer = new PlayerNull(); } - + public function sub_expl($i, $mRays, $j, $k){ $vx = $i / $mRays * 2 - 1; $vy = $j / $mRays * 2 - 1; $vz = $k / $mRays * 2 - 1; - $vlen = sqrt($vx*$vx + $vy*$vy + $vz*$vz); + $vlen = sqrt($vx * $vx + $vy * $vy + $vz * $vz); if($vlen != 0){ $vx = $vx / $vlen * $this->stepLen; $vy = $vy / $vlen * $this->stepLen; @@ -39,7 +39,7 @@ class Explosion{ }else{ $vx = $vy = $vz = 0; } - + $px = $this->source->x; $py = $this->source->y; $pz = $this->source->z; @@ -64,19 +64,19 @@ class Explosion{ $pz += $vz; } } - + public function explode(){ $radius = 2 * $this->size; $server = ServerAPI::request(); if(!Explosion::$enableExplosions){ /*Disable Explosions*/ - foreach($server->api->entity->getRadius($this->source, $radius+1) as $entity){ + foreach($server->api->entity->getRadius($this->source, $radius + 1) as $entity){ $distance = $this->source->distance($entity); $distByRad = $distance / $this->size; if($distByRad <= 1 && $distance != 0){ $diffX = ($entity->x - $this->source->x) / $distance; $diffY = ($entity->y + $entity->getEyeHeight() - $this->source->y) / $distance; $diffZ = ($entity->z - $this->source->z) / $distance; - + $impact = (1 - $distByRad) * 0.5; //TODO calculate block density around the entity instead of 0.5 $damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1); if($damage > 0){ @@ -84,7 +84,7 @@ class Explosion{ $entity->speedX = $diffX * $impact; $entity->speedY = $diffY * $impact; $entity->speedZ = $diffZ * $impact; - + if($entity->isPlayer()){ $pk = new SetEntityMotionPacket(); $pk->eid = 0; //XXX change @@ -112,7 +112,7 @@ class Explosion{ ]) === false){ return false; } - + $mRays = $this->rays - 1; $i = 0; for($j = 0; $j <= $mRays; ++$j){ @@ -126,21 +126,21 @@ class Explosion{ $this->sub_expl($i, $mRays, $j, $k); } } - + $j = 0; for($i = 1; $i < $mRays; ++$i){ for($k = 0; $k <= $mRays; ++$k){ $this->sub_expl($i, $mRays, $j, $k); } } - + $j = $mRays; for($i = 1; $i < $mRays; ++$i){ for($k = 0; $k <= $mRays; ++$k){ $this->sub_expl($i, $mRays, $j, $k); } } - + $k = 0; for($i = 1; $i < $mRays; ++$i){ for($j = 1; $j < $mRays; ++$j){ @@ -154,8 +154,7 @@ class Explosion{ } } //if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){ - - + $send = []; foreach($server->api->entity->getRadius($this->source, $radius) as $entity){ $distance = $this->source->distance($entity); @@ -164,15 +163,15 @@ class Explosion{ $diffX = ($entity->x - $this->source->x) / $distance; $diffY = ($entity->y + $entity->getEyeHeight() - $this->source->y) / $distance; $diffZ = ($entity->z - $this->source->z) / $distance; - - $impact = (1 - $distByRad) * 0.5; //TODO calculate block density around the entity instead of 0.5 + + $impact = (1 - $distByRad) * 0.5; //TODO calculate block density around the entity instead of 0.5 $damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1); if($damage > 0){ $entity->harm($damage, "explosion"); $entity->speedX = $diffX * $impact; $entity->speedY = $diffY * $impact; $entity->speedZ = $diffZ * $impact; - + if($entity->isPlayer()){ $pk = new SetEntityMotionPacket(); $pk->eid = 0; //XXX change @@ -184,7 +183,7 @@ class Explosion{ } } } - + foreach($this->affectedBlocks as $xyz => $idm){ $id = $idm >> 8 & 0xff; $meta = $idm & 0x0f; diff --git a/src/world/Level.php b/src/world/Level.php index fbec0a71..510c3485 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -1,32 +1,52 @@ true, FARMLAND => true, @@ -45,8 +65,8 @@ class Level{ ICE => true, LEAVES => true ]; - - public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ + + public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name) { $this->server = ServerAPI::request(); $this->level = $level; $this->level->level = $this; @@ -69,176 +89,208 @@ class Level{ $this->randInt2 = 0x3C6EF35F; } - public function close(){ + public function close() { $this->__destruct(); } - - public function isTopSolidBlocking($x, $y, $z){ + + public function isTopSolidBlocking($x, $y, $z) { $idmeta = $this->level->getBlock($x, $y, $z); $id = $idmeta[0]; $meta = $idmeta[1]; - if($id == 0) return false; - if(StaticBlock::getIsTransparent($id)) return false; - + if($id == 0) { + return false; + } + if(StaticBlock::getIsTransparent($id)) { + return false; + } + return true; } - public function rayTraceBlocks(Vector3 $start, Vector3 $end){ - + public function rayTraceBlocks(Vector3 $start, Vector3 $end) { + $par3 = false; //TODO move to params? $par4 = true; - + $xStart = floor($start->x); $yStart = floor($start->y); $zStart = floor($start->z); $xEnd = floor($end->x); $yEnd = floor($end->y); $zEnd = floor($end->z); - + [$startID, $startMeta] = $this->level->getBlock($xStart, $yStart, $zStart); $block = StaticBlock::getBlock($startID); //$block::updateShape($this, $xStart, $yStart, $zStart); //TODO better way to do it $aabb = $block::getAABB($this, $xStart, $yStart, $zStart); - if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck + if($startID > 0 && $aabb != null) { //TODO also block::canColideCheck $v14 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end); - if($v14 != null) return $v14; + if($v14 != null) { + return $v14; + } } - - for($i = 0; $i <= 200; ++$i){ - - if(is_nan($start->x) || is_nan($start->y) || is_nan($start->z) || ($xStart == $xEnd && $yStart == $yEnd && $zStart == $zEnd)){ //also add checks for nan? + + for($i = 0; $i <= 200; ++$i) { + + if(is_nan($start->x) || is_nan($start->y) || is_nan($start->z) || ($xStart == $xEnd && $yStart == $yEnd && $zStart == $zEnd)) { //also add checks for nan? return null; } - + $v39 = $v40 = $v41 = true; $v15 = $v17 = $v19 = 999.0; //nice mojang - - if($xEnd > $xStart) $v15 = $xStart + 1; - elseif($xEnd < $xStart) $v15 = $xStart; - else $v39 = false; - - if($yEnd > $yStart) $v17 = $yStart + 1; - elseif($yEnd < $yStart) $v17 = $yStart; - else $v40 = false; - - if($zEnd > $zStart) $v19 = $zStart + 1; - elseif($zEnd < $zStart) $v19 = $zStart; - else $v41 = false; - + + if($xEnd > $xStart) { + $v15 = $xStart + 1; + } elseif($xEnd < $xStart) { + $v15 = $xStart; + } else { + $v39 = false; + } + + if($yEnd > $yStart) { + $v17 = $yStart + 1; + } elseif($yEnd < $yStart) { + $v17 = $yStart; + } else { + $v40 = false; + } + + if($zEnd > $zStart) { + $v19 = $zStart + 1; + } elseif($zEnd < $zStart) { + $v19 = $zStart; + } else { + $v41 = false; + } + $v21 = $v23 = $v25 = 999.0; //nice mojang x2 $v27 = $end->x - $start->x; $v29 = $end->y - $start->y; $v31 = $end->z - $start->z; - - if($v39) $v21 = $v27 == 0 ? ($v15 - $start->x)*INF : ($v15 - $start->x) / $v27; - if($v40) $v23 = $v29 == 0 ? ($v17 - $start->y)*INF : ($v17 - $start->y) / $v29; - if($v41) $v25 = $v31 == 0 ? ($v19 - $start->z)*INF : ($v19 - $start->z) / $v31; - - if($v21 < $v23 && $v21 < $v25){ + + if($v39) { + $v21 = $v27 == 0 ? ($v15 - $start->x) * INF : ($v15 - $start->x) / $v27; + } + if($v40) { + $v23 = $v29 == 0 ? ($v17 - $start->y) * INF : ($v17 - $start->y) / $v29; + } + if($v41) { + $v25 = $v31 == 0 ? ($v19 - $start->z) * INF : ($v19 - $start->z) / $v31; + } + + if($v21 < $v23 && $v21 < $v25) { $v42 = $xEnd > $xStart ? 4 : 5; - + $start->x = $v15; $start->y += $v29 * $v21; $start->z += $v31 * $v21; - }elseif($v23 < $v25){ + } elseif($v23 < $v25) { $v42 = $yEnd > $yStart ? 0 : 1; - + $start->x += $v27 * $v23; $start->y = $v17; $start->z += $v31 * $v23; - }else{ + } else { $v42 = $zEnd > $zStart ? 2 : 3; - + $start->x += $v27 * $v25; $start->y += $v29 * $v25; $start->z = $v19; } - + $xStart = floor($start->x); - if($v42 == 5) --$xStart; - + if($v42 == 5) { + --$xStart; + } + $yStart = floor($start->y); - if($v42 == 1) --$yStart; - + if($v42 == 1) { + --$yStart; + } + $zStart = floor($start->z); - if($v42 == 3) --$zStart; - + if($v42 == 3) { + --$zStart; + } + [$blockID, $blockMeta] = $this->level->getBlock($xStart, $yStart, $zStart); $block = StaticBlock::getBlock($blockID); $aabb = $block::getAABB($this, $xStart, $yStart, $zStart); - if($blockID > 0 && $aabb != null){ //TODO also block::canColideCheck + if($blockID > 0 && $aabb != null) { //TODO also block::canColideCheck $v38 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end); - if($v38 != null) return $v38; + if($v38 != null) { + return $v38; + } } } - + return null; } - - public function isLavaInBB($aabb){ + + public function isLavaInBB($aabb) { $minX = floor($aabb->minX); $maxX = floor($aabb->maxX + 1); $minY = floor($aabb->minY); $maxY = floor($aabb->maxY + 1); $minZ = floor($aabb->minZ); $maxZ = floor($aabb->maxZ + 1); - - for($x = $minX; $x < $maxX; ++$x){ - for($y = $minY; $y < $maxY; ++$y){ - for($z = $minZ; $z < $maxZ; ++$z){ + + for($x = $minX; $x < $maxX; ++$x) { + for($y = $minY; $y < $maxY; ++$y) { + for($z = $minZ; $z < $maxZ; ++$z) { $blockId = $this->level->getBlockID($x, $y, $z); - - if($blockId == LAVA || $blockId == STILL_LAVA) return true; + + if($blockId == LAVA || $blockId == STILL_LAVA) { + return true; + } } } } - + return false; } - - public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, Entity $entity){ + + public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, Entity $entity) { $minX = floor($aabb->minX); $maxX = ceil($aabb->maxX); $minY = floor($aabb->minY); $maxY = ceil($aabb->maxY); $minZ = floor($aabb->minZ); $maxZ = ceil($aabb->maxZ); - + //1.5.2 checks that all chunks exist, not needed here i think - + $appliedVelocity = false; $velocityVec = new Vector3(0, 0, 0); - for($x = $minX; $x < $maxX; ++$x){ - for($y = $minY; $y < $maxY; ++$y){ - for($z = $minZ; $z < $maxZ; ++$z){ + for($x = $minX; $x < $maxX; ++$x) { + for($y = $minY; $y < $maxY; ++$y) { + for($z = $minZ; $z < $maxZ; ++$z) { [$block, $meta] = $this->level->getBlock($x, $y, $z); - if(($materialType == 0 && ($block == WATER || $block == STILL_WATER)) || ($materialType == 1 && ($block == LAVA || $block == STILL_LAVA))){ //TODO better material system + if(($materialType == 0 && ($block == WATER || $block == STILL_WATER)) || ($materialType == 1 && ($block == LAVA || $block == STILL_LAVA))) { //TODO better material system $v16 = ($y + 1) - LiquidBlock::getPercentAir($meta); - if($maxY >= $v16){ + if($maxY >= $v16) { $appliedVelocity = true; StaticBlock::$prealloc[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec); } - + } } } } - - if($velocityVec->length() > 0){ //also checks is player flying + + if($velocityVec->length() > 0) { //also checks is player flying $velocityVec = $velocityVec->normalize(); //TODO do not use vec methods $v18 = 0.014; $entity->speedX += $velocityVec->x * $v18; $entity->speedY += $velocityVec->y * $v18; $entity->speedZ += $velocityVec->z * $v18; } - + return $appliedVelocity; } /** - * @param Entity $e - * @param AxisAlignedBB $aABB * @return AxisAlignedBB[] */ public function getCubes(Entity $e, AxisAlignedBB $aABB) { @@ -249,74 +301,76 @@ class Level{ $y1 = floor($aABB->maxY + 1); $z0 = floor($aABB->minZ); $z1 = floor($aABB->maxZ + 1); - + for($x = $x0; $x < $x1; ++$x) { for($z = $z0; $z < $z1; ++$z) { for($y = $y0 - 1; $y < $y1; ++$y) { $bid = $this->level->getBlockID($x, $y, $z); - if($bid > 0){ + if($bid > 0) { $blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z); - - foreach($blockBounds as $blockBound){ - if($aABB->intersectsWith($blockBound)) $aABBs[] = $blockBound; + + foreach($blockBounds as $blockBound) { + if($aABB->intersectsWith($blockBound)) { + $aABBs[] = $blockBound; + } } } } } } - + return $aABBs; } - - public function __destruct(){ - if(isset($this->level)){ + + public function __destruct() { + if(isset($this->level)) { $this->save(false, false, false, false); $this->level->close(); unset($this->level); } unset($this->mobSpawner->level); } - - public function isDay(){ + + public function isDay() { return $this->getTime() % 19200 < TimeAPI::$phases["sunset"]; } - public function isNight(){ + public function isNight() { $t = $this->getTime() % 19200; return $t < TimeAPI::$phases["sunrise"] && $t > TimeAPI::$phases["sunset"]; } - public function save($force = false, $entities = true, $tiles = true, $blockupdates = true){ - if(!isset($this->level)){ + public function save($force = false, $entities = true, $tiles = true, $blockupdates = true) { + if(!isset($this->level)) { return false; } - if($this->server->saveEnabled === false and $force === false){ + if($this->server->saveEnabled === false and $force === false) { return; } - if($entities){ + if($entities) { $entities = []; - - foreach($this->entityList as $entity){ - if($entity instanceof Entity){ + + foreach($this->entityList as $entity) { + if($entity instanceof Entity) { $entities[] = $entity->createSaveData(); } } $this->entities->setAll($entities); $this->entities->save(); } - if($tiles){ + if($tiles) { $tiles = []; - foreach($this->server->api->tile->getAll($this) as $tile){ + foreach($this->server->api->tile->getAll($this) as $tile) { $tiles[] = $tile->data; } $this->tiles->setAll($tiles); $this->tiles->save(); } - if($blockupdates){ + if($blockupdates) { $blockUpdates = []; $updates = $this->server->query("SELECT x,y,z,type,delay FROM blockUpdates WHERE level = '" . $this->getName() . "';"); - if($updates !== false and $updates !== true){ + if($updates !== false and $updates !== true) { $timeu = microtime(true); - while(($bupdate = $updates->fetchArray(SQLITE3_ASSOC)) !== false){ + while(($bupdate = $updates->fetchArray(SQLITE3_ASSOC)) !== false) { $bupdate["delay"] = max(1, ($bupdate["delay"] - $timeu) * 20); $blockUpdates[] = $bupdate; } @@ -332,96 +386,98 @@ class Level{ $this->nextSave = microtime(true) + 45; } - public function getName(){ + public function getName() { return $this->name;//return $this->level->getData("name"); } - public function useChunk($X, $Z, Player $player){ - if(!isset($this->usedChunks[$X . "." . $Z])){ + public function useChunk($X, $Z, Player $player) { + if(!isset($this->usedChunks[$X . "." . $Z])) { $this->usedChunks[$X . "." . $Z] = []; } $this->usedChunks[$X . "." . $Z][$player->CID] = true; - if(isset($this->level)){ + if(isset($this->level)) { $this->level->loadChunk($X, $Z); } } - public function freeAllChunks(Player $player){ - foreach($this->usedChunks as $i => $c){ + public function freeAllChunks(Player $player) { + foreach($this->usedChunks as $i => $c) { unset($this->usedChunks[$i][$player->CID]); } } - public function freeChunk($X, $Z, Player $player){ + 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()){ + + 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){ + 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 isObstructed($e) { + } - - public function checkSleep(){ //TODO events? - if(count($this->players) == 0) return false; - if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla - foreach($this->players as $p){ - if(!$p->isSleeping || $p->sleepingTime < 100){ + + public function checkSleep() { //TODO events? + if(count($this->players) == 0) { + return false; + } + if($this->server->api->time->getPhase($this) === "night") { //TODO vanilla + foreach($this->players as $p) { + if(!$p->isSleeping || $p->sleepingTime < 100) { return false; } } $this->server->api->time->set("day", $this); } - foreach($this->players as $p){ + foreach($this->players as $p) { $p->stopSleep(); } } - - public function checkThings(){ - if(!isset($this->level)){ + + public function checkThings() { + if(!isset($this->level)) { return false; } $now = microtime(true); $this->players = $this->server->api->player->getAll($this); - - if(count($this->changedCount) > 0){ + + if(count($this->changedCount) > 0) { arsort($this->changedCount); $reorder = false; - foreach($this->changedCount as $index => $count){ - if($count < 582){//Optimal value, calculated using the relation between minichunks and single packets + foreach($this->changedCount as $index => $count) { + if($count < 582) {//Optimal value, calculated using the relation between minichunks and single packets break; } - foreach($this->players as $p){ + foreach($this->players as $p) { unset($p->chunksLoaded[$index]); } $reorder = true; unset($this->changedBlocks[$index]); } $this->changedCount = []; - - if($reorder){ - foreach($this->players as $p){ + + if($reorder) { + foreach($this->players as $p) { $p->orderChunks(); } } - - if(count($this->changedBlocks) > 0){ - foreach($this->changedBlocks as $i => $blocks){ - foreach($blocks as $b){ + + if(count($this->changedBlocks) > 0) { + foreach($this->changedBlocks as $i => $blocks) { + foreach($blocks as $b) { $pk = new UpdateBlockPacket; $pk->x = ($b >> 32) & 0xff; $pk->y = ($b >> 24) & 0xff; $pk->z = ($b >> 16) & 0xff; - $pk->block =($b >> 8) & 0xff; + $pk->block = ($b >> 8) & 0xff; $pk->meta = $b & 0xff; $this->server->api->player->broadcastPacket($this->players, $pk); } @@ -430,34 +486,34 @@ class Level{ $this->changedBlocks = []; } } - - if($this->nextSave < $now){ + + if($this->nextSave < $now) { $this->save(false, true, true, true); } } - public function isSpawnChunk($X, $Z){ + public function isSpawnChunk($X, $Z) { $spawnX = $this->level->getData("spawnX") >> 4; $spawnZ = $this->level->getData("spawnZ") >> 4; return abs($X - $spawnX) <= 1 and abs($Z - $spawnZ) <= 1; } - public function getBlockRaw(Vector3 $pos){ + public function getBlockRaw(Vector3 $pos) { $b = $this->level->getBlock($pos->x, $pos->y, $pos->z); return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this)); } - public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){ - if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false){ - if($direct === true){ + public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true) { + if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false) { + if($direct === true) { $this->addBlockToSendQueue($pos->x, $pos->y, $pos->z, $block->id, $block->meta); - }elseif($direct === false){ - if(!($pos instanceof Position)){ + } elseif($direct === false) { + if(!($pos instanceof Position)) { $pos = new Position($pos->x, $pos->y, $pos->z, $this); } $block->position($pos); $i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4); - if(!isset($this->changedBlocks[$i])){ + if(!isset($this->changedBlocks[$i])) { $this->changedBlocks[$i] = []; $this->changedCount[$i] = 0; } @@ -467,59 +523,75 @@ class Level{ } return $ret; } - public function fastSetBlockUpdateMeta($x, $y, $z, $meta, $updateBlock = false){ + public function fastSetBlockUpdateMeta($x, $y, $z, $meta, $updateBlock = false) { $this->level->setBlockDamage($x, $y, $z, $meta); $id = $this->level->getBlockID($x, $y, $z); $this->addBlockToSendQueue($x, $y, $z, $id, $meta); - if($updateBlock){ + if($updateBlock) { $this->updateNeighborsAt($x, $y, $z, $id); } } - - public function updateNeighborsAt($x, $y, $z, $oldID){ + + public function updateNeighborsAt($x, $y, $z, $oldID) { $block = $this->level->getBlockID($x - 1, $y, $z); - if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID); + if($block) { + StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID); + } $block = $this->level->getBlockID($x + 1, $y, $z); - if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID); - + if($block) { + StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID); + } + $block = $this->level->getBlockID($x, $y - 1, $z); - if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID); + if($block) { + StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID); + } $block = $this->level->getBlockID($x, $y + 1, $z); - if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID); - + if($block) { + StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID); + } + $block = $this->level->getBlockID($x, $y, $z - 1); - if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID); + if($block) { + StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID); + } $block = $this->level->getBlockID($x, $y, $z + 1); - if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID); + if($block) { + StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID); + } } - - public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false){ + + public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false) { $oldID = $this->level->getBlockID($x, $y, $z); - + $this->level->setBlock($x, $y, $z, $id, $meta); - - if($tiles){ //TODO rewrite + + if($tiles) { //TODO rewrite $this->server->api->tile->invalidateAll($this, $x, $y, $z); } - if($updateBlocksAround){ + if($updateBlocksAround) { self::updateNeighborsAt($x, $y, $z, $oldID); } $this->addBlockToSendQueue($x, $y, $z, $id, $meta); } - - public function onTick(PocketMinecraftServer $server, $currentTime){ - if(!$this->stopTime) ++$this->time; - for($cX = 0; $cX < 16; ++$cX){ - for($cZ = 0; $cZ < 16; ++$cZ){ + + public function onTick(PocketMinecraftServer $server, $currentTime) { + if(!$this->stopTime) { + ++$this->time; + } + for($cX = 0; $cX < 16; ++$cX) { + for($cZ = 0; $cZ < 16; ++$cZ) { $index = $this->level->getIndex($cX, $cZ); - if(!isset($this->level->chunks[$index]) || $this->level->chunks[$index] === false) continue; - for($c = 0; $c <= 20; ++$c){ + if(!isset($this->level->chunks[$index]) || $this->level->chunks[$index] === false) { + continue; + } + for($c = 0; $c <= 20; ++$c) { $xyz = mt_rand(0, 0xffffffff) >> 2; $x = $xyz & 0xf; $z = ($xyz >> 8) & 0xf; $y = ($xyz >> 16) & 0x7f; $id = $this->level->fastGetBlockID($cX, $y >> 4, $cZ, $x, $y & 0xf, $z, $index); - if(isset(self::$randomUpdateBlocks[$id])){ + if(isset(self::$randomUpdateBlocks[$id])) { $cl = StaticBlock::$prealloc[$id]; $cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4)); } @@ -528,100 +600,99 @@ class Level{ } $this->totalMobsAmount = 0; $post = []; - - foreach($this->entityList as $k => $e){ - if(!($e instanceof Entity)){ + + foreach($this->entityList as $k => $e) { + if(!($e instanceof Entity)) { unset($this->entityList[$k]); unset($this->server->entities[$k]); //TODO try to remove from $entityListPositioned? continue; } - + $dd = CORRECT_ENTITY_CLASSES[$e->class] ?? false; - if($dd === false || ($dd !== true && !isset($dd[$e->type]))){ + if($dd === false || ($dd !== true && !isset($dd[$e->type]))) { ConsoleAPI::warn("Entity $k has invalid entity! {$e->class} {$e->type}"); $e->close(); - + unset($this->entityList[$k]); unset($this->server->entities[$k]); - - $curChunkX = (int)$e->x >> 4; - $curChunkZ = (int)$e->z >> 4; + + $curChunkX = (int) $e->x >> 4; + $curChunkZ = (int) $e->z >> 4; $index = "$curChunkX $curChunkZ"; - - if(isset($this->entityListPositioned[$index][$k])){ + + if(isset($this->entityListPositioned[$index][$k])) { unset($this->entityListPositioned[$index][$k]); } - + continue; } - $curChunkX = (int)$e->x >> 4; - $curChunkZ = (int)$e->z >> 4; - if($e->class === ENTITY_MOB && !$e->isPlayer()){ + $curChunkX = (int) $e->x >> 4; + $curChunkZ = (int) $e->z >> 4; + if($e->class === ENTITY_MOB && !$e->isPlayer()) { ++$this->totalMobsAmount; } - if($e->isPlayer() || $e->needsUpdate){ + if($e->isPlayer() || $e->needsUpdate) { $e->update($currentTime); - if(!$e->isPlayer()) $post[] = $k; + if(!$e->isPlayer()) { + $post[] = $k; + } } - - if($e instanceof Entity){ - $newChunkX = (int)$e->x >> 4; - $newChunkZ = (int)$e->z >> 4; - if($e->chunkX != $newChunkX || $e->chunkZ != $newChunkZ){ + + if($e instanceof Entity) { + $newChunkX = (int) $e->x >> 4; + $newChunkZ = (int) $e->z >> 4; + if($e->chunkX != $newChunkX || $e->chunkZ != $newChunkZ) { $oldIndex = "{$e->chunkX} {$e->chunkZ}"; unset($this->entityListPositioned[$oldIndex][$e->eid]); - - if($e->level == $this){ + + if($e->level == $this) { $e->chunkX = $newChunkX; $e->chunkZ = $newChunkZ; $newIndex = "$newChunkX $newChunkZ"; $this->entityListPositioned[$newIndex][$e->eid] = $e->eid; } } - if($e->level != $this && isset($this->entityListPositioned["$curChunkX $curChunkZ"])){ + if($e->level != $this && isset($this->entityListPositioned["$curChunkX $curChunkZ"])) { unset($this->entityListPositioned["$curChunkX $curChunkZ"][$e->eid]); - }elseif($curChunkX != $newChunkX || $curChunkZ != $newChunkZ){ + } elseif($curChunkX != $newChunkX || $curChunkZ != $newChunkZ) { $index = "$curChunkX $curChunkZ"; //while creating index like $curChunkX << 32 | $curChunkZ is faster, placing it inside list is slow $newIndex = "$newChunkX $newChunkZ"; unset($this->entityListPositioned[$index][$e->eid]); $this->entityListPositioned[$newIndex][$e->eid] = $e->eid; //set to e->eid to avoid possible memory leaks } - - if($e->searchForClosestPlayers){ + + if($e->searchForClosestPlayers) { $e->handlePrePlayerSearcher(); - - foreach($this->players as $player){ - $dist = ($e->x - $player->entity->x)*($e->x - $player->entity->x) + ($e->y - $player->entity->y)*($e->y - $player->entity->y) + ($e->z - $player->entity->z)*($e->z - $player->entity->z); + + foreach($this->players as $player) { + $dist = ($e->x - $player->entity->x) * ($e->x - $player->entity->x) + ($e->y - $player->entity->y) * ($e->y - $player->entity->y) + ($e->z - $player->entity->z) * ($e->z - $player->entity->z); $e->handlePlayerSearcher($player, $dist); } } - - - - }elseif(isset($this->entityListPositioned["$curChunkX $curChunkZ"])){ + + } elseif(isset($this->entityListPositioned["$curChunkX $curChunkZ"])) { unset($this->entityListPositioned["$curChunkX $curChunkZ"][$k]); } } - + $this->checkSleep(); - - if($server->ticks % 100 === 0){ + + if($server->ticks % 100 === 0) { $this->mobSpawner->handle(); } - - - foreach($this->players as $player){ - foreach($post as $eid){ + + foreach($this->players as $player) { + foreach($post as $eid) { $e = $this->entityList[$eid] ?? false; - if(!($e instanceof Entity)){ + if(!($e instanceof Entity)) { continue; } $player->addEntityMovementUpdateToQueue($e); } $player->sendEntityMovementUpdateQueue(); - - foreach($this->queuedBlockUpdates as $ind => $update){ + + foreach($this->queuedBlockUpdates as $ind => $update) { $x = $update[0]; $y = $update[1]; $z = $update[2]; @@ -632,42 +703,44 @@ class Level{ } $player->sendBlockUpdateQueue(); } - + $this->queuedBlockUpdates = []; } - - public function isBoundingBoxOnFire(AxisAlignedBB $bb){ + + public function isBoundingBoxOnFire(AxisAlignedBB $bb) { $minX = floor($bb->minX); $maxX = floor($bb->maxX + 1); $minY = floor($bb->minY); $maxY = floor($bb->maxY + 1); $minZ = floor($bb->minZ); $maxZ = floor($bb->maxZ + 1); - - for($x = $minX; $x < $maxX; ++$x){ - for($y = $minY; $y < $maxY; ++$y){ - for($z = $minZ; $z < $maxZ; ++$z){ + + for($x = $minX; $x < $maxX; ++$x) { + for($y = $minY; $y < $maxY; ++$y) { + for($z = $minZ; $z < $maxZ; ++$z) { $blockAt = $this->level->getBlockID($x, $y, $z); - if($blockAt == FIRE || $blockAt == STILL_LAVA || $blockAt == LAVA) return true; + if($blockAt == FIRE || $blockAt == STILL_LAVA || $blockAt == LAVA) { + return true; + } } } } - + return false; } - public function getEntitiesInAABBOfType(AxisAlignedBB $bb, $class){ - $minChunkX = ((int)($bb->minX)) >> 4; - $minChunkZ = ((int)($bb->minZ)) >> 4; - $maxChunkX = ((int)($bb->maxX)) >> 4; - $maxChunkZ = ((int)($bb->maxZ)) >> 4; + public function getEntitiesInAABBOfType(AxisAlignedBB $bb, $class) { + $minChunkX = ((int) ($bb->minX)) >> 4; + $minChunkZ = ((int) ($bb->minZ)) >> 4; + $maxChunkX = ((int) ($bb->maxX)) >> 4; + $maxChunkZ = ((int) ($bb->maxZ)) >> 4; $ents = []; - for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){ - for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){ + for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX) { + for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ) { $ind = "$chunkX $chunkZ"; - foreach($this->entityListPositioned[$ind] ?? [] as $ind2 => $entid){ - if(isset($this->entityList[$entid]) && $this->entityList[$entid] instanceof Entity && $this->entityList[$entid]->class === $class && $this->entityList[$entid]->boundingBox->intersectsWith($bb)){ + foreach($this->entityListPositioned[$ind] ?? [] as $ind2 => $entid) { + if(isset($this->entityList[$entid]) && $this->entityList[$entid] instanceof Entity && $this->entityList[$entid]->class === $class && $this->entityList[$entid]->boundingBox->intersectsWith($bb)) { $ents[$entid] = $this->entityList[$entid]; - }elseif(!isset($this->entityList[$entid])){ + } elseif(!isset($this->entityList[$entid])) { ConsoleAPI::debug("Removing entity from level array at index $ind/$ind2: $entid"); unset($this->entityListPositioned[$ind][$ind2]); } @@ -677,23 +750,22 @@ class Level{ return $ents; } /** - * @param AxisAlignedBB $bb * @return Entity[] */ - public function getEntitiesInAABB(AxisAlignedBB $bb){ - $minChunkX = ((int)($bb->minX)) >> 4; - $minChunkZ = ((int)($bb->minZ)) >> 4; - $maxChunkX = ((int)($bb->maxX)) >> 4; - $maxChunkZ = ((int)($bb->maxZ)) >> 4; + public function getEntitiesInAABB(AxisAlignedBB $bb) { + $minChunkX = ((int) ($bb->minX)) >> 4; + $minChunkZ = ((int) ($bb->minZ)) >> 4; + $maxChunkX = ((int) ($bb->maxX)) >> 4; + $maxChunkZ = ((int) ($bb->maxZ)) >> 4; $ents = []; //TODO also index by chunkY? - for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){ - for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){ + for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX) { + for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ) { $ind = "$chunkX $chunkZ"; - foreach($this->entityListPositioned[$ind] ?? [] as $ind2 => $entid){ - if(isset($this->entityList[$entid]) && $this->entityList[$entid] instanceof Entity && $this->entityList[$entid]->boundingBox->intersectsWith($bb)){ + foreach($this->entityListPositioned[$ind] ?? [] as $ind2 => $entid) { + if(isset($this->entityList[$entid]) && $this->entityList[$entid] instanceof Entity && $this->entityList[$entid]->boundingBox->intersectsWith($bb)) { $ents[$entid] = $this->entityList[$entid]; - }elseif(!isset($this->entityList[$entid])){ + } elseif(!isset($this->entityList[$entid])) { ConsoleAPI::debug("Removing entity from level array at index $ind/$ind2: $entid"); unset($this->entityListPositioned[$ind][$ind2]); } @@ -702,147 +774,147 @@ class Level{ } return $ents; } - - public function addBlockToSendQueue($x, $y, $z, $id, $meta){ - if(!$this->forceDisableBlockQueue){ + + public function addBlockToSendQueue($x, $y, $z, $id, $meta) { + if(!$this->forceDisableBlockQueue) { $this->queuedBlockUpdates["$x $y $z"] = [$x, $y, $z, $id, $meta]; } } - - public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){ - if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){ + + public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false) { + if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0) { return false; } $oldID = $this->level->getBlockID($pos->x, $pos->y, $pos->z); $ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata()); - if($ret === true){ - if(!($pos instanceof Position)){ + if($ret === true) { + if(!($pos instanceof Position)) { $pos = new Position($pos->x, $pos->y, $pos->z, $this); } $block->position($pos); - if($direct === true){ + if($direct === true) { $this->addBlockToSendQueue($pos->x, $pos->y, $pos->z, $block->id, $block->meta); - }else{ + } else { $i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4); - if(!isset($this->changedBlocks[$i])){ + if(!isset($this->changedBlocks[$i])) { $this->changedBlocks[$i] = []; $this->changedCount[$i] = 0; } $this->changedBlocks[$i][] = ($block->x & 0xff) << 32 | ($block->y & 0xff) << 24 | ($block->z & 0xff) << 16 | ($block->getID() & 0xff) << 8 | ($block->meta & 0xff); ++$this->changedCount[$i]; } - - if($tiles === true){ + + if($tiles === true) { $this->server->api->tile->invalidateAll($this, $pos->x, $pos->y, $pos->z); } - - if($update === true){ + + if($update === true) { $this->updateNeighborsAt($pos->x, $pos->y, $pos->z, $oldID); } - + } return $ret; } - public function getMiniChunk($X, $Z, $Y){ - if(!isset($this->level)){ + public function getMiniChunk($X, $Z, $Y) { + if(!isset($this->level)) { return false; } return $this->level->getMiniChunk($X, $Z, $Y); } - public function setMiniChunk($X, $Z, $Y, $data){ - if(!isset($this->level)){ + public function setMiniChunk($X, $Z, $Y, $data) { + if(!isset($this->level)) { return false; } $this->changedCount[$X . ":" . $Y . ":" . $Z] = 4096; return $this->level->setMiniChunk($X, $Z, $Y, $data); } - public function loadChunk($X, $Z){ - if(!isset($this->level)){ + public function loadChunk($X, $Z) { + if(!isset($this->level)) { return false; } return $this->level->loadChunk($X, $Z); } - public function unloadChunk($X, $Z, $force = false){ - if(!isset($this->level)){ + public function unloadChunk($X, $Z, $force = false) { + if(!isset($this->level)) { return false; } - if($force !== true and $this->isSpawnChunk($X, $Z)){ + if($force !== true and $this->isSpawnChunk($X, $Z)) { return false; } return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled); } - public function getOrderedChunk($X, $Z, $Yndex){ - if(!isset($this->level)){ + public function getOrderedChunk($X, $Z, $Yndex) { + if(!isset($this->level)) { return false; } $raw = []; - for($Y = 0; $Y < 8; ++$Y){ - if(($Yndex & (1 << $Y)) > 0){ + for($Y = 0; $Y < 8; ++$Y) { + if(($Yndex & (1 << $Y)) > 0) { $raw[$Y] = $this->level->getMiniChunk($X, $Z, $Y); } } $ordered = ""; $flag = chr($Yndex); - for($j = 0; $j < 256; ++$j){ + for($j = 0; $j < 256; ++$j) { $ordered .= $flag; - foreach($raw as $mini){ + foreach($raw as $mini) { $ordered .= substr($mini, $j << 5, 24); //16 + 8 } } return $ordered; } - public function getOrderedMiniChunk($X, $Z, $Y){ - if(!isset($this->level)){ + public function getOrderedMiniChunk($X, $Z, $Y) { + if(!isset($this->level)) { return false; } $raw = $this->level->getMiniChunk($X, $Z, $Y); $ordered = ""; $flag = chr(1 << $Y); - for($j = 0; $j < 256; ++$j){ + for($j = 0; $j < 256; ++$j) { $ordered .= $flag . substr($raw, $j << 5, 24); //16 + 8 } return $ordered; } - public function getSafeSpawn($spawn = false){ - if($spawn === false){ + public function getSafeSpawn($spawn = false) { + if($spawn === false) { $spawn = $this->getSpawn(); } - if($spawn instanceof Vector3){ + if($spawn instanceof Vector3) { $x = (int) round($spawn->x); $fy = $y = (int) round($spawn->y); $z = (int) round($spawn->z); - if($x < 0 || $x > 255 || $z < 0 || $z > 255){ + if($x < 0 || $x > 255 || $z < 0 || $z > 255) { return new Position($x, 128, $z, $this); } - for(; $y > 0; --$y){ + for(; $y > 0; --$y) { $v = new Vector3($x, $y, $z); $b = $this->getBlock($v->getSide(0)); - if($b === false){ + if($b === false) { return $spawn; - }elseif(!($b instanceof AirBlock)){ + } elseif(!($b instanceof AirBlock)) { break; } } - if($y == 0){ + if($y == 0) { return new Position($x, $fy, $z, $this); //force tp to default if pos is empty } - for(; $y < 128; ++$y){ + for(; $y < 128; ++$y) { $v = new Vector3($x, $y, $z); - if($this->getBlock($v->getSide(1)) instanceof AirBlock){ - if($this->getBlock($v) instanceof AirBlock){ + if($this->getBlock($v->getSide(1)) instanceof AirBlock) { + if($this->getBlock($v) instanceof AirBlock) { return new Position($x, $y, $z, $this); } - }else{ + } else { ++$y; } } @@ -851,13 +923,13 @@ class Level{ return false; } - public function getSpawn(){ - if(!isset($this->level)){ + public function getSpawn() { + if(!isset($this->level)) { return false; } return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this); } - + /** * @param number $x * @param number $y @@ -865,26 +937,25 @@ class Level{ * @param boolean $positionfy assign coordinates to block or not * @return GenericBlock | false if failed */ - - public function getBlockWithoutVector($x, $y, $z, $positionfy = true){ - $b = $this->level->getBlock((int)$x, (int)$y, (int)$z); + + public function getBlockWithoutVector($x, $y, $z, $positionfy = true) { + $b = $this->level->getBlock((int) $x, (int) $y, (int) $z); return BlockAPI::get($b[0], $b[1], $positionfy ? new Position($x, $y, $z, $this) : false); } - + /** * Recommended to use {@link getBlockWithoutVector()} if you dont have the vector - * @param Vector3 $pos * @return Block|false if failed */ - public function getBlock(Vector3 $pos){ - if(!isset($this->level) or ($pos instanceof Position) and $pos->level !== $this){ + public function getBlock(Vector3 $pos) { + if(!isset($this->level) or ($pos instanceof Position) and $pos->level !== $this) { return false; } return $this->getBlockWithoutVector($pos->x, $pos->y, $pos->z); } - public function setSpawn(Vector3 $pos){ - if(!isset($this->level)){ + public function setSpawn(Vector3 $pos) { + if(!isset($this->level)) { return false; } $this->level->setData("spawnX", $pos->x); @@ -892,69 +963,69 @@ class Level{ $this->level->setData("spawnZ", $pos->z); } - public function getTime(){ + public function getTime() { return (int) ($this->time); } - public function setTime($time){ + public function setTime($time) { $this->startTime = $this->time = (int) $time; $this->startCheck = microtime(true); $this->checkTime(); } - public function checkTime(){ - if(!isset($this->level)){ + public function checkTime() { + if(!isset($this->level)) { return false; } $now = microtime(true); - if($this->stopTime){ + if($this->stopTime) { $time = $this->startTime; - }else{ + } else { $time = $this->startTime + ($now - $this->startCheck) * 20; } - if($this->server->api->dhandle("time.change", ["level" => $this, "time" => $time]) !== false){ //send time to player every 5 ticks + if($this->server->api->dhandle("time.change", ["level" => $this, "time" => $time]) !== false) { //send time to player every 5 ticks $this->time = $time; $pk = new SetTimePacket; $pk->time = (int) $this->time; $pk->started = $this->stopTime == false; $this->server->api->player->broadcastPacket($this->players, $pk); - }else{ + } else { $this->time -= 20 * 13; } } - - public function isTimeStopped(){ + + public function isTimeStopped() { return $this->stopTime; } - - public function stopTime(){ + + public function stopTime() { $this->stopTime = true; $this->startCheck = 0; $this->checkTime(); } - public function startTime(){ + public function startTime() { $this->stopTime = false; $this->startCheck = microtime(true); $this->checkTime(); } - public function getSeed(){ - if(!isset($this->level)){ + public function getSeed() { + if(!isset($this->level)) { return false; } return (int) $this->level->getData("seed"); } - public function setSeed($seed){ - if(!isset($this->level)){ + public function setSeed($seed) { + if(!isset($this->level)) { return false; } $this->level->setData("seed", (int) $seed); } - public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){ - if(!isset($this->level)){ + public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED) { + if(!isset($this->level)) { return false; } return $this->server->api->block->scheduleBlockUpdate($pos, $delay, $type); diff --git a/src/world/LevelImport.php b/src/world/LevelImport.php index 49f21773..b42743dc 100644 --- a/src/world/LevelImport.php +++ b/src/world/LevelImport.php @@ -1,33 +1,33 @@ path = $path; } - public function import(){ - if(file_exists($this->path . "tileEntities.dat")){ //OldPM + public function import() { + if(file_exists($this->path . "tileEntities.dat")) { //OldPM $level = unserialize(file_get_contents($this->path . "level.dat")); console("[INFO] Importing OldPM level \"" . $level["LevelName"] . "\" to PMF format"); $entities = new Config($this->path . "entities.yml", CONFIG_YAML, unserialize(file_get_contents($this->path . "entities.dat"))); $entities->save(); $tiles = new Config($this->path . "tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path . "tileEntities.dat"))); $tiles->save(); - }elseif(file_exists($this->path . "chunks.dat") and file_exists($this->path . "level.dat")){ //Pocket + } elseif(file_exists($this->path . "chunks.dat") and file_exists($this->path . "level.dat")) { //Pocket $nbt = new NBT(); $nbt->load(substr(file_get_contents($this->path . "level.dat"), 8)); $level = array_shift($nbt->tree); - if($level["LevelName"] == ""){ + if($level["LevelName"] == "") { $level["LevelName"] = "world" . time(); } console("[INFO] Importing Pocket level \"" . $level["LevelName"] . "\" to PMF format"); unset($level["Player"]); $nbt->load(substr(file_get_contents($this->path . "entities.dat"), 12)); $entities = array_shift($nbt->tree); - if(!isset($entities["TileEntities"])){ + if(!isset($entities["TileEntities"])) { $entities["TileEntities"] = []; } $tiles = $entities["TileEntities"]; @@ -36,7 +36,7 @@ class LevelImport{ $entities->save(); $tiles = new Config($this->path . "tiles.yml", CONFIG_YAML, $tiles); $tiles->save(); - }else{ + } else { return false; } @@ -54,8 +54,8 @@ class LevelImport{ $chunks = new PocketChunkParser(); $chunks->loadFile($this->path . "chunks.dat"); $chunks->loadMap(); - for($Z = 0; $Z < 16; ++$Z){ - for($X = 0; $X < 16; ++$X){ + for($Z = 0; $Z < 16; ++$Z) { + for($X = 0; $X < 16; ++$X) { $chunk = [ 0 => "", 1 => "", @@ -66,18 +66,18 @@ class LevelImport{ 6 => "", 7 => "" ]; - for($z = 0; $z < 16; ++$z){ - for($x = 0; $x < 16; ++$x){ + for($z = 0; $z < 16; ++$z) { + for($x = 0; $x < 16; ++$x) { $block = $chunks->getChunkColumn($X, $Z, $x, $z, 0); $meta = $chunks->getChunkColumn($X, $Z, $x, $z, 1); - for($Y = 0; $Y < 8; ++$Y){ + for($Y = 0; $Y < 8; ++$Y) { $chunk[$Y] .= substr($block, $Y << 4, 16); $chunk[$Y] .= substr($meta, $Y << 3, 8); $chunk[$Y] .= "\x00\x00\x00\x00\x00\x00\x00\x00"; } } } - foreach($chunk as $Y => $data){ + foreach($chunk as $Y => $data) { $pmf->setMiniChunk($X, $Z, $Y, $data); } $pmf->saveChunk($X, $Z); @@ -86,15 +86,29 @@ class LevelImport{ } $chunks->map = null; $chunks = null; - if(file_exists($this->path . "level.dat")) @unlink($this->path . "level.dat"); - if(file_exists($this->path . "level.dat_old")) @unlink($this->path . "level.dat_old"); - if(file_exists($this->path . "player.dat")) @unlink($this->path . "player.dat"); - if(file_exists($this->path . "entities.dat")) @unlink($this->path . "entities.dat"); - if(file_exists($this->path . "chunks.dat")) @unlink($this->path . "chunks.dat"); - if(file_exists($this->path . "chunks.dat.gz")) @unlink($this->path . "chunks.dat.gz"); - if(file_exists($this->path . "tiles.dat")) @unlink($this->path . "tiles.dat"); + if(file_exists($this->path . "level.dat")) { + @unlink($this->path . "level.dat"); + } + if(file_exists($this->path . "level.dat_old")) { + @unlink($this->path . "level.dat_old"); + } + if(file_exists($this->path . "player.dat")) { + @unlink($this->path . "player.dat"); + } + if(file_exists($this->path . "entities.dat")) { + @unlink($this->path . "entities.dat"); + } + if(file_exists($this->path . "chunks.dat")) { + @unlink($this->path . "chunks.dat"); + } + if(file_exists($this->path . "chunks.dat.gz")) { + @unlink($this->path . "chunks.dat.gz"); + } + if(file_exists($this->path . "tiles.dat")) { + @unlink($this->path . "tiles.dat"); + } unset($chunks, $level, $entities, $tiles, $nbt); return true; } -} \ No newline at end of file +} diff --git a/src/world/MobSpawner.php b/src/world/MobSpawner.php index 48d63306..dd8aa69e 100644 --- a/src/world/MobSpawner.php +++ b/src/world/MobSpawner.php @@ -1,146 +1,149 @@ server = ServerAPI::request(); $this->level = $level; } - public function countEntities(){ + public function countEntities() { return $this->level->totalMobsAmount; } - - public function checkDespawn(Living $living){ - if(!isset($this->entityAffectedPlayers[$living->eid])){ + + public function checkDespawn(Living $living) { + if(!isset($this->entityAffectedPlayers[$living->eid])) { return false; } - + $playerID = $this->entityAffectedPlayers[$living->eid]; $player = $this->level->entityList[$playerID] ?? false; - if($player === false){ + if($player === false) { //TODO try retargetting other player? return true; - }else{ + } else { $diffX = $living->x - $player->x; $diffZ = $living->z - $player->z; - $dist = $diffX*$diffX + $diffZ*$diffZ; - if($dist <= 512){ + $dist = $diffX * $diffX + $diffZ * $diffZ; + if($dist <= 512) { return false; } - + return $dist > 4096 || mt_rand($dist, 4096) == $dist; //force despawn 64 blocks away or despawn randomly } - + } - - public function handle(){ - if($this->countEntities() > self::$MOB_LIMIT || count($this->level->players) <= 0){ + + public function handle() { + if($this->countEntities() > self::$MOB_LIMIT || count($this->level->players) <= 0) { return false; //not spawning } $svd = $this->totalMobsPerPlayer; $this->totalMobsPerPlayer = min(ceil(self::$MOB_LIMIT / count($this->level->players)), self::$maxMobsNearPlayerAtOnce); - if($svd != $this->totalMobsPerPlayer) ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}."); - + if($svd != $this->totalMobsPerPlayer) { + ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}."); + } + return $this->spawnMobs(); } - public function spawnMobs(){ + public function spawnMobs() { $phase = $this->server->api->time->getPhase($this->level); - if(self::$spawnAnimals && ($phase == "day" || $phase == "sunrise")){ //Animal + if(self::$spawnAnimals && ($phase == "day" || $phase == "sunrise")) { //Animal $type = mt_rand(10, 13); $baby = false; $grassOnly = true; - }elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset") && $this->server->difficulty > 0){ //Monster, true night + } elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset") && $this->server->difficulty > 0) { //Monster, true night $type = mt_rand(32, 35); $grassOnly = false; $baby = 2; - }else{ + } else { return false; } - - foreach($this->level->players as $player){ - if(isset($this->playerAffectedEIDS[$player->entity->eid]) && count($this->playerAffectedEIDS[$player->entity->eid]) > $this->totalMobsPerPlayer){ + + foreach($this->level->players as $player) { + if(isset($this->playerAffectedEIDS[$player->entity->eid]) && count($this->playerAffectedEIDS[$player->entity->eid]) > $this->totalMobsPerPlayer) { continue; } - + $x = mt_rand($player->entity->x - 32, $player->entity->x + 32); $z = mt_rand($player->entity->z - 32, $player->entity->z + 32); - $diffX = $x-$player->entity->x; - $diffZ = $z-$player->entity->z; - $dist = $diffX*$diffX + $diffZ*$diffZ; - if($dist < 768){ + $diffX = $x - $player->entity->x; + $diffZ = $z - $player->entity->z; + $dist = $diffX * $diffX + $diffZ * $diffZ; + if($dist < 768) { continue; } - + $cnt = mt_rand(1, 3); - - for($i = 0; $i < $cnt; ++$i){ - + + for($i = 0; $i < $cnt; ++$i) { + $xMob = $x + mt_rand(-3, 3); $zMob = $z + mt_rand(-3, 3); - - + $y = $this->getSafeY($xMob, $zMob, $grassOnly, $type >= 32 && $type <= 36 && $type != 35); - if(!$y || $y < 0){ + if(!$y || $y < 0) { continue; } - + $data = $this->genPosData($xMob, $y + 0.5, $zMob); - if($baby != 2) $data["IsBaby"] = $baby; - + if($baby != 2) { + $data["IsBaby"] = $baby; + } + $e = $this->server->api->entity->add($this->level, 2, $type, $data); - - if($e instanceof Entity){ + + if($e instanceof Entity) { $this->server->api->entity->spawnToAll($e); ConsoleAPI::debug("$type spawned at $xMob, $y, $zMob"); } - if(!isset($this->playerAffectedEIDS[$player->entity->eid])){ + if(!isset($this->playerAffectedEIDS[$player->entity->eid])) { $this->playerAffectedEIDS[$player->entity->eid] = [$e->eid => true]; - }else{ + } else { $this->playerAffectedEIDS[$player->entity->eid][$e->eid] = true; } - + $this->entityAffectedPlayers[$e->eid] = $player->entity->eid; - + } } - - + return true; } - - private function genPosData($x, $y, $z){ + + private function genPosData($x, $y, $z) { return [ "x" => $x + 0.5, "y" => $y, "z" => $z + 0.5 ]; } - - protected function getSafeY($x, $z, $grassOnly = false, $highMob = false){ //first safe block //TODO check boundingbox + + protected function getSafeY($x, $z, $grassOnly = false, $highMob = false) { //first safe block //TODO check boundingbox $allowed = []; - for($y = 0; $y < 128; ++$y){ + for($y = 0; $y < 128; ++$y) { $b = $this->level->level->getBlockID($x, $y, $z); $b2 = $this->level->level->getBlockID($x, $y + 1, $z); $b1 = $this->level->level->getBlockID($x, $y - 1, $z); if( - !StaticBlock::getIsSolid($b) && !StaticBlock::getIsLiquid($b) && + !StaticBlock::getIsSolid($b) && !StaticBlock::getIsLiquid($b) && (StaticBlock::getIsSolid($b1) && (!$grassOnly || $b1 === GRASS) && (!$highMob || !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2))) - ){ + ) { $allowed[] = $y; } } - + return empty($allowed) ? -1 : $allowed[mt_rand(0, count($allowed) - 1)]; } } - diff --git a/src/world/MovingObjectPosition.php b/src/world/MovingObjectPosition.php index 2e6a6dfc..a470538d 100644 --- a/src/world/MovingObjectPosition.php +++ b/src/world/MovingObjectPosition.php @@ -1,5 +1,6 @@ blockX} {$this->blockY} {$this->blockZ}, side: {$this->sideHit} hitVec: {$this->hitVector} entityHit: {$this->entityHit}}"; } - + /** * @param int $x * @param int $y * @param int $z * @param int $side - * @param Vector3 $hitVector * * @return MovingObjectPosition */ - public static function fromBlock($x, $y, $z, $side, Vector3 $hitVector){ + public static function fromBlock($x, $y, $z, $side, Vector3 $hitVector) { $ob = new MovingObjectPosition; $ob->typeOfHit = 0; $ob->blockX = $x; @@ -49,15 +49,14 @@ class MovingObjectPosition{ } /** - * @param Entity $entity * * @return MovingObjectPosition */ - public static function fromEntity(Entity $entity){ + public static function fromEntity(Entity $entity) { $ob = new MovingObjectPosition; $ob->typeOfHit = 1; $ob->entityHit = $entity; $ob->hitVector = new Vector3($entity->x, $entity->y, $entity->z); return $ob; } -} \ No newline at end of file +} diff --git a/src/world/PocketChunkParser.php b/src/world/PocketChunkParser.php index 2c85bb4a..0917aa62 100644 --- a/src/world/PocketChunkParser.php +++ b/src/world/PocketChunkParser.php @@ -1,24 +1,26 @@ raw = gzinflate(file_get_contents($file . ".gz")); $r = @gzinflate($this->raw); - if($r !== false and $r != ""){ + if($r !== false and $r != "") { $this->raw = $r; } @unlink($file . ".gz"); file_put_contents($file, $this->raw); - }elseif(!file_exists($file)){ + } elseif(!file_exists($file)) { return false; - }else{ + } else { $this->raw = file_get_contents($file); } $this->file = $file; @@ -26,32 +28,32 @@ class PocketChunkParser{ return true; } - public function loadRaw($raw, $file){ + public function loadRaw($raw, $file) { $this->file = $file; $this->raw = $raw; $this->chunkLength = $this->sectorLength * ord($this->raw[0]); return true; } - public function getChunk($X, $Z){ + public function getChunk($X, $Z) { $X = (int) $X; $Z = (int) $Z; return substr($this->raw, $this->getOffset($X, $Z), $this->chunkLength); } - private function getOffset($X, $Z){ + private function getOffset($X, $Z) { return $this->location[$X + ($Z << 5)]; } - public function loadMap(){ - if($this->raw == ""){ + public function loadMap() { + if($this->raw == "") { return false; } $this->loadLocationTable(); console("[DEBUG] Loading chunks...", true, true, 2); - for($x = 0; $x < 16; ++$x){ + for($x = 0; $x < 16; ++$x) { $this->map[$x] = []; - for($z = 0; $z < 16; ++$z){ + for($z = 0; $z < 16; ++$z) { $this->map[$x][$z] = $this->parseChunk($x, $z); } } @@ -59,13 +61,13 @@ class PocketChunkParser{ console("[DEBUG] Chunks loaded!", true, true, 2); } - private function loadLocationTable(){ + private function loadLocationTable() { $this->location = []; console("[DEBUG] Loading Chunk Location table...", true, true, 2); - for($offset = 0; $offset < 0x1000; $offset += 4){ + for($offset = 0; $offset < 0x1000; $offset += 4) { $data = Utils::readLInt(substr($this->raw, $offset, 4)); $sectors = $data & 0xff; - if($sectors === 0){ + if($sectors === 0) { continue; } $sectorLocation = $data >> 8; @@ -73,7 +75,7 @@ class PocketChunkParser{ } } - public function parseChunk($X, $Z){ + public function parseChunk($X, $Z) { $X = (int) $X; $Z = (int) $Z; $offset = $this->getOffset($X, $Z); @@ -85,9 +87,9 @@ class PocketChunkParser{ 2 => [], //SkyLight 3 => [], //BlockLight ]; - foreach($chunk as $section => &$data){ + foreach($chunk as $section => &$data) { $l = $section === 0 ? 128 : 64; - for($i = 0; $i < 256; ++$i){ + for($i = 0; $i < 256; ++$i) { $data[$i] = substr($this->raw, $offset, $l); $offset += $l; } @@ -95,13 +97,13 @@ class PocketChunkParser{ return $chunk; } - public function saveMap($final = false){ + public function saveMap($final = false) { console("[DEBUG] Saving chunks...", true, true, 2); $fp = fopen($this->file, "r+b"); flock($fp, LOCK_EX); - foreach($this->map as $x => $d){ - foreach($d as $z => $chunk){ + foreach($this->map as $x => $d) { + foreach($d as $z => $chunk) { fseek($fp, $this->getOffset($x, $z)); fwrite($fp, $this->writeChunk($x, $z), $this->chunkLength); } @@ -112,41 +114,41 @@ class PocketChunkParser{ file_put_contents($this->file . ".gz", gzdeflate(gzdeflate(file_get_contents($this->file), 9), 9)); //Double compression for flat maps $compressed = filesize($this->file . ".gz"); console("[DEBUG] Saved chunks.dat.gz with " . round(($compressed / $original) * 100, 2) . "% (" . round($compressed / 1024, 2) . "KB) of the original size", true, true, 2); - if($final === true){ + if($final === true) { @unlink($this->file); } } - public function writeChunk($X, $Z){ + public function writeChunk($X, $Z) { $X = (int) $X; $Z = (int) $Z; - if(!isset($this->map[$X][$Z])){ + if(!isset($this->map[$X][$Z])) { return false; } $chunk = ""; - foreach($this->map[$X][$Z] as $section => $data){ - for($i = 0; $i < 256; ++$i){ + foreach($this->map[$X][$Z] as $section => $data) { + for($i = 0; $i < 256; ++$i) { $chunk .= $data[$i]; } } return Utils::writeLInt(strlen($chunk)) . $chunk; } - public function getFloor($x, $z){ + public function getFloor($x, $z) { $X = $x >> 4; $Z = $z >> 4; $aX = $x - ($X << 4); $aZ = $z - ($Z << 4); $index = $aZ + ($aX << 4); - for($y = 127; $y <= 0; --$y){ - if($this->map[$X][$Z][0][$index][$y] !== "\x00"){ + for($y = 127; $y <= 0; --$y) { + if($this->map[$X][$Z][0][$index][$y] !== "\x00") { break; } } return $y; } - public function getBlock($x, $y, $z){ + public function getBlock($x, $y, $z) { $x = (int) $x; $y = (int) $y; $z = (int) $z; @@ -157,20 +159,20 @@ class PocketChunkParser{ $index = $aZ + ($aX << 4); $block = ord($this->map[$X][$Z][0][$index][$y]); $meta = ord($this->map[$X][$Z][1][$index][$y >> 1]); - if(($y & 1) === 0){ + if(($y & 1) === 0) { $meta = $meta & 0x0F; - }else{ + } else { $meta = $meta >> 4; } return [$block, $meta]; } - public function getChunkColumn($X, $Z, $x, $z, $type = 0){ + public function getChunkColumn($X, $Z, $x, $z, $type = 0) { $index = $z + ($x << 4); return $this->map[$X][$Z][$type][$index]; } - public function setBlock($x, $y, $z, $block, $meta = 0){ + public function setBlock($x, $y, $z, $block, $meta = 0) { $x = (int) $x; $y = (int) $y; $z = (int) $z; @@ -181,12 +183,12 @@ class PocketChunkParser{ $index = $aZ + ($aX << 4); $this->map[$X][$Z][0][$index][$y] = chr($block); $old_meta = ord($this->map[$X][$Z][1][$index][$y >> 1]); - if(($y & 1) === 0){ + if(($y & 1) === 0) { $meta = ($old_meta & 0xF0) | ($meta & 0x0F); - }else{ + } else { $meta = (($meta << 4) & 0xF0) | ($old_meta & 0x0F); } $this->map[$X][$Z][1][$index][$y >> 1] = chr($meta); } -} \ No newline at end of file +} diff --git a/src/world/Position.php b/src/world/Position.php index e83861b2..d7308c2d 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -1,13 +1,13 @@ x, $x->y, $x->z); - }else{ + } else { $this->x = $x; $this->y = $y; $this->z = $z; @@ -15,25 +15,25 @@ class Position extends Vector3{ $this->level = $level; } - public function setXYZLevel($x, $y, $z, Level $level){ + public function setXYZLevel($x, $y, $z, Level $level) { $this->x = $x; $this->y = $y; $this->z = $z; $this->level = $level; } - public function getSide($side, $step = 1){ + public function getSide($side, $step = 1) { return new Position(parent::getSide($side, $step), 0, 0, $this->level); } - public function distance($x = 0, $y = 0, $z = 0){ - if(($x instanceof Position) and $x->level !== $this->level){ + public function distance($x = 0, $y = 0, $z = 0) { + if(($x instanceof Position) and $x->level !== $this->level) { return PHP_INT_MAX; } return parent::distance($x, $y, $z); } - - public function __toString(){ + + public function __toString() { return "Position(level=" . $this->level->getName() . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; } -} \ No newline at end of file +} diff --git a/src/world/Tile.php b/src/world/Tile.php index e270a68b..92cb0f36 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -1,6 +1,6 @@ server = ServerAPI::request(); $this->level = $level; $this->normal = true; $this->class = $class; $this->data = $data; $this->closed = false; - if($class === false){ + if($class === false) { $this->closed = true; } $this->name = ""; @@ -35,83 +37,83 @@ class Tile extends Position{ $this->y = (int) $y; $this->z = (int) $z; $this->server->query("INSERT OR REPLACE INTO tiles (ID, level, class, x, y, z) VALUES (" . $this->id . ", '" . $this->level->getName() . "', '" . $this->class . "', " . $this->x . ", " . $this->y . ", " . $this->z . ");"); - switch($this->class){ + switch($this->class) { case TILE_CHEST: case TILE_SIGN: $this->server->query("UPDATE tiles SET spawnable = 1 WHERE ID = " . $this->id . ";"); break; case TILE_FURNACE: - if(!isset($this->data["BurnTime"]) or $this->data["BurnTime"] < 0){ + if(!isset($this->data["BurnTime"]) or $this->data["BurnTime"] < 0) { $this->data["BurnTime"] = 0; } - if(!isset($this->data["CookTime"]) or $this->data["CookTime"] < 0 or ($this->data["BurnTime"] === 0 and $this->data["CookTime"] > 0)){ + if(!isset($this->data["CookTime"]) or $this->data["CookTime"] < 0 or ($this->data["BurnTime"] === 0 and $this->data["CookTime"] > 0)) { $this->data["CookTime"] = 0; } - if(!isset($this->data["MaxTime"])){ + if(!isset($this->data["MaxTime"])) { $this->data["MaxTime"] = $this->data["BurnTime"]; $this->data["BurnTicks"] = 0; } - if($this->data["BurnTime"] > 0){ + if($this->data["BurnTime"] > 0) { $this->update(); } break; } } - public function update(){ - if($this->closed === true){ + public function update() { + if($this->closed === true) { return false; } - if($this->class === TILE_FURNACE){ + if($this->class === TILE_FURNACE) { $fuel = $this->getSlot(1); $raw = $this->getSlot(0); $product = $this->getSlot(2); $smelt = $raw->getSmeltItem(); $canSmelt = ($smelt !== false and $raw->count > 0 and (($product->getID() === $smelt->getID() and $product->getMetadata() === $smelt->getMetadata() and $product->count < $product->getMaxStackSize()) or $product->getID() === AIR)); - if($this->data["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->count > 0){ + if($this->data["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->count > 0) { $this->lastUpdate = microtime(true); $this->data["MaxTime"] = $this->data["BurnTime"] = floor($fuel->getFuelTime() * 20); $this->data["BurnTicks"] = 0; --$fuel->count; - if($fuel->count === 0){ + if($fuel->count === 0) { $fuel = BlockAPI::getItem(AIR, 0, 0); } $this->setSlot(1, $fuel, false); $current = $this->level->getBlock($this); - if($current->getID() === FURNACE){ + if($current->getID() === FURNACE) { $this->level->setBlock($this, BlockAPI::get(BURNING_FURNACE, $current->getMetadata()), true, false, true); } } - if($this->data["BurnTime"] > 0){ + if($this->data["BurnTime"] > 0) { $ticks = (microtime(true) - $this->lastUpdate) * 20; $this->data["BurnTime"] -= $ticks; $this->data["BurnTicks"] = ceil(($this->data["BurnTime"] / $this->data["MaxTime"]) * 200); - if($smelt !== false and $canSmelt){ + if($smelt !== false and $canSmelt) { $this->data["CookTime"] += $ticks; - if($this->data["CookTime"] >= 200){ //10 seconds + if($this->data["CookTime"] >= 200) { //10 seconds $product = BlockAPI::getItem($smelt->getID(), $smelt->getMetadata(), $product->count + 1); $this->setSlot(2, $product, false); --$raw->count; - if($raw->count === 0){ + if($raw->count === 0) { $raw = BlockAPI::getItem(AIR, 0, 0); } $this->setSlot(0, $raw, false); $this->data["CookTime"] -= 200; } - }elseif($this->data["BurnTime"] <= 0){ + } elseif($this->data["BurnTime"] <= 0) { $this->data["BurnTime"] = 0; $this->data["CookTime"] = 0; $this->data["BurnTicks"] = 0; - }else{ + } else { $this->data["CookTime"] = 0; } $this->server->schedule(2, [$this, "update"]); $this->scheduledUpdate = true; - }else{ + } else { $current = $this->level->getBlock($this); - if($current->getID() === BURNING_FURNACE){ + if($current->getID() === BURNING_FURNACE) { $this->level->setBlock($this, BlockAPI::get(FURNACE, $current->getMetadata()), true, false, true); } $this->data["CookTime"] = 0; @@ -124,28 +126,28 @@ class Tile extends Position{ $this->lastUpdate = microtime(true); } - public function getSlot($s){ + public function getSlot($s) { $i = $this->getSlotIndex($s); - if($i === false or $i < 0){ + if($i === false or $i < 0) { return BlockAPI::getItem(AIR, 0, 0); - }else{ + } else { return BlockAPI::getItem($this->data["Items"][$i]["id"], $this->data["Items"][$i]["Damage"], $this->data["Items"][$i]["Count"]); } } - public function getSlotIndex($s){ - if($this->class !== TILE_CHEST and $this->class !== TILE_FURNACE){ + public function getSlotIndex($s) { + if($this->class !== TILE_CHEST and $this->class !== TILE_FURNACE) { return false; } - foreach($this->data["Items"] as $i => $slot){ - if($slot["Slot"] === $s){ + foreach($this->data["Items"] as $i => $slot) { + if($slot["Slot"] === $s) { return $i; } } return -1; } - public function setSlot($s, Item $item, $update = true, $offset = 0){ + public function setSlot($s, Item $item, $update = true, $offset = 0) { $i = $this->getSlotIndex($s); $d = [ "Count" => $item->count, @@ -153,15 +155,15 @@ class Tile extends Position{ "id" => $item->getID(), "Damage" => $item->getMetadata(), ]; - if($i === false){ + if($i === false) { return false; - }elseif($item->getID() === AIR or $item->count <= 0){ - if($i >= 0){ + } elseif($item->getID() === AIR or $item->count <= 0) { + if($i >= 0) { unset($this->data["Items"][$i]); } - }elseif($i < 0){ + } elseif($i < 0) { $this->data["Items"][] = $d; - }else{ + } else { $this->data["Items"][$i] = $d; } $this->server->api->dhandle("tile.container.slot", [ @@ -171,14 +173,14 @@ class Tile extends Position{ "slotdata" => $item, ]); - if($update === true and $this->scheduledUpdate === false){ + if($update === true and $this->scheduledUpdate === false) { $this->update(); } return true; } - public function pairWith(Tile $tile){ - if($this->isPaired() or $tile->isPaired()){ + public function pairWith(Tile $tile) { + if($this->isPaired() or $tile->isPaired()) { return false; } @@ -194,18 +196,18 @@ class Tile extends Position{ $this->server->handle("tile.update", $tile); } - public function isPaired(){ - if($this->class !== TILE_CHEST){ + public function isPaired() { + if($this->class !== TILE_CHEST) { return false; } - if(!isset($this->data["pairx"]) or !isset($this->data["pairz"])){ + if(!isset($this->data["pairx"]) or !isset($this->data["pairz"])) { return false; } return true; } - public function unpair(){ - if(!$this->isPaired()){ + public function unpair() { + if(!$this->isPaired()) { return false; } @@ -214,36 +216,36 @@ class Tile extends Position{ $this->server->api->tile->spawnToAll($this); $this->server->handle("tile.update", $this); - if($tile instanceof Tile){ + if($tile instanceof Tile) { $this->server->api->tile->spawnToAll($tile); $this->server->handle("tile.update", $tile); } } - public function getPair(){ - if($this->isPaired()){ + public function getPair() { + if($this->isPaired()) { return $this->server->api->tile->get(new Position((int) $this->data["pairx"], $this->y, (int) $this->data["pairz"], $this->level)); } return false; } - public function openInventory(Player $player){ - if($this->class === TILE_CHEST){ + public function openInventory(Player $player) { + if($this->class === TILE_CHEST) { $player->windowCnt++; $player->windowCnt = $id = max(2, $player->windowCnt % 99); - if(($pair = $this->getPair()) !== false){ - if(($pair->x + ($pair->z << 13)) > ($this->x + ($this->z << 13))){ //Order them correctly + if(($pair = $this->getPair()) !== false) { + if(($pair->x + ($pair->z << 13)) > ($this->x + ($this->z << 13))) { //Order them correctly $player->windows[$id] = [ $pair, $this ]; - }else{ + } else { $player->windows[$id] = [ $this, $pair ]; } - }else{ + } else { $player->windows[$id] = $this; } @@ -257,9 +259,9 @@ class Tile extends Position{ $player->dataPacket($pk); $slots = []; - if(is_array($player->windows[$id])){ + if(is_array($player->windows[$id])) { $all = $this->server->api->player->getAll($this->level); - foreach($player->windows[$id] as $ob){ + foreach($player->windows[$id] as $ob) { $pk = new TileEventPacket; $pk->x = $ob->x; $pk->y = $ob->y; @@ -267,16 +269,16 @@ class Tile extends Position{ $pk->case1 = 1; $pk->case2 = 2; $this->server->api->player->broadcastPacket($all, $pk); - for($s = 0; $s < CHEST_SLOTS; ++$s){ + for($s = 0; $s < CHEST_SLOTS; ++$s) { $slot = $ob->getSlot($s); - if($slot->getID() > AIR and $slot->count > 0){ + if($slot->getID() > AIR and $slot->count > 0) { $slots[] = $slot; - }else{ + } else { $slots[] = BlockAPI::getItem(AIR, 0, 0); } } } - }else{ + } else { $pk = new TileEventPacket; $pk->x = $this->x; $pk->y = $this->y; @@ -284,11 +286,11 @@ class Tile extends Position{ $pk->case1 = 1; $pk->case2 = 2; $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk); - for($s = 0; $s < CHEST_SLOTS; ++$s){ + for($s = 0; $s < CHEST_SLOTS; ++$s) { $slot = $this->getSlot($s); - if($slot->getID() > AIR and $slot->count > 0){ + if($slot->getID() > AIR and $slot->count > 0) { $slots[] = $slot; - }else{ + } else { $slots[] = BlockAPI::getItem(AIR, 0, 0); } } @@ -299,7 +301,7 @@ class Tile extends Position{ $pk->slots = $slots; $player->dataPacket($pk); return true; - }elseif($this->class === TILE_FURNACE){ + } elseif($this->class === TILE_FURNACE) { $player->windowCnt++; $player->windowCnt = $id = max(2, $player->windowCnt % 99); $player->windows[$id] = $this; @@ -314,11 +316,11 @@ class Tile extends Position{ $player->dataPacket($pk); $slots = []; - for($s = 0; $s < FURNACE_SLOTS; ++$s){ + for($s = 0; $s < FURNACE_SLOTS; ++$s) { $slot = $this->getSlot($s); - if($slot->getID() > AIR and $slot->count > 0){ + if($slot->getID() > AIR and $slot->count > 0) { $slots[] = $slot; - }else{ + } else { $slots[] = BlockAPI::getItem(AIR, 0, 0); } } @@ -330,14 +332,14 @@ class Tile extends Position{ } } - public function spawn($player){ - if($this->closed){ + public function spawn($player) { + if($this->closed) { return false; } - if(!($player instanceof Player)){ + if(!($player instanceof Player)) { $player = $this->server->api->player->get($player); } - switch($this->class){ + switch($this->class) { case TILE_CHEST: $nbt = new NBT(); $nbt->write(chr(NBT::TAG_COMPOUND) . "\x00\x00"); @@ -358,7 +360,7 @@ class Tile extends Position{ $nbt->writeTAG_String("z"); $nbt->writeTAG_Int((int) $this->z); - if($this->isPaired()){ + if($this->isPaired()) { $nbt->write(chr(NBT::TAG_INT)); $nbt->writeTAG_String("pairx"); $nbt->writeTAG_Int((int) $this->data["pairx"]); @@ -425,8 +427,8 @@ class Tile extends Position{ } } - public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){ - if($this->class !== TILE_SIGN){ + public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = "") { + if($this->class !== TILE_SIGN) { return false; } $this->data["Text1"] = $line1; @@ -438,7 +440,7 @@ class Tile extends Position{ return true; } - public function getText(){ + public function getText() { return [ $this->data["Text1"], $this->data["Text2"], @@ -447,24 +449,23 @@ class Tile extends Position{ ]; } - public function __destruct(){ + public function __destruct() { $this->close(); } - public function close(){ - if($this->closed === false){ + public function close() { + if($this->closed === false) { $this->closed = true; $this->server->api->tile->remove($this->id); } } - public function getName(){ + public function getName() { return $this->name; } - - public function setPosition(Vector3 $pos){ - if($pos instanceof Position){ + public function setPosition(Vector3 $pos) { + if($pos instanceof Position) { $this->level = $pos->level; $this->server->query("UPDATE tiles SET level = '" . $this->level->getName() . "' WHERE ID = " . $this->id . ";"); } diff --git a/src/world/generator/SuperflatGenerator.php b/src/world/generator/SuperflatGenerator.php index a36d4415..f6f32c0f 100644 --- a/src/world/generator/SuperflatGenerator.php +++ b/src/world/generator/SuperflatGenerator.php @@ -35,7 +35,7 @@ class SuperflatGenerator implements LevelGenerator{ $this->populators[] = new MineshaftPopulator(isset($this->options["mineshaft"]["chance"]) ? floatval($this->options["mineshaft"]["chance"]) : 0.01); }*/ } - + public function parsePreset($preset){ $this->preset = $preset; $preset = explode(";", $preset); @@ -61,7 +61,6 @@ class SuperflatGenerator implements LevelGenerator{ $this->structure[$y] = new AirBlock(); } - for($Y = 0; $Y < 8; ++$Y){ $this->chunks[$Y] = ""; $startY = $Y << 4; @@ -132,7 +131,7 @@ class SuperflatGenerator implements LevelGenerator{ $end = 128 + $spawn[0]; for($x = $start; $x <= $end; ++$x){ for($z = $start; $z <= $end; ++$z){ - if(floor(sqrt(($x - 128)*($x - 128)+ ($z - 128)*($z - 128))) <= $spawn[0]){ + if(floor(sqrt(($x - 128) * ($x - 128) + ($z - 128) * ($z - 128))) <= $spawn[0]){ $this->level->setBlockRaw(new Vector3($x, $this->floorLevel - 1, $z), $spawn[1], null); } } diff --git a/src/world/generator/VoidGenerator.php b/src/world/generator/VoidGenerator.php index afa04d02..d485d40b 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -24,37 +24,37 @@ require_once("LevelGenerator.php"); /***REM_END***/ class VoidGenerator implements LevelGenerator{ - private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = array(); - - public function __construct(array $options = array()){ + private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = []; + + public function __construct(array $options = []){ $this->options = $options; /*if(isset($this->options["mineshaft"])){ $this->populators[] = new MineshaftPopulator(isset($this->options["mineshaft"]["chance"]) ? floatval($this->options["mineshaft"]["chance"]) : 0.01); }*/ } - + public function init(Level $level, Random $random){ $this->level = $level; $this->random = $random; } - + public function generateChunk($chunkX, $chunkZ){ for($Y = 0; $Y < 8; ++$Y){ $this->level->setMiniChunk($chunkX, $chunkZ, $Y, $this->chunks[$Y]); } } - - public function populateChunk($chunkX, $chunkZ){ + + public function populateChunk($chunkX, $chunkZ){ foreach($this->populators as $populator){ $this->random->setSeed((int) ($chunkX * 0xdead + $chunkZ * 0xbeef) ^ $this->level->getSeed()); $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } } - + public function populateLevel(){ $this->random->setSeed($this->level->getSeed()); } - + public function getSpawn(){ return new Vector3(128, $this->floorLevel, 128); } diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index 18c0d1d7..c5855ebe 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -35,7 +35,7 @@ class WorldGenerator{ for($X = 0; $X < $this->width; ++$X){ $this->generator->generateChunk($X, $Z); } - + console("[NOTICE] Generating level " . ceil((($Z + 1) / $this->width) * 100) . "%"); }//$this->generator->generateChunk(7, 5); console("[NOTICE] Populating level"); diff --git a/src/world/generator/noise/NoiseGenerator.php b/src/world/generator/noise/NoiseGenerator.php index 227a6693..c23f0494 100644 --- a/src/world/generator/noise/NoiseGenerator.php +++ b/src/world/generator/noise/NoiseGenerator.php @@ -1,5 +1,5 @@ generatorCollection = array(); + public function __construct(MTRandom $random, $octaves) { + $this->generatorCollection = []; $this->octaves = (int) $octaves; - for($o = 0; $o < $this->octaves; ++$o){ + for($o = 0; $o < $this->octaves; ++$o) { $this->generatorCollection[$o] = new NoiseGeneratorPerlin($random); } } - - public function getValue($x, $y){ + + public function getValue($x, $y) { $noise = 0; $scale = 1; - for($i = 0; $i < $this->octaves; ++$i){ + for($i = 0; $i < $this->octaves; ++$i) { $noise += $this->generatorCollection[$i]->getValue($x * $scale, $y * $scale) / $scale; $scale /= 2; } return $noise; } - - public function generateNoiseOctaves($int1, $int2, $int3, $int4, $int5, $int6, $par1 = false, $par2 = false, $par3 = false){ - if($par1 === false or $par2 === false or $par3 === false){ + + public function generateNoiseOctaves($int1, $int2, $int3, $int4, $int5, $int6, $par1 = false, $par2 = false, $par3 = false) { + if($par1 === false or $par2 === false or $par3 === false) { return $this->generateNoiseOctaves($int1, 10, $int2, $int3, 1, $int4, $int5, 1, $int6); } - + $floats = array_fill(0, $int4 * $int5 * $int6, 0); $d1 = 1; - - for($j = 0; $j < $this->octaves; ++$j){ + + for($j = 0; $j < $this->octaves; ++$j) { $d2 = $int1 * $d1 * $par1; $d3 = $int2 * $d1 * $par2; $d4 = $int3 * $d1 * $par3; @@ -43,7 +43,7 @@ class NoiseGeneratorOctaves extends NoiseGenerator{ $d4 -= $l2; $l1 %= 16777216; $l2 %= 16777216; - + $d2 += $l1; $d4 += $l2; $this->generatorCollection[$j]->populateNoiseArray($floats, $d2, $d3, $d4, $int4, $int5, $int6, $par1 * $d1, $par2 * $d1, $par3 * $d1, $d1); @@ -51,4 +51,4 @@ class NoiseGeneratorOctaves extends NoiseGenerator{ } return $floats; } -} \ No newline at end of file +} diff --git a/src/world/generator/noise/NoiseGeneratorPerlin.php b/src/world/generator/noise/NoiseGeneratorPerlin.php index edad5c3f..85d0435c 100644 --- a/src/world/generator/noise/NoiseGeneratorPerlin.php +++ b/src/world/generator/noise/NoiseGeneratorPerlin.php @@ -4,21 +4,23 @@ require_once("NoiseGenerator.php"); /***REM_END***/ -class NoiseGeneratorPerlin extends NoiseGenerator{ +class NoiseGeneratorPerlin extends NoiseGenerator { - public $xCoord, $yCoord, $zCoord; + public $xCoord; + public $yCoord; + public $zCoord; private $permutations = []; - public function __construct(MTRandom $random){ + public function __construct(MTRandom $random) { $this->xCoord = $random->nextFloat() * 256; $this->yCoord = $random->nextFloat() * 256; $this->zCoord = $random->nextFloat() * 256; - for($i = 0; $i < 512; ++$i){ + for($i = 0; $i < 512; ++$i) { $this->permutations[$i] = $i < 256 ? $i : 0; } - for($i = 0; $i < 256; ++$i){ + for($i = 0; $i < 256; ++$i) { $j = $random->nextInt(256 - $i) + $i; $k = $this->permutations[$i]; $this->permutations[$i] = $this->permutations[$j]; @@ -27,8 +29,8 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ } } - - public function getValue($d, $d1, $d2 = 0){ + + public function getValue($d, $d1, $d2 = 0) { $d3 = $d + $this->xCoord; $d4 = $d1 + $this->yCoord; $d5 = $d2 + $this->zCoord; @@ -44,14 +46,14 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ $d6 = $d3 * $d3 * $d3 * ($d3 * ($d3 * 6 - 15) + 10); $d7 = $d4 * $d4 * $d4 * ($d4 * ($d4 * 6 - 15) + 10); $d8 = $d5 * $d5 * $d5 * ($d5 * ($d5 * 6 - 15) + 10); - + $k1 = (int) ($this->permutations[$l] + $i1); $l1 = (int) ($this->permutations[$k1] + $j1); $i2 = (int) ($this->permutations[$k1 + 1] + $j1); $j2 = (int) ($this->permutations[$l + 1] + $i1); $k2 = (int) ($this->permutations[$j2] + $j1); $l2 = (int) ($this->permutations[$j2 + 1] + $j1); - + return self::curve($d8, self::curve($d7, self::curve($d6, self::grad3D($this->permutations[$l1], $d3, $d4, $d5), self::grad3D($this->permutations[$k2], $d3 - 1, $d4, $d5)), @@ -63,19 +65,19 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ ) ); } - - public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7){ - if($int2 === 1){ + + public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7) { + if($int2 === 1) { $n = 0; $d3 = 1 / $par7; - for($i1 = 0; $i1 < $int1; ++$i1){ + for($i1 = 0; $i1 < $int1; ++$i1) { $d4 = $par1 + $i1 * $par4 + $this->xCoord; $i2 = floor($d4); $i3 = $i2 & 0xFF; $d4 -= $i2; $d5 = $d4 * $d4 * $d4 * ($d4 * ($d4 * 6 - 15) + 10); - for($i4 = 0; $i4 < $int3; ++$i4){ + for($i4 = 0; $i4 < $int3; ++$i4) { $d6 = $par3 + $i4 * $par6 + $this->zCoord; $i5 = floor($d6); $i6 = $i5 & 0xFF; @@ -101,28 +103,28 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ $n = 0; $i = 0; - for($i4 = 0; $i4 < $int1; ++$i4){ + for($i4 = 0; $i4 < $int1; ++$i4) { $d6 = $par1 + $i4 * $par4 + $this->xCoord; $i5 = floor($d6); $i6 = $i5 & 0xFF; $d6 -= $i5; $d7 = $d6 * $d6 * $d6 * ($d6 * ($d6 * 6 - 15) + 10); - for($i12 = 0; $i12 < $int3; ++$i12){ + for($i12 = 0; $i12 < $int3; ++$i12) { $d12 = $par3 + $i12 * $par6 + $this->zCoord; $i13 = floor($d12); $i14 = $i13 & 0xFF; $d12 -= $i13; $d13 = $d12 * $d12 * $d12 * ($d12 * ($d12 * 6 - 15) + 10); - for($i15 = 0; $i15 < $int2; ++$i15){ + for($i15 = 0; $i15 < $int2; ++$i15) { $d14 = $par2 + $i15 * $par5 + $this->yCoord; $i16 = floor($d14); $i17 = $i16 & 0xff; $d14 -= $i16; $d15 = $d14 * $d14 * $d14 * ($d14 * ($d14 * 6 - 15) + 10); - if($i15 == 0 or $i17 != $m){ + if($i15 == 0 or $i17 != $m) { $m = $i17; $i7 = $this->permutations[$i6] + $i17; $i8 = $this->permutations[$i7] + $i14; @@ -145,22 +147,22 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ } } - public static final function curve($par1, $par2, $par3){ + final public static function curve($par1, $par2, $par3) { return $par2 + $par1 * ($par3 - $par2); } - public static function grad2D($int, $par1, $par2){ + public static function grad2D($int, $par1, $par2) { $i = $int & 0x0F; $d1 = (1 - (($i & 0x08) >> 3)) * $par1; - $d2 = ($i == 12 || $i == 14) ? $par1 : (($i >= 4)*$par2); + $d2 = ($i == 12 || $i == 14) ? $par1 : (($i >= 4) * $par2); return (($i & 0x01) ? -$d1 : $d1) + (($i & 0x02) ? -$d2 : $d2); } - public static function grad3D($int, $par1, $par2, $par3){ + public static function grad3D($int, $par1, $par2, $par3) { $i = $int & 0x0F; $d1 = $i < 8 ? $par1 : $par2; $d2 = ($i == 12 or $i == 14) ? $par1 : ($i < 4 ? $par2 : $par3); return (($i & 0x01) ? -$d1 : $d1) + (($i & 0x02) ? -$d2 : $d2); } -} \ No newline at end of file +} diff --git a/src/world/generator/object/NetherReactorStructure.php b/src/world/generator/object/NetherReactorStructure.php index 30b0624d..78006ab9 100644 --- a/src/world/generator/object/NetherReactorStructure.php +++ b/src/world/generator/object/NetherReactorStructure.php @@ -1,7 +1,7 @@ [ @@ -591,7 +591,7 @@ class NetherReactorStructure{ " N ", ], ]; - + public static function buildReactor($level, $x, $y, $z){ /*use CENTER positions*/ $offsetX = 0; $offsetZ = 0; diff --git a/src/world/generator/object/tree/BigTreeObject.php b/src/world/generator/object/tree/BigTreeObject.php index 4616ac26..d2edd493 100644 --- a/src/world/generator/object/tree/BigTreeObject.php +++ b/src/world/generator/object/tree/BigTreeObject.php @@ -61,5 +61,4 @@ class BigTreeObject extends TreeObject{ */ } - } \ No newline at end of file diff --git a/src/world/generator/object/tree/PineTreeObject.php b/src/world/generator/object/tree/PineTreeObject.php index 91642259..e745c0a4 100644 --- a/src/world/generator/object/tree/PineTreeObject.php +++ b/src/world/generator/object/tree/PineTreeObject.php @@ -69,5 +69,4 @@ class PineTreeObject extends TreeObject{ } } - } \ No newline at end of file diff --git a/src/world/generator/object/tree/SpruceTreeObject.php b/src/world/generator/object/tree/SpruceTreeObject.php index b496454b..70dacdeb 100644 --- a/src/world/generator/object/tree/SpruceTreeObject.php +++ b/src/world/generator/object/tree/SpruceTreeObject.php @@ -60,5 +60,4 @@ class SpruceTreeObject extends TreeObject{ } } - } \ No newline at end of file diff --git a/src/world/generator/vanilla/BiomeSource.php b/src/world/generator/vanilla/BiomeSource.php index 821d7f00..ad7569e4 100644 --- a/src/world/generator/vanilla/BiomeSource.php +++ b/src/world/generator/vanilla/BiomeSource.php @@ -9,7 +9,7 @@ class BiomeSource */ public $temperatureNoise, $rainfallNoise, $detailNoise; /** - * + * * @var float[] $tempNoises * @var float[] $rainfallNoises * @var float[] $detailNoises @@ -20,61 +20,60 @@ class BiomeSource $this->rainfallNoise = new NoiseGeneratorOctaves(new MTRandom($level->getSeed() * 39811), 4); $this->detailNoise = new NoiseGeneratorOctaves(new MTRandom($level->getSeed() * 543321), 2); } - + public function getBiome($x, $z){ return $this->getBiomeBlock($x, $z, 1, 1)[0]; } - + public function getTemperatureBlock($x, $z, $xSize, $zSize){ $this->temperatureNoises = $this->temperatureNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.025, 0.025, 0.25); $this->detailNoises = $this->detailNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.25, 0.25, 0.588); - + $index = 0; - + for($blockX = 0; $blockX < $xSize; ++$blockX){ for($blockZ = 0; $blockZ < $zSize; ++$blockZ){ //float f = 1.0f - ((((this.detailNoises[index] * 1.1f) + 0.5f) * 0.01f) + (((this.temperatureNoises[index] * 0.15f) + 0.7f) * 0.99f)); //float f1 = 1.0f - (f*f); $f = 1 - (((($this->detailNoises[$index] * 1.1) + 0.5) * 0.01) + ((($this->temperatureNoises[$index] * 0.15) + 0.7) * 0.99)); - $f1 = 1 - ($f*$f); + $f1 = 1 - ($f * $f); if($f1 < 0) $f1 = 0; elseif($f1 > 1) $f1 = 1; - + $this->temperatureNoises[$index++] = $f1; } } - + return $this->temperatureNoises; } - - + public function getBiomeBlock($x, $z, $xSize, $zSize){ $this->temperatureNoises = $this->temperatureNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.025, 0.025, 0.25); $this->rainfallNoises = $this->rainfallNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.05, 0.05, 0.3333); $this->detailNoises = $this->detailNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.25, 0.25, 0.588); - + $localBiomeArray = []; $index = 0; - + for($blockX = 0; $blockX < $xSize; ++$blockX){ for($blockZ = 0; $blockZ < $zSize; ++$blockZ){ $rain = ((($this->detailNoises[$index] * 1.1) + 0.5) * 0.002) + ((($this->rainfallNoises[$index] * 0.15) + 0.5) * 0.998); $f1 = 1 - ((((($this->detailNoises[$index]) * 1.1) + 0.5) * 0.01) + ((($this->temperatureNoises[$index] * 0.15) + 0.7) * 0.99)); $blockTemp = 1 - ($f1 * $f1); - + if($blockTemp < 0) $blockTemp = 0; elseif($blockTemp > 1) $blockTemp = 1; - + if($rain < 0) $rain = 0; elseif($rain > 1) $rain = 1; - + $this->temperatureNoises[$index] = $blockTemp; $this->rainfallNoises[$index] = $rain; $localBiomeArray[$index++] = Biome::getBiome($blockTemp, $rain); } } - + return $localBiomeArray; } } diff --git a/src/world/generator/vanilla/VanillaGenerator.php b/src/world/generator/vanilla/VanillaGenerator.php index 9ec18d45..4d18f2d6 100644 --- a/src/world/generator/vanilla/VanillaGenerator.php +++ b/src/world/generator/vanilla/VanillaGenerator.php @@ -1,8 +1,8 @@ level = $level; $this->biomeSource = new BiomeSource($level); $this->rand = new MTRandom($level->getSeed()); @@ -62,22 +76,20 @@ class VanillaGenerator implements LevelGenerator $this->treeNoise = new NoiseGeneratorOctaves($this->rand, 8); } - public function getSpawn() - { + public function getSpawn() { return new Vector3(128, 64, 128); } - public function populateChunk($chunkX, $chunkZ) - { + public function populateChunk($chunkX, $chunkZ) { $chunkXWorld = $chunkX * 16; $chunkZWorld = $chunkZ * 16; //HeavyTile::instaFall = 1; TODO instant sand/gravel fall $biome = $this->biomeSource->getBiome($chunkXWorld + 16, $chunkZWorld + 16); $this->rand->setSeed($this->level->getSeed()); - $i1 = (int)(((int)($this->rand->nextInt() / 2)) * 2 + 1); //why php integers are so big....??????????????????????????????????????? - $j1 = (int)(((int)($this->rand->nextInt() / 2)) * 2 + 1); + $i1 = (int) (((int) ($this->rand->nextInt() / 2)) * 2 + 1); //why php integers are so big....??????????????????????????????????????? + $j1 = (int) (((int) ($this->rand->nextInt() / 2)) * 2 + 1); $this->rand->setSeed((($chunkX * $i1 + $chunkZ * $j1) & 0xffffffff) ^ $this->level->getSeed()); - for($i2 = 0; $i2 < 10; ++$i2){ + for($i2 = 0; $i2 < 10; ++$i2) { ClayFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(128), $chunkZWorld + $this->rand->nextInt(16)); } for ($i3 = 0; $i3 < 20; ++$i3) { @@ -89,30 +101,37 @@ class VanillaGenerator implements LevelGenerator for ($i5 = 0; $i5 < 20; ++$i5) { OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(128), $chunkZWorld + $this->rand->nextInt(16), COAL_ORE, 16); } - for($i6 = 0; $i6 < 20; ++$i6){ + for($i6 = 0; $i6 < 20; ++$i6) { OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(64), $chunkZWorld + $this->rand->nextInt(16), IRON_ORE, 8); } - for($i7 = 0; $i7 < 2; ++$i7){ + for($i7 = 0; $i7 < 2; ++$i7) { OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(32), $chunkZWorld + $this->rand->nextInt(16), GOLD_ORE, 8); } - for($i8 = 0; $i8 < 8; ++$i8){ - OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), REDSTONE_ORE, 7); + for($i8 = 0; $i8 < 8; ++$i8) { + OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), REDSTONE_ORE, 7); } - - OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), DIAMOND_ORE, 7); - OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16) + $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), LAPIS_ORE, 6); - - + + OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), DIAMOND_ORE, 7); + OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16) + $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), LAPIS_ORE, 6); + $sample = (int) (((($this->treeNoise->getValue($chunkXWorld * 0.5, $chunkZWorld * 0.5) / 8) + ($this->rand->nextFloat() * 4)) + 4) / 3); $treesAmount = $this->rand->nextInt(10) == 0; - if($biome == Biome::$forest) $treesAmount += $sample + 2; - elseif($biome == Biome::$rainForest) $treesAmount += $sample + 2; - elseif($biome == Biome::$seasonalForest) $treesAmount += $sample + 1; - elseif($biome == Biome::$taiga) $treesAmount += $sample + 1; - elseif($biome == Biome::$desert) $treesAmount -= 20; - elseif($biome == Biome::$tundra) $treesAmount -= 20; - elseif($biome == Biome::$plains) $treesAmount -= 20; - for($l8 = 0; $l8 < $treesAmount; ++$l8){ + if($biome == Biome::$forest) { + $treesAmount += $sample + 2; + } elseif($biome == Biome::$rainForest) { + $treesAmount += $sample + 2; + } elseif($biome == Biome::$seasonalForest) { + $treesAmount += $sample + 1; + } elseif($biome == Biome::$taiga) { + $treesAmount += $sample + 1; + } elseif($biome == Biome::$desert) { + $treesAmount -= 20; + } elseif($biome == Biome::$tundra) { + $treesAmount -= 20; + } elseif($biome == Biome::$plains) { + $treesAmount -= 20; + } + for($l8 = 0; $l8 < $treesAmount; ++$l8) { $l12 = $chunkXWorld + $this->rand->nextInt(16) + 8; $j15 = $chunkZWorld + $this->rand->nextInt(16) + 8; /** @@ -121,76 +140,79 @@ class VanillaGenerator implements LevelGenerator $tree = $biome->getTreeFeature($this->rand); $tree->place($this->level, $this->rand, $l12, $this->getHeightValue($l12, $j15), $j15); } - for($i9 = 0; $i9 < 2; ++$i9){ + for($i9 = 0; $i9 < 2; ++$i9) { $i13 = $chunkXWorld + $this->rand->nextInt(16) + 8; $k15 = $this->rand->nextInt(128); $l17 = $chunkZWorld + $this->rand->nextInt(16) + 8; Feature::$FLOWER_YELLOW->place($this->level, $this->rand, $i13, $k15, $l17); } - if($this->rand->nextInt(2) == 0){ + if($this->rand->nextInt(2) == 0) { $j9 = $chunkXWorld + $this->rand->nextInt(16) + 8; $j13 = $this->rand->nextInt(128); $l15 = $chunkZWorld + $this->rand->nextInt(16) + 8; Feature::$FLOWER_RED->place($this->level, $this->rand, $j9, $j13, $l15); } - if($this->rand->nextInt(4) == 0){ + if($this->rand->nextInt(4) == 0) { $j9 = $chunkXWorld + $this->rand->nextInt(16) + 8; $j13 = $this->rand->nextInt(128); $l15 = $chunkZWorld + $this->rand->nextInt(16) + 8; Feature::$MUSHROOM_BROWN->place($this->level, $this->rand, $j9, $j13, $l15); } - if($this->rand->nextInt(8) == 0){ + if($this->rand->nextInt(8) == 0) { $j9 = $chunkXWorld + $this->rand->nextInt(16) + 8; $j13 = $this->rand->nextInt(128); $l15 = $chunkZWorld + $this->rand->nextInt(16) + 8; Feature::$MUSHROOM_RED->place($this->level, $this->rand, $j9, $j13, $l15); } - + } - public function generateChunk($chunkX, $chunkZ) - { + public function generateChunk($chunkX, $chunkZ) { $this->rand->setSeed(341872712 * $chunkX + 132899541 * $chunkZ); $this->biomes = $this->biomeSource->getBiomeBlock($chunkX * 16, $chunkZ * 16, 16, 16); $chunkz = array_fill(0, 8, EMPTY_MINI_CHUNK); //[$blockY >> 4][($blockY & 0xf) + ($blockX << 5) + ($blockZ << 9)]. y&f+x&f+z&f $this->prepareHeights($chunkX, $chunkZ, $chunkz, $this->biomes, $this->biomeSource->temperatureNoises); $this->buildSurfaces($chunkX, $chunkZ, $chunkz, $this->biomes); $this->generateHeightmap($chunkX, $chunkZ, $chunkz); - - for($Y = 0; $Y < 8; ++$Y){ + + for($Y = 0; $Y < 8; ++$Y) { $index = ($chunkZ << 4) + $chunkX; $this->level->level->chunks[$index][$Y] = $chunkz[$Y]; $this->level->level->chunkChange[$index][$Y] = 8192; $this->level->level->locationTable[$index][0] |= 1 << $Y; //TODO mv out of loop } $this->level->level->chunkChange[$index][-1] = true; - + } - - public function populateLevel() - {} - public function setHeightValue($x, $z, $hv){ - if($x > 255 || $x < 0 || $z > 255 || $z < 0) return; + + public function populateLevel() { + } + public function setHeightValue($x, $z, $hv) { + if($x > 255 || $x < 0 || $z > 255 || $z < 0) { + return; + } $cX = $x >> 4; $cZ = $z >> 4; $bX = $x & 0xf; $bZ = $z & 0xf; $this->heightMap[$cX + ($cZ * 16)][$bX + ($bZ * 16)] = $hv; } - public function getHeightValue($x, $z){ - if($x > 255 || $x < 0 || $z > 255 || $z < 0) return 0; + public function getHeightValue($x, $z) { + if($x > 255 || $x < 0 || $z > 255 || $z < 0) { + return 0; + } $cX = $x >> 4; $cZ = $z >> 4; $bX = $x & 0xf; $bZ = $z & 0xf; return $this->heightMap[$cX + ($cZ * 16)][$bX + ($bZ * 16)]; } - public function generateHeightmap($x, $z, &$chunkz){ + public function generateHeightmap($x, $z, &$chunkz) { $heightmapCPtr = EMPTY_16x16_ARR; - for($blockX = 0; $blockX < 16; ++$blockX){ - for($blockZ = 0; $blockZ < 16; ++$blockZ){ - for($Y = 7; $Y >= 0; --$Y){ - for($cY = 15; $cY >= 0; --$cY){ - $blockY = $Y*16 + $cY; + for($blockX = 0; $blockX < 16; ++$blockX) { + for($blockZ = 0; $blockZ < 16; ++$blockZ) { + for($Y = 7; $Y >= 0; --$Y) { + for($cY = 15; $cY >= 0; --$cY) { + $blockY = $Y * 16 + $cY; $blockID = ord($chunkz[$Y][$cY + ($blockX << 5) + ($blockZ << 9)]); if($blockID > 0) { $heightmapCPtr[$blockX + ($blockZ * 16)] = $blockY + 1 ; @@ -202,7 +224,7 @@ class VanillaGenerator implements LevelGenerator } $this->heightMap[$x + ($z * 16)] = $heightmapCPtr; } - + /**Vanilla Functions Implementation starts here**/ /** * Decorate terrain with grass, water & other stuff. Uses ZXY placement format @@ -211,53 +233,53 @@ class VanillaGenerator implements LevelGenerator * @param array $chunks * @param Biome[] $biomes */ - public function buildSurfaces($chunkX, $chunkZ, &$chunks, $biomes){ + public function buildSurfaces($chunkX, $chunkZ, &$chunks, $biomes) { $this->sandNoises = $this->beachNoise->generateNoiseOctaves($chunkX * 16, $chunkZ * 16, 0, 16, 16, 1, 0.03125, 0.03125, 1); $this->gravelNoises = $this->beachNoise->generateNoiseOctaves($chunkX * 16, 109.01, $chunkZ * 16, 16, 1, 16, 0.03125, 1, 0.03125); $this->surfaceDepthNoises = $this->surfaceDepthNoise->generateNoiseOctaves($chunkX * 16, $chunkZ * 16, 0, 16, 16, 1, 0.0625, 0.0625, 0.0625); - for($blockX = 0; $blockX < 16; ++$blockX){ - for($blockZ = 0; $blockZ < 16; ++$blockZ){ + for($blockX = 0; $blockX < 16; ++$blockX) { + for($blockZ = 0; $blockZ < 16; ++$blockZ) { /** @var Biome $biome **/ $biome = $biomes[$blockX + ($blockZ * 16)]; $z = ($this->sandNoises[$blockX + ($blockZ * 16)] + ($this->rand->nextFloat() * 0.2)) > 0; $z2 = ($this->gravelNoises[$blockX + ($blockZ * 16)] + ($this->rand->nextFloat() * 0.2)) > 3; - $nextFloat = (int)(($this->surfaceDepthNoises[$blockX + ($blockZ * 16)] / 3) + 3 + ($this->rand->nextFloat() * 0.25)); + $nextFloat = (int) (($this->surfaceDepthNoises[$blockX + ($blockZ * 16)] / 3) + 3 + ($this->rand->nextFloat() * 0.25)); $i = -1; $b = $biome->topBlock; $b2 = $biome->fillerBlock; - for($blockY = 127; $blockY >= 0; --$blockY){ - if($blockY <= $this->rand->nextInt(5)){ + for($blockY = 127; $blockY >= 0; --$blockY) { + if($blockY <= $this->rand->nextInt(5)) { $chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = "\x07"; - }else{ + } else { $b3 = ord($chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)]); - if($b3 == 0){ + if($b3 == 0) { $i = -1; - }elseif($b3 == STONE){ - if($i == -1){ - if($nextFloat > 0){ - if($blockY >= 60 && $blockY <= 65){ - if($z){ + } elseif($b3 == STONE) { + if($i == -1) { + if($nextFloat > 0) { + if($blockY >= 60 && $blockY <= 65) { + if($z) { $b2 = $b = SAND; - }elseif($z2){ + } elseif($z2) { $b = 0; $b2 = GRAVEL; - }else{ + } else { $b = $biome->topBlock; $b2 = $biome->fillerBlock; } } - }else{ + } else { $b = 0; $b2 = STONE; } - + $b = $blockY < 64 && $b == 0 ? STILL_WATER : $b; $i = $nextFloat; $chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = $blockY >= 63 ? chr($b) : chr($b2); - }elseif($i > 0){ + } elseif($i > 0) { --$i; $chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = chr($b2); - if($i == 0 && $b2 == SAND){ + if($i == 0 && $b2 == SAND) { $i = $this->rand->nextInt(4); $b2 = SANDSTONE; } @@ -268,40 +290,39 @@ class VanillaGenerator implements LevelGenerator } } } - - - public function prepareHeights($chunkX, $chunkZ, &$chunks, $biomes, $temperatures){ + + public function prepareHeights($chunkX, $chunkZ, &$chunks, $biomes, $temperatures) { $this->heights = $this->getHeights($chunkX * 4, 0, $chunkZ * 4, 5, 17, 5); //if($chunkX == 15 && $chunkZ == 15) var_dump($this->heights); - for($unkX = 0; $unkX < 4; ++$unkX){ - for($unkZ = 0; $unkZ < 4; ++$unkZ){ - for($unkY = 0; $unkY < 16; ++$unkY){ + for($unkX = 0; $unkX < 4; ++$unkX) { + for($unkZ = 0; $unkZ < 4; ++$unkZ) { + for($unkY = 0; $unkY < 16; ++$unkY) { $f = $this->heights[(((($unkX) * 5) + $unkZ) * 17) + $unkY]; $f2 = $this->heights[(((($unkX) * 5) + $unkZ + 1) * 17) + $unkY]; $f3 = $this->heights[(((($unkX + 1) * 5) + $unkZ) * 17) + $unkY]; $f4 = $this->heights[(((($unkX + 1) * 5) + $unkZ + 1) * 17) + $unkY]; - + $f5 = ($this->heights[(((($unkX) * 5) + ($unkZ)) * 17) + ($unkY + 1)] - $f) * 0.125; $f6 = ($this->heights[(((($unkX) * 5) + ($unkZ + 1)) * 17) + ($unkY + 1)] - $f2) * 0.125; $f7 = ($this->heights[(((($unkX + 1) * 5) + ($unkZ)) * 17) + ($unkY + 1)] - $f3) * 0.125; $f8 = ($this->heights[(((($unkX + 1) * 5) + ($unkZ + 1)) * 17) + ($unkY + 1)] - $f4) * 0.125; - - for($unkYY = 0; $unkYY < 8; ++$unkYY){ + + for($unkYY = 0; $unkYY < 8; ++$unkYY) { $f9 = $f; $f10 = $f2; $f11 = ($f3 - $f) * 0.25; $f12 = ($f4 - $f2) * 0.25; - for($unkXX = 0; $unkXX < 4; ++$unkXX){ + for($unkXX = 0; $unkXX < 4; ++$unkXX) { $f13 = $f9; $f14 = ($f10 - $f9) * 0.25; - for($unkZZ = 0; $unkZZ < 4; ++$unkZZ){ + for($unkZZ = 0; $unkZZ < 4; ++$unkZZ) { $d15 = $temperatures[((($unkX * 4) + $unkXX) * 16) + ($unkZ * 4) + $unkZZ]; $i3 = $f13 > 0; //true -> STONE, false -> AIR - - if(!$i3 && ($unkY * 8) + $unkYY < 64){ + + if(!$i3 && ($unkY * 8) + $unkYY < 64) { $i3 = $d15 < 0.5 && (($unkY * 8) + $unkYY) >= 63 ? ICE : STILL_WATER; } - + $fx = ($unkXX + ($unkX * 4)); $fy = (($unkY * 8) + $unkYY); $fz = ($unkZZ + ($unkZ * 4)); @@ -320,9 +341,9 @@ class VanillaGenerator implements LevelGenerator } } } - - public function getHeights($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ){ - $heights = array_fill(0, $scaleX*$scaleY*$scaleZ, 0); + + public function getHeights($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ) { + $heights = array_fill(0, $scaleX * $scaleY * $scaleZ, 0); $rainNoises = $this->biomeSource->rainfallNoises; $tempNoises = $this->biomeSource->temperatureNoises; $this->biomeNoises = $this->biomeNoise->generateNoiseOctaves($chunkX, $chunkZ, $scaleX, $scaleZ, 1.121, 1.121, 0.5); @@ -331,56 +352,72 @@ class VanillaGenerator implements LevelGenerator $this->upperInterpolationNoises = $this->upperInterpolationNoise->generateNoiseOctaves($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ, 684.41, 684.41, 684.41); $this->lowerInterpolationNoises = $this->lowerInterpolationNoise->generateNoiseOctaves($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ, 684.41, 684.41, 684.41); $k1 = $l1 = 0; - $i2 = ((int)(16 / $scaleX)); - for($j2 = 0; $j2 < $scaleX; ++$j2){ - $k2 = (int)($j2 * $i2 + $i2 / 2); - for($l2 = 0; $l2 < $scaleZ; ++$l2){ - $i3 = (int)($l2 * $i2 + $i2 / 2); + $i2 = ((int) (16 / $scaleX)); + for($j2 = 0; $j2 < $scaleX; ++$j2) { + $k2 = (int) ($j2 * $i2 + $i2 / 2); + for($l2 = 0; $l2 < $scaleZ; ++$l2) { + $i3 = (int) ($l2 * $i2 + $i2 / 2); $d2 = $tempNoises[$k2 * 16 + $i3]; $d3 = $rainNoises[$k2 * 16 + $i3] * $d2; $d4 = 1 - $d3; $d4 *= $d4; $d4 *= $d4; $d4 = 1 - $d4; - + $d5 = (($this->biomeNoises[$l1] + 256) / 512); $d5 *= $d4; - if($d5 > 1) $d5 = 1; + if($d5 > 1) { + $d5 = 1; + } $d6 = $this->depthNoises[$l1] / 8000; - if($d6 < 0) $d6 = -$d6 * 0.3; - + if($d6 < 0) { + $d6 = -$d6 * 0.3; + } + $d6 = $d6 * 3 - 2; - if($d6 < 0){ + if($d6 < 0) { $d6 /= 2; - if($d6 < -1) $d6 = -1; + if($d6 < -1) { + $d6 = -1; + } $d6 /= 1.4; $d6 /= 2; $d5 = 0; - }else{ - if($d6 > 1) $d6 = 1; + } else { + if($d6 > 1) { + $d6 = 1; + } $d6 /= 8; } - - if($d5 < 0) $d5 = 0; - + + if($d5 < 0) { + $d5 = 0; + } + $d5 += 0.5; $d6 = ($d6 * $scaleY) / 16; $d7 = ($scaleY / 2 + $d6 * 4); ++$l1; - for($j3 = 0; $j3 < $scaleY; ++$j3){ + for($j3 = 0; $j3 < $scaleY; ++$j3) { $d8 = 0; - $d9 = (((float)$j3 - $d7) * 12) / $d5; - if($d9 < 0) $d9 *= 4; + $d9 = (((float) $j3 - $d7) * 12) / $d5; + if($d9 < 0) { + $d9 *= 4; + } $d10 = $this->upperInterpolationNoises[$k1] / 512; $d11 = $this->lowerInterpolationNoises[$k1] / 512; $d12 = ($this->interpolationNoises[$k1] / 10 + 1) / 2; - - if($d12 < 0) $d8 = $d10; - elseif($d12 > 1) $d8 = $d11; - else $d8 = $d10 + ($d11 - $d10) * $d12; - + + if($d12 < 0) { + $d8 = $d10; + } elseif($d12 > 1) { + $d8 = $d11; + } else { + $d8 = $d10 + ($d11 - $d10) * $d12; + } + $d8 -= $d9; - if($j3 > $scaleY - 4){ + if($j3 > $scaleY - 4) { $d13 = ($j3 - ($scaleY - 4)) / 3; $d8 = $d8 * (1 - $d13) + -10 * $d13; } @@ -389,9 +426,8 @@ class VanillaGenerator implements LevelGenerator } } } - + return $heights; } } - diff --git a/src/world/generator/vanilla/biome/Biome.php b/src/world/generator/vanilla/biome/Biome.php index a3f38ac2..5219d011 100644 --- a/src/world/generator/vanilla/biome/Biome.php +++ b/src/world/generator/vanilla/biome/Biome.php @@ -20,8 +20,7 @@ class Biome * @var Biome $tundra */ public static $rainForest, $swampLand, $seasonalForest, $forest, $savanna, $shrubland, $taiga, $desert, $plains, $iceDesert, $tundra; - - + public static function init(){ Biome::$rainForest = new Biome("Rainforest"); Biome::$swampLand = new Biome("Swampland"); @@ -48,26 +47,26 @@ class Biome public static function getBiome($temp, $rain){ $i = ((int) ($temp * 63)); $j = ((int) ($rain * 63)); - return Biome::$biomes[$i + $j*64]; + return Biome::$biomes[$i + $j * 64]; } public static function __getBiome($temp, $rain){ $rain *= $temp; if($temp < 0.1) return Biome::$tundra; - + if($rain < 0.2){ if($temp < 0.5) return Biome::$tundra; if($temp < 0.95) return Biome::$savanna; else return Biome::$desert; } - + if($rain > 0.5 && $temp < 0.7) return Biome::$swampLand; if($temp < 0.5) return Biome::$taiga; - + if($temp < 0.97){ if($rain < 0.45) return Biome::$shrubland; else return Biome::$forest; } - + if($rain < 0.45) return Biome::$plains; if($rain < 0.9) return Biome::$seasonalForest; return Biome::$rainForest; @@ -75,12 +74,12 @@ class Biome public function __construct($name){ $this->name = $name; } - + public function getTreeFeature(MTRandom $rand){ $rand->nextInt(); //it is necessary return Feature::$TREE; } - + public $name; public $topBlock = GRASS, $fillerBlock = DIRT; } diff --git a/src/world/generator/vanilla/feature/BirchFeature.php b/src/world/generator/vanilla/feature/BirchFeature.php index f98bdf9e..cc927f7f 100644 --- a/src/world/generator/vanilla/feature/BirchFeature.php +++ b/src/world/generator/vanilla/feature/BirchFeature.php @@ -13,7 +13,7 @@ class BirchFeature extends Feature if($i >= (($y + 1) + $nextInt) - 2){ $i2 = 2; } - + for($i3 = $x - $i2; $i3 <= $x + $i2 && $z2; ++$i3){ for($i4 = $z - $i2; $i4 <= $z + $i2 && $z2; ++$i4){ if($i >= 0 && $i < 128){ @@ -44,7 +44,7 @@ class BirchFeature extends Feature } } } - + for($i12 = 0; $i12 < $nextInt; ++$i12){ $blockID = $level->level->getBlockID($x, $y + $i12, $z); if($blockID == 0 || $blockID == LEAVES){ @@ -56,7 +56,7 @@ class BirchFeature extends Feature return false; } return false; - + } } diff --git a/src/world/generator/vanilla/feature/ClayFeature.php b/src/world/generator/vanilla/feature/ClayFeature.php index 32e51e0c..07c9506c 100644 --- a/src/world/generator/vanilla/feature/ClayFeature.php +++ b/src/world/generator/vanilla/feature/ClayFeature.php @@ -1,4 +1,5 @@ level->getBlockID($x, $y, $z); if($id != WATER && $id != STILL_WATER) return false; - + $nextFloat = $rand->nextFloat() * 3.1416; - $sin = (float)($x + 8 + ((sin($nextFloat) * $size) / 8)); - $sin2 = (float)(($x + 8) - ((sin($nextFloat) * $size) / 8)); - $cos = (float)($z + 8 + ((cos($nextFloat) * $size) / 8)); - $cos2 = (float)(($z + 8) - ((cos($nextFloat) * $size) / 8)); - + $sin = (float) ($x + 8 + ((sin($nextFloat) * $size) / 8)); + $sin2 = (float) (($x + 8) - ((sin($nextFloat) * $size) / 8)); + $cos = (float) ($z + 8 + ((cos($nextFloat) * $size) / 8)); + $cos2 = (float) (($z + 8) - ((cos($nextFloat) * $size) / 8)); + $nextInt = $y + $rand->nextInt(3) + 2; $nextInt2 = $y + $rand->nextInt(3) + 2; - + for($i = 0; $i <= $size; ++$i){ $d = $sin + ((($sin2 - $sin) * $i) / $size); $d2 = $nextInt + ((($nextInt2 - $nextInt) * $i) / $size); $d3 = $cos + ((($cos2 - $cos) * $i) / $size); - + $nextFloat = ($rand->nextFloat() * $size) / 16; $sin3 = (((sin(($i * 3.1416) / $size) + 1) * $nextFloat) + 1); $sin4 = (((sin(($i * 3.1416) / $size) + 1) * $nextFloat) + 1);//TODO optimize a bit? @@ -30,21 +31,21 @@ class ClayFeature $floor4 = floor($d2 + ($sin4 / 2.0)); $floor5 = floor($d3 - ($sin3 / 2.0)); $floor6 = floor($d3 + ($sin3 / 2.0)); - + for($i2 = $floor; $i2 <= $floor2; ++$i2){ for($i3 = $floor3; $i3 <= $floor4; ++$i3){ for($i4 = $floor5; $i4 <= $floor6; ++$i4){ $d4 = (($i2 + 0.5) - $d) / ($sin3 / 2); $d5 = (($i3 + 0.5) - $d2) / ($sin4 / 2); $d6 = (($i4 + 0.5) - $d3) / ($sin3 / 2); - if(($d4*$d4)+($d5*$d5)+($d6*$d6)<1 && $level->level->getBlockID($i2, $i3, $i4) == SAND){ + if(($d4 * $d4) + ($d5 * $d5) + ($d6 * $d6) < 1 && $level->level->getBlockID($i2, $i3, $i4) == SAND){ $level->level->setBlockID($i2, $i3, $i4, $clayid); } } } } } - + } } diff --git a/src/world/generator/vanilla/feature/Feature.php b/src/world/generator/vanilla/feature/Feature.php index f52426ad..d38ce7c8 100644 --- a/src/world/generator/vanilla/feature/Feature.php +++ b/src/world/generator/vanilla/feature/Feature.php @@ -5,7 +5,7 @@ abstract class Feature public static $TREE, $BIRCH_TREE, $PINE_TREE, $SPRUCE_TREE; public static $FLOWER_RED, $FLOWER_YELLOW, $MUSHROOM_BROWN, $MUSHROOM_RED; public static function init(){ - Feature::$TREE = new TreeFeature(); + Feature::$TREE = new TreeFeature(); Feature::$BIRCH_TREE = new BirchFeature(); Feature::$PINE_TREE = new PineFeature(); Feature::$SPRUCE_TREE = new SpruceFeature(); @@ -13,10 +13,10 @@ abstract class Feature Feature::$FLOWER_YELLOW = new FlowerFeature(DANDELION); Feature::$MUSHROOM_BROWN = new FlowerFeature(BROWN_MUSHROOM); Feature::$MUSHROOM_RED = new FlowerFeature(RED_MUSHROOM); - + } public function place(Level $level, MTRandom $rand, $x, $y, $z){ //TODO pass VanillaGenerator instance and update heightmap on ceratin block placement - + } } diff --git a/src/world/generator/vanilla/feature/FlowerFeature.php b/src/world/generator/vanilla/feature/FlowerFeature.php index 2bdacb8f..6b9e02bf 100644 --- a/src/world/generator/vanilla/feature/FlowerFeature.php +++ b/src/world/generator/vanilla/feature/FlowerFeature.php @@ -6,7 +6,7 @@ class FlowerFeature extends Feature public function __construct($id){ $this->id = $id; } - + public function place(Level $level, MTRandom $rand, $x, $y, $z){ //TODO pass VanillaGenerator instance and update heightmap on ceratin block placement for($i = 0; $i < 64; ++$i){ $xPos = ($x + $rand->nextInt(8)) - $rand->nextInt(8); diff --git a/src/world/generator/vanilla/feature/OreFeature.php b/src/world/generator/vanilla/feature/OreFeature.php index e4aa83d4..82f464f7 100644 --- a/src/world/generator/vanilla/feature/OreFeature.php +++ b/src/world/generator/vanilla/feature/OreFeature.php @@ -4,49 +4,49 @@ class OreFeature { public static function place(Level $level, MTRandom $rand, $x, $y, $z, $id, $amount){ $nextFloat = $rand->nextFloat() * 3.1415927; - + $sin = ($x + 8 + ((sin($nextFloat) * $amount) / 8)); $sin2 = (($x + 8) - ((sin($nextFloat) * $amount) / 8)); - + $cos = ($z + 8 + ((cos($nextFloat) * $amount) / 8)); $cos2 = (($z + 8) - ((cos($nextFloat) * $amount) / 8)); - + $nextInt = $y + $rand->nextInt(3) + 2; $nextInt2 = $y + $rand->nextInt(3) + 2; for($i = 0; $i <= $amount; ++$i){ $d = $sin + ((($sin2 - $sin) * $i) / $amount); - $d2 = $nextInt + ((($nextInt2 - $nextInt) * $i) / $amount); - $d3 = $cos + ((($cos2 - $cos) * $i) / $amount); - - $nextFloat = ($rand->nextFloat() * $amount) / 16; - $sin3 = (((sin(($i * 3.1415927) / $amount) + 1) * $nextFloat) + 1.0); - $sin4 = (((sin(($i * 3.1415927) / $amount) + 1) * $nextFloat) + 1.0); - - $floor = floor($d - ($sin3 / 2)); - $floor2 = floor($d2 - ($sin4 / 2)); - $floor3 = floor($d3 - ($sin3 / 2.0)); - $floor4 = floor($d + ($sin3 / 2.0)); - $floor5 = floor($d2 + ($sin4 / 2.0)); - $floor6 = floor($d3 + ($sin3 / 2.0)); - - for($i2 = $floor; $i2 <= $floor4; ++$i2){ - $d4 = (($i2 + 0.5) - $d) / ($sin3 / 2); - $d4sqrd = $d4*$d4; - if($d4sqrd < 1){ - for($i3 = $floor2; $i3 <= $floor5; ++$i3){ - $d5 = (($i3 + 0.5) - $d2) / ($sin4 / 2); - $d5sqrd = $d5*$d5; - if($d4sqrd+$d5sqrd < 1){ - for($i4 = $floor3; $i4 <= $floor6; ++$i4){ - $d6 = (($i4 + 0.5) - $d3) / ($sin3 / 2); - if($d4sqrd+$d5sqrd+($d6*$d6) < 1 && $level->level->getBlockID($i2, $i3, $i4) == STONE){ - $level->level->setBlockID($i2, $i3, $i4, $id); - } - } - } - } - } - } + $d2 = $nextInt + ((($nextInt2 - $nextInt) * $i) / $amount); + $d3 = $cos + ((($cos2 - $cos) * $i) / $amount); + + $nextFloat = ($rand->nextFloat() * $amount) / 16; + $sin3 = (((sin(($i * 3.1415927) / $amount) + 1) * $nextFloat) + 1.0); + $sin4 = (((sin(($i * 3.1415927) / $amount) + 1) * $nextFloat) + 1.0); + + $floor = floor($d - ($sin3 / 2)); + $floor2 = floor($d2 - ($sin4 / 2)); + $floor3 = floor($d3 - ($sin3 / 2.0)); + $floor4 = floor($d + ($sin3 / 2.0)); + $floor5 = floor($d2 + ($sin4 / 2.0)); + $floor6 = floor($d3 + ($sin3 / 2.0)); + + for($i2 = $floor; $i2 <= $floor4; ++$i2){ + $d4 = (($i2 + 0.5) - $d) / ($sin3 / 2); + $d4sqrd = $d4 * $d4; + if($d4sqrd < 1){ + for($i3 = $floor2; $i3 <= $floor5; ++$i3){ + $d5 = (($i3 + 0.5) - $d2) / ($sin4 / 2); + $d5sqrd = $d5 * $d5; + if($d4sqrd + $d5sqrd < 1){ + for($i4 = $floor3; $i4 <= $floor6; ++$i4){ + $d6 = (($i4 + 0.5) - $d3) / ($sin3 / 2); + if($d4sqrd + $d5sqrd + ($d6 * $d6) < 1 && $level->level->getBlockID($i2, $i3, $i4) == STONE){ + $level->level->setBlockID($i2, $i3, $i4, $id); + } + } + } + } + } + } } } } diff --git a/src/world/generator/vanilla/feature/PineFeature.php b/src/world/generator/vanilla/feature/PineFeature.php index 115473d9..38ff7c6d 100644 --- a/src/world/generator/vanilla/feature/PineFeature.php +++ b/src/world/generator/vanilla/feature/PineFeature.php @@ -32,7 +32,7 @@ class PineFeature extends Feature } } if(!$flag) return false; - + $i2 = $level->level->getBlockID($x, $y - 1, $z); if(($i2 != GRASS && $i2 != DIRT) || $y >= 128 - $l - 1) return false; $level->level->setBlockID($x, $y - 1, $z, DIRT); @@ -47,7 +47,7 @@ class PineFeature extends Feature } } } - + if($k2 >= 1 && $i3 == $y + $i1 + 1){ --$k2; continue; @@ -56,7 +56,7 @@ class PineFeature extends Feature ++$k2; } } - + for($j3 = 0; $j3 < $l - 1; ++$j3){ $i4 = $level->level->getBlockID($x, $y + $j3, $z); if($i4 == 0 || $i4 == LEAVES){ diff --git a/src/world/generator/vanilla/feature/SpruceFeature.php b/src/world/generator/vanilla/feature/SpruceFeature.php index c32c7d6f..6a05710c 100644 --- a/src/world/generator/vanilla/feature/SpruceFeature.php +++ b/src/world/generator/vanilla/feature/SpruceFeature.php @@ -1,4 +1,5 @@ 128){ return false; } - + for($i3 = $y; $i3 <= $y + 1 + $nextInt && $z2; ++$i3){ if($i3 - $y < $nextInt2){ $i = 0; @@ -30,7 +31,7 @@ class SpruceFeature extends Feature } } } - + if($z2){ $blockID = $level->level->getBlockID($x, $y - 1, $z); if(($blockID == GRASS || $blockID == DIRT) && $y < (128 - $nextInt) - 1){ @@ -49,7 +50,7 @@ class SpruceFeature extends Feature } } } - + if($nextInt4 >= $i6){ $nextInt4 = $i7; $i7 = 1; diff --git a/src/world/generator/vanilla/feature/TreeFeature.php b/src/world/generator/vanilla/feature/TreeFeature.php index 2b4f5a2a..b30b45ea 100644 --- a/src/world/generator/vanilla/feature/TreeFeature.php +++ b/src/world/generator/vanilla/feature/TreeFeature.php @@ -1,38 +1,42 @@ nextInt(3) + 4; $z2 = true; - if($y < 1 || $y + $nextInt + 1 > 128) return false; - for($i = $y; $i <= $y + 1 + $nextInt; ++$i){ + if($y < 1 || $y + $nextInt + 1 > 128) { + return false; + } + for($i = $y; $i <= $y + 1 + $nextInt; ++$i) { $i2 = ($i == $y) ? 0 : 1; - if($i >= (($y + 1) + $nextInt) - 2) $i2 = 2; - - for($i3 = $x - $i2; $i3 <= $x + $i2 && $z2; ++$i3){ - for($i4 = $z - $i2; $i4 <= $z + $i2 && $z2; ++$i4){ - if($i >= 0 && $i < 128){ + if($i >= (($y + 1) + $nextInt) - 2) { + $i2 = 2; + } + + for($i3 = $x - $i2; $i3 <= $x + $i2 && $z2; ++$i3) { + for($i4 = $z - $i2; $i4 <= $z + $i2 && $z2; ++$i4) { + if($i >= 0 && $i < 128) { $tileID = $level->level->getBlockID($i3, $i, $i4); - if($tileID != 0 && $tileID != LEAVES){ + if($tileID != 0 && $tileID != LEAVES) { return; } - }else{ + } else { return; } } } } - if($z2){ + if($z2) { $tileID = $level->level->getBlockID($x, $y - 1, $z); - if(($tileID == GRASS || $tileID == DIRT) && $y < (128 - $nextInt) - 1){ + if(($tileID == GRASS || $tileID == DIRT) && $y < (128 - $nextInt) - 1) { $level->level->setBlockID($x, $y - 1, $z, DIRT); } - for($i5 = ($y - 3) + $nextInt; $i5 <= $y + $nextInt; ++$i5){ + for($i5 = ($y - 3) + $nextInt; $i5 <= $y + $nextInt; ++$i5) { $i6 = $i5 - ($y + $nextInt); - $i7 = (int)(1 - ($i6 / 2)); - for($i8 = $x - $i7; $i8 <= $x + $i7; ++$i8){ + $i7 = (int) (1 - ($i6 / 2)); + for($i8 = $x - $i7; $i8 <= $x + $i7; ++$i8) { $i9 = $i8 - $x; - for($i10 = $z - $i7; $i10 <= $z + $i7; ++$i10){ + for($i10 = $z - $i7; $i10 <= $z + $i7; ++$i10) { $i11 = $i10 - $z; if((abs($i9) != $i7 || abs($i11) != $i7 || ($rand->nextInt(2) != 0 && $i6 != 0))/* && !Block.FULL_OPAQUE[world.getBlockIDAt(i8, i5, i10)]TODO opaque?*/) { $level->level->setBlockID($i8, $i5, $i10, LEAVES); @@ -40,13 +44,12 @@ class TreeFeature extends Feature } } } - for($i12 = 0; $i12 < $nextInt; ++$i12){ + for($i12 = 0; $i12 < $nextInt; ++$i12) { $tileID = $level->level->getBlockID($x, $y + $i12, $z); - if($tileID == 0 || $tileID == LEAVES){ + if($tileID == 0 || $tileID == LEAVES) { $level->level->setBlockID($x, $y + $i12, $z, WOOD); } } } } } -