Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@0bf8790 Fix client lag spikes due to client light recalc PaperMC/Paper@aabf676 Prevent unloading worlds with pending player logins PaperMC/Paper@eff22eb Ensure players are removed from pendingLogin PaperMC/Paper@046466f Re-arrange most chunk system patches to front (#8338) PaperMC/Paper@e8c2c3b Fix World#refreshChunk not working for chunks in no-tick range PaperMC/Paper@09904fd Re-add legacy getChunkAtAsynchronously to ChunkProviderServer PaperMC/Paper@36a5f15 Allow preventing BlockDestroyEvent from dropping items (#8349) PaperMC/Paper@e51401e Updated Upstream (Bukkit/CraftBukkit/Spigot) (#8347) PaperMC/Paper@51183af Fix console completer/highlighter having invalid source stack (#8346) PaperMC/Paper@ef0e5a6 Updated Upstream (Bukkit/CraftBukkit/Spigot) PaperMC/Paper@178f035 Restore no-crash behaviour when read-only config file(s) (#8318) PaperMC/Paper@267dd18 Stop large look changes from crashing the server (#8326) PaperMC/Paper@36f0c1b Rebuild patches PaperMC/Paper@751d092 Properly close section storage managed files (#8364) PaperMC/Paper@f5f84ff Add custom destroyerIdentity parameter to the sendBlockBreak function (#5840) PaperMC/Paper@05f6a5c Limit size of Authenticator Cache Thread Pool (#8360) PaperMC/Paper@ef670eb EndDragonFight killed statuses should be false for newly created worlds (#8354) PaperMC/Paper@b826065 fire EntityChangeBlockEvent in more places (#6371) PaperMC/Paper@34777cd Missing eating regain reason (#8244) PaperMC/Paper@dbda887 Missing some effect cause (#8307) PaperMC/Paper@63cb747 Added byte array serialization/deserialization for PersistentDataContainers (#7505) PaperMC/Paper@ea777c3 Add a consumer parameter to ProjectileSource#launchProjectile (#8374) PaperMC/Paper@470c638 Configurable chat thread limit (#7878) PaperMC/Paper@dbc2d60 Make WorldCreator#keepSpawnLoaded return the WorldCreator (Fixes #8321) (#8371) PaperMC/Paper@f8742e2 Also load resources from LibraryLoader (#8335) PaperMC/Paper@f7e6809 Fix Pathfinding After World Has Changed (#8068) PaperMC/Paper@ad3dffe Respect preventMovingIntoUnloadedChunks for optimized collision checking (#8259) PaperMC/Paper@8db45c4 Copper clear on lightning strike calls EntityChangeBlockEvent (#8126) PaperMC/Paper@9e614e6 Fix ground pathfinding (#7683) PaperMC/Paper@339e85d Updated Upstream (CraftBukkit) (#8376) PaperMC/Paper@980c1d1 Updated Upstream (Bukkit/CraftBukkit) (#8378) PaperMC/Paper@8681503 Call EntityChangeBlockEvent for frogs egg (#8136) PaperMC/Paper@ec0c550 Call BlockPhysicsEvent more often (#8264) PaperMC/Paper@f528f53 Correct javadocs on PlayerArmorStandManipulateEvent (#7719) PaperMC/Paper@3996e6e Updated Upstream (Bukkit/CraftBukkit/Spigot) PaperMC/Paper@d332623 Avoid potential place where the world map could be modified after its iterator is created (#8315) PaperMC/Paper@6736f39 Fix mangled patch PaperMC/Paper@4d52f1d Add method isTickingWorlds to Bukkit (#8316) PaperMC/Paper@62680d5 Avoid item meta usage for itemstack enchantment getter (#8373) PaperMC/Paper@b4c025b Fix player desync on dimension change (#8253) PaperMC/Paper@6d63005 Fix setEggCount method from TurtleLayEggEvent (#8385) PaperMC/Paper@abe53a7 Fix typos in isTickingWorlds API javadocs (#8382) PaperMC/Paper@01a1387 Rewrite chunk system (#8177) PaperMC/Paper@b58c0cf Update snekyaml
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 72ed25022d5ea1074304be3c72b23882b8f0f88a..22457dfb3c4a2489f79e2f977f415d2938db0d27 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -2376,4 +2376,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
|
|
}
|