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


Java ItemStack.hasCapability方法代码示例

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


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

示例1: handleItemState

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
{
    if(stack.hasCapability(net.minecraftforge.common.model.animation.CapabilityAnimation.ANIMATION_CAPABILITY, null))
    {
        // TODO: caching?
        IAnimationStateMachine asm = stack.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
        if(world == null)
        {
            world = entity.worldObj;
        }
        if(world == null)
        {
            world = Minecraft.getMinecraft().theWorld;
        }
        IModelState state = asm.apply(Animation.getWorldTime(world, Animation.getPartialTickTime())).getLeft();
        return model.bake(new ModelStateComposition(state, this.state), format, bakedTextureGetter);
    }
    return super.handleItemState(originalModel, stack, world, entity);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:21,代码来源:AnimationItemOverrideList.java

示例2: getModifier

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static float getModifier(String effect, ItemStack stack, float initial, EntityLivingBase entity) {
	//long nanoTimeStart=System.nanoTime();
	if(!stack.hasCapability(TF2weapons.WEAPONS_DATA_CAP, null))
		return initial;
	float value = stack.getCapability(TF2weapons.WEAPONS_DATA_CAP, null).getAttributeValue(stack, effect, initial);
	/*if (!stack.isEmpty() && stack.getTagCompound() != null) {
		//NBTTagCompound attributeList = stack.getTagCompound().getCompoundTag("Attributes");
		value=addValue(value,stack.getTagCompound().getCompoundTag("Attributes"),effect);
		if(MapList.buildInAttributes.get(ItemFromData.getData(stack).getName()) != null)
			value=addValue(value,MapList.buildInAttributes.get(ItemFromData.getData(stack).getName()),effect);
	}*/
	if (entity != null && entity instanceof EntityTF2Character)
		value *= ((EntityTF2Character) entity).getAttributeModifier(effect);
	/*if(!Thread.currentThread().getName().equals("Client Thread"))
		TF2EventsCommon.tickTimeOther[TF2weapons.server.getTickCounter()%20]+=System.nanoTime()-nanoTimeStart;*/
	return value;
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:18,代码来源:TF2Attribute.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: 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

示例5: 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);
    if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
        IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
        tooltip.add(new TextComponentTranslation("text.industrialforegoing.tooltip.energy_field_right_charge").getUnformattedComponentText() + new DecimalFormat().format(storage.getEnergyStored()) + " / " + new DecimalFormat().format(storage.getMaxEnergyStored()));
        if (getLinkedBlockPos(stack) != null) {
            BlockPos pos = getLinkedBlockPos(stack);
            tooltip.add(new TextComponentTranslation("text.industrialforegoing.tooltip.energy_field_right_linked").getUnformattedComponentText() + " x=" + pos.getX() + " y=" + pos.getY() + " z=" + pos.getZ());
        } else {
            tooltip.add(new TextComponentTranslation("text.industrialforegoing.tooltip.energy_field_right_click").getUnformattedComponentText());
        }
    }
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:15,代码来源:EnergyFieldAddon.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: fillFromContainer

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean fillFromContainer(ItemStack container)
{
	if(!container.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) return false;
	IFluidHandler fluidHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
	IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
	int maxAmount = this.fluid != null ? this.capacity - this.fluid.amount : this.capacity;
	return FluidUtil.tryEmptyContainerAndStow(container, fluidHandler, itemHandler, maxAmount, null).isSuccess();
}
 
开发者ID:einsteinsci,项目名称:BetterBeginningsReborn,代码行数:9,代码来源:TankNetherBrickOvenFuel.java

示例11: isItemValid

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
@param stack Inputstack
@return If item can be charged
 */
public static boolean isItemValid(ItemStack stack) {

    return stack.hasCapability(CapabilityEnergy.ENERGY, null) ||
            (Main.teslaLoaded && TeslaCompat.hasTesla(stack)) ||
            (Main.redstonefluxLoaded && FluxCompat.hasFlux(stack)) ||
            (Main.immersiveLoaded && IECompat.hasIE(stack)) ||
            (Main.ic2Loaded && Config.allowIC2 && IC2Compat.hasIC2(stack));

}
 
开发者ID:CreeperShift,项目名称:WirelessCharger,代码行数:14,代码来源:EnergyHelper.java

示例12: getData

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static WeaponData getData(ItemStack stack) {
	WeaponData value = BLANK_DATA;
	if(!stack.isEmpty() && stack.hasCapability(TF2weapons.WEAPONS_DATA_CAP, null)) {
		value=stack.getCapability(TF2weapons.WEAPONS_DATA_CAP, null).inst;
		if (value == BLANK_DATA && stack.hasTagCompound() && MapList.nameToData.containsKey(stack.getTagCompound().getString("Type")))
			value = stack.getCapability(TF2weapons.WEAPONS_DATA_CAP, null).inst = MapList.nameToData.get(stack.getTagCompound().getString("Type"));
	}
	return value;	
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:10,代码来源:ItemFromData.java

示例13: handleRightClickFluidStorage

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static boolean handleRightClickFluidStorage(EntityPlayer player, EnumHand hand, IFluidHandler tank, int maxTransfer) {
	ItemStack fluidItem = player.getHeldItem(hand);
	if (fluidItem==null || fluidItem.isEmpty()) return false;
	if (!fluidItem.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
		return false;
	}
	
	FluidActionResult result = tryEmptyOrFillContainer(fluidItem, tank, maxTransfer, player);
	if (result.isSuccess()) {
		player.setHeldItem(hand, result.result);
		return true;
	} else {
		return false;
	}
}
 
开发者ID:elytra,项目名称:Thermionics,代码行数:16,代码来源:FluidTransport.java

示例14: isItemFuelContainer

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static boolean isItemFuelContainer(ItemStack stack)
{
	//STACKNULL
	if(stack == null) return false;
	return stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
}
 
开发者ID:einsteinsci,项目名称:BetterBeginningsReborn,代码行数:7,代码来源:TileEntityNetherBrickOven.java

示例15: isStackCurrentFluid

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean isStackCurrentFluid(Fluid fluid, ItemStack stack) {
    if (!stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) return false;
    IFluidHandlerItem fluidHandlerItem = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
    return fluidHandlerItem != null && fluidHandlerItem.drain(Integer.MAX_VALUE, false) != null && fluidHandlerItem.drain(Integer.MAX_VALUE, false).getFluid().equals(fluid);
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:6,代码来源:FluidCrafterTile.java


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