diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java index ab32ced8cae..6bc0842e3b5 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumChest.java @@ -592,13 +592,17 @@ public ItemStack insertItem(int slot, @Nonnull ItemStack insertedStack, boolean return ItemStack.EMPTY; } - ItemStack exportItems = getExportItems().getStackInSlot(0); - // If there is a virtualized stack and the stack to insert does not match it, do not insert anything if (itemsStoredInside > 0L && - !virtualItemStack.isEmpty() && ( - !areItemStackIdentical(virtualItemStack, insertedStack) || - !areItemStackIdentical(exportItems, insertedStack))) { + !virtualItemStack.isEmpty() && + !areItemStackIdentical(virtualItemStack, insertedStack)) { + return insertedStack; + } + + ItemStack exportItems = getExportItems().getStackInSlot(0); + + // if there is an item in the export slot and the inserted stack does not match, do not insert + if (!exportItems.isEmpty() && !areItemStackIdentical(exportItems, insertedStack)) { return insertedStack; } diff --git a/src/test/java/gregtech/common/metatileentities/storage/QuantumChestTest.java b/src/test/java/gregtech/common/metatileentities/storage/QuantumChestTest.java index ae51478a28f..1ed28f5ea5e 100644 --- a/src/test/java/gregtech/common/metatileentities/storage/QuantumChestTest.java +++ b/src/test/java/gregtech/common/metatileentities/storage/QuantumChestTest.java @@ -101,6 +101,26 @@ public void Test_Stack_In_Slot() { } } + @Test + public void Test_Export_Checking() { + for (var quantumChest : createInstances()) { + IItemHandler itemHandler = quantumChest.getCombinedInventory(); + insertItem(itemHandler, GRAVEL.copy(), false); + + ItemStack export = quantumChest.getExportItems().getStackInSlot(0); + + insertItem(itemHandler, SAND.copy(), false); + insertItem(itemHandler, SAND.copy(), false); + + insertItem(itemHandler, GRAVEL.copy(), false); + + + String reason = "The virtualized stack is not the same as the export slot!"; + boolean isEqual = ItemStack.areItemsEqual(export, quantumChest.virtualItemStack) && export.getMetadata() == quantumChest.virtualItemStack.getMetadata(); + assertThat(reason, isEqual, is(true)); + } + } + @Test public void Test_Multiple_Insertions() { for (var quantumChest : createInstances()) {