From 2c264a023ae05869d5bdadb60cf4ad6097664cd5 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 11 Dec 2023 06:18:05 +0300 Subject: [PATCH] fixed beds --- src/API/EntityAPI.php | 11 ++++--- src/material/block/misc/BedBlock.php | 46 +++++++++++++++++----------- src/world/Level.php | 1 - 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 22f68e69..f956db1a 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -199,10 +199,6 @@ class EntityAPI{ } } - public function updateRadius(Position $center, $radius = 15, $class = false){ - //useless now? $this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;"); - } - public function getRadius(Position $center, $radius = 15, $class = false){ $entities = []; $l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;"); @@ -293,4 +289,11 @@ class EntityAPI{ } return $this->entities; } + + /** + * @deprecated this function doesnt do anything + */ + public function updateRadius(Position $center, $radius = 15, $class = false){ + + } } diff --git a/src/material/block/misc/BedBlock.php b/src/material/block/misc/BedBlock.php index c74ae653..1a12b74a 100644 --- a/src/material/block/misc/BedBlock.php +++ b/src/material/block/misc/BedBlock.php @@ -61,7 +61,7 @@ class BedBlock extends TransparentBlock{ $d = $player->entity->getDirection(); $next = $this->getSide(self::$faces[(($d + 3) % 4)]); - $downNext = $this->getSide(0); + $downNext = $next->getSide(0); if($next->isReplaceable === true and $downNext->isTransparent === false){ $meta = (($d + 3) % 4) & 0x03; $this->level->setBlock($block, BlockAPI::get($this->id, $meta), true, false, true); @@ -79,25 +79,35 @@ class BedBlock extends TransparentBlock{ $blockWest = $this->getSide(4); 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 - $this->level->setBlock($blockNorth, new AirBlock(), true, false, true); - }elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){ - $this->level->setBlock($blockSouth, new AirBlock(), true, false, true); - }elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){ - $this->level->setBlock($blockEast, new AirBlock(), true, false, true); - }elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){ - $this->level->setBlock($blockWest, new AirBlock(), true, false, true); + switch($this->meta & 0x7){ + case 0: + if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), true, false, true); + break; + case 1: + if($blockEast->id === $this->id) $this->level->setBlock($blockEast, new AirBlock(), true, false, true); + break; + 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 - if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ - $this->level->setBlock($blockNorth, new AirBlock(), true, false, true); - }elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ - $this->level->setBlock($blockSouth, new AirBlock(), true, false, true); - }elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ - $this->level->setBlock($blockEast, new AirBlock(), true, false, true); - }elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ - $this->level->setBlock($blockWest, new AirBlock(), true, false, true); - } + switch($this->meta & 0x7){ + case 0: + if($blockSouth->id === $this->id) $this->level->setBlock($blockSouth, new AirBlock(), true, false, true); + break; + case 1: + if($blockWest->id === $this->id) $this->level->setBlock($blockWest, new AirBlock(), true, false, true); + break; + 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); return true; diff --git a/src/world/Level.php b/src/world/Level.php index 1da06491..2437b634 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -431,7 +431,6 @@ class Level{ if($update === true){ $this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1); - $this->server->api->entity->updateRadius($pos, 3); } if($tiles === true){ if(($t = $this->server->api->tile->get($pos)) !== false){