Skip to content

Commit

Permalink
Version 1.5! Changes:
Browse files Browse the repository at this point in the history
Bugfix in the Tag class, dealing with TAG_Compound entries being added.

Creative Mode enable/disable.

Signed-off-by: Chris Iverson <[email protected]>
  • Loading branch information
iversc committed Sep 10, 2011
1 parent a99f658 commit 4e11c33
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 17 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="miglayout15-swing.jar" sourcepath="miglayout-src.zip"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 15 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
===============================================================
Version 1.5 -
===============================================================

Added the ability to toggle 1.8+ worlds between Creative and
Survival mode.

Also fixed a bug in the Tag class, that prevented TAG_Compound
entries from being modified correctly.

===============================================================
Version 1.4 -
===============================================================

Minor tweaks. Made the GUI use the look and feel of the current system instead of Java's default look and feel, which makes it look better no matter the platform you're on.
Minor tweaks. Made the GUI use the look and feel of the current
system instead of Java's default look and feel, which makes it
look better no matter the platform you're on.

Also modified the 'About' menu text to include the github site for the source code.
Also modified the 'About' menu text to include the github site
for the source code.

Changed behavior of folder selection dialog; now, it runs three checks after a folder has been chosen. In the folder chosen, it checks for the existence of 'level.dat', 'session.lock', and the 'region' folder. If all three exist, the folder chosen is most likely a world folder instead of the saves folder required, so the program automatically sets the chosen path to the parent folder. Let me know if any problems come from this.

Expand Down
2 changes: 2 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Minecraft Save Seed Reader

This program reads and displays the seed from all found minecraft Save files. Just select a world's name from the dropdown list that shows up to get that world's seed.

If the save file is a 1.8+ save file, you can switch the world between Creative and Survival mode by checking the box and hitting 'Save'.

If you do not see your save files, or if you get an error stating the saves aren't found, try locating the Minecraft saves folder manually, either in the popup or by opening the Help menu and choosing "Select MC Save Location". You have to select the 'saves' folder, not any of the world folders in the 'saves' folder.


Expand Down
Binary file modified bin/minecraftSeed/MinecraftSeed.class
Binary file not shown.
Binary file modified bin/minecraftSeed/Tag.class
Binary file not shown.
Binary file added miglayout-src.zip
Binary file not shown.
Binary file added miglayout15-swing.jar
Binary file not shown.
112 changes: 98 additions & 14 deletions src/minecraftSeed/MinecraftSeed.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package minecraftSeed;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

import javax.swing.*;
import net.miginfocom.swing.MigLayout;

