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 39917f2c..c6a0729a 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java @@ -17,12 +17,12 @@ public class AttributedEnchantment extends SimpleEnchantment { private final Map modifiers = new HashMap<>(); - protected AttributedEnchantment(Rarity rarity, EnchantmentTarget target, boolean cursed, int maxLevel, EquipmentSlot... slots) { - super(rarity, target, cursed, maxLevel, slots); + protected AttributedEnchantment(Options options, EnchantmentTarget target, EquipmentSlot... slots) { + super(options, target, slots); } - protected AttributedEnchantment(Rarity rarity, boolean cursed, int maxLevel, EquipmentSlot... slots) { - super(rarity, cursed, maxLevel, slots); + protected AttributedEnchantment(Options options, EquipmentSlot... slots) { + super(options, slots); } 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 117fdd0b..3322b362 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.item.enchantment; 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; @@ -13,8 +14,8 @@ import net.minecraft.entity.attribute.EntityAttributeModifier.Operation; public class CollaboratorEnchantment extends AttributedEnchantment { private static final UUID TEAM_STRENGTH_UUID = UUID.fromString("5f08c02d-d959-4763-ac84-16e2acfd4b62"); - protected CollaboratorEnchantment() { - super(Rarity.RARE, EnchantmentTarget.WEAPON, false, 3, EquipmentSlot.MAINHAND); + protected CollaboratorEnchantment(Options options) { + super(options, EnchantmentTarget.WEAPON, EquipmentSlot.MAINHAND); this.addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier); } 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 3924cf4b..83c3e032 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/ConsumptionEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/ConsumptionEnchantment.java @@ -24,8 +24,8 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; public class ConsumptionEnchantment extends SimpleEnchantment { - protected ConsumptionEnchantment() { - super(Rarity.VERY_RARE, EnchantmentTarget.DIGGER, false, 1, UEnchantmentValidSlots.HANDS); + protected ConsumptionEnchantment(Options options) { + super(options, EnchantmentTarget.DIGGER, UEnchantmentValidSlots.HANDS); } 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 5e4ef687..1ecabfca 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java @@ -13,8 +13,8 @@ import net.minecraft.util.math.BlockPos; public class GemFindingEnchantment extends SimpleEnchantment { - protected GemFindingEnchantment() { - super(Rarity.RARE, EnchantmentTarget.DIGGER, false, 3, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND); + protected GemFindingEnchantment(Options options) { + super(options, EnchantmentTarget.DIGGER, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND); } @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 03ce128c..cd01a4d7 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java @@ -29,8 +29,8 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi private static final Type TYPE = TypeUtils.parameterize(List.class, Identifier.class); private List sounds = new ArrayList<>(); - protected PoisonedJokeEnchantment() { - super(Rarity.VERY_RARE, true, 1, UEnchantmentValidSlots.ANY); + protected PoisonedJokeEnchantment(Options options) { + super(options, UEnchantmentValidSlots.ANY); } @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 cd4da131..64cc395b 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java @@ -9,27 +9,23 @@ import net.minecraft.item.ItemStack; public class SimpleEnchantment extends Enchantment { - private final boolean cursed; - private final boolean allItems; - private final int maxLevel; - private final EquipmentSlot[] slots; - protected SimpleEnchantment(Rarity rarity, EnchantmentTarget target, boolean cursed, int maxLevel, EquipmentSlot... slots) { - super(rarity, target, slots); - this.cursed = cursed; + private final Options options; + + protected SimpleEnchantment(Options options, EnchantmentTarget target, EquipmentSlot... slots) { + super(options.rarity, target, slots); + this.options = options; this.allItems = false; - this.maxLevel = maxLevel; this.slots = slots; } - protected SimpleEnchantment(Rarity rarity, boolean cursed, int maxLevel, EquipmentSlot... slots) { - super(rarity, EnchantmentTarget.VANISHABLE, slots); // vanishable includes breakable. It's the one that accepts the widest variety of items - this.cursed = cursed; + 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.maxLevel = maxLevel; this.slots = slots; } @@ -55,13 +51,28 @@ public class SimpleEnchantment extends Enchantment { } @Override - public int getMaxLevel() { - return maxLevel; + public final int getMaxLevel() { + return options.maxLevel; } @Override - public boolean isCursed() { - return cursed; + public final boolean isCursed() { + return options.cursed; + } + + @Override + public final boolean isTreasure() { + return options.treasured; + } + + @Override + public final boolean isAvailableForEnchantedBookOffer() { + return options.traded; + } + + @Override + public final boolean isAvailableForRandomSelection() { + return options.looted; } public static class Data { @@ -75,4 +86,67 @@ public class SimpleEnchantment extends Enchantment { return true; } } + + public static class Options { + private boolean cursed; + private boolean treasured; + private boolean traded = true; + private boolean looted = true; + private Rarity rarity; + private int maxLevel = 1; + + /** + * Sets how rare this enchantment is when using the enchantment table. + * Enchantments with a higher rarity appear less often and costs the user more experience when working with it the anvil. + */ + public Options rarity(Rarity rarity) { + this.rarity = rarity; + return this; + } + + /** + * Whether this enchantment is considered a negative effect by the game. + * + * Cursed enchantments are removed when repairing an item + * and do not give the user experience points when removed using a grindstone. + */ + public Options curse() { + cursed = true; + return this; + } + + /** + * Treasure enchantments only generate in loot tables with high-value items or by trading with villagers. + * They do not appear in the enchanting table. + */ + public Options treasure() { + treasured = true; + return this; + } + + /** + * Loot-Only enchantments do not appear in villager trades. + * They may still appear in loot table generation and can be found in the enchanting table. + */ + public Options lootedOnly() { + traded = false; + looted = true; + return this; + } + + /** + * Trade-Only enchantments are excluded from loot table generation and do not appear in the enchanting table. + * They can only be found by trading with villagers. + */ + public Options tradedOnly() { + looted = false; + traded = true; + return this; + } + + public Options maxLevel(int level) { + maxLevel = level; + return this; + } + } } 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 70dee276..774c7426 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java @@ -2,12 +2,13 @@ package com.minelittlepony.unicopia.item.enchantment; import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar; + import com.minelittlepony.unicopia.entity.player.Pony; public class StressfulEnchantment extends SimpleEnchantment { - protected StressfulEnchantment() { - super(Rarity.RARE, true, 3, UEnchantmentValidSlots.ANY); + protected StressfulEnchantment(Options options) { + super(options, UEnchantmentValidSlots.ANY); } @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 449ec7bc..888328e8 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java @@ -6,6 +6,7 @@ import java.util.UUID; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.entity.UEntityAttributes; +import com.minelittlepony.unicopia.item.enchantment.SimpleEnchantment.Options; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment.Rarity; @@ -24,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()); + Enchantment GEM_FINDER = register("gem_finder", new GemFindingEnchantment(new Options().rarity(Rarity.RARE).maxLevel(3).treasure())); /** * Protects against wall collisions and earth pony attacks! */ - Enchantment PADDED = register("padded", new SimpleEnchantment(Rarity.COMMON, EnchantmentTarget.ARMOR, false, 3, UEnchantmentValidSlots.ARMOR)); + Enchantment PADDED = register("padded", new SimpleEnchantment(new Options().rarity(Rarity.COMMON).maxLevel(3), EnchantmentTarget.ARMOR, UEnchantmentValidSlots.ARMOR)); /** * Heavy players move more slowly but are less likely to be flung around wildly. */ - Enchantment HEAVY = register("heavy", new AttributedEnchantment(Rarity.COMMON, EnchantmentTarget.ARMOR, false, 4, UEnchantmentValidSlots.ARMOR)) + Enchantment HEAVY = register("heavy", new AttributedEnchantment(new Options().rarity(Rarity.COMMON).maxLevel(4), EnchantmentTarget.ARMOR, UEnchantmentValidSlots.ARMOR)) .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); }); @@ -44,12 +45,12 @@ public interface UEnchantments { * * Weapons will become stronger the more allies you have around. */ - Enchantment HERDS = register("herds", new CollaboratorEnchantment()); + Enchantment HERDS = register("herds", new CollaboratorEnchantment(new Options().rarity(Rarity.RARE).maxLevel(3))); /** * Alters gravity */ - Enchantment REPULSION = register("repulsion", new AttributedEnchantment(Rarity.VERY_RARE, EnchantmentTarget.ARMOR_FEET, false, 3, EquipmentSlot.FEET)) + Enchantment REPULSION = register("repulsion", new AttributedEnchantment(new Options().rarity(Rarity.VERY_RARE).maxLevel(3), EnchantmentTarget.ARMOR_FEET, EquipmentSlot.FEET)) .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); }); @@ -59,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()); + Enchantment WANT_IT_NEED_IT = register("want_it_need_it", new WantItNeedItEnchantment(new Options().rarity(Rarity.VERY_RARE).curse().treasure())); /** * Hahaha geddit? * * Random things happen. */ - PoisonedJokeEnchantment POISONED_JOKE = register("poisoned_joke", new PoisonedJokeEnchantment()); + PoisonedJokeEnchantment POISONED_JOKE = register("poisoned_joke", new PoisonedJokeEnchantment(new Options().rarity(Rarity.VERY_RARE).curse().tradedOnly())); /** * Who doesn't like a good freakout? */ - Enchantment STRESSED = register("stressed", new StressfulEnchantment()); + Enchantment STRESSED = register("stressed", new StressfulEnchantment(new Options().rarity(Rarity.RARE).curse().treasure().maxLevel(3))); /** * This item just wants to be held. */ - Enchantment CLINGY = register("clingy", new SimpleEnchantment(Rarity.VERY_RARE, true, 6, UEnchantmentValidSlots.ANY)); + Enchantment CLINGY = register("clingy", new SimpleEnchantment(new Options().rarity(Rarity.VERY_RARE).curse().maxLevel(6), UEnchantmentValidSlots.ANY)); /** * 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(Rarity.COMMON, EnchantmentTarget.VANISHABLE, false, 5, UEnchantmentValidSlots.ANY)); + Enchantment HEART_BOUND = register("heart_bound", new SimpleEnchantment(new Options().rarity(Rarity.COMMON).maxLevel(5), EnchantmentTarget.VANISHABLE, UEnchantmentValidSlots.ANY)); /** * Consumes drops whilst mining and produces experience instead */ - Enchantment CONSUMPTION = register("consumption", new ConsumptionEnchantment()); + Enchantment CONSUMPTION = register("consumption", new ConsumptionEnchantment(new Options().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 ded97190..50e62030 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java @@ -11,8 +11,8 @@ import net.minecraft.item.ItemStack; public class WantItNeedItEnchantment extends SimpleEnchantment { - protected WantItNeedItEnchantment() { - super(Rarity.VERY_RARE, true, 1, UEnchantmentValidSlots.ANY); + protected WantItNeedItEnchantment(Options options) { + super(options, UEnchantmentValidSlots.ANY); } @Override