Skip to content

Commit b02b25c

Browse files
committed
Ensure BlockLiquid returns blue color on null biome
1 parent aae4930 commit b02b25c

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

src/main/java/fr/iamacat/optimizationsandtweaks/mixins/common/core/MixinBlockLiquid.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@
77
import net.minecraft.util.Vec3;
88
import net.minecraft.world.IBlockAccess;
99
import net.minecraft.world.World;
10+
import net.minecraft.world.biome.BiomeGenBase;
1011

1112
import org.spongepowered.asm.mixin.Mixin;
1213
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;
1320

1421
@Mixin(BlockLiquid.class)
1522
public class MixinBlockLiquid extends Block {
23+
@Unique
24+
private static final Set<Integer> NULL_BIOME_DIMENSION_CACHE = new HashSet<>();
1625

1726
protected MixinBlockLiquid(Material materialIn) {
1827
super(materialIn);
@@ -114,5 +123,29 @@ protected int getEffectiveFlowDecay(IBlockAccess blockAccess, int x, int y, int
114123

115124
return -1;
116125
}
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+
}
118151
}

0 commit comments

Comments
 (0)