more canonical codestyle

This commit is contained in:
Sunch 2025-04-28 19:49:29 +08:00
parent 27554d29bd
commit 2b90f6499e
30 changed files with 1388 additions and 1689 deletions

View file

@ -17,9 +17,6 @@ return (new PhpCsFixer\Config)
'cast_spaces' => [
'space' => 'single'
],
'concat_space' => [
'spacing' => 'one'
],
'elseif' => true,
'indentation_type' => true,
'no_closing_tag' => true,

View file

@ -2,9 +2,7 @@
class Player{
public static $smallChunks = false;
public static $experimentalHotbar = false;
public static $smallChunks = false, $experimentalHotbar = false;
/** @var Config */
public $data;
/** @var Entity */
@ -84,8 +82,7 @@ class Player {
* @var boolean $isJumping
* @var boolean $isSneaking
*/
public $isJumping;
public $isSneaking;
public $isJumping, $isSneaking;
private $lastPing = -1;
@ -161,9 +158,8 @@ class Player {
}
$spawnPoint = BedBlock::findStandUpPosition($this->level, $pos->x, $pos->y, $pos->z);
if($spawnPoint == null) {
$spawnPoint = $pos->add(0.5, 1, 0.5);
} else {
if($spawnPoint == null) $spawnPoint = $pos->add(0.5, 1, 0.5);
else{
$spawnPoint->x += 0.5;
$spawnPoint->z += 0.5;
}
@ -314,9 +310,7 @@ class Player {
$this->entity->calculateVelocity();
if($terrain === true){
$this->orderChunks();
if($this->spawned) {
$this->getNextChunk($this->level);
}
if($this->spawned) $this->getNextChunk($this->level);
}
$this->entity->check = true;
if($force === true){
@ -381,9 +375,7 @@ class Player {
$sendtime = microtime(true);
$size = $this->MTU - 34;
if($size <= 0) {
return false;
}
if($size <= 0) return false;
$buffer = str_split($packet->buffer, $size);
$bigCnt = $this->bigCnt;
$this->bigCnt = ($this->bigCnt + 1) % 0x10000;
@ -913,14 +905,10 @@ class Player {
continue;
}
$item->count += $add;
if($send) {
$this->sendInventorySlot($s);
}
if($send) $this->sendInventorySlot($s);
$count -= $add;
if($count <= 0) {
return true;
}
if($count <= 0) return true;
}
}
$toadd = BlockAPI::getItem($type, $damage, $count);
@ -928,18 +916,12 @@ class Player {
if($item->getID() === AIR){
$add = min($toadd->getMaxStackSize(), $count);
$this->inventory[$s] = BlockAPI::getItem($type, $damage, $add);
if($send) {
$this->sendInventorySlot($s);
}
if($send) $this->sendInventorySlot($s);
$count -= $add;
if($count <= 0) {
return true;
if($count <= 0) return true;
}
}
}
if($count <= 0) {
return true;
}
if($count <= 0) return true;
return false;
}
@ -1000,9 +982,7 @@ class Player {
}
public function checkSpawnPosition(){
if($this->server->api->dhandle("player.checkspawnpos", ["player" => $this]) === false) {
return;
}
if($this->server->api->dhandle("player.checkspawnpos", ["player" => $this]) === false) return;
$level = $this->spawnPosition->level;
if(!isset($this->server->api->level->levels[$level->getName()])){
ConsoleAPI::warn("Level to respawn {$this->iusername} was unloaded, changing spawnpoint to default.");
@ -1252,13 +1232,12 @@ class Player {
$cnt = $this->send($data);
if(isset($this->chunkCount[$count])){
unset($this->chunkCount[$count]);
if(!is_null($cnt) and !is_null($cnt[0])) {
if(!is_null($cnt) and !is_null($cnt[0]))
$this->chunkCount[$cnt[0]] = true;
}
}
}
}
}
public function sendEntityMovementUpdateQueue(){
if($this->entityMovementQueueLength > 0 && $this->entityMovementQueue instanceof RakNetPacket){
$this->entityMovementQueue->seqNumber = $this->counter[0]++;
@ -1365,9 +1344,7 @@ class Player {
++$packets;
$headSent = true;
}
if($packets <= 0) {
return;
}
if($packets <= 0) return;
//console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent");
$MTU = $this->MTU - 24;
if(($this->entityMovementQueueLength + $len) >= $MTU){
@ -1500,9 +1477,7 @@ class Player {
return [$pk->seqNumber];
}
public function entityTick(){
if($this->isSleeping) {
++$this->sleepingTime;
}
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){
@ -1688,12 +1663,8 @@ class Player {
$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->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");
@ -1798,9 +1769,7 @@ class Player {
if($this->spawned === false){
break;
}
if($this->isSleeping) {
break;
}
if($this->isSleeping) break;
if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){
$this->lastMovement = $packet->messageIndex;
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
@ -1868,17 +1837,13 @@ class Player {
$data["slot"] = $packet->slot;
if($this->server->handle("player.equipment.change", $data) !== false){
if(!Player::$experimentalHotbar) {
$this->slot = $packet->slot;
}
if(!Player::$experimentalHotbar) $this->slot = $packet->slot;
if(($this->gamemode & 0x01) === SURVIVAL){
$has = false;
$slotPos = 0;
$packetSlotPos = 0;
for($i = 0; $i < $this->slotCount; ++$i){
if($this->slot == $this->hotbar[$i]) {
$slotPos = $i;
}
if($this->slot == $this->hotbar[$i]) $slotPos = $i;
if($packet->slot == $this->hotbar[$i]){
$packetSlotPos = $i;
$has = true;
@ -1900,9 +1865,7 @@ class Player {
array_unshift($this->hotbar, $this->slot);
}
}
if(Player::$experimentalHotbar) {
$this->sendInventory();
}
if(Player::$experimentalHotbar) $this->sendInventory();
}else{
$this->slot = $packet->slot;
}
@ -2037,11 +2000,8 @@ class Player {
if(($this->gamemode & 0x01) == 0x0) {
if($slotItem !== false){
if($slotItem->count == 1) {
$this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0);
} else {
$slotItem->count -= 1;
}
if($slotItem->count == 1) $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0);
else $slotItem->count -= 1;
//$this->sendInventory();
}
}
@ -2077,9 +2037,7 @@ class Player {
$power = $initalPower / 20;
$power = ($power * $power + $power * 2) / 3;
if($power >= 0.1){
if($power > 1) {
$power = 1;
}
if($power > 1) $power = 1;
$this->server->dhandle("player.shoot", [
"player" => $this,
"power" => &$power,
@ -2312,9 +2270,7 @@ class Player {
if($prevItem->getID() != $packet->item->getID() || $prevItem->getMetadata() != $packet->item->getMetadata()){
if(count($this->inventory) >= 36){
foreach($this->inventory as $slot => $item){
if($item->getID() == 0) {
goto inv_desync_on_drop;
}
if($item->getID() == 0) goto inv_desync_on_drop;
}
$this->toCraft[] = $prevItem; //vanilla drops only result?
@ -2878,7 +2834,7 @@ class Player {
/**
* @return string
*/
public function __toString() {
function __toString(){
if($this->username != ""){
return $this->username;
}

View file

@ -2,68 +2,17 @@
class PocketMinecraftServer{
public $tCnt;
public $ticks;
public $extraprops;
public $serverID;
public $interface;
public $database;
public $version;
public $invisible;
public $tickMeasure;
public $preparedSQL;
public $seed;
public $gamemode;
public $name;
public $maxClients;
public $clients;
public $eidCnt;
public $custom;
public $description;
public $motd;
public $port;
public $saveEnabled;
public $tCnt, $ticks;
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
/**
* @var ServerAPI
*/
public $api;
private $serverip;
private $evCnt;
private $handCnt;
private $events;
private $eventsID;
private $handlers;
private $serverType;
private $lastTick;
private $memoryStats;
private $async = [];
private $asyncID = 0;
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0;
public $doTick;
public $levelData;
public $tiles;
public $entities;
public $schedule;
public $scheduleCnt;
public $whitelist;
public $spawn;
public $difficulty;
public $stop;
public $asyncThread;
public static $FORCE_20_TPS = false;
public static $KEEP_CHUNKS_LOADED = true;
public static $PACKET_READING_LIMIT = 100;
public function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0") {
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true, $PACKET_READING_LIMIT = 100;
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
$this->port = (int) $port;
$this->doTick = true;
$this->gamemode = (int) $gamemode;
@ -524,7 +473,8 @@ class PocketMinecraftServer {
}
}
public function process() {
public function process()
{
$lastLoop = 0;
if(self::$FORCE_20_TPS){
while($this->stop === false){

View file

@ -1,9 +1,8 @@
<?php
class RailLogic {
public $x;
public $y;
public $z;
class RailLogic
{
public $x, $y, $z;
public $level;
/**
@ -92,76 +91,38 @@ class RailLogic {
}
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($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($hasZneg || $hasZpos) $state = 0;
if($hasXneg || $hasXpos) $state = 1;
if(!$this->isStraight){
if($b){
if($hasZpos && $hasXpos) {
$state = 6;
}
if($hasXneg && $hasZpos) {
$state = 7;
}
if($hasXpos && $hasZneg) {
$state = 9;
}
if($hasZneg && $hasXneg) {
$state = 8;
}
if($hasZpos && $hasXpos) $state = 6;
if($hasXneg && $hasZpos) $state = 7;
if($hasXpos && $hasZneg) $state = 9;
if($hasZneg && $hasXneg) $state = 8;
}else{
if($hasZneg && $hasXneg) {
$state = 8;
}
if($hasXpos && $hasZneg) {
$state = 9;
}
if($hasXneg && $hasZpos) {
$state = 7;
}
if($hasZpos && $hasXpos) {
$state = 6;
}
if($hasZneg && $hasXneg) $state = 8;
if($hasXpos && $hasZneg) $state = 9;
if($hasXneg && $hasZpos) $state = 7;
if($hasZpos && $hasXpos) $state = 6;
}
}
}
if($state === 0){
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) {
$state = 4;
}
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) {
$state = 5;
}
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4;
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) $state = 5;
}elseif($state === 1){
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) {
$state = 2;
}
if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) {
$state = 3;
}
} elseif($state < 0) {
$state = 0;
}
if(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;
@ -191,9 +152,7 @@ class RailLogic {
public function hasConnection($x, $y, $z){
foreach($this->railPositions as $rpos){
if($rpos->x === $x && $rpos->z === $z) {
return true;
}
if($rpos->x === $x && $rpos->z === $z) return true;
}
return false;
}
@ -207,45 +166,23 @@ class RailLogic {
$hasXpos = $this->hasConnection($this->x + 1, $this->y, $this->z);
$state = -1;
if($hasZneg || $hasZpos) {
$state = 0;
}
if($hasXneg || $hasXpos) {
$state = 1;
}
if($hasZneg || $hasZpos) $state = 0;
if($hasXneg || $hasXpos) $state = 1;
if(!$this->isStraight){
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) {
$state = 6;
}
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) {
$state = 7;
}
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) {
$state = 8;
}
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) {
$state = 9;
}
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) $state = 6;
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) $state = 7;
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) $state = 8;
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) $state = 9;
}
if($state == 0){
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) {
$state = 4;
}
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) {
$state = 5;
}
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4;
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) $state = 5;
}elseif($state == 1){
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) {
$state = 2;
}
if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) {
$state = 3;
}
} elseif($state < 0) {
$state = 0;
}
if(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;
@ -307,3 +244,4 @@ class RailLogic {
}
}
}

View file

@ -19,30 +19,10 @@ class Level {
*/
public $players = [];
public $tiles;
public $tiles, $blockUpdates, $nextSave, $level, $mobSpawner, $totalMobsAmount = 0;
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
public $blockUpdates;
public $nextSave;
public $level;
public $mobSpawner;
public $totalMobsAmount = 0;
private $time;
private $startCheck;
private $startTime;
private $server;
private $name;
private $usedChunks;
private $changedBlocks;
private $changedCount;
private $stopTime;
public $randInt1;
public $randInt2;
public $randInt1, $randInt2;
public $queuedBlockUpdates = [];
public $forceDisableBlockQueue = false;
@ -97,12 +77,8 @@ class Level {
$idmeta = $this->level->getBlock($x, $y, $z);
$id = $idmeta[0];
$meta = $idmeta[1];
if($id == 0) {
return false;
}
if(StaticBlock::getIsTransparent($id)) {
return false;
}
if($id == 0) return false;
if(StaticBlock::getIsTransparent($id)) return false;
return true;
}
@ -126,9 +102,7 @@ class Level {
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck
$v14 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end);
if($v14 != null) {
return $v14;
}
if($v14 != null) return $v14;
}
for($i = 0; $i <= 200; ++$i){
@ -140,44 +114,26 @@ class Level {
$v39 = $v40 = $v41 = true;
$v15 = $v17 = $v19 = 999.0; //nice mojang
if($xEnd > $xStart) {
$v15 = $xStart + 1;
} elseif($xEnd < $xStart) {
$v15 = $xStart;
} else {
$v39 = false;
}
if($xEnd > $xStart) $v15 = $xStart + 1;
elseif($xEnd < $xStart) $v15 = $xStart;
else $v39 = false;
if($yEnd > $yStart) {
$v17 = $yStart + 1;
} elseif($yEnd < $yStart) {
$v17 = $yStart;
} else {
$v40 = false;
}
if($yEnd > $yStart) $v17 = $yStart + 1;
elseif($yEnd < $yStart) $v17 = $yStart;
else $v40 = false;
if($zEnd > $zStart) {
$v19 = $zStart + 1;
} elseif($zEnd < $zStart) {
$v19 = $zStart;
} else {
$v41 = false;
}
if($zEnd > $zStart) $v19 = $zStart + 1;
elseif($zEnd < $zStart) $v19 = $zStart;
else $v41 = false;
$v21 = $v23 = $v25 = 999.0; //nice mojang x2
$v27 = $end->x - $start->x;
$v29 = $end->y - $start->y;
$v31 = $end->z - $start->z;
if($v39) {
$v21 = $v27 == 0 ? ($v15 - $start->x) * INF : ($v15 - $start->x) / $v27;
}
if($v40) {
$v23 = $v29 == 0 ? ($v17 - $start->y) * INF : ($v17 - $start->y) / $v29;
}
if($v41) {
$v25 = $v31 == 0 ? ($v19 - $start->z) * INF : ($v19 - $start->z) / $v31;
}
if($v39) $v21 = $v27 == 0 ? ($v15 - $start->x) * INF : ($v15 - $start->x) / $v27;
if($v40) $v23 = $v29 == 0 ? ($v17 - $start->y) * INF : ($v17 - $start->y) / $v29;
if($v41) $v25 = $v31 == 0 ? ($v19 - $start->z) * INF : ($v19 - $start->z) / $v31;
if($v21 < $v23 && $v21 < $v25){
$v42 = $xEnd > $xStart ? 4 : 5;
@ -200,19 +156,13 @@ class Level {
}
$xStart = floor($start->x);
if($v42 == 5) {
--$xStart;
}
if($v42 == 5) --$xStart;
$yStart = floor($start->y);
if($v42 == 1) {
--$yStart;
}
if($v42 == 1) --$yStart;
$zStart = floor($start->z);
if($v42 == 3) {
--$zStart;
}
if($v42 == 3) --$zStart;
[$blockID, $blockMeta] = $this->level->getBlock($xStart, $yStart, $zStart);
$block = StaticBlock::getBlock($blockID);
@ -220,9 +170,7 @@ class Level {
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
if($blockID > 0 && $aabb != null){ //TODO also block::canColideCheck
$v38 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end);
if($v38 != null) {
return $v38;
}
if($v38 != null) return $v38;
}
}
@ -242,9 +190,7 @@ class Level {
for($z = $minZ; $z < $maxZ; ++$z){
$blockId = $this->level->getBlockID($x, $y, $z);
if($blockId == LAVA || $blockId == STILL_LAVA) {
return true;
}
if($blockId == LAVA || $blockId == STILL_LAVA) return true;
}
}
}
@ -310,9 +256,7 @@ class Level {
$blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
foreach($blockBounds as $blockBound){
if($aABB->intersectsWith($blockBound)) {
$aABBs[] = $blockBound;
}
if($aABB->intersectsWith($blockBound)) $aABBs[] = $blockBound;
}
}
}
@ -426,9 +370,7 @@ class Level {
}
public function checkSleep(){ //TODO events?
if(count($this->players) == 0) {
return false;
}
if(count($this->players) == 0) return false;
if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla
foreach($this->players as $p){
if(!$p->isSleeping || $p->sleepingTime < 100){
@ -534,31 +476,19 @@ class Level {
public function updateNeighborsAt($x, $y, $z, $oldID){
$block = $this->level->getBlockID($x - 1, $y, $z);
if($block) {
StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID);
}
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID);
$block = $this->level->getBlockID($x + 1, $y, $z);
if($block) {
StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID);
}
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID);
$block = $this->level->getBlockID($x, $y - 1, $z);
if($block) {
StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID);
}
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID);
$block = $this->level->getBlockID($x, $y + 1, $z);
if($block) {
StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID);
}
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID);
$block = $this->level->getBlockID($x, $y, $z - 1);
if($block) {
StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID);
}
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID);
$block = $this->level->getBlockID($x, $y, $z + 1);
if($block) {
StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID);
}
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID);
}
public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false){
@ -576,15 +506,11 @@ class Level {
}
public function onTick(PocketMinecraftServer $server, $currentTime){
if(!$this->stopTime) {
++$this->time;
}
if(!$this->stopTime) ++$this->time;
for($cX = 0; $cX < 16; ++$cX){
for($cZ = 0; $cZ < 16; ++$cZ){
$index = $this->level->getIndex($cX, $cZ);
if(!isset($this->level->chunks[$index]) || $this->level->chunks[$index] === false) {
continue;
}
if(!isset($this->level->chunks[$index]) || $this->level->chunks[$index] === false) continue;
for($c = 0; $c <= 20; ++$c){
$xyz = mt_rand(0, 0xffffffff) >> 2;
$x = $xyz & 0xf;
@ -634,9 +560,7 @@ class Level {
}
if($e->isPlayer() || $e->needsUpdate){
$e->update($currentTime);
if(!$e->isPlayer()) {
$post[] = $k;
}
if(!$e->isPlayer()) $post[] = $k;
}
if($e instanceof Entity){
@ -719,9 +643,7 @@ class Level {
for($y = $minY; $y < $maxY; ++$y){
for($z = $minZ; $z < $maxZ; ++$z){
$blockAt = $this->level->getBlockID($x, $y, $z);
if($blockAt == FIRE || $blockAt == STILL_LAVA || $blockAt == LAVA) {
return true;
}
if($blockAt == FIRE || $blockAt == STILL_LAVA || $blockAt == LAVA) return true;
}
}
}

View file

@ -86,27 +86,13 @@ class LevelImport {
}
$chunks->map = null;
$chunks = null;
if(file_exists($this->path . "level.dat")) {
@unlink($this->path . "level.dat");
}
if(file_exists($this->path . "level.dat_old")) {
@unlink($this->path . "level.dat_old");
}
if(file_exists($this->path . "player.dat")) {
@unlink($this->path . "player.dat");
}
if(file_exists($this->path . "entities.dat")) {
@unlink($this->path . "entities.dat");
}
if(file_exists($this->path . "chunks.dat")) {
@unlink($this->path . "chunks.dat");
}
if(file_exists($this->path . "chunks.dat.gz")) {
@unlink($this->path . "chunks.dat.gz");
}
if(file_exists($this->path . "tiles.dat")) {
@unlink($this->path . "tiles.dat");
}
if(file_exists($this->path . "level.dat")) @unlink($this->path . "level.dat");
if(file_exists($this->path . "level.dat_old")) @unlink($this->path . "level.dat_old");
if(file_exists($this->path . "player.dat")) @unlink($this->path . "player.dat");
if(file_exists($this->path . "entities.dat")) @unlink($this->path . "entities.dat");
if(file_exists($this->path . "chunks.dat")) @unlink($this->path . "chunks.dat");
if(file_exists($this->path . "chunks.dat.gz")) @unlink($this->path . "chunks.dat.gz");
if(file_exists($this->path . "tiles.dat")) @unlink($this->path . "tiles.dat");
unset($chunks, $level, $entities, $tiles, $nbt);
return true;
}

View file

@ -1,9 +1,7 @@
<?php
class MobSpawner{
public static $spawnAnimals = false;
public static $spawnMobs = false;
public static $maxMobsNearPlayerAtOnce = 10;
public static $spawnAnimals = false, $spawnMobs = false, $maxMobsNearPlayerAtOnce = 10;
private $server;
public $level;
public $totalMobsPerPlayer;
@ -49,9 +47,7 @@ class MobSpawner {
}
$svd = $this->totalMobsPerPlayer;
$this->totalMobsPerPlayer = min(ceil(self::$MOB_LIMIT / count($this->level->players)), self::$maxMobsNearPlayerAtOnce);
if($svd != $this->totalMobsPerPlayer) {
ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}.");
}
if($svd != $this->totalMobsPerPlayer) ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}.");
return $this->spawnMobs();
}
@ -97,9 +93,7 @@ class MobSpawner {
}
$data = $this->genPosData($xMob, $y + 0.5, $zMob);
if($baby != 2) {
$data["IsBaby"] = $baby;
}
if($baby != 2) $data["IsBaby"] = $baby;
$e = $this->server->api->entity->add($this->level, 2, $type, $data);
@ -147,3 +141,4 @@ class MobSpawner {
return empty($allowed) ? -1 : $allowed[mt_rand(0, count($allowed) - 1)];
}
}

View file

@ -2,12 +2,10 @@
class PocketChunkParser{
public $sectorLength = 4096;
public $chunkLength = 86016; //16 * 16 * 16
public $map; //21 * $sectorLength
private $location;
private $raw = b"";
private $file;
var $sectorLength = 4096;
var $chunkLength = 86016; //16 * 16 * 16
var $map; //21 * $sectorLength
private $location, $raw = b"", $file;
public function loadFile($file){
if(file_exists($file . ".gz")){

View file

@ -15,11 +15,9 @@ class Tile extends Position {
public $closed;
private $server;
public $scheduledUpdate;
public $scheduledUpdate, $lastUpdate;
public $lastUpdate;
public function __construct(Level $level, $id, $class, $x, $y, $z, $data = []) {
function __construct(Level $level, $id, $class, $x, $y, $z, $data = []){
$this->server = ServerAPI::request();
$this->level = $level;
$this->normal = true;

View file

@ -6,9 +6,7 @@ require_once("NoiseGenerator.php");
/***REM_END***/
class NoiseGeneratorPerlin extends NoiseGenerator{
public $xCoord;
public $yCoord;
public $zCoord;
public $xCoord, $yCoord, $zCoord;
private $permutations = [];
public function __construct(MTRandom $random){
@ -147,7 +145,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator {
}
}
final public static function curve($par1, $par2, $par3) {
public static final function curve($par1, $par2, $par3){
return $par2 + $par1 * ($par3 - $par2);
}

View file

@ -2,7 +2,8 @@
define("EMPTY_MINI_CHUNK", str_repeat("\x00", 8192));
define("EMPTY_16x16_ARR", array_fill(0, 256, 0));
class VanillaGenerator implements LevelGenerator {
class VanillaGenerator implements LevelGenerator
{
/**
* @var Level
*/
@ -22,14 +23,7 @@ class VanillaGenerator implements LevelGenerator {
* @var NoiseGeneratorOctaves $depthNoise
* @var NoiseGeneratorOctaves $treeNoise
*/
private $upperInterpolationNoise;
private $lowerInterpolationNoise;
private $interpolationNoise;
private $beachNoise;
private $surfaceDepthNoise;
private $biomeNoise;
private $depthNoise;
private $treeNoise;
private $upperInterpolationNoise, $lowerInterpolationNoise, $interpolationNoise, $beachNoise, $surfaceDepthNoise, $biomeNoise, $depthNoise, $treeNoise;
/**
* @var float[] $biomeNoises
* @var float[] $depthNoises
@ -42,16 +36,7 @@ class VanillaGenerator implements LevelGenerator {
* @var float[] $gravelNoises
* @var float[] $surfaceDepthNoises
*/
private $biomeNoises;
private $depthNoises;
private $interpolationNoises;
private $upperInterpolationNoises;
private $lowerInterpolationNoises;
private $biomes;
private $heights;
private $sandNoises;
private $gravelNoises;
private $surfaceDepthNoises;
private $biomeNoises, $depthNoises, $interpolationNoises, $upperInterpolationNoises, $lowerInterpolationNoises, $biomes, $heights, $sandNoises, $gravelNoises, $surfaceDepthNoises;
/**
* @var BiomeSource
*/
@ -59,10 +44,12 @@ class VanillaGenerator implements LevelGenerator {
private $heightMap = [];
public function __construct(array $options = []) {
public function __construct(array $options = [])
{
}
public function init(Level $level, Random $random) {
public function init(Level $level, Random $random)
{
$this->level = $level;
$this->biomeSource = new BiomeSource($level);
$this->rand = new MTRandom($level->getSeed());
@ -76,11 +63,13 @@ class VanillaGenerator implements LevelGenerator {
$this->treeNoise = new NoiseGeneratorOctaves($this->rand, 8);
}
public function getSpawn() {
public function getSpawn()
{
return new Vector3(128, 64, 128);
}
public function populateChunk($chunkX, $chunkZ) {
public function populateChunk($chunkX, $chunkZ)
{
$chunkXWorld = $chunkX * 16;
$chunkZWorld = $chunkZ * 16;
//HeavyTile::instaFall = 1; TODO instant sand/gravel fall
@ -116,21 +105,13 @@ class VanillaGenerator implements LevelGenerator {
$sample = (int) (((($this->treeNoise->getValue($chunkXWorld * 0.5, $chunkZWorld * 0.5) / 8) + ($this->rand->nextFloat() * 4)) + 4) / 3);
$treesAmount = $this->rand->nextInt(10) == 0;
if($biome == Biome::$forest) {
$treesAmount += $sample + 2;
} elseif($biome == Biome::$rainForest) {
$treesAmount += $sample + 2;
} elseif($biome == Biome::$seasonalForest) {
$treesAmount += $sample + 1;
} elseif($biome == Biome::$taiga) {
$treesAmount += $sample + 1;
} elseif($biome == Biome::$desert) {
$treesAmount -= 20;
} elseif($biome == Biome::$tundra) {
$treesAmount -= 20;
} elseif($biome == Biome::$plains) {
$treesAmount -= 20;
}
if($biome == Biome::$forest) $treesAmount += $sample + 2;
elseif($biome == Biome::$rainForest) $treesAmount += $sample + 2;
elseif($biome == Biome::$seasonalForest) $treesAmount += $sample + 1;
elseif($biome == Biome::$taiga) $treesAmount += $sample + 1;
elseif($biome == Biome::$desert) $treesAmount -= 20;
elseif($biome == Biome::$tundra) $treesAmount -= 20;
elseif($biome == Biome::$plains) $treesAmount -= 20;
for($l8 = 0; $l8 < $treesAmount; ++$l8){
$l12 = $chunkXWorld + $this->rand->nextInt(16) + 8;
$j15 = $chunkZWorld + $this->rand->nextInt(16) + 8;
@ -166,7 +147,8 @@ class VanillaGenerator implements LevelGenerator {
}
}
public function generateChunk($chunkX, $chunkZ) {
public function generateChunk($chunkX, $chunkZ)
{
$this->rand->setSeed(341872712 * $chunkX + 132899541 * $chunkZ);
$this->biomes = $this->biomeSource->getBiomeBlock($chunkX * 16, $chunkZ * 16, 16, 16);
$chunkz = array_fill(0, 8, EMPTY_MINI_CHUNK); //[$blockY >> 4][($blockY & 0xf) + ($blockX << 5) + ($blockZ << 9)]. y&f+x&f+z&f
@ -184,12 +166,10 @@ class VanillaGenerator implements LevelGenerator {
}
public function populateLevel() {
}
public function populateLevel()
{}
public function setHeightValue($x, $z, $hv){
if($x > 255 || $x < 0 || $z > 255 || $z < 0) {
return;
}
if($x > 255 || $x < 0 || $z > 255 || $z < 0) return;
$cX = $x >> 4;
$cZ = $z >> 4;
$bX = $x & 0xf;
@ -197,9 +177,7 @@ class VanillaGenerator implements LevelGenerator {
$this->heightMap[$cX + ($cZ * 16)][$bX + ($bZ * 16)] = $hv;
}
public function getHeightValue($x, $z){
if($x > 255 || $x < 0 || $z > 255 || $z < 0) {
return 0;
}
if($x > 255 || $x < 0 || $z > 255 || $z < 0) return 0;
$cX = $x >> 4;
$cZ = $z >> 4;
$bX = $x & 0xf;
@ -366,33 +344,23 @@ class VanillaGenerator implements LevelGenerator {
$d5 = (($this->biomeNoises[$l1] + 256) / 512);
$d5 *= $d4;
if($d5 > 1) {
$d5 = 1;
}
if($d5 > 1) $d5 = 1;
$d6 = $this->depthNoises[$l1] / 8000;
if($d6 < 0) {
$d6 = -$d6 * 0.3;
}
if($d6 < 0) $d6 = -$d6 * 0.3;
$d6 = $d6 * 3 - 2;
if($d6 < 0){
$d6 /= 2;
if($d6 < -1) {
$d6 = -1;
}
if($d6 < -1) $d6 = -1;
$d6 /= 1.4;
$d6 /= 2;
$d5 = 0;
}else{
if($d6 > 1) {
$d6 = 1;
}
if($d6 > 1) $d6 = 1;
$d6 /= 8;
}
if($d5 < 0) {
$d5 = 0;
}
if($d5 < 0) $d5 = 0;
$d5 += 0.5;
$d6 = ($d6 * $scaleY) / 16;
@ -401,20 +369,14 @@ class VanillaGenerator implements LevelGenerator {
for($j3 = 0; $j3 < $scaleY; ++$j3){
$d8 = 0;
$d9 = (((float) $j3 - $d7) * 12) / $d5;
if($d9 < 0) {
$d9 *= 4;
}
if($d9 < 0) $d9 *= 4;
$d10 = $this->upperInterpolationNoises[$k1] / 512;
$d11 = $this->lowerInterpolationNoises[$k1] / 512;
$d12 = ($this->interpolationNoises[$k1] / 10 + 1) / 2;
if($d12 < 0) {
$d8 = $d10;
} elseif($d12 > 1) {
$d8 = $d11;
} else {
$d8 = $d10 + ($d11 - $d10) * $d12;
}
if($d12 < 0) $d8 = $d10;
elseif($d12 > 1) $d8 = $d11;
else $d8 = $d10 + ($d11 - $d10) * $d12;
$d8 -= $d9;
if($j3 > $scaleY - 4){
@ -431,3 +393,4 @@ class VanillaGenerator implements LevelGenerator {
}
}

View file

@ -1,17 +1,14 @@
<?php
class TreeFeature extends Feature {
class TreeFeature extends Feature
{
public function place(Level $level, MTRandom $rand, $x, $y, $z){
$nextInt = $rand->nextInt(3) + 4;
$z2 = true;
if($y < 1 || $y + $nextInt + 1 > 128) {
return false;
}
if($y < 1 || $y + $nextInt + 1 > 128) return false;
for($i = $y; $i <= $y + 1 + $nextInt; ++$i){
$i2 = ($i == $y) ? 0 : 1;
if($i >= (($y + 1) + $nextInt) - 2) {
$i2 = 2;
}
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){
@ -53,3 +50,4 @@ class TreeFeature extends Feature {
}
}
}