Jump to content

Recommended Posts

Posted (edited)

I've created custom tree "Feature"s and registered them to the forge Feature registry, but I don't know what to do after this. I deally I'd like to override the vanilla trees, or tell the game not to place vanilla trees and to place mine instead. I checked the different available Events provided by forge but I didn't see any that jumped put to me as being related to world generation. If there is no Event to subscribe to for world generation, how would I go about doing this? Forge 1.15

Edited by Jkmcameron
Posted (edited)

Ok somehow I spent hours looking into this with no progress, but just when I give up and make a thread about it I sort of figure it out. Is the following code viable? 

 

@SubscribeEvent
public void worldGeneration(WorldEvent event)
{
	Collection<Biome> biomes = ForgeRegistries.BIOMES.getValues();

	for (Biome biome : biomes)
	{
	    List<ConfiguredFeature<?, ?>> configuredFeatures = biome.getFeatures(GenerationStage.Decoration.VEGETAL_DECORATION);

	    for (ConfiguredFeature<?, ?> configuredFeature : configuredFeatures)
	    {
		switch (configuredFeature.feature.getRegistryName().getPath())
		{
		    case "normal_tree":
		    case "acacia_tree":
		    case "fancy_tree":
		    case "dark_oak_tree":
		    case "mega_jungle_tree":
		    case "mega_spruce_tree":

			configuredFeatures.remove(configuredFeature);
		}
	    }

	    biome.getFeatures(GenerationStage.Decoration.VEGETAL_DECORATION).clear();

	    for (ConfiguredFeature<?, ?> configuredFeature : configuredFeatures)
	    {
		biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, configuredFeature);
	    }

	    // Add custom trees

	    biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, MY_CUSTOM_FEATURE);
	}
}

I assume this would have the intended effect, but what would be the correct Event to fire this code at? Obviously it has to be done after RegistryEvent.Register<Feature<?>> is called

Edited by Jkmcameron
Posted (edited)
2 hours ago, Jkmcameron said:

Ok somehow I spent hours looking into this with no progress, but just when I give up and make a thread about it I sort of figure it out. Is the following code viable? 

 


@SubscribeEvent
public void worldGeneration(WorldEvent event)
{
	Collection<Biome> biomes = ForgeRegistries.BIOMES.getValues();

	for (Biome biome : biomes)
	{
	    List<ConfiguredFeature<?, ?>> configuredFeatures = biome.getFeatures(GenerationStage.Decoration.VEGETAL_DECORATION);

	    for (ConfiguredFeature<?, ?> configuredFeature : configuredFeatures)
	    {
		switch (configuredFeature.feature.getRegistryName().getPath())
		{
		    case "normal_tree":
		    case "acacia_tree":
		    case "fancy_tree":
		    case "dark_oak_tree":
		    case "mega_jungle_tree":
		    case "mega_spruce_tree":

			configuredFeatures.remove(configuredFeature);
		}
	    }

	    biome.getFeatures(GenerationStage.Decoration.VEGETAL_DECORATION).clear();

	    for (ConfiguredFeature<?, ?> configuredFeature : configuredFeatures)
	    {
		biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, configuredFeature);
	    }

	    // Add custom trees

	    biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, MY_CUSTOM_FEATURE);
	}
}

I assume this would have the intended effect, but what would be the correct Event to fire this code at? Obviously it has to be done after RegistryEvent.Register<Feature<?>> is called

 

Ok the event was RegistryEvent.Register<Biome> (duh), after dealing with some BS that was preventing RegistryEvent from firing I got it to work, code is good. Not a tree in sight. Close the thread

Edited by Jkmcameron

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.