And then AI arrived
United States
Breaking News:
Washington DC
Tuesday, Nov 17, 2026
I’d abandoned development of this game a long time ago, and I’ve used the arrival of AI to give it a good push.
Since besides programming it can also draw, the least I could do was get rid of the abomination of a logo I made and generate a new one.
We went from:
to:
Same with the UI, from my hideous design:
We changed to:
While we were at it, it’s a tiiiny bit more responsive than before (meaning it should adapt better to different screen sizes), but not much. Unity has a UI system I barely understand, and I’d rather do everything with CSS. But for now we’ll stick with this iteration.
Now that our eyes no longer bleed the moment we open the game, we can move on to cleaning up the code.
Until now Brickcraft only had 1 AssemblyFile. In other words, aaaall the code was lumped into a single file.
Which meant that eeeeeeeeeeevery time, for example, the UI was edited, the game mechanics’ code was recompiled. No matter what you touched, everything had to be recompiled.
The way to avoid this is splitting the code into multiple AssemblyFiles: the UI in one place, the AI in another, the mechanics in another, etc. But of course, these sections still need to talk to each other.
The solution is to create an event system, so one side emits and the other listens.
Again, this isn’t something I fancied doing by hand, so the AI took on the refactor.
Now we can start focusing on harder tasks.
Since I’d focused entirely on the building mechanics, the game was singleplayer and not much else.
When you want to make a multiplayer game, the process is a pain, even using third-party libraries.
The reason is that in this kind of game you want to stop the player from cheating, which means the server has to validate each and every sensitive action.
If, for example, you want to place a block, where before we’d have something as simple as:
void addBlock(Vector3 position, string type) { if (!IsValidPlacement(position)) return; return; } Instantiate("prefabs/type", position);
}
To make it secure it would end up, at MINIMUM, like this:
public void RequestAddBlock(Vector3 position, string type) { if (IsServer) { AddBlockServerInternal(position, type); } else { AddBlockServerRpc(position, type); } } [ServerRpc(RequireOwnership = false)] private void AddBlockServerRpc(Vector3 position, string type) { if (!IsValidPlacement(position)) return; AddBlockServerInternal(position, type); } private void AddBlockServerInternal(Vector3 position, string type) { GameObject prefabToSpawn = GetPrefabForType(type); GameObject blockInstance = Instantiate(prefabToSpawn, position, Quaternion.identity); NetworkObject netObj = blockInstance.GetComponent(); netObj.Spawn(); }
A constant ping-pong between client and server, what’s known as authoritative multiplayer.
Thanks to AI, migrating the existing code to this wall of text was automatic, and for that I relied on the Mirror library (because it’s free and open source).
That said, the auth part is a bit flimsy when it comes to how easy it is to impersonate other users. The only good way I see to avoid that would be publishing the game on Steam so I could use its auth. That’s left for another iteration. For the same reason I haven’t enabled creating dedicated servers. It’s not worth it for now.
The next multiplayer headache is showing the other users on screen, so we need a model.
If you remember the first blog post, LEGO minifigures are still copyrighted, so using them isn’t an option.
Instead I chose to iterate on the design with AI, making a version that, among other things, has knees.
With another AI I was able to get a 3D model from that image, but I won’t post pictures so I don’t spoil the final result for you. We’ll just call this part done xD
Obviously there has to be some way for players to communicate, so chat has been added too.
Which in turn will serve as a channel for sending certain messages to the player. For example, notifying when a player connects:
There are a couple of basic actions every multiplayer game needs: kicking and banning users. Taking advantage of the chat, these have been added along with several more commands (like giving someone the admin role), which can be seen with /help.
To keep track of the users who join a server, their role, whether they’re banned and so on, you need a database. The choice here was simple because I only see 1 candidate: sqlite. It works on every platform and there’s even a Unity package for it.
We can’t forget the player list either. While we were at it, buttons have been added to do the same admin tasks with total comfort.
Finally, adding multiplayer comes with one last big headache: versioning.
It’s not just that client and server need versions so the server only lets in those on the same one, but that after every update both the database and the generated world must be able to receive changes.
In other words, a migration system has to be built.
When you update the game and go to your list of worlds, those last played on an older version will be marked and upgraded automatically, without (hopefully) any noticeable change.
With the multiplayer part done, we can move on to the next big headache: having aaaaaaaaaaaaaaaaaaaaaaaaall the official pieces.
When I started this project I barely added a couple of pieces. The most important one for me was the 2×2, because it was the closest to a Minecraft cube, which made it much easier to reuse Minecraft world generators.
However, Lego has a couple more pieces, about 4,000 more…
Obviously adding them had to be done in bulk and therefore automatically.
Luckily there are several options, the most interesting one for me being LDraw: an open source library that holds a 3D model of every piece.
With that it was “just a matter” of downloading the 180-odd MBs it took up and building an interpreter that could read the library’s custom format. Then the icon generator would also need improving so it could be run indiscriminately, in bulk.
And that’s how admins got the ALL tab in the inventory:
Buuuuuuuuuuuuut…… Having every model isn’t enough… We also need every color.
Luckily there are websites like Rebrickable where you can download that list with total ease: Rebrickable.com
Now only one tiny detail was left: combining both lists.
Usually what all these websites do is generate an icon for each piece, in every available color.
I don’t want my PC full of 99999 duplicate images whose only difference is the color, so I went for a dirty little hack: tinting the images.
We know the model’s standard color, so just generating the icon in that color and then replacing it does the trick.
It won’t look right in every case, but in the vast majority it passes, and that’s good enough for me.
Great! Perfect! We don’t have to worry about pieces/models anymore. Right?
How wrong you are, my friend. I want more. Much more.
The point of Lego is that there are no prefab models of things like beds, because you’re expected to build them out of pieces.
That means we need a way to load models that are a combination of many pieces. And this is where the next new feature comes in.
The need is clear: you have to be able to build anything in-game and then export it so the game itself can use it.
To do that there’s an item that, when you right click a block, goes looking for every block connected to it to work out the model’s bounding box, which is just a box representing its limits. Since there’s room to screw it up (imagine you’ve changed the floor you built on but don’t want it to be part of the model), there’s an option to edit the bounding box by hand before generating the model.
While we’re at it, we optimize the generated model by doing things like removing the studs of pieces that have another piece on top. You can’t see them, so we can spare them.
Making the exporter also unlocked the main reason I started this game: being able to build models intuitively, aka Minecraft-style, and then buy the physical pieces they’re made of and build it in real life.
At first I was looking at and implementing the format websites like BrickLink use to import a list of pieces you want to buy. (Bricklink.com)
P
6260
1
1
N
After building that format, I found out BrickLink also accepts LDraw files… So I chose to add generating that file too, so you can not only get the parts list but also import the models you create into other Lego building tools:
Now we’re finally sorted for models, right? Nope.
The next big model-related problem to solve is my lack of creativity. And how do we solve that? By using other people’s.
For that the game should support mods, so any user can add new items/models to the game and, while at it, do much more than that.
Mods usually need 3 things: running code, creating UIs and adding models.
I’m not one bit happy about third-party code running on my PC, so it has to be something I know will be locked down to the bare minimum. So the choice is obvious: Lua.
Lua is an embeddable language. Unlike, say, C#, the functions a Lua script can reach are limited to exactly the ones the programmer enables. A Lua script will have a hard time downloading and running an .exe from the internet. And on top of that it doesn’t even weigh 1MB.
Adding mods brings a whole bunch of changes to the systems we already had: the server must not only validate the client’s version, but also that it has the right mods, in the expected version.
The most typical UI components (button, alert, panel…) also have to be created, so Lua can use presets.
And little by little, wire up every system we want them to reach: like reading the blocks at certain coordinates, spawning creatures there, or doing something at a certain time of day.
Although of course, for many of those functions we’d first need NPCs and a day/night cycle.
To add a day cycle you have to think about how much real-life time each in-game day will last, and track it on the server to know which “day number” we’re on in-game.
Then it’s a matter of showing it visually by rotating the light that acts as the Sun at a speed that completes the cycle in that time, and adding the moon.
We’re in a world of blocks, so if you zoom in on the moon you’ll see it’s made of blocks too :p
But of course, not all of us like playing at night. Time has to be skippable.
This is where the system that lets us create new items out of multiple pieces comes into play. Thanks to it we have a bed to script so that clicking it makes the character sleep and the night pass faster.
And of course, commands have been added to switch to whatever time of day you want if you’re an admin.
Beds have also been made the respawn point in case you kick the bucket.
And who could hurt you? The NPCs…
Adding AI to a game is a slog; doing it in multiplayer is twice that.
The first thing to consider is which navigation system they’ll use. Unity has navmesh, but like everything Unity makes, it has its problems.

