From 76f366b5e3a3eadc976a861e2043d5ffbe1e07e0 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 1 Jun 2023 14:33:18 +0100 Subject: [PATCH] Move target and slots to the enchantment options --- .../enchantment/AttributedEnchantment.java | 9 +--- .../enchantment/CollaboratorEnchantment.java | 6 +-- .../enchantment/ConsumptionEnchantment.java | 3 +- .../enchantment/GemFindingEnchantment.java | 4 +- .../enchantment/PoisonedJokeEnchantment.java | 2 +- .../item/enchantment/SimpleEnchantment.java | 46 ++++++++++++------- .../enchantment/StressfulEnchantment.java | 2 +- .../item/enchantment/UEnchantments.java | 22 ++++----- .../enchantment/WantItNeedItEnchantment.java | 2 +- 9 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java index c6a0729a..4436222a 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java @@ -7,7 +7,6 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.minelittlepony.unicopia.entity.Living; -import net.minecraft.enchantment.EnchantmentTarget; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttributeInstance; @@ -17,12 +16,8 @@ public class AttributedEnchantment extends SimpleEnchantment { private final Map modifiers = new HashMap<>(); - protected AttributedEnchantment(Options options, EnchantmentTarget target, EquipmentSlot... slots) { - super(options, target, slots); - } - - protected AttributedEnchantment(Options options, EquipmentSlot... slots) { - super(options, slots); + protected AttributedEnchantment(Options options) { + super(options); } public AttributedEnchantment addModifier(EntityAttribute attribute, ModifierFactory modifierSupplier) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java index 3322b362..c9bc4fd1 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java @@ -4,8 +4,6 @@ import java.util.UUID; import com.minelittlepony.unicopia.entity.Living; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.enchantment.EnchantmentTarget; -import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.entity.attribute.EntityAttributes; @@ -15,8 +13,8 @@ public class CollaboratorEnchantment extends AttributedEnchantment { private static final UUID TEAM_STRENGTH_UUID = UUID.fromString("5f08c02d-d959-4763-ac84-16e2acfd4b62"); protected CollaboratorEnchantment(Options options) { - super(options, EnchantmentTarget.WEAPON, EquipmentSlot.MAINHAND); - this.addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier); + super(options); + addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/ConsumptionEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/ConsumptionEnchantment.java index 83c3e032..a59a797a 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/ConsumptionEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/ConsumptionEnchantment.java @@ -11,7 +11,6 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.enchantment.EnchantmentTarget; import net.minecraft.entity.Entity; import net.minecraft.entity.ExperienceOrbEntity; import net.minecraft.entity.LivingEntity; @@ -25,7 +24,7 @@ import net.minecraft.world.World; public class ConsumptionEnchantment extends SimpleEnchantment { protected ConsumptionEnchantment(Options options) { - super(options, EnchantmentTarget.DIGGER, UEnchantmentValidSlots.HANDS); + super(options); } public static boolean applyConsumption(World w, BlockState state, BlockPos pos, @Nullable BlockEntity blockEntity, Entity entity, ItemStack tool) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java index 1ecabfca..0010a097 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java @@ -7,14 +7,12 @@ import com.minelittlepony.unicopia.entity.Living; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; -import net.minecraft.enchantment.EnchantmentTarget; -import net.minecraft.entity.EquipmentSlot; import net.minecraft.util.math.BlockPos; public class GemFindingEnchantment extends SimpleEnchantment { protected GemFindingEnchantment(Options options) { - super(options, EnchantmentTarget.DIGGER, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND); + super(options); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java index cd01a4d7..93677d83 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java @@ -30,7 +30,7 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi private List sounds = new ArrayList<>(); protected PoisonedJokeEnchantment(Options options) { - super(options, UEnchantmentValidSlots.ANY); + super(options); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java index 64cc395b..805c40a4 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java @@ -9,24 +9,11 @@ import net.minecraft.item.ItemStack; public class SimpleEnchantment extends Enchantment { - private final boolean allItems; - - private final EquipmentSlot[] slots; - private final Options options; - protected SimpleEnchantment(Options options, EnchantmentTarget target, EquipmentSlot... slots) { - super(options.rarity, target, slots); + protected SimpleEnchantment(Options options) { + super(options.rarity, options.target, options.slots); this.options = options; - this.allItems = false; - this.slots = slots; - } - - protected SimpleEnchantment(Options options, EquipmentSlot... slots) { - super(options.rarity, EnchantmentTarget.VANISHABLE, slots); // vanishable includes breakable. It's the one that accepts the widest variety of items - this.options = options; - this.allItems = true; - this.slots = slots; } public void onUserTick(Living user, int level) { @@ -43,11 +30,11 @@ public class SimpleEnchantment extends Enchantment { @Override public boolean isAcceptableItem(ItemStack itemStack) { - return allItems || super.isAcceptableItem(itemStack); + return options.allItems || super.isAcceptableItem(itemStack); } public EquipmentSlot[] getSlots() { - return slots; + return options.slots; } @Override @@ -94,6 +81,31 @@ public class SimpleEnchantment extends Enchantment { private boolean looted = true; private Rarity rarity; private int maxLevel = 1; + private EquipmentSlot[] slots; + private EnchantmentTarget target; + private boolean allItems; + + public static Options create(EnchantmentTarget target, EquipmentSlot... slots) { + return new Options(target, slots); + } + + public static Options armor() { + return create(EnchantmentTarget.ARMOR, UEnchantmentValidSlots.ARMOR); + } + + public static Options allItems() { + return create(EnchantmentTarget.VANISHABLE, UEnchantmentValidSlots.ANY).ignoreTarget(); + } + + Options(EnchantmentTarget target, EquipmentSlot[] slots) { + this.slots = slots; + this.target = target; + } + + public Options ignoreTarget() { + allItems = true; + return this; + } /** * Sets how rare this enchantment is when using the enchantment table. diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java index 774c7426..f4706035 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java @@ -8,7 +8,7 @@ import com.minelittlepony.unicopia.entity.player.Pony; public class StressfulEnchantment extends SimpleEnchantment { protected StressfulEnchantment(Options options) { - super(options, UEnchantmentValidSlots.ANY); + super(options); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java index 888328e8..c1f0ff8e 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java @@ -25,17 +25,17 @@ public interface UEnchantments { /** * Makes a sound when there are interesting blocks in your area. */ - Enchantment GEM_FINDER = register("gem_finder", new GemFindingEnchantment(new Options().rarity(Rarity.RARE).maxLevel(3).treasure())); + Enchantment GEM_FINDER = register("gem_finder", new GemFindingEnchantment(Options.create(EnchantmentTarget.DIGGER, UEnchantmentValidSlots.HANDS).rarity(Rarity.RARE).maxLevel(3).treasure())); /** * Protects against wall collisions and earth pony attacks! */ - Enchantment PADDED = register("padded", new SimpleEnchantment(new Options().rarity(Rarity.COMMON).maxLevel(3), EnchantmentTarget.ARMOR, UEnchantmentValidSlots.ARMOR)); + Enchantment PADDED = register("padded", new SimpleEnchantment(Options.armor().rarity(Rarity.COMMON).maxLevel(3))); /** * Heavy players move more slowly but are less likely to be flung around wildly. */ - Enchantment HEAVY = register("heavy", new AttributedEnchantment(new Options().rarity(Rarity.COMMON).maxLevel(4), EnchantmentTarget.ARMOR, UEnchantmentValidSlots.ARMOR)) + Enchantment HEAVY = register("heavy", new AttributedEnchantment(Options.armor().rarity(Rarity.COMMON).maxLevel(4))) .addModifier(EntityAttributes.GENERIC_MOVEMENT_SPEED, (user, level) -> { return new EntityAttributeModifier(UUID.fromString("a3d5a94f-4c40-48f6-a343-558502a13e10"), "Heavyness", (1 - level/(float)10) - 1, Operation.MULTIPLY_TOTAL); }); @@ -45,12 +45,12 @@ public interface UEnchantments { * * Weapons will become stronger the more allies you have around. */ - Enchantment HERDS = register("herds", new CollaboratorEnchantment(new Options().rarity(Rarity.RARE).maxLevel(3))); + Enchantment HERDS = register("herds", new CollaboratorEnchantment(Options.create(EnchantmentTarget.WEAPON, EquipmentSlot.MAINHAND).rarity(Rarity.RARE).maxLevel(3))); /** * Alters gravity */ - Enchantment REPULSION = register("repulsion", new AttributedEnchantment(new Options().rarity(Rarity.VERY_RARE).maxLevel(3), EnchantmentTarget.ARMOR_FEET, EquipmentSlot.FEET)) + Enchantment REPULSION = register("repulsion", new AttributedEnchantment(Options.create(EnchantmentTarget.ARMOR_FEET, EquipmentSlot.FEET).rarity(Rarity.VERY_RARE).maxLevel(3))) .addModifier(UEntityAttributes.ENTITY_GRAVTY_MODIFIER, (user, level) -> { return new EntityAttributeModifier(UUID.fromString("1734bbd6-1916-4124-b710-5450ea70fbdb"), "Anti Grav", (0.5F - (0.375 * (level - 1))) - 1, Operation.MULTIPLY_TOTAL); }); @@ -60,35 +60,35 @@ public interface UEnchantments { * * Mobs really want your candy. You'd better give it to them. */ - Enchantment WANT_IT_NEED_IT = register("want_it_need_it", new WantItNeedItEnchantment(new Options().rarity(Rarity.VERY_RARE).curse().treasure())); + Enchantment WANT_IT_NEED_IT = register("want_it_need_it", new WantItNeedItEnchantment(Options.allItems().rarity(Rarity.VERY_RARE).curse().treasure())); /** * Hahaha geddit? * * Random things happen. */ - PoisonedJokeEnchantment POISONED_JOKE = register("poisoned_joke", new PoisonedJokeEnchantment(new Options().rarity(Rarity.VERY_RARE).curse().tradedOnly())); + PoisonedJokeEnchantment POISONED_JOKE = register("poisoned_joke", new PoisonedJokeEnchantment(Options.allItems().rarity(Rarity.VERY_RARE).curse().tradedOnly())); /** * Who doesn't like a good freakout? */ - Enchantment STRESSED = register("stressed", new StressfulEnchantment(new Options().rarity(Rarity.RARE).curse().treasure().maxLevel(3))); + Enchantment STRESSED = register("stressed", new StressfulEnchantment(Options.allItems().rarity(Rarity.RARE).curse().treasure().maxLevel(3))); /** * This item just wants to be held. */ - Enchantment CLINGY = register("clingy", new SimpleEnchantment(new Options().rarity(Rarity.VERY_RARE).curse().maxLevel(6), UEnchantmentValidSlots.ANY)); + Enchantment CLINGY = register("clingy", new SimpleEnchantment(Options.allItems().rarity(Rarity.VERY_RARE).curse().maxLevel(6))); /** * Items with loyalty are kept after death. * Only works if they don't also have curse of binding. */ - Enchantment HEART_BOUND = register("heart_bound", new SimpleEnchantment(new Options().rarity(Rarity.COMMON).maxLevel(5), EnchantmentTarget.VANISHABLE, UEnchantmentValidSlots.ANY)); + Enchantment HEART_BOUND = register("heart_bound", new SimpleEnchantment(Options.create(EnchantmentTarget.VANISHABLE, UEnchantmentValidSlots.ANY).rarity(Rarity.COMMON).maxLevel(5))); /** * Consumes drops whilst mining and produces experience instead */ - Enchantment CONSUMPTION = register("consumption", new ConsumptionEnchantment(new Options().rarity(Rarity.VERY_RARE))); + Enchantment CONSUMPTION = register("consumption", new ConsumptionEnchantment(Options.create(EnchantmentTarget.DIGGER, UEnchantmentValidSlots.HANDS).rarity(Rarity.VERY_RARE))); static void bootstrap() { } diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java index 50e62030..b206ff4e 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java @@ -12,7 +12,7 @@ import net.minecraft.item.ItemStack; public class WantItNeedItEnchantment extends SimpleEnchantment { protected WantItNeedItEnchantment(Options options) { - super(options, UEnchantmentValidSlots.ANY); + super(options); } @Override