Will It Host? / Garry's Mod

Can you run a Minecraft server in Garry's Mod?

It hosted#8 of 18 by difficulty

Yes. The process listening on port 25565 is Garry's Mod, and a vanilla Minecraft client connects to it and plays on it. This is the first host with physics: every block placed is a real prop, so you can physgun it, drop it, shoot it or blow it up, and the block does the same thing in Minecraft as it happens. The Minecraft player is a ragdoll you can pick up and carry.

verdict
It hosted
A vanilla Minecraft client connected and played on it.
difficulty
#8 of 18
Ranked against everything else in the series, hardest first.
built withLua
protocolMinecraft 1.8.9
read the source on github β†’

How it works

A listen server runs the game and the server in one process, so the socket sits inside the binary drawing the map. A small C++ binary module does non-blocking sockets and nothing else; everything about Minecraft is Lua. Each tick, any prop that is not frozen has its position rounded to a cell and compared with the cell it was filed under, so physgunning, falling and explosions all come out as the same block change. Anything spawned in Garry's Mod is voxelised from its collision mesh and turns up in Minecraft as wool, still moving.

The part that nearly stopped it

Garry's Mod stops caring when its window loses focus, and you spend the whole session in Minecraft. Source throttles or pauses an unfocused game, so a server driven by the game tick misses its keep-alives and the client decides it has died.

What got it over the line

Taking the send path away from the game. The module owns the outbound buffer and runs its own thread that drains it and injects a keep-alive whenever the connection has been quiet for two seconds, and Lua hands it whole packets so the thread can never split one. Lua 5.1 had its usual gaps too: floats are built from math.frexp and math.ldexp, and the 64-bit block position travels as two 32-bit halves because a LuaJIT number cannot hold it exactly.

What it cannot do

Minecraft 1.8.9, the same target as the rest of the series. One player, a world sixteen blocks tall and eighty blocks square, and props that leave that region stop existing in Minecraft. It needs the 64-bit Garry's Mod beta and a two player game, because singleplayer Source pauses entirely when unfocused, and nothing is saved.

Why this is possible at all

A Minecraft Java server is a smaller thing than its reputation suggests. It is a socket, a packet codec and a game loop. The client opens one TCP connection, sends a handshake naming its protocol version, moves through login into the play state, and from then on both sides exchange length-prefixed packets describing chunks, entities and movement. None of that needs a game engine. It needs something that can hold a socket open and put the right bytes on it in the right order, which is why Garry's Mod can be made to do it. In every episode the host is the hard part.

Every build in this series targets Minecraft 1.8.9 for one specific reason. In 1.8 a chunk is a flat byte array you can send uncompressed. From 1.9 onward chunk data is palette-encoded into bit-packed longs and the connection expects zlib, which is not something you can hand-write in VBA. 1.8.9 is the last release where the whole protocol is within reach of a scripting runtime that was never meant for it.

We have written both halves of that up properly: how the Minecraft server protocol works covers the wire format, and what a Minecraft server actually needs to run covers the four things a real one cannot do without.

Questions

Can Garry's Mod run a Minecraft server?

Yes, with a binary module and a Lua script. Garry's Mod loads native modules into its own process, so a few hundred lines of C++ are enough to give Lua a socket on port 25565, and the Minecraft protocol is written in Lua on top of it. Start a two player game and the server comes up with the map. The full source is on GitHub.

What happens when you physgun a block?

It moves in Minecraft while you move it, rounded to the nearest cell, then falls under gravity when you let go and updates the whole way down. Blocks are ordinary props, so the toolgun works too: weld a contraption together and the whole shape moves through the Minecraft world as one.

The rest of the series

See the full Will It Host? board β†’

Or just host it properly

Garry's Mod is not where your survival world should live. AMD Ryzen 9700X, hard-reserved RAM, NVMe, online in under a minute with a free address, DDoS protection and a 7-day money-back guarantee.