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