Move more events away from the mod BusGroup (#10676)

Also adds more validation to strict mode. See the GitHub PR for further details.
This commit is contained in:
Paint_Ninja authored and GitHub committed 2025-10-05 14:02:45 +01:00
1 parent 58aa3b276c
commit 9a022d1451
52 files changed
+351 -309

No files matched your search

@@ -790,9 +790,9 @@ public final class ForgeHooks {
@Deprecated
public static void modifyAttributes() {
ModLoader.postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
EntityAttributeCreationEvent.BUS.post(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
Map<EntityType<? extends LivingEntity>, AttributeSupplier.Builder> finalMap = new HashMap<>();
ModLoader.postEvent(new EntityAttributeModificationEvent(finalMap));
EntityAttributeModificationEvent.BUS.post(new EntityAttributeModificationEvent(finalMap));
finalMap.forEach((k, v) -> {
AttributeSupplier supplier = DefaultAttributes.getSupplier(k);
@@ -1066,7 +1066,7 @@ public final class ForgeHooks {
entries.put(stack, vis);
});
ModLoader.postEvent(new BuildCreativeModeTabContentsEvent(tab, tabKey, params, entries));
BuildCreativeModeTabContentsEvent.BUS.post(new BuildCreativeModeTabContentsEvent(tab, tabKey, params, entries));
for (var entry : entries)
output.accept(entry.getKey(), entry.getValue());
@@ -386,7 +386,7 @@ public class ForgeMod {
BusGroup modBusGroup = context.getModBusGroup();
// Forge-provided datapack registries
DataPackRegistryEvent.NewRegistry.getBus(modBusGroup).addListener(event -> {
DataPackRegistryEvent.NewRegistry.BUS.addListener(event -> {
event.dataPackRegistry(ForgeRegistries.Keys.BIOME_MODIFIERS, BiomeModifier.DIRECT_CODEC);
event.dataPackRegistry(ForgeRegistries.Keys.STRUCTURE_MODIFIERS, StructureModifier.DIRECT_CODEC);
});
@@ -395,7 +395,7 @@ public class ForgeMod {
var registerEventBus = RegisterEvent.getBus(modBusGroup);
registerEventBus.addListener(ForgeMod::registerFluids);
registerEventBus.addListener(ForgeMod::registerVanillaDisplayContexts);
EntityAttributeModificationEvent.getBus(modBusGroup).addListener(ForgeMod::onRegisterAttributes);
EntityAttributeModificationEvent.BUS.addListener(ForgeMod::onRegisterAttributes);
ForgeDeferredRegistriesSetup.setup(modBusGroup);
for (var reg : registries)
reg.register(modBusGroup);
@@ -9,6 +9,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.Logging;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.forgespi.language.ModFileScanData;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.ApiStatus;
@@ -91,7 +92,7 @@ public final class CapabilityManager {
var autos = modlist.getAllScanData().stream()
.flatMap(e -> e.getAnnotations().stream())
.filter(a -> AUTO_REGISTER.equals(a.annotationType()))
.map(a -> a.clazz())
.map(ModFileScanData.AnnotationData::clazz)
.distinct()
.sorted(Comparator.comparing(Type::toString))
.toList();
@@ -102,8 +103,7 @@ public final class CapabilityManager {
}
@SuppressWarnings("removal")
var event = new RegisterCapabilitiesEvent();
ModLoader.postEvent(event);
var event = RegisterCapabilitiesEvent.BUS.fire(new RegisterCapabilitiesEvent());
}
private static void error(String message) {
@@ -9,10 +9,10 @@ import java.util.Objects;
import net.minecraftforge.eventbus.api.bus.BusGroup;
import net.minecraftforge.eventbus.api.bus.EventBus;
import net.minecraftforge.eventbus.api.event.RecordEvent;
import org.jspecify.annotations.NullMarked;
import org.objectweb.asm.Type;
import net.minecraftforge.fml.event.IModBusEvent;
/**
* This event fires when it is time to register your capabilities.
* @see Capability
@@ -20,9 +20,13 @@ import net.minecraftforge.fml.event.IModBusEvent;
* @deprecated Use {@link AutoRegisterCapability} annotation on your class.
*/
@Deprecated(forRemoval = true, since = "1.21")
public final class RegisterCapabilitiesEvent implements IModBusEvent {
@NullMarked
public record RegisterCapabilitiesEvent() implements RecordEvent {
public static final EventBus<RegisterCapabilitiesEvent> BUS = EventBus.create(RegisterCapabilitiesEvent.class);
@Deprecated(forRemoval = true, since = "1.21.9")
public static EventBus<RegisterCapabilitiesEvent> getBus(BusGroup modBusGroup) {
return IModBusEvent.getBus(modBusGroup, RegisterCapabilitiesEvent.class);
return BUS;
}
/**