GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
CaveCommand Class Reference

Public Member Functions

 __construct ($name)
 
 execute (CommandSender $sender, $commandLabel, array $args)
 
 chu ($v1, $v2)
 
 getDirectionVector ($yaw, $pitch)
 
 caves (Position $pos, $cave, $tt=false)
 
 lavaSpawn (Level $level, $x, $y, $z)
 
 explodeBlocks (Position $source, $rays=16, $size=4)
 
 fdx ($x, $y, $z, Level $level, $liu=false)
 
 ranz ($a)
 
 tiankengy (Level $level, $x, $y, $z, $l, $id, $bd)
 
- Public Member Functions inherited from VanillaCommand
 __construct ($name, $description="", $usageMessage=null, array $aliases=[])
 
- Public Member Functions inherited from Command
 __construct ($name, $description="", $usageMessage=null, array $aliases=[])
 
 getDefaultCommandData ()
 
 generateCustomCommandData (Player $player)
 
 getOverloads ()
 
 execute (CommandSender $sender, $commandLabel, array $args)
 
 getName ()
 
 getPermission ()
 
 setPermission ($permission)
 
 testPermission (CommandSender $target)
 
 testPermissionSilent (CommandSender $target)
 
 getLabel ()
 
 setLabel ($name)
 
 register (CommandMap $commandMap)
 
 unregister (CommandMap $commandMap)
 
 isRegistered ()
 
 getAliases ()
 
 getPermissionMessage ()
 
 getDescription ()
 
 getUsage ()
 
 setAliases (array $aliases)
 
 setDescription ($description)
 
 setPermissionMessage ($permissionMessage)
 
 setUsage ($usage)
 
 __toString ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Command
static generateDefaultData ()
 
static broadcastCommandMessage (CommandSender $source, $message, $sendToSource=true)
 
- Data Fields inherited from VanillaCommand
const MAX_COORD = 30000000
 
const MIN_COORD = -30000000
 
- Data Fields inherited from Command
 $timings
 
- Protected Member Functions inherited from VanillaCommand
 getInteger (CommandSender $sender, $value, $min=self::MIN_COORD, $max=self::MAX_COORD)
 
 getRelativeDouble ($original, CommandSender $sender, $input, $min=self::MIN_COORD, $max=self::MAX_COORD)
 
 getDouble (CommandSender $sender, $value, $min=self::MIN_COORD, $max=self::MAX_COORD)
 
- Protected Attributes inherited from Command
 $commandData = null
 
 $description = ""
 
 $usageMessage
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name)

CaveCommand constructor.

Parameters
$name
47  {
48  parent::__construct(
49  $name,
50  "Generate a cave",
51  "%pocketmine.commands.cave.usage"
52  );
53  $this->setPermission("pocketmine.command.cave");
54  }

Member Function Documentation

◆ caves()

