Skip to content

Commit

Permalink
Adjust CCL Mixin based on Version (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
glowredman authored Nov 24, 2024
1 parent aa68618 commit 770ecf7
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Add your dependencies here

dependencies {
compileOnly("com.github.GTNewHorizons:CodeChickenCore:1.3.9:dev")
compileOnly("com.github.GTNewHorizons:Natura:2.7.4:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:CodeChickenCore:1.3.10:dev")
compileOnly("com.github.GTNewHorizons:Natura:2.7.5:dev") { transitive = false }
compileOnly(deobfCurse("pams-harvestcraft-221857:2270206"))

runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.6.42-GTNH:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.6.46-GTNH:dev")
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.29'
}


23 changes: 23 additions & 0 deletions src/main/java/squeek/applecore/helpers/CCLLegacyHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package squeek.applecore.helpers;

import codechicken.core.launch.CodeChickenCorePlugin;
import cpw.mods.fml.common.versioning.ComparableVersion;

public class CCLLegacyHelper {

public static boolean useLegacyMixin() {
return !useNewMixin();
}

@SuppressWarnings("deprecation")
public static boolean useNewMixin() {
String version;
try {
version = CodeChickenCorePlugin.version;
} catch (Exception e) {
return false;
}
return new ComparableVersion("1.3.10").compareTo(new ComparableVersion(version)) <= 0;
}

}
22 changes: 16 additions & 6 deletions src/main/java/squeek/applecore/mixinplugin/Mixins.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package squeek.applecore.mixinplugin;

import static squeek.applecore.mixinplugin.TargetedMod.CODECHICKEN_LIB;
import static squeek.applecore.mixinplugin.TargetedMod.HARVESTCRAFT;
import static squeek.applecore.mixinplugin.TargetedMod.NATURA;
import static squeek.applecore.mixinplugin.TargetedMod.VANILLA;
import static squeek.applecore.mixinplugin.TargetedMod.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

import cpw.mods.fml.relauncher.FMLLaunchHandler;
import squeek.applecore.helpers.CCLLegacyHelper;

public enum Mixins {

Expand Down Expand Up @@ -49,8 +48,10 @@ public enum Mixins {
ItemRendererMixin(new Builder().addMixinClasses("minecraft.ItemRendererMixin").setSide(Side.CLIENT)
.addTargetedMod(VANILLA).setPhase(Phase.EARLY)),

GuiDrawMixinLegacy(new Builder().addMixinClasses("codechickenlib.GuiDrawMixinLegacy").setSide(Side.CLIENT)
.addTargetedMod(CODECHICKEN_LIB).setPhase(Phase.EARLY).setApplyIf(CCLLegacyHelper::useLegacyMixin)),
GuiDrawMixin(new Builder().addMixinClasses("codechickenlib.GuiDrawMixin").setSide(Side.CLIENT)
.addTargetedMod(CODECHICKEN_LIB).setPhase(Phase.EARLY)),
.addTargetedMod(CODECHICKEN_LIB).setPhase(Phase.EARLY).setApplyIf(CCLLegacyHelper::useNewMixin)),

BlockPamFruitMixin(new Builder().addMixinClasses("harvestcraft.BlockPamFruitMixin").addTargetedMod(HARVESTCRAFT)),
BlockPamSaplingMixin(
Expand All @@ -64,6 +65,7 @@ public enum Mixins {
private final Side side;
public final List<TargetedMod> targetedMods;
public final List<TargetedMod> excludedMods;
private Supplier<Boolean> applyIf;

private static class Builder {

Expand All @@ -72,6 +74,7 @@ private static class Builder {
private Phase phase = Phase.LATE;
private final List<TargetedMod> targetedMods = new ArrayList<>();
private final List<TargetedMod> excludedMods = new ArrayList<>();
private Supplier<Boolean> applyIf = () -> true;

public Builder() {}

Expand Down Expand Up @@ -99,6 +102,11 @@ public Builder addExcludedMod(TargetedMod mod) {
this.excludedMods.add(mod);
return this;
}

public Builder setApplyIf(Supplier<Boolean> applyIf) {
this.applyIf = applyIf;
return this;
}
}

Mixins(Builder builder) {
Expand All @@ -107,6 +115,7 @@ public Builder addExcludedMod(TargetedMod mod) {
this.targetedMods = builder.targetedMods;
this.excludedMods = builder.excludedMods;
this.phase = builder.phase;
this.applyIf = builder.applyIf;
if (this.targetedMods.isEmpty()) {
throw new RuntimeException("No targeted mods specified!");
}
Expand Down Expand Up @@ -150,7 +159,8 @@ private boolean noModsLoaded(List<TargetedMod> targetedMods, Set<String> loadedC
}

public boolean shouldLoad(Set<String> loadedCoreMods, Set<String> loadedMods) {
return (shouldLoadSide() && allModsLoaded(targetedMods, loadedCoreMods, loadedMods)
return (shouldLoadSide() && applyIf.get()
&& allModsLoaded(targetedMods, loadedCoreMods, loadedMods)
&& noModsLoaded(excludedMods, loadedCoreMods, loadedMods));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
@Mixin(GuiDraw.class)
public class GuiDrawMixin {

@Inject(method = "drawTooltipBox", at = @At("HEAD"), remap = false)
private static void onDrawTooltipBox(int x, int y, int w, int h, CallbackInfo callbackInfo) {
@Inject(method = "drawTooltipBox(IIIIIIII)V", at = @At("HEAD"), remap = false)
private static void onDrawTooltipBox(int x, int y, int w, int h, int bgStart, int bgEnd, int borderStart,
int borderEnd, CallbackInfo callbackInfo) {
TooltipOverlayHandler.toolTipX = x;
TooltipOverlayHandler.toolTipY = y;
TooltipOverlayHandler.toolTipW = w;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package squeek.applecore.mixins.early.codechickenlib;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import codechicken.lib.gui.GuiDraw;
import squeek.applecore.client.TooltipOverlayHandler;

@Mixin(GuiDraw.class)
public class GuiDrawMixinLegacy {

@Inject(method = "drawTooltipBox(IIII)V", at = @At("HEAD"), remap = false)
private static void onDrawTooltipBoxLegacy(int x, int y, int w, int h, CallbackInfo callbackInfo) {
TooltipOverlayHandler.toolTipX = x;
TooltipOverlayHandler.toolTipY = y;
TooltipOverlayHandler.toolTipW = w;
TooltipOverlayHandler.toolTipH = h;
}
}

0 comments on commit 770ecf7

Please sign in to comment.