當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。