get yaw of block face

Discussion in 'Plugin Development' started by MasterG4ming, Jan 3, 2022.

  1. Offline

    MasterG4ming

    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            Block b = event.getClickedBlock();
            Action action = event.getAction();
            World world = player.getWorld();
    
            if (action == Action.RIGHT_CLICK_BLOCK && event.getHand() == EquipmentSlot.HAND && b.getType() == Material.SKULL) {
    
                Skull skull = (Skull) event.getClickedBlock().getState();
                skull.getRotation();
                System.out.println( skull.getRotation());
    
                Location loc = new Location(Bukkit.getWorld("world"), b.getX(), b.getY(), b.getZ(), b.getLocation().getYaw(), b.getLocation().getPitch()).add(0.5, 0, 0.5);
                Slime slime = (Slime) player.getWorld().spawnEntity(b.getLocation().add(0.5, 100, 0.5), EntityType.SLIME);
                slime.setSize(1);
                slime.setSilent(true);
                slime.setAI(false);
                slime.teleport(loc);
            }
        }
    i want to teleport slime to skull yaw, how do i do that? help is appreciated, thank you!
     
  2. Offline

    The_Spaceman

    I'm not sure what skull.getRotation() returns, but I suggest that you use that instead of the yaw of the block (b.getLocation().getYaw())
     

Share This Page