寻找一种方法来找到特定区域中的一个块。

huangapple go评论58阅读模式
英文:

Looking for a way to find a specific block in an are

问题

我正在尝试制作一个能够使用命令在特定方块上方生成生物的插件。问题是我真的不知道从何开始……我基本上在寻找一种循环遍历区域内所有方块并在找到一个或多个该方块类型时返回某个结果的方法或途径。

英文:

I'm trying to make a plugin that can spawn mobs above specific block with a command. The problem is that I dont really know where to start... I am basicly looking for a function or way to cycle through all of the blocks in an area and return something when it finds 1 or more of the block type.

答案1

得分: 1

if (sender instanceof Player) {
    Player p = (Player) sender;
    if (p.hasPermission(command.getPermission())) {
        Location playerLoc = p.getLocation();
        org.bukkit.World world = p.getWorld();
        double startX = playerLoc.getX();
        double startY = playerLoc.getY() - 1;
        double startZ = playerLoc.getZ() - 1;
        for (int x = 0; x < Integer.valueOf(args[0]); x++) {
            for (int z = 0; z < Integer.valueOf(args[1]); z++) {
                for (int y = 0; y <= Integer.valueOf(args[2]); y++) {
                    Location loc = new Location(world, startX + x, startY + y, startZ + z);
                    if (loc.getBlock().equals(Material.yourmaterial)){
                        //do what you want
                    }
                }
            }
        }
    } else {
        sender.sendMessage(ChatColor.DARK_RED+"Specify the size");
    }
}
return true;
}
英文:
    if (sender instanceof Player) {
        Player p = (Player) sender;
        if (p.hasPermission(command.getPermission())) {
            Location playerLoc = p.getLocation();
            org.bukkit.World world = p.getWorld();
            double startX = playerLoc.getX();
            double startY = playerLoc.getY() - 1;
            double startZ = playerLoc.getZ() - 1;
            for (int x = 0; x &lt; Integer.valueOf(args[0]); x++) {
                for (int z = 0; z &lt; Integer.valueOf(args[1]); z++) {
                    for (int y = 0; y &lt;= Integer.valueOf(args[2]); y++) {
                        Location loc = new Location(world, startX + x, startY + y, startZ + z);
                        if (loc.getBlock().equals(Material.yourmaterial)){
                            //do what you want
                        }
                    }
                }
            }
        } else {
            sender.sendMessage(ChatColor.DARK_RED+&quot;Specify the size&quot;);
        }
    }
    return true;
}

Hope that helps!

huangapple
  • 本文由 发表于 2020年5月5日 18:24:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/61610889.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定