mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 16:54:22 +00:00
Deprecate EventBusMigrationHelper for removal (#10908)
Migrating away from this should be trivial for mod devs. Refer to the PR for details.
This commit is contained in:
1 parent
da7e5f8bfa
commit
4cfa1f83c4
3 files changed
+38
-15
No files matched your search
@@ -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.
|
||||
* <p>
|
||||
* Refer to the <a href="https://gist.github.com/PaintNinja/ad82c224aecee25efac1ea3e2cf19b91">migration guide</a>
|
||||
* mentioned in the <a href="https://files.minecraftforge.net">Forge 1.21.6 changelog</a> or
|
||||
* <a href="https://forums.minecraftforge.net/topic/159525-forge-581-minecraft-1218/">1.21.8 announcement</a> on the
|
||||
* forums, or ask in <a href="https://discord.minecraftforge.net">the Forge Discord</a> for help with migrating your mod
|
||||
* to the new system.
|
||||
* </p>
|
||||
* <p>
|
||||
* You can also check the updated example code in <a href="https://files.minecraftforge.net">the MDK</a> 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);
|
||||
|
||||
|
||||
@@ -39,7 +39,12 @@ public class MinecraftForge {
|
||||
* <p>Events marked with {@link IModBusEvent} belong on the
|
||||
* {@linkplain FMLJavaModLoadingContext#getModBusGroup() mod BusGroup} and not on the
|
||||
* {@linkplain BusGroup#DEFAULT default BusGroup}.</p>
|
||||
*
|
||||
* @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();
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user