caves ( Position  $pos,
  $cave,
  $tt = false 
)
Parameters
Position$pos
$cave
bool$tt
140  {
141  $x = $pos->x;
142  $y = $pos->y;
143  $z = $pos->z;
144  $level = $pos->getLevel();
145  $ls = $cave[1]; //长度
146  $cv = $cave[2]; //分叉数
147  $lofs = $ls / $cave[2];
148  $ls2 = $lofs;
149  $yaw = $cave[0];
150  if($cave[0] >= 0 || $cave[0] < 0){
151  }else{
152  $yaw = mt_rand(0, 100) * 72;
153  }
154  $pitch = -45;
155  //$pi = M_PI / 180;
156  $s1 = [$x, $y, $z];
157  $s2 = [$x, $y, $z];
158  //$i = -10 + mt_rand(0, 100) * 0.2;
159  //$i = mt_rand(8, 25) / 10;
160  $i = 1;
161  for($u = 0; $u <= $ls; $u += $i){
162  if($pitch > 12) $pitch = -45;
163  $pitch += 5 + mt_rand(0, 5);
164  $pos->getLevel()->getServer()->getLogger()->debug("[Caves] " . TextFormat::YELLOW . "yaw: $yaw pitch: $pitch");
165  if($tt) $pitch = mt_rand(0, 100) * 0.05;
166  //$s2[0] = $s1[0] -\sin($yaw / 180 * M_PI) * \cos($pitch / 180 * M_PI) * $i;
167  //$s2[1] = $s1[1] +\sin($pitch / 180 * M_PI) * $i;
168  //$s2[2] = $s1[2] + \cos($yaw / 180 * M_PI) * \cos($pitch / 180 * M_PI) * $i;
169 
170  #echo "s1: ";
171  //var_dump($s1);
172  $see = $this->getDirectionVector($yaw, $pitch);
173  $s2[0] = $s1[0] + $see->x * $i;
174  $s2[1] = $s1[1] - $see->y * $i;
175  $s2[2] = $s1[2] + $see->z * $i;
176  //echo "s2: ";
177  //var_dump($s2);
178  if($s2[1] < 10){
179  $s2[1] = 10 + mt_rand(0, 10);
180  }
181  if($u > $lofs){
182  $cv--;
183  if($cave[3][1] === false) $cv = 0;
184  $lofs += $ls2;
185  $newPos = new Position($s2[0], $s2[1], $s2[2], $level);
186  $this->caves($newPos, [$yaw + 90 * (round(mt_rand(0, 100) / 100) * 2 - 1), $ls - $u, $cv, [false, $cave[3][1], $cave[3][2]], 0], $tt);
187  }
188 
189  //$exPos = new Position($s2[0], $s2[1], $s2[2], $level);
190  //$this->explodeBlocks($exPos, mt_rand(2, 4), mt_rand(1, 4));
191 
192  if(mt_rand(0, 100) > 80){
193  $add = mt_rand(-10, 10);
194  }else{
195  $add = mt_rand(-45, 45);
196  }
197  $yaw = $yaw + $add;
198  $yaw = $yaw % 360;
199  $yaw = $yaw >= 0 ? $yaw : 360 + $yaw;
200 
201  //$i = 5 + mt_rand(0, 100) * 0.05;
202  $x = $s1[0];
203  $y = $s1[1];
204  $z = $s1[2];
205  $x2 = $s2[0];
206  $y2 = $s2[1];
207  $z2 = $s2[2];
208  $l = max(abs($x - $x2), abs($y - $y2), abs($z - $z2));
209  for($m = 0; $m <= $l; $m++){
210  //$v = $level->getBlock(new Vector3(round($this->chu($x + $m, $l * ($x2 - $x))), round($y + $this->chu($m, $l * ($y2 - $y))), round($z + $this->chu($m, $l * ($z2 - $z)))))->getId();
211  //if ($v != 0 and $v != 95)
212  $liu = mt_rand(0, 200) == 100;
213  $this->fdx(round($x + $this->chu($m, $l * ($x2 - $x))), round($y + $this->chu($m, $l * ($y2 - $y))), round($z + $this->chu($m, $l * ($z2 - $z))), $level, $liu);
214  }
215  $s1 = [$s2[0], $s2[1], $s2[2]];
216  }
217  if(mt_rand(0, 10) >= 5 and $s2[1] <= 40){
218  $this->lavaSpawn($level, $s2[0], $s2[1], $s2[2]);
219  }
220  /*
221  if ($cave[3][0]) {
222  $l = $cave[4];
223  $x = $s2[0];
224  $y = $s2[1];
225  $z = $s2[2];
226  for ($i = -$l; $i <= $l; $i += 2) {
227  for ($j = -$l; $j <= $l; $j += 2) {
228  if ($i * $i + $j * $j <= pow($l - 0.3 * $l * mt_rand(0, 1000) / 1000, 2)) {
229  if ($level->getBlock(new Vector3($x + $i, $y - 1, $z + $j))->getId() != 0) {
230  $this->fdx($x + $i, $y - 1 + 2 * mt_rand(0, 1000) / 1000, $z + $j, $level);
231  }
232  }
233  if ($i * $i + $j * $j <= pow($l - 0.5 * $l * mt_rand(0, 1000) / 1000, 2)) {
234  if ($level->getBlock(new Vector3($x + $i, $y + 3, $z + $j))->getId() != 0) {
235  $this->fdx($x + $i, $y + 3 + 2 * mt_rand(0, 1000) / 1000, $z + $j, $level);
236  }
237  }
238  }
239  }
240 
241  //if ($level->getBlock(new Vector3($s2[0], $s2[1] - 4, $s2[2]))->getId() != 0 && $cave[3][2] && mt_rand(0, 100) / 100 > 0.5) $this->tiankengy($level, $s2[0], $s2[1], $s2[2], $l * 0.6, 11, 0);
242  } else if ($cave[3][2]) {
243  $l = $cave[4];
244  if ($pitch < -10 && $pitch > -45 && $level->getBlock(new Vector3($s2[0], $s2[1] - 3, $s2[2]))->getId() != 0) $this->tiankengy($level, $s2[0], $s2[1], $s2[2], $l / 2, 11, 0);
245  }*/
246  //echo "\n 矿洞生成完成\n";
247 
248  }

