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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#isHandActive() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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
@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;
}