Search in sources :

Example 1 with AxeItem

use of net.minecraft.world.item.AxeItem in project Tropicraft by Tropicraft.

the class EntityKoaBase method doHurtTarget.

/**
 * Copied from EntityMob
 */
@Override
public boolean doHurtTarget(Entity entityIn) {
    float damage = (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue();
    float knockback = (float) this.getAttributeValue(Attributes.ATTACK_KNOCKBACK);
    if (entityIn instanceof LivingEntity) {
        damage += EnchantmentHelper.getDamageBonus(this.getMainHandItem(), ((LivingEntity) entityIn).getMobType());
        knockback += EnchantmentHelper.getKnockbackBonus(this);
    }
    boolean flag = entityIn.hurt(DamageSource.mobAttack(this), damage);
    if (flag) {
        if (knockback > 0 && entityIn instanceof LivingEntity) {
            ((LivingEntity) entityIn).knockback(knockback * 0.5F, Mth.sin(this.getYRot() * 0.017453292F), -Mth.cos(this.getYRot() * 0.017453292F));
            this.setDeltaMovement(this.getDeltaMovement().x * 0.6D, this.getDeltaMovement().y, this.getDeltaMovement().z * 0.6D);
        /*this.motionX *= 0.6D;
                this.motionZ *= 0.6D;*/
        }
        int j = EnchantmentHelper.getFireAspect(this);
        if (j > 0) {
            entityIn.setSecondsOnFire(j * 4);
        }
        if (entityIn instanceof Player) {
            Player entityplayer = (Player) entityIn;
            ItemStack itemstack = this.getMainHandItem();
            ItemStack itemstack1 = entityplayer.isUsingItem() ? entityplayer.getUseItem() : ItemStack.EMPTY;
            if (!itemstack.isEmpty() && !itemstack1.isEmpty() && itemstack.getItem() instanceof AxeItem && itemstack1.getItem() == Items.SHIELD) {
                float f1 = 0.25F + (float) EnchantmentHelper.getBlockEfficiency(this) * 0.05F;
                if (this.random.nextFloat() < f1) {
                    entityplayer.getCooldowns().addCooldown(Items.SHIELD, 100);
                    this.level.broadcastEntityEvent(entityplayer, (byte) 30);
                }
            }
        }
        this.doEnchantDamageEffects(this, entityIn);
    }
    return flag;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Player(net.minecraft.world.entity.player.Player) ItemStack(net.minecraft.world.item.ItemStack) AxeItem(net.minecraft.world.item.AxeItem)

Aggregations

LivingEntity (net.minecraft.world.entity.LivingEntity)1 Player (net.minecraft.world.entity.player.Player)1 AxeItem (net.minecraft.world.item.AxeItem)1 ItemStack (net.minecraft.world.item.ItemStack)1