PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/pocketmine/item/FlintSteel.php

https://gitlab.com/Skull3x/GladiatorMine
PHP | 149 lines | 110 code | 12 blank | 27 comment | 37 complexity | 1e919e6569c25bc8e77754453a0d0f9c MD5 | raw file
  1. <?php
  2. /*
  3. *
  4. * ____ _ _ __ __ _ __ __ ____
  5. * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
  6. * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
  7. * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
  8. * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * @author PocketMine Team
  16. * @link http://www.pocketmine.net/
  17. *
  18. *
  19. */
  20. namespace pocketmine\item;
  21. use pocketmine\block\Block;
  22. use pocketmine\block\Fire;
  23. use pocketmine\block\Solid;
  24. use pocketmine\level\Level;
  25. use pocketmine\Player;
  26. use pocketmine\math\Vector3;
  27. class FlintSteel extends Tool{
  28. public function __construct($meta = 0, $count = 1){
  29. parent::__construct(self::FLINT_STEEL, $meta, $count, "Flint and Steel");
  30. }
  31. public function canBeActivated() : bool{
  32. return true;
  33. }
  34. public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
  35. if($target->getId() === 49 and $player->getServer()->netherEnabled){//黑曜石 4*5最小 23*23最大
  36. //$level->setBlock($block, new Fire(), true);
  37. $tx = $target->getX();
  38. $ty = $target->getY();
  39. $tz = $target->getZ();
  40. //x方向
  41. $x_max = $tx;//x最大值
  42. $x_min = $tx;//x最小值
  43. $count_x = 0;//x方向方块
  44. for($x = $tx + 1; $level->getBlock(new Vector3($x, $ty, $tz))->getId() == 49; $x++){
  45. $x_max++;
  46. }
  47. for($x = $tx - 1; $level->getBlock(new Vector3($x, $ty, $tz))->getId() == 49; $x--){
  48. $x_min--;
  49. }
  50. $count_x = $x_max - $x_min + 1;
  51. if($count_x >= 4 and $count_x <= 23){//4 23
  52. $x_max_y = $ty;//x最大值时的y最大值
  53. $x_min_y = $ty;//x最小值时的y最大值
  54. for($y = $ty; $level->getBlock(new Vector3($x_max, $y, $tz))->getId() == 49; $y++){
  55. $x_max_y++;
  56. }
  57. for($y = $ty; $level->getBlock(new Vector3($x_min, $y, $tz))->getId() == 49; $y++){
  58. $x_min_y++;
  59. }
  60. $y_max = min($x_max_y, $x_min_y) - 1;//y最大值
  61. $count_y = $y_max - $ty + 2;//方向方块
  62. //Server::getInstance()->broadcastMessage("$y_max $x_max_y $x_min_y $x_max $x_min");
  63. if($count_y >= 5 and $count_y <= 23){//5 23
  64. $count_up = 0;//上面
  65. for($ux = $x_min; ($level->getBlock(new Vector3($ux, $y_max, $tz))->getId() == 49 and $ux <= $x_max); $ux++){
  66. $count_up++;
  67. }
  68. //Server::getInstance()->broadcastMessage("$count_up $count_x");
  69. if($count_up == $count_x){
  70. for($px = $x_min + 1; $px < $x_max; $px++){
  71. for($py = $ty + 1; $py < $y_max; $py++){
  72. $level->setBlock(new Vector3($px, $py, $tz), new Block(90, 0));
  73. }
  74. }
  75. }
  76. }
  77. }
  78. //z方向
  79. $z_max = $tz;//z最大值
  80. $z_min = $tz;//z最小值
  81. $count_z = 0;//z方向方块
  82. for($z = $tz + 1; $level->getBlock(new Vector3($tx, $ty, $z))->getId() == 49; $z++){
  83. $z_max++;
  84. }
  85. for($z = $tz - 1; $level->getBlock(new Vector3($tx, $ty, $z))->getId() == 49; $z--){
  86. $z_min--;
  87. }
  88. $count_z = $z_max - $z_min + 1;
  89. if($count_z >= 4 and $count_z <= 23){//4 23
  90. $z_max_y = $ty;//z最大值时的y最大值
  91. $z_min_y = $ty;//z最小值时的y最大值
  92. for($y = $ty; $level->getBlock(new Vector3($tx, $y, $z_max))->getId() == 49; $y++){
  93. $z_max_y++;
  94. }
  95. for($y = $ty; $level->getBlock(new Vector3($tx, $y, $z_min))->getId() == 49; $y++){
  96. $z_min_y++;
  97. }
  98. $y_max = min($z_max_y, $z_min_y) - 1;//y最大值
  99. $count_y = $y_max - $ty + 2;//方向方块
  100. if($count_y >= 5 and $count_y <= 23){//5 23
  101. $count_up = 0;//上面
  102. for($uz = $z_min; ($level->getBlock(new Vector3($tx, $y_max, $uz))->getId() == 49 and $uz <= $z_max); $uz++){
  103. $count_up++;
  104. }
  105. //Server::getInstance()->broadcastMessage("$count_up $count_z");
  106. if($count_up == $count_z){
  107. for($pz = $z_min + 1; $pz < $z_max; $pz++){
  108. for($py = $ty + 1; $py < $y_max; $py++){
  109. $level->setBlock(new Vector3($tx, $py, $pz), new Block(90, 0));
  110. }
  111. }
  112. }
  113. }
  114. }
  115. //return true;
  116. }
  117. if($block->getId() === self::AIR and ($target instanceof Solid)){
  118. $level->setBlock($block, new Fire(), true);
  119. /** @var Fire $block */
  120. $block = $level->getBlock($block);
  121. if($block->isBlockTopFacingSurfaceSolid($block->getSide(Vector3::SIDE_DOWN)) or $block->canNeighborBurn()){
  122. $level->scheduleUpdate($block, $block->getTickRate() + mt_rand(0, 10));
  123. // return true;
  124. }
  125. if(($player->gamemode & 0x01) === 0 and $this->useOn($block)){
  126. if($this->getDamage() >= $this->getMaxDurability()){
  127. $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));
  128. }else{
  129. $this->meta++;
  130. $player->getInventory()->setItemInHand($this);
  131. }
  132. }
  133. return true;
  134. }
  135. return false;
  136. }
  137. }