Skip to content

Commit 0fcbd1f

Browse files
author
ANRAR4
committed
allow partially empty furnaces and brewing stands to be refilled
fix furnaceable items beeing put into any type of furnace
1 parent d53d081 commit 0fcbd1f

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/main/java/com/sk89q/craftbook/util/InventoryUtil.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.bukkit.block.ChiseledBookshelf;
88
import org.bukkit.block.Crafter;
99
import org.bukkit.block.Furnace;
10+
import org.bukkit.block.Smoker;
11+
import org.bukkit.block.BlastFurnace;
1012
import org.bukkit.block.ShulkerBox;
1113
import org.bukkit.entity.Player;
1214
import org.bukkit.inventory.BrewerInventory;
@@ -89,12 +91,16 @@ public static List<ItemStack> addItemsToFurnace(Furnace furnace, ItemStack ... s
8991
if(!ItemUtil.isStackValid(stack))
9092
continue;
9193

92-
if (ItemUtil.isFurnacable(stack) && fitsInSlot(stack, furnace.getInventory().getSmelting())) {
94+
if (((furnace instanceof Smoker && ItemUtil.isCookable(stack))
95+
|| (furnace instanceof BlastFurnace && ItemUtil.isBlastSmeltable(stack))
96+
|| (furnace instanceof Furnace && !(furnace instanceof Smoker)
97+
&& !(furnace instanceof BlastFurnace) && ItemUtil.isFurnacable(stack)))
98+
&& fitsPartiallyInSlot(stack, furnace.getInventory().getSmelting())) {
9399
if (furnace.getInventory().getSmelting() == null)
94100
furnace.getInventory().setSmelting(stack);
95101
else
96102
leftovers.add(ItemUtil.addToStack(furnace.getInventory().getSmelting(), stack));
97-
} else if (ItemUtil.isAFuel(stack) && fitsInSlot(stack, furnace.getInventory().getFuel())) {
103+
} else if (ItemUtil.isAFuel(stack) && fitsPartiallyInSlot(stack, furnace.getInventory().getFuel())) {
98104
if (furnace.getInventory().getFuel() == null)
99105
furnace.getInventory().setFuel(stack);
100106
else
@@ -123,13 +129,15 @@ public static List<ItemStack> addItemsToBrewingStand(BrewingStand brewingStand,
123129

124130
for(ItemStack stack : stacks) {
125131
BrewerInventory inv = brewingStand.getInventory();
126-
if (ItemUtil.isAPotionIngredient(stack) && InventoryUtil.fitsInSlot(stack, inv.getIngredient())) {
132+
if (ItemUtil.isAPotionIngredient(stack)
133+
&& InventoryUtil.fitsPartiallyInSlot(stack, inv.getIngredient())) {
127134
if (inv.getIngredient() == null) {
128135
inv.setIngredient(stack);
129136
} else {
130137
leftovers.add(ItemUtil.addToStack(inv.getIngredient(), stack));
131138
}
132-
} else if (stack.getType() == Material.BLAZE_POWDER && InventoryUtil.fitsInSlot(stack, inv.getFuel())) {
139+
} else if (stack.getType() == Material.BLAZE_POWDER
140+
&& InventoryUtil.fitsPartiallyInSlot(stack, inv.getFuel())) {
133141
if (inv.getFuel() == null) {
134142
inv.setFuel(stack);
135143
} else {
@@ -330,6 +338,18 @@ public static boolean fitsInSlot(ItemStack stack, ItemStack slot) {
330338
return slot == null || ItemUtil.areItemsIdentical(stack, slot) && stack.getAmount() + slot.getAmount() <= stack.getMaxStackSize();
331339
}
332340

341+
/**
342+
* Checks whether the itemstack can partially stack onto the other itemstack.
343+
*
344+
* @param stack The stack to add.
345+
* @param slot The base stack.
346+
* @return whether it can be added or not.
347+
*/
348+
public static boolean fitsPartiallyInSlot(ItemStack stack, ItemStack slot) {
349+
350+
return slot == null || (ItemUtil.areItemsIdentical(stack, slot) && slot.getAmount() < stack.getMaxStackSize());
351+
}
352+
333353
/**
334354
* Checks whether the block has an inventory.
335355
*

0 commit comments

Comments
 (0)