Skip to content

Commit

Permalink
Added IMixinConfigPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yurisuika committed May 2, 2022
1 parent f70476c commit 0c4b79d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 26 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions src/main/java/com/yurisuika/raised/RaisedMixinPlugin.java
Original file line number Diff line number Diff line change
@@ -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<Boolean> TRUE = () -> true;

private static final Map<String, Supplier<Boolean>> 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<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> 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) {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
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;

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/raised.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
],
"injectors": {
"defaultRequire": 1
}
},
"plugin": "com.yurisuika.raised.RaisedMixinPlugin"
}

0 comments on commit 0c4b79d

Please sign in to comment.