From 0c4b79d957a6d2d552fe9989fbc55f8d9b4baedf Mon Sep 17 00:00:00 2001 From: yurisuika Date: Mon, 2 May 2022 02:18:13 -0700 Subject: [PATCH] Added IMixinConfigPlugin --- gradle.properties | 6 +-- .../yurisuika/raised/RaisedMixinPlugin.java | 52 +++++++++++++++++++ .../mixin/client/gui/hud/InGameHudMixin.java | 20 +++---- .../raised/mixin/mods/AppleskinMixin.java | 16 +++--- .../mixin/mods/DetailArmorBarMixin.java | 2 +- .../raised/mixin/mods/HealthOverlayMixin.java | 2 +- .../raised/mixin/mods/InventorioMixin.java | 4 +- src/main/resources/raised.mixins.json | 3 +- 8 files changed, 79 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/yurisuika/raised/RaisedMixinPlugin.java diff --git a/gradle.properties b/gradle.properties index 65d4b3ca..2569073b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,13 +5,13 @@ org.gradle.jvmargs=-Xmx1G # check these on https://fabricmc.net/use minecraft_version=1.18.2 yarn_mappings=1.18.2+build.3 - loader_version=0.13.3 + loader_version=0.14.4 # Mod Properties - mod_version = 1.0.7 + mod_version = 1.0.8 maven_group = com.yurisuika.raised archives_base_name = raised # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.51.0+1.18.2 + fabric_version=0.51.1+1.18.2 diff --git a/src/main/java/com/yurisuika/raised/RaisedMixinPlugin.java b/src/main/java/com/yurisuika/raised/RaisedMixinPlugin.java new file mode 100644 index 00000000..bc506eca --- /dev/null +++ b/src/main/java/com/yurisuika/raised/RaisedMixinPlugin.java @@ -0,0 +1,52 @@ +package com.yurisuika.raised; + +import com.google.common.collect.ImmutableMap; +import net.fabricmc.loader.api.FabricLoader; +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Supplier; + +public final class RaisedMixinPlugin implements IMixinConfigPlugin { + + private static final Supplier TRUE = () -> true; + + private static final Map> CONDITIONS = ImmutableMap.of( + "com.yurisuika.raised.mixin.mods.AppleskinMixin", () -> FabricLoader.getInstance().isModLoaded("appleskin"), + "com.yurisuika.raised.mixin.mods.DetailArmorBarMixin", () -> FabricLoader.getInstance().isModLoaded("detailab"), + "com.yurisuika.raised.mixin.mods.HealthOverlayMixin", () -> FabricLoader.getInstance().isModLoaded("healthoverlay"), + "com.yurisuika.raised.mixin.mods.InventorioMixin", () -> FabricLoader.getInstance().isModLoaded("inventorio") + ); + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return CONDITIONS.getOrDefault(mixinClassName, TRUE).get(); + } + + @Override + public void onLoad(String mixinPackage) {} + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) {} + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} + +} diff --git a/src/main/java/com/yurisuika/raised/mixin/client/gui/hud/InGameHudMixin.java b/src/main/java/com/yurisuika/raised/mixin/client/gui/hud/InGameHudMixin.java index bedee5e6..cbaa2cd0 100644 --- a/src/main/java/com/yurisuika/raised/mixin/client/gui/hud/InGameHudMixin.java +++ b/src/main/java/com/yurisuika/raised/mixin/client/gui/hud/InGameHudMixin.java @@ -8,47 +8,47 @@ public class InGameHudMixin { @ModifyArg(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;drawTexture(Lnet/minecraft/client/util/math/MatrixStack;IIIIII)V"), index = 2) - private int hotbarDistance(int value) { + private int modifyHotbar2(int value) { return value - 2; } @ModifyArg(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;drawTexture(Lnet/minecraft/client/util/math/MatrixStack;IIIIII)V", ordinal = 1), index = 6) - private int selectorHeight(int value) { + private int modifySelectorHeight(int value) { return value + 2; } @ModifyArg(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;renderHotbarItem(IIFLnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;I)V"), index = 1) - private int itemDistance(int value) { + private int modifyItem2(int value) { return value - 2; } @ModifyVariable(method = "renderMountJumpBar", at = @At(value = "STORE"), ordinal = 3) - private int jumpBarDistance(int value) { + private int modifyJumpBar2(int value) { return value - 2; } @ModifyArg(method = "renderExperienceBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;drawTexture(Lnet/minecraft/client/util/math/MatrixStack;IIIIII)V"), index = 2) - private int experienceBarDistance(int value) { + private int modifyExperienceBar2(int value) { return value - 2; } @ModifyArg(method = "renderExperienceBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/client/util/math/MatrixStack;Ljava/lang/String;FFI)I"), index = 3) - private float xpTextDistance(float value) { - return value - 2.0F; + private float modifyXpText2(float value) { + return value - (float)2; } @ModifyVariable(method = "renderHeldItemTooltip", at = @At(value = "STORE"), ordinal = 2) - private int heldItemTooltipDistance(int value) { + private int modifyHeldItemTooltip2(int value) { return value - 2; } @ModifyVariable(method = "renderStatusBars", at = @At(value = "STORE"), ordinal = 5) - private int statusBarsDistance(int value) { + private int modifyStatusBars2(int value) { return value - 2; } @ModifyVariable(method = "renderMountHealth", at = @At(value = "STORE"), ordinal = 2) - private int mountHealthDistance(int value) { + private int modifyMountHealth2(int value) { return value - 2; } diff --git a/src/main/java/com/yurisuika/raised/mixin/mods/AppleskinMixin.java b/src/main/java/com/yurisuika/raised/mixin/mods/AppleskinMixin.java index 91929bf0..2ff840cf 100644 --- a/src/main/java/com/yurisuika/raised/mixin/mods/AppleskinMixin.java +++ b/src/main/java/com/yurisuika/raised/mixin/mods/AppleskinMixin.java @@ -1,8 +1,7 @@ package com.yurisuika.raised.mixin.mods; -import org.objectweb.asm.Opcodes; +import net.minecraft.client.util.Window; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import squeek.appleskin.client.HUDOverlayHandler; @@ -10,13 +9,14 @@ @Mixin(HUDOverlayHandler.class) public class AppleskinMixin { - @Shadow - private int foodIconsOffset; - @Shadow public int FOOD_BAR_HEIGHT; + @Redirect(method = "onPreRender", at = @At(value = "INVOKE", target = "net/minecraft/client/util/Window.getScaledHeight()I")) + private int modifyScaledHeightA(Window instance) { + return instance.getScaledHeight() - 2; + } - @Redirect(method = "onPreRender", at = @At(value = "FIELD", target = "squeek/appleskin/client/HUDOverlayHandler.foodIconsOffset:I", opcode = Opcodes.PUTFIELD)) - private void modifyFoodIconsOffset(HUDOverlayHandler instance, int value) { - foodIconsOffset = FOOD_BAR_HEIGHT + 2; + @Redirect(method = "onRender", at = @At(value = "INVOKE", target = "net/minecraft/client/util/Window.getScaledHeight()I")) + private int modifyScaledHeightB(Window instance) { + return instance.getScaledHeight() - 2; } } \ No newline at end of file diff --git a/src/main/java/com/yurisuika/raised/mixin/mods/DetailArmorBarMixin.java b/src/main/java/com/yurisuika/raised/mixin/mods/DetailArmorBarMixin.java index b5899418..8c0779e1 100644 --- a/src/main/java/com/yurisuika/raised/mixin/mods/DetailArmorBarMixin.java +++ b/src/main/java/com/yurisuika/raised/mixin/mods/DetailArmorBarMixin.java @@ -10,7 +10,7 @@ public class DetailArmorBarMixin { @Redirect(method = "render", at = @At(value = "INVOKE", target = "net/minecraft/client/util/Window.getScaledHeight()I")) - private int modifyAddonsScaledHeight(Window instance) { + private int modifyScaledHeight(Window instance) { return instance.getScaledHeight() - 2; } diff --git a/src/main/java/com/yurisuika/raised/mixin/mods/HealthOverlayMixin.java b/src/main/java/com/yurisuika/raised/mixin/mods/HealthOverlayMixin.java index 4e84f473..fe3735e5 100644 --- a/src/main/java/com/yurisuika/raised/mixin/mods/HealthOverlayMixin.java +++ b/src/main/java/com/yurisuika/raised/mixin/mods/HealthOverlayMixin.java @@ -10,7 +10,7 @@ public class HealthOverlayMixin { @Redirect(method = "renderPlayerHearts", at = @At(value = "INVOKE", target = "net/minecraft/client/util/Window.getScaledHeight()I")) - private int modifyAddonsScaledHeight(Window instance) { + private int modifyScaledHeight(Window instance) { return instance.getScaledHeight() - 2; } diff --git a/src/main/java/com/yurisuika/raised/mixin/mods/InventorioMixin.java b/src/main/java/com/yurisuika/raised/mixin/mods/InventorioMixin.java index f7a68cc2..0cff9ade 100644 --- a/src/main/java/com/yurisuika/raised/mixin/mods/InventorioMixin.java +++ b/src/main/java/com/yurisuika/raised/mixin/mods/InventorioMixin.java @@ -10,12 +10,12 @@ public class InventorioMixin { @Redirect(method = "renderSegmentedHotbar", at = @At(value = "INVOKE", target = "net/minecraft/client/util/Window.getScaledHeight()I")) - private int modifyScaledHeight(Window instance) { + private int modifyScaledHeightA(Window instance) { return instance.getScaledHeight() - 1; } @Redirect(method = "renderHotbarAddons", at = @At(value = "INVOKE", target = "net/minecraft/client/util/Window.getScaledHeight()I")) - private int modifyAddonsScaledHeight(Window instance) { + private int modifyScaledHeightB(Window instance) { return instance.getScaledHeight() - 2; } diff --git a/src/main/resources/raised.mixins.json b/src/main/resources/raised.mixins.json index d47ca6e1..80c00527 100644 --- a/src/main/resources/raised.mixins.json +++ b/src/main/resources/raised.mixins.json @@ -14,5 +14,6 @@ ], "injectors": { "defaultRequire": 1 - } + }, + "plugin": "com.yurisuika.raised.RaisedMixinPlugin" }