2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/item/crafting/CraftingManager.java
+++ b/net/minecraft/world/item/crafting/CraftingManager.java
2024-04-23 17:15:00 +02:00
@@ -34,6 +34,11 @@
2022-02-28 16:00:00 +01:00
import net.minecraft.world.level.World;
import org.slf4j.Logger;
2019-06-21 12:00:00 +02:00
2023-12-05 17:40:00 +01:00
+// CraftBukkit start
2024-04-23 17:15:00 +02:00
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Maps;
2023-12-05 17:40:00 +01:00
+// CraftBukkit end
2019-06-21 12:00:00 +02:00
+
public class CraftingManager extends ResourceDataJson {
2021-06-11 07:00:00 +02:00
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
2024-06-13 17:05:00 +02:00
@@ -70,11 +75,26 @@
2024-04-23 17:15:00 +02:00
}
2019-02-26 01:17:42 +01:00
}
2019-06-21 12:00:00 +02:00
2024-04-23 17:15:00 +02:00
- this.byType = builder.build();
- this.byName = com_google_common_collect_immutablemap_builder.build();
+ // CraftBukkit start - mutable
+ this.byType = LinkedHashMultimap.create(builder.build());
+ this.byName = Maps.newHashMap(com_google_common_collect_immutablemap_builder.build());
+ // CraftBukkit end
CraftingManager.LOGGER.info("Loaded {} recipes", this.byType.size());
2019-02-26 01:17:42 +01:00
}
2019-06-21 12:00:00 +02:00
+ // CraftBukkit start
2023-09-21 18:40:00 +02:00
+ public void addRecipe(RecipeHolder<?> irecipe) {
2024-04-23 17:15:00 +02:00
+ Collection<RecipeHolder<?>> map = this.byType.get(irecipe.value().getType()); // CraftBukkit
2019-06-21 12:00:00 +02:00
+
2024-04-23 17:15:00 +02:00
+ if (byName.containsKey(irecipe.id())) {
2023-09-21 18:40:00 +02:00
+ throw new IllegalStateException("Duplicate recipe ignored with ID " + irecipe.id());
2019-06-21 12:00:00 +02:00
+ } else {
2024-04-23 17:15:00 +02:00
+ map.add(irecipe);
2023-09-21 18:40:00 +02:00
+ byName.put(irecipe.id(), irecipe);
2019-06-21 12:00:00 +02:00
+ }
+ }
+ // CraftBukkit end
+
2021-11-21 23:00:00 +01:00
public boolean hadErrorsLoading() {
2021-06-11 07:00:00 +02:00
return this.hasErrors;
}
2024-06-13 17:05:00 +02:00
@@ -90,9 +110,13 @@
2019-04-23 04:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
2024-06-13 17:05:00 +02:00
public <I extends RecipeInput, T extends IRecipe<I>> Optional<RecipeHolder<T>> getRecipeFor(Recipes<T> recipes, I i0, World world, @Nullable RecipeHolder<T> recipeholder) {
- return i0.isEmpty() ? Optional.empty() : (recipeholder != null && recipeholder.value().matches(i0, world) ? Optional.of(recipeholder) : this.byType(recipes).stream().filter((recipeholder1) -> {
2024-04-23 17:15:00 +02:00
+ // CraftBukkit start
+ List<RecipeHolder<T>> list = this.byType(recipes).stream().filter((recipeholder1) -> {
2024-06-13 17:05:00 +02:00
return recipeholder1.value().matches(i0, world);
- }).findFirst());
2024-04-23 17:15:00 +02:00
+ }).toList();
2024-06-13 17:05:00 +02:00
+ Optional<RecipeHolder<T>> recipe = (list.isEmpty() || i0.isEmpty()) ? Optional.empty() : (recipeholder != null && recipeholder.value().matches(i0, world) ? Optional.of(recipeholder) : Optional.of(list.getLast())); // CraftBukkit - SPIGOT-4638: last recipe gets priority
2024-04-23 17:15:00 +02:00
+ return recipe;
+ // CraftBukkit end
}
2024-06-13 17:05:00 +02:00
public <I extends RecipeInput, T extends IRecipe<I>> List<RecipeHolder<T>> getAllRecipesFor(Recipes<T> recipes) {
@@ -108,7 +132,7 @@
2019-04-23 04:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
2024-06-13 17:05:00 +02:00
private <I extends RecipeInput, T extends IRecipe<I>> Collection<RecipeHolder<T>> byType(Recipes<T> recipes) {
2024-04-23 17:15:00 +02:00
- return this.byType.get(recipes);
+ return (Collection) this.byType.get(recipes); // CraftBukkit - decompile error
2019-04-23 04:00:00 +02:00
}
2015-02-26 23:41:06 +01:00
2024-06-13 17:05:00 +02:00
public <I extends RecipeInput, T extends IRecipe<I>> NonNullList<ItemStack> getRemainingItemsFor(Recipes<T> recipes, I i0, World world) {
@@ -135,7 +159,7 @@
2024-04-23 17:15:00 +02:00
private <T extends IRecipe<?>> RecipeHolder<T> byKeyTyped(Recipes<T> recipes, MinecraftKey minecraftkey) {
RecipeHolder<?> recipeholder = (RecipeHolder) this.byName.get(minecraftkey);
2021-06-11 07:00:00 +02:00
2024-04-23 17:15:00 +02:00
- return recipeholder != null && recipeholder.value().getType().equals(recipes) ? recipeholder : null;
+ return recipeholder != null && recipeholder.value().getType().equals(recipes) ? (RecipeHolder) recipeholder : null; // CraftBukkit - decompile error
}
2021-06-11 07:00:00 +02:00
2024-04-23 17:15:00 +02:00
public Collection<RecipeHolder<?>> getOrderedRecipes() {
2024-06-13 17:05:00 +02:00
@@ -171,10 +195,31 @@
2024-04-23 17:15:00 +02:00
com_google_common_collect_immutablemap_builder.put(recipeholder.id(), recipeholder);
}
- this.byType = builder.build();
- this.byName = com_google_common_collect_immutablemap_builder.build();
+ // CraftBukkit start - mutable
+ this.byType = LinkedHashMultimap.create(builder.build());
+ this.byName = Maps.newHashMap(com_google_common_collect_immutablemap_builder.build());
+ // CraftBukkit end
2024-06-13 17:05:00 +02:00
+ }
+
2019-06-21 12:00:00 +02:00
+ // CraftBukkit start
2021-12-13 01:25:22 +01:00
+ public boolean removeRecipe(MinecraftKey mcKey) {
2024-04-23 17:15:00 +02:00
+ Iterator<RecipeHolder<?>> iter = byType.values().iterator();
+ while (iter.hasNext()) {
+ RecipeHolder<?> recipe = iter.next();
+ if (recipe.id().equals(mcKey)) {
+ iter.remove();
+ }
2021-12-13 01:25:22 +01:00
+ }
+
+ return byName.remove(mcKey) != null;
2024-06-13 17:05:00 +02:00
}
2019-06-22 10:24:23 +02:00
+ public void clearRecipes() {
2024-04-23 17:15:00 +02:00
+ this.byType = LinkedHashMultimap.create();
2021-11-24 22:00:00 +01:00
+ this.byName = Maps.newHashMap();
2023-09-21 18:57:13 +02:00
+ }
2019-06-21 12:00:00 +02:00
+ // CraftBukkit end
2023-09-21 18:57:13 +02:00
+
2024-06-13 17:05:00 +02:00
public static <I extends RecipeInput, T extends IRecipe<I>> CraftingManager.a<I, T> createCheck(final Recipes<T> recipes) {
return new CraftingManager.a<I, T>() {
2023-09-21 18:57:13 +02:00
@Nullable