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

Refactor Fire Crafting Handler #749

Open
Rover656 opened this issue Jul 18, 2024 · 0 comments
Open

Refactor Fire Crafting Handler #749

Rover656 opened this issue Jul 18, 2024 · 0 comments
Labels
Area-Backend Backend work not usually visible to players. MC-1.21 Type-Enhancement New feature or enhancement to existing feature.

Comments

@Rover656
Copy link
Member

Copying from HenryLoenwind's comment on #740:

I just had a look at the handler out of curiosity, and it looks a bit wasteful. (Also very much as I remember it, so this probably is my fault.)

I'd suggest a couple of changes:

  • Put
    // Cache recipes
    if (!recipesCached) {
    cachedRecipes = level.getRecipeManager().getAllRecipesFor(EIORecipes.FIRE_CRAFTING.type().get());
    recipesCached = false;
    }
    // Search for this recipe.
    FireCraftingRecipe matchingRecipe = null;
    for (var recipeHolder : cachedRecipes) {
    var recipe = recipeHolder.value();
    if (recipe.isBaseValid(baseBlock) && recipe.isDimensionValid(level.dimension())) {
    matchingRecipe = recipe;
    break;
    }
    }
    if (matchingRecipe == null) {
    return;
    }
    into a getMatchingRecipe() method
  • Put if (getMatchingRecipe() != null) { ...} return; inside if (isFire) {
  • Surround spawnInfinityDrops(...) with a if (getMatchingRecipe() instanceof FireCraftingRecipe matchingRecipe) { (or if ((FireCraftingRecipe matchingRecipe = getMatchingRecipe()) != null) {)
  • Move the // Grab useful fields. stuff inside the two if blocks just above where it's needed. Sadly this means duplicating it, but this is not an event to be picky---NeighborNotifyEvents are fired very often.
  • I think the if (FIRE_TRACKER.isEmpty() && !isFire) { now has no benefit anymore.

And then ignore the complicated description above and look at what I cobbled up in a text editor: https://gist.github.com/HenryLoenwind/e276c7f437120011f1c84175496c531d

I think this would greatly reduce the time spent in this event handler.

@Rover656 Rover656 added Type-Enhancement New feature or enhancement to existing feature. Area-Backend Backend work not usually visible to players. MC-1.21 labels Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Backend Backend work not usually visible to players. MC-1.21 Type-Enhancement New feature or enhancement to existing feature.
Projects
Status: Ready
Development

No branches or pull requests

1 participant