time always updates, test entity optimizations

This commit is contained in:
GameHerobrine 2022-12-20 23:54:09 +03:00
parent 026daf485b
commit fc2fa6d2f8
5 changed files with 47 additions and 42 deletions

View file

@ -28,6 +28,7 @@ class Explosion{
}
public function explode(){
console("a");
if(!Explosion::$enableExplosions){ /*Disable Explosions*/
return;
}
@ -40,7 +41,7 @@ class Explosion{
]) === false){
return false;
}
console("b");
$mRays = $this->rays - 1;
for($i = 0; $i < $this->rays; ++$i){
for($j = 0; $j < $this->rays; ++$j){
@ -59,6 +60,7 @@ class Explosion{
$block->x = $vBlock->x;
$block->y = $vBlock->y;
$block->z = $vBlock->z;
$block->level = $this->level;
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
if($blastForce > 0){
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
@ -84,7 +86,6 @@ class Explosion{
}
foreach($this->affectedBlocks as $block){
if($block instanceof TNTBlock){
$data = [
"x" => $block->x + 0.5,
@ -100,7 +101,7 @@ class Explosion{
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1], $drop[2])); //id, meta, count
}
}
$this->level->setBlock($block, new AirBlock(), true, false, true);
$this->level->setBlock($block, new AirBlock(), true);
$send[] = $block->subtract($source);
}
$pk = new ExplodePacket;

View file

@ -261,6 +261,8 @@ class Level{
public function onTick(PocketMinecraftServer $server){
//$ents = $server->api->entity->getAll($this);
if(!$this->stopTime) ++$this->time;
ConsoleAPI::debug($this->getTime());
foreach($this->entityList as $k => $e){
if(!($e instanceof Entity)){
unset($this->entityList[$k]);
@ -280,14 +282,12 @@ class Level{
if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
return false;
}
$ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata());
if($ret === true){
if(!($pos instanceof Position)){
$pos = new Position($pos->x, $pos->y, $pos->z, $this);
}
$block->position($pos);
if($direct === true){
$pk = new UpdateBlockPacket;
$pk->x = $pos->x;
@ -500,13 +500,14 @@ class Level{
}else{
$time = $this->startTime + ($now - $this->startCheck) * 20;
}
if($this->server->api->dhandle("time.change", ["level" => $this, "time" => $time]) !== false){
if($this->server->api->dhandle("time.change", ["level" => $this, "time" => $time]) !== false){ //send time to player every 5 ticks
$this->time = $time;
$pk = new SetTimePacket;
$pk->time = (int) $this->time;
$pk->started = $this->stopTime == false;
$this->server->api->player->broadcastPacket($this->players, $pk);
}else{
$this->time -= 20 * 13;
}
}