71 lines
2.8 KiB
Diff
71 lines
2.8 KiB
Diff
--- a/net/minecraft/world/item/crafting/RecipeMap.java
|
|
+++ b/net/minecraft/world/item/crafting/RecipeMap.java
|
|
@@ -10,13 +10,22 @@
|
|
import net.minecraft.resources.ResourceKey;
|
|
import net.minecraft.world.level.World;
|
|
|
|
+// CraftBukkit start
|
|
+import com.google.common.collect.LinkedHashMultimap;
|
|
+import com.google.common.collect.Maps;
|
|
+import java.util.Iterator;
|
|
+import java.util.LinkedHashMap;
|
|
+// CraftBukkit end
|
|
+
|
|
public class RecipeMap {
|
|
|
|
- public static final RecipeMap EMPTY = new RecipeMap(ImmutableMultimap.of(), Map.of());
|
|
+ // CraftBukkit start - ordered
|
|
+ public static final RecipeMap EMPTY = new RecipeMap(ImmutableMultimap.of(), Maps.newLinkedHashMap());
|
|
public final Multimap<Recipes<?>, RecipeHolder<?>> byType;
|
|
- private final Map<ResourceKey<IRecipe<?>>, RecipeHolder<?>> byKey;
|
|
+ private final LinkedHashMap<ResourceKey<IRecipe<?>>, RecipeHolder<?>> byKey;
|
|
|
|
- private RecipeMap(Multimap<Recipes<?>, RecipeHolder<?>> multimap, Map<ResourceKey<IRecipe<?>>, RecipeHolder<?>> map) {
|
|
+ private RecipeMap(Multimap<Recipes<?>, RecipeHolder<?>> multimap, LinkedHashMap<ResourceKey<IRecipe<?>>, RecipeHolder<?>> map) {
|
|
+ // CraftBukkit end
|
|
this.byType = multimap;
|
|
this.byKey = map;
|
|
}
|
|
@@ -30,11 +39,39 @@
|
|
immutablemap_builder.put(recipeholder.id(), recipeholder);
|
|
}
|
|
|
|
- return new RecipeMap(immutablemultimap_builder.build(), immutablemap_builder.build());
|
|
+ // CraftBukkit start - mutable, ordered
|
|
+ return new RecipeMap(LinkedHashMultimap.create(immutablemultimap_builder.build()), Maps.newLinkedHashMap(immutablemap_builder.build()));
|
|
}
|
|
|
|
+ public void addRecipe(RecipeHolder<?> irecipe) {
|
|
+ Collection<RecipeHolder<?>> map = this.byType.get(irecipe.value().getType());
|
|
+
|
|
+ if (byKey.containsKey(irecipe.id())) {
|
|
+ throw new IllegalStateException("Duplicate recipe ignored with ID " + irecipe.id());
|
|
+ } else {
|
|
+ map.add(irecipe);
|
|
+ byKey.putFirst(irecipe.id(), irecipe); // CraftBukkit - ordered
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public boolean removeRecipe(ResourceKey<IRecipe<?>> mcKey) {
|
|
+ boolean removed = false;
|
|
+ Iterator<RecipeHolder<?>> iter = byType.values().iterator();
|
|
+ while (iter.hasNext()) {
|
|
+ RecipeHolder<?> recipe = iter.next();
|
|
+ if (recipe.id().equals(mcKey)) {
|
|
+ iter.remove();
|
|
+ removed = true;
|
|
+ }
|
|
+ }
|
|
+ removed |= byKey.remove(mcKey) != null;
|
|
+
|
|
+ return removed;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
public <I extends RecipeInput, T extends IRecipe<I>> Collection<RecipeHolder<T>> byType(Recipes<T> recipes) {
|
|
- return this.byType.get(recipes);
|
|
+ return (Collection) this.byType.get(recipes); // CraftBukkit - decompile error
|
|
}
|
|
|
|
public Collection<RecipeHolder<?>> values() {
|