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


Java ItemStack.onItemUse方法代码示例

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


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

示例1: work

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public float work() {
    if (WorkUtils.isDisabled(this.getBlockType())) return 0;
    List<BlockPos> blockPos = BlockUtils.getBlockPosInAABB(getWorkingArea());
    ++pointer;
    if (pointer >= blockPos.size()) pointer = 0;
    if (pointer < blockPos.size()) {
        BlockPos pos = blockPos.get(pointer);
        if (this.world.isAirBlock(pos) && !this.world.isAirBlock(pos.down())) {
            FakePlayer player = IndustrialForegoing.getFakePlayer(this.world);
            ItemStack stack = inPlant.getStackInSlot(getFilteredSlot(pos));
            if (stack.isEmpty() && inPlant.getLocked()) {
                ItemStack filter = inPlant.getFilterStack(getFilteredSlot(pos));
                for (int i = 0; i < inPlant.getSlots(); ++i) {
                    if (!inPlant.getStackInSlot(i).isEmpty() && inPlant.getStackInSlot(i).isItemEqual(filter)) {
                        stack = inPlant.getStackInSlot(i);
                        break;
                    }
                }
            }
            if (!stack.isEmpty()) {
                if (!ItemStackUtils.isChorusFlower(stack) && !ItemStackUtils.isStackOreDict(stack, "treeSapling") && (this.world.getBlockState(pos.offset(EnumFacing.DOWN)).getBlock().equals(Blocks.DIRT) || this.world.getBlockState(pos.offset(EnumFacing.DOWN)).getBlock().equals(Blocks.GRASS))) {
                    this.world.setBlockState(pos.offset(EnumFacing.DOWN), Blocks.FARMLAND.getDefaultState());
                }
                player.setHeldItem(EnumHand.MAIN_HAND, stack);
                if (stack.getItem().getRegistryName() != null && stack.getItem().getRegistryName().getResourceDomain().equals("forestry")) {
                    player.setPositionAndRotation(pos.getX(), pos.getY(), pos.getZ(), 90, 90);
                    stack.useItemRightClick(this.world, player, EnumHand.MAIN_HAND);
                    return 1;
                }
                EnumActionResult result = stack.onItemUse(player, this.world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
                return result == EnumActionResult.SUCCESS ? 1 : 0;
            }
        }
    } else {
        pointer = 0;
    }
    return 0.1f;
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:40,代码来源:CropSowerTile.java

示例2: placeChest

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void placeChest(TransportableChest chest, ItemStack stack, EntityPlayer player, EnumHand hand, World world, BlockPos pos, EnumFacing face)
{
    BlockPos chestPos = getChestCoords(world, pos, face);

    if (!chest.canPlaceChest(world, chestPos, player, stack))
        return;

    ItemStack chestStack = chest.createChestStack(stack);
    if (chestStack.isEmpty()) return;

    player.setHeldItem(hand, chestStack);
    EnumActionResult result = chestStack.onItemUse(player, world, pos, hand, face, 0.0f, 0.0f, 0.0f);
    player.setHeldItem(hand, stack);
    if (result != EnumActionResult.SUCCESS)
    {
        return;
    }

    TileEntity tile = world.getTileEntity(chestPos);
    if (tile == null) return;

    if (chest.copyTileEntity())
    {
        NBTTagCompound nbt = getTagCompound(stack).getCompoundTag("ChestTile");
        nbt = chest.modifyTileCompound(nbt, world, pos, player, stack);
        world.setTileEntity(chestPos, TileEntity.create(world, nbt));
    } else
    {
        IInventory inv = (IInventory) tile;
        moveItemsIntoChest(stack, inv);
    }

    getTagCompound(stack).removeTag("ChestType");
    getTagCompound(stack).removeTag("ChestName");

    chest.onChestPlaced(world, pos, player, stack);

    damageItem(stack, player);
}
 
开发者ID:cubex2,项目名称:chesttransporter,代码行数:40,代码来源:ItemChestTransporter.java

示例3: rightClick

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean rightClick(BlockPos pos) {
    EnumFacing faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World world = drone.world();
    ItemStack stack = player.getHeldItemMainhand();

    player.setPosition(pos.getX() + 0.5, pos.getY() + 0.5 - player.eyeHeight, pos.getZ() + 0.5);
    player.rotationPitch = faceDir.getFrontOffsetY() * -90;
    player.rotationYaw = PneumaticCraftUtils.getYawFromFacing(faceDir);

    float hitX = (float)(player.posX - pos.getX());
    float hitY = (float)(player.posY - pos.getY());
    float hitZ = (float)(player.posZ - pos.getZ());

    // this is adapted from PlayerInteractionManager#processRightClickBlock()
    try {
        PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, faceDir.getOpposite(),  ForgeHooks.rayTraceEyeHitVec(player, 2.0D));
        if (event.isCanceled() || event.getUseItem() == Event.Result.DENY) {
            return false;
        }

        EnumActionResult ret = stack.onItemUseFirst(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
        if (ret != EnumActionResult.PASS) return false;

        boolean bypass = player.getHeldItemMainhand().doesSneakBypassUse(world, pos, player);
        EnumActionResult result = EnumActionResult.PASS;

        if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            IBlockState iblockstate = world.getBlockState(pos);
            if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
                if (iblockstate.getBlock().onBlockActivated(world, pos, iblockstate, player, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ)) {
                    result = EnumActionResult.SUCCESS;
                }
        }

        if (stack.isEmpty() || player.getCooldownTracker().hasCooldown(stack.getItem())) {
            return false;
        }

        if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock()) {
            Block block = ((ItemBlock)stack.getItem()).getBlock();
            if (block instanceof BlockCommandBlock || block instanceof BlockStructure) {
                return false;
            }
        }

        if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
                || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            ItemStack copyBeforeUse = stack.copy();
            result = stack.onItemUse(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
            if (result == EnumActionResult.PASS) {
                ActionResult<ItemStack> rightClickResult = stack.getItem().onItemRightClick(world, player, EnumHand.MAIN_HAND);
                player.setHeldItem(EnumHand.MAIN_HAND, rightClickResult.getResult());
            }
            if (player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) {
                net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, EnumHand.MAIN_HAND);
            }
        }

        return false;
    } catch (Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:67,代码来源:DroneAIBlockInteract.java

示例4: activateBlockOrUseItem

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Activate the clicked on block, otherwise use the held item.
 */
public boolean activateBlockOrUseItem(EntityPlayer player, World worldIn, ItemStack stack, BlockPos pos, EnumFacing side, float offsetX, float offsetY, float offsetZ)
{
    if (this.gameType == WorldSettings.GameType.SPECTATOR)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof ILockableContainer)
        {
            Block block = worldIn.getBlockState(pos).getBlock();
            ILockableContainer ilockablecontainer = (ILockableContainer)tileentity;

            if (ilockablecontainer instanceof TileEntityChest && block instanceof BlockChest)
            {
                ilockablecontainer = ((BlockChest)block).getLockableContainer(worldIn, pos);
            }

            if (ilockablecontainer != null)
            {
                player.displayGUIChest(ilockablecontainer);
                return true;
            }
        }
        else if (tileentity instanceof IInventory)
        {
            player.displayGUIChest((IInventory)tileentity);
            return true;
        }

        return false;
    }
    else
    {
        if (!player.isSneaking() || player.getHeldItem() == null)
        {
            IBlockState iblockstate = worldIn.getBlockState(pos);

            if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, side, offsetX, offsetY, offsetZ))
            {
                return true;
            }
        }

        if (stack == null)
        {
            return false;
        }
        else if (this.isCreative())
        {
            int j = stack.getMetadata();
            int i = stack.stackSize;
            boolean flag = stack.onItemUse(player, worldIn, pos, side, offsetX, offsetY, offsetZ);
            stack.setItemDamage(j);
            stack.stackSize = i;
            return flag;
        }
        else
        {
            return stack.onItemUse(player, worldIn, pos, side, offsetX, offsetY, offsetZ);
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:65,代码来源:ItemInWorldManager.java

示例5: onPlayerRightClick

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean onPlayerRightClick(EntityPlayerSP player, WorldClient worldIn, ItemStack heldStack, BlockPos hitPos, EnumFacing side, Vec3 hitVec)
{
    this.syncCurrentPlayItem();
    float f = (float)(hitVec.xCoord - (double)hitPos.getX());
    float f1 = (float)(hitVec.yCoord - (double)hitPos.getY());
    float f2 = (float)(hitVec.zCoord - (double)hitPos.getZ());
    boolean flag = false;

    if (!this.mc.theWorld.getWorldBorder().contains(hitPos))
    {
        return false;
    }
    else
    {
        if (this.currentGameType != WorldSettings.GameType.SPECTATOR)
        {
            IBlockState iblockstate = worldIn.getBlockState(hitPos);

            if ((!player.isSneaking() || player.getHeldItem() == null) && iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2))
            {
                flag = true;
            }

            if (!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock)
            {
                ItemBlock itemblock = (ItemBlock)heldStack.getItem();

                if (!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack))
                {
                    return false;
                }
            }
        }

        this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));

        if (!flag && this.currentGameType != WorldSettings.GameType.SPECTATOR)
        {
            if (heldStack == null)
            {
                return false;
            }
            else if (this.currentGameType.isCreative())
            {
                int i = heldStack.getMetadata();
                int j = heldStack.stackSize;
                boolean flag1 = heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
                heldStack.setItemDamage(i);
                heldStack.stackSize = j;
                return flag1;
            }
            else
            {
                return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
            }
        }
        else
        {
            return true;
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:63,代码来源:PlayerControllerMP.java

示例6: processRightClickBlock

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public EnumActionResult processRightClickBlock(EntityPlayerSP player, WorldClient worldIn, BlockPos stack, EnumFacing pos, Vec3d facing, EnumHand vec)
{
    this.syncCurrentPlayItem();
    ItemStack itemstack = player.getHeldItem(vec);
    float f = (float)(facing.xCoord - (double)stack.getX());
    float f1 = (float)(facing.yCoord - (double)stack.getY());
    float f2 = (float)(facing.zCoord - (double)stack.getZ());
    boolean flag = false;

    if (!this.mc.world.getWorldBorder().contains(stack))
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        if (this.currentGameType != GameType.SPECTATOR)
        {
            IBlockState iblockstate = worldIn.getBlockState(stack);

            if ((!player.isSneaking() || player.getHeldItemMainhand().func_190926_b() && player.getHeldItemOffhand().func_190926_b()) && iblockstate.getBlock().onBlockActivated(worldIn, stack, iblockstate, player, vec, pos, f, f1, f2))
            {
                flag = true;
            }

            if (!flag && itemstack.getItem() instanceof ItemBlock)
            {
                ItemBlock itemblock = (ItemBlock)itemstack.getItem();

                if (!itemblock.canPlaceBlockOnSide(worldIn, stack, pos, player, itemstack))
                {
                    return EnumActionResult.FAIL;
                }
            }
        }

        this.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(stack, pos, vec, f, f1, f2));

        if (!flag && this.currentGameType != GameType.SPECTATOR)
        {
            if (itemstack.func_190926_b())
            {
                return EnumActionResult.PASS;
            }
            else if (player.getCooldownTracker().hasCooldown(itemstack.getItem()))
            {
                return EnumActionResult.PASS;
            }
            else
            {
                if (itemstack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
                {
                    Block block = ((ItemBlock)itemstack.getItem()).getBlock();

                    if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
                    {
                        return EnumActionResult.FAIL;
                    }
                }

                if (this.currentGameType.isCreative())
                {
                    int i = itemstack.getMetadata();
                    int j = itemstack.func_190916_E();
                    EnumActionResult enumactionresult = itemstack.onItemUse(player, worldIn, stack, vec, pos, f, f1, f2);
                    itemstack.setItemDamage(i);
                    itemstack.func_190920_e(j);
                    return enumactionresult;
                }
                else
                {
                    return itemstack.onItemUse(player, worldIn, stack, vec, pos, f, f1, f2);
                }
            }
        }
        else
        {
            return EnumActionResult.SUCCESS;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:81,代码来源:PlayerControllerMP.java

示例7: processRightClickBlock

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public EnumActionResult processRightClickBlock(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (this.gameType == GameType.SPECTATOR)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof ILockableContainer)
        {
            Block block1 = worldIn.getBlockState(pos).getBlock();
            ILockableContainer ilockablecontainer = (ILockableContainer)tileentity;

            if (ilockablecontainer instanceof TileEntityChest && block1 instanceof BlockChest)
            {
                ilockablecontainer = ((BlockChest)block1).getLockableContainer(worldIn, pos);
            }

            if (ilockablecontainer != null)
            {
                player.displayGUIChest(ilockablecontainer);
                return EnumActionResult.SUCCESS;
            }
        }
        else if (tileentity instanceof IInventory)
        {
            player.displayGUIChest((IInventory)tileentity);
            return EnumActionResult.SUCCESS;
        }

        return EnumActionResult.PASS;
    }
    else
    {
        if (!player.isSneaking() || player.getHeldItemMainhand().func_190926_b() && player.getHeldItemOffhand().func_190926_b())
        {
            IBlockState iblockstate = worldIn.getBlockState(pos);

            if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ))
            {
                return EnumActionResult.SUCCESS;
            }
        }

        if (stack.func_190926_b())
        {
            return EnumActionResult.PASS;
        }
        else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
        {
            return EnumActionResult.PASS;
        }
        else
        {
            if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
            {
                Block block = ((ItemBlock)stack.getItem()).getBlock();

                if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
                {
                    return EnumActionResult.FAIL;
                }
            }

            if (this.isCreative())
            {
                int j = stack.getMetadata();
                int i = stack.func_190916_E();
                EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
                stack.setItemDamage(j);
                stack.func_190920_e(i);
                return enumactionresult;
            }
            else
            {
                return stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
            }
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:79,代码来源:PlayerInteractionManager.java


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