diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java index 688ffad28ed..14cca69f05e 100644 --- a/src/main/java/gregtech/api/enums/GT_Values.java +++ b/src/main/java/gregtech/api/enums/GT_Values.java @@ -232,6 +232,7 @@ public static final class NBT { // Machines ACTIVE = "gt.active", // Boolean FLUID_OUT = "gt.fluidout", // Output Fluid + ITEM_OUT = "gt,itemout", // Output Item PARALLEL = "gt.parallel", // Number TANK_CAPACITY = "gt.tankcap", // Number TANK_IN = "gt.tank.in.", // FluidStack diff --git a/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java b/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java index 8da2107ab9e..0faca25290f 100644 --- a/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java +++ b/src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -157,6 +158,7 @@ public void writeMultiTileNBT(NBTTagCompound aNBT) { aNBT.setByte(NBT.FLIP, (byte) mExtendedFacing.getFlip().getIndex()); saveUpgradeInventoriesToNBT(aNBT); + saveItemsToOutput(aNBT); } private void saveUpgradeInventoriesToNBT(NBTTagCompound aNBT) { @@ -186,6 +188,20 @@ private void saveUpgradeInventoriesToNBT(NBTTagCompound aNBT) { aNBT.setTag(NBT.UPGRADE_INVENTORIES_OUTPUT, tListOutputInvs); } + private void saveItemsToOutput(NBTTagCompound aNBT) { + final NBTTagList tList = new NBTTagList(); + for (int tSlot = 0; tSlot < mItemsToOutput.length; tSlot++) { + final ItemStack tStack = mItemsToOutput[tSlot]; + if (tStack != null) { + final NBTTagCompound tag = new NBTTagCompound(); + tag.setByte("s", (byte) tSlot); + tStack.writeToNBT(tag); + tList.appendTag(tag); + } + } + aNBT.setTag(NBT.ITEM_OUT, tList); + } + @Override public void readMultiTileNBT(NBTTagCompound aNBT) { super.readMultiTileNBT(aNBT); @@ -202,6 +218,7 @@ public void readMultiTileNBT(NBTTagCompound aNBT) { Flip.byIndex(aNBT.getByte(NBT.FLIP))); loadUpgradeInventoriesFromNBT(aNBT); + loadItemsToOutput(aNBT); } private void loadUpgradeInventoriesFromNBT(NBTTagCompound aNBT) { @@ -229,6 +246,16 @@ private void loadUpgradeInventoriesFromNBT(NBTTagCompound aNBT) { } } + private void loadItemsToOutput(NBTTagCompound aNBT) { + final NBTTagList tList = aNBT.getTagList(NBT.ITEM_OUT, 10); + mItemsToOutput = new ItemStack[tList.tagCount()]; + for (int i = 0; i < tList.tagCount(); i++) { + final NBTTagCompound tNBT = tList.getCompoundTagAt(i); + final int tSlot = tNBT.getShort("s"); + if (tSlot >= 0 && tSlot < mItemsToOutput.length) mItemsToOutput[tSlot] = GT_Utility.loadItem(tNBT); + } + } + @Override public void addToolTips(List aList, ItemStack aStack, boolean aF3_H) { aList.addAll(Arrays.asList(getDescription())); @@ -1218,34 +1245,9 @@ protected ItemStack[] getAllItemInputs() { } protected Iterable> getItemInputsForEachInventory() { - Iterable> tIterator = new Iterable>() { - - @Override - public Iterator> iterator() { - return new Iterator>() { - - int i = 0; - - @Override - public boolean hasNext() { - if (i >= multiBlockInputInventory.values().size()) { - return false; - } - return true; - } - - @Override - public Pair next() { - return Pair.of( - multiBlockInputInventory.values().toArray(new IItemHandlerModifiable[0])[i].getStacks() - .toArray(new ItemStack[0]), - multiBlockInputInventory.keySet().toArray(new String[0])[i++]); - } - }; - } - - }; - return tIterator; + return multiBlockInputInventory.entrySet().stream() + .map((entry) -> Pair.of(entry.getValue().getStacks().toArray(new ItemStack[0]), entry.getKey())) + .collect(Collectors.toList()); } protected void setItemOutputs(ItemStack[] aItemOutputs, String aInventory) {