News for hackers. Stuff that matters.
Re:Writing a Minecraft server from scratch in Bash (2022) by TeaVMFan on Saturday March 02, 2024 @10:44AM (#39573284)
As someone who's done a lot of work with scriptable Minecraft servers for both Java and Bedrock (ScraM), this is impressive. Bonus points for using "duckduckgoing" in a sentence.
Re:Writing a Minecraft server from scratch in Bash (2022) by BearOso on Saturday March 02, 2024 @11:25AM (#39573575)
A negative power, i.e. 2^(-n) is just 1/(2^n). I'm surprised the author didn't remember that with their own 2^-1 = 0.5 example and eventually reached out to awk for it.
Re:Writing a Minecraft server from scratch in Bash (2022) by tryauuum on Saturday March 02, 2024 @04:36PM (#39575985)
I don't understand how this would help the author. Since the bash doesn't support floating point numbers anyway
Re:Writing a Minecraft server from scratch in Bash (2022) by anthk on Sunday March 03, 2024 @09:01AM (#39580879)
This. Also, gawk has netwoki support, so you can write an mc server with just gawk.
Re:Writing a Minecraft server from scratch in Bash (2022) by BearOso on Sunday March 03, 2024 @11:29AM (#39581882)
I had the same thought. bc would have been a lighter choice.

And tryauuum, I think the author only needed powers of two to emulate floating point in the first place. So they could just divide said number by 2 a number of times.

Re:Writing a Minecraft server from scratch in Bash (2022) by pvg on Saturday March 02, 2024 @10:29AM (#39573158)
Discussion at the time https://news.ycombinator.com/item?id=30347501 92 comments
Re:Writing a Minecraft server from scratch in Bash (2022) by dang on Saturday March 02, 2024 @04:34PM (#39575971)
Thanks! Macroexpanded:

My thoughts on writing a Minecraft server from scratch in Bash - https://news.ycombinator.com/item?id=30347501 - Feb 2022 (90 comments)

Re:Writing a Minecraft server from scratch in Bash (2022) by SunlitCat on Saturday March 02, 2024 @11:24AM (#39573565)
Just wondering, but is writing custom servers for commercial games still a thing?
Re:Writing a Minecraft server from scratch in Bash (2022) by madeofpalk on Saturday March 02, 2024 @12:43PM (#39574184)
For Minecraft, very much so. Minecraft, especially the Java version, is in a comparatively odd place in that it receives significant free content updates AND officially supports running any historical version AND has an extremely vibrant modding community.

Minecraft (Java) is as much of a game engine for others to build on as it is a game itself.

Re:Writing a Minecraft server from scratch in Bash (2022) by themoonisachees on Saturday March 02, 2024 @01:20PM (#39574537)
This is because in addition to being the most sold video game of all time, minecraft is effectively open source. It's not literally open source, but you can decompile java bytecode with standard tooling, and symbols are available, either community-reversed, or official.
Re:Writing a Minecraft server from scratch in Bash (2022) by teaearlgraycold on Saturday March 02, 2024 @01:45PM (#39574797)
Frustrating how game studios can see Minecraft's success here and not change a thing about their development practices.
Re:Writing a Minecraft server from scratch in Bash (2022) by Aurornis on Saturday March 02, 2024 @03:04PM (#39575341)
There’s actually a very large and vibrant community for modding Unity games like this.

More competitive games can’t afford any type of easy reverse engineering due to the cheating factor.

Re:Writing a Minecraft server from scratch in Bash (2022) by darknavi on Saturday March 02, 2024 @04:03PM (#39575744)
Mods are the (amazing) end game for Lethal Company. So many fun, new tweaks and content.
Re:Writing a Minecraft server from scratch in Bash (2022) by noah91734 on Saturday March 02, 2024 @04:51PM (#39576084)
For the curious: https://thunderstore.io/c/lethal-company/

Click on any mod, and you can see the decompiled source. The mods use function hooking to run before or after certain functions are called rather than the event based system you see in Minecraft plugins.

Re:Writing a Minecraft server from scratch in Bash (2022) by ryukoposting on Sunday March 03, 2024 @10:54AM (#39581622)
I think Minecraft's position today has as much to do with the content of the game itself as it has to do with its architecture/Mojang's engineering choices.

The nearly-infinite expandability and modularity of Minecraft is partially due to the simplicity of the art, core game mechanics, and lack of storyline. Good mods are harder to make when the world they must integrate into is more complex.

I think this means a lot of games wouldn't see the kind of sustained success Minecraft has seen, even with more "open" development practices.

I hypothesize that the "open world" craze of years past was an attempt to capture Minecraft magic, but those games lacked the thematic open-endedness that really facilitates Minecraft's longevity.

Re:Writing a Minecraft server from scratch in Bash (2022) by LtWorf on Saturday March 02, 2024 @09:48PM (#39578011)
minetest is open source for real though
Re:Writing a Minecraft server from scratch in Bash (2022) by Filligree on Saturday March 02, 2024 @01:20PM (#39574536)
The four great game engines: Unreal, Unity, Minecraft and Godot.

I don’t think Minecraft is number four on the list. It might be number two.

Re:Writing a Minecraft server from scratch in Bash (2022) by jasonjayr on Saturday March 02, 2024 @01:58PM (#39574915)
Roblox is somewhere on that list too ....
Re:Writing a Minecraft server from scratch in Bash (2022) by Filligree on Saturday March 02, 2024 @06:02PM (#39576597)
How many thousand mods does it have?
Re:Writing a Minecraft server from scratch in Bash (2022) by BalinKing on Saturday March 02, 2024 @06:07PM (#39576641)
Isn't each server its own mod, in effect?
Re:Writing a Minecraft server from scratch in Bash (2022) by LtWorf on Saturday March 02, 2024 @09:47PM (#39578004)
Minetest is much more of a game engine.

I've heard from someone I know that played both extensively that minetest is less prone to losing everything for data corruption (never happened once in minetest, regularly in minecraft after a while. But sample size is 1).

Re:Writing a Minecraft server from scratch in Bash (2022) by tehbeard on Sunday March 03, 2024 @03:24AM (#39579391)
Is that sample size of one from the java edition or bedrock edition of minecraft?
Re:Writing a Minecraft server from scratch in Bash (2022) by LtWorf on Sunday March 03, 2024 @05:59AM (#39580061)
java
Re:Writing a Minecraft server from scratch in Bash (2022) by chungy on Sunday March 03, 2024 @10:53AM (#39581617)
I don't think I've ever witnessed data corruption in Minecraft, and that's even playing since Alpha 1.0.11 and multiple data format migrations... well, my sample size is 1, too.

I've also been on ZFS nearly the whole time. Are you certain Minecraft actually corrupted your data file, or do you suffer underlying hardware failure?

Re:Writing a Minecraft server from scratch in Bash (2022) by petee on Saturday March 02, 2024 @12:09PM (#39573920)
I think it will always be a thing for those who play games & like to dabble with tech, either to fix a bug, learn a language, or just see how the sausage is made.
Re:Writing a Minecraft server from scratch in Bash (2022) by firtoz on Saturday March 02, 2024 @12:58PM (#39574329)
AFAIK yes, the RE scene is still active.
Re:Writing a Minecraft server from scratch in Bash (2022) by haunter on Saturday March 02, 2024 @01:18PM (#39574512)
Not just servers but for some games clients too https://runelite.net/
Re:Writing a Minecraft server from scratch in Bash (2022) by static_motion on Saturday March 02, 2024 @02:15PM (#39575029)
I find RuneLite a fascinatingly well-built piece of software. The lead dev, Adam, did a fantastic job with it, and good on Jagex for allowing its use, even as far as advertising it on their own front page.
Re:Writing a Minecraft server from scratch in Bash (2022) by hoten on Saturday March 02, 2024 @02:53PM (#39575268)
It really papers over (some of) the tedium of the game and let's you enjoy the rest easier. Love it.
Re:Writing a Minecraft server from scratch in Bash (2022) by SunlitCat on Sunday March 03, 2024 @10:59AM (#39581658)
Although writing game servers for commercial games is already "difficult", isn't writing game clients for commercial games a huge issue copyright wise?
Re:Writing a Minecraft server from scratch in Bash (2022) by dinkleberg on Saturday March 02, 2024 @10:43AM (#39573268)
Now this is a proper hacker site. This is great.
Re:Writing a Minecraft server from scratch in Bash (2022) by lanthade on Saturday March 02, 2024 @11:17AM (#39573514)
Except for the font choice. Barely readable. My eyes are getting old.
Re:Writing a Minecraft server from scratch in Bash (2022) by monitron on Saturday March 02, 2024 @11:25AM (#39573576)
There is a set of radio buttons in the top right corner you can use to choose a different one :)
Re:Writing a Minecraft server from scratch in Bash (2022) by love2read on Saturday March 02, 2024 @11:20AM (#39573541)
This website is the one of the rare times where safari’s reader mode that changes the font was super nice to read.
Re:Writing a Minecraft server from scratch in Bash (2022) by lagniappe on Saturday March 02, 2024 @12:27PM (#39574063)
Weird, the older I get the better that font is for me. I wonder if that's because of nostalgia as all of the terminals at that age looked like this.
Re:Writing a Minecraft server from scratch in Bash (2022) by unnouinceput on Saturday March 02, 2024 @01:13PM (#39574461)
You can always use reader mode of your browser.
Re:Writing a Minecraft server from scratch in Bash (2022) by lanthade on Saturday March 02, 2024 @01:37PM (#39574716)
100% right. I completely forgot about that. Thanks.
Re:Writing a Minecraft server from scratch in Bash (2022) by taviso on Saturday March 02, 2024 @11:33AM (#39573626)
They should have used my (dumb?) library, ctypes.sh:

https://github.com/taviso/ctypes.sh

Then they can access libm, poll(), select() and so on from bash :)

Re:Writing a Minecraft server from scratch in Bash (2022) by lagniappe on Saturday March 02, 2024 @12:28PM (#39574073)
woah that's cool :) also hello tavis
Re:Writing a Minecraft server from scratch in Bash (2022) by MrBuddyCasino on Saturday March 02, 2024 @02:29PM (#39575100)
I‘m not sure you should have done that, but it is impressive for the sheer chuzpa of it. Like reanimating Frankenstein.
Re:Writing a Minecraft server from scratch in Bash (2022) by jethro_tell on Saturday March 02, 2024 @05:31PM (#39576357)
Lol, holy shit what did I just read?

Amazing, installing now. I want to be part of the problem.

Re:Writing a Minecraft server from scratch in Bash (2022) by Brian_K_White on Saturday March 02, 2024 @06:07PM (#39576645)
Awesome, but beside the point of writing something in bash that never needed to be in bash for any technical reason.

Meaning if it requires bash plus some specially installed compiled c code, then it might as well require c or python or anything else and there is no point in calling it "written in bash", or writing it in mostly-bash-plus-special-plugin.

I do know who I'm speaking to so please assume I say this respectfully. :) I have no problem with a "pointless" project like that as I'll show in a second.

That said, this minecraft project itself relies on externals like xxd when it doesn't need to, so using ctypes.sh would be no worse in this case, so you are right, in this case they might as well have.

But for the record it is possible to read, store, manipulate, do math on, and output binary in pure bash without anything like dd or xxd.

The only byte that is a problem is null, and there is a way to deal with that. You can't directly store a null, but you can detect that you read one and store that info, and reconstruct it on output later, or do math on it, use it's numerical value as an array index or byte offset or whatever the byte is for.

For a minimal example, just copying a binary file: while LANG=C IFS= read -d '' -r -n 1 x ;do printf '%c' "$x" ;done <bin1 >bin2

That's a bit too minimal since it doesn't show what other kinds of things you can do that are more useful than cat-without-cat.

A bit more generic and useful: https://gist.github.com/bkw777/c1413d0e3de6c54524ddae890fe8d...

The LANG=C, IFS= , and -d'' all combine to render all bytes accessible except 0x00, and then the return value from read() tells you the difference between "we read a 0x00" and "we didn't read anything" and "input ended"

And it doesn't have to use < and > on the overall while() comand either. You can exec 3<>file_or_fifo_or_tty and read -u3 / printf >&3 etc inside the loop instead.

An example reading from a serial port: https://gist.github.com/bkw777/ddde771cc85fdd888c7ec74953193...

Used in anger: https://github.com/bkw777/pdd.sh see tpdd_read, tpdd_write, file_to_fhex, str_to_shex reading and writing both a serial port and local files and doing all kinds of processing on the data.

And these loops are not even subshells let alone externals. You can manipulate variables inside the loop and you are still in the same original context. I'd say parent shell but there are no childern.

Those all read a single byte at a time with read -n 1, but they don't have to.

You can read without the -n1 and each iteration of the loop will collect as much as it can between nulls instead of always one byte. That would consume less ram and less loop iterations.

But the things I'm using them for want to slice & dice the individual bytes and byte-ranges at numerical offsets anyway and the data is always small (by todays standards) so the array-of-hex-pairs is just too convenient where a[n] == byte n, and all bytes are treated the same whether printable, non-printable, or null, and aside from merely storing and regenerating the bytes with printf you can also use the numerical values directly as well by simply prepending 0x, so 0x$n or 0x${a[n]} almost anywhere you would normally have a simple integer. So you can do math on them and use them as array indexes and byte offsets etc.

Read the 2nd byte of h[] as a length of the payload to follow, and clip out that payload: ${h[@]:2:0x${h[1]}}

Re:Writing a Minecraft server from scratch in Bash (2022) by captainbland on Sunday March 03, 2024 @08:18AM (#39580648)
I mean if it's good enough for python...
Re:Writing a Minecraft server from scratch in Bash (2022) by synergy20 on Sunday March 03, 2024 @11:30AM (#39581896)
would love to see how poll() and select() etc work this way
Re:Writing a Minecraft server from scratch in Bash (2022) by taviso on Sunday March 03, 2024 @12:00PM (#39582088)
Re:Writing a Minecraft server from scratch in Bash (2022) by bilekas on Saturday March 02, 2024 @06:47PM (#39576923)
So that happened... Jesus. I've read a lot of articles about the way they implement stuff but this takes the cake. Hands down one of, if not the best write up of something wild I've ever read. Top shelf.
Re:Writing a Minecraft server from scratch in Bash (2022) by osigurdson on Saturday March 02, 2024 @07:20PM (#39577115)
While I am not good at bash programming, I am surprised how capable / non horrible it actually is.
Re:Writing a Minecraft server from scratch in Bash (2022) by fddrdplktrew on Saturday March 02, 2024 @08:21PM (#39577481)
Minecraft, one of greatest game since Quake
Re:Writing a Minecraft server from scratch in Bash (2022) by synergy20 on Sunday March 03, 2024 @10:02AM (#39581226)
bash is one of my favorite, as favorite as vim and lua.

a single binary that is less than 2M bytes, universal, way more capable than many people think.

with shellcheck and good habits, bash can be readable and safe as well.

if you want something extra, you can always use C/C++ to add those utilities without using more involved FFI etc, and without pip/npm/etc to load who knows how many dependencies.

Re:Writing a Minecraft server from scratch in Bash (2022) by inetknght on Sunday March 03, 2024 @10:09AM (#39581286)
> with shellcheck and good habits, bash can be readable and safe as well.

My favorite thing to do with shellcheck: add it to CI. Developers hate this one trick!

A lot of times CI and Dockerfiles have inline bash scripts. My next favorite thing to do is to move all of that inlined bash to their own script files. Now that CI has shellcheck: all that stuff gets checked too! Developers seem to hate this though because it's "less readable". Less readable my ass, it's way more safe.

Next problem: the same bash scripts are now in the same files in multiple repositories (a distributed build). I'm open to ideas for improvements here.

Re:Writing a Minecraft server from scratch in Bash (2022) by klardotsh on Sunday March 03, 2024 @07:55PM (#39585989)
To skip the "move your scripts to standalone files" step some devs don't like, consider something like https://github.com/hadolint/hadolint which runs Shellcheck over inline scripts within Containerfiles.
Re:Writing a Minecraft server from scratch in Bash (2022) by yodsanklai on Sunday March 03, 2024 @10:15AM (#39581337)
I dislike bash because I'm not good with it. It sucks but is still often the best solution available. Actually, one of my regret was not to invest more time on it when I was a student (a while ago) because it's one of these rare tools that accompanied me my whole career.
Re:Writing a Minecraft server from scratch in Bash (2022) by inetknght on Sunday March 03, 2024 @10:17AM (#39581347)
It's true. The nice thing is that there are many many examples of how to use bash. Just open a script file in random repositories. Most scripts are super SUPER simple. But just copy-paste to shellcheck and it will give some feedback if you're looking to get in some really quick commits and PRs :)