rewritten pumpkin and melon growth, fixed new world generation

This commit is contained in:
GameHerobrine 2025-06-26 08:17:14 +03:00
parent 37e2919f46
commit 756c597e47
4 changed files with 149 additions and 70 deletions

View file

@ -118,7 +118,7 @@ class Entity extends Position
public $moveStrafing, $moveForward; public $moveStrafing, $moveForward;
function __construct(Level $level, $eid, $class, $type = 0, $data = []) public function __construct(Level $level, $eid, $class, $type = 0, $data = [])
{ {
$this->random = new XorShift128Random(); $this->random = new XorShift128Random();
$this->last = [&$this->lastX, &$this->lastY, &$this->lastZ, &$this->lastYaw, &$this->lastPitch, &$this->lastTime]; //pointers to variables $this->last = [&$this->lastX, &$this->lastY, &$this->lastZ, &$this->lastYaw, &$this->lastPitch, &$this->lastTime]; //pointers to variables
@ -202,6 +202,7 @@ class Entity extends Position
$this->outOfWorld(); $this->outOfWorld();
} }
} }
public function handlePrePlayerSearcher(){ public function handlePrePlayerSearcher(){
} }

View file

@ -17,34 +17,79 @@ class MelonStemBlock extends FlowableBlock{
} }
return false; return false;
} }
public static function getGrowthSpeed(Level $level, $x, $y, $z){
$zneg = $level->level->getBlockID($x, $y, $z-1);
$zpos = $level->level->getBlockID($x, $y, $z+1);
$xneg = $level->level->getBlockID($x-1, $y, $z);
$xpos = $level->level->getBlockID($x+1, $y, $z);
$znxn = $level->level->getBlockID($x-1, $y, $z-1);
$znxp = $level->level->getBlockID($x+1, $y, $z-1);
$zpxp = $level->level->getBlockID($x+1, $y, $z+1);
$zpxn = $level->level->getBlockID($x-1, $y, $z+1);
$xEqual = $xneg == MELON_STEM || $xpos == MELON_STEM;
$zEqual = $zneg == MELON_STEM || $zpos == MELON_STEM;
$xzEqual = $znxn == MELON_STEM || $znxp == MELON_STEM || $zpxn == MELON_STEM || $zpxp == MELON_STEM;
$speed = 1;
for($xx = $x-1; $xx >= $x+1; ++$xx){
for($zz = $z-1; $zz >= $z+1; ++$zz){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
$v18 = 0;
if($id == FARMLAND) $v18 = $meta > 0 ? 3 : 1;
if($xx != $x || $zz != $z) $v18 *= 0.25;
$speed += $v18;
}
}
if($xzEqual || ($xEqual && $zEqual)) return $speed*0.5;
return $speed;
}
public static function onRandomTick(Level $level, $x, $y, $z){ public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){ //TODO checkAlive
$block = $level->level->getBlock($x, $y, $z); //if ( Level::getRawBrightness(a2, a3, a4 + 1, a5) > 8 ) TODO - skylight
if($block[1] < 0x07){
//++$this->meta; $growSpeed = static::getGrowthSpeed($level, $x, $y, $z);
//$this->level->setBlock($this, $this, true, false, true); $rand = mt_rand(0, (int)(25/$growSpeed));
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1); if($rand != 0) return;
}else{
$meta = $level->level->getBlockDamage($x, $y, $z);
$position = new AirBlock(); //feke block if($meta <= 6){
$position->x = $x; $level->fastSetBlockUpdateMeta($x, $y, $z, $meta+1);
$position->y = $y; return;
$position->z = $z; }
$position->level = $level;
for($side = 2; $side <= 5; ++$side){ $xn = $level->level->getBlockID($x-1, $y, $z);
$b = $position->getSide($side); $xp = $level->level->getBlockID($x+1, $y, $z);
if($b->getID() === MELON_BLOCK){ $zn = $level->level->getBlockID($x, $y, $z-1);
return; $zp = $level->level->getBlockID($x, $y, $z+1);
} if($xn != MELON_BLOCK && $xp != MELON_BLOCK && $zn != MELON_BLOCK && $zp != MELON_BLOCK){
} $below = $level->level->getBlockID($x-1, $y-1, $z);
$side = $position->getSide(mt_rand(2,5)); if($level->level->getBlockID($x-1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$d = $side->getSide(0); $level->fastSetBlockUpdate($x-1, $y, $z, MELON_BLOCK, 0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){ return;
$level->setBlock($side, new MelonBlock(), true, false, true); }
}
$below = $level->level->getBlockID($x+1, $y-1, $z);
if($level->level->getBlockID($x+1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x+1, $y, $z, MELON_BLOCK, 0);
return;
}
$below = $level->level->getBlockID($x, $y-1, $z-1);
if($level->level->getBlockID($x, $y, $z-1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x, $y, $z-1, MELON_BLOCK, 0);
return;
}
$below = $level->level->getBlockID($x, $y-1, $z+1);
if($level->level->getBlockID($x, $y, $z+1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x, $y, $z+1, MELON_BLOCK, 0);
return;
} }
} }
} }
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2))); ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
@ -67,14 +112,8 @@ class MelonStemBlock extends FlowableBlock{
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
$drops = []; $drops = [];
if($this->meta >= 0x07){ for($i = 0; $i < 3; ++$i){
$drops[] = [MELON_SEEDS, 0, mt_rand(1, 2)]; if(mt_rand(0, 15) <= $this->meta) $drops[] = [MELON_SEEDS, 0, 1];
}
elseif($this->meta >= 0x01 and $this->meta <= 0x07){
$drops[] = [MELON_SEEDS, 0, 1];
}
else{
$drops[] = [MELON_SEEDS, 0, 0];
} }
return $drops; return $drops;
} }

View file

@ -10,38 +10,82 @@ class PumpkinStemBlock extends FlowableBlock{
$this->material = Material::$plant; $this->material = Material::$plant;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === FARMLAND){ if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
return false; return false;
} }
public static function getGrowthSpeed(Level $level, $x, $y, $z){
$zneg = $level->level->getBlockID($x, $y, $z-1);
$zpos = $level->level->getBlockID($x, $y, $z+1);
$xneg = $level->level->getBlockID($x-1, $y, $z);
$xpos = $level->level->getBlockID($x+1, $y, $z);
$znxn = $level->level->getBlockID($x-1, $y, $z-1);
$znxp = $level->level->getBlockID($x+1, $y, $z-1);
$zpxp = $level->level->getBlockID($x+1, $y, $z+1);
$zpxn = $level->level->getBlockID($x-1, $y, $z+1);
$xEqual = $xneg == PUMPKIN_STEM || $xpos == PUMPKIN_STEM;
$zEqual = $zneg == PUMPKIN_STEM || $zpos == PUMPKIN_STEM;
$xzEqual = $znxn == PUMPKIN_STEM || $znxp == PUMPKIN_STEM || $zpxn == PUMPKIN_STEM || $zpxp == PUMPKIN_STEM;
$speed = 1;
for($xx = $x-1; $xx >= $x+1; ++$xx){
for($zz = $z-1; $zz >= $z+1; ++$zz){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if($id == FARMLAND) $v18 = $meta > 0 ? 3 : 1;
else $v18 = 0;
if($xx != $x || $zz != $z) $v18 *= 0.25;
$speed += $v18;
}
}
if($xzEqual || ($xEqual && $zEqual)) return $speed*0.5;
return $speed;
}
public static function onRandomTick(Level $level, $x, $y, $z){ public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){ //TODO checkAlive
$block = $level->level->getBlock($x, $y, $z); //if ( Level::getRawBrightness(a2, a3, a4 + 1, a5) > 8 ) TODO - skylight
if($block[1] < 0x07){
//++$this->meta; $growSpeed = static::getGrowthSpeed($level, $x, $y, $z);
//$this->level->setBlock($this, $this, true, false, true); $rand = mt_rand(0, (int)(25/$growSpeed));
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1); if($rand != 0) return;
}else{
$meta = $level->level->getBlockDamage($x, $y, $z);
$position = new AirBlock(); //feke block if($meta <= 6){
$position->x = $x; $level->fastSetBlockUpdateMeta($x, $y, $z, $meta+1);
$position->y = $y; return;
$position->z = $z; }
$position->level = $level;
for($side = 2; $side <= 5; ++$side){ $xn = $level->level->getBlockID($x-1, $y, $z);
$b = $position->getSide($side); $xp = $level->level->getBlockID($x+1, $y, $z);
if($b->getID() === PUMPKIN){ $zn = $level->level->getBlockID($x, $y, $z-1);
return; $zp = $level->level->getBlockID($x, $y, $z+1);
} if($xn != PUMPKIN && $xp != PUMPKIN && $zn != PUMPKIN && $zp != PUMPKIN){
} $below = $level->level->getBlockID($x-1, $y-1, $z);
$side = $position->getSide(mt_rand(2,5)); if($level->level->getBlockID($x-1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$d = $side->getSide(0); $level->fastSetBlockUpdate($x-1, $y, $z, PUMPKIN, 0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){ return;
$level->setBlock($side, new PumpkinBlock(), true, false, true); }
}
$below = $level->level->getBlockID($x+1, $y-1, $z);
if($level->level->getBlockID($x+1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x+1, $y, $z, PUMPKIN, 0);
return;
}
$below = $level->level->getBlockID($x, $y-1, $z-1);
if($level->level->getBlockID($x, $y, $z-1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x, $y, $z-1, PUMPKIN, 0);
return;
}
$below = $level->level->getBlockID($x, $y-1, $z+1);
if($level->level->getBlockID($x, $y, $z+1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x, $y, $z+1, PUMPKIN, 0);
return;
} }
} }
} }
@ -67,14 +111,8 @@ class PumpkinStemBlock extends FlowableBlock{
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
$drops = []; $drops = [];
if($this->meta >= 0x07){ for($i = 0; $i < 3; ++$i){
$drops[] = [PUMPKIN_SEEDS, 0, mt_rand(1, 2)]; if(mt_rand(0, 15) <= $this->meta) $drops[] = [PUMPKIN_SEEDS, 0, 1];
}
elseif($this->meta >= 0x01 and $this->meta <= 0x07){
$drops[] = [PUMPKIN_SEEDS, 0, 1];
}
else{
$drops[] = [PUMPKIN_SEEDS, 0, 0];
} }
return $drops; return $drops;
} }

View file

@ -45,6 +45,7 @@ class PMFLevel extends PMF{
@mkdir($dirname , 0755); @mkdir($dirname , 0755);
} }
$this->hasLight = str_repeat("\x00", 16*16);
for($index = 0; $index < $cnt; ++$index){ for($index = 0; $index < $cnt; ++$index){
$this->chunks[$index] = false; $this->chunks[$index] = false;
$this->chunkChange[$index] = false; $this->chunkChange[$index] = false;