|
7 | 7 | import net.minecraft.util.Vec3; |
8 | 8 | import net.minecraft.world.IBlockAccess; |
9 | 9 | import net.minecraft.world.World; |
| 10 | +import net.minecraft.world.biome.BiomeGenBase; |
10 | 11 |
|
11 | 12 | import org.spongepowered.asm.mixin.Mixin; |
12 | 13 | import org.spongepowered.asm.mixin.Overwrite; |
| 14 | +import org.spongepowered.asm.mixin.Unique; |
| 15 | +import org.spongepowered.asm.mixin.injection.At; |
| 16 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 17 | + |
| 18 | +import java.util.HashSet; |
| 19 | +import java.util.Set; |
13 | 20 |
|
14 | 21 | @Mixin(BlockLiquid.class) |
15 | 22 | public class MixinBlockLiquid extends Block { |
| 23 | + @Unique |
| 24 | + private static final Set<Integer> NULL_BIOME_DIMENSION_CACHE = new HashSet<>(); |
16 | 25 |
|
17 | 26 | protected MixinBlockLiquid(Material materialIn) { |
18 | 27 | super(materialIn); |
@@ -114,5 +123,29 @@ protected int getEffectiveFlowDecay(IBlockAccess blockAccess, int x, int y, int |
114 | 123 |
|
115 | 124 | return -1; |
116 | 125 | } |
117 | | - |
| 126 | + /** |
| 127 | + * Avoid returning an error if biome is null at getWaterColorMultiplier |
| 128 | + */ |
| 129 | + @Redirect( |
| 130 | + method = "colorMultiplier", |
| 131 | + at = @At( |
| 132 | + value = "INVOKE", |
| 133 | + target = "Lnet/minecraft/world/biome/BiomeGenBase;getWaterColorMultiplier()I" |
| 134 | + ) |
| 135 | + ) |
| 136 | + private int safeGetWaterColorMultiplier(BiomeGenBase biome, IBlockAccess world, int x, int y, int z) { |
| 137 | + if (biome == null) { |
| 138 | + if (world instanceof World) { |
| 139 | + World actualWorld = (World) world; |
| 140 | + int dimId = actualWorld.provider.dimensionId; |
| 141 | + if (!NULL_BIOME_DIMENSION_CACHE.contains(dimId)) { |
| 142 | + System.err.println("[NullBiomeFix] BiomeGenBase is NULL in Dimension " + dimId + " (at x=" + x + ", z=" + z + ")."); |
| 143 | + NULL_BIOME_DIMENSION_CACHE.add(dimId); |
| 144 | + } |
| 145 | + } |
| 146 | + return 0x4080FF; // blue color |
| 147 | + } |
| 148 | + |
| 149 | + return biome.getWaterColorMultiplier(); |
| 150 | + } |
118 | 151 | } |
0 commit comments