VillagerV2 5.46.0
Extends Animal
Implements Trader
The current villager (Bedrock "minecraft:villager_v2", entities/villager_v2.json): 20 health, 0.6x1.9, movement 0.5 (strolls and panics at 0.6x), flees from zombies, babies scale 0.5. Profession (VARIANT 0-14: unemployed, farmer, fisherman, shepherd, fletcher, librarian, cartographer, cleric, armorer, weaponsmith, toolsmith, butcher, leatherworker, mason, nitwit), biome type (MARK_VARIANT 0-6: plains, desert, jungle, savanna, snow, swamp, taiga; plains by default) and skin (SKIN_ID 0-5). A spawn egg gives a baby 5% of the time, otherwise a random profession.
Village life ("minecraft:dweller", updated every 3-5 seconds of AI time):
- Claims: a villager claims the nearest free bed within 48 blocks; an unemployed adult (not a nitwit) with a bed claims the nearest free job site block within 32 blocks and takes its profession (
JobSites); employed villagers without a job site claim one of their profession. If the job site is broken, a villager that never traded becomes unemployed again; one that traded keeps its profession and looks for another job site. Claims are saved in the NBT, registered in the world's\pocketmine\world\raid\PoiManagerand released on death. - Schedule (
VillagerSchedule): work at the job site (farmers also harvest and replant crops), gather and gossip at the bell, wander, go home and sleep in the claimed bed at night (SLEEPING flag, bed occupied). Babies play. When it rains (or snows) where they are, villagers go home instead. A sleeping villager wakes up when hurt, when its schedule moves on or when a player uses its bed. - Trades restock when the villager arrives at its job site, at most twice a day, if it has a bed (Bedrock).
- Food: villagers pick up bread, carrots, potatoes and beetroots within reach (farmers also wheat, seeds and bone meal) into 8 hidden slots; farmers bake 3 wheat into bread; villagers with a surplus throw half of it to hungry villagers nearby.
- Breeding: an adult with at least 12 food points (bread 4, carrot/potato/beetroot 1), outside its work hours and with a free bed nearby, spends them and becomes willing (in love) for 30 seconds; two willing villagers make a baby, which grows up unemployed in 20 minutes.
- Gossip (
Gossips): curing, trading, hitting and killing villagers change the reputation of the player, which lowers prices (seeTradePrices) and makes iron golems hostile at -100 or less. - Iron golems: when villagers gossip, a village with at least 10 villagers per golem (plus one), 20 beds and 75% of its villagers having worked in the last day summons an iron golem nearby (Bedrock conditions).
Trading: players open the vanilla trading screen (UpdateTradePacket, see TradeInventory); trades come from VillagerTrades, two per level. Trading gives the villager experience (TRADE_XP) and levels it up (TRADE_TIER, up to master) with new trades, and gives the player experience. Players with Hero of the Village pay less.
During a raid villagers run to the beds of the village (HideFromRaidGoal); they celebrate when it is won. Struck by lightning a villager becomes a witch.
Not implemented: trade demand, bone meal fertilizing, librarians inspecting bookshelves, fishermen/shepherd specific work goals, waking up when a bell rings, village migration and the Java panic golem summoning.
Constants
BED_SEARCH_HORIZONTAL
public const BED_SEARCH_HORIZONTAL = 48Range of the bed and job site searches.
BED_SEARCH_VERTICAL
public const BED_SEARCH_VERTICAL = 16BREEDING_FOOD_POINTS
public const BREEDING_FOOD_POINTS = 12Food points spent to become willing to breed (3 bread, or 12 carrots, potatoes or beetroots).
DWELLER_INTERVAL
public const DWELLER_INTERVAL = 60Ticks between two village updates (Bedrock dweller update_interval_base 60 + variant 40).
DWELLER_INTERVAL_VARIANT
public const DWELLER_INTERVAL_VARIANT = 40GOLEM_CHECK_INTERVAL
public const GOLEM_CHECK_INTERVAL = 700GOLEM_DEFEND_RANGE
public const GOLEM_DEFEND_RANGE = 16.0Iron golems within this range help a villager that is hurt (see IronGolem::onVillagerAttacked()).
GOLEM_MIN_BEDS
public const GOLEM_MIN_BEDS = 20GOLEM_VILLAGERS_PER_GOLEM
public const GOLEM_VILLAGERS_PER_GOLEM = 10Iron golem summoning (Bedrock): villagers per golem, beds and share of villagers that worked in the last day.
GOLEM_WORKED_RATIO
public const GOLEM_WORKED_RATIO = 0.75GOSSIP_CURE_MAJOR
public const GOSSIP_CURE_MAJOR = 20GOSSIP_CURE_MINOR
public const GOSSIP_CURE_MINOR = 25GOSSIP_HIT
public const GOSSIP_HIT = 25GOSSIP_KILL
public const GOSSIP_KILL = 25GOSSIP_TRADE
public const GOSSIP_TRADE = 2INVENTORY_SIZE
public const INVENTORY_SIZE = 8JOB_SITE_SEARCH_HORIZONTAL
public const JOB_SITE_SEARCH_HORIZONTAL = 32JOB_SITE_SEARCH_VERTICAL
public const JOB_SITE_SEARCH_VERTICAL = 8KILL_WITNESS_RANGE
public const KILL_WITNESS_RANGE = 16.0Villagers this close to a villager killed by a player remember it.
MAX_RESTOCKS_PER_DAY
public const MAX_RESTOCKS_PER_DAY = 2Restocks a day at most (vanilla: twice, when working at the job site).
MAX_TIER
public const MAX_TIER = 4PROFESSION_ARMORER
public const PROFESSION_ARMORER = 8PROFESSION_BUTCHER
public const PROFESSION_BUTCHER = 11PROFESSION_CARTOGRAPHER
public const PROFESSION_CARTOGRAPHER = 6PROFESSION_CLERIC
public const PROFESSION_CLERIC = 7PROFESSION_FARMER
public const PROFESSION_FARMER = 1PROFESSION_FISHERMAN
public const PROFESSION_FISHERMAN = 2PROFESSION_FLETCHER
public const PROFESSION_FLETCHER = 4PROFESSION_LEATHERWORKER
public const PROFESSION_LEATHERWORKER = 12PROFESSION_LIBRARIAN
public const PROFESSION_LIBRARIAN = 5PROFESSION_MASON
public const PROFESSION_MASON = 13PROFESSION_NITWIT
public const PROFESSION_NITWIT = 14PROFESSION_SHEPHERD
public const PROFESSION_SHEPHERD = 3PROFESSION_TOOLSMITH
public const PROFESSION_TOOLSMITH = 10PROFESSION_UNEMPLOYED
public const PROFESSION_UNEMPLOYED = 0PROFESSION_WEAPONSMITH
public const PROFESSION_WEAPONSMITH = 9TAG_BED
public const TAG_BED = "PmBedPosition"TAG_GOSSIPS
public const TAG_GOSSIPS = "Gossips"TAG_GOSSIP_DECAY
public const TAG_GOSSIP_DECAY = "PmGossipDecay"TAG_INVENTORY
public const TAG_INVENTORY = "Inventory"TAG_JOB_SITE
public const TAG_JOB_SITE = "PmJobSitePosition"TAG_OFFERS
public const TAG_OFFERS = "Offers"TAG_PROFESSION
public const TAG_PROFESSION = "Variant"TAG_RESTOCKS
public const TAG_RESTOCKS = "PmRestocks"TAG_RESTOCK_DAY
public const TAG_RESTOCK_DAY = "PmRestockDay"TAG_SKIN
public const TAG_SKIN = "SkinID"TAG_TRADE_EXP
public const TAG_TRADE_EXP = "TradeExperience"TAG_TRADE_TIER
public const TAG_TRADE_TIER = "TradeTier"TAG_TYPE
public const TAG_TYPE = "MarkVariant"TYPE_DESERT
public const TYPE_DESERT = 1TYPE_JUNGLE
public const TYPE_JUNGLE = 2TYPE_PLAINS
public const TYPE_PLAINS = 0TYPE_SAVANNA
public const TYPE_SAVANNA = 3TYPE_SNOW
public const TYPE_SNOW = 4TYPE_SWAMP
public const TYPE_SWAMP = 5TYPE_TAIGA
public const TYPE_TAIGA = 6UNREACHABLE_BED_MEMORY
public const UNREACHABLE_BED_MEMORY = 1200Ticks an unreachable bed is skipped when looking for one.
VILLAGE_RANGE_HORIZONTAL
public const VILLAGE_RANGE_HORIZONTAL = 32VILLAGE_RANGE_VERTICAL
public const VILLAGE_RANGE_VERTICAL = 16Methods
addToInventory()
public function addToInventory(\pocketmine\item\Item $item) : voidPuts the item in the villager's inventory; what doesn't fit is dropped.
addTradeExperience()
public function addTradeExperience(int $exp) : voidAdds trading experience, levelling the villager up (with new trades) when it reaches the next level.
attack()
public function attack(\pocketmine\event\entity\EntityDamageEvent $source) : voidbreed()
public function breed(\pocketmine\entity\animal\Animal $partner) : ?\pocketmine\entity\animal\AnimalcanBeLeashed()
public function canBeLeashed() : boolVillagers cannot be led (vanilla).
canTradeWith()
public function canTradeWith(\pocketmine\player\Player $player) : boolcanWalkTo()
public function canWalkTo(\pocketmine\math\Vector3 $block) : boolWhether the path finder finds a way to the block (within 1.5 blocks of it).
claimBed()
public function claimBed(\pocketmine\math\Vector3 $bed) : boolClaims the bed (its head block). Returns false if another villager has it.
claimJobSite()
public function claimJobSite(\pocketmine\math\Vector3 $pos) : boolClaims the job site block; an unemployed villager takes its profession. Returns false if another villager has it or it isn't a job site of the villager's profession.
countFreeBeds()
public function countFreeBeds() : intUnclaimed beds around the villager (in the village).
createBaby() protected
protected function createBaby(\pocketmine\entity\animal\Animal $partner, \pocketmine\entity\Location $location) : \pocketmine\entity\animal\AnimalcreateNavigation() protected
protected function createNavigation() : \pocketmine\entity\ai\navigation\PathNavigatorVillagers path through doors and open them (vanilla navigation can_open_doors, see DoorInteraction).
entityBaseTick() protected
protected function entityBaseTick(int $tickDiff = 1) : boolfindSleeperAt()
public static function findSleeperAt(\pocketmine\world\World $world, \pocketmine\math\Vector3 $bedHead) : ?\pocketmine\entity\npc\VillagerV2Returns the villager sleeping in the bed whose head is at the position, if any.
getActivity()
public function getActivity() : \pocketmine\entity\npc\VillagerActivityWhat the villager does now according to its schedule.
getBedPosition()
public function getBedPosition() : ?\pocketmine\math\Vector3getFoodPoints()
public static function getFoodPoints(\pocketmine\item\Item $item) : intFood points of an item: bread 4, carrot, potato and beetroot 1.
getFoodPointsInInventory()
public function getFoodPointsInInventory() : intgetGossips()
public function getGossips() : \pocketmine\entity\npc\GossipsgetInitialSizeInfo() protected
protected function getInitialSizeInfo() : \pocketmine\entity\EntitySizeInfogetInventory()
public function getInventory() : \pocketmine\inventory\SimpleInventorygetJobSitePosition()
public function getJobSitePosition() : ?\pocketmine\math\Vector3getName()
public function getName() : stringgetNetworkTypeId()
public static function getNetworkTypeId() : stringgetPlayerReputation()
public function getPlayerReputation(\pocketmine\player\Player $player) : intgetProfession()
public function getProfession() : intgetRestocksToday()
public function getRestocksToday() : intgetShareableFood()
public function getShareableFood() : ?\pocketmine\item\ItemFood the villager can give away: half of a stack of at least 6 bread or 24 carrots, potatoes or beetroots.
getTierExpRequirements()
public function getTierExpRequirements() : arraygetTradeDisplayName()
public function getTradeDisplayName() : stringgetTradeExperience()
public function getTradeExperience() : intgetTradeOffers()
public function getTradeOffers() : arraygetTradeTier()
public function getTradeTier() : intgetTradingPlayer()
public function getTradingPlayer() : ?\pocketmine\player\PlayergetVillagerType()
public function getVillagerType() : intgetXpDropAmount()
public function getXpDropAmount() : intgossipWith()
public function gossipWith(\pocketmine\entity\npc\VillagerV2 $other) : voidTwo villagers talk: they share their gossip, and the village may summon an iron golem.
hasTraded()
public function hasTraded() : boolWhether a player traded with this villager: it then keeps its profession for good.
hasWorkedRecently()
public function hasWorkedRecently() : boolWhether the villager worked at its job site during the last day.
initEntity() protected
protected function initEntity(\pocketmine\nbt\tag\CompoundTag $nbt) : voidisBreedingItem()
public function isBreedingItem(\pocketmine\item\Item $item) : boolisCelebrating()
public function isCelebrating() : boolisSleeping()
public function isSleeping() : boolisWillingToBreed()
public function isWillingToBreed() : boolWhether the villager becomes willing to breed now: an adult (not on cooldown) with enough food, outside its work hours (unemployed villagers and nitwits any time), awake, with a free bed in the village.
markBedUnreachable()
public function markBedUnreachable(\pocketmine\math\Vector3 $bed) : voidForgets the bed if it is the claimed one and skips it when looking for a bed for a while (the villager couldn't get there).
onArriveAtWork()
public function onArriveAtWork() : voidCalled by WorkAtJobSiteGoal when the villager reaches its job site: restocks the trades if some were used, at most VillagerV2::MAX_RESTOCKS_PER_DAY times a day and only with a bed (Bedrock).
onCuredBy()
public function onCuredBy(string $playerUuid) : voidCalled when a player cured this villager from a zombie villager: major and minor positive gossip (the cure discount).
onDeath() protected
protected function onDeath() : voidonDispose() protected
protected function onDispose() : voidonInteractWithItem() protected
protected function onInteractWithItem(\pocketmine\player\Player $player, \pocketmine\item\Item $item) : boolonStruckByLightning()
public function onStruckByLightning(\pocketmine\entity\object\LightningBolt $bolt) : voidVanilla: lightning turns a villager into a witch (not on Peaceful), which frees its bed and job site.
onTrade()
public function onTrade(\pocketmine\player\Player $player, \pocketmine\entity\npc\TradeOffer $offer, int $times) : voidregisterGoals() protected
protected function registerGoals() : voidreleaseBed()
public function releaseBed() : voidreleaseJobSite()
public function releaseJobSite() : voidrestock()
public function restock() : voidResets the uses of every trade.
saveNBT()
public function saveNBT() : \pocketmine\nbt\tag\CompoundTagsetCelebrating()
public function setCelebrating(bool $celebrating) : voidVillagers celebrate when their village wins a raid.
setProfession()
public function setProfession(int $profession) : voidChanges the profession; the trades are replaced by the new profession's for the current level.
setTradingPlayer()
public function setTradingPlayer(?\pocketmine\player\Player $player) : voidsetVillagerType()
public function setVillagerType(int $type) : voidstartSleeping()
public function startSleeping() : boolLies down in the claimed bed (the villager must be next to it). Returns false if there is no bed or someone else sleeps in it.
syncNetworkData() protected
protected function syncNetworkData(\pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection $properties) : voidthrowFoodTo()
public function throwFoodTo(\pocketmine\entity\npc\VillagerV2 $receiver) : voidThrows half of a food surplus towards the other villager.
tickAi() protected
protected function tickAi(int $currentTick) : voidtrySummonGolem()
public function trySummonGolem() : ?\pocketmine\entity\golem\IronGolemSummons an iron golem near the villager if the village around it meets the Bedrock conditions (see the class doc). Each 32x32 area is checked at most once every VillagerV2::GOLEM_CHECK_INTERVAL ticks.
typeForBiome()
public static function typeForBiome(\pocketmine\world\World $world, \pocketmine\math\Vector3 $pos) : intVillager type of a biome (Bedrock biome tags).
updateDweller()
public function updateDweller() : voidRegisters the saved claims, checks they still stand, claims a bed and a job site if needed, and updates food and breeding (vanilla dweller update, every 3-5 seconds).
wakeUp()
public function wakeUp() : voidGets out of bed. A villager that slept until morning heals (Bedrock).
wantsFood()
public function wantsFood() : boolWhether the villager has less food than it wants (less than 12 food points).
wantsItem()
public function wantsItem(\pocketmine\item\Item $item) : boolWhether the villager picks up the item: food, plus wheat, seeds and bone meal for farmers.
