Class ServerLevel

All Implemented Interfaces:
AutoCloseable, BiomeManager.NoiseBiomeSource, BlockAndTintGetter, BlockGetter, CollisionGetter, CommonLevelAccessor, EntityGetter, LevelAccessor, LevelHeightAccessor, LevelReader, LevelSimulatedReader, LevelSimulatedRW, LevelTimeAccess, LevelWriter, ServerLevelAccessor, SignalGetter, WorldGenLevel, IAttachmentHolder, IBlockAndTintGetterExtension, IBlockGetterExtension, ILevelExtension, ILevelReaderExtension

public class ServerLevel extends Level implements WorldGenLevel
  • Field Details

    • END_SPAWN_POINT

      public static final BlockPos END_SPAWN_POINT
    • RAIN_DELAY

      public static final IntProvider RAIN_DELAY
    • RAIN_DURATION

      public static final IntProvider RAIN_DURATION
    • THUNDER_DELAY

      private static final IntProvider THUNDER_DELAY
    • THUNDER_DURATION

      public static final IntProvider THUNDER_DURATION
    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • EMPTY_TIME_NO_TICK

      private static final int EMPTY_TIME_NO_TICK
      See Also:
    • MAX_SCHEDULED_TICKS_PER_TICK

      private static final int MAX_SCHEDULED_TICKS_PER_TICK
      See Also:
    • players

      final List<ServerPlayer> players
    • chunkSource

      private final ServerChunkCache chunkSource
    • server

      private final MinecraftServer server
    • serverLevelData

      private final ServerLevelData serverLevelData
    • lastSpawnChunkRadius

      private int lastSpawnChunkRadius
    • entityTickList

      final EntityTickList entityTickList
    • entityManager

      private final PersistentEntitySectionManager<Entity> entityManager
    • gameEventDispatcher

      private final GameEventDispatcher gameEventDispatcher
    • noSave

      public boolean noSave
    • sleepStatus

      private final SleepStatus sleepStatus
    • emptyTime

      private int emptyTime
    • portalForcer

      private final PortalForcer portalForcer
    • blockTicks

      private final LevelTicks<Block> blockTicks
    • fluidTicks

      private final LevelTicks<Fluid> fluidTicks
    • pathTypesByPosCache

      private final PathTypeCache pathTypesByPosCache
    • isUpdatingNavigations

      volatile boolean isUpdatingNavigations
    • raids

      protected final Raids raids
    • blockEvents

      private final it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet<BlockEventData> blockEvents
    • blockEventsToReschedule

      private final List<BlockEventData> blockEventsToReschedule
    • handlingTick

      private boolean handlingTick
    • customSpawners

      private final List<CustomSpawner> customSpawners
    • dragonFight

      @Nullable private EndDragonFight dragonFight
    • dragonParts

      final it.unimi.dsi.fastutil.ints.Int2ObjectMap<PartEntity<?>> dragonParts
    • structureManager

      private final StructureManager structureManager
    • structureCheck

      private final StructureCheck structureCheck
    • tickTime

      private final boolean tickTime
    • randomSequences

      private final RandomSequences randomSequences
    • capListenerHolder

      private final CapabilityListenerHolder capListenerHolder
  • Constructor Details

  • Method Details

    • setDragonFight

      @Deprecated public void setDragonFight(@Nullable EndDragonFight pDragonFight)
      Deprecated.
    • setWeatherParameters

      public void setWeatherParameters(int pClearTime, int pWeatherTime, boolean pIsRaining, boolean pIsThundering)
    • getUncachedNoiseBiome

      public Holder<Biome> getUncachedNoiseBiome(int pX, int pY, int pZ)
      Specified by:
      getUncachedNoiseBiome in interface LevelReader
    • structureManager

      public StructureManager structureManager()
    • tick

      public void tick(BooleanSupplier pHasTimeLeft)
      Runs a single tick for the world
    • shouldTickBlocksAt

      public boolean shouldTickBlocksAt(long pChunkPos)
      Overrides:
      shouldTickBlocksAt in class Level
    • tickTime

      protected void tickTime()
    • setDayTime

      public void setDayTime(long pTime)
    • tickCustomSpawners

      public void tickCustomSpawners(boolean pSpawnEnemies, boolean pSpawnFriendlies)
    • shouldDiscardEntity

      private boolean shouldDiscardEntity(Entity pEntity)
    • wakeUpAllPlayers

      private void wakeUpAllPlayers()
    • tickChunk

      public void tickChunk(LevelChunk pChunk, int pRandomTickSpeed)
    • tickPrecipitation

      public void tickPrecipitation(BlockPos pBlockPos)
    • findLightningRod

      private Optional<BlockPos> findLightningRod(BlockPos pPos)
    • findLightningTargetAround

      protected BlockPos findLightningTargetAround(BlockPos pPos)
    • isHandlingTick

      public boolean isHandlingTick()
    • canSleepThroughNights

      public boolean canSleepThroughNights()
    • announceSleepStatus

      private void announceSleepStatus()
    • updateSleepingPlayerList

      public void updateSleepingPlayerList()
    • getScoreboard

      public ServerScoreboard getScoreboard()
      Specified by:
      getScoreboard in class Level
    • advanceWeatherCycle

      private void advanceWeatherCycle()
    • resetWeatherCycle

      public void resetWeatherCycle()
    • resetEmptyTime

      public void resetEmptyTime()
    • tickFluid

      private void tickFluid(BlockPos p_184077_, Fluid p_184078_)
    • tickBlock

      private void tickBlock(BlockPos p_184113_, Block p_184114_)
    • tickNonPassenger

      public void tickNonPassenger(Entity p_8648_)
    • tickPassenger

      private void tickPassenger(Entity pRidingEntity, Entity pPassengerEntity)
    • mayInteract

      public boolean mayInteract(Player pPlayer, BlockPos pPos)
      Overrides:
      mayInteract in class Level
    • save

      public void save(@Nullable ProgressListener pProgress, boolean pFlush, boolean pSkipSave)
    • saveLevelData

      private void saveLevelData()
    • getEntities

      public <T extends Entity> List<? extends T> getEntities(EntityTypeTest<Entity,T> pTypeTest, Predicate<? super T> pPredicate)
    • getEntities

      public <T extends Entity> void getEntities(EntityTypeTest<Entity,T> pTypeTest, Predicate<? super T> pPredicate, List<? super T> pOutput)
    • getEntities

      public <T extends Entity> void getEntities(EntityTypeTest<Entity,T> pTypeTest, Predicate<? super T> pPredicate, List<? super T> pOutput, int pMaxResults)
    • getDragons

      public List<? extends EnderDragon> getDragons()
    • getPlayers

      public List<ServerPlayer> getPlayers(Predicate<? super ServerPlayer> pPredicate)
    • getPlayers

      public List<ServerPlayer> getPlayers(Predicate<? super ServerPlayer> pPredicate, int pMaxResults)
    • getRandomPlayer

      @Nullable public ServerPlayer getRandomPlayer()
    • addFreshEntity

      public boolean addFreshEntity(Entity pEntity)
      Specified by:
      addFreshEntity in interface LevelWriter
    • addWithUUID

      public boolean addWithUUID(Entity pEntity)
      Used for "unnatural" ways of entities appearing in the world, e.g. summon command, interdimensional teleports
    • addDuringTeleport

      public void addDuringTeleport(Entity pEntity)
    • addNewPlayer

      public void addNewPlayer(ServerPlayer pPlayer)
    • addRespawnedPlayer

      public void addRespawnedPlayer(ServerPlayer pPlayer)
    • addPlayer

      private void addPlayer(ServerPlayer pPlayer)
    • addEntity

      private boolean addEntity(Entity pEntity)
      Called when an entity is spawned in the world. This includes players.
    • tryAddFreshEntityWithPassengers

      public boolean tryAddFreshEntityWithPassengers(Entity pEntity)
      Attempts to summon an entity and it's passangers. They will only be summoned if all entities are unique and not already in queue to be summoned.
    • unload

      public void unload(LevelChunk pChunk)
    • removePlayerImmediately

      public void removePlayerImmediately(ServerPlayer pPlayer, Entity.RemovalReason pReason)
    • destroyBlockProgress

      public void destroyBlockProgress(int pBreakerId, BlockPos pPos, int pProgress)
      Specified by:
      destroyBlockProgress in class Level
    • playSeededSound

      public void playSeededSound(@Nullable Player pPlayer, double pX, double pY, double pZ, Holder<SoundEvent> pSound, SoundSource pCategory, float pVolume, float pPitch, long pSeed)
      Specified by:
      playSeededSound in class Level
    • playSeededSound

      public void playSeededSound(@Nullable Player pPlayer, Entity pEntity, Holder<SoundEvent> pSound, SoundSource pCategory, float pVolume, float pPitch, long pSeed)
      Specified by:
      playSeededSound in class Level
    • globalLevelEvent

      public void globalLevelEvent(int pId, BlockPos pPos, int pData)
      Overrides:
      globalLevelEvent in class Level
    • levelEvent

      public void levelEvent(@Nullable Player pPlayer, int pType, BlockPos pPos, int pData)
      Specified by:
      levelEvent in interface LevelAccessor
    • getLogicalHeight

      public int getLogicalHeight()
    • gameEvent

      public void gameEvent(Holder<GameEvent> pGameEvent, Vec3 pPos, GameEvent.Context pContext)
      Specified by:
      gameEvent in interface LevelAccessor
    • sendBlockUpdated

      public void sendBlockUpdated(BlockPos pPos, BlockState pOldState, BlockState pNewState, int pFlags)
      Flags are as in setBlockState
      Specified by:
      sendBlockUpdated in class Level
    • updateNeighborsAt

      public void updateNeighborsAt(BlockPos pPos, Block pBlock)
      Overrides:
      updateNeighborsAt in class Level
    • updateNeighborsAtExceptFromFacing

      public void updateNeighborsAtExceptFromFacing(BlockPos pPos, Block pBlockType, Direction pSkipSide)
      Overrides:
      updateNeighborsAtExceptFromFacing in class Level
    • neighborChanged

      public void neighborChanged(BlockPos pPos, Block pBlock, BlockPos pFromPos)
      Overrides:
      neighborChanged in class Level
    • neighborChanged

      public void neighborChanged(BlockState pState, BlockPos pPos, Block pBlock, BlockPos pFromPos, boolean pIsMoving)
      Overrides:
      neighborChanged in class Level
    • broadcastEntityEvent

      public void broadcastEntityEvent(Entity pEntity, byte pState)
      Sends a ClientboundEntityEventPacket to all tracked players of that entity.
      Overrides:
      broadcastEntityEvent in class Level
    • broadcastDamageEvent

      public void broadcastDamageEvent(Entity pEntity, DamageSource pDamageSource)
      Overrides:
      broadcastDamageEvent in class Level
    • getChunkSource

      public ServerChunkCache getChunkSource()
      Specified by:
      getChunkSource in interface LevelAccessor
    • explode

      public Explosion explode(@Nullable Entity pSource, @Nullable DamageSource pDamageSource, @Nullable ExplosionDamageCalculator pDamageCalculator, double pX, double pY, double pZ, float pRadius, boolean pFire, Level.ExplosionInteraction pExplosionInteraction, ParticleOptions pSmallExplosionParticles, ParticleOptions pLargeExplosionParticles, Holder<SoundEvent> pExplosionSound)
      Overrides:
      explode in class Level
    • blockEvent

      public void blockEvent(BlockPos pPos, Block pBlock, int pEventID, int pEventParam)
      Overrides:
      blockEvent in class Level
    • runBlockEvents

      private void runBlockEvents()
    • doBlockEvent

      private boolean doBlockEvent(BlockEventData pEvent)
    • getBlockTicks

      public LevelTicks<Block> getBlockTicks()
      Specified by:
      getBlockTicks in interface LevelAccessor
    • getFluidTicks

      public LevelTicks<Fluid> getFluidTicks()
      Specified by:
      getFluidTicks in interface LevelAccessor
    • getServer

      @Nonnull public MinecraftServer getServer()
      Specified by:
      getServer in interface LevelAccessor
      Overrides:
      getServer in class Level
    • getPortalForcer

      public PortalForcer getPortalForcer()
    • getStructureManager

      public StructureTemplateManager getStructureManager()
    • sendParticles

      public <T extends ParticleOptions> int sendParticles(T pType, double pPosX, double pPosY, double pPosZ, int pParticleCount, double pXOffset, double pYOffset, double pZOffset, double pSpeed)
    • sendParticles

      public <T extends ParticleOptions> boolean sendParticles(ServerPlayer pPlayer, T pType, boolean pLongDistance, double pPosX, double pPosY, double pPosZ, int pParticleCount, double pXOffset, double pYOffset, double pZOffset, double pSpeed)
    • sendParticles

      private boolean sendParticles(ServerPlayer pPlayer, boolean pLongDistance, double pPosX, double pPosY, double pPosZ, Packet<?> pPacket)
    • getEntity

      @Nullable public Entity getEntity(int pId)
      Returns the Entity with the given ID, or null if it doesn't exist in this World.
      Specified by:
      getEntity in class Level
    • getEntityOrPart

      @Deprecated @Nullable public Entity getEntityOrPart(int pId)
      Deprecated.
    • getEntity

      @Nullable public Entity getEntity(UUID pUniqueId)
    • findNearestMapStructure

      @Nullable public BlockPos findNearestMapStructure(TagKey<Structure> pStructureTag, BlockPos pPos, int pRadius, boolean pSkipExistingChunks)
    • findClosestBiome3d

      @Nullable public com.mojang.datafixers.util.Pair<BlockPos,Holder<Biome>> findClosestBiome3d(Predicate<Holder<Biome>> p_215070_, BlockPos p_215071_, int p_215072_, int p_215073_, int p_215074_)
    • getRecipeManager

      public RecipeManager getRecipeManager()
      Specified by:
      getRecipeManager in class Level
    • tickRateManager

      public TickRateManager tickRateManager()
      Specified by:
      tickRateManager in class Level
    • noSave

      public boolean noSave()
      Overrides:
      noSave in class Level
    • getDataStorage

      public DimensionDataStorage getDataStorage()
    • getMapData

      @Nullable public MapItemSavedData getMapData(MapId pMapId)
      Specified by:
      getMapData in class Level
    • setMapData

      public void setMapData(MapId pMapId, MapItemSavedData pMapData)
      Specified by:
      setMapData in class Level
    • getFreeMapId

      public MapId getFreeMapId()
      Specified by:
      getFreeMapId in class Level
    • setDefaultSpawnPos

      public void setDefaultSpawnPos(BlockPos pPos, float pAngle)
    • getForcedChunks

      public it.unimi.dsi.fastutil.longs.LongSet getForcedChunks()
    • setChunkForced

      public boolean setChunkForced(int pChunkX, int pChunkZ, boolean pAdd)
    • players

      public List<ServerPlayer> players()
      Specified by:
      players in interface EntityGetter
    • onBlockStateChange

      public void onBlockStateChange(BlockPos pPos, BlockState pBlockState, BlockState pNewState)
      Overrides:
      onBlockStateChange in class Level
    • getPoiManager

      public PoiManager getPoiManager()
    • isVillage

      public boolean isVillage(BlockPos pPos)
    • isVillage

      public boolean isVillage(SectionPos pPos)
    • isCloseToVillage

      public boolean isCloseToVillage(BlockPos pPos, int pSections)
    • sectionsToVillage

      public int sectionsToVillage(SectionPos pPos)
    • getRaids

      public Raids getRaids()
    • getRaidAt

      @Nullable public Raid getRaidAt(BlockPos pPos)
    • isRaided

      public boolean isRaided(BlockPos pPos)
    • onReputationEvent

      public void onReputationEvent(ReputationEventType pType, Entity pTarget, ReputationEventHandler pHost)
    • saveDebugReport

      public void saveDebugReport(Path pPath) throws IOException
      Throws:
      IOException
    • dumpEntities

      private static void dumpEntities(Writer pWriter, Iterable<Entity> pEntities) throws IOException
      Throws:
      IOException
    • dumpBlockEntityTickers

      private void dumpBlockEntityTickers(Writer pOutput) throws IOException
      Throws:
      IOException
    • clearBlockEvents

      public void clearBlockEvents(BoundingBox pBoundingBox)
    • blockUpdated

      public void blockUpdated(BlockPos pPos, Block pBlock)
      Specified by:
      blockUpdated in interface LevelAccessor
    • getShade

      public float getShade(Direction pDirection, boolean pShade)
      Specified by:
      getShade in interface BlockAndTintGetter
    • getAllEntities

      public Iterable<Entity> getAllEntities()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isFlat

      public boolean isFlat()
    • getSeed

      public long getSeed()
      Specified by:
      getSeed in interface WorldGenLevel
    • getDragonFight

      @Nullable public EndDragonFight getDragonFight()
    • getLevel

      public ServerLevel getLevel()
      Specified by:
      getLevel in interface ServerLevelAccessor
    • getWatchdogStats

      public String getWatchdogStats()
    • getTypeCount

      private static <T> String getTypeCount(Iterable<T> pObjects, Function<T,String> pTypeGetter)
    • getEntities

      public LevelEntityGetter<Entity> getEntities()
      Specified by:
      getEntities in class Level
    • addLegacyChunkEntities

      public void addLegacyChunkEntities(Stream<Entity> pEntities)
    • addWorldGenChunkEntities

      public void addWorldGenChunkEntities(Stream<Entity> pEntities)
    • startTickingChunk

      public void startTickingChunk(LevelChunk pChunk)
    • onStructureStartsAvailable

      public void onStructureStartsAvailable(ChunkAccess pChunk)
    • getPathTypeCache

      public PathTypeCache getPathTypeCache()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class Level
      Throws:
      IOException
    • gatherChunkSourceStats

      public String gatherChunkSourceStats()
      Specified by:
      gatherChunkSourceStats in class Level
    • areEntitiesLoaded

      public boolean areEntitiesLoaded(long pChunkPos)
    • isPositionTickingWithEntitiesLoaded

      private boolean isPositionTickingWithEntitiesLoaded(long p_184111_)
    • isPositionEntityTicking

      public boolean isPositionEntityTicking(BlockPos pPos)
    • isNaturalSpawningAllowed

      public boolean isNaturalSpawningAllowed(BlockPos pPos)
    • isNaturalSpawningAllowed

      public boolean isNaturalSpawningAllowed(ChunkPos pChunkPos)
    • enabledFeatures

      public FeatureFlagSet enabledFeatures()
      Specified by:
      enabledFeatures in interface LevelReader
    • potionBrewing

      public PotionBrewing potionBrewing()
      Specified by:
      potionBrewing in class Level
    • getRandomSequence

      public RandomSource getRandomSequence(ResourceLocation pLocation)
    • getRandomSequences

      public RandomSequences getRandomSequences()
    • fillReportDetails

      public CrashReportCategory fillReportDetails(CrashReport pReport)
      Adds some basic stats of the world to the given crash report.
      Overrides:
      fillReportDetails in class Level
    • getPartEntities

      public Collection<PartEntity<?>> getPartEntities()
      Description copied from interface: ILevelExtension
      All part entities in this world. Used when collecting entities in an AABB to fix parts being ignored whose parent entity is in a chunk that does not intersect with the AABB.
      Specified by:
      getPartEntities in interface ILevelExtension
    • invalidateCapabilities

      public void invalidateCapabilities(BlockPos pos)
      Description copied from interface: ILevelExtension
      Notify all listeners that the capabilities at a specific position might have changed. This includes new capabilities becoming available.

      This method will only do something on ServerLevels, but it is safe to call on any Level, without the need for an instanceof check.

      If you already have a block entity at that position, you can call IBlockEntityExtension.invalidateCapabilities() instead.

      Specified by:
      invalidateCapabilities in interface ILevelExtension
    • invalidateCapabilities

      public void invalidateCapabilities(ChunkPos pos)
      Description copied from interface: ILevelExtension
      Notify all listeners that the capabilities at all the positions in a chunk might have changed. This includes new capabilities becoming available.

      This method will only do something on ServerLevels, but it is safe to call on any Level, without the need for an instanceof check.

      Specified by:
      invalidateCapabilities in interface ILevelExtension
    • registerCapabilityListener

      public void registerCapabilityListener(BlockPos pos, ICapabilityInvalidationListener listener)
      Register a listener for capability invalidation.
      See Also:
    • cleanCapabilityListenerReferences

      @Internal public void cleanCapabilityListenerReferences()
      Internal method, used to clean capability listeners that are not referenced. Do not call.
    • setDayTimeFraction

      @Internal public void setDayTimeFraction(float dayTimeFraction)
      Specified by:
      setDayTimeFraction in class Level
    • getDayTimeFraction

      @Internal public float getDayTimeFraction()
      Specified by:
      getDayTimeFraction in class Level
    • getDayTimePerTick

      public float getDayTimePerTick()
      Returns the current ratio between game ticks and clock ticks. If this value is negative, no speed has been set and those two are coupled 1:1 (i.e. vanilla mode).
      Specified by:
      getDayTimePerTick in class Level
    • setDayTimePerTick

      public void setDayTimePerTick(float dayTimePerTick)
      This allows mods to set the rate time flows in a level. By default, each game tick the clock time also advances by one tick, with Level.TICKS_PER_DAY clock ticks (or 20 real-life minutes) forming a Minecraft day.

      This can be sped up for shorter days by giving a higher number, or slowed down for longer days with a smaller number. A negative value will reset it back to vanilla logic.

      This value can also be changed with the command /neoforge day, where you can set either the speed or a day length in minutes.

      This has no effect when time progression is stopped.

      While this still technically works when vanilla clients are connected, those will desync and experience a time jump once per second.

      Specified by:
      setDayTimePerTick in class Level