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.

Advertisement

Hello, visitor! These forums are run off of the revenue generated from these ads. If you'd like to support us, please whitelist us or consider donating:

#1 2018-10-09 08:28:42

Latif
Member
From: The Netherlands
Joined: 2015-03-13
Posts: 1,148

[C# Tutorial] How to use InitParse - get all blocks in a world

I decided to make my own tutorial about using InitParse, because I noticed there aren't really other tutorials except Ninjasupeatsninja's one.

So let me start.

InitParse is a class written by Processor. The class only has one single method to parse the world data you receive from the "init" message (or "reset", I will explain later). That explains why it's called InitParse. The method returns an array of DataChunk objects. The DataChunk object (part of the class) can store all properties of a block. So you basically receive an array of all blocks in a world.

Step 1: InitParse class
View
Step 2: Block class
View
Step 3: Three dimensional array
View
Step 4: Parse world data
View
Step 5: Updating the array
View
Step 6: Loading the world
View

Now you are done! Here's a small explanation how to use the block array:

Using the array
View

Let me know if you need any help, or if you have some feedback for the tutorial. //forums.everybodyedits.com/img/smilies/smile

Last edited by Latif (2018-10-28 23:53:10)

Offline

Wooted by: (2)

#2 2018-10-09 13:29:47

Tomahawk
Member
From: BiH
Joined: 2015-02-18
Posts: 1,666

Re: [C# Tutorial] How to use InitParse - get all blocks in a world

Why are you using null for an empty space? There is a block there with ID 0; you're just making life harder for yourself.

Also you can compact the code in Step 5 by checking the message type against an array containing all of the block types. It'll be something similar to the code in this post.


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:

#3 2018-10-09 14:25:31

Latif
Member
From: The Netherlands
Joined: 2015-03-13
Posts: 1,148

Re: [C# Tutorial] How to use InitParse - get all blocks in a world

Tomahawk wrote:

Why are you using null for an empty space? There is a block there with ID 0; you're just making life harder for yourself.

You're right. I just changed it because I also realized it isn't really a good idea. It's a reference type so it's null by default. ¯\_(ツ)_/¯

Tomahawk wrote:

Also you can compact the code in Step 5 by checking the message type against an array containing all of the block types. It'll be something similar to the code in this post.

I knew there was a shorter way to do that. I just didn't know how I could do it. The "br" message also confused me a lot, but I see you just added a case for that. Thanks anyway, I changed it with credits to you. //forums.everybodyedits.com/img/smilies/tongue

Offline

#4 2018-10-28 20:15:00

Tomahawk
Member
From: BiH
Joined: 2015-02-18
Posts: 1,666

Re: [C# Tutorial] How to use InitParse - get all blocks in a world

Note to OP and anyone else updating their mapdata in realtime: you gotta listen for "bn" as well, when an NPC gets placed.


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)

#5 2018-10-29 00:00:45

Latif
Member
From: The Netherlands
Joined: 2015-03-13
Posts: 1,148

Re: [C# Tutorial] How to use InitParse - get all blocks in a world

Tomahawk wrote:

Note to OP and anyone else updating their mapdata in realtime: you gotta listen for "bn" as well, when an NPC gets placed.

Nice catch, it used to be there in my old code, just forgot that yours was made before the npc update.

I've added the "bn" message to the array, thanks. //forums.everybodyedits.com/img/smilies/smile

Offline

#6 2018-10-29 02:09:00

Tomahawk
Member
From: BiH
Joined: 2015-02-18
Posts: 1,666

Re: [C# Tutorial] How to use InitParse - get all blocks in a world

If you want, you can add another int to the Block class and have it start collecting the ID of the player who places each block.

Just make sure you default it to -1 or something, since 0 is a valid user ID.

Btw OP, you don’t need that initialisation loop in the deserialiser class, for the same reason - the default value of an int is already 0.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

#7 2018-10-31 18:47:37

Gosha
Dev Team
From: Russia
Joined: 2015-03-15
Posts: 5,468

Re: [C# Tutorial] How to use InitParse - get all blocks in a world

Step 5: Updating the array

repeating

blockTypes.Contains(m.Type)

Offline

Gosha1541008057730082

Board footer

Powered by FluxBB

[ Started around 1544906350.3803 - Generated in 0.074 seconds, 14 queries executed - Memory usage: 1.34 MiB (Peak: 1.49 MiB) ]