Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.08 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4. import java.util.Scanner;
  5.  
  6.  
  7.  
  8. import org.jnbt.*;
  9.  
  10. public class test
  11. {
  12.     static byte[] ref;
  13.     static boolean[][][] picked = new boolean[16][16][128];
  14.     static MCObjWriter out = new MCObjWriter();
  15.     static int count;
  16.     public static ArrayList<String> list = new ArrayList<String>();
  17.    
  18.     public static void main(String[] args) throws IOException
  19.     {
  20.         File f = new File("C:\\Users\\adam\\AppData\\Roaming\\.minecraft\\saves\\World1");
  21.         next(f);
  22.         Collections.sort(list);
  23.         File outfile = new File("objtest.obj");
  24.         for(String thing : list)
  25.         {
  26.             if (count > 300)
  27.                 break;
  28.             picked = new boolean[16][16][128];
  29.             FileInputStream i;
  30.             try {
  31.                 i = new FileInputStream(new File(thing));
  32.             } catch (FileNotFoundException e) {
  33.                 break;
  34.             }
  35.             Tag t = Tag.readFrom(i);
  36.             int xoffset = (Integer) t.findTagByName("xPos").getValue();
  37.             int zoffset = (Integer) t.findTagByName("zPos").getValue();
  38.             xoffset*=16;
  39.             zoffset*=16;
  40.             t = t.findTagByName("Blocks");
  41.             byte[] blocks = (byte[]) t.getValue();
  42.             ref = blocks;
  43.             Byte current;
  44.    
  45.            
  46.            
  47.            
  48.             for (int y = 0; y < 128; y++)
  49.             {
  50.                 for (int z = 0; z < 16; z++)
  51.                 {
  52.                     for(int x = 0; x < 16; x++)
  53.                     {
  54.                         current = blocks[y + (z*128 + (x*128*16))];
  55.                        
  56.                         if(current == 0 || current == 18 || current == 9)
  57.                         {
  58.                             if((x!=0) && blocks[y + (z*128 + ((x-1)*128*16))] != 0 && draw(x-1,y,z))
  59.                                 out.add(x-1 + xoffset, y, z + zoffset, blocks[y + (z*128 + ((x-1)*128*16))]);
  60.                             if((z!=0) && blocks[y + ((z-1)*128 + ((x)*128*16))] != 0 && draw(x,y,z-1))
  61.                                 out.add(x + xoffset, y, z-1 + zoffset, blocks[y + ((z-1)*128 + ((x)*128*16))]);
  62.                             if((y!=0) && blocks[y-1 + ((z)*128 + ((x)*128*16))] != 0 && draw(x,y-1,z))
  63.                                 out.add(x + xoffset, y-1, z + zoffset, blocks[y-1 + ((z)*128 + ((x)*128*16))]);
  64.                            
  65.                             if((x!=15) && blocks[y + (z*128 + ((x+1)*128*16))] != 0 && draw(x+1,y,z))
  66.                                 out.add(x+1 + xoffset, y, z + zoffset, blocks[y + (z*128 + ((x+1)*128*16))]);
  67.                             if((z!=15) && blocks[y + ((z+1)*128 + ((x)*128*16))] != 0 && draw(x,y,z+1))
  68.                                 out.add(x + xoffset, y, z+1 + zoffset, blocks[y + ((z+1)*128 + ((x)*128*16))]);
  69.                             if((y!=127) && blocks[y+1 + ((z)*128 + ((x)*128*16))] != 0 && draw(x,y+1,z))
  70.                                 out.add(x + xoffset, y+1, z + zoffset, blocks[y+1 + ((z)*128 + ((x)*128*16))]);
  71.                         }
  72.                        
  73.                     }
  74.                     //System.out.println("");
  75.                 }
  76.                 //System.out.println("\n\n\n\n");
  77.             }
  78.             System.out.println("done! " + ++count);
  79.         }      
  80.         out.write(outfile);
  81.         System.out.println("completely done!");
  82.     }
  83.    
  84.     public static boolean draw(int x, int y,int z)
  85.     {
  86.         if(!picked[x][z][y])
  87.         {
  88.             picked[x][z][y] = true;
  89.             return true;
  90.         }
  91.         return false;
  92.     }
  93.    
  94.     public static void next(File current)
  95.     {
  96.         if(current.isDirectory())
  97.         {
  98.             for(String s : current.list())
  99.             {
  100.                 next(new File(current.getAbsolutePath() + "\\" + s));
  101.             }
  102.         }
  103.         else
  104.         {
  105.             if (current.toString().endsWith(".dat"))
  106.                 list.add(current.toString());
  107.         }
  108.         return;
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement