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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#setActiveHand() . 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: MetaItem.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    for (IItemBehaviour behaviour : getBehaviours(itemStack)) {
        ActionResult<ItemStack> behaviourResult = behaviour.onItemRightClick(world, player, hand);
        itemStack = behaviourResult.getResult();
        if (behaviourResult.getType() != EnumActionResult.PASS) {
            return ActionResult.newResult(behaviourResult.getType(), itemStack);
        } else if (itemStack.isEmpty()) {
            return ActionResult.newResult(EnumActionResult.PASS, ItemStack.EMPTY);
        }
    }
    IItemUseManager useManager = getUseManager(itemStack);
    if (useManager != null && useManager.canStartUsing(itemStack, player)) {
        useManager.onItemUseStart(itemStack, player);
        player.setActiveHand(hand);
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
    }
    return ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
 
Example 2
Source File: ItemStaff.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);

	if(PotionTimeSlow.timeScale(player) == 0) return new ActionResult<>(EnumActionResult.PASS, stack);

	if (player.isSneaking()) return new ActionResult<>(EnumActionResult.PASS, stack);

	boolean hasHalo = BaublesSupport.getItem(player, ModItems.CREATIVE_HALO, ModItems.FAKE_HALO, ModItems.REAL_HALO).isEmpty();
	if (isCoolingDown(world, stack) || hasHalo) {
		return new ActionResult<>(EnumActionResult.FAIL, stack);
	} else {
		if (requiresBowAction(stack))
			player.setActiveHand(hand);
		else {
			SpellData spell = new SpellData();
			spell.processEntity(player, true);
			SpellUtils.runSpell(world, stack, spell);

			setCooldown(world, player, hand, stack, spell);
		}
		return new ActionResult<>(EnumActionResult.PASS, stack);
	}
}
 
Example 3
Source File: DrinkSoymilkRamune.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(true)||playerIn.isCreative())
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 4
Source File: ItemGrowingTofu.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(false))
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult<>(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 5
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);
    BlockPosEU pos = this.getPosition(stack, POS_START);

    if (pos == null)
    {
        return super.onItemRightClick(world, player, hand);
    }

    Mode mode = Mode.getMode(stack);

    if (world.isRemote == false)
    {
        if (this.cancelRunningTask(player))
        {
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
        }
        else if (mode.hasUseDelay() == false)
        {
            EnumActionResult result = this.useWand(stack, world, player, pos);
            return new ActionResult<ItemStack>(result, stack);
        }
    }

    if (mode.hasUseDelay() && this.getPosition(stack, POS_END) != null)
    {
        player.setActiveHand(hand);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
    }

    return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
 
Example 6
Source File: ItemFirestarter.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
	ItemStack itemstack = playerIn.getHeldItem(handIn);

	playerIn.setActiveHand(handIn);
	return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
 
Example 7
Source File: ItemFoodTFC.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
	ItemStack itemStackIn = playerIn.getHeldItem(handIn);
	if (playerIn.canEat(false))
	{
		playerIn.setActiveHand(handIn);
		return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
	}

	return new ActionResult(EnumActionResult.FAIL, itemStackIn);
}
 
Example 8
Source File: ItemGravityRay.java    From Production-Line with MIT License 5 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    if (player.capabilities.isCreativeMode || ElectricItem.manager.getCharge(stack) >= 100) {
        player.setActiveHand(hand);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }
    return new ActionResult<>(EnumActionResult.PASS, stack);
}
 
Example 9
Source File: ItemEnderBow.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);
    // This method needs to also be executed on the client, otherwise the bow won't be set to in use

    if (this.isBroken(stack))
    {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
    }

    if (this.getBowMode(stack) == BOW_MODE_TP_TARGET)
    {
        // In survival teleporting targets requires Ender Charge
        if ((player.capabilities.isCreativeMode == false && UtilItemModular.useEnderCharge(stack, ENDER_CHARGE_COST_MOB_TP, true) == false) ||
            OwnerData.canAccessSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL, player) == false ||
            TargetData.selectedModuleHasTargetTag(stack, ModuleType.TYPE_LINKCRYSTAL) == false)
        {
            return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
        }
    }

    if (player.capabilities.isCreativeMode || player.inventory.hasItemStack(new ItemStack(EnderUtilitiesItems.ENDER_ARROW)))
    {
        player.setActiveHand(hand);

        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
    }

    return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
 
Example 10
Source File: ItemFood.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack stack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(content.alwaysEdible.get(stack.getMetadata()).orElse(false)))
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    } else
    {
        return new ActionResult<>(EnumActionResult.FAIL, stack);
    }
}
 
