在自定义维度中生成自定义矿石

Generate custom ores in custom dimension

我最近使用 Minecraft 1.16.5 中的数据包创建了一个自定义维度。 这个维度是我正在编写的 mod 的一部分,我目前正在尝试在该维度中生成自定义矿石;但是,我无法像在主世界或下界中生成矿石那样在自定义维度中生成矿石。正如我提到的,维度是通过数据包(.json 文件)处理的,但生物群落是在游戏代码中处理的(.java)。我对 Java & modding 很陌生,如有任何建议,我们将不胜感激。 提前致谢。

我的世界版本:1.16.5
锻造版本:36.2.9

主世界和下界矿石生成的当前代码:

public class OreGeneration 
{
    public static void generateOres(final BiomeLoadingEvent event)
    {
        // Gigalium :
        if(!(event.getCategory().equals(Biome.Category.THEEND)))
        {
            // Nether :
            if(event.getCategory().equals(Biome.Category.NETHER))
            {
                generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NETHERRACK, BlockInit.GIGALIUM_NETHER_ORE.get().defaultBlockState(), 6, 25, 50, 2);
                generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NETHERRACK, BlockInit.GIGALIUM_NETHER_ORE.get().defaultBlockState(), 4, 51, 120, 2);
            }

            // Overworld :
            if(event.getCategory().equals(Biome.Category.SWAMP) || event.getCategory().equals(Biome.Category.TAIGA))
            {
                generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockInit.GIGALIUM_ORE.get().defaultBlockState(), 5, 12, 15, 2);
                generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockInit.GIGALIUM_ORE.get().defaultBlockState(), 4, 16, 20, 2);
            }

            if(!(event.getCategory().equals(Biome.Category.SWAMP) && event.getCategory().equals(Biome.Category.TAIGA)))
            {
                generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockInit.GIGALIUM_ORE.get().defaultBlockState(), 4, 10, 13, 1);
                generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockInit.GIGALIUM_ORE.get().defaultBlockState(), 3, 14, 18, 1);
            }
        }
    }

    private static void generateOre(BiomeGenerationSettingsBuilder settings, RuleTest fillerType, BlockState state, int veinSize, int minHeight, int maxHeight, int amount)
    {
        settings.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.configured(new OreFeatureConfig(fillerType, state, veinSize)).decorated(Placement.RANGE.configured(new TopSolidRangeConfig(minHeight, 0, maxHeight))).squared().count(amount));
    }
}

尺寸代码:

{
    "type": "gigawhat_gigamod:gigaland",
    "generator": {
        "type": "minecraft:noise",
        "seed": 0,
        "settings": {
            "bedrock_roof_position": -10,
            "bedrock_floor_position": 0,
            "sea_level": 80,
            "disable_mob_generation": true,
            "default_block": {
                "Name": "gigawhat_gigamod:gigastone"
            },
            "default_fluid": {
                "Name": "minecraft:water",
                "Properties": {
                    "level": "0"
                }
            },
            "noise": {
                "height": 256,
                "density_factor": 1,
                "density_offset": -0.46875,
                "size_horizontal": 1,
                "size_vertical": 2,
                "simplex_surface_noise": true,
                "random_density_offset": true,
                "amplified": true,
                "sampling": {
                    "xz_scale": 1,
                    "y_scale": 1,
                    "xz_factor": 80,
                    "y_factor": 160
                },
                "bottom_slide": {
                    "target": -30,
                    "size": 0,
                    "offset": 0
                },
                "top_slide": {
                    "target": -10,
                    "size": 3,
                    "offset": 0
                }
            },
            "structures": {
                "structures": {}
            }
        },
        "biome_source": {
            "type": "minecraft:fixed",
            "biome": "gigawhat_gigamod:gigaland_main_biome"
        }
    }
}

生物群落初始化代码:

public class ModBiomes 
{
    public static final DeferredRegister<Biome> BIOMES = DeferredRegister.create(ForgeRegistries.BIOMES, Gigamod.MOD_ID);

    public static final RegistryObject<Biome> GIGALAND_MAIN_BIOME = BIOMES.register("gigaland_main_biome", () -> makeGigalandMainBiome(() -> ModConfiguredSurfaceBuilders.GIGALAND_SURFACE, 0.205f, 0.02f));

    private static Biome makeGigalandMainBiome(final Supplier<ConfiguredSurfaceBuilder<?>> surfaceBuilder, float depth, float scale) 
    {
        MobSpawnInfo.Builder mobspawninfo$builder = new MobSpawnInfo.Builder();
        BiomeGenerationSettings.Builder biomegenerationsettings$builder = (new BiomeGenerationSettings.Builder()).surfaceBuilder(surfaceBuilder);

        DefaultBiomeFeatures.addDefaultOverworldLandStructures(biomegenerationsettings$builder);
        biomegenerationsettings$builder.addStructureStart(StructureFeatures.MINESHAFT);

        DefaultBiomeFeatures.addDefaultCarvers(biomegenerationsettings$builder);
        DefaultBiomeFeatures.addDefaultUndergroundVariety(biomegenerationsettings$builder);

        mobspawninfo$builder.addSpawn(EntityClassification.MONSTER, new MobSpawnInfo.Spawners(EntityType.BLAZE, 100, 10, 15));

        return (new Biome.Builder()).precipitation(RainType.RAIN).biomeCategory(Category.EXTREME_HILLS).depth(depth).scale(scale).temperature(1.5F).downfall(0.9F).specialEffects((new BiomeAmbience.Builder()).waterColor(65518).waterFogColor(16763760).fogColor(16763760).skyColor(16763760).foliageColorOverride(9547008).grassColorOverride(9547008).ambientParticle(new ParticleEffectAmbience(ParticleTypes.LAVA, 0.003f)).skyColor(16763760).ambientLoopSound(SoundEvents.AMBIENT_CRIMSON_FOREST_LOOP).ambientMoodSound(new MoodSoundAmbience(SoundEvents.AMBIENT_WARPED_FOREST_MOOD, 6000, 8, 2.0D)).ambientAdditionsSound(new SoundAdditionsAmbience(SoundEvents.AMBIENT_NETHER_WASTES_MOOD, 0.0111D)).build()).mobSpawnSettings(mobspawninfo$builder.build()).generationSettings(biomegenerationsettings$builder.build()).build();
    }

    public static void register(IEventBus eventBus)
    {
        BIOMES.register(eventBus);
    }
}

回答我自己的问题。

OreGen class 中的 if 语句中不应使用 event.getCategory().equals(SomeBiomeCategory),而应使用 event.getName().equals(YourModBiomeInit.BiomeName.getId()。因为 event.getCategory().equals(SomeBiomeCategory) 获取当前生成的生物群系的类别,而 event.getName().equals(YourModBiomeInit.BiomeName.getId() 获取注册名称(或 ID)。

所以 if 语句看起来像这样:

if(event.getName().equals(YourModBiomeInit.SOME_BIOME.getId()))
{
   // Generate ores ...
}