Jump to content

1.11.2 Enchantment Difference Help


[NoOneButNo]

Recommended Posts

So I direct port my mod from 1.7.10 to 1.11.2. This code that I will be posting came from 1.7.10 but edited a little bit. The problem is that the enchantment doesn't seem to work so I 

started to look in the minecraft codes. When looking at the EnchantmentDamage.class, I don't understand why it gives extra damage because it just put senseless code 

this is an example of the enchantmentdamage in 1.11.2

Spoiler

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
{
    /** Holds the name to be translated of each protection type. */
    private static final String[] PROTECTION_NAME = new String[] {"all", "undead", "arthropods"};
    /** Holds the base factor of enchantability needed to be able to use the enchant. */
    private static final int[] BASE_ENCHANTABILITY = new int[] {1, 5, 5};
    /** Holds how much each level increased the enchantability factor to be able to use this enchant. */
    private static final int[] LEVEL_ENCHANTABILITY = new int[] {11, 8, 8};
    /**
     * 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[] THRESHOLD_ENCHANTABILITY = 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 BASE_ENCHANTABILITY[this.damageType] + (enchantmentLevel - 1) * LEVEL_ENCHANTABILITY[this.damageType];
    }

    /**
     * Returns the maximum value of enchantability nedded on the enchantment level passed.
     */
    public int getMaxEnchantability(int enchantmentLevel)
    {
        return this.getMinEnchantability(enchantmentLevel) + THRESHOLD_ENCHANTABILITY[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)
    {
        return this.damageType == 0 ? 1.0F + (float)Math.max(0, level - 1) * 0.5F : (this.damageType == 1 && creatureType == EnumCreatureAttribute.UNDEAD ? (float)level * 2.5F : (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." + PROTECTION_NAME[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));
            }
        }
    }
}

as you read it, you can't find the original damage of an item (for example a sword, then added by 1.0f per level) all you see is a float that get multiplies by each level without it adding in the original damage. Help me and this is the directed 1.7.10 code. Can someone help me fix it or tell me what the hell is wrong with this code because it worked backed in 1.7.10 (This code was changed a little bit to be registered in 1.11.2)

Spoiler

package com.NoOne.ButNo.MyEnchantments.DamageChanger_Sword;

import com.NoOne.ButNo.MyEnchantments.MyEnchantments;
import com.NoOne.ButNo.MyEnchantments.Util.Physical;
import com.NoOne.ButNo.MyEnchantments.Util.Utility1;
import com.NoOne.ButNo.MyEnchantments.Util.Utility2;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentDamage;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityMagmaCube;
import net.minecraft.entity.monster.EntityWitch;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;


public class EnchantmentArmorPiercing extends Enchantment {
    public EnchantmentArmorPiercing(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
    {
        super(rarityIn, EnumEnchantmentType.WEAPON, slots);
        this.setName("ArmorPiercing");
    }
      
    

        
    
    @Override
    public int getMaxLevel()
    {
        return 4;
    }
    
    @Override
    public int getMinEnchantability(int par1)
    {
        return 15 + (par1 - 1) * 8;
    }

    @Override
    public int getMaxEnchantability(int par1)
    {
        return this.getMinEnchantability(par1) + 30;
    }
    
    @Override
    public boolean canApplyTogether(Enchantment fTest)
    {
        if(fTest == SoManyEnchantments.enchantArmorCrushing || fTest instanceof EnchantmentDamage ||fTest == SoManyEnchantments.enchantEnchanted ||fTest == SoManyEnchantments.enchantThorned ||fTest == SoManyEnchantments.enchantCrushing) 
            return false;
        return true;
    }
    
    @Override
    public boolean canApply(ItemStack fTest)
    {
        return Enchantment.getEnchantmentByID(16).canApply(fTest);
    }

  

    
    @SubscribeEvent
    public void HandleEnchant(LivingHurtEvent fEvent)
    {
        if(fEvent.getSource().damageType != "player" && fEvent.getSource().damageType != "mob")
            return;
        
        if(!(fEvent.getSource().getSourceOfDamage() instanceof EntityLivingBase))
            return;
        

        
        EntityLivingBase attacker = (EntityLivingBase)fEvent.getSource().getSourceOfDamage();
        if(attacker == null)
            return;
        
        EntityLivingBase entity = (EntityLivingBase)fEvent.getEntity();

        
        
        
        ItemStack dmgSource = ((EntityLivingBase)fEvent.getSource().getSourceOfDamage()).getHeldItemMainhand();
        if(dmgSource == null)
            return;
        
        ItemStack sword = attacker.getHeldItemMainhand();
        
        if(EnchantmentHelper.getEnchantmentLevel(SoManyEnchantments.enchantArmorPierceBlade, dmgSource) <= 0)
            return;
        
    
        
        
        int levelArmorPiercing = EnchantmentHelper.getEnchantmentLevel(SoManyEnchantments.enchantArmorPierceBlade, dmgSource);
        if(!(fEvent.getEntity() instanceof EntityWitch))
            {
            
            net.minecraft.entity.UtilEntityAttacker.damageEntity(fEvent.getEntityLiving(), Physical.causePhysicalDamage(fEvent.getEntityLiving()), fEvent.getAmount() - (fEvent.getAmount() * (levelArmorPiercing * 0.25f)));
            float LevelDamage = fEvent.getAmount();
            LevelDamage = LevelDamage * (levelArmorPiercing * 0.25f);
            fEvent.setAmount(LevelDamage);
            
            net.minecraft.entity.UtilEntityAttackerNoPotion.damageEntity(fEvent.getEntityLiving(), Utility1.causeArmorBreakDamage(fEvent.getEntityLiving()), fEvent.getAmount());
            fEvent.setAmount(0.1f);
            
            
            
            
            
            
        }
        else if(fEvent.getEntity() instanceof EntityWitch)
        {
            float armor = fEvent.getEntityLiving().getTotalArmorValue();
            float LevelDamage = fEvent.getAmount();
            net.minecraft.entity.UtilEntityAttacker.damageEntity(fEvent.getEntityLiving(), Physical.causePhysicalDamage(fEvent.getEntityLiving()), fEvent.getAmount() - (fEvent.getAmount() * (levelArmorPiercing * 0.25f)));
            LevelDamage = LevelDamage * (levelArmorPiercing * 0.25f);
            float newDamage = LevelDamage;
            
            net.minecraft.entity.UtilEntityAttackerNoPotion.damageEntity(fEvent.getEntityLiving(), DamageSource.STARVE, newDamage);
            float heal = newDamage / 2;
            fEvent.getEntityLiving().heal((heal + 3.65f) * (1.0f - (armor * 0.04f)));
    }
}
}

and don't mind about that witch part. There is some bug about it in 1.7.10.

Link to comment
Share on other sites

This is likely due to the fact that the enchantment doesn't directly handle dealing the damage. The code for attacking does, by checking if there is an enchantment for damage, and if so, querying its value (and then doing the addition itself).

 

For you to get the same effect, you need to use Events.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

LivingAttackEvent probably

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.