mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Plant growth & scheduled updates!
This commit is contained in:
parent
be9676ebe5
commit
dce9b3140a
@ -191,7 +191,7 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function init(){
|
public function init(){
|
||||||
$this->server->event("server.tick", array($this, "blockUpdateTick"));
|
$this->server->schedule(1, array($this, "blockUpdateTick"), array(), true);
|
||||||
$this->server->api->console->register("give", "<player> <item[:damage]> [amount]", array($this, "commandHandler"));
|
$this->server->api->console->register("give", "<player> <item[:damage]> [amount]", array($this, "commandHandler"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,11 +728,14 @@ class BlockAPI{
|
|||||||
if(!($pos instanceof Block)){
|
if(!($pos instanceof Block)){
|
||||||
$block = $pos->level->getBlock($pos);
|
$block = $pos->level->getBlock($pos);
|
||||||
}else{
|
}else{
|
||||||
$block = $pos;
|
$pos = new Position($pos->x, $pos->y, $pos->z, $pos->level);
|
||||||
|
$block = $pos->level->getBlock($pos);
|
||||||
}
|
}
|
||||||
$level = $block->onUpdate($type);
|
$level = $block->onUpdate($type);
|
||||||
if($level === BLOCK_UPDATE_NORMAL){
|
if($level === BLOCK_UPDATE_NORMAL){
|
||||||
$this->blockUpdateAround($block, $level);
|
$this->blockUpdateAround($block, $level);
|
||||||
|
}elseif($level === BLOCK_UPDATE_RANDOM){
|
||||||
|
$this->scheduleBlockUpdate($pos, Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||||
}
|
}
|
||||||
return $level;
|
return $level;
|
||||||
}
|
}
|
||||||
@ -743,33 +746,27 @@ class BlockAPI{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$index = $pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName();
|
$index = $pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".$type;
|
||||||
$delay = microtime(true) + $delay * 0.05;
|
$delay = microtime(true) + $delay * 0.05;
|
||||||
if(!isset($this->scheduledUpdates[$index])){
|
if(!isset($this->scheduledUpdates[$index])){
|
||||||
$this->scheduledUpdates[$index] = array(
|
$this->scheduledUpdates[$index] = $pos;
|
||||||
$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.");");
|
||||||
$type,
|
|
||||||
$delay,
|
|
||||||
);
|
|
||||||
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, delay) VALUES (".$pos->x.", ".$pos->y.", ".$pos->z.", '".$pos->level->getName()."', ".$delay.");");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function blockUpdateTick($time, $event){
|
public function blockUpdateTick(){
|
||||||
if($event !== "server.tick"){ //WTF??
|
$time = microtime(true);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(count($this->scheduledUpdates) > 0){
|
if(count($this->scheduledUpdates) > 0){
|
||||||
$update = $this->server->query("SELECT x,y,z,level FROM blockUpdates WHERE delay <= ".$time.";");
|
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= ".$time.";");
|
||||||
if($update !== false and $update !== true){
|
if($update !== false and $update !== true){
|
||||||
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
|
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
$index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"];
|
$index = $up["x"].".".$up["y"].".".$up["z"].".".$up["level"].".".$up["type"];
|
||||||
if(isset($this->scheduledUpdates[$index])){
|
if(isset($this->scheduledUpdates[$index])){
|
||||||
$up = $this->scheduledUpdates[$index];
|
$upp = $this->scheduledUpdates[$index];
|
||||||
unset($this->scheduledUpdates[$index]);
|
unset($this->scheduledUpdates[$index]);
|
||||||
$this->blockUpdate($up[0], $up[1]);
|
$this->blockUpdate($upp, (int) $up["type"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ class LevelAPI{
|
|||||||
}
|
}
|
||||||
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed);
|
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed);
|
||||||
$gen->generate();
|
$gen->generate();
|
||||||
|
$gen->close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +160,8 @@ class LevelAPI{
|
|||||||
@rename($path."tileEntities.yml", $path."tiles.yml");
|
@rename($path."tileEntities.yml", $path."tiles.yml");
|
||||||
}
|
}
|
||||||
$tiles = new Config($path."tiles.yml", CONFIG_YAML);
|
$tiles = new Config($path."tiles.yml", CONFIG_YAML);
|
||||||
$this->levels[$name] = new Level($level, $entities, $tiles, $name);
|
$blockUpdates = new Config($path."bupdates.yml", CONFIG_YAML);
|
||||||
|
$this->levels[$name] = new Level($level, $entities, $tiles, $blockUpdates, $name);
|
||||||
foreach($entities->getAll() as $entity){
|
foreach($entities->getAll() as $entity){
|
||||||
if(!isset($entity["id"])){
|
if(!isset($entity["id"])){
|
||||||
break;
|
break;
|
||||||
@ -195,6 +197,11 @@ class LevelAPI{
|
|||||||
}
|
}
|
||||||
$t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile);
|
$t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$timeu = microtime(true);
|
||||||
|
foreach($blockUpdates->getAll() as $bupdate){
|
||||||
|
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), $bupdate["delay"], (int) $bupdate["type"]);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -742,8 +742,8 @@ class Player{
|
|||||||
$this->lag = array();
|
$this->lag = array();
|
||||||
$this->sendBuffer();
|
$this->sendBuffer();
|
||||||
if($this->packetLoss >= PLAYER_MAX_PACKET_LOSS){
|
if($this->packetLoss >= PLAYER_MAX_PACKET_LOSS){
|
||||||
$this->sendChat("Your connection suffers high packet loss");
|
//$this->sendChat("Your connection suffers high packet loss");
|
||||||
$this->close("packet.loss");
|
//$this->close("packet.loss");
|
||||||
}
|
}
|
||||||
$this->lastMeasure = microtime(true);
|
$this->lastMeasure = microtime(true);
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ class PocketMinecraftServer{
|
|||||||
$this->query("CREATE TABLE tiles (ID INTEGER PRIMARY KEY, level TEXT, class TEXT, x NUMERIC, y NUMERIC, z NUMERIC, spawnable NUMERIC);");
|
$this->query("CREATE TABLE tiles (ID INTEGER PRIMARY KEY, level TEXT, class TEXT, x NUMERIC, y NUMERIC, z NUMERIC, spawnable NUMERIC);");
|
||||||
$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 handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);");
|
$this->query("CREATE TABLE handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);");
|
||||||
$this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, delay NUMERIC);");
|
$this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, type INTEGER, delay NUMERIC);");
|
||||||
//$this->query("PRAGMA synchronous = OFF;");
|
//$this->query("PRAGMA synchronous = OFF;");
|
||||||
$this->preparedSQL->selectHandlers = $this->database->prepare("SELECT DISTINCT ID FROM handlers WHERE name = :name ORDER BY priority DESC;");
|
$this->preparedSQL->selectHandlers = $this->database->prepare("SELECT DISTINCT ID FROM handlers WHERE name = :name ORDER BY priority DESC;");
|
||||||
$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);");
|
||||||
|
@ -35,7 +35,7 @@ class GlowingRedstoneOreBlock extends SolidBlock{
|
|||||||
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false);
|
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false);
|
||||||
return BLOCK_UPDATE_WEAK;
|
return BLOCK_UPDATE_WEAK;
|
||||||
}else{
|
}else{
|
||||||
$this->level->scheduleBlockUpdate($this, mt_rand(45, 100));
|
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class RedstoneOreBlock extends SolidBlock{
|
|||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){
|
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){
|
||||||
$this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false);
|
$this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false);
|
||||||
$this->level->scheduleBlockUpdate($this, mt_rand(45, 100));
|
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||||
return BLOCK_UPDATE_WEAK;
|
return BLOCK_UPDATE_WEAK;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -26,19 +26,37 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class CactusBlock extends TransparentBlock{
|
class CactusBlock extends TransparentBlock{
|
||||||
public function __construct(){
|
public function __construct($meta = 0){
|
||||||
parent::__construct(CACTUS, 0, "Cactus");
|
parent::__construct(CACTUS, $meta, "Cactus");
|
||||||
$this->isFullBlock = false;
|
$this->isFullBlock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($type === BLOCK_UPDATE_NORMAL){
|
||||||
$down = $this->getSide(0)->getID();
|
$down = $this->getSide(0);
|
||||||
if($down !== SAND and $down !== CACTUS){ //Replace wit common break method
|
if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace wit common break method
|
||||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
|
||||||
$this->level->setBlock($this, new AirBlock(), false);
|
$this->level->setBlock($this, new AirBlock(), false);
|
||||||
|
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||||
return BLOCK_UPDATE_NORMAL;
|
return BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||||
|
if($this->getSide(0)->getID() !== CACTUS){
|
||||||
|
if($this->meta == 0x0F){
|
||||||
|
for($y = 1; $y < 3; ++$y){
|
||||||
|
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||||
|
if($b->getID() === AIR){
|
||||||
|
$this->level->setBlock($b, new CactusBlock());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->meta = 0;
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
}else{
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
}
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -51,11 +69,17 @@ class CactusBlock extends TransparentBlock{
|
|||||||
$block2 = $this->getSide(4);
|
$block2 = $this->getSide(4);
|
||||||
$block3 = $this->getSide(5);
|
$block3 = $this->getSide(5);
|
||||||
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
||||||
$this->level->setBlock($block, $this);
|
$this->level->setBlock($this, $this);
|
||||||
|
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item, Player $player){
|
||||||
|
return array(
|
||||||
|
array($this->id, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -34,6 +34,7 @@ class MelonStemBlock extends FlowableBlock{
|
|||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === FARMLAND){
|
if($down->getID() === FARMLAND){
|
||||||
$this->level->setBlock($block, $this);
|
$this->level->setBlock($block, $this);
|
||||||
|
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -46,6 +47,27 @@ class MelonStemBlock extends FlowableBlock{
|
|||||||
$this->level->setBlock($this, new AirBlock(), false);
|
$this->level->setBlock($this, new AirBlock(), false);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
return BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||||
|
if(mt_rand(0, 2) == 1){
|
||||||
|
if($this->meta < 0x07){
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
|
}else{
|
||||||
|
for($side = 2; $side <= 5; ++$side){
|
||||||
|
$b = $this->getSide($side);
|
||||||
|
if($b->getID() === MELON_BLOCK){
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$side = $this->getSide(mt_rand(2,5));
|
||||||
|
$d = $side->getSide(0);
|
||||||
|
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
|
||||||
|
$this->level->setBlock($side, new MelonBlock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ class SaplingBlock extends FlowableBlock{
|
|||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
|
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
|
||||||
$this->level->setBlock($block, $this);
|
$this->level->setBlock($block, $this);
|
||||||
|
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -65,12 +66,17 @@ class SaplingBlock extends FlowableBlock{
|
|||||||
$this->level->setBlock($this, new AirBlock(), false);
|
$this->level->setBlock($this, new AirBlock(), false);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
return BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
}elseif($type === BLOCK_UPDATE_RANDOM and mt_rand(0,2) === 0){ //Growth
|
}elseif($type === BLOCK_UPDATE_RANDOM){ //Growth
|
||||||
|
if(mt_rand(1,7) === 1){
|
||||||
if(($this->meta & 0x08) === 0x08){
|
if(($this->meta & 0x08) === 0x08){
|
||||||
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||||
}else{
|
}else{
|
||||||
$this->meta |= 0x08;
|
$this->meta |= 0x08;
|
||||||
$this->level->setBlock($this, $this);
|
$this->level->setBlock($this, $this);
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class SugarcaneBlock extends FlowableBlock{
|
class SugarcaneBlock extends FlowableBlock{
|
||||||
public function __construct(){
|
public function __construct($meta = 0){
|
||||||
parent::__construct(SUGARCANE_BLOCK, 0, "Sugarcane");
|
parent::__construct(SUGARCANE_BLOCK, $meta, "Sugarcane");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
@ -38,11 +38,30 @@ class SugarcaneBlock extends FlowableBlock{
|
|||||||
|
|
||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($type === BLOCK_UPDATE_NORMAL){
|
||||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
$down = $this->getSide(0);
|
||||||
|
if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace wit common break method
|
||||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
|
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
|
||||||
$this->level->setBlock($this, new AirBlock(), false);
|
$this->level->setBlock($this, new AirBlock(), false);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
return BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||||
|
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
|
||||||
|
if($this->meta === 0x0F){
|
||||||
|
for($y = 1; $y < 3; ++$y){
|
||||||
|
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||||
|
if($b->getID() === AIR){
|
||||||
|
$this->level->setBlock($b, new SugarcaneBlock());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->meta = 0;
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
}else{
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
}
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -53,19 +72,19 @@ class SugarcaneBlock extends FlowableBlock{
|
|||||||
$this->level->setBlock($block, new SugarcaneBlock());
|
$this->level->setBlock($block, new SugarcaneBlock());
|
||||||
return true;
|
return true;
|
||||||
}elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
|
}elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
|
||||||
$block0 = $this->getSide(2);
|
$block0 = $down->getSide(2);
|
||||||
$block1 = $this->getSide(3);
|
$block1 = $down->getSide(3);
|
||||||
$block2 = $this->getSide(4);
|
$block2 = $down->getSide(4);
|
||||||
$block3 = $this->getSide(5);
|
$block3 = $down->getSide(5);
|
||||||
if($block0->getID() === WATER or $block0->getID() === STILL_WATER
|
if(($block0 instanceof WaterBlock)
|
||||||
or $block1->getID() === WATER or $block1->getID() === STILL_WATER
|
or ($block1 instanceof WaterBlock)
|
||||||
or $block2->getID() === WATER or $block2->getID() === STILL_WATER
|
or ($block2 instanceof WaterBlock)
|
||||||
or $block3->getID() === WATER or $block3->getID() === STILL_WATER){
|
or ($block3 instanceof WaterBlock)){
|
||||||
$this->level->setBlock($block, new SugarcaneBlock());
|
$this->level->setBlock($block, new SugarcaneBlock());
|
||||||
|
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -35,6 +35,7 @@ class WheatBlock extends FlowableBlock{
|
|||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === FARMLAND){
|
if($down->getID() === FARMLAND){
|
||||||
$this->level->setBlock($block, $this);
|
$this->level->setBlock($block, $this);
|
||||||
|
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -56,6 +57,16 @@ class WheatBlock extends FlowableBlock{
|
|||||||
$this->level->setBlock($this, new AirBlock(), false);
|
$this->level->setBlock($this, new AirBlock(), false);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
return BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||||
|
if(mt_rand(0, 2) == 1){
|
||||||
|
if($this->meta < 0x07){
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -356,6 +356,7 @@ class PMFLevel extends PMF{
|
|||||||
}else{
|
}else{
|
||||||
$m = ($meta << 4) | ($old_m & 0x0F);
|
$m = ($meta << 4) | ($old_m & 0x0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($old_b !== $block or $old_m !== $m){
|
if($old_b !== $block or $old_m !== $m){
|
||||||
$this->chunks[$index][$Y]{$bindex} = chr($block);
|
$this->chunks[$index][$Y]{$bindex} = chr($block);
|
||||||
$this->chunks[$index][$Y]{$mindex} = chr($m);
|
$this->chunks[$index][$Y]{$mindex} = chr($m);
|
||||||
|
@ -108,6 +108,10 @@ class Utils{
|
|||||||
return substr(pack("N", $value), 1);
|
return substr(pack("N", $value), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getRandomUpdateTicks(){
|
||||||
|
return -log(lcg_value())*1365.4; //Poisson distribution (1/(68.27 * 20))
|
||||||
|
}
|
||||||
|
|
||||||
public static function writeMetadata($data){
|
public static function writeMetadata($data){
|
||||||
$m = "";
|
$m = "";
|
||||||
foreach($data as $bottom => $d){
|
foreach($data as $bottom => $d){
|
||||||
|
@ -26,14 +26,15 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class Level{
|
class Level{
|
||||||
public $entities, $tiles, $nextSave, $players = array();
|
public $entities, $tiles, $blockUpdates, $nextSave, $players = array();
|
||||||
private $level, $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount;
|
private $level, $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount;
|
||||||
|
|
||||||
public function __construct(PMFLevel $level, Config $entities, Config $tiles, $name){
|
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
|
||||||
$this->server = ServerAPI::request();
|
$this->server = ServerAPI::request();
|
||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
$this->entities = $entities;
|
$this->entities = $entities;
|
||||||
$this->tiles = $tiles;
|
$this->tiles = $tiles;
|
||||||
|
$this->blockUpdates = $blockUpdates;
|
||||||
$this->startTime = $this->time = (int) $this->level->getData("time");
|
$this->startTime = $this->time = (int) $this->level->getData("time");
|
||||||
$this->nextSave = $this->startCheck = microtime(true);
|
$this->nextSave = $this->startCheck = microtime(true);
|
||||||
$this->nextSave += 90;
|
$this->nextSave += 90;
|
||||||
@ -116,7 +117,7 @@ class Level{
|
|||||||
$this->level->unloadChunk((int) array_pop($X), (int) $Z, $this->server->saveEnabled);
|
$this->level->unloadChunk((int) array_pop($X), (int) $Z, $this->server->saveEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->save();
|
$this->save(false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,13 +127,15 @@ class Level{
|
|||||||
unset($this->level);
|
unset($this->level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save($force = false){
|
public function save($force = false, $extra = true){
|
||||||
if(!isset($this->level)){
|
if(!isset($this->level)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($this->server->saveEnabled === false and $force === false){
|
if($this->server->saveEnabled === false and $force === false){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($extra !== false){
|
||||||
$entities = array();
|
$entities = array();
|
||||||
foreach($this->server->api->entity->getAll($this) as $entity){
|
foreach($this->server->api->entity->getAll($this) as $entity){
|
||||||
if($entity->class === ENTITY_MOB){
|
if($entity->class === ENTITY_MOB){
|
||||||
@ -230,6 +233,21 @@ class Level{
|
|||||||
$this->tiles->setAll($tiles);
|
$this->tiles->setAll($tiles);
|
||||||
$this->tiles->save();
|
$this->tiles->save();
|
||||||
|
|
||||||
|
$blockUpdates = array();
|
||||||
|
$updates = $this->server->query("SELECT x,y,z,type,delay FROM blockUpdates WHERE level = '".$this->getName()."';");
|
||||||
|
if($updates !== false and $updates !== true){
|
||||||
|
$timeu = microtime(true);
|
||||||
|
while(($bupdate = $updates->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
|
$bupdate["delay"] = max(1, ($bupdate["delay"] - $timeu) * 20);
|
||||||
|
$blockUpdates[] = $bupdate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->blockUpdates->setAll($blockUpdates);
|
||||||
|
$this->blockUpdates->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$this->level->setData("time", (int) $this->time);
|
$this->level->setData("time", (int) $this->time);
|
||||||
$this->level->doSaveRound();
|
$this->level->doSaveRound();
|
||||||
$this->level->saveData();
|
$this->level->saveData();
|
||||||
|
@ -72,7 +72,7 @@ class LevelImport{
|
|||||||
"width" => 16,
|
"width" => 16,
|
||||||
"height" => 8
|
"height" => 8
|
||||||
));
|
));
|
||||||
$chunks = new ChunkParser();
|
$chunks = new PocketChunkParser();
|
||||||
$chunks->loadFile($this->path."chunks.dat");
|
$chunks->loadFile($this->path."chunks.dat");
|
||||||
$chunks->loadMap();
|
$chunks->loadMap();
|
||||||
for($Z = 0; $Z < 16; ++$Z){
|
for($Z = 0; $Z < 16; ++$Z){
|
||||||
|
@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ChunkParser{
|
class PocketChunkParser{
|
||||||
private $location, $raw = b"", $file;
|
private $location, $raw = b"", $file;
|
||||||
var $sectorLength = 4096; //16 * 16 * 16
|
var $sectorLength = 4096; //16 * 16 * 16
|
||||||
var $chunkLength = 86016; //21 * $sectorLength
|
var $chunkLength = 86016; //21 * $sectorLength
|
||||||
|
@ -47,7 +47,8 @@ class WorldGenerator{
|
|||||||
));
|
));
|
||||||
$entities = new Config($this->path."entities.yml", CONFIG_YAML);
|
$entities = new Config($this->path."entities.yml", CONFIG_YAML);
|
||||||
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML);
|
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML);
|
||||||
$this->level = new Level($level, $entities, $tiles, $name);
|
$blockUpdates = new Config($this->path."bupdates.yml", CONFIG_YAML);
|
||||||
|
$this->level = new Level($level, $entities, $tiles, $blockUpdates, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generate(){
|
public function generate(){
|
||||||
@ -67,4 +68,8 @@ class WorldGenerator{
|
|||||||
$this->level->save(true);
|
$this->level->save(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function close(){
|
||||||
|
$this->level->close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user