invalidated all tile entities on block change

This commit is contained in:
GameHerobrine 2024-06-01 00:57:17 +03:00
parent c5bdb933ed
commit bbf506c887
2 changed files with 26 additions and 6 deletions

View file

@ -11,12 +11,34 @@ class TileAPI{
$this->server = ServerAPI::request();
}
public function getXYZ(Level $level, $x, $y, $z){
$tile = $this->server->query("SELECT * FROM tiles WHERE level = '{$level->getName()}' AND x = $z AND y = $y AND z = $z;", true);
$tile = $this->server->query("SELECT * FROM tiles WHERE level = '{$level->getName()}' AND x = $x AND y = $y AND z = $z;", true);
if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){
return $tile;
}
return false;
}
public function invalidateAll(Level $level, $x, $y, $z){
$x = (int) $x;
$y = (int) $y;
$z = (int) $z;
$tile = $this->server->query("SELECT id FROM tiles WHERE level = '{$level->getName()}' AND x = $x AND y = $y AND z = $z;", false);
$invcnt = 0;
if($tile instanceof SQLite3Result){
while(($t = $tile->fetchArray(SQLITE3_ASSOC)) !== false){
$tl = $this->getByID($t["ID"]);
if($tl instanceof Tile){
++$invcnt;
$tl->close();
}
if($invcnt > 1){
ConsoleAPI::warn("{$level->getName()}: ($x $y $z) has more than 1 tile entity! Invalidated ID {$t["ID"]} (Total invaliated: $invcnt)");
}
}
}
}
public function get(Position $pos){
$tile = $this->server->query("SELECT * FROM tiles WHERE level = '" . $pos->level->getName() . "' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true);
if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){