net.minecraft.item.ItemStack.getTagCompound()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(224)

本文整理了Java中net.minecraft.item.ItemStack.getTagCompound()方法的一些代码示例,展示了ItemStack.getTagCompound()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.getTagCompound()方法的具体详情如下:
包路径:net.minecraft.item.ItemStack
类名称:ItemStack
方法名:getTagCompound

ItemStack.getTagCompound介绍

暂无

代码示例

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
public int hashCode()
{
  return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

/**
 * Compares two {@link ItemStack} and their NBT tag for equality.
 *
 * Use this when a precise check is required and the same item is required.
 * Not just something with different NBT tags.
 *
 * @return true, if both are identical.
 */
public boolean isSameItem( @Nonnull final ItemStack is, @Nonnull final ItemStack filter )
{
  return ItemStack.areItemsEqual( is, filter ) && this.isNbtTagEqual( is.getTagCompound(), filter.getTagCompound() );
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
  if(stack.getTagCompound() != null && stack.getTagCompound().hasKey(TAG_ITEMS)) {
    NBTTagList oldData = stack.getTagCompound().getTagList(TAG_ITEMS, Constants.NBT.TAG_COMPOUND);
    IItemHandler newInv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(newInv, null, oldData);
    stack.getTagCompound().removeTag(TAG_ITEMS);
    if(stack.getTagCompound().getSize() == 0)
      stack.setTagCompound(null);
  }
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
  if(stack.getTagCompound() != null && stack.getTagCompound().hasKey(TAG_ITEMS)) {
    NBTTagList oldData = stack.getTagCompound().getTagList(TAG_ITEMS, Constants.NBT.TAG_COMPOUND);
    IItemHandler newInv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(newInv, null, oldData);
    stack.getTagCompound().removeTag(TAG_ITEMS);
    if(stack.getTagCompound().getSize() == 0)
      stack.setTagCompound(null);
  }
}

代码示例来源:origin: Vazkii/Botania

public static NBTTagCompound getSpawnerTag(ItemStack stack) {
  NBTTagCompound tag = stack.getTagCompound();
  if(tag != null && tag.hasKey(TAG_SPAWNER)) {
    return tag.getCompoundTag(TAG_SPAWNER);
  }
  return null;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public FluidStack getFluidStack( ItemStack is )
{
  if( is.hasTagCompound() )
  {
    NBTTagCompound tag = is.getTagCompound();
    return FluidStack.loadFluidStackFromNBT( tag );
  }
  return null;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
public int getStoredDimensionID( final ItemStack is )
{
  if( is.hasTagCompound() )
  {
    final NBTTagCompound c = is.getTagCompound();
    return c.getInteger( NBT_CELL_ID_KEY );
  }
  return -1;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public void onPlacement( final ItemStack stack, final EntityPlayer player, final EnumFacing side )
{
  if( stack.hasTagCompound() )
  {
    this.uploadSettings( SettingsFrom.DISMANTLE_ITEM, stack.getTagCompound() );
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public static NBTTagCompound openNbtData( final ItemStack i )
{
  NBTTagCompound compound = i.getTagCompound();
  if( compound == null )
  {
    i.setTagCompound( compound = new NBTTagCompound() );
  }
  return compound;
}

代码示例来源:origin: Vazkii/Botania

/** Gets the NBTTagCompound in an ItemStack. Tries to init it
 * previously in case there isn't one present **/
public static NBTTagCompound getNBT(ItemStack stack) {
  if(!stack.hasTagCompound())
    stack.setTagCompound(new NBTTagCompound());
  return stack.getTagCompound();
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) {
  super.onBlockPlacedBy(world, pos, state, entity, stack);
  if(isPassiveFlower()) {
    NBTTagCompound cmp = stack.getTagCompound();
    passiveDecayTicks = cmp.getInteger(TAG_PASSIVE_DECAY_TICKS);
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public Bounds( final ItemStack stack, final FuzzyMode fuzzy, final boolean ignoreMeta )
{
  Preconditions.checkState( !stack.isEmpty(), "ItemStack#isEmpty() has to be false" );
  Preconditions.checkState( stack.getCount() == 1, "ItemStack#getCount() has to be 1" );
  final NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : null;
  this.lower = this.makeLowerBound( stack, tag, fuzzy, ignoreMeta );
  this.upper = this.makeUpperBound( stack, tag, fuzzy, ignoreMeta );
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public long getQEFrequency()
{
  final ItemStack is = this.internalInventory.getStackInSlot( 0 );
  if( !is.isEmpty() )
  {
    final NBTTagCompound c = is.getTagCompound();
    if( c != null )
    {
      return c.getLong( "freq" );
    }
  }
  return 0;
}

代码示例来源:origin: Vazkii/Botania

private boolean compareStacks(ItemStack recipe, ItemStack supplied) {
  if(recipe.getItem() == supplied.getItem() && recipe.getItemDamage() == supplied.getItemDamage()) {
    //check that the user supplied nbt tag is a superset of the recipe item nbt tag
    //if the recipe doesn't have an NBT tag, the user supplied one doesn't matter, it is a superset
    if(!recipe.hasTagCompound()) return true;
    //if the recipe does have an NBT tag but the user supplied doesn't, also no way it's a superset
    if(!supplied.hasTagCompound()) return false;
    
    NBTTagCompound mergedNBT = supplied.getTagCompound().copy();
    mergedNBT.merge(recipe.getTagCompound());
    return supplied.getTagCompound().equals(mergedNBT);
  }
  
  return false;
}

代码示例来源:origin: Vazkii/Botania

public void populateDropStackNBTs(List<ItemStack> drops) {
  if(isPassiveFlower() && ticksExisted > 0 && BotaniaAPI.internalHandler.getPassiveFlowerDecay() > 0) {
    ItemStack drop = drops.get(0);
    if(!drop.isEmpty()) {
      if(!drop.hasTagCompound())
        drop.setTagCompound(new NBTTagCompound());
      NBTTagCompound cmp = drop.getTagCompound();
      cmp.setInteger(TAG_PASSIVE_DECAY_TICKS, passiveDecayTicks);
    }
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public ItemStack getColor( final ItemStack is )
{
  final NBTTagCompound c = is.getTagCompound();
  if( c != null && c.hasKey( "color" ) )
  {
    final NBTTagCompound color = c.getCompoundTag( "color" );
    final ItemStack oldColor = new ItemStack( color );
    if( !oldColor.isEmpty() )
    {
      return oldColor;
    }
  }
  return this.findNextColor( is, ItemStack.EMPTY, 0 );
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
public WorldCoord getStoredSize( final ItemStack is )
{
  if( is.hasTagCompound() )
  {
    final NBTTagCompound c = is.getTagCompound();
    return new WorldCoord( c.getInteger( NBT_SIZE_X_KEY ), c.getInteger( NBT_SIZE_Y_KEY ), c.getInteger( NBT_SIZE_Z_KEY ) );
  }
  return new WorldCoord( 0, 0, 0 );
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onEquipped(ItemStack stack, EntityLivingBase player) {
  super.onEquipped(stack, player);
  if(stack.getItemDamage() != WING_TYPES && StringObfuscator.matchesHash(stack.getDisplayName(), SUPER_AWESOME_HASH)) {
    stack.setItemDamage(WING_TYPES);
    stack.getTagCompound().removeTag("display");
  }
}

代码示例来源:origin: Vazkii/Botania

public ItemBlockPool(Block par2Block) {
  super(par2Block);
  addPropertyOverride(new ResourceLocation(LibMisc.MOD_ID, "full"), (stack, worldIn, entityIn) -> {
    boolean renderFull = stack.getItemDamage() == PoolVariant.CREATIVE.ordinal() || stack.hasTagCompound() && stack.getTagCompound().getBoolean("RenderFull");
    return renderFull ? 1F : 0F;
  });
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

static int getProgress( final ItemStack is )
{
  if( is.hasTagCompound() )
  {
    return is.getTagCompound().getInteger( "progress" );
  }
  else
  {
    final int progress;
    final NBTTagCompound comp = Platform.openNbtData( is );
    comp.setInteger( "progress", progress = is.getItemDamage() );
    is.setItemDamage( ( is.getItemDamage() / SINGLE_OFFSET ) * SINGLE_OFFSET );
    return progress;
  }
}

相关文章

微信公众号

最新文章

更多

ItemStack类方法