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


Java IItemHandlerModifiable.getStackInSlot方法代码示例

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


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

示例1: removeInputsFromInventory

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static void removeInputsFromInventory(List<RecipeInput> inputs, IItemHandlerModifiable inv, int start, int numSlots)
{
    List<RecipeInput> remaining = Lists.newLinkedList(inputs);

    for (int i = start; i < start + numSlots; i++)
    {
        ItemStack stack = inv.getStackInSlot(i);
        for (Iterator<RecipeInput> iterator = remaining.iterator(); iterator.hasNext(); )
        {
            RecipeInput input = iterator.next();
            if (stackMatchesRecipeInput(stack, input, true))
            {
                extractInput(input, inv, i);

                iterator.remove();
                break;
            }
        }
    }
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:21,代码来源:ItemHelper.java

示例2: extract

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static ItemStack extract(TileEntity tile, EnumFacing from, boolean fullStack) {

		if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from)) {
			IItemHandlerModifiable handler = (IItemHandlerModifiable) tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from);
			if (handler != null) {
				int invSize = handler.getSlots();

				for (int i = 0; i < invSize; i++) {
					ItemStack current = handler.getStackInSlot(i);

					if (current != null && !current.isEmpty() && current.getItem() != Items.AIR) {
						ItemStack stack = handler.extractItem(i, !fullStack ? 1 : current.getCount(), false);
						return stack;
					}
				}
			}
		} // TODO: TileEntities that don't have capabilities - needs testing

		return null;
	}
 
开发者ID:oMilkyy,项目名称:SimpleTubes,代码行数:21,代码来源:TubeUtil.java

示例3: getStackInSlot

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
@Override
public ItemStack getStackInSlot(int slot)
{
    int index = getIndexForSlot(slot);
    IItemHandlerModifiable handler = getHandlerFromIndex(index);
    slot = getSlotFromIndex(slot, index);
    return handler.getStackInSlot(slot);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:9,代码来源:CombinedInvWrapper.java

示例4: findItemsIndexedInInventoryFuel

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static Map<Integer, ItemStack> findItemsIndexedInInventoryFuel(IItemHandlerModifiable handler, @Nullable NBTTagCompound matchNBTTag) {
    Map<Integer, ItemStack> stacksOut = new HashMap<>();
    for (int j = 0; j < handler.getSlots(); j++) {
        ItemStack s = handler.getStackInSlot(j);
        if (TileEntityFurnace.getItemBurnTime(s) > 0 && NBTMatchingHelper.matchNBTCompound(matchNBTTag, s.getTagCompound())) {
            stacksOut.put(j, s.copy());
        }
    }
    return stacksOut;
}
 
开发者ID:HellFirePvP,项目名称:ModularMachinery,代码行数:11,代码来源:ItemUtils.java

示例5: findItemsIndexedInInventoryOreDict

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static Map<Integer, ItemStack> findItemsIndexedInInventoryOreDict(IItemHandlerModifiable handler, String oreDict, @Nullable NBTTagCompound matchNBTTag) {
    Map<Integer, ItemStack> stacksOut = new HashMap<>();
    for (int j = 0; j < handler.getSlots(); j++) {
        ItemStack s = handler.getStackInSlot(j);
        if(s.isEmpty()) continue;
        int[] ids = OreDictionary.getOreIDs(s);
        for (int id : ids) {
            if(OreDictionary.getOreName(id).equals(oreDict) && NBTMatchingHelper.matchNBTCompound(matchNBTTag, s.getTagCompound())) {
                stacksOut.put(j, s.copy());
            }
        }
    }
    return stacksOut;
}
 
开发者ID:HellFirePvP,项目名称:ModularMachinery,代码行数:15,代码来源:ItemUtils.java

示例6: findItemsIndexedInInventory

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static Map<Integer, ItemStack> findItemsIndexedInInventory(IItemHandlerModifiable handler, ItemStack match, boolean strict, @Nullable NBTTagCompound matchNBTTag) {
    Map<Integer, ItemStack> stacksOut = new HashMap<>();
    for (int j = 0; j < handler.getSlots(); j++) {
        ItemStack s = handler.getStackInSlot(j);
        if ((strict ? matchStacks(s, match) : matchStackLoosely(s, match)) && NBTMatchingHelper.matchNBTCompound(matchNBTTag, s.getTagCompound())) {
            stacksOut.put(j, s.copy());
        }
    }
    return stacksOut;
}
 
开发者ID:HellFirePvP,项目名称:ModularMachinery,代码行数:11,代码来源:ItemUtils.java

示例7: breakBlock

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { // Drop item when block breaks
    TileEntity t = worldIn.getTileEntity(pos);
    if(!(t instanceof IItemHandlerModifiable)) return;
    IItemHandlerModifiable h = (IItemHandlerModifiable) t;
    for(int i = 0; i<h.getSlots(); ++i) {
        if(h.getStackInSlot(i)!=null && h.getStackInSlot(i).stackSize>0)
            InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), h.getStackInSlot(i));
    }
    super.breakBlock(worldIn, pos, state);
}
 
开发者ID:tjkenmate,项目名称:TeslaEssentials,代码行数:12,代码来源:BlockGrinder.java

示例8: sortInventoryWithinRange

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static void sortInventoryWithinRange(IItemHandlerModifiable inv, SlotRange range)
{
    List<ItemTypeByName> blocks = new ArrayList<ItemTypeByName>();
    List<ItemTypeByName> items = new ArrayList<ItemTypeByName>();
    final int lastSlot = Math.min(range.lastInc, inv.getSlots() - 1);

    // Get the different items that are present in the inventory
    for (int i = range.first; i <= lastSlot; i++)
    {
        ItemStack stack = inv.getStackInSlot(i);

        if (stack.isEmpty() == false)
        {
            ItemTypeByName type = new ItemTypeByName(stack);

            if (stack.getItem() instanceof ItemBlock)
            {
                if (blocks.contains(type) == false)
                {
                    blocks.add(type);
                }
            }
            else if (items.contains(type) == false)
            {
                items.add(type);
            }
        }
    }

    Collections.sort(blocks);
    Collections.sort(items);

    int slots = sortInventoryWithinRangeByTypes(inv, blocks, range);
    sortInventoryWithinRangeByTypes(inv, items, new SlotRange(range.first + slots, range.lastExc - (range.first + slots)));
}
 
开发者ID:maruohon,项目名称:enderutilities,代码行数:36,代码来源:InventoryUtils.java

示例9: handleHorseSpecialSlots

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
/**
 * Handles special slots of the horse inventory (Slot 0: Saddle, Slot 1: Armor) and
 * a special slot 99 which must be a chest (sets whether the horse is chested or not)
 * 
 * @param slot the special horse slot (0, 1 or 99)
 * @param horse the horse
 * @param stack the item stack (must be saddle for slot 0, any horse armor for slot 1 and chest for slot 99)
 * @param tag the new nbt tag of the special slot (works only for 0 and 1, e.g. to enchant the armor)
 * @param mergeLists See the "mergeLists" parameter of {@link #nbtMerge(NBTTagCompound, NBTTagCompound, boolean)}
 * @return whether the given data was valid (valid slot, valid item, etc.) and whether the special slots could successfully be handled
 * @throws Exeption if reflective access failed
 */
private static boolean handleHorseSpecialSlots(AbstractHorse horse, int slot, ItemStack stack, NBTTagCompound tag, boolean mergeLists) throws Exception {
	IItemHandler h = horse.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
	IItemHandlerModifiable inventory = h instanceof IItemHandlerModifiable ? (IItemHandlerModifiable) h : null;
	if (initChest == null || updateSlots == null || inventory == null) return false;
	
	if (tag != null) {
		if (slot < inventory.getSlots()) return false;
		
		if (inventory.getStackInSlot(slot) != ItemStack.EMPTY) {
			stack = inventory.getStackInSlot(slot).copy();
			nbtMerge(stack.getTagCompound(), tag, mergeLists);
			inventory.setStackInSlot(slot, stack);
			updateSlots.invoke(horse);
		}
		
		return true;
	}
	
	if (slot == 99 && horse instanceof AbstractChestHorse) {
		if (stack == ItemStack.EMPTY || ((AbstractChestHorse) horse).hasChest()) {
			((AbstractChestHorse) horse).setChested(false);
			initChest.invoke(horse);
			return true;
		}
		
		if (stack != ItemStack.EMPTY && stack.getItem() == Item.getItemFromBlock(Blocks.CHEST) && !(horse instanceof AbstractChestHorse)) {
			((AbstractChestHorse) horse).setChested(true);
			initChest.invoke(horse);
			return true;
		}
		
		return false;
	}
	else if (slot >= 0 && slot < 2 && slot < inventory.getSlots()) {
		if (slot == 0 && stack != ItemStack.EMPTY && stack.getItem() != Items.SADDLE) return false;
		else if (slot != 1 || (stack == ItemStack.EMPTY || horse.isArmor(stack)) && horse.wearsArmor()) {
			inventory.setStackInSlot(slot, stack == ItemStack.EMPTY ? ItemStack.EMPTY : stack.copy());
			updateSlots.invoke(horse);
			return true;
		}
		else return false;
	}
	else return false;
}
 
开发者ID:MrNobody98,项目名称:morecommands,代码行数:57,代码来源:TargetSelector.java

示例10: isSlotMatching

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
/**
 * Compares a given ItemStack with the one at a slot of an inventory of an entity
 * 
 * @param entity the entity
 * @param slot the inventory slot to replace corresponding to a slot shortcut (see {@link #getSlotForShortcut(String)}
 * @param stack the item stack to compare (the item and the nbt tag can be null if they shouldn't be compared).
 * @param noMeta whether to compare metadata
 * @param equalLists The opposite of the "listContains" parameter of {@link #nbtContains(NBTBase, NBTBase, boolean)}
 * @return whether the two ItemStacks are equal
 */
public static boolean isSlotMatching(Entity entity, int slot, ItemStack stack, boolean noMeta, boolean equalLists) {
	if (entity instanceof IInventory) return isSlotMatching((IInventory) entity, slot, stack, noMeta, equalLists);
	ItemStack stackInSlot;
	
	if (slot >= 400 && slot < 500 && entity instanceof EntityHorse)
		slot -= 300;
	
	if (slot >= 0 && slot < 100 && entity instanceof EntityLivingBase) {
		if (slot >= EntityEquipmentSlot.values().length) return false;
		stackInSlot = ((EntityLivingBase) entity).getItemStackFromSlot(EntityEquipmentSlot.values()[slot]);
	}
	else if (slot >= 100 && slot < 200) {
		slot -= 100;
		IItemHandler h = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
		if (!(h instanceof IItemHandlerModifiable)) return false;
		
		IItemHandlerModifiable inventory = (IItemHandlerModifiable) h;
		if (slot >= inventory.getSlots()) return false;
		else stackInSlot = inventory.getStackInSlot(slot);
	}
	else if (slot >= 200 && slot < 300 && entity instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) entity;
		slot -= 200;
		
		if (slot >= player.getInventoryEnderChest().getSizeInventory()) return false;
		else stackInSlot = player.getInventoryEnderChest().getStackInSlot(slot);
	}
	else if (slot >= 300 && slot < 400 && entity instanceof EntityVillager) {
		EntityVillager villager = (EntityVillager) entity;
		slot -= 300;
		
		if (slot >= villager.getVillagerInventory().getSizeInventory()) return false;
		else stackInSlot = villager.getVillagerInventory().getStackInSlot(slot);
	}
	else return false;
	
	if (stack == ItemStack.EMPTY || stackInSlot == ItemStack.EMPTY) return stackInSlot == ItemStack.EMPTY && stack == ItemStack.EMPTY;
	else {
		boolean matches = stack.getItem() == null || stack.getItem() == stackInSlot.getItem();
		matches = matches && (noMeta || stack.getItemDamage() == stackInSlot.getItemDamage());
		matches = matches && (stack.isEmpty() || stack.getCount() == stackInSlot.getCount());
		matches = matches && nbtContains(stackInSlot.getTagCompound(), stack.getTagCompound(), !equalLists);
		return matches;
	}
}
 
开发者ID:MrNobody98,项目名称:morecommands,代码行数:56,代码来源:TargetSelector.java

示例11: sortInventoryWithinRangeByTypes

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
private static int sortInventoryWithinRangeByTypes(IItemHandlerModifiable inv, List<ItemTypeByName> types, SlotRange range)
{
    int slot = range.first;
    int slots = 0;

    for (ItemTypeByName type : types)
    {
        ItemStack stack = type.getStack();

        while (true)
        {
            int max = inv instanceof IItemHandlerSize ? ((IItemHandlerSize) inv).getItemStackLimit(slot, stack) : inv.getSlotLimit(slot);
            //System.out.printf("sorting for: %s - slot: %d, max: %d\n", stack.toString(), slot, max);

            if (slot >= range.lastInc)
            {
                //System.out.printf("slot >= range.lastInc\n");
                return slots;
            }

            SlotRange rangeTmp = new SlotRange(slot, range.lastExc - slot);
            stack = collectItemsFromInventoryFromSlotRange(inv, stack, rangeTmp, max, false, false);
            //System.out.printf("collected stack: %s from range: %s\n", stack, rangeTmp.toString());

            if (stack.isEmpty())
            {
                break;
            }

            ItemStack stackTmp = inv.getStackInSlot(slot);

            // There is a stack in the slot that we are moving items to, try to move the stack towards the end of the inventory
            if (stackTmp.isEmpty() == false)
            {
                //System.out.printf("existing stack: %s\n", inv.getStackInSlot(slot).toString());
                rangeTmp = new SlotRange(slot + 1, range.lastExc - (slot + 1));
                stackTmp = tryInsertItemStackToInventoryWithinSlotRange(inv, stackTmp, rangeTmp);
                //System.out.printf("tried moving stack to range: %s - remaining: %s\n", rangeTmp.toString(), stackTmp);

                // Failed to move the stack - this shouldn't happen, we are in trouble now!
                if (stackTmp.isEmpty() == false)
                {
                    //System.out.printf("failed moving existing stack, panic mode!\n");
                    // Try to return all the items currently being worked on and then bail out
                    tryInsertItemStackToInventoryWithinSlotRange(inv, stackTmp, range);
                    tryInsertItemStackToInventoryWithinSlotRange(inv, stack, range);
                    return slots;
                }
            }

            //System.out.printf("setting stack: %s to slot: %d - slots: %d\n", stack, slot, slots + 1);
            // Put the stack (collected starting from this slot towards the end of the inventory) into this slot
            inv.setStackInSlot(slot, stack);

            /*if (inv instanceof IItemHandlerModifiable)
            {
                ((IItemHandlerModifiable)inv).setStackInSlot(slot, stack);
            }
            else
            {
                tryToEmptySlot(inv, slots, 128);
                inv.insertItem(slot, stack, false);
            }*/

            slot++;
            slots++;
        }
    }

    return slots;
}
 
开发者ID:maruohon,项目名称:enderutilities,代码行数:72,代码来源:InventoryUtils.java

示例12: onUpdate

import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean held)
{
    if (world.isRemote || world.getTotalWorldTime() % UPDATE_INTERVAL != 0)
        return;

    IItemHandler handler = entity.getCapability(ITEM_HANDLER_CAPABILITY, null);
    if (!(handler instanceof IItemHandlerModifiable))
        return;

    if (entity instanceof EntityPlayer && ((EntityPlayer)entity).capabilities.isCreativeMode)
        return;

    IItemHandlerModifiable inventory = (IItemHandlerModifiable)handler;

    if (stack.getMetadata() == LIT_METADATA && entity.isWet())
    {
        for (int i = 0; i < inventory.getSlots(); i++)
        {
            stack = inventory.getStackInSlot(i);
            if (stack != null && stack.getItem() == this && stack.stackSize != 0)
            {
                stack = stack.copy();
                stack.setItemDamage(UNLIT_METADATA);
                inventory.setStackInSlot(i, stack);
            }
        }
        playDousingSound(entity.worldObj, entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
    }
    else if (stack.getMetadata() == UNLIT_METADATA && entity.isBurning())
    {
        for (int i = 0; i < inventory.getSlots(); i++)
        {
            stack = inventory.getStackInSlot(i);
            if (stack != null && stack.getItem() == this && stack.stackSize != 0)
            {
                stack = stack.copy();
                stack.setItemDamage(LIT_METADATA);
                inventory.setStackInSlot(i, stack);
            }
        }
        playIgnitingSound(entity.worldObj, entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
    }
}
 
开发者ID:pelepmc,项目名称:Unlit-Torch,代码行数:45,代码来源:TorchItem.java


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