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 <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2020-07-27 17:36:30 -04:00
parent 849e718a42
commit 532d153d33
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7
12 changed files with 48 additions and 25 deletions

View file

@ -444,10 +444,10 @@ project(':forge') {
installer 'org.ow2.asm:asm-tree:7.2'
installer 'org.ow2.asm:asm-util:7.2'
installer 'org.ow2.asm:asm-analysis:7.2'
installer 'cpw.mods:modlauncher:5.1.+'
installer 'cpw.mods:modlauncher:6.1.+'
installer 'cpw.mods:grossjava9hacks:1.3.+'
installer 'net.minecraftforge:accesstransformers:2.1.+:shadowed'
installer 'net.minecraftforge:eventbus:2.2.+:service'
installer 'net.minecraftforge:accesstransformers:2.2.+:shadowed'
installer 'net.minecraftforge:eventbus:3.0.+:service'
installer 'net.minecraftforge:forgespi:3.0.+'
installer 'net.minecraftforge:coremods:2.0.+'
installer 'net.minecraftforge:unsafe:0.2.+'

View file

@ -58,10 +58,10 @@ public class CapabilityInjectDefinalize implements ILaunchPluginService {
}
@Override
public boolean processClass(Phase phase, ClassNode classNode, Type classType)
public int processClassWithFlags(final Phase phase, final ClassNode classNode, final Type classType, final String reason)
{
final int flags = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
AtomicBoolean changed = new AtomicBoolean();
final AtomicBoolean changed = new AtomicBoolean();
classNode.fields.stream().filter(f -> ((f.access & flags) == flags) && f.desc.equals(CAP) && hasHolder(f.visibleAnnotations)).forEach(f ->
{
int prev = f.access;
@ -70,7 +70,7 @@ public class CapabilityInjectDefinalize implements ILaunchPluginService {
changed.compareAndSet(false, prev != f.access);
});
return changed.get();
return changed.get() ? ComputeFlags.SIMPLE_REWRITE : ComputeFlags.NO_REWRITE;
}
}

View file

@ -73,9 +73,9 @@ public class ObjectHolderDefinalize implements ILaunchPluginService {
}
@Override
public boolean processClass(Phase phase, ClassNode classNode, Type classType)
public int processClassWithFlags(final Phase phase, final ClassNode classNode, final Type classType, final String reason)
{
AtomicBoolean changes = new AtomicBoolean();
final AtomicBoolean changes = new AtomicBoolean();
//Must be public static finals, and non-array objects
final int flags = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
@ -107,7 +107,7 @@ public class ObjectHolderDefinalize implements ILaunchPluginService {
changes.compareAndSet(false, prev != f.access);
});
}
return changes.get();
return changes.get() ? ComputeFlags.SIMPLE_REWRITE : ComputeFlags.NO_REWRITE;
}
}

View file

@ -69,10 +69,10 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
}
@Override
public boolean processClass(Phase phase, ClassNode classNode, Type classType)
public int processClassWithFlags(final Phase phase, final ClassNode classNode, final Type classType, final String reason)
{
if ((classNode.access & Opcodes.ACC_ENUM) == 0)
return false;
return ComputeFlags.NO_REWRITE;
Type array = Type.getType("[" + classType.getDescriptor());
final int flags = Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC;
@ -80,7 +80,7 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
FieldNode values = classNode.fields.stream().filter(f -> f.desc.contentEquals(array.getDescriptor()) && ((f.access & flags) == flags)).findFirst().orElse(null);
if (!classNode.interfaces.contains(MARKER_IFACE.getInternalName())) {
return false;
return ComputeFlags.NO_REWRITE;
}
//Static methods named "create" with first argument as a string
@ -98,8 +98,8 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
if (args.length == 0 || !args[0].equals(STRING)) {
LOGGER.fatal(()->new AdvancedLogMessageAdapter(sb-> {
sb.append("Enum has create method without String as first parameter:\n");
sb.append(" Enum: " + classType.getDescriptor()).append("\n");
sb.append(" Target: ").append(mtd.name + mtd.desc).append("\n");
sb.append(" Enum: ").append(classType.getDescriptor()).append("\n");
sb.append(" Target: ").append(mtd.name).append(mtd.desc).append("\n");
}));
throw new IllegalStateException("Enum has create method without String as first parameter: " + mtd.name + mtd.desc);
}
@ -108,8 +108,8 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
if (!ret.equals(classType)) {
LOGGER.fatal(()->new AdvancedLogMessageAdapter(sb-> {
sb.append("Enum has create method with incorrect return type:\n");
sb.append(" Enum: " + classType.getDescriptor()).append("\n");
sb.append(" Target: ").append(mtd.name + mtd.desc).append("\n");
sb.append(" Enum: ").append(classType.getDescriptor()).append("\n");
sb.append(" Target: ").append(mtd.name).append(mtd.desc).append("\n");
sb.append(" Found: ").append(ret.getClassName()).append(", Expected: ").append(classType.getClassName());
}));
throw new IllegalStateException("Enum has create method with incorrect return type: " + mtd.name + mtd.desc);
@ -223,7 +223,7 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
ins.areturn(classType);
}
});
return true;
return ComputeFlags.COMPUTE_FRAMES;
}
}

View file

@ -233,7 +233,7 @@ public class FMLLoader
public static void addAccessTransformer(Path atPath, ModFile modName)
{
LOGGER.debug(SCAN, "Adding Access Transformer in {}", modName.getFilePath());
accessTransformer.addResource(atPath, modName.getFileName());
accessTransformer.offerResource(atPath, modName.getFileName());
}
public static Dist getDist()

View file

@ -62,7 +62,7 @@ public class RuntimeDistCleaner implements ILaunchPluginService
}
@Override
public boolean processClass(Phase phase, ClassNode classNode, Type classType)
public int processClassWithFlags(final Phase phase, final ClassNode classNode, final Type classType, final String reason)
{
AtomicBoolean changes = new AtomicBoolean();
if (remove(classNode.visibleAnnotations, DIST))
@ -147,7 +147,7 @@ public class RuntimeDistCleaner implements ILaunchPluginService
}
}
}
return changes.get();
return changes.get() ? ComputeFlags.SIMPLE_REWRITE : ComputeFlags.NO_REWRITE;
}
@SuppressWarnings("unchecked")

View file

@ -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);

View file

@ -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) {

View file

@ -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 {
}

View file

@ -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;

View file

@ -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;

View file

@ -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.
*/