Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ private void processShapedRecipe(@NotNull ShapedRecipe recipe, @NotNull BoxItem
continue;
}

IngredientHolder ingredient = this.convertChoice(row * 3 + column, choices.get(symbol));
RecipeChoice choice = choices.get(symbol);
if (choice == null || choice == RecipeChoice.empty()) {
continue;
}

IngredientHolder ingredient = this.convertChoice(row * 3 + column, choice);
if (ingredient == null || ingredient.patterns().isEmpty()) {
return;
}
Expand Down Expand Up @@ -167,8 +172,8 @@ private void processCustomRecipe(@Nullable BoxItem @NotNull [] ingredients, @Not
}

private @Nullable IngredientHolder convertChoice(int slot, @Nullable RecipeChoice choice) {
if (choice instanceof RecipeChoice.MaterialChoice materialChoice) {
return IngredientHolder.fromMaterialChoice(slot, materialChoice);
if (choice instanceof RecipeChoice.ItemTypeChoice itemTypeChoice) {
return IngredientHolder.fromItemTypeChoice(slot, itemTypeChoice);
}
if (choice instanceof RecipeChoice.ExactChoice exactChoice) {
return IngredientHolder.fromExactChoice(slot, exactChoice);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package net.okocraft.box.feature.craft.model;

import io.papermc.paper.registry.TypedKey;

import org.bukkit.Registry;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ItemType;
import org.bukkit.inventory.RecipeChoice;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;

import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -37,14 +42,18 @@ public static void disableCache() {
}

/**
* Creates a {@link IngredientHolder} from {@link org.bukkit.inventory.RecipeChoice.MaterialChoice}.
* Creates a {@link IngredientHolder} from {@link RecipeChoice.ItemTypeChoice}.
*
* @param slot the position in the crafting table (0-8)
* @param choice the {@link org.bukkit.inventory.RecipeChoice.MaterialChoice} instance to create {@link IngredientHolder}
* @param choice the {@link RecipeChoice.ItemTypeChoice} instance to create {@link IngredientHolder}
* @return a {@link IngredientHolder}
*/
public static @NotNull IngredientHolder fromMaterialChoice(int slot, @NotNull RecipeChoice.MaterialChoice choice) {
return ModelCache.getIngredientHolder(slot, choice.getChoices().stream().map(ItemStack::new).toList());
public static @NotNull IngredientHolder fromItemTypeChoice(int slot, @NotNull RecipeChoice.ItemTypeChoice choice) {
List<ItemStack> itemStacks = new ArrayList<>();
for (TypedKey<ItemType> type : choice.itemTypes()) {
itemStacks.add(Registry.ITEM.getOrThrow(type).createItemStack());
}
return ModelCache.getIngredientHolder(slot, itemStacks);
}

/**
Expand Down
Loading