Yatopia/patches/server/0037-Fix-recipe-crash.patch
Ivan Pekov d065d41c0e
Drop this unsafe shit
Apparently caused issues we werent aware of.
Unfortunately there's no way to improve it without blocking the main thread.
2020-10-02 17:00:13 +03:00

61 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
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 <C extends IInventory, T extends IRecipe<C>> Optional<T> craft(Recipes<T> recipes, C c0, World world) {
// CraftBukkit start
+ // Yatopia start - replace stream
+ Collection<IRecipe<C>> collection = this.b(recipes).values();
+ Optional<T> recipe = collection.isEmpty() ? Optional.empty() : recipes.a(collection.iterator().next(), world, c0);
+ /*
Optional<T> 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 <C extends IInventory, T extends IRecipe<C>> List<T> b(Recipes<T> recipes, C c0, World world) {
+ // Yatopia start - WHY?! WHO DID THIS TO YOU!?!
+ Collection<IRecipe<C>> recipeCollection = this.b(recipes).values();
+ if (recipeCollection.isEmpty()) return java.util.Collections.emptyList();
+ List<T> ret = new net.yatopia.server.list.GlueList<>();
+ for (IRecipe<C> 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 <C extends IInventory, T extends IRecipe<C>> Map<MinecraftKey, IRecipe<C>> b(Recipes<T> 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);
}