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
|
description: Teleports you to an another world
|
||||||
usage: "/worldtp <world name>"
|
usage: "/worldtp <world name>"
|
||||||
permission: bettergen.cmd.worldtp
|
permission: bettergen.cmd.worldtp
|
||||||
|
temple:
|
||||||
|
description: Spawns a temple for debugging
|
||||||
|
usage: "/temple"
|
||||||
|
permission: bettergen.cmd.debug
|
||||||
permissions:
|
permissions:
|
||||||
bettergen.cmd.createworld:
|
bettergen.cmd.createworld:
|
||||||
default: op
|
default: op
|
||||||
bettergen.cmd.worldtp:
|
bettergen.cmd.worldtp:
|
||||||
default: op
|
default: op
|
||||||
|
bettergen.cmd.debug:
|
||||||
|
default: op
|
||||||
...
|
...
|
|
@ -17,9 +17,11 @@ namespace Ad5001\BetterGen;
|
||||||
use Ad5001\BetterGen\biome\BetterForest;
|
use Ad5001\BetterGen\biome\BetterForest;
|
||||||
use Ad5001\BetterGen\generator\BetterNormal;
|
use Ad5001\BetterGen\generator\BetterNormal;
|
||||||
use Ad5001\BetterGen\loot\LootTable;
|
use Ad5001\BetterGen\loot\LootTable;
|
||||||
|
use Ad5001\BetterGen\structure\Temple;
|
||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\command\Command;
|
use pocketmine\command\Command;
|
||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
|
use pocketmine\command\ConsoleCommandSender;
|
||||||
use pocketmine\event\block\BlockBreakEvent;
|
use pocketmine\event\block\BlockBreakEvent;
|
||||||
use pocketmine\event\level\ChunkPopulateEvent;
|
use pocketmine\event\level\ChunkPopulateEvent;
|
||||||
use pocketmine\event\Listener;
|
use pocketmine\event\Listener;
|
||||||
|
@ -30,10 +32,12 @@ use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\nbt\tag\ListTag;
|
use pocketmine\nbt\tag\ListTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
|
use pocketmine\Player;
|
||||||
use pocketmine\plugin\PluginBase;
|
use pocketmine\plugin\PluginBase;
|
||||||
use pocketmine\tile\Chest;
|
use pocketmine\tile\Chest;
|
||||||
use pocketmine\tile\Tile;
|
use pocketmine\tile\Tile;
|
||||||
use pocketmine\utils\Config;
|
use pocketmine\utils\Config;
|
||||||
|
use pocketmine\utils\Random;
|
||||||
|
|
||||||
class Main extends PluginBase implements Listener {
|
class Main extends PluginBase implements Listener {
|
||||||
const PREFIX = "§l§o§b[§r§l§2Better§aGen§o§b]§r§f ";
|
const PREFIX = "§l§o§b[§r§l§2Better§aGen§o§b]§r§f ";
|
||||||
|
@ -42,6 +46,15 @@ class Main extends PluginBase implements Listener {
|
||||||
/*
|
/*
|
||||||
* Called when the plugin enables
|
* Called when the plugin enables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public static function registerBiome(int $id, Biome $biome) {
|
||||||
|
BetterNormal::registerBiome($biome);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called when the plugin disables
|
||||||
|
*/
|
||||||
|
|
||||||
public function onEnable() {
|
public function onEnable() {
|
||||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||||
Generator::addGenerator(BetterNormal::class, "betternormal");
|
Generator::addGenerator(BetterNormal::class, "betternormal");
|
||||||
|
@ -51,12 +64,6 @@ class Main extends PluginBase implements Listener {
|
||||||
file_put_contents(LootTable::getPluginFolder() . "processingLoots.json", "{}");
|
file_put_contents(LootTable::getPluginFolder() . "processingLoots.json", "{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Called when the plugin disables
|
|
||||||
*/
|
|
||||||
public function onDisable() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when one of the defined commands of the plugin has been called
|
* Called when one of the defined commands of the plugin has been called
|
||||||
* @param $sender \pocketmine\command\CommandSender
|
* @param $sender \pocketmine\command\CommandSender
|
||||||
|
@ -65,6 +72,33 @@ class Main extends PluginBase implements Listener {
|
||||||
* @param $args array
|
* @param $args array
|
||||||
* return bool
|
* 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 {
|
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)]
|
case "createworld" : // /createworld <name> [generator = betternormal] [seed = rand()] [options(json)]
|
||||||
|
@ -144,41 +178,22 @@ class Main extends PluginBase implements Listener {
|
||||||
$this->getServer()->loadLevel($name);
|
$this->getServer()->loadLevel($name);
|
||||||
return true;
|
return true;
|
||||||
break;
|
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;
|
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.
|
* Generates a(semi) random seed.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function generateRandomSeed(): 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"));
|
||||||
}
|
}
|
||||||
|
@ -190,6 +205,22 @@ class Main extends PluginBase implements Listener {
|
||||||
* @param $event pocketmine\event\level\ChunkPopulateEvent
|
* @param $event pocketmine\event\level\ChunkPopulateEvent
|
||||||
* @return int
|
* @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) {
|
public function onChunkPopulate(ChunkPopulateEvent $event) {
|
||||||
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
|
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
|
||||||
foreach ($cfg->getAll() as $key => $value) {
|
foreach ($cfg->getAll() as $key => $value) {
|
||||||
|
@ -205,8 +236,9 @@ 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) {
|
public function onInteract(PlayerInteractEvent $event) {
|
||||||
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
|
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
|
||||||
if ($event->getBlock()->getId() !== Block::CHEST) return;
|
if ($event->getBlock()->getId() !== Block::CHEST) return;
|
||||||
|
@ -224,10 +256,11 @@ class Main extends PluginBase implements Listener {
|
||||||
LootTable::fillChest($chest->getInventory(), $event->getBlock());
|
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) {
|
public function onBlockBreak(BlockBreakEvent $event) {
|
||||||
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
|
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
|
||||||
if ($event->getBlock()->getId() !== Block::CHEST) return;
|
if ($event->getBlock()->getId() !== Block::CHEST) return;
|
||||||
|
@ -245,16 +278,4 @@ class Main extends PluginBase implements Listener {
|
||||||
LootTable::fillChest($chest->getInventory(), $event->getBlock());
|
LootTable::fillChest($chest->getInventory(), $event->getBlock());
|
||||||
// $event->setCancelled(); //i think nope. You want to break it with items
|
// $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;
|
public $trunkHeight = 11;
|
||||||
private $leafType;
|
public $leafType;
|
||||||
private $leaf2Type;
|
public $leaf2Type;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructs the class
|
* Constructs the class
|
||||||
|
|
|
@ -14,13 +14,13 @@
|
||||||
|
|
||||||
namespace Ad5001\BetterGen\structure;
|
namespace Ad5001\BetterGen\structure;
|
||||||
|
|
||||||
use pocketmine\block\Block;
|
|
||||||
use pocketmine\level\ChunkManager;
|
|
||||||
use pocketmine\utils\Random;
|
|
||||||
use pocketmine\math\Vector3;
|
|
||||||
use pocketmine\level\generator\object\Object;
|
|
||||||
use Ad5001\BetterGen\loot\LootTable;
|
use Ad5001\BetterGen\loot\LootTable;
|
||||||
use Ad5001\BetterGen\utils\BuildingUtils;
|
use Ad5001\BetterGen\utils\BuildingUtils;
|
||||||
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\level\ChunkManager;
|
||||||
|
use pocketmine\level\generator\object\Object;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\utils\Random;
|
||||||
|
|
||||||
class Temple extends Object {
|
class Temple extends Object {
|
||||||
const DIRECTION_PLUSX = 0;
|
const DIRECTION_PLUSX = 0;
|
||||||
|
@ -77,13 +77,12 @@ class Temple extends Object {
|
||||||
-2
|
-2
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
/** @var ChunkManager */
|
|
||||||
private $level;
|
|
||||||
public $overridable = [
|
public $overridable = [
|
||||||
Block::AIR => true,
|
Block::AIR => true,
|
||||||
6 => true,
|
Block::SAPLING => true,
|
||||||
17 => true,
|
Block::LOG => true,
|
||||||
18 => true,
|
Block::LEAVES => true,
|
||||||
|
Block::STONE => true,
|
||||||
Block::DANDELION => true,
|
Block::DANDELION => true,
|
||||||
Block::POPPY => true,
|
Block::POPPY => true,
|
||||||
Block::SNOW_LAYER => true,
|
Block::SNOW_LAYER => true,
|
||||||
|
@ -109,6 +108,9 @@ class Temple extends Object {
|
||||||
1
|
1
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
/** @var ChunkManager */
|
||||||
|
private $level;
|
||||||
|
private $direction = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks if a temple is placeable
|
* Checks if a temple is placeable
|
||||||
|
@ -119,6 +121,7 @@ class Temple extends Object {
|
||||||
* @param $random pocketmine\utils\Random
|
* @param $random pocketmine\utils\Random
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
|
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
|
||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
$this->direction = $random->nextBoundedInt(4);
|
$this->direction = $random->nextBoundedInt(4);
|
||||||
|
@ -398,9 +401,10 @@ class Temple extends Object {
|
||||||
* @param $z int
|
* @param $z int
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function placeSlab($x, $y, $z) {
|
|
||||||
$this->level->setBlockIdAt($x, $y, $z, 44);
|
protected function placeBlock($x, $y, $z, $id = Block::SANDSTONE, $meta = 0) {
|
||||||
$this->level->setBlockDataAt($x, $y, $z, 1);
|
$this->level->setBlockIdAt($x, $y, $z, $id);
|
||||||
|
$this->level->setBlockDataAt($x, $y, $z, $meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -412,20 +416,7 @@ class Temple extends Object {
|
||||||
* @param $meta int
|
* @param $meta int
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function placeBlock($x, $y, $z, $id = Block::SANDSTONE, $meta = 0) {
|
|
||||||
$this->level->setBlockIdAt($x, $y, $z, $id);
|
|
||||||
$this->level->setBlockDataAt($x, $y, $z, $meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Places one of the towers. Out is inversed $direction1, stairs come from inversed $direction2 to $direction2, patterns are on $direction1 and $direction2
|
|
||||||
* @param $x int
|
|
||||||
* @param $y int
|
|
||||||
* @param $z int
|
|
||||||
* @param $direction1 int
|
|
||||||
* @param $direction2 int
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function placeTower($x, $y, $z, $direction1 = self::DIRECTION_PLUSX, $direction2 = self::DIRECTION_PLUSZ) {
|
public function placeTower($x, $y, $z, $direction1 = self::DIRECTION_PLUSX, $direction2 = self::DIRECTION_PLUSZ) {
|
||||||
BuildingUtils::walls($this->level, new Vector3($x + 2, $y, $z + 2), new Vector3($x - 2, $y + 8, $z - 2), Block::get(Block::SANDSTONE));
|
BuildingUtils::walls($this->level, new Vector3($x + 2, $y, $z + 2), new Vector3($x - 2, $y + 8, $z - 2), Block::get(Block::SANDSTONE));
|
||||||
switch ($direction1) {
|
switch ($direction1) {
|
||||||
|
@ -890,11 +881,27 @@ class Temple extends Object {
|
||||||
$this->placeBlock($x, $y + 9, $z + 2, Block::SANDSTONE_STAIRS, 3);
|
$this->placeBlock($x, $y + 9, $z + 2, Block::SANDSTONE_STAIRS, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Places one of the towers. Out is inversed $direction1, stairs come from inversed $direction2 to $direction2, patterns are on $direction1 and $direction2
|
||||||
|
* @param $x int
|
||||||
|
* @param $y int
|
||||||
|
* @param $z int
|
||||||
|
* @param $direction1 int
|
||||||
|
* @param $direction2 int
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected function placeSlab($x, $y, $z) {
|
||||||
|
$this->level->setBlockIdAt($x, $y, $z, 44);
|
||||||
|
$this->level->setBlockDataAt($x, $y, $z, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inverses a direction
|
* Inverses a direction
|
||||||
* @param $direction int
|
* @param $direction int
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected function getInversedDirection(int $direction): int {
|
protected function getInversedDirection(int $direction): int {
|
||||||
switch ($direction) {
|
switch ($direction) {
|
||||||
case self::DIRECTION_PLUSX : // x+ (0)
|
case self::DIRECTION_PLUSX : // x+ (0)
|
||||||
|
|
Loading…
Reference in a new issue