Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minecraft Pi Projects
# Minecraft Pi Automated Bridge Builder
# Created by Joe Coburn for Make Use Of
# 15/07/2015
# http://www.makeuseof.com/connecting-minecraft-pi-real-world-beginner-electronics
from mcpi.minecraft import Minecraft
mc = Minecraft.create() # create Minecraft Object
while True:
x, y, z = mc.player.getPos() # store player position
# store the surrounding blocks
a = mc.getBlock(x, y - 1, z + 1)
b = mc.getBlock(x, y - 1, z - 1)
c = mc.getBlock(x - 1, y - 1, z)
d = mc.getBlock(x + 1, y - 1, z)
if a == 8 or a == 9 or b == 8 or b == 9 or c == 8 or c == 9 or d == 8 or d == 9:
# 8 or 9 is water. Set surrounding blocks on floor to a solid (stone) if water is found
mc.setBlocks(x, y - 1, z, x + 1, y - 1, z + 1, 1)
mc.setBlocks(x, y - 1, z, x - 1, y - 1, z - 1, 1)
mc.setBlocks(x, y - 1, z, x - 1, y - 1, z + 1, 1)
mc.setBlocks(x, y - 1, z, x + 1, y - 1, z - 1, 1)
# Minecraft Pi Diamond Detector
# Created by Joe Coburn for Make Use Of
# 15/07/2015
# http://www.makeuseof.com/connecting-minecraft-pi-real-world-beginner-electronics
import RPi.GPIO as GPIO
import time
from mcpi.minecraft import Minecraft
mc = Minecraft.create() # create Minecraft Object
led_pin = 14 # store the GPIO pin number
GPIO.setmode(GPIO.BCM) # tell the Pi what headers to use
GPIO.setup(14, GPIO.OUT) # tell the Pi this pin is an output
while True:
# repeat indefinitely
x, y, z = mc.player.getPos()
for i in range(15):
# look at every block until block 15
if mc.getBlock(x, y - i, z) == 56:
GPIO.output(led_pin, True) # turn LED on
time.sleep(0.25) # wait
GPIO.output(led_pin, False) # turn LED off
time.sleep(0.25) # wait
# Minecraft Pi House
# Created by Joe Coburn for Make Use Of
# 15/07/2015
# http://www.makeuseof.com/connecting-minecraft-pi-real-world-beginner-electronics
import RPi.GPIO as GPIO
from mcpi.minecraft import Minecraft
import time
mc = Minecraft.create() # create Minecraft Object
GPIO.setmode(GPIO.BCM) # tell the Pi what headers to use
GPIO.setup(14, GPIO.IN) # tell the Pi this pin is an input
while True:
if GPIO.input(14) == True: # look for button press
mc.player.setPos(0, 0, 0) # teleport player
time.sleep(0.5) # wait 0.5 seconds
from mcpi.minecraft import Minecraft
import RPi.GPIO as GPIO
import time
mc = Minecraft.create() # create Minecraft Object
GPIO.setmode(GPIO.BCM) # tell the Pi what headers to use
GPIO.setup(14, GPIO.IN) # tell the Pi this pin is an input
while True:
if GPIO.input(14) == True:
x, y, z = mc.player.getPos()
mc.setBlocks(x + 2, y - 1, z + 2, x + 7, y + 3, z + 8, 5) # make shell
mc.setBlocks(x + 3, y, z + 3, x + 6, y + 2, z + 7, 0) # remove inside
mc.setBlocks(x + 2, y, z + 5, x + 2, y + 1, z + 5, 0) # make doorway
mc.setBlocks(x + 4, y + 1, z + 8, x + 5, y + 1, z + 8, 102) # make window 1
mc.setBlocks(x + 4, y + 1, z + 2, x + 5, y + 1, z + 2, 102) # make window 2
mc.setBlocks(x + 7, y + 1, z + 4, x + 7, y + 1, z + 6, 102) # make window 3
# Minecraft Pi Mini Game
# Created by Joe Coburn for Make Use Of
# 15/07/2015
# http://www.makeuseof.com/connecting-minecraft-pi-real-world-beginner-electronics
from mcpi.minecraft import Minecraft
import random
import time
mc = Minecraft.create() # create Minecraft Object
while True:
x, y, z = mc.player.getPos()
block_under_player = mc.getBlock(x, y - 1, z)
if block_under_player == 12:
# player standing on sand, start the timer
random_time = random.uniform(0.1, 2.5) # generate random number
time.sleep(random_time); # wait
mc.setBlock(x, y - 1, z, 11) # turn it into lava
# Minecraft Pi Mini Game 2
# Created by Joe Coburn for Make Use Of
# 15/07/2015
# http://www.makeuseof.com/connecting-minecraft-pi-real-world-beginner-electronics
import time
import random
from mcpi.minecraft import Minecraft
mc = Minecraft.create() # create Minecraft Object
# clear area
mc.setBlocks(-10, 1, -10, 25, 5, 25, 0)
# create arena shell
mc.setBlocks(0, 0, 0, 25, 10, 25, 17)
# hollow out arena
mc.setBlocks(1, 1, 1, 24, 10, 24, 0)
# move player to arena
mc.player.setPos(14, 25, 20) # teleport player
# make them stay put
# teleport player to start position every 1/10th second.
# do this for 5 seconds then start the game
time.sleep(2)
total_wait = 0
mc.postToChat("Waiting to Start")
while total_wait < 5:
mc.player.setPos(14, 1, 20) # teleport player
time.sleep(0.1)
total_wait += 0.1
mc.postToChat("BEGIN!")
# 10 levels
for level in range(10):
x, y, z = mc.player.getPos()
level_time = 10 - level # reduce time by 1 second for each level
mc.postToChat("Level - " + str(level + 1) + " start")
# build floor
mc.setBlocks(0, 0, 0, 25, 0, 25, 17)
# make safe area
safe_area_start = random.uniform(0, 22)
safe_area_end = random.uniform(0, 22)
mc.setBlocks(safe_area_start, 0, safe_area_end, safe_area_start + level, 0, safe_area_end + level, 57)
elapsed_time = 0
while elapsed_time < 10:
x, y, z = mc.player.getPos()
time.sleep(0.25)
elapsed_time += 0.25
# check player is still on floor
if y < 0.75:
mc.postToChat("Game Over")
break;
else:
# remove floor
mc.setBlocks(-10, 0, -10, 25, 0, 25, 8)
# put safe area back
mc.setBlocks(safe_area_start, 0, safe_area_end, safe_area_start + level, 0, safe_area_end + level, 57)
time.sleep(2.5)
continue
break
# Minecraft Pi Super Mining Button
# Created by Joe Coburn for Make Use Of
# 15/07/2015
# http://www.makeuseof.com/connecting-minecraft-pi-real-world-beginner-electronics
import RPi.GPIO as GPIO
import time
from mcpi.minecraft import Minecraft
mc = Minecraft.create() # create Minecraft Object
GPIO.setmode(GPIO.BCM) # tell the Pi what headers to use
GPIO.setup(14, GPIO.IN) # tell the Pi this pin is an input
while True:
if GPIO.input(14) == True: # look for button press
x, y, z = mc.player.getPos() # read the player position
mc.setBlocks(x, y, z, x + 10, y + 10, z + 10, 0) # mine 10 blocks
mc.setBlocks(x, y, z, x - 10, y + 10, z - 10, 0) # mine 10 blocks
time.sleep(0.5) # wait 0.5 seconds
# Minecraft Pi Teleporting
# Created by Joe Coburn for Make Use Of
# 15/07/2015
# http://www.makeuseof.com/connecting-minecraft-pi-real-world-beginner-electronics
import RPi.GPIO as GPIO
from mcpi.minecraft import Minecraft
import time
mc = Minecraft.create() # create Minecraft Object
GPIO.setmode(GPIO.BCM) # tell the Pi what headers to use
GPIO.setup(14, GPIO.IN) # tell the Pi this pin is an input
while True:
if GPIO.input(14) == True: # look for button press
mc.player.setPos(0, 0, 0) # teleport player
time.sleep(0.5) # wait 0.5 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.