Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
made buffer not able to insert partial stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Sep 15, 2023
1 parent 9312676 commit be7a4cd
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tesseract.TesseractCapUtils;
import tesseract.api.item.PlatformItemHandler;

import java.util.function.Predicate;

import static muramasa.antimatter.machine.MachineFlag.ENERGY;

Expand Down Expand Up @@ -88,11 +91,29 @@ protected boolean processItemOutput() {
boolean[] booleans = new boolean[1];
booleans[0] = false;
TesseractCapUtils.getItemHandler(adjTile, outputDir.getOpposite()).ifPresent(adjHandler -> {
booleans[0] = this.itemHandler.map(h -> Utils.transferItems(h.getHandler(SlotType.STORAGE), adjHandler,true)).orElse(false);
booleans[0] = this.itemHandler.map(h -> transferItems(h.getHandler(SlotType.STORAGE), adjHandler,true)).orElse(false);
});
return booleans[0];
}

public static boolean transferItems(PlatformItemHandler from, PlatformItemHandler to, boolean once) {
boolean successful = false;
for (int i = 0; i < from.getSlots(); i++) {
ItemStack toInsert = from.extractItem(i, from.getStackInSlot(i).getCount(), true);
if (toInsert.isEmpty()) {
continue;
}
ItemStack inserted = Utils.insertItem(to, toInsert, true);
if (inserted.isEmpty()){
Utils.insertItem(to, toInsert, false);
from.extractItem(i, toInsert.getCount(), false);
if (!successful) successful = true;
if (once) break;
}
}
return successful;
}

@Override
public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
Expand Down

0 comments on commit be7a4cd

Please sign in to comment.