Nature's Aura

Nature's Aura

30M Downloads

BlockSpring's BlockColor errors when world argument is null

SuperMartijn642 opened this issue ยท 0 comments

commented

The BlockColor#getColor method takes 4 arguments, 2 of these are marked @Nullable which includes the world (BlockAndTintGetter) argument. This can indeed be null, for example when called from inside the BlockRenderDispatcher#renderSingleBlock method which doesn't take a world argument.

The implementation of BlockColor#getColor in BlockSpring#getBlockColor calls BiomeColors#getAverageWaterColor with the world argument. Whenever the world argument is null for BiomeColors#getAverageWaterColor, this leads to a null pointer exception.

@Override
@OnlyIn(Dist.CLIENT)
public BlockColor getBlockColor() {
return (state, level, pos, i) -> BiomeColors.getAverageWaterColor(level, pos);
}

This seems like a simple oversight as BlockGoldenLeaves#getBlockColor does have a null check.

return (state, levelIn, pos, tintIndex) -> {
var color = 0xF2FF00;
if (state != null && levelIn != null && pos != null) {
var foliage = BiomeColors.getAverageFoliageColor(levelIn, pos);
return Helper.blendColors(color, foliage, state.getValue(BlockGoldenLeaves.STAGE) / (float) BlockGoldenLeaves.HIGHEST_STAGE);
} else {
return color;
}
};

In my mod Entangled I happen to use BlockRenderDispatcher#renderSingleBlock to render other blocks in the world. When the rendered block is the BlockSpring from Nature's Aura, this leads to a crash.
Original issue here: SuperMartijn642/Entangled#64