Add default addon submodule for lootfiles, Reformatting, fix structure command #20, cleanups, Looting file replacement

This commit is contained in:
thebigsmileXD 2017-05-14 07:58:25 +02:00
parent f0a43c5149
commit 58b4870fee
41 changed files with 1522 additions and 1791 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "resources/mcpe-default-addon"]
path = resources/mcpe-default-addon
url = https://github.com/dktapps/mcpe-default-addon.git

View file

@ -10,11 +10,11 @@
# @author Ad5001
# @link https://github.com/Ad5001/BetterGen
name: BetterGen
author: Ad5001
authors: Ad5001, XenialDan
main: Ad5001\BetterGen\Main
version: 1.1
version: 2.0
load: STARTUP
api: [3.0.1, 3.0.0-ALPHA3]
api: [3.0.0-ALPHA3, 3.0.0-ALPHA5]
commands:
createworld:
description: Generates a new world.
@ -24,9 +24,9 @@ commands:
description: Teleports you to an another world
usage: "/worldtp <world name>"
permission: bettergen.cmd.worldtp
temple:
description: Spawns a temple for debugging
usage: "/temple"
structure:
description: Spawns a structure for debugging
usage: "/structure <type>"
permission: bettergen.cmd.debug
permissions:
bettergen.cmd.createworld:

View file

@ -1,183 +0,0 @@
{
"max": 27,
"rail": {
"percentage": 79,
"minCount": 4,
"maxCount": 8,
"minStacks": 3,
"maxStacks": 3,
"id": 66,
"data": 0
},
"torch": {
"percentage": 66,
"minCount": 1,
"maxCount": 16,
"minStacks": 3,
"maxStacks": 3,
"id": 50,
"data": 0
},
"bread": {
"percentage": 45,
"minCount": 1,
"maxCount": 3,
"minStacks": 2,
"maxStacks": 4,
"id": 297,
"data": 0
},
"name tag": {
"percentage": 42,
"minCount": 1,
"maxCount": 1,
"minStacks": 2,
"maxStacks": 4,
"id": 297,
"data": 0
},
"coal": {
"percentage": 32,
"minCount": 3,
"maxCount": 8,
"minStacks": 2,
"maxStacks": 4,
"id": 263,
"data": 0
},
"beetroot seeds": {
"percentage": 32,
"minCount": 2,
"maxCount": 4,
"minStacks": 2,
"maxStacks": 4,
"id": 458,
"data": 0
},
"melon seeds": {
"percentage": 32,
"minCount": 2,
"maxCount": 4,
"minStacks": 2,
"maxStacks": 4,
"id": 362,
"data": 0
},
"pumpkin seeds": {
"percentage": 32,
"minCount": 2,
"maxCount": 4,
"minStacks": 2,
"maxStacks": 4,
"id": 361,
"data": 0
},
"iron ingot": {
"percentage": 32,
"minCount": 1,
"maxCount": 5,
"minStacks": 2,
"maxStacks": 4,
"id": 365,
"data": 0
},
"golden apple": {
"percentage": 28,
"minCount": 1,
"maxCount": 1,
"minStacks": 1,
"maxStacks": 1,
"id": 322,
"data": 0
},
"activator rail": {
"percentage": 27,
"minCount": 1,
"maxCount": 4,
"minStacks": 3,
"maxStacks": 3,
"id": 126,
"data": 0
},
"detector rail": {
"percentage": 27,
"minCount": 1,
"maxCount": 4,
"minStacks": 3,
"maxStacks": 3,
"id": 28,
"data": 0
},
"powered rail": {
"percentage": 27,
"minCount": 1,
"maxCount": 4,
"minStacks": 3,
"maxStacks": 3,
"id": 27,
"data": 0
},
"lapis lazuli": {
"percentage": 17,
"minCount": 4,
"maxCount": 9,
"minStacks": 2,
"maxStacks": 4,
"id": 351,
"data": 4
},
"redstone": {
"percentage": 17,
"minCount": 4,
"maxCount": 9,
"minStacks": 2,
"maxStacks": 4,
"id": 331,
"data": 0
},
"gold ingot": {
"percentage": 17,
"minCount": 1,
"maxCount": 3,
"minStacks": 2,
"maxStacks": 4,
"id": 366,
"data": 0
},
"enchanted book": {
"percentage": 14,
"minCount": 1,
"maxCount": 1,
"minStacks": 1,
"maxStacks": 1,
"id": 403,
"data": 0
},
"diamond": {
"percentage": 11,
"minCount": 1,
"maxCount": 2,
"minStacks": 2,
"maxStacks": 4,
"id": 264,
"data": 0
},
"iron pickaxe": {
"percentage": 7,
"minCount": 1,
"maxCount": 1,
"minStacks": 1,
"maxStacks": 1,
"id": 257,
"data": 0
},
"enchanted golden apple": {
"percentage": 1,
"minCount": 1,
"maxCount": 1,
"minStacks": 1,
"maxStacks": 1,
"id": 466,
"data": 0
}
}

View file

@ -1,154 +0,0 @@
{
"max": 27,
"bone": {
"percentage": 71,
"minCount": 4,
"maxCount": 6,
"minStacks": 2,
"maxStacks": 4,
"id": 352,
"data": 0
},
"rotten_flesh": {
"percentage": 71,
"minCount": 3,
"maxCount": 7,
"minStacks": 2,
"maxStacks": 4,
"id": 367,
"data": 0
},
"gunpowder": {
"percentage": 59,
"minCount": 1,
"maxCount": 8,
"minStacks": 4,
"maxStacks": 4,
"id": 289,
"data": 0
},
"sand": {
"percentage": 59,
"minCount": 1,
"maxCount": 8,
"minStacks": 4,
"maxStacks": 4,
"id": 12,
"data": 0
},
"string": {
"percentage": 59,
"minCount": 1,
"maxCount": 8,
"minStacks": 4,
"maxStacks": 4,
"id": 287,
"data": 0
},
"spider_eye": {
"percentage": 29,
"minCount": 1,
"maxCount": 3,
"minStacks": 2,
"maxStacks": 4,
"id": 375,
"data": 0
},
"enchanted_book": {
"percentage": 24,
"minCount": 1,
"maxCount": 1,
"id": 403,
"data": 0
},
"saddle": {
"percentage": 24,
"minCount": 1,
"maxCount": 1,
"minStacks": 2,
"maxStacks": 4,
"id": 329,
"data": 0
},
"golden_apple": {
"percentage": 24,
"minCount": 1,
"maxCount": 1,
"minStacks": 1,
"maxStacks": 1,
"id": 322,
"data": 0
},
"gold_ingot": {
"percentage": 18,
"minCount": 2,
"maxCount": 7,
"minStacks": 2,
"maxStacks": 4,
"id": 266,
"data": 0
},
"iron_ingot": {
"percentage": 18,
"minCount": 1,
"maxCount": 5,
"minStacks": 2,
"maxStacks": 4,
"id": 265,
"data": 0
},
"emerald": {
"percentage": 18,
"minCount": 1,
"maxCount": 3,
"minStacks": 2,
"maxStacks": 4,
"id": 388,
"data": 0
},
"iron_horse_armor": {
"percentage": 18,
"minCount": 1,
"maxCount": 1,
"minStacks": 2,
"maxStacks": 4,
"id": 417,
"data": 0
},
"gold_horse_armor": {
"percentage": 12,
"minCount": 1,
"maxCount": 1,
"minStacks": 2,
"maxStacks": 4,
"id": 418,
"data": 0
},
"diamond": {
"percentage": 6,
"minCount": 1,
"maxCount": 3,
"minStacks": 2,
"maxStacks": 4,
"id": 264,
"data": 0
},
"diamond_horse_armor": {
"percentage": 6,
"minCount": 1,
"maxCount": 1,
"minStacks": 2,
"maxStacks": 4,
"id": 419,
"data": 0
},
"enchanted_golden_apple": {
"percentage": 3,
"minCount": 1,
"maxCount": 1,
"minStacks": 2,
"maxStacks": 4,
"id": 466,
"data": 0
}
}

