メインコンテンツへスキップ

プレイヤーがinteractionに触れたか判断する

        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            Location playerLocation = player.getLocation();
            Location targetLocation;
            targetLocation = playerLocation;
            double rangeY;
    
            if (player.isSneaking()) {
                rangeY = 0.75;
            } else {
                rangeY = 0.9;
            }
            targetLocation.add(0, rangeY, 0);
    
            // フィルタリングするPredicateを作成
            Predicate<Entity> interactionFilter
                    = entity -> entity.getType() == EntityType.INTERACTION;
            Collection<Entity> nearbyInteraction
                    = player.getWorld()
                    .getNearbyEntities(targetLocation,0.3, rangeY, 0.3, interactionFilter);
    
            for (Entity entity : nearbyInteraction) {
                player.sendMessage("test");
            }
        }
    

    プレイヤーの高さは1.8
    スニーク時のプレイヤーの高さは1.5
    プレイヤーの幅は0.6

    このコードは
    interactionエンティティに触れると
    testと表示される。

     
     
    minecraftのコマンドやプラグインのコードなど。

    あなたへのおすすめ