Below is a JavaScript from a interface in the Customs NPC mod which runs with minecraft. It is suppose to be running a flood fill routine. It only fill correctly to the positive x and positive z of the starting position. In minecraft x & z are in the horizontal plane y is the vertical axis.
var node1 = {
xy: []
};
var blockp;
//starting block type and position
blockp = world.getBlock(npc.getBlockX(), npc.getBlockY() - 1, npc.getBlockZ() + 1);
node1.xy[0] = npc.getBlockX();
node1.xy[1] = npc.getBlockZ() + 1;
node1.xy[2] = npc.getBlockY() - 1;
//
var floodfill = function(nameb, node) {
if (nameb == "minecraft:stone" ||
nameb == null) {
return;
}
var blkname;
//
world.setBlock(node.xy[0], node.xy[2], node.xy[1], world.createItem("minecraft:stone", 0, 1));
//
node.xy[0] = node.xy[0];
node.xy[1] = node.xy[1] + 1;
node.xy[2] = node.xy[2];
blkname = world.getBlock(node.xy[0], node.xy[2], node.xy[1]).name;
floodfill(blkname, node);
//
node.xy[0] = node.xy[0];
node.xy[1] = node.xy[1] - 1;
node.xy[2] = node.xy[2];
blkname = world.getBlock(node.xy[0], node.xy[2], node.xy[1]).name;
floodfill(blkname, node);
//
node.xy[0] = node.xy[0] + 1;
node.xy[1] = node.xy[1];
node.xy[2] = node.xy[2];
blkname = world.getBlock(node.xy[0], node.xy[2], node.xy[1]).name;
floodfill(blkname, node);
//
node.xy[0] = node.xy[0] - 1;
node.xy[1] = node.xy[1];
node.xy[2] = node.xy[2];
blkname = world.getBlock(node.xy[0], node.xy[2], node.xy[1]).name;
floodfill(blkname, node);
//
return;
}
floodfill(blockp.name, node1);