mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +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
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue