Class McUtils

java.lang.Object
com.shanebeestudios.coreapi.util.McUtils

public class McUtils extends Object
Utility class for changing Minecraft to/from Bukkit classes
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.world.level.biome.Biome
    getBiomeInChunk(@NotNull net.minecraft.world.level.chunk.LevelChunk levelChunk, int x, int y, int z)
    Get the biome at a specific point in a chunk
    static net.minecraft.world.level.biome.Biome
    getBiomeInChunk(@NotNull Chunk chunk, int x, int y, int z)
    Get the biome at a specific point in a chunk
    static @NotNull net.minecraft.world.level.biome.BiomeResolver
    getBiomeResolver(@NotNull MutableInt count, @NotNull net.minecraft.world.level.chunk.ChunkAccess chunkAccess, @NotNull net.minecraft.world.level.levelgen.structure.BoundingBox box, @NotNull net.minecraft.core.Holder<net.minecraft.world.level.biome.Biome> biome, @NotNull Predicate<net.minecraft.core.Holder<net.minecraft.world.level.biome.Biome>> filter)
    Make a resolver for 3D shifted biomes
    static @NotNull BlockData
    getBlockDataFromState(@NotNull net.minecraft.world.level.block.state.BlockState blockState)
    Get a Bukkit Blockdata from a Minecraft BlockState
    static @NotNull net.minecraft.world.level.block.state.BlockState
    getBlockStateFromBlock(@NotNull Block bukkitBlock)
    Get a Minecraft BlockState from a Bukkit Block
    static @NotNull net.minecraft.world.level.block.state.BlockState
    getBlockStateFromData(@NotNull BlockData blockData)
    Get a Minecraft BlockState from a Bukkit BlockData
    static @NotNull net.minecraft.core.Direction
    getDirection(@NotNull BlockFace blockFace)
    Convert Bukkit BlockFace to Minecraft Direction
    static net.minecraft.world.entity.EntityType<?>
    Get the NMS EntityType from Bukkit EntityType
    static <T> net.minecraft.core.Holder.Reference<T>
    getHolderReference(@NotNull net.minecraft.core.Registry<T> registry, @NotNull NamespacedKey key)
    Get a holder reference from a registry
    static @NotNull net.minecraft.resources.Identifier
    getIdentifier(@NotNull NamespacedKey bukkitKey)
    Convert a Bukkit NamespacedKey to Minecraft Identifier
    static net.minecraft.world.level.chunk.LevelChunk
    getLevelChunk(@NotNull Chunk chunk)
    Get an instance of a LevelChunk from a BukkitChunk
    static @NotNull com.mojang.datafixers.util.Pair<net.minecraft.server.level.ServerLevel,net.minecraft.core.BlockPos>
    getLevelPos(@NotNull Location location)
    Get a Minecraft Level and BlockPos from a Bukkit Location
    static @NotNull Location
    getLocation(@NotNull net.minecraft.core.BlockPos blockPos, @NotNull net.minecraft.world.level.Level level)
    Get a Bukkit Location from a Minecraft BlockPos and Level
    static @NotNull NamespacedKey
    getNamespacedKey(@NotNull net.minecraft.resources.Identifier identifier)
    Convert Minecraft Identifier to Bukkit NamespacedKey
    static net.minecraft.world.entity.Entity
    getNMSEntity(Entity bukkitEntity)
    Get an NMS Entity from a Bukkit Entity
    static @NotNull net.minecraft.core.BlockPos
    getPos(@NotNull Location location)
    Get a Minecraft BlockPos from a Bukkit Location
    static <T> net.minecraft.core.Registry<T>
    getRegistry(@NotNull net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<? extends T>> registryKey, boolean unfreeze)
    Get a Minecraft Registry
    static <T> @NotNull List<NamespacedKey>
    getRegistryKeys(@NotNull net.minecraft.core.Registry<T> registry)
    Get all keys from a registry
    static <T> T
    getRegistryValue(@NotNull net.minecraft.core.Registry<T> registry, @NotNull NamespacedKey key)
    Get a keyed value from a registry
    static @NotNull net.minecraft.server.level.ServerLevel
    getServerLevel(@NotNull World world)
    Get an instance of ServerLevel from a Bukkit World
    static @NotNull net.minecraft.server.level.ServerPlayer
    getServerPlayer(@NotNull Player player)
    Get a Minecraft ServerPlayer from a Bukkit Player
    static @NotNull net.minecraft.world.phys.Vec3
    getVec3(@NotNull Location location)
    Get a Minecraft Vec3 from a Bukkit Location
    static @NotNull net.minecraft.world.level.WorldGenLevel
    getWorldGenLevel(@NotNull World world)
    Deprecated.
    Unused, use getServerLevel(World) instead

    Methods inherited from class java.lang.Object

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

    • getPos

      @NotNull public static @NotNull net.minecraft.core.BlockPos getPos(@NotNull @NotNull Location location)
      Get a Minecraft BlockPos from a Bukkit Location
      Parameters:
      location - Location to change to BlockPos
      Returns:
      BlockPos from Location
    • getVec3

      @NotNull public static @NotNull net.minecraft.world.phys.Vec3 getVec3(@NotNull @NotNull Location location)
      Get a Minecraft Vec3 from a Bukkit Location
      Parameters:
      location - Location to convert to Vec3
      Returns:
      Vec3 from Location
    • getDirection

      @NotNull public static @NotNull net.minecraft.core.Direction getDirection(@NotNull @NotNull BlockFace blockFace)
      Convert Bukkit BlockFace to Minecraft Direction
      Parameters:
      blockFace - BlockFace to convert
      Returns:
      Minecraft Direction from BlockFace
    • getLevelPos

      @NotNull public static @NotNull com.mojang.datafixers.util.Pair<net.minecraft.server.level.ServerLevel,net.minecraft.core.BlockPos> getLevelPos(@NotNull @NotNull Location location)
      Get a Minecraft Level and BlockPos from a Bukkit Location
      Parameters:
      location - Location to get world and pos from
      Returns:
      Pair of Level and BlockPos
    • getLocation

      @NotNull public static @NotNull Location getLocation(@NotNull @NotNull net.minecraft.core.BlockPos blockPos, @NotNull @NotNull net.minecraft.world.level.Level level)
      Get a Bukkit Location from a Minecraft BlockPos and Level
      Parameters:
      blockPos - BlockPos to change to location
      level - Level to add to location
      Returns:
      Location from BlockPos/Level
    • getIdentifier

      @NotNull public static @NotNull net.minecraft.resources.Identifier getIdentifier(@NotNull @NotNull NamespacedKey bukkitKey)
      Convert a Bukkit NamespacedKey to Minecraft Identifier
      Parameters:
      bukkitKey - NamespacedKey to change to Identifier
      Returns:
      Identifier from NamespacedKey
    • getNamespacedKey

      @NotNull public static @NotNull NamespacedKey getNamespacedKey(@NotNull @NotNull net.minecraft.resources.Identifier identifier)
      Convert Minecraft Identifier to Bukkit NamespacedKey
      Parameters:
      identifier - Identifier to change to NamespacedKey
      Returns:
      NamespacedKey from Identifier
    • getServerLevel

      @NotNull public static @NotNull net.minecraft.server.level.ServerLevel getServerLevel(@NotNull @NotNull World world)
      Get an instance of ServerLevel from a Bukkit World
      Parameters:
      world - World to get ServerLevel from
      Returns:
      ServerLevel from World
    • getWorldGenLevel

      @NotNull @Deprecated public static @NotNull net.minecraft.world.level.WorldGenLevel getWorldGenLevel(@NotNull @NotNull World world)
      Deprecated.
      Unused, use getServerLevel(World) instead
      Get an instance of WorldGenLevel from a Bukkit World
      Parameters:
      world - Bukkit world to get WorldGenLevel from
      Returns:
      WorldGenLevel from Bukkit world
    • getLevelChunk

      public static net.minecraft.world.level.chunk.LevelChunk getLevelChunk(@NotNull @NotNull Chunk chunk)
      Get an instance of a LevelChunk from a BukkitChunk
      Parameters:
      chunk - Bukkit Chunk to convert
      Returns:
      LevelChunk from Chunk
    • getRegistry

      public static <T> net.minecraft.core.Registry<T> getRegistry(@NotNull @NotNull net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<? extends T>> registryKey, boolean unfreeze)
      Get a Minecraft Registry
      Type Parameters:
      T - ResourceKey
      Parameters:
      registryKey - ResourceKey of registry
      unfreeze - Optionally unfreeze the registry for modification
      Returns:
      Registry from key
    • getServerPlayer

      @NotNull public static @NotNull net.minecraft.server.level.ServerPlayer getServerPlayer(@NotNull @NotNull Player player)
      Get a Minecraft ServerPlayer from a Bukkit Player
      Parameters:
      player - Bukkit player to convert to NMS player
      Returns:
      NMS player
    • getNMSEntity

      public static net.minecraft.world.entity.Entity getNMSEntity(@NotNull Entity bukkitEntity)
      Get an NMS Entity from a Bukkit Entity
      Parameters:
      bukkitEntity - Bukkit Entity
      Returns:
      NMS Entity
    • getEntityType

      public static net.minecraft.world.entity.EntityType<?> getEntityType(@NotNull EntityType bukkitType)
      Get the NMS EntityType from Bukkit EntityType
      Parameters:
      bukkitType - Bukkit EntityType to convert
      Returns:
      NMS EntityType from Bukkit
    • getBlockDataFromState

      @NotNull public static @NotNull BlockData getBlockDataFromState(@NotNull @NotNull net.minecraft.world.level.block.state.BlockState blockState)
      Get a Bukkit Blockdata from a Minecraft BlockState
      Parameters:
      blockState - BlockState to convert
      Returns:
      BlockData from state
    • getBlockStateFromBlock

      @NotNull public static @NotNull net.minecraft.world.level.block.state.BlockState getBlockStateFromBlock(@NotNull @NotNull Block bukkitBlock)
      Get a Minecraft BlockState from a Bukkit Block
      Parameters:
      bukkitBlock - Bukkit Block to grab state from
      Returns:
      BlockState from Bukkit Block
    • getBlockStateFromData

      @NotNull public static @NotNull net.minecraft.world.level.block.state.BlockState getBlockStateFromData(@NotNull @NotNull BlockData blockData)
      Get a Minecraft BlockState from a Bukkit BlockData
      Parameters:
      blockData - BlockData to convert
      Returns:
      Converted BlockState
    • getHolderReference

      @Nullable public static <T> net.minecraft.core.Holder.Reference<T> getHolderReference(@NotNull @NotNull net.minecraft.core.Registry<T> registry, @NotNull @NotNull NamespacedKey key)
      Get a holder reference from a registry
      Type Parameters:
      T - Class type of registry
      Parameters:
      registry - Registry to grab holder from
      key - Key of holder
      Returns:
      Holder from registry
    • getRegistryValue

      @Nullable public static <T> T getRegistryValue(@NotNull @NotNull net.minecraft.core.Registry<T> registry, @NotNull @NotNull NamespacedKey key)
      Get a keyed value from a registry
      Type Parameters:
      T - Registry class type
      Parameters:
      registry - Registry to grab value from
      key - Key of value to grab
      Returns:
      Value from registry
    • getRegistryKeys

      @NotNull public static <T> @NotNull List<NamespacedKey> getRegistryKeys(@NotNull @NotNull net.minecraft.core.Registry<T> registry)
      Get all keys from a registry
      Type Parameters:
      T - Registry class type
      Parameters:
      registry - Registry to grab keys from
      Returns:
      List of NamespacedKeys for all keys in registry
    • getBiomeResolver

      @NotNull public static @NotNull net.minecraft.world.level.biome.BiomeResolver getBiomeResolver(@NotNull @NotNull MutableInt count, @NotNull @NotNull net.minecraft.world.level.chunk.ChunkAccess chunkAccess, @NotNull @NotNull net.minecraft.world.level.levelgen.structure.BoundingBox box, @NotNull @NotNull net.minecraft.core.Holder<net.minecraft.world.level.biome.Biome> biome, @NotNull @NotNull Predicate<net.minecraft.core.Holder<net.minecraft.world.level.biome.Biome>> filter)
      Make a resolver for 3D shifted biomes
      Parameters:
      count - counter
      chunkAccess - Chunk where biome is
      box - BoundingBox for biome change
      biome - Biome
      filter - Filter
      Returns:
      Biome resolver
    • getBiomeInChunk

      public static net.minecraft.world.level.biome.Biome getBiomeInChunk(@NotNull @NotNull net.minecraft.world.level.chunk.LevelChunk levelChunk, int x, int y, int z)
      Get the biome at a specific point in a chunk
      Parameters:
      levelChunk - Chunk to get biome
      x - x coord of block in chunk
      y - y coord of block in chunk
      z - z coord of block in chunk
      Returns:
      Biome at position in chunk
    • getBiomeInChunk

      public static net.minecraft.world.level.biome.Biome getBiomeInChunk(@NotNull @NotNull Chunk chunk, int x, int y, int z)
      Get the biome at a specific point in a chunk
      Parameters:
      chunk - Chunk to get biome
      x - x coord of block in chunk
      y - y coord of block in chunk
      z - z coord of block in chunk
      Returns:
      Biome at position in chunk