PrismarineJS / prismarine-design

Discuss about design and big refactoring that can affects many modules
2 stars 2 forks source link

Should Mineflayer/Flying-Squid be deeply integrated with Minecraft-Protocol? #4

Open TheDudeFromCI opened 4 years ago

TheDudeFromCI commented 4 years ago

I'm currently working on writing the design docs for the Mineflayer section when I started wondering whether or not Mineflayer (and Flying Squid) should be so tightly integrated with Minecraft-Protocol. Since all of the internal state is being moved info Prismarine-World, wouldn't it make sense to add another layer between Mineflayer and Minecraft-Protocol in the same manner?

Dependency Graph

For example, let's say we created a high-level version Minecraft-Protocol called Minecraft-Behavior or something. The purpose of this repository would be to add a higher level, version-agnostic implementation of Minecraft-Protocol. This would make maintaining both FlyingSquid and Mineflayer easier, since adding something like Minecraft 1.17 support would be done by updating this single module.

This way, we keep all states outside of Mineflayer and FlyingSquid, and we keep all protocols outside of Mineflayer and Flying Squid. The intermediate module would trigger events and add high level API for sending and recieving packets.

For example, look at Mineflayer's block_actions.js. Here, there are multiple conditions and packets to handle based on the Minecraft version. This is messy, in my opinion.

I think it would be a good idea to migrate the bot._client out of Mineflayer and into a dedicated module to manage all the low level packet processing. This new module could contain higher level packets such as useItem which would send the correct item use packet based on the given Minecraft version. It would also emit events when packets are recieved, and the format of each event would be identical, regardless of Minecraft version. (Such as in the example above, the packet would always use 'note_block', regardless of version. This would make it easier to maintain on Mineflayer and FlyingSquid.)

rom1504 commented 4 years ago

yes I agree. Here are some notes on this idea https://github.com/PrismarineJS/node-minecraft-protocol/issues/231

TheDudeFromCI commented 4 years ago

Oh, nice. I'll add this to the document, then.