From 4cfa1f83c4d5b7c3ef8bfb243523f69b09b21701 Mon Sep 17 00:00:00 2001 From: Paint_Ninja Date: Mon, 2 Nov 2026 12:59:01 +0000 Subject: [PATCH] Deprecate EventBusMigrationHelper for removal (#10908) Migrating away from this should be trivial for mod devs. Refer to the PR for details. --- .../common/EventBusMigrationHelper.java | 28 ++++++++++--------- .../minecraftforge/common/MinecraftForge.java | 5 ++++ .../extensions/IForgeGameTestHelper.java | 20 +++++++++++-- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/minecraftforge/common/EventBusMigrationHelper.java b/src/main/java/net/minecraftforge/common/EventBusMigrationHelper.java index 002a50b637..0a85c58f52 100644 --- a/src/main/java/net/minecraftforge/common/EventBusMigrationHelper.java +++ b/src/main/java/net/minecraftforge/common/EventBusMigrationHelper.java @@ -14,19 +14,21 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.util.Collection; -/** - * A small helper class to aid Forge modders in migrating from EventBus 6 to the new EventBus 7. - *

- * Refer to the migration guide - * mentioned in the Forge 1.21.6 changelog or - * 1.21.8 announcement on the - * forums, or ask in the Forge Discord for help with migrating your mod - * to the new system. - *

- *

- * You can also check the updated example code in the MDK for the MC - * version you're using. - */ +/// A small helper class to aid Forge modders in migrating from EventBus 6 to the new EventBus 7. +/// +/// Refer to the [migration guide](https://gist.github.com/PaintNinja/ad82c224aecee25efac1ea3e2cf19b91) +/// mentioned in the [Forge 1.21.6 changelog](https://files.minecraftforge.net) or +/// [1.21.8 announcement](https://forums.minecraftforge.net/topic/159525-forge-581-minecraft-1218/) on the +/// forums, or ask in [the Forge Discord](https://discord.minecraftforge.net) for help with migrating your mod +/// to the new system. +/// +/// You can also check the updated example code in [the MDK](https://files.minecraftforge.net) for the MC +/// version you're using. +/// +/// @deprecated This was intended as a temporary solution to help modders migrate to the new event system. It relies on +/// JDK internals that may break without notice and will be removed in 26.4. +/// Replace `MinecraftForge.EVENT_BUS.register(...)` with `BusGroup.DEFAULT.register(MethodHandles.lookup(), ...)`. +@Deprecated(forRemoval = true, since = "26.4") public final class EventBusMigrationHelper { public static final EventBusMigrationHelper INSTANCE = new EventBusMigrationHelper(BusGroup.DEFAULT); diff --git a/src/main/java/net/minecraftforge/common/MinecraftForge.java b/src/main/java/net/minecraftforge/common/MinecraftForge.java index 2a6093a3ca..5c4288154d 100644 --- a/src/main/java/net/minecraftforge/common/MinecraftForge.java +++ b/src/main/java/net/minecraftforge/common/MinecraftForge.java @@ -39,7 +39,12 @@ public class MinecraftForge { *

Events marked with {@link IModBusEvent} belong on the * {@linkplain FMLJavaModLoadingContext#getModBusGroup() mod BusGroup} and not on the * {@linkplain BusGroup#DEFAULT default BusGroup}.

+ * + * @deprecated This was intended as a temporary solution to help modders migrate to the new event system. + * It relies on JDK internals that may break without notice and will be removed in 26.4. + * Replace `MinecraftForge.EVENT_BUS.register(...)` with `BusGroup.DEFAULT.register(MethodHandles.lookup(), ...)`. */ + @Deprecated(forRemoval = true, since = "26.4") public static final EventBusMigrationHelper EVENT_BUS = EventBusMigrationHelper.INSTANCE; private static final Logger LOGGER = LogManager.getLogger(); diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeGameTestHelper.java b/src/main/java/net/minecraftforge/common/extensions/IForgeGameTestHelper.java index ebe3958717..b3e0e09370 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeGameTestHelper.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeGameTestHelper.java @@ -5,6 +5,7 @@ package net.minecraftforge.common.extensions; +import java.lang.invoke.MethodHandles; import java.util.Arrays; import java.util.Objects; import java.util.UUID; @@ -23,6 +24,8 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; +import net.minecraftforge.eventbus.api.bus.BusGroup; +import net.minecraftforge.unsafe.UnsafeHacks; import org.jetbrains.annotations.Nullable; import com.mojang.authlib.GameProfile; @@ -205,8 +208,21 @@ public interface IForgeGameTestHelper { * Registers an event listener that will be unregistered when the test is finished running. */ default void registerEventListener(Object handler) { - var keys = MinecraftForge.EVENT_BUS.register(handler); - self().addCleanup(_ -> MinecraftForge.EVENT_BUS.unregister(keys)); + final class JdkInternalLookup { + private JdkInternalLookup() {} + private static final MethodHandles.Lookup INSTANCE; + static { + try { + var lookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); + UnsafeHacks.setAccessible(lookupField); + INSTANCE = (MethodHandles.Lookup) lookupField.get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + var keys = BusGroup.DEFAULT.register(JdkInternalLookup.INSTANCE, handler); + self().addCleanup(_ -> BusGroup.DEFAULT.unregister(keys)); } /**