aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kubatech/api/utils/ItemUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kubatech/api/utils/ItemUtils.java')
-rw-r--r--src/main/java/kubatech/api/utils/ItemUtils.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/java/kubatech/api/utils/ItemUtils.java b/src/main/java/kubatech/api/utils/ItemUtils.java
new file mode 100644
index 0000000000..2fc34057c3
--- /dev/null
+++ b/src/main/java/kubatech/api/utils/ItemUtils.java
@@ -0,0 +1,26 @@
+package kubatech.api.utils;
+
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+
+public class ItemUtils {
+
+ public static NBTTagCompound writeItemStackToNBT(ItemStack stack) {
+ NBTTagCompound compound = new NBTTagCompound();
+
+ stack.writeToNBT(compound);
+ compound.setInteger("IntCount", stack.stackSize);
+
+ return compound;
+ }
+
+ public static ItemStack readItemStackFromNBT(NBTTagCompound compound) {
+ ItemStack stack = ItemStack.loadItemStackFromNBT(compound);
+
+ if (stack == null) return null;
+
+ if (compound.hasKey("IntCount")) stack.stackSize = compound.getInteger("IntCount");
+
+ return stack;
+ }
+}