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 2cbfef98508bcb07db1ad1e5bdafc4cc2bff1393..64adf87f2fe9921e49bf7a76170bb9908dfdaf19 100644 --- a/src/main/java/net/minecraft/server/CraftingManager.java +++ b/src/main/java/net/minecraft/server/CraftingManager.java @@ -83,7 +83,22 @@ public class CraftingManager extends ResourceDataJson { }).findFirst(); c0.setCurrentRecipe(recipe.orElse(null)); // CraftBukkit - Clear recipe when no recipe is found // CraftBukkit end - return recipe; + // Yatopia start + if (c0.getCurrentRecipe() != null) { + Optional optional = recipes.a(c0.getCurrentRecipe(), world, c0); + optional.ifPresent(c0::setCurrentRecipe); + 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(); + // Yatopia 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 99bd8626b28a837f0da2268d89fddb6d28b2a944..ef008d7e1527bde01c4a66f86ecc16492026871f 100644 --- a/src/main/java/net/minecraft/server/TileEntityFurnace.java +++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java @@ -83,7 +83,14 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I this.c = recipes; } + private static Object2IntOpenHashMap cachedFuelMap = null; // Yatopia + public static Map f() { + // Yatopia start + if(cachedFuelMap != null) { + return cachedFuelMap; + } + // Yatopia end Map map = Maps.newLinkedHashMap(); a(map, (IMaterial) Items.LAVA_BUCKET, 20000); @@ -146,6 +153,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 = new Object2IntOpenHashMap<>(map); // Yatopia return map; } @@ -599,4 +607,17 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements I } } + + // Yatopia start + private IRecipe cachedRecipe = null; + @Override + public IRecipe getCurrentRecipe() { + return cachedRecipe; + } + @Override + public void setCurrentRecipe(IRecipe recipe) { + cachedRecipe = recipe; + } + // Yatopia end + }