@Override public ItemStack getItemStack( final PartItemStack type ) { if( type == PartItemStack.NETWORK ) { final ItemStack copy = this.is.copy(); copy.setTagCompound( null ); return copy; } return this.is; }
public void setFluidStack( ItemStack is, FluidStack fs ) { if( fs == null ) { is.setTagCompound( null ); } else { NBTTagCompound tag = new NBTTagCompound(); fs.writeToNBT( tag ); is.setTagCompound( tag ); } }
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(); }
private void clearCard( final EntityPlayer player, final World w, final EnumHand hand ) { final IMemoryCard mem = (IMemoryCard) player.getHeldItem( hand ).getItem(); mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED ); player.getHeldItem( hand ).setTagCompound( null ); } }
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); } } }
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xOffset, float yOffset, float zOffset) { ItemStack itemstack = player.getHeldItem(hand); if(getEntityId(itemstack) == null) { if(world.getBlockState(pos).getBlock() == Blocks.MOB_SPAWNER) { if(!world.isRemote) { TileEntity te = world.getTileEntity(pos); NBTTagCompound tag = new NBTTagCompound(); tag.setTag(TAG_SPAWNER, new NBTTagCompound()); te.writeToNBT(tag.getCompoundTag(TAG_SPAWNER)); player.getCooldownTracker().setCooldown(this, 20); itemstack.setTagCompound(tag); world.setBlockToAir(pos); UseItemSuccessTrigger.INSTANCE.trigger((EntityPlayerMP) player, itemstack, (WorldServer) world, pos.getX(), pos.getY(), pos.getZ()); player.renderBrokenItemStack(itemstack); } else { for(int i = 0; i < 50; i++) { float red = (float) Math.random(); float green = (float) Math.random(); float blue = (float) Math.random(); Botania.proxy.wispFX(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, red, green, blue, (float) Math.random() * 0.1F + 0.05F, (float) (Math.random() - 0.5F) * 0.15F, (float) (Math.random() - 0.5F) * 0.15F, (float) (Math.random() - 0.5F) * 0.15F); } } return EnumActionResult.SUCCESS; } else return EnumActionResult.PASS; } else { return placeBlock(itemstack, player, world, pos, side, xOffset, yOffset, zOffset) ? EnumActionResult.SUCCESS : EnumActionResult.PASS; } }
newDef.setTagCompound( tag ); newDef.setTagCompound( LOW_TAG );
public ItemStack createFromIDs( final int[] ids ) { ItemStack facadeStack = AEApi.instance() .definitions() .items() .facade() .maybeStack( 1 ) .orElseThrow( () -> new MissingDefinitionException( "Tried to create a facade, while facades are being deactivated." ) ); // Convert back to a registry name... Item item = Item.REGISTRY.getObjectById( ids[0] ); if( item == null ) { return ItemStack.EMPTY; } final NBTTagCompound facadeTag = new NBTTagCompound(); facadeTag.setString( TAG_ITEM_ID, item.getRegistryName().toString() ); facadeTag.setInteger( TAG_DAMAGE, ids[1] ); facadeStack.setTagCompound( facadeTag ); return facadeStack; }
@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); } }
newDef.setTagCompound( tag ); newDef.setTagCompound( HIGH_TAG );
public @Nonnull ItemStack toStack(@Nonnull Block block, int meta, int amount) { ItemStack stack = new ItemStack(block, amount, meta); stack.setTagCompound(toNbt(null)); return stack; }
encodedValue.setBoolean( "substitute", this.isSubstitute() ); output.setTagCompound( encodedValue );
if( tag != null ) ol.setTagCompound( tag );
@SuppressWarnings("null") public @Nonnull ItemStack setBoolean(@Nonnull ItemStack stack, boolean value) { if (Prep.isValid(stack)) { if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } stack.getTagCompound().setBoolean(key, value); } return stack; }
data.setString( TAG_ITEM_ID, itemStack.getItem().getRegistryName().toString() ); data.setInteger( TAG_DAMAGE, itemStack.getItemDamage() ); is.setTagCompound( data ); return is;
@SuppressWarnings("null") public @Nonnull ItemStack setString(@Nonnull ItemStack stack, String value) { if (Prep.isValid(stack) && value != null) { if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } stack.getTagCompound().setString(key, value); } else { removeTag(stack); } return stack; }
tag.setInteger( "side", side.ordinal() ); tag.setInteger( "dimid", world.provider.getDimension() ); player.getHeldItem( hand ).setTagCompound( tag );