mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
tried porting structure api from 1.5.2
This commit is contained in:
parent
4715d938e1
commit
fad3a556dd
15 changed files with 649 additions and 27 deletions
|
|
@ -128,6 +128,8 @@ require_once(FILE_PATH . "/src/structure/Structure.php");
|
|||
require_once(FILE_PATH . "/src/world/generator/Populator.php");
|
||||
require_once(FILE_PATH . "/src/world/generator/LevelGenerator.php");
|
||||
|
||||
require_once(FILE_PATH . "/src/world/generator/structure/StructureBase.php");
|
||||
require_once(FILE_PATH . "/src/world/generator/structure/StructureGenerator.php");
|
||||
require_once(FILE_PATH . "/src/plugin/Plugin.php");
|
||||
require_once(FILE_PATH . "/src/plugin/OtherPluginRequirement.php");
|
||||
require_once(FILE_PATH . "/src/plugin/DummyPlugin.php");
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class AxisAlignedBB{
|
|||
public function grow($x, $y, $z){
|
||||
return new AxisAlignedBB($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z);
|
||||
}
|
||||
|
||||
|
||||
public function expand($x, $y, $z){
|
||||
$this->minX -= $x;
|
||||
$this->minY -= $y;
|
||||
|
|
@ -71,7 +71,8 @@ class AxisAlignedBB{
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function offset($x, $y, $z){
|
||||
$this->minX += $x;
|
||||
$this->minY += $y;
|
||||
|
|
@ -305,6 +306,28 @@ class AxisAlignedBB{
|
|||
return MovingObjectPosition::fromBlock(0, 0, 0, $f, $vector);
|
||||
}
|
||||
|
||||
public function expandTo(AxisAlignedBB $bb){
|
||||
$this->minX = min($this->minX, $bb->minX);
|
||||
$this->minY = min($this->minY, $bb->minY);
|
||||
$this->minZ = min($this->minZ, $bb->minZ);
|
||||
$this->maxX = max($this->maxX, $bb->maxX);
|
||||
$this->maxY = max($this->maxY, $bb->maxY);
|
||||
$this->maxZ = max($this->maxZ, $bb->maxZ);
|
||||
}
|
||||
|
||||
public function getXSize(){
|
||||
return $this->maxX - $this->minX + 1;
|
||||
}
|
||||
|
||||
public function getYSize(){
|
||||
return $this->maxY - $this->minY + 1;
|
||||
}
|
||||
|
||||
public function getZSize(){
|
||||
return $this->maxZ - $this->minZ + 1;
|
||||
}
|
||||
|
||||
|
||||
public function __toString(){
|
||||
return "min: {$this->minX}, {$this->minY}, {$this->minZ}, max: {$this->maxX}, {$this->maxY}, {$this->maxZ}";
|
||||
}
|
||||
|
|
|
|||
18
src/math/StructureAABB.php
Normal file
18
src/math/StructureAABB.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
class StructureAABB extends \AxisAlignedBB
|
||||
{
|
||||
public function __construct($minX, $minY, $minZ, $maxX, $maxY = 0, $maxZ = 0){
|
||||
if(func_num_args() == 4) parent::__construct($minX, 1, $minY, $minZ, 512, $maxX); //why no overloading
|
||||
else parent::__construct($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
|
||||
}
|
||||
|
||||
public function intersectsWith($bb, $minZ = 0, $maxX = 0, $maxZ = 0){
|
||||
if($bb instanceof AxisAlignedBB){
|
||||
return $this->intersectsWith($bb->minX, $bb->minZ, $bb->maxX, $bb->maxZ);
|
||||
}
|
||||
return $this->maxX >= $bb && $this->minX <= $maxX && $this->maxZ >= $minZ && $this->minZ <= $maxZ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -742,7 +742,7 @@ class PMFLevel extends PMF{
|
|||
$this->createUnpopulatedChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
if($this->chunks[$index][$Y] === false){
|
||||
if(!isset($this->chunks[$index][$Y]) || $this->chunks[$index][$Y] === false){
|
||||
$this->fillMiniChunk($X, $Z, $Y);
|
||||
}
|
||||
$aX = $x - ($X << 4);
|
||||
|
|
@ -750,8 +750,8 @@ class PMFLevel extends PMF{
|
|||
$aY = $y - ($Y << 4);
|
||||
$bindex = (int) ($aY + ($aX << 6) + ($aZ << 10));
|
||||
$mindex = (int) (($aY >> 1) + 16 + ($aX << 6) + ($aZ << 10));
|
||||
$old_b = ord($this->chunks[$index][$Y][$bindex]);
|
||||
$old_m = ord($this->chunks[$index][$Y][$mindex]);
|
||||
$old_b = ord($this->chunks[$index][$Y][$bindex] ?? '\x00');
|
||||
$old_m = ord($this->chunks[$index][$Y][$mindex] ?? '\x00');
|
||||
if(($y & 1) === 0){
|
||||
$m = ($old_m & 0xF0) | $meta;
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ class Utils{
|
|||
return $angle < 0 ? $angle + 360 : $angle;
|
||||
}
|
||||
|
||||
public static function chunkPos2Int($x, $z){
|
||||
return ($x & 0xFFFFFFFF) | (($z & 0xFFFFFFFF) << 32);
|
||||
}
|
||||
|
||||
public static function wrapAngleTo180($angle)
|
||||
{
|
||||
$angle = fmod($angle+180, 360);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
private $noiseBase;
|
||||
private $biomeSelector;
|
||||
private $caveGenerator;
|
||||
private $mineshaftGenerator;
|
||||
public function __construct(array $options = array()){
|
||||
|
||||
}
|
||||
|
|
@ -65,6 +66,7 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
$tallGrass->setRandomAmount(0);
|
||||
$this->populators[] = $tallGrass;
|
||||
$this->caveGenerator = new CaveGenerator($this->level->getSeed());
|
||||
$this->mineshaftGenerator = new MineshaftGenerator($this->level->getSeed());
|
||||
}
|
||||
|
||||
public function pickBiome(int $x, int $z){
|
||||
|
|
@ -154,7 +156,10 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
$this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk);
|
||||
}
|
||||
$this->level->level->setBiomeIdArrayForChunk($chunkX, $chunkZ, $biomes);
|
||||
if(self::HIDDEN_FEATURES) $this->caveGenerator->generate($this->level, $chunkX, $chunkZ); //TODO speedup
|
||||
if(self::HIDDEN_FEATURES) {
|
||||
$this->caveGenerator->generate($this->level, $chunkX, $chunkZ); //TODO speedup
|
||||
$this->mineshaftGenerator->generate($this->level, $chunkX, $chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
|
|
@ -175,6 +180,8 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
}
|
||||
|
||||
if(self::HIDDEN_FEATURES) {
|
||||
//this.mineshaftGenerator.generateStructuresInChunk(this.worldObj, this.rand, par2, par3);
|
||||
$this->mineshaftGenerator->generateStructuresInChunk($this->level, $this->mtrandom, $chunkX, $chunkZ);
|
||||
for ($i = 0; $i < 8; ++$i){
|
||||
$x = $blockX + $this->mtrandom->nextInt(16) + 8;
|
||||
$y = $this->mtrandom->nextInt(128);
|
||||
|
|
|
|||
|
|
@ -1,27 +1,7 @@
|
|||
<?php
|
||||
//b1.7.3
|
||||
class CaveGenerator
|
||||
class CaveGenerator extends StructureBase
|
||||
{
|
||||
public $range = 8;
|
||||
public $rand;
|
||||
|
||||
public function __construct($seed){
|
||||
$this->rand = new MTRandom($seed);
|
||||
}
|
||||
|
||||
public function generate(Level $level, $chunkX, $chunkZ){
|
||||
$range = $this->range;
|
||||
$this->rand->setSeed($level->getSeed());
|
||||
$seedInt1 = $this->rand->nextInt();
|
||||
$seedInt2 = $this->rand->nextInt();
|
||||
|
||||
for($x = $chunkX - $range; $x <= $chunkX + $range; ++$x){
|
||||
for($z = $chunkZ - $range; $z <= $chunkZ + $range; ++$z){
|
||||
$this->rand->setSeed((($x * $seedInt1) + ($z * $seedInt2)) ^ $level->getSeed());
|
||||
$this->recursiveGenerate($level, $x, $z, $chunkX, $chunkZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function recursiveGenerate(Level $level, $chunkXoffsetted, $chunkZoffsetted, $chunkX, $chunkZ){
|
||||
$nextInt = $this->rand->nextInt($this->rand->nextInt($this->rand->nextInt(40) + 1) + 1);
|
||||
|
|
|
|||
19
src/world/generator/cave/MineshaftGenerator.php
Normal file
19
src/world/generator/cave/MineshaftGenerator.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
class MineshaftGenerator extends StructureGenerator
|
||||
{
|
||||
protected $spawnChance = 1;//0.01;
|
||||
|
||||
public function canSpawnStructureAt($chunkX, $chunkZ)
|
||||
{
|
||||
$v = $this->rand->nextFloat() < $this->spawnChance && $this->rand->nextInt(80) < max(abs($chunkX), abs($chunkZ));
|
||||
if($v) ConsoleAPI::debug("u can spawn mineshaft at $chunkX $chunkZ");
|
||||
return $v;
|
||||
}
|
||||
|
||||
public function getStructureStart(Level $level, $chunkX, $chunkZ)
|
||||
{
|
||||
return new StructureMineshaftStart($level, $this->rand, $chunkX, $chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
28
src/world/generator/structure/StructureBase.php
Normal file
28
src/world/generator/structure/StructureBase.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
abstract class StructureBase
|
||||
{
|
||||
public $range = 8;
|
||||
public $rand;
|
||||
|
||||
public function __construct(){
|
||||
$this->rand = new MTRandom();
|
||||
}
|
||||
|
||||
public function generate(Level $level, $chunkX, $chunkZ){
|
||||
$range = $this->range;
|
||||
$this->rand->setSeed($level->getSeed());
|
||||
$seedInt1 = $this->rand->nextInt();
|
||||
$seedInt2 = $this->rand->nextInt();
|
||||
|
||||
for($x = $chunkX - $range; $x <= $chunkX + $range; ++$x){
|
||||
for($z = $chunkZ - $range; $z <= $chunkZ + $range; ++$z){
|
||||
$this->rand->setSeed((($x * $seedInt1) + ($z * $seedInt2)) ^ $level->getSeed());
|
||||
$this->recursiveGenerate($level, $x, $z, $chunkX, $chunkZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function recursiveGenerate(Level $level, $chunkXoffsetted, $chunkZoffsetted, $chunkX, $chunkZ){}
|
||||
}
|
||||
|
||||
301
src/world/generator/structure/StructureComponent.php
Normal file
301
src/world/generator/structure/StructureComponent.php
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
<?php
|
||||
|
||||
abstract class StructureComponent
|
||||
{
|
||||
public AxisAlignedBB $boundingBox;
|
||||
|
||||
public $coordBaseMode = -1;
|
||||
public $componentType = 0;
|
||||
|
||||
public function __construct($type){
|
||||
$this->componentType = $type;
|
||||
}
|
||||
|
||||
public function buildComponent(StructureComponent $component, $aList, MTRandom $random){}
|
||||
public abstract function addComponentParts(Level $level, MTRandom $random, AxisAlignedBB $boundingBox): bool;
|
||||
|
||||
/**
|
||||
* @param StructureComponent[] $aList
|
||||
* @param AxisAlignedBB $boundingBox
|
||||
*/
|
||||
public static function findIntersecting($aList, AxisAlignedBB $boundingBox){
|
||||
foreach($aList as $component){
|
||||
if($component->boundingBox != null && $component->boundingBox->intersectsWith($boundingBox)){
|
||||
return $component;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCenter(){
|
||||
return new Vector3(
|
||||
(int)($this->boundingBox->minX + (($this->boundingBox->maxX - $this->boundingBox->minX + 1) / 2)),
|
||||
(int)($this->boundingBox->minY + (($this->boundingBox->maxY - $this->boundingBox->minY + 1) / 2)),
|
||||
(int)($this->boundingBox->minZ + (($this->boundingBox->maxZ - $this->boundingBox->minZ + 1) / 2)),
|
||||
);
|
||||
}
|
||||
public function isLiquidInStructureBoundingBox(Level $level, AxisAlignedBB $boundingBox){
|
||||
$minX = max($boundingBox->minX - 1, $boundingBox->minX); //TODO optimize?
|
||||
$minY = max($boundingBox->minY - 1, $boundingBox->minY);
|
||||
$minZ = max($boundingBox->minZ - 1, $boundingBox->minZ);
|
||||
$maxX = min($boundingBox->maxX + 1, $boundingBox->maxX);
|
||||
$maxY = min($boundingBox->maxY + 1, $boundingBox->maxY);
|
||||
$maxZ = min($boundingBox->maxZ + 1, $boundingBox->maxZ);
|
||||
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
$blockID = $level->level->getBlockID($x, $minY, $z);
|
||||
if($blockID > 0 && StaticBlock::getIsLiquid($blockID)) return true;
|
||||
$blockID = $level->level->getBlockID($x, $maxY, $z);
|
||||
if($blockID > 0 && StaticBlock::getIsLiquid($blockID)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$blockID = $level->level->getBlockID($x, $y, $minZ);
|
||||
if($blockID > 0 && StaticBlock::getIsLiquid($blockID)) return true;
|
||||
$blockID = $level->level->getBlockID($x, $y, $maxZ);
|
||||
if($blockID > 0 && StaticBlock::getIsLiquid($blockID)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$blockID = $level->level->getBlockID($minX, $y, $z);
|
||||
if($blockID > 0 && StaticBlock::getIsLiquid($blockID)) return true;
|
||||
$blockID = $level->level->getBlockID($maxX, $y, $z);
|
||||
if($blockID > 0 && StaticBlock::getIsLiquid($blockID)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getXWithOffset($par1, $par2){
|
||||
return match($this->coordBaseMode){
|
||||
0, 2 => $this->boundingBox->minX + $par1,
|
||||
1 => $this->boundingBox->maxX - $par2,
|
||||
3 => $this->boundingBox->minX + $par2,
|
||||
default => $par1
|
||||
};
|
||||
}
|
||||
public function getYWithOffset($par1){
|
||||
return $this->coordBaseMode == -1 ? $par1 : $par1 + $this->boundingBox->minY;
|
||||
}
|
||||
public function getZWithOffset($par1, $par2){
|
||||
return match($this->coordBaseMode){
|
||||
0 => $this->boundingBox->minZ + $par2,
|
||||
1, 3 => $this->boundingBox->minZ + $par1,
|
||||
2 => $this->boundingBox->maxZ - $par2,
|
||||
default => $par2
|
||||
};
|
||||
}
|
||||
public function getMetadataWithOffset($blockID, $blockMeta){
|
||||
switch($blockID){
|
||||
case WOODEN_DOOR_BLOCK:
|
||||
case IRON_DOOR_BLOCK:
|
||||
switch($this->coordBaseMode){
|
||||
case 0:
|
||||
return match($blockMeta){
|
||||
0 => 2,
|
||||
2 => 0,
|
||||
default => $blockMeta
|
||||
};
|
||||
case 1:
|
||||
return $blockMeta + 1 & 3;
|
||||
case 3:
|
||||
return $blockMeta + 3 & 3;
|
||||
}
|
||||
|
||||
break;
|
||||
case COBBLESTONE_STAIRS:
|
||||
case WOODEN_STAIRS:
|
||||
case NETHER_BRICKS_STAIRS:
|
||||
case STONE_BRICK_STAIRS:
|
||||
case SANDSTONE_STAIRS:
|
||||
switch($this->coordBaseMode){
|
||||
case 0:
|
||||
return match($blockMeta){
|
||||
2 => 3,
|
||||
3 => 2,
|
||||
default => $blockMeta
|
||||
};
|
||||
case 1:
|
||||
return match($blockMeta){
|
||||
0 => 2,
|
||||
1 => 3,
|
||||
2 => 0,
|
||||
3 => 1,
|
||||
default => $blockMeta
|
||||
};
|
||||
case 3:
|
||||
return match($blockMeta){
|
||||
0 => 2,
|
||||
1 => 3,
|
||||
2 => 1,
|
||||
3 => 0,
|
||||
default => $blockMeta
|
||||
};
|
||||
}
|
||||
break;
|
||||
case RAIL:
|
||||
if($this->coordBaseMode == 1 || $this->coordBaseMode == 3){
|
||||
return $blockMeta == 1 ? 0 : 1;
|
||||
}
|
||||
break;
|
||||
case LADDER:
|
||||
switch($this->coordBaseMode){
|
||||
case 0:
|
||||
return match($blockMeta){
|
||||
2 => 3,
|
||||
3 => 2,
|
||||
default => $blockMeta
|
||||
};
|
||||
case 1:
|
||||
return match($blockMeta){
|
||||
2 => 4,
|
||||
3 => 5,
|
||||
4 => 2,
|
||||
5 => 3,
|
||||
default => $blockMeta
|
||||
};
|
||||
case 3:
|
||||
return match($blockMeta){
|
||||
2 => 5,
|
||||
3 => 4,
|
||||
4 => 2,
|
||||
5 => 3,
|
||||
default => $blockMeta
|
||||
};
|
||||
}
|
||||
//case stone_button, not needed
|
||||
//case pistonbase, pistonstickybase, level, dispenser, not needed
|
||||
|
||||
}
|
||||
/* TODO directional blocks, tripwire source(not needed prob)
|
||||
* if (this.coordBaseMode == 0)
|
||||
{
|
||||
if (blockMeta == 0 || blockMeta == 2) return Direction.rotateOpposite[blockMeta];
|
||||
}
|
||||
else if (this.coordBaseMode == 1)
|
||||
{
|
||||
if (blockMeta == 2) return 1;
|
||||
|
||||
if (blockMeta == 0) return 3;
|
||||
|
||||
if (blockMeta == 1) return 2;
|
||||
|
||||
if (blockMeta == 3) return 0;
|
||||
}
|
||||
else if (this.coordBaseMode == 3)
|
||||
{
|
||||
if (blockMeta == 2) return 3;
|
||||
if (blockMeta == 0) return 1;
|
||||
if (blockMeta == 1) return 2;
|
||||
if (blockMeta == 3) return 0;
|
||||
}
|
||||
*/
|
||||
return $blockMeta;
|
||||
}
|
||||
|
||||
public function placeBlockAtCurrentPosition(Level $level, $blockID, $blockMeta, $par4, $par5, $par6, AxisAlignedBB $boundingBox){
|
||||
$x = $this->getXWithOffset($par4, $par6);
|
||||
$y = $this->getYWithOffset($par5);
|
||||
$z = $this->getZWithOffset($par4, $par6);
|
||||
|
||||
if($boundingBox->isXYZInside($x, $y, $z)){
|
||||
$level->fastSetBlockUpdate($x, $y, $z, $blockID, $blockMeta);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBlockIdAtCurrentPosition(Level $level, $par2, $par3, $par4, AxisAlignedBB $boundingBox){
|
||||
$x = $this->getXWithOffset($par2, $par4);
|
||||
$y = $this->getYWithOffset($par3);
|
||||
$z = $this->getZWithOffset($par2, $par4);
|
||||
return !$boundingBox->isXYZInside($x, $y, $z) ? 0 : $level->level->getBlockID($x, $y, $z);
|
||||
}
|
||||
|
||||
public function fillWithAir(Level $level, AxisAlignedBB $boundingBox, $minX, $minY, $minZ, $maxX, $maxY, $maxZ){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($z = $minZ; $z < $maxZ; ++$z){
|
||||
$this->placeBlockAtCurrentPosition($level, AIR, 0, $x, $y, $z, $boundingBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fillWithBlocks(Level $level, AxisAlignedBB $boundingBox, $minX, $minY, $minZ, $maxX, $maxY, $maxZ, $blockID, $replaceID, $alwaysReplace){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($z = $minZ; $z < $maxZ; ++$z){
|
||||
if(!$alwaysReplace || $this->getBlockIdAtCurrentPosition($level, $x, $y, $z, $boundingBox) != 0){
|
||||
if($y != $minY && $y != $maxY && $x != $minX && $x != $maxX && $z != $minZ && $z != $maxZ){
|
||||
$this->placeBlockAtCurrentPosition($level, $replaceID, 0, $x, $y, $z, $boundingBox);
|
||||
}else{
|
||||
$this->placeBlockAtCurrentPosition($level, $blockID, 0, $x, $y, $z, $boundingBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fillWithMetadataBlocks(){throw new Exception("Not Implemented");} //TODO it is too long + not used for mineshafts i want now
|
||||
public function fillWithRandomizedBlocks(){throw new Exception("Not Implemented");} //TODO it is too long + not used for mineshafts i want now
|
||||
|
||||
public function randomlyFillWithBlocks(Level $level, AxisAlignedBB $boundingBox, MTRandom $random, $randomChance, $minX, $minY, $minZ, $maxX, $maxY, $maxZ, $blockID, $replaceID, $alwaysReplace){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($z = $minZ; $z < $maxZ; ++$z){
|
||||
if($random->nextFloat() <= $randomChance && (!$alwaysReplace || $this->getBlockIdAtCurrentPosition($level, $x, $y, $z, $boundingBox) != 0)){
|
||||
if($y != $minY && $y != $maxY && $x != $minX && $x != $maxX && $z != $minZ && $z != $maxZ){
|
||||
$this->placeBlockAtCurrentPosition($level, $replaceID, 0, $x, $y, $z, $boundingBox);
|
||||
}else{
|
||||
$this->placeBlockAtCurrentPosition($level, $blockID, 0, $x, $y, $z, $boundingBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function randomlyPlaceBlock(Level $level, AxisAlignedBB $boundingBox, MTRandom $random, $randomChance, $x, $y, $z, $blockID, $blockMeta){
|
||||
if($random->nextFloat() < $randomChance) $this->placeBlockAtCurrentPosition($level, $blockID, $blockMeta, $x, $y, $z, $boundingBox);
|
||||
}
|
||||
|
||||
public function randomlyRareFillWithBlocks(Level $level, AxisAlignedBB $boundingBox, $minX, $minY, $minZ, $maxX, $maxY, $maxZ, $blockID, $alwaysreplace){
|
||||
$v11 = ($maxX - $minX + 1);
|
||||
$v12 = ($maxY - $minY + 1);
|
||||
$v13 = ($maxZ - $minZ + 1);
|
||||
$v14 = $minX + $v11 / 2;
|
||||
$v15 = $minZ + $v13 / 2;
|
||||
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$v17 = ($y - $minY) / $v12;
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
$v19 = ($x - $v14) / ($v11 * 0.5);
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
$v21 = ($z - $v15) / ($v13 * 0.5);
|
||||
|
||||
if(!$alwaysreplace || $this->getBlockIdAtCurrentPosition($level, $x, $y, $z, $boundingBox) != 0){
|
||||
$v22 = $v19*$v19 + $v17*$v17 + $v21*$v21;
|
||||
|
||||
if($v22 <= 1.05){
|
||||
$this->placeBlockAtCurrentPosition($level, $blockID, 0, $x, $y, $z, $boundingBox);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function clearCurrentPositionBlocksUpwards(){throw new Exception("Not Implemented");} //TODO implement, used for villages
|
||||
public function fillCurrentPositionBlocksDownwards(){throw new Exception("Not Implemented");} //TODO implement, used for villages
|
||||
public function generateStructureChestContents(){throw new Exception("Not Implemented");} //TODO implement
|
||||
public function placeDoorAtCurrentPosition(){throw new Exception("Not Implemented");} //TODO implement
|
||||
|
||||
}
|
||||
|
||||
39
src/world/generator/structure/StructureGenerator.php
Normal file
39
src/world/generator/structure/StructureGenerator.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
abstract class StructureGenerator extends StructureBase
|
||||
{
|
||||
/**
|
||||
* @var StructureStart
|
||||
*/
|
||||
public $structureMap = []; //php array is hashmap
|
||||
|
||||
public function recursiveGenerate(Level $level, $chunkXoffsetted, $chunkZoffsetted, $chunkX, $chunkZ){
|
||||
$chunkXZ = Utils::chunkPos2Int($chunkXoffsetted, $chunkZoffsetted);
|
||||
if(!isset($this->structureMap[$chunkXZ])){
|
||||
$this->rand->nextInt(); //shouldnt be neccessary, but vanilla has it.
|
||||
|
||||
if($this->canSpawnStructureAt($chunkXoffsetted, $chunkZoffsetted)){
|
||||
$structureStrat = $this->getStructureStart($level, $chunkXoffsetted, $chunkZoffsetted);
|
||||
$this->structureMap[$chunkXZ] = $structureStrat;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function generateStructuresInChunk(Level $level, MTRandom $random, $chunkX, $chunkZ){
|
||||
$chunkXCenter = ($chunkX << 4) + 8;
|
||||
$chunkZCenter = ($chunkZ << 4) + 8;
|
||||
$var7 = false;
|
||||
foreach($this->structureMap as $start){
|
||||
if($start->isSizeableStructure() && $start->boundingBox->intersectsWith($chunkXCenter, $chunkZCenter, $chunkXCenter + 15, $chunkZCenter + 15)){
|
||||
$start->generateStructure($level, $random, new StructureAABB($chunkXCenter, 1, $chunkZCenter, $chunkXCenter + 15, 512, $chunkZCenter + 15));
|
||||
$var7 = true;
|
||||
}
|
||||
}
|
||||
return $var7;
|
||||
}
|
||||
|
||||
public abstract function canSpawnStructureAt($chunkX, $chunkZ);
|
||||
public abstract function getStructureStart(Level $level, $chunkX, $chunkZ);
|
||||
}
|
||||
|
||||
54
src/world/generator/structure/StructureStart.php
Normal file
54
src/world/generator/structure/StructureStart.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
abstract class StructureStart
|
||||
{
|
||||
/**
|
||||
* @var StructureComponent[]
|
||||
*/
|
||||
public $components = [];
|
||||
public $boundingBox;
|
||||
|
||||
public function generateStructure(Level $level, MTRandom $random, AxisAlignedBB $boundingBox){
|
||||
foreach($this->components as $k => $component){
|
||||
if($component->boundingBox->intersectsWith($boundingBox) && !$component->addComponentParts($level, $random, $boundingBox)){
|
||||
unset($this->components[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBoundingBox(){
|
||||
$this->boundingBox = new StructureAABB(0, 0, 0, 0, 0, 0);
|
||||
foreach($this->components as $k => $component){
|
||||
$this->boundingBox->expandTo($component->boundingBox);
|
||||
}
|
||||
}
|
||||
|
||||
public function markAvailableHeight(Level $level, MTRandom $random, $height){
|
||||
$var4 = 63 - $height;
|
||||
$var5 = $this->boundingBox->getYSize() + 1;
|
||||
|
||||
if($var5 < $var4) $var5 += $random->nextInt($var4 - $var5);
|
||||
|
||||
$var6 = (int)($var5 - $this->boundingBox->maxY);
|
||||
$this->boundingBox->offset(0, $var6, 0);
|
||||
|
||||
foreach($this->components as $component){
|
||||
$component->boundingBox->offset(0, $var6, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public function setRandomHeight(Level $level, MTRandom $random, $par3, $par4){
|
||||
$var5 = (int)($par4 - $par3 + 1 - $this->boundingBox->getYSize());
|
||||
$var10 = $var5 > 1 ? $par3 + $random->nextInt($var5) : $par3;
|
||||
$var6 = (int)($var10 - $this->boundingBox->minY);
|
||||
$this->boundingBox->offset(0, $var6, 0);
|
||||
foreach($this->components as $component){
|
||||
$component->boundingBox->offset(0, $var6, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public function isSizeableStructure(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
class StructureMineshaftPieces
|
||||
{
|
||||
//TODO chests
|
||||
//private static final WeightedRandomChestContent[] mineshaftChestContents = new WeightedRandomChestContent[] {new WeightedRandomChestContent(Item.ingotIron.itemID, 0, 1, 5, 10), new WeightedRandomChestContent(Item.ingotGold.itemID, 0, 1, 3, 5), new WeightedRandomChestContent(Item.redstone.itemID, 0, 4, 9, 5), new WeightedRandomChestContent(Item.dyePowder.itemID, 4, 4, 9, 5), new WeightedRandomChestContent(Item.diamond.itemID, 0, 1, 2, 3), new WeightedRandomChestContent(Item.coal.itemID, 0, 3, 8, 10), new WeightedRandomChestContent(Item.bread.itemID, 0, 1, 3, 15), new WeightedRandomChestContent(Item.pickaxeIron.itemID, 0, 1, 1, 1), new WeightedRandomChestContent(Block.rail.blockID, 0, 4, 8, 1), new WeightedRandomChestContent(Item.melonSeeds.itemID, 0, 2, 4, 10), new WeightedRandomChestContent(Item.pumpkinSeeds.itemID, 0, 2, 4, 10)};
|
||||
/**
|
||||
* @return StructureComponent
|
||||
*/
|
||||
public static function getRandomComponent($aList, MTRandom $random, $par2, $par3, $par4, $par5, $par6){
|
||||
$var7 = $random->nextInt(100);
|
||||
|
||||
/*if($var7 >= 80){
|
||||
$var8 = ComponentMineshaftCross //TODO
|
||||
if($var8 != null) return new ComponentMineshaftCross($par6, $random, $var8, $par5);
|
||||
}else if($var7 >= 70){
|
||||
$var8 = ComponentMineshaftStairs //TODO
|
||||
if($var8 != null) return new ComponentMineshaftStairs($par6, $random, $var8, $par5);
|
||||
}else{
|
||||
$var8 = ComponentMineshaftCorridor //TODO
|
||||
if($var8 != null) return new ComponentMineshaftCorridor($par6, $random, $var8, $par5);
|
||||
}*/
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static function getNextMineShaftComponent(StructureComponent $component, $aList, MTRandom $random, $par3, $par4, $par5, $par6, $par7){
|
||||
if($par7 > 8) return null;
|
||||
|
||||
if(abs($par3 - $component->boundingBox->minX) <= 80 && abs($par5 - $component->boundingBox->minZ) <= 80){
|
||||
$var8 = self::getRandomComponent($aList, $random, $par3, $par4, $par5, $par6, $par7 + 1);
|
||||
if($var8 != null){
|
||||
$aList[] = $var8;
|
||||
$var8->buildComponent($component, $aList, $random);
|
||||
}
|
||||
return $var8;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
class StructureMineshaftStart extends StructureStart
|
||||
{
|
||||
public function __construct(Level $level, MTRandom $random, $par3, $par4){
|
||||
$var5 = new ComponentMineshaftRoom(0, $random, ($par3 << 4) + 2, ($par4 << 4) + 2);
|
||||
$this->components[] = $var5;
|
||||
$var5->buildComponent($var5, $this->components, $random);
|
||||
$this->updateBoundingBox();
|
||||
$this->markAvailableHeight($level, $random, 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
class ComponentMineshaftRoom extends StructureComponent
|
||||
{
|
||||
/**
|
||||
* @var AxisAlignedBB[]
|
||||
*/
|
||||
public $roomsLinkedToTheRoom = [];
|
||||
|
||||
public function __construct($par1, MTRandom $random, $par3, $par4){
|
||||
parent::__construct($par1);
|
||||
$this->boundingBox = new AxisAlignedBB($par3, 50, $par4, $par3 + 7 + $random->nextInt(6), $par4 + 7, $par4 + 7 + $random->nextInt(6));
|
||||
}
|
||||
|
||||
public function buildComponent(StructureComponent $component, $aList, MTRandom $random){
|
||||
$var4 = $this->componentType;
|
||||
$var6 = $this->boundingBox->getYSize() - 3 - 1;
|
||||
if($var6 <= 0) $var6 = 1;
|
||||
|
||||
for($var5 = 0; $var5 < $this->boundingBox->getXSize(); $var5 += 4){
|
||||
$var5 += $random->nextInt($this->boundingBox->getXSize());
|
||||
if($var5 + 3 < $this->boundingBox->getXSize()) break;
|
||||
//var7 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + var5, this.boundingBox.minY + par3Random.nextInt(var6) + 1, this.boundingBox.minZ - 1, 2, var4);
|
||||
$var7 = StructureMineshaftPieces::getNextMineShaftComponent($component, $aList, $random, $this->boundingBox->minX + $var5, $this->boundingBox->minY + $random->nextInt($var6) + 1, $this->boundingBox->minZ - 1, 2, $var4);
|
||||
|
||||
if($var7 != null){
|
||||
$var8 = $var7->boundingBox;
|
||||
//this.roomsLinkedToTheRoom.add(new StructureBoundingBox(var8.minX, var8.minY, this.boundingBox.minZ, var8.maxX, var8.maxY, this.boundingBox.minZ + 1));
|
||||
$this->roomsLinkedToTheRoom[] = new StructureAABB($var8->minX, $var8->minY, $this->boundingBox->minZ, $var8->maxX, $var8->maxY, $this->boundingBox->minZ + 1);
|
||||
}
|
||||
}
|
||||
|
||||
for($var5 = 0; $var5 < $this->boundingBox->getXSize(); $var5 += 4){
|
||||
$var5 += $random->nextInt($this->boundingBox->getXSize());
|
||||
if($var5 + 3 < $this->boundingBox->getXSize()) break;
|
||||
//var7 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX + var5, this.boundingBox.minY + par3Random.nextInt(var6) + 1, this.boundingBox.maxZ + 1, 0, var4);
|
||||
$var7 = StructureMineshaftPieces::getNextMineShaftComponent($component, $aList, $random, $this->boundingBox->minX + $var5, $this->boundingBox->minY + $random->nextInt($var6) + 1, $this->boundingBox->maxZ + 1, 0, $var4);
|
||||
|
||||
if($var7 != null){
|
||||
$var8 = $var7->boundingBox;
|
||||
//this.roomsLinkedToTheRoom.add(new StructureBoundingBox(var8.minX, var8.minY, this.boundingBox.maxZ - 1, var8.maxX, var8.maxY, this.boundingBox.maxZ));
|
||||
$this->roomsLinkedToTheRoom[] = new StructureAABB($var8->minX, $var8->minY, $this->boundingBox->maxZ - 1, $var8->maxX, $var8->maxY, $this->boundingBox->maxZ);
|
||||
}
|
||||
}
|
||||
|
||||
for($var5 = 0; $var5 < $this->boundingBox->getZSize(); $var5 += 4){
|
||||
$var5 += $random->nextInt($this->boundingBox->getZSize());
|
||||
if($var5 + 3 < $this->boundingBox->getZSize()) break;
|
||||
//var7 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.minX - 1, this.boundingBox.minY + par3Random.nextInt(var6) + 1, this.boundingBox.minZ + var5, 1, var4);
|
||||
$var7 = StructureMineshaftPieces::getNextMineShaftComponent($component, $aList, $random, $this->boundingBox->minX - 1, $this->boundingBox->minY + $random->nextInt($var6) + 1, $this->boundingBox->minZ + $var5, 1, $var4);
|
||||
|
||||
if($var7 != null){
|
||||
$var8 = $var7->boundingBox;
|
||||
//this.roomsLinkedToTheRoom.add(new StructureBoundingBox(this.boundingBox.minX, var8.minY, var8.minZ, this.boundingBox.minX + 1, var8.maxY, var8.maxZ));
|
||||
$this->roomsLinkedToTheRoom[] = new StructureAABB($this->boundingBox->minX, $var8->minY, $var8->minZ, $this->boundingBox->minX + 1, $var8->maxY, $var8->maxZ);
|
||||
}
|
||||
}
|
||||
|
||||
for($var5 = 0; $var5 < $this->boundingBox->getZSize(); $var5 += 4){
|
||||
$var5 += $random->nextInt($this->boundingBox->getZSize());
|
||||
if($var5 + 3 < $this->boundingBox->getZSize()) break;
|
||||
//var7 = StructureMineshaftPieces.getNextComponent(par1StructureComponent, par2List, par3Random, this.boundingBox.maxX + 1, this.boundingBox.minY + par3Random.nextInt(var6) + 1, this.boundingBox.minZ + var5, 3, var4);
|
||||
$var7 = StructureMineshaftPieces::getNextMineShaftComponent($component, $aList, $random, $this->boundingBox->maxX + 1, $this->boundingBox->minY + $random->nextInt($var6) + 1, $this->boundingBox->minZ + $var5, 3, $var4);
|
||||
|
||||
if($var7 != null){
|
||||
$var8 = $var7->boundingBox;
|
||||
// this.roomsLinkedToTheRoom.add(new StructureBoundingBox(this.boundingBox.maxX - 1, var8.minY, var8.minZ, this.boundingBox.maxX, var8.maxY, var8.maxZ));
|
||||
$this->roomsLinkedToTheRoom[] = new StructureAABB($this->boundingBox->maxX - 1, $var8->minY, $var8->minZ, $this->boundingBox->maxX, $var8->maxY, $var8->maxZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function addComponentParts(Level $level, MTRandom $random, AxisAlignedBB $boundingBox): bool
|
||||
{
|
||||
if($this->isLiquidInStructureBoundingBox($level, $boundingBox)){
|
||||
return false;
|
||||
}
|
||||
console("Adding Mineshaft start components! $boundingBox");
|
||||
$this->fillWithBlocks($level, $boundingBox, $this->boundingBox->minX, $this->boundingBox->minY, $this->boundingBox->minZ, $this->boundingBox->maxX, $this->boundingBox->maxY, $this->boundingBox->maxZ, DIRT, 0, true);
|
||||
$this->fillWithBlocks($level, $boundingBox, $this->boundingBox->minX, $this->boundingBox->minY + 1, $this->boundingBox->minZ, $this->boundingBox->maxX, min($this->boundingBox->minY + 3, $this->boundingBox->maxY), $this->boundingBox->maxZ, 0, 0, false);
|
||||
|
||||
foreach($this->roomsLinkedToTheRoom as $bb){
|
||||
//this.fillWithBlocks(par1World, par3StructureBoundingBox, var5.minX, var5.maxY - 2, var5.minZ, var5.maxX, var5.maxY, var5.maxZ, 0, 0, false);
|
||||
$this->fillWithBlocks($level, $boundingBox, $bb->minX, $bb->maxY - 2, $bb->minZ, $bb->maxX, $bb->maxY, $bb->maxZ, 0, 0, false);
|
||||
}
|
||||
|
||||
$this->randomlyRareFillWithBlocks($level, $boundingBox, $this->boundingBox->minX, $this->boundingBox->minY + 4, $this->boundingBox->minZ, $this->boundingBox->maxX, $this->boundingBox->maxY, $this->boundingBox->maxZ, 0, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue