Bell: fixed support requirements

this somehow got overlooked in the support types refactor.
This commit is contained in:
Dylan K. Taylor 2023-01-12 21:45:25 +00:00
parent cbeae906e1
commit f4a1d69075
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -114,14 +114,13 @@ final class Bell extends Transparent{
return $this; return $this;
} }
private function canBeSupportedBy(Block $block) : bool{ private function canBeSupportedBy(Block $block, int $face) : bool{
//TODO: this isn't the actual logic, but it's the closest approximation we can support for now return !$block->getSupportType($face)->equals(SupportType::NONE());
return $block->isSolid();
} }
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()))){ if(!$this->canBeSupportedBy($tx->fetchBlock($this->position->down()), Facing::UP)){
return false; return false;
} }
if($player !== null){ if($player !== null){
@ -129,18 +128,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()))){ if(!$this->canBeSupportedBy($tx->fetchBlock($this->position->up()), Facing::DOWN)){
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))))){ if($this->canBeSupportedBy($tx->fetchBlock($this->position->getSide(Facing::opposite($face))), $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)))){ if($this->canBeSupportedBy($tx->fetchBlock($this->position->getSide($face)), Facing::opposite($face))){
$this->setAttachmentType(BellAttachmentType::TWO_WALLS()); $this->setAttachmentType(BellAttachmentType::TWO_WALLS());
} }
} }
@ -149,10 +148,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))) || ($this->attachmentType->equals(BellAttachmentType::CEILING()) && !$this->canBeSupportedBy($this->getSide(Facing::UP), Facing::DOWN)) ||
($this->attachmentType->equals(BellAttachmentType::FLOOR()) && !$this->canBeSupportedBy($this->getSide(Facing::DOWN))) || ($this->attachmentType->equals(BellAttachmentType::FLOOR()) && !$this->canBeSupportedBy($this->getSide(Facing::DOWN), Facing::UP)) ||
($this->attachmentType->equals(BellAttachmentType::ONE_WALL()) && !$this->canBeSupportedBy($this->getSide(Facing::opposite($this->facing)))) || ($this->attachmentType->equals(BellAttachmentType::ONE_WALL()) && !$this->canBeSupportedBy($this->getSide(Facing::opposite($this->facing)), $this->facing)) ||
($this->attachmentType->equals(BellAttachmentType::TWO_WALLS()) && (!$this->canBeSupportedBy($this->getSide($this->facing)) || !$this->canBeSupportedBy($this->getSide(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->position->getWorld()->useBreakOn($this->position); $this->position->getWorld()->useBreakOn($this->position);
} }