Find and report player position in Minecraft save file


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import java.io.FileInputStream;
  2.  
  3. /**
  4.  *
  5.  * @author jkerr88
  6.  *
  7.  * You need the code from here:
  8.  *
  9.  * http://www.minecraftwiki.net/wiki/NBT_class
  10.  *
  11.  * saved as Tag.java in the same folder as this one. This file should be saved as ReportPlayerLocation.java
  12.  *
  13.  */
  14. public class ReportPlayerLocation implements Runnable{
  15.  
  16. static ReportPlayerLocation iThis;
  17. static String isCurrentFile;
  18.  
  19. public static void main(String argv[]){
  20.  
  21. iThis = new ReportPlayerLocation();
  22. Thread t = new Thread(iThis);
  23. t.start();
  24.  
  25. } // main
  26.  
  27. public void run() {
  28.  
  29. String sWorldFolder = "C:\\Documents and Settings\\Jeff\\Application Data\\.minecraft\\saves\\World1";
  30.  
  31. try{
  32.  
  33. Tag datFileTag = Tag.readFrom(new FileInputStream(sWorldFolder + "\\level.dat"));
  34. reportPlayerPositionFromTag(datFileTag);
  35.  
  36. }catch(Exception e){
  37. System.out.println(e);
  38. return;
  39. }
  40.  
  41. System.out.println("\nDone!");
  42.  
  43. }
  44.  
  45.  
  46. private void reportPlayerPositionFromTag(Tag p_tag){
  47.  
  48. Tag.Type type = p_tag.getType();
  49. if (type == Tag.Type.TAG_End)
  50. return;
  51.  
  52. String sName = p_tag.getName();
  53.  
  54. if (type == Tag.Type.TAG_Byte_Array) {
  55.  
  56. } else if (type == Tag.Type.TAG_List) {
  57. Tag[] subtags = (Tag[]) p_tag.getValue();
  58. for (Tag st : subtags) {
  59. reportPlayerPositionFromTag(st);
  60. }
  61.  
  62. if(sName.equals("Pos")){
  63. System.out.println("Found Player Pos: (X is NS, Y is Altitude, Z is EW");
  64.  
  65. Double nX = (Double) subtags[0].getValue();
  66. Double nY = (Double) subtags[1].getValue();
  67. Double nZ = (Double) subtags[2].getValue();
  68.  
  69. System.out.println("X: " + Math.round(nX.doubleValue()));
  70. System.out.println("Y: " + Math.round(nY.doubleValue()));
  71. System.out.println("Z: " + Math.round(nZ.doubleValue()));
  72.  
  73. System.out.println("\nChunk: (x/16, z/16)");
  74.  
  75. System.out.println("xPos: " + Math.floor(nX.doubleValue()/16));
  76. System.out.println("zPos: " + Math.floor(nZ.doubleValue()/16));
  77.  
  78. }
  79.  
  80. } else if (type == Tag.Type.TAG_Compound) {
  81. Tag[] subtags = (Tag[]) p_tag.getValue();
  82. for (Tag st : subtags) {
  83. reportPlayerPositionFromTag(st);
  84. }
  85. } else {
  86.  
  87. }
  88.  
  89. }
  90.  
  91. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.