How to allow structure to spawn on super flat world

Started by nicholashammond2004 on

Topic category: Advanced modding

Last seen on 19:05, 23. Jul 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to allow structure to spawn on super flat world

Although I know MCreator does not have an option to enable this, what would I have to add into the code for my custom structure to generate in a super flat world? I modified the code so that the structure spawns in all dimensions and biomes, however for some reason it will not spawn into super flat worlds.

package net.zorathekidlz.backrooms.gen.level0;

import net.minecraft.world.WorldType;
import net.minecraftforge.common.BiomeManager;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.placement.IPlacementConfig;
import net.minecraft.world.gen.feature.template.Template;
import net.minecraft.world.gen.feature.template.PlacementSettings;
import net.minecraft.world.gen.feature.template.BlockIgnoreStructureProcessor;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.feature.IFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.IWorld;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Rotation;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Mirror;

import net.zorathekidlz.backrooms.BackroomsModElements;
import net.zorathekidlz.backrooms.dimensions.level0.Level0ModDimension;

import java.util.Random;
import java.util.logging.Level;

@BackroomsModElements.ModElement.Tag
public class EmptyRoomStructure extends BackroomsModElements.ModElement {
    public EmptyRoomStructure(BackroomsModElements instance) {
        super(instance, 23);
    }

    private static boolean validSpawn(int x, int z){
        if(x % 32 == 0 && z % 32 != 0) {
            return true;
        } else return false;
    }

    @Override
    public void init(FMLCommonSetupEvent event) {
        Feature<NoFeatureConfig> feature = new Feature<NoFeatureConfig>(NoFeatureConfig::deserialize) {

            @Override
            public boolean place(IWorld iworld, ChunkGenerator generator, Random random, BlockPos pos, NoFeatureConfig config) {
                int ci = pos.getX();
                int ck = pos.getZ();
                DimensionType dimensionType = iworld.getDimension().getType();
                boolean dimensionCriteria = false;
                if (dimensionType == Level0ModDimension.type)
                    dimensionCriteria = true;
                if (!dimensionCriteria)
                    return false;
                Template template = ((ServerWorld) iworld.getWorld()).getSaveHandler().getStructureTemplateManager()
                        .getTemplateDefaulted(new ResourceLocation("backrooms", "empty_room"));
                if (template == null){
                    return false;
                }
                if (!validSpawn(ci, ck)){
                    return false;
                }
                Rotation rotation = Rotation.NONE;
                Mirror mirror = Mirror.NONE;
                BlockPos spawnTo = new BlockPos(ci,  100, ck);
                template.addBlocksToWorldChunk(iworld, spawnTo, new PlacementSettings().setRotation(rotation).setRandom(random)
                        .setMirror(mirror).setChunk((ChunkPos) null).setIgnoreEntities(false));
                return true;
            }
        };
        for (Biome biome : ForgeRegistries.BIOMES.getValues()) {
            biome.addFeature(GenerationStage.Decoration.SURFACE_STRUCTURES,
                    Biome.createDecoratedFeature(feature, IFeatureConfig.NO_FEATURE_CONFIG, Placement.NOPE, IPlacementConfig.NO_PLACEMENT_CONFIG));
        }
    }
}

 

I found your topic https:/…
Sun, 06/14/2020 - 11:08

I found your topic https://www.minecraftforge.net/forum/topic/86803-how-to-spawn-structure-in-flat-world/ and did some code research.

Indeed I don't think there is an easy way to do this. Some parts of MC code are just not meant to be modded and not really written in the way to be altered easily, unfortunately.

Not sure if still relevant,…
Thu, 08/13/2020 - 20:06

Not sure if still relevant, but I found out adding feature to FlatGenerationSettings.FEATURE_CONFIGS might do the trick