Merge branch 'Level-Rewrite'

This commit is contained in:
Shoghi Cervantes 2014-06-07 23:33:49 +02:00
commit 920e2a7c7e
17 changed files with 2128 additions and 1305 deletions

View File

@ -70,6 +70,15 @@ abstract class Entity extends Position implements Metadatable{
public $passenger = null;
public $vehicle = null;
/** @var int */
public $chunkX;
/** @var int */
public $chunkZ;
/**
* TODO: REMOVE
* @var int
*/
public $chunkIndex;
public $lastX;

View File

@ -0,0 +1,39 @@
<?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/
*
*
*/
/**
* Level related events
*/
namespace pocketmine\event\level;
use pocketmine\event\Event;
abstract class LevelEvent extends Event{
/** @var \pocketmine\level\Level */
protected $level;
/**
* @return \pocketmine\level\Level
*/
public function getLevel(){
return $this->level;
}
}

View File

@ -0,0 +1,48 @@
<?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/
*
*
*/
namespace pocketmine\event\level;
use pocketmine\level\Level;
use pocketmine\level\Position;
/**
* An event that is called when a level spawn changes.
* The previous spawn is included
*/
class SpawnChangeEvent extends LevelEvent{
public static $handlerList = null;
/** @var Position */
private $previousSpawn;
public function __construct(Level $level, Position $previousSpawn){
$this->level = $level;
$this->previousSpawn = $previousSpawn;
}
/**
* @return Position
*/
public function getPreviousSpawn(){
return $this->previousSpawn;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,9 @@
namespace pocketmine\level\format;
use pocketmine\entity\Entity;
use pocketmine\tile\Tile;
interface Chunk{
const SECTION_COUNT = 8;
@ -139,9 +142,22 @@ interface Chunk{
/**
* Thread-safe read-only chunk
*
* @param bool $includeMaxBlockY
* @param bool $includeBiome
* @param bool $includeBiomeTemp
*
* @return ChunkSnapshot
*/
public function getChunkSnapshot();
public function getChunkSnapshot($includeMaxBlockY = true, $includeBiome = false, $includeBiomeTemp = false);
public function addEntity(Entity $entity);
public function removeEntity(Entity $entity);
public function addTile(Tile $tile);
public function removeTile(Tile $tile);
/**
* @return \pocketmine\entity\Entity[]
@ -199,4 +215,9 @@ interface Chunk{
*/
public function setSection($fY, ChunkSection $section);
/**
* @return ChunkSection[]
*/
public function getSections();
}

View File

@ -131,4 +131,12 @@ interface ChunkSection{
*/
public function getBlockDataColumn($x, $z);
public function getIdArray();
public function getDataArray();
public function getSkyLightArray();
public function getLightArray();
}

View File

@ -90,28 +90,4 @@ interface ChunkSnapshot{
*/
public function getBiome($x, $z);
/**
* Tests whether a section (mini-chunk) is empty
*
* @param $fY 0-7, (Y / 16)
*
* @return bool
*/
public function isSectionEmpty($fY);
/**
* @param int $Y 0-7
*
* @return ChunkSection
*/
public function getSection($Y);
/**
* @param int $Y 0-7
* @param ChunkSection $section
*
* @return boolean
*/
public function setSection($Y, ChunkSection $section);
}

View File

@ -24,10 +24,7 @@ namespace pocketmine\level\format;
use pocketmine\math\Vector3;
use pocketmine\Server;
/**
* All Level formats must implement this interface
*/
interface LevelFormat{
interface LevelProvider{
/**
* @param Server $server
@ -35,6 +32,9 @@ interface LevelFormat{
*/
public function __construct(Server $server, $path);
/** @return string */
public function getPath();
/**
* Tells if the path is a valid level.
* This must tell if the current format supports opening the files in the directory
@ -53,7 +53,7 @@ interface LevelFormat{
* @param int $Z absolute Chunk Z value
* @param bool $create Whether to generate the chunk if it does not exist
*
* @return ChunkSnapshot
* @return Chunk
*/
public function getChunk($X, $Z, $create = false);
@ -68,17 +68,22 @@ interface LevelFormat{
public function unloadChunk($X, $Z);
public function isChunkLoaded($X, $Z);
public function isChunkGenerated($X, $Z);
public function getName();
/**
* @return Vector3
*/
public function getSpawn();
public function getName();
/**
* @param Vector3 $pos
*/
public function setSpawn(Vector3 $pos);
/**
* @return ChunkSnapshot
* @return Chunk
*/
public function getLoadedChunks();

View File

@ -21,9 +21,9 @@
namespace pocketmine\level\format\anvil;
use pocketmine\level\format\LevelFormat;
use pocketmine\level\format\generic\BaseLevelProvider;
class Anvil implements LevelFormat{
class Anvil extends BaseLevelProvider{
protected $basePath;
public function __construct($path, $levelName){

View File

@ -22,6 +22,7 @@
namespace pocketmine\level\format\anvil;
use pocketmine\level\format\generic\BaseChunk;
use pocketmine\level\format\generic\EmptyChunkSection;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Compound;
@ -72,4 +73,34 @@ class Chunk extends BaseChunk{
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $sections);
}
public function getChunkSnapshot($includeMaxBlockY = true, $includeBiome = false, $includeBiomeTemp = false){
$blockId = "";
$blockData = "";
$blockSkyLight = "";
$blockLight = "";
$emptySections = [false, false, false, false, false, false, false, false];
$emptyBlocks = str_repeat("\x00", 4096);
$emptyHalf = str_repeat("\x00", 2048);
foreach($this->sections as $i => $section){
if($section instanceof EmptyChunkSection){
$blockId .= $emptyBlocks;
$blockData .= $emptyHalf;
$blockSkyLight .= $emptyHalf;
$blockLight .= $emptyHalf;
$emptySections[$i] = true;
}else{
$blockId .= $section->getIdArray();
$blockData .= $section->getDataArray();
$blockSkyLight .= $section->getSkyLightArray();
$blockLight .= $section->getLightArray();
}
}
//TODO: maxBlockY, biomeMap, biomeTemp
return new ChunkSnapshot($this->getX(), $this->getZ(), $this->getLevel()->getName(), $this->getLevel()->getTime(), $blockId, $blockData, $blockSkyLight, $blockLight, $emptySections, null, null, null, null);
}
}

View File

@ -152,4 +152,20 @@ class ChunkSection implements \pocketmine\level\format\ChunkSection{
return $column;
}
public function getIdArray(){
return $this->blocks;
}
public function getDataArray(){
return $this->data;
}
public function getSkyLightArray(){
return $this->skyLight;
}
public function getLightArray(){
return $this->blockLight;
}
}

View File

@ -0,0 +1,78 @@
<?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/
*
*
*/
namespace pocketmine\level\format\anvil;
use pocketmine\level\format\generic\BaseChunkSnapshot;
class ChunkSnapshot extends BaseChunkSnapshot{
public function getBlockId($x, $y, $z){
return ord($this->blockId{
(($y >> 4) << 12) //get section index
+ ($y << 8) + ($z << 4) + $x //get block index in section
});
}
public function getBlockData($x, $y, $z){
$data = ord($this->blockData{
(($y >> 4) << 11) //get section index
+ ($y << 7) + ($z << 3) + ($x >> 1) //get block index in section
});
if(($y & 1) === 0){
return $data & 0x0F;
}else{
return $data >> 4;
}
}
public function getBlockSkyLight($x, $y, $z){
$level = ord($this->skyLight{
(($y >> 4) << 11) //get section index
+ ($y << 7) + ($z << 3) + ($x >> 1) //get block index in section
});
if(($y & 1) === 0){
return $level & 0x0F;
}else{
return $level >> 4;
}
}
public function getBlockLight($x, $y, $z){
$level = ord($this->light{
(($y >> 4) << 11) //get section index
+ ($y << 7) + ($z << 3) + ($x >> 1) //get block index in section
});
if(($y & 1) === 0){
return $level & 0x0F;
}else{
return $level >> 4;
}
}
public function getBiome(){
return 0; //TODO
}
public function getHighestBlockAt($x, $z){
return 127; //TODO
}
}

View File

@ -74,13 +74,29 @@ abstract class BaseChunk implements Chunk{
}
public function getBlock($x, $y, $z, &$blockId, &$meta = null){
$this->sections[$y >> 4]->getBlock($x, $y - ($y >> 4), $z, $blockId, $meta);
return $this->sections[$y >> 4]->getBlock($x, $y - ($y >> 4), $z, $blockId, $meta);
}
public function setBlock($x, $y, $z, $blockId = null, $meta = null){
$this->sections[$y >> 4]->setBlock($x, $y - ($y >> 4), $z, $blockId, $meta);
}
public function getBlockId($x, $y, $z){
return $this->sections[$y >> 4]->getBlockId($x, $y - ($y >> 4), $z);
}
public function setBlockId($x, $y, $z, $id){
$this->sections[$y >> 4]->setBlockId($x, $y - ($y >> 4), $z, $id);
}
public function getBlockData($x, $y, $z){
return $this->sections[$y >> 4]->getBlockData($x, $y - ($y >> 4), $z);
}
public function setBlockData($x, $y, $z, $data){
$this->sections[$y >> 4]->setBlockData($x, $y - ($y >> 4), $z, $data);
}
public function getBlockSkyLight($x, $y, $z){
return $this->sections[$y >> 4]->getBlockSkyLight($x, $y - ($y >> 4), $z);
}
@ -123,4 +139,9 @@ abstract class BaseChunk implements Chunk{
public function setSection($fY, ChunkSection $section){
$this->sections[(int) $fY] = $section;
}
public function getSections(){
return $this->sections;
}
}

View File

@ -0,0 +1,64 @@
<?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/
*
*
*/
namespace pocketmine\level\format\generic;
use pocketmine\level\format\ChunkSnapshot;
abstract class BaseChunkSnapshot implements ChunkSnapshot{
protected $blockId;
protected $blockData;
protected $skyLight;
protected $light;
protected $x;
protected $z;
protected $levelName;
protected $levelTime;
public function __construct($x, $z, $levelName, $levelTime, $blockId, $blockData, $skyLight, $light, $heightMap, $biome, $biomeTemp, $biomeRain){
$this->x = $x;
$this->z = $z;
$this->levelName = $levelName;
$this->levelTime = $levelTime;
$this->blockId = $blockId;
$this->blockData = $blockData;
$this->skyLight = $skyLight;
$this->light = $light;
}
public function getX(){
return $this->x;
}
public function getZ(){
return $this->z;
}
public function getLevelName(){
return $this->levelName;
}
public function getLevelTime(){
return $this->levelTime;
}
}

View File

@ -0,0 +1,36 @@
<?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/
*
*
*/
namespace pocketmine\level\format\generic;
use pocketmine\level\format\LevelProvider;
use pocketmine\Server;
abstract class BaseLevelProvider implements LevelProvider{
/** @var Server */
protected $server;
/** @var string */
protected $path;
public function __construct(Server $server, $path){
$this->server = $server;
$this->path = $path;
}
}

View File

@ -39,6 +39,22 @@ class EmptyChunkSection implements ChunkSection{
return "\x00\x00\x00\x00\x00\x00\x00\x00";
}
public function getIdArray(){
return str_repeat("\x00", 4096);
}
public function getDataArray(){
return str_repeat("\x00", 2048);
}
public function getSkyLightArray(){
return str_repeat("\x00", 2048);
}
public function getLightArray(){
return str_repeat("\x00", 2048);
}
final public function setBlockId($x, $y, $z, $id){
}