SPIGOT-7380: Add PlayerInteractEvent#getClickedPosition and ChiseledBookshelf#getSlot
By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user