mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Explosions
This commit is contained in:
parent
a6615560bc
commit
bab3b8274a
@ -31,16 +31,9 @@ class TNTBlock extends SolidBlock{
|
||||
}
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($this->inWorld === true){
|
||||
$player->dataPacket(MC_EXPLOSION, array(
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z,
|
||||
"radius" => 2,
|
||||
"records" => array(),
|
||||
));
|
||||
$ex = new Explosion(ServerAPI::request()->api->block, $this, 0.5);
|
||||
$ex->explode();
|
||||
}
|
||||
return array(
|
||||
array(TNT, 0, 1),
|
||||
);
|
||||
return array();
|
||||
}
|
||||
}
|
@ -421,7 +421,7 @@ class CustomPacketHandler{
|
||||
$this->data["count"] = Utils::readInt($this->get(4));
|
||||
$this->data["records"] = array();
|
||||
for($r = 0; $r < $this->data["count"]; ++$r){
|
||||
$this->data["records"][] = array(Utils::readByte($this->get(1)), Utils::readByte($this->get(1)), Utils::readByte($this->get(1)));
|
||||
$this->data["records"][] = new Vector3(Utils::readByte($this->get(1)), Utils::readByte($this->get(1)), Utils::readByte($this->get(1)));
|
||||
}
|
||||
}else{
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
@ -432,7 +432,7 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeInt(count($this->data["records"]));
|
||||
if(count($this->data["records"]) > 0){
|
||||
foreach($this->data["records"] as $record){
|
||||
$this->raw .= Utils::writeByte($record[0]) . Utils::writeByte($record[1]) . Utils::writeByte($record[2]);
|
||||
$this->raw .= Utils::writeByte($record->x) . Utils::writeByte($record->y) . Utils::writeByte($record->z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
101
src/world/Explosion.php
Normal file
101
src/world/Explosion.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class Explosion{
|
||||
private $i = 16; //Rays
|
||||
public $level;
|
||||
public $source;
|
||||
public $size;
|
||||
public $affectedBlocks = array();
|
||||
|
||||
public function __construct($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,
|
||||
"source" => $this->source,
|
||||
"size" => $this->size
|
||||
))){
|
||||
return false;
|
||||
}
|
||||
|
||||
for($i = 0; $i < $this->i; ++$i){
|
||||
for($j = 0; $j < $this->i; ++$j){
|
||||
for($k = 0; $k < $this->i; ++$k){
|
||||
if($i === 0 or $i === ($this->i - 1) or $j === 0 or $j === ($this->i - 1) or $k === 0 or $k === ($this->i - 1)){
|
||||
$d3 = $i / ($this->i - 1) * 2 - 1;
|
||||
$d4 = $j / ($this->i - 1) * 2 - 1;
|
||||
$d5 = $k / ($this->i - 1) * 2 - 1;
|
||||
$d6 = sqrt($d3 * $d3 + $d4 * $d4 + $d5 * $d5);
|
||||
$d3 /= $d6;
|
||||
$d4 /= $d6;
|
||||
$d5 /= $d6;
|
||||
|
||||
$f1 = $this->size * (0.7 + lcg_value() * 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$d0 += $d3 * $f2;
|
||||
$d1 += $d4 * $f2;
|
||||
$d2 += $d5 * $f2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user