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 20 commits into
base: dev/feature
Choose a base branch
from

Conversation

TheAbsolutionism
Copy link

@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
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
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

src/main/resources/lang/default.lang Outdated Show resolved Hide resolved
Comment on lines +110 to +112
if (delayed.get()) {
Skript.error("Delays cannot be used within a 'register recipe' section.");
return false;
Copy link
Contributor

@Fusezion Fusezion Oct 16, 2024

Choose a reason for hiding this comment

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

Why not? Maybe I wanna add user input for these, there's nothing here that breaks

on jump:
	set {_player} to player
	register a new furnace recipe with id "why&*($^#&$(*^#&$*#":
		set recipe result to bedrock
		set recipe cooking time to 1 hour
		set recipe experience to 100
		set recipe group to "hand_holders"

		set {-RecipeBuilder::%{_player}%::waiting} to true
		send "What should be the recipe input (item), you have 5 seconds to respond":
		set {_now} to 5 second later
		while {-RecipeBuilder::%{_player}%::waiting} is true:
			if now >= {_now}:
				send "You didn't define the input in time, speed up your typing" to {_player}
				delete {-RecipeBuilder::%{_player}%::*}
				stop
			wait a tick
		set recipe input to {-RecipeBuilder::%{_player}%::waiting}
	delete {-RecipeBuilder::%{_player}%::*}

on chat:
	{-RecipeBuilder::%player%::waiting} is true
	set {_input} to uncolored message parsed as item
	if {_input} is set:
		set {-RecipeBuilder::%player%::waiting} to {_input}
		stop
	send "'%uncolored message%' is an invalid item"

More accurately I just don't see why a wait can't be done, this isn't a consumer like spawn event or anything else, this is a trigger, supporting waits should be fine and will not cause any issues

@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

@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.

lookin' better

@@ -1422,6 +1431,14 @@ public ItemStack get(CraftItemEvent e) {
return e.getRecipe().getResult();
}
}, 0);

EventValues.registerEventValue(CraftItemEvent.class, Recipe.class, new Getter<Recipe, CraftItemEvent>() {
Copy link
Member

Choose a reason for hiding this comment

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

move this to your event registration or the module's #load, same as the rest of em

Copy link
Member

Choose a reason for hiding this comment

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

can be moved to the module's package under util or just in the base package

Comment on lines +24 to +27
if (usingMinecraft)
namespacedKey = NamespacedKey.fromString(key);
else
namespacedKey = NamespacedKey.fromString(key, Skript.getInstance());
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
if (usingMinecraft)
namespacedKey = NamespacedKey.fromString(key);
else
namespacedKey = NamespacedKey.fromString(key, Skript.getInstance());
if (usingMinecraft) {
namespacedKey = NamespacedKey.fromString(key);
} else {
namespacedKey = NamespacedKey.fromString(key, Skript.getInstance());
}

more readable imo

* @param usingMinecraft whether to have it as Skript or Minecraft namespace
* @return the resulting NamespacedKey
*/
public static NamespacedKey getNamespacedKey(String key, Boolean usingMinecraft) {
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
public static NamespacedKey getNamespacedKey(String key, Boolean usingMinecraft) {
public static NamespacedKey getNamespacedKey(String key, boolean usingMinecraft) {

usingMinecraft has no reason to be nullable

else
namespacedKey = NamespacedKey.fromString(key, Skript.getInstance());
if (namespacedKey != null)
return namespacedKey;
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
return namespacedKey;
return namespacedKey;

@Since("INSERT VERSION")
public class SecRegisterRecipe extends Section {

private static final boolean RUNNING_1_20 = Skript.isRunningMinecraft(1, 20, 0);
Copy link
Member

Choose a reason for hiding this comment

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

maybe change to SUPPORTS_SMITHING as this better represents what the variable is used for

private boolean isEvent = false;

@Override
@SuppressWarnings("unchecked")
Copy link
Member

Choose a reason for hiding this comment

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

per statement

@Override
public String toString(@Nullable Event event, boolean debug) {
return "the recipe result item of " + getExpr().toString(event, debug);
}
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
}
}

}

@Override
@SuppressWarnings("unchecked")
Copy link
Member

Choose a reason for hiding this comment

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

ststata

@Override
public String toString(@Nullable Event event, boolean debug) {
return "the recipe type of " + getExpr().toString(event, debug);
}
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
}
}

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.

3 participants