Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- import org.jnbt.*;
- public class test
- {
- static byte[] ref;
- static boolean[][][] picked = new boolean[16][16][128];
- static MCObjWriter out = new MCObjWriter();
- static int count;
- public static ArrayList<String> list = new ArrayList<String>();
- public static void main(String[] args) throws IOException
- {
- File f = new File("C:\\Users\\adam\\AppData\\Roaming\\.minecraft\\saves\\World1");
- next(f);
- Collections.sort(list);
- File outfile = new File("objtest.obj");
- for(String thing : list)
- {
- if (count > 300)
- break;
- picked = new boolean[16][16][128];
- FileInputStream i;
- try {
- i = new FileInputStream(new File(thing));
- } catch (FileNotFoundException e) {
- break;
- }
- Tag t = Tag.readFrom(i);
- int xoffset = (Integer) t.findTagByName("xPos").getValue();
- int zoffset = (Integer) t.findTagByName("zPos").getValue();
- xoffset*=16;
- zoffset*=16;
- t = t.findTagByName("Blocks");
- byte[] blocks = (byte[]) t.getValue();
- ref = blocks;
- Byte current;
- for (int y = 0; y < 128; y++)
- {
- for (int z = 0; z < 16; z++)
- {
- for(int x = 0; x < 16; x++)
- {
- current = blocks[y + (z*128 + (x*128*16))];
- if(current == 0 || current == 18 || current == 9)
- {
- if((x!=0) && blocks[y + (z*128 + ((x-1)*128*16))] != 0 && draw(x-1,y,z))
- out.add(x-1 + xoffset, y, z + zoffset, blocks[y + (z*128 + ((x-1)*128*16))]);
- if((z!=0) && blocks[y + ((z-1)*128 + ((x)*128*16))] != 0 && draw(x,y,z-1))
- out.add(x + xoffset, y, z-1 + zoffset, blocks[y + ((z-1)*128 + ((x)*128*16))]);
- if((y!=0) && blocks[y-1 + ((z)*128 + ((x)*128*16))] != 0 && draw(x,y-1,z))
- out.add(x + xoffset, y-1, z + zoffset, blocks[y-1 + ((z)*128 + ((x)*128*16))]);
- if((x!=15) && blocks[y + (z*128 + ((x+1)*128*16))] != 0 && draw(x+1,y,z))
- out.add(x+1 + xoffset, y, z + zoffset, blocks[y + (z*128 + ((x+1)*128*16))]);
- if((z!=15) && blocks[y + ((z+1)*128 + ((x)*128*16))] != 0 && draw(x,y,z+1))
- out.add(x + xoffset, y, z+1 + zoffset, blocks[y + ((z+1)*128 + ((x)*128*16))]);
- if((y!=127) && blocks[y+1 + ((z)*128 + ((x)*128*16))] != 0 && draw(x,y+1,z))
- out.add(x + xoffset, y+1, z + zoffset, blocks[y+1 + ((z)*128 + ((x)*128*16))]);
- }
- }
- //System.out.println("");
- }
- //System.out.println("\n\n\n\n");
- }
- System.out.println("done! " + ++count);
- }
- out.write(outfile);
- System.out.println("completely done!");
- }
- public static boolean draw(int x, int y,int z)
- {
- if(!picked[x][z][y])
- {
- picked[x][z][y] = true;
- return true;
- }
- return false;
- }
- public static void next(File current)
- {
- if(current.isDirectory())
- {
- for(String s : current.list())
- {
- next(new File(current.getAbsolutePath() + "\\" + s));
- }
- }
- else
- {
- if (current.toString().endsWith(".dat"))
- list.add(current.toString());
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement