mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-05 02:22:12 +01:00
SPIGOT-7380: Add PlayerInteractEvent#getClickedPosition and ChiseledBookshelf#getSlot
By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
parent
b0576f313f
commit
20acc420d8
6 changed files with 66 additions and 6 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
@ -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<ChiseledBookShelfBlockEntity> implements ChiseledBookshelf {
|
||||
|
||||
|
@ -35,4 +40,31 @@ public class CraftChiseledBookshelf extends CraftBlockEntityState<ChiseledBookSh
|
|||
|
||||
return new CraftInventoryChiseledBookshelf(this.getTileEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlot(Vector clickVector) {
|
||||
BlockFace facing = ((Directional) this.getBlockData()).getFacing();
|
||||
|
||||
Vec2F faceVector;
|
||||
switch (facing) {
|
||||
case NORTH:
|
||||
faceVector = new Vec2F((float) (1.0f - clickVector.getX()), (float) clickVector.getY());
|
||||
break;
|
||||
case SOUTH:
|
||||
faceVector = new Vec2F((float) clickVector.getX(), (float) clickVector.getY());
|
||||
break;
|
||||
case WEST:
|
||||
faceVector = new Vec2F((float) clickVector.getZ(), (float) clickVector.getY());
|
||||
break;
|
||||
case EAST:
|
||||
faceVector = new Vec2F((float) (1f - clickVector.getZ()), (float) clickVector.getY());
|
||||
break;
|
||||
case DOWN:
|
||||
case UP:
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ChiseledBookShelfBlock.getHitSlot(faceVector);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParameters;
|
|||
import net.minecraft.world.phys.MovingObjectPosition;
|
||||
import net.minecraft.world.phys.MovingObjectPositionBlock;
|
||||
import net.minecraft.world.phys.MovingObjectPositionEntity;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
@ -101,6 +102,7 @@ import org.bukkit.craftbukkit.inventory.CraftMetaBook;
|
|||
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftVector;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
|
@ -239,6 +241,7 @@ import org.bukkit.inventory.EquipmentSlot;
|
|||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class CraftEventFactory {
|
||||
public static org.bukkit.block.Block blockDamage; // For use in EntityDamageByBlockEvent
|
||||
|
@ -492,13 +495,18 @@ public class CraftEventFactory {
|
|||
}
|
||||
|
||||
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, EnumHand hand) {
|
||||
return callPlayerInteractEvent(who, action, position, direction, itemstack, false, hand);
|
||||
return callPlayerInteractEvent(who, action, position, direction, itemstack, false, hand, null);
|
||||
}
|
||||
|
||||
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
|
||||
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand, Vec3D targetPos) {
|
||||
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
||||
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
||||
|
||||
Vector clickedPos = null;
|
||||
if (position != null && targetPos != null) {
|
||||
clickedPos = CraftVector.toBukkit(targetPos.subtract(Vec3D.atLowerCornerOf(position)));
|
||||
}
|
||||
|
||||
CraftWorld craftWorld = (CraftWorld) player.getWorld();
|
||||
CraftServer craftServer = (CraftServer) player.getServer();
|
||||
|
||||
|
@ -521,7 +529,7 @@ public class CraftEventFactory {
|
|||
itemInHand = null;
|
||||
}
|
||||
|
||||
PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
|
||||
PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND), clickedPos);
|
||||
if (cancelledBlock) {
|
||||
event.setUseInteractedBlock(Event.Result.DENY);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue