small entity optimizations

This commit is contained in:
GameHerobrine 2022-11-28 21:33:55 +03:00
parent 54bdb8a244
commit 019e7f26ea
5 changed files with 383 additions and 263 deletions

View file

@ -14,7 +14,6 @@ class EntityAPI{
} }
public function init(){ public function init(){
$this->server->schedule(25, [$this, "updateEntities"], [], true);
$this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]); $this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]); $this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("despawn", "", [$this, "CommandHandler"]); $this->server->api->console->register("despawn", "", [$this, "CommandHandler"]);
@ -102,7 +101,13 @@ class EntityAPI{
break; break;
}else{ }else{
if($args[0] === "all"){ if($args[0] === "all"){
$l = $this->server->query("SELECT EID FROM entities WHERE class = 2 or class = 3 or class = 4 or class = 5;"); $cnt = 0;
foreach($this->entities as $e){
if(!$e->isPlayer()){ //if player, not despawning
$this->remove($e->eid);
$cnt++;
}
}
}else{ }else{
$array = explode(",", strtolower($args[0])); $array = explode(",", strtolower($args[0]));
if(count($array) > 4){ if(count($array) > 4){
@ -117,18 +122,19 @@ class EntityAPI{
} }
$despawning = substr($list, 0, -4); $despawning = substr($list, 0, -4);
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";"); $l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$this->remove($e->eid);
$cnt++;
}
}
}
} }
} }
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ $output = "$cnt entities have been despawned!";
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$this->remove($e->eid);
$cnt++;
}
}
}
$output .= "$cnt entities have been despawned!";
break; break;
} }
return $output; return $output;
@ -174,38 +180,21 @@ class EntityAPI{
public function remove($eid){ public function remove($eid){
if(isset($this->entities[$eid])){ if(isset($this->entities[$eid])){
$entity = $this->entities[$eid]; $this->entities[$eid]->closed = true;
$this->entities[$eid] = null; if($this->entities[$eid]->isPlayer()){
unset($this->entities[$eid]);
$entity->closed = true;
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
if($entity->class === ENTITY_PLAYER){
$pk = new RemovePlayerPacket; $pk = new RemovePlayerPacket;
$pk->eid = $entity->eid; $pk->eid = $eid;
$pk->clientID = 0; $pk->clientID = 0;
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), $pk); $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
}else{ }else{
$pk = new RemoveEntityPacket; $pk = new RemoveEntityPacket;
$pk->eid = $entity->eid; $pk->eid = $eid;
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), $pk); $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
}
$this->server->api->dhandle("entity.remove", $entity);
$entity = null;
unset($entity);
}
}
public function updateEntities(){
$l = $this->server->query("SELECT EID FROM entities WHERE hasUpdate = 1;");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$e->update();
$this->server->query("UPDATE entities SET hasUpdate = 0 WHERE EID = " . $e->eid . ";");
}
} }
$this->server->api->dhandle("entity.remove", $this->entities[$eid]);
unset($this->entities[$eid]);
$this->entities[$eid] = null;
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
} }
} }

View file

