mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Move target and slots to the enchantment options
This commit is contained in:
parent
a5f11aca36
commit
76f366b5e3
9 changed files with 49 additions and 47 deletions
|
@ -7,7 +7,6 @@ import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.minelittlepony.unicopia.entity.Living;
|
import com.minelittlepony.unicopia.entity.Living;
|
||||||
|
|
||||||
import net.minecraft.enchantment.EnchantmentTarget;
|
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
import net.minecraft.entity.attribute.EntityAttribute;
|
import net.minecraft.entity.attribute.EntityAttribute;
|
||||||
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
||||||
|
@ -17,12 +16,8 @@ public class AttributedEnchantment extends SimpleEnchantment {
|
||||||
|
|
||||||
private final Map<EntityAttribute, ModifierFactory> modifiers = new HashMap<>();
|
private final Map<EntityAttribute, ModifierFactory> modifiers = new HashMap<>();
|
||||||
|
|
||||||
protected AttributedEnchantment(Options options, EnchantmentTarget target, EquipmentSlot... slots) {
|
protected AttributedEnchantment(Options options) {
|
||||||
super(options, target, slots);
|
super(options);
|
||||||
}
|
|
||||||
|
|
||||||
protected AttributedEnchantment(Options options, EquipmentSlot... slots) {
|
|
||||||
super(options, slots);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AttributedEnchantment addModifier(EntityAttribute attribute, ModifierFactory modifierSupplier) {
|
public AttributedEnchantment addModifier(EntityAttribute attribute, ModifierFactory modifierSupplier) {
|
||||||
|
|
|
@ -4,8 +4,6 @@ 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.entity.EquipmentSlot;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
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");
|
private static final UUID TEAM_STRENGTH_UUID = UUID.fromString("5f08c02d-d959-4763-ac84-16e2acfd4b62");
|
||||||
|
|
||||||
protected CollaboratorEnchantment(Options options) {
|
protected CollaboratorEnchantment(Options options) {
|
||||||
super(options, EnchantmentTarget.WEAPON, EquipmentSlot.MAINHAND);
|
super(options);
|
||||||
this.addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier);
|
addModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, this::getModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,7 +11,6 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.enchantment.EnchantmentTarget;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.ExperienceOrbEntity;
|
import net.minecraft.entity.ExperienceOrbEntity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
@ -25,7 +24,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ConsumptionEnchantment extends SimpleEnchantment {
|
public class ConsumptionEnchantment extends SimpleEnchantment {
|
||||||
protected ConsumptionEnchantment(Options options) {
|
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) {
|
public static boolean applyConsumption(World w, BlockState state, BlockPos pos, @Nullable BlockEntity blockEntity, Entity entity, ItemStack tool) {
|
||||||
|
|
|
@ -7,14 +7,12 @@ import com.minelittlepony.unicopia.entity.Living;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.enchantment.EnchantmentTarget;
|
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class GemFindingEnchantment extends SimpleEnchantment {
|
public class GemFindingEnchantment extends SimpleEnchantment {
|
||||||
|
|
||||||
protected GemFindingEnchantment(Options options) {
|
protected GemFindingEnchantment(Options options) {
|
||||||
super(options, EnchantmentTarget.DIGGER, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND);
|
super(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi
|
||||||
private List<SoundEvent> sounds = new ArrayList<>();
|
private List<SoundEvent> sounds = new ArrayList<>();
|
||||||
|
|
||||||
protected PoisonedJokeEnchantment(Options options) {
|
protected PoisonedJokeEnchantment(Options options) {
|
||||||
super(options, UEnchantmentValidSlots.ANY);
|
super(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,24 +9,11 @@ import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class SimpleEnchantment extends Enchantment {
|
public class SimpleEnchantment extends Enchantment {
|
||||||
|
|
||||||
private final boolean allItems;
|
|
||||||
|
|
||||||
private final EquipmentSlot[] slots;
|
|
||||||
|
|
||||||
private final Options options;
|
private final Options options;
|
||||||
|
|
||||||
protected SimpleEnchantment(Options options, EnchantmentTarget target, EquipmentSlot... slots) {
|
protected SimpleEnchantment(Options options) {
|
||||||
super(options.rarity, target, slots);
|
super(options.rarity, options.target, options.slots);
|
||||||
this.options = options;
|
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) {
|
public void onUserTick(Living<?> user, int level) {
|
||||||
|
@ -43,11 +30,11 @@ public class SimpleEnchantment extends Enchantment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAcceptableItem(ItemStack itemStack) {
|
public boolean isAcceptableItem(ItemStack itemStack) {
|
||||||
return allItems || super.isAcceptableItem(itemStack);
|
return options.allItems || super.isAcceptableItem(itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EquipmentSlot[] getSlots() {
|
public EquipmentSlot[] getSlots() {
|
||||||
return slots;
|
return options.slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,6 +81,31 @@ public class SimpleEnchantment extends Enchantment {
|
||||||
private boolean looted = true;
|
private boolean looted = true;
|
||||||
private Rarity rarity;
|
private Rarity rarity;
|
||||||
private int maxLevel = 1;
|
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.
|
* Sets how rare this enchantment is when using the enchantment table.
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
public class StressfulEnchantment extends SimpleEnchantment {
|
public class StressfulEnchantment extends SimpleEnchantment {
|
||||||
|
|
||||||
protected StressfulEnchantment(Options options) {
|
protected StressfulEnchantment(Options options) {
|
||||||
super(options, UEnchantmentValidSlots.ANY);
|
super(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,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(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!
|
* 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.
|
* 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) -> {
|
.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);
|
||||||
});
|
});
|
||||||
|
@ -45,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(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
|
* 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) -> {
|
.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);
|
||||||
});
|
});
|
||||||
|
@ -60,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(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?
|
* Hahaha geddit?
|
||||||
*
|
*
|
||||||
* Random things happen.
|
* 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?
|
* 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.
|
* 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.
|
* 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(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
|
* 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() { }
|
static void bootstrap() { }
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import net.minecraft.item.ItemStack;
|
||||||
public class WantItNeedItEnchantment extends SimpleEnchantment {
|
public class WantItNeedItEnchantment extends SimpleEnchantment {
|
||||||
|
|
||||||
protected WantItNeedItEnchantment(Options options) {
|
protected WantItNeedItEnchantment(Options options) {
|
||||||
super(options, UEnchantmentValidSlots.ANY);
|
super(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue