bounds for pmflevel methods, random block ticking ported from 0.1.3 core, player height was decreased a bit

This commit is contained in:
GameHerobrine 2023-06-23 07:41:04 +03:00
parent 84dd0b82b3
commit 3dd9e38a37
22 changed files with 326 additions and 216 deletions

View file

@ -16,7 +16,14 @@ class BeetrootBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$b = $level->level->getBlock($x, $y, $z);
if($b[1] < 0x07){
$level->fastSetBlockUpdate($x, $y, $z, $b[0], $b[1] + 1);
}
}
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta += mt_rand(0, 3) + 2;
@ -39,16 +46,6 @@ class BeetrootBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
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, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

View file

@ -7,6 +7,30 @@ class CactusBlock extends TransparentBlock{
$this->hardness = 2;
}
public static function onRandomTick(Level $level, $x, $y, $z){
//$b = $level->level->getBlock($x, $y - 1, $z);
$underID = $level->level->getBlockID($x, $y - 1, $z);
$b = $level->level->getBlock($x, $y, $z);
$id = $b[0];
$meta = $b[1];
if($underID !== CACTUS){
if($meta == 0x0F){
for($yy = 1; $yy < 3; ++$yy){
$bID = $level->level->getBlockID($x, $y + $yy, $z);
if($bID === AIR){
$level->setBlock(new Position($x, $y, $z, $level), new CactusBlock(), true, false, true);
break;
}
}
$meta = 0;
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta);
}else{
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta + 1);
}
return BLOCK_UPDATE_RANDOM;
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
@ -19,24 +43,6 @@ class CactusBlock extends TransparentBlock{
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem($this->id));
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(), true, false, true);
break;
}
}
$this->meta = 0;
$this->level->setBlock($this, $this, false);
}else{
++$this->meta;
$this->level->setBlock($this, $this, false);
}
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

View file

@ -31,7 +31,16 @@ class CarrotBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
@ -39,16 +48,6 @@ class CarrotBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
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, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

View file

@ -15,7 +15,34 @@ class MelonStemBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}else{
$position = new AirBlock(); //feke block
$position->x = $x;
$position->y = $y;
$position->z = $z;
$position->level = $level;
for($side = 2; $side <= 5; ++$side){
$b = $position->getSide($side);
if($b->getID() === MELON_BLOCK){
return;
}
}
$side = $position->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)){
$level->setBlock($side, new MelonBlock(), true, false, true);
}
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
@ -23,27 +50,6 @@ class MelonStemBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
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, true, false, true);
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(), true, false, true);
}
}
}
return BLOCK_UPDATE_RANDOM;
}
return false;
}

View file

@ -16,7 +16,16 @@ class PotatoBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}
}
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta += mt_rand(0, 3) + 2;
@ -39,16 +48,6 @@ class PotatoBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
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, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}

View file

@ -15,7 +15,34 @@ class PumpkinStemBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}else{
$position = new AirBlock(); //feke block
$position->x = $x;
$position->y = $y;
$position->z = $z;
$position->level = $level;
for($side = 2; $side <= 5; ++$side){
$b = $position->getSide($side);
if($b->getID() === PUMPKIN){
return;
}
}
$side = $position->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)){
$level->setBlock($side, new PumpkinBlock(), true, false, true);
}
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){

View file

@ -55,27 +55,30 @@ class SugarcaneBlock extends FlowableBlock{
$this->level->setBlock($this, new AirBlock(), false, false, true);
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(), true, false, true);
}
}
$this->meta = 0;
$this->level->setBlock($this, $this, true, false, true);
}else{
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
}
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
$underID = $level->level->getBlockID($x, $y - 1, $z);
$b = $level->level->getBlock($x, $y, $z);
$id = $b[0];
$meta = $b[1];
if($underID !== SUGARCANE_BLOCK){
if($meta == 0x0F){
for($yy = 1; $yy < 3; ++$yy){
$bID = $level->level->getBlockID($x, $y + $yy, $z);
if($bID === AIR){
$level->setBlock(new Position($x, $y, $z, $level), new SugarcaneBlock(), true, false, true);
}
}
$meta = 0;
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta);
}else{
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta + 1);
}
return BLOCK_UPDATE_RANDOM;
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === SUGARCANE_BLOCK){

View file

@ -31,7 +31,16 @@ class WheatBlock extends FlowableBlock{
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
@ -40,17 +49,6 @@ class WheatBlock extends FlowableBlock{
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, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}