◆ chu()

chu (   $v1,
  $v2 
)
Parameters
$v1
$v2
Returns
float|int
114  {
115  if($v2 == 0) return 0;
116  return $v1 / $v2;
117  }

◆ execute()

execute ( CommandSender  $sender,
  $commandLabel,
array  $args 
)
Parameters
CommandSender$sender
string$commandLabel
array$args
Returns
bool
63  {
64  if(!$this->testPermission($sender)){
65  return true;
66  }
67 
68  if(!$sender instanceof Player){
69  $sender->sendMessage(TextFormat::RED . "Please run this command in-game!");
70  return true;
71  }
72 
73  if($args[0] == "getmypos"){
74  $sender->sendMessage("Your position: ({$sender->getX()}, {$sender->getY()}, {$sender->getZ()}, {$sender->getLevel()->getFolderName()})");
75  return true;
76  }
77 
78  //0:旋转角度 1:洞穴长度 2:分叉数 3:洞穴强度
79  if(count($args) > 8){
80  $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
81 
82  return false;
83  }
84  //是否自动获取玩家位置
85  $level = isset($args[7]) ? $sender->getServer()->getLevelByName($args[7]) : $sender->getLevel();
86  if(!$level instanceof Level){
87  $sender->sendMessage(TextFormat::RED . "Wrong LevelName");
88  return false;
89  }
90  $x = isset($args[4]) ? $args[4] : $sender->getX();
91  $y = isset($args[5]) ? $args[5] : $sender->getY();
92  $z = isset($args[6]) ? $args[6] : $sender->getZ();
93 
94  $pos = new Position($x, $y, $z, $level);
95  $caves[0] = isset($args[0]) ? $args[0] : mt_rand(1, 360);
96  $caves[1] = isset($args[1]) ? $args[1] : mt_rand(10, 300);
97  $caves[2] = isset($args[2]) ? $args[2] : mt_rand(1, 6);
98  $caves[4] = isset($args[3]) ? $args[3] : mt_rand(1, 10);
99  $caves[3] = [false, true, true];
100  $sender->sendMessage(new TranslationContainer("pocketmine.commands.cave.info", [$caves[0], $caves[1], $caves[2], $caves[4]]));
101  $sender->sendMessage(new TranslationContainer(TextFormat::YELLOW . "%pocketmine.commands.cave.start"));
102  $sender->sendMessage($pos->x . " " . $pos->y . " " . $pos->z);
103  $this->caves($pos, $caves);
104  $sender->sendMessage(new TranslationContainer(TextFormat::GREEN . "%pocketmine.commands.cave.success"));
105  return true;
106  }

◆ explodeBlocks()

explodeBlocks ( Position  $source,
  $rays = 16,
  $size = 4 
)
Parameters
Position$source
int$rays
int$size
277  {
278  $vector = new Vector3(0, 0, 0);
279  $vBlock = new Vector3(0, 0, 0);
280  $stepLen = 0.3;
281  $mRays = \intval($rays - 1);
282  $affectedBlocks = [];
283  for($i = 0; $i < $rays; ++$i){
284  for($j = 0; $j < $rays; ++$j){
285  for($k = 0; $k < $rays; ++$k){
286  if($i === 0 or $i === $mRays or $j === 0 or $j === $mRays or $k === 0 or $k === $mRays){
287  $vector->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1);
288  $vector->setComponents(($vector->x / ($len = $vector->length())) * $stepLen, ($vector->y / $len) * $stepLen, ($vector->z / $len) * $stepLen);
289  $pointerX = $source->x;
290  $pointerY = $source->y;
291  $pointerZ = $source->z;
292 
293  for($blastForce = $size * (\mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $stepLen * 0.75){
294  $x = (int) $pointerX;
295  $y = (int) $pointerY;
296  $z = (int) $pointerZ;
297  $vBlock->x = $pointerX >= $x ? $x : $x - 1;
298  $vBlock->y = $pointerY >= $y ? $y : $y - 1;
299  $vBlock->z = $pointerZ >= $z ? $z : $z - 1;
300  if($vBlock->y < 0 or $vBlock->y > 127){
301  break;
302  }
303  $block = $source->getLevel()->getBlock($vBlock);
304 
305  if($block->getId() !== 0){
306  $blastForce -= (mt_rand(1, 3) / 5 + 0.3) * $stepLen;
307  if($blastForce > 0){
308  if(!isset($affectedBlocks[$index = (\PHP_INT_SIZE === 8 ? ((($block->x) & 0xFFFFFFF) << 35) | ((($block->y) & 0x7f) << 28) | (($block->z) & 0xFFFFFFF) : ($block->x) . ":" . ($block->y) . ":" . ($block->z))])){
309  $affectedBlocks[$index] = $block;
310  }
311  }
312  }
313  $pointerX += $vector->x;
314  $pointerY += $vector->y;
315  $pointerZ += $vector->z;
316  }
317  }
318  }
319  }
320  }
321  foreach($affectedBlocks as $block){
322  if($block instanceof Block){
323  $block->getLevel()->setBlock($block, new Air(), false, false);
324  }
325  }
326  }

◆ fdx()

fdx (   $x,
  $y,
  $z,
Level  $level,
  $liu = false 
)
Parameters
$x
$y
$z
Level$level
bool$liu
335  {
336  //$this->getLogger()->info(TextFormat::GREEN."fdx!");
337  for($i = 1; $i < mt_rand(2, 4); $i++){
338  $level->setBlockIdAt($x + $i - 2, $y - 1, $z + 1, 0);
339  $level->setBlockIdAt($x + $i - 2, $y - 1, $z, 0);
340  $level->setBlockIdAt($x + $i - 2, $y - 1, $z - 1, 0);
341  $level->setBlockIdAt($x + $i - 2, $y - 1, $z - 1, 0);
342  $level->setBlockIdAt($x + $i - 2, $y - 1, $z + 1, 0);
343  $level->setBlockIdAt($x + $i - 2, $y + 2, $z + 1, 0);
344  $level->setBlockIdAt($x + $i - 2, $y + 2, $z, 0);
345  $level->setBlockIdAt($x + $i - 2, $y + 2, $z - 1, 0);
346  }
347  for($i = 1; $i < mt_rand(3, 6); $i++){
348  $level->setBlockIdAt($x + $i - 3, $y + 1, $z + 2, 0);
349  $level->setBlockIdAt($x + $i - 3, $y + 1, $z + 1, 0);
350  $level->setBlockIdAt($x + $i - 3, $y + 1, $z, 0);
351  $level->setBlockIdAt($x + $i - 3, $y + 1, $z - 1, 0);
352  $level->setBlockIdAt($x + $i - 3, $y + 1, $z - 2, 0);
353  $level->setBlockIdAt($x + $i - 3, $y, $z + 2, 0);
354  $level->setBlockIdAt($x + $i - 3, $y, $z + 1, 0);
355  $level->setBlockIdAt($x + $i - 3, $y, $z, 0);
356  $level->setBlockIdAt($x + $i - 3, $y, $z - 1, 0);
357  $level->setBlockIdAt($x + $i - 3, $y, $z - 2, 0);
358  }
359  if($liu){
360  $l = (mt_rand(0, 1) == 0) ? new Water() : new Lava();
361  $i = mt_rand(3, 6);
362  $level->setBlock(new Vector3($x + $i - 3, $y + 1, $z + 3), $l);
363  }
364  }

