Move target and slots to the enchantment options

This commit is contained in:
Sollace 2023-06-01 14:33:18 +01:00
parent a5f11aca36
commit 76f366b5e3
9 changed files with 49 additions and 47 deletions

View file

@ -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<EntityAttribute, ModifierFactory> 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) {

View file

@ -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

View file

@ -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) {

View file

@ -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

View file

@ -30,7 +30,7 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi
private List<SoundEvent> sounds = new ArrayList<>();
protected PoisonedJokeEnchantment(Options options) {
super(options, UEnchantmentValidSlots.ANY);
super(options);
}
@Override

View file

@ -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.

View file

@ -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

View file

@ -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() { }

View file

@ -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