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 void tick(HandlerRegistry> registry, T object, Profiler profiler) { - Object[] handlers = ((HandlerList>) registry).getBackingArray(); + Consumer[] handlers = ((HandlerList>) registry).getBackingArray(); if (handlers.length > 0) { profiler.begin("fabric"); int i = 0; - for (Object handler : handlers) { + for (Consumer handler : handlers) { if ((i++) == 0) { profiler.begin(handler.getClass().getName()); } else { profiler.endBegin(handler.getClass().getName()); } - //noinspection unchecked - ((Consumer) 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.PROVIDE).getBackingArray()) { - ((SpriteEvent.Provider) provider).registerSprites(registry); + for (SpriteEvent.Provider provider : ((HandlerList) 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 = "(Lnet/minecraft/block/Block$Settings;)V", at = @At("RETURN")) public void init(Block.Settings builder, CallbackInfo info) { - for (Object o : ((HandlerList>) ObjectBuilderEvent.BLOCK).getBackingArray()) { - ((BiConsumer) o).accept(builder, (Block) (Object) this); + for (BiConsumer consumer : ((HandlerList>) 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 = "(Lnet/minecraft/item/Item$Settings;)V", at = @At("RETURN")) public void init(Item.Settings builder, CallbackInfo info) { - for (Object o : ((HandlerList>) ObjectBuilderEvent.ITEM).getBackingArray()) { - ((BiConsumer) o).accept(builder, (Item) (Object) this); + for (BiConsumer consumer : ((HandlerList>) 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 info) { - for (Object handler : ((HandlerList) 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.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.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.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 info) { - Object[] backingArray = ((HandlerList) PlayerInteractionEvent.INTERACT_BLOCK).getBackingArray(); + PlayerInteractionEvent.BlockPositioned[] backingArray = ((HandlerList) 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 info) { - for (Object handler : ((HandlerList) PlayerInteractionEvent.INTERACT_ITEM).getBackingArray()) { - PlayerInteractionEvent.Item event = (PlayerInteractionEvent.Item) handler; - ActionResult result = event.interact(player, world, hand); + for (PlayerInteractionEvent.Item handler : ((HandlerList) 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.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.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.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.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.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.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.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.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.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.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 info) { - for (Object handler : ((HandlerList) 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.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 info) { - for (Object handler : ((HandlerList) PlayerInteractionEvent.INTERACT_ITEM).getBackingArray()) { - PlayerInteractionEvent.Item event = (PlayerInteractionEvent.Item) handler; - ActionResult result = event.interact(player, world, hand); + for (PlayerInteractionEvent.Item handler : ((HandlerList) 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>) ServerEvent.START).getBackingArray()) { - //noinspection unchecked - ((Consumer) handler).accept((Object) this); + for (Consumer handler : ((HandlerList>) 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 implements HandlerRegistry { 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 implements HandlerRegistry { array = newArray; } - public Object[] getBackingArray() { + public T[] getBackingArray() { return array; } }