Allow injecting arbitrary preimage block for ore generation

this will be useful for nether ore generation.
This commit is contained in:
Dylan K. Taylor 2020-08-06 12:46:07 +01:00
parent b725fcbdf2
commit aa682a865e
4 changed files with 24 additions and 20 deletions

View File

@ -73,15 +73,16 @@ class Flat extends Generator{
if(isset($this->options["decoration"])){ if(isset($this->options["decoration"])){
$ores = new Ore(); $ores = new Ore();
$stone = VanillaBlocks::STONE();
$ores->setOreTypes([ $ores->setOreTypes([
new OreType(VanillaBlocks::COAL_ORE(), 20, 16, 0, 128), new OreType(VanillaBlocks::COAL_ORE(), $stone, 20, 16, 0, 128),
new OreType(VanillaBlocks::IRON_ORE(), 20, 8, 0, 64), new OreType(VanillaBlocks::IRON_ORE(), $stone, 20, 8, 0, 64),
new OreType(VanillaBlocks::REDSTONE_ORE(), 8, 7, 0, 16), new OreType(VanillaBlocks::REDSTONE_ORE(), $stone, 8, 7, 0, 16),
new OreType(VanillaBlocks::LAPIS_LAZULI_ORE(), 1, 6, 0, 32), new OreType(VanillaBlocks::LAPIS_LAZULI_ORE(), $stone, 1, 6, 0, 32),
new OreType(VanillaBlocks::GOLD_ORE(), 2, 8, 0, 32), new OreType(VanillaBlocks::GOLD_ORE(), $stone, 2, 8, 0, 32),
new OreType(VanillaBlocks::DIAMOND_ORE(), 1, 7, 0, 16), new OreType(VanillaBlocks::DIAMOND_ORE(), $stone, 1, 7, 0, 16),
new OreType(VanillaBlocks::DIRT(), 20, 32, 0, 128), new OreType(VanillaBlocks::DIRT(), $stone, 20, 32, 0, 128),
new OreType(VanillaBlocks::GRAVEL(), 10, 16, 0, 128) new OreType(VanillaBlocks::GRAVEL(), $stone, 10, 16, 0, 128)
]); ]);
$this->populators[] = $ores; $this->populators[] = $ores;
} }

View File

@ -116,15 +116,16 @@ class Normal extends Generator{
$this->generationPopulators[] = $cover; $this->generationPopulators[] = $cover;
$ores = new Ore(); $ores = new Ore();
$stone = VanillaBlocks::STONE();
$ores->setOreTypes([ $ores->setOreTypes([
new OreType(VanillaBlocks::COAL_ORE(), 20, 16, 0, 128), new OreType(VanillaBlocks::COAL_ORE(), $stone, 20, 16, 0, 128),
new OreType(VanillaBlocks::IRON_ORE(), 20, 8, 0, 64), new OreType(VanillaBlocks::IRON_ORE(), $stone, 20, 8, 0, 64),
new OreType(VanillaBlocks::REDSTONE_ORE(), 8, 7, 0, 16), new OreType(VanillaBlocks::REDSTONE_ORE(), $stone, 8, 7, 0, 16),
new OreType(VanillaBlocks::LAPIS_LAZULI_ORE(), 1, 6, 0, 32), new OreType(VanillaBlocks::LAPIS_LAZULI_ORE(), $stone, 1, 6, 0, 32),
new OreType(VanillaBlocks::GOLD_ORE(), 2, 8, 0, 32), new OreType(VanillaBlocks::GOLD_ORE(), $stone, 2, 8, 0, 32),
new OreType(VanillaBlocks::DIAMOND_ORE(), 1, 7, 0, 16), new OreType(VanillaBlocks::DIAMOND_ORE(), $stone, 1, 7, 0, 16),
new OreType(VanillaBlocks::DIRT(), 20, 32, 0, 128), new OreType(VanillaBlocks::DIRT(), $stone, 20, 32, 0, 128),
new OreType(VanillaBlocks::GRAVEL(), 10, 16, 0, 128) new OreType(VanillaBlocks::GRAVEL(), $stone, 10, 16, 0, 128)
]); ]);
$this->populators[] = $ores; $this->populators[] = $ores;
} }

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\world\generator\object; namespace pocketmine\world\generator\object;
use pocketmine\block\BlockLegacyIds;
use pocketmine\math\VectorMath; use pocketmine\math\VectorMath;
use pocketmine\utils\Random; use pocketmine\utils\Random;
use pocketmine\world\ChunkManager; use pocketmine\world\ChunkManager;
@ -46,7 +45,7 @@ class Ore{
} }
public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z) : bool{ public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z) : bool{
return $world->getBlockAt($x, $y, $z)->getId() === BlockLegacyIds::STONE; return $world->getBlockAt($x, $y, $z)->isSameType($this->type->replaces);
} }
public function placeObject(ChunkManager $world, int $x, int $y, int $z) : void{ public function placeObject(ChunkManager $world, int $x, int $y, int $z) : void{
@ -86,7 +85,7 @@ class Ore{
$sizeZ = ($zz + 0.5 - $seedZ) / $size; $sizeZ = ($zz + 0.5 - $seedZ) / $size;
$sizeZ *= $sizeZ; $sizeZ *= $sizeZ;
if(($sizeX + $sizeY + $sizeZ) < 1 and $world->getBlockAt($xx, $yy, $zz)->getId() === BlockLegacyIds::STONE){ if(($sizeX + $sizeY + $sizeZ) < 1 and $world->getBlockAt($xx, $yy, $zz)->isSameType($this->type->replaces)){
$world->setBlockAt($xx, $yy, $zz, $this->type->material); $world->setBlockAt($xx, $yy, $zz, $this->type->material);
} }
} }

View File

@ -28,6 +28,8 @@ use pocketmine\block\Block;
class OreType{ class OreType{
/** @var Block */ /** @var Block */
public $material; public $material;
/** @var Block */
public $replaces;
/** @var int */ /** @var int */
public $clusterCount; public $clusterCount;
/** @var int */ /** @var int */
@ -37,8 +39,9 @@ class OreType{
/** @var int */ /** @var int */
public $minHeight; public $minHeight;
public function __construct(Block $material, int $clusterCount, int $clusterSize, int $minHeight, int $maxHeight){ public function __construct(Block $material, Block $replaces, int $clusterCount, int $clusterSize, int $minHeight, int $maxHeight){
$this->material = $material; $this->material = $material;
$this->replaces = $replaces;
$this->clusterCount = $clusterCount; $this->clusterCount = $clusterCount;
$this->clusterSize = $clusterSize; $this->clusterSize = $clusterSize;
$this->maxHeight = $maxHeight; $this->maxHeight = $maxHeight;