Block creating and property handling rewrite, part2

This commit is contained in:
Shoghi Cervantes 2014-12-07 02:20:26 +01:00
parent a0d4bff385
commit af82d616c1
31 changed files with 45 additions and 46 deletions

View File

@ -109,7 +109,7 @@ class Bed extends Transparent{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->isTransparent === false){
if($down->isTransparent() === false){
$faces = [
0 => 3,
1 => 4,
@ -119,7 +119,7 @@ class Bed extends Transparent{
$d = $player instanceof Player ? $player->getDirection() : 0;
$next = $this->getSide($faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){
if($next->canBeReplaced() === true and $downNext->isTransparent() === false){
$meta = (($d + 3) % 4) & 0x03;
$this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, true);
$this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x08), true, true);

View File

@ -554,7 +554,6 @@ class Block extends Position implements Metadatable{
*/
public function __get($key){
static $map = [
"breakTime" => "getBreakTime",
"hardness" => "getHardness",
"lightLevel" => "getLightLevel",
"frictionFactor" => "getFrictionFactor",
@ -885,7 +884,7 @@ class Block extends Position implements Metadatable{
}
/**
* AKA: Block->isReplaceable
* AKA: Block->canBeReplaced()
*
* @return bool
*/
@ -955,7 +954,7 @@ class Block extends Position implements Metadatable{
* @param int $meta
*/
final public function setDamage($meta){
$this->meta = $meta & 0x0F;
$this->meta = $meta & 0x0f;
}
/**

View File

@ -43,7 +43,7 @@ class BrownMushroom extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){
if($this->getSide(0)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
@ -55,7 +55,7 @@ class BrownMushroom extends Flowable{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->isTransparent === false){
if($down->isTransparent() === false){
$this->getLevel()->setBlock($block, $this, true, true);
return true;

View File

@ -113,7 +113,7 @@ class Cactus extends Transparent{
$block1 = $this->getSide(3);
$block2 = $this->getSide(4);
$block3 = $this->getSide(5);
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
if($block0->isTransparent() === true and $block1->isTransparent() === true and $block2->isTransparent() === true and $block3->isTransparent() === true){
$this->getLevel()->setBlock($this, $this, true);
return true;

View File

@ -33,7 +33,7 @@ class Cake extends Transparent{
protected $id = self::CAKE_BLOCK;
public function __construct($meta = 0){
$this->meta = $meta & 0x07;
$this->meta = $meta;
}
public function canBeActivated(){

View File

@ -57,7 +57,7 @@ class Carpet extends Flowable{
14 => "Red Carpet",
15 => "Black Carpet",
];
return $names[$this->meta];
return $names[$this->meta & 0x0f];
}
protected function recalculateBoundingBox(){

View File

@ -122,7 +122,7 @@ class Chest extends Transparent{
public function onActivate(Item $item, Player $player = null){
if($player instanceof Player){
$top = $this->getSide(1);
if($top->isTransparent !== true){
if($top->isTransparent() !== true){
return true;
}

View File

@ -69,7 +69,7 @@ abstract class Crops extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){
if($this->getSide(0)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}

View File

@ -222,7 +222,7 @@ abstract class Door extends Transparent{
if($face === 1){
$blockUp = $this->getSide(1);
$blockDown = $this->getSide(0);
if($blockUp->isReplaceable === false or $blockDown->isTransparent === true){
if($blockUp->canBeReplaced() === false or $blockDown->isTransparent() === true){
return false;
}
$direction = $player instanceof Player ? $player->getDirection() : 0;
@ -235,7 +235,7 @@ abstract class Door extends Transparent{
$next = $this->getSide($face[(($direction + 2) % 4)]);
$next2 = $this->getSide($face[$direction]);
$metaUp = 0x08;
if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge
if($next->getID() === $this->id or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge
$metaUp |= 0x01;
}

View File

@ -62,7 +62,7 @@ class Fence extends Transparent{
}
public function canConnect(Block $block){
return (!($block instanceof Fence) and !($block instanceof FenceGate)) ? $block->isSolid : true;
return (!($block instanceof Fence) and !($block instanceof FenceGate)) ? $block->isSolid() : true;
}
}

View File

@ -103,7 +103,7 @@ class Ladder extends Transparent{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
if($target->isTransparent === false){
if($target->isTransparent() === false){
$faces = [
2 => 2,
3 => 3,

View File

@ -210,7 +210,7 @@ abstract class Liquid extends Transparent{
if($this->adjacentSources >= 2 and $this instanceof Water){
$bottomBlock = $this->getSide(0);
if($bottomBlock->isSolid){
if($bottomBlock->isSolid()){
$k = 0;
}elseif($bottomBlock instanceof Water and $bottomBlock->getDamage() === 0){
$k = 0;

View File

@ -40,7 +40,7 @@ class MelonStem extends Crops{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){
if($this->getSide(0)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}

View File

@ -51,7 +51,7 @@ class Poppy extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){
if($this->getSide(0)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;

View File

@ -40,7 +40,7 @@ class PumpkinStem extends Crops{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){
if($this->getSide(0)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}

View File

@ -40,7 +40,7 @@ class RedMushroom extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){
if($this->getSide(0)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
@ -52,7 +52,7 @@ class RedMushroom extends Flowable{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0);
if($down->isTransparent === false){
if($down->isTransparent() === false){
$this->getLevel()->setBlock($block, $this, true, true);
return true;

View File

@ -27,7 +27,7 @@ class Sand extends Fallable{
protected $id = self::SAND;
public function __construct($meta = 0){
$this->meta = $meta & 0x01;
$this->meta = $meta;
}
public function getHardness(){

View File

@ -87,7 +87,7 @@ class Sapling extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){
if($this->getSide(0)->isTransparent() === true){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;

View File

@ -54,7 +54,7 @@ class StainedClay extends Solid{
14 => "Red Stained Clay",
15 => "Black Stained Clay",
];
return $names[$this->meta];
return $names[$this->meta & 0x0f];
}
public function getBreakTime(Item $item){

View File

@ -79,7 +79,7 @@ class StoneWall extends Transparent{
}
public function canConnect(Block $block){
return ($block->getID() !== self::COBBLE_WALL and $block->getID() !== self::FENCE_GATE) ? $block->isSolid : true;
return ($block->getID() !== self::COBBLE_WALL and $block->getID() !== self::FENCE_GATE) ? $block->isSolid() : true;
}
}

View File

@ -76,7 +76,7 @@ class Sugarcane extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->isTransparent === true and $down->getID() !== self::SUGARCANE_BLOCK){
if($down->isTransparent() === true and $down->getID() !== self::SUGARCANE_BLOCK){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;

View File

@ -49,7 +49,7 @@ class TallGrass extends Flowable{
public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
if($this->getSide(0)->isTransparent() === true){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), false, false, true);
return Level::BLOCK_UPDATE_NORMAL;

View File

@ -76,7 +76,7 @@ abstract class Thin extends Transparent{
public function canConnect(Block $block){
return $block->isSolid or $block->getID() === $this->getID() or $block->getID() === self::GLASS_PANE or $block->getID() === self::GLASS;
return $block->isSolid() or $block->getID() === $this->getID() or $block->getID() === self::GLASS_PANE or $block->getID() === self::GLASS;
}
}

View File

@ -55,7 +55,7 @@ class Torch extends Flowable{
0 => 0,
];
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === self::FENCE)){
if($this->getSide($faces[$side])->isTransparent()=== true and !($side === 0 and $this->getSide(0)->getID() === self::FENCE)){
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
@ -66,7 +66,7 @@ class Torch extends Flowable{
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
if($target->isTransparent === false and $face !== 0){
if($target->isTransparent() === false and $face !== 0){
$faces = [
1 => 5,
2 => 4,
@ -78,7 +78,7 @@ class Torch extends Flowable{
$this->getLevel()->setBlock($block, $this, true, true);
return true;
}elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === self::FENCE){
}elseif($this->getSide(0)->isTransparent() === false or $this->getSide(0)->getID() === self::FENCE){
$this->meta = 0;
$this->getLevel()->setBlock($block, $this, true, true);

View File

@ -115,7 +115,7 @@ class Trapdoor extends Transparent{
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
if(($target->isTransparent === false or $target->getID() === self::SLAB) and $face !== 0 and $face !== 1){
if(($target->isTransparent() === false or $target->getID() === self::SLAB) and $face !== 0 and $face !== 1){
$faces = [
2 => 0,
3 => 1,

View File

@ -97,7 +97,7 @@ class Vine extends Transparent{
$flag = true;
}
if(!$flag and $this->getSide(1)->isSolid){
if(!$flag and $this->getSide(1)->isSolid()){
$f2 = min($f2, 0.9375);
$f5 = 1;
$f1 = 0;
@ -118,7 +118,7 @@ class Vine extends Transparent{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
if($target->isSolid){
if($target->isSolid()){
$faces = [
0 => 0,
1 => 0,

View File

@ -53,7 +53,7 @@ class Wool extends Solid{
14 => "Red Wool",
15 => "Black Wool",
];
return $names[$this->meta];
return $names[$this->meta & 0x0f];
}
}

View File

@ -809,7 +809,7 @@ abstract class Entity extends Location implements Metadatable{
$bb = $block->getBoundingBox();
if($bb !== null and $block->isSolid and !$block->isTransparent and $bb->intersectsWith($this->getBoundingBox())){
if($bb !== null and $block->isSolid() and !$block->isTransparent() and $bb->intersectsWith($this->getBoundingBox())){
return true;
}
return false;
@ -1053,7 +1053,7 @@ abstract class Entity extends Location implements Metadatable{
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
for($v->y = $minY; $v->y <= $maxY; ++$v->y){
$block = $this->level->getBlock($v);
if($block !== null and $block->hasEntityCollision){
if($block !== null and $block->hasEntityCollision()){
$block->onEntityCollide($this);
if(!($this instanceof Player)){
$block->addVelocityToEntity($this, $vector);

View File

@ -98,7 +98,7 @@ class Item extends Entity{
$friction = 1 - $this->drag;
if($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)){
$friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction;
$friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->getFrictionFactor() * $friction;
}
$this->motionX *= $friction;

View File

@ -33,7 +33,7 @@ class Painting extends Item{
}
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->isTransparent === false and $face > 1 and $block->isSolid === false){
if($target->isTransparent() === false and $face > 1 and $block->isSolid() === false){
$faces = [
2 => 1,
3 => 3,

View File

@ -1293,17 +1293,17 @@ class Level implements ChunkManager, Metadatable{
return false;
}
if(!($block->isReplaceable === true or ($hand->getID() === Item::SLAB and $block->getID() === Item::SLAB))){
if(!($block->canBeReplaced() === true or ($hand->getID() === Item::SLAB and $block->getID() === Item::SLAB))){
return false;
}
if($target->isReplaceable === true){
if($target->canBeReplaced() === true){
$block = $target;
$hand->position($block);
//$face = -1;
}
if($hand->isSolid === true and $hand->getBoundingBox() !== null){
if($hand->isSolid() === true and $hand->getBoundingBox() !== null){
$entities = $this->getCollidingEntities($hand->getBoundingBox());
$realCount = 0;
foreach($entities as $e){
@ -2052,14 +2052,14 @@ class Level implements ChunkManager, Metadatable{
$b = $this->getBlock($v);
if($b === null){
return $spawn;
}elseif($b->isSolid){
}elseif($b->isSolid()){
$v->y++;
break;
}
}
for(; $v->y < 128; ++$v->y){
if(!$this->getBlock($v->getSide(1))->isSolid){
if(!$this->getBlock($v)->isSolid){
if(!$this->getBlock($v->getSide(1))->isSolid()){
if(!$this->getBlock($v)->isSolid()){
return new Position($spawn->x, $v->y === Math::floorFloat($spawn->y) ? $spawn->y : $v->y, $spawn->z, $this);
}
}else{