mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
explosion tweaks
This commit is contained in:
parent
a82b271b2f
commit
2a3b36f509
2 changed files with 39 additions and 32 deletions
|
|
@ -19,7 +19,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class PlayerNull extends Player{
|
||||||
|
public function __construct(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
class Player{
|
class Player{
|
||||||
private $server;
|
private $server;
|
||||||
private $recoveryQueue = array();
|
private $recoveryQueue = array();
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,35 @@ class Explosion{
|
||||||
public $size;
|
public $size;
|
||||||
public $affectedBlocks = array();
|
public $affectedBlocks = array();
|
||||||
public $stepLen = 0.3;
|
public $stepLen = 0.3;
|
||||||
|
private $air;
|
||||||
public function __construct(Position $center, $size){
|
public function __construct(Position $center, $size){
|
||||||
$this->level = $center->level;
|
$this->level = $center->level;
|
||||||
$this->source = $center;
|
$this->source = $center;
|
||||||
$this->size = max($size, 0);
|
$this->size = max($size, 0);
|
||||||
|
$this->air = BlockAPI::getItem(AIR, 0, 1);
|
||||||
|
console($this->air);
|
||||||
|
}
|
||||||
|
private function explodeBlocks($send, $source, $block){
|
||||||
|
$server = ServerAPI::request();
|
||||||
|
if($block instanceof TNTBlock){
|
||||||
|
$data = array(
|
||||||
|
"x" => $block->x + 0.5,
|
||||||
|
"y" => $block->y + 0.5,
|
||||||
|
"z" => $block->z + 0.5,
|
||||||
|
"power" => 4,
|
||||||
|
"fuse" => mt_rand(10, 30), //0.5 to 1.5 seconds
|
||||||
|
);
|
||||||
|
$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
||||||
|
$server->api->entity->spawnToAll($e);
|
||||||
|
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
|
||||||
|
foreach($block->getDrops($this->air,new PlayerNull()) as $drop){
|
||||||
|
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
|
||||||
|
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
|
||||||
|
return $send;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function explode(){
|
public function explode(){
|
||||||
$server = ServerAPI::request();
|
$server = ServerAPI::request();
|
||||||
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array(
|
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array(
|
||||||
|
|
@ -50,6 +72,10 @@ class Explosion{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$send = array();
|
||||||
|
$source = $this->source->floor();
|
||||||
|
$radius = 2 * $this->size;
|
||||||
|
|
||||||
$mRays = $this->rays - 1;
|
$mRays = $this->rays - 1;
|
||||||
for($i = 0; $i < $this->rays; ++$i){
|
for($i = 0; $i < $this->rays; ++$i){
|
||||||
for($j = 0; $j < $this->rays; ++$j){
|
for($j = 0; $j < $this->rays; ++$j){
|
||||||
|
|
@ -72,7 +98,8 @@ class Explosion{
|
||||||
if($blastForce > 0){
|
if($blastForce > 0){
|
||||||
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
||||||
if(!isset($this->affectedBlocks[$index])){
|
if(!isset($this->affectedBlocks[$index])){
|
||||||
$this->affectedBlocks[$index] = $block;
|
$send = $this->explodeBlocks($send, $source,$block);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -82,38 +109,14 @@ class Explosion{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$send = array();
|
|
||||||
$source = $this->source->floor();
|
|
||||||
$radius = 2 * $this->size;
|
|
||||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||||
|
if($entity->type === OBJECT_PRIMEDTNT){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //placeholder, 0.7 should be exposure
|
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //placeholder, 0.7 should be exposure
|
||||||
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
|
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
|
||||||
$entity->harm($damage, "explosion");
|
$entity->harm($damage, "explosion");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->affectedBlocks as $block){
|
|
||||||
|
|
||||||
if($block instanceof TNTBlock){
|
|
||||||
$data = array(
|
|
||||||
"x" => $block->x + 0.5,
|
|
||||||
"y" => $block->y + 0.5,
|
|
||||||
"z" => $block->z + 0.5,
|
|
||||||
"power" => 4,
|
|
||||||
"fuse" => mt_rand(10, 30), //0.5 to 1.5 seconds
|
|
||||||
);
|
|
||||||
$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
|
||||||
$server->api->entity->spawnToAll($e);
|
|
||||||
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
|
|
||||||
if(isset(self::$specialDrops[$block->getID()])){
|
|
||||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0));
|
|
||||||
}else{
|
|
||||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
|
|
||||||
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
|
|
||||||
}
|
|
||||||
$pk = new ExplodePacket;
|
$pk = new ExplodePacket;
|
||||||
$pk->x = $this->source->x;
|
$pk->x = $this->source->x;
|
||||||
$pk->y = $this->source->y;
|
$pk->y = $this->source->y;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue