Class Mob

All Implemented Interfaces:
CommandSource, SyncedDataHolder, Attackable, EquipmentUser, Targeting, EntityAccess, Nameable, ScoreHolder, ICapabilityProvider, ICapabilityProviderImpl<Entity>, ICapabilitySerializable<CompoundTag>, IForgeEntity, IForgeLivingEntity, INBTSerializable<CompoundTag>
Direct Known Subclasses:
AmbientCreature, EnderDragon, FlyingMob, PathfinderMob, Slime

public abstract class Mob extends LivingEntity implements EquipmentUser, Targeting
  • Field Details

    • DATA_MOB_FLAGS_ID

      private static final EntityDataAccessor<Byte> DATA_MOB_FLAGS_ID
    • MOB_FLAG_NO_AI

      private static final int MOB_FLAG_NO_AI
      See Also:
    • MOB_FLAG_LEFTHANDED

      private static final int MOB_FLAG_LEFTHANDED
      See Also:
    • MOB_FLAG_AGGRESSIVE

      private static final int MOB_FLAG_AGGRESSIVE
      See Also:
    • PICKUP_REACH

      protected static final int PICKUP_REACH
      See Also:
    • ITEM_PICKUP_REACH

      private static final Vec3i ITEM_PICKUP_REACH
    • MAX_WEARING_ARMOR_CHANCE

      public static final float MAX_WEARING_ARMOR_CHANCE
      See Also:
    • MAX_PICKUP_LOOT_CHANCE

      public static final float MAX_PICKUP_LOOT_CHANCE
      See Also:
    • MAX_ENCHANTED_ARMOR_CHANCE

      public static final float MAX_ENCHANTED_ARMOR_CHANCE
      See Also:
    • MAX_ENCHANTED_WEAPON_CHANCE

      public static final float MAX_ENCHANTED_WEAPON_CHANCE
      See Also:
    • LEASH_TAG

      public static final String LEASH_TAG
      See Also:
    • DEFAULT_EQUIPMENT_DROP_CHANCE

      public static final float DEFAULT_EQUIPMENT_DROP_CHANCE
      See Also:
    • PRESERVE_ITEM_DROP_CHANCE

      public static final int PRESERVE_ITEM_DROP_CHANCE
      See Also:
    • UPDATE_GOAL_SELECTOR_EVERY_N_TICKS

      public static final int UPDATE_GOAL_SELECTOR_EVERY_N_TICKS
      See Also:
    • DEFAULT_ATTACK_REACH

      private static final double DEFAULT_ATTACK_REACH
    • ambientSoundTime

      public int ambientSoundTime
    • xpReward

      protected int xpReward
    • lookControl

      protected LookControl lookControl
    • moveControl

      protected MoveControl moveControl
    • jumpControl

      protected JumpControl jumpControl
    • bodyRotationControl

      private final BodyRotationControl bodyRotationControl
    • goalSelector

      public final GoalSelector goalSelector
    • targetSelector

      public final GoalSelector targetSelector
    • target

      @Nullable private LivingEntity target
    • sensing

      private final Sensing sensing
    • handItems

      private final NonNullList<ItemStack> handItems
    • handDropChances

      protected final float[] handDropChances
    • armorItems

      private final NonNullList<ItemStack> armorItems
    • armorDropChances

      protected final float[] armorDropChances
    • bodyArmorItem

      private ItemStack bodyArmorItem
    • bodyArmorDropChance

      protected float bodyArmorDropChance
    • canPickUpLoot

      private boolean canPickUpLoot
    • persistenceRequired

      private boolean persistenceRequired
    • pathfindingMalus

      private final Map<PathType,Float> pathfindingMalus
    • lootTable

      @Nullable private ResourceKey<LootTable> lootTable
    • lootTableSeed

      private long lootTableSeed
    • leashHolder

      @Nullable private Entity leashHolder
    • delayedLeashHolderId

      private int delayedLeashHolderId
    • delayedLeashInfo

      @Nullable private com.mojang.datafixers.util.Either<UUID,BlockPos> delayedLeashInfo
    • restrictCenter

      private BlockPos restrictCenter
    • restrictRadius

      private float restrictRadius
    • spawnType

      @Nullable private MobSpawnType spawnType
    • spawnCancelled

      private boolean spawnCancelled
  • Constructor Details

  • Method Details

    • registerGoals

      protected void registerGoals()
    • createMobAttributes

      public static AttributeSupplier.Builder createMobAttributes()
    • createNavigation

      protected PathNavigation createNavigation(Level p_21480_)
    • shouldPassengersInheritMalus

      protected boolean shouldPassengersInheritMalus()
    • getPathfindingMalus

      public float getPathfindingMalus(PathType p_334857_)
    • setPathfindingMalus

      public void setPathfindingMalus(PathType p_332507_, float p_21443_)
    • onPathfindingStart

      public void onPathfindingStart()
    • onPathfindingDone

      public void onPathfindingDone()
    • createBodyControl

      protected BodyRotationControl createBodyControl()
    • getLookControl

      public LookControl getLookControl()
    • getMoveControl

      public MoveControl getMoveControl()
    • getJumpControl

      public JumpControl getJumpControl()
    • getNavigation

      public PathNavigation getNavigation()
    • getControllingPassenger

      @Nullable public LivingEntity getControllingPassenger()
      Overrides:
      getControllingPassenger in class Entity
    • getSensing

      public Sensing getSensing()
    • getTarget

      @Nullable public LivingEntity getTarget()
      Specified by:
      getTarget in interface Targeting
    • getTargetFromBrain

      @Nullable protected final LivingEntity getTargetFromBrain()
    • setTarget

      public void setTarget(@Nullable LivingEntity p_21544_)
    • canAttackType

      public boolean canAttackType(EntityType<?> p_21399_)
      Overrides:
      canAttackType in class LivingEntity
    • canFireProjectileWeapon

      public boolean canFireProjectileWeapon(ProjectileWeaponItem p_21430_)
    • ate

      public void ate()
    • defineSynchedData

      protected void defineSynchedData(SynchedEntityData.Builder p_335882_)
      Overrides:
      defineSynchedData in class LivingEntity
    • getAmbientSoundInterval

      public int getAmbientSoundInterval()
    • playAmbientSound

      public void playAmbientSound()
    • baseTick

      public void baseTick()
      Overrides:
      baseTick in class LivingEntity
    • playHurtSound

      protected void playHurtSound(DamageSource p_21493_)
      Overrides:
      playHurtSound in class LivingEntity
    • resetAmbientSoundTime

      private void resetAmbientSoundTime()
    • getExperienceReward

      public int getExperienceReward()
      Overrides:
      getExperienceReward in class LivingEntity
    • spawnAnim

      public void spawnAnim()
    • handleEntityEvent

      public void handleEntityEvent(byte p_21375_)
      Overrides:
      handleEntityEvent in class LivingEntity
    • tick

      public void tick()
      Overrides:
      tick in class LivingEntity
    • updateControlFlags

      protected void updateControlFlags()
    • tickHeadTurn

      protected float tickHeadTurn(float p_21538_, float p_21539_)
      Overrides:
      tickHeadTurn in class LivingEntity
    • getAmbientSound

      @Nullable protected SoundEvent getAmbientSound()
    • addAdditionalSaveData

      public void addAdditionalSaveData(CompoundTag p_21484_)
      Overrides:
      addAdditionalSaveData in class LivingEntity
    • readAdditionalSaveData

      public void readAdditionalSaveData(CompoundTag p_21450_)
      Overrides:
      readAdditionalSaveData in class LivingEntity
    • dropFromLootTable

      protected void dropFromLootTable(DamageSource p_21389_, boolean p_21390_)
      Overrides:
      dropFromLootTable in class LivingEntity
    • getLootTable

      public final ResourceKey<LootTable> getLootTable()
      Overrides:
      getLootTable in class LivingEntity
    • getDefaultLootTable

      protected ResourceKey<LootTable> getDefaultLootTable()
    • getLootTableSeed

      public long getLootTableSeed()
      Overrides:
      getLootTableSeed in class LivingEntity
    • setZza

      public void setZza(float p_21565_)
    • setYya

      public void setYya(float p_21568_)
    • setXxa

      public void setXxa(float p_21571_)
    • setSpeed

      public void setSpeed(float p_21556_)
      Overrides:
      setSpeed in class LivingEntity
    • stopInPlace

      public void stopInPlace()
    • aiStep

      public void aiStep()
      Overrides:
      aiStep in class LivingEntity
    • getPickupReach

      protected Vec3i getPickupReach()
    • pickUpItem

      protected void pickUpItem(ItemEntity p_21471_)
    • equipItemIfPossible

      public ItemStack equipItemIfPossible(ItemStack p_255842_)
    • setItemSlotAndDropWhenKilled

      protected void setItemSlotAndDropWhenKilled(EquipmentSlot p_21469_, ItemStack p_21470_)
    • setGuaranteedDrop

      public void setGuaranteedDrop(EquipmentSlot p_21509_)
    • canReplaceCurrentItem

      protected boolean canReplaceCurrentItem(ItemStack p_21428_, ItemStack p_21429_)
    • getApproximateAttackDamageWithItem

      private double getApproximateAttackDamageWithItem(ItemStack p_329089_)
    • canReplaceEqualItem

      public boolean canReplaceEqualItem(ItemStack p_21478_, ItemStack p_21479_)
    • hasAnyComponentExceptDamage

      private static boolean hasAnyComponentExceptDamage(ItemStack p_335247_)
    • canHoldItem

      public boolean canHoldItem(ItemStack p_21545_)
    • wantsToPickUp

      public boolean wantsToPickUp(ItemStack p_21546_)
    • removeWhenFarAway

      public boolean removeWhenFarAway(double p_21542_)
    • requiresCustomPersistence

      public boolean requiresCustomPersistence()
    • shouldDespawnInPeaceful

      protected boolean shouldDespawnInPeaceful()
    • checkDespawn

      public void checkDespawn()
      Overrides:
      checkDespawn in class Entity
    • serverAiStep

      protected final void serverAiStep()
      Overrides:
      serverAiStep in class LivingEntity
    • sendDebugPackets

      protected void sendDebugPackets()
    • customServerAiStep

      protected void customServerAiStep()
    • getMaxHeadXRot

      public int getMaxHeadXRot()
    • getMaxHeadYRot

      public int getMaxHeadYRot()
    • clampHeadRotationToBody

      protected void clampHeadRotationToBody()
    • getHeadRotSpeed

      public int getHeadRotSpeed()
    • lookAt

      public void lookAt(Entity p_21392_, float p_21393_, float p_21394_)
    • rotlerp

      private float rotlerp(float p_21377_, float p_21378_, float p_21379_)
    • checkMobSpawnRules

      public static boolean checkMobSpawnRules(EntityType<? extends Mob> p_217058_, LevelAccessor p_217059_, MobSpawnType p_217060_, BlockPos p_217061_, RandomSource p_217062_)
    • checkSpawnRules

      public boolean checkSpawnRules(LevelAccessor p_21431_, MobSpawnType p_21432_)
    • checkSpawnObstruction

      public boolean checkSpawnObstruction(LevelReader p_21433_)
    • getMaxSpawnClusterSize

      public int getMaxSpawnClusterSize()
    • isMaxGroupSizeReached

      public boolean isMaxGroupSizeReached(int p_21489_)
    • getMaxFallDistance

      public int getMaxFallDistance()
      Overrides:
      getMaxFallDistance in class LivingEntity
    • getHandSlots

      public Iterable<ItemStack> getHandSlots()
      Overrides:
      getHandSlots in class LivingEntity
    • getArmorSlots

      public Iterable<ItemStack> getArmorSlots()
      Specified by:
      getArmorSlots in class LivingEntity
    • getBodyArmorItem

      public ItemStack getBodyArmorItem()
    • canWearBodyArmor

      public boolean canWearBodyArmor()
    • canUseSlot

      public boolean canUseSlot(EquipmentSlot p_334488_)
      Overrides:
      canUseSlot in class LivingEntity
    • isWearingBodyArmor

      public boolean isWearingBodyArmor()
    • isBodyArmorItem

      public boolean isBodyArmorItem(ItemStack p_335235_)
    • setBodyArmorItem

      public void setBodyArmorItem(ItemStack p_333947_)
    • getArmorAndBodyArmorSlots

      public Iterable<ItemStack> getArmorAndBodyArmorSlots()
      Overrides:
      getArmorAndBodyArmorSlots in class LivingEntity
    • getItemBySlot

      public ItemStack getItemBySlot(EquipmentSlot p_21467_)
      Specified by:
      getItemBySlot in interface EquipmentUser
      Specified by:
      getItemBySlot in class LivingEntity
    • setItemSlot

      public void setItemSlot(EquipmentSlot p_21416_, ItemStack p_21417_)
      Specified by:
      setItemSlot in interface EquipmentUser
      Specified by:
      setItemSlot in class LivingEntity
    • dropCustomDeathLoot

      protected void dropCustomDeathLoot(DamageSource p_21385_, int p_21386_, boolean p_21387_)
      Overrides:
      dropCustomDeathLoot in class LivingEntity
    • getEquipmentDropChance

      protected float getEquipmentDropChance(EquipmentSlot p_21520_)
    • createEquipmentParams

      private LootParams createEquipmentParams(ServerLevel p_331909_)
    • equip

      public void equip(EquipmentTable p_332456_)
    • equip

      public void equip(ResourceKey<LootTable> p_328521_, Map<EquipmentSlot,Float> p_335710_)
    • populateDefaultEquipmentSlots

      protected void populateDefaultEquipmentSlots(RandomSource p_217055_, DifficultyInstance p_217056_)
    • getEquipmentForSlot

      @Nullable public static Item getEquipmentForSlot(EquipmentSlot p_21413_, int p_21414_)
    • populateDefaultEquipmentEnchantments

      protected void populateDefaultEquipmentEnchantments(RandomSource p_217063_, DifficultyInstance p_217064_)
    • enchantSpawnedWeapon

      protected void enchantSpawnedWeapon(RandomSource p_217049_, float p_217050_)
    • enchantSpawnedArmor

      protected void enchantSpawnedArmor(RandomSource p_217052_, float p_217053_, EquipmentSlot p_217054_)
    • finalizeSpawn

      @Deprecated @OverrideOnly @Nullable public SpawnGroupData finalizeSpawn(ServerLevelAccessor p_21434_, DifficultyInstance p_21435_, MobSpawnType p_21436_, @Nullable SpawnGroupData p_21437_)
      Deprecated.
      Forge: Override-Only, call via ForgeEventFactory.onFinalizeSpawn.
      Overrides are allowed. Do not wrap super calls within override (as that will cause stack overflows).
      Vanilla calls are replaced with a transformer, and are not visible in source.

      Be certain to either call super.finalizeSpawn or set the spawnType field from within your override.

    • setPersistenceRequired

      public void setPersistenceRequired()
    • setDropChance

      public void setDropChance(EquipmentSlot p_21410_, float p_21411_)
      Specified by:
      setDropChance in interface EquipmentUser
    • canPickUpLoot

      public boolean canPickUpLoot()
    • setCanPickUpLoot

      public void setCanPickUpLoot(boolean p_21554_)
    • canTakeItem

      public boolean canTakeItem(ItemStack p_21522_)
      Overrides:
      canTakeItem in class LivingEntity
    • isPersistenceRequired

      public boolean isPersistenceRequired()
    • interact

      public final InteractionResult interact(Player p_21420_, InteractionHand p_21421_)
      Overrides:
      interact in class Entity
    • checkAndHandleImportantInteractions

      private InteractionResult checkAndHandleImportantInteractions(Player p_21500_, InteractionHand p_21501_)
    • onOffspringSpawnedFromEgg

      protected void onOffspringSpawnedFromEgg(Player p_21422_, Mob p_21423_)
    • mobInteract

      protected InteractionResult mobInteract(Player p_21472_, InteractionHand p_21473_)
    • isWithinRestriction

      public boolean isWithinRestriction()
    • isWithinRestriction

      public boolean isWithinRestriction(BlockPos p_21445_)
    • restrictTo

      public void restrictTo(BlockPos p_21447_, int p_21448_)
    • getRestrictCenter

      public BlockPos getRestrictCenter()
    • getRestrictRadius

      public float getRestrictRadius()
    • clearRestriction

      public void clearRestriction()
    • hasRestriction

      public boolean hasRestriction()
    • convertTo

      @Nullable public <T extends Mob> T convertTo(EntityType<T> p_21407_, boolean p_21408_)
    • tickLeash

      protected void tickLeash()
    • dropLeash

      public void dropLeash(boolean p_21456_, boolean p_21457_)
    • canBeLeashed

      public boolean canBeLeashed(Player p_21418_)
    • isLeashed

      public boolean isLeashed()
    • mayBeLeashed

      public boolean mayBeLeashed()
    • getLeashHolder

      @Nullable public Entity getLeashHolder()
    • setLeashedTo

      public void setLeashedTo(Entity p_21464_, boolean p_21465_)
    • setDelayedLeashHolderId

      public void setDelayedLeashHolderId(int p_21507_)
    • startRiding

      public boolean startRiding(Entity p_21396_, boolean p_21397_)
      Overrides:
      startRiding in class Entity
    • restoreLeashFromSave

      private void restoreLeashFromSave()
    • isEffectiveAi

      public boolean isEffectiveAi()
      Overrides:
      isEffectiveAi in class Entity
    • setNoAi

      public void setNoAi(boolean p_21558_)
    • setLeftHanded

      public void setLeftHanded(boolean p_21560_)
    • setAggressive

      public void setAggressive(boolean p_21562_)
    • isNoAi

      public boolean isNoAi()
    • isLeftHanded

      public boolean isLeftHanded()
    • isAggressive

      public boolean isAggressive()
    • setBaby

      public void setBaby(boolean p_21451_)
    • getMainArm

      public HumanoidArm getMainArm()
      Specified by:
      getMainArm in class LivingEntity
    • isWithinMeleeAttackRange

      public boolean isWithinMeleeAttackRange(LivingEntity p_217067_)
    • getAttackBoundingBox

      protected AABB getAttackBoundingBox()
    • doHurtTarget

      public boolean doHurtTarget(Entity p_21372_)
      Overrides:
      doHurtTarget in class LivingEntity
    • isSunBurnTick

      protected boolean isSunBurnTick()
    • jumpInLiquid

      @Deprecated protected void jumpInLiquid(TagKey<Fluid> p_204045_)
      Deprecated.
      Overrides:
      jumpInLiquid in class LivingEntity
    • jumpInLiquidInternal

      private void jumpInLiquidInternal(Runnable onSuper)
    • jumpInFluid

      public void jumpInFluid(FluidType type)
      Description copied from interface: IForgeLivingEntity
      Performs what to do when an entity attempts to go up or "jump" in a fluid.
      Specified by:
      jumpInFluid in interface IForgeLivingEntity
      Parameters:
      type - the type of the fluid
    • removeFreeWill

      public void removeFreeWill()
    • removeAllGoals

      public void removeAllGoals(Predicate<Goal> p_262667_)
    • removeAfterChangingDimensions

      protected void removeAfterChangingDimensions()
      Overrides:
      removeAfterChangingDimensions in class Entity
    • getPickResult

      @Nullable public ItemStack getPickResult()
      Overrides:
      getPickResult in class Entity
    • getSpawnType

      @Nullable public final MobSpawnType getSpawnType()
      Returns the type of spawn that created this mob, if applicable. If it could not be determined, this will return null.

      This is set via finalizeSpawn(net.minecraft.world.level.ServerLevelAccessor, net.minecraft.world.DifficultyInstance, net.minecraft.world.entity.MobSpawnType, net.minecraft.world.entity.SpawnGroupData), so you should not call this from within that method, instead using the parameter.

    • isSpawnCancelled

      @Internal public final boolean isSpawnCancelled()
      This method exists so that spawns can be cancelled from the FinalizeSpawnEvent without needing to hook up an additional handler for the EntityJoinLevelEvent.
      Returns:
      if this mob will be blocked from spawning during LevelWriter.addFreshEntity(Entity)
      API Note:
      Not public-facing API.
    • setSpawnCancelled

      @Internal public final void setSpawnCancelled(boolean cancel)
      Marks this mob as being disallowed to spawn during LevelWriter.addFreshEntity(Entity).

      Throws:
      UnsupportedOperationException - if this entity has already been added to the world.
      API Note:
      Not public-facing API.