Class WorldUtil

java.lang.Object
com.minecolonies.api.util.WorldUtil

public class WorldUtil extends Object
Class which has world related util functions like chunk load checks
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    getDimensionMaxHeight(net.minecraft.world.level.dimension.DimensionType dimensionType)
    Returns a dimensions max height
    static int
    getDimensionMinHeight(net.minecraft.world.level.dimension.DimensionType dimensionType)
    Returns a dimension min height
    static <T extends net.minecraft.world.entity.Entity>
    List<? extends T>
    getEntitiesWithinBuilding(@NotNull net.minecraft.world.level.Level world, @NotNull Class<? extends T> clazz, @NotNull IBuilding building, Predicate<? super T> predicate)
    Get all entities within a building.
    static <T extends net.minecraft.world.entity.LivingEntity>
    T
    getNearestEntity(List<? extends T> entityList, net.minecraft.world.entity.Mob livingEntity, int x, int y, int z, double lookDistance)
    Get the closest entity, cheaper than mojank.
    static net.minecraft.world.entity.player.Player
    getNearestPlayer(net.minecraft.world.entity.Mob livingEntity, int x, int y, int z, double lookDistance)
    Get nearest player, our own cheaper check.
    static boolean
    isAABBLoaded(net.minecraft.world.level.Level world, net.minecraft.world.phys.AABB box)
    Returns whether an axis aligned bb is entirely loaded.
    static boolean
    isBlockLoaded(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos)
    Checks if the block is loaded for block access
    static boolean
    isChunkLoaded(net.minecraft.world.level.LevelAccessor world, int x, int z)
    Returns whether a chunk is fully loaded
    static boolean
    isChunkLoaded(net.minecraft.world.level.LevelAccessor world, net.minecraft.world.level.ChunkPos pos)
    Returns whether a chunk is fully loaded
    static boolean
    isDayTime(net.minecraft.world.level.Level world)
    Check if it's currently day inn the world.
    static boolean
    isEntityBlockLoaded(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos)
    Checks if the block is loaded for ticking entities(not all chunks tick entities)
    static boolean
    isEntityChunkLoaded(net.minecraft.world.level.LevelAccessor world, int x, int z)
    Returns whether an entity ticking chunk is loaded at the position
    static boolean
    isEntityChunkLoaded(net.minecraft.world.level.LevelAccessor world, net.minecraft.world.level.ChunkPos pos)
    Returns whether an entity ticking chunk is loaded at the position
    static boolean
    isInWorldHeight(int yBlock, net.minecraft.world.level.Level world)
    Check if a given block y is within world bounds
    static boolean
    isNetherType(@NotNull net.minecraft.world.level.Level world)
    Check if a world is of the nether type.
    static boolean
    isOfWorldType(@NotNull net.minecraft.world.level.Level world, @NotNull net.minecraft.resources.ResourceKey<net.minecraft.world.level.dimension.DimensionType> type)
    Check if a world has a specific dimension type.
    static boolean
    isOverworldType(@NotNull net.minecraft.world.level.Level world)
    Check if a world is of the overworld type.
    static boolean
    isPastNoon(net.minecraft.world.level.Level world)
    Check if it's currently afternoon the world.
    static boolean
    isPastTime(net.minecraft.world.level.Level world, int pastTime)
    Check if it's currently day inn the world.
    static boolean
    isPeaceful(@NotNull net.minecraft.world.level.Level world)
    Check to see if the world is peaceful.
    static void
    markChunkDirty(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
    Mark a chunk at a position dirty if loaded.
    static boolean
    removeBlock(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos, boolean isMoving)
    See World#removeBLock
    static boolean
    setBlockState(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
    Custom set block state, with 1 instead of default flag 3, to skip vanilla's path notify upon block change, making setBlockState expensive.
    static boolean
    setBlockState(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, int flags)
    Custom set block state, skips vanilla's path notify upon block change, making setBlockState expensive.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WorldUtil

      public WorldUtil()
  • Method Details

    • isBlockLoaded

      public static boolean isBlockLoaded(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos)
      Checks if the block is loaded for block access
      Parameters:
      world - world to use
      pos - position to check
      Returns:
      true if block is accessible/loaded
    • isChunkLoaded

      public static boolean isChunkLoaded(net.minecraft.world.level.LevelAccessor world, int x, int z)
      Returns whether a chunk is fully loaded
      Parameters:
      world - world to check on
      x - chunk position
      z - chunk position
      Returns:
      true if loaded
    • markChunkDirty

      public static void markChunkDirty(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
      Mark a chunk at a position dirty if loaded.
      Parameters:
      world - the world to mark it dirty in.
      pos - the position within the chunk.
    • isChunkLoaded

      public static boolean isChunkLoaded(net.minecraft.world.level.LevelAccessor world, net.minecraft.world.level.ChunkPos pos)
      Returns whether a chunk is fully loaded
      Parameters:
      world - world to check on
      pos - chunk position
      Returns:
      true if loaded
    • isEntityBlockLoaded

      public static boolean isEntityBlockLoaded(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos)
      Checks if the block is loaded for ticking entities(not all chunks tick entities)
      Parameters:
      world - world to use
      pos - position to check
      Returns:
      true if block is accessible/loaded
    • isEntityChunkLoaded

      public static boolean isEntityChunkLoaded(net.minecraft.world.level.LevelAccessor world, int x, int z)
      Returns whether an entity ticking chunk is loaded at the position
      Parameters:
      world - world to check on
      x - chunk position
      z - chunk position
      Returns:
      true if loaded
    • isEntityChunkLoaded

      public static boolean isEntityChunkLoaded(net.minecraft.world.level.LevelAccessor world, net.minecraft.world.level.ChunkPos pos)
      Returns whether an entity ticking chunk is loaded at the position
      Parameters:
      world - world to check on
      pos - chunk position
      Returns:
      true if loaded
    • isAABBLoaded

      public static boolean isAABBLoaded(net.minecraft.world.level.Level world, net.minecraft.world.phys.AABB box)
      Returns whether an axis aligned bb is entirely loaded.
      Parameters:
      world - world to check on.
      box - the box.
      Returns:
      true if loaded.
    • isDayTime

      public static boolean isDayTime(net.minecraft.world.level.Level world)
      Check if it's currently day inn the world.
      Parameters:
      world - the world to check.
      Returns:
      true if so.
    • isPastTime

      public static boolean isPastTime(net.minecraft.world.level.Level world, int pastTime)
      Check if it's currently day inn the world.
      Parameters:
      world - the world to check.
      Returns:
      true if so.
    • isPastNoon

      public static boolean isPastNoon(net.minecraft.world.level.Level world)
      Check if it's currently afternoon the world.
      Parameters:
      world - the world to check.
      Returns:
      true if so.
    • isOverworldType

      public static boolean isOverworldType(@NotNull @NotNull net.minecraft.world.level.Level world)
      Check if a world is of the overworld type.
      Parameters:
      world - the world to check.
      Returns:
      true if so.
    • isNetherType

      public static boolean isNetherType(@NotNull @NotNull net.minecraft.world.level.Level world)
      Check if a world is of the nether type.
      Parameters:
      world - the world to check.
      Returns:
      true if so.
    • isOfWorldType

      public static boolean isOfWorldType(@NotNull @NotNull net.minecraft.world.level.Level world, @NotNull @NotNull net.minecraft.resources.ResourceKey<net.minecraft.world.level.dimension.DimensionType> type)
      Check if a world has a specific dimension type.
      Parameters:
      world - the world to check.
      type - the type to compare.
      Returns:
      true if it matches.
    • isPeaceful

      public static boolean isPeaceful(@NotNull @NotNull net.minecraft.world.level.Level world)
      Check to see if the world is peaceful.

      There are several checks performed here, currently both gamerule and difficulty.

      Parameters:
      world - world to check
      Returns:
      true if peaceful
    • setBlockState

      public static boolean setBlockState(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
      Custom set block state, with 1 instead of default flag 3, to skip vanilla's path notify upon block change, making setBlockState expensive. The state change still affects neighbours and is synced
      Parameters:
      world - world to use
      pos - position to set
      state - state to set
    • setBlockState

      public static boolean setBlockState(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, int flags)
      Custom set block state, skips vanilla's path notify upon block change, making setBlockState expensive.
      Parameters:
      world - world to use
      pos - position to set
      state - state to set
      flags - flags to use
    • removeBlock

      public static boolean removeBlock(net.minecraft.world.level.LevelAccessor world, net.minecraft.core.BlockPos pos, boolean isMoving)
      See World#removeBLock
      Parameters:
      world - world to remove a block
      pos - position the block is removed at
      isMoving - moving flag
      Returns:
      true if success
    • getEntitiesWithinBuilding

      public static <T extends net.minecraft.world.entity.Entity> List<? extends T> getEntitiesWithinBuilding(@NotNull @NotNull net.minecraft.world.level.Level world, @NotNull @NotNull Class<? extends T> clazz, @NotNull @NotNull IBuilding building, @Nullable Predicate<? super T> predicate)
      Get all entities within a building.
      Type Parameters:
      T - the type of the predicate.
      Parameters:
      world - the world to check this for.
      clazz - the entity class.
      building - the building to check the range for.
      predicate - the predicate to check
      Returns:
      a list of all within those borders.
    • getDimensionMaxHeight

      public static int getDimensionMaxHeight(net.minecraft.world.level.dimension.DimensionType dimensionType)
      Returns a dimensions max height
      Parameters:
      dimensionType -
      Returns:
    • getDimensionMinHeight

      public static int getDimensionMinHeight(net.minecraft.world.level.dimension.DimensionType dimensionType)
      Returns a dimension min height
      Parameters:
      dimensionType -
      Returns:
    • isInWorldHeight

      public static boolean isInWorldHeight(int yBlock, net.minecraft.world.level.Level world)
      Check if a given block y is within world bounds
      Parameters:
      yBlock -
      world -
      Returns:
    • getNearestPlayer

      @Nullable public static net.minecraft.world.entity.player.Player getNearestPlayer(net.minecraft.world.entity.Mob livingEntity, int x, int y, int z, double lookDistance)
      Get nearest player, our own cheaper check.
      Parameters:
      livingEntity - the entity to check.
      x - pos x
      y - pos y
      z - pos z
      lookDistance - min distance.
      Returns:
      closest player or null.
    • getNearestEntity

      @Nullable public static <T extends net.minecraft.world.entity.LivingEntity> T getNearestEntity(List<? extends T> entityList, @Nullable net.minecraft.world.entity.Mob livingEntity, int x, int y, int z, double lookDistance)
      Get the closest entity, cheaper than mojank.
      Type Parameters:
      T - type of entity.
      Parameters:
      entityList - entity list to check.
      livingEntity - the entity they should be close to.
      x - pos x
      y - pos y
      z - pos z
      lookDistance - max distance.
      Returns:
      the entity or null.