From b0a654abd6e3a090d45c31cbf39af92d9265779c Mon Sep 17 00:00:00 2001
From: kashike <kashike@vq.lc>
Date: Mon, 10 Dec 2018 03:20:37 -0800
Subject: [PATCH] Be more specific with return type

---
 .../net/fabricmc/fabric/events/TickEvent.java |  7 ++--
 .../texture/MixinSpriteAtlasTexture.java      |  4 +--
 .../events/objectbuilder/MixinBlock.java      |  4 +--
 .../mixin/events/objectbuilder/MixinItem.java |  4 +--
 .../MixinClientPlayerInteractionManager.java  | 32 ++++++++-----------
 .../MixinServerPlayNetworkHandler.java        | 14 ++------
 .../MixinServerPlayerEntity.java              |  8 ++---
 .../MixinServerPlayerInteractionManager.java  | 15 ++++-----
 .../events/server/MixinMinecraftServer.java   |  9 ++----
 .../net/fabricmc/fabric/util/HandlerList.java |  6 ++--
 10 files changed, 37 insertions(+), 66 deletions(-)

diff --git a/src/main/java/net/fabricmc/fabric/events/TickEvent.java b/src/main/java/net/fabricmc/fabric/events/TickEvent.java
index 33bd7c9eb..b179aa2f1 100644
--- a/src/main/java/net/fabricmc/fabric/events/TickEvent.java
+++ b/src/main/java/net/fabricmc/fabric/events/TickEvent.java
@@ -37,19 +37,18 @@ public final class TickEvent {
 	}
 
 	public static <T> void tick(HandlerRegistry<Consumer<T>> registry, T object, Profiler profiler) {
-		Object[] handlers = ((HandlerList<Consumer<T>>) registry).getBackingArray();
+		Consumer<T>[] handlers = ((HandlerList<Consumer<T>>) registry).getBackingArray();
 		if (handlers.length > 0) {
 			profiler.begin("fabric");
 
 			int i = 0;
-			for (Object handler : handlers) {
+			for (Consumer<T> handler : handlers) {
 				if ((i++) == 0) {
 					profiler.begin(handler.getClass().getName());
 				} else {
 					profiler.endBegin(handler.getClass().getName());
 				}
-				//noinspection unchecked
-				((Consumer<T>) handler).accept(object);
+				handler.accept(object);
 			}
 
 			if (i > 0) {
diff --git a/src/main/java/net/fabricmc/fabric/mixin/client/texture/MixinSpriteAtlasTexture.java b/src/main/java/net/fabricmc/fabric/mixin/client/texture/MixinSpriteAtlasTexture.java
index a892aa373..269c54a4f 100644
--- a/src/main/java/net/fabricmc/fabric/mixin/client/texture/MixinSpriteAtlasTexture.java
+++ b/src/main/java/net/fabricmc/fabric/mixin/client/texture/MixinSpriteAtlasTexture.java
@@ -85,8 +85,8 @@ public abstract class MixinSpriteAtlasTexture {
 		//noinspection RedundantCast,ConstantConditions
 		if ((SpriteAtlasTexture) (Object) this == MinecraftClient.getInstance().getSpriteAtlas()) {
 			SpriteRegistry registry = new SpriteRegistry(sprites, (id) -> addSpriteToLoad(manager, id));
-			for (Object provider : ((HandlerList<SpriteEvent.Provider>) SpriteEvent.PROVIDE).getBackingArray()) {
-				((SpriteEvent.Provider) provider).registerSprites(registry);
+			for (SpriteEvent.Provider provider : ((HandlerList<SpriteEvent.Provider>) SpriteEvent.PROVIDE).getBackingArray()) {
+				provider.registerSprites(registry);
 			}
 		}
 
diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinBlock.java b/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinBlock.java
index 25b8bd091..71d4da445 100644
--- a/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinBlock.java
+++ b/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinBlock.java
@@ -30,8 +30,8 @@ import java.util.function.BiConsumer;
 public class MixinBlock {
 	@Inject(method = "<init>(Lnet/minecraft/block/Block$Settings;)V", at = @At("RETURN"))
 	public void init(Block.Settings builder, CallbackInfo info) {
-		for (Object o : ((HandlerList<BiConsumer<Block.Settings, Block>>) ObjectBuilderEvent.BLOCK).getBackingArray()) {
-			((BiConsumer<Block.Settings, Block>) o).accept(builder, (Block) (Object) this);
+		for (BiConsumer<Block.Settings, Block> consumer : ((HandlerList<BiConsumer<Block.Settings, Block>>) ObjectBuilderEvent.BLOCK).getBackingArray()) {
+			consumer.accept(builder, (Block) (Object) this);
 		}
 	}
 }
diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinItem.java b/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinItem.java
index 04ed38446..18b1589da 100644
--- a/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinItem.java
+++ b/src/main/java/net/fabricmc/fabric/mixin/events/objectbuilder/MixinItem.java
@@ -30,8 +30,8 @@ import java.util.function.BiConsumer;
 public class MixinItem {
 	@Inject(method = "<init>(Lnet/minecraft/item/Item$Settings;)V", at = @At("RETURN"))
 	public void init(Item.Settings builder, CallbackInfo info) {
-		for (Object o : ((HandlerList<BiConsumer<Item.Settings, Item>>) ObjectBuilderEvent.ITEM).getBackingArray()) {
-			((BiConsumer<Item.Settings, Item>) o).accept(builder, (Item) (Object) this);
+		for (BiConsumer<Item.Settings, Item> consumer : ((HandlerList<BiConsumer<Item.Settings, Item>>) ObjectBuilderEvent.ITEM).getBackingArray()) {
+			consumer.accept(builder, (Item) (Object) this);
 		}
 	}
 }
diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinClientPlayerInteractionManager.java b/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinClientPlayerInteractionManager.java
index 262b1ac4f..5d9a4bb9b 100644
--- a/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinClientPlayerInteractionManager.java
+++ b/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinClientPlayerInteractionManager.java
@@ -52,9 +52,8 @@ public class MixinClientPlayerInteractionManager {
 
 	@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameMode;isCreative()Z", ordinal = 0), method = "attackBlock", cancellable = true)
 	public void attackBlock(BlockPos pos, Facing facing, CallbackInfoReturnable<Boolean> info) {
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.Block>) PlayerInteractionEvent.ATTACK_BLOCK).getBackingArray()) {
-			PlayerInteractionEvent.Block event = (PlayerInteractionEvent.Block) handler;
-			ActionResult result = event.interact(client.player, client.world, Hand.MAIN, pos, facing);
+		for (PlayerInteractionEvent.Block handler : ((HandlerList<PlayerInteractionEvent.Block>) PlayerInteractionEvent.ATTACK_BLOCK).getBackingArray()) {
+			ActionResult result = handler.interact(client.player, client.world, Hand.MAIN, pos, facing);
 			if (result != ActionResult.PASS) {
 				info.setReturnValue(result == ActionResult.SUCCESS);
 				info.cancel();
@@ -69,9 +68,8 @@ public class MixinClientPlayerInteractionManager {
 			return;
 		}
 
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.Block>) PlayerInteractionEvent.ATTACK_BLOCK).getBackingArray()) {
-			PlayerInteractionEvent.Block event = (PlayerInteractionEvent.Block) handler;
-			ActionResult result = event.interact(client.player, client.world, Hand.MAIN, pos, facing);
+		for (PlayerInteractionEvent.Block handler : ((HandlerList<PlayerInteractionEvent.Block>) PlayerInteractionEvent.ATTACK_BLOCK).getBackingArray()) {
+			ActionResult result = handler.interact(client.player, client.world, Hand.MAIN, pos, facing);
 			if (result != ActionResult.PASS) {
 				info.setReturnValue(result == ActionResult.SUCCESS);
 				info.cancel();
@@ -82,15 +80,14 @@ public class MixinClientPlayerInteractionManager {
 
 	@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getStackInHand(Lnet/minecraft/util/Hand;)Lnet/minecraft/item/ItemStack;", ordinal = 0), method = "interactBlock", cancellable = true)
 	public void interactBlock(ClientPlayerEntity player, ClientWorld world, BlockPos pos, Facing facing, Vec3d vec, Hand hand, CallbackInfoReturnable<ActionResult> info) {
-		Object[] backingArray = ((HandlerList<PlayerInteractionEvent.BlockPositioned>) PlayerInteractionEvent.INTERACT_BLOCK).getBackingArray();
+		PlayerInteractionEvent.BlockPositioned[] backingArray = ((HandlerList<PlayerInteractionEvent.BlockPositioned>) PlayerInteractionEvent.INTERACT_BLOCK).getBackingArray();
 		if (backingArray.length > 0) {
 			float hitX = (float) (vec.x - pos.getX());
 			float hitY = (float) (vec.y - pos.getY());
 			float hitZ = (float) (vec.z - pos.getZ());
 
-			for (Object handler : backingArray) {
-				PlayerInteractionEvent.BlockPositioned event = (PlayerInteractionEvent.BlockPositioned) handler;
-				ActionResult result = event.interact(player, world, hand, pos, facing, hitX, hitY, hitZ);
+			for (PlayerInteractionEvent.BlockPositioned handler : backingArray) {
+				ActionResult result = handler.interact(player, world, hand, pos, facing, hitX, hitY, hitZ);
 				if (result != ActionResult.PASS) {
 					if (result == ActionResult.SUCCESS) {
 						this.networkHandler.sendPacket(new PlayerInteractBlockServerPacket(pos, facing, hand, hitX, hitY, hitZ));
@@ -105,9 +102,8 @@ public class MixinClientPlayerInteractionManager {
 
 	@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getStackInHand(Lnet/minecraft/util/Hand;)Lnet/minecraft/item/ItemStack;", ordinal = 0), method = "interactItem", cancellable = true)
 	public void interactItem(PlayerEntity player, World world, Hand hand, CallbackInfoReturnable<ActionResult> info) {
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.Item>) PlayerInteractionEvent.INTERACT_ITEM).getBackingArray()) {
-			PlayerInteractionEvent.Item event = (PlayerInteractionEvent.Item) handler;
-			ActionResult result = event.interact(player, world, hand);
+		for (PlayerInteractionEvent.Item handler : ((HandlerList<PlayerInteractionEvent.Item>) PlayerInteractionEvent.INTERACT_ITEM).getBackingArray()) {
+			ActionResult result = handler.interact(player, world, hand);
 			if (result != ActionResult.PASS) {
 				info.setReturnValue(result);
 				info.cancel();
@@ -118,9 +114,8 @@ public class MixinClientPlayerInteractionManager {
 
 	@Inject(at = @At("HEAD"), method = "attackEntity", cancellable = true)
 	public void attackEntity(PlayerEntity player, Entity entity, CallbackInfo info) {
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.Entity>) PlayerInteractionEvent.ATTACK_ENTITY).getBackingArray()) {
-			PlayerInteractionEvent.Entity event = (PlayerInteractionEvent.Entity) handler;
-			ActionResult result = event.interact(player, player.getEntityWorld(), Hand.MAIN /* TODO */, entity);
+		for (PlayerInteractionEvent.Entity handler : ((HandlerList<PlayerInteractionEvent.Entity>) PlayerInteractionEvent.ATTACK_ENTITY).getBackingArray()) {
+			ActionResult result = handler.interact(player, player.getEntityWorld(), Hand.MAIN /* TODO */, entity);
 			if (result != ActionResult.PASS) {
 				info.cancel();
 				return;
@@ -133,9 +128,8 @@ public class MixinClientPlayerInteractionManager {
 		// TODO: Remove double Vec3d creation?
 		Vec3d hitVec = new Vec3d(hitResult.pos.x - entity.x, hitResult.pos.y - entity.y, hitResult.pos.z - entity.z);
 
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.EntityPositioned>) PlayerInteractionEvent.INTERACT_ENTITY_POSITIONED).getBackingArray()) {
-			PlayerInteractionEvent.EntityPositioned event = (PlayerInteractionEvent.EntityPositioned) handler;
-			ActionResult result = event.interact(player, player.getEntityWorld(), hand, entity, hitVec);
+		for (PlayerInteractionEvent.EntityPositioned handler : ((HandlerList<PlayerInteractionEvent.EntityPositioned>) PlayerInteractionEvent.INTERACT_ENTITY_POSITIONED).getBackingArray()) {
+			ActionResult result = handler.interact(player, player.getEntityWorld(), hand, entity, hitVec);
 			if (result != ActionResult.PASS) {
 				info.setReturnValue(result);
 				info.cancel();
diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayNetworkHandler.java b/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayNetworkHandler.java
index d7e068803..427cd9238 100644
--- a/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayNetworkHandler.java
+++ b/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayNetworkHandler.java
@@ -18,24 +18,15 @@ package net.fabricmc.fabric.mixin.events.playerinteraction;
 
 import net.fabricmc.fabric.events.PlayerInteractionEvent;
 import net.fabricmc.fabric.util.HandlerList;
-import net.minecraft.client.network.packet.BlockUpdateClientPacket;
-import net.minecraft.entity.player.PlayerEntity;
-import net.minecraft.item.ItemStack;
 import net.minecraft.server.network.ServerPlayNetworkHandler;
 import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.server.network.ServerPlayerInteractionManager;
 import net.minecraft.server.network.packet.PlayerInteractEntityServerPacket;
 import net.minecraft.util.ActionResult;
-import net.minecraft.util.Hand;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Facing;
-import net.minecraft.world.World;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Shadow;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
 
 @Mixin(ServerPlayNetworkHandler.class)
 public class MixinServerPlayNetworkHandler {
@@ -44,9 +35,8 @@ public class MixinServerPlayNetworkHandler {
 
 	@Inject(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"), cancellable = true)
 	public void onPlayerInteractEntity(PlayerInteractEntityServerPacket packet, CallbackInfo info) {
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.EntityPositioned>) PlayerInteractionEvent.INTERACT_ENTITY_POSITIONED).getBackingArray()) {
-			PlayerInteractionEvent.EntityPositioned event = (PlayerInteractionEvent.EntityPositioned) handler;
-			ActionResult result = event.interact(player, player.getEntityWorld(), packet.getHand(), packet.getEntity(player.world), packet.getHitPosition());
+		for (PlayerInteractionEvent.EntityPositioned handler : ((HandlerList<PlayerInteractionEvent.EntityPositioned>) PlayerInteractionEvent.INTERACT_ENTITY_POSITIONED).getBackingArray()) {
+			ActionResult result = handler.interact(player, player.getEntityWorld(), packet.getHand(), packet.getEntity(player.world), packet.getHitPosition());
 			if (result != ActionResult.PASS) {
 				info.cancel();
 				return;
diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayerEntity.java b/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayerEntity.java
index dc3d4ffc5..f217a2be7 100644
--- a/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayerEntity.java
+++ b/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayerEntity.java
@@ -19,13 +19,10 @@ package net.fabricmc.fabric.mixin.events.playerinteraction;
 import net.fabricmc.fabric.events.PlayerInteractionEvent;
 import net.fabricmc.fabric.util.HandlerList;
 import net.minecraft.entity.Entity;
-import net.minecraft.server.network.ServerPlayNetworkHandler;
 import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.server.network.packet.PlayerInteractEntityServerPacket;
 import net.minecraft.util.ActionResult;
 import net.minecraft.util.Hand;
 import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Shadow;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -36,9 +33,8 @@ public class MixinServerPlayerEntity {
 	public void onPlayerInteractEntity(Entity target, CallbackInfo info) {
 		ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
 
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.Entity>) PlayerInteractionEvent.ATTACK_ENTITY).getBackingArray()) {
-			PlayerInteractionEvent.Entity event = (PlayerInteractionEvent.Entity) handler;
-			ActionResult result = event.interact(player, player.getEntityWorld(), Hand.MAIN, target);
+		for (PlayerInteractionEvent.Entity handler : ((HandlerList<PlayerInteractionEvent.Entity>) PlayerInteractionEvent.ATTACK_ENTITY).getBackingArray()) {
+			ActionResult result = handler.interact(player, player.getEntityWorld(), Hand.MAIN, target);
 			if (result != ActionResult.PASS) {
 				info.cancel();
 				return;
diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayerInteractionManager.java b/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayerInteractionManager.java
index bdcc7a15c..536b2857f 100644
--- a/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayerInteractionManager.java
+++ b/src/main/java/net/fabricmc/fabric/mixin/events/playerinteraction/MixinServerPlayerInteractionManager.java
@@ -44,9 +44,8 @@ public class MixinServerPlayerInteractionManager {
 
 	@Inject(at = @At("HEAD"), method = "method_14263", cancellable = true)
 	public void startBlockBreak(BlockPos pos, Facing facing, CallbackInfo info) {
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.Block>) PlayerInteractionEvent.ATTACK_BLOCK).getBackingArray()) {
-			PlayerInteractionEvent.Block event = (PlayerInteractionEvent.Block) handler;
-			ActionResult result = event.interact(player, world, Hand.MAIN, pos, facing);
+		for (PlayerInteractionEvent.Block handler : ((HandlerList<PlayerInteractionEvent.Block>) PlayerInteractionEvent.ATTACK_BLOCK).getBackingArray()) {
+			ActionResult result = handler.interact(player, world, Hand.MAIN, pos, facing);
 			if (result != ActionResult.PASS) {
 				// The client might have broken the block on its side, so make sure to let it know.
 				this.player.networkHandler.sendPacket(new BlockUpdateClientPacket(world, pos));
@@ -58,9 +57,8 @@ public class MixinServerPlayerInteractionManager {
 
 	@Inject(at = @At("HEAD"), method = "interactBlock", cancellable = true)
 	public void interactBlock(PlayerEntity player, World world, ItemStack stack, Hand hand, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, CallbackInfoReturnable<ActionResult> info) {
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.BlockPositioned>) PlayerInteractionEvent.INTERACT_BLOCK).getBackingArray()) {
-			PlayerInteractionEvent.BlockPositioned event = (PlayerInteractionEvent.BlockPositioned) handler;
-			ActionResult result = event.interact(player, world, hand, pos, facing, hitX, hitY, hitZ);
+		for (PlayerInteractionEvent.BlockPositioned handler : ((HandlerList<PlayerInteractionEvent.BlockPositioned>) PlayerInteractionEvent.INTERACT_BLOCK).getBackingArray()) {
+			ActionResult result = handler.interact(player, world, hand, pos, facing, hitX, hitY, hitZ);
 			if (result != ActionResult.PASS) {
 				info.setReturnValue(result);
 				info.cancel();
@@ -71,9 +69,8 @@ public class MixinServerPlayerInteractionManager {
 
 	@Inject(at = @At("HEAD"), method = "interactItem", cancellable = true)
 	public void interactItem(PlayerEntity player, World world, ItemStack stack, Hand hand, CallbackInfoReturnable<ActionResult> info) {
-		for (Object handler : ((HandlerList<PlayerInteractionEvent.Item>) PlayerInteractionEvent.INTERACT_ITEM).getBackingArray()) {
-			PlayerInteractionEvent.Item event = (PlayerInteractionEvent.Item) handler;
-			ActionResult result = event.interact(player, world, hand);
+		for (PlayerInteractionEvent.Item handler : ((HandlerList<PlayerInteractionEvent.Item>) PlayerInteractionEvent.INTERACT_ITEM).getBackingArray()) {
+			ActionResult result = handler.interact(player, world, hand);
 			if (result != ActionResult.PASS) {
 				info.setReturnValue(result);
 				info.cancel();
diff --git a/src/main/java/net/fabricmc/fabric/mixin/events/server/MixinMinecraftServer.java b/src/main/java/net/fabricmc/fabric/mixin/events/server/MixinMinecraftServer.java
index 9d4369114..4ab15184a 100644
--- a/src/main/java/net/fabricmc/fabric/mixin/events/server/MixinMinecraftServer.java
+++ b/src/main/java/net/fabricmc/fabric/mixin/events/server/MixinMinecraftServer.java
@@ -17,26 +17,21 @@
 package net.fabricmc.fabric.mixin.events.server;
 
 import net.fabricmc.fabric.events.ServerEvent;
-import net.fabricmc.fabric.events.TickEvent;
 import net.fabricmc.fabric.util.HandlerList;
-import net.minecraft.class_3689;
 import net.minecraft.server.MinecraftServer;
 import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Shadow;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 
-import java.util.function.BooleanSupplier;
 import java.util.function.Consumer;
 
 @Mixin(MinecraftServer.class)
 public class MixinMinecraftServer {
 	@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;method_3791(Lnet/minecraft/server/ServerMetadata;)V", ordinal = 0), method = "run")
 	public void afterSetupServer(CallbackInfo info) {
-		for (Object handler : ((HandlerList<Consumer<MinecraftServer>>) ServerEvent.START).getBackingArray()) {
-			//noinspection unchecked
-			((Consumer) handler).accept((Object) this);
+		for (Consumer<MinecraftServer> handler : ((HandlerList<Consumer<MinecraftServer>>) ServerEvent.START).getBackingArray()) {
+			handler.accept((MinecraftServer) (Object) this);
 		}
 	}
 }
diff --git a/src/main/java/net/fabricmc/fabric/util/HandlerList.java b/src/main/java/net/fabricmc/fabric/util/HandlerList.java
index b4879daf8..fb9b676b6 100644
--- a/src/main/java/net/fabricmc/fabric/util/HandlerList.java
+++ b/src/main/java/net/fabricmc/fabric/util/HandlerList.java
@@ -18,11 +18,11 @@ package net.fabricmc.fabric.util;
 
 public class HandlerList<T> implements HandlerRegistry<T> {
 	private static final Object[] EMPTY = new Object[0];
-	private Object[] array;
+	private T[] array;
 
 	@SuppressWarnings("unchecked")
 	public HandlerList() {
-		this.array = EMPTY;
+		this.array = (T[]) EMPTY;
 	}
 
 	@Override
@@ -40,7 +40,7 @@ public class HandlerList<T> implements HandlerRegistry<T> {
 		array = newArray;
 	}
 
-	public Object[] getBackingArray() {
+	public T[] getBackingArray() {
 		return array;
 	}
 }