Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup(){
- size(512,512);
- frameRate(30);
- loadPixels();
- colorMode(HSB, 255,100,100);
- InputStream in = createInput("region.xaero");
- try{
- int minorSaveVersion = -1;
- int majorSaveVersion = 0;
- int firstByte = in.read();
- if(firstByte == 255){
- int fullVersion = readInt(in);
- println("version " + fullVersion);
- minorSaveVersion = fullVersion & 65535;
- majorSaveVersion = (fullVersion >> 16) & 65535;
- println("major version " + majorSaveVersion);
- println("minor version " + minorSaveVersion);
- firstByte = -1;
- }
- while (true) {
- int sectionCoords = firstByte == -1 ? in.read() : firstByte;
- if(sectionCoords == -1){//end reached
- print("end reached");
- break;
- }
- firstByte = -1;
- //section coordinates inside the region
- int sectionX = sectionCoords >> 4;
- int sectionZ = sectionCoords & 15;
- println("section "+sectionX+", "+sectionZ);
- //start reading the section
- int chunks = 0;
- for (int chunkX = 0; chunkX < 4; chunkX++){
- for (int chunkZ = 0; chunkZ < 4; chunkZ++) {
- chunks++;
- int firstPixelInfo = readInt(in); //info for the first chunk pixel
- if (firstPixelInfo == -1){ //-1 if the chunk is empty
- println("chunk "+chunks+" empty at "+chunkX+", "+chunkZ+" ");
- continue;
- }
- //println("chunk "+chunks+" found at "+chunkX+", "+chunkZ+" with pixelinfo: ng:"+(firstPixelInfo & 1)+" oh:"+(firstPixelInfo & 64)+" ol:"+(firstPixelInfo & 2)+" ct:"+((firstPixelInfo>>2) & 3)+" cv:"+(firstPixelInfo & 128)+" li:"+((firstPixelInfo>>8) & 15)+" ");
- println("chunk "+chunks+" found at "+chunkX+", "+chunkZ);
- for (int x = 0; x < 16; x++) {
- for (int z = 0; z < 16; z++) {
- int info;
- if(x==0&&z==0){
- info = firstPixelInfo;
- }else{
- info = readInt(in);
- }
- int col = readPixel(x,z, info, in);
- set(((sectionX*64)+(chunkX*16)+x),((sectionZ*64)+(chunkZ*16)+z),color(col,100,100));
- }
- }
- fill(color(0));
- strokeWeight(1);
- //text("x",((sectionX*64)+(chunkX*16))+5,((sectionZ*64)+(chunkZ*16))+9);
- line(sectionX*64+(chunkX*16),sectionZ*64+(chunkZ*16),sectionX*64+(chunkX*16)+16,sectionZ*64+(chunkZ*16));
- line(sectionX*64+(chunkX*16)+16,sectionZ*64+(chunkZ*16),sectionX*64+(chunkX*16)+16,sectionZ*64+(chunkZ*16)+16);
- line(sectionX*64+(chunkX*16)+16,sectionZ*64+(chunkZ*16)+16,sectionX*64+(chunkX*16),sectionZ*64+(chunkZ*16)+16);
- line(sectionX*64+(chunkX*16),sectionZ*64+(chunkZ*16)+16,sectionX*64+(chunkX*16),sectionZ*64+(chunkZ*16));//fuck me
- }}
- fill(color(64,100,100));
- strokeWeight(2);
- text(""+sectionX+"|"+sectionZ,(sectionX*64)+1,(sectionZ*64)+12);
- line((sectionX*64),(sectionZ*64),(sectionX*64)+64,(sectionZ*64));
- line((sectionX*64)+64,(sectionZ*64),(sectionX*64)+64,(sectionZ*64)+64);
- line((sectionX*64)+64,(sectionZ*64)+64,(sectionX*64),(sectionZ*64)+64);
- line((sectionX*64),(sectionZ*64)+64,(sectionX*64),(sectionZ*64));
- }
- }catch(IOException e){
- e.printStackTrace();
- }
- //updatePixels();
- }
- int readPixel(int x, int z, int info, InputStream in){
- int col = 0;
- try{
- if ((info & 1) != 0) { // it isn't grass, so read 4 bytes???
- int state = readInt(in);
- }
- int heightType = (info >> 4) & 3;//0 - no slope, 1 - bright slope, 2 - dark slope, 3 - unknown slope
- int heigt;
- if ((info & 64) != 0){//old height, read a byte.
- heigt = in.read();
- }else{
- heigt = (info >> 12) & 255;
- }
- if ((info & 2) != 0) {// has overlays, for example water and ice, read a byte.
- int amount = in.read();
- for (int i = 0; i < amount; i++)
- {
- readOverlay(in,info);
- }
- int colorType = (info >> 2) & 3;//0 - normal, 1 - grass, 2 - foliage, 3 - custom color
- int customColorMultiplier = -1;
- int biome = 0;
- if (colorType == 3) // read 4 bytes
- customColorMultiplier = readInt(in);
- if(colorType != 0 && colorType != 3 || (info & 1048576) != 0)// read 1 byte
- biome = in.read();
- if(colorType == 3 && customColorMultiplier == -1)
- colorType = 0;
- boolean caveBlock = (info & 128) != 0;
- int light = (info >> 8) & 15;
- }
- }catch(IOException e){
- e.printStackTrace();
- }
- return col;
- }
- void readOverlay(InputStream in, int info){
- //overlays
- //int info = readInt(in);
- if ((info & 1) != 0) { //isnt water so read 4 bytes
- int state = readInt(in);
- }else{ }
- int opacity = 1;
- int colorType = (info >> 8) & 3;
- int customColorMultiplier = -1;
- if (colorType == 2 || (info & 4) != 0){
- colorType = 2;
- customColorMultiplier = readInt(in);
- if(customColorMultiplier == -1)
- colorType = 0;
- }
- if ((info & 8) != 0) // opacity not 1
- opacity = readInt(in);
- int light = (info >> 4) & 15;
- //end overlays
- }
- int readInt(InputStream in){
- int i = 0;
- try{
- i = in.read() << 24 | (in.read() & 0xff) << 16 | (in.read() & 0xff) << 8 | (in.read() & 0xff);
- }catch(IOException e){
- e.printStackTrace();
- }
- return i;
- }
- void draw(){
- }
Add Comment
Please, Sign In to add comment