Skip to content

Commit

Permalink
clean up and save items which need to be outputted
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWeabo committed Feb 11, 2023
1 parent 068a827 commit 6422e0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/enums/GT_Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -202,6 +218,7 @@ public void readMultiTileNBT(NBTTagCompound aNBT) {
Flip.byIndex(aNBT.getByte(NBT.FLIP)));

loadUpgradeInventoriesFromNBT(aNBT);
loadItemsToOutput(aNBT);
}

private void loadUpgradeInventoriesFromNBT(NBTTagCompound aNBT) {
Expand Down Expand Up @@ -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<String> aList, ItemStack aStack, boolean aF3_H) {
aList.addAll(Arrays.asList(getDescription()));
Expand Down Expand Up @@ -1218,34 +1245,9 @@ protected ItemStack[] getAllItemInputs() {
}

protected Iterable<Pair<ItemStack[], String>> getItemInputsForEachInventory() {
Iterable<Pair<ItemStack[], String>> tIterator = new Iterable<Pair<ItemStack[], String>>() {

@Override
public Iterator<Pair<ItemStack[], String>> iterator() {
return new Iterator<Pair<ItemStack[], String>>() {

int i = 0;

@Override
public boolean hasNext() {
if (i >= multiBlockInputInventory.values().size()) {
return false;
}
return true;
}

@Override
public Pair<ItemStack[], String> 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) {
Expand Down

0 comments on commit 6422e0d

Please sign in to comment.