Java Code Examples for net.minecraft.item.Item#isDamageable()

The following examples show how to use net.minecraft.item.Item#isDamageable() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
 * Writes an {@link ItemStack} to the stream.
 * The <code>limitedTag</code> parameter, can be used to force the use of
 * the stack {@link ItemStack#getShareTag()} instead of its {@link ItemStack#getTag()}.
 * Under normal circumstances in Server -> Client sync, not all NBT tags are required,
 * to be sent to the client. For Example, the inventory of a pouch / bag(Containers sync it).
 * However, in Client -> Server sync, the entire tag may be required, modders can choose,
 * if they want a stacks full tag or not. The default is to use {@link ItemStack#getShareTag()}.
 * <p>
 * It should also be noted that this implementation writes the {@link ItemStack#getCount()}
 * as a varInt opposed to a byte, as that is favourable in some cases.
 * @param stack      The {@link ItemStack}.
 * @param limitedTag Weather to use the stacks {@link ItemStack#getShareTag()} instead.
 * @return The same stream.
default MCDataOutput writeItemStack(ItemStack stack, boolean limitedTag) {
    if (stack.isEmpty()) {
    } else {
        Item item = stack.getItem();
        writeRegistryIdUnsafe(ForgeRegistries.ITEMS, item);
        CompoundNBT nbt = null;
        if (item.isDamageable() || item.shouldSyncTag()) {
            nbt = limitedTag ? stack.getShareTag() : stack.getTag();
    return this;