Skip to content

Piglin 5.46.0 ​

class · pocketmine\entity\monster\Piglin · source

Extends Monster
Implements Ageable, Angerable

Bedrock values (piglin.json): 16 health, movement 0.35 (baby 0.42), 0.6x1.9. Adults hold a golden sword (attack 5) or a crossbow (shoots within 8 blocks, backing off within 4), 50/50 (5% of the swords are golden spears), and wear each piece of golden armor with a 10% chance; 5% spawn as babies, which panic when hurt.

  • Neutral to players wearing a piece of golden armor; attacks the others within 16 blocks, and wither skeletons.
  • Hurting one angers the piglins within 16 blocks for 30 seconds. So does opening a chest, trapped chest, ender chest, barrel or shulker box in their sight, or breaking a gold block, gold ore, raw gold block, gilded blackstone or one of those containers within 16 blocks (see PiglinAi), gold armor or not.
  • Bartering: give an adult a gold ingot (interact) or let it pick one up; it holds it in its off hand and admires it for 8 seconds (admire_item), then throws an item of the bartering table (PiglinBarter) towards the player. Other gold items it picks up (Java tag piglin_loved) are admired too and kept: golden armor is worn when the slot is free, the rest goes into its 8-slot inventory, dropped on death. Being hurt stops the admiring and keeps it from picking gold up for 20 seconds. Babies don't barter.
  • Picks up porkchops and eats them (one every 10 seconds).
  • Hunts hoglins: an adult which hasn't hunted for 30-120 seconds attacks the nearest adult hoglin within 16 blocks unless the hoglins outnumber the piglins, and calls the piglins around to join; when the hoglin dies, the piglins within 16 blocks celebrate (dance) for 10 seconds. Outnumbered piglins walk away from hoglins instead.
  • Flees zombified piglins and zoglins within 6 blocks, and soul fire, soul torches, soul lanterns and lit soul campfires within 8 blocks.
  • Turns into a zombified piglin after 15 seconds outside the Nether. Loot: its spawn equipment (8.5%), the gold it picked up and its inventory. Experience 5 (+1-3 per equipped item), baby 1 (+1-2). Not implemented: babies admiring gold, piglins staring at players holding gold, jealousy when a player takes the gold they wanted, riding hoglins as baby piglins, minecart chests (no minecarts).

Constants ​

ADMIRE_COOLDOWN_TICKS ​

php
public const ADMIRE_COOLDOWN_TICKS = 400

admire_item cooldown_after_being_attacked

ADMIRE_TICKS ​

php
public const ADMIRE_TICKS = 160

ANGER_TICKS ​

php
public const ANGER_TICKS = 600

ARMOR_CHANCE ​

php
public const ARMOR_CHANCE = 10

ATE_RECENTLY_TICKS ​

php
public const ATE_RECENTLY_TICKS = 200

ATTACK_DAMAGE ​

php
public const ATTACK_DAMAGE = 5.0

CELEBRATE_TICKS ​

php
public const CELEBRATE_TICKS = 200

HUNT_RANGE ​

php
public const HUNT_RANGE = 16.0

INVENTORY_SIZE ​

php
public const INVENTORY_SIZE = 8

TAG_ARMOR ​

php
public const TAG_ARMOR = "Armor"

TAG_ARMOR_KEPT ​

php
public const TAG_ARMOR_KEPT = "ArmorKept"

TAG_INVENTORY ​

php
public const TAG_INVENTORY = "Inventory"

TAG_IS_BABY ​

php
public const TAG_IS_BABY = "IsBaby"

WANTED_ITEM_RANGE ​

php
public const WANTED_ITEM_RANGE = 10.0

Methods ​

attack() ​

php
public function attack(\pocketmine\event\entity\EntityDamageEvent $source) : void

countAdultsAround() ​

php
public function countAdultsAround() : array

Counts the adult piglins (this one included) and adult hoglins within 16 blocks.

entityBaseTick() protected ​

php
protected function entityBaseTick(int $tickDiff = 1) : bool

findRepellent() ​

php
public function findRepellent() : ?\pocketmine\math\Vector3

Nearest soul fire, soul torch, soul lantern or lit soul campfire within 8 blocks (4 up or down), looked for once a second.

findWantedItem() ​

php
public function findWantedItem() : ?\pocketmine\entity\object\ItemEntity

Nearest wanted item lying within 10 blocks, looked for once a second while the piglin has no target.

getBarterLoot() ​

php
public static function getBarterLoot() : \pocketmine\item\Item

Returns a random item of the bartering table.

getDrops() ​

php
public function getDrops() : array

getHuntCooldown() ​

php
public function getHuntCooldown() : int

getInitialSizeInfo() protected ​

php
protected function getInitialSizeInfo() : \pocketmine\entity\EntitySizeInfo

getInventoryContents() ​

php
public function getInventoryContents() : array

getItemInteractButtonText() protected ​

php
protected function getItemInteractButtonText(\pocketmine\player\Player $player, \pocketmine\item\Item $item) : ?string

getName() ​

php
public function getName() : string

getNetworkTypeId() ​

php
public static function getNetworkTypeId() : string

getPickedItem() ​

php
public function getPickedItem() : ?\pocketmine\item\Item

getXpDropAmount() ​

php
public function getXpDropAmount() : int

hasCrossbow() ​

php
public function hasCrossbow() : bool

initEntity() protected ​

php
protected function initEntity(\pocketmine\nbt\tag\CompoundTag $nbt) : void

isAdmiring() ​

php
public function isAdmiring() : bool

isBaby() ​

php
public function isBaby() : bool

isCelebrating() ​

php
public function isCelebrating() : bool

onAngerChange() protected ​

php
protected function onAngerChange(bool $angry) : void

onInteractWithItem() protected ​

php
protected function onInteractWithItem(\pocketmine\player\Player $player, \pocketmine\item\Item $item) : bool

pickUp() ​

php
public function pickUp(\pocketmine\entity\object\ItemEntity $entity) : bool

Picks one item of the stack up: porkchops are eaten, gold is admired.

registerGoals() protected ​

php
protected function registerGoals() : void

saveNBT() ​

php
public function saveNBT() : \pocketmine\nbt\tag\CompoundTag

setBaby() ​

php
public function setBaby(bool $baby) : void

setCharging() ​

php
public function setCharging(bool $charging) : void

setHuntCooldown() ​

php
public function setHuntCooldown(int $ticks) : void

shootCrossbow() ​

php
public function shootCrossbow(\pocketmine\entity\Living $target, float $distance) : void

startAdmiring() ​

php
public function startAdmiring(?\pocketmine\item\Item $item = null, ?\pocketmine\player\Player $from = null) : void

Holds the item (default: a gold ingot) in its off hand and admires it; afterwards it barters it (gold ingots) or keeps it. $from is the player who gave or threw it, who gets the bartered item.

startCelebrating() ​

php
public function startCelebrating() : void

Dances for 10 seconds (celebrate_hunt), after a hoglin hunt.

syncNetworkData() protected ​

php
protected function syncNetworkData(\pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection $properties) : void

tryHunting() ​

php
public function tryHunting() : bool

Starts a hunt when possible: an adult not on hunt cooldown, not busy, which sees an adult hoglin and isn't outnumbered. The adult piglins around join the hunt, and none of them hunts again for 30-120 seconds.

wantsItem() ​

php
public function wantsItem(\pocketmine\item\Item $item) : bool

Whether the piglin would pick up the item now: gold it loves when it's free to admire it, and porkchops when it hasn't eaten recently.

wearsGold() ​

php
public static function wearsGold(\pocketmine\entity\Living $entity) : bool

Piglins leave alone players wearing at least one piece of golden armor.

wouldAttack() ​

php
public function wouldAttack(\pocketmine\entity\Living $entity) : bool

Whether the piglin attacks the entity on sight: adults not busy admiring attack wither skeletons and players without golden armor.

zombify() protected ​

php
protected function zombify() : void

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.