From 4d49e1ec8fc41e47b1d173ff51b985bd84268d94 Mon Sep 17 00:00:00 2001 From: Ome_R Date: Sat, 26 Sep 2020 17:39:20 +0300 Subject: [PATCH 1/2] Fixed CargoNetworkTask not checking for other slots before dropping items on ground --- .../slimefun4/core/networks/cargo/CargoNetworkTask.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java index a65bdb25a..85b1ce474 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java @@ -111,7 +111,8 @@ class CargoNetworkTask implements Runnable { if (inv.getItem(previousSlot) == null) { inv.setItem(previousSlot, stack); } - else { + // Making sure the item cannot be added to another slot before dropping it on ground + else if((stack = inv.addItem(stack).get(0)) != null){ inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack); } } From 75da0b883a576ab41c9c2829950a91187c6c549f Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 26 Sep 2020 22:05:47 +0200 Subject: [PATCH 2/2] Refactored code --- .../core/networks/cargo/CargoNetworkTask.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java index 85b1ce474..7ac5912ed 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java @@ -108,12 +108,18 @@ class CargoNetworkTask implements Runnable { Inventory inv = inventories.get(inputTarget.getLocation()); if (inv != null) { + // Check if the original slot hasn't been occupied in the meantime if (inv.getItem(previousSlot) == null) { inv.setItem(previousSlot, stack); } - // Making sure the item cannot be added to another slot before dropping it on ground - else if((stack = inv.addItem(stack).get(0)) != null){ - inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack); + else { + // Try to add the item into another available slot then + ItemStack rest = inv.addItem(stack).get(0); + + if (rest != null) { + // If the item still couldn't be inserted, simply drop it on the ground + inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), rest); + } } } else {