Fixed slab placement, close #145

This commit is contained in:
Dylan K. Taylor 2017-07-15 17:49:21 +01:00
parent c394aea803
commit f2ff0198cc
9 changed files with 21 additions and 18 deletions

View File

@ -54,7 +54,7 @@ class Air extends Transparent{
return true;
}
public function canBeReplaced() : bool{
public function canBeReplaced(Block $with = null) : bool{
return true;
}

View File

@ -597,9 +597,11 @@ class Block extends Position implements BlockIds, Metadatable{
}
/**
* @param Block|null $with
*
* @return bool
*/
public function canBeReplaced() : bool{
public function canBeReplaced(Block $with = null) : bool{
return false;
}

View File

@ -37,7 +37,7 @@ class DoublePlant extends Flowable{
$this->meta = $meta;
}
public function canBeReplaced() : bool{
public function canBeReplaced(Block $with = null) : bool{
return $this->meta === 2 or $this->meta === 3; //grass or fern
}

View File

@ -57,7 +57,7 @@ class Fire extends Flowable{
return false;
}
public function canBeReplaced() : bool{
public function canBeReplaced(Block $with = null) : bool{
return true;
}

View File

@ -41,7 +41,7 @@ abstract class Liquid extends Transparent{
return false;
}
public function canBeReplaced() : bool{
public function canBeReplaced(Block $with = null) : bool{
return true;
}

View File

@ -41,7 +41,7 @@ class SnowLayer extends Flowable{
return "Snow Layer";
}
public function canBeReplaced() : bool{
public function canBeReplaced(Block $with = null) : bool{
return true;
}

View File

@ -36,7 +36,7 @@ class TallGrass extends Flowable{
$this->meta = $meta;
}
public function canBeReplaced() : bool{
public function canBeReplaced(Block $with = null) : bool{
return true;
}

View File

@ -78,6 +78,10 @@ class WoodenSlab extends Transparent{
}
}
public function canBeReplaced(Block $with = null) : bool{
return $with !== null and $with->getId() === $this->getId() and ($with->getDamage() & 0x07) === ($this->getDamage() & 0x07);
}
public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{
$this->meta &= 0x07;
if($face === Vector3::SIDE_DOWN){

View File

@ -1777,23 +1777,20 @@ class Level implements ChunkManager, Metadatable{
return true;
}
if($item->canBePlaced()){
$hand = $item->getBlock();
$hand->position($block);
}else{
if(!$item->canBePlaced()){
return false;
}
if(!($block->canBeReplaced() === true or ($hand->getId() === Item::WOODEN_SLAB and $block->getId() === Item::WOODEN_SLAB) or ($hand->getId() === Item::STONE_SLAB and $block->getId() === Item::STONE_SLAB))){
return false;
}
$hand = $item->getBlock();
if($target->canBeReplaced() === true){
if($target->canBeReplaced($hand)){
$block = $target;
$hand->position($block);
//$face = -1;
}elseif(!$block->canBeReplaced($hand)){
return false;
}
$hand->position($block);
if($hand->isSolid() === true and $hand->getBoundingBox() !== null){
$entities = $this->getCollidingEntities($hand->getBoundingBox());
$realCount = 0;
@ -1834,7 +1831,7 @@ class Level implements ChunkManager, Metadatable{
}
}
if($hand->place($item, $block, $target, $face, $facePos, $player) === false){
if(!$hand->place($item, $block, $target, $face, $facePos, $player)){
return false;
}