From 411498e394b386c6697ac837bb9ee28659873e15 Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm Date: Sun, 29 Sep 2024 16:21:26 +0200 Subject: [PATCH] Add PlayerInsertLecternBookEvent --- .../world/level/block/LecternBlock.java.patch | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/LecternBlock.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/LecternBlock.java.patch index 85b8dc7778..a928fea703 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/LecternBlock.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/LecternBlock.java.patch @@ -1,6 +1,32 @@ --- a/net/minecraft/world/level/block/LecternBlock.java +++ b/net/minecraft/world/level/block/LecternBlock.java -@@ -175,6 +175,16 @@ +@@ -153,7 +153,24 @@ + 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); + } +@@ -175,6 +192,16 @@ } private static void changePowered(Level world, BlockPos pos, BlockState state, boolean powered) { @@ -17,7 +43,7 @@ world.setBlock(pos, (BlockState) state.setValue(LecternBlock.POWERED, powered), 3); LecternBlock.updateBelow(world, pos, state); } -@@ -206,11 +216,12 @@ +@@ -206,11 +233,12 @@ } private void popBook(BlockState state, Level world, BlockPos pos) { @@ -31,7 +57,7 @@ float f = 0.25F * (float) enumdirection.getStepX(); float f1 = 0.25F * (float) enumdirection.getStepZ(); ItemEntity entityitem = new ItemEntity(world, (double) pos.getX() + 0.5D + (double) f, (double) (pos.getY() + 1), (double) pos.getZ() + 0.5D + (double) f1, itemstack); -@@ -282,8 +293,7 @@ +@@ -282,8 +310,7 @@ private void openScreen(Level world, BlockPos pos, Player player) { BlockEntity tileentity = world.getBlockEntity(pos);