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 f6e4e54ed..7cbb57a5d 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/ChatAPI.php b/src/API/ChatAPI.php index ff6aaf2ac..21747303e 100644 --- a/src/API/ChatAPI.php +++ b/src/API/ChatAPI.php @@ -123,8 +123,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 574e42e7c..d7046f490 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/LevelAPI.php b/src/API/LevelAPI.php index b9fcb543b..e1129ed59 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -41,7 +41,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){ @@ -49,8 +49,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"); @@ -62,13 +61,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"], @@ -106,7 +105,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/PluginAPI.php b/src/API/PluginAPI.php index 100671eb5..38eb532ac 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -154,20 +154,20 @@ private function loadAll(){ continue; } 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); @@ -272,7 +272,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){ @@ -316,4 +316,3 @@ public function __construct($name, $version = false){ } } - diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 4cadc27f6..7b7da64a4 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 @@ local. * Should be modified only by Player::addEntity or Player::removeEntity. @@ -177,9 +177,9 @@ class Player{ * @var array */ public $lastLocalEID = 0; - + public $invisibleFor = []; - + /** * @param integer $clientID * @param string $ip @@ -209,27 +209,27 @@ public function __construct($clientID, $ip, $port, $MTU){ $this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->buffer->data = []; - + $this->entityDataQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->entityDataQueue->data = []; - + $this->entityMovementQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->entityMovementQueue->data = []; $this->blockUpdateQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->blockUpdateQueue->data = []; - + $this->chatMessagesQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->chatMessagesQueue->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); } - + /** - * Gives a new local id for entity. + * Gives a new local id for entity. * @param Entity $e * @return boolean */ @@ -240,11 +240,11 @@ public function addEntity(Entity $e){ //ConsoleAPI::info("Adding Entity {$e->eid} => {$local}"); return true; } - + public function hasEntity(Entity $e){ return isset($this->global2localEID[$e->eid]); } - + /** * Removes an entity. * @param Entity $e @@ -258,14 +258,14 @@ public function removeEntity(Entity $e){ //ConsoleAPI::info("Removing Entity {$e->eid} => {$local}"); return true; } - + public function __get($name){ if(isset($this->{$name})){ return ($this->{$name}); } return null; } - + /** * @param int $slot inventory slot. -1 - drop * @param int $id @@ -276,37 +276,37 @@ public function addExpectedSetSlotPacket(int $slot, int $id, int $meta, int $cou ConsoleAPI::debug("Adding expected set slot: $slot $id $meta $count"); $this->expectedSetSlotPackets[++$this->expectedSetSlotIndex]["$slot $id $meta $count"] = $this->server->ticks; } - + public function isExpectedSetSlot(int $slot, Item $item){ $index = "$slot {$item->getID()} {$item->getMetadata()} {$item->count}"; foreach($this->expectedSetSlotPackets as $i => $stuff){ $a = key($stuff); - + if($index == $a){ return $i; } } return false; } - + public function removeExpectedSetSlot(int $index){ unset($this->expectedSetSlotPackets[$index]); } - + public function getSpawn(){ return $this->spawnPosition; } - + public function setBedPosition(?Position $bedPos){ if($bedPos != null) $this->bedPosition = [$bedPos->level->getName(), (int)$bedPos->x, (int)$bedPos->y, (int)$bedPos->z]; else $this->bedPosition = null; $this->data->set("bed-position", $this->bedPosition); } - - + + /** * @param Vector3 $pos position of the top block of the bed - * + * * @return boolean */ public function sleepOn(Position $pos){ @@ -317,7 +317,7 @@ public function sleepOn(Position $pos){ } } } - + $this->setBedPosition($pos); $this->isSleeping = $pos; $this->sleepingTime = 0; @@ -331,7 +331,7 @@ public function sleepOn(Position $pos){ $this->entity->updateMovement(); $this->entity->updateMetadata(); } - + return true; } @@ -480,7 +480,7 @@ public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $re if($this->connected === false) return false; if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) return []; if(!$this->convertToLocalEIDPacket($packet)) return false; - + $packet->encode(); $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk->data[] = $packet; @@ -489,11 +489,11 @@ public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $re if($recover !== false){ $this->recoveryQueue[$pk->seqNumber] = $pk; } - + $this->send($pk); return [$pk->seqNumber]; } - + /** * Sends data packet that will be recovered only once. Packet MAY not arrive at all or arrive out of order. * @param RakNetDataPacket $packet @@ -502,7 +502,13 @@ public function dataPacket(RakNetDataPacket $packet){ if($this->connected === false) return false; if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) return; if(!$this->convertToLocalEIDPacket($packet)) return false; - + + if(PacketPool::isPacketExist($packet->pid(), $this->PROTOCOL) != true){ + return; + } + + $packet->PROTOCOL = $this->PROTOCOL; + $packet->encode(); $len = strlen($packet->buffer) + 1; $MTU = $this->MTU - 24; @@ -529,22 +535,22 @@ public function dataPacketAlwaysRecover(RakNetDataPacket $packet){ if($this->connected === false) return false; if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) return false; if(!$this->convertToLocalEIDPacket($packet)) return false; - + $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk->data[] = $packet; $pk->seqNumber = $this->counter[0]++; $pk->sendtime = microtime(true); - + $packet->encode(); $len = strlen($packet->buffer) + 1; $MTU = $this->MTU - 24; if($len > $MTU){ return $this->sendBigPacketAlwaysRecover($packet); //TODO fix } - + $packet->messageIndex = $this->counter[3]++; $packet->reliability = RakNetInfo::RELIABILITY_RELIABLE; - + $this->send($pk); $this->packetAlwaysRecoverQueue[$pk->seqNumber] = $pk; return [$pk->seqNumber]; @@ -558,25 +564,25 @@ public function sendChatMessagePacket_big(RakNetDataPacket $pk){ $this->bigCnt = ($this->bigCnt + 1) % 0x10000; $cnts = []; $bufCount = count($buffer); - + $orderIndex = $this->chatMessagesOrderIndex++; foreach($buffer as $i => $buf){ $cnts[] = $count = $this->counter[0]++; - + $pk = new UnknownPacket; $pk->packetID = $pk->pid(); $pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED; - + $pk->orderChannel = Player::CHATMESSAGE_ORDER_CHANNEL; $pk->orderIndex = $orderIndex; - + $pk->hasSplit = true; $pk->splitCount = $bufCount; $pk->splitID = $bigCnt; $pk->splitIndex = $i; $pk->buffer = $buf; $pk->messageIndex = $this->counter[3]++; - + $rk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $rk->data[] = $pk; $rk->seqNumber = $count; @@ -595,25 +601,25 @@ public function blockQueueDataPacket_big(RakNetDataPacket $pk){ $this->bigCnt = ($this->bigCnt + 1) % 0x10000; $cnts = []; $bufCount = count($buffer); - + $orderIndex = $this->blockUpdateQueueOrderIndex++; foreach($buffer as $i => $buf){ $cnts[] = $count = $this->counter[0]++; - + $pk = new UnknownPacket; $pk->packetID = $pk->pid(); $pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED; - + $pk->orderChannel = Player::BLOCKUPDATE_ORDER_CHANNEL; $pk->orderIndex = $orderIndex; - + $pk->hasSplit = true; $pk->splitCount = $bufCount; $pk->splitID = $bigCnt; $pk->splitIndex = $i; $pk->buffer = $buf; $pk->messageIndex = $this->counter[3]++; - + $rk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $rk->data[] = $pk; $rk->seqNumber = $count; @@ -623,7 +629,7 @@ public function blockQueueDataPacket_big(RakNetDataPacket $pk){ } return $cnts; } - + public function entityQueueDataPacket_big(RakNetDataPacket $pk){ $sendtime = microtime(true); $size = $this->MTU - 34; @@ -633,25 +639,25 @@ public function entityQueueDataPacket_big(RakNetDataPacket $pk){ $this->bigCnt = ($this->bigCnt + 1) % 0x10000; $cnts = []; $bufCount = count($buffer); - + $orderIndex = $this->entityDataQueueOrderIndex++; foreach($buffer as $i => $buf){ $cnts[] = $count = $this->counter[0]++; - + $pk = new UnknownPacket; $pk->packetID = $pk->pid(); $pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED; - + $pk->orderChannel = Player::ENTITY_ORDER_CHANNEL; $pk->orderIndex = $orderIndex; - + $pk->hasSplit = true; $pk->splitCount = $bufCount; $pk->splitID = $bigCnt; $pk->splitIndex = $i; $pk->buffer = $buf; $pk->messageIndex = $this->counter[3]++; - + $rk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $rk->data[] = $pk; $rk->seqNumber = $count; @@ -661,7 +667,7 @@ public function entityQueueDataPacket_big(RakNetDataPacket $pk){ } return $cnts; } - + public function sendBigPacketAlwaysRecover(RakNetDataPacket $pk){ if($this->connected === false) return false; if(EventHandler::callEvent(new DataPacketSendEvent($this, $pk)) === BaseEvent::DENY) return; @@ -767,7 +773,7 @@ public function sendBuffer(){ public function getSlot($slot){ return $this->inventory[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); } - + /** * @param integer $slot * @param Item $item @@ -778,17 +784,17 @@ public function getSlot($slot){ public function setSlot($slot, Item $item, $send = true, $addexpected = true){ $slot = (int) $slot; $old = $this->getSlot($slot); - + $this->inventory[$slot] = $item; - + if($send === true){ $this->sendInventorySlot($slot); } - + if($addexpected){ $this->addExpectedSetSlotPacket($slot, $item->getID(), $item->getMetadata(), $item->count); } - + return true; } @@ -837,7 +843,7 @@ public function orderChunks(){ $this->chunksOrder = []; $this->lastOrderX = $X; $this->lastOrderZ = $Z; - + $v = new Vector2($X, $Z); for($x = 0; $x < 16; ++$x){ for($z = 0; $z < 16; ++$z){ @@ -882,7 +888,7 @@ public function useChunk($X, $Z){ $pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex); $cnt = $this->blockQueueDataPacket($pk); $this->chunkDataSent["$X:$Z"] = true; - + $tiles = $this->server->query("SELECT ID FROM tiles WHERE spawnable = 1 AND level = '{$this->level->getName()}' AND x >= $minX AND x <= $maxX AND z >= $minZ AND z <= $maxZ;"); $this->lastChunk = false; if($tiles !== false and $tiles !== true){ @@ -898,20 +904,20 @@ public function useChunk($X, $Z){ return false; } } - + public $currentChunk = false; - + public function getDestroySpeed($id, $meta){ return $this->getHeldItem()->getDestroySpeed($id, $meta); } - + public function canDestroy($id, $meta){ $mat = StaticBlock::getMaterial($id); if($mat->alwaysDestroyable) return true; - + return $this->getHeldItem()->canDestroySpecial($id, $meta); } - + public function onChunkReceived($blockX, $blockZ){ $minX = $blockX; $maxX = $blockX + 15; @@ -928,7 +934,7 @@ public function onChunkReceived($blockX, $blockZ){ } } } - + public function getNextChunk($world){ if($this->connected === false or $world != $this->level){ return false; @@ -979,11 +985,11 @@ public function getNextChunk($world){ $pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex); $cnt = $this->blockQueueDataPacket($pk); $this->chunkDataSent["$X:$Z"] = true; - + if($cnt === false){ return false; } - + $this->chunkCount = []; foreach($cnt as $i => $count){ $this->chunkCount[$count] = true; @@ -1072,7 +1078,7 @@ public function setArmor($slot, Item $armor, $send = true){ } return true; } - + public function invisibilityHandler(&$data, $event){ $target = $data["target"]; if($target == $this){ @@ -1148,7 +1154,7 @@ public function eventHandler($data, $event){ $pk->eid = $data["eid"]; $pk->target = $data["entity"]->eid; $this->entityQueueDataPacket($pk); - + if(($this->gamemode & 0x01) === 0x00){ $this->addItem($data["entity"]->itemID, $data["entity"]->meta, $data["entity"]->stack, false); } @@ -1259,19 +1265,19 @@ public function addItem($type, $damage, $count, $send = true, $addexpected = tru $item->count += $add; if($send) $this->sendInventorySlot($s); if($addexpected) $this->addExpectedSetSlotPacket($s, $item->getID(), $item->getMetadata(), $item->count); - + $count -= $add; if($count <= 0) return true; } } - + foreach($this->inventory as $s => $item){ if($item->getID() === AIR){ $add = min($toadd->getMaxStackSize(), $count); $this->inventory[$s] = BlockAPI::getItem($type, $damage, $add); - + if($send) $this->sendInventorySlot($s); - + if($addexpected) $this->addExpectedSetSlotPacket($s, $type, $damage, $add); $count -= $add; if($count <= 0) return true; @@ -1279,11 +1285,11 @@ public function addItem($type, $damage, $count, $send = true, $addexpected = tru } if($count <= 0) return true; if(!$drop) return false; - + while($count > 0){ $stacksz = min($toadd->getMaxStackSize(), $count); $count -= $stacksz; - + $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; @@ -1333,19 +1339,19 @@ public function sendChat($message, $author = ""){ } } } - - + + public function isInvisibleFor(Player $player){ return isset($this->invisibleFor[$player->CID]); } - + public function setInvisibleFor(Player $player, $b, $send=true){ $data = [ "target" => $this, "for" => $player, "status" => $b ]; - + $this->server->handle("player.invisible", $data); $b = $data["status"]; if(!($this->entity instanceof Entity)) $send = false; @@ -1377,7 +1383,7 @@ public function setInvisibleFor(Player $player, $b, $send=true){ } } } - + public function makeInvisibleForAllPlayers(){ foreach($this->server->api->player->getA as $player){ if($player->CID != $this->CID) $this->setInvisibleFor($player, true); @@ -1470,7 +1476,7 @@ public function setGamemode($gm){ } $this->hotbar = $gm == CREATIVE ? BlockAPI::$creativeHotbarSlots : [0, 1, 2, 3, 4, 5, 6, 7, 8]; $this->lastCorrect = $this->entity->copy(); - $this->blocked = true; + $this->blocked = true; if(($this->gamemode & 1) != ($gm & 1)){ $this->saveInventory = false; } @@ -1478,7 +1484,7 @@ public function setGamemode($gm){ $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ", you've to do a forced reconnect.\n"); $this->gmKickSoon = true; $this->server->schedule(30, [$this, "close"], "gamemode change", false, true); //Forces a kick - + } if($this->gamemode === SPECTATOR){ @@ -1578,17 +1584,17 @@ public function handlePacketQueues(){ if($this->server->ticks % 40 == 0){ //2s $this->sendPing(); } - + if($this->connected === false){ return false; } $time = microtime(true); - + if($this->loggedIn === false && ($time - $this->connectionStartedAt) >= 20){ $this->close("timeout"); return false; } - + if($time > $this->timeout){ $this->close("timeout"); return false; @@ -1613,7 +1619,7 @@ public function handlePacketQueues(){ } if($this->sendingInventoryRequired){ - + $pk = new ContainerSetContentPacket; $pk->windowid = 0; if($this->gmKickSoon){ @@ -1633,14 +1639,14 @@ public function handlePacketQueues(){ $pk->slots[$i] = BlockAPI::getItem($id, $meta, 1); } $hotbar = [9, 10, 11, 12, 13, 14, 15, 16, 17]; - + } $pk->hotbar = $hotbar; $this->dataPacket($pk); - + $this->sendingInventoryRequired = false; } - + if(($receiveCnt = count($this->receiveQueue)) > 0){ ksort($this->receiveQueue); foreach($this->receiveQueue as $count => $packets){ @@ -1667,6 +1673,7 @@ public function handlePacketQueues(){ } $this->received[$p->messageIndex] = true; } + $p->PROTOCOL = $this->PROTOCOL; $p->decode(); $this->handleDataPacket($p); } @@ -1677,19 +1684,19 @@ public function handlePacketQueues(){ if($this->chatMessagesQueueLength > 0 && $this->server->ticks % 5 == 0){ //send 4 times/second $this->sendChatBuffer(); } - + if($this->bufferLen > 0){ $this->sendBuffer(); } - + if($this->blockUpdateQueueLength > 0){ $this->sendBlockUpdateQueue(); } - + if($this->entityDataQueueLength > 0){ $this->sendEntityDataQueue(); } - + if($this->entityMovementQueueLength > 0){ $this->sendEntityMovementUpdateQueue(); } @@ -1722,7 +1729,7 @@ public function handlePacketQueues(){ } } } - + public function sendChatBuffer(){ if($this->chatMessagesQueueLength > 0 && $this->chatMessagesQueue instanceof RakNetPacket){ $this->chatMessagesQueue->seqNumber = $this->counter[0]++; @@ -1730,12 +1737,12 @@ public function sendChatBuffer(){ $this->chatMessagesQueue->sendtime = microtime(true); $this->send($this->chatMessagesQueue); } - + $this->chatMessagesQueueLength = 0; $this->chatMessagesQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->chatMessagesQueue->data = []; } - + public function sendEntityMovementUpdateQueue(){ if($this->entityMovementQueueLength > 0 && $this->entityMovementQueue instanceof RakNetPacket){ $this->entityMovementQueue->seqNumber = $this->counter[0]++; @@ -1746,7 +1753,7 @@ public function sendEntityMovementUpdateQueue(){ $this->entityMovementQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->entityMovementQueue->data = []; } - + public function sendEntityDataQueue(){ if($this->entityDataQueueLength > 0 && $this->entityDataQueue instanceof RakNetPacket){ $this->entityDataQueue->seqNumber = $this->counter[0]++; @@ -1758,7 +1765,7 @@ public function sendEntityDataQueue(){ $this->entityDataQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->entityDataQueue->data = []; } - + public function sendBlockUpdateQueue(){ if($this->blockUpdateQueueLength > 0 && $this->blockUpdateQueue instanceof RakNetPacket){ $this->blockUpdateQueue->seqNumber = $this->counter[0]++; @@ -1770,7 +1777,7 @@ public function sendBlockUpdateQueue(){ $this->blockUpdateQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->blockUpdateQueue->data = []; } - + /** * Sends packet in block order channel. Packets are always delivered and ordered. * Used for sending tileentity data, chunk data, updateblock packets. @@ -1780,16 +1787,16 @@ public function blockQueueDataPacket(RakNetDataPacket $pk){ if($this->connected === false) return false; if(EventHandler::callEvent(new DataPacketSendEvent($this, $pk)) === BaseEvent::DENY) return; if(!$this->convertToLocalEIDPacket($pk)) return false; - + $pk->encode(); - + $len = 1 + strlen($pk->buffer); $MTU = $this->MTU - 24; if($len > $MTU) return $this->blockQueueDataPacket_big($pk); if(($this->blockUpdateQueueLength + $len+10) >= $MTU){ $this->sendBlockUpdateQueue(); } - + $pk->messageIndex = $this->counter[3]++; $pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED; $pk->orderChannel = Player::BLOCKUPDATE_ORDER_CHANNEL; @@ -1797,7 +1804,7 @@ public function blockQueueDataPacket(RakNetDataPacket $pk){ @$this->blockUpdateQueue->data[] = $pk; $this->blockUpdateQueueLength += 10 + $len; } - + public function convertToGlobalEIDPacket(RakNetDataPacket $pk){ if(!$pk->eidsToGlobal($this)){ //ConsoleAPI::warn("Failed to convert eids to global in {$pk->pid()}! (Player: {$this->ip}:{$this->port}). Stacktrace: "); @@ -1814,7 +1821,7 @@ public function convertToLocalEIDPacket(RakNetDataPacket $pk){ } return true; } - + /** * Sends a packet in entity order channel. Packets are always delivered and ordered. * @param RakNetDataPacket $pk @@ -1825,24 +1832,24 @@ public function entityQueueDataPacket(RakNetDataPacket $pk){ if(EventHandler::callEvent(new DataPacketSendEvent($this, $pk)) === BaseEvent::DENY) return; if(!$this->convertToLocalEIDPacket($pk)) return false; $pk->encode(); - + $len = 1 + strlen($pk->buffer); $MTU = $this->MTU - 24; if($len > $MTU) return $this->entityQueueDataPacket_big($pk); - + if(($this->entityDataQueueLength + $len+10) >= $MTU){ $this->sendEntityDataQueue(); } - + $pk->messageIndex = $this->counter[3]++; - + $pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED; $pk->orderChannel = Player::ENTITY_ORDER_CHANNEL; $pk->orderIndex = $this->entityDataQueueOrderIndex++; @$this->entityDataQueue->data[] = $pk; $this->entityDataQueueLength += 10 + $len; } - + /** * Adds block update into queue. Does nothing if chunk wasnt loaded. * @param int $x @@ -1880,7 +1887,7 @@ public function addEntityMovementUpdateToQueue(Entity $e){ foreach(explode("\n", (new Exception())->getTraceAsString()) as $s) ConsoleAPI::warn($s); return false; } - + $svdYSpeed = $e->speedY; if($e->modifySpeedY){ $e->speedY = $e->modifedSpeedY; @@ -1892,6 +1899,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 += 10 + strlen($motion->buffer); ++$packets; @@ -1913,6 +1921,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(); @@ -1922,16 +1931,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) + 10; ++$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 = $localeid; $headyaw->yaw = $e->headYaw; + $headyaw->PROTOCOL = $this->PROTOCOL; $headyaw->encode(); $len += strlen($headyaw->buffer) + 10; ++$packets; @@ -2001,11 +2013,11 @@ public function close($reason = "", $msg = true){ if($msg === true and $this->username != "" and $this->spawned !== false){ $this->server->api->chat->broadcast($this->username . " left the game: " . $reason); } - + foreach($this->server->api->player->getAll() as $player){ $player->setInvisibleFor($this, false); } - + $this->spawned = false; console("[INFO] " . FORMAT_AQUA . $this->username . FORMAT_RESET . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . $reason); $this->windows = []; @@ -2038,7 +2050,7 @@ public function save(){ "y" => $this->spawnPosition->y, "z" => $this->spawnPosition->z ]); - + if($this->saveInventory){ $inv = []; foreach($this->inventory as $slot => $item){ @@ -2050,7 +2062,7 @@ public function save(){ } $this->data->set("inventory", $inv); } - + $this->data->set("hotbar", $this->hotbar); if($this->saveInventory){ @@ -2062,26 +2074,26 @@ public function save(){ } $this->data->set("armor", $armor); } - + if($this->entity instanceof Entity){ $this->data->set("health", $this->entity->getHealth()); } $this->data->set("gamemode", $this->gamemode); } } - + public function sendChatMessagePacket(RakNetDataPacket $packet){ if($this->connected === false) return false; if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) return false; if(!$this->convertToLocalEIDPacket($packet)) return false; - + $packet->encode(); $len = strlen($packet->buffer) + 1; $MTU = $this->MTU - 24; if($len > $MTU) return $this->sendChatMessagePacket_big($packet); - + if(($this->chatMessagesQueueLength + $len+10) >= $MTU) $this->sendChatBuffer(); - + $packet->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED; $packet->messageIndex = $this->counter[3]++; $packet->orderChannel = Player::CHATMESSAGE_ORDER_CHANNEL; @@ -2090,16 +2102,16 @@ public function sendChatMessagePacket(RakNetDataPacket $packet){ $this->chatMessagesQueueLength += 10+$len; //reliability(1)+lenbits(2)+messageindex(3)+orderChannel(1)+orderIndex(3) = 10 return true; } - + 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"); } } - + $cnt = 0; foreach($this->expectedSetSlotPackets as $s => $stuff){ $b = current($stuff); @@ -2131,7 +2143,184 @@ public function handleDataPacket(RakNetDataPacket $packet){ return; } - switch($packet->pid()){ + 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; + } + + $internalPid = $packet->getInternalPid(); + + switch ($internalPid) { case 0x01: break; case ProtocolInfo::PONG_PACKET: @@ -2171,6 +2360,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $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; @@ -2228,7 +2418,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ } $this->auth = true; - + $inv = []; if(!$this->data->exists("inventory") || ($this->gamemode & 0x01) === 0x01){ if(($this->gamemode & 0x01) === 0x01){ @@ -2248,7 +2438,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $inv[$slot] = [$item[0], $item[1], $item[2]]; } } - + $this->achievements = $this->data->get("achievements"); $this->data->set("caseusername", $this->username); $this->inventory = []; @@ -2275,16 +2465,16 @@ public function handleDataPacket(RakNetDataPacket $packet){ $pk = new LoginStatusPacket; $pk->status = 0; $this->dataPacket($pk); - + if($this->data->exists("hotbar")){ $this->hotbar = $this->data->get("hotbar"); }else{ if(($this->gamemode & 0x01) === 0x01) $this->hotbar = BlockAPI::$creativeHotbarSlots; else $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; } - + $this->slot = $this->hotbar[0]; - + for($i = 0; $i < count($this->hotbar); ++$i){ if($this->hotbar[$i] > (($this->gamemode & 1) == 0 ? 36 : count(BlockAPI::$creative))) $this->hotbar[$i] = -1; if($this->hotbar[$i] < -1) $this->hotbar[$i] = -1; @@ -2294,13 +2484,13 @@ public function handleDataPacket(RakNetDataPacket $packet){ }else{ $this->data->set("slot-count", $this->slotCount); } - + if($this->data->exists("bed-position")){ $this->bedPosition = $this->data->get("bed-position"); }else{ $this->setBedPosition(null); } - + $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 . ";"); @@ -2315,19 +2505,19 @@ public function handleDataPacket(RakNetDataPacket $packet){ $pk->generator = 0; $pk->gamemode = $this->gamemode & 0x01; $pk->eid = $this->entity->eid; - + $this->entity->x = $pk->x; $this->entity->y = $pk->y-0.9; $this->entity->z = $pk->z; $this->dataPacket($pk); - + //should cache it for client(unless the queue was full and startgamepacket was sent without settime //and client receives time before startgame - TODO maybe make it ordered?) $pk = new SetTimePacket; $pk->time = $this->level->getTime(); $pk->started = !$this->level->isTimeStopped(); $this->dataPacket($pk); - + 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); @@ -2355,25 +2545,25 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->lastMeasure = microtime(true); $this->server->schedule(50, [$this, "measureLag"], [], true); - + 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) . ") MTU: {$this->MTU}"); break; case ProtocolInfo::READY_PACKET: if($this->loggedIn === false){ break; } - + switch($packet->status){ case 1: //Spawn!! if($this->spawned !== false){ break; } - + $pk = new SetTimePacket; $pk->time = $this->level->getTime(); $pk->started = !$this->level->isTimeStopped(); $this->dataPacketAlwaysRecover($pk); - + $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, allowHarm: false); @@ -2444,7 +2634,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ } $this->entity->updateAABB(); } - + break; case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: if($this->spawned === false){ @@ -2490,12 +2680,12 @@ public function handleDataPacket(RakNetDataPacket $packet){ } $data["slot"] = $packet->slot; - + if($this->gamemode == VIEW && $packet->item != AIR){ $this->sendInventory(); break; } - + if($this->server->handle("player.equipment.change", $data) !== false){ if(!Player::$experimentalHotbar) $this->slot = $packet->slot; if(($this->gamemode & 0x01) === SURVIVAL){ @@ -2525,7 +2715,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ array_unshift($this->hotbar, $this->slot); } } - + if(Player::$experimentalHotbar) $this->sendInventory(); }else{ $this->slot = $packet->slot; @@ -2583,14 +2773,14 @@ public function handleDataPacket(RakNetDataPacket $packet){ $heldItem = $this->getHeldItem(); $pmeta = ($packet->meta & 0xff); $hmeta = ($heldItem->getMetadata() & 0xff); //in 0.8.1 useitempacket uses byte for meta - + if($heldItem->getID() != $packet->item || $hmeta != $pmeta){ $this->sendInventory(); if($heldItem->getID() == $packet->item && $heldItem->getMaxDurability() != false){ //id matches, meta is used as durability -> allow to perform whatever action the player wants to do goto allow_use_item; } ConsoleAPI::warn("{$this->username}'s heldItem doesnt match on clientside({$packet->item} {$pmeta}) and serverside({$heldItem->getID()} {$hmeta}) when using item. Resending inventory."); - + if($packet->face >= 0 && $packet->face <= 5){ $target = $this->level->getBlock($blockVector); $block = $target->getSide($packet->face); @@ -2618,7 +2808,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ } $target = $this->level->getBlock($blockVector); $block = $target->getSide($packet->face); - + $this->addBlockUpdateIntoQueue($target->x, $target->y, $target->z, $target->getID(), $target->getMetadata()); $this->addBlockUpdateIntoQueue($block->x, $block->y, $block->z, $block->getID(), $block->getMetadata()); break; @@ -2675,6 +2865,73 @@ 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){ break; @@ -2772,7 +3029,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $s = BlockAPI::getItem($s + 256, 0, 1); } $slot = $this->armor[$i]; - + if($slot->getID() !== AIR && $s->getID() === AIR){ $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); $this->armor[$i] = BlockAPI::getItem(AIR, 0, 0); @@ -2853,7 +3110,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $tpTarget = $spawnPoint; } } - + $this->teleport($tpTarget, false, false, true, false); $pk = new MovePlayerPacket(); $pk->eid = $this->entity->eid; @@ -2931,15 +3188,15 @@ public function handleDataPacket(RakNetDataPacket $packet){ $packet->eid = $this->eid; $prevItem = $packet->item; $newItem = $this->getHeldItem(); - + if(($n = $this->isExpectedSetSlot(-1, $prevItem))){ ConsoleAPI::debug("{$this->username}: Expected drop slot dropped"); $this->removeExpectedSetSlot($n); return; } - + if($newItem->getID() != $prevItem->getID() || $newItem->getMetadata() != $prevItem->getMetadata()){ - + if(count($this->inventory) >= 36){ foreach($this->inventory as $slot => $item){ if($item->getID() == 0) goto inv_desync_on_drop; @@ -2949,12 +3206,12 @@ public function handleDataPacket(RakNetDataPacket $packet){ break; } inv_desync_on_drop: - + ConsoleAPI::debug("{$this->username} tried dropping item from non-held slot or inventory desynchronized."); $this->sendInventory(); break; } - + if($newItem->count < $prevItem->count){ ConsoleAPI::warn("{$this->username} tried dropping too many items(serverside stack has {$newItem->count}, tried dropping {$prevItem->count}."); $this->sendInventory(); @@ -2965,7 +3222,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ }else{ $packet->item = $newItem; } - + $this->craftingItems = []; $this->toCraft = []; $this->craftingType = CraftingRecipes::TYPE_INVENTORY; @@ -2986,7 +3243,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1; $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); - $newItem->count -= $packet->item->count; + $newItem->count -= $packet->item->count; if($newItem->count <= 0){ $this->setSlot($this->slot, BlockAPI::getItem(0, 0, 0), false); } @@ -3088,10 +3345,10 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->hotbar[$packet->slot] = $yes; return; } - + $slot = $this->getSlot($packet->slot); $citem = $packet->item; - + if(($n = $this->isExpectedSetSlot($packet->slot, $packet->item)) !== false){ //ConsoleAPI::debug("Expected setslot at $n found {$packet->item}"); $this->removeExpectedSetSlot($n); @@ -3099,7 +3356,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ }else{ //ConsoleAPI::info("unexpected setslot, assuming caused by crafting {$packet->slot} {$packet->item}"); } - + if($slot->getID() == $citem->getID() && $slot->getMetadata() == $citem->getMetadata()){ if($citem->count > $slot->count){ //item added, result $this->addCraftingResult($packet->slot, $slot->getID(), $slot->getMetadata(), $citem->count - $slot->count); @@ -3121,7 +3378,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ $this->craftingItems = []; $this->craftingType = CraftingRecipes::TYPE_INVENTORY; } - + if(!isset($this->windows[$packet->windowid])){ break; } @@ -3246,7 +3503,7 @@ public function handleDataPacket(RakNetDataPacket $packet){ if($d["id"] !== TILE_SIGN){ $t->spawn($this); }else{ - + $t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]); } } @@ -3406,7 +3663,7 @@ public function tryCraft(){ } } } - + $this->toCraft = []; $this->craftingItems = []; } @@ -3450,7 +3707,7 @@ public function hasItem($type, $damage = false){ } return false; } - + /** * Removes a single item from whatever player is holding. * @param boolean $send Force send inventory to player. @@ -3458,21 +3715,21 @@ public function hasItem($type, $damage = false){ public function consumeSingleItem($send = false){ $it = $this->getHeldItem(); if(($this->gamemode & 0x01) === 0x00) --$it->count; - + if($it->count <= 0){ $this->setSlot($this->slot, BlockAPI::getItem(0, 0, 0), false); } - + if($send) $this->sendInventory(); } - + public function removeItem($type, $damage, $count, $send = true, $addexpected = true){ while($count > 0){ $remove = 0; foreach($this->inventory as $s => $item){ if($item->getID() === $type and $item->getMetadata() === $damage){ $remove = min($count, $item->count); - + if($remove < $item->count){ $item->count -= $remove; $exid = $item->getID(); @@ -3483,7 +3740,7 @@ public function removeItem($type, $damage, $count, $send = true, $addexpected = $exid = $exmeta = $excnt = 0; } if($send === true) $this->sendInventorySlot($s); - + if($addexpected) $this->addExpectedSetSlotPacket($s, $exid, $exmeta, $excnt); break; } @@ -3520,7 +3777,7 @@ public function handlePacket(RakNetPacket $packet){ foreach($packet->packets as $count){ if(isset($this->packetAlwaysRecoverQueue[$count])){ $this->lag[] = $time - $this->packetAlwaysRecoverQueue[$count]->sendtime; - + unset($this->packetAlwaysRecoverQueue[$count]); unset($this->chunkCount[$count]); }else if(isset($this->recoveryQueue[$count])){ @@ -3557,7 +3814,7 @@ public function handlePacket(RakNetPacket $packet){ } } } - + /** * @return string */ @@ -3576,7 +3833,7 @@ function __toString(){ public function makeInvisibleForOnePlayer(Player $player){ $this->setInvisibleFor($player, true); } - + /** * @deprecated craft system changed * @param array $craft @@ -3588,12 +3845,12 @@ public function makeInvisibleForOnePlayer(Player $player){ public function craftItems(array $craft, array $recipe, $type){ return false; } - + /** * @deprecated armor is damaged by Entity::hurtArmor and cant be damaged by singular pieces */ public function damageArmorPart($slot, $part){} - + /** * @deprecated 16x16x16 chunk sending was removed */ 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/constants/BlockIDs.php b/src/constants/BlockIDs.php index 52e352a24..7db0855f9 100755 --- a/src/constants/BlockIDs.php +++ b/src/constants/BlockIDs.php @@ -109,7 +109,6 @@ define("GLOWSTONE", 89); define("GLOWSTONE_BLOCK", 89); - define("LIT_PUMPKIN", 91); define("JACK_O_LANTERN", 91); define("CAKE_BLOCK", 92); diff --git a/src/constants/EntityIDs.php b/src/constants/EntityIDs.php index 4e6b0293e..237cc4997 100644 --- a/src/constants/EntityIDs.php +++ b/src/constants/EntityIDs.php @@ -26,10 +26,10 @@ define("ENTITY_ITEM", 4); define("ENTITY_ITEM_TYPE", 64); - + define("ENTITY_FALLING", 5); define("FALLING_SAND", 66); - + //TileEntities define("TILE_SIGN", "Sign"); define("TILE_CHEST", "Chest"); @@ -44,7 +44,7 @@ MOB_COW => 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 98f74b900..6c3bc9bc9 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -98,7 +98,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"); @@ -133,8 +132,6 @@ require_all(FILE_PATH . "src/"); - - $inc = get_included_files(); $inc[] = array_shift($inc); $srcdir = realpath(FILE_PATH . "src/"); 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 444edd738..52817b89b 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; } @@ -219,5 +220,5 @@ public function spawn(Player $player) } return false; } - + } \ 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 27909a8ff..6c0e4c52d 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -13,24 +13,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; } @@ -40,11 +40,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; } @@ -55,7 +55,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); @@ -63,45 +63,45 @@ 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 8bc3766e5..a81ef6cac 100644 --- a/src/entity/ai/tasks/TaskEatTileGoal.php +++ b/src/entity/ai/tasks/TaskEatTileGoal.php @@ -12,7 +12,7 @@ public function onStart(EntityAI $ai) public function onEnd(EntityAI $ai) { - + } public function onUpdate(EntityAI $ai) @@ -20,7 +20,7 @@ public function onUpdate(EntityAI $ai) if($ai->isStarted("TaskPanic")){ $this->reset(); return false; - } + } if (--$this->selfCounter == 4) { @@ -29,7 +29,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 0501e99b4..dcb0bcf4a 100644 --- a/src/entity/ai/tasks/TaskFollowParent.php +++ b/src/entity/ai/tasks/TaskFollowParent.php @@ -6,7 +6,7 @@ class TaskFollowParent extends TaskBase public function __construct($speed){ $this->speedMultiplier = $speed; } - + public function onStart(EntityAI $ai) { $this->selfCounter = 1; @@ -24,19 +24,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 71480b0c5..6b39692df 100644 --- a/src/entity/ai/tasks/TaskMate.php +++ b/src/entity/ai/tasks/TaskMate.php @@ -6,9 +6,9 @@ class TaskMate extends TaskBase public function __construct($speed){ $this->speedMultiplier = $speed; } - + public $targetMateID; - + public function onStart(EntityAI $ai) { $this->selfCounter = 60; @@ -28,17 +28,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 @@ -46,20 +45,20 @@ public function createBaby(EntityAI $ai, Entity $entpar2){ $baby = $ai->entity->breed($entpar2); //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){ @@ -72,7 +71,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 7267e8f1c..ab1f3d421 100644 --- a/src/entity/ai/tasks/TaskRangedAttack.php +++ b/src/entity/ai/tasks/TaskRangedAttack.php @@ -8,10 +8,10 @@ class TaskRangedAttack extends \TaskBase public $rangeSquared = 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 14081cd2e..9bec48585 100644 --- a/src/entity/ai/tasks/TaskTempt.php +++ b/src/entity/ai/tasks/TaskTempt.php @@ -6,19 +6,19 @@ class TaskTempt extends TaskBase public $targetDistance; 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")){ @@ -26,22 +26,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)){ @@ -49,16 +48,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){ @@ -66,13 +65,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 65072669e..52ae52277 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", allowHarm: false); $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 5abf467e8..151d7a4b4 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 48b0f2784..bc564bebd 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->rider == 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->consumeSingleItem(send: true); @@ -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/monster/PigZombie.php b/src/entity/monster/PigZombie.php index 8d58edc5d..0b3381b27 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 65360334d..6cb57c981 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", allowHarm: false); @@ -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/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 583440523..3437d45c7 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", allowHarm: false); } - + 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/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/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 c117cf265..31ae7cd54 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); } @@ -50,7 +50,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), @@ -58,7 +58,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); @@ -66,8 +66,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 eab861ba8..0b3ecd689 100644 --- a/src/material/block/attachable/SignPostBlock.php +++ b/src/material/block/attachable/SignPostBlock.php @@ -19,7 +19,7 @@ public function __construct($meta = 0){ $this->breakTime = 1; $this->material = Material::$wood; } - + 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 || $target->getID() === GLASS_PANE || $target->getID() === IRON_BARS || $target->getID() === STONE_WALL) && $face !== 0){ if(!isset(self::$faces[$face])){ @@ -34,7 +34,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)); @@ -42,15 +42,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 bbd181ccc..878afd48b 100644 --- a/src/material/block/attachable/TorchBlock.php +++ b/src/material/block/attachable/TorchBlock.php @@ -9,15 +9,15 @@ public function __construct($meta = 0){ $this->material = Material::$decoration; $this->lightEmission = 14; } - + 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){ @@ -25,9 +25,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); @@ -36,13 +36,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; @@ -54,8 +54,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 3af179293..1aa47ab05 100644 --- a/src/material/block/attachable/TrapdoorBlock.php +++ b/src/material/block/attachable/TrapdoorBlock.php @@ -19,25 +19,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){ @@ -58,24 +58,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)){ @@ -85,13 +85,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/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index 7167bae4c..f011073d1 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -1,4 +1,5 @@ lightEmission = 15; $this->lightBlock = 255; } - + 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/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 5fb354aca..455ce2cc2 100644 --- a/src/material/block/liquid/StillLavaBlock.php +++ b/src/material/block/liquid/StillLavaBlock.php @@ -1,4 +1,5 @@ lightEmission = 15; $this->lightBlock = 255; } - + 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 14682827c..9e9566ece 100644 --- a/src/material/block/liquid/StillWaterBlock.php +++ b/src/material/block/liquid/StillWaterBlock.php @@ -1,6 +1,5 @@ material = Material::$water; $this->lightBlock = 3; } - + public static function getTickDelay(){ return 5; } diff --git a/src/material/block/liquid/WaterBlock.php b/src/material/block/liquid/WaterBlock.php index c55bada54..179445b8f 100644 --- a/src/material/block/liquid/WaterBlock.php +++ b/src/material/block/liquid/WaterBlock.php @@ -1,9 +1,10 @@ hardness = 500; @@ -11,12 +12,12 @@ public function __construct($meta = 0){ $this->material = Material::$water; $this->lightBlock = 3; } - + 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/FireBlock.php b/src/material/block/misc/FireBlock.php index 99fc63cc5..3fbf4ab12 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; @@ -22,39 +22,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; @@ -68,20 +68,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 f7250d947..7049fb2f3 100644 --- a/src/material/block/misc/NetherReactorBlock.php +++ b/src/material/block/misc/NetherReactorBlock.php @@ -11,7 +11,7 @@ public function __construct($meta = 0){ $this->material = Material::$metal; $this->lightBlock = 255; } - + 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){ @@ -19,58 +19,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(); @@ -92,28 +92,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); } @@ -124,63 +124,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; } } @@ -222,18 +222,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/nonfull/CakeBlock.php b/src/material/block/nonfull/CakeBlock.php index fe276310b..97dd01b8a 100644 --- a/src/material/block/nonfull/CakeBlock.php +++ b/src/material/block/nonfull/CakeBlock.php @@ -11,18 +11,18 @@ public function __construct($meta = 0){ $this->breakTime = 0.5; $this->material = Material::$cake; } - + 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){ @@ -31,17 +31,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; @@ -55,5 +55,5 @@ public function onActivate(Item $item, Player $player){ } return false; } - + } \ No newline at end of file diff --git a/src/material/block/nonfull/ChestBlock.php b/src/material/block/nonfull/ChestBlock.php index cdc68777d..d27a5481d 100644 --- a/src/material/block/nonfull/ChestBlock.php +++ b/src/material/block/nonfull/ChestBlock.php @@ -13,19 +13,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; @@ -42,22 +42,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){ @@ -66,48 +66,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 010b1e37b..60e96fe35 100644 --- a/src/material/block/nonfull/CobwebBlock.php +++ b/src/material/block/nonfull/CobwebBlock.php @@ -3,7 +3,7 @@ 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 = 30; @@ -11,11 +11,11 @@ public function __construct(){ $this->material = Material::$web; $this->lightBlock = 1; } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } - + public function getDrops(Item $item, Player $player){ if ($item->isSword()){ return [ @@ -24,11 +24,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 b431bb01b..0f26343c6 100644 --- a/src/material/block/nonfull/FarmlandBlock.php +++ b/src/material/block/nonfull/FarmlandBlock.php @@ -9,27 +9,27 @@ public function __construct($meta = 0){ $this->material = Material::$dirt; } 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, true); } } - + public static function onRandomTick(Level $level, $x, $y, $z){ for($xx = $x-4; $xx <= $x+4; ++$xx){ for($yy = $y; $yy <= $y+1; ++$yy){ @@ -71,7 +71,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/FenceGateBlock.php b/src/material/block/nonfull/FenceGateBlock.php index 74d8c59ee..b24bb34cb 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; @@ -35,29 +35,29 @@ public function __construct($meta = 0){ $this->material = Material::$wood; } 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)){ @@ -65,7 +65,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 810be4680..e89b54890 100644 --- a/src/material/block/nonfull/GlassPaneBlock.php +++ b/src/material/block/nonfull/GlassPaneBlock.php @@ -12,33 +12,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){ @@ -54,7 +54,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); @@ -63,14 +63,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 3d15b857a..4104ce20a 100644 --- a/src/material/block/nonfull/IronBarsBlock.php +++ b/src/material/block/nonfull/IronBarsBlock.php @@ -10,39 +10,39 @@ public function __construct(){ $this->hardness = 30; $this->material = Material::$metal; } - + 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)); @@ -56,7 +56,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); @@ -65,9 +65,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 266769866..c9196533f 100644 --- a/src/material/block/nonfull/IronDoorBlock.php +++ b/src/material/block/nonfull/IronDoorBlock.php @@ -23,14 +23,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/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/SlabBlock.php b/src/material/block/nonfull/SlabBlock.php index da167514e..008a45a00 100644 --- a/src/material/block/nonfull/SlabBlock.php +++ b/src/material/block/nonfull/SlabBlock.php @@ -12,21 +12,21 @@ 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; $this->breakTime = 2; $this->material = Material::$stone; } public static function updateShape(Level $level, $x, $y, $z){ - + [$id, $meta] = $level->level->getBlock($x, $y, $z); if($meta & 0x08 == 0x08){ @@ -37,11 +37,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], @@ -49,7 +49,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){ @@ -105,14 +105,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/StoneWallBlock.php b/src/material/block/nonfull/StoneWallBlock.php index f70c55263..dfeb5b3fc 100644 --- a/src/material/block/nonfull/StoneWallBlock.php +++ b/src/material/block/nonfull/StoneWallBlock.php @@ -17,45 +17,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){ @@ -64,7 +64,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 91bbce49e..e19dbc894 100644 --- a/src/material/block/nonfull/WoodDoorBlock.php +++ b/src/material/block/nonfull/WoodDoorBlock.php @@ -9,10 +9,10 @@ public function __construct($meta = 0){ $this->breakTime = 3; $this->material = Material::$wood; } - + 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/stairs/BirchWoodStairsBlock.php b/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php index 21979c8f5..694b7db5b 100644 --- a/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/BirchWoodStairsBlock.php @@ -10,8 +10,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 2d22e1fab..d6a0743de 100644 --- a/src/material/block/nonfull/stairs/BrickStairsBlock.php +++ b/src/material/block/nonfull/stairs/BrickStairsBlock.php @@ -8,5 +8,5 @@ public function __construct($meta = 0){ $this->hardness = 30; $this->material = Material::$stone; } - + } \ 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 80095c91d..7e74c7cd0 100644 --- a/src/material/block/nonfull/stairs/CobblestoneStairsBlock.php +++ b/src/material/block/nonfull/stairs/CobblestoneStairsBlock.php @@ -8,5 +8,5 @@ public function __construct($meta = 0){ $this->hardness = 30; $this->material = Material::$stone; } - + } \ 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 179948b18..07defb898 100644 --- a/src/material/block/nonfull/stairs/JungleWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/JungleWoodStairsBlock.php @@ -10,8 +10,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 520506ada..9a732c4dc 100644 --- a/src/material/block/nonfull/stairs/NetherBricksStairsBlock.php +++ b/src/material/block/nonfull/stairs/NetherBricksStairsBlock.php @@ -8,5 +8,5 @@ public function __construct($meta = 0){ $this->breakTime = 2; $this->material = Material::$stone; } - + } \ 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 136ded106..fe7502da1 100644 --- a/src/material/block/nonfull/stairs/QuartzStairsBlock.php +++ b/src/material/block/nonfull/stairs/QuartzStairsBlock.php @@ -8,5 +8,5 @@ public function __construct($meta = 0){ $this->hardness = 4; $this->material = Material::$stone; } - + } \ 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 7b374f2b3..623b2eba6 100644 --- a/src/material/block/nonfull/stairs/SandstoneStairsBlock.php +++ b/src/material/block/nonfull/stairs/SandstoneStairsBlock.php @@ -8,5 +8,5 @@ public function __construct($meta = 0){ $this->breakTime = 0.8; $this->material = Material::$stone; } - + } \ 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 98f65fb4f..9e4609de0 100644 --- a/src/material/block/nonfull/stairs/SpruceWoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/SpruceWoodStairsBlock.php @@ -10,8 +10,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 40575ca3f..deb69fecd 100644 --- a/src/material/block/nonfull/stairs/StoneBrickStairsBlock.php +++ b/src/material/block/nonfull/stairs/StoneBrickStairsBlock.php @@ -8,5 +8,5 @@ public function __construct($meta = 0){ $this->breakTime = 1.5; $this->material = Material::$stone; } - + } \ 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 e507e102f..a907af50a 100644 --- a/src/material/block/nonfull/stairs/WoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/WoodStairsBlock.php @@ -25,8 +25,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 5dd90323c..08737c5ce 100644 --- a/src/material/block/ore/CoalOreBlock.php +++ b/src/material/block/ore/CoalOreBlock.php @@ -9,7 +9,7 @@ public function __construct(){ $this->material = Material::$stone; $this->lightBlock = 255; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -23,15 +23,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 29929b784..d7a051067 100644 --- a/src/material/block/ore/DiamondOreBlock.php +++ b/src/material/block/ore/DiamondOreBlock.php @@ -9,7 +9,7 @@ public function __construct(){ $this->material = Material::$stone; $this->lightBlock = 255; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -20,14 +20,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 20a921973..0e1d48711 100644 --- a/src/material/block/ore/GlowingRedstoneOreBlock.php +++ b/src/material/block/ore/GlowingRedstoneOreBlock.php @@ -10,11 +10,11 @@ public function __construct(){ $this->lightBlock = 255; $this->lightEmission = 9; } - + public static function onRandomTick(Level $level, $x, $y, $z){ $level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0); } - + public function getMaxLightValue(){ return 9; } @@ -29,15 +29,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 5209b3796..ac0b93480 100644 --- a/src/material/block/ore/GoldOreBlock.php +++ b/src/material/block/ore/GoldOreBlock.php @@ -20,14 +20,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 020dec828..bf77c2363 100644 --- a/src/material/block/ore/IronOreBlock.php +++ b/src/material/block/ore/IronOreBlock.php @@ -21,14 +21,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 a60ef0158..5eb5c99b3 100644 --- a/src/material/block/ore/LapisOreBlock.php +++ b/src/material/block/ore/LapisOreBlock.php @@ -9,7 +9,7 @@ public function __construct(){ $this->material = Material::$stone; $this->lightBlock = 255; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -24,12 +24,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 3f0b260c4..39a52c75e 100644 --- a/src/material/block/ore/RedstoneOreBlock.php +++ b/src/material/block/ore/RedstoneOreBlock.php @@ -9,18 +9,18 @@ public function __construct(){ $this->material = Material::$stone; $this->lightBlock = 255; } - + 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 0c68a3b40..3915dd5cc 100644 --- a/src/material/block/plant/BeetrootBlock.php +++ b/src/material/block/plant/BeetrootBlock.php @@ -45,7 +45,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/CactusBlock.php b/src/material/block/plant/CactusBlock.php index 5c6bdd6b6..e3ebdef02 100644 --- a/src/material/block/plant/CactusBlock.php +++ b/src/material/block/plant/CactusBlock.php @@ -9,14 +9,14 @@ public function __construct($meta = 0){ $this->breakTime = 0.4; $this->material = Material::$cactus; } - + 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); @@ -40,7 +40,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); @@ -52,7 +52,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){ @@ -68,10 +68,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 5abe9ad8c..9482207a9 100644 --- a/src/material/block/plant/CarrotBlock.php +++ b/src/material/block/plant/CarrotBlock.php @@ -18,7 +18,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; @@ -47,7 +47,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 2674620b8..5d2868424 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -9,7 +9,7 @@ public function __construct(){ $this->breakTime = 0; $this->material = Material::$plant; } - + public static function getAABB(Level $level, $x, $y, $z){ return null; } @@ -23,17 +23,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){ $random = new Random(); diff --git a/src/material/block/plant/DeadBushBlock.php b/src/material/block/plant/DeadBushBlock.php index f1f51e386..a74c40bca 100644 --- a/src/material/block/plant/DeadBushBlock.php +++ b/src/material/block/plant/DeadBushBlock.php @@ -9,33 +9,33 @@ public function __construct(){ $this->breakTime = 0; $this->material = Material::$replaceable_plant; } - + 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/PotatoBlock.php b/src/material/block/plant/PotatoBlock.php index 9af1dbb32..54a5ce249 100644 --- a/src/material/block/plant/PotatoBlock.php +++ b/src/material/block/plant/PotatoBlock.php @@ -47,7 +47,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/SaplingBlock.php b/src/material/block/plant/SaplingBlock.php index d622130ac..cdce156e5 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; $this->breakTime = 0; @@ -33,7 +33,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); @@ -46,7 +46,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); } } @@ -63,8 +63,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/TallGrassBlock.php b/src/material/block/plant/TallGrassBlock.php index 02f8b4bd2..975128edb 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; $this->breakTime = 0; @@ -19,28 +19,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 caaab02af..6b92570b1 100644 --- a/src/material/block/plant/WheatBlock.php +++ b/src/material/block/plant/WheatBlock.php @@ -18,7 +18,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; @@ -47,7 +47,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){ @@ -58,7 +58,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 70d8035ce..43350929a 100644 --- a/src/material/block/solid/BedrockBlock.php +++ b/src/material/block/solid/BedrockBlock.php @@ -10,12 +10,12 @@ public function __construct(){ $this->material = Material::$stone; $this->lightBlock = 255; } - + 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 fdd93bfc5..d8ac0e2b6 100644 --- a/src/material/block/solid/BookshelfBlock.php +++ b/src/material/block/solid/BookshelfBlock.php @@ -9,5 +9,5 @@ public function __construct(){ $this->material = Material::$wood; $this->lightBlock = 255; } - + } \ No newline at end of file diff --git a/src/material/block/solid/BricksBlock.php b/src/material/block/solid/BricksBlock.php index f0657c6dc..ce39f7bc7 100644 --- a/src/material/block/solid/BricksBlock.php +++ b/src/material/block/solid/BricksBlock.php @@ -23,14 +23,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 030b7b632..c77c7ff74 100644 --- a/src/material/block/solid/BurningFurnaceBlock.php +++ b/src/material/block/solid/BurningFurnaceBlock.php @@ -13,12 +13,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; @@ -39,23 +39,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; @@ -69,18 +69,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 a059962af..695d583a8 100644 --- a/src/material/block/solid/ClayBlock.php +++ b/src/material/block/solid/ClayBlock.php @@ -11,8 +11,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 6a8191ef1..613ea0691 100644 --- a/src/material/block/solid/CoalBlock.php +++ b/src/material/block/solid/CoalBlock.php @@ -23,14 +23,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 7ba03d99e..4e47f3396 100644 --- a/src/material/block/solid/CobblestoneBlock.php +++ b/src/material/block/solid/CobblestoneBlock.php @@ -23,14 +23,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 eaa0131da..d5f15a7af 100644 --- a/src/material/block/solid/DiamondBlock.php +++ b/src/material/block/solid/DiamondBlock.php @@ -9,7 +9,7 @@ public function __construct(){ $this->material = Material::$metal; $this->lightBlock = 255; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -20,14 +20,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 87f2eb746..296e8a6e4 100644 --- a/src/material/block/solid/DirtBlock.php +++ b/src/material/block/solid/DirtBlock.php @@ -31,33 +31,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 0bac086da..0372066a1 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; $this->breakTime = 2; @@ -34,15 +34,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 848c7b87e..3771ffc06 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 = 30; $this->breakTime = 2; @@ -32,11 +32,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 8fe0cdf97..083f26132 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 f3c505698..ec105c8d8 100644 --- a/src/material/block/solid/GlassBlock.php +++ b/src/material/block/solid/GlassBlock.php @@ -8,11 +8,11 @@ public function __construct(){ $this->breakTime = 0.3; $this->material = Material::$glass; } - + 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 b2e143db4..5f3c642c4 100644 --- a/src/material/block/solid/GlowingObsidianBlock.php +++ b/src/material/block/solid/GlowingObsidianBlock.php @@ -10,9 +10,9 @@ public function __construct($meta = 0){ $this->lightBlock = 255; $this->lightEmission = 13; } - + 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 e123d491a..01e6a1498 100644 --- a/src/material/block/solid/GlowstoneBlock.php +++ b/src/material/block/solid/GlowstoneBlock.php @@ -10,17 +10,17 @@ public function __construct(){ $this->lightBlock = 255; $this->lightEmission = 15; } - + 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 eff8f97d8..580011e45 100644 --- a/src/material/block/solid/GoldBlock.php +++ b/src/material/block/solid/GoldBlock.php @@ -20,14 +20,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/GravelBlock.php b/src/material/block/solid/GravelBlock.php index 2ac020a3f..48710cf10 100644 --- a/src/material/block/solid/GravelBlock.php +++ b/src/material/block/solid/GravelBlock.php @@ -9,11 +9,11 @@ public function __construct(){ $this->material = Material::$sand; $this->lightBlock = 255; } - + 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 86dacd511..3a19ab126 100644 --- a/src/material/block/solid/HayBaleBlock.php +++ b/src/material/block/solid/HayBaleBlock.php @@ -9,16 +9,16 @@ public function __construct($meta = 0){ $this->material = Material::$dirt; $this->lightBlock = 255; } - + 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); @@ -26,9 +26,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/InfoUpdate2Block.php b/src/material/block/solid/InfoUpdate2Block.php index a8a29de63..c20752390 100755 --- a/src/material/block/solid/InfoUpdate2Block.php +++ b/src/material/block/solid/InfoUpdate2Block.php @@ -10,5 +10,5 @@ public function __construct(){ $this->material = Material::$dirt; $this->lightBlock = 255; } - + } \ No newline at end of file diff --git a/src/material/block/solid/InfoUpdateBlock.php b/src/material/block/solid/InfoUpdateBlock.php index cad299b5e..12c283f71 100755 --- a/src/material/block/solid/InfoUpdateBlock.php +++ b/src/material/block/solid/InfoUpdateBlock.php @@ -10,5 +10,5 @@ public function __construct(){ $this->material = Material::$dirt; $this->lightBlock = 255; } - + } \ No newline at end of file diff --git a/src/material/block/solid/InvisibleBedrockBlock.php b/src/material/block/solid/InvisibleBedrockBlock.php index 5ef1f20f4..5a0a3f7fb 100755 --- a/src/material/block/solid/InvisibleBedrockBlock.php +++ b/src/material/block/solid/InvisibleBedrockBlock.php @@ -10,12 +10,12 @@ public function __construct(){ $this->material = Material::$stone; $this->lightBlock = 255; } - + 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 1b576ba2d..e5dc40eba 100644 --- a/src/material/block/solid/IronBlock.php +++ b/src/material/block/solid/IronBlock.php @@ -21,14 +21,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 073461926..191383920 100644 --- a/src/material/block/solid/LapisBlock.php +++ b/src/material/block/solid/LapisBlock.php @@ -21,14 +21,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/LitPumpkinBlock.php b/src/material/block/solid/LitPumpkinBlock.php index 2303db16e..2386cf840 100644 --- a/src/material/block/solid/LitPumpkinBlock.php +++ b/src/material/block/solid/LitPumpkinBlock.php @@ -8,8 +8,7 @@ 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; @@ -18,11 +17,11 @@ public function __construct($meta = 0){ $this->lightBlock = 255; $this->lightEmission = 15; } - + 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)){ @@ -32,12 +31,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 71596b2ae..94ee8a998 100644 --- a/src/material/block/solid/MelonBlock.php +++ b/src/material/block/solid/MelonBlock.php @@ -10,11 +10,11 @@ public function __construct(){ $this->lightBlock = 255; } 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 e1bb14367..fbc2dde8c 100644 --- a/src/material/block/solid/MossStoneBlock.php +++ b/src/material/block/solid/MossStoneBlock.php @@ -23,14 +23,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 f2eec4a5d..2af0ff0e1 100644 --- a/src/material/block/solid/NetherBricksBlock.php +++ b/src/material/block/solid/NetherBricksBlock.php @@ -23,14 +23,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 ff6b510a9..61f0bd858 100644 --- a/src/material/block/solid/NetherrackBlock.php +++ b/src/material/block/solid/NetherrackBlock.php @@ -9,7 +9,7 @@ public function __construct(){ $this->material = Material::$stone; $this->lightBlock = 255; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -26,11 +26,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/PlanksBlock.php b/src/material/block/solid/PlanksBlock.php index e321f4c77..b329a384b 100644 --- a/src/material/block/solid/PlanksBlock.php +++ b/src/material/block/solid/PlanksBlock.php @@ -4,17 +4,17 @@ 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; $this->breakTime = 2; $this->material = Material::$wood; $this->lightBlock = 255; } - + } \ No newline at end of file diff --git a/src/material/block/solid/QuartzBlock.php b/src/material/block/solid/QuartzBlock.php index 00fb68b3f..5e4d1261b 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]; $this->breakTime = 0.8; $this->hardness = 4; @@ -30,14 +30,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 133f763cd..fd5601b12 100644 --- a/src/material/block/solid/Reserved6Block.php +++ b/src/material/block/solid/Reserved6Block.php @@ -10,5 +10,5 @@ public function __construct(){ $this->material = Material::$dirt; $this->lightBlock = 255; } - + } \ No newline at end of file diff --git a/src/material/block/solid/SandBlock.php b/src/material/block/solid/SandBlock.php index 16623ef11..36a62d2f7 100644 --- a/src/material/block/solid/SandBlock.php +++ b/src/material/block/solid/SandBlock.php @@ -9,5 +9,5 @@ public function __construct(){ $this->material = Material::$sand; $this->lightBlock = 255; } - + } \ No newline at end of file diff --git a/src/material/block/solid/SandstoneBlock.php b/src/material/block/solid/SandstoneBlock.php index 33a752b5e..9b713bd69 100644 --- a/src/material/block/solid/SandstoneBlock.php +++ b/src/material/block/solid/SandstoneBlock.php @@ -4,18 +4,18 @@ 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; $this->breakTime = 0.8; $this->material = Material::$stone; $this->lightBlock = 255; } - + public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; @@ -32,12 +32,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 92addfaec..054d6389d 100644 --- a/src/material/block/solid/SnowBlock.php +++ b/src/material/block/solid/SnowBlock.php @@ -18,5 +18,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 ac5275e18..31237e031 100644 --- a/src/material/block/solid/SpongeBlock.php +++ b/src/material/block/solid/SpongeBlock.php @@ -9,5 +9,5 @@ public function __construct(){ $this->material = Material::$dirt; $this->lightBlock = 255; } - + } diff --git a/src/material/block/solid/StoneBlock.php b/src/material/block/solid/StoneBlock.php index e18b1acbb..7f3739f08 100644 --- a/src/material/block/solid/StoneBlock.php +++ b/src/material/block/solid/StoneBlock.php @@ -23,15 +23,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 cc83158f6..37558e577 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; $this->breakTime = 1.5; @@ -30,15 +30,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 63a4d296a..a18b41d91 100644 --- a/src/material/block/solid/StonecutterBlock.php +++ b/src/material/block/solid/StonecutterBlock.php @@ -10,7 +10,7 @@ public function __construct($meta = 0){ $this->material = Material::$stone; $this->lightBlock = 255; } - + public function onActivate(Item $item, Player $player){ $player->craftingType = CraftingRecipes::TYPE_STONECUTTER; return true; @@ -24,6 +24,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 4b688228d..7c60603c7 100644 --- a/src/material/block/solid/WoodBlock.php +++ b/src/material/block/solid/WoodBlock.php @@ -6,31 +6,31 @@ 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; $this->breakTime = 2.0; $this->material = Material::$wood; $this->lightBlock = 255; } - + 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); @@ -54,8 +54,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/WorkbenchBlock.php b/src/material/block/solid/WorkbenchBlock.php index 3148a2231..5ca24f5f8 100644 --- a/src/material/block/solid/WorkbenchBlock.php +++ b/src/material/block/solid/WorkbenchBlock.php @@ -10,15 +10,15 @@ public function __construct($meta = 0){ $this->material = Material::$wood; $this->lightBlock = 255; } - + 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 64064b4e3..a224571de 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 ArmorMaterial::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 ceca50d2f..ab5967cd9 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 ArmorMaterial::CHAIN; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/armor/ChainHelmetItem.php b/src/material/item/armor/ChainHelmetItem.php index 4b13c6542..864eeee96 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 ArmorMaterial::CHAIN; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/ChainLeggingsItem.php b/src/material/item/armor/ChainLeggingsItem.php index 4ca503f5d..a7b1f270f 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 ArmorMaterial::CHAIN; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/DiamondBootsItem.php b/src/material/item/armor/DiamondBootsItem.php index 3a34c7a2b..e13df2402 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 ArmorMaterial::DIAMOND; } - + public function getBaseDurability(){ return 13; } diff --git a/src/material/item/armor/DiamondChestplateItem.php b/src/material/item/armor/DiamondChestplateItem.php index ce3ccc105..e2728b9b9 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 ArmorMaterial::DIAMOND; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/armor/DiamondHelmetItem.php b/src/material/item/armor/DiamondHelmetItem.php index 2ba995426..088c4747b 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 ArmorMaterial::DIAMOND; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/DiamondLeggingsItem.php b/src/material/item/armor/DiamondLeggingsItem.php index 59ea59934..7255dce9a 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 ArmorMaterial::DIAMOND; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/GoldenBootsItem.php b/src/material/item/armor/GoldenBootsItem.php index a31a7b726..d75711145 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 ArmorMaterial::GOLD; } - + public function getBaseDurability(){ return 13; } diff --git a/src/material/item/armor/GoldenChestplateItem.php b/src/material/item/armor/GoldenChestplateItem.php index 957dfd368..116cf9a49 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 ArmorMaterial::GOLD; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/armor/GoldenHelmetItem.php b/src/material/item/armor/GoldenHelmetItem.php index 62339bd50..9abe5c01e 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 ArmorMaterial::GOLD; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/GoldenLeggingsItem.php b/src/material/item/armor/GoldenLeggingsItem.php index 288416977..fb5054e8d 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 ArmorMaterial::GOLD; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/IronBootsItem.php b/src/material/item/armor/IronBootsItem.php index 07c01d240..2d091aba8 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 ArmorMaterial::IRON; } - + public function getBaseDurability(){ return 13; } diff --git a/src/material/item/armor/IronChestplateItem.php b/src/material/item/armor/IronChestplateItem.php index 499811dae..69d0ae5a5 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 ArmorMaterial::IRON; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/armor/IronHelmetItem.php b/src/material/item/armor/IronHelmetItem.php index fc3602c00..72704f10e 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 ArmorMaterial::IRON; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/IronLeggingsItem.php b/src/material/item/armor/IronLeggingsItem.php index 8b33465c2..593a15533 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 ArmorMaterial::IRON; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/LeatherBootsItem.php b/src/material/item/armor/LeatherBootsItem.php index f18988d53..034c2b82a 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 ArmorMaterial::LEATHER; } - + public function getBaseDurability(){ return 13; } diff --git a/src/material/item/armor/LeatherCapItem.php b/src/material/item/armor/LeatherCapItem.php index 2790bae18..d70140f87 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 ArmorMaterial::LEATHER; } - + public function getBaseDurability(){ return 11; } diff --git a/src/material/item/armor/LeatherPantsItem.php b/src/material/item/armor/LeatherPantsItem.php index d7ebfaf33..565f717c9 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 ArmorMaterial::LEATHER; } - + public function getBaseDurability(){ return 15; } diff --git a/src/material/item/armor/LeatherTunicItem.php b/src/material/item/armor/LeatherTunicItem.php index fe63643d6..cdc0d5a8b 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 ArmorMaterial::LEATHER; } - + public function getBaseDurability(){ return 16; } diff --git a/src/material/item/base/ItemAxe.php b/src/material/item/base/ItemAxe.php index 469bb551a..fc669ac7b 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/ItemPickaxe.php b/src/material/item/base/ItemPickaxe.php index 9f731f9c1..e7cc6fdf8 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/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 a96ede895..562400f9b 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/MinecartItem.php b/src/material/item/generic/MinecartItem.php index 19475feaf..f550e5472 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 329e92228..0fd6c6931 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 && $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/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/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/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/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/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/protocol/ProtocolInfo.php b/src/network/protocol/ProtocolInfo.php index 86dde7ed9..1418d913c 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 131b8079a..70a9cc3f5 100644 --- a/src/network/protocol/packet/AddItemEntityPacket.php +++ b/src/network/protocol/packet/AddItemEntityPacket.php @@ -11,6 +11,9 @@ class AddItemEntityPacket extends RakNetDataPacket{ public $speedZ; public function pid(){ + if($this->PROTOCOL < ProtocolInfo6::CURRENT_PROTOCOL_6){ + return ProtocolInfo4::ADD_ITEM_ENTITY_PACKET; + } return ProtocolInfo::ADD_ITEM_ENTITY_PACKET; } @@ -21,7 +24,7 @@ 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 56620be39..1cee76f2a 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 60337c469..8017344c9 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 166a27e1c..00881dc44 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 e8ce12253..31ee66c38 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 8d1fc1650..272546509 100644 --- a/src/network/protocol/packet/ContainerSetContentPacket.php +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -6,6 +6,19 @@ class ContainerSetContentPacket extends RakNetDataPacket{ public $hotbar = array(); 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; } @@ -15,11 +28,13 @@ public function decode(){ for($s = 0; $s < $count and !$this->feof(); ++$s){ $this->slots[$s] = $this->getSlot(); } - - $count = $this->getShort(); - for($s = 0; $s < $count and !$this->feof(); ++$s){ - $this->hotbar[$s] = $this->getInt(); - } + if($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9){ + return; + } + $count = $this->getShort(); + for($s = 0; $s < $count and !$this->feof(); ++$s){ + $this->hotbar[$s] = $this->getInt(); + } } public function encode(){ @@ -27,8 +42,11 @@ public function encode(){ $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 dd76ee218..c9fa9fa33 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 $randomly; 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->randomly = $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);*/ } public function eidsToGlobal(Player $p){ 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 767f4b5c1..ca7aa6e08 100644 --- a/src/network/protocol/packet/EntityEventPacket.php +++ b/src/network/protocol/packet/EntityEventPacket.php @@ -3,7 +3,7 @@ class EntityEventPacket extends RakNetDataPacket{ public $eid; public $event; - + const ENTITY_DAMAGE = 2; const ENTITY_DEAD = 3; /** @@ -11,21 +11,30 @@ class EntityEventPacket extends RakNetDataPacket{ */ const ENTITY_COMPLETE_USING_ITEM = 9; 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 dcc7f53c0..fe73beb2b 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 02930e1f3..61b5ba350 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 dc234b51c..d189449a1 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); + } } public function eidsToLocal(Player $p){ 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 743bf6742..7bec317ab 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);*/ } public function eidsToGlobal(Player $p){ diff --git a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php index c867232c7..db7eec47c 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 62af566ef..66bfea7d5 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);} } public function eidsToGlobal(Player $p){ 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 c314c20bf..dbd716f4d 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);*/ } public function eidsToGlobal(Player $p){ diff --git a/src/network/protocol/packet/RemoveEntityPacket.php b/src/network/protocol/packet/RemoveEntityPacket.php index fded3c761..670a4c774 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 4847aff60..1b2201fe6 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 7fc4fad65..9550425d3 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 781578586..de06551f1 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 375b70323..ea012548b 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 c30f35c90..f9030e9be 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 e01fa40a4..c9489bd94 100644 --- a/src/network/protocol/packet/SetEntityLinkPacket.php +++ b/src/network/protocol/packet/SetEntityLinkPacket.php @@ -23,8 +23,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 bc8ff9a18..cd71f52da 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 293a1b232..b1bcaa173 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 d3e6b9496..f0e36e032 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 6c2875dab..be89ec6b4 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);*/ } public function eidsToGlobal(Player $p){ if($this->localEids){ 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 10d11ee80..e5ea67ca6 100755 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -12,8 +12,10 @@ abstract class RakNetDataPacket extends stdClass{ public $splitID; public $splitIndex; public $seqIndex; + public $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL; + private $offset = 0; - + public abstract function encode(); public abstract function decode(); @@ -25,7 +27,7 @@ public function eidsToLocal(Player $p){ public function eidsToGlobal(Player $p){ return true; } - + public function getBuffer(){ return $this->buffer; } @@ -45,6 +47,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); } @@ -142,8 +152,8 @@ 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()); } diff --git a/src/network/raknet/RakNetInfo.php b/src/network/raknet/RakNetInfo.php index 2e5abf75c..9126f8fcb 100644 --- a/src/network/raknet/RakNetInfo.php +++ b/src/network/raknet/RakNetInfo.php @@ -47,7 +47,7 @@ abstract class RakNetInfo{ const RELIABILITY_RELIABLE_ORDERED_WITHACKRECEIPT = 7; 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/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/recipes/CraftingRecipes.php b/src/recipes/CraftingRecipes.php index 6ccbc1e90..e42a2da17 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 0664ad1a9..31ac1964c 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -181,9 +181,6 @@ private function writeProperties(){ return $content; } - /** - * @param $content - */ private function parseProperties($content){ $content2 = ""; foreach(explode("\n", $content) as $cnt){ //regex is very evil and malicious @@ -217,9 +214,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); @@ -231,8 +225,6 @@ private function parseList($content){ } /** - * @param $default - * @param $data * * @return integer */ @@ -268,7 +260,6 @@ public function reload(){ } /** - * @param $k * * @return boolean|mixed */ @@ -276,16 +267,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 */ @@ -298,7 +284,6 @@ public function &get($k){ } /** - * @param $k * @param bool $v */ public function set($k, $v = true){ @@ -306,7 +291,6 @@ public function set($k, $v = true){ } /** - * @param $k * * @return boolean */ @@ -315,7 +299,6 @@ public function __isset($k){ } /** - * @param $k * @param bool $lowercase If set, searches Config in single-case / lowercase. * * @return boolean @@ -330,16 +313,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/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 261c657fb..1751bc748 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; @@ -466,7 +466,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){