Update enchantment obtainability:

gem_finder, want_it_need_it, stressed are now a treasures
 poisoned_joke can only be found by trading
This commit is contained in:
Sollace 2023-06-01 14:09:15 +01:00
parent a13ec4979a
commit a5f11aca36
9 changed files with 120 additions and 43 deletions

View file

@ -17,12 +17,12 @@ public class AttributedEnchantment extends SimpleEnchantment {
private final Map<EntityAttribute, ModifierFactory> modifiers = new HashMap<>(); private final Map<EntityAttribute, ModifierFactory> modifiers = new HashMap<>();
protected AttributedEnchantment(Rarity rarity, EnchantmentTarget target, boolean cursed, int maxLevel, EquipmentSlot... slots) { protected AttributedEnchantment(Options options, EnchantmentTarget target, EquipmentSlot... slots) {
super(rarity, target, cursed, maxLevel, slots); super(options, target, slots);
} }
protected AttributedEnchantment(Rarity rarity, boolean cursed, int maxLevel, EquipmentSlot... slots) { protected AttributedEnchantment(Options options, EquipmentSlot... slots) {
super(rarity, cursed, maxLevel, slots); super(options, slots);
} }
public AttributedEnchantment addModifier(EntityAttribute attribute, ModifierFactory modifierSupplier) { public AttributedEnchantment addModifier(EntityAttribute attribute, ModifierFactory modifierSupplier) {

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.item.enchantment;
import java.util.UUID; import java.util.UUID;
import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.Living;
import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.EnchantmentTarget; import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
@ -13,8 +14,8 @@ import net.minecraft.entity.attribute.EntityAttributeModifier.Operation;
public class CollaboratorEnchantment extends AttributedEnchantment { public class CollaboratorEnchantment extends AttributedEnchantment {
private static final UUID TEAM_STRENGTH_UUID = UUID.fromString("5f08c02d-d959-4763-ac84-16e2acfd4b62"); private static final UUID TEAM_STRENGTH_UUID = UUID.fromString("5f08c02d-d959-4763-ac84-16e2acfd4b62");
protected CollaboratorEnchantment() { protected CollaboratorEnchantment(Options options) {
super(Rarity.RARE, EnchantmentTarget.WEAPON, false, 3, EquipmentSlot.MAINHAND); super(options, EnchantmentTarget.WEAPON, EquipmentSlot.MAINHAND);
this.addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier); this.addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier);
} }

View file

@ -24,8 +24,8 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ConsumptionEnchantment extends SimpleEnchantment { public class ConsumptionEnchantment extends SimpleEnchantment {
protected ConsumptionEnchantment() { protected ConsumptionEnchantment(Options options) {
super(Rarity.VERY_RARE, EnchantmentTarget.DIGGER, false, 1, UEnchantmentValidSlots.HANDS); super(options, EnchantmentTarget.DIGGER, UEnchantmentValidSlots.HANDS);
} }
public static boolean applyConsumption(World w, BlockState state, BlockPos pos, @Nullable BlockEntity blockEntity, Entity entity, ItemStack tool) { public static boolean applyConsumption(World w, BlockState state, BlockPos pos, @Nullable BlockEntity blockEntity, Entity entity, ItemStack tool) {

View file

@ -13,8 +13,8 @@ import net.minecraft.util.math.BlockPos;
public class GemFindingEnchantment extends SimpleEnchantment { public class GemFindingEnchantment extends SimpleEnchantment {
protected GemFindingEnchantment() { protected GemFindingEnchantment(Options options) {
super(Rarity.RARE, EnchantmentTarget.DIGGER, false, 3, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND); super(options, EnchantmentTarget.DIGGER, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND);
} }
@Override @Override

View file

@ -29,8 +29,8 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi
private static final Type TYPE = TypeUtils.parameterize(List.class, Identifier.class); private static final Type TYPE = TypeUtils.parameterize(List.class, Identifier.class);
private List<SoundEvent> sounds = new ArrayList<>(); private List<SoundEvent> sounds = new ArrayList<>();
protected PoisonedJokeEnchantment() { protected PoisonedJokeEnchantment(Options options) {
super(Rarity.VERY_RARE, true, 1, UEnchantmentValidSlots.ANY); super(options, UEnchantmentValidSlots.ANY);
} }
@Override @Override

View file

@ -9,27 +9,23 @@ import net.minecraft.item.ItemStack;
public class SimpleEnchantment extends Enchantment { public class SimpleEnchantment extends Enchantment {
private final boolean cursed;
private final boolean allItems; private final boolean allItems;
private final int maxLevel;
private final EquipmentSlot[] slots; private final EquipmentSlot[] slots;
protected SimpleEnchantment(Rarity rarity, EnchantmentTarget target, boolean cursed, int maxLevel, EquipmentSlot... slots) { private final Options options;
super(rarity, target, slots);
this.cursed = cursed; protected SimpleEnchantment(Options options, EnchantmentTarget target, EquipmentSlot... slots) {
super(options.rarity, target, slots);
this.options = options;
this.allItems = false; this.allItems = false;
this.maxLevel = maxLevel;
this.slots = slots; this.slots = slots;
} }
protected SimpleEnchantment(Rarity rarity, boolean cursed, int maxLevel, EquipmentSlot... slots) { protected SimpleEnchantment(Options options, EquipmentSlot... slots) {
super(rarity, EnchantmentTarget.VANISHABLE, slots); // vanishable includes breakable. It's the one that accepts the widest variety of items super(options.rarity, EnchantmentTarget.VANISHABLE, slots); // vanishable includes breakable. It's the one that accepts the widest variety of items
this.cursed = cursed; this.options = options;
this.allItems = true; this.allItems = true;
this.maxLevel = maxLevel;
this.slots = slots; this.slots = slots;
} }
@ -55,13 +51,28 @@ public class SimpleEnchantment extends Enchantment {
} }
@Override @Override
public int getMaxLevel() { public final int getMaxLevel() {
return maxLevel; return options.maxLevel;
} }
@Override @Override
public boolean isCursed() { public final boolean isCursed() {
return cursed; 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 { public static class Data {
@ -75,4 +86,67 @@ public class SimpleEnchantment extends Enchantment {
return true; 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;
}
}
} }

View file

@ -2,12 +2,13 @@ package com.minelittlepony.unicopia.item.enchantment;
import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar; import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
public class StressfulEnchantment extends SimpleEnchantment { public class StressfulEnchantment extends SimpleEnchantment {
protected StressfulEnchantment() { protected StressfulEnchantment(Options options) {
super(Rarity.RARE, true, 3, UEnchantmentValidSlots.ANY); super(options, UEnchantmentValidSlots.ANY);
} }
@Override @Override

View file

@ -6,6 +6,7 @@ import java.util.UUID;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.entity.UEntityAttributes; import com.minelittlepony.unicopia.entity.UEntityAttributes;
import com.minelittlepony.unicopia.item.enchantment.SimpleEnchantment.Options;
import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantment.Rarity; import net.minecraft.enchantment.Enchantment.Rarity;
@ -24,17 +25,17 @@ public interface UEnchantments {
/** /**
* Makes a sound when there are interesting blocks in your area. * 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! * 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. * 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) -> { .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); 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. * 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 * 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) -> { .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); 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. * 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? * Hahaha geddit?
* *
* Random things happen. * 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? * 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. * 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. * Items with loyalty are kept after death.
* Only works if they don't also have curse of binding. * 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 * 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() { } static void bootstrap() { }

View file

@ -11,8 +11,8 @@ import net.minecraft.item.ItemStack;
public class WantItNeedItEnchantment extends SimpleEnchantment { public class WantItNeedItEnchantment extends SimpleEnchantment {
protected WantItNeedItEnchantment() { protected WantItNeedItEnchantment(Options options) {
super(Rarity.VERY_RARE, true, 1, UEnchantmentValidSlots.ANY); super(options, UEnchantmentValidSlots.ANY);
} }
@Override @Override