Skip to content

Commit

Permalink
fix: Fix crash due to missing null checks for certain block colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed May 31, 2024
1 parent 07158b1 commit a444465
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -20,7 +22,7 @@
@Mixin(BlockColors.class)
public class BlockColorsMixin {
@Inject(method = "create", at = @At(value = "RETURN"), locals = LocalCapture.CAPTURE_FAILSOFT)
private static void simple_seasons$createInject(CallbackInfoReturnable<BlockColors> cir, BlockColors blockColors) {
private static void simple_seasons$createInject(@NotNull CallbackInfoReturnable<BlockColors> cir, @NotNull BlockColors blockColors) {
// Grab all registered blocks from the API
Block[] registeredBlocks = BlockColorProviderRegistry.getRegisteredBlocks().toArray(new Block[0]);

Expand All @@ -34,14 +36,22 @@ public class BlockColorsMixin {
}, registeredBlocks);
}

@Inject(method = {"method_1695", "method_1687", "method_1684"}, at = @At(value = "RETURN"), cancellable = true)
private static void simple_seasons$modifyLeafAndLilyPadColors(BlockState blockState, BlockRenderView world, BlockPos blockPos, int tintIndex, CallbackInfoReturnable<Integer> cir) {
@Inject(method = {"method_1695", "method_1687", "method_1684"}, at = @At(value = "HEAD"), cancellable = true)
private static void simple_seasons$modifyLeafAndLilyPadColors(@NotNull BlockState blockState, @Nullable BlockRenderView world, @Nullable BlockPos blockPos, int tintIndex, @NotNull CallbackInfoReturnable<Integer> cir) {
if (world == null || blockPos == null) {
return;
}

cir.setReturnValue(BiomeColors.getFoliageColor(world, blockPos));
}

// TODO: Reimplement stem block ageing colors
@Inject(method = "method_1696", at = @At(value = "HEAD"), cancellable = true)
private static void simple_seasons$modifyStemColor(BlockState state, BlockRenderView world, BlockPos blockPos, int tintIndex, CallbackInfoReturnable<Integer> cir) {
private static void simple_seasons$modifyStemColor(@NotNull BlockState blockState, @Nullable BlockRenderView world, @Nullable BlockPos blockPos, int tintIndex, @NotNull CallbackInfoReturnable<Integer> cir) {
if (world == null || blockPos == null) {
return;
}

cir.setReturnValue(BiomeColors.getFoliageColor(world, blockPos));
}
}

0 comments on commit a444465

Please sign in to comment.