Added MonsterRoom Structure

This commit is contained in:
ArkQuark 2023-03-02 16:59:39 +03:00
parent 762ff1b3eb
commit 022664c402
5 changed files with 100 additions and 4 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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),

View file

@ -0,0 +1,88 @@
<?php
class MonsterRoomStructure{
public static $width = -1;
public static $structure = [];
public static function getWidth(){
self::$structure = [-1 => [], 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()));
}
}

View file

@ -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;