From 7bc97cca3789fca37dbafbfbee1863491420ac6e Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 29 May 2024 06:30:02 +0300 Subject: [PATCH] bed will now break from tnt explosion --- src/API/EntityAPI.php | 12 ++++---- src/Player.php | 2 +- src/material/block/misc/BedBlock.php | 41 +++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 49d69bc0..96627ad3 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -248,15 +248,15 @@ class EntityAPI{ $e->setHealth($e->getHealth() - $attack, $cause, $force); } - public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){ + public function dropRawPos(Level $level, $x, $y, $z, $item, $speedX, $speedY, $speedZ){ if($item->getID() === AIR or $item->count <= 0){ return; } $data = [ - "x" => $pos->x, - "y" => $pos->y, - "z" => $pos->z, - "level" => $pos->level, + "x" => $x, + "y" => $y, + "z" => $z, + "level" => $level, "speedX" => $speedX, "speedY" => $speedY, "speedZ" => $speedZ, @@ -268,7 +268,7 @@ class EntityAPI{ for($count = $item->count; $count > 0;){ $item->count = min($item->getMaxStackSize(), $count); $count -= $item->count; - $e = $this->add($pos->level, ENTITY_ITEM, ENTITY_ITEM_TYPE, $data); + $e = $this->add($level, ENTITY_ITEM, ENTITY_ITEM_TYPE, $data); $this->spawnToAll($e); $this->server->api->handle("entity.motion", $e); } diff --git a/src/Player.php b/src/Player.php index 1c5f57c5..43895a3e 100755 --- a/src/Player.php +++ b/src/Player.php @@ -2184,7 +2184,7 @@ class Player{ $sX += cos($f3) * $f1; $sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1; $sZ += sin($f3) * $f1; - $this->server->api->entity->dropRawPos(new Position($this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $this->level), $packet->item, $sX, $sY, $sZ); + $this->server->api->entity->dropRawPos($this->level, $this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $packet->item, $sX, $sY, $sZ); $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); } if($this->entity->inAction === true){ diff --git a/src/material/block/misc/BedBlock.php b/src/material/block/misc/BedBlock.php index 0f1efde7..cb2a9885 100644 --- a/src/material/block/misc/BedBlock.php +++ b/src/material/block/misc/BedBlock.php @@ -24,7 +24,34 @@ class BedBlock extends TransparentBlock{ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [static::getAABB($level, $x, $y, $z)]; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + + $meta = $level->level->getBlockDamage($x, $y, $z); + $dir = $meta & 3; + $isHead = ($meta >> 3) & 1; + + $offX = self::HEAD_DIRECTION_OFFSETS[$dir][0]; + $offZ = self::HEAD_DIRECTION_OFFSETS[$dir][1]; + + if($isHead){ + if($level->level->getBlockID($x - $offX, $y, $z - $offZ) != BED_BLOCK){ + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + } + }else if($level->level->getBlockID($x + $offX, $y, $z + $offZ) != BED_BLOCK){ + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + + ServerAPI::request()->api->entity->dropRawPos( + $level, + $x + (lcg_value() * 0.7) + 0.15, + $y + (lcg_value() * 0.7) + 0.15, + $z + (lcg_value() * 0.7) + 0.15, + BlockAPI::getItem(BED, 0, 1), + lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1 + ); + + } + + } public static function findStandUpPosition(Level $level, $x, $y, $z){ $blockMeta = $level->level->getBlockDamage($x, $y, $z); $direction = $blockMeta & 0x3; @@ -95,8 +122,8 @@ class BedBlock extends TransparentBlock{ $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); - $this->level->setBlock($next, BlockAPI::get($this->id, $meta | 0x08), true, false, true); + $this->level->fastSetBlockUpdate($block->x, $block->y, $block->z, $this->id, $meta, true); + $this->level->fastSetBlockUpdate($next->x, $next->y, $next->z, $this->id, $meta | 0x08, true); return true; } } @@ -127,16 +154,16 @@ class BedBlock extends TransparentBlock{ }else{ //Bottom Part of Bed switch($this->meta & 0x7){ case 0: - if($blockSouth->id === $this->id) $this->level->setBlock($blockSouth, new AirBlock(), true, false, true); + if($blockSouth->id === $this->id) $this->level->setBlock($blockSouth, new AirBlock(), false, false, true); break; case 1: - if($blockWest->id === $this->id) $this->level->setBlock($blockWest, new AirBlock(), true, false, true); + if($blockWest->id === $this->id) $this->level->setBlock($blockWest, new AirBlock(), false, false, true); break; case 2: - if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), true, false, true); + if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), false, false, true); break; case 3: - if($blockEast->id === $this->id) $this->level->setBlock($blockEast, new AirBlock(), true, false, true); + if($blockEast->id === $this->id) $this->level->setBlock($blockEast, new AirBlock(), false, false, true); break; } }