diff --git a/build.gradle b/build.gradle index 96ae7a7f9..d7cd8593f 100644 --- a/build.gradle +++ b/build.gradle @@ -114,6 +114,8 @@ dependencies { compileOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${patchouli_version}") + + implementation fg.deobf("teamtwilight:twilightforest:${twilight_forest_version}:universal") } tasks.withType(JavaCompile).configureEach { diff --git a/gradle.properties b/gradle.properties index d308a3906..05b3d32bd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,8 @@ org.gradle.jvmargs=-Xmx4G org.gradle.daemon=false -mod_version=1.1.0-hotfix +mod_version=1.1.1 forge_version=1.19.2-43.2.0 mc_version=1.19.2 jei_version=11.4.0.286 -patchouli_version=1.19.2-76 \ No newline at end of file +patchouli_version=1.19.2-76 +twilight_forest_version=4.2.1518 \ No newline at end of file diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/config/subconfig/MiscConfig.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/config/subconfig/MiscConfig.java index c5697a8b4..d7806b5aa 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/config/subconfig/MiscConfig.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/config/subconfig/MiscConfig.java @@ -1,7 +1,13 @@ package com.github.tartaricacid.touhoulittlemaid.config.subconfig; +import com.google.common.collect.Lists; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biomes; import net.minecraftforge.common.ForgeConfigSpec; +import java.util.List; + public final class MiscConfig { public static ForgeConfigSpec.DoubleValue MAID_FAIRY_POWER_POINT; public static ForgeConfigSpec.IntValue MAID_FAIRY_SPAWN_PROBABILITY; @@ -10,6 +16,8 @@ public final class MiscConfig { public static ForgeConfigSpec.DoubleValue SHRINE_LAMP_EFFECT_COST; public static ForgeConfigSpec.DoubleValue SHRINE_LAMP_MAX_STORAGE; public static ForgeConfigSpec.IntValue SHRINE_LAMP_MAX_RANGE; + public static ForgeConfigSpec.ConfigValue> MAID_FAIRY_BLACKLIST_BIOME; + public static ForgeConfigSpec.ConfigValue> MAID_FAIRY_BLACKLIST_DIMENSION; public static void init(ForgeConfigSpec.Builder builder) { builder.push("misc"); @@ -20,6 +28,16 @@ public static void init(ForgeConfigSpec.Builder builder) { builder.comment("Maid fairy's spawn probability (zombie is 100, enderman is 10)"); MAID_FAIRY_SPAWN_PROBABILITY = builder.defineInRange("MaidFairySpawnProbability", 70, 0, Integer.MAX_VALUE); + builder.comment("The following biome do not spawn maid fairy"); + MAID_FAIRY_BLACKLIST_BIOME = builder.defineList("MaidFairyBlacklistBiome", + Lists.newArrayList(Biomes.THE_VOID.location().toString(), + Biomes.MUSHROOM_FIELDS.location().toString()), MiscConfig::checkId); + + builder.comment("The following dimension do not spawn maid fairy"); + MAID_FAIRY_BLACKLIST_DIMENSION = builder.defineList("MaidFairyBlacklistDimension", + Lists.newArrayList(Level.NETHER.location().toString(), Level.END.location().toString(), + "twilightforest:twilight_forest"), MiscConfig::checkId); + builder.comment("Loss power point after player death"); PLAYER_DEATH_LOSS_POWER_POINT = builder.defineInRange("PlayerDeathLossPowerPoint", 1.0, 0, 5); @@ -37,4 +55,11 @@ public static void init(ForgeConfigSpec.Builder builder) { builder.pop(); } + + private static boolean checkId(Object o) { + if (o instanceof String name) { + return ResourceLocation.isValidResourceLocation(name); + } + return false; + } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/registry/MobSpawnInfoRegistry.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/registry/MobSpawnInfoRegistry.java index b9d2c0a6b..4a4bb08c3 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/registry/MobSpawnInfoRegistry.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/init/registry/MobSpawnInfoRegistry.java @@ -3,31 +3,41 @@ import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MiscConfig; import com.github.tartaricacid.touhoulittlemaid.init.InitEntities; import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraftforge.event.level.LevelEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import static com.github.tartaricacid.touhoulittlemaid.config.subconfig.MiscConfig.MAID_FAIRY_BLACKLIST_BIOME; +import static com.github.tartaricacid.touhoulittlemaid.config.subconfig.MiscConfig.MAID_FAIRY_BLACKLIST_DIMENSION; + @Mod.EventBusSubscriber public final class MobSpawnInfoRegistry { private static MobSpawnSettings.SpawnerData SPAWNER_DATA; @SubscribeEvent public static void addMobSpawnInfo(LevelEvent.PotentialSpawns event) { - Holder biome = event.getLevel().getBiome(event.getPos()); - if (biomeIsOkay(biome) && event.getMobCategory() == MobCategory.MONSTER) { - if (SPAWNER_DATA == null) { - SPAWNER_DATA = new MobSpawnSettings.SpawnerData(InitEntities.FAIRY.get(), MiscConfig.MAID_FAIRY_SPAWN_PROBABILITY.get(), 2, 6); + if (event.getLevel() instanceof Level level) { + ResourceLocation dimensionId = level.dimension().location(); + Holder biome = level.getBiome(event.getPos()); + if (dimensionIsOkay(dimensionId) && biomeIsOkay(biome) && event.getMobCategory() == MobCategory.MONSTER) { + if (SPAWNER_DATA == null) { + SPAWNER_DATA = new MobSpawnSettings.SpawnerData(InitEntities.FAIRY.get(), MiscConfig.MAID_FAIRY_SPAWN_PROBABILITY.get(), 2, 6); + } + event.addSpawnerData(SPAWNER_DATA); } - event.addSpawnerData(SPAWNER_DATA); } } + private static boolean dimensionIsOkay(ResourceLocation id) { + return !MAID_FAIRY_BLACKLIST_DIMENSION.get().contains(id.toString()); + } + private static boolean biomeIsOkay(Holder biome) { - // TODO: 2021/10/17 添加配置文件,管控可生成的生物群系 - return !biome.is(Biomes.NETHER_WASTES) && !biome.is(Biomes.THE_END) && !biome.is(Biomes.THE_VOID) && !biome.is(Biomes.MUSHROOM_FIELDS); + return MAID_FAIRY_BLACKLIST_BIOME.get().stream().noneMatch(name -> biome.is(new ResourceLocation(name))); } }