From fad3a556dd6e88181d3e057fea7b3329701a4f8a Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sun, 3 Dec 2023 15:45:34 +0300 Subject: [PATCH] tried porting structure api from 1.5.2 --- src/dependencies.php | 2 + src/math/AxisAlignedBB.php | 27 +- src/math/StructureAABB.php | 18 ++ src/pmf/PMFLevel.php | 6 +- src/utils/Utils.php | 4 + src/world/generator/NormalGenerator.php | 9 +- src/world/generator/cave/CaveGenerator.php | 22 +- .../generator/cave/MineshaftGenerator.php | 19 ++ .../generator/structure/StructureBase.php | 28 ++ .../structure/StructureComponent.php | 301 ++++++++++++++++++ .../structure/StructureGenerator.php | 39 +++ .../generator/structure/StructureStart.php | 54 ++++ .../mineshaft/StructureMineshaftPieces.php | 43 +++ .../mineshaft/StructureMineshaftStart.php | 13 + .../component/ComponentMineshaftRoom.php | 91 ++++++ 15 files changed, 649 insertions(+), 27 deletions(-) create mode 100644 src/math/StructureAABB.php create mode 100644 src/world/generator/cave/MineshaftGenerator.php create mode 100644 src/world/generator/structure/StructureBase.php create mode 100644 src/world/generator/structure/StructureComponent.php create mode 100644 src/world/generator/structure/StructureGenerator.php create mode 100644 src/world/generator/structure/StructureStart.php create mode 100644 src/world/generator/structure/mineshaft/StructureMineshaftPieces.php create mode 100644 src/world/generator/structure/mineshaft/StructureMineshaftStart.php create mode 100644 src/world/generator/structure/mineshaft/component/ComponentMineshaftRoom.php diff --git a/src/dependencies.php b/src/dependencies.php index aff3def1..85b6a25a 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -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"); diff --git a/src/math/AxisAlignedBB.php b/src/math/AxisAlignedBB.php index f32b77ea..862651f1 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.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}"; } diff --git a/src/math/StructureAABB.php b/src/math/StructureAABB.php new file mode 100644 index 00000000..f85f8709 --- /dev/null +++ b/src/math/StructureAABB.php @@ -0,0 +1,18 @@ +intersectsWith($bb->minX, $bb->minZ, $bb->maxX, $bb->maxZ); + } + return $this->maxX >= $bb && $this->minX <= $maxX && $this->maxZ >= $minZ && $this->minZ <= $maxZ; + } + +} + diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 2bb035d0..7ced9e97 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -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{ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 910a4e0e..2bb6afce 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -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); diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index 836b0dbc..f259aa93 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -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); diff --git a/src/world/generator/cave/CaveGenerator.php b/src/world/generator/cave/CaveGenerator.php index 2f1219e4..38acbd7a 100644 --- a/src/world/generator/cave/CaveGenerator.php +++ b/src/world/generator/cave/CaveGenerator.php @@ -1,27 +1,7 @@ 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); diff --git a/src/world/generator/cave/MineshaftGenerator.php b/src/world/generator/cave/MineshaftGenerator.php new file mode 100644 index 00000000..1e198290 --- /dev/null +++ b/src/world/generator/cave/MineshaftGenerator.php @@ -0,0 +1,19 @@ +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); + } +} + diff --git a/src/world/generator/structure/StructureBase.php b/src/world/generator/structure/StructureBase.php new file mode 100644 index 00000000..7e8222c5 --- /dev/null +++ b/src/world/generator/structure/StructureBase.php @@ -0,0 +1,28 @@ +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){} +} + diff --git a/src/world/generator/structure/StructureComponent.php b/src/world/generator/structure/StructureComponent.php new file mode 100644 index 00000000..72806380 --- /dev/null +++ b/src/world/generator/structure/StructureComponent.php @@ -0,0 +1,301 @@ +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 + +} + diff --git a/src/world/generator/structure/StructureGenerator.php b/src/world/generator/structure/StructureGenerator.php new file mode 100644 index 00000000..71a7ca9e --- /dev/null +++ b/src/world/generator/structure/StructureGenerator.php @@ -0,0 +1,39 @@ +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); +} + diff --git a/src/world/generator/structure/StructureStart.php b/src/world/generator/structure/StructureStart.php new file mode 100644 index 00000000..36d3eb17 --- /dev/null +++ b/src/world/generator/structure/StructureStart.php @@ -0,0 +1,54 @@ +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; + } +} + diff --git a/src/world/generator/structure/mineshaft/StructureMineshaftPieces.php b/src/world/generator/structure/mineshaft/StructureMineshaftPieces.php new file mode 100644 index 00000000..ed004585 --- /dev/null +++ b/src/world/generator/structure/mineshaft/StructureMineshaftPieces.php @@ -0,0 +1,43 @@ +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; + } +} + diff --git a/src/world/generator/structure/mineshaft/StructureMineshaftStart.php b/src/world/generator/structure/mineshaft/StructureMineshaftStart.php new file mode 100644 index 00000000..f31a715b --- /dev/null +++ b/src/world/generator/structure/mineshaft/StructureMineshaftStart.php @@ -0,0 +1,13 @@ +components[] = $var5; + $var5->buildComponent($var5, $this->components, $random); + $this->updateBoundingBox(); + $this->markAvailableHeight($level, $random, 10); + } +} + diff --git a/src/world/generator/structure/mineshaft/component/ComponentMineshaftRoom.php b/src/world/generator/structure/mineshaft/component/ComponentMineshaftRoom.php new file mode 100644 index 00000000..4d67d413 --- /dev/null +++ b/src/world/generator/structure/mineshaft/component/ComponentMineshaftRoom.php @@ -0,0 +1,91 @@ +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; + } +} +