Class ServerLevel

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

public class ServerLevel extends Level implements ServerEntityGetter, 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 p_203775_, int p_203776_, int p_203777_)
      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 p_184059_)
      Overrides:
      shouldTickBlocksAt in class Level
    • tickTime

      protected void tickTime()
    • setDayTime

      public void setDayTime(long pTime)
    • tickCustomSpawners

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

      private void wakeUpAllPlayers()
    • tickChunk

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

      public void tickThunder(LevelChunk pChunk)
    • 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 pPos, Fluid pFluid)
    • tickBlock

      private void tickBlock(BlockPos pPos, Block pBlock)
    • tickNonPassenger

      public void tickNonPassenger(Entity pEntity)
    • tickPassenger

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

      public boolean mayInteract(Entity p_393624_, BlockPos p_8697_)
      Overrides:
      mayInteract in class Level
    • save

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

      private void saveLevelData(boolean pJoin)
    • 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 Entity p_393855_, double p_263393_, double p_263369_, double p_263354_, Holder<SoundEvent> p_263412_, SoundSource p_263338_, float p_263352_, float p_263390_, long p_263403_)
      Specified by:
      playSeededSound in class Level
    • playSeededSound

      public void playSeededSound(@Nullable Entity p_263544_, Entity p_394316_, Holder<SoundEvent> p_263491_, SoundSource p_263542_, float p_263530_, float p_263520_, long p_263490_)
      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 Entity p_393790_, int p_8685_, BlockPos p_8686_, int p_8687_)
      Specified by:
      levelEvent in interface LevelAccessor
    • getLogicalHeight

      public int getLogicalHeight()
    • gameEvent

      public void gameEvent(Holder<GameEvent> p_316597_, Vec3 p_215042_, GameEvent.Context p_215043_)
      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 p_215045_, Block p_215046_)
      Specified by:
      updateNeighborsAt in interface LevelAccessor
    • updateNeighborsAt

      public void updateNeighborsAt(BlockPos p_363893_, Block p_362383_, @Nullable Orientation p_364696_)
      Overrides:
      updateNeighborsAt in class Level
    • updateNeighborsAtExceptFromFacing

      public void updateNeighborsAtExceptFromFacing(BlockPos p_215052_, Block p_215053_, Direction p_215054_, @Nullable Orientation p_365231_)
      Overrides:
      updateNeighborsAtExceptFromFacing in class Level
    • neighborChanged

      public void neighborChanged(BlockPos p_215036_, Block p_215037_, @Nullable Orientation p_363242_)
      Overrides:
      neighborChanged in class Level
    • neighborChanged

      public void neighborChanged(BlockState p_362490_, BlockPos p_215048_, Block p_215049_, @Nullable Orientation p_363197_, boolean p_365415_)
      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 p_270420_, DamageSource p_270311_)
      Overrides:
      broadcastDamageEvent in class Level
    • getChunkSource

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

      public void explode(@Nullable Entity p_256039_, @Nullable DamageSource p_255778_, @Nullable ExplosionDamageCalculator p_256002_, double p_256067_, double p_256370_, double p_256153_, float p_256045_, boolean p_255686_, Level.ExplosionInteraction p_255827_, ParticleOptions p_312436_, ParticleOptions p_312391_, Holder<SoundEvent> p_320497_)
      Specified by:
      explode in class Level
    • getDestroyType

      private Explosion.BlockInteraction getDestroyType(GameRules.Key<GameRules.BooleanValue> pDecayGameRule)
    • 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 ScheduledTickAccess
    • getFluidTicks

      public LevelTicks<Fluid> getFluidTicks()
      Specified by:
      getFluidTicks in interface ScheduledTickAccess
    • 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> int sendParticles(T pType, boolean pOverrideLimiter, boolean pAlwaysShow, 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 pParticle, boolean pOverrideLimiter, boolean pAlwaysShow, double pPosX, double pPosY, double pPosZ, int pCount, double pXDist, double pYDist, double pZDist, double pMaxSpeed)
    • 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.
    • dragonParts

      public Collection<PartEntity<?>> dragonParts()
      Specified by:
      dragonParts in class Level
    • 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>> pBiomePredicate, BlockPos pPos, int pRadius, int pHorizontalStep, int pVerticalStep)
    • recipeAccess

      public RecipeManager recipeAccess()
      Specified by:
      recipeAccess 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 p_323746_)
      Specified by:
      getMapData in class Level
    • setMapData

      public void setMapData(MapId pMapId, MapItemSavedData pData)
    • getFreeMapId

      public MapId getFreeMapId()
    • setDefaultSpawnPos

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

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

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

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

      public void updatePOIOnBlockStateChange(BlockPos p_8751_, BlockState p_8752_, BlockState p_8753_)
      Overrides:
      updatePOIOnBlockStateChange 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)
    • getShade

      public float getShade(Direction p_8760_, boolean p_8761_)
      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 ServerEntityGetter
      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

      public boolean isPositionTickingWithEntitiesLoaded(long pChunkPos)
    • isPositionEntityTicking

      public boolean isPositionEntityTicking(BlockPos pPos)
    • areEntitiesActuallyLoadedAndTicking

      public boolean areEntitiesActuallyLoadedAndTicking(ChunkPos pChunkPos)
    • anyPlayerCloseEnoughForSpawning

      public boolean anyPlayerCloseEnoughForSpawning(BlockPos pPos)
    • anyPlayerCloseEnoughForSpawning

      public boolean anyPlayerCloseEnoughForSpawning(ChunkPos pChunkPos)
    • canSpawnEntitiesInChunk

      public boolean canSpawnEntitiesInChunk(ChunkPos pChunkPos)
    • enabledFeatures

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

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

      public FuelValues fuelValues()
      Specified by:
      fuelValues in class Level
    • getRandomSequence

      public RandomSource getRandomSequence(ResourceLocation pLocation)
    • getRandomSequences

      public RandomSequences getRandomSequences()
    • getGameRules

      public GameRules getGameRules()
    • fillReportDetails

      public CrashReportCategory fillReportDetails(CrashReport p_307518_)
      Description copied from class: Level
      Adds some basic stats of the world to the given crash report.
      Overrides:
      fillReportDetails in class Level
    • getSeaLevel

      public int getSeaLevel()
      Specified by:
      getSeaLevel in interface LevelReader
    • 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