Skip to content

Commit

Permalink
添加女仆妖精生成黑名单
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Sep 27, 2023
1 parent 2619fed commit 956f05c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
patchouli_version=1.19.2-76
twilight_forest_version=4.2.1518
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<List<? extends String>> MAID_FAIRY_BLACKLIST_BIOME;
public static ForgeConfigSpec.ConfigValue<List<? extends String>> MAID_FAIRY_BLACKLIST_DIMENSION;

public static void init(ForgeConfigSpec.Builder builder) {
builder.push("misc");
Expand All @@ -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);

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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> 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> 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)));
}
}

0 comments on commit 956f05c

Please sign in to comment.