Class ServerPlayer

All Implemented Interfaces:
CommandSource, SyncedDataHolder, Attackable, EntityAccess, Nameable, ScoreHolder, IAttachmentHolder, IEntityExtension, ILivingEntityExtension, IPlayerExtension, INBTSerializable<CompoundTag>
Direct Known Subclasses:
FakePlayer

public class ServerPlayer extends Player
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • NEUTRAL_MOB_DEATH_NOTIFICATION_RADII_XZ

      private static final int NEUTRAL_MOB_DEATH_NOTIFICATION_RADII_XZ
      See Also:
    • NEUTRAL_MOB_DEATH_NOTIFICATION_RADII_Y

      private static final int NEUTRAL_MOB_DEATH_NOTIFICATION_RADII_Y
      See Also:
    • FLY_STAT_RECORDING_SPEED

      private static final int FLY_STAT_RECORDING_SPEED
      See Also:
    • INTERACTION_DISTANCE_VERIFICATION_BUFFER

      public static final double INTERACTION_DISTANCE_VERIFICATION_BUFFER
      See Also:
    • CREATIVE_BLOCK_INTERACTION_RANGE_MODIFIER

      private static final AttributeModifier CREATIVE_BLOCK_INTERACTION_RANGE_MODIFIER
    • CREATIVE_ENTITY_INTERACTION_RANGE_MODIFIER

      private static final AttributeModifier CREATIVE_ENTITY_INTERACTION_RANGE_MODIFIER
    • connection

      public ServerGamePacketListenerImpl connection
    • server

      public final MinecraftServer server
    • gameMode

      public final ServerPlayerGameMode gameMode
    • advancements

      private final PlayerAdvancements advancements
    • stats

      private final ServerStatsCounter stats
    • lastRecordedHealthAndAbsorption

      private float lastRecordedHealthAndAbsorption
      the total health of the player, includes actual health and absorption health. Updated every tick.
    • lastRecordedFoodLevel

      private int lastRecordedFoodLevel
    • lastRecordedAirLevel

      private int lastRecordedAirLevel
    • lastRecordedArmor

      private int lastRecordedArmor
    • lastRecordedLevel

      private int lastRecordedLevel
    • lastRecordedExperience

      private int lastRecordedExperience
    • lastSentHealth

      private float lastSentHealth
    • lastSentFood

      private int lastSentFood
    • lastFoodSaturationZero

      private boolean lastFoodSaturationZero
    • lastSentExp

      private int lastSentExp
    • spawnInvulnerableTime

      private int spawnInvulnerableTime
    • chatVisibility

      private ChatVisiblity chatVisibility
    • canChatColor

      private boolean canChatColor
    • lastActionTime

      private long lastActionTime
    • camera

      @Nullable private Entity camera
      The entity the player is currently spectating through.
    • isChangingDimension

      private boolean isChangingDimension
    • seenCredits

      public boolean seenCredits
    • recipeBook

      private final ServerRecipeBook recipeBook
    • levitationStartPos

      @Nullable private Vec3 levitationStartPos
    • levitationStartTime

      private int levitationStartTime
    • disconnected

      private boolean disconnected
    • requestedViewDistance

      private int requestedViewDistance
    • language

      private String language
    • startingToFallPosition

      @Nullable private Vec3 startingToFallPosition
    • enteredNetherPosition

      @Nullable private Vec3 enteredNetherPosition
    • enteredLavaOnVehiclePosition

      @Nullable private Vec3 enteredLavaOnVehiclePosition
    • lastSectionPos

      private SectionPos lastSectionPos
      Player section position as last updated by TicketManager, used by ChunkManager
    • chunkTrackingView

      private ChunkTrackingView chunkTrackingView
    • respawnDimension

      private ResourceKey<Level> respawnDimension
    • respawnPosition

      @Nullable private BlockPos respawnPosition
    • respawnForced

      private boolean respawnForced
    • respawnAngle

      private float respawnAngle
    • textFilter

      private final TextFilter textFilter
    • textFilteringEnabled

      private boolean textFilteringEnabled
    • allowsListing

      private boolean allowsListing
    • spawnExtraParticlesOnFall

      private boolean spawnExtraParticlesOnFall
    • wardenSpawnTracker

      private WardenSpawnTracker wardenSpawnTracker
    • raidOmenPosition

      @Nullable private BlockPos raidOmenPosition
    • lastKnownClientMovement

      private Vec3 lastKnownClientMovement
    • containerSynchronizer

      private final ContainerSynchronizer containerSynchronizer
    • containerListener

      private final ContainerListener containerListener
    • chatSession

      @Nullable private RemoteChatSession chatSession
    • object

      @Nullable public final Object object
    • containerCounter

      private int containerCounter
    • wonGame

      public boolean wonGame
    • tabListHeader

      private Component tabListHeader
    • tabListFooter

      private Component tabListFooter
    • hasTabListName

      private boolean hasTabListName
    • tabListDisplayName

      private Component tabListDisplayName
  • Constructor Details

  • Method Details

    • adjustSpawnLocation

      public BlockPos adjustSpawnLocation(ServerLevel level, BlockPos pos)
      Overrides:
      adjustSpawnLocation in class Entity
    • getCoprime

      private int getCoprime(int spawnArea)
    • readAdditionalSaveData

      public void readAdditionalSaveData(CompoundTag compound)
      (abstract) Protected helper method to read subclass entity data from NBT.
      Overrides:
      readAdditionalSaveData in class Player
    • addAdditionalSaveData

      public void addAdditionalSaveData(CompoundTag compound)
      Overrides:
      addAdditionalSaveData in class Player
    • setExperiencePoints

      public void setExperiencePoints(int experiencePoints)
    • setExperienceLevels

      public void setExperienceLevels(int level)
    • giveExperienceLevels

      public void giveExperienceLevels(int levels)
      Add experience levels to this player.
      Overrides:
      giveExperienceLevels in class Player
    • onEnchantmentPerformed

      public void onEnchantmentPerformed(ItemStack enchantedItem, int cost)
      Overrides:
      onEnchantmentPerformed in class Player
    • initMenu

      private void initMenu(AbstractContainerMenu menu)
    • initInventoryMenu

      public void initInventoryMenu()
    • onEnterCombat

      public void onEnterCombat()
      Overrides:
      onEnterCombat in class LivingEntity
    • onLeaveCombat

      public void onLeaveCombat()
      Overrides:
      onLeaveCombat in class LivingEntity
    • onInsideBlock

      public void onInsideBlock(BlockState state)
      Overrides:
      onInsideBlock in class Entity
    • createItemCooldowns

      protected ItemCooldowns createItemCooldowns()
      Overrides:
      createItemCooldowns in class Player
    • tick

      public void tick()
      Overrides:
      tick in class Player
    • updatePlayerAttributes

      private void updatePlayerAttributes()
    • doTick

      public void doTick()
    • resetFallDistance

      public void resetFallDistance()
      Overrides:
      resetFallDistance in class Entity
    • trackStartFallingPosition

      public void trackStartFallingPosition()
    • trackEnteredOrExitedLavaOnVehicle

      public void trackEnteredOrExitedLavaOnVehicle()
    • updateScoreForCriteria

      private void updateScoreForCriteria(ObjectiveCriteria criteria, int points)
    • die

      public void die(DamageSource cause)
      Called when the mob's health reaches 0.
      Overrides:
      die in class Player
    • tellNeutralMobsThatIDied

      private void tellNeutralMobsThatIDied()
    • awardKillScore

      public void awardKillScore(Entity killed, int scoreValue, DamageSource damageSource)
      Overrides:
      awardKillScore in class Entity
    • handleTeamKill

      private void handleTeamKill(ScoreHolder scoreHolder, ScoreHolder teamMember, ObjectiveCriteria[] crtieria)
    • hurt

      public boolean hurt(DamageSource source, float amount)
      Called when the entity is attacked.
      Overrides:
      hurt in class Player
    • canHarmPlayer

      public boolean canHarmPlayer(Player other)
      Overrides:
      canHarmPlayer in class Player
    • isPvpAllowed

      private boolean isPvpAllowed()
    • findRespawnPositionAndUseSpawnBlock

      public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean keepInventory, DimensionTransition.PostDimensionTransition postDimensionTransition)
    • findRespawnAndUseSpawnBlock

      private static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel level, BlockPos pos, float angle, boolean forced, boolean keepInventory)
    • showEndCredits

      public void showEndCredits()
    • changeDimension

      @Nullable public Entity changeDimension(DimensionTransition transition)
      Overrides:
      changeDimension in class Entity
    • triggerDimensionChangeTriggers

      private void triggerDimensionChangeTriggers(ServerLevel level)
    • broadcastToPlayer

      public boolean broadcastToPlayer(ServerPlayer player)
      Overrides:
      broadcastToPlayer in class Entity
    • take

      public void take(Entity entity, int quantity)
      Called when the entity picks up an item.
      Overrides:
      take in class LivingEntity
    • startSleepInBed

      public com.mojang.datafixers.util.Either<Player.BedSleepingProblem,Unit> startSleepInBed(BlockPos at)
      Overrides:
      startSleepInBed in class Player
    • startSleeping

      public void startSleeping(BlockPos pos)
      Overrides:
      startSleeping in class LivingEntity
    • bedInRange

      private boolean bedInRange(BlockPos pos, Direction direction)
    • isReachableBedBlock

      private boolean isReachableBedBlock(BlockPos pos)
    • bedBlocked

      private boolean bedBlocked(BlockPos pos, Direction direction)
    • stopSleepInBed

      public void stopSleepInBed(boolean wakeImmediately, boolean updateLevelForSleepingPlayers)
      Overrides:
      stopSleepInBed in class Player
    • dismountTo

      public void dismountTo(double x, double y, double z)
      Overrides:
      dismountTo in class Entity
    • isInvulnerableTo

      public boolean isInvulnerableTo(DamageSource source)
      Returns whether this Entity is invulnerable to the given DamageSource.
      Overrides:
      isInvulnerableTo in class Player
    • checkFallDamage

      protected void checkFallDamage(double y, boolean onGround, BlockState state, BlockPos pos)
      Overrides:
      checkFallDamage in class LivingEntity
    • onChangedBlock

      protected void onChangedBlock(ServerLevel level, BlockPos pos)
      Overrides:
      onChangedBlock in class LivingEntity
    • doCheckFallDamage

      public void doCheckFallDamage(double movementX, double movementY, double movementZ, boolean onGround)
    • onExplosionHit

      public void onExplosionHit(@Nullable Entity entity)
      Overrides:
      onExplosionHit in class Entity
    • pushEntities

      protected void pushEntities()
      Overrides:
      pushEntities in class LivingEntity
    • openTextEdit

      public void openTextEdit(SignBlockEntity signEntity, boolean isFrontText)
      Overrides:
      openTextEdit in class Player
    • nextContainerCounter

      private void nextContainerCounter()
    • openMenu

      public OptionalInt openMenu(@Nullable MenuProvider menu)
      Overrides:
      openMenu in class Player
    • openMenu

      public OptionalInt openMenu(@Nullable MenuProvider menu, @Nullable Consumer<RegistryFriendlyByteBuf> extraDataWriter)
      Description copied from interface: IPlayerExtension
      Request to open a GUI on the client, from the server

      Refer to IMenuTypeExtension.create(IContainerFactory) for creating a MenuType that can consume the extra data sent to the client by this method.

      The maximum size for #extraDataWriter is 32600 bytes.

      Parameters:
      menu - A supplier of container properties including the registry name of the container
      extraDataWriter - Consumer to write any additional data the GUI needs. This data is written after
      invalid reference
      IMenuProviderExtension#writeClientSideData(AbstractContainerMenu, RegistryFriendlyByteBuf)
      .
      Returns:
      The window ID of the opened GUI, or empty if the GUI could not be opened
    • sendMerchantOffers

      public void sendMerchantOffers(int containerId, MerchantOffers offers, int level, int xp, boolean showProgress, boolean canRestock)
      Overrides:
      sendMerchantOffers in class Player
    • openHorseInventory

      public void openHorseInventory(AbstractHorse horse, Container inventory)
      Overrides:
      openHorseInventory in class Player
    • openItemGui

      public void openItemGui(ItemStack stack, InteractionHand hand)
      Overrides:
      openItemGui in class Player
    • openCommandBlock

      public void openCommandBlock(CommandBlockEntity commandBlock)
      Overrides:
      openCommandBlock in class Player
    • closeContainer

      public void closeContainer()
      Overrides:
      closeContainer in class Player
    • doCloseContainer

      public void doCloseContainer()
      Overrides:
      doCloseContainer in class Player
    • setPlayerInput

      public void setPlayerInput(float strafe, float forward, boolean jumping, boolean sneaking)
    • travel

      public void travel(Vec3 travelVector)
      Overrides:
      travel in class Player
    • rideTick

      public void rideTick()
      Overrides:
      rideTick in class Player
    • checkMovementStatistics

      public void checkMovementStatistics(double dx, double dy, double dz)
    • checkRidingStatistics

      public void checkRidingStatistics(double dx, double dy, double dz)
    • didNotMove

      private static boolean didNotMove(double dx, double dy, double dz)
    • awardStat

      public void awardStat(Stat<?> stat, int amount)
      Adds a value to a statistic field.
      Overrides:
      awardStat in class Player
    • resetStat

      public void resetStat(Stat<?> stat)
      Overrides:
      resetStat in class Player
    • awardRecipes

      public int awardRecipes(Collection<RecipeHolder<?>> recipes)
      Overrides:
      awardRecipes in class Player
    • triggerRecipeCrafted

      public void triggerRecipeCrafted(RecipeHolder<?> recipe, List<ItemStack> items)
      Overrides:
      triggerRecipeCrafted in class Player
    • awardRecipesByKey

      public void awardRecipesByKey(List<ResourceLocation> recipes)
      Overrides:
      awardRecipesByKey in class Player
    • resetRecipes

      public int resetRecipes(Collection<RecipeHolder<?>> recipes)
      Overrides:
      resetRecipes in class Player
    • giveExperiencePoints

      public void giveExperiencePoints(int xpPoints)
      Overrides:
      giveExperiencePoints in class Player
    • disconnect

      public void disconnect()
    • hasDisconnected

      public boolean hasDisconnected()
    • resetSentInfo

      public void resetSentInfo()
    • displayClientMessage

      public void displayClientMessage(Component chatComponent, boolean actionBar)
      Overrides:
      displayClientMessage in class Player
    • completeUsingItem

      protected void completeUsingItem()
      Overrides:
      completeUsingItem in class LivingEntity
    • lookAt

      public void lookAt(EntityAnchorArgument.Anchor anchor, Vec3 target)
      Overrides:
      lookAt in class LivingEntity
    • lookAt

      public void lookAt(EntityAnchorArgument.Anchor fromAnchor, Entity entity, EntityAnchorArgument.Anchor toAnchor)
    • restoreFrom

      public void restoreFrom(ServerPlayer that, boolean keepEverything)
    • onEffectAdded

      protected void onEffectAdded(MobEffectInstance effectInstance, @Nullable Entity entity)
      Overrides:
      onEffectAdded in class LivingEntity
    • onEffectUpdated

      protected void onEffectUpdated(MobEffectInstance effectInstance, boolean forced, @Nullable Entity entity)
      Overrides:
      onEffectUpdated in class LivingEntity
    • onEffectRemoved

      protected void onEffectRemoved(MobEffectInstance effect)
      Overrides:
      onEffectRemoved in class LivingEntity
    • teleportTo

      public void teleportTo(double x, double y, double z)
      Sets the position of the entity and updates the 'last' variables
      Overrides:
      teleportTo in class Entity
    • teleportRelative

      public void teleportRelative(double dx, double dy, double dz)
      Overrides:
      teleportRelative in class Entity
    • teleportTo

      public boolean teleportTo(ServerLevel level, double x, double y, double z, Set<RelativeMovement> relativeMovements, float yRot, float xRot)
      Overrides:
      teleportTo in class Entity
    • moveTo

      public void moveTo(double x, double y, double z)
      Overrides:
      moveTo in class Entity
    • crit

      public void crit(Entity entityHit)
      Called when the entity is dealt a critical hit.
      Overrides:
      crit in class Player
    • magicCrit

      public void magicCrit(Entity entityHit)
      Called when the entity hit is dealt extra melee damage due to an enchantment.
      Overrides:
      magicCrit in class Player
    • onUpdateAbilities

      public void onUpdateAbilities()
      Overrides:
      onUpdateAbilities in class Player
    • serverLevel

      public ServerLevel serverLevel()
    • setGameMode

      public boolean setGameMode(GameType gameMode)
    • isSpectator

      public boolean isSpectator()
      Specified by:
      isSpectator in class Player
    • isCreative

      public boolean isCreative()
      Specified by:
      isCreative in class Player
    • sendSystemMessage

      public void sendSystemMessage(Component component)
      Specified by:
      sendSystemMessage in interface CommandSource
      Overrides:
      sendSystemMessage in class Entity
    • sendSystemMessage

      public void sendSystemMessage(Component p_component, boolean bypassHiddenChat)
    • sendChatMessage

      public void sendChatMessage(OutgoingChatMessage message, boolean filtered, ChatType.Bound boundType)
    • getIpAddress

      public String getIpAddress()
    • updateOptions

      public void updateOptions(ClientInformation clientInformation)
    • clientInformation

      public ClientInformation clientInformation()
    • canChatInColor

      public boolean canChatInColor()
    • getChatVisibility

      public ChatVisiblity getChatVisibility()
    • acceptsSystemMessages

      private boolean acceptsSystemMessages(boolean bypassHiddenChat)
    • acceptsChatMessages

      private boolean acceptsChatMessages()
    • requestedViewDistance

      public int requestedViewDistance()
    • sendServerStatus

      public void sendServerStatus(ServerStatus serverStatus)
    • getPermissionLevel

      protected int getPermissionLevel()
      Overrides:
      getPermissionLevel in class Entity
    • resetLastActionTime

      public void resetLastActionTime()
    • getStats

      public ServerStatsCounter getStats()
    • getRecipeBook

      public ServerRecipeBook getRecipeBook()
    • updateInvisibilityStatus

      protected void updateInvisibilityStatus()
      Overrides:
      updateInvisibilityStatus in class LivingEntity
    • getCamera

      public Entity getCamera()
    • setCamera

      public void setCamera(@Nullable Entity entityToSpectate)
    • processPortalCooldown

      protected void processPortalCooldown()
      Overrides:
      processPortalCooldown in class Entity
    • attack

      public void attack(Entity targetEntity)
      Attacks for the player the targeted entity with the currently equipped item. The equipped item has hitEntity called on it. Args: targetEntity
      Overrides:
      attack in class Player
    • getLastActionTime

      public long getLastActionTime()
    • getTabListDisplayName

      @Nullable public Component getTabListDisplayName()
    • swing

      public void swing(InteractionHand hand)
      Overrides:
      swing in class LivingEntity
    • isChangingDimension

      public boolean isChangingDimension()
    • hasChangedDimension

      public void hasChangedDimension()
    • getAdvancements

      public PlayerAdvancements getAdvancements()
    • teleportTo

      public void teleportTo(ServerLevel newLevel, double x, double y, double z, float yaw, float pitch)
    • getRespawnPosition

      @Nullable public BlockPos getRespawnPosition()
    • getRespawnAngle

      public float getRespawnAngle()
    • getRespawnDimension

      public ResourceKey<Level> getRespawnDimension()
    • isRespawnForced

      public boolean isRespawnForced()
    • copyRespawnPosition

      public void copyRespawnPosition(ServerPlayer player)
    • setRespawnPosition

      public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos position, float angle, boolean forced, boolean sendMessage)
    • getLastSectionPos

      public SectionPos getLastSectionPos()
    • setLastSectionPos

      public void setLastSectionPos(SectionPos sectionPos)
    • getChunkTrackingView

      public ChunkTrackingView getChunkTrackingView()
    • setChunkTrackingView

      public void setChunkTrackingView(ChunkTrackingView chunkTrackingView)
    • playNotifySound

      public void playNotifySound(SoundEvent sound, SoundSource source, float volume, float pitch)
      Overrides:
      playNotifySound in class Player
    • drop

      public ItemEntity drop(ItemStack droppedItem, boolean dropAround, boolean traceItem)
      Creates and drops the provided item. Depending on the dropAround, it will drop the item around the player, instead of dropping the item from where the player is pointing at. Likewise, if includeThrowerName is true, the dropped item entity will have the thrower set as the player.
      Overrides:
      drop in class Player
    • getLanguage

      public String getLanguage()
      Returns the language last reported by the player as their local language. Defaults to en_us if the value is unknown.
    • getTabListHeader

      public Component getTabListHeader()
    • setTabListHeader

      public void setTabListHeader(Component header)
      Set the tab list header while preserving the footer.
      Parameters:
      header - the new header, or Component.empty() to clear
    • getTabListFooter

      public Component getTabListFooter()
    • setTabListFooter

      public void setTabListFooter(Component footer)
      Set the tab list footer while preserving the header.
      Parameters:
      footer - the new footer, or Component.empty() to clear
    • setTabListHeaderFooter

      public void setTabListHeaderFooter(Component header, Component footer)
      Set the tab list header and footer at once.
      Parameters:
      header - the new header, or Component.empty() to clear
      footer - the new footer, or Component.empty() to clear
    • refreshTabListName

      public void refreshTabListName()
      Force the name displayed in the tab list to refresh, by firing PlayerEvent.TabListNameFormat.
    • getTextFilter

      public TextFilter getTextFilter()
    • setServerLevel

      public void setServerLevel(ServerLevel level)
    • readPlayerMode

      @Nullable private static GameType readPlayerMode(@Nullable CompoundTag tag, String key)
    • calculateGameModeForNewPlayer

      private GameType calculateGameModeForNewPlayer(@Nullable GameType gameType)
    • loadGameTypes

      public void loadGameTypes(@Nullable CompoundTag tag)
    • storeGameTypes

      private void storeGameTypes(CompoundTag tag)
    • isTextFilteringEnabled

      public boolean isTextFilteringEnabled()
      Overrides:
      isTextFilteringEnabled in class Player
    • shouldFilterMessageTo

      public boolean shouldFilterMessageTo(ServerPlayer player)
    • mayInteract

      public boolean mayInteract(Level level, BlockPos pos)
      Overrides:
      mayInteract in class Entity
    • updateUsingItem

      protected void updateUsingItem(ItemStack usingItem)
      Overrides:
      updateUsingItem in class LivingEntity
    • drop

      public boolean drop(boolean dropStack)
      Parameters:
      dropStack - Whether to drop the entire stack of items. If false, drops a single item.
    • allowsListing

      public boolean allowsListing()
    • getWardenSpawnTracker

      public Optional<WardenSpawnTracker> getWardenSpawnTracker()
      Overrides:
      getWardenSpawnTracker in class Player
    • setSpawnExtraParticlesOnFall

      public void setSpawnExtraParticlesOnFall(boolean spawnExtraParticlesOnFall)
    • onItemPickup

      public void onItemPickup(ItemEntity itemEntity)
      Overrides:
      onItemPickup in class LivingEntity
    • setChatSession

      public void setChatSession(RemoteChatSession chatSession)
    • getChatSession

      @Nullable public RemoteChatSession getChatSession()
    • indicateDamage

      public void indicateDamage(double xDistance, double zDistance)
      Overrides:
      indicateDamage in class LivingEntity
    • startRiding

      public boolean startRiding(Entity vehicle, boolean force)
      Overrides:
      startRiding in class Entity
    • stopRiding

      public void stopRiding()
      Overrides:
      stopRiding in class LivingEntity
    • createCommonSpawnInfo

      public CommonPlayerSpawnInfo createCommonSpawnInfo(ServerLevel level)
    • setRaidOmenPosition

      public void setRaidOmenPosition(BlockPos raidOmenPosition)
    • clearRaidOmenPosition

      public void clearRaidOmenPosition()
    • getRaidOmenPosition

      @Nullable public BlockPos getRaidOmenPosition()
    • getKnownMovement

      public Vec3 getKnownMovement()
      Overrides:
      getKnownMovement in class Entity
    • setKnownMovement

      public void setKnownMovement(Vec3 knownMovement)
    • getEnchantedDamage

      protected float getEnchantedDamage(Entity entity, float damage, DamageSource damageSource)
      Overrides:
      getEnchantedDamage in class Player
    • onEquippedItemBroken

      public void onEquippedItemBroken(Item item, EquipmentSlot slot)
      Overrides:
      onEquippedItemBroken in class LivingEntity