mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2024-11-22 10:36:11 +01:00
Autocrafting Duplication Bug #27
Crafting now removes duplicate inventories from input array
This commit is contained in:
parent
418ada0b73
commit
a902d66f42
@ -1,21 +1,16 @@
|
||||
package com.jamesdpeters.minecraft.chests.crafting;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.api.ApiSpecific;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class Crafting {
|
||||
|
||||
private static List<ShapedRecipe> shapedRecipes;
|
||||
@ -42,32 +37,6 @@ public class Crafting {
|
||||
return ApiSpecific.getNmsProvider().getCraftingProvider().craft(Bukkit.getWorlds().get(0), recipe);
|
||||
}
|
||||
|
||||
private static boolean matchesShapeless(List<RecipeChoice> choice, List<ItemStack> items) {
|
||||
items = new ArrayList<>(items);
|
||||
for (RecipeChoice c : choice) {
|
||||
boolean match = false;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
ItemStack item = items.get(i);
|
||||
if (item == null || item.getType() == Material.AIR)
|
||||
continue;
|
||||
if (c.test(item)) {
|
||||
match = true;
|
||||
items.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match)
|
||||
return false;
|
||||
}
|
||||
Set<ItemStack> remainingItems = new HashSet<>(items);
|
||||
return (remainingItems.size() == 1 && (items.contains(new ItemStack(Material.AIR)) || items.contains(null)));
|
||||
}
|
||||
|
||||
private static boolean matchesShaped(ShapedRecipe shape, List<ItemStack> items) {
|
||||
UserShapedRecipe userShapedRecipe = new UserShapedRecipe(items);
|
||||
return userShapedRecipe.matchesRecipe(shape);
|
||||
}
|
||||
|
||||
public static Recipe getRecipeByKey(NamespacedKey key) {
|
||||
Optional<ShapelessRecipe> recipe = shapelessRecipes.stream().filter(s -> s.getKey().equals(key)).findFirst();
|
||||
if (recipe.isPresent()) return recipe.get();
|
||||
|
@ -8,6 +8,11 @@ import com.jamesdpeters.minecraft.chests.serialize.Config;
|
||||
import com.jamesdpeters.minecraft.chests.serialize.LocationInfo;
|
||||
import com.jamesdpeters.minecraft.chests.storage.autocraft.AutoCraftingStorage;
|
||||
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
@ -27,11 +32,6 @@ import org.bukkit.inventory.ShapelessRecipe;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class VirtualCraftingHolder implements InventoryHolder {
|
||||
|
||||
private final Inventory inventory;
|
||||
@ -394,6 +394,9 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
// Create a copy of the real inventories and decide if any of the inputs match the output.
|
||||
List<Inventory> tempInvs = new ArrayList<>();
|
||||
|
||||
// Remove duplicate inventories from list.
|
||||
inputs = inputs.stream().distinct().collect(Collectors.toList());
|
||||
|
||||
for (Inventory inv : inputs) {
|
||||
Inventory tempInv = Utils.copyInventory(inv);
|
||||
tempInvs.add(tempInv);
|
||||
|
Loading…
Reference in New Issue
Block a user