pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.26k stars 1.54k forks source link

Random->nextSignedInt() returns an unsigned value #4645

Closed CortexPE closed 2 years ago

CortexPE commented 2 years ago

Issue description

OS and versions

Plugins

A plugin or a world generator is needed to invoke the function, the following snippet may be used to produce a similar output below:

$rnd = new Random(time());
for ($i = 0; $i < 10; $i++){
    var_dump($rnd->nextSignedInt());
}

Crashdump, backtrace or other files

int(3695939109)
int(3432772977)
int(2405991418)
int(716041031)
int(2458067232)
int(138586938)
int(4146417334)
int(1957814663)
int(3472200452)
int(4260561129)
dktapps commented 2 years ago

⚠️ This issue ticket doesn't have all the required information ⚠️ To make it as quick and easy as possible for maintainers to fix your problem, an issue template is provided which lists certain required information. This includes (but is not limited to):

Without this information, your problem cannot begin to be investigated, so the issue will be closed. You may amend this one, or create a new one, providing all the required information using one of the provided issue templates.

Help us to help you by providing the information we ask for.

CortexPE commented 2 years ago

Issue description updated

dktapps commented 2 years ago

this is a tough problem to fix because it will change the outputs of all the generators.

CortexPE commented 2 years ago

this is a tough problem to fix because it will change the outputs of all the generators.

I would suggest providing a LegacyRandom class which explicitly declares in the documentation that it has broken outputs, then the new Random class would simply overwrite the nextSignedInt() method, which should fix the behavior of #4646 as well...

I could also suggest naming them Random32 and Random64 respectively, but it would imply that the former works perfectly as intended and doesn't have broken behavior.

This way, old legacy generators that depend on the old broken behavior wouldn't get broken terrain... Given the proper migration on the code-side. (or insist on renaming the fixed Random class to force a BC-break... for safety)

A more comprehensive change is to do proper world generator versioning to possibly support even the future massive changes to terrain generation

dktapps commented 2 years ago

All of these solutions require some kind of BC break.

dktapps commented 2 years ago

After digging into generator sources it appears that the generator was not affected by this problem at all, due to exclusively using unsigned values.

The only thing this actually has any impact on are the following things:

dktapps commented 2 years ago

grepPlugins suggests that impact is similarly negligible to plugins, with only SimpleWarp particles being affected (bias). I am however unable to speak of private plugins.