bed will now break from tnt explosion

This commit is contained in:
GameHerobrine 2024-05-29 06:30:02 +03:00
parent fc0f3f6bde
commit 7bc97cca37
3 changed files with 41 additions and 14 deletions

View file

@ -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;
}
}