mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
support php8019 and some cleanup (by @D-aHTuCT)
This commit is contained in:
parent
cf0f9df267
commit
b60f0877e1
376 changed files with 6528 additions and 13472 deletions
|
|
@ -1,41 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class Explosion{
|
||||
public static $specialDrops = array(
|
||||
|
||||
public static $specialDrops = [
|
||||
GRASS => DIRT,
|
||||
STONE => COBBLESTONE,
|
||||
COAL_ORE => COAL,
|
||||
DIAMOND_ORE => DIAMOND,
|
||||
REDSTONE_ORE => REDSTONE,
|
||||
);
|
||||
];
|
||||
public static $enableExplosions = true;
|
||||
private $rays = 16; //Rays
|
||||
public $level;
|
||||
public $level; //Rays
|
||||
public $source;
|
||||
public $size;
|
||||
public $affectedBlocks = array();
|
||||
public $affectedBlocks = [];
|
||||
public $stepLen = 0.3;
|
||||
private $rays = 16;
|
||||
private $air;
|
||||
private $nullPlayer;
|
||||
|
||||
public function __construct(Position $center, $size){
|
||||
$this->level = $center->level;
|
||||
$this->source = $center;
|
||||
|
|
@ -43,17 +26,18 @@ class Explosion{
|
|||
$this->air = BlockAPI::getItem(AIR, 0, 1);
|
||||
$this->nullPlayer = new PlayerNull();
|
||||
}
|
||||
|
||||
|
||||
public function explode(){
|
||||
if(!Explosion::$enableExplosions){ /*Disable Explosions*/
|
||||
return;
|
||||
}
|
||||
|
||||
$server = ServerAPI::request();
|
||||
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array(
|
||||
"level" => $this->level,
|
||||
"source" => $this->source,
|
||||
"size" => $this->size
|
||||
)) === false){
|
||||
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", [
|
||||
"level" => $this->level,
|
||||
"source" => $this->source,
|
||||
"size" => $this->size
|
||||
]) === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -65,11 +49,11 @@ class Explosion{
|
|||
$vector = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); //($i / $mRays) * 2 - 1
|
||||
$vector = $vector->normalize()->multiply($this->stepLen);
|
||||
$pointer = clone $this->source;
|
||||
|
||||
|
||||
for($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
|
||||
$vBlock = $pointer->floor();
|
||||
$blockID = $this->level->level->getBlockID($vBlock->x, $vBlock->y, $vBlock->z);
|
||||
|
||||
|
||||
if($blockID > 0){
|
||||
$block = BlockAPI::get($blockID, 0);
|
||||
$block->x = $vBlock->x;
|
||||
|
|
@ -77,7 +61,7 @@ class Explosion{
|
|||
$block->z = $vBlock->z;
|
||||
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
|
||||
if($blastForce > 0){
|
||||
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
||||
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
||||
if(!isset($this->affectedBlocks[$index])){
|
||||
$this->affectedBlocks[$index] = $block;
|
||||
}
|
||||
|
|
@ -89,8 +73,8 @@ class Explosion{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$send = array();
|
||||
|
||||
$send = [];
|
||||
$source = $this->source->floor();
|
||||
$radius = 2 * $this->size;
|
||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||
|
|
@ -102,18 +86,18 @@ class Explosion{
|
|||
foreach($this->affectedBlocks as $block){
|
||||
|
||||
if($block instanceof TNTBlock){
|
||||
$data = array(
|
||||
$data = [
|
||||
"x" => $block->x + 0.5,
|
||||
"y" => $block->y + 0.5,
|
||||
"z" => $block->z + 0.5,
|
||||
"power" => 4,
|
||||
"fuse" => mt_rand(10, 30), //0.5 to 1.5 seconds
|
||||
);
|
||||
];
|
||||
$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
|
||||
}elseif(mt_rand(0, 10000) < ((1 / $this->size) * 10000)){
|
||||
foreach($block->getDrops($this->air, $this->nullPlayer) as $drop){
|
||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1],$drop[2])); //id, meta, count
|
||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1], $drop[2])); //id, meta, count
|
||||
}
|
||||
}
|
||||
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
|
||||
|
|
@ -127,6 +111,5 @@ class Explosion{
|
|||
$pk->radius = $this->size;
|
||||
$pk->records = $send;
|
||||
$server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class Level{
|
||||
public $entities, $tiles, $blockUpdates, $nextSave, $players = array(), $level;
|
||||
|
||||
public $entities, $tiles, $blockUpdates, $nextSave, $players = [], $level;
|
||||
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
|
||||
|
||||
|
||||
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->level = $level;
|
||||
|
|
@ -34,28 +16,168 @@ class Level{
|
|||
$this->nextSave = $this->startCheck = microtime(true);
|
||||
$this->nextSave += 90;
|
||||
$this->stopTime = false;
|
||||
$this->server->schedule(15, array($this, "checkThings"), array(), true);
|
||||
$this->server->schedule(20 * 13, array($this, "checkTime"), array(), true);
|
||||
$this->server->schedule(15, [$this, "checkThings"], [], true);
|
||||
$this->server->schedule(20 * 13, [$this, "checkTime"], [], true);
|
||||
$this->name = $name;
|
||||
$this->usedChunks = array();
|
||||
$this->changedBlocks = array();
|
||||
$this->changedCount = array();
|
||||
$this->usedChunks = [];
|
||||
$this->changedBlocks = [];
|
||||
$this->changedCount = [];
|
||||
}
|
||||
|
||||
|
||||
public function close(){
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
public function useChunk($X, $Z, Player $player){
|
||||
if(!isset($this->usedChunks[$X.".".$Z])){
|
||||
$this->usedChunks[$X.".".$Z] = array();
|
||||
|
||||
public function __destruct(){
|
||||
if(isset($this->level)){
|
||||
$this->save(false, false);
|
||||
$this->level->close();
|
||||
unset($this->level);
|
||||
}
|
||||
$this->usedChunks[$X.".".$Z][$player->CID] = true;
|
||||
}
|
||||
|
||||
public function save($force = false, $extra = true){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
if($this->server->saveEnabled === false and $force === false){
|
||||
return;
|
||||
}
|
||||
|
||||
if($extra !== false){
|
||||
$entities = [];
|
||||
foreach($this->server->api->entity->getAll($this) as $entity){
|
||||
if($entity->class === ENTITY_MOB){
|
||||
$entities[] = [
|
||||
"id" => $entity->type,
|
||||
"Color" => @$entity->data["Color"],
|
||||
"Sheared" => @$entity->data["Sheared"],
|
||||
"IsBaby" => @$entity->data["IsBaby"],
|
||||
"Health" => $entity->health,
|
||||
"Pos" => [
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
],
|
||||
"Rotation" => [
|
||||
0 => $entity->yaw,
|
||||
1 => $entity->pitch,
|
||||
],
|
||||
];
|
||||
}elseif($entity->class === ENTITY_OBJECT){
|
||||
if($entity->type === OBJECT_PAINTING){
|
||||
$entities[] = [
|
||||
"id" => $entity->type,
|
||||
"TileX" => $entity->x,
|
||||
"TileY" => $entity->y,
|
||||
"TileZ" => $entity->z,
|
||||
"Health" => $entity->health,
|
||||
"Motive" => $entity->data["Motive"],
|
||||
"Pos" => [
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
],
|
||||
"Rotation" => [
|
||||
0 => $entity->yaw,
|
||||
1 => $entity->pitch,
|
||||
],
|
||||
];
|
||||
}else{
|
||||
$entities[] = [
|
||||
"id" => $entity->type,
|
||||
"Health" => $entity->health,
|
||||
"Pos" => [
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
],
|
||||
"Rotation" => [
|
||||
0 => $entity->yaw,
|
||||
1 => $entity->pitch,
|
||||
],
|
||||
];
|
||||
}
|
||||
}elseif($entity->class === ENTITY_FALLING){
|
||||
$entities[] = [
|
||||
"id" => $entity->type,
|
||||
"Health" => $entity->health,
|
||||
"Tile" => $entity->data["Tile"],
|
||||
"Pos" => [
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
],
|
||||
"Rotation" => [
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
],
|
||||
];
|
||||
}elseif($entity->class === ENTITY_ITEM){
|
||||
$entities[] = [
|
||||
"id" => 64,
|
||||
"Item" => [
|
||||
"id" => $entity->type,
|
||||
"Damage" => $entity->meta,
|
||||
"Count" => $entity->stack,
|
||||
],
|
||||
"Health" => $entity->health,
|
||||
"Pos" => [
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
],
|
||||
"Rotation" => [
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
$this->entities->setAll($entities);
|
||||
$this->entities->save();
|
||||
$tiles = [];
|
||||
foreach($this->server->api->tile->getAll($this) as $tile){
|
||||
$tiles[] = $tile->data;
|
||||
}
|
||||
$this->tiles->setAll($tiles);
|
||||
$this->tiles->save();
|
||||
|
||||
$blockUpdates = [];
|
||||
$updates = $this->server->query("SELECT x,y,z,type,delay FROM blockUpdates WHERE level = '" . $this->getName() . "';");
|
||||
if($updates !== false and $updates !== true){
|
||||
$timeu = microtime(true);
|
||||
while(($bupdate = $updates->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$bupdate["delay"] = max(1, ($bupdate["delay"] - $timeu) * 20);
|
||||
$blockUpdates[] = $bupdate;
|
||||
}
|
||||
}
|
||||
|
||||
$this->blockUpdates->setAll($blockUpdates);
|
||||
$this->blockUpdates->save();
|
||||
|
||||
}
|
||||
|
||||
$this->level->setData("time", (int) $this->time);
|
||||
$this->level->doSaveRound();
|
||||
$this->level->saveData();
|
||||
$this->nextSave = microtime(true) + 45;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;//return $this->level->getData("name");
|
||||
}
|
||||
|
||||
public function useChunk($X, $Z, Player $player){
|
||||
if(!isset($this->usedChunks[$X . "." . $Z])){
|
||||
$this->usedChunks[$X . "." . $Z] = [];
|
||||
}
|
||||
$this->usedChunks[$X . "." . $Z][$player->CID] = true;
|
||||
if(isset($this->level)){
|
||||
$this->level->loadChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function freeAllChunks(Player $player){
|
||||
foreach($this->usedChunks as $i => $c){
|
||||
unset($this->usedChunks[$i][$player->CID]);
|
||||
|
|
@ -63,39 +185,19 @@ class Level{
|
|||
}
|
||||
|
||||
public function freeChunk($X, $Z, Player $player){
|
||||
unset($this->usedChunks[$X.".".$Z][$player->CID]);
|
||||
unset($this->usedChunks[$X . "." . $Z][$player->CID]);
|
||||
}
|
||||
|
||||
public function checkTime(){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
$now = microtime(true);
|
||||
if($this->stopTime == true){
|
||||
|
||||
}else{
|
||||
$time = $this->startTime + ($now - $this->startCheck) * 20;
|
||||
}
|
||||
if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){
|
||||
$this->time = $time;
|
||||
|
||||
$pk = new SetTimePacket;
|
||||
$pk->time = (int) $this->time;
|
||||
$pk->started = $this->stopTime == false;
|
||||
$this->server->api->player->broadcastPacket($this->players, $pk);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkThings(){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
$now = microtime(true);
|
||||
$this->players = $this->server->api->player->getAll($this);
|
||||
|
||||
|
||||
if(count($this->changedCount) > 0){
|
||||
arsort($this->changedCount);
|
||||
$resendChunks = array();
|
||||
$resendChunks = [];
|
||||
foreach($this->changedCount as $index => $count){
|
||||
if($count < 582){//Optimal value, calculated using the relation between minichunks and single packets
|
||||
break;
|
||||
|
|
@ -105,7 +207,7 @@ class Level{
|
|||
}
|
||||
unset($this->changedBlocks[$index]);
|
||||
}
|
||||
$this->changedCount = array();
|
||||
$this->changedCount = [];
|
||||
|
||||
if(count($this->changedBlocks) > 0){
|
||||
foreach($this->changedBlocks as $blocks){
|
||||
|
|
@ -119,10 +221,10 @@ class Level{
|
|||
$this->server->api->player->broadcastPacket($this->players, $pk);
|
||||
}
|
||||
}
|
||||
$this->changedBlocks = array();
|
||||
$this->changedBlocks = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($this->nextSave < $now){
|
||||
foreach($this->usedChunks as $i => $c){
|
||||
if(count($c) === 0){
|
||||
|
|
@ -138,156 +240,18 @@ class Level{
|
|||
$this->save(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
if(isset($this->level)){
|
||||
$this->save(false, false);
|
||||
$this->level->close();
|
||||
unset($this->level);
|
||||
}
|
||||
}
|
||||
|
||||
public function save($force = false, $extra = true){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
if($this->server->saveEnabled === false and $force === false){
|
||||
return;
|
||||
}
|
||||
|
||||
if($extra !== false){
|
||||
$entities = array();
|
||||
foreach($this->server->api->entity->getAll($this) as $entity){
|
||||
if($entity->class === ENTITY_MOB){
|
||||
$entities[] = array(
|
||||
"id" => $entity->type,
|
||||
"Color" => @$entity->data["Color"],
|
||||
"Sheared" => @$entity->data["Sheared"],
|
||||
"IsBaby" => @$entity->data["IsBaby"],
|
||||
"Health" => $entity->health,
|
||||
"Pos" => array(
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
),
|
||||
"Rotation" => array(
|
||||
0 => $entity->yaw,
|
||||
1 => $entity->pitch,
|
||||
),
|
||||
);
|
||||
}elseif($entity->class === ENTITY_OBJECT){
|
||||
if($entity->type === OBJECT_PAINTING){
|
||||
$entities[] = array(
|
||||
"id" => $entity->type,
|
||||
"TileX" => $entity->x,
|
||||
"TileY" => $entity->y,
|
||||
"TileZ" => $entity->z,
|
||||
"Health" => $entity->health,
|
||||
"Motive" => $entity->data["Motive"],
|
||||
"Pos" => array(
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
),
|
||||
"Rotation" => array(
|
||||
0 => $entity->yaw,
|
||||
1 => $entity->pitch,
|
||||
),
|
||||
);
|
||||
}else{
|
||||
$entities[] = array(
|
||||
"id" => $entity->type,
|
||||
"Health" => $entity->health,
|
||||
"Pos" => array(
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
),
|
||||
"Rotation" => array(
|
||||
0 => $entity->yaw,
|
||||
1 => $entity->pitch,
|
||||
),
|
||||
);
|
||||
}
|
||||
}elseif($entity->class === ENTITY_FALLING){
|
||||
$entities[] = array(
|
||||
"id" => $entity->type,
|
||||
"Health" => $entity->health,
|
||||
"Tile" => $entity->data["Tile"],
|
||||
"Pos" => array(
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
),
|
||||
"Rotation" => array(
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
),
|
||||
);
|
||||
}elseif($entity->class === ENTITY_ITEM){
|
||||
$entities[] = array(
|
||||
"id" => 64,
|
||||
"Item" => array(
|
||||
"id" => $entity->type,
|
||||
"Damage" => $entity->meta,
|
||||
"Count" => $entity->stack,
|
||||
),
|
||||
"Health" => $entity->health,
|
||||
"Pos" => array(
|
||||
0 => $entity->x,
|
||||
1 => $entity->y,
|
||||
2 => $entity->z,
|
||||
),
|
||||
"Rotation" => array(
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->entities->setAll($entities);
|
||||
$this->entities->save();
|
||||
$tiles = array();
|
||||
foreach($this->server->api->tile->getAll($this) as $tile){
|
||||
$tiles[] = $tile->data;
|
||||
}
|
||||
$this->tiles->setAll($tiles);
|
||||
$this->tiles->save();
|
||||
|
||||
$blockUpdates = array();
|
||||
$updates = $this->server->query("SELECT x,y,z,type,delay FROM blockUpdates WHERE level = '".$this->getName()."';");
|
||||
if($updates !== false and $updates !== true){
|
||||
$timeu = microtime(true);
|
||||
while(($bupdate = $updates->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$bupdate["delay"] = max(1, ($bupdate["delay"] - $timeu) * 20);
|
||||
$blockUpdates[] = $bupdate;
|
||||
}
|
||||
}
|
||||
|
||||
$this->blockUpdates->setAll($blockUpdates);
|
||||
$this->blockUpdates->save();
|
||||
|
||||
}
|
||||
|
||||
$this->level->setData("time", (int) $this->time);
|
||||
$this->level->doSaveRound();
|
||||
$this->level->saveData();
|
||||
$this->nextSave = microtime(true) + 45;
|
||||
public function isSpawnChunk($X, $Z){
|
||||
$spawnX = $this->level->getData("spawnX") >> 4;
|
||||
$spawnZ = $this->level->getData("spawnZ") >> 4;
|
||||
return abs($X - $spawnX) <= 1 and abs($Z - $spawnZ) <= 1;
|
||||
}
|
||||
|
||||
|
||||
public function getBlockRaw(Vector3 $pos){
|
||||
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z);
|
||||
return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
|
||||
}
|
||||
|
||||
public function getBlock(Vector3 $pos){
|
||||
if(!isset($this->level) or ($pos instanceof Position) and $pos->level !== $this){
|
||||
return false;
|
||||
}
|
||||
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z);
|
||||
return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
|
||||
}
|
||||
|
||||
|
||||
public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){
|
||||
if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false){
|
||||
if($direct === true){
|
||||
|
|
@ -303,12 +267,12 @@ class Level{
|
|||
$pos = new Position($pos->x, $pos->y, $pos->z, $this);
|
||||
}
|
||||
$block->position($pos);
|
||||
$i = ($pos->x >> 4).":".($pos->y >> 4).":".($pos->z >> 4);
|
||||
$i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4);
|
||||
if(ADVANCED_CACHE == true){
|
||||
Cache::remove("world:{$this->name}:".($pos->x >> 4).":".($pos->z >> 4));
|
||||
Cache::remove("world:{$this->name}:" . ($pos->x >> 4) . ":" . ($pos->z >> 4));
|
||||
}
|
||||
if(!isset($this->changedBlocks[$i])){
|
||||
$this->changedBlocks[$i] = array();
|
||||
$this->changedBlocks[$i] = [];
|
||||
$this->changedCount[$i] = 0;
|
||||
}
|
||||
$this->changedBlocks[$i][] = clone $block;
|
||||
|
|
@ -317,7 +281,7 @@ class Level{
|
|||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false){
|
||||
if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
|
||||
return false;
|
||||
|
|
@ -339,19 +303,19 @@ class Level{
|
|||
$pk->meta = $block->getMetadata();
|
||||
$this->server->api->player->broadcastPacket($this->players, $pk);
|
||||
}else{
|
||||
$i = ($pos->x >> 4).":".($pos->y >> 4).":".($pos->z >> 4);
|
||||
$i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4);
|
||||
if(!isset($this->changedBlocks[$i])){
|
||||
$this->changedBlocks[$i] = array();
|
||||
$this->changedBlocks[$i] = [];
|
||||
$this->changedCount[$i] = 0;
|
||||
}
|
||||
if(ADVANCED_CACHE == true){
|
||||
Cache::remove("world:{$this->name}:".($pos->x >> 4).":".($pos->z >> 4));
|
||||
Cache::remove("world:{$this->name}:" . ($pos->x >> 4) . ":" . ($pos->z >> 4));
|
||||
}
|
||||
$this->changedBlocks[$i][] = clone $block;
|
||||
++$this->changedCount[$i];
|
||||
}
|
||||
|
||||
if($update === true){
|
||||
if($update === true){
|
||||
$this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1);
|
||||
$this->server->api->entity->updateRadius($pos, 3);
|
||||
}
|
||||
|
|
@ -363,32 +327,32 @@ class Level{
|
|||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public function getMiniChunk($X, $Z, $Y){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
return $this->level->getMiniChunk($X, $Z, $Y);
|
||||
}
|
||||
|
||||
|
||||
public function setMiniChunk($X, $Z, $Y, $data){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
$this->changedCount[$X.":".$Y.":".$Z] = 4096;
|
||||
$this->changedCount[$X . ":" . $Y . ":" . $Z] = 4096;
|
||||
if(ADVANCED_CACHE == true){
|
||||
Cache::remove("world:{$this->name}:$X:$Z");
|
||||
}
|
||||
return $this->level->setMiniChunk($X, $Z, $Y, $data);
|
||||
}
|
||||
|
||||
|
||||
public function loadChunk($X, $Z){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
return $this->level->loadChunk($X, $Z);
|
||||
}
|
||||
|
||||
|
||||
public function unloadChunk($X, $Z, $force = false){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
|
|
@ -401,12 +365,6 @@ class Level{
|
|||
return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
|
||||
}
|
||||
|
||||
public function isSpawnChunk($X, $Z){
|
||||
$spawnX = $this->level->getData("spawnX") >> 4;
|
||||
$spawnZ = $this->level->getData("spawnZ") >> 4;
|
||||
return abs($X - $spawnX) <= 1 and abs($Z - $spawnZ) <= 1;
|
||||
}
|
||||
|
||||
public function getOrderedChunk($X, $Z, $Yndex){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
|
|
@ -417,15 +375,15 @@ class Level{
|
|||
return $cache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$raw = array();
|
||||
|
||||
|
||||
$raw = [];
|
||||
for($Y = 0; $Y < 8; ++$Y){
|
||||
if(($Yndex & (1 << $Y)) > 0){
|
||||
$raw[$Y] = $this->level->getMiniChunk($X, $Z, $Y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$ordered = "";
|
||||
$flag = chr($Yndex);
|
||||
for($j = 0; $j < 256; ++$j){
|
||||
|
|
@ -436,7 +394,7 @@ class Level{
|
|||
}
|
||||
if(ADVANCED_CACHE == true and $Yndex == 0xff){
|
||||
Cache::add($identifier, $ordered, 60);
|
||||
}
|
||||
}
|
||||
return $ordered;
|
||||
}
|
||||
|
||||
|
|
@ -452,14 +410,7 @@ class Level{
|
|||
}
|
||||
return $ordered;
|
||||
}
|
||||
|
||||
public function getSpawn(){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this);
|
||||
}
|
||||
|
||||
|
||||
public function getSafeSpawn($spawn = false){
|
||||
if($spawn === false){
|
||||
$spawn = $this->getSpawn();
|
||||
|
|
@ -491,7 +442,22 @@ class Level{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function getSpawn(){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this);
|
||||
}
|
||||
|
||||
public function getBlock(Vector3 $pos){
|
||||
if(!isset($this->level) or ($pos instanceof Position) and $pos->level !== $this){
|
||||
return false;
|
||||
}
|
||||
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z);
|
||||
return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
|
||||
}
|
||||
|
||||
public function setSpawn(Vector3 $pos){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
|
|
@ -500,47 +466,63 @@ class Level{
|
|||
$this->level->setData("spawnY", $pos->y);
|
||||
$this->level->setData("spawnZ", $pos->z);
|
||||
}
|
||||
|
||||
|
||||
public function getTime(){
|
||||
return (int) ($this->time);
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;//return $this->level->getData("name");
|
||||
}
|
||||
|
||||
|
||||
public function setTime($time){
|
||||
$this->startTime = $this->time = (int) $time;
|
||||
$this->startCheck = microtime(true);
|
||||
$this->checkTime();
|
||||
}
|
||||
|
||||
|
||||
public function checkTime(){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
$now = microtime(true);
|
||||
if($this->stopTime == true){
|
||||
|
||||
}else{
|
||||
$time = $this->startTime + ($now - $this->startCheck) * 20;
|
||||
}
|
||||
if($this->server->api->dhandle("time.change", ["level" => $this, "time" => $time]) !== false){
|
||||
$this->time = $time;
|
||||
|
||||
$pk = new SetTimePacket;
|
||||
$pk->time = (int) $this->time;
|
||||
$pk->started = $this->stopTime == false;
|
||||
$this->server->api->player->broadcastPacket($this->players, $pk);
|
||||
}
|
||||
}
|
||||
|
||||
public function stopTime(){
|
||||
$this->stopTime = true;
|
||||
$this->startCheck = 0;
|
||||
$this->checkTime();
|
||||
}
|
||||
|
||||
|
||||
public function startTime(){
|
||||
$this->stopTime = false;
|
||||
$this->startCheck = microtime(true);
|
||||
$this->checkTime();
|
||||
}
|
||||
|
||||
|
||||
public function getSeed(){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
return (int) $this->level->getData("seed");
|
||||
}
|
||||
|
||||
|
||||
public function setSeed($seed){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
$this->level->setData("seed", (int) $seed);
|
||||
}
|
||||
|
||||
|
||||
public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,63 +1,46 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class LevelImport{
|
||||
|
||||
private $path;
|
||||
|
||||
public function __construct($path){
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
|
||||
public function import(){
|
||||
if(file_exists($this->path."tileEntities.dat")){ //OldPM
|
||||
$level = unserialize(file_get_contents($this->path."level.dat"));
|
||||
console("[INFO] Importing OldPM level \"".$level["LevelName"]."\" to PMF format");
|
||||
$entities = new Config($this->path."entities.yml", CONFIG_YAML, unserialize(file_get_contents($this->path."entities.dat")));
|
||||
if(file_exists($this->path . "tileEntities.dat")){ //OldPM
|
||||
$level = unserialize(file_get_contents($this->path . "level.dat"));
|
||||
console("[INFO] Importing OldPM level \"" . $level["LevelName"] . "\" to PMF format");
|
||||
$entities = new Config($this->path . "entities.yml", CONFIG_YAML, unserialize(file_get_contents($this->path . "entities.dat")));
|
||||
$entities->save();
|
||||
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path."tileEntities.dat")));
|
||||
$tiles = new Config($this->path . "tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path . "tileEntities.dat")));
|
||||
$tiles->save();
|
||||
}elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket
|
||||
}elseif(file_exists($this->path . "chunks.dat") and file_exists($this->path . "level.dat")){ //Pocket
|
||||
$nbt = new NBT();
|
||||
$nbt->load(substr(file_get_contents($this->path."level.dat"), 8));
|
||||
$nbt->load(substr(file_get_contents($this->path . "level.dat"), 8));
|
||||
$level = array_shift($nbt->tree);
|
||||
if($level["LevelName"] == ""){
|
||||
$level["LevelName"] = "world".time();
|
||||
$level["LevelName"] = "world" . time();
|
||||
}
|
||||
console("[INFO] Importing Pocket level \"".$level["LevelName"]."\" to PMF format");
|
||||
console("[INFO] Importing Pocket level \"" . $level["LevelName"] . "\" to PMF format");
|
||||
unset($level["Player"]);
|
||||
$nbt->load(substr(file_get_contents($this->path."entities.dat"), 12));
|
||||
$nbt->load(substr(file_get_contents($this->path . "entities.dat"), 12));
|
||||
$entities = array_shift($nbt->tree);
|
||||
if(!isset($entities["TileEntities"])){
|
||||
$entities["TileEntities"] = array();
|
||||
$entities["TileEntities"] = [];
|
||||
}
|
||||
$tiles = $entities["TileEntities"];
|
||||
$entities = $entities["Entities"];
|
||||
$entities = new Config($this->path."entities.yml", CONFIG_YAML, $entities);
|
||||
$entities = new Config($this->path . "entities.yml", CONFIG_YAML, $entities);
|
||||
$entities->save();
|
||||
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML, $tiles);
|
||||
$tiles = new Config($this->path . "tiles.yml", CONFIG_YAML, $tiles);
|
||||
$tiles->save();
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
$pmf = new PMFLevel($this->path."level.pmf", array(
|
||||
|
||||
$pmf = new PMFLevel($this->path . "level.pmf", [
|
||||
"name" => $level["LevelName"],
|
||||
"seed" => $level["RandomSeed"],
|
||||
"time" => $level["Time"],
|
||||
|
|
@ -67,13 +50,13 @@ class LevelImport{
|
|||
"extra" => "",
|
||||
"width" => 16,
|
||||
"height" => 8
|
||||
));
|
||||
]);
|
||||
$chunks = new PocketChunkParser();
|
||||
$chunks->loadFile($this->path."chunks.dat");
|
||||
$chunks->loadFile($this->path . "chunks.dat");
|
||||
$chunks->loadMap();
|
||||
for($Z = 0; $Z < 16; ++$Z){
|
||||
for($X = 0; $X < 16; ++$X){
|
||||
$chunk = array(
|
||||
$chunk = [
|
||||
0 => "",
|
||||
1 => "",
|
||||
2 => "",
|
||||
|
|
@ -81,8 +64,8 @@ class LevelImport{
|
|||
4 => "",
|
||||
5 => "",
|
||||
6 => "",
|
||||
7 => ""
|
||||
);
|
||||
7 => ""
|
||||
];
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$block = $chunks->getChunkColumn($X, $Z, $x, $z, 0);
|
||||
|
|
@ -99,17 +82,17 @@ class LevelImport{
|
|||
}
|
||||
$pmf->saveChunk($X, $Z);
|
||||
}
|
||||
console("[NOTICE] Importing level ".ceil(($Z + 1)/0.16)."%");
|
||||
console("[NOTICE] Importing level " . ceil(($Z + 1) / 0.16) . "%");
|
||||
}
|
||||
$chunks->map = null;
|
||||
$chunks = null;
|
||||
@unlink($this->path."level.dat");
|
||||
@unlink($this->path."level.dat_old");
|
||||
@unlink($this->path."player.dat");
|
||||
@unlink($this->path."entities.dat");
|
||||
@unlink($this->path."chunks.dat");
|
||||
@unlink($this->path."chunks.dat.gz");
|
||||
@unlink($this->path."tiles.dat");
|
||||
@unlink($this->path . "level.dat");
|
||||
@unlink($this->path . "level.dat_old");
|
||||
@unlink($this->path . "player.dat");
|
||||
@unlink($this->path . "entities.dat");
|
||||
@unlink($this->path . "chunks.dat");
|
||||
@unlink($this->path . "chunks.dat.gz");
|
||||
@unlink($this->path . "tiles.dat");
|
||||
unset($chunks, $level, $entities, $tiles, $nbt);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class PocketChunkParser{
|
||||
|
||||
var $sectorLength = 4096;
|
||||
var $chunkLength = 86016; //16 * 16 * 16
|
||||
var $map; //21 * $sectorLength
|
||||
private $location, $raw = b"", $file;
|
||||
var $sectorLength = 4096; //16 * 16 * 16
|
||||
var $chunkLength = 86016; //21 * $sectorLength
|
||||
var $map;
|
||||
|
||||
function __construct(){
|
||||
$map = array();
|
||||
}
|
||||
|
||||
private function loadLocationTable(){
|
||||
$this->location = array();
|
||||
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
||||
for($offset = 0; $offset < 0x1000; $offset += 4){
|
||||
$data = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||
$sectors = $data & 0xff;
|
||||
if($sectors === 0){
|
||||
continue;
|
||||
}
|
||||
$sectorLocation = $data >> 8;
|
||||
$this->location[$offset >> 2] = $sectorLocation * $this->sectorLength;//$this->getOffset($X, $Z, $sectors);
|
||||
}
|
||||
$map = [];
|
||||
}
|
||||
|
||||
public function loadFile($file){
|
||||
if(file_exists($file.".gz")){
|
||||
$this->raw = gzinflate(file_get_contents($file.".gz"));
|
||||
if(file_exists($file . ".gz")){
|
||||
$this->raw = gzinflate(file_get_contents($file . ".gz"));
|
||||
$r = @gzinflate($this->raw);
|
||||
if($r !== false and $r != ""){
|
||||
$this->raw = $r;
|
||||
}
|
||||
@unlink($file.".gz");
|
||||
@unlink($file . ".gz");
|
||||
file_put_contents($file, $this->raw);
|
||||
}elseif(!file_exists($file)){
|
||||
return false;
|
||||
|
|
@ -69,51 +37,14 @@ class PocketChunkParser{
|
|||
return true;
|
||||
}
|
||||
|
||||
private function getOffset($X, $Z){
|
||||
return $this->location[$X + ($Z << 5)];
|
||||
}
|
||||
|
||||
public function getChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
return substr($this->raw, $this->getOffset($X, $Z), $this->chunkLength);
|
||||
}
|
||||
|
||||
public function writeChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
if(!isset($this->map[$X][$Z])){
|
||||
return false;
|
||||
}
|
||||
$chunk = "";
|
||||
foreach($this->map[$X][$Z] as $section => $data){
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$chunk .= $data[$i];
|
||||
}
|
||||
}
|
||||
return Utils::writeLInt(strlen($chunk)).$chunk;
|
||||
}
|
||||
|
||||
public function parseChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
$offset = $this->getOffset($X, $Z);
|
||||
$len = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||
$offset += 4;
|
||||
$chunk = array(
|
||||
0 => array(), //Block
|
||||
1 => array(), //Data
|
||||
2 => array(), //SkyLight
|
||||
3 => array(), //BlockLight
|
||||
);
|
||||
foreach($chunk as $section => &$data){
|
||||
$l = $section === 0 ? 128:64;
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$data[$i] = substr($this->raw, $offset, $l);
|
||||
$offset += $l;
|
||||
}
|
||||
}
|
||||
return $chunk;
|
||||
private function getOffset($X, $Z){
|
||||
return $this->location[$X + ($Z << 5)];
|
||||
}
|
||||
|
||||
public function loadMap(){
|
||||
|
|
@ -123,7 +54,7 @@ class PocketChunkParser{
|
|||
$this->loadLocationTable();
|
||||
console("[DEBUG] Loading chunks...", true, true, 2);
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$this->map[$x] = array();
|
||||
$this->map[$x] = [];
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$this->map[$x][$z] = $this->parseChunk($x, $z);
|
||||
}
|
||||
|
|
@ -132,6 +63,42 @@ class PocketChunkParser{
|
|||
console("[DEBUG] Chunks loaded!", true, true, 2);
|
||||
}
|
||||
|
||||
private function loadLocationTable(){
|
||||
$this->location = [];
|
||||
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
||||
for($offset = 0; $offset < 0x1000; $offset += 4){
|
||||
$data = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||
$sectors = $data & 0xff;
|
||||
if($sectors === 0){
|
||||
continue;
|
||||
}
|
||||
$sectorLocation = $data >> 8;
|
||||
$this->location[$offset >> 2] = $sectorLocation * $this->sectorLength;//$this->getOffset($X, $Z, $sectors);
|
||||
}
|
||||
}
|
||||
|
||||
public function parseChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
$offset = $this->getOffset($X, $Z);
|
||||
$len = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||
$offset += 4;
|
||||
$chunk = [
|
||||
0 => [], //Block
|
||||
1 => [], //Data
|
||||
2 => [], //SkyLight
|
||||
3 => [], //BlockLight
|
||||
];
|
||||
foreach($chunk as $section => &$data){
|
||||
$l = $section === 0 ? 128 : 64;
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$data[$i] = substr($this->raw, $offset, $l);
|
||||
$offset += $l;
|
||||
}
|
||||
}
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
public function saveMap($final = false){
|
||||
console("[DEBUG] Saving chunks...", true, true, 2);
|
||||
|
||||
|
|
@ -146,14 +113,29 @@ class PocketChunkParser{
|
|||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
$original = filesize($this->file);
|
||||
file_put_contents($this->file .".gz", gzdeflate(gzdeflate(file_get_contents($this->file),9),9)); //Double compression for flat maps
|
||||
$compressed = filesize($this->file .".gz");
|
||||
console("[DEBUG] Saved chunks.dat.gz with ".round(($compressed/$original)*100, 2)."% (".round($compressed/1024, 2)."KB) of the original size", true, true, 2);
|
||||
file_put_contents($this->file . ".gz", gzdeflate(gzdeflate(file_get_contents($this->file), 9), 9)); //Double compression for flat maps
|
||||
$compressed = filesize($this->file . ".gz");
|
||||
console("[DEBUG] Saved chunks.dat.gz with " . round(($compressed / $original) * 100, 2) . "% (" . round($compressed / 1024, 2) . "KB) of the original size", true, true, 2);
|
||||
if($final === true){
|
||||
@unlink($this->file);
|
||||
}
|
||||
}
|
||||
|
||||
public function writeChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
if(!isset($this->map[$X][$Z])){
|
||||
return false;
|
||||
}
|
||||
$chunk = "";
|
||||
foreach($this->map[$X][$Z] as $section => $data){
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$chunk .= $data[$i];
|
||||
}
|
||||
}
|
||||
return Utils::writeLInt(strlen($chunk)) . $chunk;
|
||||
}
|
||||
|
||||
public function getFloor($x, $z){
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
|
|
@ -184,7 +166,7 @@ class PocketChunkParser{
|
|||
}else{
|
||||
$meta = $meta >> 4;
|
||||
}
|
||||
return array($block, $meta);
|
||||
return [$block, $meta];
|
||||
}
|
||||
|
||||
public function getChunkColumn($X, $Z, $x, $z, $type = 0){
|
||||
|
|
|
|||
|
|
@ -1,51 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class Position extends Vector3{
|
||||
|
||||
public $level;
|
||||
|
||||
public function __construct($x = 0, $y = 0, $z = 0, Level $level){
|
||||
if(($x instanceof Vector3) === true){
|
||||
$this->__construct($x->x, $x->y, $x->z, $level);
|
||||
public function __construct($x = 0, $y = 0, $z = 0, Level $level = null){
|
||||
if($x instanceof Vector3){
|
||||
parent::__construct($x->x, $x->y, $x->z);
|
||||
}else{
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->z = $z;
|
||||
}
|
||||
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
|
||||
public function getSide($side, $step = 1){
|
||||
return new Position(parent::getSide($side, $step), 0, 0, $this->level);
|
||||
}
|
||||
|
||||
|
||||
public function distance($x = 0, $y = 0, $z = 0){
|
||||
if(($x instanceof Position) and $x->level !== $this->level){
|
||||
return PHP_INT_MAX;
|
||||
}
|
||||
|
||||
return parent::distance($x, $y, $z);
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return "Position(level=".$this->level->getName().",x=".$this->x.",y=".$this->y.",z=".$this->z.")";
|
||||
return "Position(level=" . $this->level->getName() . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class Tile extends Position{
|
||||
|
||||
public $name;
|
||||
public $normal;
|
||||
public $id;
|
||||
|
|
@ -32,7 +14,8 @@ class Tile extends Position{
|
|||
public $metadata;
|
||||
public $closed;
|
||||
private $server;
|
||||
function __construct(Level $level, $id, $class, $x, $y, $z, $data = array()){
|
||||
|
||||
function __construct(Level $level, $id, $class, $x, $y, $z, $data = []){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->level = $level;
|
||||
$this->normal = true;
|
||||
|
|
@ -49,11 +32,11 @@ class Tile extends Position{
|
|||
$this->x = (int) $x;
|
||||
$this->y = (int) $y;
|
||||
$this->z = (int) $z;
|
||||
$this->server->query("INSERT OR REPLACE INTO tiles (ID, level, class, x, y, z) VALUES (".$this->id.", '".$this->level->getName()."', '".$this->class."', ".$this->x.", ".$this->y.", ".$this->z.");");
|
||||
$this->server->query("INSERT OR REPLACE INTO tiles (ID, level, class, x, y, z) VALUES (" . $this->id . ", '" . $this->level->getName() . "', '" . $this->class . "', " . $this->x . ", " . $this->y . ", " . $this->z . ");");
|
||||
switch($this->class){
|
||||
case TILE_CHEST:
|
||||
case TILE_SIGN:
|
||||
$this->server->query("UPDATE tiles SET spawnable = 1 WHERE ID = ".$this->id.";");
|
||||
$this->server->query("UPDATE tiles SET spawnable = 1 WHERE ID = " . $this->id . ";");
|
||||
break;
|
||||
case TILE_FURNACE:
|
||||
if(!isset($this->data["BurnTime"]) or $this->data["BurnTime"] < 0){
|
||||
|
|
@ -72,165 +55,12 @@ class Tile extends Position{
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function isPaired(){
|
||||
if($this->class !== TILE_CHEST){
|
||||
return false;
|
||||
}
|
||||
if(!isset($this->data["pairx"]) or !isset($this->data["pairz"])){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getPair(){
|
||||
if($this->isPaired()){
|
||||
return $this->server->api->tile->get(new Position((int) $this->data["pairx"], $this->y, (int) $this->data["pairz"], $this->level));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function pairWith(Tile $tile){
|
||||
if($this->isPaired()or $tile->isPaired()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->data["pairx"] = $tile->x;
|
||||
$this->data["pairz"] = $tile->z;
|
||||
|
||||
$tile->data["pairx"] = $this->x;
|
||||
$tile->data["pairz"] = $this->z;
|
||||
|
||||
$this->server->api->tile->spawnToAll($this);
|
||||
$this->server->api->tile->spawnToAll($tile);
|
||||
$this->server->handle("tile.update", $this);
|
||||
$this->server->handle("tile.update", $tile);
|
||||
}
|
||||
|
||||
public function unpair(){
|
||||
if(!$this->isPaired()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$tile = $this->getPair();
|
||||
unset($this->data["pairx"], $this->data["pairz"], $tile->data["pairx"], $tile->data["pairz"]);
|
||||
|
||||
$this->server->api->tile->spawnToAll($this);
|
||||
$this->server->handle("tile.update", $this);
|
||||
if($tile instanceof Tile){
|
||||
$this->server->api->tile->spawnToAll($tile);
|
||||
$this->server->handle("tile.update", $tile);
|
||||
}
|
||||
}
|
||||
|
||||
public function openInventory(Player $player){
|
||||
if($this->class === TILE_CHEST){
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(2, $player->windowCnt % 99);
|
||||
if(($pair = $this->getPair()) !== false){
|
||||
if(($pair->x + ($pair->z << 13)) > ($this->x + ($this->z << 13))){ //Order them correctly
|
||||
$player->windows[$id] = array(
|
||||
$pair,
|
||||
$this
|
||||
);
|
||||
}else{
|
||||
$player->windows[$id] = array(
|
||||
$this,
|
||||
$pair
|
||||
);
|
||||
}
|
||||
}else{
|
||||
$player->windows[$id] = $this;
|
||||
}
|
||||
|
||||
$pk = new ContainerOpenPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->type = WINDOW_CHEST;
|
||||
$pk->slots = is_array($player->windows[$id]) ? CHEST_SLOTS << 1:CHEST_SLOTS;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$player->dataPacket($pk);
|
||||
$slots = array();
|
||||
|
||||
if(is_array($player->windows[$id])){
|
||||
$all = $this->server->api->player->getAll($this->level);
|
||||
foreach($player->windows[$id] as $ob){
|
||||
$pk = new TileEventPacket;
|
||||
$pk->x = $ob->x;
|
||||
$pk->y = $ob->y;
|
||||
$pk->z = $ob->z;
|
||||
$pk->case1 = 1;
|
||||
$pk->case2 = 2;
|
||||
$this->server->api->player->broadcastPacket($all, $pk);
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $ob->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$pk = new TileEventPacket;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->case1 = 1;
|
||||
$pk->case2 = 2;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk);
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $this->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pk = new ContainerSetContentPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->slots = $slots;
|
||||
$player->dataPacket($pk);
|
||||
return true;
|
||||
}elseif($this->class === TILE_FURNACE){
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(2, $player->windowCnt % 99);
|
||||
$player->windows[$id] = $this;
|
||||
|
||||
$pk = new ContainerOpenPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->type = WINDOW_FURNACE;
|
||||
$pk->slots = FURNACE_SLOTS;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$slots = array();
|
||||
for($s = 0; $s < FURNACE_SLOTS; ++$s){
|
||||
$slot = $this->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
$pk = new ContainerSetContentPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->slots = $slots;
|
||||
$player->dataPacket($pk);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($this->class === TILE_FURNACE){
|
||||
$fuel = $this->getSlot(1);
|
||||
$raw = $this->getSlot(0);
|
||||
|
|
@ -274,8 +104,8 @@ class Tile extends Position{
|
|||
}else{
|
||||
$this->data["CookTime"] = 0;
|
||||
}
|
||||
|
||||
$this->server->schedule(2, array($this, "update"));
|
||||
|
||||
$this->server->schedule(2, [$this, "update"]);
|
||||
$this->scheduledUpdate = true;
|
||||
}else{
|
||||
$current = $this->level->getBlock($this);
|
||||
|
|
@ -291,7 +121,16 @@ class Tile extends Position{
|
|||
$this->server->handle("tile.update", $this);
|
||||
$this->lastUpdate = microtime(true);
|
||||
}
|
||||
|
||||
|
||||
public function getSlot($s){
|
||||
$i = $this->getSlotIndex($s);
|
||||
if($i === false or $i < 0){
|
||||
return BlockAPI::getItem(AIR, 0, 0);
|
||||
}else{
|
||||
return BlockAPI::getItem($this->data["Items"][$i]["id"], $this->data["Items"][$i]["Damage"], $this->data["Items"][$i]["Count"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSlotIndex($s){
|
||||
if($this->class !== TILE_CHEST and $this->class !== TILE_FURNACE){
|
||||
return false;
|
||||
|
|
@ -303,24 +142,15 @@ class Tile extends Position{
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function getSlot($s){
|
||||
$i = $this->getSlotIndex($s);
|
||||
if($i === false or $i < 0){
|
||||
return BlockAPI::getItem(AIR, 0, 0);
|
||||
}else{
|
||||
return BlockAPI::getItem($this->data["Items"][$i]["id"], $this->data["Items"][$i]["Damage"], $this->data["Items"][$i]["Count"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function setSlot($s, Item $item, $update = true, $offset = 0){
|
||||
$i = $this->getSlotIndex($s);
|
||||
$d = array(
|
||||
$d = [
|
||||
"Count" => $item->count,
|
||||
"Slot" => $s,
|
||||
"id" => $item->getID(),
|
||||
"Damage" => $item->getMetadata(),
|
||||
);
|
||||
];
|
||||
if($i === false){
|
||||
return false;
|
||||
}elseif($item->getID() === AIR or $item->count <= 0){
|
||||
|
|
@ -332,12 +162,12 @@ class Tile extends Position{
|
|||
}else{
|
||||
$this->data["Items"][$i] = $d;
|
||||
}
|
||||
$this->server->api->dhandle("tile.container.slot", array(
|
||||
$this->server->api->dhandle("tile.container.slot", [
|
||||
"tile" => $this,
|
||||
"slot" => $s,
|
||||
"offset" => $offset,
|
||||
"slotdata" => $item,
|
||||
));
|
||||
]);
|
||||
|
||||
if($update === true and $this->scheduledUpdate === false){
|
||||
$this->update();
|
||||
|
|
@ -345,6 +175,159 @@ class Tile extends Position{
|
|||
return true;
|
||||
}
|
||||
|
||||
public function pairWith(Tile $tile){
|
||||
if($this->isPaired() or $tile->isPaired()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->data["pairx"] = $tile->x;
|
||||
$this->data["pairz"] = $tile->z;
|
||||
|
||||
$tile->data["pairx"] = $this->x;
|
||||
$tile->data["pairz"] = $this->z;
|
||||
|
||||
$this->server->api->tile->spawnToAll($this);
|
||||
$this->server->api->tile->spawnToAll($tile);
|
||||
$this->server->handle("tile.update", $this);
|
||||
$this->server->handle("tile.update", $tile);
|
||||
}
|
||||
|
||||
public function isPaired(){
|
||||
if($this->class !== TILE_CHEST){
|
||||
return false;
|
||||
}
|
||||
if(!isset($this->data["pairx"]) or !isset($this->data["pairz"])){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function unpair(){
|
||||
if(!$this->isPaired()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$tile = $this->getPair();
|
||||
unset($this->data["pairx"], $this->data["pairz"], $tile->data["pairx"], $tile->data["pairz"]);
|
||||
|
||||
$this->server->api->tile->spawnToAll($this);
|
||||
$this->server->handle("tile.update", $this);
|
||||
if($tile instanceof Tile){
|
||||
$this->server->api->tile->spawnToAll($tile);
|
||||
$this->server->handle("tile.update", $tile);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPair(){
|
||||
if($this->isPaired()){
|
||||
return $this->server->api->tile->get(new Position((int) $this->data["pairx"], $this->y, (int) $this->data["pairz"], $this->level));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function openInventory(Player $player){
|
||||
if($this->class === TILE_CHEST){
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(2, $player->windowCnt % 99);
|
||||
if(($pair = $this->getPair()) !== false){
|
||||
if(($pair->x + ($pair->z << 13)) > ($this->x + ($this->z << 13))){ //Order them correctly
|
||||
$player->windows[$id] = [
|
||||
$pair,
|
||||
$this
|
||||
];
|
||||
}else{
|
||||
$player->windows[$id] = [
|
||||
$this,
|
||||
$pair
|
||||
];
|
||||
}
|
||||
}else{
|
||||
$player->windows[$id] = $this;
|
||||
}
|
||||
|
||||
$pk = new ContainerOpenPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->type = WINDOW_CHEST;
|
||||
$pk->slots = is_array($player->windows[$id]) ? CHEST_SLOTS << 1 : CHEST_SLOTS;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$player->dataPacket($pk);
|
||||
$slots = [];
|
||||
|
||||
if(is_array($player->windows[$id])){
|
||||
$all = $this->server->api->player->getAll($this->level);
|
||||
foreach($player->windows[$id] as $ob){
|
||||
$pk = new TileEventPacket;
|
||||
$pk->x = $ob->x;
|
||||
$pk->y = $ob->y;
|
||||
$pk->z = $ob->z;
|
||||
$pk->case1 = 1;
|
||||
$pk->case2 = 2;
|
||||
$this->server->api->player->broadcastPacket($all, $pk);
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $ob->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$pk = new TileEventPacket;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->case1 = 1;
|
||||
$pk->case2 = 2;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk);
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $this->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pk = new ContainerSetContentPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->slots = $slots;
|
||||
$player->dataPacket($pk);
|
||||
return true;
|
||||
}elseif($this->class === TILE_FURNACE){
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(2, $player->windowCnt % 99);
|
||||
$player->windows[$id] = $this;
|
||||
|
||||
$pk = new ContainerOpenPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->type = WINDOW_FURNACE;
|
||||
$pk->slots = FURNACE_SLOTS;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$slots = [];
|
||||
for($s = 0; $s < FURNACE_SLOTS; ++$s){
|
||||
$slot = $this->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
$pk = new ContainerSetContentPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->slots = $slots;
|
||||
$player->dataPacket($pk);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
if($this->closed){
|
||||
return false;
|
||||
|
|
@ -355,36 +338,36 @@ class Tile extends Position{
|
|||
switch($this->class){
|
||||
case TILE_CHEST:
|
||||
$nbt = new NBT();
|
||||
$nbt->write(chr(NBT::TAG_COMPOUND)."\x00\x00");
|
||||
|
||||
$nbt->write(chr(NBT::TAG_COMPOUND) . "\x00\x00");
|
||||
|
||||
$nbt->write(chr(NBT::TAG_STRING));
|
||||
$nbt->writeTAG_String("id");
|
||||
$nbt->writeTAG_String($this->class);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("x");
|
||||
$nbt->writeTAG_Int((int) $this->x);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("y");
|
||||
$nbt->writeTAG_Int((int) $this->y);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("z");
|
||||
$nbt->writeTAG_Int((int) $this->z);
|
||||
|
||||
|
||||
if($this->isPaired()){
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("pairx");
|
||||
$nbt->writeTAG_Int((int) $this->data["pairx"]);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("pairz");
|
||||
$nbt->writeTAG_Int((int) $this->data["pairz"]);
|
||||
}
|
||||
|
||||
$nbt->write(chr(NBT::TAG_END));
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_END));
|
||||
|
||||
$pk = new EntityDataPacket;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
|
|
@ -394,42 +377,42 @@ class Tile extends Position{
|
|||
break;
|
||||
case TILE_SIGN:
|
||||
$nbt = new NBT();
|
||||
$nbt->write(chr(NBT::TAG_COMPOUND)."\x00\x00");
|
||||
|
||||
$nbt->write(chr(NBT::TAG_COMPOUND) . "\x00\x00");
|
||||
|
||||
$nbt->write(chr(NBT::TAG_STRING));
|
||||
$nbt->writeTAG_String("Text1");
|
||||
$nbt->writeTAG_String($this->data["Text1"]);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_STRING));
|
||||
$nbt->writeTAG_String("Text2");
|
||||
$nbt->writeTAG_String($this->data["Text2"]);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_STRING));
|
||||
$nbt->writeTAG_String("Text3");
|
||||
$nbt->writeTAG_String($this->data["Text3"]);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_STRING));
|
||||
$nbt->writeTAG_String("Text4");
|
||||
$nbt->writeTAG_String($this->data["Text4"]);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_STRING));
|
||||
$nbt->writeTAG_String("id");
|
||||
$nbt->writeTAG_String($this->class);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("x");
|
||||
$nbt->writeTAG_Int((int) $this->x);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("y");
|
||||
$nbt->writeTAG_Int((int) $this->y);
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("z");
|
||||
$nbt->writeTAG_Int((int) $this->z);
|
||||
|
||||
$nbt->write(chr(NBT::TAG_END));
|
||||
|
||||
|
||||
$nbt->write(chr(NBT::TAG_END));
|
||||
|
||||
$pk = new EntityDataPacket;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
|
|
@ -439,7 +422,7 @@ class Tile extends Position{
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
|
||||
if($this->class !== TILE_SIGN){
|
||||
return false;
|
||||
|
|
@ -448,18 +431,22 @@ class Tile extends Position{
|
|||
$this->data["Text2"] = $line2;
|
||||
$this->data["Text3"] = $line3;
|
||||
$this->data["Text4"] = $line4;
|
||||
$this->server->api->tile->spawnToAll($this);
|
||||
$this->server->api->tile->spawnToAll($this);
|
||||
$this->server->handle("tile.update", $this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function getText(){
|
||||
return array(
|
||||
return [
|
||||
$this->data["Text1"],
|
||||
$this->data["Text2"],
|
||||
$this->data["Text3"],
|
||||
$this->data["Text4"]
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function close(){
|
||||
|
|
@ -469,10 +456,6 @@ class Tile extends Position{
|
|||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
|
@ -481,12 +464,11 @@ class Tile extends Position{
|
|||
public function setPosition(Vector3 $pos){
|
||||
if($pos instanceof Position){
|
||||
$this->level = $pos->level;
|
||||
$this->server->query("UPDATE tiles SET level = '".$this->level->getName()."' WHERE ID = ".$this->id.";");
|
||||
$this->server->query("UPDATE tiles SET level = '" . $this->level->getName() . "' WHERE ID = " . $this->id . ";");
|
||||
}
|
||||
$this->x = (int) $pos->x;
|
||||
$this->y = (int) $pos->y;
|
||||
$this->z = (int) $pos->z;
|
||||
$this->server->query("UPDATE tiles SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z." WHERE ID = ".$this->id.";");
|
||||
$this->server->query("UPDATE tiles SET x = " . $this->x . ", y = " . $this->y . ", z = " . $this->z . " WHERE ID = " . $this->id . ";");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
interface LevelGenerator{
|
||||
public function __construct(array $options = array());
|
||||
|
||||
|
||||
public function __construct(array $options = []);
|
||||
|
||||
public function init(Level $level, Random $random);
|
||||
|
||||
public function generateChunk($chunkX, $chunkZ);
|
||||
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ);
|
||||
|
||||
|
||||
public function populateLevel();
|
||||
|
||||
|
||||
public function getSpawn();
|
||||
}
|
||||
|
|
@ -1,24 +1,6 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class Populator{
|
||||
|
||||
public abstract function populate(Level $level, $chunkX, $chunkZ, Random $random);
|
||||
}
|
||||
|
|
@ -1,32 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once("LevelGenerator.php");
|
||||
/***REM_END***/
|
||||
|
||||
/***REM_END***/
|
||||
class SuperflatGenerator 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->preset = "2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)";
|
||||
$this->options = $options;
|
||||
if(isset($options["preset"])){
|
||||
|
|
@ -36,50 +18,50 @@ class SuperflatGenerator implements LevelGenerator{
|
|||
}
|
||||
if(isset($this->options["decoration"])){
|
||||
$ores = new OrePopulator();
|
||||
$ores->setOreTypes(array(
|
||||
$ores->setOreTypes([
|
||||
new OreType(new CoalOreBlock(), 20, 16, 0, 128),
|
||||
new OreType(New IronOreBlock(), 20, 8, 0, 64),
|
||||
new OreType(new IronOreBlock(), 20, 8, 0, 64),
|
||||
new OreType(new RedstoneOreBlock(), 8, 7, 0, 16),
|
||||
new OreType(new LapisOreBlock(), 1, 6, 0, 32),
|
||||
new OreType(new GoldOreBlock(), 2, 8, 0, 32),
|
||||
new OreType(new DiamondOreBlock(), 1, 7, 0, 16),
|
||||
new OreType(new DirtBlock(), 20, 32, 0, 128),
|
||||
new OreType(new GravelBlock(), 10, 16, 0, 128),
|
||||
));
|
||||
$this->populators[] = $ores;
|
||||
]);
|
||||
$this->populators[] = $ores;
|
||||
}
|
||||
|
||||
|
||||
/*if(isset($this->options["mineshaft"])){
|
||||
$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);
|
||||
$version = (int) $preset[0];
|
||||
$blocks = @$preset[1];
|
||||
$biome = isset($preset[2]) ? $preset[2]:1;
|
||||
$options = isset($preset[3]) ? $preset[3]:"";
|
||||
$biome = isset($preset[2]) ? $preset[2] : 1;
|
||||
$options = isset($preset[3]) ? $preset[3] : "";
|
||||
preg_match_all('#(([0-9]{0,})x?([0-9]{1,3}:?[0-9]{0,2})),?#', $blocks, $matches);
|
||||
$y = 0;
|
||||
$this->structure = array();
|
||||
$this->chunks = array();
|
||||
$this->structure = [];
|
||||
$this->chunks = [];
|
||||
foreach($matches[3] as $i => $b){
|
||||
$b = BlockAPI::fromString($b);
|
||||
$cnt = $matches[2][$i] === "" ? 1:intval($matches[2][$i]);
|
||||
$cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
|
||||
for($cY = $y, $y += $cnt; $cY < $y; ++$cY){
|
||||
$this->structure[$cY] = $b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->floorLevel = $y;
|
||||
|
||||
for(;$y < 0xFF; ++$y){
|
||||
|
||||
for(; $y < 0xFF; ++$y){
|
||||
$this->structure[$y] = new AirBlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for($Y = 0; $Y < 8; ++$Y){
|
||||
$this->chunks[$Y] = "";
|
||||
$startY = $Y << 4;
|
||||
|
|
@ -92,16 +74,16 @@ class SuperflatGenerator implements LevelGenerator{
|
|||
$blocks .= chr($this->structure[$y]->getID());
|
||||
$metas .= substr(dechex($this->structure[$y]->getMetadata()), -1);
|
||||
}
|
||||
$this->chunks[$Y] .= $blocks.hex2bin($metas)."\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
$this->chunks[$Y] .= $blocks . hex2bin($metas) . "\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
preg_match_all('#(([0-9a-z_]{1,})\(?([0-9a-z_ =:]{0,})\)?),?#', $options, $matches);
|
||||
foreach($matches[2] as $i => $option){
|
||||
$params = true;
|
||||
if($matches[3][$i] !== ""){
|
||||
$params = array();
|
||||
$params = [];
|
||||
$p = explode(" ", $matches[3][$i]);
|
||||
foreach($p as $k){
|
||||
$k = explode("=", $k);
|
||||
|
|
@ -113,29 +95,29 @@ class SuperflatGenerator implements LevelGenerator{
|
|||
$this->options[$option] = $params;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
if(isset($this->options["spawn"])){
|
||||
$spawn = array(10, new SandstoneBlock());
|
||||
$spawn = [10, new SandstoneBlock()];
|
||||
if(isset($this->options["spawn"]["radius"])){
|
||||
$spawn[0] = intval($this->options["spawn"]["radius"]);
|
||||
}
|
||||
|
|
@ -156,7 +138,7 @@ class SuperflatGenerator implements LevelGenerator{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(isset($this->options["decoration"])){
|
||||
$treecount = 80;
|
||||
$grasscount = 120;
|
||||
|
|
@ -171,7 +153,7 @@ class SuperflatGenerator implements LevelGenerator{
|
|||
$centerZ = $this->random->nextRange(0, 255);
|
||||
$down = $this->level->level->getBlockID($centerX, $this->floorLevel - 1, $centerZ);
|
||||
if($down === DIRT or $down === GRASS or $down === FARMLAND){
|
||||
TreeObject::growTree($this->level, new Vector3($centerX, $this->floorLevel, $centerZ), $this->random, $this->random->nextRange(0,3));
|
||||
TreeObject::growTree($this->level, new Vector3($centerX, $this->floorLevel, $centerZ), $this->random, $this->random->nextRange(0, 3));
|
||||
}
|
||||
}
|
||||
for($t = 0; $t < $grasscount; ++$t){
|
||||
|
|
@ -184,7 +166,7 @@ class SuperflatGenerator implements LevelGenerator{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getSpawn(){
|
||||
return new Vector3(128, $this->floorLevel, 128);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,34 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class WorldGenerator{
|
||||
|
||||
private $seed, $level, $path, $random, $generator, $width;
|
||||
|
||||
public function __construct(LevelGenerator $generator, $name, $seed = false, $width = 16, $height = 8){
|
||||
$this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false));
|
||||
$this->seed = $seed !== false ? (int) $seed : Utils::readInt(Utils::getRandomBytes(4, false));
|
||||
$this->random = new Random($this->seed);
|
||||
$this->width = (int) $width;
|
||||
$this->height = (int) $height;
|
||||
$this->path = DATA_PATH."worlds/".$name."/";
|
||||
$this->path = DATA_PATH . "worlds/" . $name . "/";
|
||||
$this->generator = $generator;
|
||||
$level = new PMFLevel($this->path."level.pmf", array(
|
||||
$level = new PMFLevel($this->path . "level.pmf", [
|
||||
"name" => $name,
|
||||
"seed" => $this->seed,
|
||||
"time" => 0,
|
||||
|
|
@ -38,20 +21,20 @@ class WorldGenerator{
|
|||
"extra" => "",
|
||||
"width" => $this->width,
|
||||
"height" => $this->height
|
||||
));
|
||||
$entities = new Config($this->path."entities.yml", CONFIG_YAML);
|
||||
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML);
|
||||
$blockUpdates = new Config($this->path."bupdates.yml", CONFIG_YAML);
|
||||
]);
|
||||
$entities = new Config($this->path . "entities.yml", CONFIG_YAML);
|
||||
$tiles = new Config($this->path . "tiles.yml", CONFIG_YAML);
|
||||
$blockUpdates = new Config($this->path . "bupdates.yml", CONFIG_YAML);
|
||||
$this->level = new Level($level, $entities, $tiles, $blockUpdates, $name);
|
||||
}
|
||||
|
||||
|
||||
public function generate(){
|
||||
$this->generator->init($this->level, $this->random);
|
||||
for($Z = 0; $Z < $this->width; ++$Z){
|
||||
for($X = 0; $X < $this->width; ++$X){
|
||||
$this->generator->generateChunk($X, $Z);
|
||||
}
|
||||
console("[NOTICE] Generating level ".ceil((($Z + 1)/$this->width) * 100)."%");
|
||||
console("[NOTICE] Generating level " . ceil((($Z + 1) / $this->width) * 100) . "%");
|
||||
}
|
||||
console("[NOTICE] Populating level");
|
||||
$this->generator->populateLevel();
|
||||
|
|
@ -59,13 +42,13 @@ class WorldGenerator{
|
|||
for($X = 0; $X < $this->width; ++$X){
|
||||
$this->generator->populateChunk($X, $Z);
|
||||
}
|
||||
console("[NOTICE] Populating level ".ceil((($Z + 1)/$this->width) * 100)."%");
|
||||
console("[NOTICE] Populating level " . ceil((($Z + 1) / $this->width) * 100) . "%");
|
||||
}
|
||||
|
||||
|
||||
$this->level->setSpawn($this->generator->getSpawn());
|
||||
$this->level->save(true, true);
|
||||
}
|
||||
|
||||
|
||||
public function close(){
|
||||
$this->level->close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class NoiseGenerator{
|
||||
|
||||
}
|
||||
|
|
@ -1,24 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once("NoiseGenerator.php");
|
||||
/***REM_END***/
|
||||
|
|
|
|||
|
|
@ -1,32 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once("NoiseGenerator.php");
|
||||
/***REM_END***/
|
||||
|
||||
/***REM_END***/
|
||||
class NoiseGeneratorPerlin extends NoiseGenerator{
|
||||
private $permutations = array();
|
||||
|
||||
public $xCoord, $yCoord, $zCoord;
|
||||
|
||||
private $permutations = [];
|
||||
|
||||
public function __construct($random = false){
|
||||
if(!($random instanceof Random)){
|
||||
$random = new Random();
|
||||
|
|
@ -41,7 +23,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
for($i = 0; $i < 256; ++$i){
|
||||
$this->permutations[$i] = $i;
|
||||
}
|
||||
|
||||
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$j = $random->nextRange(0, 256 - $i) + $i;
|
||||
$k = $this->permutations[$i];
|
||||
|
|
@ -49,29 +31,9 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
$this->permutations[$j] = $k;
|
||||
$this->permutations[$i + 256] = $this->permutations[$i];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public final function curve($par1, $par2, $par3){
|
||||
return $par2 + $par1 * ($par3 - $par2);
|
||||
}
|
||||
|
||||
public function grad2D($int, $par1, $par2){
|
||||
$i = $int & 0x0F;
|
||||
$d1 = (1 - (($i & 0x08) >> 3)) * $par1;
|
||||
$d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? 0:$par2);
|
||||
|
||||
return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2);
|
||||
}
|
||||
|
||||
public function grad3D($int, $par1, $par2, $par3){
|
||||
$i = $int & 0x0F;
|
||||
$d1 = $i < 8 ? $par1 : $par2;
|
||||
$d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? $par2:$par3);
|
||||
|
||||
return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2);
|
||||
}
|
||||
|
||||
|
||||
public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7){
|
||||
if($int2 === 1){
|
||||
$n = 0;
|
||||
|
|
@ -85,7 +47,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
$i3 = $i2 & 0xFF;
|
||||
$d4 -= $i2;
|
||||
$d5 = $d4 * $d4 * $d4 * ($d4 * ($d4 * 6 - 15) + 10);
|
||||
|
||||
|
||||
for($i4 = 0; $i4 < $int3; ++$i4){
|
||||
$d6 = $par3 + $i4 * $par6 + $this->zCoord;
|
||||
$i5 = (int) $d6;
|
||||
|
|
@ -95,14 +57,14 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
$i6 = $i5 & 0xFF;
|
||||
$d6 -= $i5;
|
||||
$d7 = $d6 * $d6 * $d6 * ($d6 * ($d6 * 6 - 15) + 10);
|
||||
|
||||
|
||||
$i = $this->permutations[$i3];
|
||||
$j = $this->permutations[$i] + $i6;
|
||||
$k = $this->permutations[$i3 + 1];
|
||||
$m = $this->permutations[$k] + $i6;
|
||||
$d1 = $this->curve($d5, $this->grad2D($this->permutations[$j], $d4, $d6), $this->grad3D($this->permutations[$m], $d4 - 1, 0, $d6));
|
||||
$d2 = $this->curve($d5, $this->grad3D($this->permutations[$j + 1], $d4, 0, $d6 - 1), $this->grad3D($this->permutations[$m + 1], $d4 - 1, 0, $d6 - 1));
|
||||
|
||||
|
||||
$d8 = $this->curve($d7, $d1, $d2);
|
||||
$floats[$n++] += $d8 * $d3;
|
||||
}
|
||||
|
|
@ -114,7 +76,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
$m = -1;
|
||||
$n = 0;
|
||||
$i = 0;
|
||||
|
||||
|
||||
for($i4 = 0; $i4 < $int1; ++$i4){
|
||||
$d6 = $par1 + $i4 * $par4 + $this->xCoord;
|
||||
$i5 = (int) $d6;
|
||||
|
|
@ -124,7 +86,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
$i6 = $i5 & 0xFF;
|
||||
$d6 -= $i5;
|
||||
$d7 = $d6 * $d6 * $d6 * ($d6 * ($d6 * 6 - 15) + 10);
|
||||
|
||||
|
||||
for($i12 = 0; $i12 < $int3; ++$i12){
|
||||
$d12 = $par3 + $i12 * $par6 + $this->zCoord;
|
||||
$i13 = (int) $d12;
|
||||
|
|
@ -134,7 +96,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
$i14 = $i13 & 0xFF;
|
||||
$d12 -= $i13;
|
||||
$d13 = $d12 * $d12 * $d12 * ($d12 * ($d12 * 6 - 15) + 10);
|
||||
|
||||
|
||||
for($i15 = 0; $i15 < $int2; ++$i15){
|
||||
$d14 = $par2 + $i15 * $par5 + $this->yCoord;
|
||||
$i16 = (int) $d14;
|
||||
|
|
@ -157,7 +119,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
$d11 = $this->curve($d7, $this->grad3D($this->permutations[$i8 + 1], $d6, $d14, $d12 - 1), $this->grad3D($this->permutations[$n + 1], $d6 - 1, $d14, $d12 - 1));
|
||||
$d5 = $this->curve($d7, $this->grad3D($this->permutations[$i9 + 1], $d6, $d14 - 1, $d12 - 1), $this->grad3D($this->permutations[$i11 + 1], $d6 - 1, $d14 - 1, $d12 - 1));
|
||||
}
|
||||
|
||||
|
||||
$d16 = $this->curve($d15, $d10, $d4);
|
||||
$d17 = $this->curve($d15, $d11, $d5);
|
||||
$d18 = $this->curve($d13, $d16, $d17);
|
||||
|
|
@ -166,4 +128,24 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final function curve($par1, $par2, $par3){
|
||||
return $par2 + $par1 * ($par3 - $par2);
|
||||
}
|
||||
|
||||
public function grad2D($int, $par1, $par2){
|
||||
$i = $int & 0x0F;
|
||||
$d1 = (1 - (($i & 0x08) >> 3)) * $par1;
|
||||
$d2 = ($i === 12 or $i === 14) ? $par1 : ($i < 4 ? 0 : $par2);
|
||||
|
||||
return (($i & 0x01) === 0 ? $d1 : -$d1) + (($i & 0x02) === 0 ? $d2 : -$d2);
|
||||
}
|
||||
|
||||
public function grad3D($int, $par1, $par2, $par3){
|
||||
$i = $int & 0x0F;
|
||||
$d1 = $i < 8 ? $par1 : $par2;
|
||||
$d2 = ($i === 12 or $i === 14) ? $par1 : ($i < 4 ? $par2 : $par3);
|
||||
|
||||
return (($i & 0x01) === 0 ? $d1 : -$d1) + (($i & 0x02) === 0 ? $d2 : -$d2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
class NetherReactorStructure{
|
||||
|
||||
/*pretty long =D*/
|
||||
private static $structure = [
|
||||
-2 => [
|
||||
|
|
@ -174,23 +176,23 @@ class NetherReactorStructure{
|
|||
"NNNNNNNNNNNNNNNNN",
|
||||
],
|
||||
7 => [ //spaces are required
|
||||
"NNNNNNNNNNNNNNNNN",
|
||||
"N N",
|
||||
"N N",
|
||||
"N NNNNNNNNNNN N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N NNNNNNNNNNN N",
|
||||
"N NN",
|
||||
"N NNN",
|
||||
"NNNNNNNNNNNNNNNN ",
|
||||
"NNNNNNNNNNNNNNNNN",
|
||||
"N N",
|
||||
"N N",
|
||||
"N NNNNNNNNNNN N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N N N N",
|
||||
"N NNNNNNNNNNN N",
|
||||
"N NN",
|
||||
"N NNN",
|
||||
"NNNNNNNNNNNNNNNN ",
|
||||
],
|
||||
8 => [
|
||||
"NNNNNNNNNNNNNNNNN",
|
||||
|
|
@ -589,6 +591,7 @@ class NetherReactorStructure{
|
|||
" N ",
|
||||
],
|
||||
];
|
||||
|
||||
public static function buildReactor($level, $x, $y, $z){ /*use CENTER positions*/
|
||||
$offsetX = 0;
|
||||
$offsetZ = 0;
|
||||
|
|
|
|||
|
|
@ -1,41 +1,23 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class OreObject{
|
||||
private $random;
|
||||
|
||||
public $type;
|
||||
|
||||
private $random;
|
||||
|
||||
public function __construct(Random $random, OreType $type){
|
||||
$this->type = $type;
|
||||
$this->random = $random;
|
||||
}
|
||||
|
||||
|
||||
public function getType(){
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
|
||||
public function canPlaceObject(Level $level, $x, $y, $z){
|
||||
return ($level->level->getBlockID($x, $y, $z) != AIR);
|
||||
}
|
||||
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos){
|
||||
$clusterSize = (int) $this->type->clusterSize;
|
||||
$angle = $this->random->nextFloat() * M_PI;
|
||||
|
|
@ -51,14 +33,14 @@ class OreObject{
|
|||
$seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
|
||||
$seedZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
|
||||
$size = ((sin($count * (M_PI / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
|
||||
|
||||
|
||||
$startX = (int) ($seedX - $size);
|
||||
$startY = (int) ($seedY - $size);
|
||||
$startZ = (int) ($seedZ - $size);
|
||||
$endX = (int) ($seedX + $size);
|
||||
$endY = (int) ($seedY + $size);
|
||||
$endZ = (int) ($seedZ + $size);
|
||||
|
||||
|
||||
for($x = $startX; $x <= $endX; ++$x){
|
||||
$sizeX = ($x + 0.5 - $seedX) / $size;
|
||||
$sizeX *= $sizeX;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class OreType{
|
||||
|
||||
public $material, $clusterCount, $clusterSize, $maxHeight, $minHeight;
|
||||
|
||||
|
||||
public function __construct(Block $material, $clusterCount, $clusterSize, $minHeight, $maxHeight){
|
||||
$this->material = $material;
|
||||
$this->clusterCount = (int) $clusterCount;
|
||||
|
|
|
|||
|
|
@ -1,37 +1,18 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class PondObject{
|
||||
private $random;
|
||||
|
||||
public $type;
|
||||
|
||||
private $random;
|
||||
|
||||
public function __construct(Random $random, Block $type){
|
||||
$this->type = $type;
|
||||
$this->random = $random;
|
||||
}
|
||||
|
||||
|
||||
public function canPlaceObject(Level $level, Vector3 $pos){
|
||||
}
|
||||
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos){
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class TallGrassObject{
|
||||
|
||||
public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){
|
||||
$arr = array(
|
||||
$arr = [
|
||||
BlockAPI::get(DANDELION, 0),
|
||||
BlockAPI::get(CYAN_FLOWER, 0),
|
||||
BlockAPI::get(TALL_GRASS, 1),
|
||||
BlockAPI::get(TALL_GRASS, 1),
|
||||
BlockAPI::get(TALL_GRASS, 2),
|
||||
BlockAPI::get(TALL_GRASS, 1)
|
||||
);
|
||||
];
|
||||
$arrC = count($arr) - 1;
|
||||
for($c = 0; $c < $count; ++$c){
|
||||
$x = $random->nextRange($pos->x - $radius, $pos->x + $radius);
|
||||
|
|
|
|||
|
|
@ -1,39 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once("src/world/generator/object/tree/TreeObject.php");
|
||||
/***REM_END***/
|
||||
|
||||
/***REM_END***/
|
||||
class BigTreeObject extends TreeObject{
|
||||
|
||||
protected $radiusIncrease = 0;
|
||||
private $trunkHeightMultiplier = 0.618;
|
||||
private $trunkHeight;
|
||||
private $leafAmount = 1;
|
||||
private $leafDistanceLimit = 5;
|
||||
private $widthScale = 1;
|
||||
private $branchSlope = 0.381;
|
||||
|
||||
private $totalHeight = 6;
|
||||
private $leavesHeight = 3;
|
||||
protected $radiusIncrease = 0;
|
||||
private $addLeavesVines = false;
|
||||
private $addLogVines = false;
|
||||
private $addCocoaPlants = false;
|
||||
|
|
@ -50,7 +31,7 @@ class BigTreeObject extends TreeObject{
|
|||
$groupX = $leafGroup->getBlockX();
|
||||
$groupY = $leafGrou->getBlockY();
|
||||
$groupZ = $leafGroup->getBlockZ();
|
||||
for ($yy = $groupY; $yy < $groupY + $this->leafDistanceLimit; ++$yy) {
|
||||
for($yy = $groupY; $yy < $groupY + $this->leafDistanceLimit; ++$yy){
|
||||
$this->generateGroupLayer($level, $groupX, $yy, $groupZ, $this->getLeafGroupLayerSize($yy - $groupY));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once("src/world/generator/object/tree/TreeObject.php");
|
||||
/***REM_END***/
|
||||
|
||||
/***REM_END***/
|
||||
class PineTreeObject extends TreeObject{
|
||||
|
||||
var $type = 1;
|
||||
private $totalHeight = 8;
|
||||
private $leavesSizeY = -1;
|
||||
|
|
@ -32,8 +14,8 @@ class PineTreeObject extends TreeObject{
|
|||
public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
|
||||
$this->findRandomLeavesSize($random);
|
||||
$checkRadius = 0;
|
||||
for($yy = 0; $yy < $this->totalHeight; ++$yy) {
|
||||
if($yy === $this->leavesSizeY) {
|
||||
for($yy = 0; $yy < $this->totalHeight; ++$yy){
|
||||
if($yy === $this->leavesSizeY){
|
||||
$checkRadius = $this->leavesAbsoluteMaxRadius;
|
||||
}
|
||||
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
|
||||
|
|
@ -54,7 +36,7 @@ class PineTreeObject extends TreeObject{
|
|||
}
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos, Random $random){
|
||||
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) {
|
||||
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1){
|
||||
$this->findRandomLeavesSize($random);
|
||||
}
|
||||
$level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock());
|
||||
|
|
@ -62,19 +44,19 @@ class PineTreeObject extends TreeObject{
|
|||
$leavesMaxRadius = 1;
|
||||
$leavesBottomY = $this->totalHeight - $this->leavesSizeY;
|
||||
$firstMaxedRadius = false;
|
||||
for($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY) {
|
||||
for($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY){
|
||||
$yy = $this->totalHeight - $leavesY;
|
||||
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
|
||||
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
|
||||
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
|
||||
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx){
|
||||
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz){
|
||||
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0){
|
||||
$level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new LeavesBlock($this->type));
|
||||
}
|
||||
}
|
||||
}
|
||||
if($leavesRadius >= $leavesMaxRadius) {
|
||||
if($leavesRadius >= $leavesMaxRadius){
|
||||
$leavesRadius = $firstMaxedRadius ? 1 : 0;
|
||||
$firstMaxedRadius = true;
|
||||
if(++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius) {
|
||||
if(++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius){
|
||||
$leavesMaxRadius = $this->leavesAbsoluteMaxRadius;
|
||||
}
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -1,42 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once("TreeObject.php");
|
||||
/***REM_END***/
|
||||
|
||||
/***REM_END***/
|
||||
class SmallTreeObject extends TreeObject{
|
||||
public $type = 0;
|
||||
private $trunkHeight = 5;
|
||||
private static $leavesHeight = 4; // All trees appear to be 4 tall
|
||||
private static $leafRadii = array( 1, 1.41, 2.83, 2.24 );
|
||||
|
||||
private static $leavesHeight = 4;
|
||||
private static $leafRadii = [1, 1.41, 2.83, 2.24];
|
||||
public $type = 0; // All trees appear to be 4 tall
|
||||
public $treeHeight = 7;
|
||||
private $trunkHeight = 5;
|
||||
private $addLeavesVines = false;
|
||||
private $addLogVines = false;
|
||||
private $addCocoaPlants = false;
|
||||
|
||||
public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
|
||||
$radiusToCheck = 0;
|
||||
for ($yy = 0; $yy < $this->trunkHeight + 3; ++$yy) {
|
||||
if($yy == 1 or $yy === $this->trunkHeight) {
|
||||
for($yy = 0; $yy < $this->trunkHeight + 3; ++$yy){
|
||||
if($yy == 1 or $yy === $this->trunkHeight){
|
||||
++$radiusToCheck;
|
||||
}
|
||||
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
|
||||
|
|
@ -49,27 +31,13 @@ class SmallTreeObject extends TreeObject{
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function placeTrunk(Level $level, $x, $y, $z, Random $random, $trunkHeight){
|
||||
// The base dirt block
|
||||
$dirtpos = new Vector3($x, $y - 1, $z);
|
||||
$level->setBlockRaw($dirtpos, new DirtBlock());
|
||||
|
||||
for($yy = 0; $yy < $this->treeHeight; ++$yy){
|
||||
$blockId = $level->getBlock(new Vector3($x, $y + $yy, $z))->getID();
|
||||
if(isset($this->overridable[$blockId])){
|
||||
$trunkpos = new Vector3($x, $y + $yy, $z);
|
||||
$level->setBlockRaw($trunkpos, new WoodBlock($this->type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos, Random $random){
|
||||
$this->treeHeight = mt_rand(0, 3) + 4; //randomized tree height
|
||||
$x = $pos->getX();
|
||||
$y = $pos->getY();
|
||||
$z = $pos->getZ();
|
||||
|
||||
|
||||
for($yy = $y - 3 + $this->treeHeight; $yy <= $y + $this->treeHeight; ++$yy){
|
||||
$yOff = $yy - ($y + $this->treeHeight);
|
||||
$mid = (int) (1 - $yOff / 2);
|
||||
|
|
@ -90,5 +58,19 @@ class SmallTreeObject extends TreeObject{
|
|||
$this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function placeTrunk(Level $level, $x, $y, $z, Random $random, $trunkHeight){
|
||||
// The base dirt block
|
||||
$dirtpos = new Vector3($x, $y - 1, $z);
|
||||
$level->setBlockRaw($dirtpos, new DirtBlock());
|
||||
|
||||
for($yy = 0; $yy < $this->treeHeight; ++$yy){
|
||||
$blockId = $level->getBlock(new Vector3($x, $y + $yy, $z))->getID();
|
||||
if(isset($this->overridable[$blockId])){
|
||||
$trunkpos = new Vector3($x, $y + $yy, $z);
|
||||
$level->setBlockRaw($trunkpos, new WoodBlock($this->type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,29 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once("src/world/generator/object/tree/TreeObject.php");
|
||||
/***REM_END***/
|
||||
|
||||
/***REM_END***/
|
||||
class SpruceTreeObject extends TreeObject{
|
||||
|
||||
var $type = 1;
|
||||
private $totalHeight = 8;
|
||||
private $leavesBottomY = -1;
|
||||
|
|
@ -32,8 +14,8 @@ class SpruceTreeObject extends TreeObject{
|
|||
public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
|
||||
$this->findRandomLeavesSize($random);
|
||||
$checkRadius = 0;
|
||||
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
|
||||
if($yy === $this->leavesBottomY) {
|
||||
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy){
|
||||
if($yy === $this->leavesBottomY){
|
||||
$checkRadius = $this->leavesMaxRadius;
|
||||
}
|
||||
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
|
||||
|
|
@ -54,20 +36,20 @@ class SpruceTreeObject extends TreeObject{
|
|||
}
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos, Random $random){
|
||||
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
|
||||
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1){
|
||||
$this->findRandomLeavesSize();
|
||||
}
|
||||
$level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock());
|
||||
$leavesRadius = 0;
|
||||
for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){
|
||||
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
|
||||
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
|
||||
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
|
||||
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx){
|
||||
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz){
|
||||
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0){
|
||||
$level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new LeavesBlock($this->type));
|
||||
}
|
||||
}
|
||||
}
|
||||
if($leavesRadius > 0 and $yy === ($pos->y + $this->leavesBottomY + 1)) {
|
||||
if($leavesRadius > 0 and $yy === ($pos->y + $this->leavesBottomY + 1)){
|
||||
--$leavesRadius;
|
||||
}elseif($leavesRadius < $this->leavesMaxRadius){
|
||||
++$leavesRadius;
|
||||
|
|
|
|||
|
|
@ -1,31 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class TreeObject{
|
||||
public $overridable = array(
|
||||
|
||||
public $overridable = [
|
||||
0 => true,
|
||||
6 => true,
|
||||
18 => true,
|
||||
);
|
||||
];
|
||||
|
||||
public static function growTree(Level $level, Vector3 $pos, Random $random, $type = 0){
|
||||
switch($type & 0x03){
|
||||
|
|
@ -49,7 +30,7 @@ class TreeObject{
|
|||
/*if($random->nextRange(0, 9) === 0){
|
||||
$tree = new BigTreeObject();
|
||||
}else{*/
|
||||
$tree = new SmallTreeObject();
|
||||
$tree = new SmallTreeObject();
|
||||
//}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class MineshaftPopulator extends Populator{
|
||||
|
||||
private static $DISTANCE = 256;
|
||||
private static $VARIATION = 16;
|
||||
private static $ODD = 3;
|
||||
private static $BASE_Y = 35;
|
||||
private static $RAND_Y = 11;
|
||||
|
||||
|
||||
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
|
||||
if($random->nextRange(0, MineshaftPopulator::$ODD) === 0){
|
||||
$mineshaft = new Mineshaft($random);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,26 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class OrePopulator extends Populator{
|
||||
private $oreTypes = array();
|
||||
|
||||
private $oreTypes = [];
|
||||
|
||||
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
|
||||
foreach($this->oreTypes as $type){
|
||||
$ore = new OreObject($random, $type);
|
||||
|
|
@ -34,7 +17,7 @@ class OrePopulator extends Populator{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function setOreTypes(array $types){
|
||||
$this->oreTypes = $types;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class PondPopulator extends Populator{
|
||||
|
||||
private $waterOdd = 4;
|
||||
private $lavaOdd = 4;
|
||||
private $lavaSurfaceOdd = 4;
|
||||
|
||||
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
|
||||
if($random->nextRange(0, $this->waterOdd) === 0){
|
||||
$v = new Vector3(
|
||||
|
|
@ -36,7 +19,7 @@ class PondPopulator extends Populator{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function setWaterOdd($waterOdd){
|
||||
$this->waterOdd = $waterOdd;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue