13
0
geforkt von Mirrors/Paper
Paper/patches/server/0486-Add-PlayerStonecutterRecipeSelectEvent.patch

53 Zeilen
3.1 KiB
Diff

2021-06-14 21:58:32 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 27 Nov 2020 17:14:27 -0800
Subject: [PATCH] Add PlayerStonecutterRecipeSelectEvent
2021-06-14 21:58:32 +02:00
2021-11-27 09:11:43 +01:00
Co-Authored-By: MiniDigger <admin@benndorf.dev>
2021-06-14 21:58:32 +02:00
diff --git a/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java b/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
2024-06-13 23:42:02 +02:00
index bb29107cb15e2ec644a14cabb3cf91f4bde5471d..977ccef3c9fa7685209f3eca894a3b69501ebcc1 100644
2021-06-14 21:58:32 +02:00
--- a/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/StonecutterMenu.java
2024-06-13 23:42:02 +02:00
@@ -64,7 +64,7 @@ public class StonecutterMenu extends AbstractContainerMenu {
2021-06-14 21:58:32 +02:00
public StonecutterMenu(int syncId, Inventory playerInventory, final ContainerLevelAccess context) {
super(MenuType.STONECUTTER, syncId);
- this.selectedRecipeIndex = DataSlot.standalone();
+ this.selectedRecipeIndex = DataSlot.shared(new int[1], 0); // Paper - Add PlayerStonecutterRecipeSelectEvent
2021-06-14 21:58:32 +02:00
this.recipes = Lists.newArrayList();
this.input = ItemStack.EMPTY;
this.slotUpdateListener = () -> {
2024-06-13 23:42:02 +02:00
@@ -162,7 +162,30 @@ public class StonecutterMenu extends AbstractContainerMenu {
2021-06-14 21:58:32 +02:00
@Override
public boolean clickMenuButton(net.minecraft.world.entity.player.Player player, int id) {
if (this.isValidRecipeIndex(id)) {
- this.selectedRecipeIndex.set(id);
+ // Paper start - Add PlayerStonecutterRecipeSelectEvent
2021-06-14 21:58:32 +02:00
+ int recipeIndex = id;
+ this.selectedRecipeIndex.set(recipeIndex);
+ this.selectedRecipeIndex.checkAndClearUpdateFlag(); // mark as changed
+ if (this.isValidRecipeIndex(id)) {
+ io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent event = new io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent((Player) player.getBukkitEntity(), (org.bukkit.inventory.StonecutterInventory) getBukkitView().getTopInventory(), (org.bukkit.inventory.StonecuttingRecipe) this.getRecipes().get(id).toBukkitRecipe());
+ if (!event.callEvent()) {
2024-02-01 10:15:57 +01:00
+ player.containerMenu.sendAllDataToRemote();
2021-06-14 21:58:32 +02:00
+ return false;
+ }
2024-02-01 10:15:57 +01:00
+
+ net.minecraft.resources.ResourceLocation key = org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey());
+ if (!this.getRecipes().get(recipeIndex).id().equals(key)) { // If the recipe did NOT stay the same
+ for (int newRecipeIndex = 0; newRecipeIndex < this.getRecipes().size(); newRecipeIndex++) {
+ if (this.getRecipes().get(newRecipeIndex).id().equals(key)) {
2021-06-14 21:58:32 +02:00
+ recipeIndex = newRecipeIndex;
+ break;
+ }
+ }
+ }
+ }
2024-02-01 10:15:57 +01:00
+ player.containerMenu.sendAllDataToRemote();
2021-06-14 21:58:32 +02:00
+ this.selectedRecipeIndex.set(recipeIndex); // set new index, so that listeners can read it
+ // Paper end - Add PlayerStonecutterRecipeSelectEvent
2021-06-14 21:58:32 +02:00
this.setupResultSlot();
}