forked from Ad5001/BetterGen
Reformatting, Fix #2, temple debug command
This commit is contained in:
parent
a7b8469c9c
commit
7ce51d546a
4 changed files with 484 additions and 450 deletions
|
@ -23,9 +23,15 @@ 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"
|
||||
permission: bettergen.cmd.debug
|
||||
permissions:
|
||||
bettergen.cmd.createworld:
|
||||
default: op
|
||||
bettergen.cmd.worldtp:
|
||||
default: op
|
||||
bettergen.cmd.debug:
|
||||
default: op
|
||||
...
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* ____ __ __ ____
|
||||
* /\ _`\ /\ \__ /\ \__ /\ _`\
|
||||
* \ \ \L\ \ __ \ \ ,_\\ \ ,_\ __ _ __ \ \ \L\_\ __ ___
|
||||
* \ \ _ <' /'__`\\ \ \/ \ \ \/ /'__`\/\`'__\\ \ \L_L /'__`\ /' _ `\
|
||||
* \ \ \L\ \/\ __/ \ \ \_ \ \ \_ /\ __/\ \ \/ \ \ \/, \/\ __/ /\ \/\ \
|
||||
* ____ __ __ ____
|
||||
* /\ _`\ /\ \__ /\ \__ /\ _`\
|
||||
* \ \ \L\ \ __ \ \ ,_\\ \ ,_\ __ _ __ \ \ \L\_\ __ ___
|
||||
* \ \ _ <' /'__`\\ \ \/ \ \ \/ /'__`\/\`'__\\ \ \L_L /'__`\ /' _ `\
|
||||
* \ \ \L\ \/\ __/ \ \ \_ \ \ \_ /\ __/\ \ \/ \ \ \/, \/\ __/ /\ \/\ \
|
||||
* \ \____/\ \____\ \ \__\ \ \__\\ \____\\ \_\ \ \____/\ \____\\ \_\ \_\
|
||||
* \/___/ \/____/ \/__/ \/__/ \/____/ \/_/ \/___/ \/____/ \/_/\/_/
|
||||
* Tomorrow's pocketmine generator.
|
||||
|
@ -17,9 +17,11 @@ namespace Ad5001\BetterGen;
|
|||
use Ad5001\BetterGen\biome\BetterForest;
|
||||
use Ad5001\BetterGen\generator\BetterNormal;
|
||||
use Ad5001\BetterGen\loot\LootTable;
|
||||
use Ad5001\BetterGen\structure\Temple;
|
||||
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;
|
||||
|
@ -30,33 +32,38 @@ 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\Tile;
|
||||
use pocketmine\utils\Config;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
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
|
||||
*/
|
||||
public function onEnable() {
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
Generator::addGenerator(BetterNormal::class, "betternormal");
|
||||
if($this->isOtherNS()) $this->getLogger()->warning("Tesseract detected. Note that Tesseract is not up to date with the generation structure and some generation features may be limited or not working");
|
||||
@mkdir($this->getDataFolder());
|
||||
if(! file_exists(LootTable::getPluginFolder(). "processingLoots.json"))
|
||||
file_put_contents(LootTable::getPluginFolder(). "processingLoots.json", "{}");
|
||||
|
||||
public static function registerBiome(int $id, Biome $biome) {
|
||||
BetterNormal::registerBiome($biome);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Called when the plugin disables
|
||||
*/
|
||||
public function onDisable() {
|
||||
|
||||
public function onEnable() {
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
Generator::addGenerator(BetterNormal::class, "betternormal");
|
||||
if ($this->isOtherNS()) $this->getLogger()->warning("Tesseract detected. Note that Tesseract is not up to date with the generation structure and some generation features may be limited or not working");
|
||||
@mkdir($this->getDataFolder());
|
||||
if (!file_exists(LootTable::getPluginFolder() . "processingLoots.json"))
|
||||
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
|
||||
|
@ -65,10 +72,37 @@ class Main extends PluginBase implements Listener {
|
|||
* @param $args array
|
||||
* return bool
|
||||
*/
|
||||
|
||||
public static function isOtherNS() {
|
||||
try {
|
||||
return @class_exists("pocketmine\\level\\generator\\normal\\object\\OakTree");
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Registers a forest type.
|
||||
* @param $name string
|
||||
* @param $treeClass string
|
||||
* @params $infos Array(temperature, rainfall)
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args): bool {
|
||||
switch($cmd->getName()) {
|
||||
switch ($cmd->getName()) {
|
||||
case "createworld" : // /createworld <name> [generator = betternormal] [seed = rand()] [options(json)]
|
||||
switch(count($args)) {
|
||||
switch (count($args)) {
|
||||
case 0 :
|
||||
return false;
|
||||
break;
|
||||
|
@ -77,50 +111,50 @@ class Main extends PluginBase implements Listener {
|
|||
$generator = Generator::getGenerator("betternormal");
|
||||
$generatorName = "betternormal";
|
||||
$seed = $this->generateRandomSeed();
|
||||
$options = [ ];
|
||||
$options = [];
|
||||
break;
|
||||
case 2 : // /createworld <name> [generator = betternormal]
|
||||
$name = $args [0];
|
||||
$generator = Generator::getGenerator($args [1]);
|
||||
if(Generator::getGeneratorName($generator) !== strtolower($args [1])) {
|
||||
if (Generator::getGeneratorName($generator) !== strtolower($args [1])) {
|
||||
$sender->sendMessage(self::PREFIX . "§4Could not find generator {$args[1]}. Are you sure it is registered?");
|
||||
return true;
|
||||
}
|
||||
$generatorName = strtolower($args [1]);
|
||||
$seed = $this->generateRandomSeed();
|
||||
$options = [ ];
|
||||
$options = [];
|
||||
break;
|
||||
case 3 : // /createworld <name> [generator = betternormal] [seed = rand()]
|
||||
$name = $args [0];
|
||||
$generator = Generator::getGenerator($args [1]);
|
||||
if(Generator::getGeneratorName($generator) !== strtolower($args [1])) {
|
||||
if (Generator::getGeneratorName($generator) !== strtolower($args [1])) {
|
||||
$sender->sendMessage(self::PREFIX . "§4Could not find generator {$args[1]}. Are you sure it is registered?");
|
||||
return true;
|
||||
}
|
||||
$generatorName = strtolower($args [1]);
|
||||
if(preg_match("[^\d]", $args [2]) !== false) {
|
||||
if (preg_match("[^\d]", $args [2]) !== false) {
|
||||
$parts = str_split($args [2]);
|
||||
foreach($parts as $key => $str) {
|
||||
foreach ($parts as $key => $str) {
|
||||
$parts [$key] = ord($str);
|
||||
}
|
||||
$seed = implode("", $parts);
|
||||
} else {
|
||||
$seed = $args [2];
|
||||
}
|
||||
$options = [ ];
|
||||
$options = [];
|
||||
break;
|
||||
default : // /createworld <name> [generator = betternormal] [seed = rand()] [options(json)]
|
||||
$name = $args [0];
|
||||
$generator = Generator::getGenerator($args [1]);
|
||||
if(Generator::getGeneratorName($generator) !== strtolower($args [1])) {
|
||||
if (Generator::getGeneratorName($generator) !== strtolower($args [1])) {
|
||||
$sender->sendMessage(self::PREFIX . "§4Could not find generator {$args[1]}. Are you sure it is registered?");
|
||||
return true;
|
||||
}
|
||||
$generatorName = strtolower($args [1]);
|
||||
if($args[2] == "rand") $args[2] = $this->generateRandomSeed();
|
||||
if(preg_match("[^\d]", $args [2]) !== false) {
|
||||
if ($args[2] == "rand") $args[2] = $this->generateRandomSeed();
|
||||
if (preg_match("[^\d]", $args [2]) !== false) {
|
||||
$parts = str_split($args [2]);
|
||||
foreach($parts as $key => $str) {
|
||||
foreach ($parts as $key => $str) {
|
||||
$parts [$key] = ord($str);
|
||||
}
|
||||
$seed = implode("", $parts);
|
||||
|
@ -129,14 +163,14 @@ class Main extends PluginBase implements Listener {
|
|||
}
|
||||
unset($args [0], $args [1], $args [2]);
|
||||
$options = json_decode($args [3], true);
|
||||
if(! is_array($options)) {
|
||||
if (!is_array($options)) {
|
||||
$sender->sendMessage(Main::PREFIX . "§4Invalid JSON for options.");
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$options["preset"] = json_encode($options);
|
||||
if((int) $seed == 0/*String*/){
|
||||
if ((int)$seed == 0/*String*/) {
|
||||
$seed = $this->generateRandomSeed();
|
||||
}
|
||||
$this->getServer()->broadcastMessage(Main::PREFIX . "§aGenerating level $name with generator $generatorName and seed $seed..");
|
||||
|
@ -144,57 +178,54 @@ class Main extends PluginBase implements Listener {
|
|||
$this->getServer()->loadLevel($name);
|
||||
return true;
|
||||
break;
|
||||
case 'temple':{
|
||||
if($sender instanceof ConsoleCommandSender) return false;
|
||||
/** @var Player $sender */
|
||||
$temple = new Temple();
|
||||
$temple->placeObject($sender->getLevel(), $sender->x, $sender->y, $sender->z, new Random());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
if(! @is_subclass_of($treeClass, "pocketmine\\level\\generator\\normal\\object\\Tree"))
|
||||
return false;
|
||||
if(count($infos) < 2 or ! is_float($infos [0]) or ! is_float($infos [1]))
|
||||
return false;
|
||||
return BetterForest::registerForest($name, $treeClass, $infos);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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"));
|
||||
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
|
||||
*/
|
||||
|
||||
public function registerForest(string $name, string $treeClass, array $infos): bool {
|
||||
if (!@class_exists($treeClass))
|
||||
return false;
|
||||
if (!@is_subclass_of($treeClass, "pocketmine\\level\\generator\\normal\\object\\Tree"))
|
||||
return false;
|
||||
if (count($infos) < 2 or !is_float($infos [0]) or !is_float($infos [1]))
|
||||
return false;
|
||||
return BetterForest::registerForest($name, $treeClass, $infos);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Checks when a player interacts with a loot chest to create it.
|
||||
*/
|
||||
|
||||
public function onChunkPopulate(ChunkPopulateEvent $event) {
|
||||
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
|
||||
foreach($cfg->getAll() as $key => $value) {
|
||||
foreach ($cfg->getAll() as $key => $value) {
|
||||
list($x, $y, $z) = explode(";", $key);
|
||||
if($value["saveAs"] == "chest" && $event->getLevel()->getBlockIdAt($x, $y, $z) == Block::AIR ){
|
||||
if ($value["saveAs"] == "chest" && $event->getLevel()->getBlockIdAt($x, $y, $z) == Block::AIR) {
|
||||
$event->getLevel()->setBlockIdAt($x, $y, $z, Block::CHEST);
|
||||
} else {
|
||||
$cfg->remove($key);
|
||||
|
@ -202,36 +233,38 @@ class Main extends PluginBase implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Checks when a player interacts with a loot chest to create it.
|
||||
* 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;
|
||||
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)
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Checks when a player breaks a loot chest which is not created to create it
|
||||
*/
|
||||
* Check if it's a Tesseract like namespace
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
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;
|
||||
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),
|
||||
|
@ -245,16 +278,4 @@ class Main extends PluginBase implements Listener {
|
|||
LootTable::fillChest($chest->getInventory(), $event->getBlock());
|
||||
// $event->setCancelled(); //i think nope. You want to break it with items
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if it's a Tesseract like namespace
|
||||
* @return bool
|
||||
*/
|
||||
public static function isOtherNS() {
|
||||
try {
|
||||
return @class_exists("pocketmine\\level\\generator\\normal\\object\\OakTree");
|
||||
} catch(\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -442,8 +442,8 @@ class SakuraTree extends Tree {
|
|||
|
||||
|
||||
public $trunkHeight = 11;
|
||||
private $leafType;
|
||||
private $leaf2Type;
|
||||
public $leafType;
|
||||
public $leaf2Type;
|
||||
|
||||
/*
|
||||
* Constructs the class
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue