Class Level

All Implemented Interfaces:
AutoCloseable, BiomeManager.NoiseBiomeSource, BlockAndTintGetter, BlockGetter, CollisionGetter, CommonLevelAccessor, EntityGetter, LevelAccessor, LevelHeightAccessor, LevelReader, LevelSimulatedReader, LevelSimulatedRW, LevelWriter, ScheduledTickAccess, 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:
    • 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:
    • DEFAULT_EXPLOSION_BLOCK_PARTICLES

      private static final WeightedList<ExplosionParticleInfo> DEFAULT_EXPLOSION_BLOCK_PARTICLES
    • blockEntityTickers

      protected final List<TickingBlockEntity> blockEntityTickers
    • neighborUpdater

      protected final CollectingNeighborUpdater 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

      private final boolean isClientSide
    • biomeManager

      private final BiomeManager biomeManager
    • dimension

      private final ResourceKey<Level> dimension
    • registryAccess

      private final RegistryAccess registryAccess
    • damageSources

      private final DamageSources damageSources
    • palettedContainerFactory

      private final PalettedContainerFactory palettedContainerFactory
    • 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
    • NEIGHBOR_UPDATE_LIST

      private static final Direction[] NEIGHBOR_UPDATE_LIST
    • maxEntityRadius

      private double maxEntityRadius
  • Constructor Details

  • Method Details

    • isClientSide

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

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

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

      public boolean isInValidBounds(BlockPos pos)
    • isInSpawnableBounds

      public static boolean isInSpawnableBounds(BlockPos pos)
    • isInWorldBoundsHorizontal

      private static boolean isInWorldBoundsHorizontal(BlockPos pos)
    • isInValidBoundsHorizontal

      private static boolean isInValidBoundsHorizontal(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

      public @Nullable 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 state, @net.minecraft.world.level.block.Block.UpdateFlags int flags)
      Specified by:
      setBlock in interface LevelWriter
    • setBlock

      public boolean setBlock(BlockPos pos, BlockState state, @net.minecraft.world.level.block.Block.UpdateFlags int flags, int recursionLeft)
      Sets a block state into this world. Flags are as follows: Flags can be OR-ed
      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 movedByPiston)
      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, @net.minecraft.world.level.block.Block.UpdateFlags int flags)
      Flags are as in setBlock
    • setBlocksDirty

      public void setBlocksDirty(BlockPos pos, 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_, @net.minecraft.world.level.block.Block.UpdateFlags 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()
    • 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 options, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed)
      Specified by:
      addParticle in interface LevelAccessor
    • addParticle

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

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

      public void addAlwaysVisibleParticle(ParticleOptions options, boolean overrideLimiter, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed)
    • addBlockEntityTicker

      public void addBlockEntityTicker(TickingBlockEntity ticker)
    • addFreshBlockEntities

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

      public void tickBlockEntities()
    • guardEntityTick

      public <T extends Entity> void guardEntityTick(Consumer<T> action, 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, WeightedList<ExplosionParticleInfo> blockParticles, Holder<SoundEvent> explosionSound)
    • gatherChunkSourceStats

      public abstract String gatherChunkSourceStats()
    • getBlockEntity

      public @Nullable 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)
    • setRespawnData

      public abstract void setRespawnData(LevelData.RespawnData respawnData)
    • getRespawnData

      public abstract LevelData.RespawnData getRespawnData()
    • getWorldBorderAdjustedRespawnData

      public LevelData.RespawnData getWorldBorderAdjustedRespawnData(LevelData.RespawnData respawnData)
    • prepareWeather

      protected void prepareWeather()
    • close

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

      public @Nullable 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)
    • hasEntities

      public <T extends Entity> boolean hasEntities(EntityTypeTest<Entity,T> entityTypeTest, AABB bounds, Predicate<? super T> predicate)
    • getPushableEntities

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

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

      public @Nullable Entity getEntity(UUID uuid)
    • getEntityInAnyDimension

      public @Nullable Entity getEntityInAnyDimension(UUID uuid)
    • getPlayerInAnyDimension

      public @Nullable Player getPlayerInAnyDimension(UUID uuid)
    • dragonParts

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

      public void blockEntityChanged(BlockPos pos)
    • onBlockEntityAdded

      public void onBlockEntityAdded(BlockEntity entity)
    • 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 level)
      Sets the level of the thunder.
    • getRainLevel

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

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

      public 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
    • precipitationAt

      public Biome.Precipitation precipitationAt(BlockPos pos)
    • getMapData

      public abstract @Nullable 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)
    • getSkyDarken

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

      public void setSkyFlashTime(int timeFlash)
    • 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()
    • environmentAttributes

      public abstract EnvironmentAttributeSystem environmentAttributes()
      Specified by:
      environmentAttributes in interface LevelReader
    • potionBrewing

      public abstract PotionBrewing potionBrewing()
    • fuelValues

      public abstract FuelValues fuelValues()
    • getClientLeafTintColor

      public int getClientLeafTintColor(BlockPos pos)
    • palettedContainerFactory

      public PalettedContainerFactory palettedContainerFactory()
    • 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()