PrismarineJS / node-minecraft-protocol

Parse and serialize minecraft packets, plus authentication and encryption.
https://prismarinejs.github.io/node-minecraft-protocol/
BSD 3-Clause "New" or "Revised" License
1.23k stars 239 forks source link

How to build the color buffer in the map packet ? #605

Closed Sceat closed 5 years ago

Sceat commented 5 years ago

I'm trying to send a map packet but still trying to figure out what kind of data i'd need to provide :disappointed:

this.client.write('map', {
    itemDamage: 0,
    scale: 4,
    trackingPosition: false,
    icons: [],
    columns: 127,
    rows: 127,
    x: 0,
    y: 0,
    data: ?,
})

The original wiki is not so clear either

Do i need to use prismarine-nbt and build a nbt representation of the map format ? it doesn't seems the right anwser at all so it's a dead end for my weak breain :disappointed_relieved:

rom1504 commented 5 years ago

Read this issue https://github.com/PrismarineJS/mineflayer/issues/583 I think it would be great to add a feature to so that either in mineflayer or an independent package. If you feel like doing that once you got this working, it would be useful to other people ;)

On Tue, Dec 11, 2018, 02:59 Sceat notifications@github.com wrote:

I'm trying to send a map packet http://minecraft-data.prismarine.js.org/?v=1.12.1&d=protocol#toClient_map but still trying to figure out what kind of data i'd need to provide 😞

this.client.write('map', {

itemDamage: 0,

scale: 4,

trackingPosition: false,

icons: [],

columns: 127,

rows: 127,

x: 0,

y: 0,

data: ?,

})


https://camo.githubusercontent.com/55352e6f1728161f63447b79d823853207116406/68747470733a2f2f692e696d6775722e636f6d2f70537a4872444d2e706e67

The original wiki is not so clear either

https://camo.githubusercontent.com/28291570b71e3f7ebb2e7d1ebd6f61072a322bb5/68747470733a2f2f692e696d6775722e636f6d2f716d643451526d2e706e67

Do i need to use prismarine-nbt and build a nbt representation of the map format ? it doesn't seems the right anwser at all so it's a dead end for my weak breain 😥

https://user-images.githubusercontent.com/11330271/49773156-98c5f800-fcf8-11e8-9a99-ace4a5466c3e.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/node-minecraft-protocol/issues/605, or mute the thread https://github.com/notifications/unsubscribe-auth/ACPN_qy4o8_8oiZNf2b-AsHubGSNOIg8ks5u3xGOgaJpZM4ZMhYB .

Sceat commented 5 years ago

Annnw okay it's just a dumb array lol thx mate! going to work on it but at least i managed to show something on the map :smile: !

for whoever wanting a quick working stuff see below

const buffer = []
let size = 128
const r = 89
const g = 125
const b = 39
for (let x = 0; x < size; x++) {
    for (let y = 0; y < size; y++) {
        buffer[x + y * size] = ((r & 255) << 16) + ((g & 255) << 8) + (b & 255)
    }
}

this.client.write('map', {
    itemDamage: 0,
    scale: 4,
    trackingPosition: false,
    icons: [],
    columns: --size,
    rows: size,
    x: 0,
    y: 0,
    data: Buffer.from(buffer),
})

image

Interesting result with every pixels set at 0xFFFFFF i got in game render of some part of my desktop lmao wtf, everytime i restart the server i get a different result, also tried to move some windows around to see if it impacted the render but dunno

image

Sceat commented 5 years ago

Still i get wrong colors dunno why

const buffer = []
const size = 128

for (let x = 0; x < size; x++) {
    for (let y = 0; y < size; y++) {
        buffer.push(0x7fb238)
    }
}

this.client.write('map', {
    itemDamage: 0,
    scale: 4,
    trackingPosition: false,
    icons: [],
    columns: size - 1,
    rows: size - 1,
    x: 0,
    y: 0,
    data: Buffer.from(buffer),
})

image image

image

Sceat commented 5 years ago

Problem solved

it was not a hex value but simply the corresponding id in the minecraft wiki table !

Contribution

I made an utility here aresrpg-map-colors ! it's MIT so feel free to use it if some want to make an official implementation in prismarine (the color table is only compatible 1.12 and higher)

Use with prismarine

import MapColor from '@aresrpg/aresrpg-map-colors'

const buffer = []
const size = 128
const { id } = MapColor.nearestMatch(49, 27, 146)
for (let x = 0; x < size; x++) for (let y = 0; y < size; y++) buffer.push(id)

this.client.write('map', {
    itemDamage: 0,
    scale: 4,
    trackingPosition: false,
    icons: [],
    columns: size - 1,
    rows: size - 1,
    x: 0,
    y: 0,
    data: Buffer.from(buffer),
})
Sceat commented 5 years ago

I can also make a PR if someone tell me in which way it should be implemented

rom1504 commented 5 years ago

Looks good. If I understand well this is a server side thing.

There are 2 possibilities (not incompatible, you can do both) :

  1. add a function in your module to convert a picture to a map using the function you already have
  2. then use it to make a flying-squid plugin (see its doc to see how to do it)

If you do 2 well, it will probably be usable even in a non-flying-squid context.

1 is probably good enough though, and you can just do a pr to reference your module in the readme and/or add a node-minecraft-protocol example to use your module ;)

On Sat, Dec 15, 2018, 06:38 Sceat notifications@github.com wrote:

I can also make a PR if someone tell me in which way it should be implemented

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/node-minecraft-protocol/issues/605#issuecomment-447539434, or mute the thread https://github.com/notifications/unsubscribe-auth/ACPN_oCnPjoZi7DRIhwzAe2bB0gqU4GIks5u5Iq6gaJpZM4ZMhYB .

rom1504 commented 5 years ago

hmm no would still like to have that in the readme

rom1504 commented 5 years ago

nevermind, it's already the case https://github.com/PrismarineJS/node-minecraft-protocol/commit/4cd893607c0c66277eb3982635bcfb5d567c85de