Slab placement

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-03 20:15:55 +01:00
parent d9c87161ba
commit fb9a0f2119
5 changed files with 43 additions and 5 deletions

View File

@ -531,19 +531,23 @@ class BlockAPI{
return false;
}
if($block->isReplaceable === true and $item->isPlaceable()){
if($item->isPlaceable()){
$hand = $item->getBlock();
}else{
return $this->cancelAction($block);
}
if(!($block->isReplaceable === true or ($hand->getID() === SLAB and $block->getID() === SLAB))){
return $this->cancelAction($block);
}
if($hand->isTransparent === false and $player->entity->inBlock($block->x, $block->y, $block->z)){
return $this->cancelAction($block); //Entity in block
}
//$direction = $player->entity->getDirection();
if($hand->place($this, $item, $player, $block, $target, $data["face"]) === false){
if($hand->place($this, $item, $player, $block, $target, $data["face"], $data["fx"], $data["fy"], $data["fz"]) === false){
return false;
}

View File

@ -77,7 +77,7 @@ abstract class Block{
);
}
abstract function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face);
abstract function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);
abstract function onActivate(BlockAPI $level, Item $item, Player $player);

View File

@ -30,7 +30,7 @@ class GenericBlock extends Block{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face){
public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($block->inWorld === true){
$level->setBlock($block, $this->id, $this->getMetadata());
return true;

View File

@ -43,7 +43,7 @@ class SaplingBlock extends TransparentBlock{
$this->name = $names[$this->meta & 0x03];
}
public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face){
public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($block->inWorld === true){
$down = $level->getBlockFace($block, 0);
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){

View File

@ -41,4 +41,38 @@ class SlabBlock extends TransparentBlock{
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
}
public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($block->inWorld === true){
$this->meta = $this->meta & 0x07;
if($face === 0){
if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$level->setBlock($target, DOUBLE_SLAB, $this->meta & 0x07);
return true;
}else{
$this->meta |= 0x08;
}
}elseif($face === 1){
if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$level->setBlock($target, DOUBLE_SLAB, $this->meta & 0x07);
return true;
}
}else{
if($block->getID() === SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$level->setBlock($block, DOUBLE_SLAB, $this->meta & 0x07);
return true;
}
return false;
}else{
if($fy > 0.5){
$this->meta |= 0x08;
}
}
}
$level->setBlock($block, $this->id, $this->meta);
return true;
}
return false;
}
}