@ -284,7 +284,7 @@ class Player{
$packet->messageIndex = $this->counter[3]++; $packet->messageIndex = $this->counter[3]++;
$packet->reliability = 2; $packet->reliability = 2;
$this->buffer->data[] = $packet; @$this->buffer->data[] = $packet;
$this->bufferLen += 6 + $len; $this->bufferLen += 6 + $len;
return []; return [];
} }
@ -760,7 +760,7 @@ class Player{
if($data->eid === $this->eid or $data->level !== $this->level){ if($data->eid === $this->eid or $data->level !== $this->level){
break; break;
} }
if($data->speedX === 0 && $data->speedY === 0 && $data->speedZ === 0){ //causer of packet flood is eliminated. if(($data->speedX === 0 && $data->speedY === 0 && $data->speedZ === 0) || ($data->speedX === $data->lastSpeedX && $data->speedY === $data->lastSpeedY && $data->lastSpeedZ === $data->speedZ)){ //causer of packet flood is eliminated.
break; break;
} }
$pk = new SetEntityMotionPacket; $pk = new SetEntityMotionPacket;
@ -769,6 +769,9 @@ class Player{
$pk->speedY = $data->speedY; $pk->speedY = $data->speedY;
$pk->speedZ = $data->speedZ; $pk->speedZ = $data->speedZ;
$this->dataPacket($pk); $this->dataPacket($pk);
$data->lastSpeedZ = $data->speedZ;
$data->lastSpeedY = $data->speedY;
$data->lastSpeedX = $data->speedX;
break; break;
case "entity.animate": case "entity.animate":
if($data["eid"] === $this->eid or $data["entity"]->level->getName() === $this->level->getName()){ if($data["eid"] === $this->eid or $data["entity"]->level->getName() === $this->level->getName()){

View file

@ -24,14 +24,21 @@ class Entity extends Position
public $eid; public $eid;
public $type; public $type;
public $name; public $name;
public $x; public $x, $y, $z;
public $y; public $speedX, $speedY, $speedZ, $speed;
public $z; public $lastX = 0, $lastY = 0, $lastZ = 0, $lastYaw = 0, $lastPitch = 0, $lastTime = 0, $lastHeadYaw = 0, $lastSpeedX = 0, $lastSpeedY = 0, $lastSpeedZ = 0;
public $speedX; /**
public $speedY; * 0 = lastX,
public $speedZ; * 1 = lastY,
public $speed; * 2 = lastZ,
public $lastX = 0, $lastY = 0, $lastZ = 0, $lastYaw = 0, $lastPitch = 0, $lastTime = 0, $lastHeadYaw = 0; * 3 = lastYaw,
* 4 = lastPitch,
* 5 = lastTime.
*
* It is not recommended to use this and it is left as a backwards compability.
*
* @var array
*/
public $last; public $last;
public $yaw, $headYaw; public $yaw, $headYaw;
public $pitch; public $pitch;
@ -393,63 +400,69 @@ class Entity extends Position
$endY = $startY + 2; $endY = $startY + 2;
$endZ = $startZ + 2; $endZ = $startZ + 2;
$waterDone = false; $waterDone = false;
for($y = $startY; $y <= $endY; ++ $y){ if($this->isPlayer()){
for($x = $startX; $x <= $endX; ++ $x){
for($z = $startZ; $z <= $endZ; ++ $z){ }
$pos = new Vector3($x, $y, $z); if($this->isPlayer()){
$b = $this->level->getBlock($pos); for($y = $startY; $y <= $endY; ++ $y){
switch($b->getID()) { for($x = $startX; $x <= $endX; ++ $x){
case WATER: for($z = $startZ; $z <= $endZ; ++ $z){
case STILL_WATER: // Drowing $pos = new Vector3($x, $y, $z);
if($this->fire > 0 and $this->inBlock($pos)){ $b = $this->level->getBlock($pos);
$this->fire = 0; switch($b->getID()) {
$this->updateMetadata(); case WATER:
} case STILL_WATER: // Drowing
if($this->air <= 0){ if($this->fire > 0 and $this->inBlock($pos)){
$this->harm(2, "water"); $this->fire = 0;
$hasUpdate = true; $this->updateMetadata();
} elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and ! $waterDone){ }
$this->air -= 1; if($this->air <= 0){
$waterDone = true; $this->harm(2, "water");
$this->updateMetadata(); $hasUpdate = true;
$hasUpdate = true; } elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and ! $waterDone){
} $this->air -= 1;
break; $waterDone = true;
case LAVA: // Lava damage $this->updateMetadata();
case STILL_LAVA: $hasUpdate = true;
if($this->inBlock($pos)){ }
$this->harm(5, "lava"); break;
$this->fire = 300; case LAVA: // Lava damage
$this->updateMetadata(); case STILL_LAVA:
$hasUpdate = true; if($this->inBlock($pos)){
} $this->harm(5, "lava");
break; $this->fire = 300;
case FIRE: // Fire block damage $this->updateMetadata();
if($this->inBlock($pos)){ $hasUpdate = true;
$this->harm(1, "fire"); }
$this->fire = 300; break;
$this->updateMetadata(); case FIRE: // Fire block damage
$hasUpdate = true; if($this->inBlock($pos)){
} $this->harm(1, "fire");
break; $this->fire = 300;
case CACTUS: // Cactus damage $this->updateMetadata();
if($this->touchingBlock($pos)){ $hasUpdate = true;
$this->harm(1, "cactus"); }
$hasUpdate = true; break;
} case CACTUS: // Cactus damage
break; if($this->touchingBlock($pos)){
default: $this->harm(1, "cactus");
if($this->inBlock($pos, 0.7) and $y == $endY and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)){ $hasUpdate = true;
$this->harm(1, "suffocation"); // Suffocation }
$hasUpdate = true; break;
} elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){ default:
$this->air = 300; // Breathing if($this->inBlock($pos, 0.7) and $y == $endY and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)){
} $this->harm(1, "suffocation"); // Suffocation
break; $hasUpdate = true;
} elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){
$this->air = 300; // Breathing
}
break;
}
} }
} }
} }
} }
return $hasUpdate; return $hasUpdate;
} }
@ -491,35 +504,38 @@ class Entity extends Position
$endZ = ceil($this->z - 0.5 + $this->width + 1); $endZ = ceil($this->z - 0.5 + $this->width + 1);
$support = false; $support = false;
$isFlying = true; $isFlying = true;
for($z = $startZ; $z <= $endZ; ++ $z){ if($this->isPlayer()){
for($x = $startX; $x <= $endX; ++ $x){ for($z = $startZ; $z <= $endZ; ++ $z){
$v = new Vector3($x, $y, $z); for($x = $startX; $x <= $endX; ++ $x){
$v1 = new Vector3($x, $yC, $z); $v = new Vector3($x, $y, $z);
if($this->isSupport($v, $this->width)){ $v1 = new Vector3($x, $yC, $z);
$b = $this->level->getBlock($v); if($this->isSupport($v, $this->width)){
if($b->isSolid === true){ $b = $this->level->getBlock($v);
$support = true; if($b->isSolid === true){
$isFlying = false; $support = true;
break; $isFlying = false;
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){ break;
$isFlying = false; } elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
} $isFlying = false;
} elseif($this->isSupport($v1, $this->width)){ }
$b = $this->level->getBlock($v1); } elseif($this->isSupport($v1, $this->width)){
if($b->isSolid === true){ $b = $this->level->getBlock($v1);
$support = true; if($b->isSolid === true){
$isFlying = false; $support = true;
break; $isFlying = false;
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){ break;
$isFlying = false; } elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
$isFlying = false;
}
} }
} }
} if($support === true){
if($support === true){ break;
break; }
} }
} }
if($this->class !== ENTITY_PLAYER){
if(!$this->isPlayer()){
$update = false; $update = false;
$drag = 0.2; $drag = 0.2;
if(Utils::in_range($this->speedX, - 0.01, 0.01)){ if(Utils::in_range($this->speedX, - 0.01, 0.01)){
@ -532,14 +548,119 @@ class Entity extends Position
$this->speedY = 0; $this->speedY = 0;
} }
if(($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)) && ($this->speedX != 0 || $this->speedY != 0 || $this->speedZ != 0)){ if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)){
$blocks = $this->level->getCubes($this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ)); $aABB = $this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ);
foreach($blocks as $b){ $x0 = floor($aABB->minX);
$this->speedX = $b->calculateXOffset($this->boundingBox, $this->speedX); $x1 = ceil($aABB->maxX);
$this->speedY = $b->calculateYOffset($this->boundingBox, $this->speedY); $y0 = floor($aABB->minY);
$this->speedZ = $b->calculateZOffset($this->boundingBox, $this->speedZ); $y1 = round($aABB->maxY);
$z0 = floor($aABB->minZ);
$z1 = ceil($aABB->maxZ);
$x0 = $x0 < 0 ? 0 : $x0;
$y0 = $y0 < 0 ? 0 : $y0;
$z0 = $z0 < 0 ? 0 : $z0;
$x1 = $x1 > 256 ? 256 : $x1;
$y1 = $y1 > 128 ? 128 : $y1;
$z1 = $z1 > 256 ? 256 : $z1;
$waterDone = false;
for($x = $x0; $x < $x1; ++ $x){
for($y = $y0; $y < $y1; ++ $y){
for($z = $z0; $z < $z1; ++ $z){
$pos = new Vector3($x, $y, $z);
$b = $this->level->getBlock($pos);
switch($b->getID()) {
case WATER:
case STILL_WATER: // Drowing
if($this->fire > 0 and $this->inBlock($pos)){
$this->fire = 0;
$this->updateMetadata();
}
if($this->air <= 0){
$this->harm(2, "water");
$hasUpdate = true;
} elseif($x == ($endX - 1) and $y == $y1 and $z == ($endZ - 1) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and ! $waterDone){
$this->air -= 1;
$waterDone = true;
$this->updateMetadata();
$hasUpdate = true;
}
break;
case LAVA: // Lava damage
case STILL_LAVA:
if($this->inBlock($pos)){
$this->harm(5, "lava");
$this->fire = 300;
$this->updateMetadata();
$hasUpdate = true;
}
break;
case FIRE: // Fire block damage
if($this->inBlock($pos)){
$this->harm(1, "fire");
$this->fire = 300;
$this->updateMetadata();
$hasUpdate = true;
}
break;
case CACTUS: // Cactus damage
if($this->touchingBlock($pos)){
$this->harm(1, "cactus");
$hasUpdate = true;
}
break;
default:
if($this->inBlock($pos, 0.7) and $y == $y1 and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)){
$this->harm(1, "suffocation"); // Suffocation
$hasUpdate = true;
} elseif($x == ($endX - 1) and $y == $y1 and $z == ($endZ - 1)){
$this->air = 300; // Breathing
}
break;
}
if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid && $this->isMoving()){
$this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX);
$lastY = $this->speedY;
$this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY);
if($this->speedY == 0 && $lastY > 0){
$support = true;
}
$this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ);
}
}
}
}
}
for($z = $startZ; $z <= $endZ; ++ $z){
for($x = $startX; $x <= $endX; ++ $x){
$v = new Vector3($x, $y, $z);
$v1 = new Vector3($x, $yC, $z);
if($this->isSupport($v, $this->width)){
$b = $this->level->getBlock($v);
if($b->isSolid === true){
$support = true;
$isFlying = false;
break;
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
$isFlying = false;
}
} elseif($this->isSupport($v1, $this->width)){
$b = $this->level->getBlock($v1);
if($b->isSolid === true){
$support = true;
$isFlying = false;
break;
} elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
$isFlying = false;
}
}
}
if($support === true){
break;
} }
} }
if($this->speedX != 0){ if($this->speedX != 0){
$this->x += $this->speedX; $this->x += $this->speedX;
$this->speedX -= $this->speedX * $drag; $this->speedX -= $this->speedX * $drag;
@ -557,6 +678,7 @@ class Entity extends Position
$z = (int) ($this->z - 0.5); $z = (int) ($this->z - 0.5);
$lim = (int) floor($ny); $lim = (int) floor($ny);
for($y = (int) ceil($this->y) - 1; $y >= $lim; -- $y){ for($y = (int) ceil($this->y) - 1; $y >= $lim; -- $y){
if($this->level->getBlockWithoutVector($x, $y, $z)->isSolid === true){ if($this->level->getBlockWithoutVector($x, $y, $z)->isSolid === true){
$support = true; $support = true;
if($this->class === ENTITY_FALLING){ if($this->class === ENTITY_FALLING){
@ -580,7 +702,7 @@ class Entity extends Position
$this->speedY -= $this->speedY * $drag; $this->speedY -= $this->speedY * $drag;
$update = true; $update = true;
} }
$this->onGround = $support;
if($this->hasGravity && $support === false){ if($this->hasGravity && $support === false){
$this->speedY -= ($this->class === ENTITY_FALLING) ? 0.04 : ($this->class === ENTITY_ITEM ? 0.06 : 0.08); // TODO: replace with $gravity $this->speedY -= ($this->class === ENTITY_FALLING) ? 0.04 : ($this->class === ENTITY_ITEM ? 0.06 : 0.08); // TODO: replace with $gravity
$update = true; $update = true;
@ -589,9 +711,6 @@ class Entity extends Position
// $this->speedY = 0; // $this->speedY = 0;
// $this->speedZ = 0; // $this->speedZ = 0;
$this->server->api->handle("entity.move", $this); $this->server->api->handle("entity.move", $this);
if(($this->class === ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $this->speedY <= 0.1){
$this->server->api->handle("entity.motion", $this);
}
$update = true; $update = true;
} }
@ -1391,6 +1510,13 @@ class Entity extends Position
return "Entity(x={$this->x},y={$this->y},z={$this->z},level=" . $this->level->getName() . ",class={$this->class},type={$this->type})"; return "Entity(x={$this->x},y={$this->y},z={$this->z},level=" . $this->level->getName() . ",class={$this->class},type={$this->type})";
} }
/**
* Debug
*/
public function printSpeed(){
console("{$this->speedX}:{$this->speedY}:{$this->speedZ}");
}
/* /*
* Deprecated methods. * Deprecated methods.
* Those methods were left only for compability with older plugins * Those methods were left only for compability with older plugins

View file

@ -1,126 +1,126 @@
<?php <?php
class WaterBlock extends LiquidBlock{ class WaterBlock extends LiquidBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(WATER, $meta, "Water"); parent::__construct(WATER, $meta, "Water");
$this->hardness = 500; $this->hardness = 500;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }
public function getSourceCount(){ public function getSourceCount(){
$count = 0; $count = 0;
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
if( $this->getSide($side) instanceof WaterBlock ){ if( $this->getSide($side) instanceof WaterBlock ){
$b = $this->getSide($side); $b = $this->getSide($side);
$level = $b->meta & 0x07; $level = $b->meta & 0x07;
if($level == 0x00){ if($level == 0x00){
$count++; $count++;
} }
} }
} }
return $count; return $count;
} }
public function checkLava(){ public function checkLava(){
for($side = 0; $side <= 5; ++$side){ for($side = 0; $side <= 5; ++$side){
if($side == 1){ if($side == 1){
continue; continue;
} }
$b = $this->getSide($side); $b = $this->getSide($side);
if($b instanceof LavaBlock){ if($b instanceof LavaBlock){
$level = $b->meta & 0x07; $level = $b->meta & 0x07;
if($level == 0x00){ if($level == 0x00){
$this->level->setBlock($b, new ObsidianBlock(), false, false, true); $this->level->setBlock($b, new ObsidianBlock(), false, false, true);
}else{ }else{
$this->level->setBlock($b, new CobblestoneBlock(), false, false, true); $this->level->setBlock($b, new CobblestoneBlock(), false, false, true);
} }
return true; return true;
} }
} }
return false; return false;
} }
public function getFrom(){ public function getFrom(){
for($side = 0; $side <= 5; ++$side){ for($side = 0; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
$tlevel = $b->meta & 0x07; $tlevel = $b->meta & 0x07;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){
return $b; return $b;
} }
} }
} }
return null; return null;
} }
public function onUpdate($type){ public function onUpdate($type){
//return false; //return false;
$newId = $this->id; $newId = $this->id;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if($type !== BLOCK_UPDATE_NORMAL){ if($type !== BLOCK_UPDATE_NORMAL){
return false; return false;
} }
$this->checkLava(); $this->checkLava();
$falling = $this->meta >> 3; $falling = $this->meta >> 3;
$down = $this->getSide(0); $down = $this->getSide(0);
$from = $this->getFrom(); $from = $this->getFrom();
//Has Source or Its Source //Has Source or Its Source
if($from !== null || $level == 0x00){ if($from !== null || $level == 0x00){
if($down instanceof AirBlock || $down instanceof WaterBlock){ if($down instanceof AirBlock || $down instanceof WaterBlock){
$this->level->setBlock($down, new WaterBlock(0x01), false, false, true); $this->level->setBlock($down, new WaterBlock(0x00), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
}elseif($level !== 0x07){{ }elseif($level !== 0x07){{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
if( $this->getSourceCount() >= 2 && $level != 0x00){ if( $this->getSourceCount() >= 2 && $level != 0x00){
$this->level->setBlock($this, new WaterBlock(0), false, false, true); $this->level->setBlock($this, new WaterBlock(0), false, false, true);
} }
}elseif($b->isFlowable === true){ }elseif($b->isFlowable === true){
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
} }
} }
} }
} }
}else{ }else{
//Extend Remove for Left Waters //Extend Remove for Left Waters
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$sb = $this->getSide($side); $sb = $this->getSide($side);
if($sb instanceof WaterBlock){ if($sb instanceof WaterBlock){
$tlevel = $sb->meta & 0x07; $tlevel = $sb->meta & 0x07;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($sb, new AirBlock(), false, false, true); $this->level->setBlock($sb, new AirBlock(), false, false, true);
} }
} }
$b = $this->getSide(0)->getSide($side); $b = $this->getSide(0)->getSide($side);
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
$tlevel = $b->meta & 0x07; $tlevel = $b->meta & 0x07;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($b, new AirBlock(), false, false, true); $this->level->setBlock($b, new AirBlock(), false, false, true);
} }
} }
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); //ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($this, new AirBlock(), false, false, true); $this->level->setBlock($this, new AirBlock(), false, false, true);
} }
return false; return false;
} }
} }

View file

@ -89,8 +89,10 @@ class Level{
if($extra !== false){ if($extra !== false){
$entities = []; $entities = [];
foreach($this->server->api->entity->getAll($this) as $entity){ foreach($this->entityList as $entity){
$entities[] = $entity->createSaveData(); if($entity instanceof Entity){
$entities[] = $entity->createSaveData();
}
} }
$this->entities->setAll($entities); $this->entities->setAll($entities);
$this->entities->save(); $this->entities->save();