Renaming the plugin, adding more heightmaps, fixing the plugin.
parent
f49444442a
commit
5dd4de71ef
Binary file not shown.
Before Width: | Height: | Size: 17 MiB |
@ -1,9 +1,9 @@
|
||||
---
|
||||
name: RealWorld
|
||||
name: GenPainterPE
|
||||
author: Ad5001
|
||||
version: 1.0
|
||||
api: [3.0.0-ALPHA9]
|
||||
main: Ad5001\RealWorld\Main
|
||||
main: Ad5001\GenPainterPE\Main
|
||||
commands: []
|
||||
permissions: []
|
||||
...
|
Binary file not shown.
After Width: | Height: | Size: 1.4 MiB |
@ -0,0 +1,21 @@
|
||||
# Welcome to GenPainter's config.
|
||||
|
||||
# Name of the heightmap to generate.
|
||||
# Default heightmaps: big_5400x2700, normal_1000x500, and small_250_150.
|
||||
# How to add a custom heightmap: https://github.com/Ad5001/GenPainterPE#add-heightmap
|
||||
heightmap_name: normal_1000x500
|
||||
|
||||
# Should the generator generate caves and ravines? (BetterGen's)
|
||||
generate_caves: true
|
||||
|
||||
# Should the generator generate structures? (Trees, bushes, ...)
|
||||
generate_structures: true
|
||||
|
||||
# Should the generator generate biome's ground? (Grass blocks, sand, dirt, ...)
|
||||
generate_custom_ground: true
|
||||
|
||||
# Should the generator generate ores? (Diamond, gold, iron... but also dirt, gravel,...)
|
||||
generate_ores: true
|
||||
|
||||
# Should the generator generate biomes?
|
||||
generate_biomes: true
|
Binary file not shown.
Before Width: | Height: | Size: 5.9 MiB |
Binary file not shown.
Before Width: | Height: | Size: 17 MiB |
Binary file not shown.
After Width: | Height: | Size: 122 KiB |
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
namespace Ad5001\GenPainterPE;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\event\entity\EntityLevelChangeEvent;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\level\generator\Generator;
|
||||
use pocketmine\level\generator\biome\Biome;
|
||||
|
||||
use Ad5001\GenPainterPE\utils\Range;
|
||||
use Ad5001\GenPainterPE\generator\GenPainter;
|
||||
|
||||
|
||||
class Main extends PluginBase implements Listener{
|
||||
|
||||
public static $GENERATOR_IDS = 0;
|
||||
public static $BIOMES_BY_RANGE = [];
|
||||
|
||||
/**
|
||||
* Loads the plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onEnable(){
|
||||
@mkdir($this->getDataFolder());
|
||||
@mkdir($this->getDataFolder() . "tmp");
|
||||
@mkdir($this->getDataFolder() . "heightmaps");
|
||||
$this->saveDefaultConfig();
|
||||
if(!file_exists($this->getDataFolder() . "heightmaps/big_5400x2700.png")) file_put_contents($this->getDataFolder() . "heightmaps/big_5400x2700.png", $this->getResource("big_5400x2700.png"));
|
||||
if(!file_exists($this->getDataFolder() . "heightmaps/normal_1000x500.png")) file_put_contents($this->getDataFolder() . "heightmaps/normal_1000x500.png", $this->getResource("normal_1000x500.png"));
|
||||
if(!file_exists($this->getDataFolder() . "heightmaps/small_250x150.png")) file_put_contents($this->getDataFolder() . "heightmaps/small_250x150.png", $this->getResource("small_250x150.png"));
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
// Register generators
|
||||
Generator::addGenerator(GenPainter::class, "genpainter");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks when a command is sent.
|
||||
*
|
||||
* @param CommandSender $sender
|
||||
* @param Command $cmd
|
||||
* @param string $label
|
||||
* @param array $args
|
||||
* @return bool
|
||||
*/
|
||||
public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args): bool{
|
||||
switch($cmd->getName()){
|
||||
case "default":
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the plugin disables
|
||||
*/
|
||||
public function onDisable() {
|
||||
foreach(array_diff(scandir($this->getDataFolder() . "tmp"), ["..", "."]) as $link){
|
||||
unlink($this->getDataFolder() . "tmp/" . $link);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks when a world will start being generated to give it's id to it and start generation
|
||||
*
|
||||
* @param EntityLevelChangeEvent $ev
|
||||
* @return void
|
||||
*/
|
||||
public function onEntityLevelChange(EntityLevelChangeEvent $event){
|
||||
if($event->getTarget()->getProvider()->getGenerator() == "worldpainter" &&
|
||||
$event->getEntity() instanceof Player){
|
||||
$spawnpoint = json_decode(
|
||||
file_get_contents(
|
||||
get_cwd() . "/worlds/" . $event->getTarget()->getFolderName() . "/gendata/geninfos.json"
|
||||
)
|
||||
)->startPoint;
|
||||
$event->getEntity()->setSpawn(new Position($spawnpoint[0], $spawnpoint[1], $spawnpoint[2], $event->getTarget()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates all ranges for biomes.
|
||||
* Default WATER_HEIGHT is 100.
|
||||
* Sorry for the formating, but it's the crisis.
|
||||
* Big screens are too expensive.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function generateRanges(){
|
||||
self::$BIOMES_BY_RANGE = [];
|
||||
self::$BIOMES_BY_RANGE[Biome::OCEAN] = new Range(
|
||||
GenPainter::MIN_HEIGHT,
|
||||
GenPainter::WATER_HEIGHT);
|
||||
self::$BIOMES_BY_RANGE[Biome::RIVER] = new Range(GenPainter::WATER_HEIGHT,
|
||||
GenPainter::WATER_HEIGHT + (17 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::SWAMP] = new Range(GenPainter::WATER_HEIGHT,
|
||||
GenPainter::WATER_HEIGHT + (17 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::DESERT] = new Range(
|
||||
GenPainter::WATER_HEIGHT + (8 * GenPainter::DEPTH_MULTIPLICATOR),
|
||||
GenPainter::WATER_HEIGHT + (52 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::ICE_PLAINS] = new Range(
|
||||
GenPainter::WATER_HEIGHT + (17 * GenPainter::DEPTH_MULTIPLICATOR),
|
||||
GenPainter::WATER_HEIGHT + (46 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::PLAINS] = new Range(
|
||||
GenPainter::WATER_HEIGHT + (17 * GenPainter::DEPTH_MULTIPLICATOR),
|
||||
GenPainter::WATER_HEIGHT + (52 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::FOREST] = new Range(
|
||||
GenPainter::WATER_HEIGHT + (40 * GenPainter::DEPTH_MULTIPLICATOR),
|
||||
GenPainter::WATER_HEIGHT + (78 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::BIRCH_FOREST] = new Range(
|
||||
GenPainter::WATER_HEIGHT + (40 * GenPainter::DEPTH_MULTIPLICATOR),
|
||||
GenPainter::WATER_HEIGHT + (78 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::TAIGA] = new Range(
|
||||
GenPainter::WATER_HEIGHT + (52 * GenPainter::DEPTH_MULTIPLICATOR),
|
||||
GenPainter::WATER_HEIGHT + (78 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::SMALL_MOUNTAINS] = new Range(
|
||||
GenPainter::WATER_HEIGHT + (78 * GenPainter::DEPTH_MULTIPLICATOR),
|
||||
GenPainter::WATER_HEIGHT + (158 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
self::$BIOMES_BY_RANGE[Biome::MOUNTAINS] = new Range(
|
||||
GenPainter::WATER_HEIGHT + (158 * GenPainter::DEPTH_MULTIPLICATOR),
|
||||
GenPainter::WATER_HEIGHT + (258 * GenPainter::DEPTH_MULTIPLICATOR));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prompts the command line for a message
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
public static function prompt(string $message): string{
|
||||
if (PHP_OS == 'WINNT') {
|
||||
echo $message;
|
||||
$line = stream_get_line(STDIN, 1024, PHP_EOL);
|
||||
} else {
|
||||
$line = readline($message);
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Modified version of PocketMine's to allow a better implementation
|
||||
*/
|
||||
namespace Ad5001\GenPainterPE\utils;
|
||||
use pocketmine\level\generator\noise\Simplex;
|
||||
use pocketmine\utils\Random;
|
||||
use pocketmine\level\generator\biome\Biome;
|
||||
|
||||
|
||||
class BiomeSelector{
|
||||
/** @var Biome */
|
||||
private $fallback;
|
||||
/** @var Simplex */
|
||||
private $temperature;
|
||||
/** @var Simplex */
|
||||
private $rainfall;
|
||||
/** @var Biome[] */
|
||||
private $biomes = [];
|
||||
/** @var \SplFixedArray */
|
||||
private $map = null;
|
||||
/** @var callable */
|
||||
private $lookup;
|
||||
public function __construct(Random $random, callable $lookup, Biome $fallback){
|
||||
$this->fallback = $fallback;
|
||||
$this->lookup = $lookup;
|
||||
$this->temperature = new Simplex($random, 2, 1 / 16, 1 / 512);
|
||||
$this->rainfall = new Simplex($random, 2, 1 / 16, 1 / 512);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a biome to the selector
|
||||
*
|
||||
* @param Biome $biome
|
||||
* @return void
|
||||
*/
|
||||
public function addBiome(Biome $biome){
|
||||
$this->biomes[$biome->getId()] = $biome;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the temperature of a biome
|
||||
*
|
||||
* @param [type] $x
|
||||
* @param [type] $z
|
||||
* @return void
|
||||
*/
|
||||
public function getTemperature($x, $z){
|
||||
return ($this->temperature->noise2D($x, $z, true) + 1) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rainfall of a location
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
* @return void
|
||||
*/
|
||||
public function getRainfall($x, $z){
|
||||
return ($this->rainfall->noise2D($x, $z, true) + 1) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $x
|
||||
* @param $z
|
||||
*
|
||||
* @return Biome
|
||||
*/
|
||||
public function pickBiome($x, $z) : Biome{
|
||||
$temperature = (int) ($this->getTemperature($x, $z) * 63);
|
||||
$rainfall = (int) ($this->getRainfall($x, $z) * 63);
|
||||
$biomeId = call_user_func($this->lookup, $temperature / 63, $rainfall / 63);
|
||||
return $this->biomes[$biomeId] ?? $this->fallback;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Ad5001\RealWorld\utils;
|
||||
namespace Ad5001\GenPainterPE\utils;
|
||||
|
||||
class Range {
|
||||
|
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
namespace Ad5001\RealWorld;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\event\level\LevelInitEvent;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\level\generator\Generator;
|
||||
|
||||
use Ad5001\RealWorld\utils\Range;
|
||||
use Ad5001\RealWorld\generator\RealWorld;
|
||||
use Ad5001\RealWorld\generator\RealWorldLarge;
|
||||
|
||||
|
||||
class Main extends PluginBase implements Listener{
|
||||
public static $BIOMES_BY_RANGE = [];
|
||||
|
||||
/**
|
||||
* Loads the plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onEnable(){
|
||||
@mkdir($this->getDataFolder());
|
||||
if(!file_exists($this->getDataFolder() . "heightmap.png")) { // Get default world HeightMap
|
||||
file_put_contents($this->getDataFolder() . "heightmap.png", $this->getResource("heightmap.png"));
|
||||
}
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
// Register generators
|
||||
Generator::addGenerator(RealWorld::class, "realworld");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks when a command is sent.
|
||||
*
|
||||
* @param CommandSender $sender
|
||||
* @param Command $cmd
|
||||
* @param string $label
|
||||
* @param array $args
|
||||
* @return bool
|
||||
*/
|
||||
public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args): bool{
|
||||
switch($cmd->getName()){
|
||||
case "default":
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Checks when a world will start being generated to give it's id to it and start generation
|
||||
// *
|
||||
// * @param LevelInitEvent $ev
|
||||
// * @return void
|
||||
// */
|
||||
// public function onLevelInit(LevelInitEvent $ev){
|
||||
// $lvl = $ev->getLevel();
|
||||
// $contents = "";
|
||||
// if(file_exists($this->getDataFolder() . "worldsids.txt")){
|
||||
// $contents = file_get_contents($this->getDataFolder() . "worldsids.txt") . "\n";
|
||||
// }
|
||||
// $contents .= $lvl->getId() . ": " . $lvl->getName();
|
||||
// file_put_contents($this->getDataFolder() . "worldsids.txt")
|
||||
// }
|
||||
|
||||
/**
|
||||
* Generates all ranges for biomes.
|
||||
* Default WATER_HEIGHT is 100
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function generateRanges(){
|
||||
self::$BIOMES_BY_RANGE = [];
|
||||
self::$BIOMES_BY_RANGE[Biome::OCEAN] = new Range(RealWorld::MIN_HEIGHT, RealWorld::WATER_HEIGHT);
|
||||
self::$BIOMES_BY_RANGE[Biome::RIVER] = new Range(RealWorld::WATER_HEIGHT, RealWorld::WATER_HEIGHT + 10);
|
||||
self::$BIOMES_BY_RANGE[Biome::SWAMP] = new Range(RealWorld::WATER_HEIGHT, RealWorld::WATER_HEIGHT + 10);
|
||||
self::$BIOMES_BY_RANGE[Biome::DESERT] = new Range(RealWorld::WATER_HEIGHT + 5, RealWorld::WATER_HEIGHT + 31);
|
||||
self::$BIOMES_BY_RANGE[Biome::ICE_PLAINS] = new Range(RealWorld::WATER_HEIGHT + 10, RealWorld::WATER_HEIGHT + 31);
|
||||
self::$BIOMES_BY_RANGE[Biome::PLAINS] = new Range(RealWorld::WATER_HEIGHT + 10, RealWorld::WATER_HEIGHT + 31);
|
||||
self::$BIOMES_BY_RANGE[Biome::FOREST] = new Range(RealWorld::WATER_HEIGHT + 24, RealWorld::WATER_HEIGHT + 47);
|
||||
self::$BIOMES_BY_RANGE[Biome::BIRCH_FOREST] = new Range(RealWorld::WATER_HEIGHT + 24, RealWorld::WATER_HEIGHT + 47);
|
||||
self::$BIOMES_BY_RANGE[Biome::TAIGA] = new Range(RealWorld::WATER_HEIGHT + 31, RealWorld::WATER_HEIGHT + 47);
|
||||
self::$BIOMES_BY_RANGE[Biome::SMALL_MOUNTAINS] = new Range(RealWorld::WATER_HEIGHT + 47, RealWorld::WATER_HEIGHT + 95);
|
||||
self::$BIOMES_BY_RANGE[Biome::MOUNTAINS] = new Range(RealWorld::WATER_HEIGHT + 95, RealWorld::WATER_HEIGHT + 155);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
namespace Ad5001\RealWorld\generator;
|
||||
|
||||
use pocketmine\level\generator\Generator;
|
||||
|
||||
use Ad5001\RealWorld\Main;
|
||||
|
||||
|
||||
|
||||
class RealWorldLarge extends Generator{
|
||||
|
||||
|
||||
/**
|
||||
* Inits the class for the var
|
||||
* @param ChunkManager $level
|
||||
* @param Random $random
|
||||
* @return void
|
||||
*/
|
||||
public function init(ChunkManager $level, Random $random) {}
|
||||
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
namespace Ad5001\RealWorld\generator;
|
||||
|
||||
use pocketmine\level\generator\Generator;
|
||||
|
||||
use Ad5001\RealWorld\Main;
|
||||
|
||||
|
||||
|
||||
class RealWorldLarge extends Generator{
|
||||
|
||||
|
||||
/**
|
||||
* Inits the class for the var
|
||||
* @param ChunkManager $level
|
||||
* @param Random $random
|
||||
* @return void
|
||||
*/
|
||||
public function init(ChunkManager $level, Random $random) {}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue