Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@c2e2281 Initial 1.18 update PaperMC/Paper@12efc3f Fixes PaperMC/Paper@60af9b0 moar fixes PaperMC/Paper@19f9520 1.18.2 compiles successfuly now PaperMC/Paper@f4eb08a Readd 'Fix entity type tags suggestions in selectors' PaperMC/Paper@706c98a Update Datafixer PaperMC/Paper@02e2402 Update README PaperMC/Paper@c984991 Fix mc dev fix by removing it PaperMC/Paper@490517d fixed flat bedrock patch PaperMC/Paper@9da236f re-add config for stronghold seed patch PaperMC/Paper@9a73213 Adventure 4.10.0 PaperMC/Paper@37436ac Move comment up PaperMC/Paper@c6fc144 Fix unload stall PaperMC/Paper@fbe43d6 clean up patch changes PaperMC/Paper@3526f22 move patch relying on TraceUtil to after its creation PaperMC/Paper@fd74326 update reobf-mappings-patch.tiny PaperMC/Paper@5071d50 clean up view distance api diff PaperMC/Paper@cc45a35 move decompile fixes to start of git history PaperMC/Paper@146ac7b address failing mob goals test PaperMC/Paper@b9037a5 fix issue resulting from kenny's apatch addiction PaperMC/Paper@126ca73 Add TODO for leaf PaperMC/Paper@ab8a139 Configure javadoc overview and doc-files copying PaperMC/Paper@0859f59 1_18_R2 PaperMC/Paper@14add2b Updated Upstream (CraftBukkit) PaperMC/Paper@178802a Fix various 1.18.2 update issues (#7523) PaperMC/Paper@b1afebb Force close world loading screen on join (#7529) PaperMC/Paper@d3caeeb Fix early registry access in xray patch PaperMC/Paper@c6ea84c Drop unneeded desync patch PaperMC/Paper@12d89fe Revert chunk postprocessing back to 1.18.1 logic PaperMC/Paper@90788a5 clean up prepareTickingChunk diff PaperMC/Paper@d33cdcf Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@753bf2c Update paperweight to 1.3.5 PaperMC/Paper@15b6b3d Add StructuresLocateEvent as replacement for StructureLocateEvent (#7524) PaperMC/Paper@c09365a Fix deadlock on watchdog crash (#7535) PaperMC/Paper@719daa8 Updated Upstream (CraftBukkit) PaperMC/Paper@b9f26bb Add printPaperVersion task PaperMC/Paper@63aa4d3 Clarify exception messages for invalid view distances (#7510) PaperMC/Paper@0ee6dda Add javadoc linking for adventure-text-minimessage (#7538) PaperMC/Paper@b6616c8 Fix falling block spawn methods PaperMC/Paper@6d47843 replace bungeecord-chat dependency with deprecated version (#7539) PaperMC/Paper@42a9c37 Move Adventure patch up
233 lines
8.3 KiB
Diff
233 lines
8.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: lexikiq <noellekiq@gmail.com>
|
|
Date: Tue, 13 Jul 2021 17:27:45 -0400
|
|
Subject: [PATCH] Add Furnace Recipe API
|
|
|
|
Temporary API to get the result of smelting an item in a (type of) furnace.
|
|
|
|
Will eventually (hopefully) be replaced by a more extensive Paper PR with support for all recipes.
|
|
|
|
diff --git a/src/main/java/gg/projecteden/parchment/inventory/CraftRecipeType.java b/src/main/java/gg/projecteden/parchment/inventory/CraftRecipeType.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..5549da2a0b0790699abff627148a6b15ca37febf
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/projecteden/parchment/inventory/CraftRecipeType.java
|
|
@@ -0,0 +1,44 @@
|
|
+package gg.projecteden.parchment.inventory;
|
|
+
|
|
+import net.minecraft.world.item.crafting.AbstractCookingRecipe;
|
|
+
|
|
+public class CraftRecipeType {
|
|
+ public static net.minecraft.world.item.crafting.RecipeType asNMS(RecipeType recipeType) {
|
|
+ return switch (recipeType) {
|
|
+ case CRAFTING -> net.minecraft.world.item.crafting.RecipeType.CRAFTING;
|
|
+ case SMELTING -> net.minecraft.world.item.crafting.RecipeType.SMELTING;
|
|
+ case BLASTING -> net.minecraft.world.item.crafting.RecipeType.BLASTING;
|
|
+ case SMOKING -> net.minecraft.world.item.crafting.RecipeType.SMOKING;
|
|
+ case CAMPFIRE_COOKING -> net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING;
|
|
+ case STONECUTTING -> net.minecraft.world.item.crafting.RecipeType.STONECUTTING;
|
|
+ case SMITHING -> net.minecraft.world.item.crafting.RecipeType.SMITHING;
|
|
+ };
|
|
+ }
|
|
+
|
|
+ public static RecipeType asBukkit(net.minecraft.world.item.crafting.RecipeType recipeType) {
|
|
+ if (recipeType == net.minecraft.world.item.crafting.RecipeType.CRAFTING) {
|
|
+ return RecipeType.CRAFTING;
|
|
+ } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.SMELTING) {
|
|
+ return RecipeType.SMELTING;
|
|
+ } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.BLASTING) {
|
|
+ return RecipeType.BLASTING;
|
|
+ } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.SMOKING) {
|
|
+ return RecipeType.SMOKING;
|
|
+ } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING) {
|
|
+ return RecipeType.CAMPFIRE_COOKING;
|
|
+ } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.STONECUTTING) {
|
|
+ return RecipeType.STONECUTTING;
|
|
+ } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.SMITHING) {
|
|
+ return RecipeType.SMITHING;
|
|
+ }
|
|
+ throw new IllegalArgumentException("Unknown recipe type");
|
|
+ }
|
|
+
|
|
+ public static net.minecraft.world.item.crafting.RecipeType<AbstractCookingRecipe> asCookingRecipe(RecipeType recipeType) {
|
|
+ try {
|
|
+ return (net.minecraft.world.item.crafting.RecipeType<AbstractCookingRecipe>) asNMS(recipeType);
|
|
+ } catch (ClassCastException exc) {
|
|
+ throw new IllegalArgumentException("Recipe type must be a cooking recipe");
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/projecteden/parchment/inventory/SingletonContainer.java b/src/main/java/gg/projecteden/parchment/inventory/SingletonContainer.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..e7114e456f818d7bdd4081620f4b9b9376679145
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/projecteden/parchment/inventory/SingletonContainer.java
|
|
@@ -0,0 +1,151 @@
|
|
+package gg.projecteden.parchment.inventory;
|
|
+
|
|
+import com.google.common.base.Preconditions;
|
|
+import net.minecraft.world.Container;
|
|
+import net.minecraft.world.entity.player.Player;
|
|
+import net.minecraft.world.item.ItemStack;
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.Material;
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
+import org.bukkit.entity.HumanEntity;
|
|
+import org.bukkit.inventory.InventoryHolder;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+import java.util.Collections;
|
|
+import java.util.List;
|
|
+
|
|
+/**
|
|
+ * A container which holds only one item and returns similar values to that of
|
|
+ * {@link net.minecraft.world.SimpleContainer SimpleContainer}, meaning it will raise
|
|
+ * {@link IndexOutOfBoundsException IndexOutOfBoundsExceptions} and return empty item stacks
|
|
+ * where applicable to mirror that class.
|
|
+ */
|
|
+public class SingletonContainer implements net.minecraft.world.Container {
|
|
+
|
|
+ private @NotNull ItemStack item;
|
|
+ private int maxStackSize = Container.MAX_STACK;
|
|
+
|
|
+ public SingletonContainer() {
|
|
+ this.item = ItemStack.EMPTY;
|
|
+ }
|
|
+
|
|
+ public SingletonContainer(@NotNull ItemStack item) {
|
|
+ this.item = Preconditions.checkNotNull(item, "item");
|
|
+ }
|
|
+
|
|
+ public SingletonContainer(org.bukkit.inventory.@NotNull ItemStack item) {
|
|
+ this.item = CraftItemStack.asNMSCopy(Preconditions.checkNotNull(item, "item"));
|
|
+ }
|
|
+
|
|
+ public SingletonContainer(@NotNull Material material) {
|
|
+ this(new org.bukkit.inventory.ItemStack(Preconditions.checkNotNull(material, "material")));
|
|
+ }
|
|
+
|
|
+ private static void throwIndexException(int index) {
|
|
+ throw new IndexOutOfBoundsException("Received slot " + index + ", expected 0");
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getContainerSize() {
|
|
+ return 1;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isEmpty() {
|
|
+ return item.isEmpty();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ItemStack getItem(int slot) {
|
|
+ if (slot < 0) {
|
|
+ throwIndexException(slot);
|
|
+ }
|
|
+ return slot == 0 ? item : ItemStack.EMPTY;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ItemStack removeItem(int slot, int amount) {
|
|
+ if (slot < 0) {
|
|
+ throwIndexException(slot);
|
|
+ }
|
|
+ ItemStack itemStack = slot == 0 && !item.isEmpty() ? item.split(amount) : ItemStack.EMPTY;
|
|
+ if (!itemStack.isEmpty()) {
|
|
+ setChanged();
|
|
+ }
|
|
+ return itemStack;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ItemStack removeItemNoUpdate(int slot) {
|
|
+ if (slot != 0) {
|
|
+ throwIndexException(slot);
|
|
+ }
|
|
+ ItemStack oldItem = item;
|
|
+ item = ItemStack.EMPTY;
|
|
+ return oldItem.isEmpty() ? ItemStack.EMPTY : oldItem;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setItem(int slot, ItemStack stack) {
|
|
+ if (slot != 0) {
|
|
+ throwIndexException(slot);
|
|
+ }
|
|
+ item = stack;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getMaxStackSize() {
|
|
+ return maxStackSize;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setMaxStackSize(int size) {
|
|
+ maxStackSize = size;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setChanged() {
|
|
+
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean stillValid(Player player) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<ItemStack> getContents() {
|
|
+ return Collections.singletonList(item);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onOpen(CraftHumanEntity who) {
|
|
+
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onClose(CraftHumanEntity who) {
|
|
+
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<HumanEntity> getViewers() {
|
|
+ return Collections.emptyList();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public InventoryHolder getOwner() {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Location getLocation() {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void clearContent() {
|
|
+ item = ItemStack.EMPTY;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index 028663b86970b8a1ae3e5275429516ee00ef0a04..f3b65b3fa80f2cbc5986b6dfd56b6346bae83b36 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -2328,4 +2328,11 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
return this.adventure$pointers;
|
|
}
|
|
// Paper end
|
|
+
|
|
+ // Parchment start
|
|
+ @Override
|
|
+ public ItemStack smeltItem(ItemStack toSmelt, gg.projecteden.parchment.inventory.RecipeType recipeType) {
|
|
+ return world.getRecipeManager().getRecipeFor(gg.projecteden.parchment.inventory.CraftRecipeType.asCookingRecipe(recipeType), new gg.projecteden.parchment.inventory.SingletonContainer(toSmelt), world).map(recipe -> recipe.getResultItem().getBukkitStack()).orElse(null);
|
|
+ }
|
|
+ // Parchment end
|
|
}
|