AMIDST in its current state

All items in MoF package should eventually be replaced.
master
Skiphs 2013-03-30 06:19:00 -07:00
parent e2f4764059
commit 8a63d46b1c
35 changed files with 3528 additions and 0 deletions

BIN
images/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

BIN
images/netherhold.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
images/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
images/pyramid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
images/slime.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
images/stronghold.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
images/village.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
images/witch.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

95
src/MoF/Biome.java Normal file
View File

@ -0,0 +1,95 @@
package MoF;
import java.awt.Color;
public class Biome {
public static Color[] colors = new Color[] {
new Color(13 ,51 ,219), //Ocean;
new Color(104,222,104), //Plains;
new Color(226,242,131), //Desert;
new Color(171,105,34 ), //Extreme Hills;
new Color(40 ,181,22 ), //Forest;
new Color(32 ,110,22 ), //Taiga;
new Color(108,158,79), //Swampland;
new Color(14,127,227), //River;
new Color(143,25 ,10 ), //Hell;
new Color(209,233,235), //Sky;
new Color(70 ,104,199), //FrozenOcean;
new Color(171,216,255), //FrozenRiver;
new Color(156,214,190), //Ice Plains;
new Color(151,162,130), //Ice Mountains;
new Color(219,196,164), //MushroomIsland;
new Color(242,216,179), //MushroomIslandShore;
new Color(255,254,189), //Beach
new Color(230,202, 78), //DesertHills
new Color(89 ,176, 32), //ForestHills
new Color(66 ,110, 22), //TaigaHills
new Color(186,159, 39), //Extreme Hills Edge
new Color(26 ,87 ,34 ),
new Color(73 ,105,33 )
};
public static final Biome[] a = new Biome[256];
public static final Biome b = new Biome(0).b(112).a("Ocean").b(-1.0F, 0.4F);
public static final Biome c = new Biome(1).b(9286496).a("Plains").a(0.8F, 0.4F);
public static final Biome d = new Biome(2).b(16421912).a("Desert").g().a(2.0F, 0.0F).b(0.1F, 0.2F);
public static final Biome e = new Biome(3).b(6316128).a("Extreme Hills").b(0.2F, 1.8F).a(0.2F, 0.3F);
public static final Biome f = new Biome(4).b(353825).a("Forest").a(5159473).a(0.7F, 0.8F);
public static final Biome g = new Biome(5).b(747097).a("Taiga").a(5159473).a(0.3F, 0.8F).b(0.1F, 0.4F);
public static final Biome h = new Biome(6).b(522674).a("Swampland").a(9154376).b(-0.2F, 0.1F).a(0.8F, 0.9F);
public static final Biome i = new Biome(7).b(255).a("River").b(-0.5F, 0.0F);
public static final Biome j = new Biome(8).b(16711680).a("Hell").g().a(2.0F, 0.0F);
public static final Biome k = new Biome(9).b(8421631).a("Sky").g();
public static final Biome l = new Biome(10).b(9474208).a("FrozenOcean").b(-1.0F, 0.5F).a(0.0F, 0.5F);
public static final Biome m = new Biome(11).b(10526975).a("FrozenRiver").b(-0.5F, 0.0F).a(0.0F, 0.5F);
public static final Biome n = new Biome(12).b(16777215).a("Ice Plains").a(0.0F, 0.5F);
public static final Biome o = new Biome(13).b(10526880).a("Ice Mountains").b(0.2F, 1.8F).a(0.0F, 0.5F);
public static final Biome p = new Biome(14).b(16711935).a("MushroomIsland").a(0.9F, 1.0F).b(0.2F, 1.0F);
public static final Biome q = new Biome(15).b(10486015).a("MushroomIslandShore").a(0.9F, 1.0F).b(-1.0F, 0.1F);
public static final Biome r = new Biome(16).b(16440917).a("Beach").a(0.8F, 0.4F).b(0.0F, 0.1F);
public static final Biome s = new Biome(17).b(13786898).a("DesertHills").g().a(2.0F, 0.0F).b(0.2F, 0.7F);
public static final Biome t = new Biome(18).b(2250012).a("ForestHills").a(5159473).a(0.7F, 0.8F).b(0.2F, 0.6F);
public static final Biome u = new Biome(19).b(1456435).a("TaigaHills").a(5159473).a(0.05F, 0.8F).b(0.2F, 0.7F);
public static final Biome v = new Biome(20).b(7501978).a("Extreme Edge").b(0.2F, 0.8F).a(0.2F, 0.3F);
public static final Biome w = new Biome(21).b(5470985).a("Jungle").a(5470985).a(1.2F, 0.9F).b(0.2F, 0.4F);
public static final Biome x = new Biome(22).b(2900485).a("JungleHills").a(5470985).a(1.2F, 0.9F).b(1.8F, 0.2F);
public String name;
public Biome(int number) {
a[number] = this;
}
public Biome b(int l) {
return this;
}
public Biome a(String name) {
this.name = name;
return this;
}
public Biome a(float f1, float f2) {
return this;
}
public Biome b(float f1, float f2) {
return this;
}
public Biome g() {
return this;
}
public Biome a(int a) {
return this;
}
}

324
src/MoF/ChunkManager.java Normal file
View File

@ -0,0 +1,324 @@
package MoF;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Stack;
public class ChunkManager extends Thread
{
private Object b;
public float[] a;
public long seed;
public Point[] strongholds;
private Stack<Fragment> queue;
private MapGenVillage villageFinder;
private MapGenNetherhold netherholdFinder;
private MapGenPyramid pyramidFinder;
private boolean active;
private static Class<?> iBiome, iCache, s12w03a;
private Method getData, clearCache;
private ArrayList<Player> players;
private static boolean firstRun = true;
private SkinManager m;
public ChunkManager(long seed) {
try {
if (firstRun) {
iBiome = ClassLoader.getSystemClassLoader().loadClass(MoF.chunkName);
iCache = ClassLoader.getSystemClassLoader().loadClass(MoF.intCacheName);
Type t = null;
if (MoF.versionID >= 9) {
Method cs[] = iBiome.getDeclaredMethods();
for (int i = 0; i < cs.length; i++) {
Class<?>[] types = cs[i].getParameterTypes();
if ((types.length == 2)&&(types[1]!=long.class)) {
t = types[1];
}
}
System.out.println("Err: " + t.toString());
s12w03a = ClassLoader.getSystemClassLoader().loadClass(t.toString().split(" ")[1]);
}
firstRun = false;
}
Object[] ret = null;
Method init;
clearCache = iCache.getDeclaredMethod("a");
if (MoF.versionID >= 9) {
init = iBiome.getDeclaredMethod("a", new Class[] {Long.TYPE, s12w03a});
String genString = "b";
if (SaveLoader.genType.equals("flat"))
genString = "c";
else if (SaveLoader.genType.equals("largeBiomes"))
genString = "d";
System.out.println("GenString: " + genString);
ret = (Object[])init.invoke(null, seed, s12w03a.getField(genString).get(null));
} else {
init = iBiome.getDeclaredMethod("a", new Class[] {Long.TYPE});
ret = (Object[])init.invoke(null, seed);
}
this.b = ret[0];
getData = iBiome.getMethod("a", new Class[] {Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE} );
} catch (Exception e) {
e.printStackTrace();
}
m = new SkinManager();
m.start();
this.seed = seed;
strongholds = (new MapGenStronghold().a(seed, this));
queue = new Stack<Fragment>();
players = new ArrayList<Player>();
active = true;
villageFinder = new MapGenVillage();
netherholdFinder = new MapGenNetherhold(seed);
pyramidFinder = new MapGenPyramid();
}
public void dispose() {
System.out.println("DISPOSING OF CHUNKMANAGER");
this.active = false;
this.b = null;
this.strongholds = null;
this.queue.clear();
this.queue = null;
this.villageFinder = null;
this.getData = null;
this.clearCache = null;
this.players.clear();
this.players = null;
this.netherholdFinder = null;
}
private int[] ba(int a, int b, int c, int d) {
try {
clearCache.invoke(iCache);
int[] temp = (int[])getData.invoke(this.b, a,b,c,d);
return temp;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public byte[] getBiomeForArea(int x, int y, int range) {
byte[] barr = new byte[range*range];
int[] temp = ba(x*Project.FRAGMENT_SIZE, y*Project.FRAGMENT_SIZE, range, range);
for (int i = 0; i < barr.length; i++) {
barr[i] = (byte)temp[i];
}
return barr;
}
public void run() {
while (this.active) {
if (!queue.isEmpty()) {
Fragment frag = queue.pop();
if (frag.active) {
drawBiomeData(frag);
getStrongholdData(frag);
getVillageData(frag);
getSlimeData(frag);
getPlayerData(frag);
getNetherholdData(frag);
if (MoF.versionID >= 21)
getPyramidData(frag);
/*try {
Thread.sleep(5L);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
}
} else {
try {
Thread.sleep(5L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private void getPlayerData(Fragment frag) {
for (int i = 0; i < players.size(); i++) {
Player p = players.get(i);
if (frag.isInside(p.x, p.y)) {
frag.addMapObject(p);
}
}
}
public void addPlayer(Player p) {
players.add(p);
m.addPlayer(p);
}
public void setPlayerData(ArrayList<Player> ar) {
players = ar;
for (int i = 0; i < ar.size(); i++) {
m.addPlayer(ar.get(i));
}
}
private void getSlimeData(Fragment frag) {
Graphics2D g2d = frag.newLayer();
int fs = Project.FRAGMENT_SIZE >> 2;
for (int y = 0; y < fs; y++) {
for (int x = 0; x < fs; x++) {
int xPosition = (frag.x*fs) + (x);
int zPosition = (frag.y*fs) + (y);
Random rnd = new Random(seed + (long) (xPosition * xPosition * 0x4c1906) + (long) (xPosition * 0x5ac0db) +
(long) (zPosition * zPosition) * 0x4307a7L + (long) (zPosition * 0x5f24f) ^ 0x3ad8025f);
if (rnd.nextInt(10) == 0) {
g2d.drawImage(MapMarker.slime,
x << 2,
y << 2,
4, 4, null);
}
}
}
g2d.dispose();
}
private void getNetherholdData(Fragment frag) {
int fs = Project.FRAGMENT_SIZE >> 2;
int ls = Project.FRAGMENT_SIZE << 2;
for (int y = 0; y < fs; y++) {
for (int x = 0; x < fs; x++) {
if (netherholdFinder.checkChunk((frag.x*fs) + (x), (frag.y*fs) + (y))) {
frag.addMapObject(new NetherMapObject("Netherhold", (frag.x*ls) + (x << 4), (frag.y*ls) + (y << 4)));
}
}
}
}
private void getPyramidData(Fragment frag) {
int fs = Project.FRAGMENT_SIZE >> 2;
int ls = Project.FRAGMENT_SIZE << 2;
for (int y = 0; y < fs; y++) {
for (int x = 0; x < fs; x++) {
if (pyramidFinder.checkChunk((frag.x*fs) + (x), (frag.y*fs) + (y),seed,this)) {
int biome = frag.getBiomeAt((x << 2) + 2, (y << 2) + 2);
String type = (biome == 6)?"Witch":"Temple";
frag.addMapObject(new MapObject(type, (frag.x*ls) + (x << 4), (frag.y*ls) + (y << 4)));
}
}
}
}
private void getStrongholdData(Fragment frag) {
for (int i = 0; i < 3; i++) {
Point t = strongholds[i];
if (frag.isInside(t.x, t.y)) {
frag.addMapObject(new MapObject("Stronghold", t.x, t.y));
}
}
}
private void getVillageData(Fragment frag) {
int fs = Project.FRAGMENT_SIZE >> 2;
int ls = Project.FRAGMENT_SIZE << 2;
for (int y = 0; y < fs; y++) {
for (int x = 0; x < fs; x++) {
if (villageFinder.checkChunk((frag.x*fs) + (x), (frag.y*fs) + (y), seed, this)) {
frag.addMapObject(new MapObject("Village", (frag.x*ls) + (x << 4), (frag.y*ls) + (y << 4)));
}
}
}
}
public void drawBiomeData(Fragment frag) {
int x = frag.x;
int y = frag.y;
int range = frag.range;
byte[] data = getBiomeForArea(x, y, range);
frag.data = data;
Graphics2D g2d = frag.createGraphics();
int i = 0;
long[] stat = new long[Biome.colors.length];
for (int i1 = 0; i1 < stat.length; i1++) {
stat[i1] = 0;
}
for (int ey = 0; ey < range; ey++) {
for (int ex = 0; ex < range; ex++) {
stat[data[i]]++;
g2d.setColor(Biome.colors[data[i]]);
g2d.fillRect(ex, ey, 1, 1);
i++;
}
}
for (int i1 = 0; i1 < stat.length; i1++) {
frag.stat[i1] = stat[i1]/(float)i;
}
Graphics2D g2d2 = frag.newLayer();
g2d2.setColor(Color.black);
g2d2.drawRect(0, 0, Project.FRAGMENT_SIZE, Project.FRAGMENT_SIZE);
g2d2.drawString(((x*Project.FRAGMENT_SIZE) << 2) + ", " + ((y*Project.FRAGMENT_SIZE) << 2), 5, 15);
g2d.dispose();
g2d2.dispose();
}
public void requestChunk(Fragment frag) {
queue.add(frag);
}
public boolean a(int paramInt1, int paramInt2, int paramInt3, List<Biome> paramList) {
int i = paramInt1 - paramInt3 >> 2;
int j = paramInt2 - paramInt3 >> 2;
int k = paramInt1 + paramInt3 >> 2;
int m = paramInt2 + paramInt3 >> 2;
int n = k - i + 1;
int i1 = m - j + 1;
int[] arrayOfInt = ba(i, j, n, i1);
for (int i2 = 0; i2 < n * i1; i2++) {
Biome localBiome = Biome.a[arrayOfInt[i2]];
if (!paramList.contains(localBiome)) return false;
}
return true;
}
public Point a(int paramInt1, int paramInt2, int paramInt3, List<Biome> paramList, Random paramRandom) {
int i = paramInt1 - paramInt3 >> 2;
int j = paramInt2 - paramInt3 >> 2;
int k = paramInt1 + paramInt3 >> 2;
int m = paramInt2 + paramInt3 >> 2;
int n = k - i + 1;
int i1 = m - j + 1;
int[] arrayOfInt = ba(i, j, n, i1);
Point localPoint = null;
int i2 = 0;
for (int i3 = 0; i3 < n*i1; i3++) {
int i4 = i + i3 % n << 2;
int i5 = j + i3 / n << 2;
if (arrayOfInt[i3] > Biome.a.length) {
System.out.println(arrayOfInt[i3]);
System.exit(0);
}
Biome localBiome = Biome.a[arrayOfInt[i3]];
if ((!paramList.contains(localBiome)) || (
(localPoint != null) && (paramRandom.nextInt(i2 + 1) != 0))) continue;
localPoint = new Point(i4, i5);
i2++;
}
return localPoint;
}
}

View File

@ -0,0 +1,55 @@
package MoF;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
/**
* Useful class for dynamically changing the classpath, adding classes during runtime.
* @author unknown
*/
public class ClasspathHacker {
/**
* Parameters of the method to add an URL to the System classes.
*/
private static final Class<?>[] parameters = new Class[]{URL.class};
/**
* Adds a file to the classpath.
* @param s a String pointing to the file
* @throws IOException
*/
public static void addFile(String s) throws IOException {
File f = new File(s);
addFile(f);
}//end method
/**
* Adds a file to the classpath
* @param f the file to be added
* @throws IOException
*/
public static void addFile(File f) throws IOException {
addURL(f.toURI().toURL());
}//end method
/**
* Adds the content pointed by the URL to the classpath.
* @param u the URL pointing to the content to be added
* @throws IOException
*/
public static void addURL(URL u) throws IOException {
URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
Class<?> sysclass = URLClassLoader.class;
try {
Method method = sysclass.getDeclaredMethod("addURL",parameters);
method.setAccessible(true);
method.invoke(sysloader,new Object[]{ u });
} catch (Throwable t) {
t.printStackTrace();
throw new IOException("Error, could not add URL to system classloader");
}//end try catch
}//end method
}

770
src/MoF/FinderWindow.java Normal file
View File

@ -0,0 +1,770 @@
package MoF;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.prefs.Preferences;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileFilter;
public class FinderWindow extends JFrame {
/**
*
*/
public static Class<?> biomeFinder;
private static final long serialVersionUID = 196896954675968191L;
private Container pane;
private Project curProject;
private JMenu mapMenu;
public JCheckBoxMenuItem layerGridMenu, layerSlimeMenu, layerNetherMenu, layerIconMenu;
public static Preferences pref;
public static boolean dataCollect;
private JFileChooser fc;
public FinderWindow() {
//Initialize window
super("Amidst v" + MoF.version());
pref = Preferences.userRoot().node(this.getClass().getName());
boolean first = pref.getBoolean("firstRun", true);
if (first) {
Google.track("RunFirstTime");
} else {
Google.track("Run");
}
pref.putBoolean("firstRun", false);
setSize(800,800);
//setLookAndFeel();
pane = getContentPane();
//UI Manager:
pane.setLayout(new BorderLayout());
loadMinecraft();
(new UpdateManager(this, true)).start();
setJMenuBar(createMainMenu());
setVisible(true);
Image icon = Toolkit.getDefaultToolkit().getImage(MoF.getURL("images/icon.png"));
setIconImage(icon);
//OnClose
/*
boolean dcFirst = pref.getBoolean("datacheckfirst", false);
if (!dcFirst) {
int result = JOptionPane.YES_OPTION;
result = JOptionPane.showConfirmDialog(null, "AMIDST would like to collect data about the maps you search, anonymously.\n You will only be prompted for this once:\n Would you like to allow data to be collected?", "Important alert!", JOptionPane.YES_NO_OPTION);
pref.putBoolean("datacollect", (result==0));
}
dataCollect = pref.getBoolean("datacollect", false);
*/addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
this.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getKeyCode() == KeyEvent.VK_EQUALS) {
if (curProject!=null)
curProject.map.scaleBy(2);
} else if (arg0.getKeyCode() == KeyEvent.VK_MINUS) {
if (curProject!=null)
curProject.map.scaleBy(0.5);
}
}
@Override
public void keyReleased(KeyEvent arg0) {
}
@Override
public void keyTyped(KeyEvent arg0) {
}
});
}
private JMenuBar createMainMenu() {
JMenuBar menu = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
JMenu newMenu = new JMenu("New");
newMenu.setMnemonic(KeyEvent.VK_N);
JMenuItem fromSeedMenu = new JMenuItem("From Seed"); fromSeedMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
JMenuItem fromFileMenu = new JMenuItem("From File");
JMenuItem fromServerMenu = new JMenuItem("From Server");
JMenuItem saveMenu = new JMenuItem("Save Player Locations"); saveMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
JMenuItem exitMenu = new JMenuItem("Exit");
JMenu scriptMenu = new JMenu("Script");
JMenuItem newScriptMenu = new JMenuItem("New");
JMenuItem openScriptMenu = new JMenuItem("Open");
JMenuItem saveScriptMenu = new JMenuItem("Save");
JMenuItem runScriptMenu = new JMenuItem("Run");
mapMenu = new JMenu("Map");
mapMenu.setMnemonic(KeyEvent.VK_M);
JMenu findMenu = new JMenu("Find");
JMenuItem findBiomeMenu = new JMenuItem("Biome");
JMenuItem findVillageMenu = new JMenuItem("Village");
JMenuItem findStrongholdMenu = new JMenuItem("Stronghold");findStrongholdMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
JMenu gotoMenu = new JMenu("Go To");
JMenuItem gotoCoordMenu = new JMenuItem("Coordinate"); gotoCoordMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK));
JMenuItem gotoPlayerMenu = new JMenuItem("Player");
JMenuItem gotoSpawnMenu = new JMenuItem("Spawn");
JMenuItem gotoChunkMenu = new JMenuItem("Chunk");
JMenu layersMenu = new JMenu("Layers");
layerSlimeMenu = new JCheckBoxMenuItem("Slimes"); layerSlimeMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.CTRL_MASK));
layerGridMenu = new JCheckBoxMenuItem("Grid"); layerGridMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.CTRL_MASK));
layerNetherMenu = new JCheckBoxMenuItem("Netherholds"); layerNetherMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.CTRL_MASK));
layerIconMenu = new JCheckBoxMenuItem("Icons"); layerIconMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, ActionEvent.CTRL_MASK));
JMenuItem captureMenu = new JMenuItem("Capture"); captureMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
JMenu helpMenu = new JMenu("Help");
JMenuItem checkMenu = new JMenuItem("Check for updates");
JMenuItem aboutMenu = new JMenuItem("About");
menu.add(fileMenu);
fileMenu.add(newMenu);
newMenu.add(fromSeedMenu);
newMenu.add(fromFileMenu);
//newMenu.add(fromServerMenu);
fileMenu.add(saveMenu);
fileMenu.add(exitMenu);
//menu.add(scriptMenu);
scriptMenu.add(newScriptMenu);
scriptMenu.add(openScriptMenu);
scriptMenu.add(saveScriptMenu);
scriptMenu.add(runScriptMenu);
menu.add(mapMenu);
mapMenu.add(findMenu);
//findMenu.add(findBiomeMenu);
//findMenu.add(findVillageMenu);
findMenu.add(findStrongholdMenu);
mapMenu.add(gotoMenu);
gotoMenu.add(gotoCoordMenu);
gotoMenu.add(gotoPlayerMenu);
//gotoMenu.add(gotoSpawnMenu);
//gotoMenu.add(gotoChunkMenu);
mapMenu.add(layersMenu);
layersMenu.add(layerSlimeMenu);
layersMenu.add(layerGridMenu);
layersMenu.add(layerNetherMenu);
layersMenu.add(layerIconMenu);
mapMenu.add(captureMenu);
menu.add(helpMenu);
helpMenu.add(checkMenu);
helpMenu.add(aboutMenu);
final FinderWindow window = this;
scriptMenu.setEnabled(false);
findBiomeMenu.setEnabled(false);
mapMenu.setEnabled(false);
findVillageMenu.setEnabled(false);
fromServerMenu.setEnabled(false);
gotoChunkMenu.setEnabled(false);
gotoSpawnMenu.setEnabled(false);
layerIconMenu.setSelected(true);
if (MoF.DISABLE_SAVE)
saveMenu.setEnabled(false);
captureMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
fc = new JFileChooser();
fc.addChoosableFileFilter(new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String[] st = f.getName().split("/.");
if (st[st.length-1].toLowerCase().equals("png"))
return true;
return false;
}
@Override
public String getDescription() {
return "Portable Network Graphic (*.PNG)";
}
});
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showSaveDialog(window);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String s = fc.getSelectedFile().toString();
if (!s.toLowerCase().endsWith(".png")) {
s += ".png";
}
curProject.map.saveToFile(new File(s));
}
}
});
layerGridMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
curProject.setGridLayer(layerGridMenu.isSelected());
}
});
layerSlimeMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
curProject.setSlimeLayer(layerSlimeMenu.isSelected());
}
});
checkMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
(new UpdateManager(window)).start();
}
});
aboutMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(window, "Advanced Minecraft Interfacing and Data/Structure Tracking (AMIDST)\nBy Skidoodle (amidst.project@gmail.com)");
}
});
saveMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (curProject.saveLoaded) {
ArrayList<Player> ar = curProject.save.getPlayers();
for (int i = 0; i < ar.size(); i++) {
if (ar.get(i).needSave) {
curProject.save.movePlayer(ar.get(i).getName(), ar.get(i).x, ar.get(i).y);
ar.get(i).needSave = false;
}
}
}
}
});
gotoPlayerMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (curProject.saveLoaded) {
ArrayList<Player> ar = curProject.save.getPlayers();
Object[] options = new Object[ar.size()];
for (int i = 0; i < options.length; i++) {
options[i] = "Player \"" + ar.get(i).getName() + "\" at (" + ar.get(i).x + ", " + ar.get(i).y + ")";
}
String s = (String)JOptionPane.showInputDialog(
window,
"Select Player:",
"Go to...",
JOptionPane.PLAIN_MESSAGE,
null,
options,
options[0]);
for (int i = 0; i < options.length; i++) {
if (s.equals(options[i])) {
curProject.moveMapTo(ar.get(i).x >> 2, ar.get(i).y >> 2);
}
}
}
}
});
findStrongholdMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Point[] sholds = curProject.manager.strongholds;
Object[] options = {
"Stronghold at (" + sholds[0].x + ", " + sholds[0].y + ")",
"Stronghold at (" + sholds[1].x + ", " + sholds[1].y + ")",
"Stronghold at (" + sholds[2].x + ", " + sholds[2].y + ")"};
String s = (String)JOptionPane.showInputDialog(
window,
"Select Stronghold:",
"Go to...",
JOptionPane.PLAIN_MESSAGE,
null,
options,
options[0]);
if (s!=null) {
for (int i = 0; i < 3; i++) {
if (s.equals(options[i])) {
curProject.moveMapTo(sholds[i].x >> 2, sholds[i].y >> 2);
}
}
}
}
});
fromFileMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
fc = new JFileChooser();
fc.addChoosableFileFilter(SaveLoader.getFilter());
fc.setAcceptAllFileFilterUsed(false);
fc.setCurrentDirectory(SaveLoader.getPath("saves/"));
int returnVal = fc.showOpenDialog(window);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File f = fc.getSelectedFile();
SaveLoader s = new SaveLoader(f);
setProject(new Project(s, window));
}
}
});
fromSeedMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
//Create the JOptionPane.
String s = JOptionPane.showInputDialog(null, "Enter seed...", "New Project", 1);
if (s!=null) {
Object[] possibilities = {"default","flat", "largeBiomes"};
String worldType = (String)JOptionPane.showInputDialog(
null,
"Enter world type...\n",
"New Project",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
"default");
//If a string was returned, say so.
if (worldType != null) {
setProject(new Project(s, window, worldType));
}
}
}
});
gotoCoordMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String s = JOptionPane.showInputDialog(null, "Enter coordinates: (Ex. 123,456)", "Go To", 1);
if (s!=null) {
String[] c = s.split(",");
long x = 0, y = 0;
boolean w = true;
try {
x = Long.parseLong(c[0]) >> 2;
y = Long.parseLong(c[1]) >> 2;
} catch (Exception e) {
w = false;
}
if (w)
curProject.moveMapTo((int)x, (int)y);
}
}
});
exitMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
int ret = JOptionPane.showConfirmDialog(window, "Are you sure you want to exit?");
if (ret==0) {
System.exit(0);
}
}
});
return menu;
}
public void setProject(Project ep) {
// FIXME Release resources.
if (curProject != null) {
curProject.dispose();
pane.remove(curProject);
System.gc();
}
mapMenu.setEnabled(true);
curProject = ep;
pane.add(curProject, BorderLayout.CENTER);
this.validate();
}
private void loadMinecraft() {
fc = new JFileChooser();
Class<?> mc = null;
String s = null;
//Temporary fix -- Should be removed in a few patches.
if (pref.getBoolean("osxMistake", true)) {
pref.putBoolean("osxMistake", false);
pref.remove("jar");
}
try {
s = SaveLoader.getDefaultPath() + "bin/minecraft.jar";
ClasspathHacker.addFile(pref.get("jar", s));
mc = ClassLoader.getSystemClassLoader().loadClass("net.minecraft.client.Minecraft");
} catch (Exception e) {
e.printStackTrace();
fc.addChoosableFileFilter(new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
if (f.getName().toLowerCase().endsWith(".jar"))
return true;
return false;
}
@Override
public String getDescription() {
return "Java Executable (*.JAR)";
}
});
fc.setAcceptAllFileFilterUsed(false);
JOptionPane.showMessageDialog(this, "Unable to find minecraft.jar, please locate it.");
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
s = fc.getSelectedFile().toString();
try {
ClasspathHacker.addFile(s);
mc = ClassLoader.getSystemClassLoader().loadClass("net.minecraft.client.Minecraft");
} catch (Exception e1) {
JOptionPane.showMessageDialog(this, "Error loading minecraft.jar");
System.exit(0);
}
} else {
System.exit(0);
}
}
try {
pref.put("jar", s);
String typeDump = "";
Field fields[] = mc.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
String typeString = fields[i].getType().toString();
if (typeString.startsWith("class ") && !typeString.contains("."))
typeDump += typeString.substring(6);
}
typeDump.replace("[", "-");
System.out.println(typeDump);
String worldName = "";
Field f = null;
java.lang.reflect.Type t = null;
boolean is25 = false;
boolean is131 = false;
if (typeDump.equals("[Bbeabdsbawemabdtbfzbdwngngbevawfbgfawvawvaxrawbbfrausbjhaycawwaraavybkdavwbjvbkila")) {
worldName = "aab";
is131 = true;
} else if (typeDump.equals("[Baywayoaaszleaypbavaysmdazratabbaatqatqaulaswbanarnbdzauwatraohastbevasrbenbezbdmbdjkh")) {
worldName = "yc";
is131 = true;
} else if (typeDump.equals("[Bayoaygaasrleayhbakaykmdazfassbapatjatjaueasobacarfbdoaupatkanzaslbekasjbecbenbdbbcykh")) {
worldName = "xv";
is131 = true;
} else if (typeDump.equals("[Baxgawyaarjkpawzayyaxclnaxxarkazcasbasbaswargaytaqabcbathascamuardbcxarbbcpbdabbobbljy")) {
worldName = "xe";
is131 = true;
} else if (typeDump.equals("[Batkatcaaofjbatdavbatgjwaubaogavfaovaovapnaocauwamxaxvapyaowajqanzayqanxayjaytaxkaxhik")) {
worldName = "up";
is131 = true;
} else if (typeDump.equals("[Batjatbaaoejaatcavaatfjvauaaofaveaouaouapmaobauvamwaxuapxaovajpanyaypanwayiaysaxjaxgij")) {
worldName = "uo";
is131 = true;
} else if (typeDump.equals("[Barjarbaikarcataarfjfasaateamuamuanmasvavuanxamvaizawpawiawsavjavght")) {
worldName = "ty";
} else if (typeDump.equals("[Bafswjoganiammmnqaptajvejhfahrrmrmabmmkphdvkrarquyaqzuelaxgasiivattuucypn")) {
worldName = "adn";
} else if (typeDump.equals("[Bafgvznwamualymdqapfajhefhbahercrcabamaoxdsknarbuoaqktuktwvartir[J[Jateukcy")) {
worldName = "adb";
is25 = true;
} else if (typeDump.equals("[Baflwdoaamzamdmhqapkajmehhdahjrgrgabfmepbdukpargusaqptykwxaaryit[J[Jatjuocy")){
worldName = "adg";
} else if (typeDump.equals("[Bbdtbdlbavymabdmbfsbdpngngbeoavzbfyawpawpaxlavvbfkaumbjaaxwawqaquavsbjwavqbjobkbla")){
worldName = "zv";
is131 = true;
} else {
//Get world
f = mc.getDeclaredField("f");
t = f.getType();
worldName = t.toString().split(" ")[1];
if (worldName.equals("lj")) {
//Version 12w19a
worldName = "abo";
} else if (worldName.equals("lr")) {
//Version 12w21a
worldName = "ach";
} else if (worldName.equals("md")) {
//Version 12w21b
worldName = "act";
} else if (worldName.equals("mf")) {
//Version 12w22a
worldName = "acz";
String otherName = mc.getDeclaredField("a").getType().toString().split(" ")[1];
if (otherName.equals("aff")) {
worldName = "adb";
}
} else if (worldName.equals("mb")) {
//Version 12w24a
worldName = "acv";
}
}
System.out.println("World class : " + worldName);
//Find biomeManager:
mc = ClassLoader.getSystemClassLoader().loadClass(worldName);
Method m = null;
boolean v13 = false;
try {
m = mc.getMethod("a");
} catch (NoSuchMethodException e3) {
v13 = true;
System.out.println("1.3-pre or newer found.");
}
if (v13) {
try {
m = mc.getMethod("q");
} catch (NoSuchMethodException e4) {
try {
m = mc.getMethod("r");
} catch (NoSuchMethodException e5) {
try {
m = mc.getMethod("s");
} catch (NoSuchMethodException e6) {
m = mc.getMethod("t");
}
}
}
}
t = m.getReturnType();
if (t.toString().equals("boolean")) {
//12w07a or newer.
m = mc.getDeclaredMethod("i");
t = m.getReturnType();
System.out.println("Version 12w07a or newer found!");
}
if (t.equals("void")) {
System.out.println("Version 1.4.2 or newer found.");
}
String chunkName = t.toString().split(" ")[1];
mc = ClassLoader.getSystemClassLoader().loadClass(chunkName);
biomeFinder = mc;
System.out.println("Biome Finder : " + chunkName);
f = mc.getDeclaredField(is131?"d":"b");
t = f.getType();
String biomeName = t.toString().split(" ")[1];
if (biomeName.equals("[F")) {
f = mc.getDeclaredField("c");
t = f.getType();
biomeName = t.toString().split(" ")[1];
}
if (biomeName.equals("[F")) {
f = mc.getDeclaredField("d");
t = f.getType();
biomeName = t.toString().split(" ")[1];
}
MoF.chunkName = biomeName;
f = mc.getDeclaredField(is131?"d":"a");
t = f.getType();
MoF.biomeName = t.toString().split(" ")[1];
String intCache = "";
System.out.println(biomeName);
if (biomeName.equals("ait")&&is131) {
MoF.version = "1.5.1";
MoF.versionID = 60;
intCache = "air";
} else if (biomeName.equals("ain")&&is131) {
MoF.version = "1.5.0";
MoF.versionID = 58;
intCache = "ail";
} else if (biomeName.equals("agw")&&is131) {
MoF.version = "1.4.6";
MoF.versionID = 54;
intCache = "agu";
} else if (biomeName.equals("agp")&&is131) {
MoF.version = "1.4.5";
MoF.versionID = 53;
intCache = "agn";
} else if (biomeName.equals("afu")&&is131) {
MoF.version = "1.4.2";
MoF.versionID = 50;
intCache = "afs";
} else if (biomeName.equals("adc")&&is131) {
MoF.version = "1.3.2";
MoF.versionID = 43;
intCache = "ada";
} else if (biomeName.equals("adb")&&is131) {
MoF.version = "1.3.1";
MoF.versionID = 42;
intCache = "acz";
} else if (biomeName.equals("acl")&&v13) {
MoF.version = "1.3pre";
MoF.versionID = 40;
intCache = "acj";
} else if (biomeName.equals("acs")) {
MoF.version = "12w27a";
MoF.versionID = 28;
intCache = "av";
} else if (biomeName.equals("acl")) {
MoF.version = "12w26a";
MoF.versionID = 27;
intCache = "av";
} else if (biomeName.equals("aca")) {
MoF.version = "12w24a";
MoF.versionID = 25;
intCache = "av";
} else if (biomeName.equals("acg")) {
if (is25) {
MoF.version = "12w25a";
MoF.versionID = 26;
intCache = "av";
} else {
MoF.version = "12w23b";
MoF.versionID = 24;
intCache = "ay";
}
} else if (biomeName.equals("ace")) {
MoF.version = "12w22a";
MoF.versionID = 23;
intCache = "ay";
MoF.DISABLE_SAVE = true;
} else if (biomeName.equals("aby")) {
MoF.version = "12w21b";
MoF.versionID = 22;
intCache = "ax";
MoF.DISABLE_SAVE = true;
} else if (biomeName.equals("abm")) {
MoF.version = "12w21a";
MoF.versionID = 21;
intCache = "ar";
MoF.DISABLE_SAVE = true;
} else if (biomeName.equals("aau")) {
MoF.version = "12w19a";
MoF.versionID = 19;
intCache = "ao";
} else if (biomeName.equals("wp")) {
MoF.version = "1.2.4";
MoF.versionID = 17;
intCache = "ad";
} else if (biomeName.equals("wl")) {
MoF.version = "1.2.2";
MoF.versionID = 16;
intCache = "ac";
} else if (biomeName.equals("wj")) {
MoF.version = "12w08a";
MoF.versionID = 15;
intCache = "ac";
} else if (biomeName.equals("wd")) {
MoF.version = "12w07b";
intCache = "ab";
MoF.versionID = 14;
//Skipping 12w07a
} else if (biomeName.equals("wb")) {
MoF.version = "12w06a";
intCache = "ab";
MoF.versionID = 12;
} else if (biomeName.equals("vy")) {
MoF.version = "12w05a";
intCache = "ab";
MoF.versionID = 11;
} else if (biomeName.equals("vu")) {
MoF.version = "12w04a";
intCache = "ab";
MoF.versionID = 10;
} else if (biomeName.equals("vj")) {
intCache = "ab";
MoF.version = "12w03a";
MoF.versionID = 9;
} else if (biomeName.equals("vc")) {
intCache = "ab";
MoF.version = "1.1";
MoF.versionID = 8;
} else if (biomeName.equals("jx")) {
intCache = "bm";
MoF.version = "1.0";
MoF.versionID = 7;
} else if (biomeName.equals("uk")) {
intCache = "z";
MoF.version = "1.9-pre6";
MoF.versionID = 6;
} else if (biomeName.equals("ug")) {
intCache = "y";
MoF.version = "1.9-pre5";
MoF.versionID = 5;
} else if (biomeName.equals("uh")) {
intCache = "y";
MoF.version = "1.9-pre4";
MapGenStronghold.reset0 = true;
MoF.versionID = 4;
} else if (biomeName.equals("to")) {
intCache = "x";
MoF.version = "1.9-pre3";
MoF.versionID = 3;
} else if (biomeName.equals("sv")) {
intCache = "x";
MoF.version = "1.9-pre2";
MoF.versionID = 2;
} else if (biomeName.equals("sq")) {
intCache = "x";
MoF.version = "1.9-pre1";
MoF.versionID = 1;
} else if (biomeName.equals("rj")) {
intCache = "w";
MoF.version = "1.8.1";
MoF.versionID = 0;
} else {
MoF.version = "unknown";
MoF.versionID = -1;
intCache = "ab";
String st = JOptionPane.showInputDialog(null, "Unsupported version of minecraft detected!\nEnter code to continue:\n(Name of the IntCache class)", "Error", 1);
if (st==null) {
System.exit(0);
} else {
intCache = st;
}
}
System.out.println("Version " + MoF.version + " detected. " + (MoF.DISABLE_SAVE?"Saves disabled.":""));
// pre5 - y, ug
// pre4 - y, uh
// pre3 - x, to
// pre2 - x, sv
// pre1 - x, sq
// pre0 - w, rj
MoF.intCacheName = intCache;
} catch (java.lang.NoClassDefFoundError e2) {
JOptionPane.showMessageDialog(this, "AMIDST ran in JAR mode without -noverify!\nUse: java -noverify -jar AMIDST.jar");
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
private void setLookAndFeel() {
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }
catch (ClassNotFoundException e1) { e1.printStackTrace(); }
catch (InstantiationException e1) { e1.printStackTrace(); }
catch (IllegalAccessException e1) { e1.printStackTrace(); }
catch (UnsupportedLookAndFeelException e1) { e1.printStackTrace(); }
}
}

129
src/MoF/Fragment.java Normal file
View File

@ -0,0 +1,129 @@
package MoF;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
public class Fragment extends BufferedImage {
public int x, y, range;
public boolean active;
public ArrayList<MapObject> objects;
public int tempX, tempY;
public byte[] data;
public boolean marked = false;
public ArrayList<BufferedImage> layers;
private Project proj;
public float stat[];
public int strongholdCount = 0;
public int villageCount = 0;
public Fragment(int x, int y, int range, Project proj) {
super(range,range,BufferedImage.TYPE_INT_ARGB);
this.range = range;
this.x = x;
this.y = y;
active = true;
Graphics2D g2d = this.createGraphics();
g2d.setColor(Color.blue);
g2d.fillRect(0, 0, Project.FRAGMENT_SIZE, Project.FRAGMENT_SIZE);
objects = new ArrayList<MapObject>();
layers = new ArrayList<BufferedImage>();
this.proj = proj;
stat = new float[Biome.colors.length];
}
public void dispose() {
this.flush();
for (int i = 0; i < layers.size(); i++) {
layers.get(i).flush();
}
this.objects.clear();
this.objects = null;
this.data = null;
this.layers.clear();
this.layers = null;
this.proj = null;
this.stat = null;
active = false;
}
public void disable() {
this.active = false;
for (int i = 0; i < layers.size(); i++) {
layers.get(i).flush();
}
flush();
}
public Graphics2D newLayer() {
BufferedImage temp = new BufferedImage(Project.FRAGMENT_SIZE, Project.FRAGMENT_SIZE, BufferedImage.TYPE_INT_ARGB);
layers.add(temp);
return temp.createGraphics();
}
public void paint(Graphics2D g2d, int x, int y, int width, int height) {
g2d.drawImage(this, x, y, width, height, null);
if (proj.grid&(layers.size()>0))
g2d.drawImage(layers.get(0), x, y, width, height, null);
if (proj.slimes&(layers.size()>1))
g2d.drawImage(layers.get(1), x, y, width, height, null);
}
public int getBiomeAt(int x, int y) {
if ((data != null)&&(y*Project.FRAGMENT_SIZE + x < data.length))
return data[y*Project.FRAGMENT_SIZE + x];
else
return 255;
}
public boolean isInside(int x, int y) {
int sX = x >> 2;
int sY = y >> 2;
int fs = Project.FRAGMENT_SIZE;
sX -= this.x*fs;
sY -= this.y*fs;
if ((sX >= 0) & (sY >= 0) & (sX < fs) & (sY < fs)) {
return true;
} else {
return false;
}
}
public MapObject getObjectAt(int x, int y) {
MapObject m = null;
double td = 1600;
for (int i = 0; i < objects.size(); i++) {
if (objects.get(i).isSelectable()) {
int sx = x - (objects.get(i).x >> 2);
int sy = y - (objects.get(i).y >> 2);
double dist = sx*sx + sy*sy;
if (dist < td) {
td = dist;
objects.get(i).tempDist = dist;
m = objects.get(i);
}
}
}
return m;
}
public void addMapObject(MapObject m) {
int sX = m.x >> 2;
int sY = m.y >> 2;
int fs = Project.FRAGMENT_SIZE;
sX -= this.x*fs;
sY -= this.y*fs;
m.rx = sX;
m.ry = sY;
if (m.type.toLowerCase().equals("stronghold")) {
strongholdCount++;
} else if (m.type.toLowerCase().equals("village")) {
villageCount++;
}
objects.add(m);
}
}

19
src/MoF/Google.java Normal file
View File

@ -0,0 +1,19 @@
package MoF;
//import com.boxysystems.jgoogleanalytics.*;
public class Google {
//private static JGoogleAnalyticsTracker tracker;
public static void startTracking() {
//tracker = new JGoogleAnalyticsTracker("AMIDST",MoF.version(),"UA-27092717-1");
}
public static void track(String s) {
//FocusPoint focusPoint = new FocusPoint(s);
//tracker.trackAsynchronously(focusPoint);
}
}

View File

@ -0,0 +1,32 @@
package MoF;
import java.util.Random;
public class MapGenNetherhold
{
private Random c;
private long seed;
public MapGenNetherhold(long seed)
{
c = new Random();
this.seed = seed;
}
protected boolean checkChunk(int paramInt1, int paramInt2)
{
int i = paramInt1 >> 4;
int j = paramInt2 >> 4;
this.c.setSeed((long)(i ^ j << 4) ^ seed);
this.c.nextInt();
if (this.c.nextInt(3) != 0) {
return false;
}
if (paramInt1 != (i << 4) + 4 + this.c.nextInt(8)) {
return false;
}
return paramInt2 == (j << 4) + 4 + this.c.nextInt(8);
}
}

View File

@ -0,0 +1,48 @@
package MoF;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class MapGenPyramid {
private static List<Biome> a = Arrays.asList(new Biome[] { Biome.d, Biome.s});
private static List<Biome> b = Arrays.asList(new Biome[] { Biome.d, Biome.s, Biome.w});
private static List<Biome> c = Arrays.asList(new Biome[] {Biome.d, Biome.s, Biome.w, Biome.x, Biome.h});
public boolean checkChunk(int paramInt1, int paramInt2, long seed, ChunkManager x) {
int i = 32;
int j = 8;
int k = paramInt1;
int m = paramInt2;
if (paramInt1 < 0) paramInt1 -= i - 1;
if (paramInt2 < 0) paramInt2 -= i - 1;
int n = paramInt1 / i;
int i1 = paramInt2 / i;
Random localRandom = new Random();
long l1 = n * 341873128712L + i1 * 132897987541L + seed + 14357617;
localRandom.setSeed(l1);
n *= i;
i1 *= i;
n += localRandom.nextInt(i - j);
i1 += localRandom.nextInt(i - j);
paramInt1 = k;
paramInt2 = m;
if ((paramInt1 == n) && (paramInt2 == i1)) {
boolean bool = false;
if (MoF.versionID >= 50) //1.4.2
bool = x.a(paramInt1 * 16 + 8, paramInt2 * 16 + 8, 0, c);
else if (MoF.versionID >= 23) //12w22a
bool = x.a(paramInt1 * 16 + 8, paramInt2 * 16 + 8, 0, b);
else
bool = x.a(paramInt1 * 16 + 8, paramInt2 * 16 + 8, 0, a);
if (bool) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,54 @@
package MoF;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;
public class MapGenStronghold
{
private Biome[] a = { Biome.d, Biome.f, Biome.e, Biome.h };
private Biome[] b = { Biome.d, Biome.f, Biome.e, Biome.h, Biome.g, Biome.n, Biome.o };
private Biome[] ab = { Biome.d, Biome.f, Biome.e, Biome.h, Biome.g, Biome.n, Biome.o, Biome.s, Biome.t, Biome.v };
private Biome[] ac = { Biome.d, Biome.f, Biome.e, Biome.h, Biome.g, Biome.n, Biome.o, Biome.s, Biome.t, Biome.v, Biome.w, Biome.x };
public Point[] coords = new Point[3];
private Random c = new Random();
public static boolean reset0 = false;
protected Point[] a(long seed, ChunkManager x)
{
int j;
c = new Random();
this.c.setSeed(seed);
double d1 = this.c.nextDouble() * 3.141592653589793D * 2.0D;
for (j = 0; j < this.coords.length; j++) {
double d2 = (1.25D + this.c.nextDouble()) * 32.0D;
System.out.println(d2);
int k = (int)Math.round(Math.cos(d1) * d2);
int m = (int)Math.round(Math.sin(d1) * d2);
Biome[] v = a;
if (MoF.version.equals("1.9-pre6")||MoF.version.equals("1.0"))
v = b;
if (MoF.version.equals("1.1"))
v = ab;
if (MoF.versionID >= 9)
v = ac;
ArrayList<Biome> localArrayList = new ArrayList<Biome>();
for (Object localObject2 : v) {
localArrayList.add((Biome) localObject2);
}
Point localPoint = x.a((k << 4) + 8, (m << 4) + 8, 112, localArrayList, this.c);
if (localPoint != null) {
k = localPoint.x >> 4;
m = localPoint.y >> 4;
}
coords[j] = new Point((k << 4),(m << 4));
d1 += 6.283185307179586D / this.coords.length;
}
if (reset0)
coords[0] = new Point(0, 0);
return coords;
}
}

View File

@ -0,0 +1,42 @@
package MoF;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class MapGenVillage
{
public static List<Biome> a = Arrays.asList(new Biome[] { Biome.c, Biome.d });
public boolean checkChunk(int paramInt1, int paramInt2, long seed, ChunkManager x) {
byte i = 32;
byte j = 8;
int k = paramInt1;
int m = paramInt2;
if (paramInt1 < 0) paramInt1 -= i - 1;
if (paramInt2 < 0) paramInt2 -= i - 1;
int n = paramInt1 / i;
int i1 = paramInt2 / i;
Random localRandom = new Random();
long rannum = n * 341873128712L + i1 * 132897987541L + seed + 10387312L;
localRandom.setSeed(rannum);
n *= i;
i1 *= i;
n += localRandom.nextInt(i - j);
i1 += localRandom.nextInt(i - j);
paramInt1 = k;
paramInt2 = m;
if ((paramInt1 == n) && (paramInt2 == i1)) {
boolean bool = x.a(paramInt1 * 16 + 8, paramInt2 * 16 + 8, 0, a);
if (bool)
return true;
}
return false;
}
}

108
src/MoF/MapInfoPanel.java Normal file
View File

@ -0,0 +1,108 @@
package MoF;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JPanel;
public class MapInfoPanel extends JPanel {
private static final long serialVersionUID = 45237076617899377L;
private MapViewer map;
private Color bgColor = new Color(230, 230, 230);
public MapInfoPanel(MapViewer map) {
this.map = map;
this.setPreferredSize(new Dimension(200,3000));
//this.setPreferredSize(new Dimension(200,200));
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.black);
g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
g2d.setColor(Color.white);
g2d.drawString("Info Panel will be here!", 50, 50);
tPaint(g2d); bPaint(g2d);
g2d.dispose();
}
public void tPaint(Graphics2D g2d) {
g2d.setColor(bgColor);
g2d.fillRect(0, 0, 200, getHeight()-100);
g2d.setColor(Color.black);
g2d.drawLine(0, getHeight()-105, 200, getHeight()-105);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
MapObject m = map.getSelectedObject();
//Draw outer rectangle:
g2d.drawRect(5, 15, 190, 70);
g2d.setColor(bgColor);
g2d.fillRect(15, 10, 105, 30);
g2d.setColor(Color.black);
g2d.setFont(new Font("arial", 15, 15));
g2d.drawString("Selected Object", 15, 20);
int yOffset = 40;
if (m==null) {
g2d.setFont(new Font("arial", 12, 12));
g2d.drawString("No Object Selected", 10,yOffset);
} else {
g2d.setFont(new Font("arial", 20, 20));
g2d.drawString(m.getName(), 15,yOffset + 10);
g2d.setFont(new Font("arial", 12, 12));
g2d.drawString("Location: (" + m.x + ", " + m.y + ")", 15, yOffset + 30);
}
yOffset += 50;
g2d.drawRect(5, yOffset + 15, 190, getHeight() - yOffset - 15 - 115);
g2d.setColor(bgColor);
g2d.fillRect(15, yOffset+10, 70, 30);
g2d.setColor(Color.black);
g2d.setFont(new Font("arial", 15, 15));
g2d.drawString("View Data", 15, yOffset + 20);
PieChart chart = map.getChart();
if (chart != null) {
chart.paint(g2d, 15, yOffset + 45, 180, 180);
g2d.setFont(new Font("arial", 20, 20));
yOffset = getHeight() - 170;
g2d.setColor(Color.black);
g2d.drawString("Strongholds: " + map.strongholdCount, 15, yOffset + 10);
g2d.drawString("Villages: " + map.villageCount, 15, yOffset + 40);
}
}
public void bPaint(Graphics2D g2d) {
PixelInfo p = map.getCursorInformation();
int yOffset = getHeight() - 100;
g2d.setColor(bgColor);
g2d.fillRect(0, yOffset, 200, 100);
if ((p!=null)&&(p.getBiome()!=255)) {
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Color c = Biome.colors[p.getBiome()];
g2d.setColor(c);
g2d.fillRect(16, yOffset + 10, 32, 32);
g2d.setColor(Color.black);
g2d.setFont(new Font("arial", 20, 20));
g2d.drawString(Biome.a[p.getBiome()].name, 55, yOffset + 34);
g2d.drawString("X: " + p.getBlockX(), 16, yOffset + 70);
g2d.drawString("Z: " + p.getBlockY(), 16, yOffset + 90);
} else {
}
}
public void dispose() {
map = null;
}
}

18
src/MoF/MapListener.java Normal file
View File

@ -0,0 +1,18 @@
package MoF;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MapListener implements ActionListener {
private MapViewer map;
private String name;
public MapListener(MapViewer p, String name) {
this.name = name;
map = p;
}
@Override
public void actionPerformed(ActionEvent e) {
map.movePlayer(name, e);
}
}

23
src/MoF/MapMarker.java Normal file
View File

@ -0,0 +1,23 @@
package MoF;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class MapMarker {
public static BufferedImage village, stronghold, spawn, player,slime, nether, pyramid, witch;
public static int init() {
try {
village = ImageIO.read(MoF.getURL("images/village.png"));
stronghold = ImageIO.read(MoF.getURL("images/stronghold.png"));
slime = ImageIO.read(MoF.getURL("images/slime.png"));
player = ImageIO.read(MoF.getURL("images/player.png"));
nether = ImageIO.read(MoF.getURL("images/netherhold.png"));
pyramid = ImageIO.read(MoF.getURL("images/pyramid.png"));
witch = ImageIO.read(MoF.getURL("images/witch.png"));
} catch (IOException e) {
System.out.println(e);
}
return 0;
}
}

48
src/MoF/MapObject.java Normal file
View File

@ -0,0 +1,48 @@
package MoF;
import java.awt.image.BufferedImage;
public class MapObject {
public String type;
public int x, y, rx, ry;
public BufferedImage marker;
public double localScale = 1.0;
public boolean selectable = true;
public double tempDist = 0;
public MapObject(String eType, int eX, int eY) {
type = eType;
x = eX;
y = eY;
if (eType == "Stronghold") {
marker = MapMarker.stronghold;
} else if (eType == "Village") {
marker = MapMarker.village;
} else if (eType == "Slime") {
marker = MapMarker.slime;
} else if (eType == "Player") {
marker = MapMarker.player;
} else if (eType == "Netherhold") {
marker = MapMarker.nether;
} else if (eType == "Temple") {
marker = MapMarker.pyramid;
} else if (eType == "Witch") {
marker = MapMarker.witch;
}
}
public String getName() {
return type;
}
public int getWidth() {
if (MoF.mainWindow.layerIconMenu.isSelected())
return (int)(marker.getWidth()*localScale);
return 0;
}
public int getHeight() {
if (MoF.mainWindow.layerIconMenu.isSelected())
return (int)(marker.getHeight()*localScale);
return 0;
}
public boolean isSelectable() {
return MoF.mainWindow.layerIconMenu.isSelected();
}
}

495
src/MoF/MapViewer.java Normal file
View File

@ -0,0 +1,495 @@
package MoF;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
public class MapViewer extends JComponent implements MouseListener, MouseWheelListener, ComponentListener {
/**
*
*/
private static final long serialVersionUID = -8309927053337294612L;
private Project proj;
private int fragXMax = 0, fragYMax = 0, fragX = 0, fragY = 0;
private boolean mTracking = false, resized = false;
private double mX = 0, mY = 0, tX = 0, tY = 0;
private PieChart chart;
private ArrayList<ArrayList<Fragment>> frags;
private JPopupMenu menu = new JPopupMenu();
private double scale = 1;
private boolean dataChange, sizeChange, firstRun;
public int strongholdCount, villageCount;
private static int offset[] = new int[] {
-1,-1,
-1, 0,
-1, 1,
0,-1,
0, 1,
1,-1,
1, 0,
1, 1
};
public void dispose() {
System.out.println("DISPOSING OF MAPVIEWER");
for (int ey = 0; ey < fragYMax; ey++) {
for (int ex = 0; ex < fragXMax; ex++) {
Fragment tempFrag = frags.get(ey).get(ex);
tempFrag.dispose();
}
frags.get(ey).clear();
}
frags.clear();
frags = null;
chart.dispose();
menu.removeAll();
proj = null;
}
MapViewer(Project proj) {
dataChange = true;
sizeChange = true;
firstRun = true;
chart = new PieChart(Biome.colors.length,0);
this.addMouseListener(this);
resized = true;
this.addComponentListener(this);
this.addMouseWheelListener(this);
menu = new JPopupMenu();
if (proj.saveLoaded) {
ArrayList<Player> pl = proj.save.getPlayers();
for (int i = 0; i < pl.size(); i++) {
JMenuItem tj = new JMenuItem("Move " + pl.get(i).getName() + " here.");
tj.addActionListener(new MapListener(this, pl.get(i).getName()));
menu.add(tj);
}
}
this.proj = proj;
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.black);
g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
updateFragments();
ArrayList<MapObject> markers = null;
if (firstRun) {
centerAt(0,0);
firstRun = false;
}
for (int ey = 0; ey < fragYMax; ey++) {
for (int ex = 0; ex < fragXMax; ex++) {
Fragment tempFrag = frags.get(ey).get(ex);
tempFrag.tempX = (int)(((tempFrag.x - fragX - 1)*Project.FRAGMENT_SIZE)*scale + (int)mX);
tempFrag.tempY = (int)(((tempFrag.y - fragY - 1)*Project.FRAGMENT_SIZE)*scale + (int)mY);
tempFrag.paint(g2d,
tempFrag.tempX,
tempFrag.tempY,
(int)(Project.FRAGMENT_SIZE*scale),
(int)(Project.FRAGMENT_SIZE*scale));
if (tempFrag.marked) {
g2d.setColor(Color.pink);
g2d.drawRect(
tempFrag.tempX,
tempFrag.tempY,
(int)(Project.FRAGMENT_SIZE*scale),
(int)(Project.FRAGMENT_SIZE*scale));
}
}
}
for (int ey = 0; ey < fragYMax; ey++) {
for (int ex = 0; ex < fragXMax; ex++) {
Fragment tempFrag = frags.get(ey).get(ex);
markers = tempFrag.objects;
for (int i = 0; i < markers.size(); i++) {
MapObject m = markers.get(i);
BufferedImage img = m.marker;
g2d.drawImage(img,
(int)(tempFrag.tempX + m.rx*scale - (m.getWidth() >> 1)),
(int)(tempFrag.tempY + m.ry*scale - (m.getHeight() >> 1)),
(int)(m.getWidth()),
(int)(m.getHeight()),
null);
}
}
}
g2d.setColor(new Color(25, 25, 25));
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setFont(new Font("arial", Font.BOLD, 15));
g2d.drawString(proj.seedText, 20, 30);
if (mTracking) {
Point p = this.getMousePosition();
if (p!=null) {
mX += (p.x - tX);
mY += (p.y - tY);
tX = p.x;
tY = p.y;
}
}
if (resized) {
resized = false;
cleanUpdate();
}
updateChart();
}
public Project getProject() {
return proj;
}
private void updateChart() {
if (sizeChange) {
chart.setSources(fragXMax*fragYMax);
}
if (dataChange) {
chart.clearData();
villageCount = 0;
strongholdCount = 0;
for (int y = 0; y < fragYMax; y++) {
for (int x = 0; x < fragXMax; x++) {
chart.addData(frags.get(y).get(x).stat);
strongholdCount += frags.get(y).get(x).strongholdCount;
villageCount += frags.get(y).get(x).villageCount;
}
}
}
}
private void shiftFragmentX(int pos) {
dataChange = true;
int offset = (pos + 1) >> 1;
int marker = getWriteX(fragX + offset + fragXMax - 1);
fragX += pos;
for (int i = 0; i < fragYMax; i++) {
frags.get(getWriteY(fragY + i)).get(marker).disable();
frags.get(getWriteY(fragY + i)).set(marker, proj.getFragment(fragX + (fragXMax - 1) * offset, fragY + i));
}
}
private void shiftFragmentY(int pos) {
dataChange = true;
int offset = (pos + 1) >> 1;
int marker = getWriteY(fragY + offset + fragYMax - 1);
fragY += pos;
ArrayList<Fragment> tempList = new ArrayList<Fragment>(fragXMax);
for (int i = 0; i < fragXMax; i++)
tempList.add(null);
for (int i = 0; i < fragXMax; i++) {
frags.get(marker).get(getWriteX(fragX + i)).disable();
tempList.set(getWriteX(fragX + i), proj.getFragment(fragX + i, fragY + (fragYMax - 1) * offset));
}
frags.set(marker, tempList);
}
public void cleanUpdate() {
System.gc();
dataChange = true;
sizeChange = true;
for (int i = 0; i < fragYMax; i++) {
for (int c = 0; c < fragXMax; c++) {
frags.get(i).get(c).disable();
}
}
//Resize arrays
fragXMax = (int) (Math.round((double)this.getWidth()/((double)Project.FRAGMENT_SIZE*scale)) + 2);
fragYMax = (int) (Math.round((double)this.getHeight()/((double)Project.FRAGMENT_SIZE*scale)) + 2);
frags = new ArrayList<ArrayList<Fragment>>(fragYMax);
for (int i = 0; i < fragYMax; i++) {
frags.add(new ArrayList<Fragment>(fragXMax));
for (int c = 0; c < fragXMax; c++) {
frags.get(i).add(null);
}
}
for (int i = fragY; i < fragY + fragYMax; i++) {
for (int c = fragX; c < fragX + fragXMax; c++) {
frags.get(getWriteY(i)).set(getWriteX(c), proj.getFragment(c, i));
}
}
}
public PixelInfo getCursorInformation(Point c) {
PixelInfo p = null;
if (c!=null) {
if (fragXMax + fragYMax > 0) {
double fx = (((c.x - mX)/(scale*Project.FRAGMENT_SIZE)) + 1 + fragX);
double fy = (((c.y - mY)/(scale*Project.FRAGMENT_SIZE)) + 1 + fragY);
int ix = (int)fx;
int iy = (int)fy;
if (fx < 0)
ix--;
if (fy < 0)
iy--;
Fragment curFrag = frags.get(getWriteY(iy)).get(getWriteX(ix));
int ox = (int) ((fx - ix)*Project.FRAGMENT_SIZE);
int oy = (int) ((fy - iy)*Project.FRAGMENT_SIZE);
p = new PixelInfo(ix*Project.FRAGMENT_SIZE + ox, iy*Project.FRAGMENT_SIZE + oy, curFrag);
}
}
return p;
}
public PixelInfo getCursorInformation() {
Point c = this.getMousePosition();
PixelInfo p = null;
p = getCursorInformation(c);
return p;
}
private void updateFragments() {
double fragSize = scale*Project.FRAGMENT_SIZE;
if (mX > fragSize) {
mX -= fragSize; //Trigger Left Moving
shiftFragmentX(-1);
} else if (mX < 0) {
mX += fragSize; //Trigger Right Moving
shiftFragmentX(1);
}
if (mY > fragSize) {
mY -= fragSize; //Trigger Up Moving
shiftFragmentY(-1);
} else if (mY < 0) {
mY += fragSize; //Trigger Down Moving
shiftFragmentY(1);
}
}
public void centerAt(double x, double y) {
double adjX, adjY, zx, zy;
zx = x;
zy = y;
scale = 1;
int fs = Project.FRAGMENT_SIZE;
adjX = Math.floor(zx/fs) - 1;
adjY = Math.floor(zy/fs) - 1;
mX = -1*(Math.floor(zx - getWidth()/(2)) - (adjX + 1)*fs);
mY = -1*(Math.floor(zy - getHeight()/(2)) - (adjY + 1)*fs);
fragX = (int)adjX;
fragY = (int)adjY;
}
public void centerAndReset(double x, double y) {
centerAt(x,y);
cleanUpdate();
}
public void setScale(double scale) {
if ((scale <= 8)&&(scale >= 0.25)) {
this.scale = scale;
sizeChange = true;
cleanUpdate();
}
}
public void scaleBy(double scale) {
setScale(this.scale*scale);
}
private int getWriteX(int in) {
int ex = in % fragXMax;
if (ex < 0)
ex += fragXMax;
return ex;
}
private int getWriteY(int in) {
int ey = in % fragYMax;
if (ey < 0)
ey += fragYMax;
return ey;
}
@SuppressWarnings("unused")
private int getWrite(int in, int max) {
int ew = in % max;
if (ew < 0)
ew += max;
return ew;
}
public void mouseWheelMoved(MouseWheelEvent e) {
int notches = e.getWheelRotation();
double z = 2;
if (notches == 1)
z = 0.5;
scaleBy(z);
}
@Override
public void mouseClicked(MouseEvent me) {
if (!me.isPopupTrigger()) {
PixelInfo p = getCursorInformation();
MapObject m = p.getFrag().getObjectAt(p.getX(), p.getY());
int rx = p.getX() - (p.getFrag().x * Project.FRAGMENT_SIZE);
int ry = p.getY() - (p.getFrag().y * Project.FRAGMENT_SIZE);
double dist = 3600;
if (m!=null)
dist = m.tempDist;
for (int i = 0; i < offset.length; i+=2) {
int ix = rx + offset[i ]*40;
int iy = ry + offset[i+1]*40;
if ( ((Math.abs(ix - (Project.FRAGMENT_SIZE >> 1))>(Project.FRAGMENT_SIZE >> 1))||(offset[i]==0))&
((Math.abs(iy - (Project.FRAGMENT_SIZE >> 1))>(Project.FRAGMENT_SIZE >> 1))||(offset[i+1]==0)) ) {
MapObject m2 = frags.get(getWriteY(p.getFrag().y + offset[i+1])).get(getWriteX(p.getFrag().x + offset[i])).getObjectAt(p.getX(), p.getY());
if ((m2!=null)&&(m2.isSelectable())&&(m2.tempDist < dist)) {
m = m2;
}
}
}
if (m!=null) {
if (proj.curTarget!=null) {
proj.curTarget.localScale = 1.0;
}
m.localScale = 2.0;
proj.curTarget = m;
} else {
if (proj.curTarget!=null)
proj.curTarget.localScale = 1.0;
proj.curTarget = null;
}
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
}
@Override
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
if (!arg0.isMetaDown()) {
mTracking = true;
Point p = this.getMousePosition();
tX = p.x;
tY = p.y;
}
}
private int tempX, tempY;
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()&&!MoF.DISABLE_SAVE) {
if (proj.saveLoaded) {
tempX = e.getX();
tempY = e.getY();
menu.show(e.getComponent(), e.getX(), e.getY());
}
} else {
mTracking = false;
}
}
@Override
public void componentHidden(ComponentEvent arg0) {
}
@Override
public void componentMoved(ComponentEvent arg0) {
}
@Override
public void componentResized(ComponentEvent arg0) {
resized = true;
}
@Override
public void componentShown(ComponentEvent arg0) {
}
public MapObject getSelectedObject() {
return proj.curTarget;
}
public PieChart getChart() {
return chart;
}
public void setChart(PieChart chart) {
this.chart = chart;
}
public void movePlayer(String name, ActionEvent e) {
PixelInfo p = getCursorInformation(new Point(tempX, tempY));
proj.movePlayer(name, p);
}
public void saveToFile(File f) {
int fs = Project.FRAGMENT_SIZE;
BufferedImage img = new BufferedImage(fragXMax*fs,fragYMax*fs,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.black);
g2d.fillRect(0, 0, img.getWidth(), img.getHeight());
ArrayList<MapObject> markers = null;
for (int ey = 0; ey < fragYMax; ey++) {
for (int ex = 0; ex < fragXMax; ex++) {
Fragment tempFrag = frags.get(ey).get(ex);
tempFrag.tempX = (int)((tempFrag.x - fragX)*Project.FRAGMENT_SIZE);
tempFrag.tempY = (int)((tempFrag.y - fragY)*Project.FRAGMENT_SIZE);
tempFrag.paint(g2d,
tempFrag.tempX,
tempFrag.tempY,
(int)(Project.FRAGMENT_SIZE),
(int)(Project.FRAGMENT_SIZE));
}
}
for (int ey = 0; ey < fragYMax; ey++) {
for (int ex = 0; ex < fragXMax; ex++) {
Fragment tempFrag = frags.get(ey).get(ex);
markers = tempFrag.objects;
for (int i = 0; i < markers.size(); i++) {
MapObject m = markers.get(i);
BufferedImage img2 = m.marker;
g2d.drawImage(img2,
(int)(tempFrag.tempX + m.rx - (m.getWidth() >> 1)),
(int)(tempFrag.tempY + m.ry - (m.getHeight() >> 1)),
(int)(m.getWidth()),
(int)(m.getHeight()),
null);
}
}
}
try {
ImageIO.write(img, "png", f);
} catch (IOException e) {
e.printStackTrace();
}
g2d.dispose();
img.flush();
}
}

