Java Code Examples for net.minecraft.item.ItemStack#damageItem()

The following examples show how to use net.minecraft.item.ItemStack#damageItem() . 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: ItemArtifact.java    From Artifacts with MIT License 6 votes vote down vote up
public boolean hitEntity(ItemStack itemStack, EntityLivingBase entityVictim, EntityLivingBase entityAttacker)
  {
NBTTagCompound data = itemStack.getTagCompound();
int effectID = 0;
if(data != null) {
	//System.out.println("Hitting...");
	effectID = data.getInteger("hitEntity");
	if(effectID != 0) {
		IArtifactComponent c = ArtifactsAPI.artifacts.getComponent(effectID);
		boolean r = false;
		if(c != null)
			r = c.hitEntity(itemStack, entityVictim, entityAttacker);
		itemStack.damageItem(1, entityVictim);
		return r;
	}
	NBTTagList tagList = data.getTagList("AttributeModifiers", 10);
	for(int i = 0; i < tagList.tagCount(); i++) {
		if(tagList.getCompoundTagAt(i).getString("AttributeName").equals("generic.attackDamage")) {
			itemStack.damageItem(1, entityVictim);
			break; //break out of for loop.
		}
	}
}
return false;
  }
 
Example 2
Source File: ComponentResurrect.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
public void onDeath(ItemStack itemStack, LivingDeathEvent event, boolean isWornArmor) {
	System.out.println("ABORTING DEATH");
	if(isWornArmor && !event.isCanceled()) {
		EntityPlayer player = (EntityPlayer)event.entity;
		NBTTagCompound data = itemStack.getTagCompound();
		//System.out.println("Cooldown: " + data.getInteger("resCooldown"));
		if(data.getInteger("resCooldown_armor") <= 0) {
			event.setCanceled(true);
			player.setHealth(20);
			data.setInteger("resCooldown_armor", 6000);
			itemStack.damageItem(5, player);
			return;
		}
	}
}
 
Example 3
Source File: ItemRidingCrop.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase player) {
    stack.damageItem(1, player);
    if (victim instanceof EntityHorse || victim instanceof EntityPig)
        victim.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 5));
    else if (victim instanceof EntityPlayer || victim instanceof EntityGolem) {
        victim.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 1));
        victim.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 200, 1));
        victim.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 200, 1));
    }
    if (!player.worldObj.isRemote && !Config.noLust && player.worldObj.provider.dimensionId == -1 && player.worldObj.rand.nextInt(15) == 1) {
        EntityItem ent = victim.entityDropItem(new ItemStack(ForbiddenItems.deadlyShards, 1, 4), 1.0F);
        ent.motionY += player.worldObj.rand.nextFloat() * 0.05F;
        ent.motionX += (player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.1F;
        ent.motionZ += (player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.1F;
    }
    return true;
}
 
Example 4
Source File: ItemThorHammerBroken.java    From Electro-Magic-Tools with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
    player.swingItem();
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX + 8, player.posY, player.posZ - 8));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX - 8, player.posY, player.posZ + 8));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX - 8, player.posY, player.posZ - 8));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX + 8, player.posY, player.posZ + 8));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX, player.posY + 4, player.posZ));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX, player.posY + 8, player.posZ));

    if (player.capabilities.isCreativeMode) {
        return itemstack;
    } else {
        itemstack.damageItem(20, player);
        return itemstack;
    }
}
 
Example 5
Source File: ItemEnderSword.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean addToolDamage(ItemStack stack, int amount, EntityLivingBase living1, EntityLivingBase living2)
{
    if (this.isToolBroken(stack))
    {
        return false;
    }

    amount = Math.min(amount, this.getMaxDamage(stack) - stack.getItemDamage());
    stack.damageItem(amount, living2);

    // Tool just broke
    if (this.isToolBroken(stack))
    {
        living1.renderBrokenItemStack(stack);
    }

    return true;
}
 
Example 6
Source File: ComponentObscurity.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
	public boolean hitEntity(ItemStack itemStack, EntityLivingBase entityVictim, EntityLivingBase entityAttacker) {
		EntityPlayerMP player = UtilsForComponents.getPlayerFromUsername(entityAttacker.getCommandSenderName());
		
		if(player != null) {
			player.addPotionEffect(new PotionEffect(14, 600, 0));
			
			PacketBuffer out = new PacketBuffer(Unpooled.buffer());
			
			out.writeInt(PacketHandlerClient.OBSCURITY);
			SToCMessage packet = new SToCMessage(out);
			DragonArtifacts.artifactNetworkWrapper.sendTo(packet, player);
			
			//System.out.println("Cloaking player.");
			itemStack.damageItem(1, player);
//			UtilsForComponents.sendItemDamagePacket(entityAttacker, entityAttacker.inventory.currentItem, 1); //itemStack.damageItem(1, player);
//			itemStack.stackTagCompound.setInteger("onItemRightClickDelay", 200);
		}
		return false;
	}
 
Example 7
Source File: ItemBloodRapier.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase player) {
    stack.damageItem(1, player);
    victim.motionY *= 0.8;
    if (victim.hurtResistantTime > 18)
        victim.hurtResistantTime -= 5;
    if (Compat.bm & victim instanceof EntityPlayer) {
        String target = ((EntityPlayer) victim).getDisplayName();
        int lp = SoulNetworkHandler.getCurrentEssence(target);
        int damage = Math.max(4000, lp / 4);
        if (lp >= damage)
            lp -= damage;
        else
            lp = 0;
        SoulNetworkHandler.setCurrentEssence(target, lp);
        victim.addPotionEffect(new PotionEffect(DarkPotions.bloodSeal.getId(), 1200));
    }
    return true;
}
 
Example 8
Source File: ItemShinai.java    From Sakura_mod with 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 9
Source File: MoCItemWeapon.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Current implementations of this method in child classes do not use the
 * entry argument beside ev. They just raise the damage on the stack.
 */
@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
{
    int i = 1;
    if (breakable)
    {
        i = 10;
    }
    par1ItemStack.damageItem(i, par3EntityLiving);
    int potionTime = 100;
    switch (specialWeaponType)
    {
    case 1: //poison
        par2EntityLiving.addPotionEffect(new PotionEffect(Potion.poison.id, potionTime, 0));
        break;
    case 2: //frost slowdown
        par2EntityLiving.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, potionTime, 0));
        break;
    case 3: //fire
        par2EntityLiving.setFire(10);
        break;
    case 4: //confusion
        par2EntityLiving.addPotionEffect(new PotionEffect(Potion.confusion.id, potionTime, 0));
        break;
    case 5: //blindness
        par2EntityLiving.addPotionEffect(new PotionEffect(Potion.blindness.id, potionTime, 0));
        break;
    default:
        break;
    }

    return true;
}
 
Example 10
Source File: ItemBaseChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    if (player.worldObj.isRemote) {
        return false;
    }
    Block block = player.worldObj.getBlock(x, y, z);
    if (block instanceof IShearable) {
        IShearable target = (IShearable) block;
        if (target.isShearable(stack, player.worldObj, x, y, z)) {
            ArrayList<ItemStack> drops = target.onSheared(stack, player.worldObj, x, y, z,
                    EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
            Random rand = new Random();
            for (ItemStack drop : drops) {
                float f = 0.7F;
                double d = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                double d1 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                double d2 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
                EntityItem entityitem = new EntityItem(player.worldObj, (double) x + d, (double) y + d1, (double) z + d2, drop);
                entityitem.delayBeforeCanPickup = 10;
                player.worldObj.spawnEntityInWorld(entityitem);
            }
            stack.damageItem(1, player);
            player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1);
        }
    }
    return false;
}
 
Example 11
Source File: BlockLogNaturalPalm.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
	if(world.isRemote)
		return true;

	//get our item parameters
	ItemStack stack = player.getHeldItemMainhand();
	int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
	int maxCut = 0;
	if(stack.getItem() instanceof ItemAxe)
	{
		maxCut = ((ItemAxe)stack.getItem()).maxTreeSize;
	}
	else return false;

	//create the map of our tree
	BlockPosList tree = BlockLogNatural.getTreeForCut(world, pos);
	int count = tree.size();

	//if the tree has too many blocks then prevent chopping
	if(count > maxCut)
	{
		player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.treetoobig")));
		return false;
	}
	else if(count > stack.getMaxDamage() - stack.getItemDamage())
	{
		player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.needsrepair")));
		return false;
	}
	else
	{
		for(BlockPos p : tree)
		{
			IBlockState s = world.getBlockState(p);
			this.onBlockHarvested(world, pos, s, player);
			world.setBlockToAir(p);
			s.getBlock().dropBlockAsItem(world, p, s, fortune);
		}
	}
	stack.damageItem(count-1, player);

	return true;
}
 
Example 12
Source File: ItemRelayWire.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos,
    EnumHand hand,
    EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState clickedState = worldIn.getBlockState(pos);
    Block block = clickedState.getBlock();
    TileEntity currentTile = worldIn.getTileEntity(pos);
    ItemStack stack = player.getHeldItem(hand);

    if (currentTile instanceof IVSNodeProvider && !worldIn.isRemote) {
        ICapabilityLastRelay inst = stack
            .getCapability(ValkyrienSkiesControl.lastRelayCapability, null);
        if (inst != null) {
            if (!inst.hasLastRelay()) {
                inst.setLastRelay(pos);
                // Draw a wire in the player's hand after this
            } else {
                BlockPos lastPos = inst.getLastRelay();
                double distanceSq = lastPos.distanceSq(pos);
                TileEntity lastPosTile = worldIn.getTileEntity(lastPos);
                // System.out.println(lastPos.toString());

                if (!lastPos.equals(pos) && lastPosTile != null && currentTile != null) {
                    if (distanceSq < VSConfig.relayWireLength * VSConfig.relayWireLength) {
                        IVSNode lastPosNode = ((IVSNodeProvider) lastPosTile).getNode();
                        IVSNode currentPosNode = ((IVSNodeProvider) currentTile).getNode();
                        if (lastPosNode != null && currentPosNode != null) {
                            if (currentPosNode.isLinkedToNode(lastPosNode)) {
                                player.sendMessage(
                                    new TextComponentString("These nodes are already linked!"));
                            } else if (currentPosNode.canLinkToOtherNode(lastPosNode)) {
                                currentPosNode.makeConnection(lastPosNode);
                                stack.damageItem(1, player);
                            } else {
                                // Tell the player what they did wrong
                                player.sendMessage(new TextComponentString(TextFormatting.RED +
                                    I18n.format("message.vs_control.error_relay_wire_limit", VSConfig.networkRelayLimit)));
                            }
                            inst.setLastRelay(null);
                        }
                    } else {
                        player.sendMessage(
                            new TextComponentString(TextFormatting.RED +
                                I18n.format("message.vs_control.error_relay_wire_length")));
                        inst.setLastRelay(null);
                    }
                } else {
                    inst.setLastRelay(pos);
                }
            }
        }
    }

    if (currentTile instanceof IVSNodeProvider) {
        return EnumActionResult.SUCCESS;
    }

    return EnumActionResult.PASS;
}
 
Example 13
Source File: ItemMetalSword.java    From BaseMetals with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean hitEntity(final ItemStack item, final EntityLivingBase target, final EntityLivingBase attacker) {
    item.damageItem(1, attacker);
    MetalToolEffects.extraEffectsOnAttack(metal,item, target, attacker);
    return true;
}
 
Example 14
Source File: ItemChisel.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
	stack.damageItem(1, attacker);
	return super.hitEntity(stack, attacker, target);
}
 
Example 15
Source File: ItemThorHammer.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 12F);
    itemstack.damageItem(1, attacker);
    return true;
}
 
Example 16
Source File: ItemKatana.java    From Sakura_mod with 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);
    }

}
 
Example 17
Source File: GTEventCheckSpawn.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onSpawn(CheckSpawn event) {
	if (event.getResult() == Event.Result.ALLOW) {
		return;
	}
	if (event.getEntityLiving().isCreatureType(EnumCreatureType.MONSTER, false)) {
		Entity entity = event.getEntity();
		BlockPos spawn = entity.getEntityWorld().getSpawnPoint();
		// This is the code for the safe spawn zone
		if (GTConfig.general.preventMobSpawnsCloseToSpawn
				&& entity.getEntityWorld().provider.getDimensionType().equals(DimensionType.OVERWORLD)
				&& entity.getPosition().distanceSq(spawn.getX(), spawn.getY(), spawn.getZ()) <= 128 * 128) {
			event.setResult(Event.Result.DENY);
		}
		// this is code for zombies spawning with pickaxes
		if (GTConfig.general.caveZombiesSpawnWithPickaxe && entity instanceof EntityZombie && event.getY() <= 50.0F
				&& event.getWorld().rand.nextInt(2) == 0) {
			EntityZombie zombie = (EntityZombie) entity;
			ItemStack tool = getRandomPickaxe(event.getWorld().rand);
			int damage = event.getWorld().rand.nextInt(tool.getMaxDamage() + 1);
			tool.damageItem(GTHelperMath.clip(damage, 1, tool.getMaxDamage() - 1), zombie);
			zombie.setHeldItem(EnumHand.MAIN_HAND, tool);
		}
		// This is the code for the mob repellator
		for (int[] rep : mobReps) {
			World world = event.getEntity().getEntityWorld();
			if (rep[3] == world.provider.getDimension()) {
				TileEntity tile = world.getTileEntity(new BlockPos(rep[0], rep[1], rep[2]));
				if (tile instanceof GTTileMobRepeller) {
					int r = ((GTTileMobRepeller) tile).range;
					double dx = rep[0] + 0.5F - event.getEntity().posX;
					double dy = rep[1] + 0.5F - event.getEntity().posY;
					double dz = rep[2] + 0.5F - event.getEntity().posZ;
					if ((dx * dx + dz * dz + dy * dy) <= Math.pow(r, 2)) {
						event.setResult(Event.Result.DENY);
					}
				}
			}
		}
	}
}
 
Example 18
Source File: ItemThorHammer.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
    player.swingItem();
    float f = 1.0F;
    float f1 = player.prevRotationPitch + ((player.rotationPitch - player.prevRotationPitch) * f);
    float f2 = player.prevRotationYaw + ((player.rotationYaw - player.prevRotationYaw) * f);
    double d = player.prevPosX + ((player.posX - player.prevPosX) * f);
    double d1 = (player.prevPosY + ((player.posY - player.prevPosY) * f) + 1.6200000000000001D) - player.yOffset;
    double d2 = player.prevPosZ + ((player.posZ - player.prevPosZ) * f);
    Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
    float f3 = MathHelper.cos((-f2 * 0.01745329F) - 3.141593F);
    float f4 = MathHelper.sin((-f2 * 0.01745329F) - 3.141593F);
    float f5 = -MathHelper.cos(-f1 * 0.01745329F);
    float f6 = MathHelper.sin(-f1 * 0.01745329F);
    float f7 = f4 * f5;
    float f8 = f6;
    float f9 = f3 * f5;
    double d3 = 5000D;
    Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3, f9 * d3);
    MovingObjectPosition movingobjectposition = player.worldObj.rayTraceBlocks(vec3d, vec3d1, true);
    if (movingobjectposition == null) {
        return itemstack;
    }
    if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
        int i = movingobjectposition.blockX;
        int j = movingobjectposition.blockY;
        int k = movingobjectposition.blockZ;
        world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k));
    } else if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY) {
        Entity entityhit = movingobjectposition.entityHit;
        double x = entityhit.posX;
        double y = entityhit.posY;
        double z = entityhit.posZ;
        world.spawnEntityInWorld(new EntityLightningBolt(world, x, y, z));
    }
    if (player.capabilities.isCreativeMode) {
        return itemstack;
    } else {
        itemstack.damageItem(20, player);
        return itemstack;
    }
}
 
Example 19
Source File: ItemVanillaChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase entityliving, EntityLivingBase attacker) {
    stack.damageItem(1, attacker);
    entityliving.attackEntityFrom(DamageSource.generic, damageAdded);
    return true;
}
 
Example 20
Source File: ItemBaseChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entityLiving) {
    if ((double) block.getBlockHardness(world, x, y, z) != 0.0D) stack.damageItem(1, entityLiving);
    return true;
}