mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-14 15:35:31 +00:00
Block: introduce new methods to reduce support type boilerplate checks
this switches from a 'can be supported by' concept to a 'can stay at this position' paradigm, which requires way less boilerplate code. there may be further improvements we can make from here, such as adding traits, but this is a good first step.
This commit is contained in:
parent
3c34841dfc
commit
5899f2fc1d
@ -38,7 +38,7 @@ use function in_array;
|
|||||||
abstract class BaseRail extends Flowable{
|
abstract class BaseRail extends Flowable{
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($blockReplace->getSide(Facing::DOWN)->getSupportType(Facing::UP)->hasEdgeSupport()){
|
if($blockReplace->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport()){
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ abstract class BaseRail extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
if(!$this->getSide(Facing::DOWN)->getSupportType(Facing::UP)->hasEdgeSupport()){
|
if(!$this->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport()){
|
||||||
$world->useBreakOn($this->position);
|
$world->useBreakOn($this->position);
|
||||||
}else{
|
}else{
|
||||||
foreach($this->getCurrentShapeConnections() as $connection){
|
foreach($this->getCurrentShapeConnections() as $connection){
|
||||||
|
@ -177,11 +177,11 @@ class Bed extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if($this->canBeSupportedAt($blockReplace)){
|
||||||
$this->facing = $player !== null ? $player->getHorizontalFacing() : Facing::NORTH;
|
$this->facing = $player !== null ? $player->getHorizontalFacing() : Facing::NORTH;
|
||||||
|
|
||||||
$next = $this->getSide($this->getOtherHalfSide());
|
$next = $this->getSide($this->getOtherHalfSide());
|
||||||
if($next->canBeReplaced() && $this->canBeSupportedBy($next->getSide(Facing::DOWN))){
|
if($next->canBeReplaced() && $this->canBeSupportedAt($next)){
|
||||||
$nextState = clone $this;
|
$nextState = clone $this;
|
||||||
$nextState->head = true;
|
$nextState->head = true;
|
||||||
$tx->addBlock($blockReplace->position, $this)->addBlock($next->position, $nextState);
|
$tx->addBlock($blockReplace->position, $this)->addBlock($next->position, $nextState);
|
||||||
@ -208,8 +208,8 @@ class Bed extends Transparent{
|
|||||||
return parent::getAffectedBlocks();
|
return parent::getAffectedBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return !$block->getSupportType(Facing::UP)->equals(SupportType::NONE());
|
return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMaxStackSize() : int{ return 1; }
|
public function getMaxStackSize() : int{ return 1; }
|
||||||
|
@ -87,13 +87,13 @@ final class Bell extends Transparent{
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block, int $face) : bool{
|
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||||
return !$block->getSupportType($face)->equals(SupportType::NONE());
|
return !$block->getAdjacentSupportType($face)->equals(SupportType::NONE());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($face === Facing::UP){
|
if($face === Facing::UP){
|
||||||
if(!$this->canBeSupportedBy($tx->fetchBlock($this->position->down()), Facing::UP)){
|
if(!$this->canBeSupportedAt($blockReplace, Facing::DOWN)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
@ -101,18 +101,18 @@ final class Bell extends Transparent{
|
|||||||
}
|
}
|
||||||
$this->setAttachmentType(BellAttachmentType::FLOOR());
|
$this->setAttachmentType(BellAttachmentType::FLOOR());
|
||||||
}elseif($face === Facing::DOWN){
|
}elseif($face === Facing::DOWN){
|
||||||
if(!$this->canBeSupportedBy($tx->fetchBlock($this->position->up()), Facing::DOWN)){
|
if(!$this->canBeSupportedAt($blockReplace, Facing::UP)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->setAttachmentType(BellAttachmentType::CEILING());
|
$this->setAttachmentType(BellAttachmentType::CEILING());
|
||||||
}else{
|
}else{
|
||||||
$this->setFacing($face);
|
$this->setFacing($face);
|
||||||
if($this->canBeSupportedBy($tx->fetchBlock($this->position->getSide(Facing::opposite($face))), $face)){
|
if($this->canBeSupportedAt($blockReplace, Facing::opposite($face))){
|
||||||
$this->setAttachmentType(BellAttachmentType::ONE_WALL());
|
$this->setAttachmentType(BellAttachmentType::ONE_WALL());
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($this->canBeSupportedBy($tx->fetchBlock($this->position->getSide($face)), Facing::opposite($face))){
|
if($this->canBeSupportedAt($blockReplace, $face)){
|
||||||
$this->setAttachmentType(BellAttachmentType::TWO_WALLS());
|
$this->setAttachmentType(BellAttachmentType::TWO_WALLS());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,10 +121,10 @@ final class Bell extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(
|
if(
|
||||||
($this->attachmentType->equals(BellAttachmentType::CEILING()) && !$this->canBeSupportedBy($this->getSide(Facing::UP), Facing::DOWN)) ||
|
($this->attachmentType->equals(BellAttachmentType::CEILING()) && !$this->canBeSupportedAt($this, Facing::UP)) ||
|
||||||
($this->attachmentType->equals(BellAttachmentType::FLOOR()) && !$this->canBeSupportedBy($this->getSide(Facing::DOWN), Facing::UP)) ||
|
($this->attachmentType->equals(BellAttachmentType::FLOOR()) && !$this->canBeSupportedAt($this, Facing::DOWN)) ||
|
||||||
($this->attachmentType->equals(BellAttachmentType::ONE_WALL()) && !$this->canBeSupportedBy($this->getSide(Facing::opposite($this->facing)), $this->facing)) ||
|
($this->attachmentType->equals(BellAttachmentType::ONE_WALL()) && !$this->canBeSupportedAt($this, Facing::opposite($this->facing))) ||
|
||||||
($this->attachmentType->equals(BellAttachmentType::TWO_WALLS()) && (!$this->canBeSupportedBy($this->getSide($this->facing), Facing::opposite($this->facing)) || !$this->canBeSupportedBy($this->getSide(Facing::opposite($this->facing)), $this->facing)))
|
($this->attachmentType->equals(BellAttachmentType::TWO_WALLS()) && (!$this->canBeSupportedAt($this, $this->facing) || !$this->canBeSupportedAt($this, Facing::opposite($this->facing))))
|
||||||
){
|
){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ use pocketmine\item\Item;
|
|||||||
use pocketmine\item\ItemBlock;
|
use pocketmine\item\ItemBlock;
|
||||||
use pocketmine\math\Axis;
|
use pocketmine\math\Axis;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\RayTraceResult;
|
use pocketmine\math\RayTraceResult;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
@ -863,6 +864,10 @@ class Block{
|
|||||||
return SupportType::FULL();
|
return SupportType::FULL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getAdjacentSupportType(int $facing) : SupportType{
|
||||||
|
return $this->getSide($facing)->getSupportType(Facing::opposite($facing));
|
||||||
|
}
|
||||||
|
|
||||||
public function isFullCube() : bool{
|
public function isFullCube() : bool{
|
||||||
$bb = $this->getCollisionBoxes();
|
$bb = $this->getCollisionBoxes();
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ abstract class Button extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedBy($blockReplace->getSide(Facing::opposite($face)), $face)){
|
if($this->canBeSupportedAt($blockReplace, $face)){
|
||||||
$this->facing = $face;
|
$this->facing = $face;
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
@ -83,12 +83,12 @@ abstract class Button extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::opposite($this->facing)), $this->facing)){
|
if(!$this->canBeSupportedAt($this, $this->facing)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $support, int $face) : bool{
|
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||||
return $support->getSupportType($face)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::opposite($face))->hasCenterSupport();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,8 +104,7 @@ class Candle extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$down = $blockReplace->getSide(Facing::DOWN);
|
if(!$blockReplace->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport()){
|
||||||
if(!$down->getSupportType(Facing::UP)->hasCenterSupport()){
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$existing = $this->getCandleIfCompatibleType($blockReplace);
|
$existing = $this->getCandleIfCompatibleType($blockReplace);
|
||||||
|
@ -87,18 +87,18 @@ class CaveVines extends Flowable{
|
|||||||
return $this->berries ? 14 : 0;
|
return $this->berries ? 14 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getSupportType(Facing::DOWN)->equals(SupportType::FULL()) || $block->hasSameTypeId($this);
|
return $block->getAdjacentSupportType(Facing::UP)->equals(SupportType::FULL()) || $block->hasSameTypeId($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::UP))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::UP))){
|
if(!$this->canBeSupportedAt($blockReplace)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->age = mt_rand(0, self::MAX_AGE);
|
$this->age = mt_rand(0, self::MAX_AGE);
|
||||||
|
@ -32,7 +32,7 @@ use pocketmine\world\BlockTransaction;
|
|||||||
final class Coral extends BaseCoral{
|
final class Coral extends BaseCoral{
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($tx->fetchBlock($blockReplace->getPosition()->down()))){
|
if(!$this->canBeSupportedAt($blockReplace)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
@ -40,14 +40,14 @@ final class Coral extends BaseCoral{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
if(!$this->canBeSupportedBy($world->getBlock($this->position->down()))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$world->useBreakOn($this->position);
|
$world->useBreakOn($this->position);
|
||||||
}else{
|
}else{
|
||||||
parent::onNearbyBlockChange();
|
parent::onNearbyBlockChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getSupportType(Facing::UP)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ class Door extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN)) && !$this->getSide(Facing::DOWN) instanceof Door){ //Replace with common break method
|
if(!$this->canBeSupportedAt($this) && !$this->getSide(Facing::DOWN) instanceof Door){ //Replace with common break method
|
||||||
$this->position->getWorld()->useBreakOn($this->position); //this will delete both halves if they exist
|
$this->position->getWorld()->useBreakOn($this->position); //this will delete both halves if they exist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,8 +114,7 @@ class Door extends Transparent{
|
|||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($face === Facing::UP){
|
if($face === Facing::UP){
|
||||||
$blockUp = $this->getSide(Facing::UP);
|
$blockUp = $this->getSide(Facing::UP);
|
||||||
$blockDown = $this->getSide(Facing::DOWN);
|
if(!$blockUp->canBeReplaced() || !$this->canBeSupportedAt($blockReplace)){
|
||||||
if(!$blockUp->canBeReplaced() || !$this->canBeSupportedBy($blockDown)){
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +171,7 @@ class Door extends Transparent{
|
|||||||
return parent::getAffectedBlocks();
|
return parent::getAffectedBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getSupportType(Facing::UP)->hasEdgeSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ final class FloorCoralFan extends BaseCoral{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($tx->fetchBlock($blockReplace->getPosition()->down()))){
|
if(!$this->canBeSupportedAt($blockReplace)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
@ -75,15 +75,15 @@ final class FloorCoralFan extends BaseCoral{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
if(!$this->canBeSupportedBy($world->getBlock($this->position->down()))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$world->useBreakOn($this->position);
|
$world->useBreakOn($this->position);
|
||||||
}else{
|
}else{
|
||||||
parent::onNearbyBlockChange();
|
parent::onNearbyBlockChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getSupportType(Facing::UP)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asItem() : Item{
|
public function asItem() : Item{
|
||||||
|
@ -90,7 +90,7 @@ class FlowerPot extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if(!$this->canBeSupportedAt($blockReplace)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,13 +98,13 @@ class FlowerPot extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getSupportType(Facing::UP)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||||
|
@ -121,7 +121,7 @@ class GlowLichen extends Transparent{
|
|||||||
$changed = false;
|
$changed = false;
|
||||||
|
|
||||||
foreach($this->faces as $face){
|
foreach($this->faces as $face){
|
||||||
if(!$this->getSide($face)->getSupportType(Facing::opposite($face))->equals(SupportType::FULL())){
|
if(!$this->getAdjacentSupportType($face)->equals(SupportType::FULL())){
|
||||||
unset($this->faces[$face]);
|
unset($this->faces[$face]);
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ class GlowLichen extends Transparent{
|
|||||||
private function getAvailableFaces() : array{
|
private function getAvailableFaces() : array{
|
||||||
$faces = [];
|
$faces = [];
|
||||||
foreach(Facing::ALL as $face){
|
foreach(Facing::ALL as $face){
|
||||||
if(!$this->hasFace($face) && $this->getSide($face)->getSupportType(Facing::opposite($face))->equals(SupportType::FULL())){
|
if(!$this->hasFace($face) && $this->getAdjacentSupportType($face)->equals(SupportType::FULL())){
|
||||||
$faces[$face] = $face;
|
$faces[$face] = $face;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,18 +163,18 @@ class ItemFrame extends Flowable{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block, int $face) : bool{
|
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||||
return !$block->getSupportType($face)->equals(SupportType::NONE());
|
return !$block->getAdjacentSupportType($face)->equals(SupportType::NONE());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::opposite($this->facing)), $this->facing)){
|
if(!$this->canBeSupportedAt($this, Facing::opposite($this->facing))){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::opposite($face)), $face)){
|
if(!$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class Ladder extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedBy($blockReplace->getSide(Facing::opposite($face)), $face) && Facing::axis($face) !== Axis::Y){
|
if($this->canBeSupportedAt($blockReplace, Facing::opposite($face)) && Facing::axis($face) !== Axis::Y){
|
||||||
$this->facing = $face;
|
$this->facing = $face;
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
@ -79,12 +79,12 @@ class Ladder extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::opposite($this->facing)), $this->facing)){ //Replace with common break method
|
if(!$this->canBeSupportedAt($this, Facing::opposite($this->facing))){ //Replace with common break method
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block, int $face) : bool{
|
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||||
return $block->getSupportType($face)->equals(SupportType::FULL());
|
return $block->getAdjacentSupportType($face)->equals(SupportType::FULL());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,22 +77,23 @@ class Lantern extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::UP), Facing::DOWN) && !$this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN), Facing::UP)){
|
$downSupport = $this->canBeSupportedAt($blockReplace, Facing::DOWN);
|
||||||
|
if(!$downSupport && !$this->canBeSupportedAt($blockReplace, Facing::UP)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hanging = ($face === Facing::DOWN || !$this->canBeSupportedBy($this->position->getWorld()->getBlock($blockReplace->getPosition()->down()), Facing::UP));
|
$this->hanging = $face === Facing::DOWN || !$downSupport;
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$face = $this->hanging ? Facing::UP : Facing::DOWN;
|
$face = $this->hanging ? Facing::UP : Facing::DOWN;
|
||||||
if(!$this->canBeSupportedBy($this->getSide($face), Facing::opposite($face))){
|
if(!$this->canBeSupportedAt($this, $face)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block, int $face) : bool{
|
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||||
return $block->getSupportType($face)->hasCenterSupport();
|
return $block->getAdjacentSupportType($face)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class Lever extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::opposite($face)), $face)){
|
if(!$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +90,7 @@ class Lever extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$facing = $this->facing->getFacing();
|
if(!$this->canBeSupportedAt($this, Facing::opposite($this->facing->getFacing()))){
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::opposite($facing)), $facing)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,8 +106,8 @@ class Lever extends Flowable{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block, int $face) : bool{
|
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||||
return $block->getSupportType($face)->hasCenterSupport();
|
return $block->getAdjacentSupportType($face)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
|
@ -83,16 +83,13 @@ class NetherVines extends Flowable{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSupportFace() : int{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return Facing::opposite($this->growthFace);
|
$supportBlock = $block->getSide(Facing::opposite($this->growthFace));
|
||||||
}
|
return $supportBlock->getSupportType($this->growthFace)->hasCenterSupport() || $supportBlock->hasSameTypeId($this);
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
|
||||||
return $block->getSupportType($this->getSupportFace())->hasCenterSupport() || $block->hasSameTypeId($this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide($this->getSupportFace()))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +106,7 @@ class NetherVines extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide($this->getSupportFace()))){
|
if(!$this->canBeSupportedAt($blockReplace)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->age = mt_rand(0, self::MAX_AGE - 1);
|
$this->age = mt_rand(0, self::MAX_AGE - 1);
|
||||||
|
@ -45,18 +45,18 @@ abstract class PressurePlate extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){
|
if($this->canBeSupportedAt($blockReplace)){
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return !$block->getSupportType(Facing::UP)->equals(SupportType::NONE());
|
return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ class RedstoneComparator extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){
|
if($this->canBeSupportedAt($blockReplace)){
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
||||||
}
|
}
|
||||||
@ -102,13 +102,13 @@ class RedstoneComparator extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return !$block->getSupportType(Facing::UP)->equals(SupportType::NONE());
|
return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: redstone functionality
|
//TODO: redstone functionality
|
||||||
|
@ -68,7 +68,7 @@ class RedstoneRepeater extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){
|
if($this->canBeSupportedAt($blockReplace)){
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
||||||
}
|
}
|
||||||
@ -88,13 +88,13 @@ class RedstoneRepeater extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return !$block->getSupportType(Facing::UP)->equals(SupportType::NONE());
|
return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: redstone functionality
|
//TODO: redstone functionality
|
||||||
|
@ -35,7 +35,7 @@ class RedstoneWire extends Flowable{
|
|||||||
use AnalogRedstoneSignalEmitterTrait;
|
use AnalogRedstoneSignalEmitterTrait;
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if($this->canBeSupportedAt($blockReplace)){
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -49,13 +49,13 @@ class RedstoneWire extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getSupportType(Facing::UP)->hasCenterSupport();
|
return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asItem() : Item{
|
public function asItem() : Item{
|
||||||
|
@ -80,8 +80,8 @@ class SnowLayer extends Flowable implements Fallable{
|
|||||||
return SupportType::NONE();
|
return SupportType::NONE();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $b) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $b->getSupportType(Facing::UP)->equals(SupportType::FULL());
|
return $block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::FULL());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
@ -91,7 +91,7 @@ class SnowLayer extends Flowable implements Fallable{
|
|||||||
}
|
}
|
||||||
$this->layers = $blockReplace->layers + 1;
|
$this->layers = $blockReplace->layers + 1;
|
||||||
}
|
}
|
||||||
if($this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){
|
if($this->canBeSupportedAt($blockReplace)){
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,12 +32,12 @@ use pocketmine\world\BlockTransaction;
|
|||||||
|
|
||||||
final class SporeBlossom extends Flowable{
|
final class SporeBlossom extends Flowable{
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedAt(Block $block) : bool{
|
||||||
return $block->getSupportType(Facing::DOWN)->equals(SupportType::FULL());
|
return $block->getAdjacentSupportType(Facing::UP)->equals(SupportType::FULL());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::UP))){
|
if(!$this->canBeSupportedAt($blockReplace)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ final class SporeBlossom extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->canBeSupportedBy($this->getSide(Facing::UP))){
|
if(!$this->canBeSupportedAt($this)){
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ namespace pocketmine\block;
|
|||||||
use pocketmine\block\utils\SupportType;
|
use pocketmine\block\utils\SupportType;
|
||||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Axis;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
@ -56,15 +55,13 @@ class Torch extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$face = Facing::opposite($this->facing);
|
if(!$this->canBeSupportedAt($this, Facing::opposite($this->facing))){
|
||||||
|
|
||||||
if(!$this->canBeSupportedBy($this->getSide($face), $this->facing)){
|
|
||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$this->position->getWorld()->useBreakOn($this->position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($face !== Facing::DOWN && $this->canBeSupportedBy($blockReplace->getSide(Facing::opposite($face)), $face)){
|
if($face !== Facing::DOWN && $this->canBeSupportedAt($blockReplace, Facing::opposite($face))){
|
||||||
$this->facing = $face;
|
$this->facing = $face;
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}else{
|
}else{
|
||||||
@ -75,8 +72,7 @@ class Torch extends Flowable{
|
|||||||
Facing::EAST,
|
Facing::EAST,
|
||||||
Facing::DOWN
|
Facing::DOWN
|
||||||
] as $side){
|
] as $side){
|
||||||
$block = $this->getSide($side);
|
if($this->canBeSupportedAt($blockReplace, $side)){
|
||||||
if($this->canBeSupportedBy($block, Facing::opposite($side))){
|
|
||||||
$this->facing = Facing::opposite($side);
|
$this->facing = Facing::opposite($side);
|
||||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
@ -85,8 +81,9 @@ class Torch extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $support, int $face) : bool{
|
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||||
return ($face === Facing::UP && $support->getSupportType($face)->hasCenterSupport()) ||
|
return $face === Facing::DOWN ?
|
||||||
(Facing::axis($face) !== Axis::Y && $support->getSupportType($face)->equals(SupportType::FULL()));
|
$block->getAdjacentSupportType($face)->hasCenterSupport() :
|
||||||
|
$block->getAdjacentSupportType($face)->equals(SupportType::FULL());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ final class WallCoralFan extends BaseCoral{
|
|||||||
|
|
||||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$axis = Facing::axis($face);
|
$axis = Facing::axis($face);
|
||||||
if(($axis !== Axis::X && $axis !== Axis::Z) || !$this->canBeSupportedBy($blockReplace->getSide(Facing::opposite($face)), $face)){
|
if(($axis !== Axis::X && $axis !== Axis::Z) || !$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->facing = $face;
|
$this->facing = $face;
|
||||||
@ -54,15 +54,15 @@ final class WallCoralFan extends BaseCoral{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$world = $this->position->getWorld();
|
$world = $this->position->getWorld();
|
||||||
if(!$this->canBeSupportedBy($world->getBlock($this->position->getSide(Facing::opposite($this->facing))), $this->facing)){
|
if(!$this->canBeSupportedAt($this, Facing::opposite($this->facing))){
|
||||||
$world->useBreakOn($this->position);
|
$world->useBreakOn($this->position);
|
||||||
}else{
|
}else{
|
||||||
parent::onNearbyBlockChange();
|
parent::onNearbyBlockChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block, int $face) : bool{
|
private function canBeSupportedAt(Block $block, int $face) : bool{
|
||||||
return $block->getSupportType($face)->hasCenterSupport();
|
return $block->getAdjacentSupportType($face)->hasCenterSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asItem() : Item{
|
public function asItem() : Item{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user