loonmc

loonmc logo
Join the server!
Up on "ciomek.pl" and with web view hosted on loonmc web.

loonmc

How does it work?

The logic structure works in 3 components. Babric server - MQTT server - backend bridge. Babric mod logs every action to MQTT server. Backend retrieves all of them and then filters them out to specific users. It also adds some internal logic like Marquee stuff. Even though for now it only uses loon-backend, the MQTT server architecture allows any programmer to create their own apps utilizing it.

Babric server

loonmc mod

logs every action

MQTT server

events + req / resp

backend bridge

loon-backend

local auth

filter per user + marquee

loonmc web

any other integrations you need

Still more work to do

Right now the mod is working as MVP. There are a lot of ideas in my head but the most important ones right now are:
  • Thread safety
  • Integrating other mods (like Quetzal)
  • Admin views
  • Allowing friends to see your stats
  • Android App
  • Code refactoring on some components

Current issues

@Mixin(value = WorldServer.class, remap = false)
public class WorldServerMixin {
	...
	@Inject(method = "tick", at = @At("TAIL"))
	private void onTick(CallbackInfo ci) {
		countTicks();
		positionCountdown();
		handleRequests();
	}
	...
	@Unique private void handleRequests()
	{
		IRequest request;
		while ((request = RequestManager.pollRequest()) != null) {
			IRequest current = request;
			if (current.requireTickThread()) {
				runRequest(current);
			} else {
				EXECUTOR.submit(() -> runRequest(current));
			}
		}
	}
	@Unique
	private void runRequest(IRequest request) {
		try {
			request.handle(mcServer);
		} catch (Exception e) {
			Loon.LOGGER.error("Failed to handle request: {}, {}", request.getClass().getSimpleName(), e);
		}
	}
}
The current biggest one is using the tick thread. Minecraft works through ticks to sync everything. Because of that to be safe you should be doing everything in ticks. It works fine for stuff like reading inventory. It becomes an issue when you want to run some long operation between ticks. If it takes too much time then TPS becomes low and the server lags.
Reading chunks takes a lot of time as there are quite a lot of them. In the prototype it just used a completely different thread to not lag the server. Then I just switched to not reading chunks from Minecraft thread. Right now it reads all chunks from disk which is not only sub-optimal but also doesn't solve the issue 100%. There still can be some issues if the app tried to read chunks the exact time when Minecraft thread tries to write into it.
The structure allows you to set a command off Minecraft thread (at your own risk).

Links

You can check it out here:
Jar: gitea | github
Backend: gitea | github
And fully working deployment on loonmc web.