Added new Block properties (Block::isSolid, Block::isFullBlock)

This commit is contained in:
Shoghi Cervantes 2013-05-30 12:47:24 +02:00
parent 8d00ef381d
commit a795b64bab
36 changed files with 57 additions and 32 deletions

View File

@ -337,7 +337,7 @@ class BlockAPI{
return $this->cancelAction($block, $player);
}
if($hand->isFlowable === false and $player->entity->inBlock($block)){
if($hand->isSolid === true and $player->entity->inBlock($block)){
return $this->cancelAction($block, $player); //Entity in block
}

View File

@ -140,12 +140,14 @@ abstract class Block extends Position{
public $isActivable = false;
public $breakable = true;
public $isFlowable = false;
public $isSolid = true;
public $isTransparent = false;
public $isReplaceable = false;
public $isPlaceable = true;
public $level = false;
public $hasPhysics = false;
public $isLiquid = false;
public $isFullBlock = true;
public $x = 0;
public $y = 0;
public $z = 0;

View File

@ -28,6 +28,8 @@ the Free Software Foundation, either version 3 of the License, or
class DoorBlock extends TransparentBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isSolid = false;
$this->isFullBlock = false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View File

@ -29,5 +29,7 @@ class FlowableBlock extends TransparentBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isFlowable = true;
$this->isFullBlock = false;
$this->isSolid = false;
}
}

View File

@ -31,5 +31,7 @@ class LiquidBlock extends TransparentBlock{
$this->isLiquid = true;
$this->breakable = false;
$this->isReplaceable = true;
$this->isSolid = false;
$this->isFullBlock = true;
}
}

View File

@ -28,5 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class SolidBlock extends GenericBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isSolid = true;
$this->isFullBlock = true;
}
}

View File

@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class StairBlock extends TransparentBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
$this->isFullBlock = false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View File

@ -33,6 +33,7 @@ class TransparentBlock extends GenericBlock{
$this->isFlowable = false;
$this->isTransparent = true;
$this->isReplaceable = false;
$this->isPlaceable = true;
$this->isPlaceable = true;
$this->isSolid = true;
}
}

View File

