mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add PrepareResultEvent
Adds a new event for all crafting stations that generate a result slot item Anvil, Grindstone and Smithing now extend this event
This commit is contained in:
parent
e3bd1e8117
commit
ea5eaa7503
8 changed files with 121 additions and 27 deletions
|
@ -126,7 +126,15 @@
|
|||
}
|
||||
|
||||
public static int calculateIncreasedRepairCost(int cost) {
|
||||
@@ -329,4 +349,19 @@
|
||||
@@ -313,6 +333,7 @@
|
||||
}
|
||||
|
||||
this.createResult();
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper - Add PrepareResultEvent
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -329,4 +350,19 @@
|
||||
public int getCost() {
|
||||
return this.cost.get();
|
||||
}
|
||||
|
|
|
@ -109,7 +109,15 @@
|
|||
return stillValid(this.access, player, Blocks.CARTOGRAPHY_TABLE);
|
||||
}
|
||||
|
||||
@@ -147,7 +183,7 @@
|
||||
@@ -104,6 +140,7 @@
|
||||
this.setupResultSlot(itemstack, itemstack1, itemstack2);
|
||||
}
|
||||
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper - Add PrepareResultEvent
|
||||
}
|
||||
|
||||
private void setupResultSlot(ItemStack map, ItemStack item, ItemStack oldResult) {
|
||||
@@ -147,7 +184,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,7 +126,7 @@
|
|||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
Slot slot1 = (Slot) this.slots.get(slot);
|
||||
|
||||
@@ -199,7 +235,7 @@
|
||||
@@ -199,7 +236,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,17 +39,16 @@
|
|||
public static final int MAX_NAME_LENGTH = 35;
|
||||
public static final int INPUT_SLOT = 0;
|
||||
public static final int ADDITIONAL_SLOT = 1;
|
||||
@@ -46,16 +66,23 @@
|
||||
public void setChanged() {
|
||||
@@ -47,15 +67,22 @@
|
||||
super.setChanged();
|
||||
GrindstoneMenu.this.slotsChanged(this);
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return context.getLocation();
|
||||
}
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.access = context;
|
||||
|
@ -86,7 +85,13 @@
|
|||
}
|
||||
|
||||
@Override
|
||||
@@ -125,7 +153,8 @@
|
||||
@@ -120,12 +148,14 @@
|
||||
super.slotsChanged(inventory);
|
||||
if (inventory == this.repairSlots) {
|
||||
this.createResult();
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper - Add PrepareResultEvent
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createResult() {
|
||||
|
@ -96,7 +101,7 @@
|
|||
this.broadcastChanges();
|
||||
}
|
||||
|
||||
@@ -218,7 +247,7 @@
|
||||
@@ -218,7 +248,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,7 +110,7 @@
|
|||
super.removed(player);
|
||||
this.access.execute((world, blockposition) -> {
|
||||
this.clearContainer(player, this.repairSlots);
|
||||
@@ -226,12 +255,13 @@
|
||||
@@ -226,12 +256,13 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,7 +9,15 @@
|
|||
@Override
|
||||
public boolean mayPlace(ItemStack stack) {
|
||||
return itemcombinermenuslotdefinition_b.mayPlace().test(stack);
|
||||
@@ -110,6 +110,7 @@
|
||||
@@ -96,6 +96,7 @@
|
||||
super.slotsChanged(inventory);
|
||||
if (inventory == this.inputSlots) {
|
||||
this.createResult();
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, this instanceof SmithingMenu ? 3 : 2); // Paper - Add PrepareResultEvent
|
||||
}
|
||||
|
||||
}
|
||||
@@ -110,6 +111,7 @@
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
private static final int PATTERN_NOT_SET = -1;
|
||||
private static final int INV_SLOT_START = 4;
|
||||
private static final int INV_SLOT_END = 31;
|
||||
@@ -60,6 +80,13 @@
|
||||
@@ -60,28 +80,42 @@
|
||||
LoomMenu.this.slotsChanged(this);
|
||||
LoomMenu.this.slotUpdateListener.run();
|
||||
}
|
||||
|
@ -53,16 +53,16 @@
|
|||
};
|
||||
this.outputContainer = new SimpleContainer(1) {
|
||||
@Override
|
||||
@@ -67,21 +94,28 @@
|
||||
public void setChanged() {
|
||||
super.setChanged();
|
||||
LoomMenu.this.slotUpdateListener.run();
|
||||
}
|
||||
+ }
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return context.getLocation();
|
||||
+ }
|
||||
}
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.access = context;
|
||||
|
@ -123,7 +123,17 @@
|
|||
if (id >= 0 && id < this.selectablePatterns.size()) {
|
||||
this.selectedBannerPatternIndex.set(id);
|
||||
this.setupResultSlot((Holder) this.selectablePatterns.get(id));
|
||||
@@ -222,7 +258,7 @@
|
||||
@@ -201,7 +237,8 @@
|
||||
this.resultSlot.set(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
- this.broadcastChanges();
|
||||
+ // this.broadcastChanges(); // Paper - Add PrepareResultEvent; done below
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, 3); // Paper - Add PrepareResultEvent
|
||||
} else {
|
||||
this.resultSlot.set(ItemStack.EMPTY);
|
||||
this.selectablePatterns = List.of();
|
||||
@@ -222,7 +259,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,7 +142,7 @@
|
|||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
Slot slot1 = (Slot) this.slots.get(slot);
|
||||
|
||||
@@ -277,7 +313,7 @@
|
||||
@@ -277,7 +314,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,7 +151,7 @@
|
|||
super.removed(player);
|
||||
this.access.execute((world, blockposition) -> {
|
||||
this.clearContainer(player, this.inputContainer);
|
||||
@@ -294,6 +330,11 @@
|
||||
@@ -294,6 +331,11 @@
|
||||
DyeColor enumcolor = ((DyeItem) itemstack1.getItem()).getDyeColor();
|
||||
|
||||
itemstack2.update(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY, (bannerpatternlayers) -> {
|
||||
|
|
|
@ -18,7 +18,14 @@
|
|||
|
||||
public SmithingMenu(int syncId, Inventory playerInventory) {
|
||||
this(syncId, playerInventory, ContainerLevelAccess.NULL);
|
||||
@@ -117,7 +121,7 @@
|
||||
@@ -111,13 +115,14 @@
|
||||
this.hasRecipeError.set(flag ? 1 : 0);
|
||||
}
|
||||
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper - Add PrepareResultEvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createResult() {
|
||||
SmithingRecipeInput smithingrecipeinput = this.createRecipeInput();
|
||||
Level world = this.level;
|
||||
|
@ -27,7 +34,7 @@
|
|||
|
||||
if (world instanceof ServerLevel worldserver) {
|
||||
optional = worldserver.recipeAccess().getRecipeFor(RecipeType.SMITHING, smithingrecipeinput, worldserver);
|
||||
@@ -129,7 +133,9 @@
|
||||
@@ -129,7 +134,9 @@
|
||||
ItemStack itemstack = ((SmithingRecipe) recipeholder.value()).assemble(smithingrecipeinput, this.level.registryAccess());
|
||||
|
||||
this.resultSlots.setRecipeUsed(recipeholder);
|
||||
|
@ -38,7 +45,7 @@
|
|||
}, () -> {
|
||||
this.resultSlots.setRecipeUsed((RecipeHolder) null);
|
||||
this.resultSlots.setItem(0, ItemStack.EMPTY);
|
||||
@@ -149,4 +155,18 @@
|
||||
@@ -149,4 +156,18 @@
|
||||
public boolean hasRecipeError() {
|
||||
return this.hasRecipeError.get() > 0;
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
public class StonecutterMenu extends AbstractContainerMenu {
|
||||
|
||||
public static final int INPUT_SLOT = 0;
|
||||
@@ -36,6 +42,21 @@
|
||||
@@ -36,7 +42,22 @@
|
||||
Runnable slotUpdateListener;
|
||||
public final Container container;
|
||||
final ResultContainer resultContainer;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftStonecutterView bukkitEntity = null;
|
||||
+ private Player player;
|
||||
+
|
||||
|
||||
+ @Override
|
||||
+ public CraftStonecutterView getBukkitView() {
|
||||
+ if (this.bukkitEntity != null) {
|
||||
|
@ -41,9 +41,10 @@
|
|||
+ return this.bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
+
|
||||
public StonecutterMenu(int syncId, Inventory playerInventory) {
|
||||
this(syncId, playerInventory, ContainerLevelAccess.NULL);
|
||||
}
|
||||
@@ -55,6 +76,13 @@
|
||||
StonecutterMenu.this.slotsChanged(this);
|
||||
StonecutterMenu.this.slotUpdateListener.run();
|
||||
|
@ -100,7 +101,15 @@
|
|||
if (this.selectedRecipeIndex.get() == id) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -158,7 +188,7 @@
|
||||
@@ -144,6 +174,7 @@
|
||||
this.setupRecipeList(itemstack);
|
||||
}
|
||||
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareResultEvent(this, RESULT_SLOT); // Paper - Add PrepareResultEvent
|
||||
}
|
||||
|
||||
private void setupRecipeList(ItemStack stack) {
|
||||
@@ -158,7 +189,7 @@
|
||||
}
|
||||
|
||||
void setupResultSlot(int selectedId) {
|
||||
|
@ -109,7 +118,7 @@
|
|||
|
||||
if (!this.recipesForInput.isEmpty() && this.isValidRecipeIndex(selectedId)) {
|
||||
SelectableRecipe.SingleInputEntry<StonecutterRecipe> selectablerecipe_a = (SelectableRecipe.SingleInputEntry) this.recipesForInput.entries().get(selectedId);
|
||||
@@ -193,7 +223,7 @@
|
||||
@@ -193,7 +224,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,7 +127,7 @@
|
|||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
Slot slot1 = (Slot) this.slots.get(slot);
|
||||
|
||||
@@ -246,7 +276,7 @@
|
||||
@@ -246,7 +277,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1679,6 +1679,12 @@ public class CraftEventFactory {
|
|||
}
|
||||
|
||||
public static PrepareAnvilEvent callPrepareAnvilEvent(AnvilView view, ItemStack item) {
|
||||
// Paper start - Add PrepareResultEvent
|
||||
if (true) {
|
||||
view.getTopInventory().setItem(net.minecraft.world.inventory.AnvilMenu.RESULT_SLOT, CraftItemStack.asCraftMirror(item));
|
||||
return null; // verify nothing uses return - disable event: handled below in PrepareResult
|
||||
}
|
||||
// Paper end - Add PrepareResultEvent
|
||||
PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone());
|
||||
event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
|
||||
event.getInventory().setItem(2, event.getResult());
|
||||
|
@ -1686,6 +1692,12 @@ public class CraftEventFactory {
|
|||
}
|
||||
|
||||
public static PrepareGrindstoneEvent callPrepareGrindstoneEvent(InventoryView view, ItemStack item) {
|
||||
// Paper start - Add PrepareResultEvent
|
||||
if (true) {
|
||||
view.getTopInventory().setItem(net.minecraft.world.inventory.GrindstoneMenu.RESULT_SLOT, CraftItemStack.asCraftMirror(item));
|
||||
return null; // verify nothing uses return - disable event: handled below in PrepareResult
|
||||
}
|
||||
// Paper end - Add PrepareResultEvent
|
||||
PrepareGrindstoneEvent event = new PrepareGrindstoneEvent(view, CraftItemStack.asCraftMirror(item).clone());
|
||||
event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
|
||||
event.getInventory().setItem(2, event.getResult());
|
||||
|
@ -1693,12 +1705,39 @@ public class CraftEventFactory {
|
|||
}
|
||||
|
||||
public static PrepareSmithingEvent callPrepareSmithingEvent(InventoryView view, ItemStack item) {
|
||||
// Paper start - Add PrepareResultEvent
|
||||
if (true) {
|
||||
view.getTopInventory().setItem(net.minecraft.world.inventory.SmithingMenu.RESULT_SLOT, CraftItemStack.asCraftMirror(item));
|
||||
return null; // verify nothing uses return - disable event: handled below in PrepareResult
|
||||
}
|
||||
// Paper end - Add PrepareResultEvent
|
||||
PrepareSmithingEvent event = new PrepareSmithingEvent(view, CraftItemStack.asCraftMirror(item).clone());
|
||||
event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
|
||||
event.getInventory().setResult(event.getResult());
|
||||
return event;
|
||||
}
|
||||
|
||||
// Paper start - Add PrepareResultEvent
|
||||
public static void callPrepareResultEvent(AbstractContainerMenu container, int resultSlot) {
|
||||
final 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 && view instanceof AnvilView anvilView) {
|
||||
event = new PrepareAnvilEvent(anvilView, result);
|
||||
} else if (view.getTopInventory() instanceof org.bukkit.inventory.GrindstoneInventory) {
|
||||
event = new 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());
|
||||
container.broadcastChanges();;
|
||||
}
|
||||
// Paper end - Add PrepareResultEvent
|
||||
|
||||
/**
|
||||
* Mob spawner event.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue