@Override public int hashCode() { return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 ); }
/** * 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() ); }
@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); } }
@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); } }
public static NBTTagCompound getSpawnerTag(ItemStack stack) { NBTTagCompound tag = stack.getTagCompound(); if(tag != null && tag.hasKey(TAG_SPAWNER)) { return tag.getCompoundTag(TAG_SPAWNER); } return null; }
public FluidStack getFluidStack( ItemStack is ) { if( is.hasTagCompound() ) { NBTTagCompound tag = is.getTagCompound(); return FluidStack.loadFluidStackFromNBT( tag ); } return null; }
@Override public int getStoredDimensionID( final ItemStack is ) { if( is.hasTagCompound() ) { final NBTTagCompound c = is.getTagCompound(); return c.getInteger( NBT_CELL_ID_KEY ); } return -1; }
public void onPlacement( final ItemStack stack, final EntityPlayer player, final EnumFacing side ) { if( stack.hasTagCompound() ) { this.uploadSettings( SettingsFrom.DISMANTLE_ITEM, stack.getTagCompound() ); } }
public static NBTTagCompound openNbtData( final ItemStack i ) { NBTTagCompound compound = i.getTagCompound(); if( compound == null ) { i.setTagCompound( compound = new NBTTagCompound() ); } return compound; }
/** 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(); }
@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); } }
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 ); }
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; }
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; }
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); } } }
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 ); }
@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 ); }
@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"); } }
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; }); }
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; } }