mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
bounds for pmflevel methods, random block ticking ported from 0.1.3 core, player height was decreased a bit
This commit is contained in:
parent
84dd0b82b3
commit
3dd9e38a37
22 changed files with 326 additions and 216 deletions
|
|
@ -536,14 +536,14 @@ class BlockAPI{
|
|||
if($block === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($type === BLOCK_UPDATE_RANDOM) return false; //I HATE U NO
|
||||
$level = $block->onUpdate($type);
|
||||
if($level === BLOCK_UPDATE_NORMAL){
|
||||
$this->blockUpdateAround($block, $level);
|
||||
$this->server->api->entity->updateRadius($pos, 1);
|
||||
}elseif($level === BLOCK_UPDATE_RANDOM){
|
||||
//$this->nextRandomUpdate($pos); old version, change back if any issues will start to happen with this one(please note that old version makes a lot of lag)
|
||||
$this->scheduleBlockUpdate($pos, (mt_rand(25, 75) + Utils::getRandomUpdateTicks() * 0.05) / 0.05, BLOCK_UPDATE_RANDOM);
|
||||
//NO $this->scheduleBlockUpdate($pos, (mt_rand(25, 75) + Utils::getRandomUpdateTicks() * 0.05) / 0.05, BLOCK_UPDATE_RANDOM);
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class LevelAPI{
|
|||
|
||||
$timeu = microtime(true);
|
||||
foreach($blockUpdates->getAll() as $bupdate){
|
||||
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"], (int) $bupdate["y"], (int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
|
||||
if($bupdate["type"] !== BLOCK_UPDATE_RANDOM) $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"], (int) $bupdate["y"], (int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class Entity extends Position
|
|||
$this->setHealth($this->health, "generic");
|
||||
$this->speedModifer = 1;
|
||||
$this->width = 1.4;
|
||||
$this->height = 1.9;
|
||||
$this->height = 1.85;
|
||||
$this->hasKnockback = true;
|
||||
$this->hasGravity = true;
|
||||
$this->canBeAttacked = true;
|
||||
|
|
@ -259,7 +259,7 @@ class Entity extends Position
|
|||
*
|
||||
* @return number
|
||||
*/
|
||||
public function getHeight($a)
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ abstract class Block extends Position{
|
|||
public $z = 0;
|
||||
public $slipperiness;
|
||||
|
||||
public static function onRandomTick(Level $level, $x, $y, $z){}
|
||||
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
$this->id = (int) $id;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,13 @@ class FireBlock extends FlowableBlock implements LightingBlock{
|
|||
$this->hardness = 0;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array();
|
||||
}
|
||||
|
|
@ -25,11 +32,6 @@ class FireBlock extends FlowableBlock implements LightingBlock{
|
|||
}
|
||||
$this->level->setBlock($this, new AirBlock(), true, false, true);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== NETHERRACK){
|
||||
$this->level->setBlock($this, new AirBlock(), true, false, true);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,37 @@ class FarmlandBlock extends TransparentBlock{
|
|||
$b = $this->getSide(1);
|
||||
return $b->isTransparent && $b->id != 0;
|
||||
}
|
||||
|
||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||
$meta = $level->level->getBlockDamage($x, $y, $z);
|
||||
$b = $level->getBlockWithoutVector($x, $y + 1, $z, $level, false);
|
||||
if($meta === 0 && mt_rand(0, 5) === 0){
|
||||
$water = self::checkWaterStatic($level, $x, $y, $z);
|
||||
if($water){
|
||||
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(FARMLAND, 1), true, false, true);
|
||||
}elseif(!(($b instanceof Block) && $b->isTransparent && $b->id != 0)){
|
||||
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(DIRT, 0), true, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
if($b instanceof Block && !$b->isFlowable){
|
||||
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(DIRT, 0), true, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkWaterStatic(Level $level, $x, $y, $z){
|
||||
for($bx = $x - 4; $bx <= $x + 4; $bx++){
|
||||
for($by = $y; $by <= $y + 1; $by++){
|
||||
for($bz = $z - 4; $bz <= $z + 4; $bz++){
|
||||
$id = $level->level->getBlockID($bx, $by, $bz);
|
||||
if($id === 8 || $id === 9){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if(!$this->getSide(1)->isTransparent){
|
||||
|
|
@ -22,26 +53,12 @@ class FarmlandBlock extends TransparentBlock{
|
|||
return $type;
|
||||
}
|
||||
}
|
||||
if($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->meta === 0 && mt_rand(0,5) == 0){
|
||||
$water = $this->checkWater();
|
||||
if($water){
|
||||
$this->level->setBlock($this, BlockAPI::get(FARMLAND, 1), true, false, true);
|
||||
}elseif(!$this->hasCrops()){
|
||||
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
|
||||
}
|
||||
}
|
||||
if(!$this->getSide(1)->isFlowable){
|
||||
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getBlockID($x, $y, $z){
|
||||
return $this->level->level->getBlockID($x, $y, $z); //PMFLevel method
|
||||
}
|
||||
}
|
||||
|
||||
public function checkWater(){
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
|
|||
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(REDSTONE_ORE, $level->level->getBlockDamage($x, $y, $z)), false, false, true);
|
||||
}
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
|
||||
if($type === BLOCK_UPDATE_SCHEDULED){
|
||||
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true);
|
||||
return BLOCK_UPDATE_WEAK;
|
||||
}else{
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,56 +20,48 @@ class DirtBlock extends SolidBlock{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_RANDOM){
|
||||
if(mt_rand(0, 3) == 0){
|
||||
$up = $this->getSide(1);
|
||||
if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false;
|
||||
if($this->getGrassInRadius()){
|
||||
$this->level->setBlock($this, BlockAPI::get(GRASS, 0), true, false, true);
|
||||
}
|
||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||
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);
|
||||
}
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
|
||||
public function getBlockID($x, $y, $z){
|
||||
return $this->level->getBlock(new Vector3($x, $y, $z))->getID();
|
||||
}
|
||||
|
||||
public function getGrassInRadius(){
|
||||
$x = $this->x;
|
||||
$y = $this->y;
|
||||
$z = $this->z;
|
||||
|
||||
if($this->getBlockID($x+1, $y, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y, $z) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x, $y, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x, $y, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y, $z) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y, $z-1) == 2) return true;
|
||||
public static function getGrassInRadius(Level $level, $x, $y, $z){ //umwut (although kinda faster than for loop =D)
|
||||
if($level->level->getBlockID($x+1, $y, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x+1, $y, $z) == 2) return true;
|
||||
if($level->level->getBlockID($x+1, $y, $z-1) == 2) return true;
|
||||
if($level->level->getBlockID($x, $y, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x, $y, $z-1) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y, $z) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y, $z-1) == 2) return true;
|
||||
|
||||
if($this->getBlockID($x+1, $y-1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y-1, $z) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y-1, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x, $y-1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x, $y-1, $z) == 2) return true;
|
||||
if($this->getBlockID($x, $y-1, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y-1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y-1, $z) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y-1, $z-1) == 2) return true;
|
||||
if($level->level->getBlockID($x+1, $y-1, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x+1, $y-1, $z) == 2) return true;
|
||||
if($level->level->getBlockID($x+1, $y-1, $z-1) == 2) return true;
|
||||
if($level->level->getBlockID($x, $y-1, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x, $y-1, $z) == 2) return true;
|
||||
if($level->level->getBlockID($x, $y-1, $z-1) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y-1, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y-1, $z) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y-1, $z-1) == 2) return true;
|
||||
|
||||
if($this->getBlockID($x+1, $y+1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y+1, $z) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y+1, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x, $y+1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x, $y+1, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y+1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y+1, $z) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y+1, $z-1) == 2) return true;
|
||||
if($level->level->getBlockID($x+1, $y+1, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x+1, $y+1, $z) == 2) return true;
|
||||
if($level->level->getBlockID($x+1, $y+1, $z-1) == 2) return true;
|
||||
if($level->level->getBlockID($x, $y+1, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x, $y+1, $z-1) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y+1, $z+1) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y+1, $z) == 2) return true;
|
||||
if($level->level->getBlockID($x-1, $y+1, $z-1) == 2) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,12 +46,10 @@ class GrassBlock extends SolidBlock{
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_RANDOM && !$this->getSide(1)->isTransparent && mt_rand(0, 2) == 1){
|
||||
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
|
||||
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);
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ class IceBlock extends TransparentBlock{
|
|||
}
|
||||
}
|
||||
public function onUpdate($type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/
|
||||
if($type === BLOCK_UPDATE_RANDOM){
|
||||
/*if($type === BLOCK_UPDATE_RANDOM){
|
||||
$light = $this->scanForNearbyLightSources(3,3,3);
|
||||
if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){
|
||||
$this->level->setBlock($this, new WaterBlock(), true);
|
||||
|
|
@ -49,7 +49,7 @@ class IceBlock extends TransparentBlock{
|
|||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
return false;
|
||||
return false;*/ //TODO i dont want it now
|
||||
}
|
||||
public function getBreakTime(Item $item, Player $player){
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
|
|
|
|||
|
|
@ -15,53 +15,55 @@ class LeavesBlock extends TransparentBlock{
|
|||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->hardness = 1;
|
||||
}
|
||||
private function createIndex($x, $y, $z){
|
||||
return $index = $x.".".$y.".".$z;
|
||||
public static function createIndex($x, $y, $z){
|
||||
return $x.".".$y.".".$z;
|
||||
}
|
||||
private function findLog(Block $pos, array $visited, $distance){ //port from newest pocketmine
|
||||
$index = $this->createIndex($pos->x, $pos->y, $pos->z);
|
||||
public static function findLog(Level $level, $x, $y, $z, array $visited, $distance){ //port from newest pocketmine
|
||||
$index = self::createIndex($x, $y, $z);
|
||||
if(isset($visited[$index])){
|
||||
return false;
|
||||
}
|
||||
$visited[$index] = true;
|
||||
|
||||
$block = $this->level->getBlock($pos);
|
||||
$block = $level->getBlockWithoutVector($x, $y, $z, false);
|
||||
if($block instanceof WoodBlock){ //type doesn't matter
|
||||
return true;
|
||||
}
|
||||
|
||||
if($block->getId() === $this->getId() && $distance <= 4){
|
||||
foreach(array(2,3,4,5) as $side){
|
||||
if($this->findLog($pos->getSide($side), $visited, $distance + 1)){ //recursion i guess?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if($block->getId() === LEAVES && $distance <= 4){
|
||||
if(self::findLog($level, $x - 1, $y, $z, $visited, $distance + 1)) return true;
|
||||
if(self::findLog($level, $x + 1, $y, $z, $visited, $distance + 1)) return true;
|
||||
if(self::findLog($level, $x, $y, $z - 1, $visited, $distance + 1)) return true;
|
||||
if(self::findLog($level, $x, $y, $z + 1, $visited, $distance + 1)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||
$b = $level->level->getBlock($x, $y, $z);
|
||||
$id = $b[0];
|
||||
$meta = $b[1];
|
||||
|
||||
if(($meta & 0b00001100) === 0x08){
|
||||
$meta &= 0x03;
|
||||
$visited = array();
|
||||
if(!self::findLog($level, $x, $y, $z, $visited, 0)){
|
||||
//$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||
if(mt_rand(1,20) === 1){ //Saplings
|
||||
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SAPLING, $meta & 0x03, 1));
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if(($this->meta & 0b00001100) === 0){
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this, $this, false, false, true);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if(($this->meta & 0b00001100) === 0x08){
|
||||
$this->meta &= 0x03;
|
||||
$visited = array();
|
||||
$check = 0;
|
||||
if($this->findLog($this, $visited, 0) !== true){
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
if(mt_rand(1,20) === 1){ //Saplings
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1));
|
||||
}
|
||||
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
|
||||
}
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ class PMFLevel extends PMF{
|
|||
console("[NOTICE] If you see this message, you should send the log with error to the devs.");
|
||||
}
|
||||
public function getBlockID($x, $y, $z){
|
||||
if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){
|
||||
if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){
|
||||
return 0;
|
||||
}
|
||||
$X = $x >> 4;
|
||||
|
|
@ -347,7 +347,7 @@ class PMFLevel extends PMF{
|
|||
}
|
||||
|
||||
public function setBlockID($x, $y, $z, $block){
|
||||
if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){
|
||||
if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){
|
||||
return false;
|
||||
}
|
||||
$X = $x >> 4;
|
||||
|
|
@ -372,7 +372,7 @@ 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){
|
||||
if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){
|
||||
return 0;
|
||||
}
|
||||
$X = $x >> 4;
|
||||
|
|
@ -397,7 +397,7 @@ 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){
|
||||
if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){
|
||||
return false;
|
||||
}
|
||||
$X = $x >> 4;
|
||||
|
|
@ -436,7 +436,7 @@ class PMFLevel extends PMF{
|
|||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$Y = $y >> 4;
|
||||
if($x < 0 or $z < 0 or $X >= $this->levelData["width"] or $Z >= $this->levelData["width"] or $Y >= $this->levelData["height"] or $y < 0){
|
||||
if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){
|
||||
return [AIR, 0];
|
||||
}
|
||||
$index = $this->getIndex($X, $Z);
|
||||
|
|
@ -473,7 +473,7 @@ class PMFLevel extends PMF{
|
|||
$Y = $y >> 4;
|
||||
$block &= 0xFF;
|
||||
$meta &= 0x0F;
|
||||
if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){
|
||||
if($x < 0 || $x > 255 || $z < 0 || $z > 255 || $y < 0 || $y > 127){
|
||||
return false;
|
||||
}
|
||||
$index = $this->getIndex($X, $Z);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,24 @@ class Level{
|
|||
public $tiles, $blockUpdates, $nextSave, $players = [], $level, $mobSpawner;
|
||||
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
|
||||
|
||||
public static $randomUpdateBlocks = [
|
||||
FIRE => true,
|
||||
FARMLAND => true,
|
||||
GLOWING_REDSTONE_ORE => true,
|
||||
BEETROOT_BLOCK => true,
|
||||
CACTUS => true,
|
||||
CARROT_BLOCK => true,
|
||||
MELON_STEM => true,
|
||||
POTATO_BLOCK => true,
|
||||
PUMPKIN_STEM => true,
|
||||
SUGARCANE_BLOCK => true,
|
||||
WHEAT_BLOCK => true,
|
||||
DIRT => true,
|
||||
GRASS => true,
|
||||
ICE => true,
|
||||
LEAVES => true
|
||||
];
|
||||
|
||||
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->level = $level;
|
||||
|
|
@ -33,6 +51,8 @@ class Level{
|
|||
$this->changedBlocks = [];
|
||||
$this->changedCount = [];
|
||||
$this->mobSpawner = new MobSpawner($this);
|
||||
$this->randInt1 = 0x283AE83; //it is static in 0.1, and i dont care is it in 0.8
|
||||
$this->randInt2 = 0x3C6EF35F;
|
||||
}
|
||||
|
||||
public function close(){
|
||||
|
|
@ -267,9 +287,47 @@ class Level{
|
|||
return $ret;
|
||||
}
|
||||
|
||||
public function fastSetBlockUpdate($x, $y, $z, $id, $meta){
|
||||
$this->level->setBlock($x, $y, $z, $id, $meta);
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $x;
|
||||
$pk->y = $y;
|
||||
$pk->z = $z;
|
||||
$pk->block = $id;
|
||||
$pk->meta = $meta;
|
||||
$this->server->api->player->broadcastPacket($this->players, $pk);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
//$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){
|
||||
if(!($e instanceof Entity)){
|
||||
unset($this->entityList[$k]);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,12 @@ class Position extends Vector3{
|
|||
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
public function setXYZLevel($x, $y, $z, Level $level){
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->z = $z;
|
||||
$this->level = $level;
|
||||
}
|
||||
public function getSide($side, $step = 1){
|
||||
return new Position(parent::getSide($side, $step), 0, 0, $this->level);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue