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


Java IItemHandler.insertItem方法代码示例

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


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

示例1: onMessage

import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public IMessage onMessage(MessageGlassJarUpdateStats message, MessageContext ctx) {
    ItemStack stack = message.stack;
    BlockPos pos = message.pos;
    WorldClient world = Minecraft.getMinecraft().world;
    if (world.isBlockLoaded(pos) &&
            world.getBlockState(pos).getBlock().hasTileEntity(world.getBlockState(pos))) {
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof TileFaerieHome) {
            IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            if (handler != null) {
                handler.insertItem(0, stack, false);
            }
        }
    }
    return null;
}
 
开发者ID:BenjaminSutter,项目名称:genera,代码行数:18,代码来源:MessageGlassJarUpdateStats.java

示例2: transferIn

import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private boolean transferIn(BlockPos pos, ItemStack inserted, boolean test) {
	EnumFacing facing = getFacing();
	Pair<IItemHandler, ISidedInventory> inv = getInventory(pos, facing);
	if(inv.getKey() != null) {
		IItemHandler handler = inv.getKey();
		ISidedInventory tile = inv.getValue();

		for(int slot = 0; slot < handler.getSlots(); slot++) {
			ItemStack inSlot = handler.getStackInSlot(slot);
			if(tile != null && !tile.canInsertItem(slot, inserted, facing)) return false;
			if(inSlot.isEmpty() || (ItemHandlerHelper.canItemStacksStack(inSlot, inserted) && (inSlot.getCount() < inSlot.getMaxStackSize() && inSlot.getCount() < handler.getSlotLimit(slot)))) {
				return handler.insertItem(slot, inserted, test) != inserted;
			}
		}
	}
	return false;
}
 
开发者ID:ArekkuusuJerii,项目名称:Solar,代码行数:18,代码来源:TileGravityHopper.java

示例3: innerUpdate

import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
protected void innerUpdate() {
    if (this.world.isRemote) return;
    if (++tick <= 4) return;
    for (EnumFacing facing : this.getSideConfig().getSidesForColor(EnumDyeColor.ORANGE)) {
        facing = this.orientFacing(facing).getOpposite();
        BlockPos side = this.pos.offset(facing);
        if (this.world.getTileEntity(side) != null && this.world.getTileEntity(side).hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())) {
            TileEntity tileEntity = this.world.getTileEntity(side);
            IItemHandler handler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
            for (int i = 0; i < handler.getSlots(); ++i) {
                if (!handler.getStackInSlot(i).isEmpty() && (handler.getStackInSlot(i).getCount() >= size || handler.getStackInSlot(i).getCount() >= handler.getStackInSlot(i).getMaxStackSize()))
                    continue;
                ItemStack handlerStack = handler.getStackInSlot(i);
                ItemStack posible = ItemStack.EMPTY;
                boolean hasWorked = false;
                for (int x = 0; x < input.getSlots(); ++x) {
                    if (!input.getStackInSlot(x).isEmpty() && (handlerStack.isEmpty() || input.getStackInSlot(x).isItemEqual(handlerStack))) {
                        posible = input.getStackInSlot(x);
                        if (!posible.isEmpty()) {
                            ItemStack def = posible.copy();
                            def.setCount(1);
                            def = handler.insertItem(i, def, false);
                            if (def.isEmpty()) posible.shrink(1);
                            else continue;
                            hasWorked = true;
                            break;
                        }
                    }
                }
                if (hasWorked) break;
            }
        }
    }
    tick = 0;
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:37,代码来源:ItemSplitterTile.java

示例4: fetchFromInventory

import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private void fetchFromInventory(BlockPos pos, Predicate<ItemStack> matcher, int maxAmount) {
    materialChest = pos;
    World world = entity.getEntityWorld();
    if (!InventoryTools.isInventory(world, pos)) {
        // No longer an inventory. We cannot get the items from here
        return;
    }
    TileEntity te = world.getTileEntity(pos);
    IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
    for (int i = 0; i < handler.getSlots(); i++) {
        if (maxAmount <= 0) {
            return;
        }
        ItemStack stack = handler.getStackInSlot(i);
        if (stack == null) {
            // There are still bad mods!
            String badBlock = world.getBlockState(pos).getBlock().getRegistryName().toString();
            MeeCreeps.logger.warn("Block " + badBlock + " is returning null for handler.getStackInSlot()! That's a bug!");
        } else if (!stack.isEmpty() && matcher.test(stack)) {
            ItemStack extracted = handler.extractItem(i, Math.min(maxAmount, stack.getCount()), false);
            ItemStack remaining = entity.addStack(extracted);
            maxAmount -= extracted.getCount() - remaining.getCount();
            if (!remaining.isEmpty()) {
                handler.insertItem(i, remaining, false);
            }
        }
    }
}
 
开发者ID:McJty,项目名称:MeeCreeps,代码行数:29,代码来源:WorkerHelper.java

示例5: onBlockActivated

import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer p, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    TileEntity te = worldIn.getTileEntity(pos);
    if (te != null && te instanceof TileAbstractSingleItem)
    {
        TileAbstractSingleItem tasi = (TileAbstractSingleItem) te;
        IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        ItemStack held = p.getHeldItem(hand);
        if (!p.isSneaking() && (tasi.isItemValid(held)))
        {
            ItemStack st = handler.insertItem(0, held, false);
            if(!ItemStack.areItemStacksEqualUsingNBTShareTag(st, held))
            {
                p.setHeldItem(hand, st);
                return true;
            }
        }
        if (p.isSneaking() && !handler.getStackInSlot(0).isEmpty())
        {
            p.inventory.addItemStackToInventory(handler.getStackInSlot(0));
            ItemStackUtils.extractAll(handler, 0);
            return true;
        }
        openClientGui(worldIn, pos, state, p, hand, facing, hitX, hitY, hitZ, tasi);
        return true;
    }
    return false;
}
 
开发者ID:PearXTeam,项目名称:PurificatiMagicae,代码行数:30,代码来源:BlockAbstractSingleItemHorizontal.java

示例6: setInventorySlotContents

import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void setInventorySlotContents(int index, ItemStack stack)
{
    IItemHandler itemHandler = getItemHandler();
    if(itemHandler != null)
    {
        itemHandler.extractItem(index, 64, false);
        itemHandler.insertItem(index, stack, false);
    }
}
 
开发者ID:Lumaceon,项目名称:CraftingParadiseMod,代码行数:11,代码来源:TileWorldMachine.java

示例7: onBlockActivated

import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
		EnumFacing facing, float hitX, float hitY, float hitZ)
{
	if (world.isRemote)
	{
		return true;
	}
	TileEntity te = world.getTileEntity(pos);
	if (!(te instanceof TileEntityWritingDesk))
	{
		return false;
	}

	ItemStack stack = player.getHeldItem(hand);

	int slot = 0;
	IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

	if (stack != null && !stack.isEmpty() && !player.isSneaking())
	{
		ItemStack insertStack = stack.copy();
		ItemStack remain = cap.insertItem(slot, insertStack, false);
		if (remain.getCount() != insertStack.getCount())
		{
			if (!world.isRemote)
			{
				player.setHeldItem(hand, remain);
				te.markDirty();
			} else
			{
				world.playSound(player, pos, SoundEvents.ENTITY_ITEMFRAME_ADD_ITEM, SoundCategory.BLOCKS, 1, 1);
			}
		}

	} else if (player.isSneaking())
	{
		ItemStack toExtract = cap.getStackInSlot(slot);
		if (toExtract != null && !toExtract.isEmpty())
		{
			if (!world.isRemote)
			{
				if (player.addItemStackToInventory(toExtract.copy()))
				{
					cap.getStackInSlot(slot).setCount(0);
					te.markDirty();
				}
			} else
			{
				world.playSound(player, pos, SoundEvents.ENTITY_ITEMFRAME_REMOVE_ITEM, SoundCategory.BLOCKS, 1, 1);
			}
		}
	}

	return true;
}
 
开发者ID:raphydaphy,项目名称:ArcaneMagic,代码行数:57,代码来源:BlockWritingDesk.java


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