#1450: Add CrafterCraftEvent

By: ploppyperson <nathat890@outlook.com>
Also-by: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-07-30 07:07:10 +10:00
parent 8317d4c799
commit 9a7508c3ab
4 changed files with 51 additions and 22 deletions

View File

@@ -1,18 +1,22 @@
--- a/net/minecraft/world/item/crafting/IRecipeComplex.java
+++ b/net/minecraft/world/item/crafting/IRecipeComplex.java
@@ -3,6 +3,11 @@
@@ -3,6 +3,15 @@
import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import net.minecraft.core.IRegistryCustom;
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.inventory.CraftComplexRecipe;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.inventory.Recipe;
+// CraftBukkit end
+
public abstract class IRecipeComplex implements RecipeCrafting {
private final CraftingBookCategory category;
@@ -25,4 +30,11 @@
@@ -25,4 +34,17 @@
public CraftingBookCategory category() {
return this.category;
}
@@ -20,7 +24,13 @@
+ // CraftBukkit start
+ @Override
+ public Recipe toBukkitRecipe(NamespacedKey id) {
+ return new org.bukkit.craftbukkit.inventory.CraftComplexRecipe(id, this);
+ CraftItemStack result = CraftItemStack.asCraftMirror(getResultItem(IRegistryCustom.EMPTY));
+
+ CraftComplexRecipe recipe = new CraftComplexRecipe(id, result, this);
+ recipe.setGroup(this.getGroup());
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
+
+ return recipe;
+ }
+ // CraftBukkit end
}

View File

@@ -1,12 +1,14 @@
--- a/net/minecraft/world/level/block/CrafterBlock.java
+++ b/net/minecraft/world/level/block/CrafterBlock.java
@@ -39,6 +39,13 @@
@@ -39,6 +39,15 @@
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import net.minecraft.world.InventoryLargeChest;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.block.CrafterCraftEvent;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+import org.bukkit.inventory.Inventory;
+// CraftBukkit end
@@ -14,7 +16,21 @@
public class CrafterBlock extends BlockTileEntity {
public static final MapCodec<CrafterBlock> CODEC = simpleCodec(CrafterBlock::new);
@@ -226,7 +233,25 @@
@@ -188,6 +197,13 @@
RecipeHolder<RecipeCrafting> recipeholder = (RecipeHolder) optional.get();
ItemStack itemstack = ((RecipeCrafting) recipeholder.value()).assemble(craftinginput, worldserver.registryAccess());
+ // CraftBukkit start
+ CrafterCraftEvent event = CraftEventFactory.callCrafterCraftEvent(blockposition, worldserver, crafterblockentity, itemstack, recipeholder);
+ if (event.isCancelled()) {
+ return;
+ }
+ itemstack = CraftItemStack.asNMSCopy(event.getResult());
+ // CraftBukkit end
if (itemstack.isEmpty()) {
worldserver.levelEvent(1050, blockposition, 0);
} else {
@@ -226,7 +242,25 @@
ItemStack itemstack1 = itemstack.copy();
if (iinventory != null && (iinventory instanceof CrafterBlockEntity || itemstack.getCount() > iinventory.getMaxStackSize(itemstack))) {
@@ -40,7 +56,7 @@
ItemStack itemstack2 = itemstack1.copyWithCount(1);
ItemStack itemstack3 = TileEntityHopper.addItem(crafterblockentity, iinventory, itemstack2, enumdirection.getOpposite());
@@ -237,7 +262,25 @@
@@ -237,7 +271,25 @@
itemstack1.shrink(1);
}
} else if (iinventory != null) {