Class Level

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

public abstract class Level extends AttachmentHolder implements LevelAccessor, 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
    • profiler

      private final Supplier<ProfilerFiller> profiler
    • 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 x, int z, ChunkStatus chunkStatus, boolean requireChunk)
      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_)
    • onBlockStateChange

      public void onBlockStateChange(BlockPos pos, BlockState blockState, 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)
    • updateNeighborsAtExceptFromFacing

      public void updateNeighborsAtExceptFromFacing(BlockPos pos, Block blockType, Direction skipSide)
    • neighborChanged

      public void neighborChanged(BlockPos pos, Block block, BlockPos fromPos)
    • neighborChanged

      public void neighborChanged(BlockState state, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving)
    • neighborShapeChanged

      public void neighborShapeChanged(Direction direction, BlockState queried, BlockPos pos, BlockPos offsetPos, int flags, int recursionLevel)
      Specified by:
      neighborShapeChanged in interface LevelAccessor
      Parameters:
      queried - The block state of the current block
      pos - The position of the neighbor block
      offsetPos - The position of the current block
    • 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
    • isDay

      public boolean isDay()
    • isNight

      public boolean isNight()
    • playSound

      public void playSound(@Nullable Entity entity, BlockPos pos, SoundEvent sound, SoundSource category, float volume, float pitch)
    • playSound

      public void playSound(@Nullable Player player, BlockPos pos, SoundEvent sound, SoundSource category, float volume, float pitch)
      Plays a sound. On the server, the sound is broadcast to all nearby except the given player. On the client, the sound only plays if the given player is the client player. Thus, this method is intended to be called from code running on both sides. The client plays it locally and the server plays it for everyone else.
      Specified by:
      playSound in interface LevelAccessor
    • playSeededSound

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

      public void playSeededSound(@Nullable Player player, double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch, long seed)
    • playSeededSound

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

      public void playSound(@Nullable Player player, double x, double y, double z, SoundEvent sound, SoundSource category)
    • playSound

      public void playSound(@Nullable Player player, double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch)
    • playSound

      public void playSound(@Nullable Player player, double x, double y, double z, Holder<SoundEvent> sound, SoundSource category, float volume, float pitch)
    • playSound

      public void playSound(@Nullable Player player, Entity entity, SoundEvent event, SoundSource category, float volume, float pitch)
    • playLocalSound

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

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

      public void playLocalSound(double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch, boolean distanceDelay)
    • 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 particleData, boolean forceAlwaysRender, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed)
    • addAlwaysVisibleParticle

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

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

      public float getSunAngle(float partialTicks)
      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 Explosion explode(@Nullable Entity source, double x, double y, double z, float radius, Level.ExplosionInteraction explosionInteraction)
    • explode

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

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

      public Explosion 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 Explosion 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)
    • explode

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

    • 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 hostile, boolean peaceful)
      First boolean for hostile mobs and second for peaceful mobs
    • 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> entityTypeTest, AABB bounds, Predicate<? super T> predicate)
      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)
    • 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.
    • blockEntityChanged

      public void blockEntityChanged(BlockPos pos)
    • getSeaLevel

      public int getSeaLevel()
      Specified by:
      getSeaLevel in interface LevelReader
    • disconnect

      public void disconnect()
    • getGameTime

      public long getGameTime()
    • getDayTime

      public long getDayTime()
    • mayInteract

      public boolean mayInteract(Player player, 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
    • getGameRules

      public GameRules getGameRules()
    • tickRateManager

      public abstract TickRateManager tickRateManager()
    • getThunderLevel

      public float getThunderLevel(float delta)
    • setThunderLevel

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

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

      public void setRainLevel(float strength)
      Sets the strength of the rain.
    • 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)
    • setMapData

      public abstract void setMapData(MapId mapId, MapItemSavedData mapData)
    • getFreeMapId

      public abstract MapId getFreeMapId()
    • 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 pos, Predicate<FluidState> predicate)
      Specified by:
      isFluidAtPosition in interface LevelSimulatedReader
    • getRecipeManager

      public abstract RecipeManager getRecipeManager()
    • getBlockRandomPos

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

      public boolean noSave()
    • getProfiler

      public ProfilerFiller getProfiler()
    • getProfilerSupplier

      public Supplier<ProfilerFiller> getProfilerSupplier()
    • 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()
    • 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()