base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,299 @@
package net.minecraft.enchantment;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
public abstract class Enchantment extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<Enchantment>
{
public static final RegistryNamespaced<ResourceLocation, Enchantment> REGISTRY = net.minecraftforge.registries.GameData.getWrapper(Enchantment.class);
/** Where this enchantment has an effect, e.g. offhand, pants */
private final EntityEquipmentSlot[] applicableEquipmentTypes;
private final Enchantment.Rarity rarity;
/** The EnumEnchantmentType given to this Enchantment. */
@Nullable
public EnumEnchantmentType type;
/** Used in localisation and stats. */
protected String name;
/**
* Gets an Enchantment from the registry, based on a numeric ID.
*/
@Nullable
public static Enchantment getEnchantmentByID(int id)
{
return REGISTRY.getObjectById(id);
}
/**
* Gets the numeric ID for the passed enchantment.
*/
public static int getEnchantmentID(Enchantment enchantmentIn)
{
return REGISTRY.getIDForObject(enchantmentIn);
}
/**
* Retrieves an enchantment by using its location name.
*/
@Nullable
public static Enchantment getEnchantmentByLocation(String location)
{
return REGISTRY.getObject(new ResourceLocation(location));
}
protected Enchantment(Enchantment.Rarity rarityIn, EnumEnchantmentType typeIn, EntityEquipmentSlot[] slots)
{
this.rarity = rarityIn;
this.type = typeIn;
this.applicableEquipmentTypes = slots;
}
/**
* Gets list of all the entity's currently equipped gear that this enchantment can go on
*/
public List<ItemStack> getEntityEquipment(EntityLivingBase entityIn)
{
List<ItemStack> list = Lists.<ItemStack>newArrayList();
for (EntityEquipmentSlot entityequipmentslot : this.applicableEquipmentTypes)
{
ItemStack itemstack = entityIn.getItemStackFromSlot(entityequipmentslot);
if (!itemstack.isEmpty())
{
list.add(itemstack);
}
}
return list;
}
/**
* Retrieves the weight value of an Enchantment. This weight value is used within vanilla to determine how rare an
* enchantment is.
*/
public Enchantment.Rarity getRarity()
{
return this.rarity;
}
/**
* 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 calcModifierDamage(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 float calcDamageByCreature(int level, EnumCreatureAttribute creatureType)
{
return 0.0F;
}
public final boolean isCompatibleWith(Enchantment p_191560_1_)
{
return this.canApplyTogether(p_191560_1_) && p_191560_1_.canApplyTogether(this);
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
protected 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 in translation table of this enchantment.
*/
public String getName()
{
return "enchantment." + this.name;
}
/**
* Returns the correct traslated name of the enchantment and the level in roman numbers.
*/
public String getTranslatedName(int level)
{
String s = I18n.translateToLocal(this.getName());
if (this.isCurse())
{
s = TextFormatting.RED + s;
}
return level == 1 && this.getMaxLevel() == 1 ? s : s + " " + I18n.translateToLocal("enchantment.level." + level);
}
/**
* Determines if this enchantment can be applied to a specific ItemStack.
*/
public boolean canApply(ItemStack stack)
{
return canApplyAtEnchantingTable(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)
{
}
/**
* Whenever an entity that has this enchantment on one of its associated items is damaged this method will be
* called.
*/
public void onUserHurt(EntityLivingBase user, Entity attacker, int level)
{
}
public boolean isTreasureEnchantment()
{
return false;
}
public boolean isCurse()
{
return false;
}
/**
* This applies specifically to applying at the enchanting table. The other method {@link #canApply(ItemStack)}
* applies for <i>all possible</i> enchantments.
* @param stack
* @return
*/
public boolean canApplyAtEnchantingTable(ItemStack stack)
{
return stack.getItem().canApplyAtEnchantingTable(stack, this);
}
/**
* Is this enchantment allowed to be enchanted on books via Enchantment Table
* @return false to disable the vanilla feature
*/
public boolean isAllowedOnBooks()
{
return true;
}
/**
* Registers all of the vanilla enchantments.
*/
public static void registerEnchantments()
{
EntityEquipmentSlot[] aentityequipmentslot = new EntityEquipmentSlot[] {EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET};
REGISTRY.register(0, new ResourceLocation("protection"), new EnchantmentProtection(Enchantment.Rarity.COMMON, EnchantmentProtection.Type.ALL, aentityequipmentslot));
REGISTRY.register(1, new ResourceLocation("fire_protection"), new EnchantmentProtection(Enchantment.Rarity.UNCOMMON, EnchantmentProtection.Type.FIRE, aentityequipmentslot));
REGISTRY.register(2, new ResourceLocation("feather_falling"), new EnchantmentProtection(Enchantment.Rarity.UNCOMMON, EnchantmentProtection.Type.FALL, aentityequipmentslot));
REGISTRY.register(3, new ResourceLocation("blast_protection"), new EnchantmentProtection(Enchantment.Rarity.RARE, EnchantmentProtection.Type.EXPLOSION, aentityequipmentslot));
REGISTRY.register(4, new ResourceLocation("projectile_protection"), new EnchantmentProtection(Enchantment.Rarity.UNCOMMON, EnchantmentProtection.Type.PROJECTILE, aentityequipmentslot));
REGISTRY.register(5, new ResourceLocation("respiration"), new EnchantmentOxygen(Enchantment.Rarity.RARE, aentityequipmentslot));
REGISTRY.register(6, new ResourceLocation("aqua_affinity"), new EnchantmentWaterWorker(Enchantment.Rarity.RARE, aentityequipmentslot));
REGISTRY.register(7, new ResourceLocation("thorns"), new EnchantmentThorns(Enchantment.Rarity.VERY_RARE, aentityequipmentslot));
REGISTRY.register(8, new ResourceLocation("depth_strider"), new EnchantmentWaterWalker(Enchantment.Rarity.RARE, aentityequipmentslot));
REGISTRY.register(9, new ResourceLocation("frost_walker"), new EnchantmentFrostWalker(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.FEET}));
REGISTRY.register(10, new ResourceLocation("binding_curse"), new EnchantmentBindingCurse(Enchantment.Rarity.VERY_RARE, aentityequipmentslot));
REGISTRY.register(16, new ResourceLocation("sharpness"), new EnchantmentDamage(Enchantment.Rarity.COMMON, 0, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(17, new ResourceLocation("smite"), new EnchantmentDamage(Enchantment.Rarity.UNCOMMON, 1, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(18, new ResourceLocation("bane_of_arthropods"), new EnchantmentDamage(Enchantment.Rarity.UNCOMMON, 2, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(19, new ResourceLocation("knockback"), new EnchantmentKnockback(Enchantment.Rarity.UNCOMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(20, new ResourceLocation("fire_aspect"), new EnchantmentFireAspect(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(21, new ResourceLocation("looting"), new EnchantmentLootBonus(Enchantment.Rarity.RARE, EnumEnchantmentType.WEAPON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(22, new ResourceLocation("sweeping"), new EnchantmentSweepingEdge(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(32, new ResourceLocation("efficiency"), new EnchantmentDigging(Enchantment.Rarity.COMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(33, new ResourceLocation("silk_touch"), new EnchantmentUntouching(Enchantment.Rarity.VERY_RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(34, new ResourceLocation("unbreaking"), new EnchantmentDurability(Enchantment.Rarity.UNCOMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(35, new ResourceLocation("fortune"), new EnchantmentLootBonus(Enchantment.Rarity.RARE, EnumEnchantmentType.DIGGER, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(48, new ResourceLocation("power"), new EnchantmentArrowDamage(Enchantment.Rarity.COMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(49, new ResourceLocation("punch"), new EnchantmentArrowKnockback(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(50, new ResourceLocation("flame"), new EnchantmentArrowFire(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(51, new ResourceLocation("infinity"), new EnchantmentArrowInfinite(Enchantment.Rarity.VERY_RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(61, new ResourceLocation("luck_of_the_sea"), new EnchantmentLootBonus(Enchantment.Rarity.RARE, EnumEnchantmentType.FISHING_ROD, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(62, new ResourceLocation("lure"), new EnchantmentFishingSpeed(Enchantment.Rarity.RARE, EnumEnchantmentType.FISHING_ROD, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
REGISTRY.register(70, new ResourceLocation("mending"), new EnchantmentMending(Enchantment.Rarity.RARE, EntityEquipmentSlot.values()));
REGISTRY.register(71, new ResourceLocation("vanishing_curse"), new EnchantmentVanishingCurse(Enchantment.Rarity.VERY_RARE, EntityEquipmentSlot.values()));
}
public static enum Rarity
{
COMMON(10),
UNCOMMON(5),
RARE(2),
VERY_RARE(1);
/** The weight of the Rarity. */
private final int weight;
private Rarity(int rarityWeight)
{
this.weight = rarityWeight;
}
/**
* Retrieves the weight of Rarity.
*/
public int getWeight()
{
return this.weight;
}
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentArrowDamage extends Enchantment
{
public EnchantmentArrowDamage(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.BOW, slots);
this.setName("arrowDamage");
}
/**
* 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 net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentArrowFire extends Enchantment
{
public EnchantmentArrowFire(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.BOW, slots);
this.setName("arrowFire");
}
/**
* 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,44 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentArrowInfinite extends Enchantment
{
public EnchantmentArrowInfinite(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.BOW, slots);
this.setName("arrowInfinite");
}
/**
* 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;
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
public boolean canApplyTogether(Enchantment ench)
{
return ench instanceof EnchantmentMending ? false : super.canApplyTogether(ench);
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentArrowKnockback extends Enchantment
{
public EnchantmentArrowKnockback(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.BOW, slots);
this.setName("arrowKnockback");
}
/**
* 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,46 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentBindingCurse extends Enchantment
{
public EnchantmentBindingCurse(Enchantment.Rarity p_i47254_1_, EntityEquipmentSlot... p_i47254_2_)
{
super(p_i47254_1_, EnumEnchantmentType.WEARABLE, p_i47254_2_);
this.setName("binding_curse");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 25;
}
/**
* 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;
}
public boolean isTreasureEnchantment()
{
return true;
}
public boolean isCurse()
{
return true;
}
}

View File

@@ -0,0 +1,115 @@
package net.minecraft.enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.init.MobEffects;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
public class EnchantmentDamage extends Enchantment
{
/** None */
private static final String[] DAMAGE_NAMES = new String[] {"all", "undead", "arthropods"};
/** Holds the base factor of enchantability needed to be able to use the enchant. */
private static final int[] MIN_COST = new int[] {1, 5, 5};
/** None */
private static final int[] LEVEL_COST = new int[] {11, 8, 8};
/** None */
private static final int[] LEVEL_COST_SPAN = new int[] {20, 20, 20};
/** Defines the type of damage of the enchantment, 0 = all, 1 = undead, 3 = arthropods */
public final int damageType;
public EnchantmentDamage(Enchantment.Rarity rarityIn, int damageTypeIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.WEAPON, slots);
this.damageType = damageTypeIn;
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return MIN_COST[this.damageType] + (enchantmentLevel - 1) * LEVEL_COST[this.damageType];
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + LEVEL_COST_SPAN[this.damageType];
}
/**
* 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 float calcDamageByCreature(int level, EnumCreatureAttribute creatureType)
{
if (this.damageType == 0)
{
return 1.0F + (float)Math.max(0, level - 1) * 0.5F;
}
else if (this.damageType == 1 && creatureType == EnumCreatureAttribute.UNDEAD)
{
return (float)level * 2.5F;
}
else
{
return this.damageType == 2 && creatureType == EnumCreatureAttribute.ARTHROPOD ? (float)level * 2.5F : 0.0F;
}
}
/**
* Return the name of key in translation table of this enchantment.
*/
public String getName()
{
return "enchantment.damage." + DAMAGE_NAMES[this.damageType];
}
/**
* 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.getCreatureAttribute() == EnumCreatureAttribute.ARTHROPOD)
{
int i = 20 + user.getRNG().nextInt(10 * level);
entitylivingbase.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, i, 3));
}
}
}
}

View File

@@ -0,0 +1,18 @@
package net.minecraft.enchantment;
import net.minecraft.util.WeightedRandom;
public class EnchantmentData extends WeightedRandom.Item
{
/** Enchantment object associated with this EnchantmentData */
public final Enchantment enchantment;
/** Enchantment level associated with this EnchantmentData */
public final int enchantmentLevel;
public EnchantmentData(Enchantment enchantmentObj, int enchLevel)
{
super(enchantmentObj.getRarity().getWeight());
this.enchantment = enchantmentObj;
this.enchantmentLevel = enchLevel;
}
}

View File

@@ -0,0 +1,46 @@
package net.minecraft.enchantment;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
public class EnchantmentDigging extends Enchantment
{
protected EnchantmentDigging(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.DIGGER, slots);
this.setName("digging");
}
/**
* 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() == Items.SHEARS ? true : super.canApply(stack);
}
}

View File

@@ -0,0 +1,64 @@
package net.minecraft.enchantment;
import java.util.Random;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
public class EnchantmentDurability extends Enchantment
{
protected EnchantmentDurability(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.BREAKABLE, slots);
this.setName("durability");
}
/**
* 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)
{
if (stack.getItem() instanceof ItemArmor && rand.nextFloat() < 0.6F)
{
return false;
}
else
{
return rand.nextInt(level + 1) > 0;
}
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentFireAspect extends Enchantment
{
protected EnchantmentFireAspect(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.WEAPON, slots);
this.setName("fire");
}
/**
* 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 net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentFishingSpeed extends Enchantment
{
protected EnchantmentFishingSpeed(Enchantment.Rarity rarityIn, EnumEnchantmentType typeIn, EntityEquipmentSlot... slots)
{
super(rarityIn, typeIn, slots);
this.setName("fishingSpeed");
}
/**
* 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,89 @@
package net.minecraft.enchantment;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
public class EnchantmentFrostWalker extends Enchantment
{
public EnchantmentFrostWalker(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.ARMOR_FEET, slots);
this.setName("frostWalker");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return enchantmentLevel * 10;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + 15;
}
public boolean isTreasureEnchantment()
{
return true;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 2;
}
public static void freezeNearby(EntityLivingBase living, World worldIn, BlockPos pos, int level)
{
if (living.onGround)
{
float f = (float)Math.min(16, 2 + level);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(0, 0, 0);
for (BlockPos.MutableBlockPos blockpos$mutableblockpos1 : BlockPos.getAllInBoxMutable(pos.add((double)(-f), -1.0D, (double)(-f)), pos.add((double)f, -1.0D, (double)f)))
{
if (blockpos$mutableblockpos1.distanceSqToCenter(living.posX, living.posY, living.posZ) <= (double)(f * f))
{
blockpos$mutableblockpos.setPos(blockpos$mutableblockpos1.getX(), blockpos$mutableblockpos1.getY() + 1, blockpos$mutableblockpos1.getZ());
IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos);
if (iblockstate.getMaterial() == Material.AIR)
{
IBlockState iblockstate1 = worldIn.getBlockState(blockpos$mutableblockpos1);
if (iblockstate1.getMaterial() == Material.WATER && (iblockstate1.getBlock() == net.minecraft.init.Blocks.WATER || iblockstate1.getBlock() == net.minecraft.init.Blocks.FLOWING_WATER) && ((Integer)iblockstate1.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.mayPlace(Blocks.FROSTED_ICE, blockpos$mutableblockpos1, false, EnumFacing.DOWN, (Entity)null))
{
worldIn.setBlockState(blockpos$mutableblockpos1, Blocks.FROSTED_ICE.getDefaultState());
worldIn.scheduleUpdate(blockpos$mutableblockpos1.toImmutable(), Blocks.FROSTED_ICE, MathHelper.getInt(living.getRNG(), 60, 120));
}
}
}
}
}
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
public boolean canApplyTogether(Enchantment ench)
{
return super.canApplyTogether(ench) && ench != Enchantments.DEPTH_STRIDER;
}
}

View File

@@ -0,0 +1,572 @@
package net.minecraft.enchantment;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Map.Entry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Util;
import net.minecraft.util.WeightedRandom;
import net.minecraft.util.math.MathHelper;
public class EnchantmentHelper
{
/** Used to calculate the extra armor of enchantments on armors equipped on player. */
private static final EnchantmentHelper.ModifierDamage ENCHANTMENT_MODIFIER_DAMAGE = new EnchantmentHelper.ModifierDamage();
/** Used to calculate the (magic) extra damage done by enchantments on current equipped item of player. */
private static final EnchantmentHelper.ModifierLiving ENCHANTMENT_MODIFIER_LIVING = 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(Enchantment enchID, ItemStack stack)
{
if (stack.isEmpty())
{
return 0;
}
else
{
NBTTagList nbttaglist = stack.getEnchantmentTagList();
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
Enchantment enchantment = Enchantment.getEnchantmentByID(nbttagcompound.getShort("id"));
int j = nbttagcompound.getShort("lvl");
if (enchantment == enchID)
{
return j;
}
}
return 0;
}
}
/**
* Return the enchantments for the specified stack.
*/
public static Map<Enchantment, Integer> getEnchantments(ItemStack stack)
{
Map<Enchantment, Integer> map = Maps.<Enchantment, Integer>newLinkedHashMap();
NBTTagList nbttaglist = stack.getItem() == Items.ENCHANTED_BOOK ? ItemEnchantedBook.getEnchantments(stack) : stack.getEnchantmentTagList();
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
Enchantment enchantment = Enchantment.getEnchantmentByID(nbttagcompound.getShort("id"));
int j = nbttagcompound.getShort("lvl");
map.put(enchantment, Integer.valueOf(j));
}
return map;
}
/**
* Set the enchantments for the specified stack.
*/
public static void setEnchantments(Map<Enchantment, Integer> enchMap, ItemStack stack)
{
NBTTagList nbttaglist = new NBTTagList();
for (Entry<Enchantment, Integer> entry : enchMap.entrySet())
{
Enchantment enchantment = entry.getKey();
if (enchantment != null)
{
int i = ((Integer)entry.getValue()).intValue();
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setShort("id", (short)Enchantment.getEnchantmentID(enchantment));
nbttagcompound.setShort("lvl", (short)i);
nbttaglist.appendTag(nbttagcompound);
if (stack.getItem() == Items.ENCHANTED_BOOK)
{
ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(enchantment, i));
}
}
}
if (nbttaglist.hasNoTags())
{
if (stack.hasTagCompound())
{
stack.getTagCompound().removeTag("ench");
}
}
else if (stack.getItem() != Items.ENCHANTED_BOOK)
{
stack.setTagInfo("ench", nbttaglist);
}
}
/**
* Executes the enchantment modifier on the ItemStack passed.
*/
private static void applyEnchantmentModifier(EnchantmentHelper.IModifier modifier, ItemStack stack)
{
if (!stack.isEmpty())
{
NBTTagList nbttaglist = stack.getEnchantmentTagList();
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, Iterable<ItemStack> stacks)
{
for (ItemStack itemstack : stacks)
{
applyEnchantmentModifier(modifier, itemstack);
}
}
/**
* Returns the modifier of protection enchantments on armors equipped on player.
*/
public static int getEnchantmentModifierDamage(Iterable<ItemStack> stacks, DamageSource source)
{
ENCHANTMENT_MODIFIER_DAMAGE.damageModifier = 0;
ENCHANTMENT_MODIFIER_DAMAGE.source = source;
applyEnchantmentModifierArray(ENCHANTMENT_MODIFIER_DAMAGE, stacks);
ENCHANTMENT_MODIFIER_DAMAGE.source = null; //Forge Fix memory leaks: https://bugs.mojang.com/browse/MC-128547
return ENCHANTMENT_MODIFIER_DAMAGE.damageModifier;
}
public static float getModifierForCreature(ItemStack stack, EnumCreatureAttribute creatureAttribute)
{
ENCHANTMENT_MODIFIER_LIVING.livingModifier = 0.0F;
ENCHANTMENT_MODIFIER_LIVING.entityLiving = creatureAttribute;
applyEnchantmentModifier(ENCHANTMENT_MODIFIER_LIVING, stack);
return ENCHANTMENT_MODIFIER_LIVING.livingModifier;
}
public static float getSweepingDamageRatio(EntityLivingBase p_191527_0_)
{
int i = getMaxEnchantmentLevel(Enchantments.SWEEPING, p_191527_0_);
return i > 0 ? EnchantmentSweepingEdge.getSweepingDamageRatio(i) : 0.0F;
}
public static void applyThornEnchantments(EntityLivingBase p_151384_0_, Entity p_151384_1_)
{
ENCHANTMENT_ITERATOR_HURT.attacker = p_151384_1_;
ENCHANTMENT_ITERATOR_HURT.user = p_151384_0_;
if (p_151384_0_ != null)
{
applyEnchantmentModifierArray(ENCHANTMENT_ITERATOR_HURT, p_151384_0_.getEquipmentAndArmor());
}
if (p_151384_1_ instanceof EntityPlayer)
{
applyEnchantmentModifier(ENCHANTMENT_ITERATOR_HURT, p_151384_0_.getHeldItemMainhand());
}
ENCHANTMENT_ITERATOR_HURT.attacker = null; //Forge Fix memory leaks: https://bugs.mojang.com/browse/MC-128547
ENCHANTMENT_ITERATOR_HURT.user = null;
}
public static void applyArthropodEnchantments(EntityLivingBase p_151385_0_, Entity p_151385_1_)
{
ENCHANTMENT_ITERATOR_DAMAGE.user = p_151385_0_;
ENCHANTMENT_ITERATOR_DAMAGE.target = p_151385_1_;
if (p_151385_0_ != null)
{
applyEnchantmentModifierArray(ENCHANTMENT_ITERATOR_DAMAGE, p_151385_0_.getEquipmentAndArmor());
}
if (p_151385_0_ instanceof EntityPlayer)
{
applyEnchantmentModifier(ENCHANTMENT_ITERATOR_DAMAGE, p_151385_0_.getHeldItemMainhand());
}
ENCHANTMENT_ITERATOR_DAMAGE.user = null; //Forge Fix memory leaks: https://bugs.mojang.com/browse/MC-128547
ENCHANTMENT_ITERATOR_DAMAGE.target = null;
}
public static int getMaxEnchantmentLevel(Enchantment p_185284_0_, EntityLivingBase p_185284_1_)
{
Iterable<ItemStack> iterable = p_185284_0_.getEntityEquipment(p_185284_1_);
if (iterable == null)
{
return 0;
}
else
{
int i = 0;
for (ItemStack itemstack : iterable)
{
int j = getEnchantmentLevel(p_185284_0_, itemstack);
if (j > i)
{
i = j;
}
}
return i;
}
}
/**
* Returns the Knockback modifier of the enchantment on the players held item.
*/
public static int getKnockbackModifier(EntityLivingBase player)
{
return getMaxEnchantmentLevel(Enchantments.KNOCKBACK, player);
}
/**
* Returns the fire aspect modifier of the players held item.
*/
public static int getFireAspectModifier(EntityLivingBase player)
{
return getMaxEnchantmentLevel(Enchantments.FIRE_ASPECT, player);
}
public static int getRespirationModifier(EntityLivingBase p_185292_0_)
{
return getMaxEnchantmentLevel(Enchantments.RESPIRATION, p_185292_0_);
}
public static int getDepthStriderModifier(EntityLivingBase p_185294_0_)
{
return getMaxEnchantmentLevel(Enchantments.DEPTH_STRIDER, p_185294_0_);
}
public static int getEfficiencyModifier(EntityLivingBase p_185293_0_)
{
return getMaxEnchantmentLevel(Enchantments.EFFICIENCY, p_185293_0_);
}
public static int getFishingLuckBonus(ItemStack p_191529_0_)
{
return getEnchantmentLevel(Enchantments.LUCK_OF_THE_SEA, p_191529_0_);
}
public static int getFishingSpeedBonus(ItemStack p_191528_0_)
{
return getEnchantmentLevel(Enchantments.LURE, p_191528_0_);
}
public static int getLootingModifier(EntityLivingBase p_185283_0_)
{
return getMaxEnchantmentLevel(Enchantments.LOOTING, p_185283_0_);
}
public static boolean getAquaAffinityModifier(EntityLivingBase p_185287_0_)
{
return getMaxEnchantmentLevel(Enchantments.AQUA_AFFINITY, p_185287_0_) > 0;
}
/**
* Checks if the player has any armor enchanted with the frost walker enchantment.
* @return If player has equipment with frost walker
*/
public static boolean hasFrostWalkerEnchantment(EntityLivingBase player)
{
return getMaxEnchantmentLevel(Enchantments.FROST_WALKER, player) > 0;
}
public static boolean hasBindingCurse(ItemStack p_190938_0_)
{
return getEnchantmentLevel(Enchantments.BINDING_CURSE, p_190938_0_) > 0;
}
public static boolean hasVanishingCurse(ItemStack p_190939_0_)
{
return getEnchantmentLevel(Enchantments.VANISHING_CURSE, p_190939_0_) > 0;
}
public static ItemStack getEnchantedItem(Enchantment p_92099_0_, EntityLivingBase p_92099_1_)
{
List<ItemStack> list = p_92099_0_.getEntityEquipment(p_92099_1_);
if (list.isEmpty())
{
return ItemStack.EMPTY;
}
else
{
List<ItemStack> list1 = Lists.<ItemStack>newArrayList();
for (ItemStack itemstack : list)
{
if (!itemstack.isEmpty() && getEnchantmentLevel(p_92099_0_, itemstack) > 0)
{
list1.add(itemstack);
}
}
return list1.isEmpty() ? ItemStack.EMPTY : (ItemStack)list1.get(p_92099_1_.getRNG().nextInt(list1.size()));
}
}
/**
* 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(stack);
if (i <= 0)
{
return 0;
}
else
{
if (power > 15)
{
power = 15;
}
int j = rand.nextInt(8) + 1 + (power >> 1) + rand.nextInt(power + 1);
if (enchantNum == 0)
{
return Math.max(j / 3, 1);
}
else
{
return enchantNum == 1 ? j * 2 / 3 + 1 : Math.max(j, power * 2);
}
}
}
/**
* Applys a random enchantment to the specified item.
*/
public static ItemStack addRandomEnchantment(Random random, ItemStack stack, int level, boolean allowTreasure)
{
List<EnchantmentData> list = buildEnchantmentList(random, stack, level, allowTreasure);
boolean flag = stack.getItem() == Items.BOOK;
if (flag)
{
stack = new ItemStack(Items.ENCHANTED_BOOK);
}
for (EnchantmentData enchantmentdata : list)
{
if (flag)
{
ItemEnchantedBook.addEnchantment(stack, enchantmentdata);
}
else
{
stack.addEnchantment(enchantmentdata.enchantment, enchantmentdata.enchantmentLevel);
}
}
return stack;
}
/**
* Create a list of random EnchantmentData (enchantments) that can be added together to the ItemStack, the 3rd
* parameter is the total enchantability level.
*/
public static List<EnchantmentData> buildEnchantmentList(Random randomIn, ItemStack itemStackIn, int level, boolean allowTreasure)
{
List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList();
Item item = itemStackIn.getItem();
int i = item.getItemEnchantability(itemStackIn);
if (i <= 0)
{
return list;
}
else
{
level = level + 1 + randomIn.nextInt(i / 4 + 1) + randomIn.nextInt(i / 4 + 1);
float f = (randomIn.nextFloat() + randomIn.nextFloat() - 1.0F) * 0.15F;
level = MathHelper.clamp(Math.round((float)level + (float)level * f), 1, Integer.MAX_VALUE);
List<EnchantmentData> list1 = getEnchantmentDatas(level, itemStackIn, allowTreasure);
if (!list1.isEmpty())
{
list.add(WeightedRandom.getRandomItem(randomIn, list1));
while (randomIn.nextInt(50) <= level)
{
removeIncompatible(list1, (EnchantmentData)Util.getLastElement(list));
if (list1.isEmpty())
{
break;
}
list.add(WeightedRandom.getRandomItem(randomIn, list1));
level /= 2;
}
}
return list;
}
}
public static void removeIncompatible(List<EnchantmentData> p_185282_0_, EnchantmentData p_185282_1_)
{
Iterator<EnchantmentData> iterator = p_185282_0_.iterator();
while (iterator.hasNext())
{
if (!p_185282_1_.enchantment.isCompatibleWith((iterator.next()).enchantment))
{
iterator.remove();
}
}
}
public static List<EnchantmentData> getEnchantmentDatas(int p_185291_0_, ItemStack p_185291_1_, boolean allowTreasure)
{
List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList();
Item item = p_185291_1_.getItem();
boolean flag = p_185291_1_.getItem() == Items.BOOK;
for (Enchantment enchantment : Enchantment.REGISTRY)
{
if ((!enchantment.isTreasureEnchantment() || allowTreasure) && (enchantment.canApplyAtEnchantingTable(p_185291_1_) || (flag && enchantment.isAllowedOnBooks())))
{
for (int i = enchantment.getMaxLevel(); i > enchantment.getMinLevel() - 1; --i)
{
if (p_185291_0_ >= enchantment.getMinEnchantability(i) && p_185291_0_ <= enchantment.getMaxEnchantability(i))
{
list.add(new EnchantmentData(enchantment, i));
break;
}
}
}
}
return list;
}
static final class DamageIterator implements EnchantmentHelper.IModifier
{
/** The user of the enchantment */
public EntityLivingBase user;
/** The target entity being damaged */
public Entity target;
private DamageIterator()
{
}
/**
* Generic method use to calculate modifiers of offensive or defensive enchantment values.
*/
public void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel)
{
enchantmentIn.onEntityDamaged(this.user, this.target, enchantmentLevel);
}
}
static final class HurtIterator implements EnchantmentHelper.IModifier
{
/** The user of the enchantment */
public EntityLivingBase user;
/** The attacker of the user with the enchantment */
public Entity attacker;
private HurtIterator()
{
}
/**
* Generic method use to calculate modifiers of offensive or defensive enchantment values.
*/
public void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel)
{
enchantmentIn.onUserHurt(this.user, this.attacker, enchantmentLevel);
}
}
interface IModifier
{
/**
* Generic method use to calculate modifiers of offensive or defensive enchantment values.
*/
void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel);
}
static final class ModifierDamage implements EnchantmentHelper.IModifier
{
/**
* Used to calculate the damage modifier (extra armor) on enchantments that the player have on equipped
* armors.
*/
public int damageModifier;
/**
* Used as parameter to calculate the damage modifier (extra armor) on enchantments that the player have on
* equipped armors.
*/
public DamageSource source;
private ModifierDamage()
{
}
/**
* Generic method use to calculate modifiers of offensive or defensive enchantment values.
*/
public void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel)
{
this.damageModifier += enchantmentIn.calcModifierDamage(enchantmentLevel, this.source);
}
}
static final class ModifierLiving implements EnchantmentHelper.IModifier
{
/** Used to calculate the (magic) extra damage based on enchantments of current equipped player item. */
public float livingModifier;
public EnumCreatureAttribute entityLiving;
private ModifierLiving()
{
}
/**
* Generic method use to calculate modifiers of offensive or defensive enchantment values.
*/
public void calculateModifier(Enchantment enchantmentIn, int enchantmentLevel)
{
this.livingModifier += enchantmentIn.calcDamageByCreature(enchantmentLevel, this.entityLiving);
}
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentKnockback extends Enchantment
{
protected EnchantmentKnockback(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.WEAPON, slots);
this.setName("knockback");
}
/**
* 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,57 @@
package net.minecraft.enchantment;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentLootBonus extends Enchantment
{
protected EnchantmentLootBonus(Enchantment.Rarity rarityIn, EnumEnchantmentType typeIn, EntityEquipmentSlot... slots)
{
super(rarityIn, typeIn, slots);
if (typeIn == EnumEnchantmentType.DIGGER)
{
this.setName("lootBonusDigger");
}
else if (typeIn == EnumEnchantmentType.FISHING_ROD)
{
this.setName("lootBonusFishing");
}
else
{
this.setName("lootBonus");
}
}
/**
* 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 != Enchantments.SILK_TOUCH;
}
}

View File

@@ -0,0 +1,41 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentMending extends Enchantment
{
public EnchantmentMending(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.BREAKABLE, slots);
this.setName("mending");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return enchantmentLevel * 25;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + 50;
}
public boolean isTreasureEnchantment()
{
return true;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 1;
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentOxygen extends Enchantment
{
public EnchantmentOxygen(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.ARMOR_HEAD, slots);
this.setName("oxygen");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 10 * enchantmentLevel;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + 30;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 3;
}
}

View File

@@ -0,0 +1,178 @@
package net.minecraft.enchantment;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.MathHelper;
public class EnchantmentProtection extends Enchantment
{
/**
* Defines the type of protection of the enchantment, 0 = all, 1 = fire, 2 = fall (feather fall), 3 = explosion and
* 4 = projectile.
*/
public final EnchantmentProtection.Type protectionType;
public EnchantmentProtection(Enchantment.Rarity rarityIn, EnchantmentProtection.Type protectionTypeIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.ARMOR, slots);
this.protectionType = protectionTypeIn;
if (protectionTypeIn == EnchantmentProtection.Type.FALL)
{
this.type = EnumEnchantmentType.ARMOR_FEET;
}
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return this.protectionType.getMinimalEnchantability() + (enchantmentLevel - 1) * this.protectionType.getEnchantIncreasePerLevel();
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + this.protectionType.getEnchantIncreasePerLevel();
}
/**
* 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 calcModifierDamage(int level, DamageSource source)
{
if (source.canHarmInCreative())
{
return 0;
}
else if (this.protectionType == EnchantmentProtection.Type.ALL)
{
return level;
}
else if (this.protectionType == EnchantmentProtection.Type.FIRE && source.isFireDamage())
{
return level * 2;
}
else if (this.protectionType == EnchantmentProtection.Type.FALL && source == DamageSource.FALL)
{
return level * 3;
}
else if (this.protectionType == EnchantmentProtection.Type.EXPLOSION && source.isExplosion())
{
return level * 2;
}
else
{
return this.protectionType == EnchantmentProtection.Type.PROJECTILE && source.isProjectile() ? level * 2 : 0;
}
}
/**
* Return the name of key in translation table of this enchantment.
*/
public String getName()
{
return "enchantment.protect." + this.protectionType.getTypeName();
}
/**
* 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;
if (this.protectionType == enchantmentprotection.protectionType)
{
return false;
}
else
{
return this.protectionType == EnchantmentProtection.Type.FALL || enchantmentprotection.protectionType == EnchantmentProtection.Type.FALL;
}
}
else
{
return super.canApplyTogether(ench);
}
}
/**
* Gets the amount of ticks an entity should be set fire, adjusted for fire protection.
*/
public static int getFireTimeForEntity(EntityLivingBase p_92093_0_, int p_92093_1_)
{
int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FIRE_PROTECTION, p_92093_0_);
if (i > 0)
{
p_92093_1_ -= MathHelper.floor((float)p_92093_1_ * (float)i * 0.15F);
}
return p_92093_1_;
}
public static double getBlastDamageReduction(EntityLivingBase entityLivingBaseIn, double damage)
{
int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.BLAST_PROTECTION, entityLivingBaseIn);
if (i > 0)
{
damage -= (double)MathHelper.floor(damage * (double)((float)i * 0.15F));
}
return damage;
}
public static enum Type
{
ALL("all", 1, 11, 20),
FIRE("fire", 10, 8, 12),
FALL("fall", 5, 6, 10),
EXPLOSION("explosion", 5, 8, 12),
PROJECTILE("projectile", 3, 6, 15);
private final String typeName;
private final int minEnchantability;
private final int levelCost;
private final int levelCostSpan;
private Type(String name, int minimal, int perLevelEnchantability, int p_i47051_6_)
{
this.typeName = name;
this.minEnchantability = minimal;
this.levelCost = perLevelEnchantability;
this.levelCostSpan = p_i47051_6_;
}
public String getTypeName()
{
return this.typeName;
}
public int getMinimalEnchantability()
{
return this.minEnchantability;
}
public int getEnchantIncreasePerLevel()
{
return this.levelCost;
}
}
}

View File

@@ -0,0 +1,48 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentSweepingEdge extends Enchantment
{
public EnchantmentSweepingEdge(Enchantment.Rarity p_i47366_1_, EntityEquipmentSlot... p_i47366_2_)
{
super(p_i47366_1_, EnumEnchantmentType.WEAPON, p_i47366_2_);
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 5 + (enchantmentLevel - 1) * 9;
}
/**
* 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 3;
}
public static float getSweepingDamageRatio(int p_191526_0_)
{
return 1.0F - 1.0F / (float)(p_191526_0_ + 1);
}
/**
* Return the name of key in translation table of this enchantment.
*/
public String getName()
{
return "enchantment.sweeping";
}
}

View File

@@ -0,0 +1,116 @@
package net.minecraft.enchantment;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
public class EnchantmentThorns extends Enchantment
{
public EnchantmentThorns(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.ARMOR_CHEST, slots);
this.setName("thorns");
}
/**
* 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(EntityLivingBase user, Entity attacker, int level)
{
Random random = user.getRNG();
ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantments.THORNS, user);
if (shouldHit(level, random))
{
if (attacker != null)
{
attacker.attackEntityFrom(DamageSource.causeThornsDamage(user), (float)getDamage(level, random));
}
if (!itemstack.isEmpty())
{
damageArmor(itemstack, 3, user);
}
}
else if (!itemstack.isEmpty())
{
damageArmor(itemstack, 1, user);
}
}
public static boolean shouldHit(int level, Random rnd)
{
if (level <= 0)
{
return false;
}
else
{
return rnd.nextFloat() < 0.15F * (float)level;
}
}
public static int getDamage(int level, Random rnd)
{
return level > 10 ? level - 10 : 1 + rnd.nextInt(4);
}
private void damageArmor(ItemStack stack, int amount, EntityLivingBase entity)
{
int slot = -1;
int x = 0;
for (ItemStack i : entity.getArmorInventoryList())
{
if (i == stack){
slot = x;
break;
}
x++;
}
if (slot == -1 || !(stack.getItem() instanceof net.minecraftforge.common.ISpecialArmor))
{
stack.damageItem(1, entity);
return;
}
net.minecraftforge.common.ISpecialArmor armor = (net.minecraftforge.common.ISpecialArmor)stack.getItem();
armor.damageArmor(entity, stack, DamageSource.causeThornsDamage(entity), amount, slot);
}
}

View File

@@ -0,0 +1,45 @@
package net.minecraft.enchantment;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentUntouching extends Enchantment
{
protected EnchantmentUntouching(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.DIGGER, slots);
this.setName("untouching");
}
/**
* 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 != Enchantments.FORTUNE;
}
}

View File

@@ -0,0 +1,46 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentVanishingCurse extends Enchantment
{
public EnchantmentVanishingCurse(Enchantment.Rarity p_i47252_1_, EntityEquipmentSlot... p_i47252_2_)
{
super(p_i47252_1_, EnumEnchantmentType.ALL, p_i47252_2_);
this.setName("vanishing_curse");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 25;
}
/**
* 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;
}
public boolean isTreasureEnchantment()
{
return true;
}
public boolean isCurse()
{
return true;
}
}

View File

@@ -0,0 +1,45 @@
package net.minecraft.enchantment;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentWaterWalker extends Enchantment
{
public EnchantmentWaterWalker(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.ARMOR_FEET, slots);
this.setName("waterWalker");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return enchantmentLevel * 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 3;
}
/**
* Determines if the enchantment passed can be applyied together with this enchantment.
*/
public boolean canApplyTogether(Enchantment ench)
{
return super.canApplyTogether(ench) && ench != Enchantments.FROST_WALKER;
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.enchantment;
import net.minecraft.inventory.EntityEquipmentSlot;
public class EnchantmentWaterWorker extends Enchantment
{
public EnchantmentWaterWorker(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
{
super(rarityIn, EnumEnchantmentType.ARMOR_HEAD, slots);
this.setName("waterWorker");
}
/**
* Returns the minimal value of enchantability needed on the enchantment level passed.
*/
public int getMinEnchantability(int enchantmentLevel)
{
return 1;
}
/**
* Returns the maximum value of enchantability nedded on the enchantment level passed.
*/
public int getMaxEnchantability(int enchantmentLevel)
{
return this.getMinEnchantability(enchantmentLevel) + 40;
}
/**
* Returns the maximum level that the enchantment can have.
*/
public int getMaxLevel()
{
return 1;
}
}

View File

@@ -0,0 +1,151 @@
package net.minecraft.enchantment;
import net.minecraft.block.BlockPumpkin;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemElytra;
import net.minecraft.item.ItemFishingRod;
import net.minecraft.item.ItemSkull;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
public enum EnumEnchantmentType
{
ALL {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
for (EnumEnchantmentType enumenchantmenttype : EnumEnchantmentType.values())
{
if (enumenchantmenttype != EnumEnchantmentType.ALL && enumenchantmenttype.canEnchantItem(itemIn))
{
return true;
}
}
return false;
}
},
ARMOR {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemArmor;
}
},
ARMOR_FEET {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemArmor && ((ItemArmor)itemIn).armorType == EntityEquipmentSlot.FEET;
}
},
ARMOR_LEGS {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemArmor && ((ItemArmor)itemIn).armorType == EntityEquipmentSlot.LEGS;
}
},
ARMOR_CHEST {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemArmor && ((ItemArmor)itemIn).armorType == EntityEquipmentSlot.CHEST;
}
},
ARMOR_HEAD {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemArmor && ((ItemArmor)itemIn).armorType == EntityEquipmentSlot.HEAD;
}
},
WEAPON {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemSword;
}
},
DIGGER {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemTool;
}
},
FISHING_ROD {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemFishingRod;
}
},
BREAKABLE {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn.isDamageable();
}
},
BOW {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return itemIn instanceof ItemBow;
}
},
WEARABLE {
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
boolean flag = itemIn instanceof ItemBlock && ((ItemBlock)itemIn).getBlock() instanceof BlockPumpkin;
return itemIn instanceof ItemArmor || itemIn instanceof ItemElytra || itemIn instanceof ItemSkull || flag;
}
};
private EnumEnchantmentType()
{
}
private com.google.common.base.Predicate<Item> delegate = null;
private EnumEnchantmentType(com.google.common.base.Predicate<Item> delegate)
{
this.delegate = delegate;
}
/**
* Return true if the item passed can be enchanted by a enchantment of this type.
*/
public boolean canEnchantItem(Item itemIn)
{
return this.delegate == null ? false : this.delegate.apply(itemIn);
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.enchantment;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;