mineflayer icon indicating copy to clipboard operation
mineflayer copied to clipboard

Image from filled map

Open enlyow opened this issue 8 years ago • 17 comments

Hello.

How get image from filled map?

enlyow avatar Aug 24 '17 17:08 enlyow

bot._client.on('map', console.log)

Mineflayer currently has no support for non vanilla map formats.

Some useful resources regarding the vanilla map format:

https://prismarinejs.github.io/minecraft-data/?d=protocol#toClient_map http://wiki.vg/Protocol#Map https://minecraft.gamepedia.com/Map_item_format

plexigras avatar Aug 24 '17 20:08 plexigras

Okay, I get buffer from map, but how convert it to png?

image

image

enlyow avatar Aug 25 '17 09:08 enlyow

you can use https://github.com/PrismarineJS/prismarine-nbt to decode packet.data

On Fri, Aug 25, 2017 at 11:50 AM enly1337 [email protected] wrote:

Okay, I get buffer from map, but how convert it to png?

[image: image] https://user-images.githubusercontent.com/29000881/29709134-f5d3374e-8993-11e7-9f63-d918ca424fb1.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/583#issuecomment-324873500, or mute the thread https://github.com/notifications/unsubscribe-auth/ACPN_iJzg2mgWAHYwCyay_dFiAbudgEJks5sbpjngaJpZM4PBsgu .

rom1504 avatar Aug 25 '17 10:08 rom1504

Ughm. It does not work.

image

image

enlyow avatar Aug 25 '17 11:08 enlyow

hmm nevermind, it's not nbt at all. you need to read it manually. It's "Optional Array of Unsigned Byte"

rom1504 avatar Aug 25 '17 11:08 rom1504

Hmm, how this "Optional Array of Unsigned Byte" convert to nbt? :)

enlyow avatar Aug 25 '17 11:08 enlyow

It doesn't, it's not nbt. I guess it's a yx indexed array. just loop through the bytes to get the colors

rom1504 avatar Aug 25 '17 12:08 rom1504

See this gist for a quick example on how to extract map colors.

lluiscab avatar Aug 29 '18 13:08 lluiscab

shouldn't this be size instead of 128?

https://gist.github.com/lluiscab/5eeda7e37b7d5d75f53f4c66e61b6537#file-map-js-L27-L28

plexigras avatar Aug 29 '18 13:08 plexigras

I've fixed that and tested the code with a level 4 map, seems like the size is always 128.

lluiscab avatar Aug 29 '18 13:08 lluiscab

@lluiscab can you share some test data i can use to test this out?

plexigras avatar Aug 29 '18 14:08 plexigras

Not really sure what do you want, best way to test this is to connect to some server, get a map and throwing it to the bot.

lluiscab avatar Aug 29 '18 14:08 lluiscab

just the output of console.log(JSON.stringify(data))

plexigras avatar Aug 29 '18 14:08 plexigras

Pastebin seems to be down, I've uploaded the json here

This JSON corresponds to this map (ingame) Map

And produces this output Map

lluiscab avatar Aug 29 '18 14:08 lluiscab

https://gist.github.com/plexigras/753007b7638a47162b6246e2b754414b

require('./map.js')(data).writeImage('map.png')

plexigras avatar Aug 29 '18 14:08 plexigras

pngjs-image is too old now and not passes npm audit. Has anyone rewritten it?

ulcuber avatar May 16 '22 15:05 ulcuber

Huh this issue is still open? @ulcuber use this https://github.com/IceTank/mineflayer-item-map-downloader

IceTank avatar May 16 '22 16:05 IceTank