mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 14:30:17 +01:00
36 lines
2.1 KiB
Diff
36 lines
2.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Mariell Hoversholm <proximyst@proximyst.com>
|
|
Date: Sun, 29 Sep 2024 16:21:26 +0200
|
|
Subject: [PATCH] Add PlayerInsertLecternBookEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/LecternBlock.java b/src/main/java/net/minecraft/world/level/block/LecternBlock.java
|
|
index 23066357205f5a67b8ab5a2fe6c2912e698c7f8c..1ca52ab9379a4758ec4583bb201e4b1954297da7 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/LecternBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/LecternBlock.java
|
|
@@ -153,7 +153,24 @@ public class LecternBlock extends BaseEntityBlock {
|
|
BlockEntity tileentity = world.getBlockEntity(pos);
|
|
|
|
if (tileentity instanceof LecternBlockEntity tileentitylectern) {
|
|
- tileentitylectern.setBook(stack.consumeAndReturn(1, user));
|
|
+ // Paper start - Add PlayerInsertLecternBookEvent
|
|
+ ItemStack eventSourcedBookStack = null;
|
|
+ if (user instanceof final net.minecraft.server.level.ServerPlayer serverPlayer) {
|
|
+ final io.papermc.paper.event.player.PlayerInsertLecternBookEvent event = new io.papermc.paper.event.player.PlayerInsertLecternBookEvent(
|
|
+ serverPlayer.getBukkitEntity(),
|
|
+ org.bukkit.craftbukkit.block.CraftBlock.at(world, pos),
|
|
+ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack.copyWithCount(1))
|
|
+ );
|
|
+ if (!event.callEvent()) return;
|
|
+ eventSourcedBookStack = org.bukkit.craftbukkit.inventory.CraftItemStack.unwrap(event.getBook());
|
|
+ }
|
|
+ if (eventSourcedBookStack == null) {
|
|
+ eventSourcedBookStack = stack.consumeAndReturn(1, user);
|
|
+ } else {
|
|
+ stack.consume(1, user);
|
|
+ }
|
|
+ tileentitylectern.setBook(eventSourcedBookStack);
|
|
+ // Paper end - Add PlayerInsertLecternBookEvent
|
|
LecternBlock.resetBookState(user, world, pos, state, true);
|
|
world.playSound((Player) null, pos, SoundEvents.BOOK_PUT, SoundSource.BLOCKS, 1.0F, 1.0F);
|
|
}
|