Imagine you want the user to be attacked by a group of enemies. Unity doesn’t consider that possibility, which means the enemies don’t see each other, so they all pick the same route (the shortest). Forming a queue that makes no sense at all, because normally each one would try to keep line of sight with its target (to be able to shoot it, for example).
The usual hack is adding a component called NavMeshObstacle to each enemy, which, as you can see in one of the previous images, removes the space it takes up from the navigation system (that’s the blue area). That way the space is marked as taken and the next enemy doesn’t even consider walking through it.
But of course, things with a NavMeshObstacle CAN’T move. So what people do is enable the component, recalculate the route and disable it, constantly.
Extraordinarily gross.
Another detail is that Unity’s pathfinding is single-threaded; it has to run on the main thread.
Knowing the official solution is utter crap, I chose to create one that uses the grid generated when building the world out of blocks. After all, in the worst case it’ll be just as bad as the official one.
The next thing needed is a model. This time I went with one made by someone else, which isn’t even made of bricks. It’s one of the things to improve.

The result is on par with an official Unity package: it has bugs and needs improving.
You can see the land NPCs happily walking on the water instead of avoiding it.
The cause of this problem lies in several of the optimizations applied to the terrain.
When you roamed around the world, it rarely went above 30fps. In fact, it often dropped to 10.
The 2×2 brick model I used as the base for building the world had waaaaaaaay too many triangles because of the spherical studs.
Which led to more than 16 million triangles when several chunks were rendered at once.
Once again LDraw comes to the rescue. This library has a lowpoly version of each model that basically skimps on the studs:
Although it looks much worse, the result of using this model is clear:
Now it’s “only” 3 million pixels and we’ve gone up to 140fps.
It wasn’t the only change made to reach those frames. Every chunk generated its collider even when far from the player. Not giving every chunk a collider is what let the NPCs walk on water.
Right, we have a game you can get absorbed building in for a while. The problem is it’s still missing something. It’s all very quiet.
To create some atmosphere, it needed some background music. The most fitting style for this seemed to be 8-bit. So I loaded the game with several songs that have a commercial license.
Not everyone will like it, so a settings section was needed where, among other things, the music volume can be changed.
The settings panel is what I’m least passionate about when making games, so being able to feed it to the AI so it’s its problem has been a real treat.
Doing it also forced me to take another big step: migrating to Unity’s new input system.
In Unity, if you want to know whether the player is pressing a certain key, you just have to do:
if (Input.GetKeyDown(KeyCode.Space)) { // pressing the Space bar
}
Simple and convenient, but with one problem. The key is hardcoded. The player can’t change it to another one.
The hack used to get around that was putting a class in between that kept the relation between an action and a key, so the code ended up as:
if (Input.GetKeyDown(GameInput.keyFor("Jump"))) { // pressing the Space bar
}
Well, Unity’s InputSystem does exactly that, but officially and with more improvements, including letting you fake the keys being pressed. And why would anyone want to fake key presses? To be able to add tests.
Usually validating a flow in an application is relatively simple.
Want to check that sign-up works automatically? You just have to follow a few steps:

With video games, however, the plot thickens. We’re now in a 3D environment, and if on top of that it’s a sandbox, there are mechanics that can play tricks on you and make a check fail intermittently.
You have to try to make everything as deterministic as possible. Everything random has to be seeded. Every mechanic that could interfere has to be controlled.
Even so, it’s usually the combination of several mechanics that causes a bug.
For example: I made right clicking with nothing in your hand zoom in. Now every time you drank a potion the system zoomed in. Because at first the potion was there, but then it wasn’t.

I don’t know the perfect way to fix this, but I’ve tried to give the game a minimum of checks to avoid messes in the most basic mechanics.
Ideally they’d run on every PR, but I have to check whether that’s doable, because I know Unity likes to complain if its runtime is run the wrong way.
We’ll see; for now we have tests even for fluids.
Back in the day I made blocks able to have different physics, so a water block would have different gravity. But water isn’t just about that; it should also be able to flow.
Just like in Minecraft, grabbing a block of water and dropping it on the ground now makes it spread to the neighbouring blocks.

The first iteration didn’t turn out very well.

The next one improved things a bit by not removing extra polys. The brick model I picked to simulate sloped water probably isn’t the best.
All these tests slowly filled my inventory with junk. It was time to add the option to drop items.
There were 2 ways to fix the problem and I chose to implement both.
On one hand, you can now press Q to drop whatever you’re holding at that moment.
While at it, that feature has been reused so that killing an NPC makes it spit out its loot too.

How pretty, floating there and spinning around.
Getting close to those items lets you pick them up.
The other way to fix the problem was adding a chest system.
Again, the behaviour is what we all expect: click it to open it and you can put things in and take them out. Only 1 player at a time. Breaking the chest makes it spit out everything it had stored.
The only new thing I’ve added is that in Lego, chests are 2 pieces: the lid and the box.
If you don’t put the lid on, any player can get at what’s inside.
And that would be most of the latest update.