From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Ivan Pekov Date: Wed, 26 Aug 2020 10:48:41 +0300 Subject: [PATCH] Fix recipe crash Caused due to slow streams, was kabooming tps when you were crafting F A S T diff --git a/src/main/java/net/minecraft/server/CraftingManager.java b/src/main/java/net/minecraft/server/CraftingManager.java index 64adf87f2fe9921e49bf7a76170bb9908dfdaf19..09b8065156a66a72ad5d09c6e8be0551970ffb56 100644 --- a/src/main/java/net/minecraft/server/CraftingManager.java +++ b/src/main/java/net/minecraft/server/CraftingManager.java @@ -78,9 +78,15 @@ public class CraftingManager extends ResourceDataJson { public > Optional craft(Recipes recipes, C c0, World world) { // CraftBukkit start + // Yatopia start - replace stream + Collection> collection = this.b(recipes).values(); + Optional recipe = collection.isEmpty() ? Optional.empty() : recipes.a(collection.iterator().next(), world, c0); + /* Optional recipe = this.b(recipes).values().stream().flatMap((irecipe) -> { return SystemUtils.a(recipes.a(irecipe, world, c0)); }).findFirst(); + */ + // Yatopia end c0.setCurrentRecipe(recipe.orElse(null)); // CraftBukkit - Clear recipe when no recipe is found // CraftBukkit end // Yatopia start @@ -111,11 +117,20 @@ public class CraftingManager extends ResourceDataJson { } public > List b(Recipes recipes, C c0, World world) { + // Yatopia start - WHY?! WHO DID THIS TO YOU!?! + Collection> recipeCollection = this.b(recipes).values(); + if (recipeCollection.isEmpty()) return java.util.Collections.emptyList(); + List ret = new net.yatopia.server.list.GlueList<>(); + for (IRecipe iRecipe : recipeCollection) recipes.a(iRecipe, world, c0).ifPresent(ret::add); + ret.sort(Comparator.comparing((iRecipe) -> iRecipe.getResult().getTranslationKey())); + return ret; + /* return (List) this.b(recipes).values().stream().flatMap((irecipe) -> { return SystemUtils.a(recipes.a(irecipe, world, c0)); }).sorted(Comparator.comparing((irecipe) -> { return irecipe.getResult().j(); })).collect(Collectors.toList()); + */ // Yatopia end } private > Map> b(Recipes recipes) { diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java index 3adb29f004d2fee36f3ee9b21ee5417e84b64837..dbb2fee9f48e99ccaa6382563227c722e04797e9 100644 --- a/src/main/java/net/minecraft/server/ItemStack.java +++ b/src/main/java/net/minecraft/server/ItemStack.java @@ -570,6 +570,7 @@ public final class ItemStack { return !this.e() ? this.doMaterialsMatch(itemstack) : !itemstack.isEmpty() && this.getItem() == itemstack.getItem(); } + public final String getTranslationKey() { return j(); } // Yatopia public String j() { return this.getItem().f(this); }