Standardize explosion radius terminology

closes #5061
This commit is contained in:
Dylan K. Taylor 2022-12-15 22:43:36 +00:00
parent ba4d038972
commit 3d75094874
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 15 additions and 15 deletions

View File

@ -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();
}

View File

@ -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{

View File

@ -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);