What Animals Eat lets modpack authors customize animal breeding foods and player-held attractants through simple, readable JSON configuration files.
what_animals_eat_food.json.what_animals_eat_attractant.json./reload.Food configuration:
config/what_animals_eat_food.json
Attractant configuration:
config/what_animals_eat_attractant.json
Example:
{
"minecraft:cow": [
"minecraft:apple",
"minecraft:golden_carrot"
],
"minecraft:chicken": [
"#minecraft:seeds"
],
"*": [
"minecraft:beetroot"
]
}
Each key is an entity ID and each value is an array of item IDs. Use * to define a rule for all supported animals. Use #tag_id to reference an item tag.
Food rules replace an animal's default breeding foods. Attractant rules define which items held by a player make the animal follow them.
Run /reload after editing either JSON file to apply the changes without restarting the server.
When the server starts, the mod scans registered animal entities and detects their default breeding foods and attractants.
If a newly installed mod adds an animal with detectable default rules, its entity ID is automatically appended to the appropriate JSON file with the detected defaults. Existing entity entries and custom item lists are never overwritten.
The old what_animals_eat.json and what_animals_eat-common.toml files are migrated to what_animals_eat_food.json when possible.
Place scripts in the server_scripts folder.
// Change the breeding foods for every cow.
WhatAnimalsEat.setBreedingFoods(
'minecraft:cow',
['minecraft:apple', 'minecraft:golden_carrot']
)
// Add beetroot as an additional breeding food for every pig.
WhatAnimalsEat.addBreedingFood(
'minecraft:pig',
'minecraft:beetroot'
)
// Change the items that attract every cow.
WhatAnimalsEat.setAttractant(
'minecraft:cow',
['minecraft:apple', 'minecraft:golden_carrot']
)
// Add beetroot as an attractant for every pig.
WhatAnimalsEat.addAttractant(
'minecraft:pig',
'minecraft:beetroot'
)
Passing event.animal changes only the individual entity that was fed. The override is stored in the entity's persistent NBT and survives world saves and server restarts.
WhatAnimalsEatEvents.afterAnimalFed(event => {
console.log(
event.player.name +
' fed ' +
event.animal.id +
' with ' +
event.item.id
)
// Only this individual animal is changed.
WhatAnimalsEat.setBreedingFoods(
event.animal,
['minecraft:apple', 'minecraft:golden_carrot']
)
// Only this individual animal is attracted by beetroot.
WhatAnimalsEat.setAttractant(
event.animal,
['minecraft:beetroot']
)
})
Passing an entity ID string changes all entities of that type. Passing an animal entity object changes only that individual entity.
WhatAnimalsEatEvents.beforeAnimalFed(event => {
console.log(
'Player ' + event.player.name +
' is feeding ' + event.animal.id +
' with ' + event.item.id
)
// Cancel the feeding operation when necessary.
// event.cancel()
})
WhatAnimalsEatEvents.afterAnimalFed(event => {
console.log(
'Player ' + event.player.name +
' fed ' + event.animal.id +
' with ' + event.item.id
)
})
The feeding event provides:
event.player: the player feeding the entity.event.animal: the animal being fed.event.item: the item being used.// Remove one breeding food from every pig.
WhatAnimalsEat.removeBreedingFood(
'minecraft:pig',
'minecraft:carrot'
)
// Reset an individual breeding-food override.
WhatAnimalsEat.resetBreedingFoods(event.animal)
// Reset an individual attractant override.
WhatAnimalsEat.resetAttractant(event.animal)
// Read the currently effective rules.
console.log(WhatAnimalsEat.getBreedingFoods('minecraft:cow'))
console.log(WhatAnimalsEat.getAttractants('minecraft:cow'))
KubeJS changes are applied immediately on the current server. Individual entity overrides are stored in persistent entity NBT, while JSON files contain the default rules for entity types.