mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 03:25:18 +00:00
Update modlauncher, eventbus, accesstransformers and more to use a newer mechanism for generating ASM.
Introduced IModBusEvent as a marker interface for events on the ModBus. Expect exceptions if you use the modbus for events not listened there. Signed-off-by: cpw <[email protected]>
This commit is contained in:
12 files changed
+48
-25
No files matched your search
@@ -22,6 +22,7 @@ package net.minecraftforge.event;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -35,7 +36,7 @@ import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
/**
|
||||
* RegistryEvent supertype.
|
||||
*/
|
||||
public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEvent<T>
|
||||
public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEvent<T> implements IModBusEvent
|
||||
{
|
||||
RegistryEvent(Class<T> clazz) {
|
||||
super(clazz);
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
|
||||
import net.minecraftforge.fml.loading.StringUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -133,7 +134,7 @@ public class ModConfig
|
||||
}
|
||||
}
|
||||
|
||||
public static class ModConfigEvent extends Event {
|
||||
public static class ModConfigEvent extends Event implements IModBusEvent {
|
||||
private final ModConfig config;
|
||||
|
||||
ModConfigEvent(final ModConfig config) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.minecraftforge.fml.event.lifecycle;
|
||||
|
||||
/**
|
||||
* Marker interface for events dispatched on the ModLifecycle event bus instead of the primary event bus
|
||||
*/
|
||||
public interface IModBusEvent {
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import java.util.stream.Stream;
|
||||
* Parent type to all ModLifecycle events. This is based on Forge EventBus. They fire through the
|
||||
* ModContainer's eventbus instance.
|
||||
*/
|
||||
public class ModLifecycleEvent extends Event
|
||||
public class ModLifecycleEvent extends Event implements IModBusEvent
|
||||
{
|
||||
private final ModContainer container;
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ import net.minecraftforge.fml.LifecycleEventProvider;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingException;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.ModLifecycleEvent;
|
||||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
import net.minecraftforge.forgespi.language.ModFileScanData;
|
||||
|
||||
@@ -62,7 +64,7 @@ public class FMLModContainer extends ModContainer
|
||||
triggerMap.put(ModLoadingStage.PROCESS_IMC, dummy().andThen(this::beforeEvent).andThen(this::fireEvent).andThen(this::afterEvent));
|
||||
triggerMap.put(ModLoadingStage.COMPLETE, dummy().andThen(this::beforeEvent).andThen(this::completeLoading).andThen(this::fireEvent).andThen(this::afterEvent));
|
||||
triggerMap.put(ModLoadingStage.GATHERDATA, dummy().andThen(this::beforeEvent).andThen(this::fireEvent).andThen(this::afterEvent));
|
||||
this.eventBus = BusBuilder.builder().setExceptionHandler(this::onEventFailed).setTrackPhases(false).build();
|
||||
this.eventBus = BusBuilder.builder().setExceptionHandler(this::onEventFailed).setTrackPhases(false).markerType(IModBusEvent.class).build();
|
||||
this.configHandler = Optional.of(event -> this.eventBus.post(event));
|
||||
final FMLJavaModLoadingContext contextExtension = new FMLJavaModLoadingContext(this);
|
||||
this.contextExtension = () -> contextExtension;
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -154,12 +155,23 @@ public class DeferredRegister<T extends IForgeRegistryEntry<T>>
|
||||
*/
|
||||
public void register(IEventBus bus)
|
||||
{
|
||||
bus.addListener(this::addEntries);
|
||||
bus.register(new EventDispatcher(this));
|
||||
if (this.type == null && this.registryFactory != null) {
|
||||
bus.addListener(this::createRegistry);
|
||||
}
|
||||
}
|
||||
public static class EventDispatcher {
|
||||
private final DeferredRegister<?> register;
|
||||
|
||||
public EventDispatcher(final DeferredRegister<?> register) {
|
||||
this.register = register;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handleEvent(RegistryEvent.Register<?> event) {
|
||||
register.addEntries(event);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return The unmodifiable view of registered entries. Useful for bulk operations on all values.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user