post

lua, a tree farm and a create sorter

Needed a break from staring at offsets, so I've been on a modded Minecraft server instead. The thing that keeps me there is ComputerCraft with Advanced Peripherals: it drops real programmable computers and robots into the game, you write Lua on them, and that's it, same loop as everything else I do. Poke a system until it does the boring job for you.

the tree farm

First thing I automated was wood, because I was tired of punching trees. A turtle is a little robot you give a program to. Mine stands in front of a sapling, waits for it to grow, chops the whole trunk going up, comes back down, sucks up the drops and plants a new sapling. Then it refuels off a few of the logs it just cut so it never runs dry.

while true do
  if turtle.detect() then
    while turtle.detectUp() do
      turtle.digUp()
      turtle.up()
    end
    while not turtle.detectDown() do turtle.down() end
    turtle.dig()
  end
  turtle.suck()
  turtle.refuel(4)
  turtle.place()      -- replant the sapling
  sleep(30)
end

It's nothing clever, but watching a block of code quietly fill a chest with logs while I do something else is weirdly satisfying.

sorting a create build

The one I actually use is for Create. You can hand Create a schematic and have a cannon build it for you, but the cannon only fires if the exact blocks are sitting in a chest next to it, and a decent build wants a stupid amount of stuff. Counting that out by hand is miserable.

So there's a computer wired to the input chest and a row of barrels. It reads what the build needs from a list, watches everything I dump in, pushes each block into its own barrel, and keeps a running tally of what's still short. When a stack is full enough it feeds it over to the cannon's chest. Anything the schematic doesn't ask for gets shoved in an overflow barrel so I notice when I've thrown in junk.

local input  = peripheral.wrap("minecraft:chest_0")
local need   = { ["minecraft:andesite"] = 2400,
                 ["create:brass_casing"] = 128 }

for slot, item in pairs(input.list()) do
  local barrel = barrels[item.name]
  if barrel then
    input.pushItems(barrel, slot)
    have[item.name] = (have[item.name] or 0) + item.count
  else
    input.pushItems(overflow, slot)   -- not on the list
  end
end

The real file is longer and uglier than that, with the list loaded from a text file so I don't have to edit code every time I start a new build. But that's the whole idea: it tells me "still need 600 andesite" instead of me squinting at a tooltip.

why bother

None of this is useful off the server, and it's a toy language in a block game. But it's the same thing I like about the reversing work: something is doing the same job over and over, and you can make it stop. If you're on the server and want the sorter script, it's in the Discord.