From bc69fb6ab0b77fdfa44e20e7544c8ca45cb47b7a Mon Sep 17 00:00:00 2001
From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Date: Mon, 22 Aug 2022 18:49:05 -0500
Subject: [PATCH 1/4] Fix Voiding Input Resources Bug & fix some Repeating Code
---
.../infinitylib/machines/MachineBlock.java | 50 +++++++++++++++----
1 file changed, 40 insertions(+), 10 deletions(-)
diff --git a/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java b/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
index 4a53374..21c9aea 100644
--- a/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
+++ b/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
@@ -11,6 +11,7 @@
import lombok.Setter;
+import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
@@ -19,6 +20,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
+import io.github.thebusybiscuit.slimefun4.libraries.dough.items.ItemUtils;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@@ -99,26 +101,26 @@ protected boolean process(Block b, BlockMenu menu) {
}
MachineBlockRecipe recipe = getOutput(input);
+
if (recipe != null) {
+ if (!(getFreeSpace(layout.outputSlots(), recipe.output.clone(), menu) >= recipe.output.getAmount())) {
+ displayIfViewer(menu, NO_ROOM_ITEM);
+ return false;
+ }
+
ItemStack rem = menu.pushItem(recipe.output.clone(), layout.outputSlots());
- if (rem == null || rem.getAmount() < recipe.output.getAmount()) {
+ if (rem == null) {
recipe.consume();
- if (menu.hasViewer()) {
- menu.replaceExistingItem(getStatusSlot(), PROCESSING_ITEM);
- }
+ displayIfViewer(menu, PROCESSING_ITEM);
return true;
}
else {
- if (menu.hasViewer()) {
- menu.replaceExistingItem(getStatusSlot(), NO_ROOM_ITEM);
- }
+ displayIfViewer(menu, NO_ROOM_ITEM);
return false;
}
}
- if (menu.hasViewer()) {
- menu.replaceExistingItem(getStatusSlot(), IDLE_ITEM);
- }
+ displayIfViewer(menu, IDLE_ITEM);
return false;
}
@@ -143,6 +145,34 @@ MachineBlockRecipe getOutput(ItemStack[] items) {
return null;
}
+ int getFreeSpace(int[] slots, ItemStack toWrap, BlockMenu menu) {
+ int freeSpace = 0;
+ for (int slotNumber : slots) {
+ //Get the Item in the Slot and Check if it's an Actual Item
+ ItemStack itemStack = menu.getItemInSlot(slotNumber);
+ if (itemStack == null || itemStack.getType() == Material.AIR) {
+ freeSpace += 64;
+ continue;
+ }
+
+ //If the Items can't stack then continue to the next Slot
+ if (!ItemUtils.canStack(toWrap, itemStack)) {
+ continue;
+ }
+
+ //Add the Amount of FreeSpace that is Left in the Stack
+ freeSpace += 64 - itemStack.getAmount();
+ }
+
+ return freeSpace;
+ }
+
+ void displayIfViewer(@Nonnull BlockMenu menu, @Nonnull ItemStack toDisplay) {
+ if (menu.hasViewer()) {
+ menu.replaceExistingItem(getStatusSlot(), toDisplay);
+ }
+ }
+
@Override
protected int getStatusSlot() {
return layout.statusSlot();
From 031ca7b5d5c3a15eea1cefef827c64d201d8b79d Mon Sep 17 00:00:00 2001
From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Date: Mon, 22 Aug 2022 18:56:01 -0500
Subject: [PATCH 2/4] Increment Version
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 126b022..377c852 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
4.0.0
io.github.mooy1
InfinityLib
- 1.3.9
+ 1.4.0
1.8
From 24733247a024380b68341c3eda8a50bb2d5f7de5 Mon Sep 17 00:00:00 2001
From: Lit Kladov
Date: Wed, 28 Dec 2022 19:06:56 +0300
Subject: [PATCH 3/4] fix for items that stack to less than 64
---
.../java/io/github/mooy1/infinitylib/machines/MachineBlock.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java b/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
index 21c9aea..601ae02 100644
--- a/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
+++ b/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
@@ -161,7 +161,7 @@ int getFreeSpace(int[] slots, ItemStack toWrap, BlockMenu menu) {
}
//Add the Amount of FreeSpace that is Left in the Stack
- freeSpace += 64 - itemStack.getAmount();
+ freeSpace += itemStack.getMaxStackSize() - itemStack.getAmount();
}
return freeSpace;
From dfaf0a31f95ad2fb4b80dabddfdbbbd4de4fcb34 Mon Sep 17 00:00:00 2001
From: Lit Kladov
Date: Wed, 28 Dec 2022 19:24:41 +0300
Subject: [PATCH 4/4] fix item stack calculation for empty slots
this will fix additional miscalculation in case an item that stacks to less than 64 overflows its initial stack.
---
.../java/io/github/mooy1/infinitylib/machines/MachineBlock.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java b/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
index 601ae02..0cfc56c 100644
--- a/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
+++ b/src/main/java/io/github/mooy1/infinitylib/machines/MachineBlock.java
@@ -151,7 +151,7 @@ int getFreeSpace(int[] slots, ItemStack toWrap, BlockMenu menu) {
//Get the Item in the Slot and Check if it's an Actual Item
ItemStack itemStack = menu.getItemInSlot(slotNumber);
if (itemStack == null || itemStack.getType() == Material.AIR) {
- freeSpace += 64;
+ freeSpace += toWrap.getMaxStackSize();
continue;
}