diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..ff0eb9fba --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + codestyle: + name: Code Style checks + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP and tools + uses: shivammathur/setup-php@2.31.1 + with: + php-version: 8.0 + tools: php-cs-fixer:3.60 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Run PHP-CS-Fixer + run: php-cs-fixer fix --dry-run --diff --ansi diff --git a/.gitignore b/.gitignore index b95b29688..3b0c39ad4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ server.lock *.txt *.properties +# php-cs-fixer +/.php_cs.cache +/.php-cs-fixer.cache ############ ## Windows diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 000000000..6d0926a1e --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,36 @@ +in(__DIR__ . '/src'); + +return (new PhpCsFixer\Config) + ->setRules([ + 'array_indentation' => true, + 'array_syntax' => [ + 'syntax' => 'short' + ], + 'binary_operator_spaces' => [ + 'default' => 'single_space' + ], + 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => true, + 'cast_spaces' => [ + 'space' => 'single' + ], + 'elseif' => true, + 'indentation_type' => true, + 'no_closing_tag' => true, + 'no_empty_phpdoc' => true, + 'no_extra_blank_lines' => true, + 'no_superfluous_phpdoc_tags' => [ + 'allow_mixed' => true, + ], + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_whitespace_in_blank_line' => true, + 'unary_operator_spaces' => true + ]) + ->setFinder($finder) + ->setIndent("\t") + ->setLineEnding("\n") + ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()); \ No newline at end of file diff --git a/README.md b/README.md index e58c77839..ffbe02f92 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ NostalgiaCore is a fork of Legacy PocketMine-MP 1.3.12, which fixes bugs of Legacy PocketMine-MP, and adds new content -Supported MCPE versions: 0.8.0, 0.8.1 (maybe 0.8.2) +Supported MCPE versions: 0.3.0 ~ 0.8.1 (maybe 0.8.2) (Special thx to GullCraft Network and DartMiner43) diff --git a/src/API/AchievementAPI.php b/src/API/AchievementAPI.php index beabe3084..be89f3b7b 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 @@ public static function addAchievement($achievementId, $achievementName, array $r } 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 @@ public static function grantAchievement(Player $player, $achievementId){ } 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 @@ public static function broadcastAchievement(Player $player, $achievementId){ } 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,17 +170,17 @@ public function viewAchievements($cmd, $params, $issuer, $alias) }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"; } @@ -192,9 +191,9 @@ public function viewAchievements($cmd, $params, $issuer, $alias) $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 7ab128b6d..bab63ec39 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 ddd309d99..951e05daa 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -259,7 +259,7 @@ public function commandHandler($cmd, $args, $issuer, $alias){ $output .= "Usage: /setblock "; break; } - + $level = $issuer->entity->level; $block = self::fromString($args[3])->getBlock(); } @@ -294,8 +294,8 @@ public function commandHandler($cmd, $args, $issuer, $alias){ 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 @@ public function commandHandler($cmd, $args, $issuer, $alias){ 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; 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."; } @@ -412,7 +412,6 @@ public function playerBlockBreak(Player $player, Vector3 $vector){ 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 @@ public function playerBlockAction(Player $player, Vector3 $vector, $face, $fx, $ 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 @@ public function playerBlockAction(Player $player, Vector3 $vector, $face, $fx, $ $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 @@ public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){ 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 @@ public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $d } return; } - + if($delay !== false){ $this->scheduleBlockUpdate($pos->getSide(0), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(1), $delay, $type); @@ -576,7 +573,7 @@ public function scheduleBlockUpdateXYZ(Level $level, $x, $y, $z, $type = BLOCK_U 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 @@ public function scheduleBlockUpdateXYZ(Level $level, $x, $y, $z, $type = BLOCK_U } return false; } - + public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){ $type = (int) $type; if($delay < 0){ @@ -644,4 +641,31 @@ public function blockUpdateTick(){ } } } + + /** + * 方块/物品id转换,防止新版本影响旧版本视觉效果 + */ + public static function convertHighItemIdsToOldItemIds(int $protocolId, int $itemId) : int{ + if ($protocolId >= ProtocolInfo12::CURRENT_PROTOCOL_12) { + return $itemId; + } + + $idMap = [ //default for protocol < 12 + LIT_PUMPKIN => MELON_BLOCK, //block + PUMPKIN_SEEDS => MELON_SEEDS, //item + PUMPKIN_PIE => BREAD, //item + BEETROOT => BREAD, //item + BEETROOT_SEEDS => SEEDS, //item + ]; + + if ($protocolId < ProtocolInfo9::CURRENT_PROTOCOL_9) { + $idMap += [ + NETHERRACK => OBSIDIAN, //block + NETHER_BRICK => BRICK, //item + NETHER_QUARTZ => BRICK, //item + ]; + } + + return $idMap[$itemId] ?? $itemId; + } } diff --git a/src/API/ChatAPI.php b/src/API/ChatAPI.php index 69fade6d6..92bffa511 100644 --- a/src/API/ChatAPI.php +++ b/src/API/ChatAPI.php @@ -107,8 +107,6 @@ public function broadcast($message){ /** * @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 540bc7391..a0c5036b3 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -24,12 +24,12 @@ public function init(){ $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 @@ public function init(){ 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; diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 6d64f453b..26d691a4e 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, @@ -46,24 +45,24 @@ public function commandHandler($cmd, $args, $issuer, $alias){ 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,11 +76,11 @@ public function commandHandler($cmd, $args, $issuer, $alias){ 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."; } elseif(strtolower($args[1]) == "baby"){//summon [baby] @@ -94,7 +93,7 @@ public function commandHandler($cmd, $args, $issuer, $alias){ if(!isset($args[0])){ return "/despawn "; } - + $despawnclass = 0; $despawntype = 0; switch($args[0]){ @@ -138,12 +137,12 @@ public function commandHandler($cmd, $args, $issuer, $alias){ } } } - + 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 @@ public function summon(Position $pos, $class, $type, array $data = []){ ] + $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 @@ public function add(Level $level, $class, $type = 0, $data = []){ } 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 @@ public function spawnToAll(Entity $e){ } } } - + 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 @@ public function remove($eid){ 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 @@ public function getRadius(Position $center, $radius = 15, $class = false){ } 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 @@ public function harm($eid, $attack, $cause, $force = false){ } $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 @@ public function dropRawPos(Level $level, $x, $y, $z, $item, $speedX, $speedY, $s "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 @@ public function dropRawPos(Level $level, $x, $y, $z, $item, $speedX, $speedY, $s } } } - + public function drop(Position $pos, Item $item, $pickupDelay = 10){ if($item->getID() === AIR or $item->count <= 0){ return; @@ -310,7 +309,7 @@ public function drop(Position $pos, Item $item, $pickupDelay = 10){ } } } - + public function spawnAll(Player $player){ foreach($player->level->entityList as $e){ if($e->class !== ENTITY_PLAYER){ @@ -318,18 +317,18 @@ public function spawnAll(Player $player){ } } } - + 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 3784363a8..8f5edd9f7 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -40,7 +40,7 @@ public function loadLevel($name){ 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 @@ public function loadLevel($name){ } } } - - + $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 @@ public function loadLevel($name){ 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 @@ public function loadLevel($name){ 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 373f3c708..2bba24860 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -19,7 +19,7 @@ public function init(){ $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 @@ public function handle($data, $event){ 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 @@ public function commandHandler($cmd, $args, $issuer, $alias){ 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 @@ public function commandHandler($cmd, $args, $issuer, $alias){ $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; @@ -327,6 +327,17 @@ public function online(){ return $o; } + /** + * @return int + */ + public static function decodeProtocol($ip){ + foreach(ServerAPI::request()->clients as $p) { + if($p->ip == $ip){ + return $p->PROTOCOL; + } + } + } + public function add($CID){ if(isset($this->server->clients[$CID])){ $player = $this->server->clients[$CID]; @@ -462,7 +473,7 @@ public function remove($CID){ unset($player->entity->player); //unset($player->entity); } - + $player = null; unset($player); } diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 5e98b6ce9..facda55ba 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -150,20 +150,20 @@ private function loadAll(){ } } 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"]); $class = $pluginInfo["CLClass"]; $loader = new $class(); $loader->loadAll($phr); - + $pluginName = PharUtils::getNameSpaceClass($pluginInfo["mainFile"]); include($phr."/src/".$pluginInfo["mainFile"]); $plugin = new $pluginName($this->server->api, false); @@ -268,7 +268,7 @@ public function initAll(){ $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 @@ public function __construct($name, $version = false){ } } - diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index b990a8c6f..2fd9ae4cb 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 a5a481182..c4bbdbe66 100644 --- a/src/API/TileAPI.php +++ b/src/API/TileAPI.php @@ -17,7 +17,7 @@ public function getXYZ(Level $level, $x, $y, $z){ } return false; } - + public function invalidateAll(Level $level, $x, $y, $z){ $x = (int) $x; $y = (int) $y; @@ -31,14 +31,14 @@ public function invalidateAll(Level $level, $x, $y, $z){ ++$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 e8e9f54ef..d7e0cd66f 100644 --- a/src/API/TimeAPI.php +++ b/src/API/TimeAPI.php @@ -175,5 +175,4 @@ public function sunset(){ return $this->set("sunset"); } - } diff --git a/src/Deprecation.php b/src/Deprecation.php index 7d8e66cd1..c0e077887 100644 --- a/src/Deprecation.php +++ b/src/Deprecation.php @@ -1,6 +1,5 @@ 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); } @@ -145,7 +146,6 @@ public function getSpawn(){ } /** - * @param Vector3 $pos * * @return boolean */ @@ -164,7 +164,7 @@ public function sleepOn(Vector3 $pos){ 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{ @@ -174,14 +174,13 @@ public function sleepOn(Vector3 $pos){ $this->setSpawn($spawnPoint); return true; } - + 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 @@ -221,7 +220,7 @@ public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = $pk->pitch = 0; $pk->bodyYaw = 0; $e->player->dataPacket($pk); - + $pk = new MovePlayerPacket(); $pk->eid = $e->eid; $pk->x = -256; @@ -231,7 +230,7 @@ public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = $pk->pitch = 0; $pk->bodyYaw = 0; $this->dataPacket($pk); - + }else{ $pk = new MoveEntityPacket_PosRot(); $pk->eid = $e->eid; @@ -270,7 +269,7 @@ public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = } } } - + $pk = new SetTimePacket; $pk->time = $this->level->getTime(); $this->dataPacket($pk); @@ -303,12 +302,12 @@ public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = $player->sendArmor($this); } } - + $resyncpos = new Position($pos->x, $pos->y, $pos->z, $pos->level); }else{ $resyncpos = new Vector3($pos->x, $pos->y, $pos->z); } - + $this->lastCorrect = $resyncpos; $this->entity->fallY = false; $this->entity->fallStart = false; @@ -326,14 +325,14 @@ public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = $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; @@ -346,8 +345,6 @@ public function teleport(Vector3 $pos, $yaw = false, $pitch = false, $terrain = } /** - * @param integer $id - * @param array $data * * @return array|bool */ @@ -359,14 +356,23 @@ public function dataPacket(RakNetDataPacket $packet){ if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ return; } - + + if(PacketPool::isPacketExist($packet->pid(), $this->PROTOCOL) != true){ + return; + } + + $packet->PROTOCOL = $this->PROTOCOL; + $packet->encode(); + if($packet->pid() == 163 or $packet->pid() == 164 && $this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return; + } $len = strlen($packet->buffer) + 1; $MTU = $this->MTU - 24; if($len > $MTU){ return $this->directBigRawPacket($packet); } - + if(($this->bufferLen + $len) >= $MTU){ $this->sendBuffer(); } @@ -478,12 +484,11 @@ public function sendBuffer(){ * @return Item */ public function getSlot($slot){ - return $this->inventory[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); + return $this->inventory[(int) $slot] ?? BlockAPI::getItem(AIR, 0, 0); } /** * @param integer $slot - * @param Item $item * @param boolean $send * * @return boolean @@ -531,18 +536,18 @@ public function sendArmor($player = false){ } public $lastOrderX = 0; public $lastOrderZ = 0; - + 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; + $Y = ((int) $this->entity->y) >> 4; $v = new Vector3($X, $Y, $Z); for($x = 0; $x < 16; ++$x){ for($z = 0; $z < 16; ++$z){ @@ -569,10 +574,10 @@ public function orderChunks(){ } } } - + asort($this->chunksOrder); } - + public function loaddAllChunks(){ for($x = 0; $x < 16; $x++){ for($z = 0; $z < 16; $z++){ @@ -580,7 +585,7 @@ public function loaddAllChunks(){ } } } - + public function useChunk($X, $Z){ $Yndex = 0; for($iY = 0; $iY < 8; ++$iY){ @@ -594,7 +599,7 @@ public function useChunk($X, $Z){ $maxX = (($X << 4) + 15); $minZ = ($Z << 4); $maxZ = (($Z << 4) + 15); - + $pk = new ChunkDataPacket; $pk->chunkX = $X; $pk->chunkZ = $Z; @@ -611,12 +616,12 @@ public function useChunk($X, $Z){ } } } - + if($cnt === false){ return false; } } - + public function getNextChunk($world){ if($this->connected === false or $world != $this->level){ return false; @@ -693,9 +698,6 @@ public function getNextChunk($world){ $this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world); } - /** - * @param Vector3 $pos - */ public function setSpawn(Vector3 $pos){ if(!($pos instanceof Position)){ $level = $this->entity->level; @@ -731,9 +733,6 @@ public function sendInventory(){ } /** - * @param $type - * @param $damage - * @param $count * * @return boolean */ @@ -748,7 +747,7 @@ public function hasSpace($type, $damage, $count){ break; }elseif($item->getID() === $type and $item->getMetadata() === $damage){ $add = min($item->getMaxStackSize() - $item->count, $count); - + if($add <= 0){ continue; } @@ -770,7 +769,7 @@ public function hasSpace($type, $damage, $count){ * @return Item */ public function getArmor($slot){ - return $this->armor[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); + return $this->armor[(int) $slot] ?? BlockAPI::getItem(AIR, 0, 0); } public function setArmor($slot, Item $armor, $send = true){ @@ -946,25 +945,23 @@ public function eventHandler($data, $event){ } /** - * @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){ $add = min($item->getMaxStackSize() - $item->count, $count); - + if($add <= 0){ continue; } $item->count += $add; if($send) $this->sendInventorySlot($s); - + $count -= $add; if($count <= 0) return true; } @@ -1038,7 +1035,7 @@ public function getGamemode(){ return "view"; } } - + public function checkSpawnPosition(){ if($this->server->api->dhandle("player.checkspawnpos", ["player" => $this]) === false) return; $level = $this->spawnPosition->level; @@ -1047,20 +1044,20 @@ public function checkSpawnPosition(){ $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); + $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)){ $blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this->entity->level, $x, $y, $z, $this->entity); - + foreach($blockBounds as $blockBound){ if($this->entity->boundingBox->intersectsWith($blockBound)){ $this->sendChat("Your spawn positon is obstructed."); @@ -1076,7 +1073,7 @@ public function checkSpawnPosition(){ $this->spawnPosition = $this->server->api->level->getDefault()->getSpawn(); } } - + public function setGamemode($gm){ if($gm < 0 or $gm > 3 or $this->gamemode === $gm){ return false; @@ -1111,19 +1108,19 @@ public function setGamemode($gm){ } $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){ $this->makeInvisibleForAllPlayers(); } if($this->gamemode === CREATIVE){ $this->server->api->player->spawnToAllPlayers($this); } - + $this->inventory = $inv; $this->sendSettings(); $this->sendInventory(); @@ -1150,10 +1147,10 @@ public function sendSettings($nametags = true){ if($nametags !== false){ $flags |= 0x20; //Show Nametags } - + //$flags |= 0x2; //pvp //$flags |= 0x4; //pve - + $pk = new AdventureSettingsPacket; $pk->flags = $flags; $this->dataPacket($pk); @@ -1260,6 +1257,7 @@ public function handlePacketQueues(){ } $this->received[$p->messageIndex] = true; } + $p->PROTOCOL = $this->PROTOCOL; $p->decode(); $this->handleDataPacket($p); } @@ -1305,7 +1303,7 @@ public function sendEntityMovementUpdateQueue(){ $this->entityMovementQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->entityMovementQueue->data = []; } - + public function sendBlockUpdateQueue(){ if($this->blockUpdateQueueLength > 0 && $this->blockUpdateQueue instanceof RakNetPacket){ $this->blockUpdateQueue->seqNumber = $this->counter[0]++; @@ -1317,7 +1315,7 @@ public function sendBlockUpdateQueue(){ $this->blockUpdateQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->blockUpdateQueue->data = []; } - + public function addBlockUpdateIntoQueue($x, $y, $z, $id, $meta){ $packet = new UpdateBlockPacket(); $packet->x = $x; @@ -1325,21 +1323,22 @@ public function addBlockUpdateIntoQueue($x, $y, $z, $id, $meta){ $packet->z = $z; $packet->block = $id; $packet->meta = $meta; + $packet->PROTOCOL = $this->PROTOCOL; $packet->encode(); - + $len = 1 + strlen($packet->buffer); $MTU = $this->MTU - 24; - + 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){ $len = 0; $packets = 0; @@ -1357,6 +1356,7 @@ public function addEntityMovementUpdateToQueue(Entity $e){ $motion->speedX = $e->speedX; $motion->speedY = $e->speedY; $motion->speedZ = $e->speedZ; + $motion->PROTOCOL = $this->PROTOCOL; $motion->encode(); $len += 1 + strlen($motion->buffer); ++$packets; @@ -1367,7 +1367,7 @@ public function addEntityMovementUpdateToQueue(Entity $e){ $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){ $move = new MovePlayerPacket(); @@ -1378,6 +1378,7 @@ public function addEntityMovementUpdateToQueue(Entity $e){ $move->yaw = $e->yaw; $move->pitch = $e->pitch; $move->bodyYaw = $e->headYaw; + $move->PROTOCOL = $this->PROTOCOL; $move->encode(); }else{ $move = new MoveEntityPacket_PosRot(); @@ -1387,16 +1388,19 @@ public function addEntityMovementUpdateToQueue(Entity $e){ $move->z = $e->z; $move->yaw = $e->yaw; $move->pitch = $e->pitch; + $move->PROTOCOL = $this->PROTOCOL; $move->encode(); } - + $len += strlen($move->buffer) + 1; ++$packets; $moveSent = true; - }else if($e->headYaw != $e->lastHeadYaw){ + + }elseif($this->PROTOCOL > ProtocolInfo12::CURRENT_PROTOCOL_12 && $e->headYaw != $e->lastHeadYaw){ $headyaw = new RotateHeadPacket(); $headyaw->eid = $e->eid; $headyaw->yaw = $e->headYaw; + $headyaw->PROTOCOL = $this->PROTOCOL; $headyaw->encode(); $len += strlen($headyaw->buffer) + 1; ++$packets; @@ -1423,10 +1427,10 @@ public function addEntityMovementUpdateToQueue(Entity $e){ $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. @@ -1522,6 +1526,7 @@ public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $re return []; } + $packet->PROTOCOL = $this->PROTOCOL; $packet->encode(); $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk->data[] = $packet; @@ -1536,13 +1541,12 @@ public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $re } 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() { @@ -1555,21 +1559,199 @@ public function getPing() { 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; + } + + if ($packet->pid() == ProtocolInfo::LOGIN_PACKET) { + if ($this->loggedIn === true) { + return; + } + $this->username = $packet->username; + $this->iusername = strtolower($this->username); + $this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData]; + $this->PROTOCOL = $packet->PROTOCOL; + 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 < ProtocolInfo3::CURRENT_PROTOCOL_3 && $packet->protocol1 > ProtocolInfo::CURRENT_PROTOCOL) { + if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) { + $pk = new LoginStatusPacket; + $pk->status = 1; + $this->directDataPacket($pk); + } else { + $pk = new LoginStatusPacket; + $pk->status = 2; + $this->directDataPacket($pk); + } + $this->close("Incorrect protocol #" . $packet->protocol1, false); + return; + } + if (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) { + $this->close("Unknown reason", false); + return; + } + + 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)) { + $this->close("You are banned!", false); + return; + } + $this->loggedIn = true; + + 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) { + $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) { + $this->close("join cancelled", false); + return; + } + + 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) { + $inv = []; + if (($this->gamemode & 0x02) === 0x02) { + foreach (BlockAPI::$creative as $item) { + $inv[] = [0, 0, 1]; + } + } else { + foreach (BlockAPI::$creative as $item) { + $inv[] = [$item[0], $item[1], 1]; + } + } + } + $this->data->set("inventory", $inv); + } + $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) { + $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) { + $this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], $item[0] === 0 ? 0 : 1); + } + + $this->data->set("lastIP", $this->ip); + $this->data->set("lastID", $this->clientID); + + $this->server->api->player->saveOffline($this->data); + + $pk = new LoginStatusPacket; + $pk->status = 0; + $this->dataPacket($pk); + + $pk = new StartGamePacket; + $pk->seed = $this->level->getSeed(); + $pk->x = $this->data->get("position")["x"]; + $pk->y = $this->data->get("position")["y"]; + $pk->z = $this->data->get("position")["z"]; + $pk->generator = 0; + $pk->gamemode = $this->gamemode & 0x01; + $pk->eid = 0; + $this->dataPacket($pk); + + if (($this->gamemode & 0x01) === 0x01) { + $this->slot = 0; + $this->hotbar = []; + } elseif ($this->data->exists("hotbar")) { + $this->hotbar = $this->data->get("hotbar"); + $this->slot = $this->hotbar[0]; + } 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; + } + if ($this->data->exists("slot-count")) { + $this->slotCount = $this->data->get("slot-count"); + } 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) { + $this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level); + + $pk = new SetSpawnPositionPacket; + $pk->x = (int) $this->spawnPosition->x; + $pk->y = (int) $this->spawnPosition->y; + $pk->z = (int) $this->spawnPosition->z; + $this->dataPacket($pk); + } + $this->entity->check = false; + $this->entity->setName($this->username); + $this->entity->data["CID"] = $this->CID; + $this->evid[] = $this->server->event("server.chat", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.motion", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.animate", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.event", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.metadata", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.link", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.equipment.change", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.armor", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.pickup", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("tile.container.slot", [$this, "eventHandler"]); + $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) . ")"); return; } - switch($packet->pid()){ + $internalPid = $packet->getInternalPid(); + + switch ($internalPid) { 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; @@ -1583,7 +1765,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->close("client disconnect"); break; case ProtocolInfo::CLIENT_CONNECT_PACKET: - if($this->loggedIn === true){ + if ($this->loggedIn === true) { break; } $pk = new ServerHandshakePacket; @@ -1593,27 +1775,28 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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)){ + $this->PROTOCOL = $packet->PROTOCOL; + 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); @@ -1621,55 +1804,55 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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]; } } @@ -1679,15 +1862,15 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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); } @@ -1696,7 +1879,6 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->server->api->player->saveOffline($this->data); - $pk = new LoginStatusPacket; $pk->status = 0; $this->dataPacket($pk); @@ -1710,27 +1892,28 @@ public function handleDataPacket(RakNetDataPacket $packet){ $pk->gamemode = $this->gamemode & 0x01; $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 . ";"); @@ -1762,25 +1945,24 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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); @@ -1794,9 +1976,9 @@ public function handleDataPacket(RakNetDataPacket $packet){ //$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(); @@ -1812,48 +1994,48 @@ public function handleDataPacket(RakNetDataPacket $packet){ } 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; @@ -1862,79 +2044,78 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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) { + + if (Player::$experimentalHotbar && $has) { $this->slot = $packet->slot; $this->curHotbarIndex = $packetSlotPos; } - if(!$has){ - if(Player::$experimentalHotbar) { + 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(); @@ -1946,13 +2127,13 @@ public function handleDataPacket(RakNetDataPacket $packet){ //$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); @@ -1992,7 +2173,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $data["posX"] = $packet->posX; $data["posY"] = $packet->posY; $data["posZ"] = $packet->posZ; - + //nc: check item desync $heldItem = $this->getHeldItem(); if($heldItem->getID() != $packet->item || $heldItem->getMetadata() != $packet->meta){ @@ -2014,11 +2195,11 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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; } @@ -2041,21 +2222,21 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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(), @@ -2067,26 +2248,26 @@ public function handleDataPacket(RakNetDataPacket $packet){ "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); + + 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; //$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); @@ -2095,8 +2276,75 @@ public function handleDataPacket(RakNetDataPacket $packet){ } } break; + case ProtocolInfo::PLACE_BLOCK_PACKET: + 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) { + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->dataPacket($pk); + break; + } + $this->craftingItems = []; + $this->toCraft = []; + $packet->eid = $this->eid; + $data = []; + + if ($packet->face >= 0 and $packet->face <= 5) { + 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)) { + + } else { + $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->x, $packet->y, $packet->z); + break; + } + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->dataPacket($pk); + break; + } + 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; @@ -2106,20 +2354,20 @@ public function handleDataPacket(RakNetDataPacket $packet){ 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, @@ -2143,11 +2391,11 @@ public function handleDataPacket(RakNetDataPacket $packet){ * 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) { + 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); @@ -2155,7 +2403,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ } } } - }else{ //inv desynced, resend + } else { //inv desynced, resend $this->sendInventory(); } } @@ -2170,7 +2418,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ 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; @@ -2188,7 +2436,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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 = []; @@ -2196,39 +2444,39 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->craftingType = CraftingRecipes::TYPE_INVENTORY; $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; @@ -2240,37 +2488,36 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->toCraft = []; $this->craftingType = CraftingRecipes::TYPE_INVENTORY; $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->craftingType = CraftingRecipes::TYPE_INVENTORY; - $this->checkSpawnPosition(); $this->teleport($this->spawnPosition, false, false, true, false); - + $pk = new MovePlayerPacket(); $pk->eid = $this->entity->eid; $pk->x = $this->entity->x; @@ -2279,18 +2526,18 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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(); @@ -2300,23 +2547,23 @@ public function handleDataPacket(RakNetDataPacket $packet){ 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 = []; $this->craftingType = CraftingRecipes::TYPE_INVENTORY; $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; @@ -2324,10 +2571,10 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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); } } @@ -2335,35 +2582,34 @@ public function handleDataPacket(RakNetDataPacket $packet){ } 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->addCraftingResult(-1, $prevItem->getID(), $prevItem->getMetadata(), $prevItem->count); break; - }else{ - inv_desync_on_drop: - ConsoleAPI::debug("Inventory desync on drop({$this->iusername})"); - $sendOnDrop = true; } + } else { + inv_desync_on_drop: + ConsoleAPI::debug("Inventory desync on drop({$this->iusername})"); + $sendOnDrop = true; } - + $this->craftingItems = []; $this->toCraft = []; $this->craftingType = CraftingRecipes::TYPE_INVENTORY; @@ -2371,7 +2617,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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; @@ -2384,17 +2630,17 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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 = []; @@ -2402,29 +2648,29 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->craftingType = CraftingRecipes::TYPE_INVENTORY; 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); } } @@ -2432,7 +2678,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ } break; case ProtocolInfo::CONTAINER_CLOSE_PACKET: - if($this->spawned === false){ + if ($this->spawned === false) { break; } $this->craftingItems = []; @@ -2449,7 +2695,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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; @@ -2466,7 +2712,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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; } @@ -2490,41 +2736,40 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->addCraftingIngridient($packet->slot, $slot->getID(), $slot->getMetadata(), $slot->count); $this->addCraftingResult($packet->slot, $citem->getID(), $citem->getMetadata(), $citem->count); } - }else{ $this->toCraft = []; $this->craftingItems = []; $this->craftingType = CraftingRecipes::TYPE_INVENTORY; } - 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; } $item = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); $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){ + if ($this->server->api->dhandle("player.container.slot", [ + "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; @@ -2532,37 +2777,36 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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){ + if ($this->server->api->dhandle("player.container.slot", [ + "tile" => $tile, + "slot" => $packet->slot, + "slotdata" => $slot, + "itemdata" => $item, + "player" => $this, + ]) === false) { $pk = new ContainerSetSlotPacket; $pk->windowid = $packet->windowid; $pk->slot = $packet->slot; @@ -2571,24 +2815,24 @@ public function handleDataPacket(RakNetDataPacket $packet){ 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); @@ -2598,28 +2842,28 @@ public function handleDataPacket(RakNetDataPacket $packet){ } 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 = []; $this->craftingType = CraftingRecipes::TYPE_INVENTORY; $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"]); } } @@ -2630,14 +2874,14 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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) { + if ($e === false) { ConsoleAPI::warn("Player is riding on entity that doesnt exist in world! ({$this->iusername}, {$this->entity->linkedEntity})"); $this->entity->stopRiding(); break; @@ -2655,23 +2899,23 @@ public function handleDataPacket(RakNetDataPacket $packet){ 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(){ return $this->getSlot($this->slot); } - + public function stopSleep(){ $this->isSleeping = false; $this->sleepingTime = 0; @@ -2857,7 +3101,7 @@ public function removeItem($type, $damage, $count, $send = true){ } return true; } - + public function handlePacket(RakNetPacket $packet){ if($this->connected === true){ $time = microtime(true); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 9086b01ea..5e3db1101 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -9,7 +9,7 @@ class PocketMinecraftServer{ */ public $api; private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0; - + public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread; public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true, $PACKET_READING_LIMIT = 100; @@ -24,10 +24,9 @@ function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $this->serverip = $serverip; $this->load(); } - + public static $SAVE_PLAYER_DATA = true; - - + private function load(){ global $dolog; /*if(defined("DEBUG") and DEBUG >= 0){ @@ -68,6 +67,7 @@ private function load(){ $this->saveEnabled = true; $this->tickMeasure = array_fill(0, 40, 0); $this->setType("normal"); + PacketPool::init(); $this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip); $this->stop = false; $this->ticks = 0; @@ -86,10 +86,10 @@ private function load(){ "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, @@ -230,7 +230,7 @@ public function close($reason = "server stop"){ } release_lock(); } - + 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"); @@ -244,7 +244,7 @@ public function send2Discord($msg){ ], null); } } - + public function asyncOperation($type, array $data, callable $callable = null){ if(defined("NO_THREADS")){ return false; @@ -348,7 +348,6 @@ public function asyncOperationChecker(){ /** * @param string $event - * @param callable $callable * @param integer $priority * * @return boolean @@ -433,7 +432,7 @@ public function init(){ 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 "?"'); @@ -453,7 +452,7 @@ public function schedule($ticks, callable $callback, $data = [], $repeat = false 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) . ");"); @@ -491,7 +490,7 @@ public function process() } } } - + $this->tick(); } }else{ @@ -524,12 +523,11 @@ public function process() $this->tick(); } } - - + } public function packetHandler(Packet $packet){ - $data =& $packet; + $data = &$packet; $CID = PocketMinecraftServer::clientID($packet->ip, $packet->port); if(isset($this->clients[$CID])){ $this->clients[$CID]->handlePacket($packet); @@ -617,14 +615,14 @@ public function tick(){ $this->tickMeasure[] = $this->lastTick = $time; unset($this->tickMeasure[key($this->tickMeasure)]); ++$this->ticks; - + foreach($this->clients as $client){ $client->handlePacketQueues(); if($this->ticks % 40 == 0){ //2s $client->sendPing(); } } - + foreach($this->api->level->levels as $l){ $l->onTick($this, $time); } diff --git a/src/astarnavigator/TileNavigator.php b/src/astarnavigator/TileNavigator.php index c29c4fecf..24769b51a 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 @@ public function reconstructPath($path, $current){ } 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 @@ public function isLocBlocked(PMFLevel $level, $loc){ $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 @@ public function navigate(Level $level, $fromX, $fromY, $fromZ, $toX, $toY, $toZ, if ($current == $to){ return $this->reconstructPath($path, $current); } - + $points = []; foreach(self::OFFSETS as $offset){ $newX = $offset[0] + $currentX; @@ -98,7 +98,7 @@ public function navigate(Level $level, $fromX, $fromY, $fromZ, $toX, $toY, $toZ, $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 @@ public function navigate(Level $level, $fromX, $fromY, $fromZ, $toX, $toY, $toZ, 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 @@ public function navigate(Level $level, $fromX, $fromY, $fromZ, $toX, $toY, $toZ, } 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 fcaaaea85..8352e4316 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 @@ ENTITY_FALLING => [ FALLING_SAND => true ] - + ]; diff --git a/src/dependencies.php b/src/dependencies.php index 5af85a1c4..54260b95e 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -103,7 +103,6 @@ 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_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 b21aab0d6..f9ccf9bed 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -1,17 +1,15 @@ setAge($data["Age"] ?? 0); @@ -20,11 +18,11 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ } $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 @@ public function handlePrePlayerSearcher(){ $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 @@ public function handlePlayerSearcher(Player $player, $dist){ } } } - + 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 @@ public function breed(){ } 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 @@ public function update($now){ 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 @@ public function spawnChild() "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 @@ public function interactWith(Entity $e, $action){ } 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 59cc21ec1..211c6c7ea 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 a8e97972d..be41e0e57 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 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ public function handlePrePlayerSearcher(){ $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 @@ public function handlePlayerSearcher(Player $player, $dist){ $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 @@ public function spawn($player){ $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 e4f5383c1..82678e6f5 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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []) $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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []) $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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []) $this->hasGravity = true; $this->canBeAttacked = true; $this->fireResistance = 20; - + break; case ENTITY_OBJECT: if($this->type == OBJECT_PAINTING) break; @@ -197,7 +197,7 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []) } } public function handlePrePlayerSearcher(){ - + } public function isType(){ return in_array($this->type, func_get_args()); @@ -210,12 +210,12 @@ public function isType(){ 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 @@ public function addVelocity($vX, $vY = 0, $vZ = 0) $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 @@ public function applyCollision(Entity $collided){ $sqrtMax = sqrt($maxDiff); $diffX /= $sqrtMax; $diffZ /= $sqrtMax; - + $col = (($v = 1 / $sqrtMax) > 1 ? 1 : $v); $diffX *= $col; $diffZ *= $col; @@ -250,7 +250,7 @@ public function applyCollision(Entity $collided){ } } } - + 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 @@ public function getDrops() 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 @@ private function spawnDrops() $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 @@ public function canSee(Entity $e){ 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 @@ public function handleWaterMovement(){ }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 @@ public function environmentUpdate($time) $this->air = $this->maxAir; return false; } - + $this->handleWaterMovement(); if($this->fire > 0){ //TODO move somewhere if(!$this->isImmuneToFire){ @@ -475,7 +475,7 @@ public function environmentUpdate($time) $this->fire -= 4; if($this->fire <= 0) $this->fire = 0; } - + if($this->fire <= 0){ $this->updateMetadata(); } else{ @@ -487,16 +487,16 @@ public function environmentUpdate($time) 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 @@ public function environmentUpdate($time) $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 @@ public function environmentUpdate($time) } 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 @@ public function doBlocksCollision(){ $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 @@ public function move($dx, $dy, $dz){ $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 @@ public function move($dx, $dy, $dz){ $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 @@ public function isFree($offsetX, $offsetY, $offsetZ){ 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 @@ public function update($now){ return false; } ++$this->counter; - + if($this->isStatic === false){ if(!$this->isPlayer()){ $this->updateLast(); @@ -761,18 +755,18 @@ public function update($now){ }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 @@ public function update($now){ $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 @@ public function update($now){ ++$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 @@ public function update($now){ $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 @@ public function update($now){ } } } - - + 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 @@ public function update($now){ $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 @@ public function fall(){ $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 @@ public function updateFallState($fallTick){ }elseif($fallTick < 0){ $this->fallDistance -= $fallTick; } - + } - + public function updateMovement() { if($this->closed === true){ @@ -966,7 +958,7 @@ public function updateMovement() } $this->lastUpdate = $now; } - + /** * Handle fall out of world */ @@ -978,11 +970,11 @@ public function outOfWorld(){ $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 @@ public function getMetadata() ], 1 => [ "type" => 1, - "value" => (int)$this->air + "value" => (int) $this->air ], 14 => [ "type" => 0, @@ -1099,7 +1091,7 @@ public function updateMetadata() 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 @@ public function spawn($player) $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 @@ public function counterUpdate(){ if($this->idleTime > 0){ --$this->idleTime; } - - + if($this->inAction){ ++$this->inActionCounter; } } - + public function close() { if($this->closed === false){ @@ -1224,7 +1215,7 @@ public function look($pos2) 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 @@ public function updatePosition() $this->sendMoveUpdate(); $this->updateAABB(); } - + public function setPosition(Vector3 $pos, $yaw = false, $pitch = false, $headYaw = false) { $this->x = $pos->x; @@ -1246,12 +1237,12 @@ public function setPosition(Vector3 $pos, $yaw = false, $pitch = false, $headYaw 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 @@ public function isSupport(Vector3 $pos, $radius = 1) { $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 @@ public function isSupport(Vector3 $pos, $radius = 1) 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 @@ public function createSaveData(){ "speedX" => $this->speedX, "speedY" => $this->speedY, "speedZ" => $this->speedZ, - + ]; if($this->class === ENTITY_OBJECT){ $data["TileX"] = $this->x; @@ -1349,12 +1340,12 @@ public function createSaveData(){ "Damage" => $this->meta, "Count" => $this->stack, ]; - + $data["id"] = 64; //ty shoghicp } return $data; } - + public function updateLast() { $this->lastX = $this->x; @@ -1387,30 +1378,30 @@ public function harm($dmg, $cause = "generic", $force = false) // $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 @@ public function heal($health, $cause = "generic") { 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 @@ public function stopRiding(){ $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 @@ public function setRiding(Entity $e, $type = 0) $this->isRider = true; $this->server->api->dhandle("entity.link", ["rider" => $this->eid, "riding" => $e->eid, "type" => 0]); } - - + } public function isPlayer() @@ -1539,7 +1529,7 @@ public function applyArmor($damage, $cause){ } return $damage; } - + public function setHealth($health, $cause = "generic", $force = false, $allowHarm = true) { $health = (int) $health; @@ -1556,14 +1546,14 @@ public function setHealth($health, $cause = "generic", $force = false, $allowHar }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 @@ public function setSize($w, $h) $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 @@ public function makeDead($cause){ } } } - + public function getAttackDamage(){ return 0; } - + public function setSpeed($s) { $this->speed = $s; @@ -1681,14 +1671,14 @@ public function __toString() { 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 @@ public static function getSizeOf($e) { 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 d00f9bfbc..90735cc5f 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 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = array $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 @@ public function close(){ 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 @@ public function collideHandler(){ } } } - + 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 @@ public function update($now){ } parent::update($now); } - + public $pathEIDS = []; private static $lastPathEID = 10000000; public static $pathfind = true; @@ -139,22 +138,21 @@ public function updateEntityMovement(){ } 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 @@ public function updateEntityMovement(){ } $this->pathFollower->followPath(); } - - + //not exactly here if($this->jumping){ if(!$this->inWater && !$this->inLava){ @@ -186,12 +183,11 @@ public function updateEntityMovement(){ }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 @@ public function updateEntityMovement(){ $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 @@ public function moveEntityWithHeading($strafe, $forward){ $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 @@ public function moveEntityWithHeading($strafe, $forward){ $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 be046207c..6e4468e2a 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 @@ public function handlePrePlayerSearcher(){ $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 @@ public function handlePlayerSearcher(Player $player, $dist){ } } } - + } diff --git a/src/entity/Projectile.php b/src/entity/Projectile.php index 3c37424bc..ed9df100b 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 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = []) $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 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = []) $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 @@ public function shoot($d, $d1, $d2, $f, $f1){ //unchecked, may be not same as ar $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 @@ public function update($now){ $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 @@ public function update($now){ $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 @@ public function update($now){ }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 @@ public function update($now){ $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 @@ public function spawn($player) $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 a8c9d883d..d7f1d8200 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 @@ public function removeTask($name){ } 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 @@ public function updateTasks(){ } } } - + public function __destruct(){ unset($this->entity); } - + } diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index 1e1eec00b..586d93fe1 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 @@ public function isDangerous($id){ 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 @@ public function setMovingTarget($x, $y, $z, $speed){ $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,44 +64,44 @@ public function setMovingOffset($x, $y, $z, $speed){ $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); @@ -119,11 +119,11 @@ public function movementTick(){ //} //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; @@ -135,7 +135,7 @@ public function updateHeadYaw(){ $this->headYaw = $this->entity->headYaw; }else{ ++$this->someTicker; - + if($this->someTicker > 10){ $v5 = max(1 - ($this->someTicker - 10) / 10, 0) * 75; } @@ -143,30 +143,30 @@ public function updateHeadYaw(){ $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); @@ -183,13 +183,13 @@ public function rotateTick(){ //TODO handle more rotation } } */ - + //$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; @@ -198,9 +198,9 @@ public function setLookPosition($posX, $posY, $posZ, $lookYaw, $lookPitch){ $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; @@ -209,38 +209,37 @@ public function faceEntity($x, $y, $z){ $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 c17cde93d..3066c4fe1 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 @@ public function followPath(){ //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 @@ public function followPath(){ $player->dataPacket($pk); } }*/ - + } } - + } diff --git a/src/entity/ai/tasks/TaskAttackPlayer.php b/src/entity/ai/tasks/TaskAttackPlayer.php index 8760cd111..213a0eb22 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 @@ public function onUpdate(EntityAI $ai) } $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 @@ public function onUpdate(EntityAI $ai) $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 @@ public function isTargetValid(EntityAI $ai){ $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 @@ public function tryTargeting(EntityAI $ai){ $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 14f776eb1..dd2eba250 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 5af5d21ea..4f69a7a89 100644 --- a/src/entity/ai/tasks/TaskEatTileGoal.php +++ b/src/entity/ai/tasks/TaskEatTileGoal.php @@ -10,7 +10,7 @@ public function onStart(EntityAI $ai) public function onEnd(EntityAI $ai) { - + } public function onUpdate(EntityAI $ai) @@ -18,7 +18,7 @@ public function onUpdate(EntityAI $ai) if($ai->isStarted("TaskPanic")){ $this->reset(); return false; - } + } if (--$this->selfCounter == 4) { @@ -27,7 +27,7 @@ public function onUpdate(EntityAI $ai) 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 99dcdbe68..9c5a989d3 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 @@ public function onUpdate(EntityAI $ai) $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 a931d98a6..6463503a7 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 @@ public function onEnd(EntityAI $ai) 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 174304a93..7fa7b8160 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 @@ public function onStart(EntityAI $ai){ $this->onEnd($ai); return; } - + $this->selfCounter = mt_rand(20, 60); } @@ -35,7 +35,7 @@ public function onUpdate(EntityAI $ai){ $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 5bfdd26ba..d073bd1a6 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 @@ public function onUpdate(EntityAI $ai) $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 @@ public function createBaby(EntityAI $ai, Entity $entpar2){ $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 @@ public function findMate(EntityAI $ai){ } 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 a010802d9..a906ec3fb 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 @@ public function onEnd(EntityAI $ai) $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 @@ public function canBeExecuted(EntityAI $ai) 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 4b68a746a..e81d22633 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 @@ public function onUpdate(EntityAI $ai) $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 @@ public function canBeExecuted(EntityAI $ai) 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 04d53630e..dfe2dee15 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 @@ public function onStart(EntityAI $ai) public function onEnd(EntityAI $ai) { $ai->entity->target = false; - + } public function onUpdate(EntityAI $ai) @@ -36,24 +36,23 @@ public function onUpdate(EntityAI $ai) }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 @@ public function rangedAttack($selfEntity, $target){ $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 @@ public function isTargetValid(EntityAI $ai){ $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 @@ public function tryTargeting(EntityAI $ai){ $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 61842afbd..ad9ecdc7a 100644 --- a/src/entity/ai/tasks/TaskSwimming.php +++ b/src/entity/ai/tasks/TaskSwimming.php @@ -9,7 +9,7 @@ public function onStart(EntityAI $ai) public function onEnd(EntityAI $ai) { - + } public function onUpdate(EntityAI $ai) @@ -18,12 +18,12 @@ public function onUpdate(EntityAI $ai) $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 eee2f39aa..5dd67c66f 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 @@ public function onUpdate(EntityAI $ai) $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 @@ public function isTargetValid(EntityAI $ai){ $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 @@ public function tryTargeting(EntityAI $ai){ $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 2b19cd1a7..8f66e5f88 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -10,7 +10,7 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ 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 441ff126e..86a5358a9 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -17,11 +17,11 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ public function interactWith(Entity $e, $action){ } 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 d8bfe2190..9b48b6f89 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 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ 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 @@ public function updateEntityMovement(){ $this->yaw = $e->headYaw; } }*/ - + parent::updateEntityMovement(); } - + public function interactWith(Entity $e, $action) { if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ @@ -59,7 +60,7 @@ public function interactWith(Entity $e, $action) $e->setRiding($this); return true; } - + if($slot->getID() === SADDLE){ if(!$this->isSaddled()){ $e->player->removeItem($slot->getID(), 0, 1); @@ -67,15 +68,15 @@ public function interactWith(Entity $e, $action) } 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 d79c87019..5cd80c1bd 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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ public function eatGrass(){ $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 @@ public function getDrops(){ [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 @@ public function interactWith(Entity $e, $action){ $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 @@ public function interactWith(Entity $e, $action){ 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 @@ public function interactWith(Entity $e, $action){ } return parent::interactWith($e, $action); } - + public function getMetadata(){ $d = parent::getMetadata(); if(!isset($this->data["Sheared"])){ @@ -107,7 +107,7 @@ public function getMetadata(){ $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 b1279f9c9..a8539b116 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 @@ public function interactWith(Entity $e, $action){ } 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 @@ public function explode() $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 812901ced..c508d1a86 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 @@ public function updateBurning(){ 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 1752638f8..081187fb7 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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ $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 bc38cf3ae..7cfb48851 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 @@ public function updateBurning(){ return false; } } - + public function getAttackDamage(){ return 4; } @@ -57,7 +58,7 @@ public function updateEntityMovement(){ $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 d671113e9..cac786cf7 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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ public function handleUpdate(){ $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 @@ public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA dec //$this->update(); $this->groundTicks = 0; } - + public function update($now){ $this->lastX = $this->x; $this->lastY = $this->y; @@ -101,40 +101,39 @@ public function update($now){ $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 @@ public function update($now){ $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 @@ public function update($now){ }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 @@ public function update($now){ $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 @@ public function update($now){ $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 @@ public function spawn($player){ $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 81b6fa9b3..8bb6c9365 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 @@ public function __construct($level, $eid, $class, $type = 0, $data = []){ $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; @@ -45,15 +45,15 @@ public function update($now){ ++$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(($blockAt = $this->level->level->getBlockID($x, $y, $z)) != 0){ //TODO vanilla-like checking? if(StaticBlock::getIsTransparent($blockAt) && !StaticBlock::getIsLiquid($blockAt)){ @@ -62,6 +62,7 @@ public function update($now){ return; } } + 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 9af57bee4..f290fe071 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 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = array $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 @@ public function spawn($player) $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 @@ public function spawn($player) $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 @@ public function checkInTile($x, $y, $z){ $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 @@ public function checkInTile($x, $y, $z){ $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 @@ public function checkInTile($x, $y, $z){ $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 @@ public function checkInTile($x, $y, $z){ $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 @@ public function updateEntityMovement(){ $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 f10ab47ea..5361e47ee 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 @@ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ public function moveAlongTrack($x, $y, $z, $maxSpeed, $boost, $id, $meta){ $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 @@ public function moveAlongTrack($x, $y, $z, $maxSpeed, $boost, $id, $meta){ $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 @@ public function moveAlongTrack($x, $y, $z, $maxSpeed, $boost, $id, $meta){ $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 @@ public function moveAlongTrack($x, $y, $z, $maxSpeed, $boost, $id, $meta){ $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 @@ public function update($now){ } $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 @@ public function update($now){ } $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 @@ public function update($now){ }else{ $e->applyCollision($this); } - + } } } } } } - + public function close() { parent::close(); @@ -421,11 +420,11 @@ public function close() } } } - + public function isPushable(){ return false; //TODO replace with true } - + public function spawn($player){ $pk = new AddEntityPacket; $pk->eid = $this->eid; @@ -436,7 +435,7 @@ public function spawn($player){ $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 @@ public function spawn($player){ $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 9b2aa8b53..c451075f9 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,17 +30,17 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ 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){ @@ -53,7 +53,7 @@ public function update($now){ $this->makeDead("nosurvive"); } } - + return true; } @@ -62,34 +62,34 @@ public function setRandomMotive($dir){ 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 @@ public function setDirection($dir){ $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 @@ public function setDirection($dir){ $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 @@ public function survives(){ }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 @@ public function survives(){ } 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 f88adb7e0..b6be4d6cb 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -14,11 +14,11 @@ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $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 @@ public function getMetadata(){ } 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 @@ public function update($now){ $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 661bbe0ff..98794845d 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 a6758cd38..811040614 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 6855cd3cc..f69339d87 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 565c65b27..b2a8641dc 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 d2cf972bd..999620be0 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 7751306ca..96f5b7d32 100644 --- a/src/event/EventHandler.php +++ b/src/event/EventHandler.php @@ -16,7 +16,7 @@ public static function callEvent(BaseEvent $event){ }else{ return BaseEvent::ALLOW; } - } + } } } diff --git a/src/event/EventPriority.php b/src/event/EventPriority.php index f42e8d732..6de6a27e1 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 3887bb0de..0796e7bbe 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 5e55a29b9..62f2e6a0f 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 cb26cbf05..60b8b3542 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 becb15e48..cea83d3d9 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 1838b9a3d..3a9375960 100644 --- a/src/functions.php +++ b/src/functions.php @@ -11,7 +11,6 @@ function cli_set_process_title($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 d732b689b..b2697189b 100644 --- a/src/installer/Installer.php +++ b/src/installer/Installer.php @@ -8,7 +8,7 @@ class Installer{ const DEFAULT_MEMORY = 128; const DEFAULT_PLAYERS = 20; const DEFAULT_GAMEMODE = SURVIVAL; - + private $lang, $config; public function __construct(){ echo "[*] NostalgiaCore set-up wizard\n"; @@ -34,12 +34,12 @@ public function __construct(){ $this->welcome(); $this->generateBaseConfig(); $this->generateUserFiles(); - + $this->networkFunctions(); - + $this->endWizard(); } - + private function welcome(){ echo $this->lang->welcome_to_pocketmine."\n"; echo <<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."): "; @@ -95,7 +95,7 @@ private function generateBaseConfig(){ } $config->save(); } - + private function generateUserFiles(){ echo "[*] ".$this->lang->op_info."\n"; echo "[?] ".$this->lang->op_who.": "; @@ -118,7 +118,7 @@ private function generateUserFiles(){ } $config->save(); } - + private function networkFunctions(){ $config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES); echo "[!] ".$this->lang->query_warning1."\n"; @@ -129,7 +129,7 @@ private function networkFunctions(){ }else{ $config->set("enable-query", true); } - + echo "[*] ".$this->lang->rcon_info."\n"; echo "[?] ".$this->lang->rcon_enable." (y/N): "; if(strtolower($this->getInput("n")) === "y"){ @@ -142,35 +142,33 @@ private function networkFunctions(){ } $config->save(); - - + 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->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"; 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 @@ class InstallerLang{ //"vi" => "Tiếng Việt", "ko" => "한국어", "fr" => "Français", - "it" => "Italiano", + "it" => "Italiano", //"lv" => "Latviešu", "nl" => "Nederlands", //"pt" => "Português", @@ -189,8 +187,8 @@ class InstallerLang{ "tr" => "Türkçe", "uk" => "Український" //"et" => "Eesti", - ); - private $texts = array(); + ]; + private $texts = []; private $lang; private $langfile; public function __construct($lang = ""){ @@ -200,7 +198,7 @@ public function __construct($lang = ""){ }else{ $l = glob(FILE_PATH."src/lang/Installer/".$lang."_*.ini"); if(count($l) > 0){ - $files = array(); + $files = []; foreach($l as $file){ $files[$file] = filesize($file); } @@ -215,32 +213,32 @@ public function __construct($lang = ""){ $this->langfile = FILE_PATH."src/lang/Installer/en.ini"; } } - + $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 @@ public function get($name, $search = array(), $replace = array()){ 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 459c1e919..f723cb601 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", - - 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", - - 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", - - FENCE => "FenceBlock", - PUMPKIN => "PumpkinBlock", - NETHERRACK => "NetherrackBlock", - SOUL_SAND => "SoulSandBlock", - GLOWSTONE_BLOCK => "GlowstoneBlock", - - LIT_PUMPKIN => "LitPumpkinBlock", - INVISIBLE_BEDROCK => "InvisibleBedrockBlock", - - CAKE_BLOCK => "CakeBlock", - - TRAPDOOR => "TrapdoorBlock", - - STONE_BRICKS => "StoneBricksBlock", - - IRON_BARS => "IronBarsBlock", - GLASS_PANE => "GlassPaneBlock", - MELON_BLOCK => "MelonBlock", - PUMPKIN_STEM => "PumpkinStemBlock", - MELON_STEM => "MelonStemBlock", - - FENCE_GATE => "FenceGateBlock", - BRICK_STAIRS => "BrickStairsBlock", - STONE_BRICK_STAIRS => "StoneBrickStairsBlock", - - NETHER_BRICKS => "NetherBricksBlock", - - 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 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", + + 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", + + 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", + + LIT_PUMPKIN => "LitPumpkinBlock", + INVISIBLE_BEDROCK => "InvisibleBedrockBlock", + + CAKE_BLOCK => "CakeBlock", + + TRAPDOOR => "TrapdoorBlock", + + STONE_BRICKS => "StoneBricksBlock", + + IRON_BARS => "IronBarsBlock", + GLASS_PANE => "GlassPaneBlock", + MELON_BLOCK => "MelonBlock", + PUMPKIN_STEM => "PumpkinStemBlock", + MELON_STEM => "MelonStemBlock", + + FENCE_GATE => "FenceGateBlock", + BRICK_STAIRS => "BrickStairsBlock", + STONE_BRICK_STAIRS => "StoneBrickStairsBlock", + + NETHER_BRICKS => "NetherBricksBlock", + + 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 @@ public static function clip(Level $level, $x, $y, $z, Vector3 $start, Vector3 $e 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 @@ public static function clip(Level $level, $x, $y, $z, Vector3 $start, Vector3 $e 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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit 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 @@ public function __construct($id, $meta = 0, $name = "Unknown"){ $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 @@ public function setMetadata($i){ 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 @@ final public function position(Position $v){ $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 @@ public function getSide($side, $step = 1){ } return $v; } - + final public function __toString(){ 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 b7997318e..22e1b392f 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 @@ public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){ $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 @@ public function getBlock(){ 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 @@ public function getFuelTime(){ } 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 @@ public function useOn($object, $force = false){ } 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 @@ public function getMaxDurability(){ } 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 @@ public function getPickaxeLevel(){ //Returns false or level of the pickaxe default => false, }; } - + public function isAxe(){ return false; } @@ -280,11 +280,11 @@ public function isAxe(){ public function isSword(){ return false; } - + public function isShovel(){ return false; } - + public function isHoe(){ return false; } @@ -292,23 +292,23 @@ public function isHoe(){ public function isShears(){ return ($this->id === SHEARS); } - + public function __toString(){ 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 @@ public static function getFoodHeal($id){ POTATO => 1, BAKED_POTATO => 6, BEETROOT => 1, - + default => 0 }; } - + } diff --git a/src/material/Material.php b/src/material/Material.php index 674ce90b6..0608a4720 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 @@ public static function init(){ 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 @@ public static function init(){ 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 @@ public static function init(){ 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 @@ public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){ $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 abfe20a69..fdfdb0c68 100644 --- a/src/material/block/DoorBlock.php +++ b/src/material/block/DoorBlock.php @@ -86,14 +86,13 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit } 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 @@ public static function getCompositeData(Level $level, $x, $y, $z){ $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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, } } - /** - * @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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ $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 @@ public function onBreak(Item $item, Player $player){ } /** - * @param Item $item - * @param Player $player * * @return boolean */ diff --git a/src/material/block/FallableBlock.php b/src/material/block/FallableBlock.php index ca8113db6..32a0051f5 100644 --- a/src/material/block/FallableBlock.php +++ b/src/material/block/FallableBlock.php @@ -12,10 +12,6 @@ public function __construct($id, $meta = 0, $name = "Unknown"){ } /** - * @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 f7a128cb5..a2b23d1b0 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, "z" => $z + 0.5, "Tile" => $id, - ); + ]; $server = ServerAPI::request(); $e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data); $server->api->entity->spawnToAll($e); } } - + /** - * @param integer $type * * @return boolean */ @@ -85,8 +75,6 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, } /** - * @param Item $item - * @param Player $player * * @return boolean */ diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index feafe045c..993675800 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -21,14 +21,14 @@ public static function getDepth(Level $level, $x, $y, $z){ 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 @@ public static function getPercentAir($meta){ $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 @@ public static function getRenderedDepth(Level $level, $x, $y, $z){ 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 @@ public static function getFlow(Level $level, $x, $y, $z){ ++$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 @@ public static function getFlow(Level $level, $x, $y, $z){ $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 @@ public static function getFlow(Level $level, $x, $y, $z){ }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 @@ public static function updateLiquid(Level $level, $x, $y, $z){ }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 9fddfceec..8ca26113c 100644 --- a/src/material/block/SolidBlock.php +++ b/src/material/block/SolidBlock.php @@ -11,7 +11,7 @@ public function __construct($id, $meta = 0, $name = "Unknown"){ $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 9af56b506..f5a693736 100644 --- a/src/material/block/StairBlock.php +++ b/src/material/block/StairBlock.php @@ -15,26 +15,26 @@ public function __construct($id, $meta = 0, $name = "Unknown"){ } $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 @@ public static function setBaseShape(Level $level, $x, $y, $z){ [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 @@ public static function setStepShape(Level $level, $x, $y, $z){ $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 @@ public static function setStepShape(Level $level, $x, $y, $z){ $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 @@ public static function setStepShape(Level $level, $x, $y, $z){ $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 @@ public static function setStepShape(Level $level, $x, $y, $z){ $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 @@ public static function setStepShape(Level $level, $x, $y, $z){ $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 @@ public static function setStepShape(Level $level, $x, $y, $z){ 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 @@ public static function setInnerPieceShape(Level $level, $x, $y, $z){ 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 @@ public static function setInnerPieceShape(Level $level, $x, $y, $z){ $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 @@ public static function setInnerPieceShape(Level $level, $x, $y, $z){ $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 @@ public static function setInnerPieceShape(Level $level, $x, $y, $z){ } 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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit $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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit * @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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } /** - * @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 16b8ffc3a..678dbb1fc 100644 --- a/src/material/block/TransparentBlock.php +++ b/src/material/block/TransparentBlock.php @@ -13,11 +13,11 @@ public function __construct($id, $meta = 0, $name = "Unknown"){ $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 82ef14b35..571d18d4d 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 @@ public static function getAABB(Level $level, $x, $y, $z){ 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, } 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 a635eccc8..ea7e15b29 100644 --- a/src/material/block/attachable/SignPostBlock.php +++ b/src/material/block/attachable/SignPostBlock.php @@ -17,7 +17,7 @@ public function __construct($meta = 0){ $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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $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 761ba9d7a..69c0f5bed 100644 --- a/src/material/block/attachable/TorchBlock.php +++ b/src/material/block/attachable/TorchBlock.php @@ -6,15 +6,15 @@ public function __construct($meta = 0){ 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ 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 6e932bde0..48d2de84c 100644 --- a/src/material/block/attachable/TrapdoorBlock.php +++ b/src/material/block/attachable/TrapdoorBlock.php @@ -17,25 +17,25 @@ public function canAttachTo(Block $target){ $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 @@ public static function updateShape(Level $level, $x, $y, $z){ } } } - + 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, 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 02ca1aa5b..1a61c615b 100644 --- a/src/material/block/attachable/WallSignBlock.php +++ b/src/material/block/attachable/WallSignBlock.php @@ -10,7 +10,7 @@ public function __construct($meta = 0){ 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, 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 9329d736f..ed80bbf14 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 c4028f300..5d35973b8 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 @@ public static function getSpread(Level $level, $x, $y, $z){ ++$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 @@ public static function getSpread(Level $level, $x, $y, $z){ 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 @@ public static function getSlopeDistance(Level $level, $x, $y, $z, $l, $i1){ ++$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 @@ public static function getSlopeDistance(Level $level, $x, $y, $z, $l, $i1){ ){ 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 @@ public static function trySpreadTo(Level $level, $x, $y, $z, $meta){ } } } - + $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 @@ public static function onUpdate(Level $level, $x, $y, $z, $type){ 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 @@ public static function onUpdate(Level $level, $x, $y, $z, $type){ 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 552c08ebb..12265b5d0 100644 --- a/src/material/block/liquid/LiquidBlockStatic.php +++ b/src/material/block/liquid/LiquidBlockStatic.php @@ -6,13 +6,13 @@ public function __construct($id, $meta = 0, $name = "Unknown"){ } 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, 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 2a8e89cf6..2ca2daa29 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 632177a31..9e79836b9 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 c9e5c3e9c..3356ca723 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 9d6545b92..defdaf3fe 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 @@ public function __construct(){ $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 dcfb37299..db72ca0cb 100644 --- a/src/material/block/misc/BedBlock.php +++ b/src/material/block/misc/BedBlock.php @@ -20,37 +20,37 @@ public function __construct($type = 0){ $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 @@ public static function findStandUpPosition(Level $level, $x, $y, $z){ $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 @@ public static function findStandUpPosition(Level $level, $x, $y, $z){ } } } - + 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 @@ public function onActivate(Item $item, Player $player){ $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 @@ public function onActivate(Item $item, Player $player){ } 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } } 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 @@ public function onBreak(Item $item, Player $player){ $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 8e3b93652..778f1f295 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 @@ public static function setFlammabilityAndCatchingChance($blockID, $flammability, 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 @@ public static function onUpdate(Level $level, $x, $y, $z, $type){ } } $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 8c1ff0d0b..52d795895 100644 --- a/src/material/block/misc/NetherReactorBlock.php +++ b/src/material/block/misc/NetherReactorBlock.php @@ -7,7 +7,7 @@ public function __construct($meta = 0){ 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 @@ public function onActivate(Item $item, Player $player){ $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 @@ public function spawnItems($data) { $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 @@ public function glow($part){ $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 @@ private function isCorrect($x, $y, $z){ } 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 aeef0412d..800180571 100644 --- a/src/material/block/misc/TNTBlock.php +++ b/src/material/block/misc/TNTBlock.php @@ -7,19 +7,19 @@ public function __construct(){ $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 f7eded78e..fc9740e97 100644 --- a/src/material/block/nonfull/CakeBlock.php +++ b/src/material/block/nonfull/CakeBlock.php @@ -9,18 +9,18 @@ public function __construct($meta = 0){ $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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 @@ public function onActivate(Item $item, Player $player){ } 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 60b93a987..bfe18df4a 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 @@ public function __construct($meta = 0){ 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 344daff4f..b3a3422d3 100644 --- a/src/material/block/nonfull/ChestBlock.php +++ b/src/material/block/nonfull/ChestBlock.php @@ -11,19 +11,19 @@ public function __construct($meta = 0){ 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } $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 @@ public function onBreak(Item $item, Player $player){ $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 4b6a9226e..558dbd696 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 @@ public function getDrops(Item $item, Player $player){ } 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 dcf05a394..6f30afea8 100644 --- a/src/material/block/nonfull/FarmlandBlock.php +++ b/src/material/block/nonfull/FarmlandBlock.php @@ -7,27 +7,27 @@ public function __construct($meta = 0){ $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){ for($xx = $x-4; $xx <= $x+4; ++$xx){ for($yy = $y; $yy <= $y+1; ++$yy){ @@ -69,7 +69,7 @@ public static function checkWaterStatic(Level $level, $x, $y, $z) } } } - + 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 98442208b..47b17932d 100644 --- a/src/material/block/nonfull/FenceBlock.php +++ b/src/material/block/nonfull/FenceBlock.php @@ -7,16 +7,16 @@ public function __construct(){ $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 @@ public static function getAABB(Level $level, $x, $y, $z){ 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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit $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 be286bf95..0de9a3549 100644 --- a/src/material/block/nonfull/FenceGateBlock.php +++ b/src/material/block/nonfull/FenceGateBlock.php @@ -7,21 +7,21 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit 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 @@ public function __construct($meta = 0){ $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 @@ public function onActivate(Item $item, Player $player){ } $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 0af71ac48..959cdd225 100644 --- a/src/material/block/nonfull/GlassPaneBlock.php +++ b/src/material/block/nonfull/GlassPaneBlock.php @@ -9,33 +9,33 @@ public function __construct(){ } 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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit }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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit } 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 feeca1cc0..3666bc6f3 100644 --- a/src/material/block/nonfull/IronBarsBlock.php +++ b/src/material/block/nonfull/IronBarsBlock.php @@ -7,39 +7,39 @@ public function __construct(){ $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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit }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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit } 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 5ac59aae2..fd3b24f3a 100644 --- a/src/material/block/nonfull/IronDoorBlock.php +++ b/src/material/block/nonfull/IronDoorBlock.php @@ -21,14 +21,14 @@ public function getBreakTime(Item $item, Player $player){ 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 0fd8a32af..0de0c7cdc 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 f74a085ca..c68865968 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $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 9d63e231d..b129d8af0 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 3319bb7b6..9a6cec6d5 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 @@ public static function updateShape(Level $level, $x, $y, $z){ 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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit ) ]; } - + 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 @@ public function getBreakTime(Item $item, Player $player){ 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 3e9961a3b..168070943 100644 --- a/src/material/block/nonfull/SnowLayerBlock.php +++ b/src/material/block/nonfull/SnowLayerBlock.php @@ -20,20 +20,20 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 730bc4809..16f41faa4 100644 --- a/src/material/block/nonfull/StoneWallBlock.php +++ b/src/material/block/nonfull/StoneWallBlock.php @@ -15,45 +15,45 @@ public function getDrops(Item $item, Player $player){ } 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 @@ public static function updateShape(Level $level, $x, $y, $z){ $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 7109a6b6c..43c5827f4 100644 --- a/src/material/block/nonfull/WoodDoorBlock.php +++ b/src/material/block/nonfull/WoodDoorBlock.php @@ -7,10 +7,10 @@ public function __construct($meta = 0){ $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 d39f0931b..e2f6c84e6 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 @@ public static function updateShape(Level $level, $x, $y, $z){ 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 @@ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entit ) ]; } - + 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 @@ public function getBreakTime(Item $item, Player $player){ 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 619208b72..5cebc8dd4 100644 --- a/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php @@ -7,8 +7,8 @@ public function __construct($meta = 0){ } 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 133a5f0bf..52ee5a7f3 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 54d1710af..dbe84da31 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 76c4bc684..c466fda26 100644 --- a/src/material/block/nonfull/stairs/JungleWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/JungleWoodStairsBlock.php @@ -7,8 +7,8 @@ public function __construct($meta = 0){ } 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 0b984590e..d798d1e56 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 062b60d01..b9f7ac8df 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 8512e6285..89e44b6db 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 f001a8883..8468e0e2e 100644 --- a/src/material/block/nonfull/stairs/SpruceWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/SpruceWoodStairsBlock.php @@ -7,8 +7,8 @@ public function __construct($meta = 0){ } 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 b43efbb77..0a13b42b4 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 0421dac4f..d3cc9e109 100644 --- a/src/material/block/nonfull/stairs/WoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/WoodStairsBlock.php @@ -21,8 +21,8 @@ public function getBreakTime(Item $item, Player $player){ } 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 12e5c262c..8bc6ce596 100644 --- a/src/material/block/ore/CoalOreBlock.php +++ b/src/material/block/ore/CoalOreBlock.php @@ -6,7 +6,7 @@ public function __construct(){ 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 @@ public function getBreakTime(Item $item, Player $player){ 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 dec08e785..8b4fc682b 100644 --- a/src/material/block/ore/DiamondOreBlock.php +++ b/src/material/block/ore/DiamondOreBlock.php @@ -6,7 +6,7 @@ public function __construct(){ 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 @@ public function getBreakTime(Item $item, Player $player){ 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 33dd8e0c6..ed9ad90e2 100644 --- a/src/material/block/ore/GlowingRedstoneOreBlock.php +++ b/src/material/block/ore/GlowingRedstoneOreBlock.php @@ -6,11 +6,11 @@ public function __construct(){ 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 @@ public function getBreakTime(Item $item, Player $player){ 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 c835dbc19..2de507f6f 100644 --- a/src/material/block/ore/GoldOreBlock.php +++ b/src/material/block/ore/GoldOreBlock.php @@ -17,14 +17,14 @@ public function getBreakTime(Item $item, Player $player){ 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 d8d001ff1..abb023def 100644 --- a/src/material/block/ore/IronOreBlock.php +++ b/src/material/block/ore/IronOreBlock.php @@ -18,14 +18,14 @@ public function getBreakTime(Item $item, Player $player){ 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 ecb3e83f9..5130db867 100644 --- a/src/material/block/ore/LapisOreBlock.php +++ b/src/material/block/ore/LapisOreBlock.php @@ -6,7 +6,7 @@ public function __construct(){ 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 @@ public function getBreakTime(Item $item, Player $player){ 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 471f87ae6..dfe5c77ec 100644 --- a/src/material/block/ore/RedstoneOreBlock.php +++ b/src/material/block/ore/RedstoneOreBlock.php @@ -6,18 +6,18 @@ public function __construct(){ 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 c1b51d73b..423ed15f3 100644 --- a/src/material/block/plant/BeetrootBlock.php +++ b/src/material/block/plant/BeetrootBlock.php @@ -46,7 +46,7 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $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 495d8a731..aae803a7a 100644 --- a/src/material/block/plant/BrownMushroomBlock.php +++ b/src/material/block/plant/BrownMushroomBlock.php @@ -9,11 +9,11 @@ public function __construct(){ 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ 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 4dd97196d..debb3dc25 100644 --- a/src/material/block/plant/CactusBlock.php +++ b/src/material/block/plant/CactusBlock.php @@ -7,14 +7,14 @@ public function __construct($meta = 0){ $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 @@ public static function onRandomTick(Level $level, $x, $y, $z){ 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 498399f4a..b7fe8619a 100644 --- a/src/material/block/plant/CarrotBlock.php +++ b/src/material/block/plant/CarrotBlock.php @@ -17,7 +17,7 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $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 8486ede63..60de96399 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -7,7 +7,7 @@ public function __construct(){ $this->isActivable = true; $this->hardness = 0; } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } @@ -21,17 +21,14 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ 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 57f5ef648..69f39eefe 100644 --- a/src/material/block/plant/DandelionBlock.php +++ b/src/material/block/plant/DandelionBlock.php @@ -22,7 +22,7 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ 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 4f7d49b7c..b3be7cdce 100644 --- a/src/material/block/plant/DeadBushBlock.php +++ b/src/material/block/plant/DeadBushBlock.php @@ -7,33 +7,33 @@ public function __construct(){ //$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 a9e3c5424..4dee856fe 100644 --- a/src/material/block/plant/MelonStemBlock.php +++ b/src/material/block/plant/MelonStemBlock.php @@ -24,7 +24,7 @@ public static function onRandomTick(Level $level, $x, $y, $z){ //$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 @@ public static function onRandomTick(Level $level, $x, $y, $z){ } 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 @@ public function onActivate(Item $item, Player $player){ } 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 3ab969fe5..62d44ac6a 100644 --- a/src/material/block/plant/PotatoBlock.php +++ b/src/material/block/plant/PotatoBlock.php @@ -48,7 +48,7 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $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 c74926230..00eed1cb4 100644 --- a/src/material/block/plant/PumpkinStemBlock.php +++ b/src/material/block/plant/PumpkinStemBlock.php @@ -24,7 +24,7 @@ public static function onRandomTick(Level $level, $x, $y, $z){ //$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 @@ public static function onRandomTick(Level $level, $x, $y, $z){ } 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 @@ public function onActivate(Item $item, Player $player){ } 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 29bdc2250..3ba418b53 100644 --- a/src/material/block/plant/RedMushroomBlock.php +++ b/src/material/block/plant/RedMushroomBlock.php @@ -9,7 +9,7 @@ public function __construct(){ 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ 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 a6acde153..fd8308449 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $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 @@ public static function onRandomTick(Level $level, $x, $y, $z){ } } 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 d49284602..660f1393b 100644 --- a/src/material/block/plant/SugarcaneBlock.php +++ b/src/material/block/plant/SugarcaneBlock.php @@ -7,7 +7,7 @@ public function __construct($meta = 0){ $this->isActivable = true; $this->hardness = 0; } - + public function getDrops(Item $item, Player $player){ return [ [SUGARCANE, 0, 1], @@ -28,7 +28,7 @@ public function onActivate(Item $item, Player $player){ $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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, } } 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ $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 df8ce39fd..94ec709de 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 @@ public function __construct($meta = 1){ 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 53bf67f42..36f8d2474 100644 --- a/src/material/block/plant/WheatBlock.php +++ b/src/material/block/plant/WheatBlock.php @@ -17,7 +17,7 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } } - + public function getDrops(Item $item, Player $player){ $drops = []; if($this->meta >= 0x07){ @@ -59,7 +59,7 @@ public function getDrops(Item $item, Player $player){ $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 8974deaef..d214a6d80 100644 --- a/src/material/block/solid/BedrockBlock.php +++ b/src/material/block/solid/BedrockBlock.php @@ -7,12 +7,12 @@ public function __construct(){ $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 8f19b6fe9..4e501fe00 100644 --- a/src/material/block/solid/BookshelfBlock.php +++ b/src/material/block/solid/BookshelfBlock.php @@ -6,5 +6,5 @@ public function __construct(){ 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 97f448b2b..653d398e5 100644 --- a/src/material/block/solid/BricksBlock.php +++ b/src/material/block/solid/BricksBlock.php @@ -20,14 +20,14 @@ public function getBreakTime(Item $item, Player $player){ 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 0adb007c8..1cfc3039d 100644 --- a/src/material/block/solid/BurningFurnaceBlock.php +++ b/src/material/block/solid/BurningFurnaceBlock.php @@ -9,12 +9,12 @@ public function __construct($meta = 0){ } 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 @@ public function onActivate(Item $item, Player $player){ 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 @@ public function getBreakTime(Item $item, Player $player){ 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 3ca8b2a42..7ce626de6 100644 --- a/src/material/block/solid/ClayBlock.php +++ b/src/material/block/solid/ClayBlock.php @@ -8,8 +8,8 @@ public function __construct(){ } 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 cf7a252e0..0995aa262 100644 --- a/src/material/block/solid/CoalBlock.php +++ b/src/material/block/solid/CoalBlock.php @@ -20,14 +20,14 @@ public function getBreakTime(Item $item, Player $player){ 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 895953d17..0990c10d4 100644 --- a/src/material/block/solid/CobblestoneBlock.php +++ b/src/material/block/solid/CobblestoneBlock.php @@ -20,14 +20,14 @@ public function getBreakTime(Item $item, Player $player){ 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 2ffeed396..7f073778b 100644 --- a/src/material/block/solid/DiamondBlock.php +++ b/src/material/block/solid/DiamondBlock.php @@ -6,7 +6,7 @@ public function __construct(){ 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 @@ public function getBreakTime(Item $item, Player $player){ 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 bf96b7c27..64b43604b 100644 --- a/src/material/block/solid/DirtBlock.php +++ b/src/material/block/solid/DirtBlock.php @@ -32,33 +32,33 @@ public static function onRandomTick(Level $level, $x, $y, $z){ } 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 4b6f28db9..8211f7963 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 @@ public function __construct($meta = 0){ 5 => "Stone Brick", 6 => "Quartz", 7 => "Smooth Stone", - ); + ]; $this->name = "Double " . $names[$this->meta & 0x07] . " Slab"; $this->hardness = 30; } @@ -31,15 +31,15 @@ public function getBreakTime(Item $item, Player $player){ 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 7ff69ef13..61b4648f3 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 @@ public function getBreakTime(Item $item, Player $player){ 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 06f2db28e..bbe31df52 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 a6149c59f..6b133b3e0 100644 --- a/src/material/block/solid/GlassBlock.php +++ b/src/material/block/solid/GlassBlock.php @@ -6,11 +6,11 @@ public function __construct(){ 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 ea88b7793..474118228 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 177cbb3f6..531ed7331 100644 --- a/src/material/block/solid/GlowstoneBlock.php +++ b/src/material/block/solid/GlowstoneBlock.php @@ -6,17 +6,17 @@ public function __construct(){ 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 800061709..460c2b021 100644 --- a/src/material/block/solid/GoldBlock.php +++ b/src/material/block/solid/GoldBlock.php @@ -17,14 +17,14 @@ public function getBreakTime(Item $item, Player $player){ 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 9b689ff69..47ae9f0dc 100644 --- a/src/material/block/solid/GrassBlock.php +++ b/src/material/block/solid/GrassBlock.php @@ -9,9 +9,9 @@ public function __construct(){ } 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 @@ public function onActivate(Item $item, Player $player){ } 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 @@ public static function onRandomTick(Level $level, $x, $y, $z){ $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 f35adb53d..144792f3e 100644 --- a/src/material/block/solid/GravelBlock.php +++ b/src/material/block/solid/GravelBlock.php @@ -6,11 +6,11 @@ public function __construct(){ 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 869eebe59..dd6d52a8d 100644 --- a/src/material/block/solid/HayBaleBlock.php +++ b/src/material/block/solid/HayBaleBlock.php @@ -6,16 +6,16 @@ public function __construct($meta = 0){ 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 e5e7860dd..28701ad69 100644 --- a/src/material/block/solid/IceBlock.php +++ b/src/material/block/solid/IceBlock.php @@ -7,17 +7,17 @@ public function __construct(){ $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 @@ public function onBreak(Item $item, Player $player){ } 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 @@ public function getBreakTime(Item $item, Player $player){ } 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 0497b8610..1d9a45ea8 100755 --- a/src/material/block/solid/InfoUpdate2Block.php +++ b/src/material/block/solid/InfoUpdate2Block.php @@ -7,5 +7,5 @@ public function __construct(){ $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 8b0881900..81af72766 100755 --- a/src/material/block/solid/InfoUpdateBlock.php +++ b/src/material/block/solid/InfoUpdateBlock.php @@ -7,5 +7,5 @@ public function __construct(){ $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 dede980e8..2fd0843da 100755 --- a/src/material/block/solid/InvisibleBedrockBlock.php +++ b/src/material/block/solid/InvisibleBedrockBlock.php @@ -7,12 +7,12 @@ public function __construct(){ $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 504b94a18..5db4b364f 100644 --- a/src/material/block/solid/IronBlock.php +++ b/src/material/block/solid/IronBlock.php @@ -18,14 +18,14 @@ public function getBreakTime(Item $item, Player $player){ 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 1d4c4dc68..7d0e790c0 100644 --- a/src/material/block/solid/LapisBlock.php +++ b/src/material/block/solid/LapisBlock.php @@ -18,14 +18,14 @@ public function getBreakTime(Item $item, Player $player){ 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 353913004..2862884c7 100644 --- a/src/material/block/solid/LeavesBlock.php +++ b/src/material/block/solid/LeavesBlock.php @@ -7,20 +7,20 @@ 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; } @@ -50,7 +50,7 @@ public static function onRandomTick(Level $level, $x, $y, $z){ $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 @@ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $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 6775794a4..2edd0c116 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 @@ public function place(Item $item, Player $player, Block $block, Block $target, $ } 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 4b46e3930..3eaa724eb 100644 --- a/src/material/block/solid/MelonBlock.php +++ b/src/material/block/solid/MelonBlock.php @@ -7,11 +7,11 @@ public function __construct(){ $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 495de40d7..c738c615e 100644 --- a/src/material/block/solid/MossStoneBlock.php +++ b/src/material/block/solid/MossStoneBlock.php @@ -20,14 +20,14 @@ public function getBreakTime(Item $item, Player $player){ 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 bf1c79477..8211ad7b2 100644 --- a/src/material/block/solid/NetherBricksBlock.php +++ b/src/material/block/solid/NetherBricksBlock.php @@ -20,14 +20,14 @@ public function getBreakTime(Item $item, Player $player){ 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 4700a083f..f93af9924 100644 --- a/src/material/block/solid/NetherrackBlock.php +++ b/src/material/block/solid/NetherrackBlock.php @@ -6,7 +6,7 @@ public function __construct(){ 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 @@ public function getBreakTime(Item $item, Player $player){ 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 dc0ff7335..71453cc2d 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 @@ public function getBreakTime(Item $item, Player $player){ 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 ed0ba0419..2380c10fb 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 25239421b..cfba83d30 100644 --- a/src/material/block/solid/PumpkinBlock.php +++ b/src/material/block/solid/PumpkinBlock.php @@ -6,17 +6,17 @@ public function __construct($meta = 0){ 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 1c7bcfb74..7eeb9fb15 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 @@ public function getBreakTime(Item $item, Player $player){ 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 1a9d6bd62..65117a4e6 100644 --- a/src/material/block/solid/Reserved6Block.php +++ b/src/material/block/solid/Reserved6Block.php @@ -7,5 +7,5 @@ public function __construct(){ $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 fa41be00b..67f920296 100644 --- a/src/material/block/solid/SandBlock.php +++ b/src/material/block/solid/SandBlock.php @@ -6,5 +6,5 @@ public function __construct(){ 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 c65339982..790ebe24c 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 @@ public function getBreakTime(Item $item, Player $player){ 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 2e024c8f1..8fdea37a4 100644 --- a/src/material/block/solid/SnowBlock.php +++ b/src/material/block/solid/SnowBlock.php @@ -15,5 +15,5 @@ public function getDrops(Item $item, Player $player){ } return []; } - + } \ No newline at end of file diff --git a/src/material/block/solid/SoulSandBlock.php b/src/material/block/solid/SoulSandBlock.php index f5ff6e207..cb4d30aa4 100644 --- a/src/material/block/solid/SoulSandBlock.php +++ b/src/material/block/solid/SoulSandBlock.php @@ -6,5 +6,5 @@ public function __construct(){ 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 39b4c2379..25a7c0601 100644 --- a/src/material/block/solid/SpongeBlock.php +++ b/src/material/block/solid/SpongeBlock.php @@ -6,5 +6,5 @@ public function __construct(){ 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 51504b66e..3f56c022e 100644 --- a/src/material/block/solid/StoneBlock.php +++ b/src/material/block/solid/StoneBlock.php @@ -20,15 +20,15 @@ public function getBreakTime(Item $item, Player $player){ 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 58299703c..741ac21f9 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 @@ public function getBreakTime(Item $item, Player $player){ 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 110747d16..2f145ac89 100644 --- a/src/material/block/solid/StonecutterBlock.php +++ b/src/material/block/solid/StonecutterBlock.php @@ -6,7 +6,7 @@ public function __construct($meta = 0){ parent::__construct(STONECUTTER, $meta, "Stonecutter"); $this->isActivable = true; } - + public function onActivate(Item $item, Player $player){ $player->craftingType = CraftingRecipes::TYPE_STONECUTTER; return true; @@ -20,6 +20,6 @@ public function getDrops(Item $item, Player $player){ }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 e97111416..369b74830 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 @@ public function onBreak(Item $item, Player $player){ } } 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 3bfb0de84..c4a370e18 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 @@ public function __construct($meta = 0){ 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 080ac13c9..171f5e2a6 100644 --- a/src/material/block/solid/WorkbenchBlock.php +++ b/src/material/block/solid/WorkbenchBlock.php @@ -7,15 +7,15 @@ public function __construct($meta = 0){ $this->isActivable = true; $this->hardness = 15; } - + public function onActivate(Item $item, Player $player){ $player->craftingType = CraftingRecipes::TYPE_CRAFTIGTABLE; 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 ebb5536d3..a90789488 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 730832382..afd02dcde 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 @@ public function getDamageReduceAmount() 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 ae28d0c51..19a6d9bdc 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 df7c83d9a..b78cb920c 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 9d1800b16..de13dc830 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 4591f9d84..75d8c1298 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 fad4edcef..3a6b8a053 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 b0e53cbc6..514986f0a 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 ef2e005d5..55eb9356f 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 1ac0f9a4d..8f9b75810 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 739617b60..05b3aed0e 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 c7ee47116..11a942561 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 ee9dd964e..d2fb35a0b 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 7f548bb90..6ed188940 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 05ca1086c..d7229d4b4 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 70c85f5ed..78300ed48 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 f646899d8..a7734651a 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 6ec78a246..8bbf9ed55 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 9a1468395..2950c741f 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 4fc3bc741..a1ad3b88e 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 ceaa939ae..2be715774 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 5efc1d5bd..d911950f1 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 277b75fb5..09675cca1 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 91666c54e..87ed20258 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 e5a3af257..8875cca6d 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 6e5fe0fa2..9c12d6030 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 9aaa46a1d..5ca017ccd 100755 --- a/src/material/item/food/PotatoItem.php +++ b/src/material/item/food/PotatoItem.php @@ -5,5 +5,5 @@ public function __construct($meta = 0, $count = 1){ $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 3a30ebfad..098c08034 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 79e9d765c..18823a315 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 08e7c3c64..380e3f97f 100755 --- a/src/material/item/generic/DyeItem.php +++ b/src/material/item/generic/DyeItem.php @@ -20,7 +20,7 @@ public function __construct($meta = 0, $count = 1){ 13 => "Magenta Dye", 14 => "Orange Dye", 15 => "Bone Meal", - ); + ]; $this->name = $names[$this->meta]; } } diff --git a/src/material/item/generic/MinecartItem.php b/src/material/item/generic/MinecartItem.php index b8923748a..d38079288 100755 --- a/src/material/item/generic/MinecartItem.php +++ b/src/material/item/generic/MinecartItem.php @@ -12,8 +12,8 @@ public function onActivate(Level $level, Player $player, Block $block, Block $ta } $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 4ce688c8d..f8e134be7 100644 --- a/src/material/item/generic/PaintingItem.php +++ b/src/material/item/generic/PaintingItem.php @@ -5,44 +5,44 @@ public function __construct($meta = 0, $count = 1){ 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 @@ public function onActivate(Level $level, Player $player, Block $block, Block $ta "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 f41e9a01c..7d755b4f3 100644 --- a/src/material/item/generic/SpawnEggItem.php +++ b/src/material/item/generic/SpawnEggItem.php @@ -6,19 +6,19 @@ public function __construct($meta = 0, $count = 1){ $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 9c2e1f83f..f462f9415 100755 --- a/src/material/item/tool/CompassItem.php +++ b/src/material/item/tool/CompassItem.php @@ -5,5 +5,5 @@ public function __construct($meta = 0, $count = 1){ 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 7cb03b243..f602c05bf 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 b90fc8822..608f26fc9 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 134b160a3..9de35dbbd 100644 --- a/src/material/item/tool/FlintSteelItem.php +++ b/src/material/item/tool/FlintSteelItem.php @@ -6,19 +6,19 @@ public function __construct($meta = 0, $count = 1){ $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 7f0b2cb68..a8d41066b 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 d8c5dc86c..3a3744665 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 620e5ea49..0e6332a24 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 321a714f7..6f4cffda3 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 059ede729..53ff3a114 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 b3f948f7f..791e26f35 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 d7428123c..22890581b 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 c23e42c63..d780f9611 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 c5f5f49dd..b573d1bfd 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 a6f9fd21a..e173e3c6e 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 187700cab..d778842be 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.php @@ -1,4 +1,5 @@ minX = $minX; $this->minY = $minY; @@ -30,7 +31,7 @@ public function setBounds($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ 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 @@ public function calculateZOffset(AxisAlignedBB $bb, $z){ 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 @@ public function isXYZInsideNS($x, $y, $z){ 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 @@ public function isXYZInside($x, $y, $z){ 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 @@ public function isVectorInXZ(Vector3 $vector){ 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 @@ public function calculateIntercept(Vector3 $pos1, Vector3 $pos2){ 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 d2f3b245d..8d74c09fc 100644 --- a/src/math/Matrix.php +++ b/src/math/Matrix.php @@ -148,7 +148,6 @@ public function determinant(){ }; } - //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 03dcb0153..eff4b30d3 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 @@ public function abs(){ } 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 @@ public function distanceSquared($x = 0, $y = 0, $z = 0){ 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 @@ public function cross(Vector3 $v){ $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 @@ public function clipX(Vector3 $v, $x){ $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 @@ public function clipX(Vector3 $v, $x){ 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 @@ public function clipY(Vector3 $v, $y){ $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 @@ public function getIntermediateWithYValue(Vector3 $v, $y){ * 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 @@ public function clipZ(Vector3 $v, $z){ $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 ad91322e8..ef43122ae 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -41,7 +41,7 @@ private function parsePacket($buffer, $source, $port){ $pid = ord($buffer[0]); if(RakNetInfo::isValid($pid)){ - $parser = new RakNetParser($buffer); + $parser = new RakNetParser($buffer, $source); if($parser->packet !== false){ $parser->packet->ip = $source; $parser->packet->port = $port; @@ -55,7 +55,7 @@ private function parsePacket($buffer, $source, $port){ $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 @@ private function parsePacket($buffer, $source, $port){ $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/PacketPool.php b/src/network/PacketPool.php new file mode 100644 index 000000000..3571c697b --- /dev/null +++ b/src/network/PacketPool.php @@ -0,0 +1,126 @@ + $class + */ + private static function registerPacket(string $class, $protocols = self::ACCEPTED_PROTOCOLS): void{ + /** @var RakNetDataPacket $pk */ + $pk = new $class; + foreach ($protocols as $protocol) { + $pk->PROTOCOL = $protocol; + $pid = $pk->pid(); + if(isset(self::$packetPool[$protocol][$pid])) { + $oldPk = self::$packetPool[$protocol][$pid]; + console("[WARNING] 协议$protocol 中 PID:$pid (0x".dechex($pid).")包".get_class($oldPk)."与包".get_class($pk)."冲突"); + } + self::$packetPool[$protocol][$pid] = clone $pk; + } + } + + public static function getPacket($pid, $protocol) : RakNetDataPacket{ + if(isset(self::$packetPool[$protocol][$pid])) { + return clone self::$packetPool[$protocol][$pid]; + } + $pk = new UnknownPacket(); + $pk->packetID = $pid; + $pk->PROTOCOL = $protocol; + return $pk; + } + + public static function isPacketExist($pid, $protocol) : bool{ + if(isset(self::$packetPool[$protocol][$pid])) { + return true; + } + return false; + } + + public static function init() : void{ + if(self::$isInit){ + return; + } + + self::registerPacket(AddEntityPacket::class); + self::registerPacket(AddItemEntityPacket::class); + self::registerPacket(AddMobPacket::class); + self::registerPacket(AddPaintingPacket::class, [8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(AddPlayerPacket::class); + self::registerPacket(AdventureSettingsPacket::class, [8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(AnimatePacket::class); + + self::registerPacket(ChatPacket::class, [6, 7, 8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(ChunkDataPacket::class); + self::registerPacket(ClientConnectPacket::class); + self::registerPacket(ClientHandshakePacket::class); + self::registerPacket(ContainerClosePacket::class); + self::registerPacket(ContainerOpenPacket::class); + self::registerPacket(ContainerSetContentPacket::class); + self::registerPacket(ContainerSetDataPacket::class); + self::registerPacket(ContainerSetSlotPacket::class); + self::registerPacket(ContainerAckPacket::class); + + self::registerPacket(DisconnectPacket::class); + self::registerPacket(DropItemPacket::class); + + self::registerPacket(EntityDataPacket::class, [8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(EntityEventPacket::class); + self::registerPacket(ExplodePacket::class); + + self::registerPacket(HurtArmorPacket::class, [9, 10, 11, 12, 13, 14]); + + self::registerPacket(InteractPacket::class); + + self::registerPacket(LevelEventPacket::class); + self::registerPacket(LoginPacket::class); + self::registerPacket(LoginStatusPacket::class); + + self::registerPacket(MessagePacket::class); + self::registerPacket(MoveEntityPacket::class); + self::registerPacket(MoveEntityPacket_PosRot::class); + self::registerPacket(MovePlayerPacket::class); + + self::registerPacket(PingPacket::class); + self::registerPacket(PlaceBlockPacket::class); + self::registerPacket(PlayerActionPacket::class, [6, 7, 8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(PlayerArmorEquipmentPacket::class, [9, 10, 11, 12, 13, 14]); + self::registerPacket(PlayerEquipmentPacket::class); + self::registerPacket(PlayerInputPacket::class, [8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(PongPacket::class); + + self::registerPacket(ReadyPacket::class); + self::registerPacket(RemoveBlockPacket::class); + self::registerPacket(RemoveEntityPacket::class); + self::registerPacket(RemovePlayerPacket::class); + self::registerPacket(RequestChunkPacket::class); + self::registerPacket(RespawnPacket::class); + self::registerPacket(RotateHeadPacket::class); + + self::registerPacket(SendInventoryPacket::class); + self::registerPacket(ServerHandshakePacket::class); + self::registerPacket(SetEntityDataPacket::class); + self::registerPacket(SetEntityLinkPacket::class, [12, 13, 14]); + self::registerPacket(SetEntityMotionPacket::class, [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(SetHealthPacket::class); + self::registerPacket(SetSpawnPositionPacket::class, [8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(SetTimePacket::class); + self::registerPacket(SignUpdatePacket::class, [6, 7, 8, 9]); + self::registerPacket(StartGamePacket::class); + + self::registerPacket(TakeItemEntityPacket::class); + self::registerPacket(TileEventPacket::class, [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]); + + self::registerPacket(UpdateBlockPacket::class); + self::registerPacket(UseItemPacket::class); + + //self::registerPacket(UnknownPacket::class); //DO NOT REGISTER THIS + + self::$isInit = true; + } +} \ No newline at end of file diff --git a/src/network/RCON.php b/src/network/RCON.php index 60f41149b..9492cc579 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 @@ public function __construct($socket, $password, $maxClients = 50){ $this->maxClients = (int) $maxClients; $this->start(); } - + public function close(){ $this->stop = true; } @@ -108,7 +108,7 @@ public function run(){ }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 @@ public function run(){ $disconnect[$id] = $sock; continue; } - + switch($packetType){ case 3: //Login if($authenticated[$id]){ @@ -160,19 +160,18 @@ public function run(){ } } } - + 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 @@ public function run(){ 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 @@ private function disconnectClient($client){ @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 15cf0b3cb..772df211b 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 fc6c6b8f2..79fc5a367 100644 --- a/src/network/protocol/ProtocolInfo.php +++ b/src/network/protocol/ProtocolInfo.php @@ -1,6 +1,5 @@ PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::ADD_ENTITY_PACKET; + } return ProtocolInfo::ADD_ENTITY_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); @@ -28,9 +31,9 @@ public function encode(){ $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 fb68f60a8..0ba0e2c64 100644 --- a/src/network/protocol/packet/AddItemEntityPacket.php +++ b/src/network/protocol/packet/AddItemEntityPacket.php @@ -9,19 +9,22 @@ class AddItemEntityPacket extends RakNetDataPacket{ public $yaw; public $pitch; public $roll; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::ADD_ITEM_ENTITY_PACKET; + } return ProtocolInfo::ADD_ITEM_ENTITY_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->eid); - $this->putSlot($this->item); + $this->putSlot($this->PROTOCOL, $this->item); $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); diff --git a/src/network/protocol/packet/AddMobPacket.php b/src/network/protocol/packet/AddMobPacket.php index 5b2d9a903..4a469196f 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 bd50ab0a7..405f22d4e 100644 --- a/src/network/protocol/packet/AddPaintingPacket.php +++ b/src/network/protocol/packet/AddPaintingPacket.php @@ -7,15 +7,18 @@ class AddPaintingPacket extends RakNetDataPacket{ public $z; public $direction; public $title; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ADD_PAINTING_PACKET; + } 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 044f119af..709c1a307 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 b395975cc..c19c89da0 100644 --- a/src/network/protocol/packet/AdventureSettingsPacket.php +++ b/src/network/protocol/packet/AdventureSettingsPacket.php @@ -2,15 +2,22 @@ class AdventureSettingsPacket extends RakNetDataPacket{ public $flags; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::ADVENTURE_SETTINGS_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::ADVENTURE_SETTINGS_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ADVENTURE_SETTINGS_PACKET; + } 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 a8ea6820e..84b980cfb 100644 --- a/src/network/protocol/packet/AnimatePacket.php +++ b/src/network/protocol/packet/AnimatePacket.php @@ -3,19 +3,32 @@ class AnimatePacket extends RakNetDataPacket{ const ANIM_SWING_HAND = 0x1; const ANIM_STOP_SLEEP = 0x3; - + public $action; public $eid; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ANIMATE_PACKET; + } 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 cbe5998ac..cc750b03e 100644 --- a/src/network/protocol/packet/ChatPacket.php +++ b/src/network/protocol/packet/ChatPacket.php @@ -2,15 +2,24 @@ class ChatPacket extends RakNetDataPacket{ public $message; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::CHAT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::CHAT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CHAT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CHAT_PACKET; + } 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 024bebbb8..1c6cbe1e7 100644 --- a/src/network/protocol/packet/ChunkDataPacket.php +++ b/src/network/protocol/packet/ChunkDataPacket.php @@ -4,15 +4,24 @@ class ChunkDataPacket extends RakNetDataPacket{ public $chunkX; public $chunkZ; public $data; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CHUNK_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::CHUNK_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::CHUNK_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CHUNK_DATA_PACKET; + } 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 f4a95243c..b71e80e6e 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 7d807d9ce..9cce1aa21 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 @@ public function decode(){ $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/ContainerAckPacket.php b/src/network/protocol/packet/ContainerAckPacket.php new file mode 100644 index 000000000..d748a73bc --- /dev/null +++ b/src/network/protocol/packet/ContainerAckPacket.php @@ -0,0 +1,62 @@ +PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::CONTAINER_ACK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::CONTAINER_ACK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::CONTAINER_ACK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_ACK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_ACK_PACKET; + } + return ProtocolInfo::CONTAINER_ACK_PACKET; + } + + public function decode(){ + $this->unknwonubyte1 = $this->getByte(); + $this->unknownshort = $this->getShort(); + if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + $this->unknwonubyte2 = $this->getByte(); + return; + } + $this->write1 = $this->get(); + $this->write0 = $this->get(); + ConsoleAPI::debug($this->unknwonubyte1); + ConsoleAPI::debug($this->unknownshort); + ConsoleAPI::debug($this->write1); + ConsoleAPI::debug($this->write0); + + ConsoleAPI::debug($this->unknwonubyte2); + } + + public function encode(){ + if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + $this->reset(); + } + $this->putByte($this->unknwonubyte1); + $this->putShort($this->unknownshort); + if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + $this->putByte($this->unknwonubyte2); + return; + } + $this->put($this->write1); + $this->put($this->write0); + ConsoleAPI::debug($this->unknwonubyte1); + ConsoleAPI::debug($this->unknownshort); + ConsoleAPI::debug($this->write1); + ConsoleAPI::debug($this->write0); + + ConsoleAPI::debug($this->unknwonubyte2); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerClosePacket.php b/src/network/protocol/packet/ContainerClosePacket.php index 008d80977..be5164721 100644 --- a/src/network/protocol/packet/ContainerClosePacket.php +++ b/src/network/protocol/packet/ContainerClosePacket.php @@ -2,15 +2,28 @@ class ContainerClosePacket extends RakNetDataPacket{ public $windowid; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_CLOSE_PACKET; + } 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 92eecd786..93241c939 100644 --- a/src/network/protocol/packet/ContainerOpenPacket.php +++ b/src/network/protocol/packet/ContainerOpenPacket.php @@ -7,23 +7,42 @@ class ContainerOpenPacket extends RakNetDataPacket{ public $x; public $y; public $z; - + public $unknownstring; + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_OPEN_PACKET; + } return ProtocolInfo::CONTAINER_OPEN_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putByte($this->windowid); $this->putByte($this->type); $this->putByte($this->slots); - $this->putInt($this->x); - $this->putInt($this->y); - $this->putInt($this->z); + if ($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9){ + $this->putString($this->unknownstring); + ConsoleAPI::debug($this->unknownstring); + }else{ + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + } } } \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerSetContentPacket.php b/src/network/protocol/packet/ContainerSetContentPacket.php index a4afe1db9..115058e69 100644 --- a/src/network/protocol/packet/ContainerSetContentPacket.php +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -2,19 +2,35 @@ class ContainerSetContentPacket extends RakNetDataPacket{ public $windowid; - public $slots = array(); - public $hotbar = array(); - + public $slots = []; + public $hotbar = []; + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_SET_CONTENT_PACKET; + } return ProtocolInfo::CONTAINER_SET_CONTENT_PACKET; } - + public function decode(){ $this->windowid = $this->getByte(); $count = $this->getShort(); for($s = 0; $s < $count and !$this->feof(); ++$s){ $this->slots[$s] = $this->getSlot(); } + if($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9){ + return; + } if($this->windowid === 0){ $count = $this->getShort(); for($s = 0; $s < $count and !$this->feof(); ++$s){ @@ -22,14 +38,17 @@ public function decode(){ } } } - + public function encode(){ $this->reset(); $this->putByte($this->windowid); $this->putShort(count($this->slots)); foreach($this->slots as $slot){ - $this->putSlot($slot); + $this->putSlot($this->PROTOCOL, $slot); } + if($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9){ + return; + } if($this->windowid === 0 and count($this->hotbar) > 0){ $this->putShort(count($this->hotbar)); foreach($this->hotbar as $slot){ diff --git a/src/network/protocol/packet/ContainerSetDataPacket.php b/src/network/protocol/packet/ContainerSetDataPacket.php index 0d93c4e13..50cbaa1ec 100644 --- a/src/network/protocol/packet/ContainerSetDataPacket.php +++ b/src/network/protocol/packet/ContainerSetDataPacket.php @@ -4,15 +4,28 @@ class ContainerSetDataPacket extends RakNetDataPacket{ public $windowid; public $property; public $value; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_SET_DATA_PACKET; + } 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 fab25153c..7a5d8ef68 100644 --- a/src/network/protocol/packet/ContainerSetSlotPacket.php +++ b/src/network/protocol/packet/ContainerSetSlotPacket.php @@ -4,22 +4,35 @@ class ContainerSetSlotPacket extends RakNetDataPacket{ public $windowid; public $slot; public $item; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_SET_SLOT_PACKET; + } 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); $this->putShort($this->slot); - $this->putSlot($this->item); + $this->putSlot($this->PROTOCOL, $this->item); } } \ No newline at end of file diff --git a/src/network/protocol/packet/DisconnectPacket.php b/src/network/protocol/packet/DisconnectPacket.php index f0cc9fe84..17a4effbe 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 415311607..b3fccc5ce 100644 --- a/src/network/protocol/packet/DropItemPacket.php +++ b/src/network/protocol/packet/DropItemPacket.php @@ -4,19 +4,36 @@ class DropItemPacket extends RakNetDataPacket{ public $eid; public $unknown; public $item; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::DROP_ITEM_PACKET; + } return ProtocolInfo::DROP_ITEM_PACKET; } - + public function decode(){ + //if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8)$this->reset(); $this->eid = $this->getInt(); $this->unknown = $this->getByte(); $this->item = $this->getSlot(); } - - public function encode(){ + public function encode(){ + /*$this->reset(); + $this->putInt($this->eid); + $this->putByte($this->unknown); + $this->putSlot($this->item);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/EntityDataPacket.php b/src/network/protocol/packet/EntityDataPacket.php index 01b2cafbf..b78c73585 100644 --- a/src/network/protocol/packet/EntityDataPacket.php +++ b/src/network/protocol/packet/EntityDataPacket.php @@ -5,18 +5,25 @@ class EntityDataPacket extends RakNetDataPacket{ public $y; public $z; public $namedtag; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ENTITY_DATA_PACKET; + } 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 05cf7770f..4ddb4d8cd 100644 --- a/src/network/protocol/packet/EntityEventPacket.php +++ b/src/network/protocol/packet/EntityEventPacket.php @@ -3,25 +3,34 @@ 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(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::ENTITY_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::ENTITY_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::ENTITY_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ENTITY_EVENT_PACKET; + } 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 1d60b72a3..5d0930f8f 100644 --- a/src/network/protocol/packet/ExplodePacket.php +++ b/src/network/protocol/packet/ExplodePacket.php @@ -6,15 +6,22 @@ class ExplodePacket extends RakNetDataPacket{ public $z; public $radius; public $records; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::EXPLODE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::EXPLODE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::EXPLODE_PACKET; + } 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 e23aac3e1..a8ddcf989 100644 --- a/src/network/protocol/packet/HurtArmorPacket.php +++ b/src/network/protocol/packet/HurtArmorPacket.php @@ -2,15 +2,18 @@ class HurtArmorPacket extends RakNetDataPacket{ public $health; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::HURT_ARMOR_PACKET; + } 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 2d33773d9..3f07246ec 100644 --- a/src/network/protocol/packet/InteractPacket.php +++ b/src/network/protocol/packet/InteractPacket.php @@ -9,15 +9,26 @@ class InteractPacket extends RakNetDataPacket{ public $target; public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::INTERACT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::INTERACT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::INTERACT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::INTERACT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::INTERACT_PACKET; + } 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 50727e45d..4dba836b2 100644 --- a/src/network/protocol/packet/LevelEventPacket.php +++ b/src/network/protocol/packet/LevelEventPacket.php @@ -1,24 +1,31 @@ PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::LEVEL_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::LEVEL_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::LEVEL_EVENT_PACKET; + } return ProtocolInfo::LEVEL_EVENT_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putShort($this->evid); diff --git a/src/network/protocol/packet/LoginPacket.php b/src/network/protocol/packet/LoginPacket.php index 34f049551..0d4225a6a 100644 --- a/src/network/protocol/packet/LoginPacket.php +++ b/src/network/protocol/packet/LoginPacket.php @@ -6,21 +6,23 @@ class LoginPacket extends RakNetDataPacket{ public $protocol2; public $clientId; public $loginData; - + public function pid(){ return ProtocolInfo::LOGIN_PACKET; } - + public function decode(){ + //if($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->username = $this->getString(); $this->protocol1 = $this->getInt(); $this->protocol2 = $this->getInt(); - $this->clientId = $this->getInt(); + $this->clientId = $this->getInt();//null $this->loginData = $this->getString(); - } - + $this->PROTOCOL = $this->protocol1; + } + 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 bd5019179..ef02b0d2a 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 dcb1b0bbb..5af2520e2 100644 --- a/src/network/protocol/packet/MessagePacket.php +++ b/src/network/protocol/packet/MessagePacket.php @@ -3,19 +3,23 @@ class MessagePacket extends RakNetDataPacket{ public $source; public $message; - + public function pid(){ return ProtocolInfo::MESSAGE_PACKET; } - + public function decode(){ - $this->source = $this->getString(); + if($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9){ //0.6.1 and below From NostalgiaCore-BackPort Author:Gameherobrine + $this->source = $this->getString(); + } $this->message = $this->getString(); - } - + } + public function encode(){ $this->reset(); - $this->putString($this->source); + if($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9){ //0.6.1 and below From NostalgiaCore-BackPort Author:Gameherobrine + $this->putString($this->source); + } $this->putString($this->message); } diff --git a/src/network/protocol/packet/MoveEntityPacket.php b/src/network/protocol/packet/MoveEntityPacket.php index be59077ce..d4cbbf931 100644 --- a/src/network/protocol/packet/MoveEntityPacket.php +++ b/src/network/protocol/packet/MoveEntityPacket.php @@ -3,15 +3,18 @@ class MoveEntityPacket extends RakNetDataPacket{ public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::MOVE_ENTITY_PACKET; + } return ProtocolInfo::MOVE_ENTITY_PACKET; } - + public function decode(){ } - + public function encode(){ - $this->reset(); + $this->reset(); //null } } \ No newline at end of file diff --git a/src/network/protocol/packet/MoveEntityPacket_PosRot.php b/src/network/protocol/packet/MoveEntityPacket_PosRot.php index c2143c180..5ec9632dc 100644 --- a/src/network/protocol/packet/MoveEntityPacket_PosRot.php +++ b/src/network/protocol/packet/MoveEntityPacket_PosRot.php @@ -7,11 +7,14 @@ class MoveEntityPacket_PosRot extends RakNetDataPacket{ public $z; public $yaw; public $pitch; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::MOVE_ENTITY_PACKET_POSROT; + } return ProtocolInfo::MOVE_ENTITY_PACKET_POSROT; } - + public function decode(){ $this->get(7); $this->eid = $this->getInt(); @@ -21,7 +24,7 @@ public function decode(){ $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 5325cf761..276ae2e0f 100644 --- a/src/network/protocol/packet/MovePlayerPacket.php +++ b/src/network/protocol/packet/MovePlayerPacket.php @@ -8,11 +8,16 @@ class MovePlayerPacket extends RakNetDataPacket{ public $yaw; public $pitch; public $bodyYaw; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::MOVE_PLAYER_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::MOVE_PLAYER_PACKET; + } return ProtocolInfo::MOVE_PLAYER_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->x = $this->getFloat(); @@ -20,9 +25,11 @@ public function decode(){ $this->z = $this->getFloat(); $this->yaw = $this->getFloat(); $this->pitch = $this->getFloat(); - $this->bodyYaw = $this->getFloat(); + if($this->PROTOCOL > 13){ + $this->bodyYaw = $this->getFloat(); + } } - + public function encode(){ $this->reset(); $this->putInt($this->eid); @@ -31,7 +38,9 @@ public function encode(){ $this->putFloat($this->z); $this->putFloat($this->yaw); $this->putFloat($this->pitch); - $this->putFloat($this->bodyYaw); + if($this->PROTOCOL > 13){ + $this->putFloat($this->bodyYaw); + } } } \ No newline at end of file diff --git a/src/network/protocol/packet/PingPacket.php b/src/network/protocol/packet/PingPacket.php index 77e380dc3..92eefb03e 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/PlaceBlockPacket.php b/src/network/protocol/packet/PlaceBlockPacket.php new file mode 100644 index 000000000..743738bdf --- /dev/null +++ b/src/network/protocol/packet/PlaceBlockPacket.php @@ -0,0 +1,42 @@ +PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::PLACE_BLOCK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL) { + return ProtocolInfo12::PLACE_BLOCK_PACKET; + } + return ProtocolInfo::PLACE_BLOCK_PACKET; + } + + public function decode(){ + $this->eid = $this->getInt(); + $this->x = $this->getInt(); + $this->z = $this->getInt(); + $this->y = $this->getByte(); + $this->block = $this->getByte(); + $this->meta = $this->getByte(); + $this->face = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putInt($this->x); + $this->putInt($this->z); + $this->putByte($this->y); + $this->putByte(BlockAPI::convertHighItemIdsToOldItemIds($this->PROTOCOL, $this->block)); + $this->putByte($this->meta); + $this->putByte($this->face); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerActionPacket.php b/src/network/protocol/packet/PlayerActionPacket.php index cdcc64ad0..945347cc2 100644 --- a/src/network/protocol/packet/PlayerActionPacket.php +++ b/src/network/protocol/packet/PlayerActionPacket.php @@ -7,12 +7,20 @@ class PlayerActionPacket extends RakNetDataPacket{ public $z; public $face; public $eid; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::PLAYER_ACTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::PLAYER_ACTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::PLAYER_ACTION_PACKET; + } return ProtocolInfo::PLAYER_ACTION_PACKET; } - + public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->action = $this->getInt(); $this->x = $this->getInt(); $this->y = $this->getInt(); @@ -20,9 +28,15 @@ public function decode(){ $this->face = $this->getInt(); $this->eid = $this->getInt(); } - - public function encode(){ + public function encode(){ + /*$this->reset(); + $this->putInt($this->action); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + $this->putInt($this->face); + $this->putInt($this->eid);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php index d32be3162..41424a253 100644 --- a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php @@ -2,20 +2,23 @@ class PlayerArmorEquipmentPacket extends RakNetDataPacket{ public $eid; - public $slots = array(); - + public $slots = []; + public function pid(){ + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::PLAYER_ARMOR_EQUIPMENT_PACKET; + } 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 06e65fee9..c7806eb5d 100644 --- a/src/network/protocol/packet/PlayerEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerEquipmentPacket.php @@ -5,24 +5,33 @@ class PlayerEquipmentPacket extends RakNetDataPacket{ public $item; public $meta; public $slot; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::PLAYER_EQUIPMENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::PLAYER_EQUIPMENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::PLAYER_EQUIPMENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::PLAYER_EQUIPMENT_PACKET; + } return ProtocolInfo::PLAYER_EQUIPMENT_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->item = $this->getShort(); $this->meta = $this->getShort(); - $this->slot = $this->getSignedByte(); + if($this->PROTOCOL === ProtocolInfo::CURRENT_PROTOCOL){$this->slot = $this->getSignedByte();} } - + public function encode(){ $this->reset(); $this->putInt($this->eid); - $this->putShort($this->item); + $this->putShort(BlockAPI::convertHighItemIdsToOldItemIds($this->PROTOCOL, $this->item)); $this->putShort($this->meta); - $this->putByte($this->slot); + if($this->PROTOCOL === ProtocolInfo::CURRENT_PROTOCOL){$this->putByte($this->slot);} } } \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerInputPacket.php b/src/network/protocol/packet/PlayerInputPacket.php index f80f18bcc..618dba701 100644 --- a/src/network/protocol/packet/PlayerInputPacket.php +++ b/src/network/protocol/packet/PlayerInputPacket.php @@ -1,13 +1,18 @@ PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::PLAYER_INPUT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::PLAYER_INPUT_PACKET; + } return ProtocolInfo::PLAYER_INPUT_PACKET; } @@ -18,6 +23,6 @@ public function decode() $this->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 ab1a19483..ab9da4fa3 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 2fa12b5ec..e6eae824c 100644 --- a/src/network/protocol/packet/ReadyPacket.php +++ b/src/network/protocol/packet/ReadyPacket.php @@ -2,17 +2,19 @@ class ReadyPacket extends RakNetDataPacket{ public $status; - + public function pid(){ return ProtocolInfo::READY_PACKET; } - + public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->status = $this->getByte(); - } - - public function encode(){ + } + public function encode(){ + /*$this->reset(); + $this->putByte($this->status);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/RemoveBlockPacket.php b/src/network/protocol/packet/RemoveBlockPacket.php index d3e3a969a..4c01228cc 100644 --- a/src/network/protocol/packet/RemoveBlockPacket.php +++ b/src/network/protocol/packet/RemoveBlockPacket.php @@ -5,20 +5,30 @@ class RemoveBlockPacket extends RakNetDataPacket{ public $x; public $y; public $z; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::REMOVE_BLOCK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::REMOVE_BLOCK_PACKET; + } return ProtocolInfo::REMOVE_BLOCK_PACKET; } - + public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->eid = $this->getInt(); $this->x = $this->getInt(); $this->z = $this->getInt(); $this->y = $this->getByte(); } - - public function encode(){ + public function encode(){ + /*$this->reset(); + $this->putInt($this->eid); + $this->putInt($this->x); + $this->putInt($this->z); + $this->putInt($this->y);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/RemoveEntityPacket.php b/src/network/protocol/packet/RemoveEntityPacket.php index 27d6c42b3..c835d9a9f 100644 --- a/src/network/protocol/packet/RemoveEntityPacket.php +++ b/src/network/protocol/packet/RemoveEntityPacket.php @@ -4,13 +4,16 @@ class RemoveEntityPacket extends RakNetDataPacket{ public $eid; public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::REMOVE_ENTITY_PACKET; + } 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 f23cd4df3..553a46b79 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 d06507488..8bdeea7cb 100644 --- a/src/network/protocol/packet/RequestChunkPacket.php +++ b/src/network/protocol/packet/RequestChunkPacket.php @@ -3,18 +3,30 @@ class RequestChunkPacket extends RakNetDataPacket{ public $chunkX; public $chunkZ; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::REQUEST_CHUNK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::REQUEST_CHUNK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::REQUEST_CHUNK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::REQUEST_CHUNK_PACKET; + } return ProtocolInfo::REQUEST_CHUNK_PACKET; } - + public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->chunkX = $this->getInt(); $this->chunkZ = $this->getInt(); } - - public function encode(){ + public function encode(){ + /*$this->reset(); + $this->putInt($this->chunkX); + $this->putInt($this->chunkZ);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/RespawnPacket.php b/src/network/protocol/packet/RespawnPacket.php index 1d3c208e2..c88a856aa 100644 --- a/src/network/protocol/packet/RespawnPacket.php +++ b/src/network/protocol/packet/RespawnPacket.php @@ -5,18 +5,31 @@ class RespawnPacket extends RakNetDataPacket{ public $x; public $y; public $z; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::RESPAWN_PACKET; + } 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 21cc7cf00..634e38511 100644 --- a/src/network/protocol/packet/RotateHeadPacket.php +++ b/src/network/protocol/packet/RotateHeadPacket.php @@ -11,15 +11,18 @@ class RotateHeadPacket extends RakNetDataPacket{ */ public $rawYaw = false; public function pid(){ + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ROTATE_HEAD_PACKET; + } 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 1bddca97d..e1e2ef0a5 100644 --- a/src/network/protocol/packet/SendInventoryPacket.php +++ b/src/network/protocol/packet/SendInventoryPacket.php @@ -3,13 +3,26 @@ class SendInventoryPacket extends RakNetDataPacket{ public $eid; public $windowid; - public $slots = array(); - public $armor = array(); - + public $slots = []; + public $armor = []; + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SEND_INVENTORY_PACKET; + } return ProtocolInfo::SEND_INVENTORY_PACKET; } - + public function decode(){ $this->eid = $this->getInt(); $this->windowid = $this->getByte(); @@ -23,18 +36,18 @@ public function decode(){ } } } - + public function encode(){ $this->reset(); $this->putInt($this->eid); $this->putByte($this->windowid); $this->putShort(count($this->slots)); foreach($this->slots as $slot){ - $this->putSlot($slot); + $this->putSlot($this->PROTOCOL, $slot); } if($this->windowid === 1 and count($this->armor) === 4){ for($s = 0; $s < 4; ++$s){ - $this->putSlot($this->armor[$s]); + $this->putSlot($this->PROTOCOL, $this->armor[$s]); } } } diff --git a/src/network/protocol/packet/ServerHandshakePacket.php b/src/network/protocol/packet/ServerHandshakePacket.php index 4931aa23a..2b1a93845 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 @@ public function encode(){ "\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 8626885da..160d35c4b 100644 --- a/src/network/protocol/packet/SetEntityDataPacket.php +++ b/src/network/protocol/packet/SetEntityDataPacket.php @@ -3,15 +3,26 @@ class SetEntityDataPacket extends RakNetDataPacket{ public $eid; public $metadata; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::SET_ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::SET_ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::SET_ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::SET_ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_ENTITY_DATA_PACKET; + } 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 34de37c1a..c473ef131 100644 --- a/src/network/protocol/packet/SetEntityLinkPacket.php +++ b/src/network/protocol/packet/SetEntityLinkPacket.php @@ -21,8 +21,10 @@ public function encode() { $this->putInt($this->type); } - public function pid(){ + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_ENTITY_LINK_PACKET; + } return ProtocolInfo::SET_ENTITY_LINK_PACKET; } diff --git a/src/network/protocol/packet/SetEntityMotionPacket.php b/src/network/protocol/packet/SetEntityMotionPacket.php index e4cf70b94..5bd44bf63 100644 --- a/src/network/protocol/packet/SetEntityMotionPacket.php +++ b/src/network/protocol/packet/SetEntityMotionPacket.php @@ -5,15 +5,24 @@ class SetEntityMotionPacket extends RakNetDataPacket{ public $speedX; public $speedY; public $speedZ; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::SET_ENTITY_MOTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::SET_ENTITY_MOTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::SET_ENTITY_MOTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_ENTITY_MOTION_PACKET; + } 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 42e52f810..0ef18bdbf 100644 --- a/src/network/protocol/packet/SetHealthPacket.php +++ b/src/network/protocol/packet/SetHealthPacket.php @@ -2,15 +2,28 @@ class SetHealthPacket extends RakNetDataPacket{ public $health; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_HEALTH_PACKET; + } 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 3da187eac..a072a1312 100644 --- a/src/network/protocol/packet/SetSpawnPositionPacket.php +++ b/src/network/protocol/packet/SetSpawnPositionPacket.php @@ -4,15 +4,22 @@ class SetSpawnPositionPacket extends RakNetDataPacket{ public $x; public $z; public $y; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::SET_SPAWN_POSITION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::SET_SPAWN_POSITION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_SPAWN_POSITION_PACKET; + } 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 302afd9e9..4f055bc01 100644 --- a/src/network/protocol/packet/SetTimePacket.php +++ b/src/network/protocol/packet/SetTimePacket.php @@ -3,19 +3,21 @@ 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); - $this->putByte($this->started ? 0x80:0x00); + $this->putInt($this->time);// long in 0.6.1 + if($this->PROTOCOL >= ProtocolInfo8::CURRENT_PROTOCOL_8){ + $this->putByte($this->started ? 0x80:0x00); + } } } \ No newline at end of file diff --git a/src/network/protocol/packet/SignUpdatePacket.php b/src/network/protocol/packet/SignUpdatePacket.php new file mode 100644 index 000000000..1ba4542dd --- /dev/null +++ b/src/network/protocol/packet/SignUpdatePacket.php @@ -0,0 +1,34 @@ +PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::SIGN_UPDATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::SIGN_UPDATE_PACKET) { + return ProtocolInfo8::SIGN_UPDATE_PACKET; + } + return ProtocolInfo9::SIGN_UPDATE_PACKET; + } + + public function decode(){ + //$this->reset(); + $this->x = $this->getShort(); + $this->y = $this->getByte(); + $this->z = $this->getShort(); + $this->content = $this->getString(); + } + + public function encode(){ + //$this->reset(); + $this->putShort($this->x); + $this->putByte($this->y); + $this->putShort($this->z); + $this->putString($this->content); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/StartGamePacket.php b/src/network/protocol/packet/StartGamePacket.php index a746ea3ab..c81898a8d 100644 --- a/src/network/protocol/packet/StartGamePacket.php +++ b/src/network/protocol/packet/StartGamePacket.php @@ -8,18 +8,18 @@ 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); + $this->putInt($this->seed);// long in 0.6.1 $this->putInt($this->generator); $this->putInt($this->gamemode); $this->putInt($this->eid); diff --git a/src/network/protocol/packet/TakeItemEntityPacket.php b/src/network/protocol/packet/TakeItemEntityPacket.php index 85221c38d..5c3e9eae8 100644 --- a/src/network/protocol/packet/TakeItemEntityPacket.php +++ b/src/network/protocol/packet/TakeItemEntityPacket.php @@ -5,13 +5,16 @@ class TakeItemEntityPacket extends RakNetDataPacket{ public $eid; public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::TAKE_ITEM_ENTITY_PACKET; + } 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 e22668961..ef33178be 100644 --- a/src/network/protocol/packet/TileEventPacket.php +++ b/src/network/protocol/packet/TileEventPacket.php @@ -6,15 +6,22 @@ class TileEventPacket extends RakNetDataPacket{ public $z; public $case1; public $case2; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::TILE_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::TILE_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::TILE_EVENT_PACKET; + } 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 08b89139e..d85cb81c1 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 020fc63ba..d1e85f11c 100644 --- a/src/network/protocol/packet/UpdateBlockPacket.php +++ b/src/network/protocol/packet/UpdateBlockPacket.php @@ -6,21 +6,26 @@ class UpdateBlockPacket extends RakNetDataPacket{ public $y; public $block; public $meta; - + public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::UPDATE_BLOCK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::UPDATE_BLOCK_PACKET; + } return ProtocolInfo::UPDATE_BLOCK_PACKET; } - + public function decode(){ } - + public function encode(){ $this->reset(); $this->putInt($this->x); $this->putInt($this->z); $this->putByte($this->y); - $this->putByte($this->block); + $this->putByte(BlockAPI::convertHighItemIdsToOldItemIds($this->PROTOCOL, $this->block)); $this->putByte($this->meta); } diff --git a/src/network/protocol/packet/UseItemPacket.php b/src/network/protocol/packet/UseItemPacket.php index 32e2c651b..5f086013f 100644 --- a/src/network/protocol/packet/UseItemPacket.php +++ b/src/network/protocol/packet/UseItemPacket.php @@ -14,12 +14,26 @@ class UseItemPacket extends RakNetDataPacket{ public $posX; public $posY; public $posZ; - + + public $unknownInt1; + public function pid(){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::USE_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::USE_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + return ProtocolInfo6::USE_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo8::USE_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::USE_ITEM_PACKET; + } return ProtocolInfo::USE_ITEM_PACKET; } - + public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->x = $this->getInt(); $this->y = $this->getInt(); $this->z = $this->getInt(); @@ -27,16 +41,30 @@ public function decode(){ $this->item = $this->getShort(); $this->meta = $this->getByte(); $this->eid = $this->getInt(); + if ($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9) { + $this->unknownInt1 = $this->getInt(); + return; + } $this->fx = $this->getFloat(); $this->fy = $this->getFloat(); $this->fz = $this->getFloat(); - $this->posX = $this->getFloat(); - $this->posY = $this->getFloat(); - $this->posZ = $this->getFloat(); + if ($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9) { + $this->posX = $this->getFloat(); + $this->posY = $this->getFloat(); + $this->posZ = $this->getFloat(); + } } - - public function encode(){ + public function encode(){ + /*$this->reset(); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + $this->putInt($this->face); + $this->putShort($this->item); + $this->putByte($this->meta); + $this->putInt($this->eid); + $this->putInt($this->unknownInt1);*/ } } diff --git a/src/network/query/QueryHandler.php b/src/network/query/QueryHandler.php index 7530d3b67..41bb81aa4 100644 --- a/src/network/query/QueryHandler.php +++ b/src/network/query/QueryHandler.php @@ -19,7 +19,7 @@ public function __construct(){ 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 5f64ac476..43a3a5b52 100755 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -11,8 +11,11 @@ abstract class RakNetDataPacket extends stdClass{ public $splitCount; public $splitID; public $splitIndex; + private $offset = 0; - + + public $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL; + abstract public function encode(); abstract public function decode(); @@ -20,11 +23,11 @@ abstract public function decode(); public function getBuffer(){ return $this->buffer; } - + public function getOffset(){ return $this->offset; } - + public function setBuffer($buffer = ""){ $this->buffer = $buffer; $this->offset = 0; @@ -36,6 +39,14 @@ protected function reset(){ abstract public function pid(); + public function getInternalPid() : int{ + $rawProtocol = $this->PROTOCOL; + $this->PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL; + $pid = (int) $this->pid(); + $this->PROTOCOL = $rawProtocol; + return $pid; + } + protected function getLong($unsigned = false){ return Utils::readLong($this->get(8), $unsigned); } @@ -123,18 +134,18 @@ protected function getSlot(){ 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)); } - protected function putSlot(Item $item){ - $this->putShort($item->getID()); + protected function putSlot(Int $protocolId, Item $item){ + $this->putShort(BlockAPI::convertHighItemIdsToOldItemIds($protocolId, $item->getID())); $this->putByte($item->count); $this->putShort($item->getMetadata()); } @@ -144,7 +155,7 @@ protected function putShort($v){ } 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 634e2e763..dabb8b751 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 f5318b9c5..906777805 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -4,10 +4,12 @@ class RakNetParser{ public $packet; private $buffer; + private $source; private $offset; - public function __construct(&$buffer){ - $this->buffer =& $buffer; + public function __construct(&$buffer, $source){ + $this->source = &$source; + $this->buffer = &$buffer; $this->offset = 0; if(strlen($this->buffer) > 0){ $this->parse(); @@ -18,7 +20,7 @@ public function __construct(&$buffer){ 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: @@ -56,8 +58,10 @@ private function parse(){ case RakNetInfo::DATA_PACKET_F: $this->packet->seqNumber = $this->getLTriad(); $this->packet->data = []; - - while(!$this->feof() and ($pk = $this->parseDataPacket()) instanceof RakNetDataPacket){ + $this->packet->ip = $this->source; + $PROTOCOL = PlayerAPI::decodeProtocol($this->packet->ip); + + while(!$this->feof() and ($pk = $this->parseDataPacket($PROTOCOL)) instanceof RakNetDataPacket){ $this->packet->data[] = $pk; } break; @@ -118,7 +122,7 @@ private function feof(){ return !isset($this->buffer[$this->offset]); } - private function parseDataPacket(){ + private function parseDataPacket($protocol = ProtocolInfo::CURRENT_PROTOCOL){ $packetFlags = $this->getByte(); $reliability = ($packetFlags & 0b11100000) >> 5; $hasSplit = ($packetFlags & 0b00010000) > 0; @@ -165,66 +169,8 @@ private function parseDataPacket(){ if(strlen($buffer) < ($length - 1)){ return false; } - - $data = match($pid){ - ProtocolInfo::PING_PACKET => new PingPacket(), - ProtocolInfo::PONG_PACKET => new PongPacket(), - ProtocolInfo::CLIENT_CONNECT_PACKET => new ClientConnectPacket(), - ProtocolInfo::SERVER_HANDSHAKE_PACKET => new ServerHandshakePacket(), - ProtocolInfo::DISCONNECT_PACKET => new DisconnectPacket(), - ProtocolInfo::LOGIN_PACKET => new LoginPacket(), - ProtocolInfo::LOGIN_STATUS_PACKET => new LoginStatusPacket(), - ProtocolInfo::READY_PACKET => new ReadyPacket(), - ProtocolInfo::MESSAGE_PACKET => new MessagePacket(), - ProtocolInfo::SET_TIME_PACKET => new SetTimePacket(), - ProtocolInfo::START_GAME_PACKET => new StartGamePacket(), - ProtocolInfo::ADD_MOB_PACKET => new AddMobPacket(), - ProtocolInfo::ADD_PLAYER_PACKET => new AddPlayerPacket(), - ProtocolInfo::REMOVE_PLAYER_PACKET => new RemovePlayerPacket(), - ProtocolInfo::ADD_ENTITY_PACKET => new AddEntityPacket(), - ProtocolInfo::REMOVE_ENTITY_PACKET => new RemoveEntityPacket(), - ProtocolInfo::ADD_ITEM_ENTITY_PACKET => new AddItemEntityPacket(), - ProtocolInfo::TAKE_ITEM_ENTITY_PACKET => new TakeItemEntityPacket(), - ProtocolInfo::MOVE_ENTITY_PACKET => new MoveEntityPacket(), - ProtocolInfo::MOVE_ENTITY_PACKET_POSROT => new MoveEntityPacket_PosRot(), - ProtocolInfo::ROTATE_HEAD_PACKET => new RotateHeadPacket(), - ProtocolInfo::MOVE_PLAYER_PACKET => new MovePlayerPacket(), - ProtocolInfo::REMOVE_BLOCK_PACKET => new RemoveBlockPacket(), - ProtocolInfo::UPDATE_BLOCK_PACKET => new UpdateBlockPacket(), - ProtocolInfo::ADD_PAINTING_PACKET => new AddPaintingPacket(), - ProtocolInfo::EXPLODE_PACKET => new ExplodePacket(), - ProtocolInfo::LEVEL_EVENT_PACKET => new LevelEventPacket(), - ProtocolInfo::TILE_EVENT_PACKET => new TileEventPacket(), - ProtocolInfo::ENTITY_EVENT_PACKET => new EntityEventPacket(), - ProtocolInfo::REQUEST_CHUNK_PACKET => new RequestChunkPacket(), - ProtocolInfo::CHUNK_DATA_PACKET => new ChunkDataPacket(), - ProtocolInfo::PLAYER_EQUIPMENT_PACKET => new PlayerEquipmentPacket(), - ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET => new PlayerArmorEquipmentPacket(), - ProtocolInfo::INTERACT_PACKET => new InteractPacket(), - ProtocolInfo::USE_ITEM_PACKET => new UseItemPacket(), - ProtocolInfo::PLAYER_ACTION_PACKET => new PlayerActionPacket(), - ProtocolInfo::HURT_ARMOR_PACKET => new HurtArmorPacket(), - ProtocolInfo::SET_ENTITY_DATA_PACKET => new SetEntityDataPacket(), - ProtocolInfo::SET_ENTITY_MOTION_PACKET => new SetEntityMotionPacket(), - ProtocolInfo::SET_HEALTH_PACKET => new SetHealthPacket(), - ProtocolInfo::SET_SPAWN_POSITION_PACKET => new SetSpawnPositionPacket(), - ProtocolInfo::ANIMATE_PACKET => new AnimatePacket(), - ProtocolInfo::RESPAWN_PACKET => new RespawnPacket(), - ProtocolInfo::SEND_INVENTORY_PACKET => new SendInventoryPacket(), - ProtocolInfo::DROP_ITEM_PACKET => new DropItemPacket(), - ProtocolInfo::CONTAINER_OPEN_PACKET => new ContainerOpenPacket(), - ProtocolInfo::CONTAINER_CLOSE_PACKET => new ContainerClosePacket(), - ProtocolInfo::CONTAINER_SET_SLOT_PACKET => new ContainerSetSlotPacket(), - ProtocolInfo::CONTAINER_SET_DATA_PACKET => new ContainerSetDataPacket(), - ProtocolInfo::CONTAINER_SET_CONTENT_PACKET => new ContainerSetContentPacket(), - ProtocolInfo::CHAT_PACKET => new ChatPacket(), - ProtocolInfo::ADVENTURE_SETTINGS_PACKET => new AdventureSettingsPacket(), - ProtocolInfo::ENTITY_DATA_PACKET => new EntityDataPacket(), - ProtocolInfo::SET_ENTITY_LINK_PACKET => new SetEntityLinkPacket(), - ProtocolInfo::PLAYER_INPUT_PACKET => new PlayerInputPacket(), - default => new UnknownPacket($pid) - }; - + + $data = PacketPool::getPacket($pid, $protocol); $data->reliability = $reliability; $data->hasSplit = $hasSplit; $data->messageIndex = $messageIndex; @@ -242,4 +188,4 @@ private function getInt($unsigned = false){ return Utils::readInt($this->get(4), $unsigned); } -} \ No newline at end of file +} diff --git a/src/plugin/DummyPlugin.php b/src/plugin/DummyPlugin.php index 34d8abcc2..8b5b4e51a 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 f00388e69..0439b5bbf 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -40,7 +40,7 @@ private function createBlank(){ 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 @@ private function writeLocationTable(){ $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 @@ public function backupLocTable(){ }finally{ fclose($file); } - + } public function getXZ($index, &$X = null, &$Z = null){ @@ -212,7 +212,7 @@ public function unloadChunk($X, $Z, $save = true){ 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 @@ public function setMiniChunk($X, $Z, $Y, $data){ 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 @@ public function getBlockID($x, $y, $z){ $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 @@ public function setBlockID($x, $y, $z, $block){ 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 @@ public function setBlockID($x, $y, $z, $block){ $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 @@ public function setBlockDamage($x, $y, $z, $damage){ $Z = $z >> 4; $Y = $y >> 4; $damage &= 0x0F; - + $index = self::getIndex($X, $Z); $aX = $x & 0xf; $aZ = $z & 0xf; @@ -467,11 +467,11 @@ public function getBlock($x, $y, $z){ 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 @@ public function getBlock($x, $y, $z){ $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 @@ public function setBlock($x, $y, $z, $block, $meta = 0){ $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 @@ public function setBlock($x, $y, $z, $block, $meta = 0){ ++$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 d46782348..e9ac25f66 100644 --- a/src/recipes/CraftingRecipes.php +++ b/src/recipes/CraftingRecipes.php @@ -6,7 +6,7 @@ class CraftingRecipes{ const TYPE_STONECUTTER = 2; private static $small = [ // Probably means craftable on crafting bench and in inventory. Name it better! - // Building + // Building "CLAY:?x4=>CLAY_BLOCK:0x1", "WOODEN_PLANKS:?x4=>WORKBENCH:0x1", "GLOWSTONE_DUST:?x4=>GLOWSTONE_BLOCK:0x1", @@ -76,7 +76,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", diff --git a/src/structure/Structure.php b/src/structure/Structure.php index eaa51259d..c7bc25c0c 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 @@ public function __construct($struct, $width, $symToID = []){ $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 @@ protected function placeBlock($level, $sym, $tv){ $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 @@ public function build($level, $centerX, $centerY, $centerZ){ ++$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 e033c274d..0762ec4dc 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 5581a63b3..f43cee272 100644 --- a/src/utils/AsyncMultipleQueue.php +++ b/src/utils/AsyncMultipleQueue.php @@ -111,8 +111,8 @@ public function __construct(){ } } } - + public function __destruct(){} - + public function run(){} }*/ diff --git a/src/utils/Config.php b/src/utils/Config.php index 23b3c1536..a196879ac 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -168,9 +168,6 @@ private function writeProperties(){ 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 @@ public function fixYAMLIndexes($str){ 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 @@ private function parseList($content){ } /** - * @param $default - * @param $data * * @return integer */ @@ -250,7 +242,6 @@ public function reload(){ } /** - * @param $k * * @return boolean|mixed */ @@ -258,16 +249,11 @@ public function &__get($k){ 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 @@ public function &get($k){ } /** - * @param $k * @param bool $v */ public function set($k, $v = true){ @@ -288,7 +273,6 @@ public function set($k, $v = true){ } /** - * @param $k * * @return boolean */ @@ -297,7 +281,6 @@ public function __isset($k){ } /** - * @param $k * @param bool $lowercase If set, searches Config in single-case / lowercase. * * @return boolean @@ -312,16 +295,10 @@ public function exists($k, $lowercase = false){ } } - /** - * @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 0d22f2c0e..36cfb41af 100644 --- a/src/utils/Container.php +++ b/src/utils/Container.php @@ -43,7 +43,6 @@ public function check($target){ return true; } - public function __toString(){ return $this->payload; } diff --git a/src/utils/LightUtils.php b/src/utils/LightUtils.php index 83820d8fc..253d78340 100644 --- a/src/utils/LightUtils.php +++ b/src/utils/LightUtils.php @@ -13,7 +13,7 @@ public static function getLightValueFromNearbySource($source, $block){ $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 5cc5d5c3c..462f4075d 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 @@ public function genRandInt(){ $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 e35c7f256..bc521acfe 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 @@ $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 @@ function int32(){ return $y & 0xFFFFFFFF; } - + /* generates a random number on [0,1]-real-interval */ function real_closed(){ @@ -325,15 +323,15 @@ function nextIntBndn($bound){ 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 92eb05abf..9e8de9562 100644 --- a/src/utils/RailLogic.php +++ b/src/utils/RailLogic.php @@ -4,7 +4,7 @@ class RailLogic { public $x, $y, $z; public $level; - + /** * @var Vector3[] */ @@ -18,7 +18,7 @@ public function __construct(RailBaseBlock $rail){ $this->y = $rail->y; $this->z = $rail->z; $this->isStraight = $id === POWERED_RAIL; - + $this->updateConnections($meta); } public function getRail($v){ @@ -29,18 +29,18 @@ public function getRail($v){ }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){ 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(){ 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){ $logic = $this->getRail($this->railPositions[$ind]); @@ -52,7 +52,7 @@ public function removeSoftConnections(){ } } } - + public function connectsTo(RailLogic $logic){ foreach($this->railPositions as $rpos){ if(($rpos->x === $logic->x) && ($rpos->z === $logic->z)){ @@ -61,11 +61,11 @@ public function connectsTo(RailLogic $logic){ } return false; } - + public function canConnectTo(RailLogic $rail){ return $this->connectsTo($rail) || !(count($this->railPositions) == 2); } - + public function hasNeighborRail($x, $y, $z){ $logic = $this->getRail(new Vector3($x, $y, $z)); if($logic === null){ @@ -74,9 +74,9 @@ public function hasNeighborRail($x, $y, $z){ $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){ $hasZneg = $this->hasNeighborRail($this->x, $this->y, $this->z - 1); $hasZpos = $this->hasNeighborRail($this->x, $this->y, $this->z + 1); @@ -89,18 +89,18 @@ public function place($b, $b1){ 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($state === -1){ if($hasZneg || $hasZpos) $state = 0; if($hasXneg || $hasXpos) $state = 1; - + if(!$this->isStraight){ if($b){ if($hasZpos && $hasXpos) $state = 6; @@ -115,7 +115,6 @@ public function place($b, $b1){ } } } - if($state === 0){ if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4; @@ -124,13 +123,13 @@ public function place($b, $b1){ 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){ $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)){ //this.logicWorld.setBlockMetadataWithNotify(this.railX, this.railY, this.railZ, var8, 3); $bl = $this->level->getBlockWithoutVector($this->x, $this->y, $this->z); @@ -143,33 +142,33 @@ public function place($b, $b1){ 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; } return false; } - + 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; @@ -184,23 +183,23 @@ public function connectTo(RailLogic $logic){ 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){ $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){ - + $this->railPositions = []; - + switch($meta){ case 0: $this->railPositions[] = new Vector3($this->x, $this->y, $this->z - 1); diff --git a/src/utils/Random.php b/src/utils/Random.php index f2b146df1..b0011fef2 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 2c07172ec..fff741bb3 100644 --- a/src/utils/StopMessageThread.php +++ b/src/utils/StopMessageThread.php @@ -9,9 +9,9 @@ public function __construct(PocketMinecraftServer $server, $msg){ $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 a6f8a08c1..c3cb47f32 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -21,25 +21,25 @@ public static function getEntityTypeByID($id){ 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 @@ public static function sint32($r){ } 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 @@ public static function wrapAngleTo180($angle) 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 @@ public static function getCallableIdentifier(callable $variable){ 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,7 +181,7 @@ public static function getIP($force = false){ return Utils::$ip; } - + public static function makeHeaders($json){ $arr = json_decode($json); $rarr = []; @@ -190,12 +190,12 @@ public static function makeHeaders($json){ } 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 @@ public static function readDataArray($str, $len = 10, &$offset = null){ } return $data; } - + public static function readTriad($str){ return strlen($str) < 3 ? false : @unpack("N", "\x00$str")[1]; } @@ -444,11 +444,11 @@ public static function writeDataArray($data){ } 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 @@ public static function writeTriad($value){ 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 @@ public static function manh_distance($pos1, $pos2){ 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 @@ public static function distance_noroot($pos1, $pos2){ $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 @@ public static function distance($pos1, $pos2){ 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 @@ public static function writeBool($b){ } 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 e44c7bd38..b92e614db 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 @@ public function __construct(Position $center, $size){ $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 @@ public function sub_expl($i, $mRays, $j, $k){ }else{ $vx = $vy = $vz = 0; } - + $px = $this->source->x; $py = $this->source->y; $pz = $this->source->z; @@ -64,19 +64,19 @@ public function sub_expl($i, $mRays, $j, $k){ $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 @@ public function explode(){ $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 @@ public function explode(){ ]) === false){ return false; } - + $mRays = $this->rays - 1; $i = 0; for($j = 0; $j <= $mRays; ++$j){ @@ -126,21 +126,21 @@ public function explode(){ $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 @@ public function explode(){ } } //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 @@ public function explode(){ $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 @@ public function explode(){ } } } - + 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 fbec0a710..200d91a98 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -6,27 +6,27 @@ class Level{ */ public $entities; /** - * This is an array of entities in this world. + * This is an array of entities in this world. * @var Entity[] */ public $entityList; - + public $entityListPositioned = []; public $entitiesInLove = []; - + /** * @var Player[] */ public $players = []; - + public $tiles, $blockUpdates, $nextSave, $level, $mobSpawner, $totalMobsAmount = 0; private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime; - + public $randInt1, $randInt2; public $queuedBlockUpdates = []; - + public $forceDisableBlockQueue = false; - + public static $randomUpdateBlocks = [ FIRE => true, FARMLAND => true, @@ -45,7 +45,7 @@ class Level{ ICE => true, LEAVES => true ]; - + public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ $this->server = ServerAPI::request(); $this->level = $level; @@ -72,29 +72,29 @@ public function __construct(PMFLevel $level, Config $entities, Config $tiles, Co public function close(){ $this->__destruct(); } - + 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; - + return true; } 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); @@ -104,66 +104,66 @@ public function rayTraceBlocks(Vector3 $start, Vector3 $end){ $v14 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end); 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? 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; - + $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($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){ $v42 = $yEnd > $yStart ? 0 : 1; - + $start->x += $v27 * $v23; $start->y = $v17; $start->z += $v31 * $v23; }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; - + $yStart = floor($start->y); if($v42 == 1) --$yStart; - + $zStart = floor($start->z); if($v42 == 3) --$zStart; - + [$blockID, $blockMeta] = $this->level->getBlock($xStart, $yStart, $zStart); $block = StaticBlock::getBlock($blockID); @@ -173,10 +173,10 @@ public function rayTraceBlocks(Vector3 $start, Vector3 $end){ if($v38 != null) return $v38; } } - + return null; } - + public function isLavaInBB($aabb){ $minX = floor($aabb->minX); $maxX = floor($aabb->maxX + 1); @@ -184,20 +184,20 @@ public function isLavaInBB($aabb){ $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){ $blockId = $this->level->getBlockID($x, $y, $z); - + if($blockId == LAVA || $blockId == STILL_LAVA) return true; } } } - + return false; } - + public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, Entity $entity){ $minX = floor($aabb->minX); $maxX = ceil($aabb->maxX); @@ -205,9 +205,9 @@ public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, E $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){ @@ -220,12 +220,12 @@ public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, E $appliedVelocity = true; StaticBlock::$prealloc[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec); } - + } } } } - + if($velocityVec->length() > 0){ //also checks is player flying $velocityVec = $velocityVec->normalize(); //TODO do not use vec methods $v18 = 0.014; @@ -233,12 +233,10 @@ public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, E $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,14 +247,14 @@ public function getCubes(Entity $e, AxisAlignedBB $aABB) { $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){ $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; } @@ -264,10 +262,10 @@ public function getCubes(Entity $e, AxisAlignedBB $aABB) { } } } - + return $aABBs; } - + public function __destruct(){ if(isset($this->level)){ $this->save(false, false, false, false); @@ -276,7 +274,7 @@ public function __destruct(){ } unset($this->mobSpawner->level); } - + public function isDay(){ return $this->getTime() % 19200 < TimeAPI::$phases["sunset"]; } @@ -294,7 +292,7 @@ public function save($force = false, $entities = true, $tiles = true, $blockupda if($entities){ $entities = []; - + foreach($this->entityList as $entity){ if($entity instanceof Entity){ $entities[] = $entity->createSaveData(); @@ -355,7 +353,7 @@ public function freeAllChunks(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()){ return false; //not the same world @@ -368,12 +366,12 @@ public function checkCollisionsFor(Entity $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 + if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla foreach($this->players as $p){ if(!$p->isSleeping || $p->sleepingTime < 100){ return false; @@ -385,14 +383,14 @@ public function checkSleep(){ //TODO events? $p->stopSleep(); } } - + 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){ arsort($this->changedCount); $reorder = false; @@ -407,13 +405,13 @@ public function checkThings(){ unset($this->changedBlocks[$index]); } $this->changedCount = []; - + if($reorder){ foreach($this->players as $p){ $p->orderChunks(); } } - + if(count($this->changedBlocks) > 0){ foreach($this->changedBlocks as $i => $blocks){ foreach($blocks as $b){ @@ -421,7 +419,7 @@ public function checkThings(){ $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,7 +428,7 @@ public function checkThings(){ $this->changedBlocks = []; } } - + if($this->nextSave < $now){ $this->save(false, true, true, true); } @@ -475,29 +473,29 @@ public function fastSetBlockUpdateMeta($x, $y, $z, $meta, $updateBlock = false){ $this->updateNeighborsAt($x, $y, $z, $id); } } - + 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); $block = $this->level->getBlockID($x + 1, $y, $z); 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); $block = $this->level->getBlockID($x, $y + 1, $z); 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); $block = $this->level->getBlockID($x, $y, $z + 1); 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){ $oldID = $this->level->getBlockID($x, $y, $z); - + $this->level->setBlock($x, $y, $z, $id, $meta); - + if($tiles){ //TODO rewrite $this->server->api->tile->invalidateAll($this, $x, $y, $z); } @@ -506,7 +504,7 @@ public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = } $this->addBlockToSendQueue($x, $y, $z, $id, $meta); } - + public function onTick(PocketMinecraftServer $server, $currentTime){ if(!$this->stopTime) ++$this->time; for($cX = 0; $cX < 16; ++$cX){ @@ -528,7 +526,7 @@ public function onTick(PocketMinecraftServer $server, $currentTime){ } $this->totalMobsAmount = 0; $post = []; - + foreach($this->entityList as $k => $e){ if(!($e instanceof Entity)){ unset($this->entityList[$k]); @@ -536,27 +534,27 @@ public function onTick(PocketMinecraftServer $server, $currentTime){ //TODO try to remove from $entityListPositioned? continue; } - + $dd = CORRECT_ENTITY_CLASSES[$e->class] ?? false; 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])){ unset($this->entityListPositioned[$index][$k]); } - + continue; } - $curChunkX = (int)$e->x >> 4; - $curChunkZ = (int)$e->z >> 4; + $curChunkX = (int) $e->x >> 4; + $curChunkZ = (int) $e->z >> 4; if($e->class === ENTITY_MOB && !$e->isPlayer()){ ++$this->totalMobsAmount; } @@ -564,14 +562,14 @@ public function onTick(PocketMinecraftServer $server, $currentTime){ $e->update($currentTime); if(!$e->isPlayer()) $post[] = $k; } - + if($e instanceof Entity){ - $newChunkX = (int)$e->x >> 4; - $newChunkZ = (int)$e->z >> 4; + $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){ $e->chunkX = $newChunkX; $e->chunkZ = $newChunkZ; @@ -587,30 +585,27 @@ public function onTick(PocketMinecraftServer $server, $currentTime){ 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){ $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); + $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"])){ unset($this->entityListPositioned["$curChunkX $curChunkZ"][$k]); } } - + $this->checkSleep(); - + if($server->ticks % 100 === 0){ $this->mobSpawner->handle(); } - - + foreach($this->players as $player){ foreach($post as $eid){ $e = $this->entityList[$eid] ?? false; @@ -620,7 +615,7 @@ public function onTick(PocketMinecraftServer $server, $currentTime){ $player->addEntityMovementUpdateToQueue($e); } $player->sendEntityMovementUpdateQueue(); - + foreach($this->queuedBlockUpdates as $ind => $update){ $x = $update[0]; $y = $update[1]; @@ -632,10 +627,10 @@ public function onTick(PocketMinecraftServer $server, $currentTime){ } $player->sendBlockUpdateQueue(); } - + $this->queuedBlockUpdates = []; } - + public function isBoundingBoxOnFire(AxisAlignedBB $bb){ $minX = floor($bb->minX); $maxX = floor($bb->maxX + 1); @@ -643,7 +638,7 @@ public function isBoundingBoxOnFire(AxisAlignedBB $bb){ $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){ @@ -652,14 +647,14 @@ public function isBoundingBoxOnFire(AxisAlignedBB $bb){ } } } - + 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; + $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){ @@ -677,14 +672,13 @@ public function getEntitiesInAABBOfType(AxisAlignedBB $bb, $class){ 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; + $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){ @@ -702,20 +696,20 @@ public function getEntitiesInAABB(AxisAlignedBB $bb){ } return $ents; } - + 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){ 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($ret === true){ if(!($pos instanceof Position)){ $pos = new Position($pos->x, $pos->y, $pos->z, $this); } @@ -731,15 +725,15 @@ public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = fa $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){ $this->server->api->tile->invalidateAll($this, $pos->x, $pos->y, $pos->z); } - + if($update === true){ $this->updateNeighborsAt($pos->x, $pos->y, $pos->z, $oldID); } - + } return $ret; } @@ -857,7 +851,7 @@ public function getSpawn(){ } return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this); } - + /** * @param number $x * @param number $y @@ -865,15 +859,14 @@ public function getSpawn(){ * @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); + $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){ @@ -922,11 +915,11 @@ public function checkTime(){ $this->time -= 20 * 13; } } - + public function isTimeStopped(){ return $this->stopTime; } - + public function stopTime(){ $this->stopTime = true; $this->startCheck = 0; diff --git a/src/world/MobSpawner.php b/src/world/MobSpawner.php index 48d63306b..53bf5850d 100644 --- a/src/world/MobSpawner.php +++ b/src/world/MobSpawner.php @@ -8,7 +8,7 @@ class MobSpawner{ public $playerAffectedEIDS = []; public $entityAffectedPlayers = []; public static $MOB_LIMIT = 50; - + public function __construct(Level $level){ $this->server = ServerAPI::request(); $this->level = $level; @@ -17,12 +17,12 @@ public function __construct(Level $level){ public function countEntities(){ return $this->level->totalMobsAmount; } - + 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){ @@ -31,16 +31,16 @@ public function checkDespawn(Living $living){ }else{ $diffX = $living->x - $player->x; $diffZ = $living->z - $player->z; - $dist = $diffX*$diffX + $diffZ*$diffZ; + $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){ return false; //not spawning @@ -48,7 +48,7 @@ public function handle(){ $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}."); - + return $this->spawnMobs(); } @@ -65,39 +65,38 @@ public function spawnMobs(){ }else{ return false; } - + 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; + $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){ - + $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){ continue; } - + $data = $this->genPosData($xMob, $y + 0.5, $zMob); if($baby != 2) $data["IsBaby"] = $baby; - + $e = $this->server->api->entity->add($this->level, 2, $type, $data); - + if($e instanceof Entity){ $this->server->api->entity->spawnToAll($e); ConsoleAPI::debug("$type spawned at $xMob, $y, $zMob"); @@ -107,16 +106,15 @@ public function spawnMobs(){ }else{ $this->playerAffectedEIDS[$player->entity->eid][$e->eid] = true; } - + $this->entityAffectedPlayers[$e->eid] = $player->entity->eid; - + } } - - + return true; } - + private function genPosData($x, $y, $z){ return [ "x" => $x + 0.5, @@ -124,7 +122,7 @@ private function genPosData($x, $y, $z){ "z" => $z + 0.5 ]; } - + protected function getSafeY($x, $z, $grassOnly = false, $highMob = false){ //first safe block //TODO check boundingbox $allowed = []; for($y = 0; $y < 128; ++$y){ @@ -132,14 +130,14 @@ protected function getSafeY($x, $z, $grassOnly = false, $highMob = false){ //fir $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 2e6a6dfc7..b3f535f51 100644 --- a/src/world/MovingObjectPosition.php +++ b/src/world/MovingObjectPosition.php @@ -1,4 +1,5 @@ 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 */ @@ -49,7 +49,6 @@ public static function fromBlock($x, $y, $z, $side, Vector3 $hitVector){ } /** - * @param Entity $entity * * @return MovingObjectPosition */ diff --git a/src/world/Position.php b/src/world/Position.php index e83861b26..dff854679 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -32,7 +32,7 @@ public function distance($x = 0, $y = 0, $z = 0){ return parent::distance($x, $y, $z); } - + public function __toString(){ return "Position(level=" . $this->level->getName() . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; } diff --git a/src/world/Tile.php b/src/world/Tile.php index e270a68ba..2ffefb841 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -14,9 +14,9 @@ class Tile extends Position{ public $metadata; public $closed; private $server; - + public $scheduledUpdate, $lastUpdate; - + function __construct(Level $level, $id, $class, $x, $y, $z, $data = []){ $this->server = ServerAPI::request(); $this->level = $level; @@ -462,7 +462,6 @@ public function getName(){ return $this->name; } - public function setPosition(Vector3 $pos){ if($pos instanceof Position){ $this->level = $pos->level; diff --git a/src/world/generator/SuperflatGenerator.php b/src/world/generator/SuperflatGenerator.php index a36d44159..f6f32c0fb 100644 --- a/src/world/generator/SuperflatGenerator.php +++ b/src/world/generator/SuperflatGenerator.php @@ -35,7 +35,7 @@ public function __construct(array $options = []){ $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 @@ public function parsePreset($preset){ $this->structure[$y] = new AirBlock(); } - for($Y = 0; $Y < 8; ++$Y){ $this->chunks[$Y] = ""; $startY = $Y << 4; @@ -132,7 +131,7 @@ public function populateLevel(){ $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 afa04d02f..d485d40ba 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 @@ /***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 18c0d1d7d..c5855ebec 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -35,7 +35,7 @@ public function generate(){ 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 227a66933..c23f0494e 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){ $this->generatorCollection[$o] = new NoiseGeneratorPerlin($random); } } - + public function getValue($x, $y){ $noise = 0; $scale = 1; @@ -24,15 +24,15 @@ public function getValue($x, $y){ } 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){ 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){ $d2 = $int1 * $d1 * $par1; $d3 = $int2 * $d1 * $par2; @@ -43,7 +43,7 @@ public function generateNoiseOctaves($int1, $int2, $int3, $int4, $int5, $int6, $ $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); diff --git a/src/world/generator/noise/NoiseGeneratorPerlin.php b/src/world/generator/noise/NoiseGeneratorPerlin.php index edad5c3fc..2d812a8f2 100644 --- a/src/world/generator/noise/NoiseGeneratorPerlin.php +++ b/src/world/generator/noise/NoiseGeneratorPerlin.php @@ -27,7 +27,7 @@ public function __construct(MTRandom $random){ } } - + public function getValue($d, $d1, $d2 = 0){ $d3 = $d + $this->xCoord; $d4 = $d1 + $this->yCoord; @@ -44,14 +44,14 @@ public function getValue($d, $d1, $d2 = 0){ $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,7 +63,7 @@ public function getValue($d, $d1, $d2 = 0){ ) ); } - + public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7){ if($int2 === 1){ $n = 0; @@ -152,7 +152,7 @@ public static final function curve($par1, $par2, $par3){ 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); } diff --git a/src/world/generator/object/NetherReactorStructure.php b/src/world/generator/object/NetherReactorStructure.php index 30b0624db..78006ab95 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 4616ac266..d2edd4931 100644 --- a/src/world/generator/object/tree/BigTreeObject.php +++ b/src/world/generator/object/tree/BigTreeObject.php @@ -61,5 +61,4 @@ public function placeObject(Level $level, Vector3 $pos, $type){ */ } - } \ 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 916422599..e745c0a45 100644 --- a/src/world/generator/object/tree/PineTreeObject.php +++ b/src/world/generator/object/tree/PineTreeObject.php @@ -69,5 +69,4 @@ public function placeObject(Level $level, Vector3 $pos, Random $random){ } } - } \ 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 b496454b0..70dacdebb 100644 --- a/src/world/generator/object/tree/SpruceTreeObject.php +++ b/src/world/generator/object/tree/SpruceTreeObject.php @@ -60,5 +60,4 @@ public function placeObject(Level $level, Vector3 $pos, Random $random){ } } - } \ No newline at end of file diff --git a/src/world/generator/vanilla/BiomeSource.php b/src/world/generator/vanilla/BiomeSource.php index 821d7f002..ad7569e4a 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 @@ public function __construct(Level $level){ $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 9ec18d457..91289d8fc 100644 --- a/src/world/generator/vanilla/VanillaGenerator.php +++ b/src/world/generator/vanilla/VanillaGenerator.php @@ -1,4 +1,5 @@ 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){ ClayFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(128), $chunkZWorld + $this->rand->nextInt(16)); @@ -98,11 +99,10 @@ public function populateChunk($chunkX, $chunkZ) 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); - - + $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; @@ -145,7 +145,7 @@ public function populateChunk($chunkX, $chunkZ) $l15 = $chunkZWorld + $this->rand->nextInt(16) + 8; Feature::$MUSHROOM_RED->place($this->level, $this->rand, $j9, $j13, $l15); } - + } public function generateChunk($chunkX, $chunkZ) { @@ -155,7 +155,7 @@ public function generateChunk($chunkX, $chunkZ) $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){ $index = ($chunkZ << 4) + $chunkX; $this->level->level->chunks[$index][$Y] = $chunkz[$Y]; @@ -163,9 +163,9 @@ public function generateChunk($chunkX, $chunkZ) $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){ @@ -190,7 +190,7 @@ public function generateHeightmap($x, $z, &$chunkz){ for($blockZ = 0; $blockZ < 16; ++$blockZ){ for($Y = 7; $Y >= 0; --$Y){ for($cY = 15; $cY >= 0; --$cY){ - $blockY = $Y*16 + $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 +202,7 @@ public function generateHeightmap($x, $z, &$chunkz){ } $this->heightMap[$x + ($z * 16)] = $heightmapCPtr; } - + /**Vanilla Functions Implementation starts here**/ /** * Decorate terrain with grass, water & other stuff. Uses ZXY placement format @@ -221,7 +221,7 @@ public function buildSurfaces($chunkX, $chunkZ, &$chunks, $biomes){ $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; @@ -250,7 +250,7 @@ public function buildSurfaces($chunkX, $chunkZ, &$chunks, $biomes){ $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); @@ -268,8 +268,7 @@ public function buildSurfaces($chunkX, $chunkZ, &$chunks, $biomes){ } } } - - + 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); @@ -280,12 +279,12 @@ public function prepareHeights($chunkX, $chunkZ, &$chunks, $biomes, $temperature $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){ $f9 = $f; $f10 = $f2; @@ -297,11 +296,11 @@ public function prepareHeights($chunkX, $chunkZ, &$chunks, $biomes, $temperature 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){ $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 +319,9 @@ public function prepareHeights($chunkX, $chunkZ, &$chunks, $biomes, $temperature } } } - + public function getHeights($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ){ - $heights = array_fill(0, $scaleX*$scaleY*$scaleZ, 0); + $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,24 +330,24 @@ public function getHeights($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ) $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)); + $i2 = ((int) (16 / $scaleX)); for($j2 = 0; $j2 < $scaleX; ++$j2){ - $k2 = (int)($j2 * $i2 + $i2 / 2); + $k2 = (int) ($j2 * $i2 + $i2 / 2); for($l2 = 0; $l2 < $scaleZ; ++$l2){ - $i3 = (int)($l2 * $i2 + $i2 / 2); + $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; $d6 = $this->depthNoises[$l1] / 8000; if($d6 < 0) $d6 = -$d6 * 0.3; - + $d6 = $d6 * 3 - 2; if($d6 < 0){ $d6 /= 2; @@ -360,25 +359,25 @@ public function getHeights($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ) if($d6 > 1) $d6 = 1; $d6 /= 8; } - + if($d5 < 0) $d5 = 0; - + $d5 += 0.5; $d6 = ($d6 * $scaleY) / 16; $d7 = ($scaleY / 2 + $d6 * 4); ++$l1; for($j3 = 0; $j3 < $scaleY; ++$j3){ $d8 = 0; - $d9 = (((float)$j3 - $d7) * 12) / $d5; + $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; - + $d8 -= $d9; if($j3 > $scaleY - 4){ $d13 = ($j3 - ($scaleY - 4)) / 3; @@ -389,7 +388,7 @@ public function getHeights($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ) } } } - + return $heights; } diff --git a/src/world/generator/vanilla/biome/Biome.php b/src/world/generator/vanilla/biome/Biome.php index a3f38ac25..5219d011a 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 @@ public static function recalc(){ 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 @@ public static function __getBiome($temp, $rain){ 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 f98bdf9ef..cc927f7f8 100644 --- a/src/world/generator/vanilla/feature/BirchFeature.php +++ b/src/world/generator/vanilla/feature/BirchFeature.php @@ -13,7 +13,7 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ 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 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ } } } - + for($i12 = 0; $i12 < $nextInt; ++$i12){ $blockID = $level->level->getBlockID($x, $y + $i12, $z); if($blockID == 0 || $blockID == LEAVES){ @@ -56,7 +56,7 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ return false; } return false; - + } } diff --git a/src/world/generator/vanilla/feature/ClayFeature.php b/src/world/generator/vanilla/feature/ClayFeature.php index 32e51e0c7..07c9506cb 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 @@ public static function place(Level $level, MTRandom $rand, $x, $y, $z){ $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 f52426adc..d38ce7c89 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 @@ public static function init(){ 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 2bdacb8f1..6b9e02bfc 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 e4aa83d4f..82f464f75 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 115473d98..38ff7c6dc 100644 --- a/src/world/generator/vanilla/feature/PineFeature.php +++ b/src/world/generator/vanilla/feature/PineFeature.php @@ -32,7 +32,7 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ } } 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 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ } } } - + if($k2 >= 1 && $i3 == $y + $i1 + 1){ --$k2; continue; @@ -56,7 +56,7 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ ++$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 c32c7d6f8..6a05710ca 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 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ } } } - + if($z2){ $blockID = $level->level->getBlockID($x, $y - 1, $z); if(($blockID == GRASS || $blockID == DIRT) && $y < (128 - $nextInt) - 1){ @@ -49,7 +50,7 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ } } } - + 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 2b4f5a2a0..3ffd91fd6 100644 --- a/src/world/generator/vanilla/feature/TreeFeature.php +++ b/src/world/generator/vanilla/feature/TreeFeature.php @@ -1,4 +1,5 @@ = (($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){ @@ -29,7 +30,7 @@ public function place(Level $level, MTRandom $rand, $x, $y, $z){ } for($i5 = ($y - 3) + $nextInt; $i5 <= $y + $nextInt; ++$i5){ $i6 = $i5 - ($y + $nextInt); - $i7 = (int)(1 - ($i6 / 2)); + $i7 = (int) (1 - ($i6 / 2)); for($i8 = $x - $i7; $i8 <= $x + $i7; ++$i8){ $i9 = $i8 - $x; for($i10 = $z - $i7; $i10 <= $z + $i7; ++$i10){