Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Pages: 1
I am trying to parse the world data that I get in the init but the page on github does not document what the numbers between "ws" and "we" are.
From what I am seeing in the array itself it seems to be 4 values for each block type
- block id
- layer
- byte array containing 2 entries per block all even entries giving an unknown value and all uneven entries giving X
- byte array containing 2 entries per block all even entries giving an unknown value and all uneven entries giving Y
What I mostly want to know is what those 2 unknown values are, they seem to be at 0 for most of the time.
I could very well be wrong with what those 4 values are too, so if they are wrong please correct me.
Offline
Not really since it does not help me understand what values there are.
As well as it being 2 years old so I am not even sure if that would still be working.
The link to github in that post does help me understand it a bit more so thank you for the post link.
Offline
Not really since it does not help me understand what values there are.
Well, each different block "instance" is sent, and the byte arrays are the coordinates they are located at. What I mean by "instance" is like the same block with the same parameters. If a block has a different parameter, it is another instance.
As well as it being 2 years old so I am not even sure if that would still be working.
It's designed to be future proof. It won't break when there are new updates.
The link to github in that post does help me understand it a bit more so thank you for the post link.
Yeah that's what I was going for, I thought a guide might've been useful too.
Offline
This format is repeated for every block in the world, iirc sorted by the first block in the arrays, top to bottom, left to right:
Type: The ID of the block
Layer: The layer of the block, (0 for fg, 1 for bg)
Xs: A bytearray storing 16 bit x positions (by appending the bits of the first and second bytes)
Ys: A bytearray storing 16 bit y positions (same as above)
[Extra arguments are found here, depending on what block it is (see InitParse for a good way to parse these)]
Offline
I meant to write an explanation of the mapdata for Thanel's protocol a while back. Here's a quick one:
Below I've put part of an example "init" message. Ignore the indexes - it's from an earlier version of EE.
Every normal block has 4 values: ID, layer, X and Y coords, but special blocks - like portals, coindoors, any block or decor that can rotate, etc. - have more. These extra arguments are found right after the two byte arrays, before the ID of the next block in the list.
In order to deserialise (decode) the mapdata, you either have to have a list of the ID of every special block so that you can record the correct parameters, or you can work backwards from "we" (~world end), which is what InitParse does.
The way that the X and Y coordinates are encoded in the byte arrays is difficult to understand if you don't understand binary. Basically, BigDB only has one type of array - byte arrays - and as a byte only has a max value of 255, a single byte cannot be used to store a coordinate, because some worlds are taller or wider than 255 blocks. Instead, pairs of bytes are used to store each coordinate as an Int16 (16-bit integer) - the first byte stores the first 8 bits, and the second byte stores the second 8 bits of the full coordinate, allowing for a max value of 32767.
To put these bytes together to form the coordinate, it's easiest to use two of C#'s bitwise operators, (operators that work with bits in numerical data types), which are << and |
<< or >> are bitwise shift operators and move the bits around in a variable in the direction that they point. For instance, if a byte has the value 00000111 (or 4) and you shift the bits one place to the left (<< 1) you get 00001110. I'm not gonna try and explain this properly - go on Google for that - so I'll explain its relevance to the mapdata.
Likewise the bitwise OR operator does what it sounds like; it "OR"s together two binary strings. 00001111 | 11110000 = 11111111. This is used to join the two bytes together after byte-shifting the first one.
So, some code;
Now given that OP asked for an explanation of the serialised map data and not for an explanation of InitParse, I won't bother. There's probably explanations around anyway.
However, I wrote a modified version of InitParse (credits to sugardaddy Processor for the original) to make it more compact:
This post was too long. TL;DR = it's complicated.
One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.
Offline
Thank you tomahawk,
The way that the X and Y coordinates are encoded in the byte arrays is difficult to understand if you don't understand binary. Basically, BigDB only has one type of array - byte arrays - and as a byte only has a max value of 255, a single byte cannot be used to store a coordinate, because some worlds are taller or wider than 255 blocks. Instead, pairs of bytes are used to store each coordinate as a Int16 (16-bit integer) - the first byte stores the first 8 bits, and the second byte stores the second 8 bits of the full coordinate, allowing for a max value of 32767.
That was the bit I was so confused about since it seemed there was 2 numbers per block one of which I did not know what it was for.
So this fully answered the question I was having.
Offline
Hey - I made a mistake in my original modified version of InitParse.
The mistake was in clearing the stack of arguments after assigning them to the first block in the byte arrays.
I've edited the code in my post above, and I'll put it again below:
Sorry.
EDIT: Fixed it again T_T
uint c needs to be m.Count - 2, otherwise the argument "we" gets added to all instances of the last block in the map data.
There goes my reputation.
One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.
Offline
Pages: 1
[ Started around 1732621595.7018 - Generated in 0.086 seconds, 10 queries executed - Memory usage: 1.53 MiB (Peak: 1.69 MiB) ]