Class LevelUtil

java.lang.Object
info.u_team.u_team_core.util.LevelUtil

public class LevelUtil extends Object
Some utility methods for level interaction.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends net.minecraft.world.level.saveddata.SavedData>
    T
    getSaveData(net.minecraft.server.level.ServerLevel level, String name, Function<net.minecraft.nbt.CompoundTag,T> load, Supplier<T> defaultData)
    Get a saved instance (own implementation) of SavedData.
    static <T extends net.minecraft.world.level.saveddata.SavedData>
    T
    getSaveData(net.minecraft.server.level.ServerLevel level, Function<net.minecraft.nbt.CompoundTag,T> load, String name, Function<String,T> defaultData)
    Get a saved instance (own implementation) of SavedData.
    static net.minecraft.server.level.ServerLevel
    getServerLevel(net.minecraft.server.MinecraftServer server, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key)
    Get the ServerLevel from the ResourceKey
    static net.minecraft.server.level.ServerLevel
    getServerLevel(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key)
    Get the ServerLevel from the ResourceKey
    static net.minecraft.world.phys.HitResult
    rayTraceServerSide(net.minecraft.world.entity.Entity entity, double range)
    Raytrace from an entities look vector for collisions in range.
    static net.minecraft.world.phys.HitResult
    rayTraceServerSide(net.minecraft.world.entity.Entity entity, double range, net.minecraft.world.level.ClipContext.Block blockMode, net.minecraft.world.level.ClipContext.Fluid fluidMode)
    Raytrace from an entities look vector for collisions in range.
    static net.minecraft.world.entity.Entity
    teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, double x, double y, double z, float yaw, float pitch)
    Teleports any entity to a given location in a given DimensionType.
    static net.minecraft.world.entity.Entity
    teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, net.minecraft.core.BlockPos pos)
    Teleports any entity to a given location in a given ServerLevel.
    static net.minecraft.world.entity.Entity
    teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, net.minecraft.world.phys.Vec3 pos)
    Teleports any entity to a given location in a given ServerLevel.
    static net.minecraft.world.entity.Entity
    teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, double x, double y, double z, float yaw, float pitch)
    Teleports any entity to a given location in a given ServerLevel.
    static net.minecraft.world.entity.Entity
    teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, double x, double y, double z, float yaw, float pitch, boolean detach)
    Teleports any entity to a given location in a given ServerLevel.
    static net.minecraft.world.entity.Entity
    teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos)
    Teleports any entity to a given location in a given ServerLevel.
    static net.minecraft.world.entity.Entity
    teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, net.minecraft.world.phys.Vec3 pos)
    Teleports any entity to a given location in a given ServerLevel.

    Methods inherited from class java.lang.Object

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

    • LevelUtil

      public LevelUtil()
  • Method Details

    • rayTraceServerSide

      public static net.minecraft.world.phys.HitResult rayTraceServerSide(net.minecraft.world.entity.Entity entity, double range)
      Raytrace from an entities look vector for collisions in range. Use default block mode ClipContext.Block.OUTLINE and fluid mode ClipContext.Fluid.NONE.
      Parameters:
      entity - Entity from where we get the look vector
      range - Range in blocks
      Returns:
      Raytrace result with information about the trace
    • rayTraceServerSide

      public static net.minecraft.world.phys.HitResult rayTraceServerSide(net.minecraft.world.entity.Entity entity, double range, net.minecraft.world.level.ClipContext.Block blockMode, net.minecraft.world.level.ClipContext.Fluid fluidMode)
      Raytrace from an entities look vector for collisions in range.
      Parameters:
      entity - Entity from where we get the look vector
      range - Range in blocks
      blockMode - Mode for block collisions
      fluidMode - Mode for fluid collisions
      Returns:
      Raytrace result with information about the trace
    • getSaveData

      public static <T extends net.minecraft.world.level.saveddata.SavedData> T getSaveData(net.minecraft.server.level.ServerLevel level, Function<net.minecraft.nbt.CompoundTag,T> load, String name, Function<String,T> defaultData)
      Get a saved instance (own implementation) of SavedData. If it does not exist, a new one is created.
      Type Parameters:
      T - Custom level save data class
      Parameters:
      level - Server level
      name - Name of this data
      defaultData - Function for creating an instance and for the default instance
      Returns:
      An instance of with the loaded data or default data.
    • getSaveData

      public static <T extends net.minecraft.world.level.saveddata.SavedData> T getSaveData(net.minecraft.server.level.ServerLevel level, String name, Function<net.minecraft.nbt.CompoundTag,T> load, Supplier<T> defaultData)
      Get a saved instance (own implementation) of SavedData. If it does not exist, a new one is created.
      Type Parameters:
      T - Custom level save data class
      Parameters:
      level - Server level
      name - Name of this data
      defaultData - Supplier for creating an instance and for the default instance
      Returns:
      An instance of with the loaded data or default data.
    • getServerLevel

      public static net.minecraft.server.level.ServerLevel getServerLevel(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key)
      Get the ServerLevel from the ResourceKey
      Parameters:
      entity - An entity used to get the server instance with Entity.getServer()
      key - The dimension key
      Returns:
      The server level for the given key
    • getServerLevel

      public static net.minecraft.server.level.ServerLevel getServerLevel(net.minecraft.server.MinecraftServer server, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key)
      Get the ServerLevel from the ResourceKey
      Parameters:
      server - The server instance
      key - The dimension key
      Returns:
      The server level for the given key
    • teleportEntity

      public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, net.minecraft.core.BlockPos pos)
      Teleports any entity to a given location in a given ServerLevel. Don't change the yaw and pitch of the entity.
      Parameters:
      entity - The entity to teleport
      key - The dimension key where the entity should be teleported. Can be the same as the current dimension key or a different one
      pos - The position the entity should be teleported to
      Returns:
      The teleported entity
    • teleportEntity

      public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, net.minecraft.world.phys.Vec3 pos)
      Teleports any entity to a given location in a given ServerLevel. Don't change the yaw and pitch of the entity.
      Parameters:
      entity - The entity to teleport
      key - The dimension key where the entity should be teleported. Can be the same as the current dimension key or a different one
      pos - The position the entity should be teleported to
      Returns:
      The teleported entity
    • teleportEntity

      public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos)
      Teleports any entity to a given location in a given ServerLevel. Don't change the yaw and pitch of the entity.
      Parameters:
      entity - The entity to teleport
      level - The server level where the entity should be teleported. Can be the same as the current level or a different one
      pos - The position the entity should be teleported to
      Returns:
      The teleported entity
    • teleportEntity

      public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, net.minecraft.world.phys.Vec3 pos)
      Teleports any entity to a given location in a given ServerLevel. Don't change the yaw and pitch of the entity.
      Parameters:
      entity - The entity to teleport
      level - The server level where the entity should be teleported. Can be the same as the current level or a different one
      pos - The position the entity should be teleported to
      Returns:
      The teleported entity
    • teleportEntity

      public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> key, double x, double y, double z, float yaw, float pitch)
      Teleports any entity to a given location in a given DimensionType.
      Parameters:
      entity - The entity to teleport
      key - The dimension key where the entity should be teleported. Can be the same as the current dimension key or a different one
      x - X-Coordinate
      y - Y-Coordinate
      z - Z-Coordinate
      yaw - Yaw
      pitch - Pitch
      Returns:
      The teleported entity
    • teleportEntity

      public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, double x, double y, double z, float yaw, float pitch)
      Teleports any entity to a given location in a given ServerLevel.
      Parameters:
      entity - The entity to teleport
      level - The server level where the entity should be teleported. Can be the same as the current level or a different one
      x - X-Coordinate
      y - Y-Coordinate
      z - Z-Coordinate
      yaw - Yaw
      pitch - Pitch
      Returns:
      The teleported entity
    • teleportEntity

      public static net.minecraft.world.entity.Entity teleportEntity(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel level, double x, double y, double z, float yaw, float pitch, boolean detach)
      Teleports any entity to a given location in a given ServerLevel.
      Parameters:
      entity - The entity to teleport
      level - The server level where the entity should be teleported. Can be the same as the current level or a different one
      x - X-Coordinate
      y - Y-Coordinate
      z - Z-Coordinate
      yaw - Yaw
      pitch - Pitch
      detach - Detach the entity
      Returns:
      The teleported entity