diff --git a/pom.xml b/pom.xml
index a58d15f64..fc14fbaef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -343,7 +343,7 @@
com.github.TheBusyBiscuit
CS-CoreLib2
- 0.29.6
+ 0.30.0
compile
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java
index 694f1b352..3956c5740 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java
@@ -10,6 +10,8 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
+import org.bukkit.Bukkit;
+import org.bukkit.NamespacedKey;
import org.bukkit.Server;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
@@ -160,4 +162,16 @@ public class MinecraftRecipeService {
}
}
+ @Nullable
+ public Recipe getRecipe(@Nonnull NamespacedKey key) {
+ Validate.notNull(key, "The NamespacedKey should not be null");
+
+ if (snapshot != null) {
+ // We operate on a cached HashMap which is much faster than Bukkit's method.
+ return snapshot.getRecipe(key);
+ } else {
+ return Bukkit.getRecipe(key);
+ }
+ }
+
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractAutoCrafter.java
index 98f271846..fc6589dd6 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractAutoCrafter.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractAutoCrafter.java
@@ -10,6 +10,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
+import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
@@ -24,7 +25,6 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
-import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
@@ -148,7 +148,8 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
if (craft(inv, recipe)) {
// We are done crafting!
- b.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, b.getLocation(), 16);
+ Location loc = b.getLocation().add(0.5, 0.8, 0.5);
+ b.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, loc, 6);
removeCharge(b.getLocation(), getEnergyConsumption());
}
}
@@ -239,8 +240,10 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
@ParametersAreNonnullByDefault
protected boolean matchesAny(Inventory inv, Map itemQuantities, Predicate predicate) {
- for (int slot = 0; slot < inv.getSize(); slot++) {
- ItemStack item = inv.getItem(slot);
+ ItemStack[] contents = inv.getContents();
+
+ for (int slot = 0; slot < contents.length; slot++) {
+ ItemStack item = contents[slot];
if (item != null) {
int amount = itemQuantities.getOrDefault(slot, item.getAmount());
@@ -260,7 +263,8 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
Validate.notNull(inv, "The Inventory must not be null");
Validate.notNull(recipe, "The Recipe shall not be null");
- if (InvUtils.fits(inv, recipe.getResult())) {
+ // Check if we have an empty slot
+ if (inv.firstEmpty() != -1) {
Map itemQuantities = new HashMap<>();
for (Predicate predicate : recipe.getInputs()) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaAutoCrafter.java
index 8bfc2faea..18cef5781 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaAutoCrafter.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaAutoCrafter.java
@@ -68,7 +68,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
@SuppressWarnings("deprecation")
NamespacedKey key = new NamespacedKey(values[0], values[1]);
- return Bukkit.getRecipe(key);
+ return SlimefunPlugin.getMinecraftRecipeService().getRecipe(key);
}
}
@@ -115,7 +115,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
private void offerRecipe(Player p, Block b, List recipes, int index, ChestMenu menu, AsyncRecipeChoiceTask task) {
Validate.isTrue(index >= 0 && index < recipes.size(), "page must be between 0 and " + (recipes.size() - 1));
- menu.addItem(46, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.size()));
+ menu.replaceExistingItem(46, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.size()));
menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
if (index > 0) {
pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
@@ -125,7 +125,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
return false;
});
- menu.addItem(52, ChestMenuUtils.getNextButton(p, index + 1, recipes.size()));
+ menu.replaceExistingItem(52, ChestMenuUtils.getNextButton(p, index + 1, recipes.size()));
menu.addMenuClickHandler(52, (pl, slot, item, action) -> {
if (index < (recipes.size() - 1)) {
pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
@@ -137,7 +137,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
AbstractRecipe recipe = AbstractRecipe.of(recipes.get(index));
- menu.addItem(49, new CustomItem(Material.CRAFTING_TABLE, ChatColor.GREEN + SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.select")));
+ menu.replaceExistingItem(49, new CustomItem(Material.CRAFTING_TABLE, ChatColor.GREEN + SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.select")));
menu.addMenuClickHandler(49, (pl, slot, item, action) -> {
setSelectedRecipe(b, recipe);
pl.closeInventory();
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaRecipe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaRecipe.java
index 5cd475d7b..bcea3cb2a 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaRecipe.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaRecipe.java
@@ -70,7 +70,9 @@ class VanillaRecipe extends AbstractRecipe {
@Override
public void show(@Nonnull ChestMenu menu, @Nonnull AsyncRecipeChoiceTask task) {
- menu.addItem(24, getResult().clone(), ChestMenuUtils.getEmptyClickHandler());
+ menu.replaceExistingItem(24, getResult().clone());
+ menu.addMenuClickHandler(24, ChestMenuUtils.getEmptyClickHandler());
+
RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipeService().getRecipeShape(recipe);
ItemStack[] items = new ItemStack[9];
@@ -93,7 +95,8 @@ class VanillaRecipe extends AbstractRecipe {
}
for (int i = 0; i < 9; i++) {
- menu.addItem(slots[i], items[i], ChestMenuUtils.getEmptyClickHandler());
+ menu.replaceExistingItem(slots[i], items[i]);
+ menu.addMenuClickHandler(slots[i], ChestMenuUtils.getEmptyClickHandler());
}
}
diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/interfaces/InventoryBlock.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/interfaces/InventoryBlock.java
index b09f898e8..47868aac4 100644
--- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/interfaces/InventoryBlock.java
+++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/interfaces/InventoryBlock.java
@@ -60,7 +60,7 @@ public interface InventoryBlock {
@Override
public boolean canOpen(Block b, Player p) {
- return p.hasPermission("slimefun.inventory.bypass") || (SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES) && Slimefun.hasUnlocked(p, item, false));
+ return p.hasPermission("slimefun.inventory.bypass") || (SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.INTERACT_BLOCK) && Slimefun.hasUnlocked(p, item, false));
}
};
}