Java Code Examples for net.minecraft.enchantment.EnchantmentHelper#getEfficiencyModifier()

The following examples show how to use net.minecraft.enchantment.EnchantmentHelper#getEfficiencyModifier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityToroNpc.java    From ToroQuest with GNU General Public License v3.0 7 votes vote down vote up
protected void handleSuccessfulAttack(Entity entityIn, int knockback) {
	if (knockback > 0 && entityIn instanceof EntityLivingBase) {
		((EntityLivingBase) entityIn).knockBack(this, (float) knockback * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
		this.motionX *= 0.6D;
		this.motionZ *= 0.6D;
	}

	int j = EnchantmentHelper.getFireAspectModifier(this);

	if (j > 0) {
		entityIn.setFire(j * 4);
	}

	if (entityIn instanceof EntityPlayer) {
		EntityPlayer entityplayer = (EntityPlayer) entityIn;
		ItemStack itemstack = this.getHeldItemMainhand();
		ItemStack itemstack1 = entityplayer.isHandActive() ? entityplayer.getActiveItemStack() : null;

		if (itemstack != null && itemstack1 != null && itemstack.getItem() instanceof ItemAxe && itemstack1.getItem() == Items.SHIELD) {
			float f1 = 0.25F + (float) EnchantmentHelper.getEfficiencyModifier(this) * 0.05F;

			if (this.rand.nextFloat() < f1) {
				entityplayer.getCooldownTracker().setCooldown(Items.SHIELD, 100);
				this.world.setEntityState(entityplayer, (byte) 30);
			}
		}
	}

	this.applyEnchantments(this, entityIn);
}
 
Example 2
Source File: AutoToolModule.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
private float getDigSpeed(IBlockState state, BlockPos pos, ItemStack stack) {
    final Minecraft mc = Minecraft.getMinecraft();
    float f = getDestroySpeed(state, stack);

    if (f > 1.0F) {
        int i = EnchantmentHelper.getEfficiencyModifier(mc.player);

        if (i > 0 && !stack.isEmpty()) {
            f += (float) (i * i + 1);
        }
    }

    if (mc.player.isPotionActive(MobEffects.HASTE)) {
        f *= 1.0F + (float) (mc.player.getActivePotionEffect(MobEffects.HASTE).getAmplifier() + 1) * 0.2F;
    }

    if (mc.player.isPotionActive(MobEffects.MINING_FATIGUE)) {
        float f1;

        switch (mc.player.getActivePotionEffect(MobEffects.MINING_FATIGUE).getAmplifier()) {
            case 0:
                f1 = 0.3F;
                break;
            case 1:
                f1 = 0.09F;
                break;
            case 2:
                f1 = 0.0027F;
                break;
            case 3:
            default:
                f1 = 8.1E-4F;
        }

        f *= f1;
    }

    if (mc.player.isInsideOfMaterial(Material.WATER) && !EnchantmentHelper.getAquaAffinityModifier(mc.player)) {
        f /= 5.0F;
    }

    if (!mc.player.onGround) {
        f /= 5.0F;
    }

    f = net.minecraftforge.event.ForgeEventFactory.getBreakSpeed(mc.player, state, f, pos);
    return (f < 0 ? 0 : f);
}
 
Example 3
Source File: EntityToro.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean attackEntityAsMob(Entity victim) {

	float attackDamage = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
	int knockback = 2;

	if (victim instanceof EntityLivingBase) {
		attackDamage += EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase) victim).getCreatureAttribute());
		knockback += EnchantmentHelper.getKnockbackModifier(this);
	}

	boolean wasDamaged = victim.attackEntityFrom(DamageSource.causeMobDamage(this), attackDamage);

	if (wasDamaged) {

		setRevengeTarget(getAttackTarget());
		setAttackTarget(null);

		if (knockback > 0 && victim instanceof EntityLivingBase) {
			((EntityLivingBase) victim).knockBack(this, (float) knockback * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F),
					(double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
			this.motionX *= 0.6D;
			this.motionZ *= 0.6D;
		}

		if (victim instanceof EntityPlayer) {
			EntityPlayer entityplayer = (EntityPlayer) victim;
			ItemStack itemstack = this.getHeldItemMainhand();
			ItemStack itemstack1 = entityplayer.isHandActive() ? entityplayer.getActiveItemStack() : null;

			if (itemstack != null && itemstack1 != null && itemstack.getItem() instanceof ItemAxe && itemstack1.getItem() == Items.SHIELD) {
				float f1 = 0.25F + (float) EnchantmentHelper.getEfficiencyModifier(this) * 0.05F;

				if (this.rand.nextFloat() < f1) {
					entityplayer.getCooldownTracker().setCooldown(Items.SHIELD, 100);
					this.world.setEntityState(entityplayer, (byte) 30);
				}
			}
		}

		this.applyEnchantments(this, victim);
	}

	return wasDamaged;
}