Jump to content

[1.17.1] Custom Structures (also a little bit of entity spawning)


Recommended Posts

Posted

A long time ago I tried to make a Minecraft mod (key word is tried). I knew a lot less about Java back then and I mainly relied on the tutorial videos I found. Recently I decided to try and get back into it, and I found it was really fun! I've started doing things that I had no chance of figuring out how to do last time like implementing custom mobs and even bosses. The biggest problem is that there are close to no tutorials or any actual useful documentation for forge 1.17.1, but because of my increased skill level since my last modding attempt, I haven't had to rely on tutorials that much

I recently started trying to add custom entity spawning to the game, but couldn't figure out how to do it in the current forge version. Eventually I just decided to use reflection to add my own data into the vanilla map of "spawners" in net.minecraft.world.level.biome.MobSpawnSettings. This obviously isn't the intended way to add custom entity spawning to the game but because I can't find anything on this subject online, I did it and it works. Entity spawning isn't the main subject of this post, but it gives you the backstory of what I'm about to do (or more specifically, what I did).

After that, I wanted to add my own custom structure. I decided to add an RV that spawns in deserts and mesa biomes so I just looked at how vanilla adds structures.

I created all the proper java classes for the structure itself (The Feature class and the Pieces class) and created a StructureFeature field and a ConfiguredStructureFeature from that Feature. Then in a similar fashion to what I did with the entities, In biomes I wanted my structure to spawn in, I added my ConfiguredStructureFeature to "structureStarts" in net.minecraft.world.level.biome.BiomeGenerationSettings using reflection.

On top of that I also added my own StructureFeatureConfiguration to "BUILTIN_OVERWORLD" from net.minecraft.world.level.levelgen.NoiseGeneratorSettings.

If you're wondering, it works... kind of

When I create a new world, It will spawn the structures but after I exit that world it will take a long time to load the world and there are many EOFExceptions in the console. I did the best job I could do with debugging and found that the error was happening while loading the NBT data for structures in every chunk. It is having a lot of trouble when trying to do something having to do with structure references. I have done my best to try and see exactly what is going wrong in the code and how I can fix it, but frankly, I'm stumped and I have no idea of how to fix it. Honestly the way to fix it is probably to stop using reflection and to just properly register my structures, but I don't know how to do that. After I've exhausted every single solution I can think of, I finally decided to come here and ask for help.

My code for world generation:

  Reveal hidden contents
Posted
  On 10/15/2021 at 4:34 AM, Luis_ST said:

which version of forge do you exactly using 1.17.x.x.x because the first version throws an EOFException

Expand  

My mod is for minecraft 1.17.1, forge 37.0.67. Should I move my project to 37.0.95?

  Quote

you can use BiomeLoadingEvent instead of Reflection

Expand  

I utilize BiomeLoadingEvent at line 68 in my code, but that alone did not add structures to the game. I also had to use reflection to add my own StructureFeatureConfiguration.

Posted
  On 10/16/2021 at 12:45 AM, Goosey said:

I utilize BiomeLoadingEvent at line 68 in my code, but that alone did not add structures to the game. I also had to use reflection to add my own StructureFeatureConfiguration.

Expand  

show the code of your Structure, if possible via a git repo 

Posted
  On 10/16/2021 at 8:55 AM, Luis_ST said:

show the code of your Structure, if possible via a git repo 

Expand  

The code which utilizes BiomeLoadingEvent I have already shown above but here it is again:

  Reveal hidden contents

This code for the feature is this:

  Reveal hidden contents

And the code for the structure piece is this:

  Reveal hidden contents

I mainly took advantage of the many examples in vanilla to make the above two classes

  • 2 weeks later...
Posted

I figured it out, thanks.

It turns out I had to use event.getGeneration().addStructureStart() instead of event.getGeneration().getStructures().add() among a few other things like updating my version of forge.

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.