mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 17:20:02 +00:00
parent
ba4d038972
commit
3d75094874
@ -117,7 +117,7 @@ class PrimedTNT extends Entity implements Explosive{
|
|||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
//TODO: deal with underwater TNT (underwater TNT treats water as if it has a blast resistance of 0)
|
//TODO: deal with underwater TNT (underwater TNT treats water as if it has a blast resistance of 0)
|
||||||
$explosion = new Explosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->getWorld()), $ev->getForce(), $this);
|
$explosion = new Explosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->getWorld()), $ev->getRadius(), $this);
|
||||||
if($ev->isBlockBreaking()){
|
if($ev->isBlockBreaking()){
|
||||||
$explosion->explodeA();
|
$explosion->explodeA();
|
||||||
}
|
}
|
||||||
|
@ -42,23 +42,23 @@ class EntityPreExplodeEvent extends EntityEvent implements Cancellable{
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Entity $entity,
|
Entity $entity,
|
||||||
protected float $force
|
protected float $radius
|
||||||
){
|
){
|
||||||
if($force <= 0){
|
if($radius <= 0){
|
||||||
throw new \InvalidArgumentException("Explosion radius must be positive");
|
throw new \InvalidArgumentException("Explosion radius must be positive");
|
||||||
}
|
}
|
||||||
$this->entity = $entity;
|
$this->entity = $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getForce() : float{
|
public function getRadius() : float{
|
||||||
return $this->force;
|
return $this->radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setForce(float $force) : void{
|
public function setRadius(float $radius) : void{
|
||||||
if($force <= 0){
|
if($radius <= 0){
|
||||||
throw new \InvalidArgumentException("Explosion radius must be positive");
|
throw new \InvalidArgumentException("Explosion radius must be positive");
|
||||||
}
|
}
|
||||||
$this->force = $force;
|
$this->radius = $radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isBlockBreaking() : bool{
|
public function isBlockBreaking() : bool{
|
||||||
|
@ -58,7 +58,7 @@ class Explosion{
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public Position $source,
|
public Position $source,
|
||||||
public float $size,
|
public float $radius,
|
||||||
private Entity|Block|null $what = null
|
private Entity|Block|null $what = null
|
||||||
){
|
){
|
||||||
if(!$this->source->isValid()){
|
if(!$this->source->isValid()){
|
||||||
@ -66,8 +66,8 @@ class Explosion{
|
|||||||
}
|
}
|
||||||
$this->world = $this->source->getWorld();
|
$this->world = $this->source->getWorld();
|
||||||
|
|
||||||
if($size <= 0){
|
if($radius <= 0){
|
||||||
throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $size");
|
throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $radius");
|
||||||
}
|
}
|
||||||
$this->subChunkExplorer = new SubChunkExplorer($this->world);
|
$this->subChunkExplorer = new SubChunkExplorer($this->world);
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ class Explosion{
|
|||||||
* will be destroyed.
|
* will be destroyed.
|
||||||
*/
|
*/
|
||||||
public function explodeA() : bool{
|
public function explodeA() : bool{
|
||||||
if($this->size < 0.1){
|
if($this->radius < 0.1){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ class Explosion{
|
|||||||
$pointerY = $this->source->y;
|
$pointerY = $this->source->y;
|
||||||
$pointerZ = $this->source->z;
|
$pointerZ = $this->source->z;
|
||||||
|
|
||||||
for($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
|
for($blastForce = $this->radius * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
|
||||||
$x = (int) $pointerX;
|
$x = (int) $pointerX;
|
||||||
$y = (int) $pointerY;
|
$y = (int) $pointerY;
|
||||||
$z = (int) $pointerZ;
|
$z = (int) $pointerZ;
|
||||||
@ -142,7 +142,7 @@ class Explosion{
|
|||||||
*/
|
*/
|
||||||
public function explodeB() : bool{
|
public function explodeB() : bool{
|
||||||
$source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
|
$source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
|
||||||
$yield = min(100, (1 / $this->size) * 100);
|
$yield = min(100, (1 / $this->radius) * 100);
|
||||||
|
|
||||||
if($this->what instanceof Entity){
|
if($this->what instanceof Entity){
|
||||||
$ev = new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield);
|
$ev = new EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield);
|
||||||
@ -155,7 +155,7 @@ class Explosion{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$explosionSize = $this->size * 2;
|
$explosionSize = $this->radius * 2;
|
||||||
$minX = (int) floor($this->source->x - $explosionSize - 1);
|
$minX = (int) floor($this->source->x - $explosionSize - 1);
|
||||||
$maxX = (int) ceil($this->source->x + $explosionSize + 1);
|
$maxX = (int) ceil($this->source->x + $explosionSize + 1);
|
||||||
$minY = (int) floor($this->source->y - $explosionSize - 1);
|
$minY = (int) floor($this->source->y - $explosionSize - 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user