当前位置: 首页>>代码示例>>Java>>正文


Java EntityPlayer.getHeldItem方法代码示例

本文整理汇总了Java中net.minecraft.entity.player.EntityPlayer.getHeldItem方法的典型用法代码示例。如果您正苦于以下问题:Java EntityPlayer.getHeldItem方法的具体用法?Java EntityPlayer.getHeldItem怎么用?Java EntityPlayer.getHeldItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.entity.player.EntityPlayer的用法示例。


在下文中一共展示了EntityPlayer.getHeldItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onItemUse

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    ItemStack is = player.getHeldItem(hand);
    if(is.getItemDamage() == 0)
    {
        if(side == EnumFacing.UP)
        {
            if(world.isSideSolid(pos, side, false))
            {
                is.shrink(1);
                if(!world.isRemote)
                {
                    world.spawnEntity(new EntityTorchFirework(world, pos.getX(), pos.getY(), pos.getZ(), player.capabilities.isCreativeMode && player.isSneaking()));
                }
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return EnumActionResult.PASS;
}
 
开发者ID:iChun,项目名称:Torched,代码行数:22,代码来源:ItemTorchFirework.java

示例2: onItemRightClick

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	if (!world.isRemote) {
		IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
		for (int i = 0; i < baubles.getSlots(); i++)
			if (baubles.getStackInSlot(i).isEmpty() && baubles.isItemValidForSlot(i, player.getHeldItem(hand), player)) {
				baubles.setStackInSlot(i, player.getHeldItem(hand).copy());
				if (!player.capabilities.isCreativeMode) {
					player.setHeldItem(hand, ItemStack.EMPTY);
				}
				onEquipped(player.getHeldItem(hand), player);
				break;
			}
	}
	return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
 
开发者ID:Um-Mitternacht,项目名称:Bewitchment,代码行数:17,代码来源:ItemHorseshoe.java

示例3: onBlockActivated

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
	ItemStack item = playerIn.getHeldItem(hand);
	TileEntity tileEntity = worldIn.getTileEntity(pos);
	if(tileEntity instanceof BaseTileEntityHarshenSingleItemInventory)
		if(((BaseTileEntityHarshenSingleItemInventory)tileEntity).canAddItem() && Item.getItemFromBlock(Blocks.AIR) != item.getItem())
		{
			int i =  item.getCount() - 1;
			if(((BaseTileEntityHarshenSingleItemInventory)tileEntity).setItem(item))
				playerIn.setHeldItem(hand, new ItemStack(item.getItem(), i, item.getMetadata(), item.serializeNBT()));
		}
		else if (!((BaseTileEntityHarshenSingleItemInventory) tileEntity).canAddItem())
		{
			ItemStack stack = ((BaseTileEntityHarshenSingleItemInventory)tileEntity).getItem();
			((BaseTileEntityHarshenSingleItemInventory)tileEntity).setItemAir();
			if(!worldIn.isRemote)
				InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY() + 0.7f, pos.getZ(), stack);
		}

	return true;
}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:23,代码来源:BaseBlockHarshenSingleInventory.java

示例4: onItemRightClick

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
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 && arrowType != EnumHarshenArrowTypes.RIPPER) return ret;

       if (!playerIn.capabilities.isCreativeMode && !flag && arrowType != EnumHarshenArrowTypes.RIPPER)
       {
           return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
       }
       else
       {
           playerIn.setActiveHand(handIn);
           return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
       }
}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:19,代码来源:BaseHarshenBow.java

示例5: giveItemToPlayer

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
/**
 * This function will first try to set the item at the 'heldItem' position if possible.
 * Otherwise it will try to find a suitable place elsewhere. If that fails it will spawn
 * the item in the world. The stack parameter may be modified
 */
public static void giveItemToPlayer(EntityPlayer player, ItemStack stack) {
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
    if (ItemStackTools.isEmpty(heldItem)) {
        player.setHeldItem(EnumHand.MAIN_HAND, stack);
        player.openContainer.detectAndSendChanges();
        return;
    } else if (isItemStackConsideredEqual(heldItem, stack)) {
        if (ItemStackTools.getStackSize(heldItem) < heldItem.getMaxStackSize()) {
            int itemsToAdd = Math.min(ItemStackTools.getStackSize(stack), heldItem.getMaxStackSize() - ItemStackTools.getStackSize(heldItem));
            ItemStackTools.incStackSize(heldItem, itemsToAdd);
            ItemStackTools.incStackSize(stack, -itemsToAdd);
            if (ItemStackTools.isEmpty(stack)) {
                player.openContainer.detectAndSendChanges();
                return;
            }
        }
    }
    // We have items remaining. Add them elsewhere
    if (player.inventory.addItemStackToInventory(stack)) {
        player.openContainer.detectAndSendChanges();
        return;
    }
    // Spawn in world
    spawnItemStack(player.getEntityWorld(), player.getPosition(), stack);
}
 
