rockym93 dot net

archive · tags · feed

Crenelations are cool.

17 January 201202:22AMminecraftgamescode

If you play enough Minecraft (or depending on your definition of enough, too much Minecraft) you eventually develop certain architectural quirks. All of your buildings end up being variations on a theme. For example, if you are James, you build a gigantic elaborate palace and maze-like mine at bedrock level and decorate the entrance with giant dwarf statues made of diamond.

And if you're Morgan, you find the nearest mesa and hollow it out, and put a tree farm on top and a massive pit underneath, and then get bored and start building a gimmick like a giant dome or a giant farm or a giant glass-covered- valley.

And if you're me, you build a house which is predominantly above-ground (possibly even to the extent of flying), consistently smaller than any other house on the server (and often not even big enough to be practical), use absurd amounts of glass and put crenelations on top, because crenelations are cool.

And that's what we're going to talk about today, kids. Crenelations.

Crenelations, in case you didn't already know, are the patterns of up-and-down lumps which get built into the side of castles. They're also called by the much less interesting name of battlements. The actual lump is called a merlon, and the gap is called a crenel, and in the middle ages they were exceptionally useful for standing behind while people were shooting arrows at you, while still being able to duck out and take pot-shots of your own. They, along with most of the other features of castles, stopped being useful around the time gunpowder made its way to Europe in the 12th century, since although several inches of stone is great against arrows, it's not so great against cannonballs.

In Minecraft they're not quite so useful, because if other players wanted you dead they'd use dynamite, and skeletons are too useless to warrant a defensive structure purely for their benefit. Plus, if you make them starting at floor level they're too low to be useful, but if you make them starting from one up they're too impractical to shoot over. There are some workarounds using half- blocks, but essentially they're decorative. They make even a messy cobblestone pile look like a badass fortress. Observe:

Hideous pile.

Badass.

But, because of the way Minecraft blocks work, only certain sizes of buildings will crenelate neatly. Specifically, it needs to have an odd number of blocks on both sides, or else you'll have to put two blocks together or leave corners uncrenelated, which looks stupid. Because it's been a boring day and I feel like writing some code, I'm going to express this very simple maths in the form of some Python functions.

First, let's figure out whether your structure will crenelate neatly or not. This function, given two side lengths, will return true or false. Basically, it works by testing if the side length / 2 gives a remainder or not.

def crenelate(sidex, sidey):
       if sidex % 2 == 1 and sidey % 2 == 1:
           return True
       else:
           return False

Cool. Now, in the past I've made the mistake of designing a building based solely on the outside, when really it's the inside that counts. Aww. But seriously, that's why my current tower on the server looks fine on the outside, but is tiny on the inside, like some kind of anti-Tardis. Because a 5x5 building on the exterior is only 3x3 on the interior, which is basically as small as you can get while still being livable. So this function will give you the interior space of the building from the exterior.

def interior(sidex, sidey):
       dimensions = tuple(sidex - 2, sidey - 2)
       return dimensions

That's just stupidly simple, but whatever. Finally, just fo' fun, I'm going to work out how much material you need per level of the building. After an embarrassing amount of experimenting, because of the way sides share corners, each side needs one less block than their length. At least, that's the easiest way to think about it. And since we're talking about a rectangle, that'll be 2x + 2y - 4 every time, but by the time I'd figured that out, I'd already written the code below for 2(x-1) + 2(y-1), which works out to be the same anyway.

def materials(sidex, sidey):
       perlevel = (sidex - 1) * 2 + (sidey -1) * 2
       return perlevel

Then it's a pretty simple task to string it all together to spit out some output. Here's the finished script, you'll need Python installed on your system to use it. Or you could wait until I get bored next, and turn it into a webpage. WHO KNOWS.

And that? That concludes today's rant about crenelations.

< Movies Wot I Have Seen Recently V: HAT TRICK'S REVENGE Some Facts >