From b9534e1c48e3499555fcc9a8ae802903975efbd5 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 15 Feb 2022 18:48:54 +1100 Subject: [PATCH] #1009: Add Furnace#getRecipesUsed By: Doc --- .../block/entity/TileEntityFurnace.patch | 20 +++++++++++-------- .../craftbukkit/block/CraftFurnace.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch index 64ae78b309..15aeaad1f4 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch @@ -21,7 +21,7 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements IWorldInventory, RecipeHolder, AutoRecipeOutput { protected static final int SLOT_INPUT = 0; -@@ -182,6 +196,36 @@ +@@ -182,6 +196,40 @@ return map; } @@ -53,12 +53,16 @@ + public void setMaxStackSize(int size) { + maxStack = size; + } ++ ++ public Object2IntOpenHashMap getRecipesUsed() { ++ return this.recipesUsed; // PAIL private -> public ++ } + // CraftBukkit end + private static boolean isNeverAFurnaceFuel(Item item) { return TagsItem.NON_FLAMMABLE_WOOD.contains(item); } -@@ -265,13 +309,24 @@ +@@ -265,13 +313,24 @@ tileentityfurnace.cookingProgress = MathHelper.clamp(tileentityfurnace.cookingProgress - 2, (int) 0, tileentityfurnace.cookingTotalTime); } } else { @@ -86,7 +90,7 @@ flag1 = true; if (!itemstack.isEmpty()) { Item item = itemstack.getItem(); -@@ -287,11 +342,23 @@ +@@ -287,11 +346,23 @@ } if (tileentityfurnace.isLit() && canBurn(irecipe, tileentityfurnace.items, i)) { @@ -111,7 +115,7 @@ tileentityfurnace.setRecipeUsed(irecipe); } -@@ -330,17 +397,44 @@ +@@ -330,17 +401,44 @@ } } @@ -157,7 +161,7 @@ if (itemstack.is(Blocks.WET_SPONGE.asItem()) && !((ItemStack) nonnulllist.get(1)).isEmpty() && ((ItemStack) nonnulllist.get(1)).is(Items.BUCKET)) { nonnulllist.set(1, new ItemStack(Items.WATER_BUCKET)); -@@ -364,7 +458,7 @@ +@@ -364,7 +462,7 @@ } private static int getTotalCookTime(World world, Recipes recipes, IInventory iinventory) { @@ -166,7 +170,7 @@ } public static boolean isFuel(ItemStack itemstack) { -@@ -483,14 +577,20 @@ +@@ -483,14 +581,20 @@ @Override public void awardUsedRecipes(EntityHuman entityhuman) {} @@ -189,7 +193,7 @@ List> list = Lists.newArrayList(); ObjectIterator objectiterator = this.recipesUsed.object2IntEntrySet().iterator(); -@@ -499,14 +599,14 @@ +@@ -499,14 +603,14 @@ worldserver.getRecipeManager().byKey((MinecraftKey) entry.getKey()).ifPresent((irecipe) -> { list.add(irecipe); @@ -206,7 +210,7 @@ int j = MathHelper.floor((float) i * f); float f1 = MathHelper.frac((float) i * f); -@@ -514,6 +614,17 @@ +@@ -514,6 +618,17 @@ ++j; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java index 5746082f5e..2c251acf34 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java @@ -1,11 +1,18 @@ package org.bukkit.craftbukkit.block; +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import net.minecraft.resources.MinecraftKey; import net.minecraft.world.level.block.BlockFurnace; import net.minecraft.world.level.block.entity.TileEntityFurnace; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.block.Furnace; import org.bukkit.craftbukkit.inventory.CraftInventoryFurnace; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.inventory.CookingRecipe; import org.bukkit.inventory.FurnaceInventory; +import org.bukkit.inventory.Recipe; public abstract class CraftFurnace extends CraftContainer implements Furnace { @@ -58,4 +65,17 @@ public abstract class CraftFurnace extends CraftCon public void setCookTimeTotal(int cookTimeTotal) { this.getSnapshot().cookingTotalTime = cookTimeTotal; } + + @Override + public Map, Integer> getRecipesUsed() { + ImmutableMap.Builder, Integer> recipesUsed = ImmutableMap.builder(); + for (Map.Entry entrySet : this.getSnapshot().getRecipesUsed().object2IntEntrySet()) { + Recipe recipe = Bukkit.getRecipe(CraftNamespacedKey.fromMinecraft(entrySet.getKey())); + if (recipe instanceof CookingRecipe cookingRecipe) { + recipesUsed.put(cookingRecipe, entrySet.getValue()); + } + } + + return recipesUsed.build(); + } }