Skip to content

Commit

Permalink
Heavily optimize furnance fuel and recipe lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
Toffikk committed Jun 23, 2021
1 parent a383663 commit cb9a859
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Thu, 25 Jun 2020 23:40:12 +0200
Subject: [PATCH] Heavily optimize furnance fuel and recipe lookups

From Yatopia
Co-authored-by: Mykyta Komarn <nkomarn@hotmail.com>
Updated to 1.17 by: Toffikk <slodkitofik@gmail.com>

diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
index c559ec5041474e585e4d95a664c84e1fa895cf16..0dc25a12bc487895bb9a8d08acedb247d318c912 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
@@ -322,7 +322,11 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
blockEntity.cookingProgress = Mth.clamp(blockEntity.cookingProgress - 2, 0, blockEntity.cookingTotalTime);
}
} else {
- Recipe<?> irecipe = (Recipe) world.getRecipeManager().getRecipeFor((RecipeType<AbstractCookingRecipe>) blockEntity.recipeType, blockEntity, world).orElse(null); // CraftBukkit - decompile error // Eclipse fail
+ // Recipe<?> irecipe = (Recipe) world.getRecipeManager().getRecipeFor((RecipeType<AbstractCookingRecipe>) blockEntity.recipeType, blockEntity, world).orElse(null); // CraftBukkit - decompile error // Eclipse fail // Sugarcane - use cached recipe if possible, otherwise look up
+ // Sugarcane start - use cached recipe if possible, otherwise look up
+ Recipe<?> irecipe = blockEntity.getCurrentRecipe();
+ if (irecipe == null) irecipe = (Recipe) world.getRecipeManager().getRecipeFor((RecipeType<AbstractCookingRecipe>) blockEntity.recipeType, blockEntity, world).orElse(null); // CraftBukkit - decompile error // Eclipse fail // Sugarcane - use cached recipe if possible, otherwise look up
+ // Sugarcane end
int i = blockEntity.getMaxStackSize();

if (!blockEntity.isLit() && AbstractFurnaceBlockEntity.canBurn(irecipe, blockEntity.items, i)) {
@@ -644,4 +648,17 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
}

}
+ // Sugarcane start - cache recipe
+ private Recipe cachedRecipe = null;
+
+ @Override
+ public Recipe getCurrentRecipe() {
+ return cachedRecipe;
+ }
+
+ @Override
+ public void setCurrentRecipe(Recipe recipe) {
+ cachedRecipe = recipe;
+ }
+ // Sugarcane end
}

0 comments on commit cb9a859

Please sign in to comment.