◆ getDirectionVector()

getDirectionVector (   $yaw,
  $pitch 
)
Parameters
$yaw
$pitch
Returns
Vector3
125  {
126  $y = -\sin(\deg2rad($pitch));
127  $xz = \cos(\deg2rad($pitch));
128  $x = -$xz * \sin(\deg2rad($yaw));
129  $z = $xz * \cos(\deg2rad($yaw));
130 
131  $temporalVector = new Vector3($x, $y, $z);
132  return $temporalVector->normalize();
133  }

◆ lavaSpawn()

lavaSpawn ( Level  $level,
  $x,
  $y,
  $z 
)
Parameters
Level$level
$x
$y
$z
256  {
257  $level->getServer()->getLogger()->info("生成岩浆中 " . "floor($x)" . ", " . "floor($y)" . ", " . floor($z));
258  for($xx = $x - 20; $xx <= $x + 20; $xx++){
259  for($zz = $z - 20; $zz <= $z + 20; $zz++){
260  for($yy = $y; $yy > $y - 4; $yy--){
261  $id = $level->getBlockIdAt($xx, $yy, $zz);
262  if($id == 0){
263  $level->setBlockIdAt($xx, $yy, $zz, 10);
264  $level->setBlockDataAt($xx, $yy, $zz, 0);
265  }
266  }
267  }
268  }
269  $level->setBlock(new Vector3($x, $y, $z), new Lava());
270  }

◆ ranz()

ranz (   $a)
Parameters
$a
Returns
array
371  {
372  $n = [];
373  $j = 0;
374  for($m = 0; $m < $a; $m++){
375  $n[] = mt_rand(0, 999) / 1000 - 1;
376  }
377 
378  for($m = 0; $m < $a; $m++){
379  foreach($n as $q){
380  $min = min($n);
381  if($n[$q] == $min){
382  $n[$q] = $j;
383  $j++;
384  break;
385  }
386  }
387  }
388  return $n;
389  }

◆ tiankengy()

tiankengy ( Level  $level,
  $x,
  $y,
  $z,
  $l,
  $id,
  $bd 
)
Parameters
Level$level
$x
$y
$z
$l
$id
$bd
400  {
401  if($level->getBlock(new Vector3($x, $y, $z))->getId() == 0) $level->setBlock(new Vector3($x, $y, $z), Item::get($id, $bd)->getBlock());
402  if($l >= 0){
403  $random = mt_rand(0, 99999) / 100000;
404  $mz = $this->ranz(4);
405  foreach($mz as $sss){
406  switch($mz[$sss]){
407  case 0:
408  if($level->getBlock(new Vector3($x, $y, $z - 1))->getId() == 0) $this->tiankengy($level, $x, $y, $z - 1, $l - $random, $id, $bd);
409  break;
410  case 1:
411  if($level->getBlock(new Vector3($x, $y, $z + 1))->getId() == 0) $this->tiankengy($level, $x, $y, $z + 1, $l - $random, $id, $bd);
412  break;
413  case 2:
414  if($level->getBlock(new Vector3($x + 1, $y, $z))->getId() == 0) $this->tiankengy($level, $x + 1, $y, $z, $l - $random, $id, $bd);
415  break;
416  case 3:
417  if($level->getBlock(new Vector3($x - 1, $y, $z))->getId() == 0) $this->tiankengy($level, $x - 1, $y, $z, $l - $random, $id, $bd);
418  break;
419  }
420  }
421  }
422  }

The documentation for this class was generated from the following file: