change package names

This commit is contained in:
Sen 2025-05-07 18:19:24 +02:00
parent 3e70accb76
commit d08d0e11fc
1246 changed files with 9285 additions and 9272 deletions

View file

@ -0,0 +1,221 @@
package common.enchantment;
import java.util.List;
import java.util.Map;
import java.util.Set;
import common.collect.Lists;
import common.collect.Maps;
import common.entity.DamageSource;
import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.item.ItemStack;
public abstract class Enchantment
{
private static final String[] LEVELS = new String[] {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};
private static final Enchantment[] enchantmentsList = new Enchantment[256];
public static final Enchantment[] enchantmentsBookList;
private static final Map<String, Enchantment> locationEnchantments = Maps.<String, Enchantment>newHashMap();
public static final Enchantment protection = new EnchantmentProtection(0, "protection", 10, 0);
public static final Enchantment fireProtection = new EnchantmentProtection(1, "fire_protection", 5, 1);
public static final Enchantment featherFalling = new EnchantmentProtection(2, "feather_falling", 5, 2);
public static final Enchantment blastProtection = new EnchantmentProtection(3, "blast_protection", 2, 3);
public static final Enchantment projectileProtection = new EnchantmentProtection(4, "projectile_protection", 5, 4);
// public static final Enchantment respiration = new EnchantmentOxygen(5, "respiration", 2);
// public static final Enchantment aquaAffinity = new EnchantmentWaterWorker(6, "aqua_affinity", 2);
public static final Enchantment thorns = new EnchantmentThorns(7, "thorns", 1);
// public static final Enchantment depthStrider = new EnchantmentWaterWalker(8, "depth_strider", 2);
public static final Enchantment sharpness = new EnchantmentDamage(16, "sharpness", 10);
// public static final Enchantment smite = new EnchantmentDamage(17, "smite", 5, 1);
// public static final Enchantment baneOfArthropods = new EnchantmentDamage(18, "bane_of_arthropods", 5, 2);
public static final Enchantment knockback = new EnchantmentKnockback(19, "knockback", 5);
public static final Enchantment fireAspect = new EnchantmentFireAspect(20, "fire_aspect", 2);
public static final Enchantment looting = new EnchantmentLootBonus(21, "looting", 2, EnumEnchantmentType.WEAPON);
public static final Enchantment efficiency = new EnchantmentDigging(32, "efficiency", 10);
public static final Enchantment silkTouch = new EnchantmentUntouching(33, "silk_touch", 1);
public static final Enchantment unbreaking = new EnchantmentDurability(34, "unbreaking", 5);
public static final Enchantment fortune = new EnchantmentLootBonus(35, "fortune", 2, EnumEnchantmentType.DIGGER);
public static final Enchantment power = new EnchantmentArrowDamage(48, "power", 10);
public static final Enchantment punch = new EnchantmentArrowKnockback(49, "punch", 2);
public static final Enchantment flame = new EnchantmentArrowFire(50, "flame", 2);
public static final Enchantment infinity = new EnchantmentArrowInfinite(51, "infinity", 1);
public static final Enchantment luckOfTheSea = new EnchantmentLootBonus(61, "luck_of_the_sea", 2, EnumEnchantmentType.FISHING_ROD);
public static final Enchantment lure = new EnchantmentFishingSpeed(62, "lure", 2, EnumEnchantmentType.FISHING_ROD);
public static final Enchantment draining = new EnchantmentDraining(64, "draining", 1);
public final int effectId;
private final int weight;
/** The EnumEnchantmentType given to this Enchantment. */
public EnumEnchantmentType type;
/** Used in localisation and stats. */
protected String name;
/**
* Retrieves an Enchantment from the enchantmentsList
*/
public static Enchantment getEnchantmentById(int enchID)
{
return enchID >= 0 && enchID < enchantmentsList.length ? enchantmentsList[enchID] : null;
}
protected Enchantment(int enchID, String enchName, int enchWeight, EnumEnchantmentType enchType)
{
this.effectId = enchID;
this.weight = enchWeight;
this.type = enchType;
if (enchantmentsList[enchID] != null)
{
throw new IllegalArgumentException("Duplicate enchantment id!");
}
else
{
enchantmentsList[enchID] = this;
locationEnchantments.put(enchName, this);
}
}
/**
* Retrieves an enchantment by using its location name.
*/
public static Enchantment getEnchantmentByLocation(String location)
{
return locationEnchantments.get(location);
}
public static Set<String> getNames()
{
return locationEnchantments.keySet();
}
/**
* Retrieves the weight value of an Enchantment. This weight value is used within vanilla to determine how rare an
* enchantment is.
*/
public int getWeight()
{
return this.weight;
}
/**
* Returns the minimum level that the enchantment can have.
*/
public int getMinLevel()
{
return 1;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 1;
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 1 + enchantmentLevel * 10;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + 5;
}
/**
* Calculates the damage protection of the enchantment based on level and damage source passed.
*/
public int calcDamageReduction(int level, DamageSource source)
{
return 0;
}
/**
* Calculates the additional damage that will be dealt by an item with this enchantment. This alternative to
* calcModifierDamage is sensitive to the targets EnumCreatureAttribute.
*/
public int calcAdditionalDamage(int level)
{
return 0;
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
public boolean canApplyTogether(Enchantment ench)
{
return this != ench;
}
/**
* Sets the enchantment name
*/
public Enchantment setName(String enchName)
{
this.name = enchName;
return this;
}
/**
* Return the name of key of this enchantment.
*/
public String getName()
{
return this.name;
}
public String getFormattedName(int level)
{
return this.getName() + " " + ((level >= 1 && level <= 10) ? LEVELS[level - 1] : "" + level);
}
/**
* Determines if this enchantment can be applied to a specific ItemStack.
*/
public boolean canApply(ItemStack stack)
{
return this.type.canEnchantItem(stack.getItem());
}
/**
* Called whenever a mob is damaged with an item that has this enchantment on it.
*/
public void onEntityDamaged(EntityLiving user, Entity target, int level)
{
}
/**
* Whenever an entity that has this enchantment on one of its associated items is damaged this method will be
* called.
*/
public void onUserHurt(EntityLiving user, Entity attacker, int level)
{
}
static
{
List<Enchantment> list = Lists.<Enchantment>newArrayList();
for (Enchantment enchantment : enchantmentsList)
{
if (enchantment != null)
{
list.add(enchantment);
}
}
enchantmentsBookList = (Enchantment[])list.toArray(new Enchantment[list.size()]);
}
}

View file

@ -0,0 +1,36 @@
package common.enchantment;
public class EnchantmentArrowDamage extends Enchantment
{
public EnchantmentArrowDamage(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BOW);
this.setName("Stärke");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 1 + (enchantmentLevel - 1) * 10;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + 15;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 5;
}
}

