mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 19:34:15 +00:00
Entity: truncate fire ticks instead of throwing exceptions
as written in the comments, it's not reasonable to propagate this limitation, since it ultimately comes from a shortfall in the Mojang save format, not a limitation of PM's capability. It's also not obvious how this would be propagated to the likes of setOnFire(), as this would translate into a max time of 1638 seconds, a value no one is going to remember. There's a case to be made for truncating this on save rather than on initial set, but this is at least better than having Fire Aspect level 1000 cause crashes and whatever other gameplay logic that would have to work around this stupid limitation.
This commit is contained in:
parent
2548422973
commit
4a5c1e7540
@ -60,6 +60,7 @@ use pocketmine\player\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\timings\Timings;
|
||||
use pocketmine\timings\TimingsHandler;
|
||||
use pocketmine\utils\Limits;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\VersionInfo;
|
||||
use pocketmine\world\format\Chunk;
|
||||
@ -700,9 +701,16 @@ abstract class Entity{
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setFireTicks(int $fireTicks) : void{
|
||||
if($fireTicks < 0 || $fireTicks > 0x7fff){
|
||||
throw new \InvalidArgumentException("Fire ticks must be in range 0 ... " . 0x7fff . ", got $fireTicks");
|
||||
if($fireTicks < 0){
|
||||
throw new \InvalidArgumentException("Fire ticks cannot be negative");
|
||||
}
|
||||
|
||||
//Since the max value is not externally obvious or intuitive, many plugins use this without being aware that
|
||||
//reasonably large values are not accepted. We even have such usages within PM itself. It doesn't make sense
|
||||
//to force all those calls to be aware of this limitation, as it's not a functional limit but a limitation of
|
||||
//the Mojang save format. Truncating this to the max acceptable value is the next best thing we can do.
|
||||
$fireTicks = min($fireTicks, Limits::INT16_MAX);
|
||||
|
||||
if(!$this->isFireProof()){
|
||||
$this->fireTicks = $fireTicks;
|
||||
$this->networkPropertiesDirty = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user