API Reference v1.4.0

Comprehensive documentation for all ChosenLib utility classes and methods.

🌍 WorldUtils NEW

World and block manipulation utilities with safe operations and area queries.

Block Operations

Method Description Example
getBlockState(World world, BlockPos pos) Safely gets block state with chunk loading check WorldUtils.getBlockState(world, pos)
setBlockState(World world, BlockPos pos, BlockState state) Safely sets block state with validation WorldUtils.setBlockState(world, pos, newState)
isPositionLoaded(World world, BlockPos pos) Checks if position is loaded WorldUtils.isPositionLoaded(world, pos)
canPlaceBlock(World world, BlockPos pos, BlockState state) Checks if block can be placed WorldUtils.canPlaceBlock(world, pos, state)

Area Operations

Method Description Example
getBlocksInCube(BlockPos center, int radius) Gets all blocks in cubic area WorldUtils.getBlocksInCube(center, 5)
getBlocksInSphere(BlockPos center, double radius) Gets all blocks in spherical area WorldUtils.getBlocksInSphere(center, 5.0)
getBlocksInArea(BlockPos pos1, BlockPos pos2) Gets all blocks in rectangular area WorldUtils.getBlocksInArea(pos1, pos2)
findBlocks(World world, BlockPos center, int radius, Predicate<BlockState> predicate) Finds blocks matching predicate WorldUtils.findBlocks(world, center, 10, state -> state.isOf(Blocks.DIAMOND_ORE))

World Properties

Method Description Example
getBiome(World world, BlockPos pos) Gets biome at position WorldUtils.getBiome(world, pos)
getLightLevel(World world, BlockPos pos) Gets total light level WorldUtils.getLightLevel(world, pos)
canSeeSky(World world, BlockPos pos) Checks if position can see sky WorldUtils.canSeeSky(world, pos)
getHighestBlock(World world, int x, int z) Finds highest solid block WorldUtils.getHighestBlock(world, x, z)

👤 EntityUtils NEW

Entity-related helper functions for health, teleportation, and physics operations.

Health Management

Method Description Example
getHealth(Entity entity) Gets entity's current health EntityUtils.getHealth(entity)
setHealth(Entity entity, float health) Sets entity's health safely EntityUtils.setHealth(entity, 20.0f)
heal(Entity entity, float amount) Heals entity by amount EntityUtils.heal(entity, 10.0f)
damage(Entity entity, DamageSource source, float amount) Damages entity with source EntityUtils.damage(entity, damageSource, 5.0f)

Teleportation

Method Description Example
teleport(Entity entity, Vec3d pos) Teleports entity to position EntityUtils.teleport(entity, targetPos)
teleport(Entity entity, BlockPos pos) Teleports entity to block position EntityUtils.teleport(entity, blockPos)
teleportToEntity(Entity entity, Entity target) Teleports entity to another entity EntityUtils.teleportToEntity(entity, target)

Entity Finding

Method Description Example
getEntitiesInRadius(World world, Vec3d center, double radius, Predicate<Entity> predicate) Gets entities in radius with filter EntityUtils.getEntitiesInRadius(world, center, 10.0, null)
getPlayersInRadius(World world, Vec3d center, double radius) Gets players in radius EntityUtils.getPlayersInRadius(world, center, 20.0)
findNearestPlayer(World world, Vec3d center, double radius) Finds nearest player EntityUtils.findNearestPlayer(world, center, 50.0)

Physics Operations

Method Description Example
setVelocity(Entity entity, Vec3d velocity) Sets entity velocity EntityUtils.setVelocity(entity, new Vec3d(0, 1, 0))
launchTowards(Entity entity, Vec3d target, double force) Launches entity towards target EntityUtils.launchTowards(entity, target, 2.0)
knockback(Entity entity, Vec3d source, double force) Knocks back entity from source EntityUtils.knockback(entity, source, 1.5)

🌐 NetworkUtils NEW

Networking and packet utilities for client-server communication.

Packet Creation

Method Description Example
createBuffer() Creates new packet buffer NetworkUtils.createBuffer()
createBuffer(Consumer<PacketByteBuf> writer) Creates buffer with pre-written data NetworkUtils.createBuffer(buf -> buf.writeString("hello"))
createSimplePacket(String message) Creates simple string packet NetworkUtils.createSimplePacket("test message")
createPositionPacket(BlockPos pos) Creates position packet NetworkUtils.createPositionPacket(blockPos)

