mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
Explosion performance improvements
This commit is contained in:
parent
8a4ebcc907
commit
2b0ad36e14
5 changed files with 38 additions and 24 deletions
|
|
@ -564,7 +564,7 @@ class BlockAPI{
|
|||
$this->blockUpdate($pos->getSide(5), $type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){
|
||||
$type = (int) $type;
|
||||
if($delay < 0){
|
||||
|
|
|
|||
|
|
@ -1278,7 +1278,6 @@ class Player{
|
|||
if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){
|
||||
return;
|
||||
}
|
||||
|
||||
switch($packet->pid()){
|
||||
case 0x01:
|
||||
break;
|
||||
|
|
@ -1527,9 +1526,11 @@ class Player{
|
|||
}
|
||||
break;
|
||||
case ProtocolInfo::MOVE_PLAYER_PACKET:
|
||||
|
||||
if($this->spawned === false){
|
||||
break;
|
||||
}
|
||||
|
||||
if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){
|
||||
$this->lastMovement = $packet->messageIndex;
|
||||
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ class PocketMinecraftServer{
|
|||
if(!defined("NO_THREADS")){
|
||||
$this->asyncThread = new AsyncMultipleQueue();
|
||||
}
|
||||
|
||||
console("[INFO] Loading extra.properties...");
|
||||
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [
|
||||
"version" => "5",
|
||||
|
|
@ -220,7 +219,11 @@ class PocketMinecraftServer{
|
|||
$this->interface->close();
|
||||
|
||||
if(!defined("NO_THREADS")){
|
||||
@$this->asyncThread->stop = true;
|
||||
$this->asyncThread->synchronized(function ($t){
|
||||
$t->stop = true;
|
||||
$t->notify();
|
||||
}, $this->asyncThread);
|
||||
//@$this->asyncThread->stop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
class StaticBlock
|
||||
{
|
||||
const DEFAULT_SLIPPERINESS = 0.6;
|
||||
const DEFAULT_HARDNESS = 0;
|
||||
private static $NULL_BOUNDS;
|
||||
public static $isSolid = [];
|
||||
public static $isTransparent = [];
|
||||
|
|
@ -15,6 +16,7 @@ class StaticBlock
|
|||
public static $isLiquid = [];
|
||||
public static $isFullBlock = [];
|
||||
|
||||
public static $hardness = [];
|
||||
public static $slipperiness = [];
|
||||
public static $boundingBoxes = [];
|
||||
public static function init(){
|
||||
|
|
@ -31,9 +33,9 @@ class StaticBlock
|
|||
self::$hasPhysics[$b->getID()] = $b->hasPhysics;
|
||||
self::$isLiquid[$b->getID()] = $b->isLiquid;
|
||||
self::$isFullBlock[$b->getID()] = $b->isFullBlock;
|
||||
|
||||
self::$slipperiness[$b->getID()] = $b->slipperiness;
|
||||
self::$boundingBoxes[$b->getID()] = $b->boundingBox;
|
||||
self::$hardness[$b->getID()] = $b->getHardness();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +43,10 @@ class StaticBlock
|
|||
return nullsafe(Block::$class[$id], Block::$class[0]);
|
||||
}
|
||||
|
||||
public static function getHardness($id){
|
||||
return nullsafe(self::$hardness[$id], StaticBlock::DEFAULT_HARDNESS);
|
||||
}
|
||||
|
||||
public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){
|
||||
/**@var AxisAlignedBB $bb*/
|
||||
$bb = nullsafe(self::$boundingBoxes[$id], false);
|
||||
|
|
|
|||
|
|
@ -68,21 +68,24 @@ class Explosion{
|
|||
$blockID = $BIDM[0];
|
||||
$blockMeta = $BIDM[1];
|
||||
if($blockID > 0){
|
||||
$block = BlockAPI::get($blockID, $blockMeta);
|
||||
$block->x = $vBlock->x;
|
||||
$block->y = $vBlock->y;
|
||||
$block->z = $vBlock->z;
|
||||
$block->level = $this->level;
|
||||
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
||||
if($block instanceof LiquidBlock && !isset($visited[$index])){
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate($block, 5, BLOCK_UPDATE_NORMAL);
|
||||
$index = ($vBlock->x << 15) + ($vBlock->z << 7) + $vBlock->y;
|
||||
|
||||
if(StaticBlock::getIsLiquid($blockID) && !isset($visited[$index])){
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($vBlock->x, $vBlock->y, $vBlock->z, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
$visited[$index] = true;
|
||||
}
|
||||
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
|
||||
|
||||
$blastForce -= (StaticBlock::getHardness($blockID) / 5 + 0.3) * $this->stepLen;
|
||||
if($blastForce > 0){
|
||||
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
||||
$index = ($vBlock->x << 15) + ($vBlock->z << 7) + $vBlock->y;
|
||||
if(!isset($this->affectedBlocks[$index])){
|
||||
$this->affectedBlocks[$index] = $block;
|
||||
$this->affectedBlocks[$index] = [
|
||||
"x" => $vBlock->x,
|
||||
"y" => $vBlock->y,
|
||||
"z" => $vBlock->z,
|
||||
"id" => $blockID,
|
||||
"meta" => $blockMeta
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -101,27 +104,28 @@ class Explosion{
|
|||
$entity->harm($damage, "explosion");
|
||||
}
|
||||
|
||||
foreach($this->affectedBlocks as $block){
|
||||
if($block instanceof TNTBlock){
|
||||
foreach($this->affectedBlocks as $blockA){
|
||||
if($blockA["id"] === TNT){
|
||||
$data = [
|
||||
"x" => $block->x + 0.5,
|
||||
"y" => $block->y + 0.5,
|
||||
"z" => $block->z + 0.5,
|
||||
"x" => $blockA["x"] + 0.5,
|
||||
"y" => $blockA["y"] + 0.5,
|
||||
"z" => $blockA["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)){
|
||||
$block = BlockAPI::get($blockA["id"], $blockA["meta"], new Position($blockA["x"], $blockA["y"], $blockA["z"], $this->level));
|
||||
$dropz = $block->getDrops($this->air, $this->nullPlayer);
|
||||
if(is_array($dropz)){
|
||||
foreach($dropz 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($blockA["x"] + 0.5, $blockA["y"], $blockA["z"] + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1], $drop[2])); //id, meta, count
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->level->setBlock($block, new AirBlock(), true);
|
||||
$send[] = $block->subtract($source);
|
||||
$this->level->fastSetBlockUpdate($blockA["x"], $blockA["y"], $blockA["z"], 0, 0);
|
||||
$send[] = new Vector3($blockA["x"] - $source->x, $blockA["y"] - $source->y, $blockA["z"] - $source->z);
|
||||
}
|
||||
$pk = new ExplodePacket;
|
||||
$pk->x = $this->source->x;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue