mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
parent
ba4d038972
commit
3d75094874
@ -117,7 +117,7 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled()){
|
||||
//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()){
|
||||
$explosion->explodeA();
|
||||
}
|
||||
|
@ -42,23 +42,23 @@ class EntityPreExplodeEvent extends EntityEvent implements Cancellable{
|
||||
|
||||
public function __construct(
|
||||
Entity $entity,
|
||||
protected float $force
|
||||
protected float $radius
|
||||
){
|
||||
if($force <= 0){
|
||||
if($radius <= 0){
|
||||
throw new \InvalidArgumentException("Explosion radius must be positive");
|
||||
}
|
||||
$this->entity = $entity;
|
||||
}
|
||||
|
||||
public function getForce() : float{
|
||||
return $this->force;
|
||||
public function getRadius() : float{
|
||||
return $this->radius;
|
||||
}
|
||||
|
||||
public function setForce(float $force) : void{
|
||||
if($force <= 0){
|
||||
public function setRadius(float $radius) : void{
|
||||
if($radius <= 0){
|
||||
throw new \InvalidArgumentException("Explosion radius must be positive");
|
||||
}
|
||||
$this->force = $force;
|
||||
$this->radius = $radius;
|
||||
}
|
||||
|
||||
public function isBlockBreaking() : bool{
|
||||
|
@ -58,7 +58,7 @@ class Explosion{
|
||||
|
||||
public function __construct(
|
||||
public Position $source,
|
||||
public float $size,
|
||||
public float $radius,
|
||||
private Entity|Block|null $what = null
|
||||
){
|
||||
if(!$this->source->isValid()){
|
||||
@ -66,8 +66,8 @@ class Explosion{
|
||||
}
|
||||
$this->world = $this->source->getWorld();
|
||||
|
||||
if($size <= 0){
|
||||
throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $size");
|
||||
if($radius <= 0){
|
||||
throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $radius");
|
||||
}
|
||||
$this->subChunkExplorer = new SubChunkExplorer($this->world);
|
||||
}
|
||||
@ -77,7 +77,7 @@ class Explosion{
|
||||
* will be destroyed.
|
||||
*/
|
||||
public function explodeA() : bool{
|
||||
if($this->size < 0.1){
|
||||
if($this->radius < 0.1){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ class Explosion{
|
||||
$pointerY = $this->source->y;
|
||||
$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;
|
||||
$y = (int) $pointerY;
|
||||
$z = (int) $pointerZ;
|
||||
@ -142,7 +142,7 @@ class Explosion{
|
||||
*/
|
||||
public function explodeB() : bool{
|
||||
$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){
|
||||
$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);
|
||||
$maxX = (int) ceil($this->source->x + $explosionSize + 1);
|
||||
$minY = (int) floor($this->source->y - $explosionSize - 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user