Skip to content

Commit 30fa2f9

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 c25faf6 commit 30fa2f9

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.sk89q.craftbook.util;
22

33
import org.bukkit.Material;
4+
import org.bukkit.block.BlastFurnace;
45
import org.bukkit.block.Block;
56
import org.bukkit.block.BrewingStand;
67
import org.bukkit.block.Chest;
78
import org.bukkit.block.ChiseledBookshelf;
89
import org.bukkit.block.Crafter;
910
import org.bukkit.block.Furnace;
1011
import org.bukkit.block.ShulkerBox;
12+
import org.bukkit.block.Smoker;
1113
import org.bukkit.entity.Player;
1214
import org.bukkit.inventory.BrewerInventory;
1315
import org.bukkit.inventory.DoubleChestInventory;
@@ -89,12 +91,12 @@ public static List<ItemStack> addItemsToFurnace(Furnace furnace, ItemStack ... s
8991
if(!ItemUtil.isStackValid(stack))
9092
continue;
9193

92-
if (ItemUtil.isFurnaceable(stack) && fitsInSlot(stack, furnace.getInventory().getSmelting())) {
94+
if (((furnace instanceof Smoker && ItemUtil.isCookable(stack)) || (furnace instanceof BlastFurnace && ItemUtil.isBlastSmeltable(stack)) || (furnace instanceof Furnace && !(furnace instanceof Smoker) && !(furnace instanceof BlastFurnace) && ItemUtil.isSmeltable(stack))) && fitsPartiallyInSlot(stack, furnace.getInventory().getSmelting())) {
9395
if (furnace.getInventory().getSmelting() == null)
9496
furnace.getInventory().setSmelting(stack);
9597
else
9698
leftovers.add(ItemUtil.addToStack(furnace.getInventory().getSmelting(), stack));
97-
} else if (ItemUtil.isAFuel(stack) && fitsInSlot(stack, furnace.getInventory().getFuel())) {
99+
} else if (ItemUtil.isAFuel(stack) && fitsPartiallyInSlot(stack, furnace.getInventory().getFuel())) {
98100
if (furnace.getInventory().getFuel() == null)
99101
furnace.getInventory().setFuel(stack);
100102
else
@@ -123,13 +125,13 @@ public static List<ItemStack> addItemsToBrewingStand(BrewingStand brewingStand,
123125

124126
for(ItemStack stack : stacks) {
125127
BrewerInventory inv = brewingStand.getInventory();
126-
if (ItemUtil.isAPotionIngredient(stack) && InventoryUtil.fitsInSlot(stack, inv.getIngredient())) {
128+
if (ItemUtil.isAPotionIngredient(stack) && InventoryUtil.fitsPartiallyInSlot(stack, inv.getIngredient())) {
127129
if (inv.getIngredient() == null) {
128130
inv.setIngredient(stack);
129131
} else {
130132
leftovers.add(ItemUtil.addToStack(inv.getIngredient(), stack));
131133
}
132-
} else if (stack.getType() == Material.BLAZE_POWDER && InventoryUtil.fitsInSlot(stack, inv.getFuel())) {
134+
} else if (stack.getType() == Material.BLAZE_POWDER && InventoryUtil.fitsPartiallyInSlot(stack, inv.getFuel())) {
133135
if (inv.getFuel() == null) {
134136
inv.setFuel(stack);
135137
} else {
@@ -330,6 +332,18 @@ public static boolean fitsInSlot(ItemStack stack, ItemStack slot) {
330332
return slot == null || ItemUtil.areItemsIdentical(stack, slot) && stack.getAmount() + slot.getAmount() <= stack.getMaxStackSize();
331333
}
332334

335+
/**
336+
* Checks whether the itemstack can partially stack onto the other itemstack.
337+
*
338+
* @param stack The stack to add.
339+
* @param slot The base stack.
340+
* @return whether it can be added or not.
341+
*/
342+
public static boolean fitsPartiallyInSlot(ItemStack stack, ItemStack slot) {
343+
344+
return slot == null || (ItemUtil.areItemsIdentical(stack, slot) && slot.getAmount() < stack.getMaxStackSize());
345+
}
346+
333347
/**
334348
* Checks whether the block has an inventory.
335349
*

0 commit comments

Comments
 (0)