made aabb work correctly with 0-height hitboxes, added hitbox for carpet, world will save all data on autosave

This commit is contained in:
GameHerobrine 2024-07-18 05:00:05 +03:00
parent e13b1f28ce
commit 66d847c82f
4 changed files with 17 additions and 12 deletions

View file

@ -74,6 +74,7 @@ class StaticBlock
self::setBlockBounds(SUGARCANE_BLOCK, 0.5 - 0.375, 0, 0.5 - 0.375, 0.5 + 0.375, 1, 0.5 + 0.375);
self::setBlockBounds(SNOW_LAYER, 0, 0, 0, 1, 0.125, 1);
self::setBlockBounds(CARPET, 0, 0, 0, 1, 0, 1);
//Stairs: based on different factors
//Stone wall: based on state

View file

@ -27,7 +27,9 @@ class CarpetBlock extends FlowableBlock{
$this->isFullBlock = false;
$this->isSolid = true;
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)];
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() !== AIR){

View file

@ -171,7 +171,7 @@ class AxisAlignedBB{
}
public function intersectsWith(AxisAlignedBB $bb){
return $bb->maxX > $this->minX and $bb->minX < $this->maxX && $bb->maxZ > $this->minZ and $bb->minZ < $this->maxZ && $bb->maxY > $this->minY and $bb->minY < $this->maxY;
return $bb->maxX >= $this->minX && $bb->minX <= $this->maxX && $bb->maxZ >= $this->minZ && $bb->minZ <= $this->maxZ && $bb->maxY >= $this->minY && $bb->minY <= $this->maxY;
}
public function isXYZInsideNS($x, $y, $z){
if($x < $this->minX or $x > $this->maxX){
@ -184,20 +184,20 @@ class AxisAlignedBB{
return $z > $this->minZ and $z < $this->maxZ;
}
public function isXYZInside($x, $y, $z){
if($x <= $this->minX or $x >= $this->maxX){
if($x < $this->minX or $x > $this->maxX){
return false;
}
if($y <= $this->minY or $y >= $this->maxY){
if($y < $this->minY or $y > $this->maxY){
return false;
}
return $z > $this->minZ and $z < $this->maxZ;
}
public function isVectorInside(Vector3 $vector){
if($vector->x <= $this->minX or $vector->x >= $this->maxX){
if($vector->x < $this->minX or $vector->x > $this->maxX){
return false;
}
if($vector->y <= $this->minY or $vector->y >= $this->maxY){
if($vector->y < $this->minY or $vector->y > $this->maxY){
return false;
}

View file

@ -285,7 +285,7 @@ class Level{
$t = $this->getTime() % 19200;
return $t < TimeAPI::$phases["sunrise"] && $t > TimeAPI::$phases["sunset"];
}
public function save($force = false, $extra = true){
public function save($force = false, $entities = true, $tiles = true, $blockupdates = true){
if(!isset($this->level)){
return false;
}
@ -293,7 +293,7 @@ class Level{
return;
}
if($extra !== false){
if($entities){
$entities = [];
foreach($this->entityList as $entity){
@ -303,13 +303,16 @@ class Level{
}
$this->entities->setAll($entities);
$this->entities->save();
}
if($tiles){
$tiles = [];
foreach($this->server->api->tile->getAll($this) as $tile){
$tiles[] = $tile->data;
}
$this->tiles->setAll($tiles);
$this->tiles->save();
}
if($blockupdates){
$blockUpdates = [];
$updates = $this->server->query("SELECT x,y,z,type,delay FROM blockUpdates WHERE level = '" . $this->getName() . "';");
if($updates !== false and $updates !== true){
@ -322,7 +325,6 @@ class Level{
$this->blockUpdates->setAll($blockUpdates);
$this->blockUpdates->save();
}
$this->level->setData("time", (int) $this->time);
@ -422,9 +424,9 @@ class Level{
$this->changedBlocks = [];
}
}
if($this->nextSave < $now){
$this->save(false, false);
$this->save(false, true, true, true);
}
}