Class Level

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

public abstract class Level extends AttachmentHolder implements LevelAccessor, UUIDLookup<Entity>, AutoCloseable, ILevelExtension
  • Field Details

    • RESOURCE_KEY_CODEC

      public static final com.mojang.serialization.Codec<ResourceKey<Level>> RESOURCE_KEY_CODEC
    • OVERWORLD

      public static final ResourceKey<Level> OVERWORLD
    • NETHER

      public static final ResourceKey<Level> NETHER
    • END

      public static final ResourceKey<Level> END
    • MAX_LEVEL_SIZE

      public static final int MAX_LEVEL_SIZE
      See Also:
    • LONG_PARTICLE_CLIP_RANGE

      public static final int LONG_PARTICLE_CLIP_RANGE
      See Also:
    • SHORT_PARTICLE_CLIP_RANGE

      public static final int SHORT_PARTICLE_CLIP_RANGE
      See Also:
    • MAX_BRIGHTNESS

      public static final int MAX_BRIGHTNESS
      See Also:
    • TICKS_PER_DAY

      public static final int TICKS_PER_DAY
      See Also:
    • MAX_ENTITY_SPAWN_Y

      public static final int MAX_ENTITY_SPAWN_Y
      See Also:
    • MIN_ENTITY_SPAWN_Y

      public static final int MIN_ENTITY_SPAWN_Y
      See Also:
    • blockEntityTickers

      protected final List<TickingBlockEntity> blockEntityTickers
    • neighborUpdater

      protected final NeighborUpdater neighborUpdater
    • pendingBlockEntityTickers

      private final List<TickingBlockEntity> pendingBlockEntityTickers
    • tickingBlockEntities

      private boolean tickingBlockEntities
    • thread

      private final Thread thread
    • isDebug

      private final boolean isDebug
    • skyDarken

      private int skyDarken
    • randValue

      protected int randValue
      Contains the current Linear Congruential Generator seed for block updates. Used with an A value of 3 and a C value of 0x3c6ef35f, producing a highly planar series of values ill-suited for choosing random blocks in a 16x128x16 field.
    • addend

      protected final int addend
      See Also:
    • oRainLevel

      public float oRainLevel
    • rainLevel

      public float rainLevel
    • oThunderLevel

      public float oThunderLevel
    • thunderLevel

      public float thunderLevel
    • random

      public final RandomSource random
    • threadSafeRandom

      @Deprecated private final RandomSource threadSafeRandom
      Deprecated.
    • dimensionTypeRegistration

      private final Holder<DimensionType> dimensionTypeRegistration
    • levelData

      protected final WritableLevelData levelData
    • isClientSide

      public final boolean isClientSide
    • worldBorder

      private final WorldBorder worldBorder
    • biomeManager

      private final BiomeManager biomeManager
    • dimension

      private final ResourceKey<Level> dimension
    • registryAccess

      private final RegistryAccess registryAccess
    • damageSources

      private final DamageSources damageSources
    • subTickCount

      private long subTickCount
    • restoringBlockSnapshots

      public boolean restoringBlockSnapshots
    • captureBlockSnapshots

      public boolean captureBlockSnapshots
    • capturedBlockSnapshots

      public ArrayList<BlockSnapshot> capturedBlockSnapshots
    • freshBlockEntities

      private final ArrayList<BlockEntity> freshBlockEntities
    • pendingFreshBlockEntities

      private final ArrayList<BlockEntity> pendingFreshBlockEntities
    • maxEntityRadius

      private double maxEntityRadius
  • Constructor Details

  • Method Details

    • isClientSide

      public boolean isClientSide()
      Specified by:
      isClientSide in interface LevelReader
    • getServer

      @Nullable public MinecraftServer getServer()
      Specified by:
      getServer in interface LevelAccessor
    • isInWorldBounds

      public boolean isInWorldBounds(BlockPos pos)
      Check if the given BlockPos has valid coordinates
    • isInSpawnableBounds

      public static boolean isInSpawnableBounds(BlockPos pos)
    • isInWorldBoundsHorizontal

      private static boolean isInWorldBoundsHorizontal(BlockPos pos)
    • isOutsideSpawnableHeight

      private static boolean isOutsideSpawnableHeight(int y)
    • getChunkAt

      public LevelChunk getChunkAt(BlockPos pos)
    • getChunk

      public LevelChunk getChunk(int chunkX, int chunkZ)
      Specified by:
      getChunk in interface LevelReader
    • getChunk

      @Nullable public ChunkAccess getChunk(int p_46502_, int p_46503_, ChunkStatus p_331611_, boolean p_46505_)
      Specified by:
      getChunk in interface LevelReader
    • setBlock

      public boolean setBlock(BlockPos pos, BlockState newState, int flags)
      Sets a block state into this world.Flags are as follows: 1 will notify neighboring blocks through
      invalid reference
      neighborChanged
      updates. 2 will send the change to clients. 4 will prevent the block from being re-rendered. 8 will force any re-renders to run on the main thread instead 16 will prevent neighbor reactions (e.g. fences connecting, observers pulsing). 32 will prevent neighbor reactions from spawning drops. 64 will signify the block is being moved. Flags can be OR-ed
      Specified by:
      setBlock in interface LevelWriter
    • setBlock

      public boolean setBlock(BlockPos pos, BlockState state, int flags, int recursionLeft)
      Specified by:
      setBlock in interface LevelWriter
    • markAndNotifyBlock

      public void markAndNotifyBlock(BlockPos p_46605_, @Nullable LevelChunk levelchunk, BlockState blockstate, BlockState p_46606_, int p_46607_, int p_46608_)
    • updatePOIOnBlockStateChange

      public void updatePOIOnBlockStateChange(BlockPos pos, BlockState oldState, BlockState newState)
    • removeBlock

      public boolean removeBlock(BlockPos pos, boolean isMoving)
      Specified by:
      removeBlock in interface LevelWriter
    • destroyBlock

      public boolean destroyBlock(BlockPos pos, boolean dropBlock, @Nullable Entity entity, int recursionLeft)
      Specified by:
      destroyBlock in interface LevelWriter
    • addDestroyBlockEffect

      public void addDestroyBlockEffect(BlockPos pos, BlockState state)
    • setBlockAndUpdate

      public boolean setBlockAndUpdate(BlockPos pos, BlockState state)
      Convenience method to update the block on both the client and server
    • sendBlockUpdated

      public abstract void sendBlockUpdated(BlockPos pos, BlockState oldState, BlockState newState, int flags)
      Flags are as in setBlockState
    • setBlocksDirty

      public void setBlocksDirty(BlockPos blockPos, BlockState oldState, BlockState newState)
    • updateNeighborsAt

      public void updateNeighborsAt(BlockPos pos, Block block, @Nullable Orientation orientation)
    • updateNeighborsAtExceptFromFacing

      public void updateNeighborsAtExceptFromFacing(BlockPos pos, Block block, Direction facing, @Nullable Orientation orientation)
    • neighborChanged

      public void neighborChanged(BlockPos pos, Block block, @Nullable Orientation orientation)
    • neighborChanged

      public void neighborChanged(BlockState state, BlockPos pos, Block block, @Nullable Orientation orientation, boolean movedByPiston)
    • neighborShapeChanged

      public void neighborShapeChanged(Direction p_220385_, BlockPos p_220387_, BlockPos p_220388_, BlockState p_220386_, int p_220389_, int p_220390_)
      Specified by:
      neighborShapeChanged in interface LevelAccessor
    • getHeight

      public int getHeight(Heightmap.Types heightmapType, int x, int z)
      Specified by:
      getHeight in interface LevelReader
    • getLightEngine

      public LevelLightEngine getLightEngine()
      Specified by:
      getLightEngine in interface BlockAndTintGetter
    • getBlockState

      public BlockState getBlockState(BlockPos pos)
      Specified by:
      getBlockState in interface BlockGetter
    • getFluidState

      public FluidState getFluidState(BlockPos pos)
      Specified by:
      getFluidState in interface BlockGetter
    • isBrightOutside

      public boolean isBrightOutside()
    • isDarkOutside

      public boolean isDarkOutside()
    • isMoonVisible

      public boolean isMoonVisible()
    • playSound

      public void playSound(@Nullable Entity entity, BlockPos pos, SoundEvent sound, SoundSource category, float volume, float pitch)
      Specified by:
      playSound in interface LevelAccessor
    • playSeededSound

      public abstract void playSeededSound(@Nullable Entity entity, double x, double y, double z, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch, long seed)
    • playSeededSound

      public void playSeededSound(@Nullable Entity entity, double x, double y, double z, SoundEvent sound, SoundSource source, float volume, float pitch, long seed)
    • playSeededSound

      public abstract void playSeededSound(@Nullable Entity entity, Entity sourceEntity, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch, long seed)
    • playSound

      public void playSound(@Nullable Entity entity, double x, double y, double z, SoundEvent sound, SoundSource source)
    • playSound

      public void playSound(@Nullable Entity entity, double x, double y, double z, SoundEvent sound, SoundSource source, float volume, float pitch)
    • playSound

      public void playSound(@Nullable Entity entity, double x, double y, double z, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch)
    • playSound

      public void playSound(@Nullable Entity entity, Entity sourceEntity, SoundEvent sound, SoundSource source, float volume, float pitch)
    • playLocalSound

      public void playLocalSound(BlockPos pos, SoundEvent sound, SoundSource source, float volume, float pitch, boolean distanceDelay)
    • playLocalSound

      public void playLocalSound(Entity entity, SoundEvent sound, SoundSource source, float volume, float pitch)
    • playLocalSound

      public void playLocalSound(double x, double y, double z, SoundEvent sound, SoundSource source, float volume, float pitch, boolean distanceDelay)
    • playPlayerSound

      public void playPlayerSound(SoundEvent sound, SoundSource source, float volume, float pitch)
    • addParticle

      public void addParticle(ParticleOptions particleData, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed)
      Specified by:
      addParticle in interface LevelAccessor
    • addParticle

      public void addParticle(ParticleOptions particle, boolean overrideLimiter, boolean alwaysShow, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed)
    • addAlwaysVisibleParticle

      public void addAlwaysVisibleParticle(ParticleOptions particle, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed)
    • addAlwaysVisibleParticle

      public void addAlwaysVisibleParticle(ParticleOptions particle, boolean ignoreRange, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed)
    • getSunAngle

      public float getSunAngle(float partialTick)
      Return getCelestialAngle()*2*PI
    • addBlockEntityTicker

      public void addBlockEntityTicker(TickingBlockEntity ticker)
    • addFreshBlockEntities

      public void addFreshBlockEntities(Collection<BlockEntity> beList)
    • tickBlockEntities

      protected void tickBlockEntities()
    • guardEntityTick

      public <T extends Entity> void guardEntityTick(Consumer<T> consumerEntity, T entity)
    • shouldTickDeath

      public boolean shouldTickDeath(Entity entity)
    • shouldTickBlocksAt

      public boolean shouldTickBlocksAt(long chunkPos)
    • shouldTickBlocksAt

      public boolean shouldTickBlocksAt(BlockPos pos)
    • explode

      public void explode(@Nullable Entity source, double x, double y, double z, float radius, Level.ExplosionInteraction explosionInteraction)
    • explode

      public void explode(@Nullable Entity source, double x, double y, double z, float radius, boolean fire, Level.ExplosionInteraction explosionInteraction)
    • explode

      public void explode(@Nullable Entity source, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator damageCalculator, Vec3 pos, float radius, boolean fire, Level.ExplosionInteraction explosionInteraction)
    • explode

      public void explode(@Nullable Entity source, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator damageCalculator, double x, double y, double z, float radius, boolean fire, Level.ExplosionInteraction explosionInteraction)
    • explode

      public abstract void explode(@Nullable Entity source, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator damageCalculator, double x, double y, double z, float radius, boolean fire, Level.ExplosionInteraction explosionInteraction, ParticleOptions smallExplosionParticles, ParticleOptions largeExplosionParticles, Holder<SoundEvent> explosionSound)
    • gatherChunkSourceStats

      public abstract String gatherChunkSourceStats()
    • getBlockEntity

      @Nullable public BlockEntity getBlockEntity(BlockPos pos)
      Specified by:
      getBlockEntity in interface BlockGetter
    • setBlockEntity

      public void setBlockEntity(BlockEntity blockEntity)
    • removeBlockEntity

      public void removeBlockEntity(BlockPos pos)
    • isLoaded

      public boolean isLoaded(BlockPos pos)
    • loadedAndEntityCanStandOnFace

      public boolean loadedAndEntityCanStandOnFace(BlockPos pos, Entity entity, Direction direction)
    • loadedAndEntityCanStandOn

      public boolean loadedAndEntityCanStandOn(BlockPos pos, Entity entity)
    • updateSkyBrightness

      public void updateSkyBrightness()
    • setSpawnSettings

      public void setSpawnSettings(boolean spawnSettings)
    • getSharedSpawnPos

      public BlockPos getSharedSpawnPos()
    • getSharedSpawnAngle

      public float getSharedSpawnAngle()
    • prepareWeather

      protected void prepareWeather()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
    • getChunkForCollisions

      @Nullable public BlockGetter getChunkForCollisions(int chunkX, int chunkZ)
      Specified by:
      getChunkForCollisions in interface CollisionGetter
      Specified by:
      getChunkForCollisions in interface LevelReader
    • getEntities

      public List<Entity> getEntities(@Nullable Entity entity, AABB boundingBox, Predicate<? super Entity> predicate)
      Gets all entities within the specified AABB excluding the one passed into it.
      Specified by:
      getEntities in interface EntityGetter
    • getEntities

      public <T extends Entity> List<T> getEntities(EntityTypeTest<Entity,T> p_151528_, AABB p_151529_, Predicate<? super T> p_151530_)
      Specified by:
      getEntities in interface EntityGetter
    • getEntities

      public <T extends Entity> void getEntities(EntityTypeTest<Entity,T> entityTypeTest, AABB bounds, Predicate<? super T> predicate, List<? super T> output)
    • getEntities

      public <T extends Entity> void getEntities(EntityTypeTest<Entity,T> entityTypeTest, AABB bounds, Predicate<? super T> predicate, List<? super T> output, int maxResults)
    • getPushableEntities

      public List<Entity> getPushableEntities(Entity entity, AABB boundingBox)
    • getEntity

      @Nullable public abstract Entity getEntity(int id)
      Returns the Entity with the given ID, or null if it doesn't exist in this Level.
    • getEntity

      @Nullable public Entity getEntity(UUID p_394067_)
      Specified by:
      getEntity in interface UUIDLookup<Entity>
    • dragonParts

      public abstract Collection<PartEntity<?>> dragonParts()
    • blockEntityChanged

      public void blockEntityChanged(BlockPos pos)
    • disconnect

      public void disconnect()
    • getGameTime

      public long getGameTime()
    • getDayTime

      public long getDayTime()
    • mayInteract

      public boolean mayInteract(Entity entity, BlockPos pos)
    • broadcastEntityEvent

      public void broadcastEntityEvent(Entity entity, byte state)
      Sends a ClientboundEntityEventPacket to all tracked players of that entity.
    • broadcastDamageEvent

      public void broadcastDamageEvent(Entity entity, DamageSource damageSource)
    • blockEvent

      public void blockEvent(BlockPos pos, Block block, int eventID, int eventParam)
    • getLevelData

      public LevelData getLevelData()
      Specified by:
      getLevelData in interface LevelAccessor
    • tickRateManager

      public abstract TickRateManager tickRateManager()
    • getThunderLevel

      public float getThunderLevel(float partialTick)
    • setThunderLevel

      public void setThunderLevel(float strength)
      Sets the strength of the thunder.
    • getRainLevel

      public float getRainLevel(float partialTick)
      Returns rain strength.
    • setRainLevel

      public void setRainLevel(float strength)
      Sets the strength of the rain.
    • canHaveWeather

      private boolean canHaveWeather()
    • isThundering

      public boolean isThundering()
    • isRaining

      public boolean isRaining()
    • isRainingAt

      public boolean isRainingAt(BlockPos pos)
      Check if precipitation is currently happening at a position
    • getMapData

      @Nullable public abstract MapItemSavedData getMapData(MapId mapId)
    • globalLevelEvent

      public void globalLevelEvent(int id, BlockPos pos, int data)
    • fillReportDetails

      public CrashReportCategory fillReportDetails(CrashReport report)
      Adds some basic stats of the world to the given crash report.
    • destroyBlockProgress

      public abstract void destroyBlockProgress(int breakerId, BlockPos pos, int progress)
    • createFireworks

      public void createFireworks(double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, List<FireworkExplosion> explosions)
    • getScoreboard

      public abstract Scoreboard getScoreboard()
    • updateNeighbourForOutputSignal

      public void updateNeighbourForOutputSignal(BlockPos pos, Block block)
    • getCurrentDifficultyAt

      public DifficultyInstance getCurrentDifficultyAt(BlockPos pos)
      Specified by:
      getCurrentDifficultyAt in interface LevelAccessor
    • getSkyDarken

      public int getSkyDarken()
      Specified by:
      getSkyDarken in interface LevelReader
    • setSkyFlashTime

      public void setSkyFlashTime(int timeFlash)
    • getWorldBorder

      public WorldBorder getWorldBorder()
      Specified by:
      getWorldBorder in interface CollisionGetter
    • sendPacketToServer

      public void sendPacketToServer(Packet<?> packet)
    • dimensionType

      public DimensionType dimensionType()
      Specified by:
      dimensionType in interface LevelReader
    • dimensionTypeRegistration

      public Holder<DimensionType> dimensionTypeRegistration()
    • dimension

      public ResourceKey<Level> dimension()
    • getRandom

      public RandomSource getRandom()
      Specified by:
      getRandom in interface LevelAccessor
    • isStateAtPosition

      public boolean isStateAtPosition(BlockPos pos, Predicate<BlockState> state)
      Specified by:
      isStateAtPosition in interface LevelSimulatedReader
    • isFluidAtPosition

      public boolean isFluidAtPosition(BlockPos p_151541_, Predicate<FluidState> p_151542_)
      Specified by:
      isFluidAtPosition in interface LevelSimulatedReader
    • recipeAccess

      public abstract RecipeAccess recipeAccess()
    • getBlockRandomPos

      public BlockPos getBlockRandomPos(int x, int y, int z, int yMask)
    • noSave

      public boolean noSave()
    • getBiomeManager

      public BiomeManager getBiomeManager()
      Specified by:
      getBiomeManager in interface LevelReader
    • getMaxEntityRadius

      public double getMaxEntityRadius()
      Description copied from interface: ILevelExtension
      The maximum radius to scan for entities when trying to check bounding boxes. Vanilla's default is 2.0D But mods that add larger entities may increase this.
      Specified by:
      getMaxEntityRadius in interface ILevelExtension
    • increaseMaxEntityRadius

      public double increaseMaxEntityRadius(double value)
      Description copied from interface: ILevelExtension
      Increases the max entity radius, this is safe to call with any value. The setter will verify the input value is larger then the current setting.
      Specified by:
      increaseMaxEntityRadius in interface ILevelExtension
      Parameters:
      value - New max radius to set.
      Returns:
      The new max radius
    • isDebug

      public final boolean isDebug()
    • getEntities

      protected abstract LevelEntityGetter<Entity> getEntities()
    • nextSubTickCount

      public long nextSubTickCount()
      Specified by:
      nextSubTickCount in interface LevelAccessor
    • registryAccess

      public RegistryAccess registryAccess()
      Specified by:
      registryAccess in interface LevelReader
    • damageSources

      public DamageSources damageSources()
    • potionBrewing

      public abstract PotionBrewing potionBrewing()
    • fuelValues

      public abstract FuelValues fuelValues()
    • getClientLeafTintColor

      public int getClientLeafTintColor(BlockPos pos)
    • setDayTimeFraction

      @Internal public abstract void setDayTimeFraction(float dayTimeFraction)
    • getDayTimeFraction

      @Internal public abstract float getDayTimeFraction()
    • getDayTimePerTick

      public abstract 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).
    • setDayTimePerTick

      public abstract void setDayTimePerTick(float dayTimePerTick)
      DO NOT CALL.

      Use ServerLevel.setDayTimePerTick(float) instead.

    • advanceDaytime

      @Internal protected long advanceDaytime()