API Reference v1.6.0

Comprehensive documentation for all ChosenLib utility classes and methods.

🔧 AdvancedBlockOps NEW v1.5.0

Enhanced block manipulation with safety checks, transactional editing, and undo systems.

Transactional Operations

Method Description Example
startTransaction(World world) Begins a new transaction for safe block operations AdvancedBlockOps.startTransaction(world)
commitTransaction(TransactionId id) Commits all changes in transaction AdvancedBlockOps.commitTransaction(transactionId)
rollbackTransaction(TransactionId id) Rolls back all changes in transaction AdvancedBlockOps.rollbackTransaction(transactionId)
safeSetBlock(World world, BlockPos pos, BlockState state) Safely sets block with validation AdvancedBlockOps.safeSetBlock(world, pos, state)

Area Operations

Method Description Example
fillArea(World world, BlockPos pos1, BlockPos pos2, BlockState state) Fills area with specified block AdvancedBlockOps.fillArea(world, pos1, pos2, state)
replaceInArea(World world, BlockPos pos1, BlockPos pos2, BlockState from, BlockState to) Replaces blocks in area AdvancedBlockOps.replaceInArea(world, pos1, pos2, from, to)
copyArea(World world, BlockPos source1, BlockPos source2, BlockPos dest) Copies block area to new location AdvancedBlockOps.copyArea(world, source1, source2, dest)
analyzeArea(World world, BlockPos pos1, BlockPos pos2) Analyzes area for patterns and statistics AdvancedBlockOps.analyzeArea(world, pos1, pos2)

🤖 EntityAIUtils NEW v1.5.0

AI utilities for custom mobs and behavior management with goal systems and pathfinding.

Goal Management

Method Description Example
addGoal(MobEntity entity, Goal goal, int priority) Adds AI goal with priority EntityAIUtils.addGoal(entity, goal, 1)
removeGoal(MobEntity entity, Class<? extends Goal> goalClass) Removes specific goal type EntityAIUtils.removeGoal(entity, FollowPlayerGoal.class)
clearGoals(MobEntity entity) Clears all AI goals EntityAIUtils.clearGoals(entity)
getActiveGoals(MobEntity entity) Gets list of active goals EntityAIUtils.getActiveGoals(entity)

Behavior States

Method Description Example
setBehaviorState(MobEntity entity, String state) Sets custom behavior state EntityAIUtils.setBehaviorState(entity, "aggressive")
getBehaviorState(MobEntity entity) Gets current behavior state EntityAIUtils.getBehaviorState(entity)
addMemory(MobEntity entity, String key, Object value) Adds memory to AI system EntityAIUtils.addMemory(entity, "lastPlayer", player)
getMemory(MobEntity entity, String key) Retrieves AI memory EntityAIUtils.getMemory(entity, "lastPlayer")

💾 DataPersistence NEW v1.5.0

World, player, and global data storage with compression and migration support.

World Data

Method Description Example
saveWorldData(ServerWorld world, String key, Object data) Saves data to world DataPersistence.saveWorldData(world, "config", configData)
loadWorldData(ServerWorld world, String key, Class<T> type) Loads data from world DataPersistence.loadWorldData(world, "config", Config.class)
deleteWorldData(ServerWorld world, String key) Deletes world data DataPersistence.deleteWorldData(world, "oldData")
hasWorldData(ServerWorld world, String key) Checks if world data exists DataPersistence.hasWorldData(world, "config")

Player Data

Method Description Example
savePlayerData(PlayerEntity player, String key, Object data) Saves data to player DataPersistence.savePlayerData(player, "stats", statsData)
loadPlayerData(PlayerEntity player, String key, Class<T> type) Loads player data DataPersistence.loadPlayerData(player, "stats", Stats.class)
migratePlayerData(UUID playerId, String fromKey, String toKey) Migrates player data DataPersistence.migratePlayerData(playerId, "oldKey", "newKey")

✨ EffectsUtils NEW v1.5.0

Sound and particle effect utilities with timing control and combinations.

Sound Effects

Method Description Example
playSound(World world, Vec3d pos, SoundEvent sound, float volume, float pitch) Plays sound at position EffectsUtils.playSound(world, pos, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)
playSoundToPlayer(PlayerEntity player, SoundEvent sound, float volume, float pitch) Plays sound to specific player EffectsUtils.playSoundToPlayer(player, sound, 1.0f, 1.0f)
playDelayedSound(World world, Vec3d pos, SoundEvent sound, int delay) Plays sound after delay EffectsUtils.playDelayedSound(world, pos, sound, 20)
createSoundSequence(SoundEvent[] sounds, int[] delays) Creates sound sequence EffectsUtils.createSoundSequence(sounds, delays)

Particle Effects

Method Description Example
spawnParticle(World world, ParticleEffect particle, Vec3d pos) Spawns particle at position EffectsUtils.spawnParticle(world, ParticleTypes.EXPLOSION, pos)
spawnParticleLine(World world, ParticleEffect particle, Vec3d start, Vec3d end, int count) Spawns particles in line EffectsUtils.spawnParticleLine(world, particle, start, end, 10)
spawnParticleSphere(World world, ParticleEffect particle, Vec3d center, double radius, int count) Spawns particles in sphere EffectsUtils.spawnParticleSphere(world, particle, center, 2.0, 20)
createParticleSystem(ParticleEffect particle, Vec3d center, int duration) Creates persistent particle system EffectsUtils.createParticleSystem(particle, center, 100)

🌐 AdvancedNetworking fixed v1.5.1

Sophisticated packet handling with routing, synchronization, compression, and encryption.

Packet Routing

Method Description Example
createPacket(String type, Object data) Creates typed packet AdvancedNetworking.createPacket("data", dataObject)
routePacket(Identifier channel, PacketByteBuf buffer, PacketRoute route) Routes packet with custom logic AdvancedNetworking.routePacket(channel, buffer, route)
broadcastPacket(Identifier channel, PacketByteBuf buffer, Predicate<PlayerEntity> filter) Broadcasts packet with filter AdvancedNetworking.broadcastPacket(channel, buffer, player -> true)
syncData(Identifier channel, String key, Object data) Synchronizes data across clients AdvancedNetworking.syncData(channel, "config", config)

Compression and Encryption

Method Description Example
compressPacket(PacketByteBuf buffer) Compresses packet data AdvancedNetworking.compressPacket(buffer)
decompressPacket(PacketByteBuf buffer) Decompresses packet data AdvancedNetworking.decompressPacket(buffer)
encryptPacket(PacketByteBuf buffer, String key) Encrypts packet data AdvancedNetworking.encryptPacket(buffer, "secret")
decryptPacket(PacketByteBuf buffer, String key) Decrypts packet data AdvancedNetworking.decryptPacket(buffer, "secret")

🌍 DimensionUtils NEW v1.5.0

Custom dimension management with teleportation and portal systems.

Dimension Management

Method Description Example
createDimension(Identifier dimensionId, DimensionType dimensionType) Creates new custom dimension DimensionUtils.createDimension(new Identifier("mymod", "custom"), dimensionType)
deleteDimension(Identifier dimensionId) Deletes custom dimension DimensionUtils.deleteDimension(dimensionId)
getDimensionInfo(Identifier dimensionId) Gets dimension information DimensionUtils.getDimensionInfo(dimensionId)
listCustomDimensions() Lists all custom dimensions DimensionUtils.listCustomDimensions()

Teleportation

Method Description Example
teleportToDimension(Entity entity, Identifier dimensionId, Vec3d pos) Teleports entity to dimension DimensionUtils.teleportToDimension(entity, dimensionId, pos)
createPortal(World world, BlockPos pos, Identifier destination) Creates portal to dimension DimensionUtils.createPortal(world, pos, destination)
findPortal(World world, Identifier dimensionId) Finds existing portal DimensionUtils.findPortal(world, dimensionId)

