mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
support php8019 and some cleanup (by @D-aHTuCT)
This commit is contained in:
parent
cf0f9df267
commit
b60f0877e1
376 changed files with 6528 additions and 13472 deletions
|
|
@ -1,41 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class Explosion{
|
||||
public static $specialDrops = array(
|
||||
|
||||
public static $specialDrops = [
|
||||
GRASS => DIRT,
|
||||
STONE => COBBLESTONE,
|
||||
COAL_ORE => COAL,
|
||||
DIAMOND_ORE => DIAMOND,
|
||||
REDSTONE_ORE => REDSTONE,
|
||||
);
|
||||
];
|
||||
public static $enableExplosions = true;
|
||||
private $rays = 16; //Rays
|
||||
public $level;
|
||||
public $level; //Rays
|
||||
public $source;
|
||||
public $size;
|
||||
public $affectedBlocks = array();
|
||||
public $affectedBlocks = [];
|
||||
public $stepLen = 0.3;
|
||||
private $rays = 16;
|
||||
private $air;
|
||||
private $nullPlayer;
|
||||
|
||||
public function __construct(Position $center, $size){
|
||||
$this->level = $center->level;
|
||||
$this->source = $center;
|
||||
|
|
@ -43,17 +26,18 @@ class Explosion{
|
|||
$this->air = BlockAPI::getItem(AIR, 0, 1);
|
||||
$this->nullPlayer = new PlayerNull();
|
||||
}
|
||||
|
||||
|
||||
public function explode(){
|
||||
if(!Explosion::$enableExplosions){ /*Disable Explosions*/
|
||||
return;
|
||||
}
|
||||
|
||||
$server = ServerAPI::request();
|
||||
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array(
|
||||
"level" => $this->level,
|
||||
"source" => $this->source,
|
||||
"size" => $this->size
|
||||
)) === false){
|
||||
if($this->size < 0.1 or $server->api->dhandle("entity.explosion", [
|
||||
"level" => $this->level,
|
||||
"source" => $this->source,
|
||||
"size" => $this->size
|
||||
]) === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -65,11 +49,11 @@ class Explosion{
|
|||
$vector = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); //($i / $mRays) * 2 - 1
|
||||
$vector = $vector->normalize()->multiply($this->stepLen);
|
||||
$pointer = clone $this->source;
|
||||
|
||||
|
||||
for($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75){
|
||||
$vBlock = $pointer->floor();
|
||||
$blockID = $this->level->level->getBlockID($vBlock->x, $vBlock->y, $vBlock->z);
|
||||
|
||||
|
||||
if($blockID > 0){
|
||||
$block = BlockAPI::get($blockID, 0);
|
||||
$block->x = $vBlock->x;
|
||||
|
|
@ -77,7 +61,7 @@ class Explosion{
|
|||
$block->z = $vBlock->z;
|
||||
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
|
||||
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])){
|
||||
$this->affectedBlocks[$index] = $block;
|
||||
}
|
||||
|
|
@ -89,8 +73,8 @@ class Explosion{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$send = array();
|
||||
|
||||
$send = [];
|
||||
$source = $this->source->floor();
|
||||
$radius = 2 * $this->size;
|
||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||
|
|
@ -102,18 +86,18 @@ class Explosion{
|
|||
foreach($this->affectedBlocks as $block){
|
||||
|
||||
if($block instanceof TNTBlock){
|
||||
$data = array(
|
||||
$data = [
|
||||
"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)){
|
||||
}elseif(mt_rand(0, 10000) < ((1 / $this->size) * 10000)){
|
||||
foreach($block->getDrops($this->air, $this->nullPlayer) as $drop){
|
||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1],$drop[2])); //id, meta, count
|
||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1], $drop[2])); //id, meta, count
|
||||
}
|
||||
}
|
||||
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
|
||||
|
|
@ -127,6 +111,5 @@ class Explosion{
|
|||
$pk->radius = $this->size;
|
||||
$pk->records = $send;
|
||||
$server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue