Skip to content

Commit

Permalink
transfer to early/late mixin stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru authored and kuba6000 committed Oct 2, 2024
1 parent 600ae37 commit acb2029
Show file tree
Hide file tree
Showing 48 changed files with 213 additions and 221 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ separateMixinSourceSet =
usesMixinDebug = false

# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin = mixin.MixinPlugin
mixinPlugin =

# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
mixinsPackage = mixin

# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
coreModClass =
coreModClass = mixin.EarlyMixinLoader

# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kuba6000/mobsinfo/api/MobRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.kuba6000.mobsinfo.api.helper.EnderIOHelper;
import com.kuba6000.mobsinfo.api.helper.InfernalMobsCoreHelper;
import com.kuba6000.mobsinfo.loader.MobRecipeLoader;
import com.kuba6000.mobsinfo.mixin.InfernalMobs.InfernalMobsCoreAccessor;
import com.kuba6000.mobsinfo.mixin.late.InfernalMobs.InfernalMobsCoreAccessor;

import atomicstryker.infernalmobs.common.InfernalMobsCore;
import jas.spawner.modern.MVELProfile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.minecraft.entity.boss.IBossDisplayData;

import com.kuba6000.mobsinfo.api.LoaderReference;
import com.kuba6000.mobsinfo.mixin.EnderIO.ItemSoulVesselAccessor;
import com.kuba6000.mobsinfo.mixin.late.EnderIO.ItemSoulVesselAccessor;

import crazypants.enderio.EnderIO;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.IMob;

import com.kuba6000.mobsinfo.mixin.InfernalMobs.InfernalMobsCoreAccessor;
import com.kuba6000.mobsinfo.mixin.late.InfernalMobs.InfernalMobsCoreAccessor;

import atomicstryker.infernalmobs.common.InfernalMobsCore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Rectangle;

import com.kuba6000.mobsinfo.mixin.minecraft.RendererLivingEntityAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.RendererLivingEntityAccessor;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/kuba6000/mobsinfo/api/utils/ModUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@

import com.google.common.collect.Multimap;
import com.kuba6000.mobsinfo.MobsInfo;
import com.kuba6000.mobsinfo.mixin.minecraft.ASMEventHandlerAccessor;
import com.kuba6000.mobsinfo.mixin.minecraft.EventBusAccessor;
import com.kuba6000.mobsinfo.mixin.minecraft.VillagerRegistryAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.ASMEventHandlerAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.EventBusAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.VillagerRegistryAccessor;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.kuba6000.mobsinfo.mixin.minecraft.EventBusAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.EventBusAccessor;

import cpw.mods.fml.common.eventhandler.IEventListener;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/kuba6000/mobsinfo/loader/MobRecipeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@
import com.kuba6000.mobsinfo.config.Config;
import com.kuba6000.mobsinfo.config.OverridesConfig;
import com.kuba6000.mobsinfo.loader.extras.ExtraLoader;
import com.kuba6000.mobsinfo.mixin.InfernalMobs.InfernalMobsCoreAccessor;
import com.kuba6000.mobsinfo.mixin.minecraft.EntityAccessor;
import com.kuba6000.mobsinfo.mixin.minecraft.EntityLivingAccessor;
import com.kuba6000.mobsinfo.mixin.minecraft.EntityLivingBaseAccessor;
import com.kuba6000.mobsinfo.mixin.minecraft.EntitySlimeAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.EntityAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.EntityLivingAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.EntityLivingBaseAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.EntitySlimeAccessor;
import com.kuba6000.mobsinfo.mixin.late.InfernalMobs.InfernalMobsCoreAccessor;
import com.kuba6000.mobsinfo.nei.MobHandler;
import com.kuba6000.mobsinfo.network.LoadConfigPacket;
import com.mojang.authlib.GameProfile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import com.kuba6000.mobsinfo.api.DummyWorld;
import com.kuba6000.mobsinfo.api.MobDrop;
import com.kuba6000.mobsinfo.api.MobRecipe;
import com.kuba6000.mobsinfo.mixin.minecraft.EntitySlimeAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.EntitySlimeAccessor;

public class VanillaMobRecipeLoader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.kuba6000.mobsinfo.api.utils.ItemID;
import com.kuba6000.mobsinfo.api.utils.ModUtils;
import com.kuba6000.mobsinfo.config.Config;
import com.kuba6000.mobsinfo.mixin.minecraft.VillagerRegistryAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.VillagerRegistryAccessor;
import com.kuba6000.mobsinfo.nei.VillagerTradesHandler;
import com.kuba6000.mobsinfo.network.LoadConfigPacket;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.kuba6000.mobsinfo.api.IChanceModifier;
import com.kuba6000.mobsinfo.api.MobDrop;
import com.kuba6000.mobsinfo.api.MobRecipe;
import com.kuba6000.mobsinfo.mixin.DraconicEvolution.MinecraftForgeEventHandlerAccessor;
import com.kuba6000.mobsinfo.mixin.late.DraconicEvolution.MinecraftForgeEventHandlerAccessor;

import io.netty.buffer.ByteBuf;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.kuba6000.mobsinfo.api.LoaderReference;
import com.kuba6000.mobsinfo.api.MobDrop;
import com.kuba6000.mobsinfo.api.MobRecipe;
import com.kuba6000.mobsinfo.mixin.minecraft.ASMEventHandlerAccessor;
import com.kuba6000.mobsinfo.mixin.minecraft.EventBusAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.ASMEventHandlerAccessor;
import com.kuba6000.mobsinfo.mixin.early.minecraft.EventBusAccessor;

import cpw.mods.fml.common.eventhandler.ASMEventHandler;
import cpw.mods.fml.common.eventhandler.IEventListener;
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/kuba6000/mobsinfo/mixin/EarlyMixinLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.kuba6000.mobsinfo.mixin;

import java.util.List;
import java.util.Map;
import java.util.Set;

import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;

import cpw.mods.fml.relauncher.IFMLLoadingPlugin;

@IFMLLoadingPlugin.MCVersion("1.7.10")
public class EarlyMixinLoader implements IFMLLoadingPlugin, IEarlyMixinLoader {

@Override
public String[] getASMTransformerClass() {
return null;
}

@Override
public String getModContainerClass() {
return null;
}

@Override
public String getSetupClass() {
return null;
}

@Override
public void injectData(Map<String, Object> data) {}

@Override
public String getAccessTransformerClass() {
return null;
}

@Override
public String getMixinConfig() {
return "mixins.mobsinfo.early.json";
}

@Override
public List<String> getMixins(Set<String> loadedCoreMods) {
return Mixin.getEarlyMixins(loadedCoreMods);
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/kuba6000/mobsinfo/mixin/LateMixinLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.kuba6000.mobsinfo.mixin;

import java.util.List;
import java.util.Set;

import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
import com.gtnewhorizon.gtnhmixins.LateMixin;

@LateMixin
public class LateMixinLoader implements ILateMixinLoader {

@Override
public String getMixinConfig() {
return "mixins.mobsinfo.late.json";
}

@Override
public List<String> getMixins(Set<String> loadedMods) {
return Mixin.getLateMixins(loadedMods);
}

}
67 changes: 53 additions & 14 deletions src/main/java/com/kuba6000/mobsinfo/mixin/Mixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import static com.kuba6000.mobsinfo.mixin.TargetedMod.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import cpw.mods.fml.relauncher.FMLLaunchHandler;

Expand Down Expand Up @@ -54,30 +55,68 @@ public enum Mixin {
public final String mixinClass;
public final List<TargetedMod> targetedMods;
private final Side side;

Mixin(String mixinClass, Side side, TargetedMod... targetedMods) {
this.mixinClass = mixinClass;
this.targetedMods = Arrays.asList(targetedMods);
this.side = side;
}
private final Phase phase;

Mixin(String mixinClass, TargetedMod... targetedMods) {
this.mixinClass = mixinClass;
this.targetedMods = Arrays.asList(targetedMods);
this.side = Side.BOTH;
this.phase = this.targetedMods.size() == 1 && this.targetedMods.contains(VANILLA) ? Phase.EARLY : Phase.LATE;
}

public static List<String> getEarlyMixins(Set<String> loadedCoreMods) {
final List<String> mixins = new ArrayList<>();
for (Mixin mixin : Mixin.values()) {
if (mixin.phase == Phase.EARLY) {
mixins.add(mixin.mixinClass);
}
}
return mixins;
}

public static List<String> getLateMixins(Set<String> loadedMods) {
// NOTE: Any targetmod here needs a modid, not a coremod id
final List<String> mixins = new ArrayList<>();
for (Mixin mixin : Mixin.values()) {
if (mixin.phase == Phase.LATE) {
if (mixin.shouldLoad(loadedMods)) {
mixins.add(mixin.mixinClass);
}
}
}
return mixins;
}

private boolean shouldLoad(Set<String> loadedMods) {
return shouldLoadSide() && allModsLoaded(loadedMods);
}

public boolean shouldLoad(List<TargetedMod> loadedMods) {
return (side == Side.BOTH || side == Side.SERVER && FMLLaunchHandler.side()
.isServer()
|| side == Side.CLIENT && FMLLaunchHandler.side()
.isClient())
&& new HashSet<>(loadedMods).containsAll(targetedMods);
private boolean shouldLoadSide() {
return side == Side.BOTH || (side == Side.SERVER && FMLLaunchHandler.side()
.isServer())
|| (side == Side.CLIENT && FMLLaunchHandler.side()
.isClient());
}

enum Side {
private boolean allModsLoaded(Set<String> loadedMods) {
if (targetedMods.isEmpty()) return false;
for (TargetedMod target : targetedMods) {
if (target == TargetedMod.VANILLA) continue;
if (target.modId != null && !loadedMods.isEmpty() && !loadedMods.contains(target.modId)) {
return false;
}
}
return true;
}

private enum Side {
BOTH,
CLIENT,
SERVER
}

private enum Phase {
EARLY,
LATE,
}
}
Loading

0 comments on commit acb2029

Please sign in to comment.