mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
@@ -84,7 +84,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
if (ceRecipe.category() != null) {
|
||||
shapelessRecipe.setCategory(CraftingBookCategory.valueOf(Objects.requireNonNull(ceRecipe.category()).name()));
|
||||
}
|
||||
for (Ingredient<ItemStack> ingredient : ceRecipe.ingredients()) {
|
||||
for (Ingredient<ItemStack> ingredient : ceRecipe.ingredientsInUse()) {
|
||||
shapelessRecipe.addIngredient(new RecipeChoice.MaterialChoice(ingredientToBukkitMaterials(ingredient)));
|
||||
}
|
||||
try {
|
||||
@@ -207,6 +207,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
private final Map<Key, List<Recipe<ItemStack>>> byType;
|
||||
private final Map<Key, Recipe<ItemStack>> byId;
|
||||
private final Map<Key, List<Recipe<ItemStack>>> byResult;
|
||||
private final Map<Key, List<Recipe<ItemStack>>> byIngredient;
|
||||
private final VanillaRecipeReader recipeReader;
|
||||
private final List<NamespacedKey> injectedDataPackRecipes;
|
||||
private final List<NamespacedKey> registeredCustomRecipes;
|
||||
@@ -220,6 +221,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
this.plugin = plugin;
|
||||
this.byType = new HashMap<>();
|
||||
this.byId = new HashMap<>();
|
||||
this.byIngredient = new HashMap<>();
|
||||
this.byResult = new HashMap<>();
|
||||
this.injectedDataPackRecipes = new ArrayList<>();
|
||||
this.registeredCustomRecipes = new ArrayList<>();
|
||||
@@ -285,6 +287,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
this.byType.clear();
|
||||
this.byId.clear();
|
||||
this.byResult.clear();
|
||||
this.byIngredient.clear();
|
||||
this.dataPackRecipes.clear();
|
||||
|
||||
try {
|
||||
@@ -338,9 +341,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
BUKKIT_RECIPE_FACTORIES.get(recipe.type()).accept(key, recipe);
|
||||
try {
|
||||
this.registeredCustomRecipes.add(key);
|
||||
this.byType.computeIfAbsent(recipe.type(), k -> new ArrayList<>()).add(recipe);
|
||||
this.byId.put(id, recipe);
|
||||
this.byResult.computeIfAbsent(recipe.result().item().id(), k -> new ArrayList<>()).add(recipe);
|
||||
addInternalRecipe(id, recipe);
|
||||
} catch (Exception e) {
|
||||
plugin.logger().warn("Failed to add custom recipe " + id, e);
|
||||
}
|
||||
@@ -356,11 +357,20 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
return this.byResult.getOrDefault(result, List.of());
|
||||
}
|
||||
|
||||
// example: stone button
|
||||
public void addVanillaInternalRecipe(Key id, Recipe<ItemStack> recipe) {
|
||||
@Override
|
||||
public List<Recipe<ItemStack>> getRecipeByIngredient(Key ingredient) {
|
||||
return this.byIngredient.getOrDefault(ingredient, List.of());
|
||||
}
|
||||
|
||||
private void addInternalRecipe(Key id, Recipe<ItemStack> recipe) {
|
||||
this.byType.computeIfAbsent(recipe.type(), k -> new ArrayList<>()).add(recipe);
|
||||
this.byId.put(id, recipe);
|
||||
this.byResult.computeIfAbsent(recipe.result().item().id(), k -> new ArrayList<>()).add(recipe);
|
||||
for (Ingredient<ItemStack> ingredient : recipe.ingredientsInUse()) {
|
||||
for (Holder<Key> holder : ingredient.items()) {
|
||||
this.byIngredient.computeIfAbsent(holder.value(), k -> new ArrayList<>()).add(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -561,7 +571,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
});
|
||||
this.injectedDataPackRecipes.add(key);
|
||||
}
|
||||
this.addVanillaInternalRecipe(id, ceRecipe);
|
||||
this.addInternalRecipe(id, ceRecipe);
|
||||
}
|
||||
|
||||
private void handleDataPackStoneCuttingRecipe(Key id, VanillaStoneCuttingRecipe recipe) {
|
||||
@@ -583,7 +593,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
Ingredient.of(holders),
|
||||
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), result), recipe.result().count())
|
||||
);
|
||||
this.addVanillaInternalRecipe(id, ceRecipe);
|
||||
this.addInternalRecipe(id, ceRecipe);
|
||||
}
|
||||
|
||||
private void handleDataPackShapedRecipe(Key id, VanillaShapedRecipe recipe, Consumer<Runnable> callback) {
|
||||
@@ -641,7 +651,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
});
|
||||
this.injectedDataPackRecipes.add(key);
|
||||
}
|
||||
this.addVanillaInternalRecipe(id, ceRecipe);
|
||||
this.addInternalRecipe(id, ceRecipe);
|
||||
}
|
||||
|
||||
private void handleDataPackCookingRecipe(Key id,
|
||||
@@ -701,7 +711,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
});
|
||||
this.injectedDataPackRecipes.add(key);
|
||||
}
|
||||
this.addVanillaInternalRecipe(id, ceRecipe);
|
||||
this.addInternalRecipe(id, ceRecipe);
|
||||
}
|
||||
|
||||
private List<Material> tagToMaterials(Key tag) {
|
||||
@@ -802,7 +812,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void injectShapelessRecipe(Key id, CustomShapelessRecipe<ItemStack> recipe) throws ReflectiveOperationException {
|
||||
List<Ingredient<ItemStack>> actualIngredients = recipe.ingredients();
|
||||
List<Ingredient<ItemStack>> actualIngredients = recipe.ingredientsInUse();
|
||||
|
||||
Object shapelessRecipe = getNMSRecipe(id);
|
||||
recipeToMcRecipeHolder.put(recipe, shapelessRecipe);
|
||||
|
||||
@@ -4,6 +4,8 @@ import net.momirealms.craftengine.core.item.recipe.input.RecipeInput;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.SingleItemInput;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CustomCookingRecipe<T> extends AbstractRecipe<T> {
|
||||
protected final CookingRecipeCategory category;
|
||||
protected final Ingredient<T> ingredient;
|
||||
@@ -49,4 +51,9 @@ public abstract class CustomCookingRecipe<T> extends AbstractRecipe<T> {
|
||||
public int cookingTime() {
|
||||
return cookingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingredient<T>> ingredientsInUse() {
|
||||
return List.of(ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ public class CustomShapedRecipe<T> extends CustomCraftingTableRecipe<T> {
|
||||
return this.parsedPattern.matches((CraftingInput<T>) input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingredient<T>> ingredientsInUse() {
|
||||
return new ArrayList<>(this.pattern.ingredients().values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.SHAPED;
|
||||
|
||||
@@ -26,7 +26,8 @@ public class CustomShapelessRecipe<T> extends CustomCraftingTableRecipe<T> {
|
||||
return placementInfo;
|
||||
}
|
||||
|
||||
public List<Ingredient<T>> ingredients() {
|
||||
@Override
|
||||
public List<Ingredient<T>> ingredientsInUse() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,11 @@ public class CustomStoneCuttingRecipe<T> extends AbstractRecipe<T> {
|
||||
return this.ingredient.test(((SingleItemInput<T>) input).input());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingredient<T>> ingredientsInUse() {
|
||||
return List.of(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.STONE_CUTTING;
|
||||
|
||||
@@ -6,6 +6,8 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Recipe<T> {
|
||||
|
||||
boolean matches(RecipeInput input);
|
||||
@@ -14,6 +16,8 @@ public interface Recipe<T> {
|
||||
|
||||
CustomRecipeResult<T> result();
|
||||
|
||||
List<Ingredient<T>> ingredientsInUse();
|
||||
|
||||
@NotNull
|
||||
Key type();
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ public interface RecipeManager<T> extends Reloadable, ConfigSectionParser {
|
||||
|
||||
List<Recipe<T>> getRecipeByResult(Key result);
|
||||
|
||||
List<Recipe<T>> getRecipeByIngredient(Key ingredient);
|
||||
|
||||
@Nullable
|
||||
Recipe<T> getRecipe(Key type, RecipeInput input);
|
||||
|
||||
|
||||
@@ -237,12 +237,20 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.setItemOnCursor(newItem);
|
||||
return;
|
||||
}
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(itemId);
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), itemId, e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, itemId, e.gui());
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(itemId);
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, itemId, e.gui(), 0);
|
||||
}
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(itemId);
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -262,7 +270,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.open(player);
|
||||
}
|
||||
|
||||
public void openNoRecipePage(Player player, Key result, Gui parentGui) {
|
||||
public void openNoRecipePage(Player player, Key result, Gui parentGui, int depth) {
|
||||
GuiLayout layout = new GuiLayout(
|
||||
" ",
|
||||
" ",
|
||||
@@ -277,6 +285,12 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
Item<?> item = this.plugin.itemManager().createWrappedItem(result, player);
|
||||
item.count(item.maxStackSize());
|
||||
c.setItemOnCursor(item);
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(result);
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, depth + 1);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.addIngredient('^', player.hasPermission(GET_ITEM_PERMISSION) ? GuiElement.constant(this.plugin.itemManager().createWrappedItem(Constants.RECIPE_GET_ITEM, player), (e, c) -> {
|
||||
@@ -312,28 +326,29 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.open(player);
|
||||
}
|
||||
|
||||
public void openRecipePage(Player player, Key result, Gui parentGui, List<Recipe<Object>> recipes, int index, int depth) {
|
||||
public void openRecipePage(Player player, Gui parentGui, List<Recipe<Object>> recipes, int index, int depth) {
|
||||
if (index >= recipes.size()) return;
|
||||
if (depth > MAX_RECIPE_DEPTH) return;
|
||||
Recipe<Object> recipe = recipes.get(index);
|
||||
Key recipeType = recipe.type();
|
||||
if (recipeType == RecipeTypes.SHAPELESS || recipeType == RecipeTypes.SHAPED) {
|
||||
openCraftingRecipePage(player, result, (CustomCraftingTableRecipe<Object>) recipe, parentGui, recipes, index, depth);
|
||||
openCraftingRecipePage(player, (CustomCraftingTableRecipe<Object>) recipe, parentGui, recipes, index, depth);
|
||||
return;
|
||||
}
|
||||
if (recipeType == RecipeTypes.BLASTING || recipeType == RecipeTypes.CAMPFIRE_COOKING || recipeType == RecipeTypes.SMOKING || recipeType == RecipeTypes.SMELTING) {
|
||||
openCookingRecipePage(player, result, (CustomCookingRecipe<Object>) recipe, parentGui, recipes, index, depth);
|
||||
openCookingRecipePage(player, (CustomCookingRecipe<Object>) recipe, parentGui, recipes, index, depth);
|
||||
return;
|
||||
}
|
||||
if (recipeType == RecipeTypes.STONE_CUTTING) {
|
||||
openStoneCuttingRecipePage(player, result, (CustomStoneCuttingRecipe<Object>) recipe, parentGui, recipes, index, depth);
|
||||
openStoneCuttingRecipePage(player, (CustomStoneCuttingRecipe<Object>) recipe, parentGui, recipes, index, depth);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void openStoneCuttingRecipePage(Player player, Key result, CustomStoneCuttingRecipe<Object> recipe, Gui parentGui, List<Recipe<Object>> recipes, int index, int depth) {
|
||||
public void openStoneCuttingRecipePage(Player player, CustomStoneCuttingRecipe<Object> recipe, Gui parentGui, List<Recipe<Object>> recipes, int index, int depth) {
|
||||
Key previous = index > 0 ? Constants.RECIPE_PREVIOUS_PAGE_AVAILABLE : Constants.RECIPE_PREVIOUS_PAGE_BLOCK;
|
||||
Key next = index + 1 < recipes.size() ? Constants.RECIPE_NEXT_PAGE_AVAILABLE : Constants.RECIPE_NEXT_PAGE_BLOCK;
|
||||
Key result = recipe.result().item().id();
|
||||
|
||||
List<Item<?>> ingredients = new ArrayList<>();
|
||||
net.momirealms.craftengine.core.item.recipe.Ingredient<Object> ingredient = recipe.ingredient();
|
||||
@@ -354,6 +369,24 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
Item<?> item = this.plugin.itemManager().createWrappedItem(result, player);
|
||||
item.count(item.maxStackSize());
|
||||
c.setItemOnCursor(item);
|
||||
return;
|
||||
}
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(result);
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, result, e.gui(), 0);
|
||||
}
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(result);
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.addIngredient('^', player.hasPermission(GET_ITEM_PERMISSION) ? GuiElement.constant(this.plugin.itemManager().createWrappedItem(Constants.RECIPE_GET_ITEM, player), (e, c) -> {
|
||||
@@ -374,10 +407,22 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.setItemOnCursor(item);
|
||||
return;
|
||||
}
|
||||
List<Recipe<Object>> inRecipes = plugin.recipeManager().getRecipeByResult(e.item().id());
|
||||
if (!inRecipes.isEmpty()) {
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
openRecipePage(player, e.item().id(), e.gui(), inRecipes, 0, depth + 1);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, e.item().id(), e.gui(), 0);
|
||||
}
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(e.item().id());
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_BACK)
|
||||
@@ -399,7 +444,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.cancel();
|
||||
if (index + 1 < recipes.size()) {
|
||||
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1);
|
||||
openRecipePage(player, result, parentGui, recipes, index + 1, depth);
|
||||
openRecipePage(player, parentGui, recipes, index + 1, depth);
|
||||
}
|
||||
}))
|
||||
.addIngredient('<', GuiElement.constant(this.plugin.itemManager()
|
||||
@@ -412,7 +457,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.cancel();
|
||||
if (index > 0) {
|
||||
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1);
|
||||
openRecipePage(player, result, parentGui, recipes, index - 1, depth);
|
||||
openRecipePage(player, parentGui, recipes, index - 1, depth);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -429,9 +474,10 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.open(player);
|
||||
}
|
||||
|
||||
public void openCookingRecipePage(Player player, Key result, CustomCookingRecipe<Object> recipe, Gui parentGui, List<Recipe<Object>> recipes, int index, int depth) {
|
||||
public void openCookingRecipePage(Player player, CustomCookingRecipe<Object> recipe, Gui parentGui, List<Recipe<Object>> recipes, int index, int depth) {
|
||||
Key previous = index > 0 ? Constants.RECIPE_PREVIOUS_PAGE_AVAILABLE : Constants.RECIPE_PREVIOUS_PAGE_BLOCK;
|
||||
Key next = index + 1 < recipes.size() ? Constants.RECIPE_NEXT_PAGE_AVAILABLE : Constants.RECIPE_NEXT_PAGE_BLOCK;
|
||||
Key result = recipe.result().item().id();
|
||||
|
||||
List<Item<?>> ingredients = new ArrayList<>();
|
||||
net.momirealms.craftengine.core.item.recipe.Ingredient<Object> ingredient = recipe.ingredient();
|
||||
@@ -452,6 +498,24 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
Item<?> item = this.plugin.itemManager().createWrappedItem(result, player);
|
||||
item.count(item.maxStackSize());
|
||||
c.setItemOnCursor(item);
|
||||
return;
|
||||
}
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(result);
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, result, e.gui(), 0);
|
||||
}
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(result);
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.addIngredient('?', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_COOKING_INFO)
|
||||
@@ -478,10 +542,22 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.setItemOnCursor(item);
|
||||
return;
|
||||
}
|
||||
List<Recipe<Object>> inRecipes = plugin.recipeManager().getRecipeByResult(e.item().id());
|
||||
if (!inRecipes.isEmpty()) {
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
openRecipePage(player, e.item().id(), e.gui(), inRecipes, 0, depth + 1);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, e.item().id(), e.gui(), 0);
|
||||
}
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(e.item().id());
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_BACK)
|
||||
@@ -503,7 +579,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.cancel();
|
||||
if (index + 1 < recipes.size()) {
|
||||
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1);
|
||||
openRecipePage(player, result, parentGui, recipes, index + 1, depth);
|
||||
openRecipePage(player, parentGui, recipes, index + 1, depth);
|
||||
}
|
||||
}))
|
||||
.addIngredient('<', GuiElement.constant(this.plugin.itemManager()
|
||||
@@ -516,7 +592,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.cancel();
|
||||
if (index > 0) {
|
||||
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1);
|
||||
openRecipePage(player, result, parentGui, recipes, index - 1, depth);
|
||||
openRecipePage(player, parentGui, recipes, index - 1, depth);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -544,9 +620,10 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.open(player);
|
||||
}
|
||||
|
||||
public void openCraftingRecipePage(Player player, Key result, CustomCraftingTableRecipe<Object> recipe, Gui parentGui, List<Recipe<Object>> recipes, int index, int depth) {
|
||||
public void openCraftingRecipePage(Player player, CustomCraftingTableRecipe<Object> recipe, Gui parentGui, List<Recipe<Object>> recipes, int index, int depth) {
|
||||
Key previous = index > 0 ? Constants.RECIPE_PREVIOUS_PAGE_AVAILABLE : Constants.RECIPE_PREVIOUS_PAGE_BLOCK;
|
||||
Key next = index + 1 < recipes.size() ? Constants.RECIPE_NEXT_PAGE_AVAILABLE : Constants.RECIPE_NEXT_PAGE_BLOCK;
|
||||
Key result = recipe.result().item().id();
|
||||
|
||||
GuiLayout layout = new GuiLayout(
|
||||
" ",
|
||||
@@ -559,18 +636,36 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.addIngredient('X', GuiElement.constant(this.plugin.itemManager().createWrappedItem(result, player).count(recipe.result().count()), (e, c) -> {
|
||||
c.cancel();
|
||||
if (MIDDLE_CLICK.contains(c.type()) && player.isCreativeMode() && player.hasPermission(GET_ITEM_PERMISSION) && c.itemOnCursor() == null) {
|
||||
Item<?> item = this.plugin.itemManager().createWrappedItem(result, player);
|
||||
Item<?> item = this.plugin.itemManager().createWrappedItem(recipe.result().item().id(), player);
|
||||
item.count(item.maxStackSize());
|
||||
c.setItemOnCursor(item);
|
||||
return;
|
||||
}
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(result);
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, result, e.gui(), 0);
|
||||
}
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(result);
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.addIngredient('^', player.hasPermission(GET_ITEM_PERMISSION) ? GuiElement.constant(this.plugin.itemManager().createWrappedItem(Constants.RECIPE_GET_ITEM, player), (e, c) -> {
|
||||
c.cancel();
|
||||
player.playSound(Constants.SOUND_PICK_ITEM);
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
player.giveItem(this.plugin.itemManager().createWrappedItem(result, player));
|
||||
player.giveItem(this.plugin.itemManager().createWrappedItem(recipe.result().item().id(), player));
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
Item<?> item = this.plugin.itemManager().createWrappedItem(result, player);
|
||||
Item<?> item = this.plugin.itemManager().createWrappedItem(recipe.result().item().id(), player);
|
||||
player.giveItem(item.count(item.maxStackSize()));
|
||||
}
|
||||
}) : GuiElement.EMPTY)
|
||||
@@ -593,7 +688,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.cancel();
|
||||
if (index + 1 < recipes.size()) {
|
||||
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1);
|
||||
openRecipePage(player, result, parentGui, recipes, index + 1, depth);
|
||||
openRecipePage(player, parentGui, recipes, index + 1, depth);
|
||||
}
|
||||
}))
|
||||
.addIngredient('<', GuiElement.constant(this.plugin.itemManager()
|
||||
@@ -606,7 +701,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.cancel();
|
||||
if (index > 0) {
|
||||
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1);
|
||||
openRecipePage(player, result, parentGui, recipes, index - 1, depth);
|
||||
openRecipePage(player, parentGui, recipes, index - 1, depth);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -634,10 +729,22 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.setItemOnCursor(item);
|
||||
return;
|
||||
}
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
|
||||
if (!inRecipes.isEmpty()) {
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
openRecipePage(player, e.item().id(), e.gui(), inRecipes, 0, depth + 1);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, e.item().id(), e.gui(), 0);
|
||||
}
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(e.item().id());
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -647,7 +754,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<net.momirealms.craftengine.core.item.recipe.Ingredient<Object>> ingredients = ((CustomShapelessRecipe<Object>) recipe).ingredients();
|
||||
List<net.momirealms.craftengine.core.item.recipe.Ingredient<Object>> ingredients = recipe.ingredientsInUse();
|
||||
int i = 0;
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 3; y++) {
|
||||
@@ -665,10 +772,22 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
c.setItemOnCursor(item);
|
||||
return;
|
||||
}
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
|
||||
if (!inRecipes.isEmpty()) {
|
||||
if (LEFT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
openRecipePage(player, e.item().id(), e.gui(), inRecipes, 0, depth + 1);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
} else {
|
||||
openNoRecipePage(player, e.item().id(), e.gui(), 0);
|
||||
}
|
||||
} else if (RIGHT_CLICK.contains(c.type())) {
|
||||
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByIngredient(e.item().id());
|
||||
if (inRecipes == recipes) return;
|
||||
player.playSound(Constants.SOUND_CLICK_BUTTON);
|
||||
if (!inRecipes.isEmpty()) {
|
||||
openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
|
||||
}
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
|
||||
@@ -38,7 +38,7 @@ geantyref_version=1.3.16
|
||||
zstd_version=1.5.6-9
|
||||
commons_io_version=2.17.0
|
||||
sparrow_nbt_version=0.3
|
||||
sparrow_util_version=0.21
|
||||
sparrow_util_version=0.22
|
||||
fastutil_version=8.5.15
|
||||
netty_version=4.1.119.Final
|
||||
joml_version=1.10.8
|
||||
|
||||
Reference in New Issue
Block a user