Paper/patches/server/0528-Added-PlayerLoomPatternSelectEvent.patch

49 lines
2.8 KiB
Diff
Raw 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] Added PlayerLoomPatternSelectEvent
diff --git a/src/main/java/net/minecraft/world/inventory/LoomMenu.java b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
2023-06-08 01:56:33 +02:00
index c4766df6d64b484375e5e3474e97dee196c0fef4..0a87996a6ab5b4d67c2aa10daadf6174bc647a44 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
@@ -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
+ 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) {
2022-12-08 05:24:59 +01:00
+ for (BannerPattern pattern : BuiltInRegistries.BANNER_PATTERN) {
2022-06-08 09:30:41 +02:00
+ if (event.getPatternType().getIdentifier().equals(pattern.getHashname())) {
2022-12-08 05:24:59 +01:00
+ selectedPattern = BuiltInRegistries.BANNER_PATTERN.getHolder(BuiltInRegistries.BANNER_PATTERN.getId(pattern)).orElseThrow();
2022-06-08 09:30:41 +02:00
+ 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
return true;
} else {
return false;