diff --git a/src/main/java/net/fabricmc/fabric/events/ObjectBuilderEvent.java b/src/main/java/net/fabricmc/fabric/events/ObjectBuilderEvent.java index a22a5de67..6b813b614 100644 --- a/src/main/java/net/fabricmc/fabric/events/ObjectBuilderEvent.java +++ b/src/main/java/net/fabricmc/fabric/events/ObjectBuilderEvent.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.events; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.fabricmc.fabric.util.HandlerRegistry; import net.minecraft.block.Block; import net.minecraft.item.Item; diff --git a/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java b/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java index 5fbd5716b..016367332 100644 --- a/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java +++ b/src/main/java/net/fabricmc/fabric/events/PlayerInteractionEvent.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.events; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.fabricmc.fabric.util.HandlerRegistry; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.ActionResult; @@ -74,7 +74,7 @@ public final class PlayerInteractionEvent { public static final HandlerRegistry 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 ATTACK_ITEM = new HandlerArray<>(); */ + /* public static final HandlerRegistry ATTACK_ITEM = new HanderList<>(); */ /** * Event emitted when a player interacts with a block. diff --git a/src/main/java/net/fabricmc/fabric/events/ServerEvent.java b/src/main/java/net/fabricmc/fabric/events/ServerEvent.java index 3fbbc3d73..a02322f7c 100644 --- a/src/main/java/net/fabricmc/fabric/events/ServerEvent.java +++ b/src/main/java/net/fabricmc/fabric/events/ServerEvent.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.events; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.fabricmc.fabric.util.HandlerRegistry; import net.minecraft.server.MinecraftServer; diff --git a/src/main/java/net/fabricmc/fabric/events/TickEvent.java b/src/main/java/net/fabricmc/fabric/events/TickEvent.java index d590d734e..0c91ec243 100644 --- a/src/main/java/net/fabricmc/fabric/events/TickEvent.java +++ b/src/main/java/net/fabricmc/fabric/events/TickEvent.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.events; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.fabricmc.fabric.util.HandlerRegistry; import net.minecraft.server.MinecraftServer; import net.minecraft.util.Profiler; diff --git a/src/main/java/net/fabricmc/fabric/events/client/ClientTickEvent.java b/src/main/java/net/fabricmc/fabric/events/client/ClientTickEvent.java index 81d036bec..69f1b9ce0 100644 --- a/src/main/java/net/fabricmc/fabric/events/client/ClientTickEvent.java +++ b/src/main/java/net/fabricmc/fabric/events/client/ClientTickEvent.java @@ -17,7 +17,7 @@ package net.fabricmc.fabric.events.client; import net.fabricmc.fabric.events.TickEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.fabricmc.fabric.util.HandlerRegistry; import net.minecraft.client.MinecraftClient; diff --git a/src/main/java/net/fabricmc/fabric/events/client/SpriteEvent.java b/src/main/java/net/fabricmc/fabric/events/client/SpriteEvent.java index 5894bd484..38203fcb7 100644 --- a/src/main/java/net/fabricmc/fabric/events/client/SpriteEvent.java +++ b/src/main/java/net/fabricmc/fabric/events/client/SpriteEvent.java @@ -17,7 +17,7 @@ package net.fabricmc.fabric.events.client; import net.fabricmc.fabric.client.texture.SpriteRegistry; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.fabricmc.fabric.util.HandlerRegistry; public class SpriteEvent { 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 b6d63a289..e4640a3db 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 @@ -20,7 +20,7 @@ import com.google.common.base.Joiner; import net.fabricmc.fabric.client.texture.*; import net.fabricmc.fabric.impl.client.texture.FabricSprite; import net.fabricmc.fabric.events.client.SpriteEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.minecraft.class_1050; import net.minecraft.client.MinecraftClient; import net.minecraft.client.resource.metadata.AnimationResourceMetadata; 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 c0d702c10..287ac00bc 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 @@ -17,7 +17,7 @@ package net.fabricmc.fabric.mixin.events.objectbuilder; import net.fabricmc.fabric.events.ObjectBuilderEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.minecraft.block.Block; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; 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 90f0cb5df..9474d922e 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 @@ -17,7 +17,7 @@ package net.fabricmc.fabric.mixin.events.objectbuilder; import net.fabricmc.fabric.events.ObjectBuilderEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.minecraft.item.Item; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; 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 30d8fda40..edaf2817e 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 @@ -17,7 +17,7 @@ package net.fabricmc.fabric.mixin.events.playerinteraction; import net.fabricmc.fabric.events.PlayerInteractionEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; 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 92cfd97cb..177343fc8 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 @@ -17,7 +17,7 @@ package net.fabricmc.fabric.mixin.events.playerinteraction; import net.fabricmc.fabric.events.PlayerInteractionEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.packet.PlayerInteractEntityServerPacket; 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 8f89f0a40..9e5e91196 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 @@ -17,7 +17,7 @@ package net.fabricmc.fabric.mixin.events.playerinteraction; import net.fabricmc.fabric.events.PlayerInteractionEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.minecraft.entity.Entity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; 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 26c4c3af6..4505825d9 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 @@ -17,7 +17,7 @@ package net.fabricmc.fabric.mixin.events.playerinteraction; import net.fabricmc.fabric.events.PlayerInteractionEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.minecraft.client.network.packet.BlockUpdateClientPacket; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; 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 edd1ef2d1..07f174d90 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,7 +17,7 @@ package net.fabricmc.fabric.mixin.events.server; import net.fabricmc.fabric.events.ServerEvent; -import net.fabricmc.fabric.impl.util.HandlerArray; +import net.fabricmc.fabric.util.HandlerArray; import net.minecraft.server.MinecraftServer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/net/fabricmc/fabric/util/HanderList.java b/src/main/java/net/fabricmc/fabric/util/HanderList.java new file mode 100644 index 000000000..ed12bbdfc --- /dev/null +++ b/src/main/java/net/fabricmc/fabric/util/HanderList.java @@ -0,0 +1,53 @@ +/* + * 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.util; + +import java.lang.reflect.Array; + +/** + * @deprecated Use HandlerArray. + */ +@Deprecated +public class HanderList implements HandlerRegistry { + private final Class tClass; + private T[] array; + + @SuppressWarnings("unchecked") + public HanderList(Class theClass) { + this.tClass = theClass; + this.array = (T[]) Array.newInstance(tClass, 0); + } + + @Override + public void register(T handler) { + for (int i = 0; i < array.length; i++) { + if (array[i] == handler) { + throw new RuntimeException("Handler " + handler + " already registered!"); + } + } + + //noinspection unchecked + T[] newArray = (T[]) Array.newInstance(tClass, array.length + 1); + System.arraycopy(array, 0, newArray, 0, array.length); + newArray[array.length] = handler; + array = newArray; + } + + public T[] getBackingArray() { + return array; + } +} diff --git a/src/main/java/net/fabricmc/fabric/impl/util/HandlerArray.java b/src/main/java/net/fabricmc/fabric/util/HandlerArray.java similarity index 97% rename from src/main/java/net/fabricmc/fabric/impl/util/HandlerArray.java rename to src/main/java/net/fabricmc/fabric/util/HandlerArray.java index 809b5e5aa..084f1e0a8 100644 --- a/src/main/java/net/fabricmc/fabric/impl/util/HandlerArray.java +++ b/src/main/java/net/fabricmc/fabric/util/HandlerArray.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.impl.util; +package net.fabricmc.fabric.util; import net.fabricmc.fabric.util.HandlerRegistry;