54
src/MoF/MoF.java Normal file
View File

@ -0,0 +1,54 @@
package MoF;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
public class MoF {
public static double version_major = 2.0;
public static int version_minor = 44;
public static FinderWindow mainWindow;
public static String biomeName;
public static String intCacheName;
public static String chunkName;
public static String version;
public static int versionID;
public static boolean NETHER = true;
public static boolean DEBUG = true;
public static boolean DISABLE_SAVE = false;
public static String stuff = "";
static {
stuff += "Hey, if you actually bothered to decompile this code\n";
stuff += "I just want to say sorry-- it's so messy and ugly :(\n";
stuff += "I mean... really.. I'm sorry.\n";
stuff += "....I cry a little bit every time I make an update...\n";
}
public static URL getURL(String s) {
Object c = new Object();
try {
if (DEBUG)
return new URL("file:" + s);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return c.getClass().getResource("/" + s);
}
public static String version() {
return MoF.version_major + "." + MoF.version_minor;
}
public static void main(String[] args) {
Google.startTracking();
Google.track("Run");
MapMarker.init();
mainWindow = new FinderWindow();
}
}

View File

@ -0,0 +1,25 @@
package MoF;
public class NetherMapObject extends MapObject {
public NetherMapObject(String eType, int eX, int eY) {
super(eType, eX, eY);
}
public int getWidth() {
if (MoF.mainWindow.layerNetherMenu.isSelected()) {
return (int)(marker.getWidth()*localScale);
}
return 0;
}
public int getHeight() {
if (MoF.mainWindow.layerNetherMenu.isSelected()) {
return (int)(marker.getHeight()*localScale);
}
return 0;
}
public boolean isSelectable() {
return MoF.mainWindow.layerNetherMenu.isSelected();
}
}

49
src/MoF/PieChart.java Normal file
View File

@ -0,0 +1,49 @@
package MoF;
import java.awt.Graphics2D;
public class PieChart {
private float[] slices;
private int sources;
public PieChart(int numOfSlices, int numSources) {
slices = new float[numOfSlices];
sources = numSources;
}
public void addData(float[] sData) {
for (int i = 0; i < slices.length; i++) {
slices[i] += sData[i]/(float)sources;
}
}
public void setSources(int num) {
sources = num;
}
public void clearData() {
for (int i = 0; i < slices.length; i++) {
slices[i] = 0;
}
}
public void dispose() {
this.slices = null;
}
public void paint(Graphics2D g2d, int x, int y, int width, int height) {
float max = 0.0f;
for (int i = 0; i < slices.length; i++) {
max += slices[i];
}
int angle = 0;
float tp = 360f;
for (int i = 0; i < slices.length; i++) {
g2d.setColor(Biome.colors[i]);
int newangle = (int)((slices[i]/max)*tp);
if (i == slices.length - 1)
newangle = 360 - angle;
g2d.fillArc(x, y, width, height, angle, newangle);
angle += newangle;
}
}
}

64
src/MoF/PixelInfo.java Normal file
View File

@ -0,0 +1,64 @@
package MoF;
public class PixelInfo {
private int biome, x, y;
private MapObject obj;
private Fragment frag;
public PixelInfo(int x, int y, int biome) {
this.x = x;
this.y = y;
this.biome = biome;
}
public PixelInfo(int x, int y, Fragment frag) {
this.x = x;
this.y = y;
this.frag = frag;
this.biome = frag.getBiomeAt(x - frag.x*Project.FRAGMENT_SIZE, y - frag.y*Project.FRAGMENT_SIZE);
}
public int getChunkX() {
return (x >> 2);
}
public int getChunkY() {
return (y >> 2);
}
public int getBlockX() {
return (x << 2);
}
public int getBlockY() {
return (y << 2);
}
public int getBiome() {
return biome;
}
public void setBiome(int biome) {
this.biome = biome;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public MapObject getObject() {
return obj;
}
public void setObject(MapObject obj) {
this.obj = obj;
}
public Fragment getFrag() {
return frag;
}
public void setFrag(Fragment frag) {
this.frag = frag;
}
}

34
src/MoF/Player.java Normal file
View File

@ -0,0 +1,34 @@
package MoF;
import java.awt.image.BufferedImage;
public class Player extends MapObject {
private String name;
public boolean needSave;
public Player(String name, int x, int y) {
super("Player", x , y);
needSave = false;
this.setName(name);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getWidth() {
return (int)(marker.getWidth()*localScale*3);
}
public int getHeight() {
return (int)(marker.getHeight()*localScale*3);
}
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
needSave = true;
}
public void setMarker(BufferedImage img) {
this.marker = img;
}
}

156
src/MoF/Project.java Normal file
View File

@ -0,0 +1,156 @@
package MoF;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JPanel;
public class Project extends JPanel {
private static final long serialVersionUID = 1132526465987018165L;
private long seed;
public MapViewer map;
private MapInfoPanel minfo;
public static int FRAGMENT_SIZE = 256;
public ChunkManager manager;
public boolean slimes, grid;
private Timer timer;
public MapObject curTarget;
public boolean saveLoaded;
public SaveLoader save;
public String seedText;
public Project(long seed, FinderWindow window) {
this(seed, window, "default");
}
public Project(long seed, FinderWindow window, String type) {
SaveLoader.genType=type;
saveLoaded = false;
//Enter seed data:
this.setSeed(seed);
this.seedText = "Seed: " + seed;
init();
}
public void tick() {
map.repaint();
minfo.repaint();
}
public Project(String seed, FinderWindow window, String type) {
this(stringToLong(seed), window, type);
this.seedText = "Seed: \"" + seed + "\" (" + this.seed + ")";
Google.track("seed/" + seed + "/" + this.seed);
}
public Project(String seed, FinderWindow window) {
this(stringToLong(seed), window);
this.seedText = "Seed: \"" + seed + "\" (" + this.seed + ")";
Google.track("seed/" + seed + "/" + this.seed);
}
public void dispose() {
map.dispose();
map = null;
manager.dispose();
manager = null;
timer.cancel();
timer = null;
curTarget = null;
minfo.dispose();
minfo = null;
save = null;
}
public Project(SaveLoader file, FinderWindow window) {
saveLoaded = true;
save = file;
//Enter seed data:
this.setSeed(file.seed);
this.seedText = "Seed: " + seed;
init();
Google.track("seed/file/" + this.seed);
ArrayList<Player> players = file.getPlayers();
manager.setPlayerData(players);
}
private void init() {
manager = new ChunkManager(seed);
manager.start();
BorderLayout layout = new BorderLayout();
this.setLayout(layout);
//Create MapViewer
map = new MapViewer(this);
add(map, BorderLayout.CENTER);
minfo = new MapInfoPanel(map);
add(minfo, BorderLayout.EAST);
//Debug
this.setBackground(Color.BLUE);
//Timer:
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
tick();
}
}, 20, 20);
}
private static long stringToLong(String seed) {
long ret = 0L;
try {
ret = Long.parseLong(seed);
} catch (NumberFormatException err) {
ret = seed.hashCode();
}
return ret;
}
public void movePlayer(String name, PixelInfo p) {
for (int i = 0; i < save.getPlayers().size(); i++) {
if (name.toLowerCase().equals(save.getPlayers().get(i).getName().toLowerCase())) {
save.getPlayers().get(i).setPosition(p.getBlockX(), p.getBlockY());
map.cleanUpdate();
}
}
}
public long getSeed() {
return seed;
}
public void setSeed(String seed) {
this.seed = stringToLong(seed);
}
public void setSeed(long seed) {
this.seed = seed;
}
public Fragment getFragment(int x, int y) {
Fragment frag = new Fragment(x,y,FRAGMENT_SIZE, this);
manager.requestChunk(frag);
return frag;
}
public void setSlimeLayer(boolean b) {
slimes = b;
}
public void setGridLayer(boolean b) {
grid = b;
}
public void moveMapTo(int x, int y) {
map.centerAndReset(x, y);
}
}

