That's one heck of a commit you've got there...

I may have got a bit behind with version control. A lot behind, in fact. Maybe I'll go back and split this sometime - then again, I probably won't. But hey, at least it's here!
This commit is contained in:
Electroblob77
2019-08-18 00:04:18 +01:00
parent 2680d02304
commit f37812be3e
1564 changed files with 47652 additions and 12984 deletions
@@ -0,0 +1,111 @@
package electroblob.wizardry.enchantment;
import electroblob.wizardry.util.IElementalDamage;
import electroblob.wizardry.util.MagicDamage;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentProtection;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.util.DamageSource;
import java.util.function.Predicate;
/**
* This class is for the various magic protection enchantments added by wizardry.
*/
// This was mostly copied from EnchantmentProtection, with the code cleaned up a lot (the vanilla one is awful java...)
public class EnchantmentMagicProtection extends Enchantment {
/** The type of protection this enchantment gives. */
public final EnchantmentMagicProtection.Type protectionType;
public EnchantmentMagicProtection(Enchantment.Rarity rarity, EnchantmentMagicProtection.Type protectionType, EntityEquipmentSlot... slots){
super(rarity, EnumEnchantmentType.ARMOR, slots);
this.protectionType = protectionType;
}
// Who knew this was so complicated?
// https://minecraft.gamepedia.com/Tutorials/Enchantment_mechanics#How_enchantments_are_chosen
// https://minecraft.gamepedia.com/Enchanting/Levels <- This is what the results of the 2 methods below are compared to
@Override
public int getMinEnchantability(int enchantmentLevel){
return this.protectionType.getMinimalEnchantability() + (enchantmentLevel - 1) * this.protectionType.getEnchantIncreasePerLevel();
}
@Override
public int getMaxEnchantability(int enchantmentLevel){
return this.getMinEnchantability(enchantmentLevel) + this.protectionType.getEnchantIncreasePerLevel();
}
@Override
public int getMaxLevel(){
return 4;
}
@Override
public int calcModifierDamage(int level, DamageSource source){
if(source.canHarmInCreative()) return 0;
if(this.protectionType.protectsAgainst(source)) return this.protectionType.getProtectionMultiplier() * level;
return 0;
}
@Override
public String getName(){
return "enchantment.ebwizardry:" + this.protectionType.getTypeName() + "_protection";
}
@Override
public boolean canApplyTogether(Enchantment ench){
if(ench instanceof EnchantmentMagicProtection){
return false; // As per EnchantmentProtection, only feather falling can be applied with other protection types
}else if(ench instanceof EnchantmentProtection){
return ((EnchantmentProtection)ench).protectionType == EnchantmentProtection.Type.FALL;
}else{
return super.canApplyTogether(ench);
}
}
public enum Type {
MAGIC("magic", 1, 5, 8, s -> s instanceof IElementalDamage),
FROST("frost", 2, 10, 8, s -> s instanceof IElementalDamage && ((IElementalDamage)s).getType() == MagicDamage.DamageType.FROST),
SHOCK("shock", 2, 10, 8, s -> s instanceof IElementalDamage && ((IElementalDamage)s).getType() == MagicDamage.DamageType.SHOCK);
// Fire already exists, and the other types aren't used enough to be worth having
private final String typeName;
private final int minEnchantability;
private final int levelCost;
// What the heck was levelCostSpan for? Removed since it's never used.
private final Predicate<DamageSource> criteria;
private final int protectionMultiplier;
Type(String name, int protectionMultiplier, int minEnchantability, int perLevelEnchantability, Predicate<DamageSource> criteria){
this.typeName = name;
this.minEnchantability = minEnchantability;
this.levelCost = perLevelEnchantability;
this.criteria = criteria;
this.protectionMultiplier = protectionMultiplier;
}
public String getTypeName(){
return this.typeName;
}
public boolean protectsAgainst(DamageSource source){
return criteria.test(source);
}
public int getMinimalEnchantability(){
return this.minEnchantability;
}
public int getEnchantIncreasePerLevel(){
return this.levelCost;
}
public int getProtectionMultiplier(){
return protectionMultiplier;
}
}
}
@@ -1,12 +1,10 @@
package electroblob.wizardry.enchantment;
import java.util.Iterator;
import java.util.Map;
import com.google.common.collect.Iterables;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.registry.WizardryEnchantments;
import electroblob.wizardry.spell.FreezingWeapon;
import electroblob.wizardry.spell.ImbueWeapon;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
@@ -15,7 +13,6 @@ import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
@@ -28,6 +25,8 @@ import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.Iterator;
/**
* Interface for temporary enchantments that last for a certain duration ('imbuements'). This interface allows
* {@link EnchantmentMagicSword} and {@link EnchantmentTimed} to both be treated as instances of a single type, rather
@@ -59,8 +58,7 @@ public interface Imbuement {
/** Removes all imbuements from the given itemstack. */
static void removeImbuements(ItemStack stack){
if(stack.isItemEnchanted()){
// No need to check what enchantments the item has, since remove() does nothing if the element does not
// exist.
// No need to check what enchantments the item has, since remove() does nothing if the element does not exist
NBTTagList enchantmentList = stack.getItem() == Items.ENCHANTED_BOOK ?
ItemEnchantedBook.getEnchantments(stack) : stack.getEnchantmentTagList();
// Check all enchantments of the item
@@ -96,7 +94,7 @@ public interface Imbuement {
// If any imbuements were removed, inform about the removal of the enchantment(s), or
// delete the book entirely if there are none left.
if(enchantmentList.isEmpty()){
slot.putStack(ItemStack.EMPTY); // NOTE: Will need changing in 1.11
slot.putStack(ItemStack.EMPTY);
Wizardry.logger.info("Deleted enchanted book with illegal enchantments");
}else{
// Inform about enchantment removal
@@ -122,9 +120,9 @@ public interface Imbuement {
ItemStack bow = archer.getHeldItemMainhand();
if(!(bow.getItem() instanceof ItemBow)){
if(!ImbueWeapon.isBow(bow.getItem())){
bow = archer.getHeldItemOffhand();
if(!(bow.getItem() instanceof ItemBow)) return;
if(!ImbueWeapon.isBow(bow.getItem())) return;
}
// Taken directly from ItemBow, so it works exactly the same as the power enchantment.