本文整理汇总了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);
}
示例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;
}
示例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;
}
}
}
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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();
}
示例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));
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}