英文:
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 < 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;
}
Hope that helps!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论