Commits
md_5 authored 42a4fa96f04
1 1 | --- a/net/minecraft/world/item/crafting/RecipeMap.java |
2 2 | +++ b/net/minecraft/world/item/crafting/RecipeMap.java |
3 - | |
3 + | |
4 4 | import net.minecraft.resources.ResourceKey; |
5 5 | import net.minecraft.world.level.World; |
6 6 | |
7 7 | +// CraftBukkit start |
8 8 | +import com.google.common.collect.LinkedHashMultimap; |
9 9 | +import com.google.common.collect.Maps; |
10 + | +import java.util.LinkedHashMap; |
10 11 | +// CraftBukkit end |
11 12 | + |
12 13 | public class RecipeMap { |
13 14 | |
14 - | public static final RecipeMap EMPTY = new RecipeMap(ImmutableMultimap.of(), Map.of()); |
15 - | |
15 + | - public static final RecipeMap EMPTY = new RecipeMap(ImmutableMultimap.of(), Map.of()); |
16 + | + // CraftBukkit start - ordered |
17 + | + public static final RecipeMap EMPTY = new RecipeMap(ImmutableMultimap.of(), Maps.newLinkedHashMap()); |
18 + | public final Multimap<Recipes<?>, RecipeHolder<?>> byType; |
19 + | - private final Map<ResourceKey<IRecipe<?>>, RecipeHolder<?>> byKey; |
20 + | + private final LinkedHashMap<ResourceKey<IRecipe<?>>, RecipeHolder<?>> byKey; |
21 + | |
22 + | - private RecipeMap(Multimap<Recipes<?>, RecipeHolder<?>> multimap, Map<ResourceKey<IRecipe<?>>, RecipeHolder<?>> map) { |
23 + | + private RecipeMap(Multimap<Recipes<?>, RecipeHolder<?>> multimap, LinkedHashMap<ResourceKey<IRecipe<?>>, RecipeHolder<?>> map) { |
24 + | + // CraftBukkit end |
25 + | this.byType = multimap; |
26 + | this.byKey = map; |
27 + | } |
28 + | |
16 29 | com_google_common_collect_immutablemap_builder.put(recipeholder.id(), recipeholder); |
17 30 | } |
18 31 | |
19 32 | - return new RecipeMap(builder.build(), com_google_common_collect_immutablemap_builder.build()); |
20 - | + // CraftBukkit start - mutable |
21 - | + return new RecipeMap(LinkedHashMultimap.create(builder.build()), Maps.newHashMap(com_google_common_collect_immutablemap_builder.build())); |
33 + | + // CraftBukkit start - mutable, ordered |
34 + | + return new RecipeMap(LinkedHashMultimap.create(builder.build()), Maps.newLinkedHashMap(com_google_common_collect_immutablemap_builder.build())); |
22 35 | + } |
23 36 | + |
24 37 | + public void addRecipe(RecipeHolder<?> irecipe) { |
25 38 | + Collection<RecipeHolder<?>> map = this.byType.get(irecipe.value().getType()); |
26 39 | + |
27 40 | + if (byKey.containsKey(irecipe.id())) { |
28 41 | + throw new IllegalStateException("Duplicate recipe ignored with ID " + irecipe.id()); |
29 42 | + } else { |
30 43 | + map.add(irecipe); |
31 - | + byKey.put(irecipe.id(), irecipe); |
44 + | + byKey.putFirst(irecipe.id(), irecipe); // CraftBukkit - ordered |
32 45 | + } |
33 46 | } |
34 47 | |
35 48 | + public boolean removeRecipe(ResourceKey<IRecipe<?>> mcKey) { |
36 49 | + boolean removed = false; |
37 50 | + Iterator<RecipeHolder<?>> iter = byType.values().iterator(); |
38 51 | + while (iter.hasNext()) { |
39 52 | + RecipeHolder<?> recipe = iter.next(); |
40 53 | + if (recipe.id().equals(mcKey)) { |
41 54 | + iter.remove(); |