Package com.minecolonies.api.util
Class Utils
java.lang.Object
com.minecolonies.api.util.Utils
General purpose utilities class. todo: split up into logically distinct parts
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckDirectory(@NotNull File directory) Checks if directory exists, else creates it.static <T> TdeserializeCodecMess(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.Tag tag) static <T> TdeserializeCodecMess(net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, T> codec, net.minecraft.network.RegistryFriendlyByteBuf buf) static net.minecraft.world.item.ItemStackdeserializeCodecMess(net.minecraft.network.RegistryFriendlyByteBuf buf) static <T> TdeserializeCodecMessFromJson(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, com.google.gson.JsonElement tag) static Stringformat(long value) Formats a long value into a abbreviated string, ie: 1000 to 1k, 1200 to 1.2k, 13000 to 13kstatic intgetBlueprintLevel(String schematicName) Get the level of this blueprint from the namestatic <T> net.minecraft.core.Holder<T> getRegistryValue(net.minecraft.resources.ResourceKey<T> resourceKey, net.minecraft.world.level.Level level) static booleanisBlockInRange(@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 longmask(long data, long mask) Returns what flags are set, and given in mask.static PathresolvePath(Path path, String subPath) Resolve a path with a sub path.static <T> net.minecraft.nbt.TagserializeCodecMess(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, T obj) static <T> voidserializeCodecMess(net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf, T> codec, net.minecraft.network.RegistryFriendlyByteBuf buf, T obj) static voidserializeCodecMess(net.minecraft.network.RegistryFriendlyByteBuf buf, net.minecraft.world.item.ItemStack obj) static <T> com.google.gson.JsonElementserializeCodecMessToJson(com.mojang.serialization.Codec<T> codec, net.minecraft.core.HolderLookup.Provider provider, T obj) static longsetFlag(long data, long flag) Sets a flag in in the data.static String[]Split path util.static booleantestFlag(long data, long flag) Checks if the flag is set in the data.static longtoggleFlag(long data, long flag) Toggles flags.static longunsetFlag(long data, long flag) Unsets a flag.
-
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
Split path util.- Parameters:
path- the path string.- Returns:
- the array.
-
resolvePath
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
Checks if directory exists, else creates it.- Parameters:
directory- the directory to check.
-
format
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
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)
-