Improved Block selection and construction performance

This commit is contained in:
Shoghi Cervantes 2014-08-25 16:36:16 +02:00
parent 84c63c48ca
commit 049103ab7a
10 changed files with 56 additions and 64 deletions

View File

@ -21,25 +21,26 @@
namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
/**
* Air block
*/
class Air extends Transparent{
public $isActivable = false;
public $breakable = false;
public $isFlowable = true;
public $isTransparent = true;
public $isReplaceable = true;
public $isPlaceable = false;
public $hasPhysics = false;
public $isSolid = false;
public $isFullBlock = true;
protected $id = self::AIR;
protected $meta = 0;
protected $name = "Air";
protected $hardness = 0;
public function __construct(){
parent::__construct(self::AIR, 0, "Air");
$this->isActivable = false;
$this->breakable = false;
$this->isFlowable = true;
$this->isTransparent = true;
$this->isReplaceable = true;
$this->isPlaceable = false;
$this->hasPhysics = false;
$this->isSolid = false;
$this->isFullBlock = true;
$this->hardness = 0;
}

View File

@ -506,9 +506,9 @@ abstract class Block extends Position implements Metadatable{
public static $list = [];
protected $id;
protected $meta;
protected $name;
protected $breakTime;
protected $hardness;
protected $name = "Unknown";
protected $breakTime = 0.20;
protected $hardness = 10;
public $isActivable = false;
public $breakable = true;
public $isFlowable = false;
@ -698,8 +698,6 @@ abstract class Block extends Position implements Metadatable{
$this->id = (int) $id;
$this->meta = (int) $meta;
$this->name = $name;
$this->breakTime = 0.20;
$this->hardness = 10;
}
/**

View File

@ -25,10 +25,15 @@ use pocketmine\item\Item;
use pocketmine\Player;
class Dirt extends Solid{
public $isActivable = true;
protected $hardness = 2.5;
protected $id = self::DIRT;
protected $meta = 0;
protected $name = "Dirt";
public function __construct(){
parent::__construct(self::DIRT, 0, "Dirt");
$this->isActivable = true;
$this->hardness = 2.5;
}
public function onActivate(Item $item, Player $player = null){

View File

@ -26,10 +26,7 @@ use pocketmine\Player;
class Fallable extends Solid{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->hasPhysics = true;
}
public $hasPhysics = true;
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$ret = $this->getLevel()->setBlock($this, $this, true, false, true);

View File

@ -23,10 +23,9 @@ namespace pocketmine\block;
class Flowable extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isFlowable = true;
$this->isFullBlock = false;
$this->isSolid = false;
}
public $isFlowable = true;
public $isFullBlock = false;
public $isSolid = false;
}

View File

@ -27,15 +27,6 @@ use pocketmine\Player;
class Generic extends Block{
/**
* @param int $id
* @param int $meta
* @param string $name
*/
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
return $this->getLevel()->setBlock($this, $this, true, false, true);
}

View File

@ -29,10 +29,15 @@ use pocketmine\Player;
use pocketmine\utils\Random;
class Grass extends Solid{
public $isActivable = true;
protected $hardness = 3;
protected $id = self::GRASS;
protected $meta = 0;
protected $name = "Grass";
public function __construct(){
parent::__construct(self::GRASS, 0, "Grass");
$this->isActivable = true;
$this->hardness = 3;
}
public function getDrops(Item $item){

View File

@ -23,12 +23,9 @@ namespace pocketmine\block;
class Liquid extends Transparent{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isLiquid = true;
$this->breakable = false;
$this->isReplaceable = true;
$this->isSolid = false;
$this->isFullBlock = true;
}
public $isLiquid = true;
public $breakable = false;
public $isReplaceable = true;
public $isSolid = false;
public $isFullBlock = true;
}

View File

@ -32,8 +32,11 @@ class Stone extends Solid{
const ANDESITE = 5;
const POLISHED_ANDESITE = 6;
protected $hardness = 30;
protected $id = self::STONE;
public function __construct($meta = 0){
parent::__construct(self::STONE, $meta, "Stone");
$this->meta = $meta;
$names = [
self::NORMAL => "Stone",
self::GRANITE => "Granite",
@ -44,7 +47,6 @@ class Stone extends Solid{
self::POLISHED_ANDESITE => "Polished Andesite",
];
$this->name = $names[$this->meta & 0x07];
$this->hardness = 30;
}
public function getBreakTime(Item $item){

View File

@ -22,16 +22,13 @@
namespace pocketmine\block;
class Transparent extends Generic{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isActivable = false;
$this->breakable = true;
$this->isFlowable = false;
$this->isTransparent = true;
$this->isReplaceable = false;
$this->isPlaceable = true;
$this->isSolid = true;
}
class Transparent extends Generic{
public $isActivable = false;
public $breakable = true;
public $isFlowable = false;
public $isTransparent = true;
public $isReplaceable = false;
public $isPlaceable = true;
public $isSolid = true;
}