diff --git a/src/material/block/misc/TNT.php b/src/material/block/misc/TNT.php index f4974e0fe..edab02619 100644 --- a/src/material/block/misc/TNT.php +++ b/src/material/block/misc/TNT.php @@ -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(); } } \ No newline at end of file diff --git a/src/network/CustomPacketHandler.php b/src/network/CustomPacketHandler.php index 35b929617..343aa0b0e 100644 --- a/src/network/CustomPacketHandler.php +++ b/src/network/CustomPacketHandler.php @@ -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); } } } diff --git a/src/world/Explosion.php b/src/world/Explosion.php new file mode 100644 index 000000000..a3e47aca0 --- /dev/null +++ b/src/world/Explosion.php @@ -0,0 +1,101 @@ +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 + )); + } + } +} \ No newline at end of file