Yatopia/patches/server/0016-Heavily-optimize-furnance-fuel-and-recipe-lookups.patch
2021-05-20 12:51:47 -04:00

43 lines
1.9 KiB
Diff

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
Co-authored-by: Mykyta Komarn <nkomarn@hotmail.com>
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TileEntityFurnace.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntityFurnace.java
index ac42fd627009a87709448354f232d8b5ed7fa6b9..8ec9ed518a3b5f70c5a5d74605a1f17d0f47b300 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/TileEntityFurnace.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntityFurnace.java
@@ -331,7 +331,10 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I
this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.cookTimeTotal);
}
} else {
- IRecipe irecipe = this.world.getCraftingManager().craft((Recipes<RecipeCooking>) this.c, this, this.world).orElse(null); // Eclipse fail
+ // Yatopia start - used cached recipe if possible, otherwise look up
+ IRecipe irecipe = getCurrentRecipe();
+ if (irecipe == null) irecipe = this.world.getCraftingManager().craft((Recipes<RecipeCooking>) this.c, this, this.world).orElse(null); // Eclipse fail
+ // Yatopia end
if (!this.isBurning() && this.canBurn(irecipe)) {
// CraftBukkit start
@@ -663,4 +666,18 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I
}
}
+
+ // Yatopia start - cache recipe
+ private IRecipe cachedRecipe = null;
+
+ @Override
+ public IRecipe getCurrentRecipe() {
+ return cachedRecipe;
+ }
+
+ @Override
+ public void setCurrentRecipe(IRecipe recipe) {
+ cachedRecipe = recipe;
+ }
+ // Yatopia end
}