Mythruna
July 24, 2017, 01:32:57 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: World Map Access  (Read 35561 times)
pspeed
Administrator
Hero Member
*****
Posts: 5508



View Profile
« on: August 05, 2011, 09:01:51 PM »

Accessing a local Mythruna world map from Java is fairly straight forward for someone who knows Java.  I won't describe how to do this in a multiplayer game as a) it's dangerous, b) setup is difficult, and c) that will certainly be clamped down at some point as eventually the remote world database implementations will not allow direct modification at all (except through separate commands).

Anyway, to access a mythruna.db you will need the game .jar files.  For Windows these are tied up in the .exe so it's better to download the Linux version for this.  The only difference between the Linux version and the Windows version is how the games are launched.

(Note: interfaces and implementations are subject to change though these should be pretty stable.  Note also, the game code itself is copyrighted and cannot be used in other games without permission.)

The best way to access world data is through the WorldDatabase interface.  It provides built in caching and a way to save back changes.  All of the below classes can be found in the mythruna.db package.

Code:
    // Create the actual file I/O layer for "leaf" data
    DefaultLeafDatabase leafDb = new DefaultLeafDatabase( new File("mythruna.db") );

    // Create the factory that generates the world data
    ColumnFactory colFactory = WorldUtils.createDefaultColumnFactory();

    // Create the world database
    WorldDatabase worldDb = new LocalWorldDatabase( leafDb, colFactory );

At this point I'm not really prepared to provide javadocs for the WorldDatabase or related interfaces but a clever Java program can figure out the callable methods from their IDE or by using javap.

The Mythruna world is divided into 1024x1024 meter "nodes".  These nodes are sub-divided into equal size "leafs".  A leaf is 32x32x32 blocks/cells.  So a node is 32x32x5 leafs.

Should it ever matter, the mythruna.Coordinates class has methods for translating from world coordinates to node, leaf, cell, etc..

All WorldDatabase methods take world coordinates in x,y,z where x,y are a map location and z is the elevation.

The most interesting and straight forward methods on WorldDatabase are getCellType() and setCellType().  These can be used to query or change the values of blocks in the world.  Though if you will be querying and changing a lot of blocks then there are better ways.

getColumnInfo() returns a ColumnInfo data structure for an entire stack of leafs at an x,y location.  This includes elevation and surface type information used to generate maps, for example.  This data structure is the most likely to evolve of any.

getLeaf() returns a LeafData object that contains the raw 32x32x32 data for a leaf.  If changes are made to this leaf then WorldDatabase.markChanged(leaf) can be called to save it again.  (Note: if changes are made through this approach then lighting will not be recalculated.  Set LeafData.getInfo().lit to false and it will be relit the next time it is loaded.)

For the most part, that's about all of the support I can provide other than answering some questions.  I have a game to write after all. Smiley

I will add that directly mucking with the LeafInfo fields (as retrieved by leafData.getInfo()) is pretty dangerous.  This API was not designed for safety but for internal speed and ease of use.  Modifying those fields directly may totally hose your world database (except in the case of the lit flag mentioned above and even that "may" cause issues with lighting.)

Good luck!
Logged
FutureB
Donators
Hero Member
***
Posts: 512


RAWR


View Profile
« Reply #1 on: November 20, 2011, 09:39:51 PM »

ahhhhhhhhh i dont understand and i dont think i want to understand :]
Logged


Say the opposite of these words:
1)Always.
2)Coming.
3)From.
4)Take.
5)Me.
6)Down.
RadioActiveFrog
Newbie
*
Posts: 2



View Profile WWW
« Reply #2 on: December 01, 2011, 07:51:42 AM »

Heyho,
it is possible that Mythruna/MythrunaServer load a *.jar like a plugin?
The reason ist i would maybe build, based on this, a webbased map viewer(a la dynmap on bukkit/minecraft).
Or it es possible that a groovy script load/start the "Plugin" so that write a groovy script that loads plugins in a specific folder?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5508



View Profile
« Reply #3 on: December 01, 2011, 12:56:11 PM »

Heyho,
it is possible that Mythruna/MythrunaServer load a *.jar like a plugin?
The reason ist i would maybe build, based on this, a webbased map viewer(a la dynmap on bukkit/minecraft).
Or it es possible that a groovy script load/start the "Plugin" so that write a groovy script that loads plugins in a specific folder?

To build a web based map viewer, I don't think you'd need to do this unless you somehow wanted to run it while the game was running... which gets kind of complicated I guess.

Mythruna is setup to load any jars in a lib sub-directory under scripts.  Actually, mythruna will search in sub-directories for scripts also and load their lib directories, too.  It should be very flexible.

It just depends on what you want to do how you set it up.  I'd need to know more about what you want to do to comment further.
Logged
Fred50
Newbie
*
Posts: 6


View Profile
« Reply #4 on: June 23, 2012, 12:44:39 AM »

With this information and my java skills. I think im going to make my own map.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5508



View Profile
« Reply #5 on: June 23, 2012, 01:37:55 AM »

This has changed slightly over the months...

The latest world DB setup code would look something like:
Code:
long seed = 0; // or whatever
File baseDir = new File("mythruna.db");
DefaultLeafDatabase leafDb = new DefaultLeafDatabase( baseDir, seed );
LeafFileLocator locator = new DefaultLeafFileLocator(baseDir);
ColumnFactory colFactory = WorldUtils.createDefaultColumnFactory(locator, seed);
WorldDatabase worldDb = new LocalWorldDatabase( leafDb, colFactory );
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5508



View Profile
« Reply #6 on: June 23, 2012, 01:40:21 AM »

And if you have an existing world and want to know its seed:
Code:
WorldInfo info = WorldInfo.load(baseDir);
if( info == null ) {
    // It's a new world and has no defaults yet
    info = WorldInfo.create( baseDir, "Mythruna:" + seed, seed );
} else {
    // Retrieve the world's seed
    seed = info.getSeed();
}
Logged
Fred50
Newbie
*
Posts: 6


View Profile
« Reply #7 on: June 23, 2012, 02:11:14 AM »

And if you have an existing world and want to know its seed:
Code:
WorldInfo info = WorldInfo.load(baseDir);
if( info == null ) {
    // It's a new world and has no defaults yet
    info = WorldInfo.create( baseDir, "Mythruna:" + seed, seed );
} else {
    // Retrieve the world's seed
    seed = info.getSeed();
}

Thanks for informing me Paul. Ill have to do it after i clean my workspace.
Logged
Rayblon
Donators
Hero Member
***
Posts: 1743


One day I'll be a species in Mythruna...


View Profile
« Reply #8 on: September 04, 2014, 07:21:57 AM »

This is such an active forum.
Logged


^Useful links^
Sean
Donators
Hero Member
***
Posts: 576



View Profile
« Reply #9 on: September 04, 2014, 12:48:49 PM »

We're all attentively waiting Smiley
Logged

"People willing to trade their freedom for temporary security deserve neither and will lose both." - Benjamin Franklin
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!