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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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