Example 11
Source File: ItemJar.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);
	if (stack.getItemDamage() == 1) {
		player.setActiveHand(hand);
		return new ActionResult<>(EnumActionResult.SUCCESS, stack);
	}
	return new ActionResult<>(EnumActionResult.FAIL, stack);
}
 
Example 12
Source File: ItemSyringe.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);
	if (getItemUseAction(stack) == EnumAction.BOW) {
		if (world.isRemote && (Minecraft.getMinecraft().currentScreen != null)) {
			return new ActionResult<>(EnumActionResult.FAIL, stack);
		} else {
			player.setActiveHand(hand);
			return new ActionResult<>(EnumActionResult.PASS, stack);
		}
	} else return new ActionResult<>(EnumActionResult.FAIL, stack);
}
 
Example 13
Source File: ItemEnderPorter.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);
    // This needs to also happen on the client, otherwise the in-use will derp up

    if (player == null || OwnerData.canAccessSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL, player) == false)
    {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
    }

    // Don't activate when sneaking and looking at a block, aka. binding to a new location
    if (player.isSneaking())
    {
        RayTraceResult rayTraceResult = this.rayTrace(world, player, true);

        if (rayTraceResult != null && rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
        }
    }

    TargetData target = TargetData.getTargetFromSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL);
    int playerDim = player.getEntityWorld().provider.getDimension();

    // The basic version can only teleport inside the same dimension
    if (target != null && EntityUtils.doesEntityStackHaveBlacklistedEntities(player) == false
        && (this.isAdvancedPorter(stack) || target.dimension == playerDim))
    {
        int cost = (target.dimension == playerDim ? ENDER_CHARGE_COST_INTER_DIM_TP : ENDER_CHARGE_COST_CROSS_DIM_TP);

        if (UtilItemModular.useEnderCharge(stack, cost, true) == false)
        {
            return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
        }

        player.setActiveHand(hand);

        if (world.isRemote == false)
        {
            Effects.playSoundEffectServer(world, player.posX, player.posY, player.posZ,
                SoundEvents.BLOCK_PORTAL_TRIGGER, SoundCategory.MASTER, 0.08f, 1.2f);
        }

        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
    }

    return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
 
Example 14
Source File: ItemKatana.java    From Sakura_mod with MIT License 4 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack stack = playerIn.getHeldItem(handIn);
    playerIn.setActiveHand(handIn);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example 15
Source File: ItemKotachi.java    From Sakura_mod with MIT License 4 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack stack = playerIn.getHeldItem(handIn);
    playerIn.setActiveHand(handIn);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example 16
Source File: ItemShinai.java    From Sakura_mod with MIT License 4 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack stack = playerIn.getHeldItem(handIn);
    playerIn.setActiveHand(handIn);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example 17
Source File: ItemSheathKatana.java    From Sakura_mod with MIT License 4 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack stack = playerIn.getHeldItem(handIn);
    playerIn.setActiveHand(handIn);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example 18
Source File: ItemSheath.java    From Sakura_mod with MIT License 4 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack stack = playerIn.getHeldItem(handIn);
    playerIn.setActiveHand(handIn);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example 19
Source File: ItemTofuShield.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    playerIn.setActiveHand(handIn);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
 
Example 20
Source File: ItemBasicLaserGun.java    From AdvancedRocketry with MIT License 3 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand) {

	player.setActiveHand(hand);

	posMap.remove(player);
	ItemStack stack = player.getHeldItem(hand);



	//if(true)
	//	return super.onItemRightClick(stack, worldIn, player, hand);
	World world = player.getEntityWorld();

	RayTraceResult rayTrace = rayTraceEntity(world,player);

	if(rayTrace != null) {
		rayTrace.entityHit.attackEntityFrom(DamageSource.GENERIC, .5f);
		if(world.isRemote)
			LibVulpes.proxy.playSound(worldIn, player.getPosition(), AudioRegistry.basicLaser, SoundCategory.PLAYERS, Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.PLAYERS), 1f);

		return new ActionResult(EnumActionResult.PASS, stack);
	}

	rayTrace = rayTrace(world, (EntityPlayer) player, false);

	if(rayTrace != null && rayTrace.typeOfHit == Type.BLOCK) {
		IBlockState state = world.getBlockState(rayTrace.getBlockPos());

		if(world.isRemote)
			LibVulpes.proxy.playSound(worldIn, player.getPosition(), AudioRegistry.basicLaser, SoundCategory.PLAYERS, Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.PLAYERS), 1f);

		return new ActionResult(EnumActionResult.PASS, stack);
	}
	return new ActionResult(EnumActionResult.PASS, stack);
}