Started by
nicholashammond2004
on
Topic category: Help with Minecraft modding (Java Edition)
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));
}
}
}