mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Kind of Water spreading
This commit is contained in:
parent
a1b51c3da4
commit
c646b786e5
@ -39,7 +39,7 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function init(){
|
public function init(){
|
||||||
$this->server->addHandler("world.block.update", array($this, "handle"));
|
$this->server->addHandler("world.block.update", array($this, "updateBlockRemote"));
|
||||||
$this->server->addHandler("player.block.break", array($this, "blockBreak"));
|
$this->server->addHandler("player.block.break", array($this, "blockBreak"));
|
||||||
$this->server->addHandler("player.block.action", array($this, "blockAction"));
|
$this->server->addHandler("player.block.action", array($this, "blockAction"));
|
||||||
}
|
}
|
||||||
@ -176,7 +176,6 @@ class BlockAPI{
|
|||||||
$cancelPlace = true;
|
$cancelPlace = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($cancelPlace === true or $data["face"] < 0 or $data["face"] > 5){
|
if($cancelPlace === true or $data["face"] < 0 or $data["face"] > 5){
|
||||||
@ -347,6 +346,7 @@ class BlockAPI{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->server->trigger("player.block.place", $data);
|
$this->server->trigger("player.block.place", $data);
|
||||||
|
$this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,15 +354,82 @@ class BlockAPI{
|
|||||||
$this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_SCHEDULED);
|
$this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_SCHEDULED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateBlock($x, $y, $z, $type){
|
public function updateBlockRemote($data, $event){
|
||||||
|
if($event !== "world.block.update"){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->updateBlock($data["x"], $data["y"], $data["z"], isset($data["type"]) ? $data["type"]:BLOCK_UPDATE_RANDOM);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateBlock($x, $y, $z, $type = BLOCK_UPDATE_NORMAL){
|
||||||
$block = $this->server->api->level->getBlock($x, $y, $z);
|
$block = $this->server->api->level->getBlock($x, $y, $z);
|
||||||
$changed = false;
|
$changed = false;
|
||||||
|
|
||||||
switch($block[0]){
|
switch($block[0]){
|
||||||
|
case 8:
|
||||||
|
case 9:
|
||||||
|
$blockDown = $this->server->api->level->getBlock($x, $y - 1, $z);
|
||||||
|
$down = false;
|
||||||
|
if(isset(Material::$flowable[$blockDown[0]])){
|
||||||
|
$this->server->schedule(5, array($this, "blockScheduler"), array(
|
||||||
|
"x" => $x,
|
||||||
|
"y" => $y - 1,
|
||||||
|
"z" => $z,
|
||||||
|
"type" => BLOCK_UPDATE_NORMAL,
|
||||||
|
));
|
||||||
|
$this->server->api->level->setBlock($x, $y - 1, $z, 8, 8);
|
||||||
|
if($down[0] !== 9){
|
||||||
|
$down = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(($block[1] & 0x07) < 7 and ($down === false or $block[0] === 9)){
|
||||||
|
$b0 = $this->server->api->level->getBlock($x + 1, $y, $z);
|
||||||
|
if(isset(Material::$flowable[$b0[0]]) and $b0[0] !== 9){
|
||||||
|
$this->server->schedule(10, array($this, "blockScheduler"), array(
|
||||||
|
"x" => $x + 1,
|
||||||
|
"y" => $y,
|
||||||
|
"z" => $z,
|
||||||
|
"type" => BLOCK_UPDATE_NORMAL,
|
||||||
|
));
|
||||||
|
$this->server->api->level->setBlock($x + 1, $y, $z, 8, ($block[1] + 1) & 0x07);
|
||||||
|
}
|
||||||
|
$b1 = $this->server->api->level->getBlock($x - 1, $y, $z);
|
||||||
|
if(isset(Material::$flowable[$b1[0]]) and $b1[0] !== 9){
|
||||||
|
$this->server->schedule(10, array($this, "blockScheduler"), array(
|
||||||
|
"x" => $x - 1,
|
||||||
|
"y" => $y,
|
||||||
|
"z" => $z,
|
||||||
|
"type" => BLOCK_UPDATE_NORMAL,
|
||||||
|
));
|
||||||
|
$this->server->api->level->setBlock($x - 1, $y, $z, 8, ($block[1] + 1) & 0x07);
|
||||||
|
}
|
||||||
|
$b2 = $this->server->api->level->getBlock($x, $y, $z + 1);
|
||||||
|
if(isset(Material::$flowable[$b2[0]]) and $b2[0] !== 9){
|
||||||
|
$this->server->schedule(10, array($this, "blockScheduler"), array(
|
||||||
|
"x" => $x,
|
||||||
|
"y" => $y,
|
||||||
|
"z" => $z + 1,
|
||||||
|
"type" => BLOCK_UPDATE_NORMAL,
|
||||||
|
));
|
||||||
|
$this->server->api->level->setBlock($x, $y, $z + 1, 8, ($block[1] + 1) & 0x07);
|
||||||
|
}
|
||||||
|
$b3 = $this->server->api->level->getBlock($x, $y, $z - 1);
|
||||||
|
if(isset(Material::$flowable[$b3[0]]) and $b3[0] !== 9){
|
||||||
|
$this->server->schedule(10, array($this, "blockScheduler"), array(
|
||||||
|
"x" => $x,
|
||||||
|
"y" => $y,
|
||||||
|
"z" => $z - 1,
|
||||||
|
"type" => BLOCK_UPDATE_NORMAL,
|
||||||
|
));
|
||||||
|
$this->server->api->level->setBlock($x, $y, $z - 1, 8, ($block[1] + 1) & 0x07);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 74:
|
case 74:
|
||||||
if($type === BLOCK_UPDATE_SCHEDULED){
|
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
|
||||||
$changed = true;
|
$changed = true;
|
||||||
$this->server->api->level->setBlock($x, $y, $z, 73, $block[1]);
|
$this->server->api->level->setBlock($x, $y, $z, 73, $block[1]);
|
||||||
|
$type = BLOCK_UPDATE_WEAK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 73:
|
case 73:
|
||||||
|
@ -26,13 +26,11 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class LevelAPI{
|
class LevelAPI{
|
||||||
private $server, $map, $active = false;
|
private $server, $map;
|
||||||
function __construct($server){
|
function __construct($server){
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->map = $this->server->map;
|
$this->map = $this->server->map;
|
||||||
if($this->map !== false){
|
$this->heightMap = array_fill(0, 256, array());
|
||||||
$this->active = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init(){
|
public function init(){
|
||||||
@ -58,41 +56,24 @@ class LevelAPI{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function check(){
|
|
||||||
if($this->active === true){
|
|
||||||
return true;
|
|
||||||
}elseif($this->active === false and $this->server->map === false){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$this->active = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getChunk($X, $Z){
|
public function getChunk($X, $Z){
|
||||||
if($this->check() and isset($this->map->map[$X][$Z])){
|
return $this->map->map[$X][$Z];
|
||||||
return $this->map->map[$X][$Z];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlock($x, $y, $z){
|
public function getBlock($x, $y, $z){
|
||||||
if($this->check()){
|
return $this->map->getBlock($x, $y, $z);
|
||||||
return $this->map->getBlock($x, $y, $z);
|
|
||||||
}
|
|
||||||
return array(0,0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFloor($x, $z){
|
public function getFloor($x, $z){
|
||||||
if($this->check()){
|
if(!isset($this->heightMap[$z][$x])){
|
||||||
return $this->map->getFloor($x, $z);
|
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
|
||||||
}
|
}
|
||||||
return 0;
|
return $this->heightMap[$z][$x];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlock($x, $y, $z, $block, $meta = 0){
|
public function setBlock($x, $y, $z, $block, $meta = 0){
|
||||||
if($this->check()){
|
$this->map->setBlock($x, $y, $z, $block, $meta);
|
||||||
$this->map->setBlock($x, $y, $z, $block, $meta);
|
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
|
||||||
}
|
|
||||||
$this->server->trigger("world.block.change", array(
|
$this->server->trigger("world.block.change", array(
|
||||||
"x" => $x,
|
"x" => $x,
|
||||||
"y" => $y,
|
"y" => $y,
|
||||||
@ -105,9 +86,6 @@ class LevelAPI{
|
|||||||
public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){
|
public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){
|
||||||
$columnsPerPacket = max(1, (int) $columnsPerPacket);
|
$columnsPerPacket = max(1, (int) $columnsPerPacket);
|
||||||
$c = $this->getChunk($X, $Z);
|
$c = $this->getChunk($X, $Z);
|
||||||
if($c === false){
|
|
||||||
return array(str_repeat("\x00", 256));
|
|
||||||
}
|
|
||||||
$ordered = array();
|
$ordered = array();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$cnt = 0;
|
$cnt = 0;
|
||||||
|
@ -26,6 +26,25 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Material{
|
class Material{
|
||||||
|
static $flowable = array(
|
||||||
|
0 => true,
|
||||||
|
6 => true,
|
||||||
|
//8 => true,
|
||||||
|
//9 => true,
|
||||||
|
30 => true,
|
||||||
|
31 => true,
|
||||||
|
32 => true,
|
||||||
|
37 => true,
|
||||||
|
38 => true,
|
||||||
|
39 => true,
|
||||||
|
40 => true,
|
||||||
|
50 => true,
|
||||||
|
51 => true,
|
||||||
|
55 => true,
|
||||||
|
59 => true,
|
||||||
|
78 => true,
|
||||||
|
105 => true,
|
||||||
|
);
|
||||||
static $unbreakable = array(
|
static $unbreakable = array(
|
||||||
0 => true,
|
0 => true,
|
||||||
7 => true,
|
7 => true,
|
||||||
|
@ -102,16 +102,16 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
public function startDatabase(){
|
public function startDatabase(){
|
||||||
$this->preparedSQL = new stdClass();
|
$this->preparedSQL = new stdClass();
|
||||||
$this->database = new SQLite3(":memory:");
|
$this->database = new SQLite3(":memory:");
|
||||||
$this->query("PRAGMA journal_mode = OFF;");
|
//$this->query("PRAGMA journal_mode = OFF;");
|
||||||
$this->query("PRAGMA encoding = \"UTF-8\";");
|
//$this->query("PRAGMA encoding = \"UTF-8\";");
|
||||||
$this->query("PRAGMA secure_delete = OFF;");
|
//$this->query("PRAGMA secure_delete = OFF;");
|
||||||
$this->query("CREATE TABLE players (clientID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE);");
|
$this->query("CREATE TABLE players (clientID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE);");
|
||||||
$this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, type NUMERIC, class NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);");
|
$this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, type NUMERIC, class NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);");
|
||||||
$this->query("CREATE TABLE metadata (EID INTEGER PRIMARY KEY, name TEXT, value TEXT);");
|
$this->query("CREATE TABLE metadata (EID INTEGER PRIMARY KEY, name TEXT, value TEXT);");
|
||||||
$this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);");
|
$this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);");
|
||||||
$this->query("CREATE TABLE events (ID INTEGER PRIMARY KEY, name TEXT);");
|
$this->query("CREATE TABLE events (ID INTEGER PRIMARY KEY, name TEXT);");
|
||||||
$this->query("CREATE TABLE handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);");
|
$this->query("CREATE TABLE handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);");
|
||||||
$this->query("PRAGMA synchronous = OFF;");
|
//$this->query("PRAGMA synchronous = OFF;");
|
||||||
$this->preparedSQL->selectHandlers = $this->database->prepare("SELECT ID FROM handlers WHERE name = :name ORDER BY priority DESC;");
|
$this->preparedSQL->selectHandlers = $this->database->prepare("SELECT ID FROM handlers WHERE name = :name ORDER BY priority DESC;");
|
||||||
$this->preparedSQL->selectEvents = $this->database->prepare("SELECT ID FROM events WHERE name = :name;");
|
$this->preparedSQL->selectEvents = $this->database->prepare("SELECT ID FROM events WHERE name = :name;");
|
||||||
$this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);");
|
$this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);");
|
||||||
@ -429,14 +429,11 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function process(){
|
public function process(){
|
||||||
$cnt = 0;
|
|
||||||
while($this->stop === false){
|
while($this->stop === false){
|
||||||
$packet = @$this->interface->readPacket();
|
$packet = @$this->interface->readPacket();
|
||||||
if($packet !== false and $cnt < 20){
|
if($packet !== false){
|
||||||
$this->packetHandler($packet);
|
$this->packetHandler($packet);
|
||||||
++$cnt;
|
|
||||||
}else{
|
}else{
|
||||||
$cnt = 0;
|
|
||||||
usleep(1);
|
usleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,12 +464,16 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function schedule($ticks, $callback, $data = array(), $eventName = "server.schedule"){
|
public function schedule($ticks, $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){
|
||||||
if(!is_callable($callback)){
|
if(!is_callable($callback)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$add = "";
|
||||||
|
if($repeat === false){
|
||||||
|
$add = ' unset($this->schedule['.$this->scheduleCnt.']);';
|
||||||
|
}
|
||||||
$this->schedule[$this->scheduleCnt] = array($callback, $data, $eventName);
|
$this->schedule[$this->scheduleCnt] = array($callback, $data, $eventName);
|
||||||
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.']; unset($this->schedule['.$this->scheduleCnt.']); call_user_func($schedule[0], $schedule[1], $schedule[2]);', false);
|
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.' call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat);
|
||||||
return $this->scheduleCnt++;
|
return $this->scheduleCnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user