@ -0,0 +1 @@
Subproject commit f74c0588519ea390f5a09270d9c5d28d53e2de57

View file

@ -17,44 +17,52 @@ namespace Ad5001\BetterGen;
use Ad5001\BetterGen\biome\BetterForest;
use Ad5001\BetterGen\generator\BetterNormal;
use Ad5001\BetterGen\loot\LootTable;
use Ad5001\BetterGen\structure\FallenTree;
use Ad5001\BetterGen\structure\Igloo;
use Ad5001\BetterGen\structure\SakuraTree;
use Ad5001\BetterGen\structure\Temple;
use Ad5001\BetterGen\structure\Well;
use pocketmine\block\Block;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\level\ChunkPopulateEvent;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\Generator;
use pocketmine\level\generator\object\OakTree;
use pocketmine\level\Position;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\tile\Chest;
use pocketmine\tile\Chest as TileChest;
use pocketmine\block\Chest;
use pocketmine\tile\Tile;
use pocketmine\utils\Config;
use pocketmine\utils\Random;
use pocketmine\utils\TextFormat;
class Main extends PluginBase implements Listener {
const PREFIX = "§l§o§b[§r§l§2Better§aGen§o§b]§r§f ";
const SAKURA_FOREST = 100; // Letting some place for future biomes.
/*
* Called when the plugin enables
*/
/**
* Registers a biome for the normal generator. Normal means(Biome::register) doesn't allow biome to be generated
* @param $id int
* @param $biome Biome
* @return void
*/
public static function registerBiome(int $id, Biome $biome) {
BetterNormal::registerBiome($biome);
}
/*
* Called when the plugin disables
/**
* Called when the plugin enables
*/
public function onEnable() {
$this->getServer()->getPluginManager()->registerEvents($this, $this);
Generator::addGenerator(BetterNormal::class, "betternormal");
@ -64,15 +72,10 @@ class Main extends PluginBase implements Listener {
file_put_contents(LootTable::getPluginFolder() . "processingLoots.json", "{}");
}
/*
* Called when one of the defined commands of the plugin has been called
* @param $sender \pocketmine\command\CommandSender
* @param $cmd \pocketmine\command\Command
* @param $label mixed
* @param $args array
* return bool
/**
* Check if it's a Tesseract like namespace
* @return bool
*/
public static function isOtherNS() {
try {
return @class_exists("pocketmine\\level\\generator\\normal\\object\\OakTree");
@ -81,24 +84,22 @@ class Main extends PluginBase implements Listener {
}
}
/*
* Registers a forest type.
* @param $name string
* @param $treeClass string
* @params $infos Array(temperature, rainfall)
* @return bool
*/
/**
* Called when the plugin disables
*/
public function onDisable() {
}
/*
* Registers a biome for the normal generator. Normal means(Biome::register) doesn't allow biome to be generated
* @param $id int
* @param $biome Biome
* @return void
*/
/**
* Called when one of the defined commands of the plugin has been called
* @param $sender \pocketmine\command\CommandSender
* @param $cmd \pocketmine\command\Command
* @param $label mixed
* @param $args array
* @return bool
*/
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args): bool {
switch ($cmd->getName()) {
case "createworld": // /createworld <name> [generator = betternormal] [seed = rand()] [options(json)]
@ -179,6 +180,11 @@ class Main extends PluginBase implements Listener {
return true;
break;
case "worldtp":
if (!$sender instanceof Player) {
$sender->sendMessage(TextFormat::RED . 'You can\'t use this command');
return true;
}
/** @var Player $sender */
if (isset($args[0])) {
if (is_null($this->getServer()->getLevelByName($args[0]))) {
$this->getServer()->loadLevel($args[0]);
@ -187,41 +193,77 @@ class Main extends PluginBase implements Listener {
return false;
}
}
$sender->teleport(\pocketmine\level\Position::fromObject($player, $this->getServer()->getLevelByName($args[0])));
$sender->teleport(Position::fromObject($sender, $this->getServer()->getLevelByName($args[0])));
$sender->sendMessage("§aTeleporting to {$args[0]}...");
return true;
} else {
return false;
}
break;
case 'temple':{
if($sender instanceof ConsoleCommandSender) return false;
case 'structure': {
if (!$sender instanceof Player) {
$sender->sendMessage(TextFormat::RED . 'You can\'t use this command');
return true;
}
/** @var Player $sender */
if (isset($args[0])) {
switch ($args[0]) {
case 'temple': {
$temple = new Temple();
$temple->placeObject($sender->getLevel(), $sender->x, $sender->y, $sender->z, new Random(microtime()));
return true;
}
break;
case 'fallen': {
$temple = new FallenTree(new OakTree());
$temple->placeObject($sender->getLevel(), $sender->x, $sender->y, $sender->z);
return true;
}
break;
case 'igloo': {
$temple = new Igloo();
$temple->placeObject($sender->getLevel(), $sender->x, $sender->y, $sender->z, new Random(microtime()));
return true;
}
break;
case 'well': {
$temple = new Well();
$temple->placeObject($sender->getLevel(), $sender->x, $sender->y, $sender->z, new Random(microtime()));
return true;
}
break;
case 'sakura': {
$temple = new SakuraTree();
$temple->placeObject($sender->getLevel(), $sender->x, $sender->y, $sender->z, new Random(microtime()));
return true;
}
break;
default: {
}
}
}
$sender->sendMessage(implode(', ', ['temple', 'fallen', 'igloo', 'well', 'sakura']));
return true;
}
}
return false;
}
/*
/**
* Generates a(semi) random seed.
* @return int
*/
public function generateRandomSeed(): int {
return (int)round(rand(0, round(time()) / memory_get_usage(true)) * (int)str_shuffle("127469453645108") / (int)str_shuffle("12746945364"));
}
// Listener
/*
* Checks after a chunk populates so we an add tiles and loot tables
* @param $event pocketmine\event\level\ChunkPopulateEvent
* @return int
/**
* Registers a forest type.
* @param $name string
* @param $treeClass string
* @params $infos Array(temperature, rainfall)
* @return bool
*/
public function registerForest(string $name, string $treeClass, array $infos): bool {
if (!@class_exists($treeClass))
return false;
@ -233,65 +275,33 @@ class Main extends PluginBase implements Listener {
}
/*
* Checks when a player interacts with a loot chest to create it.
/**
* Checks when a player attempts to open a loot chest which is not created yet
* @param PlayerInteractEvent $event
*/
public function onChunkPopulate(ChunkPopulateEvent $event) {
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
foreach ($cfg->getAll() as $key => $value) {
list($x, $y, $z) = explode(";", $key);
if ($value["saveAs"] == "chest" && $event->getLevel()->getBlockIdAt($x, $y, $z) == Block::AIR) {
$event->getLevel()->setBlockIdAt($x, $y, $z, Block::CHEST);
} else {
$cfg->remove($key);
$cfg->save();
}
}
}
/*
* Checks when a player breaks a loot chest which is not created to create it
*/
public function onInteract(PlayerInteractEvent $event) {
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
if ($event->getBlock()->getId() !== Block::CHEST) return;
if (!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return;
$nbt = new CompoundTag("", [
new ListTag("Items", []),
new StringTag("id", Tile::CHEST),
new IntTag("x", $event->getBlock()->x),
new IntTag("y", $event->getBlock()->y),
new IntTag("z", $event->getBlock()->z)
]);
/** @var Chest $chest */
$chest = Tile::createTile(Tile::CHEST, $event->getBlock()->getLevel(), $nbt);
$chest->setName("§k(Fake)§r Minecart chest");
LootTable::fillChest($chest->getInventory(), $event->getBlock());
if (($block = $event->getBlock())->getId() !== Block::CHEST) return;
$this->generateLootChest($block);
}
/*
* Check if it's a Tesseract like namespace
* @return bool
/**
* Checks when a player breaks a loot chest which is not created yet
* @param BlockBreakEvent $event
*/
public function onBlockBreak(BlockBreakEvent $event) {
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
if ($event->getBlock()->getId() !== Block::CHEST) return;
if (!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return;
$nbt = new CompoundTag("", [
new ListTag("Items", []),
new StringTag("id", Tile::CHEST),
new IntTag("x", $event->getBlock()->x),
new IntTag("y", $event->getBlock()->y),
new IntTag("z", $event->getBlock()->z)
]);
/** @var Chest $chest */
$chest = Tile::createTile(Tile::CHEST, $event->getBlock()->getLevel(), $nbt);
$chest->setName("§k(Fake)§r Minecart chest");
LootTable::fillChest($chest->getInventory(), $event->getBlock());
// $event->setCancelled(); //i think nope. You want to break it with items
if (($block = $event->getBlock())->getId() !== Block::CHEST) return;
$this->generateLootChest($block);
}
private function generateLootChest(Block $block) {
//TODO
if (!$block instanceof Chest) return;
if (is_null($block->getLevel()->getTile($block))) {
//TODO new tile, but no loot, because we don't know which type of loot it is
return;
}
if (!($tile = $block->getLevel()->getTile($block)) instanceof TileChest) return;
/** TileChest $tile */
$tile->getInventory()->setContents([]);//TODO
}
}

View file

@ -11,14 +11,15 @@
* @author Ad5001
* @link https://github.com/Ad5001/BetterGen
*/
namespace Ad5001\BetterGen\biome;
use Ad5001\BetterGen\generator\BetterNormal;
use Ad5001\BetterGen\populator\CactusPopulator;
use Ad5001\BetterGen\populator\DeadbushPopulator;
use Ad5001\BetterGen\populator\SugarCanePopulator;
use Ad5001\BetterGen\populator\TemplePopulator;
use Ad5001\BetterGen\populator\WellPopulator;
use Ad5001\BetterGen\generator\BetterNormal;
use pocketmine\block\Block;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\normal\biome\SandyBiome;
@ -73,11 +74,12 @@ class BetterDesert extends SandyBiome implements Mountainable {
Block::get(Block::SANDSTONE, 0)
]);
}
public function getName(): string {
return "BetterDesert";
}
/*
/**
* Returns biome id
*/
public function getId() {

View file

@ -34,6 +34,7 @@ class BetterForest extends ForestBiome implements Mountainable {
Biome::BIRCH_FOREST,
Main::SAKURA_FOREST
];
public function __construct($type = 0, array $infos = [0.6, 0.5]) {
parent::__construct($type);
$this->clearPopulators();
@ -63,17 +64,7 @@ class BetterForest extends ForestBiome implements Mountainable {
$this->temperature = $infos[0];
$this->rainfall = $infos[1];
}
public function getName() {
return str_ireplace(" ", "", self::$types[$this->type]);
}
/**
* Returns the ID relatively.
* @return int
*/
public function getId() {
return self::$ids[$this->type];
}
/**
* @param string $name
* @param string $treeClass
@ -87,4 +78,16 @@ class BetterForest extends ForestBiome implements Mountainable {
Main::register(Main::SAKURA_FOREST + (count(self::$types) - 2), new BetterForest(count(self::$types) - 1, $infos));
return true;
}
public function getName() {
return str_ireplace(" ", "", self::$types[$this->type]);
}
/**
* Returns the ID relatively.
* @return int
*/
public function getId() {
return self::$ids[$this->type];
}
}

View file

@ -42,6 +42,7 @@ class BetterIcePlains extends SnowyBiome implements Mountainable {
$this->temperature = 0.05;
$this->rainfall = 0.8;
}
public function getName() {
return "BetterIcePlains";
}

View file

@ -104,11 +104,12 @@ class BetterMesa extends SandyBiome {
Block::get(Block::RED_SANDSTONE, 0)
]);
}
public function getName(): string {
return "BetterMesa";
}
/*
/**
* Returns biome id
*/
public function getId() {

View file

@ -100,11 +100,12 @@ class BetterMesaPlains extends SandyBiome {
Block::get(Block::RED_SANDSTONE, 0)
]);
}
public function getName(): string {
return "BetterMesaPlains";
}
/*
/**
* Returns biome id
*/
public function getId() {

View file

@ -40,11 +40,12 @@ class BetterRiver extends Biome {
$this->temperature = 0.5;
$this->rainfall = 0.7;
}
public function getName() {
return "BetterRiver";
}
/*
/**
* Returns the ID relatively.
*/
public function getId() {

View file

@ -11,6 +11,7 @@
* @author Ad5001
* @link https://github.com/Ad5001/BetterGen
*/
namespace Ad5001\BetterGen\generator;
use pocketmine\level\generator\biome\Biome;
@ -31,6 +32,7 @@ class BetterBiomeSelector extends BiomeSelector {
/** @var Biome[] */
private $biomes = [];
private $lookup;
public function __construct(Random $random, callable $lookup, Biome $fallback) {
parent::__construct($random, $lookup, $fallback);
$this->fallback = $fallback;
@ -38,17 +40,13 @@ class BetterBiomeSelector extends BiomeSelector {
$this->temperature = new Simplex($random, 2, 1 / 16, 1 / 512);
$this->rainfall = new Simplex($random, 2, 1 / 16, 1 / 512);
}
public function recalculate() {
} // Using our own system, No need for that
public function addBiome(Biome $biome) {
$this->biomes[$biome->getId()] = $biome;
}
public function getTemperature($x, $z) {
return ($this->temperature->noise2D($x, $z, true) + 1) / 2;
}
public function getRainfall($x, $z) {
return ($this->rainfall->noise2D($x, $z, true) + 1) / 2;
}
/**
*
@ -67,4 +65,12 @@ class BetterBiomeSelector extends BiomeSelector {
$b = (($biomeId instanceof Biome) ? $biomeId : ($this->biomes[$biomeId] ?? $this->fallback));
return $b;
}
public function getTemperature($x, $z) {
return ($this->temperature->noise2D($x, $z, true) + 1) / 2;
}
public function getRainfall($x, $z) {
return ($this->rainfall->noise2D($x, $z, true) + 1) / 2;
}
}

View file

@ -59,19 +59,11 @@ class BetterNormal extends Generator {
Block::WATER,
Block::STILL_WATER
];
/** @var BetterBiomeSelector */
protected $selector;
/** @var Level */
protected $level;
/** @var Random */
protected $random;
protected $populators = [ ];
protected $generationPopulators = [ ];
public static $biomes = [];
/** @var Biome[] */
public static $biomeById = [];
public static $levels = [];
protected static $GAUSSIAN_KERNEL = null; // From main class
protected static $GAUSSIAN_KERNEL = null;
protected static $SMOOTH_SIZE = 2;
protected static $options = [
"delBio" => [
@ -80,33 +72,59 @@ class BetterNormal extends Generator {
"Lakes"
]
];
/** @var BetterBiomeSelector */
protected $selector;
/** @var Level */
protected $level;
/** @var Random */
protected $random; // From main class
protected $populators = [];
protected $generationPopulators = [];
protected $waterHeight = 63;
private $noiseBase;
/*
* Picks a biome by X and Z
* @param $x int
* @param $z int
* @return Biome
/**
* Constructs the class
* @param $options array
*/
public function pickBiome($x, $z) {
$hash = $x * 2345803 ^ $z * 9236449 ^ $this->level->getSeed ();
$hash *= $hash + 223;
$xNoise = $hash >> 20 & 3;
$zNoise = $hash >> 22 & 3;
if ($xNoise == 3) {
$xNoise = 1;
public function __construct(array $options = []) {
self::$options["preset"] = $options["preset"];
$options = (array)json_decode($options["preset"]);
if (isset($options["delBio"])) {
if (is_string($options["de"])) $options["delBio"] = explode(",", $options["delBio"]);
if (count($options["delBio"]) !== 0) {
self::$options["delBio"] = $options["delBio"];
}
}
if (isset($options["delStruct"])) {
if (is_string($options["delStruct"])) $options["delStruct"] = explode(",", $options["delStruct"]);
if (count($options["delStruct"]) !== 0) {
self::$options["delStruct"] = $options["delStruct"];
}
}
if (self::$GAUSSIAN_KERNEL === null) {
self::generateKernel();
}
if ($zNoise == 3) {
$zNoise = 1;
}
$b = $this->selector->pickBiome($x + $xNoise - 1, $z + $zNoise - 1);
if ($b instanceof Mountainable && $this->random->nextBoundedInt(1000) < 3) {
$b = clone $b;
// $b->setElevation($b->getMinElevation () + (50 * $b->getMinElevation () / 100), $b->getMaxElevation () + (50 * $b->getMinElevation () / 100));
/**
* Generates the generation kernel based on smooth size (here 2)
*/
private static function generateKernel() {
self::$GAUSSIAN_KERNEL = [];
$bellSize = 1 / self::$SMOOTH_SIZE;
$bellHeight = 2 * self::$SMOOTH_SIZE;
for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; $sx++) {
self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE] = [];
for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; $sz++) {
$bx = $bellSize * $sx;
$bz = $bellSize * $sz;
self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE] [$sz + self::$SMOOTH_SIZE] = $bellHeight * exp(-($bx * $bx + $bz * $bz) / 2);
}
}
return $b;
}
/**
@ -224,7 +242,7 @@ class BetterNormal extends Generator {
}
}
/*
/**
* Adds a biome to the selector. Do not use this method directly use Main::registerBiome which registers it properly
* @param $biome Biome
* @return bool
@ -242,7 +260,7 @@ class BetterNormal extends Generator {
return true;
}
/*
/**
* Returns a biome by temperature
* @param $temperature float
* @param $rainfall float
@ -274,16 +292,7 @@ class BetterNormal extends Generator {
return $ret;
}
/*
* Returns a biome by its id
* @param $id int
* @return Biome
*/
public function getBiomeById(int $id): Biome {
return self::$biomeById[$id] ?? self::$biomeById[Biome::OCEAN];
}
/*
/**
* Generates a chunk.
* Cloning method to make it work with new methods.
* @param $chunkX int
@ -356,7 +365,33 @@ class BetterNormal extends Generator {
}
}
/*
/**
* Picks a biome by X and Z
* @param $x int
* @param $z int
* @return Biome
*/
public function pickBiome($x, $z) {
$hash = $x * 2345803 ^ $z * 9236449 ^ $this->level->getSeed();
$hash *= $hash + 223;
$xNoise = $hash >> 20 & 3;
$zNoise = $hash >> 22 & 3;
if ($xNoise == 3) {
$xNoise = 1;
}
if ($zNoise == 3) {
$zNoise = 1;
}
$b = $this->selector->pickBiome($x + $xNoise - 1, $z + $zNoise - 1);
if ($b instanceof Mountainable && $this->random->nextBoundedInt(1000) < 3) {
$b = clone $b;
// $b->setElevation($b->getMinElevation () + (50 * $b->getMinElevation () / 100), $b->getMaxElevation () + (50 * $b->getMinElevation () / 100));
}
return $b;
}
/**
* Populates a chunk.
* @param $chunkX int
* @param $chunk2 int
@ -380,74 +415,41 @@ class BetterNormal extends Generator {
$biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random);
}
/*
* Constructs the class
* @param $options array
/**
* Returns a biome by its id
* @param $id int
* @return Biome
*/
public function __construct(array $options = []) {
self::$options["preset"] = $options["preset"];
$options = (array) json_decode($options["preset"]);
if(isset($options["delBio"])) {
if(is_string($options["de"])) $options["delBio"] = explode(",", $options["delBio"]);
if(count($options["delBio"]) !== 0) {
self::$options["delBio"] = $options["delBio"];
}
}
if(isset($options["delStruct"])) {
if(is_string($options["delStruct"])) $options["delStruct"] = explode(",", $options["delStruct"]);
if(count($options["delStruct"]) !== 0) {
self::$options["delStruct"] = $options["delStruct"];
}
}
if (self::$GAUSSIAN_KERNEL === null) {
self::generateKernel ();
}
}
/*
* Generates the generation kernel based on smooth size (here 2)
*/
private static function generateKernel() {
self::$GAUSSIAN_KERNEL = [ ];
$bellSize = 1 / self::$SMOOTH_SIZE;
$bellHeight = 2 * self::$SMOOTH_SIZE;
for($sx = - self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; $sx++) {
self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE] = [ ];
for($sz = - self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; $sz++) {
$bx = $bellSize * $sx;
$bz = $bellSize * $sz;
self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE] [$sz + self::$SMOOTH_SIZE] = $bellHeight * exp(- ($bx * $bx + $bz * $bz) / 2);
}
}
public function getBiomeById(int $id): Biome {
return self::$biomeById[$id] ?? self::$biomeById[Biome::OCEAN];
}
//  Returns the name of the generator
public function getName() {
return "betternormal";
}
/*
/**
* Gives the generators settings.
* @return array
*/
public function getSettings(): array {
return self::$options;
}
public function getSpawn() {
return new Vector3(127.5, 128, 127.5);
}
/*
/**
* Returns a safe spawn location
*/
public function getSafeSpawn() {
return new Vector3(127.5, $this->getHighestWorkableBlock(127, 127), 127.5);
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -14,116 +14,154 @@
namespace Ad5001\BetterGen\loot;
use pocketmine\inventory\BaseInventory;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\nbt\NBT;
use pocketmine\item\Tool;
use pocketmine\Server;
use pocketmine\utils\Config;
use pocketmine\utils\Random;
/*
* This class is used for loot setting.
* Please note that they AREN'T as powerful as PC ones due to some implementations limitations.
* Loot table format:
* {
* "max": Max number of loots (storable amount)
* "example": {
* "percentage": Chance of appearing(in percent)
* "minCount": Minimal count
* "maxCount": Maximal count
* "id": Id of the item
* "data": Item damage
* "tags": {"display": {"Name": "Example NBT data"}}. This parameter is optional
* "minStacks": If chosen, the minimum amount of stacks that can be found
* "maxStacks": If chosen the maximum number of stacks that can be chosen
* }
* }
*/
class LootTable {
const LOOT_NAMES = [
"temple",
"igloo",
"mineshaft"
];
const LOOT_SAVE = [
"chest",
"chest",
"chest"
];
const LOOT_DESERT_TEMPLE = 0;
const LOOT_IGLOO = 1;
const LOOT_MINESHAFT = 2;
/*
* Asynchronous loot table choosing
* @param $place pocketmine\math\Vector3
* @param $type int
* @param $random pocketmine\utils\Random
* @return void
/**
* @var null|Config The lootfile (.json) thats used
*/
public static function buildLootTable(Vector3 $place, int $type, Random $random) {
if($place->y < 1) return; // Making sure sometimes that it doesn't write for nothing
$cfg = new Config(self::getPluginFolder() . "processingLoots.json", Config::JSON);
$lootsFromJson = json_decode(file_get_contents(self::getResourcesFolder() . "loots/" . self::LOOT_NAMES[$type] . ".json"), true);
$loots =[];
foreach($lootsFromJson as $loot) {
if(is_array($loot) && $random->nextBoundedInt(101) < $loot["percentage"])
$loots[] = $loot;
}
if($lootsFromJson["max"] < count($loots)) {
while($lootsFromJson["max"] < count($loots))
unset($loots[array_rand($loots)]);
}
$loots["saveAs"] = self::LOOT_SAVE[$type];
$cfg->set($place->x . ";" . $place->y . ";" . $place->z, $loots);
$cfg->save();
private $lootFile = null;
/**
* LootTable constructor.
* @param Config $lootFile
*/
public function __construct(Config $lootFile) {
$this->lootFile = $lootFile;
}
/*
* Synchronous inventory filling with loot table.
* @param $inv pocketmine\inventory\BaseInventory
* @param $pos pocketmine\math\Vector3
* @return void
/**
* Public function to generate loot. A {@link: \pocketmine\utils\Random} can be passed.
* @param Random|null $random
* @return Item[]
*/
public static function fillChest(BaseInventory $inv, Vector3 $pos) {
$cfg = new Config(self::getPluginFolder() . "processingLoots.json", Config::JSON);
if($cfg->exists($pos->x . ";" . $pos->y . ";" . $pos->z)) {
$loots = $cfg->get($pos->x . ";" . $pos->y . ";" . $pos->z);
public function createLoot(Random $random = null) {
return self::getRandomLoot($random);
}
/**
* Internal function. Serves as actual file reader + sub-table loader
* Do _NOT_ use this in the source, use LootTable::createLoot instead
* @param Random|null $random
* @return Item[]
*/
private function getRandomLoot(Random $random = null) {
if (is_null($random)) $random = new Random(microtime());
$array = [];
$items = [];
foreach($loots as $loot) {
if(!is_array($loot)) continue;
$randCount = rand($loot["minStacks"], $loot["maxStacks"]);
for($i = 0; $i <= $randCount; $i++) {
$rand = rand(0, count($loots));
$items[$rand] = Item::get($loot["id"], $loot["data"], rand($loot["minCount"], $loot["maxCount"]));
if(isset($loot["tags"])) $items[$rand]->setCompoundTag(NBT::parseJSON($loot["tags"]));
foreach ($this->lootFile->get("pools") as $rolls) {
$maxrolls = $rolls["rolls"];//TODO: $rolls["conditions"]
while ($maxrolls > 0) {
$maxrolls--;
foreach ($rolls["entries"] as $index => $entries) {
$array[] = $entries["weight"]??1;
}
}
$inv->setContents($items);
$cfg->remove($pos->x . ";" . $pos->y . ";" . $pos->z);
$cfg->save();
$val = $rolls["entries"][$this->getRandomWeightedElement($array)];
//typecheck
if ($val["type"] == "loot_table") {
$loottable = new self(new Config(Server::getInstance()->getFilePath() . "src/pocketmine/resources/" . $val["name"] . ".json", Config::JSON, []));
$items = array_merge($items, $loottable->getRandomLoot());
unset($loottable);
} elseif ($val["type"] == "item") {
print $val["name"] . PHP_EOL;
//name fix
$val["name"] = self::fixItemName($val["name"]);
$item = Item::fromString($val["name"]);
if (isset($val["functions"])) {
foreach ($val["functions"] as $function) {
switch ($functionname = $function["function"]) {
case "set_damage": {
if ($item instanceof Tool) $item->setDamage(mt_rand($function["damage"]["min"] * $item->getMaxDurability(), $function["damage"]["max"] * $item->getMaxDurability()));
else $item->setDamage($random->nextRange($function["damage"]["min"], $function["damage"]["max"]));
}
break;
case "set_data": {
//fish fix, blame mojang
if ($item->getId() == Item::RAW_FISH) {
switch ($function["data"]) {
case 1:
$item = Item::get(Item::RAW_SALMON, $item->getDamage(), $item->getCount(), $item->getCompoundTag());
break;
case 2:
$item = Item::get(Item::CLOWN_FISH, $item->getDamage(), $item->getCount(), $item->getCompoundTag());
break;
case 3:
$item = Item::get(Item::PUFFER_FISH, $item->getDamage(), $item->getCount(), $item->getCompoundTag());
break;
default:
break;
}
} else $item->setDamage($function["data"]);
}
break;
case "set_count": {
$item->setCount($random->nextRange($function["count"]["min"], $function["count"]["max"]));
}
break;
case "furnace_smelt": {
/* TODO
Mostly bound to conditions (burning)
"conditions": [
{
"condition": "entity_properties",
"entity": "this",
"properties": {
"on_fire": true
}
}
]
*/
}
break;
case "enchant_randomly": {
//TODO
}
break;
case "enchant_with_levels": {
//TODO
}
break;
case "looting_enchant": {
//TODO
}
break;
default:
assert("Unknown looting table function $functionname, skipping");
}
}
}
$items[] = $item;
}
}
return $items;
}
/*
* Returns the plugins folder.
* @return string
/**
* TODO: Make random actually useful here.
* @param array $weightedValues
* @return mixed
*/
public static function getPluginFolder(): string {
$dir = explode(DIRECTORY_SEPARATOR, __DIR__);
$c = count($dir);
unset($dir[$c - 1], $dir[$c - 2], $dir[$c - 3], $dir[$c - 4], $dir[$c - 5]);
return str_ireplace("phar://", "", implode(DIRECTORY_SEPARATOR, $dir)) . DIRECTORY_SEPARATOR . "BetterGen" . DIRECTORY_SEPARATOR;
private function getRandomWeightedElement(array $weightedValues) {
$array = array();
foreach ($weightedValues as $key => $weight) {
$array = array_merge(array_fill(0, $weight, $key), $array);
}
return $array[array_rand($array)];
}
/*
* Returns the resources folder.
* @return string
/**
* Fixes the item names because #BlameMojang for not changing the id's from PC -> PE
* @param $name
* @return mixed
*/
public static function getResourcesFolder(): string {
$dir = explode(DIRECTORY_SEPARATOR, __DIR__);
$c = count($dir);
unset($dir[$c - 1], $dir[$c - 2], $dir[$c - 3], $dir[$c - 4]);
return str_ireplace("phar://", "", implode(DIRECTORY_SEPARATOR, $dir)) . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR;
private static function fixItemName($name) {
//TODO add a switch-case here
return $name;
}
}

View file

@ -21,27 +21,11 @@ abstract class AmountPopulator extends Populator {
protected $baseAmount = 0;
protected $randomAmount = 0;
/*
/**
* Crosssoftware class for random amount
*/
/*
* Sets the random addition amount
* @param $amount int
*/
public function setRandomAmount(int $amount) {
$this->randomAmount = $amount;
}
/*
* Sets the base addition amount
* @param $amount int
*/
public function setBaseAmount(int $amount) {
$this->baseAmount = $amount;
}
/*
/**
* Returns the amount based on random
* @param $random Random
*/
@ -49,7 +33,7 @@ abstract class AmountPopulator extends Populator {
return $this->baseAmount + $random->nextRange(0, $this->randomAmount + 1);
}
/*
/**
* Returns the base amount
* @return int
*/
@ -57,11 +41,27 @@ abstract class AmountPopulator extends Populator {
return $this->baseAmount;
}
/*
/**
* Sets the base addition amount
* @param $amount int
*/
public function setBaseAmount(int $amount) {
$this->baseAmount = $amount;
}
/**
* Returns the random additional amount
* @return int
*/
public function getRandomAmount(): int {
return $this->randomAmount;
}
/**
* Sets the random addition amount
* @param $amount int
*/
public function setRandomAmount(int $amount) {
$this->randomAmount = $amount;
}
}

View file

@ -25,7 +25,7 @@ class BushPopulator extends AmountPopulator {
protected $level;
protected $type;
/*
/**
* Constructs the class
* @param $type int
*/
@ -33,7 +33,7 @@ class BushPopulator extends AmountPopulator {
$this->type = $type;
}
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -56,7 +56,7 @@ class BushPopulator extends AmountPopulator {
}
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -24,7 +24,8 @@ use pocketmine\utils\Random;
class CactusPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
/**
* Constructs the class
*/
public function __construct() {
@ -32,7 +33,7 @@ class CactusPopulator extends AmountPopulator {
$this->setRandomAmount(2);
}
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -53,7 +54,7 @@ class CactusPopulator extends AmountPopulator {
}
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -22,12 +22,12 @@ use pocketmine\math\Vector3;
use pocketmine\utils\Random;
class CavePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
const STOP = false;
const CONTINUE = true;
/** @var ChunkManager */
protected $level;
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -60,7 +60,7 @@ class CavePopulator extends AmountPopulator {
}
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int
@ -78,7 +78,7 @@ class CavePopulator extends AmountPopulator {
return ++$y;
}
/*
/**
* Generates a cave
* @param $x int
* @param $y int
@ -97,7 +97,8 @@ class CavePopulator extends AmountPopulator {
}
}
}
/*
/**
* Generates a cave branch.
* @param $x int
* @param $y int

View file

@ -14,7 +14,6 @@
namespace Ad5001\BetterGen\populator;
use Ad5001\BetterGen\generator\BetterBiomeSelector;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\level\generator\biome\Biome;
@ -25,7 +24,7 @@ class DeadbushPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int

View file

@ -25,7 +25,8 @@ class FallenTreePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
protected $type;
/*
/**
* Constructs the class
* @param $type int
*/
@ -35,7 +36,7 @@ class FallenTreePopulator extends AmountPopulator {
$this->setRandomAmount(2);
}
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int

View file

@ -33,7 +33,7 @@ use pocketmine\utils\Random;
class FloatingIslandPopulator extends AmountPopulator {
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -62,8 +62,7 @@ class FloatingIslandPopulator extends AmountPopulator {
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int
@ -82,8 +81,7 @@ class FloatingIslandPopulator extends AmountPopulator {
}
/*
/**
* Builds a an island shape
* @param $level pocketmine\level\ChunkManager
* @param $pos pocketmine\math\Vector3
@ -132,9 +130,7 @@ class FloatingIslandPopulator extends AmountPopulator {
}
/*
/**
* BPopulate the island with ores
* @param $level pocketmine\level\ChunkManager
* @param $pos pocketmine\math\Vector3

View file

@ -24,7 +24,7 @@ class IglooPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -43,7 +43,7 @@ class IglooPopulator extends AmountPopulator {
$igloo->placeObject($level, $x, $y, $z, $random);
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -25,7 +25,7 @@ class LakePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -52,7 +52,7 @@ class LakePopulator extends AmountPopulator {
$level->setBlockIdAt($xx, $yy, $zz, Block::AIR);
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -22,9 +22,6 @@ use pocketmine\math\Vector3;
use pocketmine\utils\Random;
class MineshaftPopulator extends AmountPopulator {
protected $maxPath;
/** @var ChunkManager */
protected $level;
const DIR_XPLUS = 0;
const DIR_XMIN = 1;
const DIR_ZPLUS = 2;
@ -32,8 +29,11 @@ class MineshaftPopulator extends AmountPopulator {
const TYPE_FORWARD = 0;
const TYPE_CROSSPATH = 1;
const TYPE_STAIRS = 2;
protected $maxPath;
/** @var ChunkManager */
protected $level;
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -420,4 +420,5 @@ class MineshaftPopulator extends AmountPopulator {
}
}
}
?>

View file

@ -21,11 +21,11 @@ use pocketmine\level\Level;
use pocketmine\utils\Random;
class RavinePopulator extends AmountPopulator {
const NOISE = 250;
/** @var ChunkManager */
protected $level;
const NOISE = 250;
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -69,7 +69,7 @@ class RavinePopulator extends AmountPopulator {
}
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int
@ -87,7 +87,7 @@ class RavinePopulator extends AmountPopulator {
return ++$y;
}
/*
/**
* Builds a ravine part
* @param $x int
* @param $y int

View file

@ -23,7 +23,8 @@ use pocketmine\utils\Random;
class SugarCanePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
/**
* Constructs the class
*/
public function __construct() {
@ -31,7 +32,7 @@ class SugarCanePopulator extends AmountPopulator {
$this->setRandomAmount(2);
}
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -52,7 +53,7 @@ class SugarCanePopulator extends AmountPopulator {
}
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -24,7 +24,7 @@ class TemplePopulator extends AmountPopulator {
/** @var Level */
protected $level;
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -43,7 +43,7 @@ class TemplePopulator extends AmountPopulator {
$temple->placeObject($level, $x, $y - 1, $z, $random);
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -33,7 +33,7 @@ class TreePopulator extends AmountPopulator {
protected $level;
protected $type;
/*
/**
* Constructs the class
*/
public function __construct($type = 0) {
@ -47,7 +47,7 @@ class TreePopulator extends AmountPopulator {
}
}
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -71,7 +71,7 @@ class TreePopulator extends AmountPopulator {
}
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -24,7 +24,7 @@ class WellPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
/**
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
@ -43,7 +43,7 @@ class WellPopulator extends AmountPopulator {
$well->placeObject($level, $x, $y, $z, $random);
}
/*
/**
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int

View file

@ -30,7 +30,7 @@ class Bush extends Object {
protected $leaf;
protected $height;
/*
/**
* Constructs the class
* @param $leafId int
* @param $leafData int
@ -42,7 +42,7 @@ class Bush extends Object {
];
}
/*
/**
* Places a bush
* @param $level pocketmine\level\ChunkManager
* @param $x int
@ -64,7 +64,7 @@ class Bush extends Object {
}
}
/*
/**
* Places a leaf
* @param $x int
* @param $y int

View file

@ -21,7 +21,7 @@ use pocketmine\utils\Random;
class Cactus extends Object {
/*
/**
* Checks if a cactus is placeable
* @param $level pocketmine\level\ChunkManager
* @param $x int
@ -42,7 +42,7 @@ class Cactus extends Object {
return true;
}
/*
/**
* Places a cactus
* @param $level pocketmine\level\ChunkManager
* @param $x int

View file

@ -41,7 +41,7 @@ class FallenTree extends Object {
protected $random;
private $length = 0;
/*
/**
* Constructs the class
* @param $tree ObjectTree
* @throws Exeption
@ -50,7 +50,7 @@ class FallenTree extends Object {
$this->tree = $tree;
}
/*
/**
* Places a fallen tree
* @param $level pocketmine\level\ChunkManager
* @param $x int
@ -103,7 +103,7 @@ class FallenTree extends Object {
return true;
}
/*
/**
* Places a fallen tree
* @param $level pocketmine\level\ChunkManager
* @param $x int
@ -147,7 +147,7 @@ class FallenTree extends Object {
}
}
/*
/**
* Places a Block
* @param $x int
* @param $y int

View file

@ -33,51 +33,7 @@ class Igloo extends Object {
];
protected $direction;
/*
* Checks if an igloo is placeable
* @param $level pocketmine\level\ChunkManager
* @param $x int
* @param $y int
* @param $z int
* @param $random pocketmine\utils\Random
* @return bool
*/
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
$this->direction = $random->nextBoundedInt(4);
switch ($this->direction) {
case 0 : // Entrance is x+
for($xx = $x - 3; $xx <= $x + 4; $xx ++)
for($yy = $y + 1; $yy <= $y + 4; $yy ++)
for($zz = $z - 3; $zz <= $z + 3; $zz ++)
if (! isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
return false;
break;
case 1 : // Entrance is x-
for($xx = $x - 4; $xx <= $x + 3; $xx ++)
for($yy = $y + 1; $yy <= $y + 4; $yy ++)
for($zz = $z - 3; $zz <= $z + 3; $zz ++)
if (! isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
return false;
break;
case 2 : // Entrance is z+
for($xx = $x - 3; $xx <= $x + 3; $xx ++)
for($yy = $y + 1; $yy <= $y + 4; $yy ++)
for($zz = $z - 3; $zz <= $z + 4; $zz ++)
if (! isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
return false;
break;
case 3 : // Entrance is z-
for($xx = $x - 3; $xx <= $x + 3; $xx ++)
for($yy = $y + 1; $yy <= $y + 4; $yy ++)
for($zz = $z - 4; $zz <= $z + 3; $zz ++)
if (! isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
return false;
break;
}
return true;
}
/*
/**
* Places an igloo
* @param $level pocketmine\level\ChunkManager
* @param $x int
@ -388,4 +344,48 @@ class Igloo extends Object {
}
return true;
}
/**
* Checks if an igloo is placeable
* @param $level pocketmine\level\ChunkManager
* @param $x int
* @param $y int
* @param $z int
* @param $random pocketmine\utils\Random
* @return bool
*/
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
$this->direction = $random->nextBoundedInt(4);
switch ($this->direction) {
case 0 : // Entrance is x+
for ($xx = $x - 3; $xx <= $x + 4; $xx++)
for ($yy = $y + 1; $yy <= $y + 4; $yy++)
for ($zz = $z - 3; $zz <= $z + 3; $zz++)
if (!isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
return false;
break;
case 1 : // Entrance is x-
for ($xx = $x - 4; $xx <= $x + 3; $xx++)
for ($yy = $y + 1; $yy <= $y + 4; $yy++)
for ($zz = $z - 3; $zz <= $z + 3; $zz++)
if (!isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
return false;
break;
case 2 : // Entrance is z+
for ($xx = $x - 3; $xx <= $x + 3; $xx++)
for ($yy = $y + 1; $yy <= $y + 4; $yy++)
for ($zz = $z - 3; $zz <= $z + 4; $zz++)
if (!isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
return false;
break;
case 3 : // Entrance is z-
for ($xx = $x - 3; $xx <= $x + 3; $xx++)
for ($yy = $y + 1; $yy <= $y + 4; $yy++)
for ($zz = $z - 4; $zz <= $z + 3; $zz++)
if (!isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
return false;
break;
}
return true;
}
}

View file

@ -445,7 +445,7 @@ class SakuraTree extends Tree {
public $leafType;
public $leaf2Type;
/*
/**
* Constructs the class
*/
public function __construct() {
@ -457,7 +457,7 @@ class SakuraTree extends Tree {
$this->type = Wood::OAK;
}
/*
/**
* Builds the tree.
* @param $level \pocketmine\level\ChunkManager
* @param $x int
@ -656,7 +656,7 @@ class SakuraTree extends Tree {
}
}
/*
/**
* Fills a log at.
* @param $level pocketmine\level\ChunkManager
* @param $x int
@ -668,7 +668,7 @@ class SakuraTree extends Tree {
$level->setBlockDataAt($x, $y, $z, $this->type);
}
/*
/**
* Fills a leave at.
* @param $level pocketmine\level\ChunkManager
* @param $x int

View file

@ -22,7 +22,7 @@ use pocketmine\utils\Random;
class SugarCane extends Object {
/*
/**
* Checks if a cactus is placeable
* @param $level pocketmine\level\ChunkManager
* @param $x int
@ -41,7 +41,7 @@ class SugarCane extends Object {
return false;
}
/*
/**
* Places a cactus
* @param $level pocketmine\level\ChunkManager
* @param $x int

View file

@ -111,7 +111,7 @@ class Temple extends Object {
private $level;
private $direction = 0;
/*
/**
* Checks if a temple is placeable
* @param $level pocketmine\level\ChunkManager
* @param $x int
@ -132,7 +132,7 @@ class Temple extends Object {
return true;
}
/*
/**
* Places a temple
* @param $level pocketmine\level\ChunkManager
* @param $x int

View file

@ -22,8 +22,6 @@ use pocketmine\utils\Random;
class Well extends Object {
/** @var ChunkManager */
protected $level;
public $overridable = [
Block::AIR => true,
6 => true,
@ -36,6 +34,8 @@ class Well extends Object {
Block::LEAVES2 => true,
Block::CACTUS => true
];
/** @var ChunkManager */
protected $level;
protected $directions = [
[
1,
@ -55,7 +55,7 @@ class Well extends Object {
]
];
/*
/**
* Checks if a well is placeable
* @param $level ChunkManager
* @param $x int
@ -74,7 +74,7 @@ class Well extends Object {
return true;
}
/*
/**
* Places a well
* @param $level ChunkManager
* @param $x int
@ -111,7 +111,7 @@ class Well extends Object {
$this->placeBlock($x, $y, $z, Block::WATER);
}
/*
/**
* Places a slab
* @param $x int
* @param $y int

View file

@ -30,7 +30,7 @@ class BuildingUtils {
Block::PLANK
];
/*
/**
* Fills an area
* @param $level pocketmine\level\ChunkManager
* @param $pos1 pocketmine\math\Vector3
@ -47,8 +47,22 @@ class BuildingUtils {
}
}
/**
* Returns 2 vector3, one with minimal values, one with max values of the provided ones.
* @param $pos1 pocketmine\math\Vector3
* @param $pos2 pocketmine\math\Vector3
* @return array
*/
protected static function minmax(Vector3 $pos1, Vector3 $pos2): array {
$v1 = new Vector3(max($pos1->x, $pos2->x), max($pos1->y, $pos2->y), max($pos1->z, $pos2->z));
$v2 = new Vector3(min($pos1->x, $pos2->x), min($pos1->y, $pos2->y), min($pos1->z, $pos2->z));
return [
$v1,
$v2
];
}
/*
/**
* Fills an area randomly
* @param $level pocketmine\level\ChunkManager
* @param $pos1 pocketmine\math\Vector3
@ -67,7 +81,7 @@ class BuildingUtils {
}
}
/*
/**
* Fills an area by custom filling
* @param $pos1 pocketmine\math\Vector3
* @param $pos2 pocketmine\math\Vector3
@ -84,7 +98,7 @@ class BuildingUtils {
return $return;
}
/*
/**
* Creates walls
* @param $level pocketmine\level\ChunkManager
* @param $pos1 pocketmine\math\Vector3
@ -110,7 +124,7 @@ class BuildingUtils {
}
}
/*
/**
* Creates the top of a structure
* @param $level pocketmine\level\ChunkManager
* @param $pos1 pocketmine\math\Vector3
@ -127,7 +141,7 @@ class BuildingUtils {
}
}
/*
/**
* Creates all corners from positions. Used for Mineshaft.
* @param $level pocketmine\level\ChunkManager
* @param $pos1 pocketmine\math\Vector3
@ -149,7 +163,7 @@ class BuildingUtils {
}
}
/*
/**
* Creates the bottom of a structure
* @param $level pocketmine\level\ChunkManager
* @param $pos1 pocketmine\math\Vector3
@ -166,7 +180,7 @@ class BuildingUtils {
}
}
/*
/**
* Builds a random structure depending of length, height, depth and random
* @param $level pocketmine\level\ChunkManager
* @param $pos pocketmine\math\Vector3
@ -192,19 +206,4 @@ class BuildingUtils {
}
}
}
/*
* Returns 2 vector3, one with minimal values, one with max values of the provided ones.
* @param $pos1 pocketmine\math\Vector3
* @param $pos2 pocketmine\math\Vector3
* @return array
*/
protected static function minmax(Vector3 $pos1, Vector3 $pos2): array {
$v1 = new Vector3(max($pos1->x, $pos2->x), max($pos1->y, $pos2->y), max($pos1->z, $pos2->z));
$v2 = new Vector3(min($pos1->x, $pos2->x), min($pos1->y, $pos2->y), min($pos1->z, $pos2->z));
return [
$v1,
$v2
];
}
}