Browse Source

Fixing namespaces issues with Tesseract.

tags/1.0
Ad5001 3 years ago
parent
commit
c9864edd99
13 changed files with 96 additions and 79 deletions
  1. +8
    -0
      src/Ad5001/BetterGen/Main.php
  2. +1
    -2
      src/Ad5001/BetterGen/biome/BetterForest.php
  3. +3
    -3
      src/Ad5001/BetterGen/biome/BetterIcePlains.php
  4. +4
    -3
      src/Ad5001/BetterGen/biome/BetterMesa.php
  5. +4
    -4
      src/Ad5001/BetterGen/biome/BetterMesaPlains.php
  6. +15
    -4
      src/Ad5001/BetterGen/generator/BetterNormal.php
  7. +1
    -1
      src/Ad5001/BetterGen/populator/BushPopulator.php
  8. +5
    -3
      src/Ad5001/BetterGen/populator/FallenTreePopulator.php
  9. +12
    -3
      src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php
  10. +9
    -0
      src/Ad5001/BetterGen/populator/TreePopulator.php
  11. +25
    -11
      src/Ad5001/BetterGen/structure/FallenTree.php
  12. +9
    -1
      src/Ad5001/BetterGen/structure/SakuraTree.php
  13. +0
    -44
      src/Ad5001/BetterGen/tasks/ChestGenerateTask.php

+ 8
- 0
src/Ad5001/BetterGen/Main.php 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");
}
}

+ 1
- 2
src/Ad5001/BetterGen/biome/BetterForest.php 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);


+ 3
- 3
src/Ad5001/BetterGen/biome/BetterIcePlains.php 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() {
@@ -26,8 +26,8 @@ class BetterIcePlains extends SnowyBiome implements Mountainable {
Block::get(Block::DIRT, 0 )
]);
$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);


+ 4
- 3
src/Ad5001/BetterGen/biome/BetterMesa.php 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;
@@ -37,10 +38,10 @@ class BetterMesa extends SandyBiome {
$sugarCane = new TreePopulator ();
$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);


+ 4
- 4
src/Ad5001/BetterGen/biome/BetterMesaPlains.php 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() {
@@ -31,10 +31,10 @@ class BetterMesaPlains extends SandyBiome {
$sugarCane = new SugarCanePopulator ();
$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);


+ 15
- 4
src/Ad5001/BetterGen/generator/BetterNormal.php 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 ),


+ 1
- 1
src/Ad5001/BetterGen/populator/BushPopulator.php View File

@@ -44,7 +44,7 @@ class BushPopulator extends AmountPopulator {
if ($y === -1) {
continue;
}
$tree = new TreePopulator::$types [$this->type] ();
$tree = new TreePopulator::$types[$this->type]();
$bush = new Bush($tree->leafBlock, $tree->leafType ?? $tree->type);
$bush->placeObject($level, $x, $y, $z, $random);
}


+ 5
- 3
src/Ad5001/BetterGen/populator/FallenTreePopulator.php 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);
}
}
}


+ 12
- 3
src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php 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)),


+ 9
- 0
src/Ad5001/BetterGen/populator/TreePopulator.php 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"
];
}
}
/*


+ 25
- 11
src/Ad5001/BetterGen/structure/FallenTree.php 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);


+ 9
- 1
src/Ad5001/BetterGen/structure/SakuraTree.php 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
@@ -427,6 +432,9 @@ class SakuraTree extends Tree {
]
];
const maxPerChunk = 2;


public $trunkHeight = 11;
/*
* Constructs the class


+ 0
- 44
src/Ad5001/BetterGen/tasks/ChestGenerateTask.php 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);
}
}

Loading…
Cancel
Save