mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 08:39:53 +00:00
Level optimizations
This commit is contained in:
parent
b3c51c6d2e
commit
d41c30945b
@ -329,7 +329,6 @@ class PMFLevel extends PMF{
|
||||
$Z = $z >> 4;
|
||||
$Y = $y >> 4;
|
||||
$block &= 0xFF;
|
||||
$meta &= 0x0F;
|
||||
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){
|
||||
return false;
|
||||
}
|
||||
@ -348,6 +347,9 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
|
||||
public function getBlockDamage($x, $y, $z){
|
||||
if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){
|
||||
return 0;
|
||||
}
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$Y = $y >> 4;
|
||||
@ -365,6 +367,9 @@ class PMFLevel extends PMF{
|
||||
}
|
||||
|
||||
public function setBlockDamage($x, $y, $z, $damage){
|
||||
if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){
|
||||
return false;
|
||||
}
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$Y = $y >> 4;
|
||||
@ -379,9 +384,9 @@ class PMFLevel extends PMF{
|
||||
$mindex = (int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9));
|
||||
$old_m = ord($this->chunks[$index][$Y]{$mindex});
|
||||
if(($y & 1) === 0){
|
||||
$m = ($old_m & 0xF0) | $meta;
|
||||
$m = ($old_m & 0xF0) | $damage;
|
||||
}else{
|
||||
$m = ($meta << 4) | ($old_m & 0x0F);
|
||||
$m = ($damage << 4) | ($old_m & 0x0F);
|
||||
}
|
||||
|
||||
if($old_m != $m){
|
||||
|
@ -54,15 +54,16 @@ class Explosion{
|
||||
|
||||
for($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
|
||||
$vBlock = $pointer->floor();
|
||||
if($vBlock->y >= 128 or $vBlock->y < 0){
|
||||
break;
|
||||
}
|
||||
$block = $this->level->getBlockRaw($vBlock);
|
||||
$blockID = $this->level->level->getBlockID($vBlock->x, $vBlock->y, $vBlock->z);
|
||||
|
||||
if(!($block instanceof AirBlock)){
|
||||
if($blockID > 0){
|
||||
$block = BlockAPI::get($blockID, 0);
|
||||
$block->x = $vBlock->x;
|
||||
$block->y = $vBlock->y;
|
||||
$block->z = $vBlock->z;
|
||||
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
|
||||
if($blastForce > 0){
|
||||
$index = ($vBlock->x << 15) + ($vBlock->z << 7) + $vBlock->y;
|
||||
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
||||
if(!isset($this->affectedBlocks[$index])){
|
||||
$this->affectedBlocks[$index] = $block;
|
||||
}
|
||||
@ -76,7 +77,6 @@ class Explosion{
|
||||
}
|
||||
|
||||
$send = array();
|
||||
$airblock = new AirBlock();
|
||||
$source = $this->source->floor();
|
||||
$radius = 2 * $this->size;
|
||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||
@ -86,7 +86,7 @@ class Explosion{
|
||||
}
|
||||
|
||||
foreach($this->affectedBlocks as $block){
|
||||
$this->level->setBlockRaw($block, $airblock, false, false); //Do not send record
|
||||
|
||||
if($block instanceof TNTBlock){
|
||||
$data = array(
|
||||
"x" => $block->x + 0.5,
|
||||
@ -97,11 +97,11 @@ class Explosion{
|
||||
);
|
||||
$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
|
||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
|
||||
}
|
||||
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
|
||||
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
|
||||
if(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
|
||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $block->getMetadata()));
|
||||
}
|
||||
}
|
||||
$server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_EXPLOSION, array(
|
||||
"x" => $this->source->x,
|
||||
|
@ -27,7 +27,7 @@ class SuperflatGenerator implements LevelGenerator{
|
||||
private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = array();
|
||||
|
||||
public function __construct(array $options = array()){
|
||||
$this->preset = "2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=120)";
|
||||
$this->preset = "2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)";
|
||||
$this->options = $options;
|
||||
if(isset($options["preset"])){
|
||||
$this->parsePreset($options["preset"]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user