Skip to content

Instantly share code, notes, and snippets.

@Drakekin
Created February 12, 2015 21:54
Show Gist options
  • Select an option

  • Save Drakekin/7e425faebdbd8162d8c9 to your computer and use it in GitHub Desktop.

Select an option

Save Drakekin/7e425faebdbd8162d8c9 to your computer and use it in GitHub Desktop.
from mcpi import minecraft, vec3, block
from collections import defaultdict, Counter
from random import choice
mc = minecraft.Minecraft.create()
INSTRUCTIONS = {}
INVENTORY = defaultdict(int)
def register(command):
def _(f):
INSTRUCTIONS[command] = f
return f
return _
@register("w")
@register("walk")
@register("move")
def walk(direction="north", length=10):
length = int(length)
x, y, z = mc.player.getPos()
if direction == "north":
x += length
elif direction == "south":
x -= length
elif direction == "east":
z += length
elif direction == "west":
z -= length
mc.player.setPos(x, mc.getHeight(x,z), z)
print "You have moved"
@register('look')
def look():
## 3 offset
x, y, z = mc.player.getPos()
for ran in range(3):
print mc.getBlockWithData(x+ran,y,z)
@register("help")
def save_me():
walk(choice(["north", "south", "east", "west"]))
print "You have been saved!"
@register("dig")
def dig_down(height=1):
height = int(height)
x, y, z = mc.player.getPos()
mc.setBlocks(x-1, y-height, z-1, x+1, y, z+1, block.AIR.id)
print "You dig!"
@register("die")
@register("anhero")
@register("go_to_new_zealand")
def kill_self():
x, y, z = mc.player.getPos()
dig_down(10000)
def noop(*args):
print "I don't understand!"
while True:
command = raw_input("> ").lower()
segments = command.split()
instruction = segments[0]
args = segments[1:]
INSTRUCTIONS.get(instruction, noop)(*args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment