Skip to content

Commit

Permalink
Merge remote-tracking branch 'mixin-booter-legacy/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tox1cozZ committed Jan 28, 2023
2 parents 410992f + 62138c7 commit 7693ae9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/io/github/tox1cozz/mixinbooterlegacy/LateMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.tox1cozz.mixinbooterlegacy;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface LateMixin {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import cpw.mods.fml.common.*;
import cpw.mods.fml.common.discovery.ASMDataTable;
import io.github.tox1cozz.mixinbooterlegacy.LateMixin;
import io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin;
import net.minecraft.launchwrapper.Launch;
import org.spongepowered.asm.launch.MixinInitialisationError;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.Mixins;
Expand Down Expand Up @@ -36,11 +38,15 @@ private void beforeConstructing(LoaderState state, Object[] eventData, CallbackI

MixinBooterLegacyPlugin.LOGGER.info("Instantiating all ILateMixinLoader implemented classes...");

for (ASMDataTable.ASMData asmData : asmDataTable.getAll(ILateMixinLoader.class.getName().replace('.', '/'))) {
for (ASMDataTable.ASMData asmData : asmDataTable.getAll(LateMixin.class.getName().replace('.', '/'))) {
modClassLoader.addFile(asmData.getCandidate().getModContainer()); // Add to path before `newInstance`
Class<?> clazz = Class.forName(asmData.getClassName().replace('/', '.'));
MixinBooterLegacyPlugin.LOGGER.info("Instantiating {} for its mixins.", clazz);
ILateMixinLoader loader = (ILateMixinLoader)clazz.newInstance();

if (!clazz.isAssignableFrom(ILateMixinLoader.class))
throw new MixinInitialisationError(String.format("The class %s has the LateMixin annotation, but does not implement the ILateMixinLoader interface.", clazz.getName()));

ILateMixinLoader loader = (ILateMixinLoader) clazz.newInstance();
for (String mixinConfig : loader.getMixinConfigs()) {
if (loader.shouldMixinConfigQueue(mixinConfig)) {
MixinBooterLegacyPlugin.LOGGER.info("Adding {} mixin configuration.", mixinConfig);
Expand Down

0 comments on commit 7693ae9

Please sign in to comment.