Fixing namespaces issues with Tesseract.

This commit is contained in:
Adsooi 2017-05-01 12:03:56 +02:00
parent 2d6bb2c679
commit c9864edd99
13 changed files with 96 additions and 79 deletions

View file

@ -245,4 +245,12 @@ class Main extends PluginBase implements \pocketmine\event\Listener {
LootTable::fillChest($inv->getInventory(), $event->getBlock());
$event->setCancelled();
}
/*
* Check if it's a Tesseract like namespace
* @return bool
*/
public static function isOtherNS() {
return @class_exists("pocketmine\\level\\generator\\normal\\object\\OakTree");
}
}

View file

@ -10,7 +10,6 @@ namespace Ad5001\BetterGen\biome;
use pocketmine\level\generator\normal\biome\ForestBiome;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\populator\TallGrass;
use Ad5001\BetterGen\Main;
use Ad5001\BetterGen\populator\TreePopulator;
use Ad5001\BetterGen\populator\BushPopulator;
@ -39,7 +38,7 @@ class BetterForest extends ForestBiome implements Mountainable {
$trees->setBaseAmount((null !== @constant(TreePopulator::$types [$type] . "::maxPerChunk" )) ? constant(TreePopulator::$types [$type] . "::maxPerChunk" ) : 5);
$this->addPopulator($trees);
$tallGrass = new TallGrass ();
$tallGrass = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\TallGrass () : new \pocketmine\level\generator\populator\TallGrass();
$tallGrass->setBaseAmount(3);
$this->addPopulator($tallGrass);

View file

@ -12,8 +12,8 @@ namespace Ad5001\BetterGen\biome;
use pocketmine\level\generator\normal\biome\SnowyBiome;
use pocketmine\level\generator\biome\Biome;
use pocketmine\block\Block;
use pocketmine\level\generator\populator\TallGrass;
use Ad5001\BetterGen\populator\IglooPopulator;
use Ad5001\BetterGen\Main;
class BetterIcePlains extends SnowyBiome implements Mountainable {
public function __construct() {
@ -27,7 +27,7 @@ class BetterIcePlains extends SnowyBiome implements Mountainable {
]);
$this->addPopulator(new IglooPopulator ());
$tallGrass = new TallGrass ();
$tallGrass = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\TallGrass() : new \pocketmine\level\generator\populator\TallGrass();
$tallGrass->setBaseAmount(3);
$this->addPopulator($tallGrass);

View file

@ -15,6 +15,7 @@ use pocketmine\level\generator\object\OreType;
use pocketmine\level\generator\biome\Biome;
use pocketmine\block\Block;
use pocketmine\block\GoldOre;
use Ad5001\BetterGen\Main;
use Ad5001\BetterGen\populator\TreePopulator;
use Ad5001\BetterGen\populator\CactusPopulator;
use Ad5001\BetterGen\populator\DeadbushPopulator;
@ -38,9 +39,9 @@ class BetterMesa extends SandyBiome {
$sugarCane->setRandomAmount(2);
$sugarCane->setBaseAmount(0);
$ores = new Ore ();
$ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore();
$ores->setOreTypes([
new OreType(new GoldOre (), 2, 8, 0, 32 )
Main::isOtherNS() ? new \pocketmine\level\generator\normal\object\OreType(new GoldOre (), 2, 8, 0, 32 ) : new \pocketmine\level\generator\object\OreType(new GoldOre (), 2, 8, 0, 32 )
]);
$this->addPopulator($cactus);

View file

@ -9,7 +9,6 @@
namespace Ad5001\BetterGen\biome;
use pocketmine\level\generator\normal\biome\SandyBiome;
use pocketmine\level\generator\populator\Ore;
use pocketmine\level\generator\object\OreType;
use pocketmine\level\generator\biome\Biome;
use pocketmine\block\Block;
@ -17,6 +16,7 @@ use pocketmine\block\GoldOre;
use Ad5001\BetterGen\populator\CactusPopulator;
use Ad5001\BetterGen\populator\DeadbushPopulator;
use Ad5001\BetterGen\populator\SugarCanePopulator;
use Ad5001\BetterGen\Main;
class BetterMesaPlains extends SandyBiome {
public function __construct() {
@ -32,9 +32,9 @@ class BetterMesaPlains extends SandyBiome {
$sugarCane->setRandomAmount(20);
$sugarCane->setBaseAmount(3);
$ores = new Ore ();
$ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore();
$ores->setOreTypes([
new OreType(new GoldOre (), 20, 8, 0, 32 )
Main::isOtherNS() ? new \pocketmine\level\generator\normal\object\OreType(new GoldOre (), 2, 8, 0, 32 ) : new \pocketmine\level\generator\object\OreType(new GoldOre (), 2, 8, 0, 32 )
]);
$this->addPopulator($cactus);

View file

@ -14,7 +14,7 @@ use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\Generator;
use pocketmine\level\generator\noise\Simplex;
use pocketmine\level\generator\object\OreType;
use pocketmine\level\generator\populator\GroundCover;
use pocketmine\level\generator\normal\object\OreType as OreType2;
use pocketmine\level\generator\populator\Ore;
use pocketmine\block\Block;
use pocketmine\block\CoalOre;
@ -38,6 +38,7 @@ use Ad5001\BetterGen\populator\RavinePopulator;
use Ad5001\BetterGen\populator\LakePopulator;
use Ad5001\BetterGen\populator\MineshaftPopulator;
use Ad5001\BetterGen\populator\FloatingIslandPopulator;
use Ad5001\BetterGen\Main;
class BetterNormal extends Generator {
const NOT_OVERWRITABLE = [
@ -135,7 +136,7 @@ class BetterNormal extends Generator {
$this->selector->recalculate ();
$cover = new GroundCover ();
$cover = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\GroundCover() : new \pocketmine\level\generator\populator\GroundCover();
$this->generationPopulators [] = $cover;
$cave = new CavePopulator ();
@ -163,8 +164,18 @@ class BetterNormal extends Generator {
$fisl->setRandomAmount(132);
$this->populators [] = $fisl;
$ores = new Ore ();
$ores->setOreTypes([
$ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore();
if(Main::isOtherNS()) $ores->setOreTypes([
new OreType2(new CoalOre (), 20, 16, 0, 128 ),
new OreType2(new IronOre (), 20, 8, 0, 64 ),
new OreType2(new RedstoneOre (), 8, 7, 0, 16 ),
new OreType2(new LapisOre (), 1, 6, 0, 32 ),
new OreType2(new GoldOre (), 2, 8, 0, 32 ),
new OreType2(new DiamondOre (), 1, 7, 0, 16 ),
new OreType2(new Dirt (), 20, 32, 0, 128 ),
new OreType2(new Gravel (), 10, 16, 0, 128 )
]);
if(!Main::isOtherNS()) $ores->setOreTypes([
new OreType(new CoalOre (), 20, 16, 0, 128 ),
new OreType(new IronOre (), 20, 8, 0, 64 ),
new OreType(new RedstoneOre (), 8, 7, 0, 16 ),

View file

@ -17,11 +17,13 @@ use Ad5001\BetterGen\populator\AmountPopulator;
class FallenTreePopulator extends AmountPopulator {
protected $level;
protected $type;
/*
* Constructs the class
* @param $type int
*/
public function __construct() {
public function __construct(int $type = 0) {
$this->setBaseAmount(1);
$this->setRandomAmount(2);
}
@ -36,13 +38,13 @@ class FallenTreePopulator extends AmountPopulator {
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
$this->level = $level;
$amount = $this->getAmount($random);
$fallenTree = new FallenTree();
$fallenTree = new FallenTree(new TreePopulator::$types[$this->type]());
for($i = 0; $i < $amount; $i++) {
$x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
$z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);
$y = $this->getHighestWorkableBlock($x, $z);
if ($y !== -1 and $fallenTree->canPlaceObject($level, $x, $y, $z, $random )) {
$fallenTree->placeObject($level, $x, $y, $z);
$fallenTree->placeObject($level, $x, $y, $z, $random);
}
}
}

View file

@ -6,8 +6,8 @@ use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
use Ad5001\BetterGen\generator\BetterNormal;
use pocketmine\block\Block;
use pocketmine\level\generator\populator\Ore;
use pocketmine\level\generator\object\OreType;
use pocketmine\level\generator\normal\object\OreType as OreType2;
use pocketmine\math\Vector3;
use pocketmine\block\CoalOre;
use pocketmine\block\IronOre;
@ -15,6 +15,7 @@ use pocketmine\block\RedstoneOre;
use pocketmine\block\LapisOre;
use pocketmine\block\GoldOre;
use pocketmine\block\DiamondOre;
use Ad5001\BetterGen\Main;
/*
* FloatingIslandPopulator from BetterGen
@ -137,8 +138,16 @@ class FloatingIslandPopulator extends AmountPopulator {
* @return void
*/
public function populateOres(ChunkManager $level, Vector3 $pos, int $width, int $height, Random $random) {
$ores = new Ore ();
$ores->setOreTypes([
$ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore();
if(Main::isOtherNS()) $ores->setOreTypes([
new OreType2(new CoalOre (), 20, 16, $pos->y - $height, $pos->y ),
new OreType2(new IronOre (), 20, 8, $pos->y - $height, $pos->y - round($height * 0.75)),
new OreType2(new RedstoneOre (), 8, 7, $pos->y - $height, $pos->y - round($height / 2)),
new OreType2(new LapisOre (), 1, 6, $pos->y - $height, $pos->y - round($height / 2)),
new OreType2(new GoldOre (), 2, 8, $pos->y - $height, $pos->y - round($height / 2)),
new OreType2(new DiamondOre (), 1, 7, $pos->y - $height, $pos->y - round($height / 4))
]);
if(!Main::isOtherNS()) $ores->setOreTypes([
new OreType(new CoalOre (), 20, 16, $pos->y - $height, $pos->y ),
new OreType(new IronOre (), 20, 8, $pos->y - $height, $pos->y - round($height * 0.75)),
new OreType(new RedstoneOre (), 8, 7, $pos->y - $height, $pos->y - round($height / 2)),

View file

@ -14,6 +14,8 @@ use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use Ad5001\BetterGen\structure\SakuraTree;
use Ad5001\BetterGen\populator\AmountPopulator;
use Ad5001\BetterGen\Main;
class TreePopulator extends AmountPopulator {
static $types = [
@ -29,6 +31,13 @@ class TreePopulator extends AmountPopulator {
*/
public function __construct($type = 0) {
$this->type = $type;
if(Main::isOtherNS()) {
self::$types = [
"pocketmine\\level\\generator\\normal\\object\\OakTree",
"pocketmine\\level\\generator\\normal\\object\\BirchTree",
"Ad5001\\BetterGen\\structure\\SakuraTree"
];
}
}
/*

View file

@ -1,7 +1,7 @@
<?php
/*
* Bush from BetterGen
* FallenTree from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
@ -14,28 +14,30 @@ use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
use pocketmine\math\Vector3;
use pocketmine\level\generator\object\Tree;
use pocketmine\level\generator\normal\object\Tree as Tree2;
use pocketmine\level\generator\object\Object;
class Bush extends Object {
class FallenTree extends Object {
public $overridable = [
Block::AIR => true,
17 => true,
Block::SNOW_LAYER => true,
Block::LOG2 => true
];
protected $trunk;
protected $tree;
protected $direction;
/*
* Constructs the class
* @param $trunkId int
* @param $trunkData int
* @param $tree Tree
* @throws Exeption
*/
public function __construct($trunk = Block::WOOD, $trunkData = 0) {
$this->trunk = [
$trunkId,
$trunkData
];
public function __construct($tree) {
if(!is_subclass_of($tree, Tree::class) && !is_subclass_of($tree, Tree2::class)) {
throw new Exception("Argument 1 passed to \\Ad5001\\BetterGen\\structure\\FallenTree must be an instance of pocketmine\\level\\generator\\normal\\object\\Tree or pocketmine\\level\\generator\\object\\Tree. Instance of " . get_class($tree) . " given.");
}
$this->tree = $tree;
}
/*
@ -46,7 +48,19 @@ class Bush extends Object {
* @param $z int
* @param $random pocketmine\utils\Random
*/
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) {
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
$randomHeight = round($random->nextBoundedInt(6) - 3);
$this->length = $this->tree->trunkHeight + $randomHeight;
}
/*
* Places a fallen tree
* @param $level pocketmine\level\ChunkManager
* @param $x int
* @param $y int
* @param $z int
*/
public function placeObject(ChunkManager $level, $x, $y, $z) {
$number = $random->nextBoundedInt(6);
$pos = new Vector3($x, $y, $z);
$this->placeLeaf($pos->x, $pos->y, $pos->z, $level);

View file

@ -13,7 +13,12 @@ use pocketmine\block\Block;
use pocketmine\block\Wood;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
use pocketmine\level\generator\object\Tree;
use Ad5001\BetterGen\Main;
if(Main::isOtherNS()) {
class_alias("pocketmine\\level\\generator\\normal\\object\\Tree", "Ad5001\\BetterGen\\structure\\Tree");
} else {
class_alias("pocketmine\\level\\generator\\object\\Tree", "Ad5001\\BetterGen\\structure\\Tree");
}
class SakuraTree extends Tree {
const TRUNK_POS = [ // Checks for trees trunks. Not automaticly generated but there is no point of making more or less
@ -428,6 +433,9 @@ class SakuraTree extends Tree {
];
const maxPerChunk = 2;
public $trunkHeight = 11;
/*
* Constructs the class
*/

View file

@ -1,44 +0,0 @@
<?php
namespace Ad5001\BetterGen\tasks;
use Ad5001\BetterGen\Main;
use Ad5001\BetterGen\loot\LootTable;
use pocketmine\block\Block;
use pocketmine\scheduler\PluginTask;
use pocketmine\level\Position;
use pocketmine\item\Item;
/*
* ChestGenerateTask from BetterGen
* Copyright (C) Ad5001 2017
*
* @author Ad5001
* @link https://en.ad5001.eu
*/
class ChestGenerateTask extends PluginTask {
protected $block;
protected $pos;
protected $item;
/*
* Constructs the class
*/
public function __construct(Main $main, Block $block, Position $pos, Item $item) {
parent::__construct($main);
$this->block = $block;
$this->pos = $pos;
$this->item = $item;
}
/*
* Runs when the delay comes
*/
public function onRun($currentTick) {
$this->block->place($this->item, $this->pos->getLevel()->getBlock($this->pos), $this->block, 0, 0, 0, 0);
$inv = $this->pos->getLevel()->getTile($this->pos);
LootTable::fillChest($inv->getInventory(), $this->pos);
}
}