Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bawnorton committed Oct 22, 2023
1 parent cc6f2f5 commit 6733fab
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 93 deletions.
Empty file removed logs/latest.log
Empty file.
3 changes: 2 additions & 1 deletion src/main/java/com/bawnorton/bettertrims/BetterTrims.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public void onInitialize() {
Networking.init();
EventHandler.init();
}
}
}

26 changes: 8 additions & 18 deletions src/main/java/com/bawnorton/bettertrims/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,5 +10,5 @@
public @interface TextureLocation {
String value() default "none";

ArmorTrimEffects effectLookup() default ArmorTrimEffects.NONE;
boolean effectLookup() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public void apply(Iterable<ItemStack> armour, Effect effect) {
}
}

public String getMaterial() {
return material.toString();
}

public Text getTooltip() {
return tooltip;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArmorTrimEffect> EFFECTS = new ArrayList<>();

private final Supplier<ArmorTrimEffect> 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<ArmorTrimEffect> 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<ArmorTrimMaterial> material) {
public static ArmorTrimEffect of(RegistryKey<ArmorTrimMaterial> 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) {
Expand All @@ -68,26 +64,10 @@ private static Text getTooltip(String path) {


public static void forEachAppliedEffect(ItemStack stack, Consumer<ArmorTrimEffect> 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<ItemStack> itemStacks, ArmorTrimEffect.Effect effect) {
getEffect().apply(itemStacks, effect);
}

public boolean appliesTo(Iterable<ItemStack> itemStacks) {
return getEffect().appliesTo(itemStacks);
}

public boolean appliesTo(ItemStack itemStack) {
return getEffect().appliesTo(itemStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public abstract class ActiveTargetGoalMixin {
@Unique
// @formatter:off
private final Map<Class<? extends LivingEntity>, UnaryOperator<Predicate<LivingEntity>>> 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 = "<init>(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;"))
Expand Down

0 comments on commit 6733fab

Please sign in to comment.