From 060c300d509685c5ad74b141270b73f2b0e50918 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 5 Aug 2020 20:59:59 +0100 Subject: [PATCH] Bed::setOccupied() no longer sets itself into the world setting itself into the world is very annoying when trying to simply set up a blockstate. --- src/block/Bed.php | 13 +++++++------ src/player/Player.php | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/block/Bed.php b/src/block/Bed.php index 5c457641cf..73b61953fc 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -106,12 +106,6 @@ class Bed extends Transparent{ public function setOccupied(bool $occupied = true) : void{ $this->occupied = $occupied; - $this->pos->getWorld()->setBlock($this->pos, $this, false); - - if(($other = $this->getOtherHalf()) !== null){ - $other->occupied = $occupied; - $this->pos->getWorld()->setBlock($other->pos, $other, false); - } } private function getOtherHalfSide() : int{ @@ -165,6 +159,13 @@ class Bed extends Transparent{ } + public function onNearbyBlockChange() : void{ + if(($other = $this->getOtherHalf()) !== null and $other->occupied !== $this->occupied){ + $this->occupied = $other->occupied; + $this->pos->getWorld()->setBlock($this->pos, $this); + } + } + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($item instanceof ItemBed){ //TODO: the item should do this $this->color = $item->getColor(); diff --git a/src/player/Player.php b/src/player/Player.php index f018f6b746..134d69d47b 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -954,6 +954,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ if($b instanceof Bed){ $b->setOccupied(); + $this->getWorld()->setBlock($pos, $b); } $this->sleeping = $pos; @@ -970,6 +971,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $b = $this->getWorld()->getBlock($this->sleeping); if($b instanceof Bed){ $b->setOccupied(false); + $this->getWorld()->setBlock($this->sleeping, $b); } (new PlayerBedLeaveEvent($this, $b))->call();