🔴 RedstoneUtils NEW v1.5.0

Redstone circuit analysis and automation with signal manipulation and logic gates.

Circuit Analysis

Method Description Example
analyzeCircuit(World world, BlockPos pos, int radius) Analyzes redstone circuit RedstoneUtils.analyzeCircuit(world, pos, 10)
getSignalStrength(World world, BlockPos pos) Gets redstone signal strength RedstoneUtils.getSignalStrength(world, pos)
setSignalStrength(World world, BlockPos pos, int strength) Sets redstone signal strength RedstoneUtils.setSignalStrength(world, pos, 15)
findRedstoneComponents(World world, BlockPos center, int radius) Finds redstone components RedstoneUtils.findRedstoneComponents(world, center, 5)

Logic Gates

Method Description Example
createANDGate(World world, BlockPos pos, List<BlockPos> inputs) Creates AND logic gate RedstoneUtils.createANDGate(world, pos, inputs)
createORGate(World world, BlockPos pos, List<BlockPos> inputs) Creates OR logic gate RedstoneUtils.createORGate(world, pos, inputs)
createNOTGate(World world, BlockPos pos, BlockPos input) Creates NOT logic gate RedstoneUtils.createNOTGate(world, pos, input)
simulateLogicGate(LogicGateType type, int[] inputs) Simulates logic gate operation RedstoneUtils.simulateLogicGate(LogicGateType.AND, inputs)

📊 PerformanceMonitor NEW v1.5.0

Built-in performance profiling with memory monitoring, tick analysis, and reporting.

Memory Monitoring

Method Description Example
getMemoryUsage() Gets current memory usage PerformanceMonitor.getMemoryUsage()
getHeapUsage() Gets heap memory usage PerformanceMonitor.getHeapUsage()
startMemoryTracking() Starts memory tracking PerformanceMonitor.startMemoryTracking()
stopMemoryTracking() Stops memory tracking PerformanceMonitor.stopMemoryTracking()

Performance Analysis

Method Description Example
startProfiling(String name) Starts performance profiling PerformanceMonitor.startProfiling("myOperation")
endProfiling(String name) Ends performance profiling PerformanceMonitor.endProfiling("myOperation")
getTPSData(ServerWorld world) Gets TPS (Ticks Per Second) data PerformanceMonitor.getTPSData(world)
generatePerformanceReport(ServerWorld world) Generates comprehensive report PerformanceMonitor.generatePerformanceReport(world)

📂 FileUtils NEW v1.6.0

File system utilities for safe file operations and data management.

File Operations

Method Description Example
readFile(Path path) Reads the content of a file into a string. FileUtils.readFile(Paths.get("config.txt"))
writeFile(Path path, String content) Writes content to a file. FileUtils.writeFile(Paths.get("config.txt"), "content")
copyFile(Path source, Path destination) Copies a file. FileUtils.copyFile(source, destination)
moveFile(Path source, Path destination) Moves a file. FileUtils.moveFile(source, destination)
deleteFile(Path path) Deletes a file. FileUtils.deleteFile(path)

Directory Operations

Method Description Example
createDirectory(Path path) Creates a directory. FileUtils.createDirectory(Paths.get("data"))
listFiles(Path path) Lists files in a directory. FileUtils.listFiles(Paths.get("data"))
searchFiles(Path startPath, String globPattern) Searches for files matching a glob pattern. FileUtils.searchFiles(Paths.get("."), "*.json")

💻 Command Framework NEW v1.6.0

A framework for creating and managing commands.

Core Components

Class/Interface Description
Command An interface that all commands must implement.
CommandManager A manager class to register and initialize commands.

🌍 WorldUtils ENHANCED v1.5.0

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.5.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.6.0. Future versions may add new methods or deprecate existing ones. We maintain backward compatibility within major versions. Check our changelog for detailed version information.