Skip to content

Commit

Permalink
Move baby biome and structure spawn blacklist to tags (syntax using m…
Browse files Browse the repository at this point in the history
…ekanismadditions:blacklist_baby_creepers and the like). Also moved the wind generator's dimension blacklist to a dimension type tag c:no_wind and fixed wind generator item rendering bugging out when in a blacklisted dimension
  • Loading branch information
pupnewfster committed Aug 23, 2024
1 parent a11d886 commit caae13f
Show file tree
Hide file tree
Showing 28 changed files with 201 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
import mekanism.common.config.value.CachedDoubleValue;
import mekanism.common.config.value.CachedFloatValue;
import mekanism.common.config.value.CachedIntValue;
import mekanism.common.config.value.CachedResourceLocationListValue;
import net.minecraft.SharedConstants;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.biome.MobSpawnSettings;
Expand Down Expand Up @@ -105,8 +102,6 @@ public static class SpawnConfig {
public final CachedDoubleValue weightPercentage;
public final CachedDoubleValue spawnCostPerEntityPercentage;
public final CachedDoubleValue maxSpawnCostPercentage;
public final CachedResourceLocationListValue biomeBlackList;
public final CachedResourceLocationListValue structureBlackList;
public final Holder<EntityType<?>> entityType;
public final EntityType<?> parentType;

Expand Down Expand Up @@ -134,10 +129,6 @@ private SpawnConfig(IMekanismConfig config, ModConfigSpec.Builder builder, Strin
this.maxSpawnCostPercentage = CachedDoubleValue.wrap(config, translations.maxCost().applyToBuilder(builder)
.worldRestart()
.defineInRange("maxSpawnCostPercentage", 1D, 0, 100));
this.biomeBlackList = CachedResourceLocationListValue.define(config, translations.biomeBlacklist().applyToBuilder(builder)
.worldRestart(), "biomeBlackList", ResourceLocation.withDefaultNamespace("plains"));
this.structureBlackList = CachedResourceLocationListValue.define(config, translations.structureBlacklist().applyToBuilder(builder)
.worldRestart(), "structureBlackList", ResourceLocation.withDefaultNamespace("fortress"), BuiltInRegistries.STRUCTURE_TYPE::containsKey);
builder.pop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ public record BabySpawnTranslations(
IConfigTranslation maxSize,
IConfigTranslation weight,
IConfigTranslation costPerEntity,
IConfigTranslation maxCost,
IConfigTranslation biomeBlacklist,
IConfigTranslation structureBlacklist
IConfigTranslation maxCost
) {

public IConfigTranslation[] toArray() {
return new IConfigTranslation[]{topLevel, shouldSpawn, minSize, maxSize, weight, costPerEntity, maxCost, biomeBlacklist, structureBlacklist};
return new IConfigTranslation[]{topLevel, shouldSpawn, minSize, maxSize, weight, costPerEntity, maxCost};
}

private static String getKey(String name, String path) {
Expand All @@ -98,15 +96,7 @@ public static BabySpawnTranslations create(String key) {
new ConfigTranslation(getKey(key, "max_size"), "Max Group Size", "The multiplier for maximum group size of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(key, "weight"), "Weight Multiplier", "The multiplier for weight of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(key, "cost_per_entity"), "Cost Per Entity Multiplier", "The multiplier for spawn cost per entity of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(key, "max_cost"), "Max Cost Multiplier", "The multiplier for max spawn cost of " + name + " spawns, compared to the adult mob."),
new ConfigTranslation(getKey(key, "biome_blacklist"),
"Biome Blacklist", "The list of biome ids that " + name + " will not spawn in even if the normal mob variant can spawn.",
"Edit Blacklist"
),
new ConfigTranslation(getKey(key, "structure_blacklist"), "Structure Blacklist",
"The list of structure ids that " + name + " will not spawn in even if the normal mob variant can spawn.",
"Edit Blacklist"
)
new ConfigTranslation(getKey(key, "max_cost"), "Max Cost Multiplier", "The multiplier for max spawn cost of " + name + " spawns, compared to the adult mob.")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@

import com.mojang.serialization.Codec;
import java.util.Locale;
import mekanism.api.MekanismAPITags;
import net.minecraft.tags.TagKey;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.structure.Structure;
import org.jetbrains.annotations.NotNull;

public enum BabyType implements StringRepresentable {
BOGGED,
CREEPER,
ENDERMAN,
SKELETON,
STRAY,
WITHER_SKELETON;
BOGGED(MekanismAPITags.Biomes.BLACKLIST_BABY_BOGGED, MekanismAPITags.Structures.BLACKLIST_BABY_BOGGED),
CREEPER(MekanismAPITags.Biomes.BLACKLIST_BABY_CREEPERS, MekanismAPITags.Structures.BLACKLIST_BABY_CREEPERS),
ENDERMAN(MekanismAPITags.Biomes.BLACKLIST_BABY_ENDERMEN, MekanismAPITags.Structures.BLACKLIST_BABY_ENDERMEN),
SKELETON(MekanismAPITags.Biomes.BLACKLIST_BABY_SKELETONS, MekanismAPITags.Structures.BLACKLIST_BABY_SKELETONS),
STRAY(MekanismAPITags.Biomes.BLACKLIST_BABY_STRAYS, MekanismAPITags.Structures.BLACKLIST_BABY_STRAYS),
WITHER_SKELETON(MekanismAPITags.Biomes.BLACKLIST_BABY_WITHER_SKELETONS, MekanismAPITags.Structures.BLACKLIST_BABY_WITHER_SKELETONS);

public static final Codec<BabyType> CODEC = StringRepresentable.fromEnum(BabyType::values);

public final TagKey<Structure> structureBlacklist;
public final TagKey<Biome> biomeBlacklist;
private final String serializedName;

BabyType() {
BabyType(TagKey<Biome> biomeBlacklist, TagKey<Structure> structureBlacklist) {
this.serializedName = name().toLowerCase(Locale.ROOT);
this.biomeBlacklist = biomeBlacklist;
this.structureBlacklist = structureBlacklist;

}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import mekanism.common.Mekanism;
import mekanism.common.util.RegistryUtils;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.neoforged.neoforge.common.world.BiomeModifier;
import net.neoforged.neoforge.common.world.MobSpawnSettingsBuilder;
import net.neoforged.neoforge.common.world.ModifiableBiomeInfo.BiomeInfo;
import net.neoforged.neoforge.server.ServerLifecycleHooks;

public record BabyEntitySpawnBiomeModifier(BabyType babyType, AdditionsConfig.SpawnConfig spawnConfig) implements BiomeModifier {

Expand All @@ -32,22 +30,21 @@ public void modify(Holder<Biome> biome, Phase phase, BiomeInfo.Builder builder)
if (phase == Phase.REMOVE && spawnConfig.shouldSpawn.get()) {
//Note: We need to run after addition in case we ran after any mods added their skeletons,
// but we run before after everything to make it easier for another mod to remove us
ResourceLocation biomeName = ServerLifecycleHooks.getCurrentServer().registryAccess().registryOrThrow(Registries.BIOME).getKey(biome.value());
if (!spawnConfig.biomeBlackList.get().contains(biomeName)) {
if (!biome.is(babyType.biomeBlacklist)) {
MobSpawnSettingsBuilder mobSpawnSettings = builder.getMobSpawnSettings();
List<MobSpawnSettings.SpawnerData> monsterSpawns = mobSpawnSettings.getSpawner(MobCategory.MONSTER);
for (MobSpawnSettings.SpawnerData spawner : spawnConfig.getSpawnersToAdd(monsterSpawns)) {
mobSpawnSettings.addSpawn(MobCategory.MONSTER, spawner);
MobSpawnSettings.MobSpawnCost parentCost = mobSpawnSettings.getCost(spawnConfig.parentType);
if (parentCost == null) {
Mekanism.logger.debug("Adding spawn rate for '{}' in biome '{}', with weight: {}, minSize: {}, maxSize: {}",
RegistryUtils.getName(spawner.type), biomeName, spawner.getWeight(), spawner.minCount, spawner.maxCount);
RegistryUtils.getName(spawner.type), biome.unwrapKey().map(ResourceKey::location).orElse(null), spawner.getWeight(), spawner.minCount, spawner.maxCount);
} else {
double spawnCostPerEntity = parentCost.charge() * spawnConfig.spawnCostPerEntityPercentage.get();
double maxSpawnCost = parentCost.energyBudget() * spawnConfig.maxSpawnCostPercentage.get();
mobSpawnSettings.addMobCharge(spawner.type, spawnCostPerEntity, maxSpawnCost);
Mekanism.logger.debug("Adding spawn rate for '{}' in biome '{}', with weight: {}, minSize: {}, maxSize: {}, spawnCostPerEntity: {}, maxSpawnCost: {}",
RegistryUtils.getName(spawner.type), biomeName, spawner.getWeight(), spawner.minCount, spawner.maxCount, spawnCostPerEntity, maxSpawnCost);
RegistryUtils.getName(spawner.type), biome.unwrapKey().map(ResourceKey::location).orElse(null), spawner.getWeight(), spawner.minCount, spawner.maxCount, spawnCostPerEntity, maxSpawnCost);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import mekanism.common.Mekanism;
import mekanism.common.util.RegistryUtils;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.levelgen.structure.Structure;
Expand All @@ -34,12 +33,12 @@ public void modify(Holder<Structure> structure, Phase phase, StructureInfo.Build
StructureSettingsBuilder structureSettings = builder.getStructureSettings();
StructureSpawnOverrideBuilder spawnOverrides = structureSettings.getSpawnOverrides(MobCategory.MONSTER);
//Fail quick if there are no overrides for this structure, or it is blacklisted
ResourceLocation structureName = BuiltInRegistries.STRUCTURE_TYPE.getKey(structure.value().type());
if (spawnOverrides != null && !spawnConfig.structureBlackList.get().contains(structureName)) {
if (spawnOverrides != null && !structure.is(babyType.structureBlacklist)) {
for (MobSpawnSettings.SpawnerData spawner : spawnConfig.getSpawnersToAdd(spawnOverrides.getSpawns())) {
spawnOverrides.addSpawn(spawner);
Mekanism.logger.debug("Adding spawn rate for '{}' in structure '{}', with weight: {}, minSize: {}, maxSize: {}",
RegistryUtils.getName(spawner.type), structureName, spawner.getWeight(), spawner.minCount, spawner.maxCount);
RegistryUtils.getName(spawner.type), structure.unwrapKey().map(ResourceKey::location).orElse(null), spawner.getWeight(),
spawner.minCount, spawner.maxCount);
}
}
}
Expand Down
160 changes: 130 additions & 30 deletions src/api/java/mekanism/api/MekanismAPITags.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.levelgen.structure.Structure;

/**
* Provides access to pre-existing tag keys for various functionality that we use tags for.
Expand All @@ -27,6 +30,44 @@ private static ResourceLocation rl(String path) {
return ResourceLocation.fromNamespaceAndPath(MekanismAPI.MEKANISM_MODID, path);
}

/**
* @since 10.6.4
*/
public static class Biomes {

private Biomes() {
}

/**
* Represents any biomes that baby bogged should not spawn in, even if normal bogged do.
*/
public static final TagKey<Biome> BLACKLIST_BABY_BOGGED = additionsTag("blacklist_baby_bogged");
/**
* Represents any biomes that baby creepers should not spawn in, even if normal creepers do.
*/
public static final TagKey<Biome> BLACKLIST_BABY_CREEPERS = additionsTag("blacklist_baby_creepers");
/**
* Represents any biomes that baby endermen should not spawn in, even if normal endermen do.
*/
public static final TagKey<Biome> BLACKLIST_BABY_ENDERMEN = additionsTag("blacklist_baby_endermen");
/**
* Represents any biomes that baby skeletons should not spawn in, even if normal skeletons do.
*/
public static final TagKey<Biome> BLACKLIST_BABY_SKELETONS = additionsTag("blacklist_baby_skeletons");
/**
* Represents any biomes that baby strays should not spawn in, even if normal strays do.
*/
public static final TagKey<Biome> BLACKLIST_BABY_STRAYS = additionsTag("blacklist_baby_strays");
/**
* Represents any biomes that baby wither skeletons should not spawn in, even if normal wither skeletons do.
*/
public static final TagKey<Biome> BLACKLIST_BABY_WITHER_SKELETONS = additionsTag("blacklist_baby_wither_skeletons");

private static TagKey<Biome> additionsTag(String name) {
return TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath("mekanismadditions", name));
}
}

/**
* @since 10.7.0
*/
Expand Down Expand Up @@ -98,6 +139,71 @@ private static TagKey<Chemical> tag(String name) {
}
}

public static class DamageTypes {

private DamageTypes() {
}

/**
* Represents any damage type that is always supported by the MekaSuit.
*/
public static final TagKey<DamageType> MEKASUIT_ALWAYS_SUPPORTED = tag("mekasuit_always_supported");
/**
* Represents any type of damage that can be prevented by the Scuba Mask or the Inhalation Purification Unit.
*/
public static final TagKey<DamageType> IS_PREVENTABLE_MAGIC = tag("is_preventable_magic");

private static TagKey<DamageType> tag(String name) {
return TagKey.create(Registries.DAMAGE_TYPE, rl(name));
}
}

/**
* @since 10.6.4
*/
public static class DimensionTypes {

private DimensionTypes() {
}

/**
* Represents any dimension without wind.
*
* @apiNote This is used by Mekanism to determine what dimensions a wind generator can function in.
*/
public static final TagKey<DimensionType> NO_WIND = commonTag("no_wind");

private static TagKey<DimensionType> commonTag(String name) {
return TagKey.create(Registries.DIMENSION_TYPE, ResourceLocation.fromNamespaceAndPath("c", name));
}
}

/**
* @since 10.6.3
*/
public static class Entities {

private Entities() {
}

/**
* Represents any entity type that is immune to all Radiation.
*/
public static final TagKey<EntityType<?>> RADIATION_IMMUNE = commonTag("radiation_immune");
/**
* Represents any entity type that is immune to Mekanism Radiation.
*/
public static final TagKey<EntityType<?>> MEK_RADIATION_IMMUNE = tag("radiation_immune");

private static TagKey<EntityType<?>> commonTag(String name) {
return TagKey.create(Registries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath("c", name));
}

private static TagKey<EntityType<?>> tag(String name) {
return TagKey.create(Registries.ENTITY_TYPE, rl(name));
}
}

/**
* @since 10.7.0
*/
Expand Down Expand Up @@ -131,48 +237,42 @@ private static TagKey<MobEffect> tag(String name) {
}
}

public static class DamageTypes {

private DamageTypes() {
/**
* @since 10.6.4
*/
public static class Structures {

private Structures() {
}

/**
* Represents any damage type that is always supported by the MekaSuit.
* Represents any structure that baby bogged should not spawn in, even if normal bogged do.
*/
public static final TagKey<DamageType> MEKASUIT_ALWAYS_SUPPORTED = tag("mekasuit_always_supported");
public static final TagKey<Structure> BLACKLIST_BABY_BOGGED = additionsTag("blacklist_baby_bogged");
/**
* Represents any type of damage that can be prevented by the Scuba Mask or the Inhalation Purification Unit.
* Represents any structure that baby creepers should not spawn in, even if normal creepers do.
*/
public static final TagKey<DamageType> IS_PREVENTABLE_MAGIC = tag("is_preventable_magic");

private static TagKey<DamageType> tag(String name) {
return TagKey.create(Registries.DAMAGE_TYPE, rl(name));
}
}

/**
* @since 10.6.3
*/
public static class Entities {

private Entities() {
}

public static final TagKey<Structure> BLACKLIST_BABY_CREEPERS = additionsTag("blacklist_baby_creepers");
/**
* Represents any entity type that is immune to all Radiation.
* Represents any structure that baby endermen should not spawn in, even if normal endermen do.
*/
public static final TagKey<EntityType<?>> RADIATION_IMMUNE = commonTag("radiation_immune");
public static final TagKey<Structure> BLACKLIST_BABY_ENDERMEN = additionsTag("blacklist_baby_endermen");
/**
* Represents any entity type that is immune to Mekanism Radiation.
* Represents any structure that baby skeletons should not spawn in, even if normal skeletons do.
*/
public static final TagKey<EntityType<?>> MEK_RADIATION_IMMUNE = tag("radiation_immune");

private static TagKey<EntityType<?>> commonTag(String name) {
return TagKey.create(Registries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath("c", name));
}
public static final TagKey<Structure> BLACKLIST_BABY_SKELETONS = additionsTag("blacklist_baby_skeletons");
/**
* Represents any structure that baby strays should not spawn in, even if normal strays do.
*/
public static final TagKey<Structure> BLACKLIST_BABY_STRAYS = additionsTag("blacklist_baby_strays");
/**
* Represents any structure that baby wither skeletons should not spawn in, even if normal wither skeletons do.
*/
public static final TagKey<Structure> BLACKLIST_BABY_WITHER_SKELETONS = additionsTag("blacklist_baby_wither_skeletons");

private static TagKey<EntityType<?>> tag(String name) {
return TagKey.create(Registries.ENTITY_TYPE, rl(name));
private static TagKey<Structure> additionsTag(String name) {
return TagKey.create(Registries.STRUCTURE, ResourceLocation.fromNamespaceAndPath("mekanismadditions", name));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit caae13f

Please sign in to comment.