From 20acc420d881469889a6424e4104022410375c70 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 17 Jun 2023 14:31:40 +1000 Subject: [PATCH] SPIGOT-7380: Add PlayerInteractEvent#getClickedPosition and ChiseledBookshelf#getSlot By: Jishuna --- .../server/level/PlayerInteractManager.patch | 2 +- .../server/network/PlayerConnection.patch | 2 +- .../net/minecraft/world/item/ItemBoat.patch | 2 +- .../level/block/ChiseledBookShelfBlock.patch | 20 ++++++++++++ .../block/CraftChiseledBookshelf.java | 32 +++++++++++++++++++ .../craftbukkit/event/CraftEventFactory.java | 14 ++++++-- 6 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 paper-server/nms-patches/net/minecraft/world/level/block/ChiseledBookShelfBlock.patch diff --git a/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch b/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch index 87d2651aed..cf594c6ada 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch @@ -292,7 +292,7 @@ + cancelledBlock = true; + } + -+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, blockposition, movingobjectpositionblock.getDirection(), itemstack, cancelledBlock, enumhand); ++ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, blockposition, movingobjectpositionblock.getDirection(), itemstack, cancelledBlock, enumhand, movingobjectpositionblock.getLocation()); + firedInteract = true; + interactResult = event.useItemInHand() == Event.Result.DENY; + interactPosition = blockposition.immutable(); diff --git a/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch b/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch index 4df68bc2f5..0227ec7535 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch @@ -784,7 +784,7 @@ + if (player.gameMode.firedInteract && player.gameMode.interactPosition.equals(movingobjectpositionblock.getBlockPos()) && player.gameMode.interactHand == enumhand && ItemStack.isSameItemSameTags(player.gameMode.interactItemStack, itemstack)) { + cancelled = player.gameMode.interactResult; + } else { -+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand); ++ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand, movingobjectpositionblock.getLocation()); + cancelled = event.useItemInHand() == Event.Result.DENY; + } + player.gameMode.firedInteract = false; diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemBoat.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemBoat.patch index ed6818e2c3..5ae99c3f6a 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemBoat.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemBoat.patch @@ -5,7 +5,7 @@ if (movingobjectpositionblock.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK) { + // CraftBukkit start - Boat placement -+ org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(entityhuman, org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), itemstack, enumhand); ++ org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(entityhuman, org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), itemstack, false, enumhand, movingobjectpositionblock.getLocation()); + + if (event.isCancelled()) { + return InteractionResultWrapper.pass(itemstack); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/ChiseledBookShelfBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/ChiseledBookShelfBlock.patch new file mode 100644 index 0000000000..7a78a63957 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/block/ChiseledBookShelfBlock.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/world/level/block/ChiseledBookShelfBlock.java ++++ b/net/minecraft/world/level/block/ChiseledBookShelfBlock.java +@@ -128,7 +128,7 @@ + } + } + +- private static int getHitSlot(Vec2F vec2f) { ++ public static int getHitSlot(Vec2F vec2f) { //CraftBukkit - private -> public + int i = vec2f.y >= 0.5F ? 0 : 1; + int j = getSection(vec2f.x); + +@@ -190,7 +190,7 @@ + + Objects.requireNonNull(blockstatelist_a); + list.forEach((iblockstate) -> { +- blockstatelist_a.add(iblockstate); ++ blockstatelist_a.add((BlockStateBoolean) iblockstate); // CraftBukkit - Decompile error + }); + } + diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftChiseledBookshelf.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftChiseledBookshelf.java index 96aec21a9e..3dac492040 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftChiseledBookshelf.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftChiseledBookshelf.java @@ -1,10 +1,15 @@ package org.bukkit.craftbukkit.block; +import net.minecraft.world.level.block.ChiseledBookShelfBlock; import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity; +import net.minecraft.world.phys.Vec2F; import org.bukkit.World; +import org.bukkit.block.BlockFace; import org.bukkit.block.ChiseledBookshelf; +import org.bukkit.block.data.Directional; import org.bukkit.craftbukkit.inventory.CraftInventoryChiseledBookshelf; import org.bukkit.inventory.ChiseledBookshelfInventory; +import org.bukkit.util.Vector; public class CraftChiseledBookshelf extends CraftBlockEntityState implements ChiseledBookshelf { @@ -35,4 +40,31 @@ public class CraftChiseledBookshelf extends CraftBlockEntityState