Added it as a library, fixed those errors. Thanks.
Another knucklehead question, though:
I get the errors
C:\Users\David\Desktop\Omen050(2)\minecraft-server\Level Conversion\src\Main.java:27: non-static method loaddat(java.lang.String) cannot be referenced from a static context
LevelEditor2.loaddat("flatgrass1.dat");
C:\Users\David\Desktop\Omen050(2)\minecraft-server\Level Conversion\src\Main.java:28: non-static method savetxt(java.lang.String) cannot be referenced from a static context
LevelEditor2.savetxt("flatgrass1.txt");
from the lines
LevelEditor2.loaddat("flatgrass1.dat");
LevelEditor2.savetxt("flatgrass1.txt");
which reference a class which is a slightly modified version of the LevelEditor class.
Exception in thread "main" java.lang.NullPointerException
at LevelEditor2.savetxt(LevelEditor2.java:57)
at Main.main(Main.java:32)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
yet with a build successful message.
line 57 of leveleditor2.java is
for(int z = 0; z < level.depth; z++) {
line 32 of main.java is
convert.savetxt("flatgrass1.txt");
The loop starting at line 57,
for(int z = 0; z < level.depth; z++) {
for(int y = 0; y < level.height; y++) {
for(int x = 0; x < level.width; x++) {
outputstream.writeByte(level.getTile(x, y, z));
}
}
}
Whenever I try to handle level.width, level.height, or level.depth, the program crashes. Why? This is the root of the problem. The object should not be null, loaddat is being used before I call savetxt.
public class LevelEditor2 {
private com.mojang.minecraft.level.Level level = null;
LevelEditor2() {
}
// load from file called filename
public void loaddat(String filename) {
FileInputStream fis = null;
GZIPInputStream gzis = null;
ObjectInputStream in = null;
DataInputStream inputstream = null;
try {
fis = new FileInputStream(filename);
gzis = new GZIPInputStream(fis);
inputstream = new DataInputStream(gzis);
if((inputstream.readInt()) != 0x271bb788) {
return;
}
if((inputstream.readByte()) > 2) {
System.out.println("Error: Level version > 2, this is unexpected!");
return;
}
in = new ObjectInputStream(gzis);
//level = new com.mojang.minecraft.level.Level();
level = (com.mojang.minecraft.level.Level)in.readObject();
inputstream.close();
in.close();
System.out.println("Loading level "+filename+" successful");
} catch(IOException ex) {
ex.printStackTrace();
} catch(ClassNotFoundException ex) {
ex.printStackTrace();
}
level.initTransient();
}
// save in file called filename
public void savetxt(String filename) {
FileOutputStream fos = null;
//GZIPOutputStream gzos = null;
//ObjectOutputStream out = null;
DataOutputStream outputstream = null;
try {
fos = new FileOutputStream(filename);
//gzos = new GZIPOutputStream(fos);
outputstream = new DataOutputStream(fos);
level.width++;
outputstream.writeByte(2);
outputstream.writeShort(level.width);
//outputstream.writeChars(Integer.toString(level.width));
outputstream.writeChars(" ");
outputstream.writeChars(Integer.toString(level.height));
outputstream.writeChars(" ");
outputstream.writeChars(Integer.toString(level.depth));
outputstream.writeChars(" ");
for(int z = 0; z < level.depth; z++) {
for(int y = 0; y < level.height; y++) {
for(int x = 0; x < level.width; x++) {
outputstream.writeByte(level.getTile(x, y, z));
}
}
}
//out = new ObjectOutputStream(gzos);
//out.writeObject(level);
//outputstream.close();
//out.close();
//System.out.println("Saving level "+filename+" successful");
} catch(IOException ex) {
ex.printStackTrace();
}
}
...
EDIT: I got it working now. Now I just need Spadge to get his rear end back on the internet.
I need to use Notch's java classes for the code I'm writing (namely com.mojang.minecraft.level.Level) but I can't figure out how.
I hate Java :tongue.gif:
Ex:
java -cp minecraft-server.jar
If you're using an IDE you need to add it as a library.
[bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf]
Added it as a library, fixed those errors. Thanks.
Another knucklehead question, though:
I get the errors
from the lines
LevelEditor2.loaddat("flatgrass1.dat");
LevelEditor2.savetxt("flatgrass1.txt");
which reference a class which is a slightly modified version of the LevelEditor class.
Static means it doesn't exist as a property of an object.
EDIT: Also, read this: http://java.sun.com/docs/books/tutorial/java/concepts/
[bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf] [bookshelf]
EDIT: Last quesiton, I think
I got some error text
yet with a build successful message.
line 57 of leveleditor2.java is
for(int z = 0; z < level.depth; z++) {
line 32 of main.java is
convert.savetxt("flatgrass1.txt");
The loop starting at line 57,
did not write the bytes it was supposed to.
EDIT: I got it working now. Now I just need Spadge to get his rear end back on the internet.