Package rakama.worldtools

Examples of rakama.worldtools.WorldManager


{
    static String directory = "C:/Users/My Computer/AppData/Roaming/.minecraft/saves/mandelbrot";
   
    public static void main(String[] args) throws IOException
    {
        WorldManager manager = WorldManager.getWorldManager(new File(directory));
        BlockCanvas canvas = manager.getCanvas();
        renderMandelbrot(canvas, 512, 128, 4);
        manager.closeAll();
    }
View Full Code Here


        if(length < 0){zSrc += length; length = -length;}

        File srcFile = new File(src);
        File destFile = new File(dest);
               
        WorldManager destManager = WorldManager.getWorldManager(new File(dest));
        WorldManager srcManager = destManager;
       
        if(!srcFile.equals(destFile))
            srcManager = WorldManager.getWorldManager(new File(src), true);

        WorldCanvas srcCanvas = srcManager.getCanvas();
        WorldCanvas destCanvas = destManager.getCanvas();
       
        // export schematic from source map
        Schematic schema = srcCanvas.exportSchematic(xSrc, ySrc, zSrc,
                            xSrc+width-1, ySrc+height-1, zSrc+length-1);

        int dx = xSrc - xDest;
        int dy = ySrc - yDest;
        int dz = zSrc - zDest;

        // regular expression for tp commands
        String space = "\\s+?";
        String target = "(@[prafPRAF](?:\\[.*\\])*?)";
        String number = "(~?-?[\\p{Digit}]+?)";
        String tpstr = "/tp" + space + target + space + number
                        + space + number + space + number + "\\s*?";

        // regular expression for general commands
        String argstr = "/([^\\s]*)" + space + "(.*)";
        String argsplit = "(@[prafPRAF])(\\[.*\\])*?)";
       
        Pattern apattern = Pattern.compile(argstr);
        Pattern tpattern = Pattern.compile(tpstr);

        // edit command block teleport coordinates   
        List<TileEntity> tileEntities = schema.getTileEntities();
        for(TileEntity e : new ArrayList<TileEntity>(tileEntities))
        {
            if(e instanceof CommandBlock)
            {
                CommandBlock cb = (CommandBlock)e;
                int xc = cb.getX();
                int yc = cb.getY();
                int zc = cb.getZ();
                String cmd = cb.getCommand();
               
                if(cmd == null)
                    continue;               

                Matcher tmatcher = tpattern.matcher(cmd);
               
                if(tmatcher.matches())
                {
                    String tar = tmatcher.group(1);
                    String xstr = tmatcher.group(2);
                    String ystr = tmatcher.group(3);
                    String zstr = tmatcher.group(4);
                                       
                    int xt = Integer.parseInt(xstr.replace("~", "")) - dx;
                    int yt = Integer.parseInt(ystr.replace("~", "")) - dy;
                    int zt = Integer.parseInt(zstr.replace("~", "")) - dz;
                   
                    xstr = xstr.startsWith("~") ? xstr : Integer.toString(xt);
                    ystr = ystr.startsWith("~") ? ystr : Integer.toString(yt);
                    zstr = zstr.startsWith("~") ? zstr : Integer.toString(zt);        
                       
                    cmd = "/tp " + tar + " " + xt + " " + yt + " " + zt;
                }
               
                Matcher amatcher = apattern.matcher(cmd);
               
                if(amatcher.matches())
                {
                    String arg = tmatcher.group(1);
                    String val = tmatcher.group(2);
                   
                    // TODO: split val into tokens, fix the xyz ones
                }
                else
                    continue;
                       
                cb = EntityFactory.getDefaultFactory().createCommandBlock(xc, yc, zc, cmd);
                schema.removeTileEntity(e);
                schema.addTileEntity(cb);
            }
        }
       
        // remove existing entities from target region
        List<Entity> removeEntities = destCanvas.getEntities(xDest, yDest, zDest,
                xDest+width-1, yDest+height-1, zDest+length-1);
        for(Entity e : new ArrayList<Entity>(removeEntities))
            destCanvas.removeEntity(e);

        // remove existing tile entities from target region
        List<TileEntity> removeTiles = destCanvas.getTileEntities(xDest, yDest, zDest,
                xDest+width-1, yDest+height-1, zDest+length-1);
        for(TileEntity e : new ArrayList<TileEntity>(removeTiles))
            destCanvas.removeTileEntity(e);
       
        // import schematic to destination map
        destCanvas.importSchematic(xDest, yDest, zDest, schema);
       
        // copy biomes from source to destination
        if(copy_biomes)
        {
            for(int z=zSrc; z<zSrc+length; z++)
            {
                for(int x=xSrc; x<xSrc+width; x++)
                {
                    int biome = srcCanvas.getBiome(x, z);
                    if(biome < 0)
                        biome = 0;
                   
                    destCanvas.setBiome(x - dx, z - dz, biome);
                }
            }
        }
       
        destManager.closeAll();
        srcManager.closeAll();
       
        System.out.println("Success...");
    }
View Full Code Here

TOP

Related Classes of rakama.worldtools.WorldManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.