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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#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
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos,
        EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)

    if (world.isRemote == false)
        ItemStack stack = player.getHeldItem(hand);

        if (this.isCarryingBlock(stack))
            this.tryPlaceDownBlock(stack, player, world, pos, side);
            this.tryPickUpBlock(stack, player, world, pos, side);

    return world.isRemote ? EnumActionResult.PASS : EnumActionResult.SUCCESS;
Example 2
Source Project: Sakura_mod   File:    License: MIT License 5 votes vote down vote up
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	if(RecipesUtil.containsMatch(false, OreDictionary.getOres("stickWood"), playerIn.getHeldItem(hand))){
		worldIn.playSound(playerIn, pos, CommonProxy.TAIKO, SoundCategory.BLOCKS, 1.2F, 1.2F);
	return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
Example 3
default void setCooldown(World world, @Nullable EntityPlayer player, @Nullable EnumHand hand, ItemStack stack, @Nonnull SpellData data) {
	int maxCooldown = 0;

	List<SpellRing> rings = SpellUtils.getAllSpellRings(stack);

	for (SpellRing ring : rings) {
		if (ring.isContinuous()) return;

		if (ring.getModule() != null && ring.getModule().getModuleClass() instanceof IOverrideCooldown) {

			maxCooldown = ring.getCooldownTime(world, data);
		if (ring.getCooldownTime() > maxCooldown)
			maxCooldown = ring.getCooldownTime();

	if (maxCooldown <= 0) return;

	if (player != null && hand != null) {
		if (!world.isRemote)
			if (hand == EnumHand.MAIN_HAND)
				PacketHandler.NETWORK.sendTo(new PacketSyncCooldown(true, false), (EntityPlayerMP) player);
			else PacketHandler.NETWORK.sendTo(new PacketSyncCooldown(false, true), (EntityPlayerMP) player);

	NBTHelper.setInt(stack, NBTConstants.NBT.LAST_COOLDOWN, maxCooldown);
	NBTHelper.setLong(stack, NBTConstants.NBT.LAST_CAST, world.getTotalWorldTime());
Example 4
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) {
	ItemStack stack = player.getHeldItem(hand);
	if (player.isSneaking()) {
		for (SpellRing spellRing : SpellUtils.getAllSpellRings(stack)) {
			if ((spellRing.getModule() != null ? spellRing.getModule().getModuleClass() : null) instanceof IBlockSelectable) {
				if ( break;
				NBTHelper.setCompound(stack, "selected", NBTUtil.writeBlockState(new NBTTagCompound(), world.getBlockState(pos)));
				return EnumActionResult.PASS;

	if (isCoolingDown(world, stack)) return EnumActionResult.PASS;
	if (requiresBowAction(stack)) return EnumActionResult.PASS;
	if (BaublesSupport.getItem(player, ModItems.CREATIVE_HALO, ModItems.FAKE_HALO, ModItems.REAL_HALO).isEmpty())
		return EnumActionResult.PASS;

	SpellData spell = new SpellData();
	spell.processEntity(player, true);
	spell.processBlock(pos, side, new Vec3d(pos).add(0.5, 0.5, 0.5));
	SpellUtils.runSpell(world, stack, spell);

	setCooldown(world, player, hand, stack, spell);

	return EnumActionResult.PASS;
Example 5
Source Project: WearableBackpacks   File:    License: MIT License 5 votes vote down vote up
public void onPlayerInteractBlock(PlayerInteractEvent.RightClickBlock event) {

	// This event is fired twice, once for each hand. Unfortunately there
	// is no way to set the result of the main hand interaction to SUCCESS
	// so the off hand one will be skipped. So: Hacky code!

	if (cancelOffHand) {
		cancelOffHand = false;
		if (event.getHand() == EnumHand.OFF_HAND)
			{ event.setCanceled(true); return; }

	// When players sneak-right-click the ground with an
	// empty hand, place down their equipped backpack.

	EntityPlayer player = event.getEntityPlayer();
	World world = event.getWorld();
	if (!player.isSneaking() || (event.getHand() != EnumHand.MAIN_HAND) ||
	    !player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) return;

	IBackpack backpack = BackpackHelper.getBackpack(player);
	if (backpack == null) return;

	// Try place the equipped backpack on the ground by using it. Also takes
	// care of setting the tile entity stack and data as well as unequipping.
	// See ItemBackpack.onItemUse.
	player.inventory.mainInventory.set(player.inventory.currentItem, backpack.getStack());
	if (backpack.getStack().onItemUse(
			player, world, event.getPos(), EnumHand.MAIN_HAND,
			event.getFace(), 0.5F, 0.5F, 0.5F) == EnumActionResult.SUCCESS) {

		cancelOffHand = true;

	} else player.inventory.mainInventory.set(player.inventory.currentItem, ItemStack.EMPTY);