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 2018-10-09 08:28:42, last edited by Latif (2018-10-28 23:53:10)

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

[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

Offline

Wooted by: (3)

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

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

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,206

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
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,847

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,206

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
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,847

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

Wooted by:

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

Gosha
Member
From: Russia
Joined: 2015-03-15
Posts: 6,211

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

Step 5: Updating the array

repeating

blockTypes.Contains(m.Type)

Offline

Wooted by:

#8 2019-03-07 13:08:41

vaishnavi
New Member
Joined: 2019-03-07
Posts: 3

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

Excellent information here. It was useful for me. Thank you!

Offline

Wooted by:

#9 2019-03-07 13:17:04

ILikeTofuuJoe
Member
From: Obvervable Universe
Joined: 2018-06-04
Posts: 1,770
Website

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

vaishnavi wrote:

Excellent information here. It was useful for me. Thank you!

Just woot ok


https://wiki.everybodyedits.com/images/8/8f/117_cat ~meow~ https://wiki.everybodyedits.com/images/8/8f/117_cat
Posting Goal: 2000
#Joe Griffin
Signature
Thanks HG for the signature and avatar!!!

Offline

#10 2019-03-07 21:16:57

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

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

I should actually fix the flaws in this.

vaishnavi wrote:

Excellent information here. It was useful for me. Thank you!

That's nice to hear. Glad it was helpful for you.

ILikeTofuuJoe wrote:

Just woot ok

This post was not needed.

Offline

Wooted by:

#11 2019-03-09 05:17:07

vaishnavi
New Member
Joined: 2019-03-07
Posts: 3

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

Excellent topic!

Offline

#12 2020-10-07 18:34:02

Blackmask
Member
From: France
Joined: 2016-06-27
Posts: 199

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

Thank you for this very helpful tutorial, Latif ! However when I try to get a block id from a world I've just entered in it returns me 0 whereas when I start putting random blocks it does return me the correct id. I've put the code from Step 4 in the (if m.Type == "init") block though :/

I've tried to make it so it is a switch like step 4 but it doesn't seem to resolve anything at all. Does anybody have some idea on what I've done wrong ? Thank you.

Offline

#13 2020-10-08 06:59:14

Gosha
Member
From: Russia
Joined: 2015-03-15
Posts: 6,211

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

you can use this

Hidden text

Offline

Wooted by:

#14 2020-10-08 07:33:07

Blackmask
Member
From: France
Joined: 2016-06-27
Posts: 199

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

Gosha wrote:

you can use this

Hidden text

Damn, it's working now //forums.everybodyedits.com/img/smilies/cool. Thank you //forums.everybodyedits.com/img/smilies/big_smile

Offline

Blackmask1602138787785130

Board footer

Powered by FluxBB

[ Started around 1732237478.5168 - Generated in 0.114 seconds, 12 queries executed - Memory usage: 1.65 MiB (Peak: 1.87 MiB) ]