Added Single Explosions [ignite TNT using fling & steel]

This commit is contained in:
Shoghi Cervantes
2013-09-06 13:46:52 +02:00
parent 41b1a0f991
commit 94f8cfb59b
77 changed files with 134 additions and 32 deletions

View File

@ -20,27 +20,29 @@
*/
class Explosion{
private $i = 16; //Rays
private $i = 8; //Rays
public $level;
public $source;
public $size;
public $affectedBlocks = array();
public function __construct($level, Vector3 $center, $size){
public function __construct(Level $level, Vector3 $center, $size){
$this->level = $level;
$this->source = $center;
$this->size = max($size, 0);
}
public function explode(){
if($this->size < 0.1 or ServerAPI::request()->api->dhandle("entity.explosion", array(
"level" => $level,
$server = ServerAPI::request();
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array(
"level" => $this->level,
"source" => $this->source,
"size" => $this->size
))){
return false;
}
$airblock = new AirBlock();
$drops = array();
for($i = 0; $i < $this->i; ++$i){
for($j = 0; $j < $this->i; ++$j){
for($k = 0; $k < $this->i; ++$k){
@ -53,24 +55,25 @@ class Explosion{
$d4 /= $d6;
$d5 /= $d6;
$f1 = $this->size * (0.7 + lcg_value() * 0.6);
$f1 = $this->size * (0.7 + (mt_rand(0, 1000000) / 1000000) * 0.6);
$d0 = $this->source->x;
$d1 = $this->source->y;
$d2 = $this->source->z;
for($f2 = 0.3; $f1 > 0; $f1 -= $f2 * 0.75){
$l = floor($d0);
$i1 = floor($d1);
$j1 = floor($d2);
$k1 = $this->level->getBlock(new Vector3($l, $i1, $j1))->getID();
if($k1 > AIR){
$f3 = 0.5; //Placeholder
$f1 -= ($f3 + 0.4) * $f2;
}
$l = (int) $d0;
$i1 = (int) $d1;
$j1 = (int) $d2;
$k1 = $this->level->getBlock(new Vector3($l, $i1, $j1));
if($f1 > 0 and $i1 < 128 and $i1 >= 0){
$this->level->setBlock(new Vector3($l, $i1, $j1), AIR, 0, false);
$this->affectedBlocks[$l.$i1.$j1] = new Vector3($l, $i1, $j1);
$f1 -= ($k1->getHardness() / 5 + 0.3) * $f2;
if(!($k1 instanceof AirBlock) and $f1 > 0 and $i1 < 128 and $i1 >= 0){
$this->level->setBlockRaw(new Vector3($l, $i1, $j1), $airblock, false, false); //Do not send record
$this->affectedBlocks[$l.$i1.$j1] = new Vector3($l - $this->source->x, $i1 - $this->source->y, $j1 - $this->source->z);
if(mt_rand(0, 100) < 30){
$drops[] = array(new Position($l, $i1, $j1, $this->level), BlockAPI::getItem($k1->getID(), $k1->getMetadata()));
}
}
$d0 += $d3 * $f2;
@ -81,15 +84,21 @@ class Explosion{
}
}
}
foreach(ServerAPI::request()->api->player->getAll() as $player){
$player->dataPacket(MC_EXPLOSION, array(
"x" => $this->source->x,
"y" => $this->source->y,
"z" => $this->source->z,
"radius" => $this->size,
"records" => array(), //Blocks are already sent
));
$server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_EXPLOSION, array(
"x" => $this->source->x,
"y" => $this->source->y,
"z" => $this->source->z,
"radius" => $this->size,
"records" => $this->affectedBlocks,
));
foreach($server->api->entity->getRadius($this->source, 10) as $entity){
$impact = (1 - $this->source->distance($entity) / 10);
$damage = (int) (($impact * $impact + $impact) * 4 * $this->size + 1);
$entity->harm($damage, "explosion");
}
foreach($drops as $drop){
$server->api->entity->drop($drop[0], $drop[1]);
}
}
}