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


Java IItemHandler类代码示例

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


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

示例1: getSearchedItemCount

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
private int getSearchedItemCount() {
        TileEntity te = world.getTileEntity(pos);
        if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
//        if (world.getTileEntity(pos) instanceof IInventory) {
            IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            int itemCount = 0;
//            IInventory inventory = (IInventory) world.getTileEntity(pos);
            ItemStack searchStack = ItemPneumaticArmor.getSearchedStack(FMLClientHandler.instance().getClient().player.getItemStackFromSlot(EntityEquipmentSlot.HEAD));
            if (searchStack.isEmpty()) return 0;
            for (int l = 0; l < handler.getSlots(); l++) {
                if (!handler.getStackInSlot(l).isEmpty()) {
                    itemCount += getSearchedItemCount(handler.getStackInSlot(l), searchStack);
                }
            }
            return itemCount;
        }
        return 0;
    }
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:19,代码来源:RenderSearchItemBlock.java

示例2: addInformation

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
@Override
public void addInformation(World world, BlockPos pos, TileEntity te, List<String> infoList) {
    try {
        IItemHandler inventory = IOHelper.getInventoryForTE(te);
        if (inventory != null) {
            boolean empty = true;
            ItemStack[] inventoryStacks = new ItemStack[inventory.getSlots()];
            for (int i = 0; i < inventory.getSlots(); i++) {
                ItemStack iStack = inventory.getStackInSlot(i);
                if (!iStack.isEmpty()) {
                    empty = false;
                }
                inventoryStacks[i] = iStack;
            }
            if (empty) {
                infoList.add("Contents: Empty");
            } else {
                infoList.add("Contents:");
                PneumaticCraftUtils.sortCombineItemStacksAndToString(infoList, inventoryStacks);
            }
        }
    } catch (Throwable e) {
        addTileEntityToBlackList(te, e);
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:26,代码来源:BlockTrackEntryInventory.java

示例3: dropItems

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
private void dropItems() {
	if(world.getTotalWorldTime() % 10 != 0) return;
	applyGravity(repulse, false);
	IItemHandler handler = from.getKey();
	ISidedInventory sidedInv = from.getValue();
	Vector3 spawn = Vector3.create(getPos()).add(0.5D).offset(getFacingLazy(), 1);
	for(int slot = 0; slot < handler.getSlots(); slot++) {
		ItemStack inSlot = handler.getStackInSlot(slot);
		if(!inSlot.isEmpty()
				&& (lookup.isEmpty() || ItemHandlerHelper.canItemStacksStack(lookup, inSlot))
				&& (sidedInv == null || sidedInv.canExtractItem(slot, inSlot, getFacingLazy()))) {
			ItemStack out = handler.extractItem(slot, Integer.MAX_VALUE, false);
			EntityTemporalItem entity = new EntityTemporalItem(world, spawn.x, spawn.y, spawn.z, out);
			impulseEntityItem(spawn, entity);
			world.spawnEntity(entity);
			break;
		}
	}
}
 
开发者ID:ArekkuusuJerii,项目名称:Solar,代码行数:20,代码来源:TileVacuumConveyor.java

示例4: addSlotAmmo

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
public void addSlotAmmo(){
	IItemHandler handler=nullInv;
	ammoBelt=false;
	if(!this.wearables.getStackInSlot(3).isEmpty()&&this.wearables.getStackInSlot(3).hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
		handler=this.wearables.getStackInSlot(3).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
		ammoBelt=true;
	}
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j){
			Slot slot=new SlotItemHandler( handler,
					j + i * 3, 98 + j * 18, 18 + i * 18) {

				@Override
				public boolean isItemValid(@Nullable ItemStack stack) {
					return this.getItemHandler()!=nullInv&&!stack.isEmpty() && stack.getItem() instanceof ItemAmmo && super.isItemValid(stack);
				}
			};
			this.inventorySlots.set(this.inventorySlots.size()-9+j + i * 3, slot);
			slot.slotNumber=this.inventorySlots.size()-9+j + i * 3;
		}
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:22,代码来源:ContainerWearables.java

示例5: renderIngredients

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
private void renderIngredients(TileEntityInfusionRepair te, double x, double y, double z, float partialTicks)
   {
GlStateManager.pushMatrix();
IItemHandler itemHandler = CapUtils.getItemHandler(te);
for(int slot = 0; slot < 8; slot++)
{
    ItemStack stack = itemHandler.getStackInSlot(TileEntityInfusionRepair.SLOT_ENCH_ITEM + 1 + slot);
    Vec2f ingredientPos = ingredientPositions[slot];
    if(Prep1_11.isEmpty(stack)) continue;
    
    GlStateManager.pushMatrix();
    GlStateManager.translate(ingredientPos.x * PIXEL_SIZE, -0.15F, ingredientPos.y * PIXEL_SIZE);
    GlStateManager.scale(0.5F, 0.5F, 0.5F);
    GlStateManager.rotate(((mc.player.ticksExisted + partialTicks) * 60.0f) / 10.0F, 0.0F, 1.0F, 0.0F);
    mc.getRenderItem().renderItem(stack, TransformType.GROUND);
    GlStateManager.scale(1.0F, 1.0F, 1.0F);
    GlStateManager.popMatrix();
}
GlStateManager.popMatrix();
   }
 
开发者ID:einsteinsci,项目名称:BetterBeginningsReborn,代码行数:21,代码来源:InfusionRender.java

示例6: getEvaluator

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
    return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {

        @Override
        protected boolean evaluate(BlockPos pos) {
            if (drone.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
                int count = 0;
                IItemHandler handler = drone.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
                for (int i = 0; i < handler.getSlots(); i++) {
                    ItemStack stack = handler.getStackInSlot(i);
                    if (widget.isItemValidForFilters(stack)) {
                        count += stack.getCount();
                    }
                }
                return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ?
                        count == ((ICondition) widget).getRequiredCount() :
                        count >= ((ICondition) widget).getRequiredCount();
            }

            return false;
        }

    };
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:26,代码来源:ProgWidgetItemInventoryCondition.java

示例7: breakBlock

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
       TileEntity tileentity = worldIn.getTileEntity(pos);
       
       if (tileentity!=null && tileentity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
       	IItemHandler inventory = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
       	for (int i=0; i<inventory.getSlots(); i++) {
               ItemStack itemstack = inventory.getStackInSlot(i);

               if (!itemstack.isEmpty()) {
                   InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), itemstack);
               }
           }
       	worldIn.updateComparatorOutputLevel(pos, this);
       }
       super.breakBlock(worldIn, pos, state);
   }
 
开发者ID:elytra,项目名称:Thermionics,代码行数:18,代码来源:BlockMachineBase.java

示例8: breakBlock

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
    if (!isAlteringLit)
    {
        TileEntity tileentity = world.getTileEntity(pos);

        if (tileentity instanceof TileEntityCampfire)
        {
            IItemHandler itemHandler = CapUtils.getItemHandler(tileentity);
            Util.dropInventory(world, pos, itemHandler);
            world.updateComparatorOutputLevel(pos, this);
        }
    }

    super.breakBlock(world, pos, state);
}
 
开发者ID:einsteinsci,项目名称:BetterBeginningsReborn,代码行数:18,代码来源:BlockCampfire.java

示例9: inventoryCanCarry

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
private boolean inventoryCanCarry() {
    insertingInventoryHasSpace = true;
    if (lastInsertingInventory == null)
        return true;
    if (inventory.getStackInSlot(CANNON_SLOT).isEmpty())
        return true;
    TileEntity te = getWorld().getTileEntity(lastInsertingInventory);
    IItemHandler inv = IOHelper.getInventoryForTE(te, lastInsertingInventorySide);
    if (inv != null) {
        ItemStack remainder = ItemHandlerHelper.insertItem(inv, inventory.getStackInSlot(CANNON_SLOT).copy(), true);
        insertingInventoryHasSpace = remainder.isEmpty();
        return insertingInventoryHasSpace;
    } else {
        lastInsertingInventory = null;
        lastInsertingInventorySide = null;
        return true;
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:19,代码来源:TileEntityAirCannon.java

示例10: validate

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
void validate() {
    if (isValid) return;

    Arrays.fill(upgradeCount, 0);
    customUpgradeCount = null;
    IItemHandler inv = te.getUpgradesInventory();
    for (int i = 0; i < inv.getSlots(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if (stack.getItem() instanceof ItemMachineUpgrade) {
            // native upgrade
            int idx = ((ItemMachineUpgrade) stack.getItem()).getUpgradeType().ordinal();
            upgradeCount[idx] += inv.getStackInSlot(i).getCount();
        } else if (!inv.getStackInSlot(i).isEmpty()) {
            // custom upgrade from another mod
            if (customUpgradeCount == null)
                customUpgradeCount = Maps.newHashMap();
            String key = makeUpgradeKey(stack);
            customUpgradeCount.put(key, customUpgradeCount.getOrDefault(key, 0) + stack.getCount());
        }
    }
    te.onUpgradesChanged();
    isValid = true;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:24,代码来源:TileEntityBase.java

示例11: transferOut

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
private ItemStack transferOut(BlockPos pos, boolean test) {
	EnumFacing facing = getFacing().getOpposite();
	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 in = handler.getStackInSlot(slot);
			if(!in.isEmpty() && (tile == null || tile.canExtractItem(slot, in, facing))) {
				return handler.extractItem(slot, Integer.MAX_VALUE, test);
			}
		}
	}
	return ItemStack.EMPTY;
}
 
开发者ID:ArekkuusuJerii,项目名称:Solar,代码行数:17,代码来源:TileGravityHopper.java

示例12: breakBlock

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
    if(!(world.getBlockState(pos).getBlock() instanceof BlockSpecializedFurnace))
    {
        TileEntity tileentity = world.getTileEntity(pos);

        if (tileentity instanceof TileEntitySpecializedFurnace)
        {
            IItemHandler itemHandler = CapUtils.getItemHandler(tileentity);
            Util.dropInventory(world, pos, itemHandler);
            world.updateComparatorOutputLevel(pos, this);
        }
    }

    super.breakBlock(world, pos, state);
}
 
开发者ID:einsteinsci,项目名称:BetterBeginningsReborn,代码行数:18,代码来源:BlockSpecializedFurnace.java

示例13: getCraftingResult

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
/**
 * Returns an Item that is the result of this recipe
 */
@Override
public ItemStack getCraftingResult(TileEntityOvenBase oven)
{
	ItemStack itemstack = getRecipeOutput().copy();
	IItemHandler itemHandler = CapUtils.getItemHandler(oven);
	
	if (strangeField)
	{
		for (int i = 0; i < itemHandler.getSlots(); ++i)
		{
			ItemStack itemstack1 = itemHandler.getStackInSlot(i);

			if (itemstack1 != null && itemstack1.hasTagCompound())
			{
				itemstack.setTagCompound((NBTTagCompound)itemstack1.getTagCompound().copy());
			}
		}
	}

	return itemstack;
}
 
开发者ID:einsteinsci,项目名称:BetterBeginningsReborn,代码行数:25,代码来源:BrickOvenShapedRecipe.java

示例14: collectItems

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
private void collectItems() {
	applyGravity(attract, true);
	IItemHandler handler = to.getKey();
	ISidedInventory sidedInv = to.getValue();
	getItemsFiltered(absorptionRange).forEach(e -> {
		e.setNoGravity(true);
		for(int slot = 0; slot < handler.getSlots(); slot++) {
			ItemStack inSlot = handler.getStackInSlot(slot);
			ItemStack in = e.getItem();
			if(sidedInv == null || sidedInv.canInsertItem(slot, in, getFacingLazy())) {
				if(inSlot.isEmpty() || (ItemHandlerHelper.canItemStacksStack(inSlot, in)
						&& (inSlot.getCount() < inSlot.getMaxStackSize()
						&& inSlot.getCount() < handler.getSlotLimit(slot)))) {
					ItemStack out = handler.insertItem(slot, in, false);
					if(out != in) {
						e.setItem(out);
						break;
					}
				}
			}
		}
	});
}
 
开发者ID:ArekkuusuJerii,项目名称:Solar,代码行数:24,代码来源:TileVacuumConveyor.java

示例15: readCapabilities

import net.minecraftforge.items.IItemHandler; //导入依赖的package包/类
protected void readCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side){
    IItemHandler inventory = this.getInventory(side);
    if(inventory != null && inventory instanceof IItemHandlerModifiable && nbt.hasKey("Inventory")){
        for(int i = 0; i < inventory.getSlots(); i++){ // clear the inventory, otherwise empty stacks doesn't get overriden while syncing. Forge Bug?
            ((IItemHandlerModifiable) inventory).setStackInSlot(i, ItemStack.EMPTY);
        }
        CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, side, nbt.getTag("Inventory"));
    }
    IFluidHandler tank = getTank(side);
    if(tank != null && tank instanceof IFluidTank && nbt.hasKey("FluidTank")){
        CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(tank, side, nbt.getCompoundTag("FluidTank"));
    }
    IEnergyStorage energy = getEnergy(side);
    if(energy != null && energy instanceof EnergyStorage && nbt.hasKey("Energy")){
        CapabilityEnergy.ENERGY.readNBT(energy, side, nbt.getTag("Energy"));
    }
}
 
开发者ID:canitzp,项目名称:Metalworks,代码行数:18,代码来源:TileBase.java


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