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

[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
Forum Mod
From: BiH
Joined: 2015-02-18
Posts: 1,970

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

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: BiH
Joined: 2015-02-18
Posts: 1,970

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

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: BiH
Joined: 2015-02-18
Posts: 1,970

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: 5,705

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,710
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,179

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:

HG

#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

vaishnavi1552105027742173

Board footer

Powered by FluxBB

[ Started around 1558825894.052 - Generated in 0.045 seconds, 12 queries executed - Memory usage: 1.43 MiB (Peak: 1.62 MiB) ]