From 022664c402cd68419bba75f03730556774160706 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Thu, 2 Mar 2023 16:59:39 +0300 Subject: [PATCH] Added MonsterRoom Structure --- .../block/misc/NetherReactorBlock.php | 3 + .../block/solid/BurningFurnaceBlock.php | 3 +- src/material/block/solid/MyceliumBlock.php | 4 + src/structure/MonsterRoomStructure.php | 88 +++++++++++++++++++ .../NetherReactorStructure.php | 6 +- 5 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/structure/MonsterRoomStructure.php rename src/{world/generator/object => structure}/NetherReactorStructure.php (97%) diff --git a/src/material/block/misc/NetherReactorBlock.php b/src/material/block/misc/NetherReactorBlock.php index cfba8be1..587b3c93 100644 --- a/src/material/block/misc/NetherReactorBlock.php +++ b/src/material/block/misc/NetherReactorBlock.php @@ -80,6 +80,7 @@ class NetherReactorBlock extends SolidBlock{ } return $pigCount < 3 ? $pigCount < 2 ? 2 : 1 : 0; } + public function spawnItems($data) { $x = $this->x; $y = $this->y; @@ -116,6 +117,7 @@ class NetherReactorBlock extends SolidBlock{ $server->api->entity->spawnToAll($e); } } + public function glow($part){ $x = $this->x; $y = $this->y; @@ -182,6 +184,7 @@ class NetherReactorBlock extends SolidBlock{ break; } } + private function isCorrect($x, $y, $z){ $offsetX = -1; $offsetZ = -1; diff --git a/src/material/block/solid/BurningFurnaceBlock.php b/src/material/block/solid/BurningFurnaceBlock.php index 98f24ec6..7eea7777 100644 --- a/src/material/block/solid/BurningFurnaceBlock.php +++ b/src/material/block/solid/BurningFurnaceBlock.php @@ -18,16 +18,17 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{ $this->level->setBlock($block, $this, true, false, true); return true; } + public function getMaxLightValue(){ return 13; } + public function onBreak(Item $item, Player $player){ $this->level->setBlock($this, new AirBlock(), true, true, true); return true; } public function onActivate(Item $item, Player $player){ - $server = ServerAPI::request(); $t = $server->api->tile->get($this); $furnace = false; diff --git a/src/material/block/solid/MyceliumBlock.php b/src/material/block/solid/MyceliumBlock.php index 77c3d633..3740d54e 100644 --- a/src/material/block/solid/MyceliumBlock.php +++ b/src/material/block/solid/MyceliumBlock.php @@ -14,6 +14,10 @@ class MyceliumBlock extends SolidBlock{ return BLOCK_UPDATE_RANDOM; } + public function onActivate(Item $item, Player $player){ + //MonsterRoomStructure::buildStructure($this->level, $this->getX(), $this->getY(), $this->getZ()); + } + public function getDrops(Item $item, Player $player){ return array( array(DIRT, 0, 1), diff --git a/src/structure/MonsterRoomStructure.php b/src/structure/MonsterRoomStructure.php new file mode 100644 index 00000000..002a0825 --- /dev/null +++ b/src/structure/MonsterRoomStructure.php @@ -0,0 +1,88 @@ + [], 0 => [], 1 => [], 2 => [], 3 => [], 4 => []]; + return mt_rand(0, 1) === 1 ? self::$width = 7 : self::$width = 9; + } + + public static function generateFloor(){ + for($i = 0; $i < self::$width; $i++){ + $line = ""; + for($j = 0; $j < self::$width; $j++){ + $line .= Utils::chance(75) ? "M" : "C"; + } + array_push(self::$structure[-1], $line); + } + } + + public static function generateWalls(){ + for($wallsLevel = 0; $wallsLevel < 5; $wallsLevel++){ + for($i = 0; $i < self::$width; $i++){ + $line = ""; + if($i == 0 or ($i == self::$width - 1)){ + $line = str_repeat("C", self::$width); + } + else{ + $line = self::$width == 7 ? "C C" : "C C"; + } + if($wallsLevel == 0){ + self::generateChests(); + } + array_push(self::$structure[$wallsLevel], $line); + } + } + } + + public static function generateChests(){} + + public static function getSpawnerMob(){ + $rand = Utils::randomFloat(); + if($rand <= 0.5) return MOB_ZOMBIE; + elseif($rand <= 0.75) return MOB_SKELETON; + else return MOB_SPIDER; + } + + public static function buildStructure($level, $x, $y, $z){ /*use CENTER positions*/ + console("building!"); + self::getWidth(); + self::generateFloor(); + self::generateWalls(); + //console(var_dump(self::$structure)); + $offsetX = 0; + $offsetZ = 0; + foreach(self::$structure as $layerCount => $layer){ + foreach($layer as $line){ + $line = rtrim($line); //remove useless spaces(only from right) + foreach(str_split($line) as $char){ + switch($char){ + case "C": + $level->setBlockRaw(new Vector3($x - floor(self::$width / 2) + $offsetX, $y + $layerCount, $z - floor(self::$width / 2) + $offsetZ), new CobblestoneBlock()); + break; + case "M": + $level->setBlockRaw(new Vector3($x - floor(self::$width / 2) + $offsetX, $y + $layerCount, $z - floor(self::$width / 2) + $offsetZ), new MossStoneBlock()); + break; + case "H": + $level->setBlockRaw(new Vector3($x - floor(self::$width / 2) + $offsetX, $y + $layerCount, $z - floor(self::$width / 2) + $offsetZ), new ChestBlock()); + break; + case " ": + $block = $level->getBlock(new Vector3($x - floor(self::$width / 2) + $offsetX, $y + $layerCount, $z - floor(self::$width / 2) + $offsetZ))->getID(); + if($block == 0){ + break; + } + $level->setBlockRaw(new Vector3($x - floor(self::$width / 2) + $offsetX, $y + $layerCount, $z - floor(self::$width / 2) + $offsetZ), new AirBlock()); + break; + } + ++$offsetX; + } + ++$offsetZ; + $offsetX = 0; + } + $offsetZ = 0; + } + $level->setBlockRaw(new Vector3($x, $y, $z), new MonsterSpawnerBlock(self::getSpawnerMob())); + } +} \ No newline at end of file diff --git a/src/world/generator/object/NetherReactorStructure.php b/src/structure/NetherReactorStructure.php similarity index 97% rename from src/world/generator/object/NetherReactorStructure.php rename to src/structure/NetherReactorStructure.php index 30b0624d..c74e1886 100644 --- a/src/world/generator/object/NetherReactorStructure.php +++ b/src/structure/NetherReactorStructure.php @@ -601,14 +601,14 @@ class NetherReactorStructure{ foreach(str_split($line) as $char){ switch($char){ case "N": //Netherrack - $level->setBlockRaw(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ), new NetherrackBlock()); + $level->setBlockRaw(new Vector3($x - 8 + $offsetX, $y + $layerCount, $z - 8 + $offsetZ), new NetherrackBlock()); break; case " ": - $block = $level->getBlock(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ))->getID(); + $block = $level->getBlock(new Vector3($x - 8 + $offsetX, $y + $layerCount, $z - 8 + $offsetZ))->getID(); if($block == 0){ break; } - $level->setBlockRaw(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ), new AirBlock()); + $level->setBlockRaw(new Vector3($x - 8 + $offsetX, $y + $layerCount, $z - 8 + $offsetZ), new AirBlock()); break; } ++$offsetX;