mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
* Added Liquid->getLiquidLevelDecreasePerBlock() * Fixed lava turning into cobblestone when flowing over water * Cache liquid flow vectors for faster entity movement * Removed a condition that made lava impossible to get rid of In the PC code, the equivalent code makes the delay between scheduled ticks 4 times longer. Here, it just breaks the code. I don't know what the 4x stuff is about, but this code does not produce the expected behaviour and lava works fine regardless. * Fixed strange behaviour with liquids trying to flow into other liquids Liquids should consider other liquids as a path of least resistance. However, they should not actually flow into them. This fixes a variety of CPU leak issues with falling water in large water bodies such as oceans. This also fixes the plus-shape effect that liquid is supposed to produce when a source is placed above ground. * Removed a bad optimization making liquids flowing down slopes behave undesirably * Optimize performance of slope searching by limiting recursion depth based on previous path lengths If we already found a step down on a previous run after 2 blocks, it doesn't make sense to continue allowing checking 4 blocks because the results will just be ignored. This allows limiting the number of recursion steps, which significantly improves the performance when flowing down slopes. However, this will still be just as bad for performance on flat terrain as it was to start with. * Make some Liquid methods only accept Blocks as parameters these are only ever passed blocks anyway, doesn't make sense to allow vectors. * Moved some things to local variables these are each only used in one function, so it doesn't make sense for them to be class members. * Fixed water flow down slopes going everywhere, but degraded performance again * Lava should only search 2 blocks for a slope * Stop wasting CPU calculating optimal flow directions for liquids with too-high decay It calculates the flow directions and THEN doesn't use them when it realizes the flow decay is too high. This is completely pointless. * Use a less hacky method to handle lava flowing into water * Doubled flow performance on flat terrain Since calculateFlowCost() usually ends up visiting the same blocks about 6 times when on flat terrain, it makes sense to cache some stuff for when blocks get revisited so expensive dumb checks don't need to keep on being done. On my machine this produces a 50-60% performance improvement when flowing on flat terrain. * Fixed missing return values in Liquid->onUpdate() these return values aren't used anywhere, but we should be consistent * Don't allow flowing back in the same direction we just came from This reduces the recursions by about 30%, providing about the same percentage performance improvement. * Remove Liquid's temporalVector (it's not used anymore) primitive types for the win! * Move liquid collide to its own method * add sound for lava/water mix
67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?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/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\block;
|
|
|
|
use pocketmine\entity\Entity;
|
|
use pocketmine\item\Item;
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\Player;
|
|
|
|
class Water extends Liquid{
|
|
|
|
protected $id = self::FLOWING_WATER;
|
|
|
|
public function __construct(int $meta = 0){
|
|
$this->meta = $meta;
|
|
}
|
|
|
|
public function getName() : string{
|
|
return "Water";
|
|
}
|
|
|
|
public function getLightFilter() : int{
|
|
return 2;
|
|
}
|
|
|
|
public function tickRate() : int{
|
|
return 5;
|
|
}
|
|
|
|
public function onEntityCollide(Entity $entity) : void{
|
|
$entity->resetFallDistance();
|
|
if($entity->fireTicks > 0){
|
|
$entity->extinguish();
|
|
}
|
|
|
|
$entity->resetFallDistance();
|
|
}
|
|
|
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
|
$ret = $this->getLevel()->setBlock($this, $this, true, false);
|
|
$this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate());
|
|
|
|
return $ret;
|
|
}
|
|
}
|