151
src/MoF/SaveLoader.java Normal file
View File

@ -0,0 +1,151 @@
package MoF;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import javax.swing.filechooser.FileFilter;
public class SaveLoader {
public static String genType = "default";
public static FileFilter getFilter() {
return (new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String[] st = f.getName().split("\\/");
if (st[st.length-1].toLowerCase().equals("level.dat"))
return true;
return false;
}
@Override
public String getDescription() {
return "Minecraft Data File (level.dat)";
}
});
}
public static File getPath(String post) {
return new File(getDefaultPath() + post);
}
public static String getDefaultPath() {
String defaultPath = System.getProperty("user.home", ".");
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
String appdata = System.getenv("APPDATA");
if (appdata!=null) {
return appdata + "/.minecraft/";
} else {
return defaultPath + "/.minecraft/";
}
} else if (os.contains("mac")) {
return defaultPath + "/Library/Application Support/minecraft/";
}
return defaultPath + "/.minecraft/";
}
private File file;
private ArrayList<Player> players;
public long seed;
private boolean multi;
private ArrayList<String> back;
public ArrayList<Player> getPlayers() {
return players;
}
public void movePlayer(String name, int x, int y) {
File out = null;
if (multi) {
String outpath = file.getParent() + "/players/" + name +".dat";
out = new File(outpath);
backupFile(out);
try {
Tag t = Tag.readFrom(new FileInputStream(out));
Tag pos = t.findTagByName("Pos");
Tag[] pa = (Tag[]) pos.getValue();
pa[0].setValue((double)x);
pa[1].setValue((double)120);
pa[2].setValue((double)y);
t.writeTo(new FileOutputStream(out));
} catch (Exception e) {
e.printStackTrace();
}
} else {
out = file;
backupFile(out);
try {
Tag t = Tag.readFrom(new FileInputStream(out));
Tag pos = t.findTagByName("Pos");
Tag[] pa = (Tag[]) pos.getValue();
pa[0].setValue((double)x);
pa[1].setValue((double)120);
pa[2].setValue((double)y);
t.writeTo(new FileOutputStream(out));
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void backupFile(File f) {
File inputFile = f;
File outputFile = new File(f.toString() + ".moth");
if (!back.contains(outputFile.toString())) {
try {
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
back.add(outputFile.toString());
} catch (Exception e) {
}
}
}
public SaveLoader(File f) {
file = f;
players = new ArrayList<Player>();
back = new ArrayList<String>();
try {
Tag t = Tag.readFrom(new FileInputStream(f));
Tag pTag = t.findTagByName("Player");
seed = (Long)t.findTagByName("RandomSeed").getValue();
genType = (String)t.findTagByName("generatorName").getValue();
System.out.println("Gen Type: " + genType);
if (pTag!=null) {
multi = false;
Tag pos = pTag.findTagByName("Pos");
Tag[] pa = (Tag[]) pos.getValue();
double x = (Double) pa[0].getValue();
double z = (Double) pa[2].getValue();
players.add(new Player("Player", (int)x, (int)z));
} else {
multi = true;
File[] listing = new File(f.getParent() + "/players").listFiles();
Tag ps;
for (int i = 0; i < listing.length; i++) {
ps = Tag.readFrom(new FileInputStream(listing[i]));
Tag pos = ps.findTagByName("Pos");
Tag[] pa = (Tag[]) pos.getValue();
double x = (Double) pa[0].getValue();
double z = (Double) pa[2].getValue();
players.add(new Player(listing[i].getName().split("\\.")[0], (int)x, (int)z));
}
}
} catch (Exception e) {
// FIXME Dialog when file read fails.
}
}
}

60
src/MoF/SkinManager.java Normal file
View File

@ -0,0 +1,60 @@
package MoF;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Stack;
import javax.imageio.ImageIO;
public class SkinManager extends Thread {
private Stack<Player> players;
public boolean active;
public SkinManager() {
players = new Stack<Player>();
active = true;
}
public void addPlayer(Player p) {
players.push(p);
}
public void run() {
while (this.active) {
try {
if (players.isEmpty()) {
Thread.sleep(50L);
} else {
Player p = players.pop();
try {
URL url = new URL("http://s3.amazonaws.com/MinecraftSkins/" + p.getName() + ".png");
BufferedImage img = ImageIO.read(url);
BufferedImage pimg = new BufferedImage(10,10,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = pimg.createGraphics();
g2d.setColor(Color.black);
g2d.fillRect(0, 0, 10, 10);
g2d.drawImage(img, 1, 1, 9, 9, 8, 8, 16, 16, null);
g2d.dispose();
img.flush();
p.setMarker(pimg);
Thread.sleep(20L);
} catch (MalformedURLException e2) {
} catch (IOException e) {
}
}
} catch (InterruptedException e) {
}
}
if (!this.active) {
dispose();
}
}
public void dispose() {
players.clear();
players = null;
}
}

538
src/MoF/Tag.java Normal file
View File

@ -0,0 +1,538 @@
package MoF;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* NBT IO class
*
* @see <a href="http://www.minecraft.net/docs/NBT.txt">Online NBT specification</a>
*/
public class Tag {
private final Type type;
private Type listType = null;
private final String name;
private Object value;
/**
* Enum for the tag types.
*/
public enum Type {
TAG_End,
TAG_Byte,
TAG_Short,
TAG_Int,
TAG_Long,
TAG_Float,
TAG_Double,
TAG_Byte_Array,
TAG_String,
TAG_List,
TAG_Compound
}
/**
* Create a new TAG_List or TAG_Compound NBT tag.
*
* @param type either TAG_List or TAG_Compound
* @param name name for the new tag or null to create an unnamed tag.
* @param value list of tags to add to the new tag.
*/
public Tag(Type type, String name, Tag[] value) {
this(type, name, (Object) value);
}
/**
* Create a new TAG_List with an empty list. Use {@link Tag#addTag(Tag)} to add tags later.
*
* @param name name for this tag or null to create an unnamed tag.
* @param listType type of the elements in this empty list.
*/
public Tag(String name, Type listType) {
this(Type.TAG_List, name, listType);
}
/**
* Create a new NBT tag.
*
* @param type any value from the {@link Type} enum.
* @param name name for the new tag or null to create an unnamed tag.
* @param value an object that fits the tag type or a {@link Type} to create an empty TAG_List with this list type.
*/
public Tag(Type type, String name, Object value) {
switch (type) {
case TAG_End:
if (value != null)
throw new IllegalArgumentException();
break;
case TAG_Byte:
if (!(value instanceof Byte))
throw new IllegalArgumentException();
break;
case TAG_Short:
if (!(value instanceof Short))
throw new IllegalArgumentException();
break;
case TAG_Int:
if (!(value instanceof Integer))
throw new IllegalArgumentException();
break;
case TAG_Long:
if (!(value instanceof Long))
throw new IllegalArgumentException();
break;
case TAG_Float:
if (!(value instanceof Float))
throw new IllegalArgumentException();
break;
case TAG_Double:
if (!(value instanceof Double))
throw new IllegalArgumentException();
break;
case TAG_Byte_Array:
if (!(value instanceof byte[]))
throw new IllegalArgumentException();
break;
case TAG_String:
if (!(value instanceof String))
throw new IllegalArgumentException();
break;
case TAG_List:
if (value instanceof Type) {
this.listType = (Type) value;
value = new Tag[0];
} else {
if (!(value instanceof Tag[]))
throw new IllegalArgumentException();
this.listType = (((Tag[]) value)[0]).getType();
}
break;
case TAG_Compound:
if (!(value instanceof Tag[]))
throw new IllegalArgumentException();
break;
default:
throw new IllegalArgumentException();
}
this.type = type;
this.name = name;
this.value = value;
}
public Type getType() {
return type;
}
public String getName() {
return name;
}
public Object getValue() {
return value;
}
public void setValue(Object newValue)
{
switch (type) {
case TAG_End:
if (value != null)
throw new IllegalArgumentException();
break;
case TAG_Byte:
if (!(value instanceof Byte))
throw new IllegalArgumentException();
break;
case TAG_Short:
if (!(value instanceof Short))
throw new IllegalArgumentException();
break;
case TAG_Int:
if (!(value instanceof Integer))
throw new IllegalArgumentException();
break;
case TAG_Long:
if (!(value instanceof Long))
throw new IllegalArgumentException();
break;
case TAG_Float:
if (!(value instanceof Float))
throw new IllegalArgumentException();
break;
case TAG_Double:
if (!(value instanceof Double))
throw new IllegalArgumentException();
break;
case TAG_Byte_Array:
if (!(value instanceof byte[]))
throw new IllegalArgumentException();
break;
case TAG_String:
if (!(value instanceof String))
throw new IllegalArgumentException();
break;
case TAG_List:
if (value instanceof Type) {
this.listType = (Type) value;
value = new Tag[0];
} else {
if (!(value instanceof Tag[]))
throw new IllegalArgumentException();
this.listType = (((Tag[]) value)[0]).getType();
}
break;
case TAG_Compound:
if (!(value instanceof Tag[]))
throw new IllegalArgumentException();
break;
default:
throw new IllegalArgumentException();
}
value = newValue;
}
public Type getListType() {
return listType;
}
/**
* Add a tag to a TAG_List or a TAG_Compound.
*/
public void addTag(Tag tag) {
if (type != Type.TAG_List && type != Type.TAG_Compound)
throw new RuntimeException();
Tag[] subtags = (Tag[]) value;
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);
}
/**
* Add a tag to a TAG_List or a TAG_Compound at the specified index.
*/
public void insertTag(Tag tag, int index) {
if (type != Type.TAG_List && type != Type.TAG_Compound)
throw new RuntimeException();
Tag[] subtags = (Tag[]) value;
if (subtags.length > 0)
if (type == Type.TAG_List && tag.getType() != getListType())
throw new IllegalArgumentException();
if (index > subtags.length)
throw new IndexOutOfBoundsException();
Tag[] newValue = new Tag[subtags.length + 1];
System.arraycopy(subtags, 0, newValue, 0, index);
newValue[index] = tag;
System.arraycopy(subtags, index, newValue, index + 1, subtags.length - index);
value = newValue;
}
/**
* Remove a tag from a TAG_List or a TAG_Compound at the specified index.
*
* @return the removed tag
*/
public Tag removeTag(int index) {
if (type != Type.TAG_List && type != Type.TAG_Compound)
throw new RuntimeException();
Tag[] subtags = (Tag[]) value;
Tag victim = subtags[index];
Tag[] newValue = new Tag[subtags.length - 1];
System.arraycopy(subtags, 0, newValue, 0, index);
index++;
System.arraycopy(subtags, index, newValue, index - 1, subtags.length - index);
value = newValue;
return victim;
}
/**
* Remove a tag from a TAG_List or a TAG_Compound. If the tag is not a child of this tag then nested tags are searched.
*
* @param tag tag to look for
*/
public void removeSubTag(Tag tag) {
if (type != Type.TAG_List && type != Type.TAG_Compound)
throw new RuntimeException();
if (tag == null)
return;
Tag[] subtags = (Tag[]) value;
for (int i = 0; i < subtags.length; i++) {
if (subtags[i] == tag) {
removeTag(i);
return;
} else {
if (subtags[i].type == Type.TAG_List || subtags[i].type == Type.TAG_Compound) {
subtags[i].removeSubTag(tag);
}
}
}
}
/**
* Find the first nested tag with specified name in a TAG_Compound.
*
* @param name the name to look for. May be null to look for unnamed tags.
* @return the first nested tag that has the specified name.
*/
public Tag findTagByName(String name) {
return findNextTagByName(name, null);
}
/**
* Find the first nested tag with specified name in a TAG_List or TAG_Compound after a tag with the same name.
*
* @param name the name to look for. May be null to look for unnamed tags.
* @param found the previously found tag with the same name.
* @return the first nested tag that has the specified name after the previously found tag.
*/
public Tag findNextTagByName(String name, Tag found) {
if (type != Type.TAG_List && type != Type.TAG_Compound)
return null;
Tag[] subtags = (Tag[]) value;
for (Tag subtag : subtags) {
if ((subtag.name == null && name == null) || (subtag.name != null && subtag.name.equals(name))) {
return subtag;
} else {
Tag newFound = subtag.findTagByName(name);
if (newFound != null)
if (newFound == found)
continue;
else
return newFound;
}
}
return null;
}
/**
* Read a tag and its nested tags from an InputStream.
*
* @param is stream to read from, like a FileInputStream
* @return NBT tag or structure read from the InputStream
* @throws IOException if there was no valid NBT structure in the InputStream or if another IOException occurred.
*/
public static Tag readFrom(InputStream is) throws IOException {
DataInputStream dis = new DataInputStream(new GZIPInputStream(is));
byte type = dis.readByte();
Tag tag = null;
if (type == 0) {
tag = new Tag(Type.TAG_End, null, null);
} else {
tag = new Tag(Type.values()[type], dis.readUTF(), readPayload(dis, type));
}
dis.close();
return tag;
}
private static Object readPayload(DataInputStream dis, byte type) throws IOException {
switch (type) {
case 0:
return null;
case 1:
return dis.readByte();
case 2:
return dis.readShort();
case 3:
return dis.readInt();
case 4:
return dis.readLong();
case 5:
return dis.readFloat();
case 6:
return dis.readDouble();
case 7:
int length = dis.readInt();
byte[] ba = new byte[length];
dis.readFully(ba);
return ba;
case 8:
return dis.readUTF();
case 9:
byte lt = dis.readByte();
int ll = dis.readInt();
Tag[] lo = new Tag[ll];
for (int i = 0; i < ll; i++) {
lo[i] = new Tag(Type.values()[lt], null, readPayload(dis, lt));
}
if (lo.length == 0)
return Type.values()[lt];
else
return lo;
case 10:
byte stt;
Tag[] tags = new Tag[0];
do {
stt = dis.readByte();
String name = null;
if (stt != 0) {
name = dis.readUTF();
}
Tag[] newTags = new Tag[tags.length + 1];
System.arraycopy(tags, 0, newTags, 0, tags.length);
newTags[tags.length] = new Tag(Type.values()[stt], name, readPayload(dis, stt));
tags = newTags;
} while (stt != 0);
return tags;
}
return null;
}
/**
* Read a tag and its nested tags from an InputStream.
*
* @param os stream to write to, like a FileOutputStream
* @throws IOException if this is not a valid NBT structure or if any IOException occurred.
*/
public void writeTo(OutputStream os) throws IOException {
GZIPOutputStream gzos;
DataOutputStream dos = new DataOutputStream(gzos = new GZIPOutputStream(os));
dos.writeByte(type.ordinal());
if (type != Type.TAG_End) {
dos.writeUTF(name);
writePayload(dos);
}
gzos.flush();
gzos.close();
}
private void writePayload(DataOutputStream dos) throws IOException {
switch (type) {
case TAG_End:
break;
case TAG_Byte:
dos.writeByte((Byte) value);
break;
case TAG_Short:
dos.writeShort((Short) value);
break;
case TAG_Int:
dos.writeInt((Integer) value);
break;
case TAG_Long:
dos.writeLong((Long) value);
break;
case TAG_Float:
dos.writeFloat((Float) value);
break;
case TAG_Double:
dos.writeDouble((Double) value);
break;
case TAG_Byte_Array:
byte[] ba = (byte[]) value;
dos.writeInt(ba.length);
dos.write(ba);
break;
case TAG_String:
dos.writeUTF((String) value);
break;
case TAG_List:
Tag[] list = (Tag[]) value;
dos.writeByte(getListType().ordinal());
dos.writeInt(list.length);
for (Tag tt : list) {
tt.writePayload(dos);
}
break;
case TAG_Compound:
Tag[] subtags = (Tag[]) value;
for (Tag st : subtags) {
Tag subtag = st;
Type type = subtag.getType();
dos.writeByte(type.ordinal());
if (type != Type.TAG_End) {
dos.writeUTF(subtag.getName());
subtag.writePayload(dos);
}
}
break;
}
}
/**
* Print the NBT structure to System.out
*/
public void print() {
print(this, 0);
}
private String getTypeString(Type type) {
switch (type) {
case TAG_End:
return "TAG_End";
case TAG_Byte:
return "TAG_Byte";
case TAG_Short:
return "TAG_Short";
case TAG_Int:
return "TAG_Int";
case TAG_Long:
return "TAG_Long";
case TAG_Float:
return "TAG_Float";
case TAG_Double:
return "TAG_Double";
case TAG_Byte_Array:
return "TAG_Byte_Array";
case TAG_String:
return "TAG_String";
case TAG_List:
return "TAG_List";
case TAG_Compound:
return "TAG_Compound";
}
return null;
}
private void indent(int indent) {
for (int i = 0; i < indent; i++) {
System.out.print(" ");
}
}
private void print(Tag t, int indent) {
Type type = t.getType();
if (type == Type.TAG_End)
return;
String name = t.getName();
indent(indent);
System.out.print(getTypeString(t.getType()));
if (name != null)
System.out.print("(\"" + t.getName() + "\")");
if (type == Type.TAG_Byte_Array) {
byte[] b = (byte[]) t.getValue();
System.out.println(": [" + b.length + " bytes]");
} else if (type == Type.TAG_List) {
Tag[] subtags = (Tag[]) t.getValue();
System.out.println(": " + subtags.length + " entries of type " + getTypeString(t.getListType()));
for (Tag st : subtags) {
print(st, indent + 1);
}
indent(indent);
System.out.println("}");
} else if (type == Type.TAG_Compound) {
Tag[] subtags = (Tag[]) t.getValue();
System.out.println(": " + (subtags.length - 1) + " entries");
indent(indent);
System.out.println("{");
for (Tag st : subtags) {
print(st, indent + 1);
}
indent(indent);
System.out.println("}");
} else {
System.out.println(": " + t.getValue());
}
}
}

130
src/MoF/UpdateManager.java Normal file
View File

@ -0,0 +1,130 @@
package MoF;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
public class UpdateManager extends Thread {
public static String updateURL = "https://sites.google.com/site/mothfinder/update.xml";
private JFrame window;
private boolean silent;
public UpdateManager(JFrame window) {
this.setWindow(window);
silent = false;
}
public UpdateManager(JFrame window, boolean silence) {
this.setWindow(window);
silent = silence;
}
public void run() {
URL url = null;
try {
url = new URL(updateURL);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(url.openStream());
doc.getDocumentElement().normalize();
NodeList vlist = doc.getDocumentElement().getElementsByTagName("version");
NodeList version = vlist.item(0).getChildNodes();
Node v = null;
double major = 0;
int minor = 0;
String updateURL = doc.getFirstChild().getAttributes().item(0).getNodeValue();
for (int i = 0; i < version.getLength(); i++) {
v = version.item(i);
if (v.getNodeType() == Node.ELEMENT_NODE) {
if (v.getNodeName().toLowerCase().equals("major")) {
major = Double.parseDouble(v.getAttributes().item(0).getNodeValue());
} else if (v.getNodeName().toLowerCase().equals("minor")) {
minor = Integer.parseInt(v.getAttributes().item(0).getNodeValue());
}
}
}
if ((major == MoF.version_major) && (minor == MoF.version_minor)) {
if (!silent)
JOptionPane.showMessageDialog(window, "There are no new updates.");
} else if ((major == MoF.version_major) && (minor != MoF.version_minor)) {
int n = JOptionPane.showConfirmDialog(
window,
"A minor revision was found. Update?",
"Update Found",
JOptionPane.YES_NO_OPTION);
if (n==0) {
if( !java.awt.Desktop.isDesktopSupported()) {
JOptionPane.showMessageDialog(window, "Error unable to open browser.");
}
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
if( !desktop.isSupported( java.awt.Desktop.Action.BROWSE ) ) {
JOptionPane.showMessageDialog(window, "Error unable to open browser page.");
}
java.net.URI uri = new java.net.URI(updateURL);
desktop.browse( uri );
}
} else if (major != MoF.version_major) {
int n = JOptionPane.showConfirmDialog(
window,
"A new version was found. Would you like to update?",
"Update Found",
JOptionPane.YES_NO_OPTION);
if (n==0) {
if( !java.awt.Desktop.isDesktopSupported()) {
JOptionPane.showMessageDialog(window, "Error unable to open browser.");
}
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
if( !desktop.isSupported( java.awt.Desktop.Action.BROWSE ) ) {
JOptionPane.showMessageDialog(window, "Error unable to open browser page.");
}
java.net.URI uri = new java.net.URI(updateURL);
desktop.browse( uri );
}
}
} catch (MalformedURLException e1) {
if (!silent)
JOptionPane.showMessageDialog(window, "Error connecting to update server: Malformed URL.");
} catch (IOException e1) {
if (!silent)
JOptionPane.showMessageDialog(window, "Error reading update data.");
} catch (ParserConfigurationException e) {
if (!silent)
JOptionPane.showMessageDialog(window, "Error with XML parser configuration.");
} catch (SAXException e) {
if (!silent)
JOptionPane.showMessageDialog(window, "Error parsing update file.");
} catch (NumberFormatException e) {
if (!silent)
JOptionPane.showMessageDialog(window, "Error parsing version numbers.");
} catch (NullPointerException e) {
if (!silent)
JOptionPane.showMessageDialog(window, "Error \"NullPointerException\" in update.");
} catch (URISyntaxException e) {
if (!silent)
JOptionPane.showMessageDialog(window, "Error parsing update URL.");
}
}
public JFrame getWindow() {
return window;
}
public void setWindow(JFrame window) {
this.window = window;
}
}

7
src/amidst/Amidst.java Normal file
View File

@ -0,0 +1,7 @@
package amidst;
public class Amidst {
public static void main(String args[]) {
MoF.MoF.main(args);
}
}