[REQ] Convert this craftscript into a plugin?

Discussion in 'Archived: Plugin Requests' started by cjbh1996, Nov 12, 2012.

  1. Offline

    cjbh1996

    I have this craftscript that basically plants saplings of a specified density over a specified radius. Problem is, it's too resource heavy to be run as a simple script when using larger radii.

    Here it is:
    Code:
    importPackage(Packages.java.io);
    importPackage(Packages.java.awt);
    importPackage(Packages.com.sk89q.worldedit);
    importPackage(Packages.com.sk89q.worldedit.blocks);
     
    var session = context.remember();
    var origin = player.getPosition();
     
    context.checkArgs(1, -1, "<radius> <density>");
     
    var radius = argv[1];
    var density = argv[2];
    var count = 0;
    for (var x = -radius; x <= radius; x++) {
        for (var y = -radius; y <= radius; y++) {
            for (var z = -radius; z <= radius; z++) {
             
                var randomNumber = Math.floor(Math.random()*4);
             
                var pt_openBlock = origin.add(x, y, z);
                var id_openBlock = session.getBlockType(pt_openBlock);
                var pt_filledBlock = origin.add(x, y - 1, z)
                var id_filledBlock = session.getBlockType(pt_filledBlock);
             
                var plantChance = Math.floor(Math.random()*101);
             
                if(plantChance > density){
                    if (id_openBlock == BlockID.AIR && id_filledBlock == BlockID.GRASS){
                        session.setBlock(pt_openBlock, new BaseBlock(BlockID.AIR));
                    }
                }
                if(plantChance <= density){
                    if (id_openBlock == BlockID.AIR && id_filledBlock == BlockID.GRASS){
                        session.setBlock(pt_openBlock, new BaseBlock(BlockID.SAPLING, randomNumber));
                        count++;
                    }
                    if (id_openBlock == BlockID.AIR && id_filledBlock == BlockID.DIRT){
                        session.setBlock(pt_openBlock, new BaseBlock(BlockID.SAPLING, randomNumber));
                        count++;
                    }
                }
            }
        }
    }
    player.print(count + " saplings placed");
    I guess the command would be /plantsaplings <radius> <density>. Thanks to anyone who will convert this to a plugin!
     
  2. Offline

    wristdirect

    I did almost exactly this with Torched, except that was torches and checked for light on the block first.

    I can make a modified version in a few minutes for saplings and no light check :)

    cjbh1996 Here you go :) MassSapling v0.1

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016

Share This Page