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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#swingArm() . 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: ItemDolly.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos,
        EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
{
    player.swingArm(hand);

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

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

    return world.isRemote ? EnumActionResult.PASS : EnumActionResult.SUCCESS;
}
 
Example 2
Source File: BlockTaiko.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
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);
		playerIn.swingArm(hand);
		}
	return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 3
Source File: ICooldownSpellCaster.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
			break;
		}
		if (ring.getCooldownTime() > maxCooldown)
			maxCooldown = ring.getCooldownTime();
	}

	if (maxCooldown <= 0) return;

	if (player != null && hand != null) {
		player.stopActiveHand();
		player.swingArm(hand);
		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
Source File: ItemStaff.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
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 (player.world.isAirBlock(pos)) break;
				NBTHelper.setCompound(stack, "selected", NBTUtil.writeBlockState(new NBTTagCompound(), world.getBlockState(pos)));
				player.stopActiveHand();
				player.swingArm(hand);
				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 File: ProxyCommon.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@SubscribeEvent
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) {

		player.swingArm(EnumHand.MAIN_HAND);
		event.setCanceled(true);
		cancelOffHand = true;

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

}