Skip to content

VillagerEntityHelper ​

com.jsmacrosce.jsmacros.client.api.helper.world.entity.VillagerEntityHelper

Since1.6.3

A villager helper exposing the villager's profession, type, level and experience.

The trade list is not available from the entity on the client; see MerchantEntityHelper.getTrades() for the client-side source of displayed offers.

js
const villagers = World.getEntities("villager");  
if (villagers !== null) {
 for (const entity of villagers) {
   if (!(entity instanceof EntityHelpers.Villager)) continue;  
   Chat.log(`a level ${entity.getLevel()} ${entity.getProfession()} `
     + `holding ${entity.getExperience()} xp`);  
 }
}

Available in scripts as EntityHelpers.Villager.

Constructors ​

new VillagerEntityHelper ​

new VillagerEntityHelper(Villager e)#
Wraps the supplied villager, retaining the same reference.

Parameters:

  • e: villager to wrap

Methods ​

getLevel ​

getLevel(): intSince1.6.3#
Returns the villager's trading level, clamped by the game to a minimum of one and with five as the maximum. This is distinct from accumulated trading experience, returned by getExperience().
Returns: this villager's trading level, from one to five

getProfession ​

getProfession(): StringSince1.6.3#
Returns the profession's registered name, including its namespace, rather than its translated display name. A villager without a job has the nitwit profession.
Returns: the registry id of this villager's profession

getStyle ​

getStyle(): StringSince1.6.3#
Returns the villager's biome type, which determines its appearance rather than its profession. This is the holder's toString() representation, not a stable registry id; use the biome at the villager's position to identify where it currently stands.
Returns: the holder's own string form for this villager's biome type