public @Nullable NBTTagCompound setString(@Nullable NBTTagCompound tag, @Nullable String value) { if (tag != null && value != null) { tag.setString(key, value); } else { removeTag(tag); } return tag; }
public static @Nonnull ItemStack getOriginalStack(@Nonnull ItemStack itemStack) { if (NbtValue.ORIGINAL_STACK.hasTag(itemStack)) { return NbtValue.ORIGINAL_STACK.getStack(itemStack); } else if (hasPaintSource(itemStack)) { return NbtValue.PAINT_SOURCE.removeTag(BLOCKSTATE.removeTagCopy(itemStack)); } return Prep.getEmpty(); }
public NBTTagCompound setTag(@Nullable NBTTagCompound tag, @Nullable NBTTagCompound value) { if (tag != null) { if (value == null) { removeTag(tag); } else { tag.setTag(key, value); } } return tag; }
public @Nonnull ItemStack removeTagCopy(@Nonnull ItemStack stack) { return removeTag(stack.copy()); }
public @Nullable NBTTagCompound removeTagCopy(@Nullable NBTTagCompound tag) { return tag != null ? removeTag(tag.copy()) : null; }
public static void setPaintSource(@Nonnull ItemStack itemStack, @Nonnull ItemStack paintSource) { if (Prep.isInvalid(paintSource)) { NbtValue.PAINT_SOURCE.removeTag(itemStack); } else { paintSource = paintSource.copy(); paintSource.setCount(1); NbtValue.PAINT_SOURCE.setStack(itemStack, paintSource); } }
public static void writeNbt(NBTTagCompound nbtRoot, IBlockState paintSource) { if (nbtRoot == null) { return; } if (paintSource == null) { BLOCKSTATE.removeTag(nbtRoot); } else { BLOCKSTATE.setTag(nbtRoot, NBTUtil.writeBlockState(new NBTTagCompound(), paintSource)); } }
@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; }
@SuppressWarnings("null") public @Nonnull ItemStack setTag(@Nonnull ItemStack stack, NBTTagCompound value) { if (Prep.isValid(stack)) { if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } if (value == null) { removeTag(stack); } else { stack.getTagCompound().setTag(key, value); } } return stack; }
public static void setSourceBlock(@Nonnull ItemStack itemStack, IBlockState paintSource) { if (Prep.isInvalid(itemStack)) { return; } if (paintSource == null || paintSource.getBlock() == Blocks.AIR) { BLOCKSTATE.removeTag(itemStack); return; } else { try { BLOCKSTATE.setTag(itemStack, NBTUtil.writeBlockState(new NBTTagCompound(), paintSource)); } catch (Exception e) { String s; try { s = "" + Block.REGISTRY.getNameForObject(paintSource.getBlock()); } catch (Exception e1) { s = e1.getMessage(); } throw new RuntimeException("Failed to write blockstate to nbt. blockstate=" + paintSource + " registry name=" + s + " block=" + paintSource.getBlock(), e); } } }