A library mod to control mob spawning using skill-based restrictions created in KubeJS scripts. If you've seen Mob Stages in 1.12, then you have a rough idea of what this mod does.
Player Skills | Block Skills | Dimension Skills | Fluid Skills | Item Skills | Mob Skills
This mod leans extensively on Player Skills by creating and consuming the Skill-based Restrictions. Out of the box, it can restrict mob spawning and player-mob interaction (i.e. right-clicking to trade with a villager).
We use the MobSkillEvents.register
server event to register mob restrictions.
Spawn restrictions are then calculated at spawn time based on the players in the entity's despawn range (i.e. 128 blocks for most mobs). If the players match the conditions, the restrictions are applied.
Other restrictions are calculated when the player attempts to interact with the mob. If the player matches the conditions, the restriction is applied.
Restrictions can cascade with other restrictions, so any restrictions which disallow an action will trump any which do allow it. We also expose these methods to indicate what restrictions are in place for when a player meets that condition. By default, no restrictions are set, so be sure to set actual restrictions. See Player Skills documentation for the shared API.
nothing()
- shorthand to apply all "allow" restrictionsspawnable(matchAllInsteadOfAny?: boolean)
- The mob can spawn if any (or all) players in range match the criteriausable()
- Players that meet the condition can interact with the entity (e.g. trade with a villager)
everything()
- shorthand to apply the below "deny" abilitiesunspawnable(matchAllInsteadOfAny?: boolean)
- The mob cannot spawn if any (or all) players in range match the criteriaunusable()
- Players that meet the condition cannot interact with the entity (e.g. trade with a villager)
always()
- Changespanwable
/unspawnable
into an absolute value instead of a conditionfromSpawner(spawner: string)
- Add a spawn type
We have a shortened list of spawn types which we are allowing granular spawn restrictions. We want to keep breeding, spawn eggs, direct summons, and more interaction-based spawns as-is.
natural
- A normal, random spawnspawner
- A nearby mob spawner blockstructure
- A spawn related to a structure (e.g. guardians, wither skeletons)patrol
- Really a subset of "natural" but related to illager patrolschunk
- A natural spawn from when the chunk generates (e.g. villager)
MobSkillEvents.register(event => {
// Always prevent blazes from spawning
event.restrict('minecraft:blaze', is => is.unspawnable().always());
// Prevent all vanilla mobs from spawning
event.restrict('@minecraft', is => is.unspawnable().always());
// Prevent all illagers from spawning
event.restrict('#raiders', is => is.unspawnable().always());
// Prevent all vanilla illager patrols from spawning
event.restrict('minecraft:*', is => is.unspawnable().fromSpawner("patrol").always());
// ALLOW creepers to spawn IF ALL players in range have the `started_quest` skill
event.restrict("minecraft:creeper", is => is.spawnable(true).if(player => player.can("skills:started_quest")));
// ALLOW cows to spawn UNLESS ANY players in range have the `started_quest` skill
event.restrict("minecraft:cow", is => is.spawnable().unless(player => player.can("skills:started_quest")));
// DENY zombies from spawning IF ANY player in range has the `started_quest` skill
event.restrict('minecraft:zombie', is => is.unspawnable().if(player => player.can('skills:started_quest')));
// DENY sheep from spawning UNLESS ALL player in range has the `started_quest` skill
event.restrict('minecraft:sheep', is => is.unspawnable(true).unless(player => player.can('skills:started_quest')));
// Players cannot interact with villagers unless they have `started_quest` skill
event.restrict("minecraft:villager", is => is.unusable().unless(player => player.can("skills:started_quest")));
});
Because of the way we're handling spawn conditions, if you are using an unless
condition, you should not also
manipulate usable
in the same restriction. Just keep the two restrictions separate.
We expose a handful of in-game commands for players and mods:
/mobskills debug
: Toggles debug-level logging for Mob Skills. Requires mod permissions.
Add the following to your build.gradle
. I depend
on Architectury API, KubeJS,
and PlayerSkills, so you'll need those as well.
dependencies {
// Common should always be included
modImplementation "net.impleri:mob-skills-${minecraft_version}:${mobskills_version}"
// Plus forge
modApi "net.impleri:mob-skills-${minecraft_version}-forge:${mobskills_version}"
// Or fabric
modApi "net.impleri:mob-skills-${minecraft_version}-fabric:${mobskills_version}"
}
repositories {
maven {
url = "https://maven.impleri.org/minecraft"
name = "Impleri Mods"
content {
includeGroup "net.impleri"
}
}
}
Want to use this in a modpack? Great! This was designed with modpack developers in mind. No need to ask.