PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.96k stars 904 forks source link

Image from custom filled map #2442

Closed JIBSIL closed 2 years ago

JIBSIL commented 2 years ago

Versions

Detailed description of a problem

A clear and concise description of what the problem is, with as much context as possible. What are you building? What problem are you trying to solve?

Building a map viewer that works with custom maps as a mineflayer plugin. Non-vanilla maps are not compatible

What did you try yet?

Reading the image and mapping it to PNG colors

Did you try any example? Any error from those?

mineflayer-viewer doesn't show map item frames at all

Your current code


    bot._client.on('map', data => {
            console.log('Map received!')
            const size = 128;
            const image = PNGImage.createImage(size, size);

            console.log(`Map size is ${size}x${size}`)

            for (let x = 0; x < size; x++) {
                for (let z = 0; z < size; z++) {

                    const colorId = data[x + (z * size)];
                    image.setAt(x, z, getColor(colorId));

                }
            }

            image.writeImage(`${__dirname}/map${Math.floor(Math.random() * 100)}.png`, function(err) {
                if (err) throw err;
                console.log('Written to the file');
            });
        })

Expected behavior

Maps to output to file

Additional context

Maps are blank

amoraschi commented 2 years ago

Did you check out this plugin? Maybe it could help you

https://github.com/IceTank/mineflayer-item-map-downloader

JIBSIL commented 2 years ago

Did you check out this plugin? Maybe it could help you

https://github.com/IceTank/mineflayer-item-map-downloader

Yep, it did not detect any map at all

extremeheat commented 2 years ago

Is this supposed to be a bug with mineflayer ?

JIBSIL commented 2 years ago

Is this supposed to be a bug with mineflayer ?

It could be Mineflayer or node-minecraft-protocol, Mineflayer doesn't have any method to do it that I know of

extremeheat commented 2 years ago

Did you check out this plugin? Maybe it could help you

https://github.com/IceTank/mineflayer-item-map-downloader

I think this could be put in an example. If this works then the maps are being serialized normally, there is no issue here beyond your code

JIBSIL commented 2 years ago

Did you check out this plugin? Maybe it could help you https://github.com/IceTank/mineflayer-item-map-downloader

I think this could be put in an example. If this works then the maps are being serialized normally, there is no issue here beyond your code

I think it's something about how I parse images. How could I parse the image buffer that it feeds out

IceTank commented 2 years ago

@JIBSIL

Yep, it did not detect any map at all

Do you think you could make an issue about that and go more into detail what you are doing for it to not work? Or maybe message me on discord about it? Ic3Tank#3548 You can also find me in the prismarineJS discord server. Update: Found the issue why it is not working with 1.17.1 Mojang changed the map packet a bit. I will push a fix when I fixed it for all versions. Edit: Should be fixed now

u9g commented 2 years ago

Seems answered, closing. Open with more info if there is still some discussion here.