This commit is contained in:
Bob 2023-02-21 20:01:26 +01:00
parent cfa87c084c
commit 202620c73a
3 changed files with 14 additions and 7 deletions

View File

@ -41,7 +41,7 @@ public class HazardTransformerRadiationContainer extends HazardTransformerBase {
if(isBox) { if(isBox) {
ItemStack[] fromNBT = ItemStackUtil.readStacksFromNBT(stack); ItemStack[] fromNBT = ItemStackUtil.readStacksFromNBT(stack, 20);
if(fromNBT == null) return; if(fromNBT == null) return;
for(ItemStack held : fromNBT) { for(ItemStack held : fromNBT) {

View File

@ -54,10 +54,10 @@ public class ItemLeadBox extends Item implements IGUIProvider {
if(!box.hasTagCompound()) if(!box.hasTagCompound())
box.setTagCompound(new NBTTagCompound()); box.setTagCompound(new NBTTagCompound());
ItemStack[] fromNBT = ItemStackUtil.readStacksFromNBT(box); ItemStack[] fromNBT = ItemStackUtil.readStacksFromNBT(box, slots.length);
if(fromNBT != null) { if(fromNBT != null) {
for(int i = 0; i < Math.min(slots.length, fromNBT.length); i++) { for(int i = 0; i < slots.length; i++) {
slots[i] = fromNBT[i]; slots[i] = fromNBT[i];
} }
} }

View File

@ -118,27 +118,34 @@ public class ItemStackUtil {
stack.stackTagCompound.setTag("items", tags); stack.stackTagCompound.setTag("items", tags);
} }
public static ItemStack[] readStacksFromNBT(ItemStack stack) { public static ItemStack[] readStacksFromNBT(ItemStack stack, int count) {
if(!stack.hasTagCompound()) if(!stack.hasTagCompound())
return null; return null;
NBTTagList list = stack.stackTagCompound.getTagList("items", 10); NBTTagList list = stack.stackTagCompound.getTagList("items", 10);
int count = list.tagCount(); if(count == 0) {
count = list.tagCount();
}
ItemStack[] stacks = new ItemStack[count]; ItemStack[] stacks = new ItemStack[count];
for(int i = 0; i < count; i++) { for(int i = 0; i < count; i++) {
NBTTagCompound slotNBT = list.getCompoundTagAt(i); NBTTagCompound slotNBT = list.getCompoundTagAt(i);
byte slot = slotNBT.getByte("slot"); byte slot = slotNBT.getByte("slot");
if(slot >= 0 && slot < stacks.length) { ItemStack loadedStack = ItemStack.loadItemStackFromNBT(slotNBT);
stacks[slot] = ItemStack.loadItemStackFromNBT(slotNBT); if(slot >= 0 && slot < stacks.length && loadedStack != null) {
stacks[slot] = loadedStack;
} }
} }
return stacks; return stacks;
} }
public static ItemStack[] readStacksFromNBT(ItemStack stack) {
return readStacksFromNBT(stack, 0);
}
/** /**
* Returns a List<String> of all ore dict names for this stack. Stack cannot be null, list is empty when there are no ore dict entries. * Returns a List<String> of all ore dict names for this stack. Stack cannot be null, list is empty when there are no ore dict entries.
* @param stack * @param stack