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


Java ItemStack.getCapability方法代码示例

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


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

示例1: chargeItem

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 *
 * @param stack Inputstack
 * @param energy Energy the item should receive
 * @param simulate If true will only simulate
 * @param tier IC2 charge tier
 * @param ignoreChargeLimit IC2 ignore charge limit
 * @return The amount of energy accepted
 */
public static int chargeItem(ItemStack stack, int energy, boolean simulate, int tier, boolean ignoreChargeLimit) {

    if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
        IEnergyStorage cap = stack.getCapability(CapabilityEnergy.ENERGY, null);
        return cap.receiveEnergy(energy, simulate);
    } else if (Main.teslaLoaded && TeslaCompat.hasTesla(stack)) {
        return TeslaCompat.chargeItem(stack, energy, simulate);
    } else if (Main.redstonefluxLoaded && FluxCompat.hasFlux(stack)) {
        return FluxCompat.chargeItem(stack, energy, simulate);
    } else if (Main.immersiveLoaded && IECompat.hasIE(stack)) {
        return IECompat.chargeItem(stack, energy, simulate);
    } else if (Main.ic2Loaded && Config.allowIC2 &&  IC2Compat.hasIC2(stack)) {
        return IC2Compat.chargeItem(stack, energy, simulate, tier, ignoreChargeLimit);
    }
    return 0;
}
 
开发者ID:CreeperShift,项目名称:WirelessCharger,代码行数:26,代码来源:EnergyHelper.java

示例2: getNewStack

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static ItemStack getNewStack(String type) {
	// "+MapList.weaponClasses.get(MapList.nameToCC.get(type).get("Class").getString())+"
	// "+Thread.currentThread().getName());
	if(!MapList.nameToData.containsKey(type))
		return ItemStack.EMPTY;
	ItemStack stack = new ItemStack(
			MapList.weaponClasses.get(MapList.nameToData.get(type).getString(PropertyType.CLASS)));
	//System.out.println(stack.hasCapability(TF2weapons.WEAPONS_DATA_CAP, null));
	stack.getCapability(TF2weapons.WEAPONS_DATA_CAP, null).inst=MapList.nameToData.get(type);
	NBTTagCompound tag=new NBTTagCompound();
	tag.setString("Type", type);
	tag.setTag("Attributes", new NBTTagCompound());
	stack.setTagCompound(tag);
	// System.out.println(stack.toString());
	return stack;
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:17,代码来源:ItemFromData.java

示例3: chargeInv

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void chargeInv(IItemHandler inv) {
    for (int i = 0; i < inv.getSlots(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
            IEnergyStorage receivingStorage = stack.getCapability(CapabilityEnergy.ENERGY, null);
            int energyLeft = energyRF.getEnergyStored();
            if (energyLeft > 0) {
                energyRF.extractEnergy(receivingStorage.receiveEnergy(Math.max(energyLeft, RF_PER_TICK), false), false);
            } else {
                break;
            }
        }
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:15,代码来源:TileEntityAerialInterface.java

示例4: getFilled

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public ItemStack getFilled(CaskLiquid liquid)
{
    ItemStack filled = new ItemStack(this);
    IFluidHandlerItem tank = filled.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY,null);
    if(tank != null)
        tank.fill(new FluidStack(liquid.fluid,capacity),true);
    return filled;
}
 
开发者ID:DaedalusGame,项目名称:Soot,代码行数:9,代码来源:ItemMug.java

示例5: getRecipeFluid

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public Fluid getRecipeFluid() {
    if (tank.getFluid() != null) {
        return tank.getFluid().getFluid();
    }
    for (ItemStack stack : crafting.getFilter()) {
        if (stack.isEmpty()) continue;
        if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
            IFluidHandlerItem fluidHandlerItem = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
            return fluidHandlerItem.drain(Integer.MAX_VALUE, false).getFluid();
        }
    }
    return null;
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:14,代码来源:FluidCrafterTile.java

示例6: getFluidHandler

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Helper method to get an IFluidHandler for an itemStack.
 *
 * The itemStack passed in here WILL be modified, the IFluidHandler acts on it directly.
 *
 * Note that the itemStack MUST have a stackSize of 1 if you want to fill or drain it.
 * You can't fill or drain a whole stack at once, if you do then liquid is multiplied or destroyed.
 *
 * Vanilla buckets will be converted to universal buckets if they are enabled.
 *
 * Returns null if the itemStack passed in does not have a fluid handler.
 */
@Nullable
public static IFluidHandler getFluidHandler(ItemStack itemStack)
{
    if (itemStack == null)
    {
        return null;
    }

    // check for capability
    if (itemStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null))
    {
        return itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
    }

    // legacy container handling
    Item item = itemStack.getItem();
    if (item instanceof IFluidContainerItem)
    {
        return new FluidContainerItemWrapper((IFluidContainerItem) item, itemStack);
    }
    else if (FluidContainerRegistry.isContainer(itemStack))
    {
        return new FluidContainerRegistryWrapper(itemStack);
    }
    else
    {
        return null;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:42,代码来源:FluidUtil.java

示例7: hasOnlyOneFluid

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean hasOnlyOneFluid() {
    Fluid tankFluid = tank.getFluid() != null ? tank.getFluid().getFluid() : null;
    List<Fluid> fluids = new ArrayList<>();
    for (ItemStack stack : crafting.getFilter()) {
        if (stack.isEmpty()) continue;
        if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
            IFluidHandlerItem fluidHandlerItem = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
            FluidStack fluid = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
            if (fluid != null && !fluids.contains(fluid.getFluid())) fluids.add(fluid.getFluid());
        }
    }
    if (tankFluid != null) fluids.remove(tankFluid);
    return fluids.size() <= 1;
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:15,代码来源:FluidCrafterTile.java

示例8: onItemUse

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
	if (worldIn.isRemote)
	{
		return EnumActionResult.FAIL;
	}

	TileEntity tile = worldIn.getTileEntity(pos);
	if (tile != null && tile.hasCapability(ExPFarmlandCapability.farmlandCap, EnumFacing.UP))
	{
		if (worldIn.isAirBlock(pos.up()))
		{
			// FIXME fix packet pipeline render issues!
			try
			{
				ItemStack held = player.getHeldItem(hand);
				CapabilityExPSeeds seedsCap = (CapabilityExPSeeds) held.getCapability(ExPSeedsCapability.seedsCap, null);
				CropStats stats = new CropStats(seedsCap.getOrCreateStats());
				worldIn.setBlockState(pos.up(), ExPBlocks.crop.getDefaultState());
				TileCrop cropTile = (TileCrop) worldIn.getTileEntity(pos.up());
				ExPCrop cropCap = (ExPCrop) IExPCrop.of(cropTile);
				cropCap.stats = stats;
				cropCap.timeKeeper = new Calendar(IExPWorld.of(worldIn).today().getTime());
				NBTTagCompound sent = new NBTTagCompound();
				sent.setTag("tileData", cropTile.serializeNBT());
				sent.setTag("blockPosData", new DimBlockPos(pos.up(), worldIn.provider.getDimension()).serializeNBT());
				VoidNetwork.sendDataToAllAround(PacketType.TileData, sent, new TargetPoint(worldIn.provider.getDimension(), pos.getX(), pos.up().getY(), pos.getZ(), 96));
				held.shrink(1);
				return EnumActionResult.SUCCESS;
			}
			catch (Exception ex)
			{
				ExPMisc.modLogger.log(LogLevel.Error, "Unable to place seeds at %s!", ex, pos.toString());
			}
		}
	}
	
	return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
 
开发者ID:V0idWa1k3r,项目名称:ExPetrum,代码行数:41,代码来源:ItemSeeds.java

示例9: getDurabilityForDisplay

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public double getDurabilityForDisplay(ItemStack stack) {
    if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
        IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
        if (storage != null)
            return (storage.getMaxEnergyStored() - storage.getEnergyStored()) / (double) storage.getMaxEnergyStored();
    }
    return 0;
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:10,代码来源:EnergyFieldAddon.java

示例10: onBlockActivated

import net.minecraft.item.ItemStack; //导入方法依赖的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;
	TileEntityBarrel barrel = (TileEntityBarrel) world.getTileEntity(pos);
	world.notifyBlockUpdate(pos, state, state, 3);
	ItemStack stack = player.getHeldItem(hand);
	if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
		IFluidHandlerItem itemHandler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
		IFluidHandler barrelHandler = barrel.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
		FluidStack fluidInItem = itemHandler.drain(Fluid.BUCKET_VOLUME, false);
		FluidStack fluidInBarrel = barrelHandler.drain(Fluid.BUCKET_VOLUME, false);
		if ((fluidInBarrel != null && fluidInBarrel.amount > 0) && (fluidInItem == null || fluidInItem.amount == 0 || (fluidInItem.isFluidEqual(fluidInBarrel) && fluidInItem.amount < Fluid.BUCKET_VOLUME))) {
			itemHandler.fill(barrelHandler.drain(Fluid.BUCKET_VOLUME, true), true);
			player.setHeldItem(hand, itemHandler.getContainer());
		} else if (fluidInItem != null && fluidInItem.amount > 0 && fluidInItem.getFluid() != null && (fluidInBarrel == null || fluidInBarrel.amount == 0 || (fluidInBarrel.amount < Fluid.BUCKET_VOLUME && fluidInBarrel.isFluidEqual(fluidInItem)))) {
			FluidStack fsin = itemHandler.drain(Fluid.BUCKET_VOLUME, true);
			if (fsin != null && fsin.amount > 0 && fsin.getFluid() != null) {
				barrelHandler.fill(fsin, true);
				player.setHeldItem(hand, itemHandler.getContainer());
				player.inventory.markDirty();
			}
		}
		return true;
	}

	player.openGui(Bewitchment.instance, LibGui.BARREL.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
	return true;
}
 
开发者ID:Um-Mitternacht,项目名称:Bewitchment,代码行数:29,代码来源:BlockBarrel.java

示例11: addInformation

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
    IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null);
    if(energy != null){
        tooltip.add(Util.formatEnergy(energy));
    }
}
 
开发者ID:canitzp,项目名称:Metalworks,代码行数:8,代码来源:ItemBattery.java

示例12: getItemEnergy

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private IEnergyStorage getItemEnergy(){
    ItemStack stack = this.inv.getStackInSlot(0);
    if(!stack.isEmpty() && stack.hasCapability(CapabilityEnergy.ENERGY, null)){
        return stack.getCapability(CapabilityEnergy.ENERGY, null);
    }
    return null;
}
 
开发者ID:canitzp,项目名称:Metalworks,代码行数:8,代码来源:TileSuperCharger.java

示例13: onUpdate

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void onUpdate(ItemStack stack, World par2World, Entity par3Entity, int par4, boolean par5) {
	super.onUpdate(stack, par2World, par3Entity, par4, par5);
	if(stack.isEmpty())
		return;
	/*
	 * if(itemProperties.get(par2World.isRemote).get(par3Entity)==null){
	 * itemProperties.get(par2World.isRemote).put((EntityLivingBase)
	 * par3Entity, new NBTTagCompound()); }
	 */
	WeaponsCapability cap = par3Entity.getCapability(TF2weapons.WEAPONS_CAP, null);
	WeaponData.WeaponDataCapability stackcap = stack.getCapability(TF2weapons.WEAPONS_DATA_CAP, null);
	EntityLivingBase living=(EntityLivingBase) par3Entity;
	if (stackcap.active == 0 && par5) {
		stackcap.active = 1;
		// itemProperties.get(par2World.isRemote).get(par3Entity).setShort("reloadd",
		// (short) 800);

		if(!par2World.isRemote && living.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).getModifier(ItemWeapon.HEALTH_MODIFIER)!=null){
			float addHealth=(float) living.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).getModifier(ItemWeapon.HEALTH_MODIFIER).getAmount();
			living.setHealth((living.getMaxHealth())/(living.getMaxHealth()-addHealth)*living.getHealth());
		}
		cap.fire1Cool = this.getDeployTime(stack, living);
		cap.fire2Cool = this.getDeployTime(stack, living);
	} else if (stackcap.active > 0
			&& stack != living.getHeldItemOffhand() && !par5) {
		if (stackcap.active == 2 && (cap.state & 3) > 0)
			this.endUse(stack, living, par2World, cap.state, 0);
		
		stackcap.active = 0;
		this.holster(cap, stack, living, par2World);

	}
	if (par3Entity.ticksExisted % 5 == 0 && stackcap.active == 2
			&& TF2Attribute.getModifier("Mark Death", stack, 0, living) > 0)
		living.addPotionEffect(new PotionEffect(TF2weapons.markDeath,
				(int) TF2Attribute.getModifier("Mark Death", stack, 0,living) * 20));
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:39,代码来源:ItemUsable.java

示例14: canAltFire

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean canAltFire(World worldObj, EntityLivingBase player, ItemStack item) {
	// TODO Auto-generated method stub
	return item.getCapability(TF2weapons.WEAPONS_DATA_CAP, null).active > 0
			&& player.getCapability(TF2weapons.WEAPONS_CAP, null).invisTicks == 0
			&& (player.getActiveItemStack().isEmpty() || this.getDoubleWieldBonus(item, player) != 1);
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:7,代码来源:ItemUsable.java

示例15: addInformation

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    super.addInformation(stack, worldIn, tooltip, flagIn);
    FluidHandlerItemStack handlerItemStack = (FluidHandlerItemStack) stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.DOWN);
    tooltip.add(getFilledAmount(stack) + "/" + handlerItemStack.getTankProperties()[0].getCapacity() + "mb of Meat");
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:7,代码来源:MeatFeederItem.java


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