mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 12:02:36 +01:00
1b34737612
By: md_5 <git@md-5.net>
129 lines
5.7 KiB
Diff
129 lines
5.7 KiB
Diff
--- a/net/minecraft/world/item/crafting/CraftingManager.java
|
|
+++ b/net/minecraft/world/item/crafting/CraftingManager.java
|
|
@@ -34,11 +34,13 @@
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
+import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; // CraftBukkit
|
|
+
|
|
public class CraftingManager extends ResourceDataJson {
|
|
|
|
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
- public Map<Recipes<?>, Map<MinecraftKey, IRecipe<?>>> recipes = ImmutableMap.of();
|
|
+ public Map<Recipes<?>, Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>>> recipes = ImmutableMap.of(); // CraftBukkit
|
|
private boolean hasErrors;
|
|
|
|
public CraftingManager() {
|
|
@@ -47,7 +49,12 @@
|
|
|
|
protected void a(Map<MinecraftKey, JsonElement> map, IResourceManager iresourcemanager, GameProfilerFiller gameprofilerfiller) {
|
|
this.hasErrors = false;
|
|
- Map<Recipes<?>, Builder<MinecraftKey, IRecipe<?>>> map1 = Maps.newHashMap();
|
|
+ // CraftBukkit start - SPIGOT-5667 make sure all types are populated and mutable
|
|
+ Map<Recipes<?>, Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>>> map1 = Maps.newHashMap();
|
|
+ for (Recipes<?> recipeType : IRegistry.RECIPE_TYPE) {
|
|
+ map1.put(recipeType, new Object2ObjectLinkedOpenHashMap<>());
|
|
+ }
|
|
+ // CraftBukkit end
|
|
Iterator iterator = map.entrySet().iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
@@ -57,8 +64,10 @@
|
|
try {
|
|
IRecipe<?> irecipe = a(minecraftkey, ChatDeserializer.m((JsonElement) entry.getValue(), "top element"));
|
|
|
|
- ((Builder) map1.computeIfAbsent(irecipe.g(), (recipes) -> {
|
|
- return ImmutableMap.builder();
|
|
+ // CraftBukkit start
|
|
+ (map1.computeIfAbsent(irecipe.g(), (recipes) -> {
|
|
+ return new Object2ObjectLinkedOpenHashMap<>();
|
|
+ // CraftBukkit end
|
|
})).put(minecraftkey, irecipe);
|
|
} catch (IllegalArgumentException | JsonParseException jsonparseexception) {
|
|
CraftingManager.LOGGER.error("Parsing error loading recipe {}", minecraftkey, jsonparseexception);
|
|
@@ -66,19 +75,35 @@
|
|
}
|
|
|
|
this.recipes = (Map) map1.entrySet().stream().collect(ImmutableMap.toImmutableMap(Entry::getKey, (entry1) -> {
|
|
- return ((Builder) entry1.getValue()).build();
|
|
+ return (entry1.getValue()); // CraftBukkit
|
|
}));
|
|
CraftingManager.LOGGER.info("Loaded {} recipes", map1.size());
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ public void addRecipe(IRecipe<?> irecipe) {
|
|
+ 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 {
|
|
+ map.putAndMoveToFirst(irecipe.getKey(), irecipe); // CraftBukkit - SPIGOT-4638: last recipe gets priority
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
public boolean a() {
|
|
return this.hasErrors;
|
|
}
|
|
|
|
public <C extends IInventory, T extends IRecipe<C>> Optional<T> craft(Recipes<T> recipes, C c0, World world) {
|
|
- return this.b(recipes).values().stream().flatMap((irecipe) -> {
|
|
+ // CraftBukkit start
|
|
+ Optional<T> recipe = this.b(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;
|
|
}
|
|
|
|
public <C extends IInventory, T extends IRecipe<C>> List<T> a(Recipes<T> recipes) {
|
|
@@ -96,7 +121,7 @@
|
|
}
|
|
|
|
private <C extends IInventory, T extends IRecipe<C>> Map<MinecraftKey, IRecipe<C>> b(Recipes<T> recipes) {
|
|
- return (Map) this.recipes.getOrDefault(recipes, Collections.emptyMap());
|
|
+ return (Map) this.recipes.getOrDefault(recipes, new Object2ObjectLinkedOpenHashMap<>()); // CraftBukkit
|
|
}
|
|
|
|
public <C extends IInventory, T extends IRecipe<C>> NonNullList<ItemStack> c(Recipes<T> recipes, C c0, World world) {
|
|
@@ -117,7 +142,7 @@
|
|
|
|
public Optional<? extends IRecipe<?>> getRecipe(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();
|
|
}
|
|
|
|
@@ -143,11 +168,11 @@
|
|
|
|
public void a(Iterable<IRecipe<?>> iterable) {
|
|
this.hasErrors = false;
|
|
- Map<Recipes<?>, Map<MinecraftKey, IRecipe<?>>> map = Maps.newHashMap();
|
|
+ Map<Recipes<?>, Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>>> map = Maps.newHashMap(); // CraftBukkit
|
|
|
|
iterable.forEach((irecipe) -> {
|
|
Map<MinecraftKey, IRecipe<?>> map1 = (Map) map.computeIfAbsent(irecipe.g(), (recipes) -> {
|
|
- return Maps.newHashMap();
|
|
+ return new Object2ObjectLinkedOpenHashMap<>(); // CraftBukkit
|
|
});
|
|
IRecipe<?> irecipe1 = (IRecipe) map1.put(irecipe.getKey(), irecipe);
|
|
|
|
@@ -157,4 +182,14 @@
|
|
});
|
|
this.recipes = ImmutableMap.copyOf(map);
|
|
}
|
|
+
|
|
+ // CraftBukkit start
|
|
+ public void clearRecipes() {
|
|
+ this.recipes = Maps.newHashMap();
|
|
+
|
|
+ for (Recipes<?> recipeType : IRegistry.RECIPE_TYPE) {
|
|
+ this.recipes.put(recipeType, new Object2ObjectLinkedOpenHashMap<>());
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|