diff --git a/src/main/java/com/majruszsdifficulty/Registries.java b/src/main/java/com/majruszsdifficulty/Registries.java index e4b853844..464c4bc37 100644 --- a/src/main/java/com/majruszsdifficulty/Registries.java +++ b/src/main/java/com/majruszsdifficulty/Registries.java @@ -14,6 +14,7 @@ import com.majruszsdifficulty.triggers.GameStageTrigger; import com.majruszsdifficulty.triggers.TreasureBagTrigger; import com.majruszsdifficulty.undeadarmy.UndeadArmyManager; +import com.majruszsdifficulty.world.WorldGenHelper; import com.mlib.Utility; import com.mlib.annotations.AnnotationHandler; import com.mlib.items.CreativeModeTabHelper; @@ -23,6 +24,7 @@ import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.renderer.RenderType; +import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleType; import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.resources.ResourceLocation; @@ -47,6 +49,8 @@ import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; import net.minecraftforge.common.ForgeSpawnEggItem; import net.minecraftforge.common.MinecraftForge; @@ -92,6 +96,8 @@ public class Registries { static final DeferredRegister< SoundEvent > SOUNDS_EVENTS = HELPER.create( ForgeRegistries.Keys.SOUND_EVENTS ); static final DeferredRegister< LootItemFunctionType > LOOT_FUNCTIONS = HELPER.create( LOOT_FUNCTION_REGISTRY ); static final DeferredRegister< Potion > POTIONS = HELPER.create( ForgeRegistries.Keys.POTIONS ); + static final DeferredRegister< PlacedFeature > PLACED_FEATURES = HELPER.create( Registry.PLACED_FEATURE_REGISTRY ); + static final DeferredRegister< ConfiguredFeature< ?, ? > > CONFIGURED_FEATURES = HELPER.create( Registry.CONFIGURED_FEATURE_REGISTRY ); // Entities public static final RegistryObject< EntityType< CreeperlingEntity > > CREEPERLING = ENTITY_TYPES.register( "creeperling", CreeperlingEntity.createSupplier() ); @@ -205,6 +211,16 @@ static RegistryObject< SoundEvent > register( String name ) { // Game Modifiers public static final AnnotationHandler ANNOTATION_HANDLER = new AnnotationHandler( MajruszsDifficulty.MOD_ID ); + // Configured Feature + public static final RegistryObject< ConfiguredFeature< ?, ? > > ENDERIUM_ORE_SMALL_CONFIGURED = CONFIGURED_FEATURES.register( "enderium_ore_small", ()->WorldGenHelper.getEndConfigured( ENDERIUM_SHARD_ORE, 2, 0.99f ) ); + public static final RegistryObject< ConfiguredFeature< ?, ? > > ENDERIUM_ORE_LARGE_CONFIGURED = CONFIGURED_FEATURES.register( "enderium_ore_large", ()->WorldGenHelper.getEndConfigured( ENDERIUM_SHARD_ORE, 3, 0.99f ) ); + public static final RegistryObject< ConfiguredFeature< ?, ? > > INFESTED_END_STONE_CONFIGURED = CONFIGURED_FEATURES.register( "infested_end_stone", ()->WorldGenHelper.getEndConfigured( INFESTED_END_STONE, 4, 0.0f ) ); + + // Placed Feature + public static final RegistryObject< PlacedFeature > ENDERIUM_ORE_SMALL_PLACED = PLACED_FEATURES.register( "enderium_ore_small_placed", ()->WorldGenHelper.getEndPlaced( ENDERIUM_ORE_SMALL_CONFIGURED, 16 ) ); + public static final RegistryObject< PlacedFeature > ENDERIUM_ORE_LARGE_PLACED = PLACED_FEATURES.register( "enderium_ore_large_placed", ()->WorldGenHelper.getEndPlaced( ENDERIUM_ORE_LARGE_CONFIGURED, 8 ) ); + public static final RegistryObject< PlacedFeature > INFESTED_END_STONE_PLACED = PLACED_FEATURES.register( "infested_end_stone_placed", ()->WorldGenHelper.getEndPlaced( INFESTED_END_STONE_CONFIGURED, 128 ) ); + public static UndeadArmyManager getUndeadArmyManager() { return GAME_DATA_SAVER != null ? GAME_DATA_SAVER.getUndeadArmyManager() : UndeadArmyManager.NOT_LOADED; } diff --git a/src/main/java/com/majruszsdifficulty/world/BiomeLoader.java b/src/main/java/com/majruszsdifficulty/world/BiomeLoader.java new file mode 100644 index 000000000..e07d774dc --- /dev/null +++ b/src/main/java/com/majruszsdifficulty/world/BiomeLoader.java @@ -0,0 +1,89 @@ +package com.majruszsdifficulty.world; + +import com.majruszsdifficulty.Registries; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.MobSpawnSettings; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder; +import net.minecraftforge.common.world.MobSpawnSettingsBuilder; +import net.minecraftforge.event.world.BiomeLoadingEvent; +import net.minecraftforge.eventbus.api.EventPriority; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +@Mod.EventBusSubscriber +public class BiomeLoader { + @SubscribeEvent( priority = EventPriority.HIGH ) + public static void onLoad( BiomeLoadingEvent event ) { + Biome.BiomeCategory category = event.getCategory(); + MobSpawnSettingsBuilder spawnInfoBuilder = event.getSpawns(); + BiomeGenerationSettingsBuilder generationSettingsBuilder = event.getGeneration(); + + if( doBiomeCategoryBelongsToOverworld( category ) ) { + addOverworldEntities( spawnInfoBuilder ); + addOverworldStructures( generationSettingsBuilder ); + } else if( doBiomeCategoryBelongsToNether( category ) ) { + addNetherEntities( spawnInfoBuilder ); + } else if( doBiomeCategoryBelongsToTheEnd( category ) ) { + addEndEntities( spawnInfoBuilder ); + addEndStructures( generationSettingsBuilder ); + addEndOres( generationSettingsBuilder ); + } + } + + static void addOverworldEntities( MobSpawnSettingsBuilder spawnInfoBuilder ) { + addFreshEntity( spawnInfoBuilder, MobCategory.MONSTER, EntityType.ILLUSIONER, 20, 1, 2 ); + addFreshEntity( spawnInfoBuilder, MobCategory.MONSTER, Registries.TANK.get(), 3, 1, 1 ); + } + + static void addOverworldStructures( BiomeGenerationSettingsBuilder generationSettingsBuilder ) {} + + static void addNetherEntities( MobSpawnSettingsBuilder spawnInfoBuilder ) {} + + protected static void addEndEntities( MobSpawnSettingsBuilder spawnInfoBuilder ) {} + + protected static void addEndStructures( BiomeGenerationSettingsBuilder generationSettingsBuilder ) {} + + protected static void addEndOres( BiomeGenerationSettingsBuilder generationSettingsBuilder ) { + generationSettingsBuilder.addFeature( GenerationStep.Decoration.UNDERGROUND_ORES, Registries.INFESTED_END_STONE_PLACED.getHolder().get() ); + generationSettingsBuilder.addFeature( GenerationStep.Decoration.UNDERGROUND_ORES, Registries.ENDERIUM_ORE_SMALL_PLACED.getHolder().get() ); + generationSettingsBuilder.addFeature( GenerationStep.Decoration.UNDERGROUND_ORES, Registries.ENDERIUM_ORE_LARGE_PLACED.getHolder().get() ); + } + + protected static boolean doBiomeCategoryBelongsToOverworld( Biome.BiomeCategory category ) { + boolean isTaiga = category == Biome.BiomeCategory.TAIGA; + boolean isExtremeHills = category == Biome.BiomeCategory.EXTREME_HILLS; + boolean isJungle = category == Biome.BiomeCategory.JUNGLE; + boolean isMesa = category == Biome.BiomeCategory.MESA; + boolean isPlains = category == Biome.BiomeCategory.PLAINS; + boolean isSavanna = category == Biome.BiomeCategory.SAVANNA; + boolean isIcy = category == Biome.BiomeCategory.ICY; + boolean isBeach = category == Biome.BiomeCategory.BEACH; + boolean isForest = category == Biome.BiomeCategory.FOREST; + boolean isOcean = category == Biome.BiomeCategory.OCEAN; + boolean isDesert = category == Biome.BiomeCategory.DESERT; + boolean isRiver = category == Biome.BiomeCategory.RIVER; + boolean isSwamp = category == Biome.BiomeCategory.SWAMP; + boolean isMushroom = category == Biome.BiomeCategory.MUSHROOM; + + return isTaiga || isExtremeHills || isJungle || isMesa || isPlains || isSavanna || isIcy || isBeach || isForest || isOcean || isDesert || isRiver || isSwamp || isMushroom; + } + + protected static boolean doBiomeCategoryBelongsToNether( Biome.BiomeCategory category ) { + return category == Biome.BiomeCategory.NETHER; + } + + protected static boolean doBiomeCategoryBelongsToTheEnd( Biome.BiomeCategory category ) { + return category == Biome.BiomeCategory.THEEND; + } + + private static void addFreshEntity( MobSpawnSettingsBuilder spawnInfoBuilder, MobCategory classification, EntityType< ? > entityType, int weight, + int minimumCount, int maximumCount + ) { + MobSpawnSettings.SpawnerData spawners = new MobSpawnSettings.SpawnerData( entityType, weight, minimumCount, maximumCount ); + + spawnInfoBuilder.addSpawn( classification, spawners ); + } +} diff --git a/src/main/java/com/majruszsdifficulty/world/WorldGenHelper.java b/src/main/java/com/majruszsdifficulty/world/WorldGenHelper.java new file mode 100644 index 000000000..0087ba777 --- /dev/null +++ b/src/main/java/com/majruszsdifficulty/world/WorldGenHelper.java @@ -0,0 +1,36 @@ +package com.majruszsdifficulty.world; + +import net.minecraft.core.Holder; +import net.minecraft.data.worldgen.placement.PlacementUtils; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; +import net.minecraft.world.level.levelgen.placement.BiomeFilter; +import net.minecraft.world.level.levelgen.placement.CountPlacement; +import net.minecraft.world.level.levelgen.placement.InSquarePlacement; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest; +import net.minecraftforge.registries.RegistryObject; + +import java.util.List; + +public class WorldGenHelper { + public static ConfiguredFeature< ?, ? > getConfigured( Block targetBlock, RegistryObject< ? extends Block > block, int count, + float airExposureDiscardChance + ) { + List< OreConfiguration.TargetBlockState > target = List.of( OreConfiguration.target( new BlockMatchTest( targetBlock ), block.get() + .defaultBlockState() ) ); + return new ConfiguredFeature<>( Feature.ORE, new OreConfiguration( target, count, airExposureDiscardChance ) ); + } + + public static ConfiguredFeature< ?, ? > getEndConfigured( RegistryObject< ? extends Block > block, int count, float airExposureDiscardChance ) { + return getConfigured( Blocks.END_STONE, block, count, airExposureDiscardChance ); + } + + public static PlacedFeature getEndPlaced( RegistryObject< ConfiguredFeature< ?, ? > > configuredFeature, int count ) { + Holder< ConfiguredFeature< ?, ? > > holder = configuredFeature.getHolder().get(); + return new PlacedFeature( holder, List.of( CountPlacement.of( count ), InSquarePlacement.spread(), PlacementUtils.FULL_RANGE, BiomeFilter.biome() ) ); + } +} diff --git a/src/main/resources/data/majruszsdifficulty/forge/biome_modifier/end_ores_modifier.json b/src/main/resources/data/majruszsdifficulty/forge/biome_modifier/end_ores_modifier.json deleted file mode 100644 index f4709b9f2..000000000 --- a/src/main/resources/data/majruszsdifficulty/forge/biome_modifier/end_ores_modifier.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "forge:add_features", - "biomes": "#minecraft:is_end", - "features": ["majruszsdifficulty:enderium_ore_small_placed", "majruszsdifficulty:enderium_ore_large_placed", "majruszsdifficulty:infested_end_stone_placed"], - "step": "underground_ores" -} \ No newline at end of file diff --git a/src/main/resources/data/majruszsdifficulty/forge/biome_modifier/overworld_mobs_modifier.json b/src/main/resources/data/majruszsdifficulty/forge/biome_modifier/overworld_mobs_modifier.json deleted file mode 100644 index e573a8094..000000000 --- a/src/main/resources/data/majruszsdifficulty/forge/biome_modifier/overworld_mobs_modifier.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "type": "forge:add_spawns", - "biomes": "#minecraft:is_overworld", - "spawners": [ - { - "type": "minecraft:illusioner", - "weight": 20, - "minCount": 1, - "maxCount": 1 - }, - { - "type": "majruszsdifficulty:tank", - "weight": 3, - "minCount": 1, - "maxCount": 1 - } - ] -} \ No newline at end of file