Java Code Examples for net.minecraft.entity.player.EntityPlayer#isHandActive()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#isHandActive() .
Example 1
Project: ToroQuest   File: EntityToroNpc.java    License: GNU General Public License v3.0 5 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
Project: ToroQuest   File: EntityToro.java    License: 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;
}