Good Morning from my Robotics Lab! This is Shadow_8472 and today, I am taking a field trip. My sister set up a modded MineCraft World, and I am into the ComputerCraft mod. Let’s get started.
ComputerCraft is a MineCraft mod that adds computers that run actual code using Lua, a scripting language. While a lot of programs are written, compiled (turned into something the target machine can run), and executed; scripting languages are more often just run off the text file as written. They will be slower, but easier to write.
ComputerCraft itself adds basic and advanced versions of both regular computers and their robot counterparts or “turtles” as well as a few other peripherals. All computers come with a Command Line Interface. Advanced computers will even let you use your mouse and show you colors while editing a program. Nevertheless, it’s the perfect mod for dealing with computers from a programmer’s point of view. In a multi-player environment, one might even get into hacking other’s networks while defending one’s own with encryption.
One mechanic within MineCraft proper I will be relying on is redstone. Think of it as a simple wire. Signal in one end,
I have dealt with ComputerCraft before. It was a few years ago, but it’s not totally new to me. Back then, I was a complete stranger to Lua and was only interested in the early game mining abilities. Other stuff was a little low level for my patience. I eventually set to modify the code for a mining turtle’s default pit digging program. In my research before reprogramming the turtle, I did not find the copy command, so I retyped the whole thing in myself before attempting the modification. Not a smart move without a second screen. But I did get the gist of the syntax of Lua and an insight into how the program was structured. It was a good way to learn the language.
In the present, I am looking to use in-game computers to manipulate the world in more ways than just mining it. I have already used a script to automate a tedious task from another mod, in this case Tinkers’ Construct, where I would otherwise have my time taken up by micromanaging the pouring of blocks and ingot casts. It provided a refresher course on programming and in Lua in particular.
I started with a description of the problem: Automatically pour from the smeltery. I formed a mental picture of how I wanted the program to do it: Send redstone pulses to the appropriate spouts. At this point, I start mapping out the logic of the system. Normally, such a stage would be done on a whiteboard or a piece of paper, but this was a small enough job, I broke good programming practice and skipped this step.
Coding the smeltry program was fairly easy. I pulled up the source code for the default mining program on my second screen and referenced it for syntax. I usually find examples a lot easier to follow than a paragraph explanation in some documentation.
What I do find helpful is bringing up the API’s (Application Programming Interface) for ComputerCraft elements I’m working with, so I can see what variables of what types the lower level functions want and in what order they want them. Think about it as tying an extra fancy knot and someone gives you a box of strings so you don’t have to make your own rope.
Debugging for the smeltery program wasn’t the smoothest. A programming practice I failed to follow was postponing the debugging until the program was fully written. I don’t like syntax errors. I don’t remember all the errors I had, but one of them stuck out as being stubborn. I eventually got it figured out and I could start debugging the logic.
The completed program has two inputs, both integers. The first is how many pulses to send, and the second is how long to wait between each pulse, as the a premature pulse can stop the flow. The final smeltery has two copies of this program, each a slightly modified to send the pulse to the correct place. Now that I think about it, I could have combined them with an in-program menu. Of course, I could always make it fancier and fancier, but it works for now, and I want to work on other things.
***
What? I underestimated the basic computer’s abilities. It CAN use analogue redstone signals. I will have to take advantage of that later on…
Final Question: Have you ever overestimated something and later took advantage of the previously overlooked abilities?