mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39: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){
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk->eid = $this->entity->linkedEntity->eid;
|
||||
var_dump($packet);
|
||||
$pk->speedX = ($this->entity->x - $this->entity->linkedEntity->x)*30;
|
||||
$pk->speedY = ($this->entity->y - $this->entity->linkedEntity->y)*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/phar/IClassLoader.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_all(FILE_PATH . "src/");
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ class FireBlock extends FlowableBlock implements LightingBlock{
|
|||
}
|
||||
|
||||
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){
|
||||
$level->setBlock(new Position($x, $y, $z, $level), new AirBlock(), true, false, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@ class DirtBlock extends SolidBlock{
|
|||
return false;
|
||||
}
|
||||
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);
|
||||
if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false;
|
||||
if(self::getGrassInRadius($level, $x, $y, $z)){
|
||||
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(GRASS), true, false, true);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public function getBlockID($x, $y, $z){
|
||||
|
|
|
|||
|
|
@ -49,6 +49,18 @@ class GrassBlock extends SolidBlock{
|
|||
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||
if(!$level->getBlockWithoutVector($x, $y + 1, $z, false)->isTransparent && mt_rand(0, 2) == 1){
|
||||
$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);
|
||||
$id = $b[0];
|
||||
$meta = $b[1];
|
||||
|
||||
if(($meta & 0b00001100) === 0x08){
|
||||
$meta &= 0x03;
|
||||
$visited = array();
|
||||
|
|
@ -55,7 +54,8 @@ class LeavesBlock extends TransparentBlock{
|
|||
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));
|
||||
}
|
||||
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(($this->meta & 0b00001100) === 0){
|
||||
$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;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,23 @@ class WoodBlock extends SolidBlock{
|
|||
$this->level->setBlock($block, $this, true, false, 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){
|
||||
return array(
|
||||
array($this->id, $this->meta & 0x03, 1),
|
||||
|
|
|
|||
|
|
@ -203,9 +203,7 @@ class PMFLevel extends PMF{
|
|||
}
|
||||
|
||||
public function getIndex($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
return ($Z << $this->log) + $X;
|
||||
return ((int) $Z << 4) + (int) $X; //statically 4, setting it to something else would destroy everything
|
||||
}
|
||||
|
||||
public function saveChunk($X, $Z){
|
||||
|
|
@ -333,15 +331,14 @@ class PMFLevel extends PMF{
|
|||
$Z = $z >> 4;
|
||||
$Y = $y >> 4;
|
||||
$index = $this->getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) || $this->chunks[$index] === false || ($this->chunks[$index][$Y] === false)){
|
||||
return 0;
|
||||
}
|
||||
$aX = $x & 0xf;
|
||||
$aZ = $z & 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))]);
|
||||
}else{ //php8 fix
|
||||
$b = 0;
|
||||
}
|
||||
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]);
|
||||
|
||||
return $b;
|
||||
}
|
||||
|
|
@ -379,21 +376,14 @@ class PMFLevel extends PMF{
|
|||
$Z = $z >> 4;
|
||||
$Y = $y >> 4;
|
||||
$index = $this->getIndex($X, $Z);
|
||||
if(!isset($this->chunks[$index]) || $this->chunks[$index] === false || ($this->chunks[$index][$Y] === false)){
|
||||
return 0;
|
||||
}
|
||||
$aX = $x & 0xf;
|
||||
$aZ = $z & 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))]);
|
||||
}else{ //php8 fix
|
||||
$m = 0;
|
||||
}
|
||||
|
||||
if(($y & 1) === 0){
|
||||
$m = $m & 0x0F;
|
||||
}else{
|
||||
$m = $m >> 4;
|
||||
}
|
||||
return $m;
|
||||
$m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
|
||||
return ($y & 1) === 0 ? $m & 0x0F : $m >> 4;
|
||||
}
|
||||
|
||||
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){
|
||||
return [AIR, 0];
|
||||
}
|
||||
|
||||
$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){
|
||||
return [AIR, 0];
|
||||
}
|
||||
}elseif($this->chunks[$index][$Y] === false){
|
||||
}
|
||||
if($this->chunks[$index][$Y] === false){
|
||||
return [AIR, 0];
|
||||
}
|
||||
$aX = $x & 0xf;
|
||||
$aZ = $z & 0xf;
|
||||
$aY = $y & 0xf;
|
||||
#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))]);
|
||||
$m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
|
||||
}else{
|
||||
$b = 0;
|
||||
$m = 0;
|
||||
}
|
||||
|
||||
//if(is_string($this->chunks[$index][$Y])){ //PHP8 warn fix
|
||||
$b = ord($this->chunks[$index][$Y][($aY + ($aX << 5) + ($aZ << 9))]);
|
||||
$m = ord($this->chunks[$index][$Y][(($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
|
||||
|
||||
if(($y & 1) === 0){
|
||||
$m = $m & 0x0F;
|
||||
|
|
|
|||
|
|
@ -301,31 +301,28 @@ class Level{
|
|||
public function onTick(PocketMinecraftServer $server){
|
||||
//$ents = $server->api->entity->getAll($this);
|
||||
if(!$this->stopTime) ++$this->time;
|
||||
$p = new Position(0, 0, 0, $this);
|
||||
for($i = 0; $i < 256; ++$i){ //0000 0000 x z
|
||||
$cZ = $i & 0xf;
|
||||
$cX = $i >> 4;
|
||||
for($c = 0; $c <= 80; ++$c){
|
||||
$this->randInt1 = $this->randInt1 * 3 + $this->randInt2;
|
||||
$xyz = $this->randInt1 >> 2;
|
||||
$this->randInt1 = $this->randInt1 & 0xffffffff; //bad php i hate u why no uint
|
||||
$x = $xyz & 0xf;
|
||||
$z = ($xyz >> 8) & 0xf; //TODO might be possible to make some micro optmizations
|
||||
$y = ($xyz >> 16) & 0x7f;
|
||||
$idmeta = $this->level->getBlock(($cX << 4) + $x, $y, $z + ($cZ << 4));
|
||||
$id = $idmeta[0];
|
||||
if(isset(self::$randomUpdateBlocks[$id])){
|
||||
$c = nullsafe(Block::$class[$id], false);
|
||||
if($c !== false){
|
||||
$c::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4));
|
||||
for($cX = 0; $cX < 16; ++$cX){
|
||||
for($cZ = 0; $cZ < 16; ++$cZ){
|
||||
for($c = 0; $c <= 20; ++$c){
|
||||
$this->randInt1 = $this->randInt1 * 3 + $this->randInt2;
|
||||
$xyz = $this->randInt1 >> 2;
|
||||
$this->randInt1 = $this->randInt1 & 0xffffffff; //bad php i hate u why no uint
|
||||
$x = $xyz & 0xf;
|
||||
$z = ($xyz >> 8) & 0xf; //TODO might be possible to make some micro optmizations
|
||||
$y = ($xyz >> 16) & 0x7f;
|
||||
$id = $this->level->getBlockID(($cX << 4) + $x, $y, $z + ($cZ << 4));
|
||||
if(isset(self::$randomUpdateBlocks[$id])){
|
||||
$cl = Block::$class[$id];
|
||||
//if($cl !== false){
|
||||
$cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4));
|
||||
//}
|
||||
//$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);
|
||||
//}
|
||||
}
|
||||
//$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){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue