aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0491-Add-PlayerLoomPatternSelectEvent.patch
blob: 62b156c72a69fb16446b5c0eed545cf68fba14f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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


diff --git a/src/main/java/net/minecraft/world/inventory/LoomMenu.java b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
index a98157f600837898dd8ef12671c4bb713e30f30c..b8440f2cd7ca46c243407ae1ba8f8c7adab4ecd4 100644
--- a/src/main/java/net/minecraft/world/inventory/LoomMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
@@ -173,8 +173,35 @@ public class LoomMenu extends AbstractContainerMenu {
     @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
+            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.block.banner.PatternType.getByIdentifier(this.selectablePatterns.get(selectablePatternIndex).value().getHashname()));
+            if (!event.callEvent()) {
+                ((Player) player.getBukkitEntity()).updateInventory();
+                return false;
+            }
+            Holder<BannerPattern> selectedPattern = null;
+            for (int i = 0; i < this.selectablePatterns.size(); i++) {
+                final Holder<BannerPattern> holder = this.selectablePatterns.get(i);
+                if (event.getPatternType().getIdentifier().equals(holder.value().getHashname())) {
+                    selectablePatternIndex = i;
+                    selectedPattern = holder;
+                    break;
+                }
+            }
+            if (selectedPattern == null) {
+                for (BannerPattern pattern : BuiltInRegistries.BANNER_PATTERN) {
+                    if (event.getPatternType().getIdentifier().equals(pattern.getHashname())) {
+                        selectedPattern = BuiltInRegistries.BANNER_PATTERN.getHolder(BuiltInRegistries.BANNER_PATTERN.getId(pattern)).orElseThrow();
+                        break;
+                    }
+                }
+                selectablePatternIndex = -1;
+            }
+            ((Player) player.getBukkitEntity()).updateInventory();
+            this.selectedBannerPatternIndex.set(selectablePatternIndex);
+            this.setupResultSlot(java.util.Objects.requireNonNull(selectedPattern, "selectedPattern was null, this is unexpected"));
+            // Paper end - Add PlayerLoomPatternSelectEvent
             return true;
         } else {
             return false;