Advertisement
Guest User

Untitled

a guest
Mar 5th, 2022
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. /*
  2. 0xFF 0x0 0x0 0x0 0x1 //header
  3. coords = (x << 4 | z);
  4.  
  5. */
  6. //String data = "";
  7. byte[] data = new byte[512*512*32];
  8. int index = -1;
  9. void addint(int b){
  10. index++;
  11. data[index] = (byte)((b>>24)&0xFF);
  12. index++;
  13. data[index] = (byte)((b>>16)&0xFF);
  14. index++;
  15. data[index] = (byte)((b>>8)&0xFF);
  16. index++;
  17. data[index] = (byte)((b)&0xFF);
  18. }
  19. void addbyte(int b){
  20. index++;
  21. data[index] = (byte)(b);
  22. }
  23. int secsize;
  24. boolean exists = true;
  25. void setup(){
  26.  
  27. //draw settings
  28. size(1024,1024);
  29. colorMode(HSB,255,255,255);
  30. secsize = width/8;
  31.  
  32. //0xff and version
  33. addbyte(255);
  34. addint(1);
  35.  
  36. for (int sectionX = 0; sectionX < 8; sectionX++){
  37. for (int sectionZ = 0; sectionZ < 8; sectionZ++) {
  38.  
  39. //add section coordinate
  40. addbyte(((char)sectionX << 4 | (char)sectionZ));
  41. println("Added section: "+sectionX+" "+sectionZ);
  42.  
  43.  
  44. int chunk = 0;
  45. print("Added chunk: ");
  46. for (int chunkX = 0; chunkX < 4; chunkX++){
  47. for (int chunkZ = 0; chunkZ < 4; chunkZ++) {
  48.  
  49.  
  50. chunk +=1;
  51. print(chunk+" ");
  52.  
  53.  
  54. if(!exists){ //chunk doesnt exist so add 0xFFFFFFFF
  55. addbyte(-1); //empty
  56. continue;
  57. }
  58.  
  59. //draw chunks
  60. int chunksize = secsize / 4;
  61.  
  62. //pixel loop
  63. for (int x = 0; x < 16; x++) {
  64. for (int z = 0; z < 16; z++) {
  65.  
  66. boolean notGrass = false; //if its not grass add a extra int for blockstate!
  67. boolean hasOverlays = false; // has overlays, for example water and ice (extra data!)
  68. boolean heightextrabyte = false; //old height (extra byte!)
  69. boolean isCaveBlock = false; // is cave block
  70. boolean hasBiome = false; //has biome (grass & foliage colortype only) (extra byte!)
  71. char light = 15; //light level 0-15
  72. char heightlevel = 64; // height level 0-255
  73. char colortype = 0; //0 - normal, 1 - grass, 2 - foliage, 3 - custom color
  74. char heightshade= 0; //0 - no slope, 1 - bright slope, 2 - dark slope, 3 - unknown slope
  75.  
  76.  
  77. int pp = 0;
  78. pp = pp | (notGrass ? 1 : 0) & 0x1;
  79. pp = pp | ((hasOverlays ? 1 : 0)<<1)& 0x1;
  80. pp = pp | (colortype & 0x3 )<<2;
  81. pp = pp | (heightshade & 0x3)<<4;
  82. pp = pp | ((heightextrabyte ? 1 : 0)<<6);
  83. pp = pp | ((isCaveBlock ? 1 : 0)<<7);
  84. pp = pp | (light & 0xF)<<8;
  85. pp = pp | ((char)heightlevel)<<12;
  86. pp = pp | (hasBiome ? 0x1 : 0x0)<<20;
  87. addint(pp);
  88.  
  89. if(notGrass){
  90. int blockstate = 0; //dunno what to add, color palette?
  91. addint(blockstate);
  92. }
  93.  
  94. if(colortype == 3){
  95. int customColorMultiplier = 0;
  96. addint(customColorMultiplier);
  97. }
  98.  
  99. if(hasBiome || (colortype != 0 && colortype != 3)){
  100. char biome = 0;
  101. addbyte(biome);
  102. }
  103.  
  104. if(hasOverlays){
  105. //skip, no overlays today, i dont need that.
  106. //one byte for amount
  107. //few ints and bytes for each...
  108. }
  109.  
  110. if(heightextrabyte){ // old height. one byte. dont need that.
  111. char oldheight = 0;
  112. addbyte(oldheight);
  113. }
  114.  
  115. //fill chunks
  116. strokeWeight(0);
  117. fill(heightlevel,255,255);
  118. rect(((sectionX*secsize)+(chunkX*chunksize)+x*(secsize/64)),((sectionZ*secsize)+(chunkZ*chunksize)+z*(secsize/64)),(secsize/64),(secsize/64));
  119.  
  120. }
  121. }
  122.  
  123.  
  124. //draw chunk
  125. strokeWeight(1);
  126. fill(0,0,0,0);
  127. stroke(0);
  128. rect((sectionX*secsize)+(chunkX*chunksize), (sectionZ*secsize)+(chunkZ*chunksize),chunksize,chunksize);
  129. }
  130. }
  131.  
  132.  
  133. //draw sections
  134. fill(0,0,0,0);
  135. stroke(0);
  136. strokeWeight(2);
  137. rect((sectionX*secsize),(sectionZ*secsize),secsize,secsize);
  138.  
  139. println(".. done");
  140.  
  141. }
  142. }
  143.  
  144.  
  145. //new array & copy so it wont write 512x512x32 bytes of 0x0...
  146. byte[] b = new byte[index];
  147. for(int i = 0; i < index ; i++){
  148. b[i] = data[i];
  149. }
  150. saveBytes("region.xaero",b);
  151. b=null;
  152. data=null;
  153. }
  154.  
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement