Got the RollingMachine working
This commit is contained in:
parent
8e7d6b011e
commit
b7ccae4b8c
7 changed files with 278 additions and 151 deletions
|
@ -1,6 +1,9 @@
|
|||
package techreborn.util;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
|
@ -30,4 +33,42 @@ public class ItemUtils {
|
|||
public static boolean isWildcard(int damage) {
|
||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
public static void writeInvToNBT(IInventory inv, String tag, NBTTagCompound data) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (byte slot = 0; slot < inv.getSizeInventory(); slot++) {
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if (stack != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
itemTag.setByte("Slot", slot);
|
||||
writeItemToNBT(stack, itemTag);
|
||||
list.appendTag(itemTag);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, list);
|
||||
}
|
||||
|
||||
public static void readInvFromNBT(IInventory inv, String tag, NBTTagCompound data) {
|
||||
NBTTagList list = data.getTagList(tag, 10);
|
||||
for (byte entry = 0; entry < list.tagCount(); entry++) {
|
||||
NBTTagCompound itemTag = list.getCompoundTagAt(entry);
|
||||
int slot = itemTag.getByte("Slot");
|
||||
if (slot >= 0 && slot < inv.getSizeInventory()) {
|
||||
ItemStack stack = readItemFromNBT(itemTag);
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeItemToNBT(ItemStack stack, NBTTagCompound data) {
|
||||
if (stack == null || stack.stackSize <= 0)
|
||||
return;
|
||||
if (stack.stackSize > 127)
|
||||
stack.stackSize = 127;
|
||||
stack.writeToNBT(data);
|
||||
}
|
||||
|
||||
public static ItemStack readItemFromNBT(NBTTagCompound data) {
|
||||
return ItemStack.loadItemStackFromNBT(data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue