From 917123658121294f3ab9432081159610d8e09aca Mon Sep 17 00:00:00 2001
From: Adrian Siekierka <kontakt@asie.pl>
Date: Fri, 14 Dec 2018 20:16:20 +0100
Subject: [PATCH] fix backwards compat HandlerList name; fix 18w50a BiomeColors
 bug

---
 .../fabric/events/PlayerInteractionEvent.java |  2 +-
 .../fabric/mixin/bugfix/MixinBiomeColors.java | 39 +++++++++++++++++++
 .../{HanderList.java => HandlerList.java}     |  4 +-
 .../net.fabricmc.fabric.mixins.client.json    |  1 +
 4 files changed, 43 insertions(+), 3 deletions(-)
 create mode 100644 src/main/java/net/fabricmc/fabric/mixin/bugfix/MixinBiomeColors.java
 rename src/main/java/net/fabricmc/fabric/util/{HanderList.java => HandlerList.java} (93%)

diff --git a/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java b/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java
index 016367332..70b5a97f1 100644
--- a/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java
+++ b/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java
@@ -74,7 +74,7 @@ public final class PlayerInteractionEvent {
 	public static final HandlerRegistry<Entity> ATTACK_ENTITY = new HandlerArray<>(Entity.class);
 	
 	// TODO: For completeness' sake, but requires us to add a custom packet. Is it worth the complexity?
-	/* public static final HandlerRegistry<Item> ATTACK_ITEM = new HanderList<>(); */
+	/* public static final HandlerRegistry<Item> ATTACK_ITEM = new HandlerList<>(); */
 
 	/**
 	 * Event emitted when a player interacts with a block.
diff --git a/src/main/java/net/fabricmc/fabric/mixin/bugfix/MixinBiomeColors.java b/src/main/java/net/fabricmc/fabric/mixin/bugfix/MixinBiomeColors.java
new file mode 100644
index 000000000..57064bc0a
--- /dev/null
+++ b/src/main/java/net/fabricmc/fabric/mixin/bugfix/MixinBiomeColors.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016, 2017, 2018 FabricMC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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 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.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();
+		}
+	}
+}
diff --git a/src/main/java/net/fabricmc/fabric/util/HanderList.java b/src/main/java/net/fabricmc/fabric/util/HandlerList.java
similarity index 93%
rename from src/main/java/net/fabricmc/fabric/util/HanderList.java
rename to src/main/java/net/fabricmc/fabric/util/HandlerList.java
index ed12bbdfc..cee84082c 100644
--- a/src/main/java/net/fabricmc/fabric/util/HanderList.java
+++ b/src/main/java/net/fabricmc/fabric/util/HandlerList.java
@@ -22,12 +22,12 @@ import java.lang.reflect.Array;
  * @deprecated Use HandlerArray.
  */
 @Deprecated
-public class HanderList<T> implements HandlerRegistry<T> {
+public class HandlerList<T> implements HandlerRegistry<T> {
 	private final Class tClass;
 	private T[] array;
 
 	@SuppressWarnings("unchecked")
-	public HanderList(Class theClass) {
+	public HandlerList(Class theClass) {
 		this.tClass = theClass;
 		this.array = (T[]) Array.newInstance(tClass, 0);
 	}
diff --git a/src/main/resources/net.fabricmc.fabric.mixins.client.json b/src/main/resources/net.fabricmc.fabric.mixins.client.json
index c9e5d4ca0..102b0307d 100644
--- a/src/main/resources/net.fabricmc.fabric.mixins.client.json
+++ b/src/main/resources/net.fabricmc.fabric.mixins.client.json
@@ -4,6 +4,7 @@
   "compatibilityLevel": "JAVA_8",
   "mixins": [
     "block.entity.MixinClientPlayNetworkHandler",
+    "bugfix.MixinBiomeColors",
     "client.render.MixinBlockEntityRenderManager",
     "client.render.MixinEntityRenderManager",
     "client.texture.MixinSpriteAtlasTexture",