开发者ID:McJty,项目名称:interactionwheel,代码行数:31,代码来源:InventoryHelper.java

示例6: processInitialInteract

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
public final boolean processInitialInteract(EntityPlayer player, EnumHand stack)
{
    if (this.getLeashed() && this.getLeashedToEntity() == player)
    {
        this.clearLeashed(true, !player.capabilities.isCreativeMode);
        return true;
    }
    else
    {
        ItemStack itemstack = player.getHeldItem(stack);

        if (itemstack.getItem() == Items.LEAD && this.canBeLeashedTo(player))
        {
            this.setLeashedToEntity(player, true);
            itemstack.func_190918_g(1);
            return true;
        }
        else
        {
            return this.processInteract(player, stack) ? true : super.processInitialInteract(player, stack);
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:24,代码来源:EntityLiving.java

示例7: onItemRightClick

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer p, EnumHand handIn)
{
    ItemStack stack = p.getHeldItem(handIn);
    if (!worldIn.isRemote)
    {
        IIfEntryStore store = p.getCapability(CapabilityRegistry.ENTRY_STORE_CAP, null);
        for (Pair<IfEntry, IRSReadPapyrus> pair : PurMag.INSTANCE.getIfRegistry().getAllResearchableSteps(IRSReadPapyrus.class, p, store))
        {
            if (pair.getRight().isSuitable(stack))
            {
                store.unlockStepAndSync(pair.getLeft().getId(), (EntityPlayerMP)p);
            }
        }
    }
    if (stack.hasTagCompound())
    {
        if (stack.getTagCompound().hasKey("papyrus_id"))
        {
            PurMag.proxy.openPapyrus(stack.getTagCompound().getString("papyrus_id"));
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, stack);
}
 
开发者ID:PearXTeam,项目名称:PurificatiMagicae,代码行数:25,代码来源:ItemPapyrus.java

示例8: throwProjectile

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
private void throwProjectile(EntityPlayer player, EnumHand hand, World world) {
    ItemStack heldItem = player.getHeldItem(hand);

    int charge = getCharge(heldItem);
    if (charge <= 0) {
        MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_no_charge"), (EntityPlayerMP) player);
        return;
    }
    setCharge(heldItem, charge-1);

    List<TeleportDestination> destinations = getDestinations(heldItem);
    int current = getCurrentDestination(heldItem);
    if (current == -1) {
        MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_no_destination"), (EntityPlayerMP) player);
    } else if (destinations.get(current) == null) {
        MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_bad_destination"), (EntityPlayerMP) player);
    } else {
        EntityProjectile projectile = new EntityProjectile(world, player);
        projectile.setDestination(destinations.get(current));
        projectile.setPlayerId(player.getUniqueID());
        projectile.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
        world.spawnEntity(projectile);
    }
}
 
开发者ID:McJty,项目名称:MeeCreeps,代码行数:25,代码来源:PortalGunItem.java

示例9: onItemRightClick

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    ItemStack itemstack1 = worldIn.capabilities.isCreativeMode ? itemstack.copy() : itemstack.splitStack(1);
    itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

    if (!itemStackIn.isRemote)
    {
        EntityPotion entitypotion = new EntityPotion(itemStackIn, worldIn, itemstack1);
        entitypotion.setHeadingFromThrower(worldIn, worldIn.rotationPitch, worldIn.rotationYaw, -20.0F, 0.5F, 1.0F);
        itemStackIn.spawnEntityInWorld(entitypotion);
    }

    worldIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:17,代码来源:ItemSplashPotion.java

示例10: onItemUse

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos.offset(facing), facing, itemstack))
    {
        int subtype = getMetadata(itemstack);
        IBlockState currentState = worldIn.getBlockState(pos);

        if (currentState.getBlock() == singleSlab)
        {
            int subtype1 = this.singleSlabCS.getSubtype(currentState);
            net.minecraft.block.BlockSlab.EnumBlockHalf half = currentState.getValue(net.minecraft.block.BlockSlab.HALF);

            if ((facing == EnumFacing.UP && half == net.minecraft.block.BlockSlab.EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && half == net.minecraft.block.BlockSlab.EnumBlockHalf.TOP)
                && subtype1 == subtype)
            {
                IBlockState stateDouble = this.makeState(subtype1);
                AxisAlignedBB axisalignedbb = stateDouble == null ? Block.NULL_AABB : stateDouble.getCollisionBoundingBox(worldIn, pos);

                if (stateDouble != null && axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, stateDouble, 11))
                {
                    SoundType soundtype = stateDouble.getBlock().getSoundType(stateDouble, worldIn, pos, player);
                    worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                    itemstack.shrink(1);
                }

                return EnumActionResult.SUCCESS;
            }
        }

        return this.tryPlace(player, itemstack, worldIn, pos.offset(facing), subtype) ? EnumActionResult.SUCCESS : super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    } else
    {
        return EnumActionResult.FAIL;
    }
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:38,代码来源:ItemSlab.java

示例11: onItemRightClick

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer living, EnumHand hand) {
	if(!world.isRemote) {
		living.setHeldItem(hand, RIG.equip(living, living.getHeldItem(hand)));
	}
	return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, living.getHeldItem(hand));
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:8,代码来源:ItemRIG.java

示例12: processRightClick

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
public EnumActionResult processRightClick(EntityPlayer player, World worldIn, EnumHand stack)
{
    if (this.currentGameType == GameType.SPECTATOR)
    {
        return EnumActionResult.PASS;
    }
    else
    {
        this.syncCurrentPlayItem();
        this.connection.sendPacket(new CPacketPlayerTryUseItem(stack));
        ItemStack itemstack = player.getHeldItem(stack);

        if (player.getCooldownTracker().hasCooldown(itemstack.getItem()))
        {
            return EnumActionResult.PASS;
        }
        else
        {
            int i = itemstack.func_190916_E();
            ActionResult<ItemStack> actionresult = itemstack.useItemRightClick(worldIn, player, stack);
            ItemStack itemstack1 = (ItemStack)actionresult.getResult();

            if (itemstack1 != itemstack || itemstack1.func_190916_E() != i)
            {
                player.setHeldItem(stack, itemstack1);
            }

            return actionresult.getType();
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:32,代码来源:PlayerControllerMP.java

示例13: onItemUse

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(EntityPlayer stack, World playerIn, BlockPos worldIn, EnumHand pos, EnumFacing hand, float facing, float hitX, float hitY)
{
    ItemStack itemstack = stack.getHeldItem(pos);
    BlockPos blockpos = worldIn.offset(hand);

    if (hand != EnumFacing.DOWN && hand != EnumFacing.UP && stack.canPlayerEdit(blockpos, hand, itemstack))
    {
        EntityHanging entityhanging = this.createEntity(playerIn, blockpos, hand);

        if (entityhanging != null && entityhanging.onValidSurface())
        {
            if (!playerIn.isRemote)
            {
                entityhanging.playPlaceSound();
                playerIn.spawnEntityInWorld(entityhanging);
            }

            itemstack.func_190918_g(1);
        }

        return EnumActionResult.SUCCESS;
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:31,代码来源:ItemHangingEntity.java

示例14: onItemRightClick

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
  {
if(!hasDrinkEffect(playerIn, handIn))
	return new ActionResult<ItemStack>(EnumActionResult.FAIL, playerIn.getHeldItem(handIn));
playerIn.setActiveHand(handIn);
      return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
  }
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:9,代码来源:GlassContainer.java

示例15: checkMultiblock

import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public Optional<Rotation> checkMultiblock(World w, BlockPos pos, @Nullable EntityPlayer p, @Nullable EnumHand hand)
{
    if(p != null && hand != null)
    {
        ItemStack st = p.getHeldItem(hand);
        if(!(st.getItem() instanceof ItemTinkeringKit && ((ItemTinkeringKit) st.getItem()).getTier() >= getTier()))
        {
            return Optional.empty();
        }
    }
    return super.checkMultiblock(w, pos, p, hand);
}
 
开发者ID:PearXTeam,项目名称:PurificatiMagicae,代码行数:14,代码来源:PMMultiblock.java


注:本文中的net.minecraft.entity.player.EntityPlayer.getHeldItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。