Package rakama.worldtools.data

Examples of rakama.worldtools.data.Schematic


        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,
View Full Code Here


            System.err.println("Error: Skin file could not be loaded.");
            System.err.println(e.getMessage() + " (" + in + ")");
            System.exit(0);
        }

        Schematic schema = null;
       
        try
        {
            schema = generateSkin(skin);
        }
View Full Code Here

        System.out.println("Success!");
    }
   
    public static Schematic generateSkin(BufferedImage skin) throws IOException
    {
        Schematic sch = new Schematic(16, 33, 10);       
        PlayerModel model = new PlayerModel(skin);
        model.draw(sch, 0, 0, 0);       
        return sch;
    }
View Full Code Here

        int width = x1 - x0 + 1;
        int height = y1 - y0 + 1;
        int length = z1 - z0 + 1;

        Schematic schema = new Schematic(width, height, length);

        int y0t = Math.max(0, y0);
        int y1t = Math.min(Chunk.height - 1, y1);
       
        for(int z=z0; z<=z1; z++)
        {
            for(int x=x0; x<=x1; x++)
            {
                for(int y=y0t; y<=y1t; y++)
                {
                    Block block = getBlock(x, y, z);

                    if(block == null)
                        continue;
                   
                    if(y-y0 >= 0 && y-y0 < Chunk.height)
                        schema.setBlock(x-x0, y-y0, z-z0, block);
                }
            }
        }

        for(Entity e : getEntities(x0, y0, z0, x1, y1, z1))
            schema.addEntity(e.clone(-x0, -y0, -z0));
       
        for(TileEntity e : getTileEntities(x0, y0, z0, x1, y1, z1))
            schema.addTileEntity(e.clone(-x0, -y0, -z0));

        return schema;
    }
View Full Code Here

TOP

Related Classes of rakama.worldtools.data.Schematic

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.