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

The following are Jave code examples for showing how to use swingArm() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Industrial-Foregoing   File: MobImprisonmentToolItem.java   Source Code and License Vote up 6 votes
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand) {
    if (target.getEntityWorld().isRemote) return false;
    if (target instanceof EntityPlayer || !target.isNonBoss()) return false;
    if (containsEntity(stack)) return false;
    String entityID = EntityList.getKey(target).toString();
    if (isBlacklisted(entityID)) return false;
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setString("entity", entityID);
    nbt.setInteger("id", EntityList.getID(target.getClass()));
    target.writeToNBT(nbt);
    stack.setTagCompound(nbt);
    playerIn.swingArm(hand);
    playerIn.setHeldItem(hand, stack);
    target.setDead();
    return true;
}
 
Example 2
Project: Geolosys   File: BlockSample.java   Source Code and License Vote up 6 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (Config.getInstance().boringSamples)
    {
        String resource = Types.Modded.byMetadata(state.getBlock().getMetaFromState(state)).getResource();
        playerIn.sendStatusMessage(new TextComponentString("You break the sample to find " + resource), true);
    }
    else
    {
        this.dropBlockAsItem(worldIn, pos, state, 0);
    }
    worldIn.setBlockToAir(pos);
    playerIn.swingArm(EnumHand.MAIN_HAND);
    return true;
}
 
Example 3
Project: Geolosys   File: BlockSampleVanilla.java   Source Code and License Vote up 6 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (Config.getInstance().boringSamples)
    {
        String resource = Types.Vanilla.byMetadata(state.getBlock().getMetaFromState(state)).getResource();
        playerIn.sendStatusMessage(new TextComponentString("You break the sample to find " + resource), true);
    }
    else
    {
        this.dropBlockAsItem(worldIn, pos, state, 0);
    }
    worldIn.setBlockToAir(pos);
    playerIn.swingArm(EnumHand.MAIN_HAND);
    return true;
}
 
Example 4
Project: Halloween   File: EntityCreeperween.java   Source Code and License Vote up 6 votes
@Override
protected boolean processInteract(EntityPlayer player, EnumHand hand)
{
	ItemStack stack = player.getHeldItem(hand);
	if (!stack.isEmpty() && stack.getItem() == Items.FLINT_AND_STEEL)
	{
		this.world.playSound(player, this.posX, this.posY, this.posZ, SoundEvents.ITEM_FLINTANDSTEEL_USE, this.getSoundCategory(), 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
		player.swingArm(hand);

		if (!this.world.isRemote)
		{
			this.ignite();
			stack.damageItem(1, player);
			return true;
		}
	}
	return super.processInteract(player, hand);
}
 
Example 5
Project: Backmemed   File: EntityCreeper.java   Source Code and License Vote up 6 votes
protected boolean processInteract(EntityPlayer player, EnumHand hand)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (itemstack.getItem() == Items.FLINT_AND_STEEL)
    {
        this.world.playSound(player, this.posX, this.posY, this.posZ, SoundEvents.ITEM_FLINTANDSTEEL_USE, this.getSoundCategory(), 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
        player.swingArm(hand);

        if (!this.world.isRemote)
        {
            this.ignite();
            itemstack.damageItem(1, player);
            return true;
        }
    }

    return super.processInteract(player, hand);
}
 
Example 6
Project: CustomWorldGen   File: EntityCreeper.java   Source Code and License Vote up 6 votes
protected boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack)
{
    if (stack != null && stack.getItem() == Items.FLINT_AND_STEEL)
    {
        this.worldObj.playSound(player, this.posX, this.posY, this.posZ, SoundEvents.ITEM_FLINTANDSTEEL_USE, this.getSoundCategory(), 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
        player.swingArm(hand);

        if (!this.worldObj.isRemote)
        {
            this.ignite();
            stack.damageItem(1, player);
            return true;
        }
    }

    return super.processInteract(player, hand, stack);
}
 
Example 7
Project: CustomWorldGen   File: ItemFishingRod.java   Source Code and License Vote up 6 votes
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    if (playerIn.fishEntity != null)
    {
        int i = playerIn.fishEntity.handleHookRetraction();
        itemStackIn.damageItem(i, playerIn);
        playerIn.swingArm(hand);
    }
    else
    {
        worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!worldIn.isRemote)
        {
            worldIn.spawnEntityInWorld(new EntityFishHook(worldIn, playerIn));
        }

        playerIn.swingArm(hand);
        playerIn.addStat(StatList.getObjectUseStats(this));
    }

    return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
 
