Jump to content

[1.16.4] Custom Structures not generating in Nether


Purplicious_Cow

Recommended Posts

I'm having issues trying to get Custom Structures to generate in the Nether. The same structure generates correctly in the Overworld (e.g., Swamp Biome works fine), but it doesn't even fire the event generation in the Nether. I suspect it's something in the way I've done registration or with the way Biome loading works in the Nether, but after two days, I haven't been able to move the needle. Any help appreciated:  

 

package com.inventorypets.worldgen;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.inventorypets.InventoryPets;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.DimensionSettings;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.IFeatureConfig;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
import net.minecraft.world.gen.feature.structure.IStructurePieceType;
import net.minecraft.world.gen.feature.structure.Structure;
import net.minecraft.world.gen.settings.DimensionStructuresSettings;
import net.minecraft.world.gen.settings.StructureSeparationSettings;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class WorldGen {
	static DeferredRegister<Structure<?>> STRUCTURES = DeferredRegister.create(ForgeRegistries.STRUCTURE_FEATURES, InventoryPets.MODID);
	static List<Structure<?>> STRUCTURE_LIST = new ArrayList<>();
	static Map<ResourceLocation, StructureSeparationSettings> STRUCTURE_SETTINGS = new HashMap<>();
	static IStructurePieceType register(IStructurePieceType type, String name) {
		net.minecraft.util.registry.Registry.register(net.minecraft.util.registry.Registry.STRUCTURE_PIECE, new ResourceLocation(InventoryPets.MODID, name), type);
		return type;
	}

	static <C extends IFeatureConfig, S extends Structure<C>> StructureFeature<C, S> register(StructureFeature<C, S> feature, String name) {
		WorldGenRegistries.register(WorldGenRegistries.CONFIGURED_STRUCTURE_FEATURE, new ResourceLocation(InventoryPets.MODID, name), feature);
		return feature;
	}

	static <C extends IFeatureConfig> RegistryObject<Structure<C>> addStructure(String name, Structure<C> structure, GenerationStage.Decoration stage, StructureSeparationSettings settings) {
		Structure.NAME_STRUCTURE_BIMAP.put(InventoryPets.MODID + ":" + name, structure);
		Structure.STRUCTURE_DECORATION_STAGE_MAP.put(structure, stage);
		STRUCTURE_LIST.add(structure);
		STRUCTURE_SETTINGS.put(new ResourceLocation(InventoryPets.MODID, name), settings);
		if (stage == GenerationStage.Decoration.SURFACE_STRUCTURES) {
			Structure.field_236384_t_ = ImmutableList.<Structure<?>>builder().addAll(Structure.field_236384_t_).add(structure).build();
		}
		return STRUCTURES.register(name, () -> structure);
	}

	public static IStructurePieceType SKY_DUNGEON_PIECE;
	public static IStructurePieceType SPACE_DUNGEON_PIECE;
	public static IStructurePieceType NETHER_DUNGEON_PIECE;
	public static IStructurePieceType UNDERGROUND_DUNGEON_PIECE;
	public static IStructurePieceType TREE_TOP_PIECE;
	public static IStructurePieceType SEA_CAVE_PIECE;

	public static RegistryObject<Structure<NoFeatureConfig>> SKY_DUNGEON_STRUCTURE = addStructure("sky_dungeon",
			new SkyDungeonStructure(NoFeatureConfig.field_236558_a_),
			GenerationStage.Decoration.RAW_GENERATION,
			new StructureSeparationSettings(7, 6, 1236));

	public static RegistryObject<Structure<NoFeatureConfig>> SPACE_DUNGEON_STRUCTURE = addStructure("space_dungeon",
			new SpaceDungeonStructure(NoFeatureConfig.field_236558_a_),
			GenerationStage.Decoration.RAW_GENERATION,
			new StructureSeparationSettings(9, 5, 1337));

	public static RegistryObject<Structure<NoFeatureConfig>> NETHER_DUNGEON_STRUCTURE = addStructure("nether_dungeon",
			new NetherDungeonStructure(NoFeatureConfig.field_236558_a_),
			GenerationStage.Decoration.RAW_GENERATION,
			new StructureSeparationSettings(6, 3, 1438));

	public static RegistryObject<Structure<NoFeatureConfig>> UNDERGROUND_DUNGEON_STRUCTURE = addStructure("underground_dungeon",
			new UndergroundDungeonStructure(NoFeatureConfig.field_236558_a_),
			GenerationStage.Decoration.RAW_GENERATION,
			new StructureSeparationSettings(8, 6, 1539));

	public static RegistryObject<Structure<NoFeatureConfig>> TREE_TOP_STRUCTURE = addStructure("tree_top",
			new TreeTopStructure(NoFeatureConfig.field_236558_a_),
			GenerationStage.Decoration.SURFACE_STRUCTURES,
			new StructureSeparationSettings(4, 3, 1640));

	public static RegistryObject<Structure<NoFeatureConfig>> SEA_CAVE_STRUCTURE = addStructure("sea_cave",
			new SeaCaveStructure(NoFeatureConfig.field_236558_a_),
			GenerationStage.Decoration.RAW_GENERATION,
			new StructureSeparationSettings(8, 6, 1741));

	public static StructureFeature<NoFeatureConfig, ? extends Structure<NoFeatureConfig>> SKY_DUNGEON_FEATURE;
	public static StructureFeature<NoFeatureConfig, ? extends Structure<NoFeatureConfig>> SPACE_DUNGEON_FEATURE;
	public static StructureFeature<NoFeatureConfig, ? extends Structure<NoFeatureConfig>> NETHER_DUNGEON_FEATURE;
	public static StructureFeature<NoFeatureConfig, ? extends Structure<NoFeatureConfig>> UNDERGROUND_DUNGEON_FEATURE;
	public static StructureFeature<NoFeatureConfig, ? extends Structure<NoFeatureConfig>> TREE_TOP_FEATURE;
	public static StructureFeature<NoFeatureConfig, ? extends Structure<NoFeatureConfig>> SEA_CAVE_FEATURE;

	public static void preInit() {
		STRUCTURES.register(FMLJavaModLoadingContext.get().getModEventBus());
	}

	public static void init() {
		SKY_DUNGEON_PIECE = register(SkyDungeonStructure.Piece::new, "sky_dungeon");
		SKY_DUNGEON_FEATURE = register(SKY_DUNGEON_STRUCTURE.get().withConfiguration(NoFeatureConfig.field_236559_b_), "sky_dungeon");
		SPACE_DUNGEON_PIECE = register(SpaceDungeonStructure.Piece::new, "space_dungeon");
		SPACE_DUNGEON_FEATURE = register(SPACE_DUNGEON_STRUCTURE.get().withConfiguration(NoFeatureConfig.field_236559_b_), "space_dungeon");
		UNDERGROUND_DUNGEON_PIECE = register(UndergroundDungeonStructure.Piece::new, "underground_dungeon");
		UNDERGROUND_DUNGEON_FEATURE = register(UNDERGROUND_DUNGEON_STRUCTURE.get().withConfiguration(NoFeatureConfig.field_236559_b_), "underground_dungeon");
		TREE_TOP_PIECE = register(TreeTopStructure.Piece::new, "tree_top");
		TREE_TOP_FEATURE = register(TREE_TOP_STRUCTURE.get().withConfiguration(NoFeatureConfig.field_236559_b_), "tree_top");
		SEA_CAVE_PIECE = register(SeaCaveStructure.Piece::new, "sea_cave");
		SEA_CAVE_FEATURE = register(SEA_CAVE_STRUCTURE.get().withConfiguration(NoFeatureConfig.field_236559_b_), "sea_cave");
		NETHER_DUNGEON_PIECE = register(NetherDungeonStructure.Piece::new, "nether_dungeon");
        NETHER_DUNGEON_FEATURE = register(NETHER_DUNGEON_STRUCTURE.get().withConfiguration(NoFeatureConfig.field_236559_b_), "nether_dungeon");
	   
		for (Structure<?> s : STRUCTURE_LIST) {
			ImmutableSet.of(DimensionSettings.field_242734_c, DimensionSettings.field_242736_e);
			DimensionStructuresSettings.field_236191_b_ = 
					ImmutableMap.<Structure<?>, StructureSeparationSettings>builder()
					.putAll(DimensionStructuresSettings.field_236191_b_)
					.put(s, STRUCTURE_SETTINGS.get(s.getRegistryName()))
					.build();
			DimensionSettings.field_242740_q.getStructures().field_236193_d_.put(s, STRUCTURE_SETTINGS.get(s.getRegistryName()));
		}
	}
	
	@SubscribeEvent(priority = EventPriority.HIGHEST)
	public void onBiomeLoad(BiomeLoadingEvent event) {
		event.getGeneration().withStructure(SKY_DUNGEON_FEATURE);
		event.getGeneration().withStructure(SPACE_DUNGEON_FEATURE);
		event.getGeneration().withStructure(UNDERGROUND_DUNGEON_FEATURE);

		if (event.getCategory() == Biome.Category.FOREST || event.getCategory() == Biome.Category.PLAINS || event.getCategory() == Biome.Category.SAVANNA || event.getCategory() == Biome.Category.TAIGA || event.getCategory() == Biome.Category.EXTREME_HILLS ) {
			event.getGeneration().withStructure(TREE_TOP_FEATURE);
		} else if (event.getCategory() == Biome.Category.OCEAN) {
			event.getGeneration().withStructure(SEA_CAVE_FEATURE);
		} else if (event.getCategory() == Biome.Category.SWAMP || event.getCategory() == Biome.Category.NETHER) {
			event.getGeneration().withStructure(NETHER_DUNGEON_FEATURE);
		} 

	}


}

 

Link to comment
Share on other sites

@Purplicious_Cow

Hmmm I've also been looking at this: 

 

Might be a problem with this line:

On 12/29/2020 at 7:31 PM, Purplicious_Cow said:

DimensionSettings.field_242740_q.getStructures().field_236193_d_.put(s, STRUCTURE_SETTINGS.get(s.getRegistryName()));

 

field_242740_q refers to a set of DimensionSettings generated by func_242745_a. That function takes a RegistryKey as a parameter, and in this case, it is passed field_242734_c which is the key for the overworld dimension. That might be the issue? Don't quote me on this! I have the same issue as you, but for all dimensions!

  • Thanks 1

How to ask a good coding question: https://stackoverflow.com/help/how-to-ask

Give logs, code, desired effects, and actual effects. Be thorough or we can't help you. Don't post code without putting it in a code block (the <> button on the post - select "C-type Language"): syntax highlighting makes everything easier, and it keeps the post tidy.

 

My own mod, Magiks Most Evile: GitHub (https://github.com/GenElectrovise/MagiksMostEvile) Wiki (https://magiksmostevile.fandom.com/wiki/Magiks_Most_Evile_Wiki)

Edit your own signature at https://www.minecraftforge.net/forum/settings/signature/

Link to comment
Share on other sites

Thanks, GenElectrovise. I had the same thought, but couldn't figure out how to force DimensionSettings to use field_242736_e (for the Nether). From my understanding of the code in func_242745_a, it looks like it pulls the world correct key prior to applying final settings, but I could be wrong. I may try this again, using access transformers to see if I can force the Nether key for this particular structure.

 

 

 

 

Link to comment
Share on other sites

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.