Structure.php now is not static

This commit is contained in:
ArkQuark 2023-03-03 19:43:08 +03:00
parent 1c606f3e5e
commit 546ca07d95
7 changed files with 155 additions and 176 deletions

View file

@ -1,10 +1,11 @@
<?php
class SmallFarmStructure{
public static $width = 7;
public static $lenght = 9;
public static $tmpStructure;
public static $structure = [
class SmallFarmStructure extends Structure{
public $width = 7;
public $lenght = 9;
public $name = "Small Farm";
private static $tmpStructure;
private static $structure = [
-1 => [
//add sand, clay if here isn't air
],
@ -20,11 +21,22 @@ class SmallFarmStructure{
"WWWWWWW",
]
];
private $map = [
"W" => "WoodBlock",
"F" => "FarmlandBlock",
"w" => "WaterBlock",
"H" => ["WheatBlock", 0],
"C" => ["CarrotBlock", 0],
"P" => ["PotatoBlock", 0],
"B" => ["BeetrootBlock", 0],
" " => "AirBlock"
];
public static function generateCrops(){
private function generateCrops(){
self::$tmpStructure = self::$structure;
$f = Utils::randomFloat();
if($f <= 0.5){
parent::setName("Wheat ".$this->name);
self::$tmpStructure[1] = [
"",
" HH HH ",
@ -38,6 +50,7 @@ class SmallFarmStructure{
];
}
elseif($f <= 0.7){
parent::setName("Carrot ".$this->name);
self::$tmpStructure[1] = [
"",
" CC CC ",
@ -51,6 +64,7 @@ class SmallFarmStructure{
];
}
elseif($f <= 0.9){
parent::setName("Potato ".$this->name);
self::$tmpStructure[1] = [
"",
" PP PP ",
@ -64,6 +78,7 @@ class SmallFarmStructure{
];
}
else{
parent::setName("Beetroot ".$this->name);
self::$tmpStructure[1] = [
"",
" BB BB ",
@ -78,53 +93,13 @@ class SmallFarmStructure{
}
}
public static function buildStructure($level, $x, $y, $z){ /*use CENTER positions*/
self::generateCrops();
public function __construct(){
parent::__construct($this->width, $this->lenght, $this->name, $this->map);
}
$offsetX = 0;
$offsetZ = 0;
foreach(self::$tmpStructure as $layerCount => $layer){
foreach($layer as $line){
$line = rtrim($line); //remove useless spaces(only from right)
foreach(str_split($line) as $char){
$vector = new Vector3($x - floor(self::$width / 2) + $offsetX, $y + $layerCount, $z + $offsetZ);
switch($char){
case "W":
$level->setBlockRaw($vector, new WoodBlock());
break;
case "F":
$level->setBlockRaw($vector, new FarmlandBlock());
break;
case "w":
$level->setBlockRaw($vector, new WaterBlock());
break;
case "H":
$level->setBlockRaw($vector, new WheatBlock());
break;
case "C":
$level->setBlockRaw($vector, new CarrotBlock());
break;
case "P":
$level->setBlockRaw($vector, new PotatoBlock());
break;
case "B":
$level->setBlockRaw($vector, new BeetrootBlock());
break;
case " ":
$block = $level->getBlock($vector)->getID();
if($block === AIR){
break;
}
$level->setBlockRaw($vector, new AirBlock());
break;
}
++$offsetX;
}
++$offsetZ;
$offsetX = 0;
}
$offsetZ = 0;
}
public function build($level, $x, $y, $z, $structure = 0){
$this->generateCrops();
parent::build($level, $x, $y, $z, self::$tmpStructure);
}
}