From 03f00c3663e9b5417e61a5ee96e39f1e5b00cdf4 Mon Sep 17 00:00:00 2001 From: Bawnorton Date: Tue, 23 Jan 2024 22:47:37 -0800 Subject: [PATCH] Add Compat w/ Better Trim Tooltips --- CHANGELOG.md | 10 +++- README.md | 2 +- build.gradle | 1 + gradle.properties | 3 +- .../ArmorTrimMixinSquared.java | 58 +++++++++++++++++++ .../resources/bettertrims.client.mixins.json | 3 +- .../bawnorton/bettertrims/config/Config.java | 2 +- .../bettertrims/effect/ArmorTrimEffect.java | 7 +++ .../bettertrims/effect/ArmorTrimEffects.java | 11 ++++ .../bettertrims/mixin/ArmorTrimMixin.java | 6 +- 10 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 src/client/java/com/bawnorton/bettertrims/client/mixin/compat/bettertrimtooltips/ArmorTrimMixinSquared.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d2e9a4..7ea0b59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,17 @@ ## Changelog +# 2.2.0 +- Add Compat with Better Trim Tooltips (Press Shift to see the effects) +- Fix default Ender Pearl dodge chance + +
+Older Versions + # 2.1.2 - Updated Readme to include the changes - Added exact figures to the Readme, in-game tooltips will still remain deliberately vague - Re-balanced Netherbrick Trim -
-Older Versions - # 2.1.1 - Fix crash with incorrect application of compat mixins when another mod is not present diff --git a/README.md b/README.md index 27fab8f..88d21be 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ BetterTrims - Ender Pearl - Chance to dodge any damage from **Any Source** and tp a short distance - Take damage from water and rain - - 25% chance per trim + - 5% chance per trim - Fire Charge - Entities that hit you or you hit will be set ablaze - 1 second per trim diff --git a/build.gradle b/build.gradle index 7b1e7f6..d1c6311 100644 --- a/build.gradle +++ b/build.gradle @@ -81,6 +81,7 @@ dependencies { // mod compats modCompileOnly("maven.modrinth:illager-invasion:${project.illager_invasion_version}") modCompileOnly("maven.modrinth:friends-and-foes:${project.friends_and_foes_version}") + modImplementation("maven.modrinth:better-trim-tooltips:${project.better_trim_tooltips_version}") } processResources { diff --git a/gradle.properties b/gradle.properties index 1744c81..8fb4e20 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10 loader_version=0.15.3 # Mod Properties -mod_version=2.1.2 +mod_version=2.2.0 maven_group=com.bawnorton archives_base_name=bettertrims @@ -17,5 +17,6 @@ archives_base_name=bettertrims fabric_version=0.91.0+1.20.1 illager_invasion_version=v8.0.0-1.20.1-Fabric friends_and_foes_version=fabric-mc1.20.1-1.9.3 +better_trim_tooltips_version=better-trim-tooltips-1.0.1-1.20 modmenu_version=7.2.1 yacl_version=3.2.1+1.20 \ No newline at end of file diff --git a/src/client/java/com/bawnorton/bettertrims/client/mixin/compat/bettertrimtooltips/ArmorTrimMixinSquared.java b/src/client/java/com/bawnorton/bettertrims/client/mixin/compat/bettertrimtooltips/ArmorTrimMixinSquared.java new file mode 100644 index 0000000..78d7a0c --- /dev/null +++ b/src/client/java/com/bawnorton/bettertrims/client/mixin/compat/bettertrimtooltips/ArmorTrimMixinSquared.java @@ -0,0 +1,58 @@ +package com.bawnorton.bettertrims.client.mixin.compat.bettertrimtooltips; + +import com.bawnorton.bettertrims.annotation.ConditionalMixin; +import com.bawnorton.bettertrims.effect.ArmorTrimEffects; +import com.bawnorton.mixinsquared.TargetHandler; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.item.trim.ArmorTrim; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +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.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(value = ArmorTrim.class, priority = 1500) +@ConditionalMixin(modid = "better-trim-tooltips") +@SuppressWarnings({"MixinAnnotationTarget", "InvalidMemberReference", "UnresolvedMixinReference"}) +public abstract class ArmorTrimMixinSquared { + @TargetHandler( + mixin = "io.github.andrew6rant.bettertrimtooltips.mixin.client.ArmorTrimMixin", + name = "appendTrimTooltip" + ) + @ModifyArg(method = "@MixinSquared:Handler", at = @At(value = "INVOKE", target = "java/util/List.add (Ljava/lang/Object;)Z")) + private static Object addEffectTooltip(Object tooltip, @Local(argsOnly = true) ArmorTrim trim) { + if(ArmorTrimEffects.getEffects(trim).isEmpty()) return tooltip; + + MutableText effectTooltip = (MutableText) tooltip; + if (!Screen.hasShiftDown()) { + effectTooltip.append(Text.of(" §b+§r")); + } else { + effectTooltip.append(Text.of(" §c-§r")); + } + return effectTooltip; + } + + @TargetHandler( + mixin = "io.github.andrew6rant.bettertrimtooltips.mixin.client.ArmorTrimMixin", + name = "appendTrimTooltip" + ) + @Inject(method = "@MixinSquared:Handler", at = @At("TAIL")) + private static void addEffectTooltip(List tooltip, ArmorTrim armorTrim, CallbackInfo ci) { + if (Screen.hasShiftDown()) { + ArmorTrimEffects.getEffects(armorTrim).forEach(effect -> tooltip.add( + effect.getTooltip() + .copy() + .fillStyle(armorTrim.getMaterial() + .value() + .description() + .getStyle() + ) + )); + } + } +} diff --git a/src/client/resources/bettertrims.client.mixins.json b/src/client/resources/bettertrims.client.mixins.json index 8852e9d..174503a 100644 --- a/src/client/resources/bettertrims.client.mixins.json +++ b/src/client/resources/bettertrims.client.mixins.json @@ -5,7 +5,8 @@ "plugin": "com.bawnorton.bettertrims.BetterTrimsMixinPlugin", "client": [ "GameRendererMixin", - "compat.iris.GameRendererMixinSquared" + "compat.iris.GameRendererMixinSquared", + "compat.bettertrimtooltips.ArmorTrimMixinSquared" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/java/com/bawnorton/bettertrims/config/Config.java b/src/main/java/com/bawnorton/bettertrims/config/Config.java index 57ddb8a..6e2c93d 100644 --- a/src/main/java/com/bawnorton/bettertrims/config/Config.java +++ b/src/main/java/com/bawnorton/bettertrims/config/Config.java @@ -231,7 +231,7 @@ public static class Coal { } public static class EnderPearl { - @FloatOption(group = "inherit", value = 0.25f, max = 1) + @FloatOption(group = "inherit", value = 0.05f, max = 1) public Float dodgeChance; @BooleanOption(group = "inherit", value = true) public Boolean waterDamagesUser; diff --git a/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffect.java b/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffect.java index 46084c9..3c8997f 100644 --- a/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffect.java +++ b/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffect.java @@ -4,8 +4,10 @@ import com.bawnorton.bettertrims.compat.StackedTrimsCompat; import com.bawnorton.bettertrims.util.EquippedStack; import net.minecraft.item.ItemStack; +import net.minecraft.item.trim.ArmorTrim; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; +import net.minecraft.registry.Registries; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -59,6 +61,11 @@ public boolean appliesTo(Iterable stacks) { return false; } + public boolean appliesTo(ArmorTrim armorTrim) { + String material = Registries.ITEM.getId(armorTrim.getMaterial().value().ingredient().value()).getPath(); + return this.material.appliesTo(material); + } + public void apply(Iterable armour, Effect effect) { for (EquippedStack stack : armour) { if (appliesTo(stack)) effect.applyEffect(); diff --git a/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffects.java b/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffects.java index 4f8495f..44c96b5 100644 --- a/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffects.java +++ b/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffects.java @@ -3,6 +3,7 @@ import com.bawnorton.bettertrims.config.ConfigManager; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.item.trim.ArmorTrim; import net.minecraft.item.trim.ArmorTrimMaterials; import java.util.ArrayList; @@ -62,4 +63,14 @@ public static void forEachAppliedEffect(ItemStack stack, Consumer getEffects(ArmorTrim armorTrim) { + List effects = new ArrayList<>(); + for (ArmorTrimEffect effect : EFFECTS) { + if (effect.appliesTo(armorTrim)) { + effects.add(effect); + } + } + return effects; + } } diff --git a/src/main/java/com/bawnorton/bettertrims/mixin/ArmorTrimMixin.java b/src/main/java/com/bawnorton/bettertrims/mixin/ArmorTrimMixin.java index 983325c..bbc6dfb 100644 --- a/src/main/java/com/bawnorton/bettertrims/mixin/ArmorTrimMixin.java +++ b/src/main/java/com/bawnorton/bettertrims/mixin/ArmorTrimMixin.java @@ -1,5 +1,6 @@ package com.bawnorton.bettertrims.mixin; +import com.bawnorton.bettertrims.annotation.ConditionalMixin; import com.bawnorton.bettertrims.effect.ArmorTrimEffects; import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.item.ItemStack; @@ -16,6 +17,7 @@ import java.util.List; @Mixin(ArmorTrim.class) +@ConditionalMixin(modid = "better-trim-tooltips", applyIfPresent = false) public abstract class ArmorTrimMixin { @Inject(method = "appendTooltip", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 2, shift = At.Shift.AFTER)) private static void addEffectTooltip(ItemStack stack, DynamicRegistryManager registryManager, List tooltip, CallbackInfo ci, @Local ArmorTrim trim) { @@ -34,8 +36,6 @@ private static void addEffectTooltip(ItemStack stack, DynamicRegistryManager reg ) ) ) - ) - ); - + )); } }