I'm a performances focused tool to help you manage minecraft map colors. I provide utilities to bridge between any colors to minecraft compatible colors
since 1.1.4 i also provide a transform stream under
aresrpg-map-colors/minecraftTransform
that take images as input and output only updated frames to avoid sending the whole image each time the feature is not documented yet so refer totest/index.js
npm i @aresrpg/aresrpg-map-colors
import { nearestMatch, color, hex, fromImage, COLORS } from '@aresrpg/aresrpg-map-colors'
Convert an image into an array of minecraft compatible ids
void (async function() {
const { width, height, datas } = await fromImage('https://i.imgur.com/28NLJWg.png')
console.log(datas.length) // imageWidth * imageHeight
console.log(datas) // [id,id,...] // uInt8
})()
use it with @Prismarine/node-minecraft-protocol
Note that you will need to handle image sizes and multiples neighbors map (via item frames) by your own, we only provide conversions
import { fromImage } from '@aresrpg/aresrpg-map-colors'
import mc from 'minecraft-protocol'
void (async function() {
const size = 128
const { datas } = await fromImage('https://i.imgur.com/h8g7SEf.jpg')
this.client.write('map', {
itemDamage: 0,
scale: 4,
trackingPosition: false,
icons: [],
columns: -size,
rows: -size,
x: 0,
y: 0,
data: Buffer.from(data),
})
})()
In case you want to build an item frame wall with multiple blocks you'll need to handle the buffer to split every 128 values, see Map item format
Arguments and return value are memoized for performances
We use a weighted aproach of the color space, read more on Here
const colorId = nearestMatch(70, 120, 35)
same as doing COLORS[id-4]
const { r, g, b } = color(4)
You can also get the decimal/hexadecimal value
const color = hex(4).toString(16)