@ -28,6 +28,8 @@ the Free Software Foundation, either version 3 of the License, or
class LadderBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(LADDER, $meta, "Ladder");
$this->isSolid = false;
$this->isFullBlock = false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->isTransparent === false){

View File

@ -28,6 +28,8 @@ the Free Software Foundation, either version 3 of the License, or
class SignPostBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(SIGN_POST, $meta, "Sign Post");
$this->isSolid = false;
$this->isFullBlock = false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View File

@ -43,7 +43,7 @@ class TorchBlock extends FlowableBlock{
0 => 0,
);
if($this->getSide($faces[$side])->isFlowable === true){ //Replace wit common break method
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -29,6 +29,7 @@ class TrapdoorBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(TRAPDOOR, $meta, "Trapdoor");
$this->isActivable = true;
$this->isFullBlock = false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if(($target->isTransparent === false or $target->getID() === SLAB) and $face !== 0 and $face !== 1){

View File

@ -35,6 +35,9 @@ class AirBlock extends TransparentBlock{
$this->isReplaceable = true;
$this->isPlaceable = false;
$this->hasPhysics = false;
$this->isSolid = false;
$this->isFullBlock = true;
}
}

View File

@ -29,6 +29,7 @@ class BedBlock extends TransparentBlock{
public function __construct($type = 0){
parent::__construct(BED_BLOCK, $type, "Bed Block");
$this->isActivable = true;
$this->isFullBlock = false;
}
public function onActivate(Item $item, Player $player){

View File

@ -30,6 +30,8 @@ class FireBlock extends FlowableBlock{
parent::__construct(FIRE, $meta, "Fire");
$this->isReplaceable = true;
$this->breakable = false;
$this->isFullBlock = true;
}
}

View File

@ -28,12 +28,11 @@ the Free Software Foundation, either version 3 of the License, or
class BrownMushroomBlock extends FlowableBlock{
public function __construct(){
parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom");
$this->isFlowable = true;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class CactusBlock extends TransparentBlock{
public function __construct(){
parent::__construct(CACTUS, 0, "Cactus");
$this->isFullBlock = false;
}
public function onUpdate($type){
@ -49,7 +50,7 @@ class CactusBlock extends TransparentBlock{
$block1 = $this->getSide(3);
$block2 = $this->getSide(4);
$block3 = $this->getSide(5);
if($block0->isFlowable === true and $block1->isFlowable === true and $block2->isFlowable === true and $block3->isFlowable === true){
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
$this->level->setBlock($block, $this);
return true;
}

View File

@ -28,7 +28,6 @@ the Free Software Foundation, either version 3 of the License, or
class CyanFlowerBlock extends FlowableBlock{
public function __construct(){
parent::__construct(CYAN_FLOWER, 0, "Cyan Flower");
$this->isFlowable = true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
@ -42,7 +41,7 @@ class CyanFlowerBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -28,7 +28,6 @@ the Free Software Foundation, either version 3 of the License, or
class DandelionBlock extends FlowableBlock{
public function __construct(){
parent::__construct(DANDELION, 0, "Dandelion");
$this->isFlowable = true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
@ -42,7 +41,7 @@ class DandelionBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -28,13 +28,12 @@ the Free Software Foundation, either version 3 of the License, or
class DeadBushBlock extends FlowableBlock{
public function __construct(){
parent::__construct(DEAD_BUSH, 0, "Dead Bush");
$this->isFlowable = true;
$this->isReplaceable = true;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;
}

View File

@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
*/
class MelonStemBlock extends TransparentBlock{
class MelonStemBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(MELON_STEM, $meta, "Melon Stem");
$this->isActivable = true;
@ -41,7 +41,7 @@ class MelonStemBlock extends TransparentBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -28,12 +28,11 @@ the Free Software Foundation, either version 3 of the License, or
class RedMushroomBlock extends FlowableBlock{
public function __construct(){
parent::__construct(RED_MUSHROOM, 0, "Red Mushroom");
$this->isFlowable = true;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
*/
class SaplingBlock extends TransparentBlock{
class SaplingBlock extends FlowableBlock{
const OAK = 0;
const SPRUCE = 1;
const BIRCH = 2;
@ -34,7 +34,6 @@ class SaplingBlock extends TransparentBlock{
public function __construct($meta = Sapling::OAK){
parent::__construct(SAPLING, $meta, "Sapling");
$this->isActivable = true;
$this->isFlowable = true;
$names = array(
0 => "Oak Sapling",
1 => "Spruce Sapling",
@ -61,7 +60,7 @@ class SaplingBlock extends TransparentBlock{
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
*/
class SugarcaneBlock extends TransparentBlock{
class SugarcaneBlock extends FlowableBlock{
public function __construct(){
parent::__construct(SUGARCANE_BLOCK, 0, "Sugarcane");
}
@ -38,7 +38,7 @@ class SugarcaneBlock extends TransparentBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -28,7 +28,6 @@ the Free Software Foundation, either version 3 of the License, or
class TallGrassBlock extends FlowableBlock{
public function __construct($meta = 1){
parent::__construct(TALL_GRASS, $meta, "Tall Grass");
$this->isFlowable = true;
$this->isReplaceable = true;
$names = array(
0 => "Dead Shrub",
@ -40,7 +39,7 @@ class TallGrassBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;
}

View File

@ -51,7 +51,7 @@ class WheatBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isFlowable === true){ //Replace wit common break method
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;

View File

@ -25,7 +25,6 @@ the Free Software Foundation, either version 3 of the License, or
*/
class BurningFurnaceBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(BURNING_FURNACE, $meta, "Burning Furnace");

View File

@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class CakeBlock extends TransparentBlock{
public function __construct(){
parent::__construct(CAKE_BLOCK, 0, "Cake Block");
$this->isFullBlock = false;
}
}

View File

@ -25,9 +25,11 @@ the Free Software Foundation, either version 3 of the License, or
*/
class CobwebBlock extends TransparentBlock{
class CobwebBlock extends FlowableBlock{
public function __construct(){
parent::__construct(COBWEB, 0, "Cobweb");
parent::__construct(COBWEB, 0, "Cobweb");
$this->isSolid = true;
$this->isFullBlock = false;
}
public function getDrops(Item $item, Player $player){
return array();

View File

@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class FenceBlock extends TransparentBlock{
public function __construct(){
parent::__construct(FENCE, 0, "Fence");
$this->isFullBlock = false;
}
}

View File

@ -29,6 +29,7 @@ class FenceGateBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(FENCE_GATE, $meta, "Fence Gate");
$this->isActivable = true;
$this->isFullBlock = false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(

View File

@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class GlassPaneBlock extends TransparentBlock{
public function __construct(){
parent::__construct(GLASS_PANE, 0, "Glass Pane");
$this->isFullBlock = false;
}
}

View File

@ -38,7 +38,8 @@ class SlabBlock extends TransparentBlock{
6 => "Nether Brick",
7 => "Quartz",
);
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
$this->isFullBlock = false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View File

@ -29,6 +29,7 @@ class SnowLayerBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(SNOW_LAYER, $meta, "Snow Layer");
$this->isReplaceable = true;
$this->isSolid = false;
}
}

View File

@ -32,7 +32,7 @@ class PaintingItem 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->isFlowable === true){
if($target->isTransparent === false and $face > 1 and $block->isSolid === false){
$server = ServerAPI::request();
$faces = array(
2 => 1,

View File

@ -352,7 +352,7 @@ class Entity extends Position{
$v = new Vector3($x, $y, $z);
if($this->isSupport($v, $this->size)){
$b = $this->level->getBlock($v);
if($b->isFlowable !== true){
if($b->isSolid === true){
$support = true;
break;
}
@ -383,7 +383,7 @@ class Entity extends Position{
$z = (int) ($this->z - 0.5);
$lim = (int) floor($ny);
for($y = (int) ceil($this->y) - 1; $y >= $lim; --$y){
if($this->level->getBlock(new Vector3($x, $y, $z))->isFlowable !== true){
if($this->level->getBlock(new Vector3($x, $y, $z))->isSolid === true){
$ny = $y + 1;
$this->speedY = 0;
$this->support = true;
@ -406,7 +406,8 @@ class Entity extends Position{
}
if($this->class === ENTITY_FALLING){
$fall = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y)), intval($this->z - 0.5)));
if($fall->getID() !== AIR and $fall->isFlowable){
$down = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y)), intval($this->z - 0.5)));
if($fall->isFullBlock === false or $down->isFullBlock === false){
$this->server->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"] & 0xFFFF, 0, 1), true);
}else{
$this->level->setBlock($fall, BlockAPI::get($this->data["Tile"]));