- **New: A mob can search a path before it walks it: `MobEntity:findPath`, `MobPath` and `MobEntity:startPathAlong`**
- `mob:findPath(target, options)` searches the path `startPathTo` would start on and returns it as a `MobPath`, without moving the mob. It returns `nil` if there is no path at all.
- A `MobPath` has the read-only fields `length`, `nodes`, `reachable` and `target`. So a spell can compare the ways to two targets, or see where a way leads, before the mob takes a step.
- Given a list of positions, `findPath` searches a path that comes by each of them in order: a patrol, or a way around a place the mob should avoid.
- `mob:startPathAlong(path, options)` starts a task that moves the mob along that path and no other. It doesn't search again: if the mob is held up, the task fails with `"unreachable"`. It doesn't start if the mob isn't on the path (`"off_path"`).
```lua
local a, b = villager:findPath(well), villager:findPath(farm)
local path = a
if not (a and a.reachable) or (b and b.reachable and b.length < a.length) then
path = b
end
if path and path.reachable then
villager:startPathAlong(path)
villager:awaitTask()
end
```
- **New: Hide aspects of a living entity from the players: `LivingEntity:setHidden` and `isHidden`**
- `entity:setHidden(aspect, hidden)` hides one aspect, or a list of them, and `entity:isHidden(aspect)` tells whether one is hidden.
- The aspects are `"equipment"` (what the entity holds and wears), `"arrows"` (the arrows and bee stingers that stick in it), `"effectParticles"`, `"stepParticles"` (the dust of sprinting and landing) and `"stepSounds"`.
- Together with `invisible`, which hides the body only, nothing gives an entity away any more.
- The entity itself is not changed: it keeps its items and its effects. The settings are not saved. A player keeps them through death and respawn, and loses them at logout.
```lua
local player = spell.owner
player.invisible = true
player:setHidden({ "equipment", "arrows", "effectParticles", "stepParticles", "stepSounds" }, true)
```
- **New: A player can wear another player's skin: `Player:setSkin` and `Player.skin`**
- `player:setSkin(name, timeout)` puts on the skin of the player account with that name, also in the middle of a game. The player keeps their own name and UUID. All players see the new skin at once.
- The skin is looked up at Mojang, which needs internet access. The function waits for it, usually less than a second, and returns `true`, or `false` and the reason: `"not_found"`, `"unavailable"`, `"offline"`, `"replaced"` or `"timeout"`.
- `player:setSkin(nil)` gives the player their own skin back. The read-only `player.skin` is the name of the player whose skin they wear.
- The skin stays on through death and respawn, and is gone when the player logs out.
```lua
local ok, reason = spell.owner:setSkin("jeb_")
if not ok then
print("No skin: " .. reason)
end
```
- **New: `Player.online`**
- The read-only `player.online` tells whether the player is still on the server. It is `false` once the player has left or was kicked; a dead player is still online.
- **Change: A reference to a player follows the player through respawn**
- A variable that holds a player, and `spell.owner`, now refer to the respawned player after a death. Before, they kept referring to the dead one, whose position and health no longer changed.
- In an `AfterPlayerRespawnEvent`, `spell.owner` therefore equals `event.newPlayer`, no longer `event.oldPlayer`.
- A reference doesn't follow a player through logout: a player who logs in again is a new player, and an old reference stays offline, as `player.online` tells.
- **Change: `MobEntity:startPathTo` reaches targets beyond its search range**
- A path search looks `searchRange` blocks ahead, so a path to a distant target, or along a long, winding way, may end short of it. The mob now searches again from where such a path ends, as long as that gets it nearer the target. Before, the mob went no further than the end of that first path.
- `task.reachable` is `false` while the current path stops short of the target; the mob may still get there.
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" }