mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
fixed block updates not being unscheduled when level is unloaded
This commit is contained in:
parent
c4b7012fe9
commit
cf25df788f
2 changed files with 29 additions and 41 deletions
|
|
@ -430,7 +430,7 @@ class BlockAPI{
|
||||||
$pk->meta = $block->getMetadata();
|
$pk->meta = $block->getMetadata();
|
||||||
$player->dataPacket($pk);
|
$player->dataPacket($pk);
|
||||||
if($send === true){
|
if($send === true){
|
||||||
$player->sendInventorySlot($player->slot);
|
$player->sendInventory();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -571,6 +571,18 @@ class BlockAPI{
|
||||||
$this->blockUpdate($pos->getSide(5), $type);
|
$this->blockUpdate($pos->getSide(5), $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeAllBlockUpdates(Level $level){
|
||||||
|
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE level = '{$level->getName()}';");
|
||||||
|
if($update instanceof SQLite3Result){
|
||||||
|
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
|
$index = $up["x"] . "." . $up["y"] . "." . $up["z"] . "." . $up["level"] . "." . $up["type"];
|
||||||
|
unset($this->scheduledUpdates[$index]);
|
||||||
|
}
|
||||||
|
$this->server->query("DELETE FROM blockUpdates WHERE level = '{$level->getName()}';");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function scheduleBlockUpdateXYZ(Level $level, $x, $y, $z, $type = BLOCK_UPDATE_SCHEDULED, $delay = false){
|
public function scheduleBlockUpdateXYZ(Level $level, $x, $y, $z, $type = BLOCK_UPDATE_SCHEDULED, $delay = false){
|
||||||
$type = (int) $type;
|
$type = (int) $type;
|
||||||
if($delay < 0){
|
if($delay < 0){
|
||||||
|
|
@ -588,41 +600,9 @@ class BlockAPI{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){
|
public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){
|
||||||
$type = (int) $type;
|
return $this->scheduleBlockUpdateXYZ($pos->level, $pos->x, $pos->y, $pos->z, $type, $delay);
|
||||||
if($delay < 0){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$index = $pos->x . "." . $pos->y . "." . $pos->z . "." . $pos->level->getName() . "." . $type;
|
|
||||||
$delay = microtime(true) + $delay * 0.05;
|
|
||||||
if(!isset($this->scheduledUpdates[$index])){
|
|
||||||
$this->scheduledUpdates[$index] = $pos;
|
|
||||||
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (" . $pos->x . ", " . $pos->y . ", " . $pos->z . ", '" . $pos->level->getName() . "', " . $type . ", " . $delay . ");");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextRandomUpdate(Position $pos){
|
|
||||||
if(!isset($this->scheduledUpdates[$pos->x . "." . $pos->y . "." . $pos->z . "." . $pos->level->getName() . "." . BLOCK_UPDATE_RANDOM])){
|
|
||||||
$time = microtime(true);
|
|
||||||
$offset = 0;
|
|
||||||
while(true){
|
|
||||||
$t = $offset + Utils::getRandomUpdateTicks() * 0.05;
|
|
||||||
$update = $this->server->query("SELECT COUNT(*) FROM blockUpdates WHERE level = '" . $pos->level->getName() . "' AND type = " . BLOCK_UPDATE_RANDOM . " AND delay >= " . ($time + $t - 1) . " AND delay <= " . ($time + $t + 1) . ";");
|
|
||||||
if($update instanceof SQLite3Result){
|
|
||||||
$update = $update->fetchArray(SQLITE3_NUM);
|
|
||||||
if($update[0] < 3){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$offset += mt_rand(25, 75);
|
|
||||||
}
|
|
||||||
$this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function blockUpdateTick(){
|
public function blockUpdateTick(){
|
||||||
$time = microtime(true);
|
$time = microtime(true);
|
||||||
|
|
@ -644,4 +624,11 @@ class BlockAPI{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated random updates are handled differently now.
|
||||||
|
*/
|
||||||
|
public function nextRandomUpdate(Position $pos){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,13 @@ class Level{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(){
|
public function close(){
|
||||||
$this->__destruct();
|
if(isset($this->level)){
|
||||||
|
$this->save(true, true, true, true);
|
||||||
|
$this->level->close();
|
||||||
|
unset($this->level);
|
||||||
|
$this->server->api->block->removeAllBlockUpdates($this);
|
||||||
|
}
|
||||||
|
unset($this->mobSpawner->level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTopSolidBlocking($x, $y, $z){
|
public function isTopSolidBlocking($x, $y, $z){
|
||||||
|
|
@ -269,12 +275,7 @@ class Level{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct(){
|
public function __destruct(){
|
||||||
if(isset($this->level)){
|
$this->close();
|
||||||
$this->save(false, false, false, false);
|
|
||||||
$this->level->close();
|
|
||||||
unset($this->level);
|
|
||||||
}
|
|
||||||
unset($this->mobSpawner->level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isDay(){
|
public function isDay(){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue