121 if($player !== null){
122 $other = $this->getOtherHalf();
123 $playerPos = $player->getPosition();
125 $player->sendMessage(TextFormat::GRAY .
"This bed is incomplete");
128 }elseif($playerPos->distanceSquared($this->position) > 4 && $playerPos->distanceSquared($other->position) > 4){
129 $player->sendMessage(KnownTranslationFactory::tile_bed_tooFar()->prefix(TextFormat::GRAY));
133 $time = $this->position->getWorld()->getTimeOfDay();
135 $isNight = ($time >= World::TIME_NIGHT && $time < World::TIME_SUNRISE);
138 $player->sendMessage(KnownTranslationFactory::tile_bed_noSleep()->prefix(TextFormat::GRAY));
143 $b = ($this->isHeadPart() ? $this : $other);
146 $player->sendMessage(KnownTranslationFactory::tile_bed_occupied()->prefix(TextFormat::GRAY));
151 $player->sleepOn($b->position);
174 if($this->canBeSupportedAt($blockReplace)){
175 $this->facing = $player !==
null ? $player->getHorizontalFacing() : Facing::NORTH;
177 $next = $this->getSide($this->getOtherHalfSide());
178 if($next->canBeReplaced() && $this->canBeSupportedAt($next)){
179 $nextState = clone $this;
180 $nextState->head =
true;
181 $tx->
addBlock($blockReplace->position, $this)->addBlock($next->position, $nextState);