Adding plugin
This commit is contained in:
commit
fb1da2b8b0
8 changed files with 796 additions and 0 deletions
110
src/Ad5001/Spherable/Main.php
Normal file
110
src/Ad5001/Spherable/Main.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
/***
|
||||
* ____ _ _ _
|
||||
* / ___| _ __ | |__ ___ _ __ __ _ | |__ | | ___
|
||||
* \___ \ | '_ \ | '_ \ / _ \| '__|/ _` || '_ \ | | / _ \
|
||||
* ___) || |_) || | | || __/| | | (_| || |_) || || __/
|
||||
* |____/ | .__/ |_| |_| \___||_| \__,_||_.__/ |_| \___|
|
||||
* |_|
|
||||
*
|
||||
* Spheres world generator. A new survival challenge.
|
||||
* @author Ad5001 <mail@ad5001.eu>
|
||||
* @copyright (C) 2017 Ad5001
|
||||
* @license NTOSL (View LICENSE.md)
|
||||
* @package Spherical
|
||||
* @version 1.0.0
|
||||
* @link https://download.ad5001.eu/en/view.php?name=Spherable&src=github
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Ad5001\Spherable;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\level\generator\Generator;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\entity\Effect;
|
||||
|
||||
use Ad5001\Spherable\generators\spheres\SpheresGenerator;
|
||||
use Ad5001\Spherable\commands\sphgenCommand;
|
||||
|
||||
|
||||
|
||||
class Main extends PluginBase implements Listener{
|
||||
|
||||
public $playersResist = [];
|
||||
|
||||
|
||||
/**
|
||||
* When the plugin enables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onEnable(){
|
||||
Generator::addGenerator(SpheresGenerator::class, "spheres");
|
||||
$this->getServer()->getCommandMap()->register("sphgen", new sphgenCommand($this));
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public function onEntityLevelChange(\pocketmine\event\entity\EntityLevelChangeEvent $event){
|
||||
if($event->getTarget()->getProvider()->getGenerator() == "spheres" && $event->getEntity() instanceof Player){
|
||||
$event->getEntity()->setSpawn(new Position(264, 255, 264, $event->getTarget()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public function onRespawn(\pocketmine\event\player\PlayerRespawnEvent $event){
|
||||
if($event->getPlayer()->getLevel()->getProvider()->getGenerator() == "spheres"){
|
||||
$this->playersResist[$event->getPlayer()->getName()] = time();
|
||||
$event->getPlayer()->sendMessage("You are resistant for 30 seconds. Profit to go back to your last death point.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event){
|
||||
if($event->getEntity()->getLevel()->getProvider()->getGenerator() == "spheres" &&
|
||||
$event->getEntity() instanceof Player &&
|
||||
isset($this->playersResist[$event->getEntity()->getName()]) &&
|
||||
$this->playersResist[$event->getEntity()->getName()] > time() - 30){
|
||||
$event->setCancelled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event){
|
||||
if($event->getBlock()->getLevel()->getProvider()->getGenerator() == "spheres"){
|
||||
if($event->getBlock()->getId() == 56){
|
||||
$diamonds_count = 1;
|
||||
foreach($event->getPlayer()->getInventory()->getContents() as $item){
|
||||
$diamonds_count += $item->getCount();
|
||||
}
|
||||
if($diamonds_count % 64 == 0 && $this->getServer()->getPluginManager()->getPlugin("PSMCore") !== null){
|
||||
\Ad5001\PSMCore\API::displayNotification("Diamonds !", $event->getPlayer()->getName() . " has mined " . ($diamonds_count / 64) . " stacks of diamond!", [], "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public function onJoin(\pocketmine\event\player\PlayerJoinEvent $event){
|
||||
if($event->getPlayer()->getLevel()->getProvider()->getGenerator() == "spheres"){
|
||||
$event->getPlayer()->setSpawn(new Position(264, 255, 264, $event->getPlayer()->getLevel()));
|
||||
}
|
||||
}
|
||||
}
|
170
src/Ad5001/Spherable/commands/sphgenCommand.php
Normal file
170
src/Ad5001/Spherable/commands/sphgenCommand.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
/***
|
||||
* ____ _ _ _
|
||||
* / ___| _ __ | |__ ___ _ __ __ _ | |__ | | ___
|
||||
* \___ \ | '_ \ | '_ \ / _ \| '__|/ _` || '_ \ | | / _ \
|
||||
* ___) || |_) || | | || __/| | | (_| || |_) || || __/
|
||||
* |____/ | .__/ |_| |_| \___||_| \__,_||_.__/ |_| \___|
|
||||
* |_|
|
||||
*
|
||||
* Spheres world generator. A new survival challenge.
|
||||
* @author Ad5001 <mail@ad5001.eu>
|
||||
* @copyright (C) 2017 Ad5001
|
||||
* @license NTOSL (View LICENSE.md)
|
||||
* @package Spherical
|
||||
* @version 1.0.0
|
||||
* @link https://download.ad5001.eu/en/view.php?name=Spherable&src=github
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
namespace Ad5001\Spherable\commands;
|
||||
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\entity\Effect;
|
||||
|
||||
use Ad5001\Spherable\Main;
|
||||
use Ad5001\Spherable\generators\spheres\SpheresGenerator;
|
||||
|
||||
class sphgenCommand extends Command{
|
||||
|
||||
/**
|
||||
* Constructs the class
|
||||
*
|
||||
* @param Main $main
|
||||
*/
|
||||
public function __construct(Main $main){
|
||||
$this->main = $main;
|
||||
parent::__construct("sphgen", "Spheres games base command", "/sphgen <createworld|join|tp> <world name> [player]");
|
||||
$this->setPermission("sphereable.cmd.join");
|
||||
$this->setUsage("§4§o[§r§4Usage§o§4]§r§4 /sphgen <createworld|join|tp> <world name>[player]");
|
||||
}
|
||||
|
||||
/**
|
||||
* When the command is executed
|
||||
*
|
||||
* @param CommandSender $sender
|
||||
* @param string $commandLabel
|
||||
* @param array $args
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(CommandSender $sender, string $commandLabel, array $args): bool {
|
||||
if(count($args) < 2){
|
||||
$this->setUsage("§4§o[§r§4Usage§o§4]§r§4 /sphgen <createworld|join|tp> <world name> [player]");
|
||||
return true;
|
||||
}
|
||||
switch($args[0]){
|
||||
case "createworld":
|
||||
case "cw":
|
||||
if(!$sender->hasPermission("sphereable.cmd.createworld")){
|
||||
$sender->sendMessage("§4§o[§r§4Permission§o§4]§r§4 You don't have the permission to execute this command. If you believe this is an error, please contact the server administrator.");
|
||||
return true;
|
||||
}
|
||||
Server::getInstance()->generateLevel($args[1],
|
||||
(int) round(rand(0, (int) (round(time() / memory_get_usage(true)) * (int) str_shuffle("127469453645108") / (int) str_shuffle("12746945364"))))
|
||||
, SpheresGenerator::class , []);
|
||||
Server::getInstance()->loadLevel($args[1]);
|
||||
$sender->sendMessage("§a§o[§r§aSuccess§o§a]§r§a Generating world $args[1]...");
|
||||
if(Server::getInstance()->getPluginManager()->getPlugin("PSMCore") !== null){
|
||||
\Ad5001\PSMCore\API::addPlayerAction('Tp to challenge world "' . $args[1] . '"', "sphgen tp {$args[1]} %p");
|
||||
}
|
||||
break;
|
||||
case "join":
|
||||
case "j":
|
||||
if(file_exists(Server::getInstance()->getDataPath() . "worlds/{$args[1]}/level.dat")){
|
||||
if(Server::getInstance()->getLevelByName($args[1]) == null){
|
||||
Server::getInstance()->loadLevel($args[1]);
|
||||
}
|
||||
if(Server::getInstance()->getLevelByName($args[1])->getProvider()->getGenerator() == "spheres"){
|
||||
$sender->teleport(new Position(264, 256, 264,Server::getInstance()->getLevelByName($args[1])));
|
||||
$effect = Effect::getEffectByName("resistance");
|
||||
$effect->setDuration(600);
|
||||
$effect->setAmplifier(99);
|
||||
$effect->setVisible(false);
|
||||
$sender->addEffect($effect);
|
||||
$sender->sendMessage("§a§o[§r§aSuccess§o§a]§r§a Teleporting to challenge world $args[1]...");
|
||||
} else {
|
||||
$sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Spheres world $args[1] doesn't exist. Generate a world using /sphgen cw <world name>.");
|
||||
}
|
||||
} else {
|
||||
$sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Spheres world $args[1] doesn't exist. Generate a world using /sphgen cw <world name>.");
|
||||
}
|
||||
break;
|
||||
case "tp":
|
||||
if(!$sender->hasPermission("sphereable.cmd.tp")){
|
||||
$sender->sendMessage("§4§o[§r§4Permission§o§4]§r§4 You don't have the permission to execute this command. If you believe this is an error, please contact the server administrator.");
|
||||
return true;
|
||||
}
|
||||
if(count($args) < 3){
|
||||
$sender->sendMessage("§4§o[§r§4Usage§o§4]§r§4 /sphgen $args[0] <world name> <player>");
|
||||
return true;
|
||||
}
|
||||
if(file_exists(Server::getInstance()->getDataPath() . "worlds/{$args[1]}/level.dat")){
|
||||
if(Server::getInstance()->getLevelByName($args[1]) == null){
|
||||
Server::getInstance()->loadLevel($args[1]);
|
||||
}
|
||||
if(Server::getInstance()->getLevelByName($args[1])->getProvider()->getGenerator() == "spheres"){
|
||||
if(Server::getInstance()->getPlayer($args[2]) == null) {
|
||||
$sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Player $args[2] doesn't exists or isn't connected.");
|
||||
return true;
|
||||
}
|
||||
$player = Server::getInstance()->getPlayer($args[2]);
|
||||
$player->teleport(new Position(264, 256, 264,Server::getInstance()->getLevelByName($args[1])));
|
||||
$effect = Effect::getEffectByName("resistance");
|
||||
$effect->setDuration(600);
|
||||
$effect->setAmplifier(99);
|
||||
$effect->setVisible(false);
|
||||
$player->addEffect($effect);
|
||||
$player->sendMessage("§a§o[§r§aSuccess§o§a]§r§a {$sender->getName()} teleported you to to challenge world $args[1]...");
|
||||
$sender->sendMessage("§a§o[§r§aSuccess§o§a]§r§a Teleporting $args[2] to challenge world $args[1]...");
|
||||
} else {
|
||||
$sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Spheres world $args[1] doesn't exist. Generate a world using /sphgen cw <world name>.");
|
||||
}
|
||||
} else {
|
||||
$sender->sendMessage("§4§o[§r§4Error§o§4]§r§4 Spheres world $args[1] doesn't exist. Generate a world using /sphgen cw <world name>.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates custom data for command
|
||||
*
|
||||
* @param Player $player
|
||||
* @return array
|
||||
*/
|
||||
public function generateCustomCommandData(Player $player): array {
|
||||
$cmdData = parent::generateCustomCommandData($player);
|
||||
$cmdData["permission"] = "sphereable.cmd.join";
|
||||
$cmdData["aliases"] = [];
|
||||
$cmdData["overloads"]["default"]["input"]["parameters"] = [
|
||||
0 => [
|
||||
"type" => "stringenum",
|
||||
"name" => "subcmd",
|
||||
"optional" => false,
|
||||
"enum_values" => [
|
||||
"createworld",
|
||||
"cw",
|
||||
"join",
|
||||
"j",
|
||||
]
|
||||
],
|
||||
1 => [
|
||||
"type" => "string",
|
||||
"name" => "world",
|
||||
"optional" => false
|
||||
],
|
||||
2 => [
|
||||
"type" => "string",
|
||||
"name" => "player",
|
||||
"optional" => true
|
||||
]
|
||||
];
|
||||
return $cmdData;
|
||||
}
|
||||
}
|
363
src/Ad5001/Spherable/generators/spheres/SpheresGenerator.php
Normal file
363
src/Ad5001/Spherable/generators/spheres/SpheresGenerator.php
Normal file
|
@ -0,0 +1,363 @@
|
|||
<?php
|
||||
/***
|
||||
* ____ _ _ _
|
||||
* / ___| _ __ | |__ ___ _ __ __ _ | |__ | | ___
|
||||
* \___ \ | '_ \ | '_ \ / _ \| '__|/ _` || '_ \ | | / _ \
|
||||
* ___) || |_) || | | || __/| | | (_| || |_) || || __/
|
||||
* |____/ | .__/ |_| |_| \___||_| \__,_||_.__/ |_| \___|
|
||||
* |_|
|
||||
*
|
||||
* Spheres world generator. A new survival challenge.
|
||||
* @author Ad5001 <mail@ad5001.eu>
|
||||
* @copyright (C) 2017 Ad5001
|
||||
* @license NTOSL (View LICENSE.md)
|
||||
* @package Spherical
|
||||
* @version 1.0.0
|
||||
* @link https://download.ad5001.eu/en/view.php?name=Spherable&src=github
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Ad5001\Spherable\generators\spheres;
|
||||
|
||||
use pocketmine\level\generator\Generator;
|
||||
use pocketmine\level\generator\biome\BiomeSelector;
|
||||
use pocketmine\level\generator\biome\Biome;
|
||||
use pocketmine\level\generator\object\OreType;
|
||||
use pocketmine\level\generator\populator\GroundCover;
|
||||
use pocketmine\level\generator\populator\Ore;
|
||||
use pocketmine\level\generator\populator\Populator;
|
||||
use pocketmine\block\Block;
|
||||
try {
|
||||
if(!class_exists("pocketmine\\block\\BlockFactory")) {
|
||||
class_alias("pocketmine\\block\\Block", "pocketmine\\block\\BlockFactory");
|
||||
}
|
||||
} catch(Throwable $e){
|
||||
class_alias("pocketmine\\block\\Block", "pocketmine\\block\\BlockFactory");
|
||||
}
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class SpheresGenerator extends Generator {
|
||||
|
||||
|
||||
|
||||
/** @var Level */
|
||||
protected $level;
|
||||
|
||||
|
||||
/** @var Random */
|
||||
protected $random;
|
||||
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
*
|
||||
* An array of planets made of different blocks.
|
||||
**/
|
||||
protected $spheresBlocks = [
|
||||
[
|
||||
[Block::IRON_ORE, 0, 25],
|
||||
[Block::STONE, 0, 75],
|
||||
|
||||
],
|
||||
[
|
||||
[Block::COAL_ORE, 0, 25],
|
||||
[Block::STONE, 0, 75],
|
||||
|
||||
],
|
||||
[
|
||||
[Block::GOLD_ORE, 0, 25],
|
||||
[Block::STONE, 0, 75],
|
||||
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::LAPIS_BLOCK, 0, 93],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::REDSTONE_BLOCK, 0, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOD, 12, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOD, 13, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOD, 14, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOD, 15, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOD2, 12, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOD2, 13, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::PLANKS, 0, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::LEAVES, 4, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::NOTEBLOCK, 0, 93],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 3],
|
||||
[Block::SNOW_BLOCK, 0, 97],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::COBWEB, 0, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOL, 0, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOL, 1, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOL, 3, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOL, 4, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::WOOL, 0, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::BOOKSHELF, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 30],
|
||||
[Block::OBSIDIAN, 0, 70],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::STONE_BRICK, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::GRAVEL, 0, 40],
|
||||
[Block::STONE, 0, 50],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::SAND, 0, 40],
|
||||
[Block::SANDSTONE, 0, 53],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::PACKED_ICE, 0, 93],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 3],
|
||||
[Block::SLIME_BLOCK, 0, 97],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::QUARTZ_BLOCK, 0, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 2],
|
||||
[Block::NETHERRACK, 0, 98],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 5],
|
||||
[Block::EMERALD_ORE, 0, 95],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::REDSTONE_LAMP, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 10],
|
||||
[Block::END_STONE, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 10],
|
||||
[Block::NETHER_BRICKS, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 10],
|
||||
[Block::MELON_BLOCK, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::GLOWSTONE, 0, 93],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 7],
|
||||
[Block::PUMPKIN, 0, 93],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 10],
|
||||
[Block::SOUL_SAND, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 10],
|
||||
[Block::SPONGE, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 10],
|
||||
[Block::PRISMARINE, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 10],
|
||||
[Block::SEA_LANTERN, 0, 90],
|
||||
],
|
||||
[
|
||||
[Block::DIAMOND_ORE, 0, 10],
|
||||
[Block::NETHER_REACTOR, 0, 90],
|
||||
],
|
||||
];
|
||||
|
||||
public function __construct(array $options = []){}
|
||||
|
||||
|
||||
/**
|
||||
* Inits the class for the var
|
||||
* @param ChunkManager $level
|
||||
* @param Random $random
|
||||
* @return void
|
||||
*/
|
||||
public function init(ChunkManager $level, Random $random) {
|
||||
$this->level = $level;
|
||||
$this->random = $random;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* Returns the name of the generator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName() : string{
|
||||
return "spheres";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the settings of the generator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSettings() : array{
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a chunk
|
||||
*
|
||||
* @param int $chunkX
|
||||
* @param int $chunkZ
|
||||
* @return void
|
||||
*/
|
||||
public function generateChunk(int $chunkX, int $chunkZ){
|
||||
// Leave blank, planets will be generated later
|
||||
$chunk = $this->level->getChunk($chunkX, $chunkZ);
|
||||
for($x = 0; $x < 16; $x++) {
|
||||
for($z = 0; $z < 16; $z++) {
|
||||
$chunk->setBiomeId($x, $z, 1);
|
||||
if($chunkX == 16 && $chunkZ == 16) $chunk->setBlockId($x, 254, $z, 2);
|
||||
}
|
||||
}
|
||||
$chunk->setGenerated();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populates the chunk with planets
|
||||
*
|
||||
* @param int $chunkX
|
||||
* @param int $chunkZ
|
||||
* @return void
|
||||
*/
|
||||
public function populateChunk(int $chunkX, int $chunkZ){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
$chunk = $this->level->getChunk($chunkX, $chunkZ);
|
||||
$count = $this->random->nextRange(1, 4);
|
||||
for($i = 0; $i <= $count; $i++){
|
||||
$y = $this->random->nextRange(17, Level::Y_MAX - 25);
|
||||
$maxRadius = $y % 10;
|
||||
if($maxRadius < 6) $maxRadius = 6;
|
||||
// $maxRadius is situated between 12 and 20 depending on Y choosen
|
||||
// Let's add a little bit more random
|
||||
$radius = $this->random->nextRange(5, (int) round($maxRadius));
|
||||
// Generating planet
|
||||
$x = $chunkX * 16 + $this->random->nextRange(0, 15);
|
||||
$z = $chunkZ * 16 + $this->random->nextRange(0, 15);
|
||||
$center = new Vector3($x, $y, $z);
|
||||
$this->generatePlanet($center, $radius);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dafault spawn
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getSpawn() : Vector3{
|
||||
return new Vector3(264, 255, 264);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a planet
|
||||
* psmcoreactplugin createlevel4psm Welp spheres 9247603569486
|
||||
*
|
||||
* @param Vector3 $center
|
||||
* @param int $radius
|
||||
* @return void
|
||||
*/
|
||||
public function generatePlanet(Vector3 $center, int $radius){
|
||||
$radiusSquared = $radius ** 2;
|
||||
$currentSphereBlocks = $this->spheresBlocks[array_rand($this->spheresBlocks)];
|
||||
for ($x = $center->x - $radius; $x <= $center->x + $radius; $x++) {
|
||||
$xsquared = ($center->x - $x) * ($center->x - $x);
|
||||
for ($y = $center->y - $radius; $y <= $center->y + $radius; $y++) {
|
||||
$ysquared = ($center->y - $y) * ($center->y - $y);
|
||||
for ($z = $center->z - $radius; $z <= $center->z + $radius; $z++) {
|
||||
$zsquared = ($center->z - $z) * ($center->z - $z);
|
||||
if($xsquared + $ysquared + $zsquared < $radiusSquared) {
|
||||
// Choosing a random block to place
|
||||
$rand = $this->random->nextBoundedInt(100) + 1;
|
||||
foreach($currentSphereBlocks as $block){
|
||||
if($rand > $block[2]) {
|
||||
$rand = $block[2];
|
||||
continue;
|
||||
} else {
|
||||
$this->level->setBlockIdAt($x, $y, $z, $block[0], false, false);
|
||||
$this->level->setBlockDataAt($x, $y, $z, $block[1], false, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue