PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/misc/world/generator/object/tree/SmallTreeObject.php

https://github.com/domanicYL/PocketMine-MP
PHP | 79 lines | 47 code | 8 blank | 24 comment | 14 complexity | aa2c69495777181b8f8bf01d5fbdd663 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /*
  3. -
  4. / \
  5. / \
  6. / PocketMine \
  7. / MP \
  8. |\ @shoghicp /|
  9. |. \ / .|
  10. | .. \ / .. |
  11. | .. | .. |
  12. | .. | .. |
  13. \ | /
  14. \ | /
  15. \ | /
  16. \ | /
  17. This program is free software: you can redistribute it and/or modify
  18. it under the terms of the GNU Lesser General Public License as published by
  19. the Free Software Foundation, either version 3 of the License, or
  20. (at your option) any later version.
  21. */
  22. require_once("misc/world/generator/object/tree/TreeObject.php");
  23. class SmallTreeObject extends TreeObject{
  24. var $type = 0;
  25. private $totalHeight = 6;
  26. private $leavesHeight = 3;
  27. protected $radiusIncrease = 0;
  28. private $addLeavesVines = false;
  29. private $addLogVines = false;
  30. private $addCocoaPlants = false;
  31. public function canPlaceObject(LevelAPI $level, $x, $y, $z){
  32. $radiusToCheck = $this->radiusIncrease;
  33. for ($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
  34. if ($yy == 1 or $yy === $this->totalHeight - 1) {
  35. ++$radiusToCheck;
  36. }
  37. for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
  38. for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){
  39. $block = $level->getBlock($x + $xx, $y + $yy, $z + $zz);
  40. if(!isset($this->overridable[$block[0]])){
  41. return false;
  42. }
  43. }
  44. }
  45. }
  46. return true;
  47. }
  48. public function placeObject(LevelAPI $level, $x, $y, $z){
  49. $level->setBlock($x, $y - 1, $z, 3, 0);
  50. $this->totalHeight += mt_rand(-1, 3);
  51. $this->leavesHeight += mt_rand(0, 1);
  52. for($yy = ($this->totalHeight - $this->leavesHeight); $yy < ($this->totalHeight + 1); ++$yy){
  53. $yRadius = ($yy - $this->totalHeight);
  54. $xzRadius = (int) (($this->radiusIncrease + 1) - $yRadius / 2);
  55. for($xx = -$xzRadius; $xx < ($xzRadius + 1); ++$xx){
  56. for($zz = -$xzRadius; $zz < ($xzRadius + 1); ++$zz){
  57. if((abs($xx) != $xzRadius or abs($zz) != $xzRadius) and $yRadius != 0){
  58. $level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $this->type);
  59. }
  60. }
  61. }
  62. }
  63. for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
  64. $level->setBlock($x, $y + $yy, $z, 17, $this->type);
  65. }
  66. }
  67. }