diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index fe9efb07..137b3c6e 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -14,7 +14,6 @@ class EntityAPI{ } public function init(){ - $this->server->schedule(25, [$this, "updateEntities"], [], true); $this->server->api->console->register("summon", "", [$this, "commandHandler"]); $this->server->api->console->register("spawnmob", "", [$this, "commandHandler"]); $this->server->api->console->register("despawn", "", [$this, "CommandHandler"]); @@ -102,7 +101,13 @@ class EntityAPI{ break; }else{ 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{ $array = explode(",", strtolower($args[0])); if(count($array) > 4){ @@ -117,18 +122,19 @@ class EntityAPI{ } $despawning = substr($list, 0, -4); $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){ - $e = $this->get($e["EID"]); - if($e instanceof Entity){ - $this->remove($e->eid); - $cnt++; - } - } - } - $output .= "$cnt entities have been despawned!"; + + $output = "$cnt entities have been despawned!"; break; } return $output; @@ -174,38 +180,21 @@ class EntityAPI{ public function remove($eid){ if(isset($this->entities[$eid])){ - $entity = $this->entities[$eid]; - $this->entities[$eid] = null; - unset($this->entities[$eid]); - $entity->closed = true; - $this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";"); - if($entity->class === ENTITY_PLAYER){ + $this->entities[$eid]->closed = true; + if($this->entities[$eid]->isPlayer()){ $pk = new RemovePlayerPacket; - $pk->eid = $entity->eid; + $pk->eid = $eid; $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{ $pk = new RemoveEntityPacket; - $pk->eid = $entity->eid; - $this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), $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 . ";"); - } + $pk->eid = $eid; + $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk); } + $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 . ";"); } } diff --git a/src/Player.php b/src/Player.php index 78d58b7c..ab58dc86 100755 --- a/src/Player.php +++ b/src/Player.php @@ -284,7 +284,7 @@ class Player{ $packet->messageIndex = $this->counter[3]++; $packet->reliability = 2; - $this->buffer->data[] = $packet; + @$this->buffer->data[] = $packet; $this->bufferLen += 6 + $len; return []; } @@ -760,7 +760,7 @@ class Player{ if($data->eid === $this->eid or $data->level !== $this->level){ 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; } $pk = new SetEntityMotionPacket; @@ -769,6 +769,9 @@ class Player{ $pk->speedY = $data->speedY; $pk->speedZ = $data->speedZ; $this->dataPacket($pk); + $data->lastSpeedZ = $data->speedZ; + $data->lastSpeedY = $data->speedY; + $data->lastSpeedX = $data->speedX; break; case "entity.animate": if($data["eid"] === $this->eid or $data["entity"]->level->getName() === $this->level->getName()){ diff --git a/src/entity/Entity.php b/src/entity/Entity.php index b874319d..acacd4fc 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -24,14 +24,21 @@ class Entity extends Position public $eid; public $type; public $name; - public $x; - public $y; - public $z; - public $speedX; - public $speedY; - public $speedZ; - public $speed; - public $lastX = 0, $lastY = 0, $lastZ = 0, $lastYaw = 0, $lastPitch = 0, $lastTime = 0, $lastHeadYaw = 0; + public $x, $y, $z; + public $speedX, $speedY, $speedZ, $speed; + public $lastX = 0, $lastY = 0, $lastZ = 0, $lastYaw = 0, $lastPitch = 0, $lastTime = 0, $lastHeadYaw = 0, $lastSpeedX = 0, $lastSpeedY = 0, $lastSpeedZ = 0; + /** + * 0 = lastX, + * 1 = lastY, + * 2 = lastZ, + * 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 $yaw, $headYaw; public $pitch; @@ -393,63 +400,69 @@ class Entity extends Position $endY = $startY + 2; $endZ = $startZ + 2; $waterDone = false; - for($y = $startY; $y <= $endY; ++ $y){ - for($x = $startX; $x <= $endX; ++ $x){ - for($z = $startZ; $z <= $endZ; ++ $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 == $endY 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 == $endY 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 == $endY and $z == ($endZ - 1)){ - $this->air = 300; // Breathing - } - break; + if($this->isPlayer()){ + + } + if($this->isPlayer()){ + for($y = $startY; $y <= $endY; ++ $y){ + for($x = $startX; $x <= $endX; ++ $x){ + for($z = $startZ; $z <= $endZ; ++ $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 == $endY 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 == $endY 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 == $endY and $z == ($endZ - 1)){ + $this->air = 300; // Breathing + } + break; + } } } } } + return $hasUpdate; } @@ -491,35 +504,38 @@ class Entity extends Position $endZ = ceil($this->z - 0.5 + $this->width + 1); $support = false; $isFlying = true; - 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($this->isPlayer()){ + 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($support === true){ + break; + } } } - if($this->class !== ENTITY_PLAYER){ + + if(!$this->isPlayer()){ $update = false; $drag = 0.2; if(Utils::in_range($this->speedX, - 0.01, 0.01)){ @@ -532,14 +548,119 @@ class Entity extends Position $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)){ - $blocks = $this->level->getCubes($this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ)); - foreach($blocks as $b){ - $this->speedX = $b->calculateXOffset($this->boundingBox, $this->speedX); - $this->speedY = $b->calculateYOffset($this->boundingBox, $this->speedY); - $this->speedZ = $b->calculateZOffset($this->boundingBox, $this->speedZ); + if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)){ + $aABB = $this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ); + $x0 = floor($aABB->minX); + $x1 = ceil($aABB->maxX); + $y0 = floor($aABB->minY); + $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){ $this->x += $this->speedX; $this->speedX -= $this->speedX * $drag; @@ -557,6 +678,7 @@ class Entity extends Position $z = (int) ($this->z - 0.5); $lim = (int) floor($ny); for($y = (int) ceil($this->y) - 1; $y >= $lim; -- $y){ + if($this->level->getBlockWithoutVector($x, $y, $z)->isSolid === true){ $support = true; if($this->class === ENTITY_FALLING){ @@ -580,7 +702,7 @@ class Entity extends Position $this->speedY -= $this->speedY * $drag; $update = true; } - + $this->onGround = $support; 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 $update = true; @@ -589,9 +711,6 @@ class Entity extends Position // $this->speedY = 0; // $this->speedZ = 0; $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; } @@ -1390,7 +1509,14 @@ 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})"; } - + + /** + * Debug + */ + public function printSpeed(){ + console("{$this->speedX}:{$this->speedY}:{$this->speedZ}"); + } + /* * Deprecated methods. * Those methods were left only for compability with older plugins diff --git a/src/material/block/liquid/Water.php b/src/material/block/liquid/Water.php index af2ce38d..2d766ae4 100644 --- a/src/material/block/liquid/Water.php +++ b/src/material/block/liquid/Water.php @@ -1,126 +1,126 @@ hardness = 500; - } - - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $ret = $this->level->setBlock($this, $this, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); - return $ret; - } - - public function getSourceCount(){ - $count = 0; - for($side = 2; $side <= 5; ++$side){ - if( $this->getSide($side) instanceof WaterBlock ){ - $b = $this->getSide($side); - $level = $b->meta & 0x07; - if($level == 0x00){ - $count++; - } - } - } - return $count; - } - - public function checkLava(){ - for($side = 0; $side <= 5; ++$side){ - if($side == 1){ - continue; - } - $b = $this->getSide($side); - if($b instanceof LavaBlock){ - $level = $b->meta & 0x07; - if($level == 0x00){ - $this->level->setBlock($b, new ObsidianBlock(), false, false, true); - }else{ - $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); - } - return true; - } - } - return false; - } - - public function getFrom(){ - for($side = 0; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - $tlevel = $b->meta & 0x07; - $level = $this->meta & 0x07; - if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ - return $b; - } - } - } - return null; - } - - public function onUpdate($type){ - //return false; - $newId = $this->id; - $level = $this->meta & 0x07; - if($type !== BLOCK_UPDATE_NORMAL){ - return false; - } - - $this->checkLava(); - - $falling = $this->meta >> 3; - $down = $this->getSide(0); - - $from = $this->getFrom(); - //Has Source or Its Source - if($from !== null || $level == 0x00){ - if($down instanceof AirBlock || $down instanceof WaterBlock){ - $this->level->setBlock($down, new WaterBlock(0x01), false, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); - }elseif($level !== 0x07){{ - for($side = 2; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - if( $this->getSourceCount() >= 2 && $level != 0x00){ - $this->level->setBlock($this, new WaterBlock(0), false, false, true); - } - }elseif($b->isFlowable === 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); - } - } - } - } - }else{ - //Extend Remove for Left Waters - for($side = 2; $side <= 5; ++$side){ - $sb = $this->getSide($side); - if($sb instanceof WaterBlock){ - $tlevel = $sb->meta & 0x07; - if($tlevel != 0x00){ - for ($s = 0; $s <= 5; $s++) { - $ssb = $sb->getSide($s); - 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); - } - } - $b = $this->getSide(0)->getSide($side); - if($b instanceof WaterBlock){ - $tlevel = $b->meta & 0x07; - if($tlevel != 0x00){ - for ($s = 0; $s <= 5; $s++) { - $ssb = $sb->getSide($s); - 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); - } - } - //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); - } - return false; - } -} + public function __construct($meta = 0){ + parent::__construct(WATER, $meta, "Water"); + $this->hardness = 500; + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $ret = $this->level->setBlock($this, $this, true, false, true); + ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); + return $ret; + } + + public function getSourceCount(){ + $count = 0; + for($side = 2; $side <= 5; ++$side){ + if( $this->getSide($side) instanceof WaterBlock ){ + $b = $this->getSide($side); + $level = $b->meta & 0x07; + if($level == 0x00){ + $count++; + } + } + } + return $count; + } + + public function checkLava(){ + for($side = 0; $side <= 5; ++$side){ + if($side == 1){ + continue; + } + $b = $this->getSide($side); + if($b instanceof LavaBlock){ + $level = $b->meta & 0x07; + if($level == 0x00){ + $this->level->setBlock($b, new ObsidianBlock(), false, false, true); + }else{ + $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); + } + return true; + } + } + return false; + } + + public function getFrom(){ + for($side = 0; $side <= 5; ++$side){ + $b = $this->getSide($side); + if($b instanceof WaterBlock){ + $tlevel = $b->meta & 0x07; + $level = $this->meta & 0x07; + if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ + return $b; + } + } + } + return null; + } + + public function onUpdate($type){ + //return false; + $newId = $this->id; + $level = $this->meta & 0x07; + if($type !== BLOCK_UPDATE_NORMAL){ + return false; + } + + $this->checkLava(); + + $falling = $this->meta >> 3; + $down = $this->getSide(0); + + $from = $this->getFrom(); + //Has Source or Its Source + if($from !== null || $level == 0x00){ + if($down instanceof AirBlock || $down instanceof WaterBlock){ + $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); + }elseif($level !== 0x07){{ + for($side = 2; $side <= 5; ++$side){ + $b = $this->getSide($side); + if($b instanceof WaterBlock){ + if( $this->getSourceCount() >= 2 && $level != 0x00){ + $this->level->setBlock($this, new WaterBlock(0), false, false, true); + } + }elseif($b->isFlowable === 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); + } + } + } + } + }else{ + //Extend Remove for Left Waters + for($side = 2; $side <= 5; ++$side){ + $sb = $this->getSide($side); + if($sb instanceof WaterBlock){ + $tlevel = $sb->meta & 0x07; + if($tlevel != 0x00){ + for ($s = 0; $s <= 5; $s++) { + $ssb = $sb->getSide($s); + 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); + } + } + $b = $this->getSide(0)->getSide($side); + if($b instanceof WaterBlock){ + $tlevel = $b->meta & 0x07; + if($tlevel != 0x00){ + for ($s = 0; $s <= 5; $s++) { + $ssb = $sb->getSide($s); + 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); + } + } + //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); + } + return false; + } +} \ No newline at end of file diff --git a/src/world/Level.php b/src/world/Level.php index 2382c7e1..1c10ba84 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -89,8 +89,10 @@ class Level{ if($extra !== false){ $entities = []; - foreach($this->server->api->entity->getAll($this) as $entity){ - $entities[] = $entity->createSaveData(); + foreach($this->entityList as $entity){ + if($entity instanceof Entity){ + $entities[] = $entity->createSaveData(); + } } $this->entities->setAll($entities); $this->entities->save();