View file

@ -0,0 +1,36 @@
package common.enchantment;
public class EnchantmentArrowFire extends Enchantment
{
public EnchantmentArrowFire(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BOW);
this.setName("Flamme");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 20;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 1;
}
}

View file

@ -0,0 +1,36 @@
package common.enchantment;
public class EnchantmentArrowInfinite extends Enchantment
{
public EnchantmentArrowInfinite(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BOW);
this.setName("Unendlich");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 20;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 1;
}
}

View file

@ -0,0 +1,36 @@
package common.enchantment;
public class EnchantmentArrowKnockback extends Enchantment
{
public EnchantmentArrowKnockback(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BOW);
this.setName("Schlag");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 12 + (enchantmentLevel - 1) * 20;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + 25;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 2;
}
}

View file

@ -0,0 +1,80 @@
package common.enchantment;
import common.item.ItemAxe;
import common.item.ItemStack;
public class EnchantmentDamage extends Enchantment
{
public EnchantmentDamage(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.WEAPON);
this.setName("Schärfe");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 1 + (enchantmentLevel - 1) * 11;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + 20;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 5;
}
/**
* Calculates the additional damage that will be dealt by an item with this enchantment. This alternative to
* calcModifierDamage is sensitive to the targets EnumCreatureAttribute.
*/
public int calcAdditionalDamage(int level)
{
return (int)(/*this.damageType == 0 ? */ (float)level * 1.25F); // : (this.damageType == 1 && creatureType == CreatureType.UNDEAD ? (float)level * 2.5F : (this.damageType == 2 && creatureType == CreatureType.ARTHROPOD ? (float)level * 2.5F : 0.0F)));
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
public boolean canApplyTogether(Enchantment ench)
{
return !(ench instanceof EnchantmentDamage);
}
/**
* Determines if this enchantment can be applied to a specific ItemStack.
*/
public boolean canApply(ItemStack stack)
{
return stack.getItem() instanceof ItemAxe ? true : super.canApply(stack);
}
// /**
// * Called whenever a mob is damaged with an item that has this enchantment on it.
// */
// public void onEntityDamaged(EntityLivingBase user, Entity target, int level)
// {
// if (target instanceof EntityLivingBase)
// {
// EntityLivingBase entitylivingbase = (EntityLivingBase)target;
//
// if (this.damageType == 2 && entitylivingbase.getCreatureType() == CreatureType.ARTHROPOD)
// {
// int i = 20 + user.getRNG().zrange(10 * level);
// entitylivingbase.addEffect(new PotionEffect(Potion.moveSlowdown.id, i, 3));
// }
// }
// }
}

View file

@ -0,0 +1,46 @@
package common.enchantment;
import common.item.ItemShears;
import common.item.ItemStack;
public class EnchantmentDigging extends Enchantment
{
protected EnchantmentDigging(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.DIGGER);
this.setName("Effizienz");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 1 + 10 * (enchantmentLevel - 1);
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return super.getMinEnchantability(enchantmentLevel) + 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 5;
}
/**
* Determines if this enchantment can be applied to a specific ItemStack.
*/
public boolean canApply(ItemStack stack)
{
return stack.getItem() instanceof ItemShears ? true : super.canApply(stack);
}
}

View file

@ -0,0 +1,44 @@
package common.enchantment;
import common.entity.DamageSource;
import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.item.ItemAxe;
import common.item.ItemStack;
public class EnchantmentDraining extends Enchantment {
public EnchantmentDraining(int enchID, String enchName, int enchWeight) {
super(enchID, enchName, enchWeight, EnumEnchantmentType.WEAPON);
this.setName("Seelenentzug");
}
public int getMinEnchantability(int enchantmentLevel) {
return 2 + (enchantmentLevel - 1) * 11;
}
public int getMaxEnchantability(int enchantmentLevel) {
return this.getMinEnchantability(enchantmentLevel) + 20;
}
public int getMaxLevel() {
return 16;
}
// public boolean canApplyTogether(Enchantment ench)
// {
// return !(ench instanceof EnchantmentDraining);
// }
public boolean canApply(ItemStack stack) {
return stack.getItem() instanceof ItemAxe ? true : super.canApply(stack);
}
public void onEntityDamaged(EntityLiving user, Entity target, int level) {
if(target instanceof EntityLiving) {
EntityLiving entity = (EntityLiving)target;
entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(user, user), (int)((float)level * 1.25F));
user.heal((int)((entity.arePotionsInverted() ? 0.2f : 1.0f) * (float)level));
}
}
}

View file

@ -0,0 +1,57 @@
package common.enchantment;
import common.item.ItemArmor;
import common.item.ItemStack;
import common.rng.Random;
public class EnchantmentDurability extends Enchantment
{
protected EnchantmentDurability(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.BREAKABLE);
this.setName("Haltbarkeit");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 5 + (enchantmentLevel - 1) * 8;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return super.getMinEnchantability(enchantmentLevel) + 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 3;
}
/**
* Determines if this enchantment can be applied to a specific ItemStack.
*/
public boolean canApply(ItemStack stack)
{
return stack.isItemStackDamageable() ? true : super.canApply(stack);
}
/**
* Used by ItemStack.attemptDamageItem. Randomly determines if a point of damage should be negated using the
* enchantment level (par1). If the ItemStack is Armor then there is a flat 60% chance for damage to be negated no
* matter the enchantment level, otherwise there is a 1-(par/1) chance for damage to be negated.
*/
public static boolean negateDamage(ItemStack stack, int level, Random rand)
{
return stack.getItem() instanceof ItemArmor && rand.floatv() < 0.6F ? false : rand.rarity(level + 1);
}
}

View file

@ -0,0 +1,36 @@
package common.enchantment;
public class EnchantmentFireAspect extends Enchantment
{
protected EnchantmentFireAspect(int enchID, String enchName, int enchWeight)
{
super(enchID, enchName, enchWeight, EnumEnchantmentType.WEAPON);
this.setName("Verbrennung");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 10 + 20 * (enchantmentLevel - 1);
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return super.getMinEnchantability(enchantmentLevel) + 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 2;
}
}

View file

@ -0,0 +1,36 @@
package common.enchantment;
public class EnchantmentFishingSpeed extends Enchantment
{
protected EnchantmentFishingSpeed(int enchID, String enchName, int enchWeight, EnumEnchantmentType enchType)
{
super(enchID, enchName, enchWeight, enchType);
this.setName("Köder");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 15 + (enchantmentLevel - 1) * 9;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return super.getMinEnchantability(enchantmentLevel) + 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 3;
}
}

View file

@ -0,0 +1,572 @@
package common.enchantment;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import common.collect.Lists;
import common.collect.Maps;
import common.entity.DamageSource;
import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.init.Items;
import common.item.Item;
import common.item.ItemStack;
import common.nbt.NBTTagCompound;
import common.nbt.NBTTagList;
import common.rng.Random;
import common.rng.WeightedList;
public class EnchantmentHelper
{
/** Is the random seed of enchantment effects. */
private static final Random enchantmentRand = new Random();
/**
* Used to calculate the extra armor of enchantments on armors equipped on player.
*/
private static final EnchantmentHelper.ModifierDamage enchantmentModifierDamage = new EnchantmentHelper.ModifierDamage();
/**
* Used to calculate the (magic) extra damage done by enchantments on current equipped item of player.
*/
private static final EnchantmentHelper.ModifierLiving enchantmentModifierLiving = new EnchantmentHelper.ModifierLiving();
private static final EnchantmentHelper.HurtIterator ENCHANTMENT_ITERATOR_HURT = new EnchantmentHelper.HurtIterator();
private static final EnchantmentHelper.DamageIterator ENCHANTMENT_ITERATOR_DAMAGE = new EnchantmentHelper.DamageIterator();
/**
* Returns the level of enchantment on the ItemStack passed.
*/
public static int getEnchantmentLevel(int enchID, ItemStack stack)
{
if (stack == null)
{
return 0;
}
else
{
NBTTagList nbttaglist = stack.getEnchantmentTagList();
if (nbttaglist == null)
{
return 0;
}
else
{
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
int j = nbttaglist.getCompoundTagAt(i).getShort("id");
int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");
if (j == enchID)
{
return k;
}
}
return 0;
}
}
}
public static Map<Integer, Integer> getEnchantments(ItemStack stack)
{
Map<Integer, Integer> map = Maps.<Integer, Integer>newLinkedHashMap();
NBTTagList nbttaglist = stack.getItem() == Items.enchanted_book ? Items.enchanted_book.getEnchantments(stack) : stack.getEnchantmentTagList();
if (nbttaglist != null)
{
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
int j = nbttaglist.getCompoundTagAt(i).getShort("id");
int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");
map.put(j, k);
}
}
return map;
}
/**
* Set the enchantments for the specified stack.
*/
public static void setEnchantments(Map<Integer, Integer> enchMap, ItemStack stack)
{
NBTTagList nbttaglist = new NBTTagList();
Iterator iterator = enchMap.keySet().iterator();
while (iterator.hasNext())
{
int i = ((Integer)iterator.next()).intValue();
Enchantment enchantment = Enchantment.getEnchantmentById(i);
if (enchantment != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setShort("id", (short)i);
nbttagcompound.setShort("lvl", (short)enchMap.get(i).intValue());
nbttaglist.appendTag(nbttagcompound);
if (stack.getItem() == Items.enchanted_book)
{
Items.enchanted_book.addEnchantment(stack, new RngEnchantment(enchantment, enchMap.get(i).intValue()));
}
}
}
if (nbttaglist.tagCount() > 0)
{
if (stack.getItem() != Items.enchanted_book)
{
stack.setTagInfo("ench", nbttaglist);
}
}
else if (stack.hasTagCompound())
{
stack.getTagCompound().removeTag("ench");
}
}
/**
* Returns the biggest level of the enchantment on the array of ItemStack passed.
*/
public static int getMaxEnchantmentLevel(int enchID, ItemStack[] stacks)
{
if (stacks == null)
{
return 0;
}
else
{
int i = 0;
for (ItemStack itemstack : stacks)
{
int j = getEnchantmentLevel(enchID, itemstack);
if (j > i)
{
i = j;
}
}
return i;
}
}
/**
* Executes the enchantment modifier on the ItemStack passed.
*/
private static void applyEnchantmentModifier(EnchantmentHelper.IModifier modifier, ItemStack stack)
{
if (stack != null)
{
NBTTagList nbttaglist = stack.getEnchantmentTagList();
if (nbttaglist != null)
{
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
int j = nbttaglist.getCompoundTagAt(i).getShort("id");
int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");
if (Enchantment.getEnchantmentById(j) != null)
{
modifier.calculateModifier(Enchantment.getEnchantmentById(j), k);
}
}
}
}
}
/**
* Executes the enchantment modifier on the array of ItemStack passed.
*/
private static void applyEnchantmentModifierArray(EnchantmentHelper.IModifier modifier, ItemStack[] stacks)
{
for (ItemStack itemstack : stacks)
{
applyEnchantmentModifier(modifier, itemstack);
}
}
/**
* Returns the modifier of protection enchantments on armors equipped on player.
*/
public static int getEnchantmentModifierDamage(ItemStack[] stacks, DamageSource source)
{
enchantmentModifierDamage.damageModifier = 0;
enchantmentModifierDamage.source = source;
applyEnchantmentModifierArray(enchantmentModifierDamage, stacks);
if (enchantmentModifierDamage.damageModifier > 25)
{
enchantmentModifierDamage.damageModifier = 25;
}
else if (enchantmentModifierDamage.damageModifier < 0)
{
enchantmentModifierDamage.damageModifier = 0;
}
return (enchantmentModifierDamage.damageModifier + 1 >> 1) + enchantmentRand.zrange((enchantmentModifierDamage.damageModifier >> 1) + 1);
}
public static int getDamageModifier(ItemStack p_152377_0_)
{
enchantmentModifierLiving.livingModifier = 0;
applyEnchantmentModifier(enchantmentModifierLiving, p_152377_0_);
return enchantmentModifierLiving.livingModifier;
}
public static void applyThornEnchantments(EntityLiving user, Entity attacker)
{
ENCHANTMENT_ITERATOR_HURT.attacker = attacker;
ENCHANTMENT_ITERATOR_HURT.user = user;
if (user != null)
{
applyEnchantmentModifierArray(ENCHANTMENT_ITERATOR_HURT, user.getInventory());
}
if (user != null && attacker != null) // && attacker.isPlayer())
{
applyEnchantmentModifier(ENCHANTMENT_ITERATOR_HURT, user.getHeldItem());
}
}
public static void applyArthropodEnchantments(EntityLiving user, Entity target)
{
ENCHANTMENT_ITERATOR_DAMAGE.user = user;
ENCHANTMENT_ITERATOR_DAMAGE.target = target;
if (user != null)
{
applyEnchantmentModifierArray(ENCHANTMENT_ITERATOR_DAMAGE, user.getInventory());
}
if (user != null) // && user.isPlayer())
{
applyEnchantmentModifier(ENCHANTMENT_ITERATOR_DAMAGE, user.getHeldItem());
}
}
/**
* Returns the Knockback modifier of the enchantment on the players held item.
*/
public static int getKnockbackModifier(EntityLiving player)
{
return getEnchantmentLevel(Enchantment.knockback.effectId, player.getHeldItem());
}
/**
* Returns the fire aspect modifier of the players held item.
*/
public static int getFireAspectModifier(EntityLiving player)
{
return getEnchantmentLevel(Enchantment.fireAspect.effectId, player.getHeldItem());
}
// /**
// * Returns the 'Water Breathing' modifier of enchantments on player equipped armors.
// */
// public static int getRespiration(Entity player)
// {
// return getMaxEnchantmentLevel(Enchantment.respiration.effectId, player.getInventory());
// }
// /**
// * Returns the level of the Depth Strider enchantment.
// */
// public static int getDepthStriderModifier(Entity player)
// {
// return getMaxEnchantmentLevel(Enchantment.depthStrider.effectId, player.getInventory());
// }
/**
* Return the extra efficiency of tools based on enchantments on equipped player item.
*/
public static int getEfficiencyModifier(EntityLiving player)
{
return getEnchantmentLevel(Enchantment.efficiency.effectId, player.getHeldItem());
}
/**
* Returns the silk touch status of enchantments on current equipped item of player.
*/
public static boolean getSilkTouchModifier(EntityLiving player)
{
return getEnchantmentLevel(Enchantment.silkTouch.effectId, player.getHeldItem()) > 0;
}
/**
* Returns the fortune enchantment modifier of the current equipped item of player.
*/
public static int getFortuneModifier(EntityLiving player)
{
return getEnchantmentLevel(Enchantment.fortune.effectId, player.getHeldItem());
}
/**
* Returns the level of the 'Luck Of The Sea' enchantment.
*/
public static int getLuckOfSeaModifier(EntityLiving player)
{
return getEnchantmentLevel(Enchantment.luckOfTheSea.effectId, player.getHeldItem());
}
/**
* Returns the level of the 'Lure' enchantment on the players held item.
*/
public static int getLureModifier(EntityLiving player)
{
return getEnchantmentLevel(Enchantment.lure.effectId, player.getHeldItem());
}
/**
* Returns the looting enchantment modifier of the current equipped item of player.
*/
public static int getLootingModifier(EntityLiving player)
{
return getEnchantmentLevel(Enchantment.looting.effectId, player.getHeldItem());
}
// /**
// * Returns the aqua affinity status of enchantments on current equipped item of player.
// */
// public static boolean getAquaAffinityModifier(EntityLivingBase player)
// {
// return getMaxEnchantmentLevel(Enchantment.aquaAffinity.effectId, player.getInventory()) > 0;
// }
public static ItemStack getEnchantedItem(Enchantment p_92099_0_, EntityLiving p_92099_1_)
{
for (ItemStack itemstack : p_92099_1_.getInventory())
{
if (itemstack != null && getEnchantmentLevel(p_92099_0_.effectId, itemstack) > 0)
{
return itemstack;
}
}
return null;
}
/**
* Returns the enchantability of itemstack, using a separate calculation for each enchantNum (0, 1 or 2), cutting to
* the max enchantability power of the table, which is locked to a max of 15.
*/
public static int calcItemStackEnchantability(Random rand, int enchantNum, int power, ItemStack stack)
{
Item item = stack.getItem();
int i = item.getItemEnchantability();
if (i <= 0)
{
return 0;
}
else
{
if (power > 15)
{
power = 15;
}
int j = rand.roll(8) + (power >> 1) + rand.zrange(power + 1);
return enchantNum == 0 ? Math.max(j / 3, 1) : (enchantNum == 1 ? j * 2 / 3 + 1 : Math.max(j, power * 2));
}
}
/**
* Adds a random enchantment to the specified item. Args: random, itemStack, enchantabilityLevel
*/
public static ItemStack addRandomEnchantment(Random p_77504_0_, ItemStack p_77504_1_, int p_77504_2_)
{
List<RngEnchantment> list = buildEnchantmentList(p_77504_0_, p_77504_1_, p_77504_2_);
boolean flag = p_77504_1_.getItem() == Items.book;
if (flag)
{
p_77504_1_.setItem(Items.enchanted_book);
}
if (list != null)
{
for (RngEnchantment enchantmentdata : list)
{
if (flag)
{
Items.enchanted_book.addEnchantment(p_77504_1_, enchantmentdata);
}
else
{
p_77504_1_.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
}
}
}
return p_77504_1_;
}
public static List<RngEnchantment> buildEnchantmentList(Random randomIn, ItemStack itemStackIn, int level)
{
Item item = itemStackIn.getItem();
int i = item.getItemEnchantability();
if (i <= 0)
{
return null;
}
else
{
i = i / 2;
i = randomIn.roll((i >> 1) + 1) + randomIn.zrange((i >> 1) + 1);
int j = i + level;
float f = (randomIn.floatv() + randomIn.floatv() - 1.0F) * 0.15F;
int k = (int)((float)j * (1.0F + f) + 0.5F);
if (k < 1)
{
k = 1;
}
List<RngEnchantment> list = null;
Map<Integer, RngEnchantment> map = mapEnchantmentData(k, itemStackIn);
if (map != null && !map.isEmpty())
{
RngEnchantment enchantmentdata = (RngEnchantment)new WeightedList(map.values()).pick(randomIn);
if (enchantmentdata != null)
{
list = Lists.<RngEnchantment>newArrayList();
list.add(enchantmentdata);
for (int l = k; randomIn.zrange(50) <= l; l >>= 1)
{
Iterator<Integer> iterator = map.keySet().iterator();
while (iterator.hasNext())
{
Integer integer = (Integer)iterator.next();
boolean flag = true;
for (RngEnchantment enchantmentdata1 : list)
{
if (!enchantmentdata1.enchantmentobj.canApplyTogether(Enchantment.getEnchantmentById(integer.intValue())))
{
flag = false;
break;
}
}
if (!flag)
{
iterator.remove();
}
}
if (!map.isEmpty())
{
RngEnchantment enchantmentdata2 = (RngEnchantment)new WeightedList(map.values()).pick(randomIn);
list.add(enchantmentdata2);
}
}
}
}
return list;
}
}
public static Map<Integer, RngEnchantment> mapEnchantmentData(int p_77505_0_, ItemStack p_77505_1_)
{
Item item = p_77505_1_.getItem();
Map<Integer, RngEnchantment> map = null;
boolean flag = p_77505_1_.getItem() == Items.book;
for (Enchantment enchantment : Enchantment.enchantmentsBookList)
{
if (enchantment != null && (enchantment.type.canEnchantItem(item) || flag))
{
for (int i = enchantment.getMinLevel(); i <= enchantment.getMaxLevel(); ++i)
{
if (p_77505_0_ >= enchantment.getMinEnchantability(i) && p_77505_0_ <= enchantment.getMaxEnchantability(i))
{
if (map == null)
{
map = Maps.<Integer, RngEnchantment>newHashMap();
}
map.put(enchantment.effectId, new RngEnchantment(enchantment, i));
}
}
}
}
return map;
}
static final class DamageIterator implements EnchantmentHelper.IModifier
{
public EntityLiving user;
public Entity target;
private DamageIterator()
{
}
public void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel)
{
enchantmentIn.onEntityDamaged(this.user, this.target, enchantmentLevel);
}
}
static final class HurtIterator implements EnchantmentHelper.IModifier
{
public EntityLiving user;
public Entity attacker;
private HurtIterator()
{
}
public void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel)
{
enchantmentIn.onUserHurt(this.user, this.attacker, enchantmentLevel);
}
}
interface IModifier
{
void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel);
}
static final class ModifierDamage implements EnchantmentHelper.IModifier
{
public int damageModifier;
public DamageSource source;
private ModifierDamage()
{
}
public void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel)
{
this.damageModifier += enchantmentIn.calcDamageReduction(enchantmentLevel, this.source);
}
}
static final class ModifierLiving implements EnchantmentHelper.IModifier
{
public int livingModifier;
private ModifierLiving()
{
}
public void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel)
{
this.livingModifier += enchantmentIn.calcAdditionalDamage(enchantmentLevel);
}
}
}

View file

@ -0,0 +1,36 @@
package common.enchantment;
public class EnchantmentKnockback extends Enchantment
{
protected EnchantmentKnockback(int p_i45768_1_, String p_i45768_2_, int p_i45768_3_)
{
super(p_i45768_1_, p_i45768_2_, p_i45768_3_, EnumEnchantmentType.WEAPON);
this.setName("Rückstoß");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 5 + 20 * (enchantmentLevel - 1);
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return super.getMinEnchantability(enchantmentLevel) + 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 2;
}
}

View file

@ -0,0 +1,56 @@
package common.enchantment;
public class EnchantmentLootBonus extends Enchantment
{
protected EnchantmentLootBonus(int p_i45767_1_, String p_i45767_2_, int p_i45767_3_, EnumEnchantmentType p_i45767_4_)
{
super(p_i45767_1_, p_i45767_2_, p_i45767_3_, p_i45767_4_);
if (p_i45767_4_ == EnumEnchantmentType.DIGGER)
{
this.setName("Glück");
}
else if (p_i45767_4_ == EnumEnchantmentType.FISHING_ROD)
{
this.setName("Glück des Meeres");
}
else
{
this.setName("Plünderung");
}
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 15 + (enchantmentLevel - 1) * 9;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return super.getMinEnchantability(enchantmentLevel) + 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 3;
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
public boolean canApplyTogether(Enchantment ench)
{
return super.canApplyTogether(ench) && ench.effectId != silkTouch.effectId;
}
}

View file

@ -0,0 +1,132 @@
package common.enchantment;
import common.entity.DamageSource;
import common.entity.Entity;
import common.util.ExtMath;
public class EnchantmentProtection extends Enchantment
{
private static final String[] NAMES = new String[] {"Schutz", "Feuerschutz", "Federfall", "Explosionsschutz", "Schusssicher"};
/**
* Holds the base factor of enchantability needed to be able to use the enchant.
*/
private static final int[] baseEnchantability = new int[] {1, 10, 5, 5, 3};
/**
* Holds how much each level increased the enchantability factor to be able to use this enchant.
*/
private static final int[] levelEnchantability = new int[] {11, 8, 6, 8, 6};
/**
* Used on the formula of base enchantability, this is the 'window' factor of values to be able to use thing
* enchant.
*/
private static final int[] thresholdEnchantability = new int[] {20, 12, 10, 12, 15};
/**
* Defines the type of protection of the enchantment, 0 = all, 1 = fire, 2 = fall (feather fall), 3 = explosion and
* 4 = projectile.
*/
public final int protectionType;
public EnchantmentProtection(int id, String name, int weight, int type)
{
super(id, name, weight, EnumEnchantmentType.ARMOR);
this.protectionType = type;
if (type == 2)
{
this.type = EnumEnchantmentType.ARMOR_FEET;
}
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return baseEnchantability[this.protectionType] + (enchantmentLevel - 1) * levelEnchantability[this.protectionType];
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + thresholdEnchantability[this.protectionType];
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 4;
}
/**
* Calculates the damage protection of the enchantment based on level and damage source passed.
*/
public int calcDamageReduction(int level, DamageSource source)
{
if (source == DamageSource.outOfWorld)
{
return 0;
}
else
{
float f = (float)(6 + level * level) / 3.0F;
return this.protectionType == 0 ? ExtMath.floorf(f * 0.75F) : (this.protectionType == 1 && source.isFireDamage() ? ExtMath.floorf(f * 1.25F) : (this.protectionType == 2 && source == DamageSource.fall ? ExtMath.floorf(f * 2.5F) : (this.protectionType == 3 && source.isExplosion() ? ExtMath.floorf(f * 1.5F) : (this.protectionType == 4 && source.isProjectile() ? ExtMath.floorf(f * 1.5F) : 0))));
}
}
public String getName()
{
return NAMES[this.protectionType];
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
public boolean canApplyTogether(Enchantment ench)
{
if (ench instanceof EnchantmentProtection)
{
EnchantmentProtection enchantmentprotection = (EnchantmentProtection)ench;
return enchantmentprotection.protectionType == this.protectionType ? false : this.protectionType == 2 || enchantmentprotection.protectionType == 2;
}
else
{
return super.canApplyTogether(ench);
}
}
/**
* Gets the amount of ticks an entity should be set fire, adjusted for fire protection.
*/
public static int getFireTimeForEntity(Entity entity, int duration)
{
int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantment.fireProtection.effectId, entity.getInventory());
if (i > 0)
{
duration -= ExtMath.floorf((float)duration * (float)i * 0.15F);
}
return duration;
}
public static double getKnockbackFactor(Entity entity, double strength)
{
int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantment.blastProtection.effectId, entity.getInventory());
if (i > 0)
{
strength -= (double)ExtMath.floord(strength * (double)((float)i * 0.15F));
}
return strength;
}
}

View file

@ -0,0 +1,88 @@
package common.enchantment;
import common.entity.DamageSource;
import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.init.Config;
import common.item.ItemArmor;
import common.item.ItemStack;
import common.rng.Random;
public class EnchantmentThorns extends Enchantment
{
public EnchantmentThorns(int p_i45764_1_, String p_i45764_2_, int p_i45764_3_)
{
super(p_i45764_1_, p_i45764_2_, p_i45764_3_, EnumEnchantmentType.ARMOR_TORSO);
this.setName("Dornen");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 10 + 20 * (enchantmentLevel - 1);
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return super.getMinEnchantability(enchantmentLevel) + 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 3;
}
/**
* Determines if this enchantment can be applied to a specific ItemStack.
*/
public boolean canApply(ItemStack stack)
{
return stack.getItem() instanceof ItemArmor ? true : super.canApply(stack);
}
/**
* Whenever an entity that has this enchantment on one of its associated items is damaged this method will be
* called.
*/
public void onUserHurt(EntityLiving user, Entity attacker, int level)
{
Random random = user.getRNG();
ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantment.thorns, user);
if ((user.worldObj.client || Config.damageThorns) && isHurting(level, random))
{
if (attacker != null)
{
attacker.attackEntityFrom(DamageSource.causeThornsDamage(user), getDamage(level, random));
// attacker.playSound("damage.thorns", 0.5F, 1.0F);
}
if (itemstack != null)
{
itemstack.damageItem(3, user);
}
}
else if (itemstack != null)
{
itemstack.damageItem(1, user);
}
}
public static boolean isHurting(int level, Random rand)
{
return level <= 0 ? false : rand.floatv() < 0.15F * (float)level;
}
public static int getDamage(int level, Random rand)
{
return level > 10 ? level - 10 : rand.roll(4);
}
}

