Possibly incorrect lighting calculations
Destructor-Ben opened this issue · 1 comments
Based on this snippet of code from MInecraft 1.20.4 from Monster.java:
public static boolean isDarkEnoughToSpawn(ServerLevelAccessor serverLevelAccessor, BlockPos blockPos, RandomSource randomSource) {
if (serverLevelAccessor.getBrightness(LightLayer.SKY, blockPos) > randomSource.nextInt(32)) {
return false;
}
DimensionType dimensionType = serverLevelAccessor.dimensionType();
int i = dimensionType.monsterSpawnBlockLightLimit();
if (i < 15 && serverLevelAccessor.getBrightness(LightLayer.BLOCK, blockPos) > i) {
return false;
}
int j = serverLevelAccessor.getLevel().isThundering() ? serverLevelAccessor.getMaxLocalRawBrightness(blockPos, 10) : serverLevelAccessor.getMaxLocalRawBrightness(blockPos);
return j <= dimensionType.monsterSpawnLightTest().sample(randomSource);
}It appears that the calculations to determine whether a monster will spawn in this mod are incorrect. minecraft.wiki and minecraft.fandom.com are also both wrong in multiple places so I wouldn't blame you if they are wrong (I'm still not sure if I'm right), since they are inconsistent between each other, have misinformation around both of them (that monsters spawn below light level 7, which is not true), and inconsistencies within each wiki (light level vs block light and sky light, lots of others that i cbf listing).
If the calculations for the crosses is changed to be based upon the code above, then it might make sense to remove a lot of the config options too, since there is no reason to allow customization the crosses if the spawn rules stay the same - It could be good though to add different presets for different types of mobs, e.g. regular monsters, drowns, piglins, slimes, etc.
I have made a fork of this repo and will change it myself for personal use, and if you want to merge it then you can. I also might be wrong, but thought I should mention it since monster spawning from light levels is more complicated than what most people think, especially when there are a lot of changes and reverts done to it as well as misinformation.
Having done some testing (in 1.21.1) myself, as well as looking at the code and my understanding of spawn requirements (verified with testing), I can confirm the colours are wrong.
Currently, the colours mean:
Red - Can spawn any time.
Yellow - Cannot spawn, but could prior to 1.18.
Blue - Can't spawn during the day. Might or might not be able to spawn at night (1.18+). Can spawn at night prior to 1.18.
Also, while I could be mistaken, I think the blue colour is meant to indicate where it could spawn if it was before version 1.18? i.e. before the light level changes to mob spawning requiring light level 0? But this would require 4 colours.
If so, we can set up a table showing all options, and indicating which colours they currently are and what they should be if I understand correctly.
| Sky light | |||
|---|---|---|---|
| <=7 | >7 | ||
| Block light | 0 | Can spawn anytime Red | Can spawn at night Currently blue Should be yellow |
| >0 <=7 | Can't spawn 1.18+ Can spawn anytime <1.18 Currently yellow Should be blue | Can't spawn 1.18+ Can spawn at night <1.18 Blue | |
| >7 | Can't spawn No colour | Can't spawn No colour | |
It seems the mixup is between skylight>7, blocklight=0, which is currently blue but should be yellow; and skylight<=7, block light>0 and <=7, which is currently yellow but should be blue.
Then there is just the question of if the 2 blue cells should be made distinct to highlight where it can spawn all the time in versions prior to 1.18 vs where it can only spawn at night.