class DirFilter implements FilenameFilter {

Expand All @@ -25,8 +25,12 @@ public class MinecraftSeed implements ActionListener {
private String[] filePaths;
private int validNames;
private JComboBox combo;
private JCheckBox cbCreative;
private boolean creativeEnabled;
private JButton btnSave;
private String selectedFilePath;

private final Double version = 1.4;
private final Double version = 1.5;

public MinecraftSeed()
{
Expand Down Expand Up @@ -68,15 +72,13 @@ public MinecraftSeed()


panel = new JPanel();
panel.setLayout(new FlowLayout());

combo = new JComboBox();
combo.addActionListener(this);

text = new JTextField();
text.setColumns(20);

setupData();

JMenuBar menuBar = new JMenuBar();
JMenu helpMenu = new JMenu("Help");
Expand All @@ -100,10 +102,26 @@ public MinecraftSeed()

menuBar.add(helpMenu);
frame.setJMenuBar(menuBar);
panel.setLayout(new MigLayout("", "[28px][166px][95px]", "[23px][]"));

panel.add(combo);
panel.add(text);
panel.add(combo, "cell 0 0,alignx left,aligny center");
panel.add(text, "cell 1 0 2 1,growx");
frame.getContentPane().add(panel);

cbCreative = new JCheckBox("Creative Mode");
cbCreative.setEnabled(false);
cbCreative.setActionCommand("creativetoggle");
cbCreative.addActionListener(this);
panel.add(cbCreative, "flowx,cell 1 1,alignx left,aligny top");

btnSave = new JButton("Save Changes");
btnSave.setEnabled(false);
btnSave.setActionCommand("save");
btnSave.addActionListener(this);
panel.add(btnSave, "cell 2 1");

setupData();

frame.pack();

//Center on screen
Expand All @@ -117,7 +135,7 @@ public static void main(String[] args) {
new MinecraftSeed();

} catch(Exception e) { //If anything unexpected goes wrong in the main program,
//write it to an error log
//write it to an error log
try {
FileOutputStream fos = new FileOutputStream("MinecraftSeed.error.log");
e.printStackTrace(new PrintStream(fos));
Expand All @@ -133,7 +151,7 @@ public static void main(String[] args) {
} catch (IOException e2) {
e.printStackTrace();
}

e.printStackTrace();
}

}
Expand Down Expand Up @@ -180,7 +198,7 @@ private void setupData()
} else {
combo.addItem((String)name.getValue());
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
Expand Down Expand Up @@ -251,19 +269,40 @@ public void actionPerformed(ActionEvent arg0) {
//Make sure something was actually chosen
if(val > -1)
{
//Disable the save button
btnSave.setEnabled(false);

try {
FileInputStream fis = new FileInputStream(new File(filePaths[val]));
selectedFilePath = filePaths[val];
FileInputStream fis = new FileInputStream(new File(selectedFilePath));
main = Tag.readFrom(fis);
fis.close();

text.setText(main.findTagByName("RandomSeed").getValue().toString());

//Only if the save file has a 'GameType' entry will
//we allow the user to switch between Creative on and off.
Tag creative = main.findTagByName("GameType");
if(creative==null)
{
cbCreative.setEnabled(false);
}
else
{
cbCreative.setEnabled(true);

//Check the box if creative is enabled
creativeEnabled = ((Integer)creative.getValue() == 1);
cbCreative.setSelected(creativeEnabled);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} else { //One of the menu items was chosen
} else { //One of the menu items was chosen, or the checkbox was checked,
//or "save" was pressed
String cmd = arg0.getActionCommand();

//"How to use" menu item
Expand All @@ -272,7 +311,10 @@ public void actionPerformed(ActionEvent arg0) {
String message = "Choose the world's name from the dropdown list." +
"\nThe world's seed will show up in the textbox." +
"\n\nIf the list is empty, click on Help > Select MC Save Folder," +
"\nand find and open the saves folder in the file chooser.";
"\nand find and open the saves folder in the file chooser.\n" +
"\nIf the save is a version 1.8+ save, you can switch the world" +
"\nbetween Creative and Survival by checking the checkbox, then" +
"\nhitting Save.";

JOptionPane.showMessageDialog(panel, message, "How to Use", JOptionPane.INFORMATION_MESSAGE);
}
Expand All @@ -297,8 +339,50 @@ public void actionPerformed(ActionEvent arg0) {
//Only load the data if the user selected a folder
if(chooseSaveFolder()) setupData();
}
}

//Checkbox checked
if(cmd.equals("creativetoggle"))
{
//File manipulation here
creativeEnabled = !creativeEnabled;

Tag data = main.findTagByName("Data");
Tag creative = data.findTagByName("GameType");
data.removeSubTag(creative);


creative = new Tag(Tag.Type.TAG_Int, "GameType", (creativeEnabled) ? 1 : 0);
data.addTag(creative);

//Enable the "Save" button
btnSave.setEnabled(true);
}

//Save button pressed
if(cmd.equals("save"))
{
int chosen = JOptionPane.showConfirmDialog(frame, "Are you sure you want to overwrite your save file?",
"Overwrite", JOptionPane.YES_NO_OPTION);

if(chosen == JOptionPane.YES_OPTION);
{
try {
FileOutputStream fos = new FileOutputStream(new File(selectedFilePath));
main.writeTo(fos);
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, "Problem saving file: File Not Found", "File Not Found", JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, "Problem saving file: IO Error", "IO Error", JOptionPane.ERROR_MESSAGE);
}

JOptionPane.showMessageDialog(frame, "File saved!");
}
}
} // else

}
} //actionPerformed

}
9 changes: 8 additions & 1 deletion src/minecraftSeed/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ public void addTag(Tag tag) {
if (type != Type.TAG_List && type != Type.TAG_Compound)
throw new RuntimeException();
Tag[] subtags = (Tag[]) value;
insertTag(tag, subtags.length);

int index = subtags.length;

//For TAG_Compund entries, we need to add the tag BEFORE the end,
//or the new tag gets placed after the TAG_End, messing up the data.
//TAG_End MUST be kept at the very end of the TAG_Compound.
if(type == Type.TAG_Compound) index--;
insertTag(tag, index);
}

/**
Expand Down

0 comments on commit 4e11c33

Please sign in to comment.