View file

@ -0,0 +1,54 @@
package common.enchantment;
import common.item.ItemShears;
import common.item.ItemStack;
public class EnchantmentUntouching extends Enchantment
{
protected EnchantmentUntouching(int p_i45763_1_, String p_i45763_2_, int p_i45763_3_)
{
super(p_i45763_1_, p_i45763_2_, p_i45763_3_, EnumEnchantmentType.DIGGER);
this.setName("Behutsamkeit");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 15;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return super.getMinEnchantability(enchantmentLevel) + 50;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 1;
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
public boolean canApplyTogether(Enchantment ench)
{
return super.canApplyTogether(ench) && ench.effectId != fortune.effectId;
}
/**
* Determines if this enchantment can be applied to a specific ItemStack.
*/
public boolean canApply(ItemStack stack)
{
return stack.getItem() instanceof ItemShears ? true : super.canApply(stack);
}
}

View file

@ -0,0 +1,54 @@
package common.enchantment;
import common.item.Item;
import common.item.ItemArmor;
import common.item.ItemBow;
import common.item.ItemFishingRod;
import common.item.ItemSword;
import common.item.ItemTool;
public enum EnumEnchantmentType
{
ALL,
ARMOR,
ARMOR_FEET,
ARMOR_LEGS,
ARMOR_TORSO,
ARMOR_HEAD,
WEAPON,
DIGGER,
FISHING_ROD,
BREAKABLE,
BOW;
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item p_77557_1_)
{
if (this == ALL)
{
return true;
}
else if (this == BREAKABLE && p_77557_1_.isDamageable())
{
return true;
}
else if (p_77557_1_ instanceof ItemArmor)
{
if (this == ARMOR)
{
return true;
}
else
{
ItemArmor itemarmor = (ItemArmor)p_77557_1_;
return itemarmor.armorType == 0 ? this == ARMOR_HEAD : (itemarmor.armorType == 2 ? this == ARMOR_LEGS : (itemarmor.armorType == 1 ? this == ARMOR_TORSO : (itemarmor.armorType == 3 ? this == ARMOR_FEET : false)));
}
}
else
{
return p_77557_1_ instanceof ItemSword ? this == WEAPON : (p_77557_1_ instanceof ItemTool ? this == DIGGER : (p_77557_1_ instanceof ItemBow ? this == BOW : (p_77557_1_ instanceof ItemFishingRod ? this == FISHING_ROD : false)));
}
}
}

View file

@ -0,0 +1,19 @@
package common.enchantment;
import common.rng.RngItem;
public class RngEnchantment extends RngItem
{
/** Enchantment object associated with this EnchantmentData */
public final Enchantment enchantmentobj;
/** Enchantment level associated with this EnchantmentData */
public final int enchantmentLevel;
public RngEnchantment(Enchantment enchantmentObj, int enchLevel)
{
super(enchantmentObj.getWeight());
this.enchantmentobj = enchantmentObj;
this.enchantmentLevel = enchLevel;
}
}