Jump to content

[1.10.2] Detecting whether a block was generated during world gen.


Recommended Posts

Posted

I want to make a better mob spawning system, and this requires determining whether a block was generated when you got close enough to the chunk containing that block, and if so, allow a mob to spawn if the light level is lower than 6. Any ideas? Thanks in advance.

Posted

There are few ways to do it, you basically need to save a boolean for every x/y/z position in world.

To do that you will need combination of ChunkLoadEvent and BlockBreak event and other stuff.

Data can be saved directly to chunk (preferred) or inside World (WorldSavedData).

1.7.10 is no longer supported by forge, you are on your own.

Posted

So, essentially use my mod's eventhandler to edit the chunkload event, such that each block is generated with a boolean, that is true?

 

Then also use my eventhandler to edit blockplace event, and make that boolean defaultly false?

 

I don't know how to save anything to a chunk yet, could you please go a little more into detail on that?

Posted

What I can give you is a outline:

 

1. @Subscribe to ChunkDataEvent.Load

2. Check if event.getData()#hasKey("generated") - if not - this means that such tag was never assigned thus - chunk has been generated just now. In that case - assign such tag.

The tag under key "generated" will be 3D ByteArray that will be saving mentioned x/y/z booleans.

A little bit about compression:

* Casuals would go ahead and make ByteArray with 16x16x256 = 65536 lenght, meaning it will be that many bytes.

* Wannabe-cool people would apply 8 times better compression and make each byte (8 bits) hold data for 8 blocks, making it only 8192 in lenghs. Similar approach can be done with 256x64(longs) array. Anyway - this is better, but requires bitwise operations knowledge.

So what next: If tag was not found assign it - you can do it however you want (as described above) and use some of NBT's methos such as setByteArray or setTagList (list of longs).

3. Now every chunk in world has array of booleans - I am not sure if chunk data can be read outside above event (probably not), so:

After all that above, no matter if the tag was there or chunk was just generated - you need to deserialize tag to some boolean[][][] x/y/z array. The array can be placed in some static x/y chunk map, so kinda like Chunk[][] of boolean[][][]. (#javaArraysComprehension).

4. This data you can access and change from several events such as said BlockBreak.

5. @Subscribe to ChunkDataEvent.Save and dump data from mentioned "Chunk[][] of boolean[][][]" into event.getData().

 

Big note: As holding all loaded-from-startup chunks would be retarded you need to design some cleaning system that will remove no longer used chunk's booleans. While that is easy (nullify data on ChunkDataEvent.Save), you also need to take care of your arrays design - this can't be just "Chunk[][] of boolean[][][]" because it would kill RAM (5D array?), think of Objectifying it to some data structures and Lists/Maps.

1.7.10 is no longer supported by forge, you are on your own.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.