diff --git a/src/main/java/net/fabricmc/fabric/api/event/EventFactory.java b/src/main/java/net/fabricmc/fabric/api/event/EventFactory.java index 6e3697979..07eb54217 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/EventFactory.java +++ b/src/main/java/net/fabricmc/fabric/api/event/EventFactory.java @@ -17,7 +17,6 @@ package net.fabricmc.fabric.api.event; import net.fabricmc.fabric.impl.event.EventFactoryImpl; -import net.fabricmc.loader.launch.common.FabricLauncherBase; import java.util.function.Function; @@ -36,11 +35,15 @@ public final class EventFactory { EventFactoryImpl.invalidate(); } - public static Event arrayBacked(Class type, Function joiner) { - return EventFactoryImpl.arrayBacked(type, joiner); + public static Event createArrayBacked(Class type, Function joiner) { + return EventFactoryImpl.createArrayBacked(type, joiner); } - public static Event arrayBacked(Class type, T emptyInvoker, Function joiner) { - return EventFactoryImpl.arrayBacked(type, emptyInvoker, joiner); + public static Event createArrayBacked(Class type, T emptyInvoker, Function joiner) { + return EventFactoryImpl.createArrayBacked(type, emptyInvoker, joiner); + } + + public static String getHandlerName(Object event) { + return event.getClass().getName(); } } diff --git a/src/main/java/net/fabricmc/fabric/api/event/client/ClientSpriteRegistryCallback.java b/src/main/java/net/fabricmc/fabric/api/event/client/ClientSpriteRegistryCallback.java index ddbef9ce8..c5e807c83 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/client/ClientSpriteRegistryCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/client/ClientSpriteRegistryCallback.java @@ -27,7 +27,7 @@ import java.util.Map; import java.util.function.Consumer; public interface ClientSpriteRegistryCallback { - public static final Event EVENT = EventFactory.arrayBacked(ClientSpriteRegistryCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(ClientSpriteRegistryCallback.class, (listeners) -> (atlasTexture, registry) -> { for (ClientSpriteRegistryCallback callback : listeners) { callback.registerSprites(atlasTexture, registry); diff --git a/src/main/java/net/fabricmc/fabric/api/event/client/ClientTickCallback.java b/src/main/java/net/fabricmc/fabric/api/event/client/ClientTickCallback.java index 1e4d765c6..d31e904dc 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/client/ClientTickCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/client/ClientTickCallback.java @@ -18,18 +18,16 @@ package net.fabricmc.fabric.api.event.client; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; -import net.fabricmc.fabric.api.event.player.AttackBlockCallback; import net.minecraft.client.MinecraftClient; -import net.minecraft.util.ActionResult; public interface ClientTickCallback { - public static final Event EVENT = EventFactory.arrayBacked(ClientTickCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(ClientTickCallback.class, (listeners) -> { if (EventFactory.isProfilingEnabled()) { return (client) -> { client.getProfiler().push("fabricClientTick"); for (ClientTickCallback event : listeners) { - client.getProfiler().push(event.getClass().getName()); + client.getProfiler().push(EventFactory.getHandlerName(event)); event.tick(client); client.getProfiler().pop(); } diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java index 9d91e48f8..97aadfa37 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java @@ -37,7 +37,7 @@ import net.minecraft.world.World; * ATTACK_BLOCK does not let you control the packet sending process yet. */ public interface AttackBlockCallback { - public static final Event EVENT = EventFactory.arrayBacked(AttackBlockCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(AttackBlockCallback.class, (listeners) -> (player, world, hand, pos, direction) -> { for (AttackBlockCallback event : listeners) { ActionResult result = event.interact(player, world, hand, pos, direction); diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java index e835b3e86..17129cb6f 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java @@ -35,7 +35,7 @@ import net.minecraft.world.World; * - FAIL cancels further processing and does not send a packet to the server. */ public interface AttackEntityCallback { - public static final Event EVENT = EventFactory.arrayBacked(AttackEntityCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(AttackEntityCallback.class, (listeners) -> (player, world, hand, entity, hitResult) -> { for (AttackEntityCallback event : listeners) { ActionResult result = event.interact(player, world, hand, entity, hitResult); diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java index cb737cdaa..a654807a2 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java @@ -22,8 +22,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; import net.minecraft.world.World; /** @@ -36,7 +34,7 @@ import net.minecraft.world.World; * - FAIL cancels further processing and does not send a packet to the server. */ public interface UseBlockCallback { - public static final Event EVENT = EventFactory.arrayBacked(UseBlockCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(UseBlockCallback.class, (listeners) -> (player, world, hand, hitResult) -> { for (UseBlockCallback event : listeners) { ActionResult result = event.interact(player, world, hand, hitResult); diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java index 83f4305c4..4cde9dc5c 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java @@ -35,7 +35,7 @@ import net.minecraft.world.World; * - FAIL cancels further processing and does not send a packet to the server. */ public interface UseEntityCallback { - public static final Event EVENT = EventFactory.arrayBacked(UseEntityCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(UseEntityCallback.class, (listeners) -> (player, world, hand, entity, hitResult) -> { for (UseEntityCallback event : listeners) { ActionResult result = event.interact(player, world, hand, entity, hitResult); diff --git a/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java b/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java index c7a7bb28b..10c4cfc52 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java @@ -33,7 +33,7 @@ import net.minecraft.world.World; * - FAIL cancels further processing and does not send a packet to the server. */ public interface UseItemCallback { - public static final Event EVENT = EventFactory.arrayBacked(UseItemCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(UseItemCallback.class, (listeners) -> (player, world, hand) -> { for (UseItemCallback event : listeners) { ActionResult result = event.interact(player, world, hand); diff --git a/src/main/java/net/fabricmc/fabric/api/event/registry/BlockConstructedCallback.java b/src/main/java/net/fabricmc/fabric/api/event/registry/BlockConstructedCallback.java index f1b8c5a88..76d3bf801 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/registry/BlockConstructedCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/registry/BlockConstructedCallback.java @@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.block.Block; public interface BlockConstructedCallback { - public static Event EVENT = EventFactory.arrayBacked(BlockConstructedCallback.class, + public static Event EVENT = EventFactory.createArrayBacked(BlockConstructedCallback.class, (listeners) -> (settings, builtBlock) -> { for (BlockConstructedCallback callback : listeners) { callback.building(settings, builtBlock); diff --git a/src/main/java/net/fabricmc/fabric/api/event/registry/ItemConstructedCallback.java b/src/main/java/net/fabricmc/fabric/api/event/registry/ItemConstructedCallback.java index 766e81f62..311439f0b 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/registry/ItemConstructedCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/registry/ItemConstructedCallback.java @@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.item.Item; public interface ItemConstructedCallback { - public static Event EVENT = EventFactory.arrayBacked(ItemConstructedCallback.class, + public static Event EVENT = EventFactory.createArrayBacked(ItemConstructedCallback.class, (listeners) -> (settings, builtItem) -> { for (ItemConstructedCallback callback : listeners) { callback.building(settings, builtItem); diff --git a/src/main/java/net/fabricmc/fabric/api/event/server/ServerStartCallback.java b/src/main/java/net/fabricmc/fabric/api/event/server/ServerStartCallback.java index 469ff7157..7ffe4163b 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/server/ServerStartCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/server/ServerStartCallback.java @@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.server.MinecraftServer; public interface ServerStartCallback { - public static final Event EVENT = EventFactory.arrayBacked(ServerStartCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(ServerStartCallback.class, (listeners) -> (server) -> { for (ServerStartCallback event : listeners) { event.onStartServer(server); diff --git a/src/main/java/net/fabricmc/fabric/api/event/server/ServerStopCallback.java b/src/main/java/net/fabricmc/fabric/api/event/server/ServerStopCallback.java index 9cc1c5f69..758e0f13d 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/server/ServerStopCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/server/ServerStopCallback.java @@ -21,7 +21,7 @@ import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.server.MinecraftServer; public interface ServerStopCallback { - public static final Event EVENT = EventFactory.arrayBacked(ServerStopCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(ServerStopCallback.class, (listeners) -> (server) -> { for (ServerStopCallback event : listeners) { event.onStopServer(server); diff --git a/src/main/java/net/fabricmc/fabric/api/event/server/ServerTickCallback.java b/src/main/java/net/fabricmc/fabric/api/event/server/ServerTickCallback.java index 54f325364..7582548ee 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/server/ServerTickCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/server/ServerTickCallback.java @@ -21,13 +21,13 @@ import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.server.MinecraftServer; public interface ServerTickCallback { - public static final Event EVENT = EventFactory.arrayBacked(ServerTickCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(ServerTickCallback.class, (listeners) -> { if (EventFactory.isProfilingEnabled()) { return (server) -> { server.getProfiler().push("fabricServerTick"); for (ServerTickCallback event : listeners) { - server.getProfiler().push(event.getClass().getName()); + server.getProfiler().push(EventFactory.getHandlerName(event)); event.tick(server); server.getProfiler().pop(); } diff --git a/src/main/java/net/fabricmc/fabric/api/event/world/WorldTickCallback.java b/src/main/java/net/fabricmc/fabric/api/event/world/WorldTickCallback.java index f25c54204..9816a7ad5 100644 --- a/src/main/java/net/fabricmc/fabric/api/event/world/WorldTickCallback.java +++ b/src/main/java/net/fabricmc/fabric/api/event/world/WorldTickCallback.java @@ -21,13 +21,13 @@ import net.fabricmc.fabric.api.event.EventFactory; import net.minecraft.world.World; public interface WorldTickCallback { - public static final Event EVENT = EventFactory.arrayBacked(WorldTickCallback.class, + public static final Event EVENT = EventFactory.createArrayBacked(WorldTickCallback.class, (listeners) -> { if (EventFactory.isProfilingEnabled()) { return (world) -> { world.getProfiler().push("fabricWorldTick"); for (WorldTickCallback event : listeners) { - world.getProfiler().push(event.getClass().getName()); + world.getProfiler().push(EventFactory.getHandlerName(event)); event.tick(world); world.getProfiler().pop(); } diff --git a/src/main/java/net/fabricmc/fabric/api/network/CustomPayloadPacketRegistry.java b/src/main/java/net/fabricmc/fabric/api/network/CustomPayloadPacketRegistry.java index cbca32b25..8b7fd5cc6 100644 --- a/src/main/java/net/fabricmc/fabric/api/network/CustomPayloadPacketRegistry.java +++ b/src/main/java/net/fabricmc/fabric/api/network/CustomPayloadPacketRegistry.java @@ -19,7 +19,9 @@ package net.fabricmc.fabric.api.network; import net.minecraft.util.Identifier; import net.minecraft.util.PacketByteBuf; +import java.util.Collection; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.function.BiConsumer; @@ -34,7 +36,7 @@ public class CustomPayloadPacketRegistry { protected final Map> consumerMap; protected CustomPayloadPacketRegistry() { - consumerMap = new HashMap<>(); + consumerMap = new LinkedHashMap<>(); } /** diff --git a/src/main/java/net/fabricmc/fabric/impl/event/EventFactoryImpl.java b/src/main/java/net/fabricmc/fabric/impl/event/EventFactoryImpl.java index 2fa336d8c..5477ca069 100644 --- a/src/main/java/net/fabricmc/fabric/impl/event/EventFactoryImpl.java +++ b/src/main/java/net/fabricmc/fabric/impl/event/EventFactoryImpl.java @@ -19,7 +19,6 @@ package net.fabricmc.fabric.impl.event; import net.fabricmc.fabric.api.event.Event; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandleProxies; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.*; @@ -38,11 +37,11 @@ public final class EventFactoryImpl { ARRAY_BACKED_EVENTS.forEach(ArrayBackedEvent::update); } - public static Event arrayBacked(Class type, Function joiner) { - return arrayBacked(type, null /* buildEmptyInvoker(type, joiner) */, joiner); + public static Event createArrayBacked(Class type, Function joiner) { + return createArrayBacked(type, null /* buildEmptyInvoker(type, joiner) */, joiner); } - public static Event arrayBacked(Class type, T emptyInvoker, Function joiner) { + public static Event createArrayBacked(Class type, T emptyInvoker, Function joiner) { ArrayBackedEvent event = new ArrayBackedEvent<>(type, emptyInvoker, joiner); ARRAY_BACKED_EVENTS.add(event); return event; diff --git a/src/main/java/net/fabricmc/fabric/mixin/registry/MixinServerPlayNetworkHandler.java b/src/main/java/net/fabricmc/fabric/mixin/registry/MixinServerPlayNetworkHandler.java index 4546c9bb7..506c65645 100644 --- a/src/main/java/net/fabricmc/fabric/mixin/registry/MixinServerPlayNetworkHandler.java +++ b/src/main/java/net/fabricmc/fabric/mixin/registry/MixinServerPlayNetworkHandler.java @@ -35,9 +35,7 @@ public abstract class MixinServerPlayNetworkHandler { @Inject(method = "", at = @At("RETURN")) public void init(MinecraftServer server, ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) { - //if (server.isDedicated()) { - // TODO: If integrated and local, don't send the packet + // TODO: If integrated and local, don't send the packet (it's ignored) sendPacket(RegistrySyncManager.createPacket()); - //} } }