Skip to content

Instantly share code, notes, and snippets.

@Phoenix616

Phoenix616/searchnbt.js

Last active Dec 6, 2016
Embed
What would you like to do?
WorldEdit craftscript to search through the NBT of blocks in your selection. Supports regex.
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.blocks);
function main() {
context.checkArgs(1, -1, "<regex>");
var regexString = argv[1];
for (var i = 2; i < argv.length; i++) {
regexString += " " + argv[i];
}
var regex = new RegExp(regexString);
regex.ignoreCase = true;
regex.multiline = true;
var blocks = context.remember();
var session = context.getSession();
var target = WorldEdit.getInstance().getServer().matchPlayer(player).getPlayer();
var region = context.getSession().getRegion();
if (region == 0) {
player.printError("Please select a region!");
return;
}
player.print("Searching blocks in selection for §f" + regexString);
var amount = 0;
for (var x = 0; x < region.getWidth(); x++) {
for (var z = 0; z < region.getLength(); z++) {
for (var y = 0; y < region.getHeight(); y++) {
var loc = region.getMinimumPoint().add(x,y,z);
var b = blocks.getBlock(loc);
if (b.hasNbtData() && regex.test(b.getNbtData().toString())) {
player.printDebug("Found " + b.getId() + " at " + loc);
amount++;
}
}
}
}
player.print("Blocks found: §f" + amount);
return;
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment