PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
object/Ore.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\level\generator\object;
23 
27 
28 class Ore{
29  private $random;
30  public $type;
31 
32  public function __construct(Random $random, OreType $type){
33  $this->type = $type;
34  $this->random = $random;
35  }
36 
37  public function getType(){
38  return $this->type;
39  }
40 
41  public function canPlaceObject(ChunkManager $level, $x, $y, $z){
42  return ($level->getBlockIdAt($x, $y, $z) === 1);
43  }
44 
45  public function placeObject(ChunkManager $level, $x, $y, $z){
46  $clusterSize = (int) $this->type->clusterSize;
47  $angle = $this->random->nextFloat() * M_PI;
48  $offset = VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8);
49  $x1 = $x + 8 + $offset->x;
50  $x2 = $x + 8 - $offset->x;
51  $z1 = $z + 8 + $offset->y;
52  $z2 = $z + 8 - $offset->y;
53  $y1 = $y + $this->random->nextRange(0, 3) + 2;
54  $y2 = $y + $this->random->nextRange(0, 3) + 2;
55  for($count = 0; $count <= $clusterSize; ++$count){
56  $seedX = $x1 + ($x2 - $x1) * $count / $clusterSize;
57  $seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
58  $seedZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
59  $size = ((sin($count * (M_PI / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
60 
61  $startX = (int) ($seedX - $size);
62  $startY = (int) ($seedY - $size);
63  $startZ = (int) ($seedZ - $size);
64  $endX = (int) ($seedX + $size);
65  $endY = (int) ($seedY + $size);
66  $endZ = (int) ($seedZ + $size);
67 
68  for($x = $startX; $x <= $endX; ++$x){
69  $sizeX = ($x + 0.5 - $seedX) / $size;
70  $sizeX **= 2;
71 
72  if($sizeX < 1){
73  for($y = $startY; $y <= $endY; ++$y){
74  $sizeY = ($y + 0.5 - $seedY) / $size;
75  $sizeY **= 2;
76 
77  if($y > 0 and ($sizeX + $sizeY) < 1){
78  for($z = $startZ; $z <= $endZ; ++$z){
79  $sizeZ = ($z + 0.5 - $seedZ) / $size;
80  $sizeZ **= 2;
81 
82  if(($sizeX + $sizeY + $sizeZ) < 1 and $level->getBlockIdAt($x, $y, $z) === 1){
83  $level->setBlockIdAt($x, $y, $z, $this->type->material->getId());
84  $level->setBlockDataAt($x, $y, $z, $this->type->material->getDamage());
85  }
86  }
87  }
88  }
89  }
90  }
91  }
92  }
93 
94 }
setBlockIdAt($x, $y, $z, $id)
setBlockDataAt($x, $y, $z, $data)