Counting blocks: How to get statistics from your Minecraft quarry.

ConstellationsDB Feb 01, 2022

Data is awesome. Why not see how many blocks your quarry, tunnel bore, or even you yourself produce each minute, hour or day? With a simple LUA script, ComputerCraft, and ConstellationsDB you can do just that! No need to setup databases, servers, or even host anything. Just follow this guide and you too can make awesome looking dashboards!

A bit of context

ConstellationsDB is an all-in-one platform for data observability. What this means is that it collects all types of data, stores it for you, and creates graphs when you need them. This data can be anything from website visits to, in this example, a Minecraft quarries output. This post is only going to be touching on the basics of ConstellationsDB to get you up and running asap but the platform has so much to offer.

ComputerCraft is an amazing mod that lets you run scripts that interact with your Minecraft world, all using a programming language called Lua. For this tutorial, we'll be using a forked version of ComputerCraft called "CC: Tweaked". This "fork" adds a bunch of inventory addons into the mod, allowing us to see into chests, and move items. The same is possible in older editions of the game if you use OpenPeripherals but you will need to modifiy the code to make it work.

Heres the links to the resources you'll need. If your modpack already has ComputerCraft Tweaked, then dont worry about the top link.

CC: Tweaked
Documentation index for CC: Tweaked
ConstellationsDB

Step 1: 🧰 Setup your chests and computer

First things first, you need to setup the chests and computer in a position you can manage easily. See the screenshot below for how we'll be doing it in the tutorial. You can change the direction to whatever you want, but you must make sure to change the code to match your input and output.

In this tutorial, we'll be putting the input on the left, and the output on the right.

When setting up your chests, make sure you put a pipe or other transport method on the output that is as fast or faster than the input. This is because if the output chest is full, it will stop working until theres space.

Step 2: ✨ Setup Constellations

Once you have an account, you need to create whats known as a "namespace". This is basically a bucket of your data. Once you have a namespace, click on its name in the dashboard and copy the write key. You will need this to authenticate with the API and send data.

The blue line represents where you can find the write key.

Constellations has tons of awesome features that you can try out for free. Free accounts can do almost anything however there are limitations on the amount a user can use. Constellations has a cap of 100,000 "events" (every stack thats moved from left to right chest counts as an event) per namespace so after a while your data will start overwriting the oldest data to stay within that 100,000 limit. However, even at a very high rate, you wouldnt need to worry about this cap unless you are constantly running the quarry for more than 7 days at max speed.

Step 3: 🍕 Code!

Dont worry, I wont make you type the script in line by line. You can run this one-liner that will download the LUA script required for this to work. Just copy and paste the following code block into your ComputerCraft computer's terminal to download the script:

pastebin get TDprQbeq count.lua
ConstellationsDB count quarry output - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
If you are interested in the source code for the script, you can find it via this link

Step 3.5: ⚡ Fill in the missing details

Now you need to put in the details you got from Constellations into the script you just downloaded. This is super easy, all you need to do is type `edit count.lua` into the computer and you will be taken to an editor. Now you just need to copy paste the relevent details from Constellations into the top of the script. Once you are done, press shift and then enter to save, and then exit by doing the same but hitting exit.

namespace = "your-namespace"
write_key = "the-write-key-for-that-namespace"
input_direction = "left"
output_direction = "right"
Edit the count.lua file to change the values at the top to be what you made

Now you can run the script and it should start outputing what it's sending to the API when it shows up in the input chest.

count
In your computer's termina, just type "count" to start the script

Step 4: 💰 Profit / Visualise your statistics

Constellations is a super powerful tool that allows you collect data as well as visualise without needing to setup databases or APIs. While this step is not needed as data is now being stored with Constellations, this is a good idea as it will let you generate graphs and bar charts based on the blocks you've mined.

In your dashboard, you should go to "Dashboards" and click "New dashboard". Then fill in the details and click the newly created dashboard in the list. Your new dashboard is empty, but it will be full of wonderful graphs soon.

Click the blue edit button to add new graphs to your dashboard

There are a few settings you need to do here but dont worry they are pretty simple. All you need to do is put in the namespace you created in step 2, then set the graph operation to "Sum". This will add all the blocks together instead of showing you the average stack size (this is most likely 64 and not very useful).

You can also configure the color of the graph, and various other settings here too! Just hit "Save" and your new graph will show up. You can drag the bottom-right corner to resize and move it around. Just remember to click the X in the top bar of the dashboard to quit edit mode. This will show you what it will look like normally.

Now what if you wanted to see the percentages of each block mined? Easy! All you need to do is create a "Tag Compare" graph. This will get the top few unique blocks mined and show you how many were mined in a time period.

"Tag comparison" bar graph showing the different blocks mined

Here's my personal dashboard that I built using all of the tools Constellations currently provides. Theres tons more cool features in the works so i'll be updating that as they release.

Constellations provides a super easy way to monitor anything. With the power of GET requests, you can build awesome dashboards without needing to run your own infrastructure.

Tags

Cerulean

CEO & Full-stack engineer @ Sponsus. 4 years industry experience with a speciality in realtime and data analytics.