Skip to content

Commit

Permalink
Add Compat w/ Better Trim Tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
Bawnorton committed Jan 24, 2024
1 parent 6420ab9 commit 03f00c3
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 10 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

<details>
<summary>Older Versions</summary>

# 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

<details>
<summary>Older Versions</summary>

# 2.1.1
- Fix crash with incorrect application of compat mixins when another mod is not present

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ 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

# Dependencies
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
Original file line number Diff line number Diff line change
@@ -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<Text> tooltip, ArmorTrim armorTrim, CallbackInfo ci) {
if (Screen.hasShiftDown()) {
ArmorTrimEffects.getEffects(armorTrim).forEach(effect -> tooltip.add(
effect.getTooltip()
.copy()
.fillStyle(armorTrim.getMaterial()
.value()
.description()
.getStyle()
)
));
}
}
}
3 changes: 2 additions & 1 deletion src/client/resources/bettertrims.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"plugin": "com.bawnorton.bettertrims.BetterTrimsMixinPlugin",
"client": [
"GameRendererMixin",
"compat.iris.GameRendererMixinSquared"
"compat.iris.GameRendererMixinSquared",
"compat.bettertrimtooltips.ArmorTrimMixinSquared"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bawnorton/bettertrims/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -59,6 +61,11 @@ public boolean appliesTo(Iterable<EquippedStack> 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<EquippedStack> armour, Effect effect) {
for (EquippedStack stack : armour) {
if (appliesTo(stack)) effect.applyEffect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,4 +63,14 @@ public static void forEachAppliedEffect(ItemStack stack, Consumer<ArmorTrimEffec
}
}
}

public static List<ArmorTrimEffect> getEffects(ArmorTrim armorTrim) {
List<ArmorTrimEffect> effects = new ArrayList<>();
for (ArmorTrimEffect effect : EFFECTS) {
if (effect.appliesTo(armorTrim)) {
effects.add(effect);
}
}
return effects;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Text> tooltip, CallbackInfo ci, @Local ArmorTrim trim) {
Expand All @@ -34,8 +36,6 @@ private static void addEffectTooltip(ItemStack stack, DynamicRegistryManager reg
)
)
)
)
);

));
}
}

0 comments on commit 03f00c3

Please sign in to comment.