From 6a84e88e76973f1e139559ac13528765abd64b62 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 14 Dec 2024 19:37:31 +0100 Subject: [PATCH] net/minecraft/world/level/block/entity/vault --- .../entity/vault/VaultBlockEntity.java.patch | 26 ++++++ .../entity/vault/VaultBlockEntity.java.patch | 83 ------------------- 2 files changed, 26 insertions(+), 83 deletions(-) create mode 100644 paper-server/patches/sources/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java.patch diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java.patch new file mode 100644 index 0000000000..055a081be5 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java.patch @@ -0,0 +1,26 @@ +--- a/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java ++++ b/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java +@@ -272,6 +_,11 @@ + if (!list.isEmpty()) { + player.awardStat(Stats.ITEM_USED.get(stack.getItem())); + stack.consume(config.keyItem().getCount(), player); ++ // CraftBukkit start ++ org.bukkit.event.block.BlockDispenseLootEvent vaultDispenseLootEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDispenseLootEvent(level, pos, player, list); ++ if (vaultDispenseLootEvent.isCancelled()) return; ++ list = vaultDispenseLootEvent.getDispensedLoot().stream().map(org.bukkit.craftbukkit.inventory.CraftItemStack::asNMSCopy).toList(); ++ // CraftBukkit end + unlock(level, state, pos, config, serverData, sharedData, list); + serverData.addToRewardedPlayers(player); + sharedData.updateConnectedPlayersWithinRange(level, pos, serverData, config, config.deactivationRange()); +@@ -294,6 +_,11 @@ + ItemStack randomDisplayItemFromLootTable = getRandomDisplayItemFromLootTable( + level, pos, config.overrideLootTableToDisplay().orElse(config.lootTable()) + ); ++ // CraftBukkit start ++ org.bukkit.event.block.VaultDisplayItemEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callVaultDisplayItemEvent(level, pos, randomDisplayItemFromLootTable); ++ if (event.isCancelled()) return; ++ randomDisplayItemFromLootTable = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getDisplayItem()); ++ // CraftBukkit end + sharedData.setDisplayItem(randomDisplayItemFromLootTable); + } + } diff --git a/paper-server/patches/unapplied/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java.patch b/paper-server/patches/unapplied/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java.patch deleted file mode 100644 index 928e901a76..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java.patch +++ /dev/null @@ -1,83 +0,0 @@ ---- a/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java -+++ b/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java -@@ -46,6 +46,13 @@ - import net.minecraft.world.phys.Vec3; - import org.slf4j.Logger; - -+// CraftBukkit start -+import org.bukkit.craftbukkit.event.CraftEventFactory; -+import org.bukkit.craftbukkit.inventory.CraftItemStack; -+import org.bukkit.event.block.BlockDispenseLootEvent; -+import org.bukkit.event.block.VaultDisplayItemEvent; -+// CraftBukkit end -+ - public class VaultBlockEntity extends BlockEntity { - - private static final Logger LOGGER = LogUtils.getLogger(); -@@ -96,18 +103,18 @@ - dataresult = VaultServerData.CODEC.parse(dynamicops, nbt.get("server_data")); - logger = VaultBlockEntity.LOGGER; - Objects.requireNonNull(logger); -- optional = dataresult.resultOrPartial(logger::error); -+ optional = ((DataResult) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error - VaultServerData vaultserverdata = this.serverData; - - Objects.requireNonNull(this.serverData); -- optional.ifPresent(vaultserverdata::set); -+ ((Optional) optional).ifPresent(vaultserverdata::set); // CraftBukkit - decompile error - } - - if (nbt.contains("config")) { - dataresult = VaultConfig.CODEC.parse(dynamicops, nbt.get("config")); - logger = VaultBlockEntity.LOGGER; - Objects.requireNonNull(logger); -- dataresult.resultOrPartial(logger::error).ifPresent((vaultconfig) -> { -+ ((DataResult) dataresult).resultOrPartial(logger::error).ifPresent((vaultconfig) -> { // CraftBukkit - decompile error - this.config = vaultconfig; - }); - } -@@ -116,11 +123,11 @@ - dataresult = VaultSharedData.CODEC.parse(dynamicops, nbt.get("shared_data")); - logger = VaultBlockEntity.LOGGER; - Objects.requireNonNull(logger); -- optional = dataresult.resultOrPartial(logger::error); -+ optional = ((DataResult) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error - VaultSharedData vaultshareddata = this.sharedData; - - Objects.requireNonNull(this.sharedData); -- optional.ifPresent(vaultshareddata::set); -+ ((Optional) optional).ifPresent(vaultshareddata::set); // CraftBukkit - decompile error - } - - } -@@ -320,6 +327,14 @@ - if (!list.isEmpty()) { - player.awardStat(Stats.ITEM_USED.get(stack.getItem())); - stack.consume(config.keyItem().getCount(), player); -+ // CraftBukkit start -+ BlockDispenseLootEvent vaultDispenseLootEvent = CraftEventFactory.callBlockDispenseLootEvent(world, pos, player, list); -+ if (vaultDispenseLootEvent.isCancelled()) { -+ return; -+ } -+ -+ list = vaultDispenseLootEvent.getDispensedLoot().stream().map(CraftItemStack::asNMSCopy).toList(); -+ // CraftBukkit end - Server.unlock(world, state, pos, config, serverData, sharedData, list); - serverData.addToRewardedPlayers(player); - sharedData.updateConnectedPlayersWithinRange(world, pos, serverData, config, config.deactivationRange()); -@@ -341,7 +356,15 @@ - sharedData.setDisplayItem(ItemStack.EMPTY); - } else { - ItemStack itemstack = Server.getRandomDisplayItemFromLootTable(world, pos, (ResourceKey) config.overrideLootTableToDisplay().orElse(config.lootTable())); -+ // CraftBukkit start -+ VaultDisplayItemEvent event = CraftEventFactory.callVaultDisplayItemEvent(world, pos, itemstack); -+ if (event.isCancelled()) { -+ return; -+ } - -+ itemstack = CraftItemStack.asNMSCopy(event.getDisplayItem()); -+ // CraftBukkit end -+ - sharedData.setDisplayItem(itemstack); - } - }