use of net.minecraft.enchantment.Enchantment in project BloodMagic by WayofTime.
the class SpellHelper method applySpecialProtection.
public static float applySpecialProtection(EntityLivingBase entity, DamageSource source, float damage) {
ItemStack[] armour = entity.getLastActiveItems();
if (armour == null) {
return damage;
}
int total = 0;
for (int i = 0; i < armour.length; i++) {
ItemStack stack = armour[i];
if (stack != null) {
NBTTagList nbttaglist = stack.getEnchantmentTagList();
if (nbttaglist != null) {
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
short short1 = nbttaglist.getCompoundTagAt(i).getShort("id");
short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl");
if (Enchantment.enchantmentsList[short1] != null) {
Enchantment ench = Enchantment.enchantmentsList[short1];
if (ench instanceof EnchantmentProtection) {
total += ench.calcModifierDamage(short2, source);
}
}
}
}
}
}
if (total > 0) {
total = (total + 1 >> +1) + rand.nextInt(total + 1 >> +1);
if (total <= 20) {
return damage * (25 - total) / 25;
} else {
float factor = (float) (0.8 + 0.2 * (1 - Math.pow(protCoeff, Math.pow((total - 20), scalCoeff))));
return damage * (1 - factor);
}
}
return damage;
}
use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.
the class ItemEnchantmentToken method clAddInformation.
// =========================
// Item and ItemSL overrides
// =========================
@Override
public void clAddInformation(ItemStack stack, World world, List list, boolean advanced) {
LocalizationHelper loc = SilentGems.localizationHelper;
Map<Enchantment, Integer> enchants = getEnchantments(stack);
if (enchants.size() == 1) {
Enchantment ench = enchants.keySet().iterator().next();
list.add(loc.getItemSubText(itemName, "maxLevel", ench.getMaxLevel()));
// Recipe info
if (KeyTracker.isControlDown()) {
list.add(loc.getItemSubText(itemName, "materials"));
String recipeString = recipeMap.get(ench);
if (recipeString != null && !recipeString.isEmpty()) {
for (String str : recipeString.split(";")) {
list.add(" " + str);
}
}
} else {
list.add(loc.getItemSubText(itemName, "pressCtrl"));
}
// Debug info
if (KeyTracker.isAltDown()) {
list.add(TextFormatting.DARK_GRAY + ench.getRegistryName().toString());
// list.add(TextFormatting.DARK_GRAY + "EnchID: " + ench.getEnchantmentID(ench));
}
}
// Enchantment list
for (Entry<Enchantment, Integer> entry : enchants.entrySet()) {
Enchantment e = entry.getKey();
String enchName = e.getTranslatedName(entry.getValue());
String modName = Loader.instance().getIndexedModList().get(e.getRegistryName().getResourceDomain()).getName();
list.add(loc.getItemSubText(itemName, "enchNameWithMod", enchName, modName));
String descKey = e.getName().replaceAll(":", ".").toLowerCase() + ".desc";
String desc = loc.getLocalizedString(descKey);
if (!desc.equals(descKey))
list.add(TextFormatting.ITALIC + " " + desc);
}
}
use of net.minecraft.enchantment.Enchantment in project SpongeCommon by SpongePowered.
the class DamageEventHandler method createEnchantmentModifiers.
public static Optional<List<DamageFunction>> createEnchantmentModifiers(EntityLivingBase entityLivingBase, DamageSource damageSource) {
if (!damageSource.isDamageAbsolute()) {
Iterable<net.minecraft.item.ItemStack> inventory = entityLivingBase.getArmorInventoryList();
if (EnchantmentHelper.getEnchantmentModifierDamage(Lists.newArrayList(entityLivingBase.getArmorInventoryList()), damageSource) == 0) {
return Optional.empty();
}
List<DamageFunction> modifiers = new ArrayList<>();
boolean first = true;
int totalModifier = 0;
for (net.minecraft.item.ItemStack itemStack : inventory) {
if (itemStack.isEmpty()) {
continue;
}
final Multimap<Enchantment, Short> enchantments = LinkedHashMultimap.create();
NBTTagList enchantmentList = itemStack.getEnchantmentTagList();
if (enchantmentList == null) {
continue;
}
for (int i = 0; i < enchantmentList.tagCount(); ++i) {
final short enchantmentId = enchantmentList.getCompoundTagAt(i).getShort(NbtDataUtil.ITEM_ENCHANTMENT_ID);
final short level = enchantmentList.getCompoundTagAt(i).getShort(NbtDataUtil.ITEM_ENCHANTMENT_LEVEL);
if (Enchantment.getEnchantmentByID(enchantmentId) != null) {
// Ok, we have an enchantment!
final Enchantment enchantment = Enchantment.getEnchantmentByID(enchantmentId);
final int temp = enchantment.calcModifierDamage(level, damageSource);
if (temp != 0) {
enchantments.put(enchantment, level);
}
}
}
ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(itemStack);
for (Map.Entry<Enchantment, Collection<Short>> enchantment : enchantments.asMap().entrySet()) {
final DamageObject object = new DamageObject();
int modifierTemp = 0;
for (short level : enchantment.getValue()) {
modifierTemp += enchantment.getKey().calcModifierDamage(level, damageSource);
}
final int modifier = modifierTemp;
object.previousDamage = totalModifier;
if (object.previousDamage > 25) {
object.previousDamage = 25;
}
totalModifier += modifier;
object.augment = first;
object.ratio = modifier;
DoubleUnaryOperator enchantmentFunction = damageIn -> {
if (object.augment) {
enchantmentDamageTracked = damageIn;
}
if (damageIn <= 0) {
return 0D;
}
double actualDamage = enchantmentDamageTracked;
if (object.previousDamage > 25) {
return 0D;
}
double modifierDamage = actualDamage;
double magicModifier;
if (modifier > 0 && modifier <= 20) {
int j = 25 - modifier;
magicModifier = modifierDamage * j;
modifierDamage = magicModifier / 25.0F;
}
return -Math.max(actualDamage - modifierDamage, 0.0D);
};
if (first) {
first = false;
}
// TODO: direct cause creation: bad bad bad
DamageModifier enchantmentModifier = DamageModifier.builder().cause(Cause.of(EventContext.empty(), enchantment, snapshot, entityLivingBase)).type(DamageModifierTypes.ARMOR_ENCHANTMENT).build();
modifiers.add(new DamageFunction(enchantmentModifier, enchantmentFunction));
}
if (!modifiers.isEmpty()) {
return Optional.of(modifiers);
}
}
}
return Optional.empty();
}
use of net.minecraft.enchantment.Enchantment in project Galacticraft by micdoodle8.
the class ContainerEnchantmentModifier method updateEnchantmentOptions.
public void updateEnchantmentOptions(boolean validate) {
int numoptions = slotEnchantment.size();
slotEnchantment.clear();
ItemStack toolstack = getSlot(0).getStack();
if (toolstack == null) {
percentscrolled = 0;
return;
}
Item item = toolstack.getItem();
int enchantablity = item.getItemEnchantability();
if (enchantablity == 0 && validate) {
percentscrolled = 0;
return;
}
for (Enchantment e : Enchantment.enchantmentsList) {
if (e == null || e.type == null || (!e.type.canEnchantItem(item) && validate)) {
continue;
}
int state = 0;
int level = -1;
if (NEIServerUtils.stackHasEnchantment(toolstack, e.effectId)) {
state = 2;
level = NEIServerUtils.getEnchantmentLevel(toolstack, e.effectId);
} else if (NEIServerUtils.doesEnchantmentConflict(NEIServerUtils.getEnchantments(toolstack), e) && validate) {
state = 1;
}
slotEnchantment.add(new EnchantmentHash(e, state, level));
}
if (numoptions != slotEnchantment.size()) {
percentscrolled = 0;
}
}
use of net.minecraft.enchantment.Enchantment in project BaseMetals by MinecraftModDevelopmentMods.
the class ShieldUpgradeRecipe method matchAndFind.
private Pair<Map<Enchantment, Integer>, ItemStack> matchAndFind(final ItemStack curItem, final Map<String, NonNullList<ItemStack>> plates) {
final ItemStack comp = new ItemStack(curItem.getItem(), 1, curItem.getMetadata());
Map<Enchantment, Integer> enchants = Collections.emptyMap();
ItemStack plateMatched = null;
final ItemStack matcher = new ItemStack(Materials.getMaterialByName(materialName).getItem(Names.SHIELD), 1, 0);
for (final Entry<String, NonNullList<ItemStack>> ent : plates.entrySet()) {
if (OreDictionary.containsMatch(false, ent.getValue(), comp)) {
plateMatched = new ItemStack(Materials.getMaterialByName(ent.getKey().toLowerCase()).getItem(Names.SHIELD), 1, 0);
}
}
if (OreDictionary.itemMatches(matcher, comp, false)) {
enchants = EnchantmentHelper.getEnchantments(curItem);
}
return Pair.of(enchants, plateMatched);
}
Aggregations