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

The following are Jave code examples for showing how to use setActiveHand() 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.
+ Save this method
Example 1
Project: Loot-Slash-Conquer   File: ItemLEMagical.java   View Source Code Vote up 6 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
	Stats statsCap = (Stats) player.getCapability(CapabilityPlayerStats.STATS, null);
	PlayerInformation playerInfo = (PlayerInformation) player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null);
	
	if (statsCap != null && playerInfo != null)
	{
		if (statsCap.getMana() - this.manaPerUse >= 0 && playerInfo.getPlayerLevel() >= NBTHelper.loadStackNBT(player.inventory.getCurrentItem()).getInteger("Level"))
		{	
			player.setActiveHand(hand);
			return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.inventory.getCurrentItem());
		}
	}
	
	if (playerInfo.getPlayerLevel() < NBTHelper.loadStackNBT(player.inventory.getCurrentItem()).getInteger("Level"))
	{
		player.sendMessage(new TextComponentString(TextFormatting.RED + "WARNING: You are using a high-leveled item. It will be useless and will take significantly more damage if it is not removed."));
	}
	
	return new ActionResult<ItemStack>(EnumActionResult.FAIL, player.inventory.getCurrentItem());
}
 
Example 2
Project: Mods   File: TNTCannon.java   View Source Code Vote up 6 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World par2World, EntityPlayer player,
		EnumHand hand) {
	// System.out.println("lel "+stack.getTagCompound().getInteger("wait")+"
	// "+this.allowShot(player,stack, par2World));
	ItemStack stack=player.getHeldItem(hand);
	if (!(stack.hasTagCompound() && stack.getTagCompound().getInteger("wait") > 0)
			&& this.allowShot(player, stack, par2World)) {
		if (!this.usesBowAnimation(stack))
			this.use(stack, par2World, player, 1.8f,
					player.inventory.getStackInSlot(this.getSlotForUse(player, stack)), false);
		else
			// System.out.println("trying");
			player.setActiveHand(hand);
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
	}
	return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
 
Example 3
Project: CustomWorldGen   File: ItemBow.java   View Source Code Vote up 6 votes
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    boolean flag = this.findAmmo(playerIn) != null;

    ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemStackIn, worldIn, playerIn, hand, flag);
    if (ret != null) return ret;

    if (!playerIn.capabilities.isCreativeMode && !flag)
    {
        return !flag ? new ActionResult(EnumActionResult.FAIL, itemStackIn) : new ActionResult(EnumActionResult.PASS, itemStackIn);
    }
    else
    {
        playerIn.setActiveHand(hand);
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
}
 
Example 4
Project: CompositeGear   File: ItemCGBow.java   View Source Code Vote up 6 votes
/**
 * Called when the equipped item is right clicked.
 */
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    boolean flag = !this.findAmmo(playerIn).isEmpty();

    ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
    if (ret != null) return ret;

    if (!playerIn.capabilities.isCreativeMode && !flag)
    {
        return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
    }
    else
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    }
}
 
Example 5
Project: MineCamera   File: ItemPictureBook.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	playerIn.setActiveHand(hand);
	if (!worldIn.isRemote) {
		BlockPos pos = playerIn.getPosition();
		int id = GuiElementLoader.GUI_PICTURE_BOOK;
		playerIn.openGui(MineCamera.instance, id, worldIn, pos.getX(), pos.getY(), pos.getZ());
	}
	return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
 
Example 6
Project: CustomWorldGen   File: ItemFood.java   View Source Code Vote up 5 votes
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    if (playerIn.canEat(this.alwaysEdible))
    {
        playerIn.setActiveHand(hand);
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
    else
    {
        return new ActionResult(EnumActionResult.FAIL, itemStackIn);
    }
}
 
Example 7
Project: harshencastle   File: BaseHarshenStaff.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
	boolean flag = canItemBeUsed(worldIn, playerIn, handIn);
	if(flag && getMaxItemUseDuration(playerIn.getHeldItem(handIn)) > 0)
		playerIn.setActiveHand(handIn);
	if(getMaxItemUseDuration(playerIn.getHeldItem(handIn)) < 0)
		onItemUseFinish(playerIn.getHeldItem(handIn), worldIn, playerIn);
	return new ActionResult<ItemStack>(flag ? EnumActionResult.SUCCESS : EnumActionResult.PASS, playerIn.getHeldItem(handIn));
}
 
Example 8
Project: Mods   File: ItemFlameThrower.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	ItemStack itemStackIn = playerIn.getHeldItem(hand);
	if (TF2Attribute.getModifier("Rage Crit", itemStackIn, 0, playerIn)!=0 &&playerIn.getCapability(TF2weapons.WEAPONS_CAP, null).getPhlogRage()>=20f) {
		playerIn.setActiveHand(hand);
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
	}
	return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
}
 
Example 9
Project: Thermionics   File: ItemSpiritBottle.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
       ItemStack itemstack = playerIn.getHeldItem(handIn);
       
       if (!this.isEmpty(itemstack)) {
           playerIn.setActiveHand(handIn);
           return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
       } else {
           return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
       }
   }
 
Example 10
Project: Infernum   File: ItemSpellBook.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	player.setActiveHand(hand);

	ItemStack stack = player.getHeldItem(hand);

	this.getSpell(stack).onCast(world, player, stack);
	return new ActionResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
 
Example 11
Project: Melodium   File: ItemTempSpellCaster.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
	ItemStack itemstack = playerIn.getHeldItem(handIn);
	playerIn.setActiveHand(handIn);
	spell.songStarted(playerIn, itemstack);

    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
 
Example 12
Project: FirstAid   File: ItemMorphine.java   View Source Code Vote up 5 votes
@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand)
{
    ItemStack itemstack = player.getHeldItem(hand);
    player.setActiveHand(hand);
    return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
}
 
Example 13
Project: Mods   File: ItemBonk.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick( World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	ItemStack itemStackIn=playerIn.getHeldItem(hand);
	Integer value = playerIn.getCapability(TF2weapons.WEAPONS_CAP, null).effectsCool
			.get(getData(itemStackIn).getName());
	if (value == null || value <= 0) {
		playerIn.setActiveHand(hand);
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
	}
	return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
}
 
Example 14
Project: customstuff4   File: ItemFood.java   View Source Code Vote up 5 votes
@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 15
Project: trumpet-skeleton   File: ItemTrumpet.java   View Source Code Vote up 4 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    player.setActiveHand(hand);
    return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
 
Example 16
Project: Soot   File: ItemMug.java   View Source Code Vote up 4 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    playerIn.setActiveHand(handIn);
    return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}
 
Example 17
Project: ExPetrum   File: ItemSpear.java   View Source Code Vote up 4 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
   {
	playerIn.setActiveHand(handIn);
	return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
   }
 
Example 18
Project: ExPetrum   File: ItemWateringCan.java   View Source Code Vote up 4 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
   {
	playerIn.setActiveHand(handIn);
	return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
   }
 
Example 19
Project: Backmemed   File: ItemBucketMilk.java   View Source Code Vote up 4 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    worldIn.setActiveHand(playerIn);
    return new ActionResult(EnumActionResult.SUCCESS, worldIn.getHeldItem(playerIn));
}
 
Example 20
Project: Backmemed   File: ItemShield.java   View Source Code Vote up 4 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    worldIn.setActiveHand(playerIn);
    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}