9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 23:19:15 +00:00

Merge pull request #42 from Xiao-MoMi/dev

0.0.33
This commit is contained in:
XiaoMoMi
2025-03-15 21:50:14 +08:00
committed by GitHub
9 changed files with 202 additions and 49 deletions

View File

@@ -84,7 +84,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
if (ceRecipe.category() != null) { if (ceRecipe.category() != null) {
shapelessRecipe.setCategory(CraftingBookCategory.valueOf(Objects.requireNonNull(ceRecipe.category()).name())); 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))); shapelessRecipe.addIngredient(new RecipeChoice.MaterialChoice(ingredientToBukkitMaterials(ingredient)));
} }
try { try {
@@ -207,6 +207,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
private final Map<Key, List<Recipe<ItemStack>>> byType; private final Map<Key, List<Recipe<ItemStack>>> byType;
private final Map<Key, Recipe<ItemStack>> byId; private final Map<Key, Recipe<ItemStack>> byId;
private final Map<Key, List<Recipe<ItemStack>>> byResult; private final Map<Key, List<Recipe<ItemStack>>> byResult;
private final Map<Key, List<Recipe<ItemStack>>> byIngredient;
private final VanillaRecipeReader recipeReader; private final VanillaRecipeReader recipeReader;
private final List<NamespacedKey> injectedDataPackRecipes; private final List<NamespacedKey> injectedDataPackRecipes;
private final List<NamespacedKey> registeredCustomRecipes; private final List<NamespacedKey> registeredCustomRecipes;
@@ -220,6 +221,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
this.plugin = plugin; this.plugin = plugin;
this.byType = new HashMap<>(); this.byType = new HashMap<>();
this.byId = new HashMap<>(); this.byId = new HashMap<>();
this.byIngredient = new HashMap<>();
this.byResult = new HashMap<>(); this.byResult = new HashMap<>();
this.injectedDataPackRecipes = new ArrayList<>(); this.injectedDataPackRecipes = new ArrayList<>();
this.registeredCustomRecipes = new ArrayList<>(); this.registeredCustomRecipes = new ArrayList<>();
@@ -285,6 +287,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
this.byType.clear(); this.byType.clear();
this.byId.clear(); this.byId.clear();
this.byResult.clear(); this.byResult.clear();
this.byIngredient.clear();
this.dataPackRecipes.clear(); this.dataPackRecipes.clear();
try { try {
@@ -338,9 +341,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
BUKKIT_RECIPE_FACTORIES.get(recipe.type()).accept(key, recipe); BUKKIT_RECIPE_FACTORIES.get(recipe.type()).accept(key, recipe);
try { try {
this.registeredCustomRecipes.add(key); this.registeredCustomRecipes.add(key);
this.byType.computeIfAbsent(recipe.type(), k -> new ArrayList<>()).add(recipe); addInternalRecipe(id, recipe);
this.byId.put(id, recipe);
this.byResult.computeIfAbsent(recipe.result().item().id(), k -> new ArrayList<>()).add(recipe);
} catch (Exception e) { } catch (Exception e) {
plugin.logger().warn("Failed to add custom recipe " + id, 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()); return this.byResult.getOrDefault(result, List.of());
} }
// example: stone button @Override
public void addVanillaInternalRecipe(Key id, Recipe<ItemStack> recipe) { 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.byType.computeIfAbsent(recipe.type(), k -> new ArrayList<>()).add(recipe);
this.byId.put(id, recipe); this.byId.put(id, recipe);
this.byResult.computeIfAbsent(recipe.result().item().id(), k -> new ArrayList<>()).add(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 @Nullable
@@ -561,7 +571,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
}); });
this.injectedDataPackRecipes.add(key); this.injectedDataPackRecipes.add(key);
} }
this.addVanillaInternalRecipe(id, ceRecipe); this.addInternalRecipe(id, ceRecipe);
} }
private void handleDataPackStoneCuttingRecipe(Key id, VanillaStoneCuttingRecipe recipe) { private void handleDataPackStoneCuttingRecipe(Key id, VanillaStoneCuttingRecipe recipe) {
@@ -583,7 +593,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
Ingredient.of(holders), Ingredient.of(holders),
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), result), recipe.result().count()) 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) { 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.injectedDataPackRecipes.add(key);
} }
this.addVanillaInternalRecipe(id, ceRecipe); this.addInternalRecipe(id, ceRecipe);
} }
private void handleDataPackCookingRecipe(Key id, private void handleDataPackCookingRecipe(Key id,
@@ -701,7 +711,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
}); });
this.injectedDataPackRecipes.add(key); this.injectedDataPackRecipes.add(key);
} }
this.addVanillaInternalRecipe(id, ceRecipe); this.addInternalRecipe(id, ceRecipe);
} }
private List<Material> tagToMaterials(Key tag) { private List<Material> tagToMaterials(Key tag) {
@@ -802,7 +812,7 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static void injectShapelessRecipe(Key id, CustomShapelessRecipe<ItemStack> recipe) throws ReflectiveOperationException { 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); Object shapelessRecipe = getNMSRecipe(id);
recipeToMcRecipeHolder.put(recipe, shapelessRecipe); recipeToMcRecipeHolder.put(recipe, shapelessRecipe);

View File

@@ -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.item.recipe.input.SingleItemInput;
import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.Key;
import java.util.List;
public abstract class CustomCookingRecipe<T> extends AbstractRecipe<T> { public abstract class CustomCookingRecipe<T> extends AbstractRecipe<T> {
protected final CookingRecipeCategory category; protected final CookingRecipeCategory category;
protected final Ingredient<T> ingredient; protected final Ingredient<T> ingredient;
@@ -49,4 +51,9 @@ public abstract class CustomCookingRecipe<T> extends AbstractRecipe<T> {
public int cookingTime() { public int cookingTime() {
return cookingTime; return cookingTime;
} }
@Override
public List<Ingredient<T>> ingredientsInUse() {
return List.of(ingredient);
}
} }

View File

@@ -32,6 +32,11 @@ public class CustomShapedRecipe<T> extends CustomCraftingTableRecipe<T> {
return this.parsedPattern.matches((CraftingInput<T>) input); return this.parsedPattern.matches((CraftingInput<T>) input);
} }
@Override
public List<Ingredient<T>> ingredientsInUse() {
return new ArrayList<>(this.pattern.ingredients().values());
}
@Override @Override
public @NotNull Key type() { public @NotNull Key type() {
return RecipeTypes.SHAPED; return RecipeTypes.SHAPED;

View File

@@ -26,7 +26,8 @@ public class CustomShapelessRecipe<T> extends CustomCraftingTableRecipe<T> {
return placementInfo; return placementInfo;
} }
public List<Ingredient<T>> ingredients() { @Override
public List<Ingredient<T>> ingredientsInUse() {
return ingredients; return ingredients;
} }

View File

@@ -29,6 +29,11 @@ public class CustomStoneCuttingRecipe<T> extends AbstractRecipe<T> {
return this.ingredient.test(((SingleItemInput<T>) input).input()); return this.ingredient.test(((SingleItemInput<T>) input).input());
} }
@Override
public List<Ingredient<T>> ingredientsInUse() {
return List.of(ingredient);
}
@Override @Override
public @NotNull Key type() { public @NotNull Key type() {
return RecipeTypes.STONE_CUTTING; return RecipeTypes.STONE_CUTTING;

View File

@@ -6,6 +6,8 @@ import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List;
public interface Recipe<T> { public interface Recipe<T> {
boolean matches(RecipeInput input); boolean matches(RecipeInput input);
@@ -14,6 +16,8 @@ public interface Recipe<T> {
CustomRecipeResult<T> result(); CustomRecipeResult<T> result();
List<Ingredient<T>> ingredientsInUse();
@NotNull @NotNull
Key type(); Key type();

View File

@@ -28,6 +28,8 @@ public interface RecipeManager<T> extends Reloadable, ConfigSectionParser {
List<Recipe<T>> getRecipeByResult(Key result); List<Recipe<T>> getRecipeByResult(Key result);
List<Recipe<T>> getRecipeByIngredient(Key ingredient);
@Nullable @Nullable
Recipe<T> getRecipe(Key type, RecipeInput input); Recipe<T> getRecipe(Key type, RecipeInput input);

View File

@@ -237,12 +237,20 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.setItemOnCursor(newItem); c.setItemOnCursor(newItem);
return; return;
} }
if (LEFT_CLICK.contains(c.type())) {
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(itemId); List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(itemId);
player.playSound(Constants.SOUND_CLICK_BUTTON); player.playSound(Constants.SOUND_CLICK_BUTTON);
if (!inRecipes.isEmpty()) { if (!inRecipes.isEmpty()) {
openRecipePage(c.clicker(), itemId, e.gui(), inRecipes, 0, 0); openRecipePage(c.clicker(), e.gui(), inRecipes, 0, 0);
} else { } else {
openNoRecipePage(player, itemId, e.gui()); 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); .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( GuiLayout layout = new GuiLayout(
" ", " ",
" ", " ",
@@ -277,6 +285,12 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
Item<?> item = this.plugin.itemManager().createWrappedItem(result, player); Item<?> item = this.plugin.itemManager().createWrappedItem(result, player);
item.count(item.maxStackSize()); item.count(item.maxStackSize());
c.setItemOnCursor(item); 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) -> { .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); .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 (index >= recipes.size()) return;
if (depth > MAX_RECIPE_DEPTH) return; if (depth > MAX_RECIPE_DEPTH) return;
Recipe<Object> recipe = recipes.get(index); Recipe<Object> recipe = recipes.get(index);
Key recipeType = recipe.type(); Key recipeType = recipe.type();
if (recipeType == RecipeTypes.SHAPELESS || recipeType == RecipeTypes.SHAPED) { 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; return;
} }
if (recipeType == RecipeTypes.BLASTING || recipeType == RecipeTypes.CAMPFIRE_COOKING || recipeType == RecipeTypes.SMOKING || recipeType == RecipeTypes.SMELTING) { 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; return;
} }
if (recipeType == RecipeTypes.STONE_CUTTING) { 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; 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 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 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<>(); List<Item<?>> ingredients = new ArrayList<>();
net.momirealms.craftengine.core.item.recipe.Ingredient<Object> ingredient = recipe.ingredient(); 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<?> item = this.plugin.itemManager().createWrappedItem(result, player);
item.count(item.maxStackSize()); item.count(item.maxStackSize());
c.setItemOnCursor(item); 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) -> { .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); c.setItemOnCursor(item);
return; return;
} }
List<Recipe<Object>> inRecipes = plugin.recipeManager().getRecipeByResult(e.item().id()); if (LEFT_CLICK.contains(c.type())) {
if (!inRecipes.isEmpty()) { List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
if (inRecipes == recipes) return;
player.playSound(Constants.SOUND_CLICK_BUTTON); 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) .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_BACK)
@@ -399,7 +444,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.cancel(); c.cancel();
if (index + 1 < recipes.size()) { if (index + 1 < recipes.size()) {
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); 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() .addIngredient('<', GuiElement.constant(this.plugin.itemManager()
@@ -412,7 +457,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.cancel(); c.cancel();
if (index > 0) { if (index > 0) {
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); 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); .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 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 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<>(); List<Item<?>> ingredients = new ArrayList<>();
net.momirealms.craftengine.core.item.recipe.Ingredient<Object> ingredient = recipe.ingredient(); 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<?> item = this.plugin.itemManager().createWrappedItem(result, player);
item.count(item.maxStackSize()); item.count(item.maxStackSize());
c.setItemOnCursor(item); 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) .addIngredient('?', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_COOKING_INFO)
@@ -478,10 +542,22 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.setItemOnCursor(item); c.setItemOnCursor(item);
return; return;
} }
List<Recipe<Object>> inRecipes = plugin.recipeManager().getRecipeByResult(e.item().id()); if (LEFT_CLICK.contains(c.type())) {
if (!inRecipes.isEmpty()) { List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
if (inRecipes == recipes) return;
player.playSound(Constants.SOUND_CLICK_BUTTON); 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) .addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(Constants.RECIPE_BACK)
@@ -503,7 +579,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.cancel(); c.cancel();
if (index + 1 < recipes.size()) { if (index + 1 < recipes.size()) {
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); 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() .addIngredient('<', GuiElement.constant(this.plugin.itemManager()
@@ -516,7 +592,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.cancel(); c.cancel();
if (index > 0) { if (index > 0) {
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); 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); .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 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 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( 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) -> { .addIngredient('X', GuiElement.constant(this.plugin.itemManager().createWrappedItem(result, player).count(recipe.result().count()), (e, c) -> {
c.cancel(); c.cancel();
if (MIDDLE_CLICK.contains(c.type()) && player.isCreativeMode() && player.hasPermission(GET_ITEM_PERMISSION) && c.itemOnCursor() == null) { 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()); item.count(item.maxStackSize());
c.setItemOnCursor(item); 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) -> { .addIngredient('^', player.hasPermission(GET_ITEM_PERMISSION) ? GuiElement.constant(this.plugin.itemManager().createWrappedItem(Constants.RECIPE_GET_ITEM, player), (e, c) -> {
c.cancel(); c.cancel();
player.playSound(Constants.SOUND_PICK_ITEM); player.playSound(Constants.SOUND_PICK_ITEM);
if (LEFT_CLICK.contains(c.type())) { 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())) { } 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())); player.giveItem(item.count(item.maxStackSize()));
} }
}) : GuiElement.EMPTY) }) : GuiElement.EMPTY)
@@ -593,7 +688,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.cancel(); c.cancel();
if (index + 1 < recipes.size()) { if (index + 1 < recipes.size()) {
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); 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() .addIngredient('<', GuiElement.constant(this.plugin.itemManager()
@@ -606,7 +701,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.cancel(); c.cancel();
if (index > 0) { if (index > 0) {
player.playSound(Constants.SOUND_CHANGE_PAGE, 0.25f, 1); 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); c.setItemOnCursor(item);
return; return;
} }
if (LEFT_CLICK.contains(c.type())) {
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id()); List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
if (!inRecipes.isEmpty()) { if (inRecipes == recipes) return;
player.playSound(Constants.SOUND_CLICK_BUTTON); 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 { } 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; int i = 0;
for (int x = 0; x < 3; x++) { for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) { for (int y = 0; y < 3; y++) {
@@ -665,10 +772,22 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
c.setItemOnCursor(item); c.setItemOnCursor(item);
return; return;
} }
if (LEFT_CLICK.contains(c.type())) {
List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id()); List<Recipe<Object>> inRecipes = this.plugin.recipeManager().getRecipeByResult(e.item().id());
if (!inRecipes.isEmpty()) { if (inRecipes == recipes) return;
player.playSound(Constants.SOUND_CLICK_BUTTON); 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 { } else {

View File

@@ -38,7 +38,7 @@ geantyref_version=1.3.16
zstd_version=1.5.6-9 zstd_version=1.5.6-9
commons_io_version=2.17.0 commons_io_version=2.17.0
sparrow_nbt_version=0.3 sparrow_nbt_version=0.3
sparrow_util_version=0.21 sparrow_util_version=0.22
fastutil_version=8.5.15 fastutil_version=8.5.15
netty_version=4.1.119.Final netty_version=4.1.119.Final
joml_version=1.10.8 joml_version=1.10.8