[add] mob spawning
This commit is contained in:
@@ -34,6 +34,7 @@ public class DataGenerators {
|
||||
generator.addProvider(event.includeServer(), new ModItemTagProvider(packOutput, lookupProvider, blockTagsProvider.contentsGetter(), existingFileHelper));
|
||||
|
||||
generator.addProvider(event.includeServer(), new ModDataMapProvider(packOutput, lookupProvider));
|
||||
generator.addProvider(event.includeServer(), new ModDatapackProvider(packOutput, lookupProvider));
|
||||
|
||||
|
||||
generator.addProvider(event.includeClient(), new ModItemModelProvider(packOutput, existingFileHelper));
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package ovh.glitchlabs.masterwild.datagen;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.RegistrySetBuilder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider;
|
||||
import net.neoforged.neoforge.registries.NeoForgeRegistries;
|
||||
import ovh.glitchlabs.masterwild.Masterwild;
|
||||
import ovh.glitchlabs.masterwild.worldgen.ModBiomeModifiers;
|
||||
import ovh.glitchlabs.masterwild.worldgen.ModConfiguredFeatures;
|
||||
import ovh.glitchlabs.masterwild.worldgen.ModPlacedFeatures;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ModDatapackProvider extends DatapackBuiltinEntriesProvider {
|
||||
public static final RegistrySetBuilder BUILDER = new RegistrySetBuilder()
|
||||
//.add(Registries.TRIM_MATERIAL, ModTrimMaterials::bootstrap)
|
||||
//.add(Registries.TRIM_PATTERN, ModTrimPatterns::bootstrap)
|
||||
//.add(Registries.ENCHANTMENT, ModEnchantments::bootstrap)
|
||||
.add(Registries.CONFIGURED_FEATURE, ModConfiguredFeatures::bootstrap)
|
||||
.add(Registries.PLACED_FEATURE, ModPlacedFeatures::bootstrap)
|
||||
.add(NeoForgeRegistries.Keys.BIOME_MODIFIERS, ModBiomeModifiers::bootstrap);
|
||||
|
||||
public ModDatapackProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
super(output, registries, BUILDER, Set.of(Masterwild.MODID));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package ovh.glitchlabs.masterwild.event;
|
||||
|
||||
import net.minecraft.world.entity.SpawnPlacementType;
|
||||
import net.minecraft.world.entity.SpawnPlacementTypes;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
|
||||
import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent;
|
||||
import net.neoforged.neoforge.event.entity.RegisterSpawnPlacementsEvent;
|
||||
import ovh.glitchlabs.masterwild.Masterwild;
|
||||
import ovh.glitchlabs.masterwild.entity.ModEntities;
|
||||
import ovh.glitchlabs.masterwild.entity.client.Pinguin.PinguinModel;
|
||||
@@ -40,4 +45,10 @@ public class ModEventBusEvents {
|
||||
event.put(ModEntities.RED_PANDA.get(), Red_PandaEntity.createAttributes().build());
|
||||
event.put(ModEntities.RACCOON.get(), RaccoonEntity.createAttributes().build());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
|
||||
event.register(ModEntities.RACCOON.get(), SpawnPlacementTypes.ON_GROUND, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES,
|
||||
Animal::checkAnimalSpawnRules, RegisterSpawnPlacementsEvent.Operation.REPLACE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package ovh.glitchlabs.masterwild.event;
|
||||
|
||||
import net.minecraft.world.entity.SpawnPlacementTypes;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.entity.animal.WaterAnimal;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.event.entity.RegisterSpawnPlacementsEvent;
|
||||
import ovh.glitchlabs.masterwild.Masterwild;
|
||||
import ovh.glitchlabs.masterwild.entity.ModEntities;
|
||||
|
||||
@EventBusSubscriber(modid = Masterwild.MODID)
|
||||
public class ModSpawnPlacements {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerSpawnPlacements(RegisterSpawnPlacementsEvent event) {
|
||||
event.register(ModEntities.RACCOON.get(), SpawnPlacementTypes.ON_GROUND,
|
||||
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, Animal::checkAnimalSpawnRules,
|
||||
RegisterSpawnPlacementsEvent.Operation.OR);
|
||||
event.register(ModEntities.PINGUIN.get(), SpawnPlacementTypes.ON_GROUND,
|
||||
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, Animal::checkAnimalSpawnRules,
|
||||
RegisterSpawnPlacementsEvent.Operation.OR);
|
||||
event.register(ModEntities.ROOSTER.get(), SpawnPlacementTypes.ON_GROUND,
|
||||
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, Animal::checkAnimalSpawnRules,
|
||||
RegisterSpawnPlacementsEvent.Operation.OR);
|
||||
event.register(ModEntities.HEDGEHOG.get(), SpawnPlacementTypes.ON_GROUND,
|
||||
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, Animal::checkAnimalSpawnRules,
|
||||
RegisterSpawnPlacementsEvent.Operation.OR);
|
||||
event.register(ModEntities.RED_PANDA.get(), SpawnPlacementTypes.ON_GROUND,
|
||||
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, Animal::checkAnimalSpawnRules,
|
||||
RegisterSpawnPlacementsEvent.Operation.OR);
|
||||
|
||||
event.register(ModEntities.SHARK.get(), SpawnPlacementTypes.IN_WATER,
|
||||
Heightmap.Types.OCEAN_FLOOR, WaterAnimal::checkSurfaceWaterAnimalSpawnRules,
|
||||
RegisterSpawnPlacementsEvent.Operation.OR);
|
||||
|
||||
event.register(ModEntities.FIREFLY.get(), SpawnPlacementTypes.NO_RESTRICTIONS,
|
||||
Heightmap.Types.MOTION_BLOCKING,
|
||||
(type, level, reason, pos, random) -> level.getLevel().isNight() && level.canSeeSky(pos),
|
||||
RegisterSpawnPlacementsEvent.Operation.OR);
|
||||
event.register(ModEntities.BUTTERFLY.get(), SpawnPlacementTypes.NO_RESTRICTIONS,
|
||||
Heightmap.Types.MOTION_BLOCKING,
|
||||
(type, level, reason, pos, random) -> level.getLevel().isDay() && level.canSeeSky(pos),
|
||||
RegisterSpawnPlacementsEvent.Operation.OR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package ovh.glitchlabs.masterwild.worldgen;
|
||||
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.worldgen.BootstrapContext;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.neoforged.neoforge.common.world.BiomeModifier;
|
||||
import net.neoforged.neoforge.common.world.BiomeModifiers;
|
||||
import net.neoforged.neoforge.registries.NeoForgeRegistries;
|
||||
import ovh.glitchlabs.masterwild.Masterwild;
|
||||
import ovh.glitchlabs.masterwild.entity.ModEntities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ModBiomeModifiers {
|
||||
|
||||
public static final ResourceKey<BiomeModifier> SPAWN_RACCOON = registerKey("spawn_raccoon");
|
||||
public static final ResourceKey<BiomeModifier> SPAWN_PINGUIN = registerKey("spawn_pinguin");
|
||||
public static final ResourceKey<BiomeModifier> SPAWN_FIREFLY = registerKey("spawn_firefly");
|
||||
public static final ResourceKey<BiomeModifier> SPAWN_ROOSTER = registerKey("spawn_rooster");
|
||||
public static final ResourceKey<BiomeModifier> SPAWN_SHARK = registerKey("spawn_shark");
|
||||
public static final ResourceKey<BiomeModifier> SPAWN_HEDGEHOG = registerKey("spawn_hedgehog");
|
||||
public static final ResourceKey<BiomeModifier> SPAWN_RED_PANDA = registerKey("spawn_red_panda");
|
||||
public static final ResourceKey<BiomeModifier> SPAWN_BUTTERFLY = registerKey("spawn_butterfly");
|
||||
|
||||
public static void bootstrap(BootstrapContext<BiomeModifier> context) {
|
||||
var placedFeatures = context.lookup(Registries.PLACED_FEATURE);
|
||||
var biomes = context.lookup(Registries.BIOME);
|
||||
|
||||
|
||||
addSpawn(context, SPAWN_RACCOON,
|
||||
HolderSet.direct(
|
||||
biomes.getOrThrow(Biomes.PLAINS),
|
||||
biomes.getOrThrow(Biomes.FOREST),
|
||||
biomes.getOrThrow(Biomes.BIRCH_FOREST)),
|
||||
ModEntities.RACCOON.get(), 20, 2, 4);
|
||||
|
||||
addSpawn(context, SPAWN_PINGUIN,
|
||||
HolderSet.direct(
|
||||
biomes.getOrThrow(Biomes.SNOWY_PLAINS),
|
||||
biomes.getOrThrow(Biomes.SNOWY_BEACH),
|
||||
biomes.getOrThrow(Biomes.SNOWY_TAIGA),
|
||||
biomes.getOrThrow(Biomes.FROZEN_RIVER),
|
||||
biomes.getOrThrow(Biomes.ICE_SPIKES)),
|
||||
ModEntities.PINGUIN.get(), 10, 2, 4);
|
||||
|
||||
addSpawn(context, SPAWN_FIREFLY,
|
||||
HolderSet.direct(
|
||||
biomes.getOrThrow(Biomes.SWAMP),
|
||||
biomes.getOrThrow(Biomes.MANGROVE_SWAMP),
|
||||
biomes.getOrThrow(Biomes.DARK_FOREST),
|
||||
biomes.getOrThrow(Biomes.FLOWER_FOREST),
|
||||
biomes.getOrThrow(Biomes.FOREST)),
|
||||
ModEntities.FIREFLY.get(), 8, 3, 6);
|
||||
|
||||
addSpawn(context, SPAWN_ROOSTER,
|
||||
HolderSet.direct(
|
||||
biomes.getOrThrow(Biomes.PLAINS),
|
||||
biomes.getOrThrow(Biomes.SUNFLOWER_PLAINS),
|
||||
biomes.getOrThrow(Biomes.MEADOW)),
|
||||
ModEntities.ROOSTER.get(), 10, 2, 3);
|
||||
|
||||
addSpawn(context, SPAWN_SHARK,
|
||||
biomes.getOrThrow(BiomeTags.IS_OCEAN),
|
||||
ModEntities.SHARK.get(), 3, 1, 2);
|
||||
|
||||
addSpawn(context, SPAWN_HEDGEHOG,
|
||||
biomes.getOrThrow(BiomeTags.IS_FOREST),
|
||||
ModEntities.HEDGEHOG.get(), 10, 1, 3);
|
||||
|
||||
addSpawn(context, SPAWN_RED_PANDA,
|
||||
HolderSet.direct(
|
||||
biomes.getOrThrow(Biomes.BAMBOO_JUNGLE),
|
||||
biomes.getOrThrow(Biomes.JUNGLE),
|
||||
biomes.getOrThrow(Biomes.CHERRY_GROVE)),
|
||||
ModEntities.RED_PANDA.get(), 8, 1, 3);
|
||||
|
||||
addSpawn(context, SPAWN_BUTTERFLY,
|
||||
HolderSet.direct(
|
||||
biomes.getOrThrow(Biomes.FLOWER_FOREST),
|
||||
biomes.getOrThrow(Biomes.MEADOW),
|
||||
biomes.getOrThrow(Biomes.SUNFLOWER_PLAINS),
|
||||
biomes.getOrThrow(Biomes.PLAINS),
|
||||
biomes.getOrThrow(Biomes.CHERRY_GROVE)),
|
||||
ModEntities.BUTTERFLY.get(), 10, 3, 6);
|
||||
}
|
||||
|
||||
private static void addSpawn(BootstrapContext<BiomeModifier> context, ResourceKey<BiomeModifier> key,
|
||||
HolderSet<Biome> biomes, EntityType<?> type, int weight, int minCount, int maxCount) {
|
||||
context.register(key, new BiomeModifiers.AddSpawnsBiomeModifier(biomes,
|
||||
List.of(new MobSpawnSettings.SpawnerData(type, weight, minCount, maxCount))));
|
||||
}
|
||||
|
||||
private static ResourceKey<BiomeModifier> registerKey(String name) {
|
||||
return ResourceKey.create(NeoForgeRegistries.Keys.BIOME_MODIFIERS, ResourceLocation.fromNamespaceAndPath(Masterwild.MODID, name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package ovh.glitchlabs.masterwild.worldgen;
|
||||
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.worldgen.BootstrapContext;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||
import ovh.glitchlabs.masterwild.Masterwild;
|
||||
|
||||
public class ModConfiguredFeatures {
|
||||
|
||||
public static void bootstrap(BootstrapContext<ConfiguredFeature<?, ?>> context) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static ResourceKey<ConfiguredFeature<?, ?>> registerKey(String name) {
|
||||
return ResourceKey.create(Registries.CONFIGURED_FEATURE, ResourceLocation.fromNamespaceAndPath(Masterwild.MODID, name));
|
||||
}
|
||||
|
||||
private static <FC extends FeatureConfiguration, F extends Feature<FC>> void register(BootstrapContext<ConfiguredFeature<?, ?>> context,
|
||||
ResourceKey<ConfiguredFeature<?, ?>> key, F feature, FC configuration) {
|
||||
context.register(key, new ConfiguredFeature<>(feature, configuration));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package ovh.glitchlabs.masterwild.worldgen;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.worldgen.BootstrapContext;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
||||
import ovh.glitchlabs.masterwild.Masterwild;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ModPlacedFeatures {
|
||||
|
||||
public static void bootstrap(BootstrapContext<PlacedFeature> context) {
|
||||
var configuredFeatures = context.lookup(Registries.CONFIGURED_FEATURE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static ResourceKey<PlacedFeature> registerKey(String name) {
|
||||
return ResourceKey.create(Registries.PLACED_FEATURE, ResourceLocation.fromNamespaceAndPath(Masterwild.MODID, name));
|
||||
}
|
||||
|
||||
private static void register(BootstrapContext<PlacedFeature> context, ResourceKey<PlacedFeature> key, Holder<ConfiguredFeature<?, ?>> configuration,
|
||||
List<PlacementModifier> modifiers) {
|
||||
context.register(key, new PlacedFeature(configuration, List.copyOf(modifiers)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user