PaperMC/patches/server/0457-Add-PlayerLoomPatternSelectEvent.patch

46 lines
2.6 KiB
Diff
Raw Permalink Normal View History

2022-06-08 09:30:41 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 25 Nov 2020 16:33:27 -0800
Subject: [PATCH] Add PlayerLoomPatternSelectEvent
2022-06-08 09:30:41 +02:00
diff --git a/src/main/java/net/minecraft/world/inventory/LoomMenu.java b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
2024-10-23 17:58:11 +02:00
index 58470d8e9a4ceb1eca05b342481ed8260588e225..1b7cf165ab0818792870f43719a6324b282bb57a 100644
2022-06-08 09:30:41 +02:00
--- a/src/main/java/net/minecraft/world/inventory/LoomMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
2024-10-23 17:58:11 +02:00
@@ -162,8 +162,32 @@ public class LoomMenu extends AbstractContainerMenu {
2022-06-08 09:30:41 +02:00
@Override
public boolean clickMenuButton(net.minecraft.world.entity.player.Player player, int id) {
if (id >= 0 && id < this.selectablePatterns.size()) {
- this.selectedBannerPatternIndex.set(id);
- this.setupResultSlot((Holder) this.selectablePatterns.get(id));
+ // Paper start - Add PlayerLoomPatternSelectEvent
2022-06-08 09:30:41 +02:00
+ int selectablePatternIndex = id;
+ io.papermc.paper.event.player.PlayerLoomPatternSelectEvent event = new io.papermc.paper.event.player.PlayerLoomPatternSelectEvent((Player) player.getBukkitEntity(), ((CraftInventoryLoom) getBukkitView().getTopInventory()), org.bukkit.craftbukkit.block.banner.CraftPatternType.minecraftHolderToBukkit(this.selectablePatterns.get(selectablePatternIndex)));
2022-06-08 09:30:41 +02:00
+ if (!event.callEvent()) {
2024-02-01 10:15:57 +01:00
+ player.containerMenu.sendAllDataToRemote();
2022-06-08 09:30:41 +02:00
+ return false;
+ }
2024-04-26 07:44:49 +02:00
+ final Holder<BannerPattern> eventPattern = org.bukkit.craftbukkit.block.banner.CraftPatternType.bukkitToMinecraftHolder(event.getPatternType());
2022-06-08 09:30:41 +02:00
+ Holder<BannerPattern> selectedPattern = null;
+ for (int i = 0; i < this.selectablePatterns.size(); i++) {
+ final Holder<BannerPattern> holder = this.selectablePatterns.get(i);
2024-04-26 07:44:49 +02:00
+ if (eventPattern.equals(holder)) {
2022-06-08 09:30:41 +02:00
+ selectablePatternIndex = i;
+ selectedPattern = holder;
+ break;
+ }
+ }
+ if (selectedPattern == null) {
2024-04-26 07:44:49 +02:00
+ selectedPattern = eventPattern;
2022-06-08 09:30:41 +02:00
+ selectablePatternIndex = -1;
+ }
2024-02-01 10:15:57 +01:00
+
+ player.containerMenu.sendAllDataToRemote();
2022-06-08 09:30:41 +02:00
+ this.selectedBannerPatternIndex.set(selectablePatternIndex);
+ this.setupResultSlot(java.util.Objects.requireNonNull(selectedPattern, "selectedPattern was null, this is unexpected"));
+ // Paper end - Add PlayerLoomPatternSelectEvent
2022-06-08 09:30:41 +02:00
return true;
} else {
return false;