Minecraft Server In Bash | Prime Reacts
TLDRThe script narrates the ambitious endeavor of writing a Minecraft server from scratch using Bash, a task fraught with challenges due to Bash's limitations with binary data and decimal numbers. Despite these hurdles, the creator perseveres, implementing various protocols and data structures, including varints, floating-point numbers, and NBT format. The project, named 'witchcraft', showcases the creator's ingenuity and determination, resulting in a functional, albeit slow, server capable of handling basic Minecraft gameplay elements. The narrative also delves into the creator's personal experiences with the Minecraft community and his struggles with the game's mechanics, highlighting the human aspect of coding and gaming.
Takeaways
- 🤔 The speaker has been contemplating writing a Minecraft server in Bash as a thought exercise for the past year.
- 🛠️ They faced challenges with parsing binary data in Bash, particularly with handling null bytes and C strings.
- 💡 A revelation led to a solution where binary data is processed within a pipe, avoiding the need for variable storage and null byte issues.
- 📊 The speaker experimented with different tools like DD, xxd, and ncat to handle file copying, data conversion, and network communication.
- 📈 They implemented number conversion routines in Bash, including handling varints and IEEE 754 floating-point numbers.
- 🔄 The process involved understanding and implementing the Minecraft protocol, which includes various data types and encodings.
- 📝 The speaker developed a working implementation for floating-point conversion using an external utility, despite initial difficulties.
- 🎲 They created a 'witchcraft' server that can load and display chunks, and even supports plugins for additional functionality.
- 🚀 The speaker's server is capable of handling multiple threads and data exchange, albeit with some performance limitations.
- 🎉 Despite the challenges, the speaker expresses a sense of accomplishment and amusement at the 'train wreck' success of their project.
- 🎮 The speaker admits a personal dislike for Minecraft and prefers games with a more action-oriented approach.
Q & A
What is the main challenge the speaker faced when trying to write a Minecraft server in Bash?
-The main challenge was handling binary data in Bash, as Bash does not have a straightforward way to parse binary data and it ignores null bytes in strings.
How did the speaker overcome the issue of null bytes in Bash strings?
-The speaker had a revelation about reversing the order of the function so that binary data never reaches a variable, but stays inside a pipe, allowing null bytes to be passed around.
What tool did the speaker use to read a specific number of bytes and convert them to a hex dump?
-The speaker used a combination of the `dd` command and the `xxd` utility to read bytes and convert them to a hex dump.
What is the purpose of implementing the server list ping packet in a Minecraft server?
-While not strictly required, implementing the server list ping packet is beneficial as it is the easiest part to tackle first and helps familiarize oneself with the core protocol concepts.
How did the speaker handle the varint (variable-length integer) encoding in Bash?
-The speaker implemented a custom decoding function for varints in Bash, which involved bit shifting and modulo operations.
What is the significance of the 'DimensionCodec' in the Minecraft protocol?
-DimensionCodec is a part of the join game packet that sends initial metadata about the world, including player identity, game mode, and dimension data.
How did the speaker simplify the implementation of the chunk data structure?
-The speaker simplified the implementation by using an 8-bit block definition instead of the minimal 4-bit definition, which allowed for easier data transmission using hex numbers referencing palette entries.
What is the speaker's opinion on the use of variable-length encoding for numbers in the Minecraft protocol?
-The speaker finds variable-length encoding unnecessary and somewhat painful unless a large portion of the numbers being sent are between 0 and 127, as it can lead to inefficiencies in data transmission.
What is the speaker's stance on the use of floating-point numbers in the Minecraft protocol?
-The speaker is not a fan of floating-point numbers due to their complexity and the difficulty in implementing the necessary conversion functions in Bash.
What is the speaker's overall assessment of the Minecraft protocol?
-The speaker finds the Minecraft protocol to be somewhat messy and complex, particularly due to the use of multiple number formats and the handling of floating-point numbers.
Outlines
📝 Writing a Minecraft Server in Bash
The speaker discusses their thought process behind writing a Minecraft server in Bash, a scripting language. They mention the challenges of handling binary data in Bash, particularly the issue with null bytes and C strings. The speaker shares their realization that by using a pipe and the 'dd' command, they could pass null bytes correctly. They also delve into the specifics of implementing the Minecraft protocol, including the server list ping packet and the complexities of handling different data types such as varints and floating-point numbers.
🔢 Dealing with Data Types in Bash
The speaker continues to explore the difficulties of handling various data types in Bash, focusing on the length-encoded byte and the varint format. They express frustration with the inefficiency of variable length encoding and the challenges of implementing signed integers. The speaker also discusses their aversion to floating-point numbers and the protocol's use of them, leading to a search for a utility to handle negative powers. They eventually find a solution using the 'awk' command and share their experience with the slow conversion function for handling player movement packets.
🎮 Minecraft Server Development
The speaker talks about their journey in developing a Minecraft server, including the challenges of implementing the handshake process and managing chunk parameters. They mention the use of NBT (Named Binary Tag) format and the complexity of handling chunk data. The speaker also reflects on their experiences with the Minecraft community and their struggles with being blocked on Twitter, particularly by the furry community.
🛠️ Implementing Chunk Data and Plugins
The speaker describes the implementation of chunk data in their Minecraft server, explaining the structure of chunk sections and the use of palette structures for block values. They discuss the decision to use an 8-bit block definition for simplicity and the challenges of encoding and decoding data. The speaker also introduces the concept of 'hooks' in their server, which are overridable functions for plugin development, and shares their thoughts on the limitations of Bash for this project.
🎲 Personal Reflections on Minecraft
The speaker shares their personal reflections on Minecraft, expressing their dislike for the game due to motion sickness and a preference for action-oriented games. They discuss their family's gaming preferences, including their children's shift from Minecraft to Roblox and their own enjoyment of games like Fortnite and Elden Rings. The speaker also talks about their creation of 'Witchcraft,' a Minecraft server written in Bash, and the challenges of handling decimal numbers and multi-threading in Bash.
Mindmap
Keywords
💡Minecraft Server
💡Bash
💡Binary Data
💡Varint
💡Floating-Point Numbers
💡Protocol Implementation
💡Data Types
💡Chunk Data
💡NBT (Named Binary Tag)
💡Hooks
Highlights
The speaker has been contemplating writing a Minecraft server in Bash for a year.
The challenge of parsing binary data in Bash was highlighted, especially with null bytes.
A solution was found by keeping binary data within a pipe, allowing null bytes to pass through.
The use of `dd` and `xxd` for reading and writing data in Bash was discussed.
The concept of variable-length encoding (varint) was explained and its application in the Minecraft protocol.
The speaker implemented a server list ping packet, which is essential for the server to function.
The difficulty of handling IEEE 754 floating-point numbers in Bash was mentioned.
A working implementation for floating-point conversion was achieved using an external binary.
The speaker's Minecraft server, named 'quirks', was introduced, which is a Bash-based server.
The 'quirks' server allows for custom plugins and has a demo that generates random chunks.
The speaker's personal experience with motion sickness while playing Minecraft was shared.
The speaker's preference for games with action and shooting elements over Minecraft's building aspect was expressed.
The speaker's household is a 'claymore household', favoring action-packed games like Elden Rings.
The speaker's disdain for Bash is contrasted with the appreciation for the effort put into the 'quirks' project.
The 'quirks' server's slow performance and limitations due to Bash's nature were acknowledged.
The speaker's experience with being blocked on Twitter, particularly by the furry community, was humorously recounted.
The speaker's approach to handling chunk data and biomes in the 'quirks' server was described.
The speaker's decision to use an 8-bit block definition for simplicity in the 'quirks' server was explained.
The speaker's thoughts on the Minecraft protocol and its complexity were shared.
The speaker's implementation of the 'join game' packet and its challenges were discussed.
The speaker's plans for future demos and the potential of the 'quirks' server were hinted at.