Guest User

Untitled

a guest
Mar 3rd, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1.  
  2.  
  3. void setup(){
  4. size(512,512);
  5. frameRate(30);
  6. loadPixels();
  7. colorMode(HSB, 255,100,100);
  8. InputStream in = createInput("region.xaero");
  9. try{
  10.  
  11. int minorSaveVersion = -1;
  12. int majorSaveVersion = 0;
  13. int firstByte = in.read();
  14. if(firstByte == 255){
  15. int fullVersion = readInt(in);
  16. println("version " + fullVersion);
  17. minorSaveVersion = fullVersion & 65535;
  18. majorSaveVersion = (fullVersion >> 16) & 65535;
  19. println("major version " + majorSaveVersion);
  20. println("minor version " + minorSaveVersion);
  21. firstByte = -1;
  22. }
  23.  
  24. while (true) {
  25. int sectionCoords = firstByte == -1 ? in.read() : firstByte;
  26. if(sectionCoords == -1){//end reached
  27. print("end reached");
  28. break;
  29. }
  30. firstByte = -1;
  31. //section coordinates inside the region
  32. int sectionX = sectionCoords >> 4;
  33. int sectionZ = sectionCoords & 15;
  34. println("section "+sectionX+", "+sectionZ);
  35.  
  36. //start reading the section
  37. int chunks = 0;
  38. for (int chunkX = 0; chunkX < 4; chunkX++){
  39. for (int chunkZ = 0; chunkZ < 4; chunkZ++) {
  40. chunks++;
  41. int firstPixelInfo = readInt(in); //info for the first chunk pixel
  42. if (firstPixelInfo == -1){ //-1 if the chunk is empty
  43. println("chunk "+chunks+" empty at "+chunkX+", "+chunkZ+" ");
  44. continue;
  45. }
  46. //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)+" ");
  47. println("chunk "+chunks+" found at "+chunkX+", "+chunkZ);
  48. for (int x = 0; x < 16; x++) {
  49. for (int z = 0; z < 16; z++) {
  50. int info;
  51. if(x==0&&z==0){
  52. info = firstPixelInfo;
  53. }else{
  54. info = readInt(in);
  55. }
  56. int col = readPixel(x,z, info, in);
  57. set(((sectionX*64)+(chunkX*16)+x),((sectionZ*64)+(chunkZ*16)+z),color(col,100,100));
  58. }
  59. }
  60.  
  61.  
  62. fill(color(0));
  63. strokeWeight(1);
  64. //text("x",((sectionX*64)+(chunkX*16))+5,((sectionZ*64)+(chunkZ*16))+9);
  65. line(sectionX*64+(chunkX*16),sectionZ*64+(chunkZ*16),sectionX*64+(chunkX*16)+16,sectionZ*64+(chunkZ*16));
  66. line(sectionX*64+(chunkX*16)+16,sectionZ*64+(chunkZ*16),sectionX*64+(chunkX*16)+16,sectionZ*64+(chunkZ*16)+16);
  67. line(sectionX*64+(chunkX*16)+16,sectionZ*64+(chunkZ*16)+16,sectionX*64+(chunkX*16),sectionZ*64+(chunkZ*16)+16);
  68. line(sectionX*64+(chunkX*16),sectionZ*64+(chunkZ*16)+16,sectionX*64+(chunkX*16),sectionZ*64+(chunkZ*16));//fuck me
  69. }}
  70. fill(color(64,100,100));
  71. strokeWeight(2);
  72. text(""+sectionX+"|"+sectionZ,(sectionX*64)+1,(sectionZ*64)+12);
  73. line((sectionX*64),(sectionZ*64),(sectionX*64)+64,(sectionZ*64));
  74. line((sectionX*64)+64,(sectionZ*64),(sectionX*64)+64,(sectionZ*64)+64);
  75. line((sectionX*64)+64,(sectionZ*64)+64,(sectionX*64),(sectionZ*64)+64);
  76. line((sectionX*64),(sectionZ*64)+64,(sectionX*64),(sectionZ*64));
  77.  
  78. }
  79.  
  80. }catch(IOException e){
  81. e.printStackTrace();
  82. }
  83.  
  84. //updatePixels();
  85.  
  86.  
  87. }
  88.  
  89.  
  90. int readPixel(int x, int z, int info, InputStream in){
  91. int col = 0;
  92. try{
  93. if ((info & 1) != 0) { // it isn't grass, so read 4 bytes???
  94. int state = readInt(in);
  95. }
  96.  
  97.  
  98. int heightType = (info >> 4) & 3;//0 - no slope, 1 - bright slope, 2 - dark slope, 3 - unknown slope
  99. int heigt;
  100. if ((info & 64) != 0){//old height, read a byte.
  101. heigt = in.read();
  102. }else{
  103. heigt = (info >> 12) & 255;
  104. }
  105. if ((info & 2) != 0) {// has overlays, for example water and ice, read a byte.
  106. int amount = in.read();
  107. for (int i = 0; i < amount; i++)
  108. {
  109. readOverlay(in,info);
  110. }
  111. int colorType = (info >> 2) & 3;//0 - normal, 1 - grass, 2 - foliage, 3 - custom color
  112. int customColorMultiplier = -1;
  113. int biome = 0;
  114. if (colorType == 3) // read 4 bytes
  115. customColorMultiplier = readInt(in);
  116. if(colorType != 0 && colorType != 3 || (info & 1048576) != 0)// read 1 byte
  117. biome = in.read();
  118. if(colorType == 3 && customColorMultiplier == -1)
  119. colorType = 0;
  120.  
  121. boolean caveBlock = (info & 128) != 0;
  122. int light = (info >> 8) & 15;
  123. }
  124. }catch(IOException e){
  125. e.printStackTrace();
  126. }
  127. return col;
  128. }
  129.  
  130.  
  131.  
  132. void readOverlay(InputStream in, int info){
  133. //overlays
  134. //int info = readInt(in);
  135. if ((info & 1) != 0) { //isnt water so read 4 bytes
  136. int state = readInt(in);
  137. }else{ }
  138.  
  139. int opacity = 1;
  140.  
  141. int colorType = (info >> 8) & 3;
  142. int customColorMultiplier = -1;
  143. if (colorType == 2 || (info & 4) != 0){
  144. colorType = 2;
  145. customColorMultiplier = readInt(in);
  146. if(customColorMultiplier == -1)
  147. colorType = 0;
  148. }
  149. if ((info & 8) != 0) // opacity not 1
  150. opacity = readInt(in);
  151. int light = (info >> 4) & 15;
  152. //end overlays
  153. }
  154.  
  155. int readInt(InputStream in){
  156. int i = 0;
  157. try{
  158. i = in.read() << 24 | (in.read() & 0xff) << 16 | (in.read() & 0xff) << 8 | (in.read() & 0xff);
  159. }catch(IOException e){
  160. e.printStackTrace();
  161. }
  162. return i;
  163. }
  164.  
  165.  
  166.  
  167. void draw(){
  168.  
  169. }
Add Comment
Please, Sign In to add comment