@mcbe-mods/utils
v1.0.0-beta.6
Published
Utility functions for Minecraft Bedrock Edition mod development
Readme
@mcbe-mods/utils
Utility functions for Minecraft Bedrock Edition mod development. Part of the @mcbe-mods/runtime monorepo.
Usage
Install:
npm install @mcbe-mods/utilsimport { Base64, Color, Experience, getCubeRange, getRandomProbability, getRandomRangeValue, getSphereRange, ms2ticks, splitGroups, unique } from '@mcbe-mods/utils'
// splitGroups - split items into stacks
splitGroups(65) // => [64, 1]
splitGroups(140) // => [64, 64, 12]
// Color - Minecraft formatting codes
Color.green.italic.bold('Dedicated Ser') + Color.reset('ver') + Color.red.obfuscated('!!!')
// => '§a§o§lDedicated Ser§rver§c§k!!!'
// Experience - player XP calculation
const exp = new Experience()
exp.addXP(100)
exp.getLevel() // => 7
// ms2ticks - time to ticks
ms2ticks(1000) // => 20
// getCubeRange / getSphereRange - block position range
getCubeRange({ x: 0, y: 0, z: 0 }, 1) // => 27 positions (cube)
getSphereRange({ x: 0, y: 0, z: 0 }, 1) // => 27 positions (sphere)API
| Function | Description |
| --- | --- |
| splitGroups(sum, groupSize?) | Split a number into groups of a given size |
| Color | Minecraft color/formatting code stylizer |
| Experience | Player experience calculator (leveling up) |
| ms2ticks(milliseconds?, gameTicksPerSecond?, millisecondsPerSecond?) | Convert real time to game ticks |
| getCubeRange(location, radius?) | Get block positions in a cube |
| getRandomProbability(probability) | Random chance with percentage |
| getRandomRangeValue(min, max) | Random integer within a range |
| getSphereRange(location, radius?) | Get block positions in a sphere |
| unique(size?) | Generate a random alphanumeric string |
| Base64 | Base64 encode/decode utility |
| utf8Encode(s) | Encode string to UTF-8 bytes using encodeURIComponent |
| utf8Decode(bytes) | Decode UTF-8 bytes back to string using decodeURIComponent |
