mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
better bed spawnpoint position
This commit is contained in:
parent
f05b66d992
commit
edc487f1f3
2 changed files with 37 additions and 2 deletions
|
|
@ -147,7 +147,15 @@ class Player{
|
|||
if($this->entity instanceof Entity){
|
||||
$this->entity->updateMetadata();
|
||||
}
|
||||
$this->setSpawn($pos);
|
||||
|
||||
$spawnPoint = BedBlock::findStandUpPosition($this->level, $pos->x, $pos->y, $pos->z);
|
||||
console($spawnPoint);
|
||||
if($spawnPoint == null) $spawnPoint = $pos->add(0.5, 1, 0.5);
|
||||
else{
|
||||
$spawnPoint->x += 0.5;
|
||||
$spawnPoint->z += 0.5;
|
||||
}
|
||||
$this->setSpawn($spawnPoint);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,12 @@ class BedBlock extends TransparentBlock{
|
|||
2 => 2,
|
||||
3 => 5,
|
||||
];
|
||||
|
||||
const HEAD_DIRECTION_OFFSETS = [
|
||||
[0, 1],
|
||||
[-1, 0],
|
||||
[0, -1],
|
||||
[1, 0]
|
||||
];
|
||||
public function __construct($type = 0){
|
||||
parent::__construct(BED_BLOCK, $type, "Bed Block");
|
||||
$this->isActivable = true;
|
||||
|
|
@ -16,6 +21,28 @@ class BedBlock extends TransparentBlock{
|
|||
$this->hardness = 1;
|
||||
}
|
||||
|
||||
public static function findStandUpPosition(Level $level, $x, $y, $z){
|
||||
$blockMeta = $level->level->getBlockDamage($x, $y, $z);
|
||||
$direction = $blockMeta & 0x3;
|
||||
for($v7 = 0; $v7 <= 1; ++$v7){
|
||||
$minX = $x - self::HEAD_DIRECTION_OFFSETS[$direction][0] * $v7 - 1;
|
||||
$minZ = $z - self::HEAD_DIRECTION_OFFSETS[$direction][1] * $v7 - 1;
|
||||
$maxX = $minX + 2;
|
||||
$maxZ = $minZ + 2;
|
||||
|
||||
for($xCheck = $minX; $xCheck <= $maxX; ++$xCheck){
|
||||
for($zCheck = $minZ; $zCheck <= $maxZ; ++$zCheck){
|
||||
$idCheck = $level->level->getBlockID($xCheck, $y - 1, $zCheck);
|
||||
if(!StaticBlock::getIsTransparent($idCheck) && $level->level->getBlockID($xCheck, $y, $zCheck) == 0 && $level->level->getBlockID($xCheck, $y + 1, $zCheck) == 0){
|
||||
return new Vector3($xCheck, $y, $zCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){
|
||||
$pk = new ChatPacket;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue