PocketMine-MP 5.28.3 git-d5a1007c80fcee27feb2251cf5dcf1ad5a59a85c
Loading...
Searching...
No Matches
BlockPreExplodeEvent.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
22declare(strict_types=1);
23
25
28use pocketmine\event\CancellableTrait;
32
41
42 private bool $blockBreaking = true;
43
44 public function __construct(
45 Block $block,
46 private float $radius,
47 private readonly ?Player $player = null,
48 private float $fireChance = 0.0
49 ){
50 Utils::checkFloatNotInfOrNaN("radius", $radius);
51 if($radius <= 0){
52 throw new \InvalidArgumentException("Explosion radius must be positive");
53 }
54 Utils::checkFloatNotInfOrNaN("fireChance", $fireChance);
55 if($fireChance < 0.0 || $fireChance > 1.0){
56 throw new \InvalidArgumentException("Fire chance must be a number between 0 and 1.");
57 }
58 parent::__construct($block);
59 }
60
61 public function getRadius() : float{
62 return $this->radius;
63 }
64
65 public function setRadius(float $radius) : void{
66 Utils::checkFloatNotInfOrNaN("radius", $radius);
67 if($radius <= 0){
68 throw new \InvalidArgumentException("Explosion radius must be positive");
69 }
70 $this->radius = $radius;
71 }
72
73 public function isBlockBreaking() : bool{
74 return $this->blockBreaking;
75 }
76
77 public function setBlockBreaking(bool $affectsBlocks) : void{
78 $this->blockBreaking = $affectsBlocks;
79 }
80
84 public function isIncendiary() : bool{
85 return $this->fireChance > 0;
86 }
87
93 public function setIncendiary(bool $incendiary) : void{
94 if(!$incendiary){
95 $this->fireChance = 0;
96 }elseif($this->fireChance <= 0){
97 $this->fireChance = Explosion::DEFAULT_FIRE_CHANCE;
98 }
99 }
100
104 public function getFireChance() : float{
105 return $this->fireChance;
106 }
107
114 public function setFireChance(float $fireChance) : void{
115 Utils::checkFloatNotInfOrNaN("fireChance", $fireChance);
116 if($fireChance < 0.0 || $fireChance > 1.0){
117 throw new \InvalidArgumentException("Fire chance must be a number between 0 and 1.");
118 }
119 $this->fireChance = $fireChance;
120 }
121
126 public function getPlayer() : ?Player{
127 return $this->player;
128 }
129}