This commit is contained in:
GameHerobrine 2023-12-11 09:16:21 +03:00
parent bfe23f5547
commit 7d100b5358

View file

@ -1,6 +1,14 @@
<?php <?php
class BedBlock extends TransparentBlock{ class BedBlock extends TransparentBlock{
public static $faces = [
0 => 3,
1 => 4,
2 => 2,
3 => 5,
];
public function __construct($type = 0){ public function __construct($type = 0){
parent::__construct(BED_BLOCK, $type, "Bed Block"); parent::__construct(BED_BLOCK, $type, "Bed Block");
$this->isActivable = true; $this->isActivable = true;
@ -50,15 +58,10 @@ class BedBlock extends TransparentBlock{
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->isTransparent === false){ if($down->isTransparent === false){
$faces = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
);
$d = $player->entity->getDirection(); $d = $player->entity->getDirection();
$next = $this->getSide($faces[(($d + 3) % 4)]); $next = $this->getSide(self::$faces[(($d + 3) % 4)]);
$downNext = $this->getSide(0); $downNext = $next->getSide(0);
if($next->isReplaceable === true and $downNext->isTransparent === false){ if($next->isReplaceable === true and $downNext->isTransparent === false){
$meta = (($d + 3) % 4) & 0x03; $meta = (($d + 3) % 4) & 0x03;
$this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true); $this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true);
@ -76,24 +79,34 @@ class BedBlock extends TransparentBlock{
$blockWest = $this->getSide(4); $blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right switch($this->meta & 0x7){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true); case 0:
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){ if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true); break;
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){ case 1:
$this->level->setBlock($blockEast, new AirBlock(), true, false, true); if($blockEast->id === $this->id) $this->level->setBlock($blockEast, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){ break;
$this->level->setBlock($blockWest, new AirBlock(), true, false, true); case 2:
if($blockSouth->id === $this->id) $this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
break;
case 3:
if($blockWest->id === $this->id) $this->level->setBlock($blockWest, new AirBlock(), true, false, true);
break;
} }
}else{ //Bottom Part of Bed }else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ switch($this->meta & 0x7){
$this->level->setBlock($blockNorth, new AirBlock(), true, false, true); case 0:
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ if($blockSouth->id === $this->id) $this->level->setBlock($blockSouth, new AirBlock(), true, false, true);
$this->level->setBlock($blockSouth, new AirBlock(), true, false, true); break;
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ case 1:
$this->level->setBlock($blockEast, new AirBlock(), true, false, true); if($blockWest->id === $this->id) $this->level->setBlock($blockWest, new AirBlock(), true, false, true);
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ break;
$this->level->setBlock($blockWest, new AirBlock(), true, false, true); case 2:
if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
break;
case 3:
if($blockEast->id === $this->id) $this->level->setBlock($blockEast, new AirBlock(), true, false, true);
break;
} }
} }
$this->level->setBlock($this, new AirBlock(), true, false, true); $this->level->setBlock($this, new AirBlock(), true, false, true);