From 4180fae30a681a6e5a96ae3848514031f934de9b Mon Sep 17 00:00:00 2001 From: trinsdar <30245301+Trinsdar@users.noreply.github.com> Date: Thu, 28 Sep 2023 23:23:01 -0400 Subject: [PATCH] more work on robot arm --- AntimatterAPI | 2 +- .../gregtech/cover/CoverRobotArm.java | 39 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/AntimatterAPI b/AntimatterAPI index 7265f9759..2c30685d8 160000 --- a/AntimatterAPI +++ b/AntimatterAPI @@ -1 +1 @@ -Subproject commit 7265f9759570c37a4f0413985382d57dae1720d3 +Subproject commit 2c30685d8efc9a28074bf2975c86347191b2113f diff --git a/common/src/main/java/muramasa/gregtech/cover/CoverRobotArm.java b/common/src/main/java/muramasa/gregtech/cover/CoverRobotArm.java index 1eaf30216..609422f95 100644 --- a/common/src/main/java/muramasa/gregtech/cover/CoverRobotArm.java +++ b/common/src/main/java/muramasa/gregtech/cover/CoverRobotArm.java @@ -3,6 +3,7 @@ import muramasa.antimatter.blockentity.BlockEntityMachine; import muramasa.antimatter.blockentity.pipe.BlockEntityPipe; import muramasa.antimatter.capability.ICoverHandler; +import muramasa.antimatter.capability.machine.MachineItemHandler; import muramasa.antimatter.cover.CoverFactory; import muramasa.antimatter.gui.SlotType; import muramasa.antimatter.gui.event.GuiEvents; @@ -16,6 +17,9 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; +import tesseract.api.item.PlatformItemHandler; + +import java.util.function.Predicate; public class CoverRobotArm extends CoverBasicTransport { int slot = 0; @@ -40,10 +44,37 @@ public ResourceLocation getModel(String type, Direction dir) { @Override public boolean onTransfer(Object object, boolean inputSide, boolean simulate) { if (object instanceof ItemStack stack && !exportMode.isExport() && handler.getTile() instanceof BlockEntityMachine machine && inputSide) { - if (machine.itemHandler.map(h -> h.getInputCount() > 0).orElse(false)){ - machine.itemHandler.ifPresent(h -> { - - }); + if (machine.itemHandler.isPresent()){ + if (stack.isEmpty()) return true; + MachineItemHandler itemHandler = machine.itemHandler.get(); + if (itemHandler.getInputCount() > 0){ + ItemStack inserted = itemHandler.getInputHandler().insertItem(slot, stack.copy(), true); + if (inserted.isEmpty()){ + if (!simulate) { + itemHandler.getInputHandler().insertItem(slot, stack.copy(), false); + } + stack.setCount(0); + } else if (inserted.getCount() < stack.getCount()) { + if (!simulate) { + itemHandler.getInputHandler().insertItem(slot, stack.copy(), false); + } + stack.setCount(stack.getCount() - inserted.getCount()); + } + } else if (itemHandler.getHandler(SlotType.STORAGE).getContainerSize() > 0){ + ItemStack inserted = itemHandler.getHandler(SlotType.STORAGE).insertItem(slot, stack.copy(), true); + if (inserted.isEmpty()){ + if (!simulate) { + itemHandler.getHandler(SlotType.STORAGE).insertItem(slot, stack, false); + } + stack.setCount(0); + } else if (inserted.getCount() < stack.getCount()) { + if (!simulate) { + itemHandler.getHandler(SlotType.STORAGE).insertItem(slot, stack, false); + } + stack.setCount(stack.getCount() - inserted.getCount()); + } + } + return true; } } return false;