3.1.0 • Published 9 months ago

@aresrpg/aresrpg-map-colors v3.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

aresrpg-map-colors

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 to test/index.js


Installation

npm i @aresrpg/aresrpg-map-colors

Minecraft colors

npm.io


Usage

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

Find the closest color available in minecraft from any color

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)

npm.io npm.io

Find a color by id

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)
3.1.0

9 months ago

3.0.0

9 months ago

2.0.2

4 years ago

2.0.1

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.18

5 years ago

1.0.16

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago