Class Mob

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

public abstract class Mob extends LivingEntity implements 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:
    • 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
    • canPickUpLoot

      private boolean canPickUpLoot
    • persistenceRequired

      private boolean persistenceRequired
    • pathfindingMalus

      private final Map<BlockPathTypes,Float> pathfindingMalus
    • lootTable

      @Nullable private ResourceLocation lootTable
    • lootTableSeed

      private long lootTableSeed
    • leashHolder

      @Nullable private Entity leashHolder
    • delayedLeashHolderId

      private int delayedLeashHolderId
    • leashInfoTag

      @Nullable private CompoundTag leashInfoTag
    • 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(BlockPathTypes p_21440_)
    • setPathfindingMalus

      public void setPathfindingMalus(BlockPathTypes p_21442_, 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
    • 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()
      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 ResourceLocation getLootTable()
      Overrides:
      getLootTable in class LivingEntity
    • getDefaultLootTable

      protected ResourceLocation 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
    • 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_)
    • canReplaceEqualItem

      public boolean canReplaceEqualItem(ItemStack p_21478_, ItemStack p_21479_)
    • 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()
    • 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 Entity
    • getHandSlots

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

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

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

      public void setItemSlot(EquipmentSlot p_21416_, ItemStack p_21417_)
      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_)
    • 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_, @Nullable CompoundTag p_21438_)
      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_)
    • 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()
    • 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
    • getMeleeAttackRangeSqr

      public double getMeleeAttackRangeSqr(LivingEntity p_147273_)
    • getPerceivedTargetDistanceSquareForMeleeAttack

      public double getPerceivedTargetDistanceSquareForMeleeAttack(LivingEntity p_263021_)
    • isWithinMeleeAttackRange

      public boolean isWithinMeleeAttackRange(LivingEntity p_217067_)
    • doHurtTarget

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

      private void maybeDisableShield(Player p_21425_, ItemStack p_21426_, ItemStack p_21427_)
    • 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, net.minecraft.nbt.CompoundTag), 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.