3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-22 22:38:17 +01:00
Paper/nms-patches/CraftingManager.patch

74 Zeilen
3.5 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/CraftingManager.java
+++ b/net/minecraft/server/CraftingManager.java
2019-04-23 04:00:00 +02:00
@@ -26,7 +26,7 @@
2019-04-25 04:00:00 +02:00
private static final Logger LOGGER = LogManager.getLogger();
public static final int a = "recipes/".length();
public static final int b = ".json".length();
2019-04-25 04:00:00 +02:00
- public Map<Recipes<?>, Map<MinecraftKey, IRecipe<?>>> recipes = (Map) SystemUtils.a((Object) Maps.newHashMap(), CraftingManager::initializeRecipeMap);
+ public Map<Recipes<?>, it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>>> recipes = SystemUtils.a(Maps.newHashMap(), CraftingManager::initializeRecipeMap); // CraftBukkit
private boolean e;
public CraftingManager() {}
2019-04-23 04:00:00 +02:00
@@ -88,19 +88,23 @@
}
public void addRecipe(IRecipe<?> irecipe) {
- Map<MinecraftKey, IRecipe<?>> map = (Map) this.recipes.get(irecipe.g());
+ it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>> map = this.recipes.get(irecipe.g()); // CraftBukkit
if (map.containsKey(irecipe.getKey())) {
throw new IllegalStateException("Duplicate recipe ignored with ID " + irecipe.getKey());
} else {
2019-04-23 04:00:00 +02:00
- map.put(irecipe.getKey(), irecipe);
+ map.putAndMoveToFirst(irecipe.getKey(), irecipe); // CraftBukkit - SPIGOT-4638: last recipe gets priority
}
}
2019-04-23 04:00:00 +02:00
public <C extends IInventory, T extends IRecipe<C>> Optional<T> craft(Recipes<T> recipes, C c0, World world) {
- return this.a(recipes).values().stream().flatMap((irecipe) -> {
+ // CraftBukkit start
+ Optional<T> recipe = this.a(recipes).values().stream().flatMap((irecipe) -> {
return SystemUtils.a(recipes.a(irecipe, world, c0));
}).findFirst();
+ c0.setCurrentRecipe(recipe.orElse(null)); // CraftBukkit - Clear recipe when no recipe is found
+ // CraftBukkit end
+ return recipe;
}
2019-04-23 04:00:00 +02:00
public <C extends IInventory, T extends IRecipe<C>> List<T> b(Recipes<T> recipes, C c0, World world) {
@@ -112,7 +116,7 @@
}
2019-04-23 04:00:00 +02:00
private <C extends IInventory, T extends IRecipe<C>> Map<MinecraftKey, IRecipe<C>> a(Recipes<T> recipes) {
- return (Map) this.recipes.getOrDefault(recipes, Maps.newHashMap());
+ return (Map) this.recipes.getOrDefault(recipes, new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>()); // CraftBukkit
}
2015-02-26 23:41:06 +01:00
2019-04-23 04:00:00 +02:00
public <C extends IInventory, T extends IRecipe<C>> NonNullList<ItemStack> c(Recipes<T> recipes, C c0, World world) {
@@ -133,7 +137,7 @@
public Optional<? extends IRecipe<?>> a(MinecraftKey minecraftkey) {
return this.recipes.values().stream().map((map) -> {
- return (IRecipe) map.get(minecraftkey);
+ return map.get(minecraftkey); // CraftBukkit - decompile error
}).filter(Objects::nonNull).findFirst();
2017-05-14 04:00:00 +02:00
}
2019-04-23 04:00:00 +02:00
@@ -157,14 +161,14 @@
})).a(minecraftkey, jsonobject);
}
2017-05-14 04:00:00 +02:00
2019-04-25 04:00:00 +02:00
- public static void initializeRecipeMap(Map<Recipes<?>, Map<MinecraftKey, IRecipe<?>>> map) {
+ public static void initializeRecipeMap(Map<Recipes<?>, it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>>> map) { // CraftBukkit
2019-04-23 04:00:00 +02:00
map.clear();
Iterator iterator = IRegistry.RECIPE_TYPE.iterator();
2017-05-14 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
while (iterator.hasNext()) {
Recipes<?> recipes = (Recipes) iterator.next();
2017-05-14 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
- map.put(recipes, Maps.newHashMap());
+ map.put(recipes, new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>()); // CraftBukkit
}
2017-05-14 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
}