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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#stopActiveHand() . 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: 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 2
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;
}