2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
|
|
|
Date: Fri, 3 Jul 2020 11:58:56 -0500
|
|
|
|
Subject: [PATCH] Add PrepareResultEvent
|
|
|
|
|
|
|
|
Adds a new event for all crafting stations that generate a result slot item
|
|
|
|
|
|
|
|
Anvil, Grindstone and Smithing now extend this event
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
2022-03-01 06:43:03 +01:00
|
|
|
index 21215d27e59d7e6ab4b9511340e642c710fb74da..aa8c101b29f7d9269f3766476ff7d552c2ab0c36 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
2022-03-01 06:43:03 +01:00
|
|
|
@@ -315,6 +315,7 @@ public class AnvilMenu extends ItemCombinerMenu {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.createResult();
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
|
|
|
}
|
|
|
|
|
2021-06-14 11:46:59 +02:00
|
|
|
public int getCost() {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/CartographyTableMenu.java b/src/main/java/net/minecraft/world/inventory/CartographyTableMenu.java
|
2021-11-24 16:07:19 +01:00
|
|
|
index fc2b400c58ddbd7b012707c61d9a37363d351251..35e13a5fc23fc0cc046345059b43b37b348a3803 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/CartographyTableMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/CartographyTableMenu.java
|
2021-06-14 11:46:59 +02:00
|
|
|
@@ -150,6 +150,7 @@ public class CartographyTableMenu extends AbstractContainerMenu {
|
2021-06-11 14:02:28 +02:00
|
|
|
this.setupResultSlot(itemstack, itemstack1, itemstack2);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupResultSlot(ItemStack map, ItemStack item, ItemStack oldResult) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java b/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java
|
2021-11-24 16:07:19 +01:00
|
|
|
index aa0ba9c7dcb0ee81c9081031c447eeab61d92a10..aa47947ea2f04afd3cca4b359891609025c112d5 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/GrindstoneMenu.java
|
2021-11-24 16:07:19 +01:00
|
|
|
@@ -159,6 +159,7 @@ public class GrindstoneMenu extends AbstractContainerMenu {
|
2021-06-11 14:02:28 +02:00
|
|
|
super.slotsChanged(inventory);
|
|
|
|
if (inventory == this.repairSlots) {
|
|
|
|
this.createResult();
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ItemCombinerMenu.java b/src/main/java/net/minecraft/world/inventory/ItemCombinerMenu.java
|
2021-11-24 16:07:19 +01:00
|
|
|
index f5e52220abc5c678c090b32d83eb9644fa91ce9d..0a30b051e2fb4f081d0d579b30732aa8289c3389 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/ItemCombinerMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/ItemCombinerMenu.java
|
2021-06-14 11:46:59 +02:00
|
|
|
@@ -78,6 +78,7 @@ public abstract class ItemCombinerMenu extends AbstractContainerMenu {
|
2021-06-11 14:02:28 +02:00
|
|
|
super.slotsChanged(inventory);
|
|
|
|
if (inventory == this.inputSlots) {
|
|
|
|
this.createResult();
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/LoomMenu.java b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
|
2021-11-24 16:07:19 +01:00
|
|
|
index 5d9e444793bc9995f669596e699ace095ae3cb2b..fba8c59071847d9669943534ff8a0898b5787c28 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/LoomMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
|
2021-11-24 16:07:19 +01:00
|
|
|
@@ -198,7 +198,8 @@ public class LoomMenu extends AbstractContainerMenu {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setupResultSlot();
|
|
|
|
- this.broadcastChanges();
|
|
|
|
+ //this.c(); // Paper - done below
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 3); // Paper
|
|
|
|
}
|
|
|
|
|
2021-06-14 11:46:59 +02:00
|
|
|
public void registerUpdateListener(Runnable inventoryChangeListener) {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/SmithingMenu.java b/src/main/java/net/minecraft/world/inventory/SmithingMenu.java
|
2021-07-07 08:52:40 +02:00
|
|
|
index 92dd2ea23185bba311e184b2ac9744a423c102ea..cb3f522a586b841056c35378a49dd50bfa673f61 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/SmithingMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/SmithingMenu.java
|
2021-06-14 11:46:59 +02:00
|
|
|
@@ -76,6 +76,7 @@ public class SmithingMenu extends ItemCombinerMenu {
|
2021-06-11 14:02:28 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 2); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java b/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
|
2021-11-24 16:07:19 +01:00
|
|
|
index cdebd0cdf6eb901464cf4c16089b10ea0147b54d..221b6ffb426edc034183dbaf37de29c694874c62 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
|
2021-06-14 11:46:59 +02:00
|
|
|
@@ -176,6 +176,7 @@ public class StonecutterMenu extends AbstractContainerMenu {
|
2021-06-11 14:02:28 +02:00
|
|
|
this.setupRecipeList(inventory, itemstack);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 1); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupRecipeList(Container input, ItemStack stack) {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2022-02-12 14:20:33 +01:00
|
|
|
index aca2b2596a43927222f9894cc2f907cae2a331c1..d031eb1976cc50c0733cfef98404bc5b3fd152cb 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2022-02-12 14:20:33 +01:00
|
|
|
@@ -1593,19 +1593,44 @@ public class CraftEventFactory {
|
2021-06-11 14:02:28 +02:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
- public static PrepareAnvilEvent callPrepareAnvilEvent(InventoryView view, ItemStack item) {
|
|
|
|
- PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone());
|
|
|
|
- event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
+ // Paper start - disable this method, handled below
|
|
|
|
+ public static void callPrepareAnvilEvent(InventoryView view, ItemStack item) { // Paper - verify nothing uses return - handled below in PrepareResult
|
|
|
|
+ PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item)); // Paper - remove clone
|
|
|
|
+ //event.getView().getPlayer().getServer().getPluginManager().callEvent(event); // disable event
|
|
|
|
event.getInventory().setItem(2, event.getResult());
|
|
|
|
- return event;
|
|
|
|
+ //return event; // Paper
|
|
|
|
}
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
- public static PrepareSmithingEvent callPrepareSmithingEvent(InventoryView view, ItemStack item) {
|
|
|
|
- PrepareSmithingEvent event = new PrepareSmithingEvent(view, CraftItemStack.asCraftMirror(item).clone());
|
|
|
|
- event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
+ // Paper start - disable this method, handled in callPrepareResultEvent
|
|
|
|
+ public static void callPrepareSmithingEvent(InventoryView view, ItemStack item) { // Paper - verify nothing uses return - handled below in PrepareResult
|
|
|
|
+ PrepareSmithingEvent event = new PrepareSmithingEvent(view, CraftItemStack.asCraftMirror(item)); // Paper - remove clone
|
|
|
|
+ //event.getView().getPlayer().getServer().getPluginManager().callEvent(event); // Paper - disable event
|
|
|
|
event.getInventory().setItem(2, event.getResult());
|
|
|
|
- return event;
|
|
|
|
+ //return event; // Paper
|
|
|
|
}
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
+ // Paper start - support specific overrides for prepare result
|
|
|
|
+ public static void callPrepareResultEvent(AbstractContainerMenu container, int resultSlot) {
|
|
|
|
+ com.destroystokyo.paper.event.inventory.PrepareResultEvent event;
|
|
|
|
+ InventoryView view = container.getBukkitView();
|
|
|
|
+ org.bukkit.inventory.ItemStack origItem = view.getTopInventory().getItem(resultSlot);
|
|
|
|
+ CraftItemStack result = origItem != null ? CraftItemStack.asCraftCopy(origItem) : null;
|
|
|
|
+ if (view.getTopInventory() instanceof org.bukkit.inventory.AnvilInventory) {
|
|
|
|
+ event = new PrepareAnvilEvent(view, result);
|
|
|
|
+ } else if (view.getTopInventory() instanceof org.bukkit.inventory.GrindstoneInventory) {
|
|
|
|
+ event = new com.destroystokyo.paper.event.inventory.PrepareGrindstoneEvent(view, result);
|
|
|
|
+ } else if (view.getTopInventory() instanceof org.bukkit.inventory.SmithingInventory) {
|
|
|
|
+ event = new PrepareSmithingEvent(view, result);
|
|
|
|
+ } else {
|
|
|
|
+ event = new com.destroystokyo.paper.event.inventory.PrepareResultEvent(view, result);
|
|
|
|
+ }
|
|
|
|
+ event.callEvent();
|
|
|
|
+ event.getInventory().setItem(resultSlot, event.getResult());
|
2021-06-17 21:37:37 +02:00
|
|
|
+ container.broadcastChanges();;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mob spawner event.
|