mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 04:29:43 +00:00
decreased block updates per chunk from 80 to 20, PMFLevel block methods should be a bit faster now, grass spread rework, leaf decay fix
This commit is contained in:
parent
3dd9e38a37
commit
4544b7bb63
9 changed files with 73 additions and 60 deletions
|
|
@ -2168,7 +2168,6 @@ class Player{
|
||||||
if($this->entity->linkedEntity instanceof Entity){
|
if($this->entity->linkedEntity instanceof Entity){
|
||||||
$pk = new SetEntityMotionPacket;
|
$pk = new SetEntityMotionPacket;
|
||||||
$pk->eid = $this->entity->linkedEntity->eid;
|
$pk->eid = $this->entity->linkedEntity->eid;
|
||||||
var_dump($packet);
|
|
||||||
$pk->speedX = ($this->entity->x - $this->entity->linkedEntity->x)*30;
|
$pk->speedX = ($this->entity->x - $this->entity->linkedEntity->x)*30;
|
||||||
$pk->speedY = ($this->entity->y - $this->entity->linkedEntity->y)*30;
|
$pk->speedY = ($this->entity->y - $this->entity->linkedEntity->y)*30;
|
||||||
$pk->speedZ = ($this->entity->z - $this->entity->linkedEntity->z)*30;
|
$pk->speedZ = ($this->entity->z - $this->entity->linkedEntity->z)*30;
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,7 @@ require_once(FILE_PATH . "/src/plugin/OtherPluginRequirement.php");
|
||||||
require_once(FILE_PATH . "/src/plugin/DummyPlugin.php");
|
require_once(FILE_PATH . "/src/plugin/DummyPlugin.php");
|
||||||
require_once(FILE_PATH . "/src/plugin/phar/IClassLoader.php");
|
require_once(FILE_PATH . "/src/plugin/phar/IClassLoader.php");
|
||||||
require_once(FILE_PATH . "/src/plugin/phar/PharUtils.php");
|
require_once(FILE_PATH . "/src/plugin/phar/PharUtils.php");
|
||||||
|
require_once(FILE_PATH . "/src/world/generator/vanilla/biome/Biome.php");
|
||||||
require_once(FILE_PATH . "/src/world/generator/vanilla/feature/Feature.php");
|
require_once(FILE_PATH . "/src/world/generator/vanilla/feature/Feature.php");
|
||||||
|
|
||||||
require_all(FILE_PATH . "src/");
|
require_all(FILE_PATH . "src/");
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ class FireBlock extends FlowableBlock implements LightingBlock{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||||
console("Fire tick at $x $y $z");
|
|
||||||
if($level->level->getBlockID($x, $y - 1, $z) !== NETHERRACK){
|
if($level->level->getBlockID($x, $y - 1, $z) !== NETHERRACK){
|
||||||
$level->setBlock(new Position($x, $y, $z, $level), new AirBlock(), true, false, true);
|
$level->setBlock(new Position($x, $y, $z, $level), new AirBlock(), true, false, true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,13 @@ class DirtBlock extends SolidBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||||
if(mt_rand(0, 3) == 0){
|
/*if(mt_rand(0, 3) == 0){
|
||||||
$up = $level->getBlockWithoutVector($x, $y + 1, $z, false); //$this->getSide(1);
|
$up = $level->getBlockWithoutVector($x, $y + 1, $z, false); //$this->getSide(1);
|
||||||
if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false;
|
if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false;
|
||||||
if(self::getGrassInRadius($level, $x, $y, $z)){
|
if(self::getGrassInRadius($level, $x, $y, $z)){
|
||||||
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(GRASS), true, false, true);
|
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(GRASS), true, false, true);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockID($x, $y, $z){
|
public function getBlockID($x, $y, $z){
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,18 @@ class GrassBlock extends SolidBlock{
|
||||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||||
if(!$level->getBlockWithoutVector($x, $y + 1, $z, false)->isTransparent && mt_rand(0, 2) == 1){
|
if(!$level->getBlockWithoutVector($x, $y + 1, $z, false)->isTransparent && mt_rand(0, 2) == 1){
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0);
|
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0);
|
||||||
|
}else{
|
||||||
|
for($cnt = 0; $cnt < 4; ++$cnt){
|
||||||
|
$x = $x + mt_rand(0, 2) - 1;
|
||||||
|
$y = $y + mt_rand(0, 4) - 3;
|
||||||
|
$z = $z + mt_rand(0, 2) - 1;
|
||||||
|
|
||||||
|
$blockUp = $level->getBlockWithoutVector($x, $y + 1, $z, false);
|
||||||
|
if($blockUp->isTransparent && !$blockUp->isLiquid && !($blockUp->getID() === 60) && $level->level->getBlockID($x, $y, $z) === DIRT){
|
||||||
|
$level->fastSetBlockUpdate($x, $y, $z, GRASS, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ class LeavesBlock extends TransparentBlock{
|
||||||
$b = $level->level->getBlock($x, $y, $z);
|
$b = $level->level->getBlock($x, $y, $z);
|
||||||
$id = $b[0];
|
$id = $b[0];
|
||||||
$meta = $b[1];
|
$meta = $b[1];
|
||||||
|
|
||||||
if(($meta & 0b00001100) === 0x08){
|
if(($meta & 0b00001100) === 0x08){
|
||||||
$meta &= 0x03;
|
$meta &= 0x03;
|
||||||
$visited = array();
|
$visited = array();
|
||||||
|
|
@ -55,7 +54,8 @@ class LeavesBlock extends TransparentBlock{
|
||||||
if(($meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
|
if(($meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(APPLE, 0, 1));
|
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(APPLE, 0, 1));
|
||||||
}
|
}
|
||||||
return BLOCK_UPDATE_NORMAL;
|
}else{
|
||||||
|
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ class LeavesBlock extends TransparentBlock{
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($type === BLOCK_UPDATE_NORMAL){
|
||||||
if(($this->meta & 0b00001100) === 0){
|
if(($this->meta & 0b00001100) === 0){
|
||||||
$this->meta |= 0x08;
|
$this->meta |= 0x08;
|
||||||
$this->level->setBlock($this, $this, false, false, true);
|
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->id, $this->meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,23 @@ class WoodBlock extends SolidBlock{
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public function onBreak(Item $item, Player $player){
|
||||||
|
parent::onBreak($item, $player);
|
||||||
|
for($xOff = -4; $xOff <= 4; ++$xOff){
|
||||||
|
for($yOff = -4; $yOff <= 4; ++$yOff){
|
||||||
|
for($zOff = -4; $zOff <= 4; ++$zOff){
|
||||||
|
$b = $player->level->level->getBlock($this->x + $xOff, $this->y + $yOff, $this->z + $zOff);
|
||||||
|
$id = $b[0];
|
||||||
|
$meta = $b[1];
|
||||||
|
if($id === LEAVES){
|
||||||
|
if(($meta & 0x8) === 0){
|
||||||
|
$player->level->fastSetBlockUpdate($this->x + $xOff, $this->y + $yOff, $this->z + $zOff, $id, $meta | 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
return array(
|
return array(
|
||||||
array($this->id, $this->meta & 0x03, 1),
|
array($this->id, $this->meta & 0x03, 1),
|
||||||
|
|
|
||||||
|
|
@ -203,9 +203,7 @@ class PMFLevel extends PMF{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIndex($X, $Z){
|
public function getIndex($X, $Z){
|
||||||
$X = (int) $X;
|
return ((int) $Z << 4) + (int) $X; //statically 4, setting it to something else would destroy everything
|
||||||
$Z = (int) $Z;
|
|
||||||
return ($Z << $this->log) + $X;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveChunk($X, $Z){
|
public function saveChunk($X, $Z){
|
||||||
|
|
@ -333,15 +331,14 @@ class PMFLevel extends PMF{
|
||||||
$Z = $z >> 4;
|
$Z = $z >> 4;
|
||||||
$Y = $y >> 4;
|
$Y = $y >> 4;
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
|
if(!isset($this->chunks[$index]) || $this->chunks[$index] === false || ($this->chunks[$index][$Y] === false)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
$aX = $x & 0xf;
|
$aX = $x & 0xf;
|
||||||
$aZ = $z & 0xf;
|
$aZ = $z & 0xf;
|
||||||
$aY = $y & 0xf;
|
$aY = $y & 0xf;
|
||||||
|
|
||||||
if(is_array($this->chunks) && isset($this->chunks[$index]) && is_array($this->chunks[$index]) && isset($this->chunks[$index][$Y]) && is_string($this->chunks[$index][$Y])){
|
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]);
|
||||||
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]);
|
|
||||||
}else{ //php8 fix
|
|
||||||
$b = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $b;
|
return $b;
|
||||||
}
|
}
|
||||||
|
|
@ -379,21 +376,14 @@ class PMFLevel extends PMF{
|
||||||
$Z = $z >> 4;
|
$Z = $z >> 4;
|
||||||
$Y = $y >> 4;
|
$Y = $y >> 4;
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
|
if(!isset($this->chunks[$index]) || $this->chunks[$index] === false || ($this->chunks[$index][$Y] === false)){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
$aX = $x & 0xf;
|
$aX = $x & 0xf;
|
||||||
$aZ = $z & 0xf;
|
$aZ = $z & 0xf;
|
||||||
$aY = $y & 0xf;
|
$aY = $y & 0xf;
|
||||||
if(is_array($this->chunks) && isset($this->chunks[$index]) && is_array($this->chunks[$index]) && isset($this->chunks[$index][$Y]) && is_string($this->chunks[$index][$Y])){
|
$m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
|
||||||
$m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
|
return ($y & 1) === 0 ? $m & 0x0F : $m >> 4;
|
||||||
}else{ //php8 fix
|
|
||||||
$m = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($y & 1) === 0){
|
|
||||||
$m = $m & 0x0F;
|
|
||||||
}else{
|
|
||||||
$m = $m >> 4;
|
|
||||||
}
|
|
||||||
return $m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlockDamage($x, $y, $z, $damage){
|
public function setBlockDamage($x, $y, $z, $damage){
|
||||||
|
|
@ -439,25 +429,24 @@ class PMFLevel extends PMF{
|
||||||
if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){
|
if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){
|
||||||
return [AIR, 0];
|
return [AIR, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$index = $this->getIndex($X, $Z);
|
$index = $this->getIndex($X, $Z);
|
||||||
if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){
|
if(!isset($this->chunks[$index]) || $this->chunks[$index] === false){
|
||||||
if($this->loadChunk($X, $Z) === false){
|
if($this->loadChunk($X, $Z) === false){
|
||||||
return [AIR, 0];
|
return [AIR, 0];
|
||||||
}
|
}
|
||||||
}elseif($this->chunks[$index][$Y] === false){
|
}
|
||||||
|
if($this->chunks[$index][$Y] === false){
|
||||||
return [AIR, 0];
|
return [AIR, 0];
|
||||||
}
|
}
|
||||||
$aX = $x & 0xf;
|
$aX = $x & 0xf;
|
||||||
$aZ = $z & 0xf;
|
$aZ = $z & 0xf;
|
||||||
$aY = $y & 0xf;
|
$aY = $y & 0xf;
|
||||||
#Need to fix. But idk how.
|
#Need to fix. But idk how.
|
||||||
if(is_array($this->chunks) && is_array($this->chunks[$index]) && is_string($this->chunks[$index][$Y])){ //PHP8 warn fix
|
|
||||||
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]);
|
//if(is_string($this->chunks[$index][$Y])){ //PHP8 warn fix
|
||||||
$m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
|
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]);
|
||||||
}else{
|
$m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
|
||||||
$b = 0;
|
|
||||||
$m = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($y & 1) === 0){
|
if(($y & 1) === 0){
|
||||||
$m = $m & 0x0F;
|
$m = $m & 0x0F;
|
||||||
|
|
|
||||||
|
|
@ -301,31 +301,28 @@ class Level{
|
||||||
public function onTick(PocketMinecraftServer $server){
|
public function onTick(PocketMinecraftServer $server){
|
||||||
//$ents = $server->api->entity->getAll($this);
|
//$ents = $server->api->entity->getAll($this);
|
||||||
if(!$this->stopTime) ++$this->time;
|
if(!$this->stopTime) ++$this->time;
|
||||||
$p = new Position(0, 0, 0, $this);
|
for($cX = 0; $cX < 16; ++$cX){
|
||||||
for($i = 0; $i < 256; ++$i){ //0000 0000 x z
|
for($cZ = 0; $cZ < 16; ++$cZ){
|
||||||
$cZ = $i & 0xf;
|
for($c = 0; $c <= 20; ++$c){
|
||||||
$cX = $i >> 4;
|
$this->randInt1 = $this->randInt1 * 3 + $this->randInt2;
|
||||||
for($c = 0; $c <= 80; ++$c){
|
$xyz = $this->randInt1 >> 2;
|
||||||
$this->randInt1 = $this->randInt1 * 3 + $this->randInt2;
|
$this->randInt1 = $this->randInt1 & 0xffffffff; //bad php i hate u why no uint
|
||||||
$xyz = $this->randInt1 >> 2;
|
$x = $xyz & 0xf;
|
||||||
$this->randInt1 = $this->randInt1 & 0xffffffff; //bad php i hate u why no uint
|
$z = ($xyz >> 8) & 0xf; //TODO might be possible to make some micro optmizations
|
||||||
$x = $xyz & 0xf;
|
$y = ($xyz >> 16) & 0x7f;
|
||||||
$z = ($xyz >> 8) & 0xf; //TODO might be possible to make some micro optmizations
|
$id = $this->level->getBlockID(($cX << 4) + $x, $y, $z + ($cZ << 4));
|
||||||
$y = ($xyz >> 16) & 0x7f;
|
if(isset(self::$randomUpdateBlocks[$id])){
|
||||||
$idmeta = $this->level->getBlock(($cX << 4) + $x, $y, $z + ($cZ << 4));
|
$cl = Block::$class[$id];
|
||||||
$id = $idmeta[0];
|
//if($cl !== false){
|
||||||
if(isset(self::$randomUpdateBlocks[$id])){
|
$cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4));
|
||||||
$c = nullsafe(Block::$class[$id], false);
|
//}
|
||||||
if($c !== false){
|
//$p->setXYZ(($cX << 4) + $x, $y, $z + ($cZ << 4));
|
||||||
$c::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4));
|
//$b = BlockAPI::get($idmeta[0], $idmeta[1], $p); //$this->getBlockWithoutVector();
|
||||||
|
//if($b instanceof Block){
|
||||||
|
// $b->onUpdate(BLOCK_UPDATE_RANDOM);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
//$p->setXYZ(($cX << 4) + $x, $y, $z + ($cZ << 4));
|
|
||||||
//$b = BlockAPI::get($idmeta[0], $idmeta[1], $p); //$this->getBlockWithoutVector();
|
|
||||||
//if($b instanceof Block){
|
|
||||||
// $b->onUpdate(BLOCK_UPDATE_RANDOM);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach($this->entityList as $k => $e){
|
foreach($this->entityList as $k => $e){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue