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-06-08 07:46:52 +02:00
|
|
|
index eb22059fe008c3d3fc0364a7f85f91b4cca8b328..506d758efbf16da9467f120321d2359a8832e477 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-04-16 10:29:50 +02:00
|
|
|
@@ -316,6 +316,7 @@ public class AnvilMenu extends ItemCombinerMenu {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.createResult();
|
2022-06-08 07:46:52 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
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
|
2022-12-07 21:16:54 +01:00
|
|
|
index 74447bd2ff36c5360db52d2a56fe3fbe56aee7d2..7733b5271307849e3e56c6089649c4caa7c0ac1d 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);
|
|
|
|
}
|
|
|
|
|
2022-06-08 07:46:52 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2022-12-14 06:03:57 +01:00
|
|
|
index e3c3d202a9852adf32d5e94c9011c3799668419b..d610bd1468d506416fe61bf93d6be3bd0dc042a9 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();
|
2022-06-08 07:46:52 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/ItemCombinerMenu.java b/src/main/java/net/minecraft/world/inventory/ItemCombinerMenu.java
|
2022-12-07 21:16:54 +01:00
|
|
|
index a0caf5d4085305121f77089dc50e4b32cd1a8d9b..c34a66310969c3c837d09693159b827c1edddd3b 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();
|
2022-06-08 07:46:52 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/LoomMenu.java b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
|
2022-12-07 21:16:54 +01:00
|
|
|
index cb08da8b5f6abc644ff5834f2ca32acf4fd0a255..b7f3dc81ecac0d814203028a9213f304bcc19574 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
|
2022-07-27 22:46:05 +02:00
|
|
|
@@ -248,7 +248,8 @@ public class LoomMenu extends AbstractContainerMenu {
|
2022-06-08 07:46:52 +02:00
|
|
|
this.resultSlot.set(ItemStack.EMPTY);
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2022-06-08 07:46:52 +02:00
|
|
|
- this.broadcastChanges();
|
|
|
|
+ // this.broadcastChanges(); // Paper - done below
|
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 3); // Paper
|
|
|
|
} else {
|
|
|
|
this.resultSlot.set(ItemStack.EMPTY);
|
|
|
|
this.selectablePatterns = List.of();
|
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
|
2022-12-07 21:16:54 +01:00
|
|
|
index 9c898862d665d073cccd0c33e5b0435c52fef5b6..c4cdf54dc5f7f84474a7af7ff43c5f986311b210 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
|
2022-12-07 21:16:54 +01:00
|
|
|
@@ -79,6 +79,7 @@ public class SmithingMenu extends ItemCombinerMenu {
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2022-06-08 07:46:52 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java b/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
|
2022-12-07 21:16:54 +01:00
|
|
|
index 78c1bd1c709ef29ccfa75fa87d8af1217cc57b59..4ee54e3a61588e5574e3f7ba06a73bbd73975957 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);
|
|
|
|
}
|
|
|
|
|
2022-06-08 07:46:52 +02:00
|
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-12-23 06:20:44 +01:00
|
|
|
index 985a5c5f01d54674f7bcb77e07f8890e81113418..856242121e5102dbc88080e8a611ae64348ba86e 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-12-23 06:20:44 +01:00
|
|
|
@@ -1593,26 +1593,53 @@ 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
|
2022-12-14 06:03:57 +01:00
|
|
|
+ //event.getView().getPlayer().getServer().getPluginManager().callEvent(event); // Paper - disable event
|
2021-06-11 14:02:28 +02:00
|
|
|
event.getInventory().setItem(2, event.getResult());
|
|
|
|
- return event;
|
|
|
|
+ //return event; // Paper
|
|
|
|
}
|
|
|
|
+ // Paper end
|
|
|
|
|
2022-12-14 06:03:57 +01:00
|
|
|
- public static PrepareGrindstoneEvent callPrepareGrindstoneEvent(InventoryView view, ItemStack item) {
|
|
|
|
- PrepareGrindstoneEvent event = new PrepareGrindstoneEvent(view, CraftItemStack.asCraftMirror(item).clone());
|
|
|
|
- event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
+ // Paper start - disable this method, handled below
|
|
|
|
+ public static void callPrepareGrindstoneEvent(InventoryView view, ItemStack item) {
|
|
|
|
+ PrepareGrindstoneEvent event = new PrepareGrindstoneEvent(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
|
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
- 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) {
|
2022-12-14 06:03:57 +01:00
|
|
|
+ event = new PrepareGrindstoneEvent(view, result);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ } 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.
|