forked from FabricMC/fabric
attempt #2 at working around BiomeColors crash
This commit is contained in:
parent
12b3189f7d
commit
9818bdc49c
2 changed files with 12 additions and 7 deletions
|
@ -26,6 +26,7 @@ import net.minecraft.util.ActionResult;
|
|||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -19,21 +19,25 @@ package net.fabricmc.fabric.mixin.bugfix;
|
|||
import net.minecraft.client.render.block.BiomeColors;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ExtendedBlockView;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biomes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(BiomeColors.class)
|
||||
public class MixinBiomeColors {
|
||||
// As of 18w50a, BiomeColors.colorAt violates Mojang's contract and doesn't check for the view (or position!) being null.
|
||||
// In some cases we could probably live with var1 being null, but...
|
||||
@Inject(at = @At("HEAD"), method = "colorAt", cancellable = true)
|
||||
private static void colorAt(ExtendedBlockView var0, BlockPos var1, @Coerce Object var2, CallbackInfoReturnable<Integer> info) {
|
||||
if (var0 == null || var1 == null) {
|
||||
info.setReturnValue(-1);
|
||||
info.cancel();
|
||||
// Apparently, ExtendedBlockView.getBiome() is null sometimes. Huh?
|
||||
@Redirect(method = "colorAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/ExtendedBlockView;getBiome(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/world/biome/Biome;"))
|
||||
private static Biome getBiome(ExtendedBlockView view, BlockPos pos) {
|
||||
Biome biome = view.getBiome(pos);
|
||||
if (biome == null) {
|
||||
return Biomes.DEFAULT;
|
||||
} else {
|
||||
return biome;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue