From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: tr7zw Date: Thu, 25 Jun 2020 23:40:12 +0200 Subject: [PATCH] Heavily optimize furnance fuel and recipe lookups diff --git a/src/main/java/net/minecraft/server/CraftingManager.java b/src/main/java/net/minecraft/server/CraftingManager.java index f27c7041cdc2f062f0abb222b02026194ab33c60..384cb3c62a3fb0972cf6058b219d1e0731a8dc0d 100644 --- a/src/main/java/net/minecraft/server/CraftingManager.java +++ b/src/main/java/net/minecraft/server/CraftingManager.java @@ -89,7 +89,24 @@ public class CraftingManager extends ResourceDataJson { }).findFirst(); c0.setCurrentRecipe(recipe.orElse(null)); // CraftBukkit - Clear recipe when no recipe is found // CraftBukkit end - return recipe; + // YAPFA start + if(c0.getCurrentRecipe() != null) { + Optional optional = recipes.a(c0.getCurrentRecipe(), world, c0); + if(optional.isPresent()) { + c0.setCurrentRecipe(optional.get()); + return optional; + } + } + for(IRecipe rep : this.a(recipes)) { + Optional optional = recipes.a(rep, world, c0); + if(optional.isPresent()) { + c0.setCurrentRecipe(optional.get()); + return optional; + } + } + c0.setCurrentRecipe(null); // CraftBukkit - Clear recipe when no recipe is found + return Optional.empty(); + // YAPFA end } public > List a(Recipes recipes) { diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java index 59aa2f8a797482c43fd47d3bce936772ad3cd6aa..7b1d20d395ffd264b23dccba230f5e6205796b56 100644 --- a/src/main/java/net/minecraft/server/TileEntityFurnace.java +++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java @@ -99,7 +99,13 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I this.c = recipes; } + //YAPFA + private static Map cachedFuelMap = null; + public static Map f() { + if(cachedFuelMap != null) { + return cachedFuelMap; // YAPFA + } Map map = Maps.newLinkedHashMap(); a(map, (IMaterial) Items.LAVA_BUCKET, 20000); @@ -162,6 +168,7 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I a(map, (IMaterial) Blocks.FLETCHING_TABLE, 300); a(map, (IMaterial) Blocks.SMITHING_TABLE, 300); a(map, (IMaterial) Blocks.COMPOSTER, 300); + cachedFuelMap = map; // YAPFA return map; } @@ -613,4 +620,19 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I } } + + // YAPFA start + private IRecipe cachedRecipe = null; + @Override + public IRecipe getCurrentRecipe() { + return cachedRecipe; + } + @Override + public void setCurrentRecipe(IRecipe recipe) { + cachedRecipe = recipe; + } + + + // YAPFA end + }