Java Code Examples for net.minecraft.entity.EntityLivingBase#swingArm()

The following examples show how to use net.minecraft.entity.EntityLivingBase#swingArm() . 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 check out the related API usage on the sidebar.
Example 1
Source Project: Sakura_mod   File: ItemSheathKatana.java    License: MIT License 5 votes vote down vote up
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
	EnumHand hand = entityLiving.getActiveHand();
        //big sweep!!!
        entityLiving.swingArm(hand);

        float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
        f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F;

        float f3 = 4.0F + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f;

        float sweepingRatio = 1f+EnchantmentHelper.getSweepingDamageRatio(entityLiving);

        for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.4D + sweepingRatio * 1.2D, 0.3D + sweepingRatio * 0.15D, 1.4D + sweepingRatio * 1.2D))) {
            if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) {
                if (entitylivingbase instanceof EntityLivingBase) {
                    if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer) entitylivingbase).isActiveItemStackBlocking()) {
                        //disable shield
                        ((EntityPlayer) entitylivingbase).disableShield(false);
                    }
                    ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.4F * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F)));
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }

                if (entitylivingbase instanceof MultiPartEntityPart) {
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }
            }
        }

        worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F);

        if (worldIn instanceof WorldServer) {
            double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F));
            double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F);
            ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D);
        }
        dropHand(entityLiving, hand, setKatana(stack));
        ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(katana, 15);
}
 
Example 2
Source Project: Sakura_mod   File: ItemShinai.java    License: MIT License 5 votes vote down vote up
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    int i = this.getMaxItemUseDuration(stack) - timeLeft;
    if (i < 0) return;
        entityLiving.swingArm(entityLiving.getActiveHand());

        float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
        f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F;

        float f1 = i / 15F;
        f1 = (f1 * f1 + f1 * 2.0F) / 2F;
        if(f1>8F) f1=8f;
        float f3 = f1 + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f ;

        float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving);

        for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.6D + sweepingRatio * 1.2D, 0.5D + sweepingRatio * 0.15D, 1.6D + sweepingRatio * 1.2D))) {
            if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) {
                if (entitylivingbase instanceof EntityLivingBase) {
                	f1 = f1/10;
                    ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.6F * f1 * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F)));
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }

                if (entitylivingbase instanceof MultiPartEntityPart) {
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }
            }
        }
        worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F);
        if (worldIn instanceof WorldServer) {
            double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F));
            double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F);
            ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D);
        }
        stack.damageItem(2, entityLiving);
        ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 25);

}
 
Example 3
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {
	if (!(player instanceof EntityPlayer)) return;
	if (player.world.isRemote) return;

	if (count <= 1) {
		player.swingArm(player.getActiveHand());
		((EntityPlayer) player).getCooldownTracker().setCooldown(this, 30);

		if (stack.getItemDamage() == 2) {
			player.addPotionEffect(new PotionEffect(ModPotions.STEROID, 500, 0, true, false));
			stack.setItemDamage(0);
		} else if (stack.getItemDamage() == 1) {
			ManaManager.forObject(player)
					.addMana(ManaManager.getMaxMana(player))
					.close();
			player.attackEntityFrom(DamageSourceMana.INSTANCE, 2);
			stack.setItemDamage(0);
		} else if (stack.getItemDamage() == 0) {

			RayTraceResult raytraceresult = this.rayTrace(player.world, (EntityPlayer) player, true);

			if (raytraceresult != null && raytraceresult.typeOfHit != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
				BlockPos blockpos = raytraceresult.getBlockPos();
				if (raytraceresult.sideHit == null) raytraceresult.sideHit = EnumFacing.UP;

				if (player.world.isBlockModifiable((EntityPlayer) player, blockpos)
						&& ((EntityPlayer) player).canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, stack)) {

					IBlockState iblockstate = player.world.getBlockState(blockpos);

					Fluid fluid = FluidRegistry.lookupFluidForBlock(iblockstate.getBlock());
					if (fluid != null && fluid == ModFluids.MANA && iblockstate.getValue(BlockLiquid.LEVEL) == 0) {
						stack.setItemDamage(1);
					}
				}
			}
		}
	}
}
 
Example 4
Source Project: Sakura_mod   File: ItemKotachi.java    License: MIT License 4 votes vote down vote up
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.SWEEPING, stack);

    if (k > 0) {
        //big sweep!!!
        entityLiving.swingArm(entityLiving.getActiveHand());

        float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
        f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.5F;

        float f3 = EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f;

        float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving);

        for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.4D + sweepingRatio * 1.2D, 0.3D + sweepingRatio * 0.15D, 1.4D + sweepingRatio * 1.2D))) {
            if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) {
                if (entitylivingbase instanceof EntityLivingBase) {
                    if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer) entitylivingbase).isActiveItemStackBlocking()) {
                        //disable shield
                        ((EntityPlayer) entitylivingbase).disableShield(false);
                    }
                    ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.1F * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F)));
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }

                if (entitylivingbase instanceof MultiPartEntityPart) {
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }
            }
        }

        worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F);

        if (worldIn instanceof WorldServer) {
            double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F));
            double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F);
            ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D);
        }

        stack.damageItem(2, entityLiving);

        ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 16);
    }

}
 
Example 5
Source Project: Sakura_mod   File: ItemKatana.java    License: MIT License 4 votes vote down vote up
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.SWEEPING, stack);

    if (k > 0) {
        //big sweep!!!
        entityLiving.swingArm(entityLiving.getActiveHand());

        float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
        f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F;

        float f3 = 2.0F + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f;

        float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving);

        for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.4D + sweepingRatio * 1.2D, 0.3D + sweepingRatio * 0.15D, 1.4D + sweepingRatio * 1.2D))) {
            if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) {
                if (entitylivingbase instanceof EntityLivingBase) {
                    if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer) entitylivingbase).isActiveItemStackBlocking()) {
                        //disable shield
                        ((EntityPlayer) entitylivingbase).disableShield(false);
                    }
                    ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.4F * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F)));
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }

                if (entitylivingbase instanceof MultiPartEntityPart) {
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }
            }
        }

        worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F);

        if (worldIn instanceof WorldServer) {
            double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F));
            double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F);
            ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D);
        }

        stack.damageItem(2, entityLiving);

        ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 25);
    }

}