Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recipe Support #7150

Open
wants to merge 47 commits into
base: dev/feature
Choose a base branch
from

Conversation

TheAbsolutionism
Copy link
Contributor

@TheAbsolutionism TheAbsolutionism commented Oct 16, 2024

Description

This PR aims to add support for recipes including:

  • BukkitClasses#Recipe
  • SkriptClasses#RecipeType
  • DefaultComparators#RecipeType->RecipeType
  • CondDiscoveredRecipes
  • CondRecipeExists
  • EffDiscoverRecipe
  • EffRemoveRecipe
  • EffResetRecipes
  • ExprAllRecipes
  • ExprGetRecipe
  • ExprRecipeCategory
  • ExprRecipeCookingTime
  • ExprRecipeExperience
  • ExprRecipeGroup
  • ExprRecipeIngredients
  • ExprRecipeKey
  • ExprRecipeKeyConverter
  • ExprRecipeResult
  • ExprRecipeType
  • SecRegisterRecipe
  • Utils#NamespacedUtils
  • Utils#RecipeUtils

Target Minecraft Versions: any
Requirements: none
Related Issues: #5261

@Fusezion

This comment was marked as resolved.

Copy link
Contributor

@Fusezion Fusezion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So uuh thinking about moving this to a module?

@TheAbsolutionism
Copy link
Contributor Author

So uuh thinking about moving this to a module?

nada

src/main/java/ch/njol/skript/util/RecipeUtils.java Outdated Show resolved Hide resolved
@Efnilite Efnilite added the feature Pull request adding a new feature. label Oct 16, 2024
src/main/java/ch/njol/skript/util/RecipeUtils.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/util/RecipeUtils.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/util/RecipeUtils.java Outdated Show resolved Hide resolved
Copy link
Contributor

@Fusezion Fusezion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided more changes were needed, we're aiming for 100

@Fusezion
Copy link
Contributor

I mentioned it to smurf once, but mentioning it in the pr itself will be good, what's the thought about a proper RecipeChoice implementation to have more support of ingredients.

If this goes through a custom ItemTypeChoice should be created to enable skript's item types correctly and not converting to an itemstack always.

This should be pretty safe due to the fact recipes and these can't be serialized by default

Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review

@TheAbsolutionism
Copy link
Contributor Author

well i should be able to treat a mutable crafting recipe the same as a crafting recipe
hence they should have the same interface, and it would allow it to pass instanceof CraftingRecipe

So, I tried to have the subclasses extends their respective Bukkit recipe class, but unfortunately it wont let me.

@sovdeeth
Copy link
Member

well i should be able to treat a mutable crafting recipe the same as a crafting recipe
hence they should have the same interface, and it would allow it to pass instanceof CraftingRecipe

So, I tried to have the subclasses extends their respective Bukkit recipe class, but unfortunately it wont let me.

ah are they final?

@TheAbsolutionism
Copy link
Contributor Author

ah are they final?

It just says "Class can not extend multiple classes"

@sovdeeth
Copy link
Member

ah are they final?

It just says "Class can not extend multiple classes"

oh right the sub recipes aren't interfaces

Copy link
Member

@Efnilite Efnilite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the way to most commented pr 💪

# Conflicts:
#	src/main/java/ch/njol/skript/Skript.java
#	src/main/resources/lang/default.lang
Copy link
Contributor

@Fusezion Fusezion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we possibly implement the transmute recipe type? https://jd.papermc.io/paper/1.21.4/org/bukkit/inventory/TransmuteRecipe.html

Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking pretty good

})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

"NOTES:",
"This condition can only be used with Smithing Recipes on PaperMC version 1.19",
"This condition can be used with Smithing Transform and Smithing Trim Recipes on PaperMC version 1.20.0 -> 1.20.4",
"This condition is redundant for PaperMC versions 1.20.5+ due to the removal in favor of copying data components and will always return true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for picking always true instead of always false or just not registering?
I'm also not sure why this isn't merged with data component condition, because I imagine most users consider components to be nbt.

Comment on lines +44 to +68
"\tset the recipe ingredients to diamond, air, diamond, air, emerald, air, diamond, air and diamond",
"\t#OR",
"\tset the recipe ingredients of the 1st row to diamond, air and diamond",
"\tset the recipe ingredients of second row to air, emerald and air",
"\tset the recipe ingredients of the third row to diamond, air and diamond",
"\tset the recipe result to beacon",
"",
"set {_recipe} to a shapeless recipe with id \"my_recipe\":",
"\tset recipe ingredients to iron ingot, gold ingot, iron ingot, nether star, 5 obsidian, nether star, iron ingot, gold ingot and iron ingot",
"\tset recipe resulting item to beacon named \"OP Beacon\"",
"",
"set {_recipe} to new blasting recipe with the id \"my_recipe\":",
"\tset the recipe input item to netherite ingot named \"Impure Netherite\"",
"\tset the recipe result item to netherite ingot named \"Pure Netherite\"",
"",
"set {_recipe} to a new smithing transform recipe with key \"my_recipe\":",
"\tset the recipe base item to diamond helmet",
"\tset the recipe template item to paper named \"Blueprint\"",
"\tset the recipe addition item to netherite ingot named \"Pure Netherite\"",
"\tset the recipe result to netherite helmet named \"Pure Helmet\"",
"",
"set {_recipe} to a new transmute recipe with key \"my_recipe\":",
"\tset the recipe input item to leather helmet",
"\tset the recipe transmute item to nether star named \"Free Upgrade\"",
"\tset the recipe result to netherite helmet"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know it's probably already been discussed but do you think there's any safe way to get rid of all the recipe keywords here? It feels awkward to have to repeat them

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
selectedPattern = recipePatterns[(int) Math.floor((double) matchedPattern / 2)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
selectedPattern = recipePatterns[(int) Math.floor((double) matchedPattern / 2)];
selectedPattern = recipePatterns[matchedPattern / 2];

integer division should truncate for you

if (getParser().isCurrentEvent(CreateRecipeEvent.class)) {
boolean classFound = false;
for (Class<? extends Event> eventClass : selectedPattern.eventClasses) {
if (getParser().isCurrentEvent(eventClass)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use the varargs version of isCurrentEvent to check multiple at once

@Override
protected ItemStack @Nullable [] get(Event event, Recipe[] source) {
if (isEvent)
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not get the ingredient of an in-process recipe? I can see it being somewhat useful:

set ingredients to func()
if ingredients contains xyz:

assert {_get} is set with "Transmute recipe was not added to the server"

assert the recipe type of {_recipe} is transmute recipe with "Created recipe is not a transmute recipe"
assert the recipe type of {_recipe} is transmute recipe with "Retrieved recipe is not a transmute recipe"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert the recipe type of {_recipe} is transmute recipe with "Retrieved recipe is not a transmute recipe"
assert the recipe type of {_recipe} is transmute recipe with "Retrieved recipe is not a transmute recipe"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants