Paper/patches/server/0658-Furnace-RecipesUsed-API.patch

49 lines
2.8 KiB
Diff
Raw Permalink Normal View History

2022-02-19 23:00:33 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 13 Jan 2022 15:20:47 -0800
Subject: [PATCH] Furnace RecipesUsed API
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
2024-10-25 17:08:48 +02:00
index 7b5f35779ac63b5f9b3a88cc4dcde38147fea2b7..e8d57a9497d545a84955eb3d0240844ae8276c08 100644
2022-02-19 23:00:33 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java
2024-10-23 22:52:43 +02:00
@@ -103,5 +103,37 @@ public abstract class CraftFurnace<T extends AbstractFurnaceBlockEntity> extends
2022-02-19 23:00:33 +01:00
snapshot.cookSpeedMultiplier = multiplier;
2024-10-25 17:08:48 +02:00
snapshot.cookingTotalTime = AbstractFurnaceBlockEntity.getTotalCookTime(this.isPlaced() ? this.world.getHandle() : null, snapshot, snapshot.recipeType, snapshot.cookSpeedMultiplier); // Update the snapshot's current total cook time to scale with the newly set multiplier
2022-02-19 23:00:33 +01:00
}
+
+ @Override
+ public int getRecipeUsedCount(org.bukkit.NamespacedKey furnaceRecipe) {
2024-10-25 17:08:48 +02:00
+ return this.getSnapshot().recipesUsed.getInt(io.papermc.paper.util.MCUtil.toResourceKey(net.minecraft.core.registries.Registries.RECIPE, furnaceRecipe));
2022-02-19 23:00:33 +01:00
+ }
+
+ @Override
+ public boolean hasRecipeUsedCount(org.bukkit.NamespacedKey furnaceRecipe) {
2024-10-25 17:08:48 +02:00
+ return this.getSnapshot().recipesUsed.containsKey(io.papermc.paper.util.MCUtil.toResourceKey(net.minecraft.core.registries.Registries.RECIPE, furnaceRecipe));
2022-02-19 23:00:33 +01:00
+ }
+
+ @Override
+ public void setRecipeUsedCount(org.bukkit.inventory.CookingRecipe<?> furnaceRecipe, int count) {
2024-10-25 17:08:48 +02:00
+ final var location = io.papermc.paper.util.MCUtil.toResourceKey(net.minecraft.core.registries.Registries.RECIPE, furnaceRecipe.getKey());
+ java.util.Optional<net.minecraft.world.item.crafting.RecipeHolder<?>> nmsRecipe = (this.isPlaced() ? this.world.getHandle().recipeAccess() : net.minecraft.server.MinecraftServer.getServer().getRecipeManager()).byKey(location);
2023-09-22 19:31:02 +02:00
+ com.google.common.base.Preconditions.checkArgument(nmsRecipe.isPresent() && nmsRecipe.get().value() instanceof net.minecraft.world.item.crafting.AbstractCookingRecipe, furnaceRecipe.getKey() + " is not recognized as a valid and registered furnace recipe");
2022-02-19 23:00:33 +01:00
+ if (count > 0) {
2024-10-25 17:08:48 +02:00
+ this.getSnapshot().recipesUsed.put(location, count);
2022-02-19 23:00:33 +01:00
+ } else {
2024-10-25 17:08:48 +02:00
+ this.getSnapshot().recipesUsed.removeInt(location);
2022-02-19 23:00:33 +01:00
+ }
+ }
+
+ @Override
+ public void setRecipesUsed(java.util.Map<org.bukkit.inventory.CookingRecipe<?>, Integer> recipesUsed) {
2024-10-25 17:08:48 +02:00
+ this.getSnapshot().recipesUsed.clear();
2022-02-19 23:00:33 +01:00
+ recipesUsed.forEach((recipe, integer) -> {
+ if (integer != null) {
+ this.setRecipeUsedCount(recipe, integer);
+ }
+ });
+ }
// Paper end
}