1.12.2 Patcher la valeur des armures vanilla



  • Bonjour à tous !
    Je viens ici pour vous demandez comment faire pour patcher la valeur des armures, j'y suis arrivé mais je n'arrive pas à appliquer l'armure quand on prend un dégat :

    @SubscribeEvent
    	public static void onDamage(LivingDamageEvent event)
    	{
    		if(!(event.getEntity() instanceof EntityPlayer)) return;
    
    		EntityPlayer player = (EntityPlayer) event.getEntityLiving();
    		
    		float damageAmount = 0;
    		DamageSource damageSrc = event.getSource();
    
    		damageAmount = event.getAmount();
            if (damageAmount <= 0) return;
            damageAmount = applyArmorCalculations(player, damageSrc, damageAmount);
            damageAmount = applyPotionDamageCalculations(player, damageSrc, damageAmount);
            float f = damageAmount;
            damageAmount = Math.max(damageAmount - player.getAbsorptionAmount(), 0.0F);
            player.setAbsorptionAmount(player.getAbsorptionAmount() - (f - damageAmount));
            
            if (damageAmount != 0.0F)
            {
                float f1 = player.getHealth();
                player.getCombatTracker().trackDamage(damageSrc, f1, damageAmount);
                player.setHealth(f1 - damageAmount);
                player.setAbsorptionAmount(player.getAbsorptionAmount() - damageAmount);
            }
    
            player.sendMessage(new TextComponentString("Damage : " + damageAmount));
    	}
    	
    	protected static float applyArmorCalculations(EntityPlayer player, DamageSource source, float damage)
        {
            if (!source.isUnblockable())
            {
                player.inventory.damageArmor(damage);
                damage = getDamageAfterAbsorb(damage, ArmorUtils.getTotalArmorValue(player), (float) player.getEntityAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).getAttributeValue());
            }
    
            return damage;
        }
    	
    	protected static float applyPotionDamageCalculations(EntityPlayer player, DamageSource source, float damage)
        {
            if (source.isDamageAbsolute())
            {
                return damage;
            }
            else
            {
                if (player.isPotionActive(MobEffects.RESISTANCE) && source != DamageSource.OUT_OF_WORLD)
                {
                    int i = (player.getActivePotionEffect(MobEffects.RESISTANCE).getAmplifier() + 1) * 5;
                    int j = 25 - i;
                    float f = damage * (float)j;
                    damage = f / 25.0F;
                }
    
                if (damage <= 0.0F)
                {
                    return 0.0F;
                }
                else
                {
                    int k = EnchantmentHelper.getEnchantmentModifierDamage(player.getArmorInventoryList(), source);
    
                    if (k > 0)
                    {
                        damage = getDamageAfterMagicAbsorb(damage, (float)k);
                    }
    
                    return damage;
                }
            }
        }
    	
    	public static float getDamageAfterAbsorb(float damage, float totalArmor, float toughnessAttribute)
        {
            float f = 2.0F + toughnessAttribute / 4.0F;
            float f1 = totalArmor - damage / f;
            
            if(f1 < 0)
            	f1 = 0.1f;
            
            return damage * (1.0F - f1 / 25.0F);
        }
    
        public static float getDamageAfterMagicAbsorb(float damage, float enchantModifiers)
        {
            float f = enchantModifiers;
            
            if(f < 0)
            	f = 0f;
            
            return damage * (1.0F - f / 25.0F);
        }
    }
    

    ArmorUtils :

    public class ArmorUtils
    {
    	private static int armorValue = 0;
    	
    	public static int getTotalArmorValue(Entity entity)
    	{
    		armorValue = 0;
    		
    		entity.getArmorInventoryList().forEach(armorStack ->
    		{
    			if(armorStack != null || armorStack != ItemStack.EMPTY)
    			{
    				try
    				{
    					ItemArmor armorItem = (ItemArmor) armorStack.getItem();
    					armorValue += armorItem.damageReduceAmount;
    				}
    				catch(Exception e) {}
    			}
    		});		
    		return armorValue;
    	}
    }
    

    Désolé mon code c'est un peu le bordel 😅




Log in to reply