Class Utils

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

public final class Utils extends Object
General purpose utilities class. todo: split up into logically distinct parts
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkDirectory(@NotNull File directory)
    Checks if directory exists, else creates it.
    static <T> T
    deserializeCodecMess(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.Tag tag)
     
    static <T> T
    deserializeCodecMess(net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,T> codec, net.minecraft.network.RegistryFriendlyByteBuf buf)
     
    static net.minecraft.world.item.ItemStack
    deserializeCodecMess(net.minecraft.network.RegistryFriendlyByteBuf buf)
     
    static <T> T
    deserializeCodecMessFromJson(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, com.google.gson.JsonElement tag)
     
    static String
    format(long value)
    Formats a long value into a abbreviated string, ie: 1000 to 1k, 1200 to 1.2k, 13000 to 13k
    static int
    getBlueprintLevel(String schematicName)
    Get the level of this blueprint from the name
    static <T> net.minecraft.core.Holder<T>
    getRegistryValue(net.minecraft.resources.ResourceKey<T> resourceKey, net.minecraft.world.level.Level level)
     
    static boolean
    isBlockInRange(@NotNull net.minecraft.world.level.Level world, net.minecraft.world.level.block.Block block, int posX, int posY, int posZ, int range)
    Searches a block in a custom range.
    static long
    mask(long data, long mask)
    Returns what flags are set, and given in mask.
    static Path
    resolvePath(Path path, String subPath)
    Resolve a path with a sub path.
    static <T> net.minecraft.nbt.Tag
    serializeCodecMess(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, T obj)
     
    static <T> void
    serializeCodecMess(net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,T> codec, net.minecraft.network.RegistryFriendlyByteBuf buf, T obj)
     
    static void
    serializeCodecMess(net.minecraft.network.RegistryFriendlyByteBuf buf, net.minecraft.world.item.ItemStack obj)
     
    static <T> com.google.gson.JsonElement
    serializeCodecMessToJson(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, T obj)
     
    static long
    setFlag(long data, long flag)
    Sets a flag in in the data.
    static String[]
    Split path util.
    static boolean
    testFlag(long data, long flag)
    Checks if the flag is set in the data.
    static long
    toggleFlag(long data, long flag)
    Toggles flags.
    static long
    unsetFlag(long data, long flag)
    Unsets a flag.

    Methods inherited from class java.lang.Object

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

    • isBlockInRange

      public static boolean isBlockInRange(@NotNull @NotNull net.minecraft.world.level.Level world, net.minecraft.world.level.block.Block block, int posX, int posY, int posZ, int range)
      Searches a block in a custom range.
      Parameters:
      world - World instance.
      block - searched Block.
      posX - X-coordinate.
      posY - Y-coordinate.
      posZ - Z-coordinate.
      range - the range to check around the point.
      Returns:
      true if he found the block.
    • splitPath

      public static String[] splitPath(String path)
      Split path util.
      Parameters:
      path - the path string.
      Returns:
      the array.
    • resolvePath

      public static Path resolvePath(Path path, String subPath)
      Resolve a path with a sub path.
      Parameters:
      path - the path.
      subPath - the sub path.
      Returns:
      the appended path.
    • testFlag

      public static boolean testFlag(long data, long flag)
      Checks if the flag is set in the data. E.G. - Flag: 000101. - Data: 100101. - All Flags are set in data, so returns true. Some more flags are set, but not take into account
      Parameters:
      data - Data to check flag in.
      flag - Flag to check whether it is set or not.
      Returns:
      True if flag is set, otherwise false.
    • mask

      public static long mask(long data, long mask)
      Returns what flags are set, and given in mask. E.G. - Flag: 000101. - Mask: 100101. - The 4th and 6th bit are set, so only those will be returned.
      Parameters:
      data - Data to check.
      mask - Mask to check.
      Returns:
      Byte in which both data bits and mask bits are set.
    • setFlag

      public static long setFlag(long data, long flag)
      Sets a flag in in the data. E.G. - Flag: 000101 - Mask: 100001 - The 4th bit will now be set, both the 1st and 6th bit are maintained.
      Parameters:
      data - Data to set flag in.
      flag - Flag to set.
      Returns:
      Data with flags set.
    • unsetFlag

      public static long unsetFlag(long data, long flag)
      Unsets a flag. E.G. - Flag: 000101 - Mask: 100101 - The 4th and 6th bit will be unset, the 1st bit is maintained.
      Parameters:
      data - Data to remove flag from.
      flag - Flag to remove.
      Returns:
      Data with flag unset.
    • toggleFlag

      public static long toggleFlag(long data, long flag)
      Toggles flags. E.G. - Flag: 000101 - Mask: 100101 - The 4th and 6th will be toggled, the 1st bit is maintained.
      Parameters:
      data - Data to toggle flag in.
      flag - Flag to toggle.
      Returns:
      Data with flag toggled.
    • checkDirectory

      public static void checkDirectory(@NotNull @NotNull File directory)
      Checks if directory exists, else creates it.
      Parameters:
      directory - the directory to check.
    • format

      public static String format(long value)
      Formats a long value into a abbreviated string, ie: 1000 to 1k, 1200 to 1.2k, 13000 to 13k
      Parameters:
      value - to format
      Returns:
      string version of the value
    • getBlueprintLevel

      public static int getBlueprintLevel(String schematicName)
      Get the level of this blueprint from the name
      Parameters:
      schematicName - the name of the blueprint.
      Returns:
      the level or -1 if it doesn't have one.
    • getRegistryValue

      public static <T> net.minecraft.core.Holder<T> getRegistryValue(net.minecraft.resources.ResourceKey<T> resourceKey, net.minecraft.world.level.Level level)
    • serializeCodecMess

      public static <T> net.minecraft.nbt.Tag serializeCodecMess(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, T obj)
    • deserializeCodecMess

      public static <T> T deserializeCodecMess(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.Tag tag)
    • serializeCodecMessToJson

      public static <T> com.google.gson.JsonElement serializeCodecMessToJson(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, T obj)
    • deserializeCodecMessFromJson

      public static <T> T deserializeCodecMessFromJson(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, com.google.gson.JsonElement tag)
    • serializeCodecMess

      public static <T> void serializeCodecMess(net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,T> codec, net.minecraft.network.RegistryFriendlyByteBuf buf, T obj)
    • deserializeCodecMess

      public static <T> T deserializeCodecMess(net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,T> codec, net.minecraft.network.RegistryFriendlyByteBuf buf)
    • serializeCodecMess

      public static void serializeCodecMess(net.minecraft.network.RegistryFriendlyByteBuf buf, net.minecraft.world.item.ItemStack obj)
    • deserializeCodecMess

      public static net.minecraft.world.item.ItemStack deserializeCodecMess(net.minecraft.network.RegistryFriendlyByteBuf buf)