Packet Sending

Method Description Example
sendToPlayer(ServerPlayerEntity player, Identifier channelId, PacketByteBuf buffer) Sends packet to specific player NetworkUtils.sendToPlayer(player, channelId, buffer)
sendToWorld(ServerWorld world, Identifier channelId, PacketByteBuf buffer) Sends packet to all players in world NetworkUtils.sendToWorld(world, channelId, buffer)
sendToPlayersInRadius(ServerWorld world, Vec3d center, double radius, Identifier channelId, PacketByteBuf buffer) Sends packet to players in radius NetworkUtils.sendToPlayersInRadius(world, center, 50.0, channelId, buffer)

Data Serialization

Method Description Example
writeString(PacketByteBuf buffer, String string) Safely writes string to buffer NetworkUtils.writeString(buffer, "hello")
writeBlockPos(PacketByteBuf buffer, BlockPos pos) Writes block position to buffer NetworkUtils.writeBlockPos(buffer, pos)
writeVec3d(PacketByteBuf buffer, Vec3d vec) Writes vector to buffer NetworkUtils.writeVec3d(buffer, vec)
writeIntArray(PacketByteBuf buffer, int[] array) Writes integer array to buffer NetworkUtils.writeIntArray(buffer, new int[]{1,2,3})

🎨 GuiUtils ENHANCED

GUI utilities now server-side compatible with client-side extensions (ClientGuiUtils).

Server-Side Color Utilities

Method Description Example
rgba(int r, int g, int b, int a) Creates RGBA color GuiUtils.rgba(255, 0, 0, 255)
rgb(int r, int g, int b) Creates RGB color (opaque) GuiUtils.rgb(255, 0, 0)
getRed(int color) Extracts red component GuiUtils.getRed(color)
interpolateColor(int color1, int color2, float factor) Interpolates between colors GuiUtils.interpolateColor(red, blue, 0.5f)

Mathematical Operations

Method Description Example
centerX(int elementWidth, int containerWidth) Centers element horizontally GuiUtils.centerX(100, 200)
isPointInRect(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) Checks if point is in rectangle GuiUtils.isPointInRect(mouseX, mouseY, 10, 10, 100, 50)
rectanglesOverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) Checks if rectangles overlap GuiUtils.rectanglesOverlap(x1, y1, w1, h1, x2, y2, w2, h2)
distance(double x1, double y1, double x2, double y2) Calculates distance between points GuiUtils.distance(x1, y1, x2, y2)

ClientGuiUtils (Client-side only)

Method Description Example
drawRect(DrawContext context, int x, int y, int width, int height, int color) Draws filled rectangle ClientGuiUtils.drawRect(context, 10, 10, 100, 50, color)
drawProgressBar(DrawContext context, int x, int y, int width, int height, double progress, int bgColor, int fgColor) Draws progress bar ClientGuiUtils.drawProgressBar(context, x, y, w, h, 0.75, bg, fg)
drawCenteredText(DrawContext context, String text, int centerX, int y, int color) Draws centered text ClientGuiUtils.drawCenteredText(context, "Hello", centerX, y, color)

📝 TextUtils ENHANCED

Advanced text operations with performance improvements and interactive components.

Interactive Text Components

Method Description Example
clickable(String label, String url) Creates clickable URL text TextUtils.clickable("Visit", "https://example.com")
clickableCommand(String label, String command) Creates clickable command text TextUtils.clickableCommand("Run", "/help")
withTooltip(String label, String tooltip) Creates text with hover tooltip TextUtils.withTooltip("Hover me", "Tooltip text")
interactiveText(String label, String tooltip, String url) Creates text with hover and click TextUtils.interactiveText("Click", "Tooltip", "https://example.com")

Text Wrapping and Formatting

Method Description Example
wrapText(String text, int width) Wraps text to fit width TextUtils.wrapText(longText, 40)
createMultiLineTextBox(List<String> lines, int width) Creates multi-line text box TextUtils.createMultiLineTextBox(lines, 50)
formatNumber(long number) Formats number with separators TextUtils.formatNumber(1234567) // "1,234,567"
formatDuration(long milliseconds) Formats duration as human-readable TextUtils.formatDuration(90000) // "1m 30s"

Enhanced Validation (with caching)

Method Description Example
isBlank(String str) Checks if null, empty, or whitespace TextUtils.isBlank(" ") // true
matches(String str, String regex) Validates with cached regex patterns TextUtils.matches("abc123", "[a-z0-9]+")
progressBar(double percentage, int length) Creates percentage-based progress bar TextUtils.progressBar(0.75, 20)

🎒 ItemUtils ENHANCED

Comprehensive item management with performance optimizations and inventory operations.

Enhanced Item Operations

Method Description Example
getItemById(String id) Gets item by string identifier ItemUtils.getItemById("minecraft:diamond_sword")
canMerge(ItemStack stack1, ItemStack stack2) Checks if stacks can be merged ItemUtils.canMerge(stack1, stack2)
isDamageable(ItemStack stack) Checks if item is damageable ItemUtils.isDamageable(stack)
getDurabilityPercentage(ItemStack stack) Gets durability percentage ItemUtils.getDurabilityPercentage(stack)

Inventory Management

Method Description Example
insertStack(Inventory inventory, ItemStack stack) Inserts stack into inventory ItemUtils.insertStack(inventory, stack)
consumeItem(Inventory inventory, Item item, int amount) Consumes items from inventory ItemUtils.consumeItem(inventory, Items.DIAMOND, 5)
countItem(Inventory inventory, Item item) Counts total items in inventory ItemUtils.countItem(inventory, Items.DIAMOND)
findFirst(Inventory inventory, Predicate<ItemStack> predicate) Finds first matching stack ItemUtils.findFirst(inventory, stack -> stack.isEnchanted())

NBT and Enchantments

Method Description Example
getNbt(ItemStack stack) Gets NBT data from stack ItemUtils.getNbt(stack)
setNbt(ItemStack stack, NbtCompound nbt) Sets NBT data on stack ItemUtils.setNbt(stack, nbtData)
getEnchantmentLevel(ItemStack stack, RegistryEntry<Enchantment> enchantment) Gets enchantment level ItemUtils.getEnchantmentLevel(stack, enchantment)
isEnchanted(ItemStack stack) Checks if stack is enchanted ItemUtils.isEnchanted(stack)

🔧 General Utilities

General-purpose utilities available through the main ChosenLib class.

Math Utilities

Method Description Example
randomInt(int min, int max) Random integer in range ChosenLib.randomInt(1, 10)
clamp(int value, int min, int max) Clamps value between min and max ChosenLib.clamp(15, 0, 10) // 10
lerp(double a, double b, double t) Linear interpolation ChosenLib.lerp(0.0, 10.0, 0.5) // 5.0
isBetween(int value, int min, int max) Checks if value is in range ChosenLib.isBetween(5, 1, 10) // true

Utility Functions

Method Description Example
safeEquals(Object a, Object b) Null-safe equality check ChosenLib.safeEquals("a", "a") // true
debugLog(String message) Logs debug message with mod prefix ChosenLib.debugLog("Debug info")

⚡ Performance and Caching

ChosenLib v1.4.0 includes comprehensive caching systems for optimal performance.

Cache Management

Method Description Example
ItemUtils.getCacheStats() Gets ItemUtils cache statistics ItemUtils.getCacheStats()
TextUtils.getCacheStats() Gets TextUtils cache statistics TextUtils.getCacheStats()
ItemUtils.clearCache() Clears ItemUtils caches ItemUtils.clearCache()
TextUtils.clearCache() Clears TextUtils caches TextUtils.clearCache()

Cached Operations

  • ItemUtils: Item IDs and max stack sizes are cached for better performance
  • TextUtils: Compiled regex patterns and formatting styles are cached
  • Thread Safety: All caches use concurrent hash maps for thread-safe operations
  • Memory Efficient: Lazy initialization and efficient data structures

📋 API Versioning: This API reference is for v1.4.0. Future versions (1.5.0-1.9.0) may add new methods or deprecate existing ones. We maintain backward compatibility within major versions. Check our changelog for detailed version information.