Official Everybody Edits Forums

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.

#1 2017-08-02 14:47:12, last edited by wjg999 (2017-08-02 14:58:45)

wjg999
Member
Joined: 2017-07-12
Posts: 6

Question about world data

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

#2 2017-08-02 15:31:41

John
Member
Joined: 2019-01-11
Posts: 1,978

Re: Question about world data

Would this help you?


PW?scale=2

Offline

#3 2017-08-02 15:41:45

wjg999
Member
Joined: 2017-07-12
Posts: 6

Re: Question about world data

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

#4 2017-08-02 15:54:24

John
Member
Joined: 2019-01-11
Posts: 1,978

Re: Question about world data

wjg999 wrote:

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.

wjg999 wrote:

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.

wjg999 wrote:

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.


PW?scale=2

Offline

#5 2017-08-02 16:24:40, last edited by LukeM (2017-08-02 16:25:31)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Question about world data

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

#6 2017-08-02 19:57:05, last edited by Tomahawk (2017-08-04 18:36:07)

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,835

Re: Question about world data

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.

Init example

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;

The 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:

Modified InitParse

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

Wooted by: (5)

#7 2017-08-03 12:25:42

wjg999
Member
Joined: 2017-07-12
Posts: 6

Re: Question about world data

Thank you tomahawk,

Tomahawk wrote:

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

#8 2017-08-04 15:01:29, last edited by Tomahawk (2017-08-04 18:38:21)

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,835

Re: Question about world data

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:

Modified InitParse

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

Wooted by: (2)
Tomahawk1501855289671001

Board footer

Powered by FluxBB

[ Started around 1714018203.1365 - Generated in 0.128 seconds, 12 queries executed - Memory usage: 1.53 MiB (Peak: 1.69 MiB) ]