- **New: Ask whether an entity sees another one: `LivingEntity:canSee`**
- `entity:canSee(other)` tells whether no block is in the line of sight from the entity's eyes to the other entity's eyes, the way the game decides whether a mob sees its target.
- Only blocks are in the way, not other entities, and which way the entity looks doesn't count: it also "sees" what is behind it.
- It is always `false` for an entity in another world, or more than 128 blocks away.
- `entity:canSee(other, range)` shortens how far the entity sees, in blocks from eyes to eyes: a short-sighted guard, or a mob that notices a player only close by. 128 blocks remain the most: a larger `range` changes nothing.
```lua
local zombie = spell:summon("zombie") --[[@as LivingEntity]]
if zombie:canSee(spell.owner) then
print("The zombie sees you.")
end
if zombie:canSee(spell.owner, 8) then
print("The zombie sees you from close by.")
end
```
- **New: Read and set a player's hunger: `Player.foodLevel` and `Player.saturation`**
- `player.foodLevel` is the food level, an integer from 0 to 20. See [Hunger](https://minecraft.wiki/w/Food#Hunger).
- `player.saturation` is the saturation, from 0 up to the food level: a larger value is cut down to it. See [Saturation](https://minecraft.wiki/w/Food#Saturation).
- Both can be assigned, for example to start a round with every player fed.
```lua
for _, player in ipairs(spell:findEntities("@a")) do
---@cast player Player
player.foodLevel = 20
player.saturation = 5
end
```
- **New: Read the game's difficulty: `Server.difficulty`**
- `spell.server.difficulty` is "peaceful", "easy", "normal" or "hard". All worlds of the server share it, and a hardcore world is always "hard".
- It is read-only: change it with the command `/difficulty`.
```lua
if spell.server.difficulty == "hard" then
print("Skeletons shoot twice as often.")
end
```
- **New: Turn the spell to a position: `Spell:lookAt`**
- `spell:lookAt(pos)` sets the spell's `yaw` and `pitch` so that it looks at the position. A raycast from the spell then leads there.
- Looking straight up or down, the spell keeps its yaw.
```lua
spell:lookAt(spell.owner.eyePos)
local hit = spell:raycastBlock(20)
print(hit and "A block is in the way." or "Nothing between us.")
```
- **Change: A mob that follows or chases searches wider before it gives up at a dead end**
- A mob with `startFollow`, or one that chases with `startAttack`, walked to where its path ended, at the foot of a cliff or at a wall, and its task failed there with "unreachable", although a way led around: the way was longer than `searchRange`.
- Now the mob searches again from such a dead end, up to 4 times as far as `searchRange`. Only when that search finds no way either, the task fails with "unreachable", as before.
- A mob that used to stop at a wall with a long way around it now takes that way.
- **Fix: `PlayerInventory` accepts additional properties, like every other object**
- `player.inventory.myNote = "..."` raised "attempt to modify unknown table index". Now a spell can keep its own values on an inventory, as it can on a player or an item.
- **Fix: `LivingEntity.hostile` is `true` for every enemy mob**
- It was `false` for the slime, magma cube, ghast, phantom, shulker, hoglin and ender dragon. A spell that picks its targets by `hostile` now finds these seven, too.
- Nothing else changes: neutral mobs like the wolf, the bee and the iron golem are still not hostile, and the enderman, the piglin and the zombified piglin still are.
Developer information
Projects on Modrinth are automatically available through a Maven repository for use with JVM build tools such as Gradle.
maven { name = "Modrinth"; url = "https://api.modrinth.com/maven" }