diff --git a/logs/latest.log b/logs/latest.log deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/bawnorton/bettertrims/BetterTrims.java b/src/main/java/com/bawnorton/bettertrims/BetterTrims.java index 6b0fc2d..008c9c6 100644 --- a/src/main/java/com/bawnorton/bettertrims/BetterTrims.java +++ b/src/main/java/com/bawnorton/bettertrims/BetterTrims.java @@ -21,4 +21,5 @@ public void onInitialize() { Networking.init(); EventHandler.init(); } -} \ No newline at end of file +} + diff --git a/src/main/java/com/bawnorton/bettertrims/config/Config.java b/src/main/java/com/bawnorton/bettertrims/config/Config.java index 764a0db..822c283 100644 --- a/src/main/java/com/bawnorton/bettertrims/config/Config.java +++ b/src/main/java/com/bawnorton/bettertrims/config/Config.java @@ -3,7 +3,6 @@ import com.bawnorton.bettertrims.config.annotation.*; import com.bawnorton.bettertrims.config.option.NestedConfigOption; import com.bawnorton.bettertrims.config.option.OptionType; -import com.bawnorton.bettertrims.effect.ArmorTrimEffects; public class Config { private static Config LOCAL_INSTANCE = new Config(); @@ -96,7 +95,6 @@ static void updateServer(Config config) { SERVER_INSTANCE = config; } - @SuppressWarnings("unused") public static class EnchantedGoldenApple implements NestedConfigOption { @FloatOption(type = OptionType.INHERIT, value = 1200, max = 12000, min = 1) @TextureLocation("minecraft:textures/item/golden_apple.png") @@ -112,29 +110,27 @@ public static class EnchantedGoldenApple implements NestedConfigOption { public Integer maxAbsorption; } - @SuppressWarnings("unused") public static class Silver implements NestedConfigOption { @FloatOption(type = OptionType.INHERIT, value = 0.05f, max = 0.5f) - @TextureLocation(effectLookup = ArmorTrimEffects.SILVER) + @TextureLocation(value = "silver", effectLookup = true) public Float movementSpeed; @FloatOption(type = OptionType.INHERIT, value = 0.05f, max = 0.5f) - @TextureLocation(effectLookup = ArmorTrimEffects.SILVER) + @TextureLocation(value = "silver", effectLookup = true) public Float jumpHeight; @FloatOption(type = OptionType.INHERIT, value = 0.5f, max = 5) - @TextureLocation(effectLookup = ArmorTrimEffects.SILVER) + @TextureLocation(value = "silver", effectLookup = true) public Float attackDamage; @FloatOption(type = OptionType.INHERIT, value = 0.3f, max = 3) - @TextureLocation(effectLookup = ArmorTrimEffects.SILVER) + @TextureLocation(value = "silver", effectLookup = true) public Float attackSpeed; @FloatOption(type = OptionType.INHERIT, value = 0.03f, max = 0.3f) - @TextureLocation(effectLookup = ArmorTrimEffects.SILVER) + @TextureLocation(value = "silver", effectLookup = true) public Float damageReduction; @FloatOption(type = OptionType.INHERIT, value = 0.25f, max = 1) - @TextureLocation(effectLookup = ArmorTrimEffects.SILVER) + @TextureLocation(value = "silver", effectLookup = true) public Float improveVision; } - @SuppressWarnings("unused") public static class SlimeBall implements NestedConfigOption { @FloatOption(type = OptionType.INHERIT, value = 0.25f, max = 1) @TextureLocation("minecraft:textures/item/slime_ball.png") @@ -144,7 +140,6 @@ public static class SlimeBall implements NestedConfigOption { public Float knockbackIncrease; } - @SuppressWarnings("unused") public static class Coal implements NestedConfigOption { @BooleanOption(type = OptionType.INHERIT, value = false) @TextureLocation("minecraft:textures/item/coal.png") @@ -157,7 +152,6 @@ public static class Coal implements NestedConfigOption { public Integer furnaceSpeedIncrease; } - @SuppressWarnings("unused") public static class EnderPearl implements NestedConfigOption { @FloatOption(type = OptionType.INHERIT, value = 0.25f, max = 1) @TextureLocation("minecraft:textures/item/ender_pearl.png") @@ -167,17 +161,15 @@ public static class EnderPearl implements NestedConfigOption { public Boolean waterDamagesUser; } - @SuppressWarnings("unused") public static class Platinum implements NestedConfigOption { @BooleanOption(type = OptionType.INHERIT, value = true) - @TextureLocation(effectLookup = ArmorTrimEffects.PLATINUM) + @TextureLocation(value = "platinum", effectLookup = true) public Boolean illagersIgnore; @IntOption(type = OptionType.INHERIT, value = 1, min = 1, max = 6) - @TextureLocation(effectLookup = ArmorTrimEffects.PLATINUM) + @TextureLocation(value = "platinum", effectLookup = true) public Integer piecesForIllagersIgnore; } - @SuppressWarnings("unused") public static class PrismarineShard implements NestedConfigOption { @BooleanOption(type = OptionType.INHERIT, value = true) @TextureLocation("minecraft:textures/item/prismarine_shard.png") @@ -193,7 +185,6 @@ public static class PrismarineShard implements NestedConfigOption { public Integer piecesForMiningFatigueImmunity; } - @SuppressWarnings("unused") public static class Gold implements NestedConfigOption { @BooleanOption(type = OptionType.INHERIT, value = true) @TextureLocation("minecraft:textures/item/gold_ingot.png") @@ -203,7 +194,6 @@ public static class Gold implements NestedConfigOption { public Integer piecesForPiglinsIgnore; } - @SuppressWarnings("unused") public static class NetherBrick implements NestedConfigOption { @BooleanOption(type = OptionType.INHERIT, value = true) @TextureLocation("minecraft:textures/item/nether_brick.png") diff --git a/src/main/java/com/bawnorton/bettertrims/config/annotation/TextureLocation.java b/src/main/java/com/bawnorton/bettertrims/config/annotation/TextureLocation.java index 59a9666..1b0215d 100644 --- a/src/main/java/com/bawnorton/bettertrims/config/annotation/TextureLocation.java +++ b/src/main/java/com/bawnorton/bettertrims/config/annotation/TextureLocation.java @@ -1,7 +1,5 @@ package com.bawnorton.bettertrims.config.annotation; -import com.bawnorton.bettertrims.effect.ArmorTrimEffects; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -12,5 +10,5 @@ public @interface TextureLocation { String value() default "none"; - ArmorTrimEffects effectLookup() default ArmorTrimEffects.NONE; + boolean effectLookup() default false; } diff --git a/src/main/java/com/bawnorton/bettertrims/config/option/reference/ConfigOptionReference.java b/src/main/java/com/bawnorton/bettertrims/config/option/reference/ConfigOptionReference.java index 55d18c9..9d8aa53 100644 --- a/src/main/java/com/bawnorton/bettertrims/config/option/reference/ConfigOptionReference.java +++ b/src/main/java/com/bawnorton/bettertrims/config/option/reference/ConfigOptionReference.java @@ -4,13 +4,12 @@ import com.bawnorton.bettertrims.config.annotation.*; import com.bawnorton.bettertrims.config.option.NestedConfigOption; import com.bawnorton.bettertrims.config.option.OptionType; -import com.bawnorton.bettertrims.effect.ArmorTrimEffect; -import com.bawnorton.bettertrims.effect.ArmorTrimEffects; -import com.bawnorton.bettertrims.util.RegexPath; import com.bawnorton.bettertrims.reflection.Reflection; +import com.bawnorton.bettertrims.util.RegexPath; import net.minecraft.data.client.ModelIds; import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -154,15 +153,15 @@ public Integer maxIntValue() { if(!field.isAnnotationPresent(TextureLocation.class)) return null; TextureLocation location = field.getAnnotation(TextureLocation.class); - if(location.effectLookup() == ArmorTrimEffects.NONE) { + if(!location.effectLookup()) { String locationString = location.value(); if(locationString.equals("none")) return null; return new Identifier(locationString); } - ArmorTrimEffect effect = location.effectLookup().getEffect(); - RegexPath identifier = RegexPath.fromString(effect.getMaterial()); + String searchString = location.value(); + RegexPath identifier = RegexPath.fromString(StringUtils.wrap(searchString, "/")); return TEXTURE_CACHE.computeIfAbsent(identifier, id -> { Identifier itemId = Registries.ITEM.getIds().stream().filter(identifier::matches).findFirst().orElseGet(() -> { BetterTrims.LOGGER.debug("Could not find item for identifier \"%s\", trying \"%s_ingot\"".formatted(identifier, identifier)); diff --git a/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffect.java b/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffect.java index 06672f0..28417f2 100644 --- a/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffect.java +++ b/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffect.java @@ -53,10 +53,6 @@ public void apply(Iterable armour, Effect effect) { } } - public String getMaterial() { - return material.toString(); - } - public Text getTooltip() { return tooltip; } diff --git a/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffects.java b/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffects.java index 8cba8bc..0a022d0 100644 --- a/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffects.java +++ b/src/main/java/com/bawnorton/bettertrims/effect/ArmorTrimEffects.java @@ -11,55 +11,51 @@ import net.minecraft.text.Text; import org.apache.commons.lang3.StringUtils; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import java.util.function.Consumer; -import java.util.function.Supplier; -import java.util.regex.Pattern; -public enum ArmorTrimEffects { - NONE(() -> new ArmorTrimEffect(new RegexPath("none"), Text.of("none"))), - QUARTZ(() -> of(ArmorTrimMaterials.QUARTZ)), - IRON(() -> of(ArmorTrimMaterials.IRON)), - NETHERITE(() -> of(ArmorTrimMaterials.NETHERITE)), - REDSTONE(() -> of(ArmorTrimMaterials.REDSTONE)), - COPPER(() -> of(ArmorTrimMaterials.COPPER)), - GOLD(() -> of(ArmorTrimMaterials.GOLD)), - EMERALD(() -> of(ArmorTrimMaterials.EMERALD)), - DIAMOND(() -> of(ArmorTrimMaterials.DIAMOND)), - LAPIS(() -> of(ArmorTrimMaterials.LAPIS)), - AMETHYST(() -> of(ArmorTrimMaterials.AMETHYST)), - COAL(() -> of(Items.COAL)), - DRAGONS_BREATH(() -> of(Items.DRAGON_BREATH)), - CHORUS_FRUIT(() -> of(Items.CHORUS_FRUIT)), - ECHO_SHARD(() -> of(Items.ECHO_SHARD)), - ENDER_PEARL(() -> of(Items.ENDER_PEARL)), - FIRE_CHARGE(() -> of(Items.FIRE_CHARGE)), - GLOWSTONE_DUST(() -> of(Items.GLOWSTONE_DUST)), - LEATHER(() -> of(Items.LEATHER)), - NETHER_BRICK(() -> of(Items.NETHER_BRICK)), - PRISMARINE_SHARD(() -> of(Items.PRISMARINE_SHARD)), - RABBIT_HIDE(() -> of(Items.RABBIT_HIDE)), - SLIME_BALL(() -> of(Items.SLIME_BALL)), - ENCHANTED_GOLDEN_APPLE(() -> of(Items.ENCHANTED_GOLDEN_APPLE)), - PLATINUM(() -> of(new RegexPath("/platinum/"))), - SILVER(() -> of(new RegexPath("/silver/"))); +public abstract class ArmorTrimEffects { + private static final List EFFECTS = new ArrayList<>(); - private final Supplier effect; + public static final ArmorTrimEffect QUARTZ = of(ArmorTrimMaterials.QUARTZ); + public static final ArmorTrimEffect IRON = of(ArmorTrimMaterials.IRON); + public static final ArmorTrimEffect NETHERITE = of(ArmorTrimMaterials.NETHERITE); + public static final ArmorTrimEffect REDSTONE = of(ArmorTrimMaterials.REDSTONE); + public static final ArmorTrimEffect COPPER = of(ArmorTrimMaterials.COPPER); + public static final ArmorTrimEffect GOLD = of(ArmorTrimMaterials.GOLD); + public static final ArmorTrimEffect EMERALD = of(ArmorTrimMaterials.EMERALD); + public static final ArmorTrimEffect DIAMOND = of(ArmorTrimMaterials.DIAMOND); + public static final ArmorTrimEffect LAPIS = of(ArmorTrimMaterials.LAPIS); + public static final ArmorTrimEffect AMETHYST = of(ArmorTrimMaterials.AMETHYST); + public static final ArmorTrimEffect COAL = of(Items.COAL); + public static final ArmorTrimEffect DRAGONS_BREATH = of(Items.DRAGON_BREATH); + public static final ArmorTrimEffect CHORUS_FRUIT = of(Items.CHORUS_FRUIT); + public static final ArmorTrimEffect ECHO_SHARD = of(Items.ECHO_SHARD); + public static final ArmorTrimEffect ENDER_PEARL = of(Items.ENDER_PEARL); + public static final ArmorTrimEffect FIRE_CHARGE = of(Items.FIRE_CHARGE); + public static final ArmorTrimEffect GLOWSTONE_DUST = of(Items.GLOWSTONE_DUST); + public static final ArmorTrimEffect LEATHER = of(Items.LEATHER); + public static final ArmorTrimEffect NETHER_BRICK = of(Items.NETHER_BRICK); + public static final ArmorTrimEffect PRISMARINE_SHARD = of(Items.PRISMARINE_SHARD); + public static final ArmorTrimEffect RABBIT_HIDE = of(Items.RABBIT_HIDE); + public static final ArmorTrimEffect SLIME_BALL = of(Items.SLIME_BALL); + public static final ArmorTrimEffect ENCHANTED_GOLDEN_APPLE = of(Items.ENCHANTED_GOLDEN_APPLE); + public static final ArmorTrimEffect PLATINUM = of(new RegexPath("/platinum/")); + public static final ArmorTrimEffect SILVER = of(new RegexPath("/silver/")); - ArmorTrimEffects(Supplier effect) { - this.effect = effect; - } - - private static ArmorTrimEffect of(Item item) { + public static ArmorTrimEffect of(Item item) { return of(new RegexPath(StringUtils.wrap(Registries.ITEM.getId(item).getPath(), "/"))); } - private static ArmorTrimEffect of(RegistryKey material) { + public static ArmorTrimEffect of(RegistryKey material) { return of(new RegexPath(StringUtils.wrap(material.getValue().getPath(), "/"))); } - private static ArmorTrimEffect of(RegexPath material) { - return new ArmorTrimEffect(material, getTooltip(material.path())); + public static ArmorTrimEffect of(RegexPath material) { + ArmorTrimEffect effect = new ArmorTrimEffect(material, getTooltip(material.path())); + EFFECTS.add(effect); + return effect; } private static Text getTooltip(String path) { @@ -68,26 +64,10 @@ private static Text getTooltip(String path) { public static void forEachAppliedEffect(ItemStack stack, Consumer effectConsumer) { - for (ArmorTrimEffects effect : values()) { + for (ArmorTrimEffect effect : EFFECTS) { if (effect.appliesTo(stack)) { - effectConsumer.accept(effect.getEffect()); + effectConsumer.accept(effect); } } } - - public ArmorTrimEffect getEffect() { - return effect.get(); - } - - public void apply(Iterable itemStacks, ArmorTrimEffect.Effect effect) { - getEffect().apply(itemStacks, effect); - } - - public boolean appliesTo(Iterable itemStacks) { - return getEffect().appliesTo(itemStacks); - } - - public boolean appliesTo(ItemStack itemStack) { - return getEffect().appliesTo(itemStack); - } } diff --git a/src/main/java/com/bawnorton/bettertrims/mixin/ActiveTargetGoalMixin.java b/src/main/java/com/bawnorton/bettertrims/mixin/ActiveTargetGoalMixin.java index bc0e31d..57e17ae 100644 --- a/src/main/java/com/bawnorton/bettertrims/mixin/ActiveTargetGoalMixin.java +++ b/src/main/java/com/bawnorton/bettertrims/mixin/ActiveTargetGoalMixin.java @@ -24,10 +24,10 @@ public abstract class ActiveTargetGoalMixin { @Unique // @formatter:off private final Map, UnaryOperator>> trimPredicates = Map.ofEntries( - Map.entry(IllagerEntity.class, original -> getTrimPredicate(original, ArmorTrimEffects.PLATINUM.getEffect(), ConfigManager.getConfig().platinumEffects.piecesForIllagersIgnore, ConfigManager.getConfig().platinumEffects.illagersIgnore)), - Map.entry(GuardianEntity.class, original -> getTrimPredicate(original, ArmorTrimEffects.PRISMARINE_SHARD.getEffect(), ConfigManager.getConfig().prismarineShardEffects.piecesForGuardiansIgnore, ConfigManager.getConfig().prismarineShardEffects.guardiansIgnore)), - Map.entry(BlazeEntity.class, original -> getTrimPredicate(original, ArmorTrimEffects.NETHER_BRICK.getEffect(), ConfigManager.getConfig().netherBrickEffects.piecesForBlazesIgnore, ConfigManager.getConfig().netherBrickEffects.blazesIgnore)), - Map.entry(WitherSkeletonEntity.class, original -> getTrimPredicate(original, ArmorTrimEffects.NETHER_BRICK.getEffect(), ConfigManager.getConfig().netherBrickEffects.piecesForWitherSkeletonsIgnore, ConfigManager.getConfig().netherBrickEffects.witherSkeletonsIgnore)) + Map.entry(IllagerEntity.class, original -> getTrimPredicate(original, ArmorTrimEffects.PLATINUM, ConfigManager.getConfig().platinumEffects.piecesForIllagersIgnore, ConfigManager.getConfig().platinumEffects.illagersIgnore)), + Map.entry(GuardianEntity.class, original -> getTrimPredicate(original, ArmorTrimEffects.PRISMARINE_SHARD, ConfigManager.getConfig().prismarineShardEffects.piecesForGuardiansIgnore, ConfigManager.getConfig().prismarineShardEffects.guardiansIgnore)), + Map.entry(BlazeEntity.class, original -> getTrimPredicate(original, ArmorTrimEffects.NETHER_BRICK, ConfigManager.getConfig().netherBrickEffects.piecesForBlazesIgnore, ConfigManager.getConfig().netherBrickEffects.blazesIgnore)), + Map.entry(WitherSkeletonEntity.class, original -> getTrimPredicate(original, ArmorTrimEffects.NETHER_BRICK, ConfigManager.getConfig().netherBrickEffects.piecesForWitherSkeletonsIgnore, ConfigManager.getConfig().netherBrickEffects.witherSkeletonsIgnore)) ); @ModifyArg(method = "(Lnet/minecraft/entity/mob/MobEntity;Ljava/lang/Class;IZZLjava/util/function/Predicate;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ai/TargetPredicate;setPredicate(Ljava/util/function/Predicate;)Lnet/minecraft/entity/ai/TargetPredicate;"))