mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 04:59:46 +00:00
more canonical codestyle
This commit is contained in:
parent
27554d29bd
commit
2b90f6499e
30 changed files with 1388 additions and 1689 deletions
|
|
@ -17,9 +17,6 @@ return (new PhpCsFixer\Config)
|
||||||
'cast_spaces' => [
|
'cast_spaces' => [
|
||||||
'space' => 'single'
|
'space' => 'single'
|
||||||
],
|
],
|
||||||
'concat_space' => [
|
|
||||||
'spacing' => 'one'
|
|
||||||
],
|
|
||||||
'elseif' => true,
|
'elseif' => true,
|
||||||
'indentation_type' => true,
|
'indentation_type' => true,
|
||||||
'no_closing_tag' => true,
|
'no_closing_tag' => true,
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
class Player{
|
class Player{
|
||||||
|
|
||||||
public static $smallChunks = false;
|
public static $smallChunks = false, $experimentalHotbar = false;
|
||||||
|
|
||||||
public static $experimentalHotbar = false;
|
|
||||||
/** @var Config */
|
/** @var Config */
|
||||||
public $data;
|
public $data;
|
||||||
/** @var Entity */
|
/** @var Entity */
|
||||||
|
|
@ -84,8 +82,7 @@ class Player {
|
||||||
* @var boolean $isJumping
|
* @var boolean $isJumping
|
||||||
* @var boolean $isSneaking
|
* @var boolean $isSneaking
|
||||||
*/
|
*/
|
||||||
public $isJumping;
|
public $isJumping, $isSneaking;
|
||||||
public $isSneaking;
|
|
||||||
|
|
||||||
private $lastPing = -1;
|
private $lastPing = -1;
|
||||||
|
|
||||||
|
|
@ -161,9 +158,8 @@ class Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
$spawnPoint = BedBlock::findStandUpPosition($this->level, $pos->x, $pos->y, $pos->z);
|
$spawnPoint = BedBlock::findStandUpPosition($this->level, $pos->x, $pos->y, $pos->z);
|
||||||
if($spawnPoint == null) {
|
if($spawnPoint == null) $spawnPoint = $pos->add(0.5, 1, 0.5);
|
||||||
$spawnPoint = $pos->add(0.5, 1, 0.5);
|
else{
|
||||||
} else {
|
|
||||||
$spawnPoint->x += 0.5;
|
$spawnPoint->x += 0.5;
|
||||||
$spawnPoint->z += 0.5;
|
$spawnPoint->z += 0.5;
|
||||||
}
|
}
|
||||||
|
|
@ -314,9 +310,7 @@ class Player {
|
||||||
$this->entity->calculateVelocity();
|
$this->entity->calculateVelocity();
|
||||||
if($terrain === true){
|
if($terrain === true){
|
||||||
$this->orderChunks();
|
$this->orderChunks();
|
||||||
if($this->spawned) {
|
if($this->spawned) $this->getNextChunk($this->level);
|
||||||
$this->getNextChunk($this->level);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$this->entity->check = true;
|
$this->entity->check = true;
|
||||||
if($force === true){
|
if($force === true){
|
||||||
|
|
@ -381,9 +375,7 @@ class Player {
|
||||||
$sendtime = microtime(true);
|
$sendtime = microtime(true);
|
||||||
|
|
||||||
$size = $this->MTU - 34;
|
$size = $this->MTU - 34;
|
||||||
if($size <= 0) {
|
if($size <= 0) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$buffer = str_split($packet->buffer, $size);
|
$buffer = str_split($packet->buffer, $size);
|
||||||
$bigCnt = $this->bigCnt;
|
$bigCnt = $this->bigCnt;
|
||||||
$this->bigCnt = ($this->bigCnt + 1) % 0x10000;
|
$this->bigCnt = ($this->bigCnt + 1) % 0x10000;
|
||||||
|
|
@ -913,14 +905,10 @@ class Player {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$item->count += $add;
|
$item->count += $add;
|
||||||
if($send) {
|
if($send) $this->sendInventorySlot($s);
|
||||||
$this->sendInventorySlot($s);
|
|
||||||
}
|
|
||||||
|
|
||||||
$count -= $add;
|
$count -= $add;
|
||||||
if($count <= 0) {
|
if($count <= 0) return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$toadd = BlockAPI::getItem($type, $damage, $count);
|
$toadd = BlockAPI::getItem($type, $damage, $count);
|
||||||
|
|
@ -928,18 +916,12 @@ class Player {
|
||||||
if($item->getID() === AIR){
|
if($item->getID() === AIR){
|
||||||
$add = min($toadd->getMaxStackSize(), $count);
|
$add = min($toadd->getMaxStackSize(), $count);
|
||||||
$this->inventory[$s] = BlockAPI::getItem($type, $damage, $add);
|
$this->inventory[$s] = BlockAPI::getItem($type, $damage, $add);
|
||||||
if($send) {
|
if($send) $this->sendInventorySlot($s);
|
||||||
$this->sendInventorySlot($s);
|
|
||||||
}
|
|
||||||
$count -= $add;
|
$count -= $add;
|
||||||
if($count <= 0) {
|
if($count <= 0) return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if($count <= 0) return true;
|
||||||
if($count <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1000,9 +982,7 @@ class Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkSpawnPosition(){
|
public function checkSpawnPosition(){
|
||||||
if($this->server->api->dhandle("player.checkspawnpos", ["player" => $this]) === false) {
|
if($this->server->api->dhandle("player.checkspawnpos", ["player" => $this]) === false) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
$level = $this->spawnPosition->level;
|
$level = $this->spawnPosition->level;
|
||||||
if(!isset($this->server->api->level->levels[$level->getName()])){
|
if(!isset($this->server->api->level->levels[$level->getName()])){
|
||||||
ConsoleAPI::warn("Level to respawn {$this->iusername} was unloaded, changing spawnpoint to default.");
|
ConsoleAPI::warn("Level to respawn {$this->iusername} was unloaded, changing spawnpoint to default.");
|
||||||
|
|
@ -1252,13 +1232,12 @@ class Player {
|
||||||
$cnt = $this->send($data);
|
$cnt = $this->send($data);
|
||||||
if(isset($this->chunkCount[$count])){
|
if(isset($this->chunkCount[$count])){
|
||||||
unset($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;
|
$this->chunkCount[$cnt[0]] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
public function sendEntityMovementUpdateQueue(){
|
public function sendEntityMovementUpdateQueue(){
|
||||||
if($this->entityMovementQueueLength > 0 && $this->entityMovementQueue instanceof RakNetPacket){
|
if($this->entityMovementQueueLength > 0 && $this->entityMovementQueue instanceof RakNetPacket){
|
||||||
$this->entityMovementQueue->seqNumber = $this->counter[0]++;
|
$this->entityMovementQueue->seqNumber = $this->counter[0]++;
|
||||||
|
|
@ -1365,9 +1344,7 @@ class Player {
|
||||||
++$packets;
|
++$packets;
|
||||||
$headSent = true;
|
$headSent = true;
|
||||||
}
|
}
|
||||||
if($packets <= 0) {
|
if($packets <= 0) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
//console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent");
|
//console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent");
|
||||||
$MTU = $this->MTU - 24;
|
$MTU = $this->MTU - 24;
|
||||||
if(($this->entityMovementQueueLength + $len) >= $MTU){
|
if(($this->entityMovementQueueLength + $len) >= $MTU){
|
||||||
|
|
@ -1500,9 +1477,7 @@ class Player {
|
||||||
return [$pk->seqNumber];
|
return [$pk->seqNumber];
|
||||||
}
|
}
|
||||||
public function entityTick(){
|
public function entityTick(){
|
||||||
if($this->isSleeping) {
|
if($this->isSleeping) ++$this->sleepingTime;
|
||||||
++$this->sleepingTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->server->difficulty == 0 && $this->entity->counter % (20 * 15) == 0){
|
if($this->server->difficulty == 0 && $this->entity->counter % (20 * 15) == 0){
|
||||||
if($this->entity->health < 20 && $this->entity->health > 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];
|
$this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||||
}
|
}
|
||||||
for($i = 0; $i < count($this->hotbar); ++$i){
|
for($i = 0; $i < count($this->hotbar); ++$i){
|
||||||
if($this->hotbar[$i] > 36) {
|
if($this->hotbar[$i] > 36) $this->hotbar[$i] = -1; //XXX unsafe?
|
||||||
$this->hotbar[$i] = -1;
|
if($this->hotbar[$i] < -1) $this->hotbar[$i] = -1;
|
||||||
} //XXX unsafe?
|
|
||||||
if($this->hotbar[$i] < -1) {
|
|
||||||
$this->hotbar[$i] = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if($this->data->exists("slot-count")){
|
if($this->data->exists("slot-count")){
|
||||||
$this->slotCount = $this->data->get("slot-count");
|
$this->slotCount = $this->data->get("slot-count");
|
||||||
|
|
@ -1798,9 +1769,7 @@ class Player {
|
||||||
if($this->spawned === false){
|
if($this->spawned === false){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if($this->isSleeping) {
|
if($this->isSleeping) break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){
|
if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){
|
||||||
$this->lastMovement = $packet->messageIndex;
|
$this->lastMovement = $packet->messageIndex;
|
||||||
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
|
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
|
||||||
|
|
@ -1868,17 +1837,13 @@ class Player {
|
||||||
$data["slot"] = $packet->slot;
|
$data["slot"] = $packet->slot;
|
||||||
|
|
||||||
if($this->server->handle("player.equipment.change", $data) !== false){
|
if($this->server->handle("player.equipment.change", $data) !== false){
|
||||||
if(!Player::$experimentalHotbar) {
|
if(!Player::$experimentalHotbar) $this->slot = $packet->slot;
|
||||||
$this->slot = $packet->slot;
|
|
||||||
}
|
|
||||||
if(($this->gamemode & 0x01) === SURVIVAL){
|
if(($this->gamemode & 0x01) === SURVIVAL){
|
||||||
$has = false;
|
$has = false;
|
||||||
$slotPos = 0;
|
$slotPos = 0;
|
||||||
$packetSlotPos = 0;
|
$packetSlotPos = 0;
|
||||||
for($i = 0; $i < $this->slotCount; ++$i){
|
for($i = 0; $i < $this->slotCount; ++$i){
|
||||||
if($this->slot == $this->hotbar[$i]) {
|
if($this->slot == $this->hotbar[$i]) $slotPos = $i;
|
||||||
$slotPos = $i;
|
|
||||||
}
|
|
||||||
if($packet->slot == $this->hotbar[$i]){
|
if($packet->slot == $this->hotbar[$i]){
|
||||||
$packetSlotPos = $i;
|
$packetSlotPos = $i;
|
||||||
$has = true;
|
$has = true;
|
||||||
|
|
@ -1900,9 +1865,7 @@ class Player {
|
||||||
array_unshift($this->hotbar, $this->slot);
|
array_unshift($this->hotbar, $this->slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Player::$experimentalHotbar) {
|
if(Player::$experimentalHotbar) $this->sendInventory();
|
||||||
$this->sendInventory();
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
$this->slot = $packet->slot;
|
$this->slot = $packet->slot;
|
||||||
}
|
}
|
||||||
|
|
@ -2037,11 +2000,8 @@ class Player {
|
||||||
|
|
||||||
if(($this->gamemode & 0x01) == 0x0) {
|
if(($this->gamemode & 0x01) == 0x0) {
|
||||||
if($slotItem !== false){
|
if($slotItem !== false){
|
||||||
if($slotItem->count == 1) {
|
if($slotItem->count == 1) $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0);
|
||||||
$this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0);
|
else $slotItem->count -= 1;
|
||||||
} else {
|
|
||||||
$slotItem->count -= 1;
|
|
||||||
}
|
|
||||||
//$this->sendInventory();
|
//$this->sendInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2077,9 +2037,7 @@ class Player {
|
||||||
$power = $initalPower / 20;
|
$power = $initalPower / 20;
|
||||||
$power = ($power * $power + $power * 2) / 3;
|
$power = ($power * $power + $power * 2) / 3;
|
||||||
if($power >= 0.1){
|
if($power >= 0.1){
|
||||||
if($power > 1) {
|
if($power > 1) $power = 1;
|
||||||
$power = 1;
|
|
||||||
}
|
|
||||||
$this->server->dhandle("player.shoot", [
|
$this->server->dhandle("player.shoot", [
|
||||||
"player" => $this,
|
"player" => $this,
|
||||||
"power" => &$power,
|
"power" => &$power,
|
||||||
|
|
@ -2312,9 +2270,7 @@ class Player {
|
||||||
if($prevItem->getID() != $packet->item->getID() || $prevItem->getMetadata() != $packet->item->getMetadata()){
|
if($prevItem->getID() != $packet->item->getID() || $prevItem->getMetadata() != $packet->item->getMetadata()){
|
||||||
if(count($this->inventory) >= 36){
|
if(count($this->inventory) >= 36){
|
||||||
foreach($this->inventory as $slot => $item){
|
foreach($this->inventory as $slot => $item){
|
||||||
if($item->getID() == 0) {
|
if($item->getID() == 0) goto inv_desync_on_drop;
|
||||||
goto inv_desync_on_drop;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->toCraft[] = $prevItem; //vanilla drops only result?
|
$this->toCraft[] = $prevItem; //vanilla drops only result?
|
||||||
|
|
@ -2878,7 +2834,7 @@ class Player {
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __toString() {
|
function __toString(){
|
||||||
if($this->username != ""){
|
if($this->username != ""){
|
||||||
return $this->username;
|
return $this->username;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,68 +2,17 @@
|
||||||
|
|
||||||
class PocketMinecraftServer{
|
class PocketMinecraftServer{
|
||||||
|
|
||||||
public $tCnt;
|
public $tCnt, $ticks;
|
||||||
public $ticks;
|
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||||
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;
|
|
||||||
/**
|
/**
|
||||||
* @var ServerAPI
|
* @var ServerAPI
|
||||||
*/
|
*/
|
||||||
public $api;
|
public $api;
|
||||||
private $serverip;
|
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0;
|
||||||
private $evCnt;
|
|
||||||
private $handCnt;
|
|
||||||
private $events;
|
|
||||||
private $eventsID;
|
|
||||||
private $handlers;
|
|
||||||
private $serverType;
|
|
||||||
private $lastTick;
|
|
||||||
private $memoryStats;
|
|
||||||
private $async = [];
|
|
||||||
private $asyncID = 0;
|
|
||||||
|
|
||||||
public $doTick;
|
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;
|
||||||
public $levelData;
|
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
||||||
|
|
||||||
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") {
|
|
||||||
$this->port = (int) $port;
|
$this->port = (int) $port;
|
||||||
$this->doTick = true;
|
$this->doTick = true;
|
||||||
$this->gamemode = (int) $gamemode;
|
$this->gamemode = (int) $gamemode;
|
||||||
|
|
@ -524,7 +473,8 @@ class PocketMinecraftServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process() {
|
public function process()
|
||||||
|
{
|
||||||
$lastLoop = 0;
|
$lastLoop = 0;
|
||||||
if(self::$FORCE_20_TPS){
|
if(self::$FORCE_20_TPS){
|
||||||
while($this->stop === false){
|
while($this->stop === false){
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class RailLogic {
|
class RailLogic
|
||||||
public $x;
|
{
|
||||||
public $y;
|
public $x, $y, $z;
|
||||||
public $z;
|
|
||||||
public $level;
|
public $level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -92,76 +91,38 @@ class RailLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->isStraight){
|
if(!$this->isStraight){
|
||||||
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) {
|
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) $state = 6;
|
||||||
$state = 6;
|
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) $state = 7;
|
||||||
}
|
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) $state = 8;
|
||||||
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) {
|
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) $state = 9;
|
||||||
$state = 7;
|
|
||||||
}
|
|
||||||
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) {
|
|
||||||
$state = 8;
|
|
||||||
}
|
|
||||||
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) {
|
|
||||||
$state = 9;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($state === -1){
|
if($state === -1){
|
||||||
if($hasZneg || $hasZpos) {
|
if($hasZneg || $hasZpos) $state = 0;
|
||||||
$state = 0;
|
if($hasXneg || $hasXpos) $state = 1;
|
||||||
}
|
|
||||||
if($hasXneg || $hasXpos) {
|
|
||||||
$state = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$this->isStraight){
|
if(!$this->isStraight){
|
||||||
if($b){
|
if($b){
|
||||||
if($hasZpos && $hasXpos) {
|
if($hasZpos && $hasXpos) $state = 6;
|
||||||
$state = 6;
|
if($hasXneg && $hasZpos) $state = 7;
|
||||||
}
|
if($hasXpos && $hasZneg) $state = 9;
|
||||||
if($hasXneg && $hasZpos) {
|
if($hasZneg && $hasXneg) $state = 8;
|
||||||
$state = 7;
|
|
||||||
}
|
|
||||||
if($hasXpos && $hasZneg) {
|
|
||||||
$state = 9;
|
|
||||||
}
|
|
||||||
if($hasZneg && $hasXneg) {
|
|
||||||
$state = 8;
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
if($hasZneg && $hasXneg) {
|
if($hasZneg && $hasXneg) $state = 8;
|
||||||
$state = 8;
|
if($hasXpos && $hasZneg) $state = 9;
|
||||||
}
|
if($hasXneg && $hasZpos) $state = 7;
|
||||||
if($hasXpos && $hasZneg) {
|
if($hasZpos && $hasXpos) $state = 6;
|
||||||
$state = 9;
|
|
||||||
}
|
|
||||||
if($hasXneg && $hasZpos) {
|
|
||||||
$state = 7;
|
|
||||||
}
|
|
||||||
if($hasZpos && $hasXpos) {
|
|
||||||
$state = 6;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($state === 0){
|
if($state === 0){
|
||||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) {
|
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4;
|
||||||
$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 = 5;
|
|
||||||
}
|
|
||||||
}elseif($state === 1){
|
}elseif($state === 1){
|
||||||
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) {
|
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) $state = 2;
|
||||||
$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 = 3;
|
|
||||||
}
|
|
||||||
} elseif($state < 0) {
|
|
||||||
$state = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->updateConnections($state);
|
$this->updateConnections($state);
|
||||||
$meta = $state;
|
$meta = $state;
|
||||||
|
|
@ -191,9 +152,7 @@ class RailLogic {
|
||||||
|
|
||||||
public function hasConnection($x, $y, $z){
|
public function hasConnection($x, $y, $z){
|
||||||
foreach($this->railPositions as $rpos){
|
foreach($this->railPositions as $rpos){
|
||||||
if($rpos->x === $x && $rpos->z === $z) {
|
if($rpos->x === $x && $rpos->z === $z) return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -207,45 +166,23 @@ class RailLogic {
|
||||||
$hasXpos = $this->hasConnection($this->x + 1, $this->y, $this->z);
|
$hasXpos = $this->hasConnection($this->x + 1, $this->y, $this->z);
|
||||||
$state = -1;
|
$state = -1;
|
||||||
|
|
||||||
if($hasZneg || $hasZpos) {
|
if($hasZneg || $hasZpos) $state = 0;
|
||||||
$state = 0;
|
if($hasXneg || $hasXpos) $state = 1;
|
||||||
}
|
|
||||||
if($hasXneg || $hasXpos) {
|
|
||||||
$state = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$this->isStraight){
|
if(!$this->isStraight){
|
||||||
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) {
|
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) $state = 6;
|
||||||
$state = 6;
|
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) $state = 7;
|
||||||
}
|
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) $state = 8;
|
||||||
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) {
|
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) $state = 9;
|
||||||
$state = 7;
|
|
||||||
}
|
|
||||||
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) {
|
|
||||||
$state = 8;
|
|
||||||
}
|
|
||||||
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) {
|
|
||||||
$state = 9;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($state == 0){
|
if($state == 0){
|
||||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) {
|
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4;
|
||||||
$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 = 5;
|
|
||||||
}
|
|
||||||
}elseif($state == 1){
|
}elseif($state == 1){
|
||||||
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) {
|
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) $state = 2;
|
||||||
$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 = 3;
|
|
||||||
}
|
|
||||||
} elseif($state < 0) {
|
|
||||||
$state = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$meta = $state;
|
$meta = $state;
|
||||||
|
|
||||||
|
|
@ -307,3 +244,4 @@ class RailLogic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,30 +19,10 @@ class Level {
|
||||||
*/
|
*/
|
||||||
public $players = [];
|
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 $randInt1, $randInt2;
|
||||||
|
|
||||||
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 $queuedBlockUpdates = [];
|
public $queuedBlockUpdates = [];
|
||||||
|
|
||||||
public $forceDisableBlockQueue = false;
|
public $forceDisableBlockQueue = false;
|
||||||
|
|
@ -97,12 +77,8 @@ class Level {
|
||||||
$idmeta = $this->level->getBlock($x, $y, $z);
|
$idmeta = $this->level->getBlock($x, $y, $z);
|
||||||
$id = $idmeta[0];
|
$id = $idmeta[0];
|
||||||
$meta = $idmeta[1];
|
$meta = $idmeta[1];
|
||||||
if($id == 0) {
|
if($id == 0) return false;
|
||||||
return false;
|
if(StaticBlock::getIsTransparent($id)) return false;
|
||||||
}
|
|
||||||
if(StaticBlock::getIsTransparent($id)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -126,9 +102,7 @@ class Level {
|
||||||
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
|
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
|
||||||
if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck
|
if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck
|
||||||
$v14 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end);
|
$v14 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end);
|
||||||
if($v14 != null) {
|
if($v14 != null) return $v14;
|
||||||
return $v14;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for($i = 0; $i <= 200; ++$i){
|
for($i = 0; $i <= 200; ++$i){
|
||||||
|
|
@ -140,44 +114,26 @@ class Level {
|
||||||
$v39 = $v40 = $v41 = true;
|
$v39 = $v40 = $v41 = true;
|
||||||
$v15 = $v17 = $v19 = 999.0; //nice mojang
|
$v15 = $v17 = $v19 = 999.0; //nice mojang
|
||||||
|
|
||||||
if($xEnd > $xStart) {
|
if($xEnd > $xStart) $v15 = $xStart + 1;
|
||||||
$v15 = $xStart + 1;
|
elseif($xEnd < $xStart) $v15 = $xStart;
|
||||||
} elseif($xEnd < $xStart) {
|
else $v39 = false;
|
||||||
$v15 = $xStart;
|
|
||||||
} else {
|
|
||||||
$v39 = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($yEnd > $yStart) {
|
if($yEnd > $yStart) $v17 = $yStart + 1;
|
||||||
$v17 = $yStart + 1;
|
elseif($yEnd < $yStart) $v17 = $yStart;
|
||||||
} elseif($yEnd < $yStart) {
|
else $v40 = false;
|
||||||
$v17 = $yStart;
|
|
||||||
} else {
|
|
||||||
$v40 = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($zEnd > $zStart) {
|
if($zEnd > $zStart) $v19 = $zStart + 1;
|
||||||
$v19 = $zStart + 1;
|
elseif($zEnd < $zStart) $v19 = $zStart;
|
||||||
} elseif($zEnd < $zStart) {
|
else $v41 = false;
|
||||||
$v19 = $zStart;
|
|
||||||
} else {
|
|
||||||
$v41 = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$v21 = $v23 = $v25 = 999.0; //nice mojang x2
|
$v21 = $v23 = $v25 = 999.0; //nice mojang x2
|
||||||
$v27 = $end->x - $start->x;
|
$v27 = $end->x - $start->x;
|
||||||
$v29 = $end->y - $start->y;
|
$v29 = $end->y - $start->y;
|
||||||
$v31 = $end->z - $start->z;
|
$v31 = $end->z - $start->z;
|
||||||
|
|
||||||
if($v39) {
|
if($v39) $v21 = $v27 == 0 ? ($v15 - $start->x) * INF : ($v15 - $start->x) / $v27;
|
||||||
$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($v40) {
|
|
||||||
$v23 = $v29 == 0 ? ($v17 - $start->y) * INF : ($v17 - $start->y) / $v29;
|
|
||||||
}
|
|
||||||
if($v41) {
|
|
||||||
$v25 = $v31 == 0 ? ($v19 - $start->z) * INF : ($v19 - $start->z) / $v31;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($v21 < $v23 && $v21 < $v25){
|
if($v21 < $v23 && $v21 < $v25){
|
||||||
$v42 = $xEnd > $xStart ? 4 : 5;
|
$v42 = $xEnd > $xStart ? 4 : 5;
|
||||||
|
|
@ -200,19 +156,13 @@ class Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
$xStart = floor($start->x);
|
$xStart = floor($start->x);
|
||||||
if($v42 == 5) {
|
if($v42 == 5) --$xStart;
|
||||||
--$xStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
$yStart = floor($start->y);
|
$yStart = floor($start->y);
|
||||||
if($v42 == 1) {
|
if($v42 == 1) --$yStart;
|
||||||
--$yStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
$zStart = floor($start->z);
|
$zStart = floor($start->z);
|
||||||
if($v42 == 3) {
|
if($v42 == 3) --$zStart;
|
||||||
--$zStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
[$blockID, $blockMeta] = $this->level->getBlock($xStart, $yStart, $zStart);
|
[$blockID, $blockMeta] = $this->level->getBlock($xStart, $yStart, $zStart);
|
||||||
$block = StaticBlock::getBlock($blockID);
|
$block = StaticBlock::getBlock($blockID);
|
||||||
|
|
@ -220,9 +170,7 @@ class Level {
|
||||||
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
|
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
|
||||||
if($blockID > 0 && $aabb != null){ //TODO also block::canColideCheck
|
if($blockID > 0 && $aabb != null){ //TODO also block::canColideCheck
|
||||||
$v38 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end);
|
$v38 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end);
|
||||||
if($v38 != null) {
|
if($v38 != null) return $v38;
|
||||||
return $v38;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,9 +190,7 @@ class Level {
|
||||||
for($z = $minZ; $z < $maxZ; ++$z){
|
for($z = $minZ; $z < $maxZ; ++$z){
|
||||||
$blockId = $this->level->getBlockID($x, $y, $z);
|
$blockId = $this->level->getBlockID($x, $y, $z);
|
||||||
|
|
||||||
if($blockId == LAVA || $blockId == STILL_LAVA) {
|
if($blockId == LAVA || $blockId == STILL_LAVA) return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -310,9 +256,7 @@ class Level {
|
||||||
$blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
|
$blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
|
||||||
|
|
||||||
foreach($blockBounds as $blockBound){
|
foreach($blockBounds as $blockBound){
|
||||||
if($aABB->intersectsWith($blockBound)) {
|
if($aABB->intersectsWith($blockBound)) $aABBs[] = $blockBound;
|
||||||
$aABBs[] = $blockBound;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -426,9 +370,7 @@ class Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkSleep(){ //TODO events?
|
public function checkSleep(){ //TODO events?
|
||||||
if(count($this->players) == 0) {
|
if(count($this->players) == 0) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla
|
if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla
|
||||||
foreach($this->players as $p){
|
foreach($this->players as $p){
|
||||||
if(!$p->isSleeping || $p->sleepingTime < 100){
|
if(!$p->isSleeping || $p->sleepingTime < 100){
|
||||||
|
|
@ -534,31 +476,19 @@ class Level {
|
||||||
|
|
||||||
public function updateNeighborsAt($x, $y, $z, $oldID){
|
public function updateNeighborsAt($x, $y, $z, $oldID){
|
||||||
$block = $this->level->getBlockID($x - 1, $y, $z);
|
$block = $this->level->getBlockID($x - 1, $y, $z);
|
||||||
if($block) {
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID);
|
||||||
StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID);
|
|
||||||
}
|
|
||||||
$block = $this->level->getBlockID($x + 1, $y, $z);
|
$block = $this->level->getBlockID($x + 1, $y, $z);
|
||||||
if($block) {
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID);
|
||||||
StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID);
|
|
||||||
}
|
|
||||||
|
|
||||||
$block = $this->level->getBlockID($x, $y - 1, $z);
|
$block = $this->level->getBlockID($x, $y - 1, $z);
|
||||||
if($block) {
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID);
|
||||||
StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID);
|
|
||||||
}
|
|
||||||
$block = $this->level->getBlockID($x, $y + 1, $z);
|
$block = $this->level->getBlockID($x, $y + 1, $z);
|
||||||
if($block) {
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID);
|
||||||
StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID);
|
|
||||||
}
|
|
||||||
|
|
||||||
$block = $this->level->getBlockID($x, $y, $z - 1);
|
$block = $this->level->getBlockID($x, $y, $z - 1);
|
||||||
if($block) {
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID);
|
||||||
StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID);
|
|
||||||
}
|
|
||||||
$block = $this->level->getBlockID($x, $y, $z + 1);
|
$block = $this->level->getBlockID($x, $y, $z + 1);
|
||||||
if($block) {
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID);
|
||||||
StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false){
|
public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false){
|
||||||
|
|
@ -576,15 +506,11 @@ class Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onTick(PocketMinecraftServer $server, $currentTime){
|
public function onTick(PocketMinecraftServer $server, $currentTime){
|
||||||
if(!$this->stopTime) {
|
if(!$this->stopTime) ++$this->time;
|
||||||
++$this->time;
|
|
||||||
}
|
|
||||||
for($cX = 0; $cX < 16; ++$cX){
|
for($cX = 0; $cX < 16; ++$cX){
|
||||||
for($cZ = 0; $cZ < 16; ++$cZ){
|
for($cZ = 0; $cZ < 16; ++$cZ){
|
||||||
$index = $this->level->getIndex($cX, $cZ);
|
$index = $this->level->getIndex($cX, $cZ);
|
||||||
if(!isset($this->level->chunks[$index]) || $this->level->chunks[$index] === false) {
|
if(!isset($this->level->chunks[$index]) || $this->level->chunks[$index] === false) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for($c = 0; $c <= 20; ++$c){
|
for($c = 0; $c <= 20; ++$c){
|
||||||
$xyz = mt_rand(0, 0xffffffff) >> 2;
|
$xyz = mt_rand(0, 0xffffffff) >> 2;
|
||||||
$x = $xyz & 0xf;
|
$x = $xyz & 0xf;
|
||||||
|
|
@ -634,9 +560,7 @@ class Level {
|
||||||
}
|
}
|
||||||
if($e->isPlayer() || $e->needsUpdate){
|
if($e->isPlayer() || $e->needsUpdate){
|
||||||
$e->update($currentTime);
|
$e->update($currentTime);
|
||||||
if(!$e->isPlayer()) {
|
if(!$e->isPlayer()) $post[] = $k;
|
||||||
$post[] = $k;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($e instanceof Entity){
|
if($e instanceof Entity){
|
||||||
|
|
@ -719,9 +643,7 @@ class Level {
|
||||||
for($y = $minY; $y < $maxY; ++$y){
|
for($y = $minY; $y < $maxY; ++$y){
|
||||||
for($z = $minZ; $z < $maxZ; ++$z){
|
for($z = $minZ; $z < $maxZ; ++$z){
|
||||||
$blockAt = $this->level->getBlockID($x, $y, $z);
|
$blockAt = $this->level->getBlockID($x, $y, $z);
|
||||||
if($blockAt == FIRE || $blockAt == STILL_LAVA || $blockAt == LAVA) {
|
if($blockAt == FIRE || $blockAt == STILL_LAVA || $blockAt == LAVA) return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,27 +86,13 @@ class LevelImport {
|
||||||
}
|
}
|
||||||
$chunks->map = null;
|
$chunks->map = null;
|
||||||
$chunks = null;
|
$chunks = null;
|
||||||
if(file_exists($this->path . "level.dat")) {
|
if(file_exists($this->path . "level.dat")) @unlink($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 . "level.dat_old")) {
|
if(file_exists($this->path . "entities.dat")) @unlink($this->path . "entities.dat");
|
||||||
@unlink($this->path . "level.dat_old");
|
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 . "player.dat")) {
|
if(file_exists($this->path . "tiles.dat")) @unlink($this->path . "tiles.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);
|
unset($chunks, $level, $entities, $tiles, $nbt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class MobSpawner{
|
class MobSpawner{
|
||||||
public static $spawnAnimals = false;
|
public static $spawnAnimals = false, $spawnMobs = false, $maxMobsNearPlayerAtOnce = 10;
|
||||||
public static $spawnMobs = false;
|
|
||||||
public static $maxMobsNearPlayerAtOnce = 10;
|
|
||||||
private $server;
|
private $server;
|
||||||
public $level;
|
public $level;
|
||||||
public $totalMobsPerPlayer;
|
public $totalMobsPerPlayer;
|
||||||
|
|
@ -49,9 +47,7 @@ class MobSpawner {
|
||||||
}
|
}
|
||||||
$svd = $this->totalMobsPerPlayer;
|
$svd = $this->totalMobsPerPlayer;
|
||||||
$this->totalMobsPerPlayer = min(ceil(self::$MOB_LIMIT / count($this->level->players)), self::$maxMobsNearPlayerAtOnce);
|
$this->totalMobsPerPlayer = min(ceil(self::$MOB_LIMIT / count($this->level->players)), self::$maxMobsNearPlayerAtOnce);
|
||||||
if($svd != $this->totalMobsPerPlayer) {
|
if($svd != $this->totalMobsPerPlayer) ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}.");
|
||||||
ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->spawnMobs();
|
return $this->spawnMobs();
|
||||||
}
|
}
|
||||||
|
|
@ -97,9 +93,7 @@ class MobSpawner {
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->genPosData($xMob, $y + 0.5, $zMob);
|
$data = $this->genPosData($xMob, $y + 0.5, $zMob);
|
||||||
if($baby != 2) {
|
if($baby != 2) $data["IsBaby"] = $baby;
|
||||||
$data["IsBaby"] = $baby;
|
|
||||||
}
|
|
||||||
|
|
||||||
$e = $this->server->api->entity->add($this->level, 2, $type, $data);
|
$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)];
|
return empty($allowed) ? -1 : $allowed[mt_rand(0, count($allowed) - 1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,10 @@
|
||||||
|
|
||||||
class PocketChunkParser{
|
class PocketChunkParser{
|
||||||
|
|
||||||
public $sectorLength = 4096;
|
var $sectorLength = 4096;
|
||||||
public $chunkLength = 86016; //16 * 16 * 16
|
var $chunkLength = 86016; //16 * 16 * 16
|
||||||
public $map; //21 * $sectorLength
|
var $map; //21 * $sectorLength
|
||||||
private $location;
|
private $location, $raw = b"", $file;
|
||||||
private $raw = b"";
|
|
||||||
private $file;
|
|
||||||
|
|
||||||
public function loadFile($file){
|
public function loadFile($file){
|
||||||
if(file_exists($file . ".gz")){
|
if(file_exists($file . ".gz")){
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,9 @@ class Tile extends Position {
|
||||||
public $closed;
|
public $closed;
|
||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
public $scheduledUpdate;
|
public $scheduledUpdate, $lastUpdate;
|
||||||
|
|
||||||
public $lastUpdate;
|
function __construct(Level $level, $id, $class, $x, $y, $z, $data = []){
|
||||||
|
|
||||||
public function __construct(Level $level, $id, $class, $x, $y, $z, $data = []) {
|
|
||||||
$this->server = ServerAPI::request();
|
$this->server = ServerAPI::request();
|
||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
$this->normal = true;
|
$this->normal = true;
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@ require_once("NoiseGenerator.php");
|
||||||
/***REM_END***/
|
/***REM_END***/
|
||||||
class NoiseGeneratorPerlin extends NoiseGenerator{
|
class NoiseGeneratorPerlin extends NoiseGenerator{
|
||||||
|
|
||||||
public $xCoord;
|
public $xCoord, $yCoord, $zCoord;
|
||||||
public $yCoord;
|
|
||||||
public $zCoord;
|
|
||||||
private $permutations = [];
|
private $permutations = [];
|
||||||
|
|
||||||
public function __construct(MTRandom $random){
|
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);
|
return $par2 + $par1 * ($par3 - $par2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
define("EMPTY_MINI_CHUNK", str_repeat("\x00", 8192));
|
define("EMPTY_MINI_CHUNK", str_repeat("\x00", 8192));
|
||||||
define("EMPTY_16x16_ARR", array_fill(0, 256, 0));
|
define("EMPTY_16x16_ARR", array_fill(0, 256, 0));
|
||||||
class VanillaGenerator implements LevelGenerator {
|
class VanillaGenerator implements LevelGenerator
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var Level
|
* @var Level
|
||||||
*/
|
*/
|
||||||
|
|
@ -22,14 +23,7 @@ class VanillaGenerator implements LevelGenerator {
|
||||||
* @var NoiseGeneratorOctaves $depthNoise
|
* @var NoiseGeneratorOctaves $depthNoise
|
||||||
* @var NoiseGeneratorOctaves $treeNoise
|
* @var NoiseGeneratorOctaves $treeNoise
|
||||||
*/
|
*/
|
||||||
private $upperInterpolationNoise;
|
private $upperInterpolationNoise, $lowerInterpolationNoise, $interpolationNoise, $beachNoise, $surfaceDepthNoise, $biomeNoise, $depthNoise, $treeNoise;
|
||||||
private $lowerInterpolationNoise;
|
|
||||||
private $interpolationNoise;
|
|
||||||
private $beachNoise;
|
|
||||||
private $surfaceDepthNoise;
|
|
||||||
private $biomeNoise;
|
|
||||||
private $depthNoise;
|
|
||||||
private $treeNoise;
|
|
||||||
/**
|
/**
|
||||||
* @var float[] $biomeNoises
|
* @var float[] $biomeNoises
|
||||||
* @var float[] $depthNoises
|
* @var float[] $depthNoises
|
||||||
|
|
@ -42,16 +36,7 @@ class VanillaGenerator implements LevelGenerator {
|
||||||
* @var float[] $gravelNoises
|
* @var float[] $gravelNoises
|
||||||
* @var float[] $surfaceDepthNoises
|
* @var float[] $surfaceDepthNoises
|
||||||
*/
|
*/
|
||||||
private $biomeNoises;
|
private $biomeNoises, $depthNoises, $interpolationNoises, $upperInterpolationNoises, $lowerInterpolationNoises, $biomes, $heights, $sandNoises, $gravelNoises, $surfaceDepthNoises;
|
||||||
private $depthNoises;
|
|
||||||
private $interpolationNoises;
|
|
||||||
private $upperInterpolationNoises;
|
|
||||||
private $lowerInterpolationNoises;
|
|
||||||
private $biomes;
|
|
||||||
private $heights;
|
|
||||||
private $sandNoises;
|
|
||||||
private $gravelNoises;
|
|
||||||
private $surfaceDepthNoises;
|
|
||||||
/**
|
/**
|
||||||
* @var BiomeSource
|
* @var BiomeSource
|
||||||
*/
|
*/
|
||||||
|
|
@ -59,10 +44,12 @@ class VanillaGenerator implements LevelGenerator {
|
||||||
|
|
||||||
private $heightMap = [];
|
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->level = $level;
|
||||||
$this->biomeSource = new BiomeSource($level);
|
$this->biomeSource = new BiomeSource($level);
|
||||||
$this->rand = new MTRandom($level->getSeed());
|
$this->rand = new MTRandom($level->getSeed());
|
||||||
|
|
@ -76,11 +63,13 @@ class VanillaGenerator implements LevelGenerator {
|
||||||
$this->treeNoise = new NoiseGeneratorOctaves($this->rand, 8);
|
$this->treeNoise = new NoiseGeneratorOctaves($this->rand, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSpawn() {
|
public function getSpawn()
|
||||||
|
{
|
||||||
return new Vector3(128, 64, 128);
|
return new Vector3(128, 64, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function populateChunk($chunkX, $chunkZ) {
|
public function populateChunk($chunkX, $chunkZ)
|
||||||
|
{
|
||||||
$chunkXWorld = $chunkX * 16;
|
$chunkXWorld = $chunkX * 16;
|
||||||
$chunkZWorld = $chunkZ * 16;
|
$chunkZWorld = $chunkZ * 16;
|
||||||
//HeavyTile::instaFall = 1; TODO instant sand/gravel fall
|
//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);
|
$sample = (int) (((($this->treeNoise->getValue($chunkXWorld * 0.5, $chunkZWorld * 0.5) / 8) + ($this->rand->nextFloat() * 4)) + 4) / 3);
|
||||||
$treesAmount = $this->rand->nextInt(10) == 0;
|
$treesAmount = $this->rand->nextInt(10) == 0;
|
||||||
if($biome == Biome::$forest) {
|
if($biome == Biome::$forest) $treesAmount += $sample + 2;
|
||||||
$treesAmount += $sample + 2;
|
elseif($biome == Biome::$rainForest) $treesAmount += $sample + 2;
|
||||||
} elseif($biome == Biome::$rainForest) {
|
elseif($biome == Biome::$seasonalForest) $treesAmount += $sample + 1;
|
||||||
$treesAmount += $sample + 2;
|
elseif($biome == Biome::$taiga) $treesAmount += $sample + 1;
|
||||||
} elseif($biome == Biome::$seasonalForest) {
|
elseif($biome == Biome::$desert) $treesAmount -= 20;
|
||||||
$treesAmount += $sample + 1;
|
elseif($biome == Biome::$tundra) $treesAmount -= 20;
|
||||||
} elseif($biome == Biome::$taiga) {
|
elseif($biome == Biome::$plains) $treesAmount -= 20;
|
||||||
$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){
|
for($l8 = 0; $l8 < $treesAmount; ++$l8){
|
||||||
$l12 = $chunkXWorld + $this->rand->nextInt(16) + 8;
|
$l12 = $chunkXWorld + $this->rand->nextInt(16) + 8;
|
||||||
$j15 = $chunkZWorld + $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->rand->setSeed(341872712 * $chunkX + 132899541 * $chunkZ);
|
||||||
$this->biomes = $this->biomeSource->getBiomeBlock($chunkX * 16, $chunkZ * 16, 16, 16);
|
$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
|
$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){
|
public function setHeightValue($x, $z, $hv){
|
||||||
if($x > 255 || $x < 0 || $z > 255 || $z < 0) {
|
if($x > 255 || $x < 0 || $z > 255 || $z < 0) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
$cX = $x >> 4;
|
$cX = $x >> 4;
|
||||||
$cZ = $z >> 4;
|
$cZ = $z >> 4;
|
||||||
$bX = $x & 0xf;
|
$bX = $x & 0xf;
|
||||||
|
|
@ -197,9 +177,7 @@ class VanillaGenerator implements LevelGenerator {
|
||||||
$this->heightMap[$cX + ($cZ * 16)][$bX + ($bZ * 16)] = $hv;
|
$this->heightMap[$cX + ($cZ * 16)][$bX + ($bZ * 16)] = $hv;
|
||||||
}
|
}
|
||||||
public function getHeightValue($x, $z){
|
public function getHeightValue($x, $z){
|
||||||
if($x > 255 || $x < 0 || $z > 255 || $z < 0) {
|
if($x > 255 || $x < 0 || $z > 255 || $z < 0) return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
$cX = $x >> 4;
|
$cX = $x >> 4;
|
||||||
$cZ = $z >> 4;
|
$cZ = $z >> 4;
|
||||||
$bX = $x & 0xf;
|
$bX = $x & 0xf;
|
||||||
|
|
@ -366,33 +344,23 @@ class VanillaGenerator implements LevelGenerator {
|
||||||
|
|
||||||
$d5 = (($this->biomeNoises[$l1] + 256) / 512);
|
$d5 = (($this->biomeNoises[$l1] + 256) / 512);
|
||||||
$d5 *= $d4;
|
$d5 *= $d4;
|
||||||
if($d5 > 1) {
|
if($d5 > 1) $d5 = 1;
|
||||||
$d5 = 1;
|
|
||||||
}
|
|
||||||
$d6 = $this->depthNoises[$l1] / 8000;
|
$d6 = $this->depthNoises[$l1] / 8000;
|
||||||
if($d6 < 0) {
|
if($d6 < 0) $d6 = -$d6 * 0.3;
|
||||||
$d6 = -$d6 * 0.3;
|
|
||||||
}
|
|
||||||
|
|
||||||
$d6 = $d6 * 3 - 2;
|
$d6 = $d6 * 3 - 2;
|
||||||
if($d6 < 0){
|
if($d6 < 0){
|
||||||
$d6 /= 2;
|
$d6 /= 2;
|
||||||
if($d6 < -1) {
|
if($d6 < -1) $d6 = -1;
|
||||||
$d6 = -1;
|
|
||||||
}
|
|
||||||
$d6 /= 1.4;
|
$d6 /= 1.4;
|
||||||
$d6 /= 2;
|
$d6 /= 2;
|
||||||
$d5 = 0;
|
$d5 = 0;
|
||||||
}else{
|
}else{
|
||||||
if($d6 > 1) {
|
if($d6 > 1) $d6 = 1;
|
||||||
$d6 = 1;
|
|
||||||
}
|
|
||||||
$d6 /= 8;
|
$d6 /= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($d5 < 0) {
|
if($d5 < 0) $d5 = 0;
|
||||||
$d5 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$d5 += 0.5;
|
$d5 += 0.5;
|
||||||
$d6 = ($d6 * $scaleY) / 16;
|
$d6 = ($d6 * $scaleY) / 16;
|
||||||
|
|
@ -401,20 +369,14 @@ class VanillaGenerator implements LevelGenerator {
|
||||||
for($j3 = 0; $j3 < $scaleY; ++$j3){
|
for($j3 = 0; $j3 < $scaleY; ++$j3){
|
||||||
$d8 = 0;
|
$d8 = 0;
|
||||||
$d9 = (((float) $j3 - $d7) * 12) / $d5;
|
$d9 = (((float) $j3 - $d7) * 12) / $d5;
|
||||||
if($d9 < 0) {
|
if($d9 < 0) $d9 *= 4;
|
||||||
$d9 *= 4;
|
|
||||||
}
|
|
||||||
$d10 = $this->upperInterpolationNoises[$k1] / 512;
|
$d10 = $this->upperInterpolationNoises[$k1] / 512;
|
||||||
$d11 = $this->lowerInterpolationNoises[$k1] / 512;
|
$d11 = $this->lowerInterpolationNoises[$k1] / 512;
|
||||||
$d12 = ($this->interpolationNoises[$k1] / 10 + 1) / 2;
|
$d12 = ($this->interpolationNoises[$k1] / 10 + 1) / 2;
|
||||||
|
|
||||||
if($d12 < 0) {
|
if($d12 < 0) $d8 = $d10;
|
||||||
$d8 = $d10;
|
elseif($d12 > 1) $d8 = $d11;
|
||||||
} elseif($d12 > 1) {
|
else $d8 = $d10 + ($d11 - $d10) * $d12;
|
||||||
$d8 = $d11;
|
|
||||||
} else {
|
|
||||||
$d8 = $d10 + ($d11 - $d10) * $d12;
|
|
||||||
}
|
|
||||||
|
|
||||||
$d8 -= $d9;
|
$d8 -= $d9;
|
||||||
if($j3 > $scaleY - 4){
|
if($j3 > $scaleY - 4){
|
||||||
|
|
@ -431,3 +393,4 @@ class VanillaGenerator implements LevelGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class TreeFeature extends Feature {
|
class TreeFeature extends Feature
|
||||||
|
{
|
||||||
public function place(Level $level, MTRandom $rand, $x, $y, $z){
|
public function place(Level $level, MTRandom $rand, $x, $y, $z){
|
||||||
$nextInt = $rand->nextInt(3) + 4;
|
$nextInt = $rand->nextInt(3) + 4;
|
||||||
$z2 = true;
|
$z2 = true;
|
||||||
if($y < 1 || $y + $nextInt + 1 > 128) {
|
if($y < 1 || $y + $nextInt + 1 > 128) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for($i = $y; $i <= $y + 1 + $nextInt; ++$i){
|
for($i = $y; $i <= $y + 1 + $nextInt; ++$i){
|
||||||
$i2 = ($i == $y) ? 0 : 1;
|
$i2 = ($i == $y) ? 0 : 1;
|
||||||
if($i >= (($y + 1) + $nextInt) - 2) {
|
if($i >= (($y + 1) + $nextInt) - 2) $i2 = 2;
|
||||||
$i2 = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
for($i3 = $x - $i2; $i3 <= $x + $i2 && $z2; ++$i3){
|
for($i3 = $x - $i2; $i3 <= $x + $i2 && $z2; ++$i3){
|
||||||
for($i4 = $z - $i2; $i4 <= $z + $i2 && $z2; ++$i4){
|
for($i4 = $z - $i2; $i4 <= $z + $i2 && $z2; ++$i4){
|
||||||
|
|
@ -53,3 +50,4 @@ class TreeFeature extends Feature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue