mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 04:59:46 +00:00
Ore Generation
This commit is contained in:
parent
808f5473d0
commit
579175b3bc
12 changed files with 386 additions and 50 deletions
88
src/world/generator/object/OreObject.php
Normal file
88
src/world/generator/object/OreObject.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class OreObject{
|
||||
private $random;
|
||||
public $type;
|
||||
|
||||
public function __construct(Random $random, OreType $type){
|
||||
$this->type = $type;
|
||||
$this->random = $random;
|
||||
}
|
||||
|
||||
public function getType(){
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function canPlaceObject(Level $level, Vector3 $pos){
|
||||
return ($level->getBlock($pos)->getID() !== AIR);
|
||||
}
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos){
|
||||
$clusterSize = (int) $this->type->clusterSize;
|
||||
$angle = $this->random->nextFloat() * pi();
|
||||
$offset = VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8);
|
||||
$x1 = $pos->x + 8 + $offset->x;
|
||||
$x2 = $pos->x + 8 - $offset->x;
|
||||
$z1 = $pos->z + 8 + $offset->y;
|
||||
$z2 = $pos->z + 8 - $offset->y;
|
||||
$y1 = $pos->y + $this->random->nextRange(0, 3) + 2;
|
||||
$y2 = $pos->y + $this->random->nextRange(0, 3) + 2;
|
||||
for($count = 0; $count <= $clusterSize; ++$count){
|
||||
$seedX = $x1 + ($x2 - $x1) * $count / $clusterSize;
|
||||
$seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
|
||||
$seedZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
|
||||
$size = ((sin($count * (pi() / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
|
||||
|
||||
$startX = (int) ($seedX - $size);
|
||||
$startY = (int) ($seedY - $size);
|
||||
$startZ = (int) ($seedZ - $size);
|
||||
$endX = (int) ($seedX + $size);
|
||||
$endY = (int) ($seedY + $size);
|
||||
$endZ = (int) ($seedZ + $size);
|
||||
|
||||
for($x = $startX; $x <= $endX; ++$x){
|
||||
$sizeX = pow(($x + 0.5 - $seedX) / $size, 2);
|
||||
if($sizeX < 1){
|
||||
for($y = $startY; $y <= $endY; ++$y){
|
||||
$sizeY = pow(($y + 0.5 - $seedY) / $size, 2);
|
||||
if($y > 0 and ($sizeX + $sizeY) < 1){
|
||||
for($z = $startZ; $z <= $endZ; ++$z){
|
||||
$sizeZ = pow(($z + 0.5 - $seedZ) / $size, 2);
|
||||
$v = new Vector3($x, $y, $z);
|
||||
if(($sizeX + $sizeY + $sizeZ) < 1 and $level->getBlock($v)->getID() === STONE){
|
||||
$level->setBlockRaw($v, $this->type->material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
38
src/world/generator/object/OreType.php
Normal file
38
src/world/generator/object/OreType.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class OreType{
|
||||
public $material, $clusterCount, $clusterSize, $maxHeight, $minHeight;
|
||||
|
||||
public function __construct(Block $material, $clusterCount, $clusterSize, $minHeight, $maxHeight){
|
||||
$this->material = $material;
|
||||
$this->clusterCount = (int) $clusterCount;
|
||||
$this->clusterSize = (int) $clusterSize;
|
||||
$this->maxHeight = (int) $maxHeight;
|
||||
$this->minHeight = (int) $minHeight;
|
||||
}
|
||||
}
|
||||
43
src/world/generator/object/PondObject.php
Normal file
43
src/world/generator/object/PondObject.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class PondObject{
|
||||
private $random;
|
||||
public $type;
|
||||
|
||||
public function __construct(Random $random, Block $type){
|
||||
$this->type = $type;
|
||||
$this->random = $random;
|
||||
}
|
||||
|
||||
public function canPlaceObject(Level $level, Vector3 $pos){
|
||||
}
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos){
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ the Free Software Foundation, either version 3 of the License, or
|
|||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once("src/world/generator/object/tree/TreeObject.php");
|
||||
require_once("TreeObject.php");
|
||||
/***REM_END***/
|
||||
|
||||
class SmallTreeObject extends TreeObject{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue