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


Java CapabilityItemHandler类代码示例

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


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

示例1: extract

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的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

示例2: getSearchedItemCount

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的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

示例3: breakBlock

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    TileEntity tile = worldIn.getTileEntity(pos);

    if (tile != null)
    {
        IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        if (itemHandler != null)
        {
            for (int i = 0; i < itemHandler.getSlots(); i++)
            {
                ItemStack stack = itemHandler.getStackInSlot(i);
                if (!stack.isEmpty())
                {
                    InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
                }
            }
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:24,代码来源:BlockMixin.java

示例4: getCapability

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Nullable
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
{
    if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
    {
        return (T) getItemHandlerCapability(facing);
    }

    for (TileEntityModule module : modules.values())
    {
        if (module.hasCapability(capability, facing))
            return module.getCapability(capability, facing);
    }

    return super.getCapability(capability, facing);
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:19,代码来源:TileEntitySimple.java

示例5: getCapability

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Nullable
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
    if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
        if (facing == null) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerMainInvHandler);
        switch (facing) {
            case UP:
                return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerArmorInvHandler);
            case DOWN:
                return super.getCapability(capability, facing);
            default:
                return dispenserUpgradeInserted ?
                        CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerFoodHandler) :
                        CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerMainInvHandler);
        }
    } else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && dispenserUpgradeInserted) {
        return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(playerExperienceHandler);
    } else if (capability == CapabilityEnergy.ENERGY) {
        return CapabilityEnergy.ENERGY.cast(energyRF);
    }
    return super.getCapability(capability, facing);
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:23,代码来源:TileEntityAerialInterface.java

示例6: update

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Override
public void update() {
    IItemHandler cap = this.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    if (cap == null) return;
    if (!world.isRemote) {
        timeSinceLastGrowth++;
        if (timeSinceLastGrowth >= TIME_BETWEEN_GROWTH) {
            ItemStack stack = cap.getStackInSlot(0);
            if (stack.getItem() == GeneraItems.ItemGlassJar &&
                    stack.getMetadata() == 1 &&
                    stack.getCount() == 1) {
                NBTTagCompound nbt = stack.getTagCompound();
                if (nbt != null) {
                    nbt.setFloat("size", nbt.getFloat("size") + 0.02F);
                    nbt.setDouble("max_health", nbt.getDouble("max_health") + 0.5D);
                    nbt.setInteger("current_exp", nbt.getInteger("current_exp") + 25);
                }
            }
            Genera.SIMPLEIMPL_INSTANCE.sendToAll(new MessageGlassJarUpdateStats(stack, getPos()));
            timeSinceLastGrowth = 0;
        }
    }
}
 
开发者ID:BenjaminSutter,项目名称:genera,代码行数:24,代码来源:TileFaerieHome.java

示例7: onMessage

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的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

示例8: getItemHandlerCapability

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Nullable
private IItemHandlerModifiable getItemHandlerCapability(@Nullable EnumFacing facing)
{
    Capability<IItemHandler> capability = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;

    List<IItemHandlerModifiable> handlers = Lists.newLinkedList();

    for (TileEntityModule module : modules.values())
    {
        if (module.hasCapability(capability, facing))
            handlers.add((IItemHandlerModifiable) module.getCapability(capability, facing));
    }

    if (handlers.size() == 1)
        return handlers.get(0);
    else if (handlers.size() > 1)
        return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[handlers.size()]));
    else
        return null;
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:21,代码来源:TileEntitySimple.java

示例9: readFromNBT

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Override
public void readFromNBT(NBTTagCompound tag) {
	super.readFromNBT(tag);
	
	if (tag.hasKey("inputtank")) {
		CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(inputTank, null, tag.getTag("inputtank"));
	}
	if (tag.hasKey("outputtank")) {
		CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(outputTank, null, tag.getTag("outputtank"));
	}
	if (tag.hasKey("heatstorage")) {
		Thermionics.CAPABILITY_HEATSTORAGE.readNBT(heat, null, tag.getTag("heatstorage"));
	}
	if (tag.hasKey("inventory")) {
		CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(itemStorage, null, tag.getTag("inventory"));
	}
	
	if (tag.hasKey("locked")) {
		tanksLocked = tag.getByte("locked")!=0;
	}
}
 
开发者ID:elytra,项目名称:Thermionics,代码行数:22,代码来源:TileEntityPotStill.java

示例10: getCapability

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
    if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){
        IItemHandler inventory = getInventory(facing);
        if(inventory != null){
            return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inventory);
        }
    }
    if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){
        IFluidHandler tank = getTank(facing);
        if(tank != null){
            return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank);
        }
    }
    if(capability == CapabilityEnergy.ENERGY){
        IEnergyStorage energy = getEnergy(facing);
        if(energy != null){
            return CapabilityEnergy.ENERGY.cast(energy);
        }
    }
    return null;
}
 
开发者ID:canitzp,项目名称:Metalworks,代码行数:24,代码来源:TileBase.java

示例11: deserializeNBT

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Override
public void deserializeNBT(NBTBase nbtIn) {
	if (nbtIn instanceof NBTTagCompound) {
		NBTTagCompound nbt = (NBTTagCompound) nbtIn;
		setSize(nbt.hasKey("Size", Constants.NBT.TAG_INT) ? nbt.getInteger("Size") : stacks.size());
		NBTTagList tagList = nbt.getTagList(getName(), Constants.NBT.TAG_COMPOUND);
		for (int i = 0; i < tagList.tagCount(); i++) {
			NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
			int slot = itemTags.getInteger("Slot");

			if (slot >= 0 && slot < stacks.size()) {
				stacks.set(slot, new ItemStack(itemTags));
				stacks.get(slot).setCount(itemTags.getInteger("RealCount"));
			}
		}
		CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(this, null, tagList);
		onLoad();
	}
}
 
开发者ID:p455w0rd,项目名称:DankNull,代码行数:20,代码来源:DankNullItemHandler.java

示例12: ContainerKiln

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
public ContainerKiln(EntityPlayer player, TileEntityKiln tileEntityKiln)
{
	super(tileEntityKiln);
	PlayerInvWrapper playerInv = (PlayerInvWrapper) player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
	addSlotToContainer(new SlotItemHandler(itemHandler, TileEntityKiln.SLOT_INPUT, 56, 17));
	addSlotToContainer(new SlotConfigurableAccess(itemHandler, TileEntityKiln.SLOT_FUEL, 56, 53));
	addSlotToContainer(new SlotOutput(itemHandler, TileEntityKiln.SLOT_OUTPUT, 116, 35));

	int i;
	for (i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 9; ++j)
		{
			addSlotToContainer(new SlotItemHandler(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

	for (i = 0; i < 9; ++i)
	{
		addSlotToContainer(new SlotItemHandler(playerInv, i, 8 + i * 18, 142));
	}
}
 
开发者ID:einsteinsci,项目名称:BetterBeginningsReborn,代码行数:23,代码来源:ContainerKiln.java

示例13: TileEntityOven

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
public TileEntityOven() {
	heatStorage = new HeatStorage(600);
	itemStorage = new ConcreteItemStorage(3)
			.withName("tile.thermionics.machine.oven.name")
			.withValidators(Validators.SMELTABLE, Validators.NOTHING, Validators.NOTHING)
			.setCanExtract(0, false)
			.setCanExtract(1, true)
			.setCanExtract(2, false);
	
	itemStorage.listen(this::markDirty);
	heatStorage.listen(this::markDirty);
	
	capabilities.registerForAllSides(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
			()->new ValidatedItemHandlerView(itemStorage), ()->itemStorage);
	capabilities.registerForAllSides(Thermionics.CAPABILITY_HEATSTORAGE,
			()->HeatStorageView.insertOnlyOf(heatStorage), ()->heatStorage);
}
 
开发者ID:elytra,项目名称:Thermionics,代码行数:18,代码来源:TileEntityOven.java

示例14: breakBlock

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
	TileEntityArcaneTransfigurationTable te = (TileEntityArcaneTransfigurationTable) world.getTileEntity(pos);
	IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

	for (int i = 0; i < cap.getSlots(); ++i)
	{
		ItemStack itemstack = cap.getStackInSlot(i);

		if (!itemstack.isEmpty())
		{
			InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
		}
	}

	super.breakBlock(world, pos, state);
}
 
开发者ID:raphydaphy,项目名称:ArcaneMagic,代码行数:19,代码来源:BlockArcaneTransfigurationTable.java

示例15: addSlotAmmo

import net.minecraftforge.items.CapabilityItemHandler; //导入依赖的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


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