Example 8
Project: TheOink   File: OinkEntityEvents.java   Source Code and License Vote up 5 votes
@SubscribeEvent
public static void sausageInteract(PlayerInteractEvent.EntityInteract e) {
    EntityPlayer player = e.getEntityPlayer();
    if (!player.world.isRemote) {
        if (e.getTarget() instanceof OinkSausage) {
            if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && sausageGlow) {
                sausageGlow = false;
            } else if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && !sausageGlow) {
                sausageGlow = true;
            }
        }
    } else {
        player.swingArm(EnumHand.MAIN_HAND);
    }
}
 
Example 9
Project: Backmemed   File: ItemFishingRod.java   Source Code and License Vote up 5 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);

    if (worldIn.fishEntity != null)
    {
        int i = worldIn.fishEntity.handleHookRetraction();
        itemstack.damageItem(i, worldIn);
        worldIn.swingArm(playerIn);
    }
    else
    {
        itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!itemStackIn.isRemote)
        {
            EntityFishHook entityfishhook = new EntityFishHook(itemStackIn, worldIn);
            int j = EnchantmentHelper.func_191528_c(itemstack);

            if (j > 0)
            {
                entityfishhook.func_191516_a(j);
            }

            int k = EnchantmentHelper.func_191529_b(itemstack);

            if (k > 0)
            {
                entityfishhook.func_191517_b(k);
            }

            itemStackIn.spawnEntityInWorld(entityfishhook);
        }

        worldIn.swingArm(playerIn);
        worldIn.addStat(StatList.getObjectUseStats(this));
    }

    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
 
Example 10
Project: Torched   File: EntityTorchFirework.java   Source Code and License Vote up 4 votes
@Override
public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
{
    if(!world.isRemote && !activating)
    {
        ItemStack is = player.getHeldItem(hand);
        if(is.getItem() == Item.getItemFromBlock(Blocks.TORCH) && getTorches() < 512)
        {
            addTorches(1);
            if(!player.capabilities.isCreativeMode)
            {
                is.shrink(1);
                if(is.isEmpty())
                {
                    player.inventory.mainInventory.set(player.inventory.currentItem, ItemStack.EMPTY);
                }
            }
            player.swingArm(hand);
            return true;
        }
        else if(is.getItem() == Items.GUNPOWDER && getGP() < 512)
        {
            addGP(1);
            if(!player.capabilities.isCreativeMode)
            {
                is.shrink(1);
                if(is.isEmpty())
                {
                    player.inventory.mainInventory.set(player.inventory.currentItem, ItemStack.EMPTY);
                }
            }
            player.swingArm(hand);
            return true;
        }
        else if(is.getItem() == Items.FLINT_AND_STEEL)
        {
            activating = true;
            if(!player.capabilities.isCreativeMode)
            {
                is.setItemDamage(is.getItemDamage() + 1);
            }
            initiator = player;
            player.swingArm(hand);
            return true;
        }
        else if(is.getItem() == Items.GOLD_NUGGET && getSplits() < 16)
        {
            addSplit();
            if(!player.capabilities.isCreativeMode)
            {
                is.shrink(1);
                if(is.isEmpty())
                {
                    player.inventory.mainInventory.set(player.inventory.currentItem, ItemStack.EMPTY);
                }
            }
            player.swingArm(hand);
            return true;
        }
    }
    if(world.isRemote && (player.getHeldItem(hand).getItem() == Item.getItemFromBlock(Blocks.TORCH) || player.getHeldItem(hand).getItem() == Items.GUNPOWDER || player.getHeldItem(hand).getItem() == Items.FLINT_AND_STEEL || player.getHeldItem(hand).getItem() == Items.GOLD_NUGGET))
    {
        player.swingArm(hand);
        return true;
    }
    return false;
}
 
Example 11
Project: ForgeHax   File: AimbotMod.java   Source Code and License Vote up 4 votes
@SubscribeEvent
public void onLocalPlayerUpdate(LocalPlayerUpdateEvent event) {
    EntityPlayer localPlayer = MC.player;
    Entity target = LocalPlayerUtils.getTargetEntity();
    // local player eye pos
    Vec3d selfPos = EntityUtils.getEyePos(localPlayer);
    // local player look vec
    Vec3d selfLookVec = localPlayer.getLookVec();
    // local player view angles
    Angle viewAngles = VectorUtils.vectorAngle(selfLookVec);
    if(hold_target.get()) {
        if(target == null ||
                !isValidTarget(target, EntityUtils.getOBBCenter(target), selfPos, selfLookVec, viewAngles)) {
            target = findTargetEntity(selfPos, selfLookVec, viewAngles);
        }
    } else {
        target = findTargetEntity(selfPos, selfLookVec, viewAngles);
    }
    if(target != null) {
        if(!isHoldingProjectileItem()) {
            Angle aim = Utils.getLookAtAngles(target);
            if (!silent.get())
                LocalPlayerUtils.setViewAngles(aim);
            if (canAttack(localPlayer, target)) {
                // attack entity
                MC.playerController.attackEntity(MC.player, target);
                // swing hand
                localPlayer.swingArm(EnumHand.MAIN_HAND);
                // for rotation packets
                if (silent.get()) {
                    LocalPlayerUtils.setActiveFakeAngles(true);
                    LocalPlayerUtils.setFakeViewAngles(aim);
                    LocalPlayerUtils.sendRotatePacket(aim);
                    return;
                }
            }
        } else {
            ItemStack heldItem = localPlayer.getHeldItemMainhand();
            //Vec3d startPos = EntityUtils.getInterpolatedPos(target, 1).addVector(0, target.getEyeHeight(), 0);
            //Vec3d endPos = EntityUtils.getInterpolatedPos(target, 5).addVector(0, target.getEyeHeight() / 2, 0);
            // this will find the angle we need to shoot at
            ProjectileUtils.ProjectileTraceResult result = new ProjectileUtils.ProjectileTraceResult();
            boolean exists = ProjectileUtils.projectileTrajectoryHitsEntity(target, selfPos, getAimPos(target), result);
            if(!exists || result.shootAngle == null) {
                LocalPlayerUtils.setProjectileTargetAcquired(false);
            } else {
                // we have a projectile target
                LocalPlayerUtils.setProjectileTargetAcquired(true);
                // set view angles
                LocalPlayerUtils.setFakeViewAngles(result.shootAngle);
                if (!silent.get() && Bindings.use.getBinding().isKeyDown()) {
                    LocalPlayerUtils.setViewAngles(result.shootAngle);
                }
                // fake angles no active (wont change rotation packets)
                LocalPlayerUtils.setActiveFakeAngles(false);
                // bow auto attack will release the use key when
                // the force is greater than or equal to the max force
                if(projectile_auto_attack.get() &&
                        Bindings.use.getBinding().isKeyDown() &&
                        ProjectileUtils.getForce(heldItem) >= result.maxForce) {
                    Bindings.use.setPressed(false);
                }
                return;
            }
        }
    }
    // disable aiming from last tick
    LocalPlayerUtils.setActiveFakeAngles(false);
    LocalPlayerUtils.setProjectileTargetAcquired(false);
}
 
Example 12
Project: ArcaneMagic   File: ItemParchment.java   Source Code and License Vote up 4 votes
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
	ItemStack stack = player.getHeldItem(hand);
	if (stack.getItem().equals(ModRegistry.WRITTEN_PARCHMENT))
	{
		Pair<NotebookCategory, Boolean> catInfo = getToUnlock(stack);
		if (catInfo != null)
		{
			if (!world.isRemote)
			{
				INotebookInfo cap = player.getCapability(INotebookInfo.CAP, null);
				if (cap != null)
				{
					NotebookCategory cat = catInfo.first();
					if (cat != null)
					{
						if (!cat.equals(NotebookCategories.UNKNOWN_REALMS)
								&& cap.isUnlocked(cat.getPrerequisiteTag())
								&& !cap.isUnlocked(cat.getRequiredTag()))
						{
							cap.setUnlocked(cat.getRequiredTag());
						}
						if (catInfo.second())
						{
							for (NotebookCategory mightBeParent : NotebookCategory.REGISTRY.getValues())
							{
								if (mightBeParent != null && mightBeParent.getRequiredTag() != null)
								{
									if (mightBeParent.getRequiredTag().equals(cat.getPrerequisiteTag()))
									{
										ArcaneMagicPacketHandler.INSTANCE
												.sendTo(new PacketNotebookToastExpanded(mightBeParent,
														cat.getRequiredTag(), true), (EntityPlayerMP) player);
									}
								}
							}
						} else
						{
							ArcaneMagicPacketHandler.INSTANCE.sendTo(new PacketNotebookToastOrFail(cat, true),
									(EntityPlayerMP) player);
						}

					} else
					{
						ArcaneMagicPacketHandler.INSTANCE.sendTo(new PacketNotebookToastOrFail(cat, true),
								(EntityPlayerMP) player);
					}
				}
			}
		}

		world.playSound(player, player.getPosition(), ArcaneMagicSoundHandler.randomWriteSound(),
				SoundCategory.PLAYERS, 1, 1);
		player.setHeldItem(hand, ItemStack.EMPTY);
		player.swingArm(hand);
		if (!world.isRemote)
		{
			return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
		}
	}
	return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}