Hey guys, gals and others.
Today I'm going to be showing how to change your Frames.java and MapData.java to read the packed data files. This is if you are still loading your mapdata from Text files.
I have tested this out on a Bulby Source. So you should be able to transfer it to Pali quite easily ("I actually got this from a Pali Source, so i assume most Pali's should have this. If not then you will have it after this tutorial.") and the other sources I'm sure you can figure it out.
Now to the important parts.
Difficulty: 1.5 / 10
Assumed Knowledge: Converting from Bulby, to your Source.
First: Changing your MapData.java to load ".dat" files
So open your MapData.java and replace it completely with this:
Code:
package Bulby.world.mapdata;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import Bulby.util.*;
public class MapData {
private static HashMap<Integer, int[]> mapRegions;
private static int mapId;
public int mapData[] = new int[4];
public int[] getMapData(int region) {
return mapRegions.get(region);
}
public void loadRegions() {
try {
DataInputStream in = new DataInputStream(new FileInputStream("./data/mapdata/1.dat"));
do {
int i = in.readInt();
if(i == 0) {
break;
} else
if(i != 0) {
mapId = in.readInt();
for(int data = 0; data < 4; data++) {
mapData[data] = in.readInt();
}
}
mapRegions.put(mapId, new int[]{ mapData[0], mapData[1], mapData[2], mapData[3]});
} while(true);
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
static {
mapId = 0;
mapRegions = new HashMap<Integer, int[]>();
}
}
Next you are going to want to change all the imports, certain other variables that your source might not have or use etc.
Second: We will now change one Method in your Frames.java file
So open up your Frames.java file and searh for:
Code:
public void setMapRegion(Player p) {
OR
Then completely replace the current method you have with this:
Code:
/**
* Send the map region and other positioning info to the client.
* @param p The Player which the frame should be created for.
*/
public void setMapRegion(Player p) {
if (p == null || p.stream == null || p.disconnected[0]) {
return;
}
p.stream.createFrameVarSizeWord(142);
p.stream.writeWordA(p.mapRegionX);
p.stream.writeWordBigEndianA(p.currentY);
p.stream.writeWordA(p.currentX);
boolean forceSend = true;
if ((((p.mapRegionX / 8) == 48) || ((p.mapRegionX / 8) == 49)) && ((p.mapRegionY / 8) == 48)) {
forceSend = false;
}
if (((p.mapRegionX / 8) == 48) && ((p.mapRegionY / 8) == 148)) {
forceSend = false;
}
for (int xCalc = (p.mapRegionX - 6) / 8; xCalc <= ((p.mapRegionX + 6) / 8); xCalc++) {
for (int yCalc = (p.mapRegionY - 6) / 8; yCalc <= ((p.mapRegionY + 6) / 8); yCalc++) {
int region = yCalc + (xCalc << 1786653352);
if (forceSend || ((yCalc != 49) && (yCalc != 149) && (yCalc != 147) && (xCalc != 50) && ((xCalc != 49) || (yCalc != 47)))) {
int[] mapData = Engine.mapData.getMapData(region);
if (mapData == null) {
p.setCoords(2827, 3344, 0);
sendMessage(p, "You got teleported home due to Mapdata missing.");
return;
}
p.stream.writeDWord(mapData[0]);
p.stream.writeDWord(mapData[1]);
p.stream.writeDWord(mapData[2]);
p.stream.writeDWord(mapData[3]);
}
}
}
p.stream.writeByteC(p.heightLevel);
p.stream.writeWord(p.mapRegionY);
p.stream.endFrameVarSizeWord();
}
Now you may need to change the way your files are read, for example some servers have getByteVector() instead of stream. In the above method you will also need to change the coords to where your home location is.
Third: Download this ".dat" file so you can use your new Map Data loading way.
Make sure you copy that into your Server Folder -> bin -> data -> mapdata
Thanks for reading.
Now Compile, Run, and Play.
Hopefully you guys don't get any errors. Just post them if you do. I'm sure I can give you a hand or someone else might.
Enjoy!