Hacking Minecraft on the Raspberry Pi using Python

Slides:



Advertisements
Similar presentations
StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures.
Advertisements

HACKING MINECRAFT. LET’S OVERCLOCK sudo raspi-config Change 7: Over clock 900Mhz at max Change 8: Select memory share = 128MB.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x.
Hacking Minecraft on the Raspberry Pi using Python
HACKING MINECRAFT.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Introduction to Minecraft Pi Aims: To know what Minecraft is To learn how to enter code into Minecraft Pi To successfully enter at least 2 Python programs.
If you don’t have Google Earth downloaded already, you can go to to get it.
HACKING MINECRAFT 1. LET’S OVERCLOCK Type sudo raspi-config Change 7: Over clock 900Mhz at max Change 8: Select memory share = 128MB.
Hacking Minecraft on the Raspberry Pi using Python Lesson 2 1.
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Login using your own username and password Go to programming -> geany Enter the following program: Open LX Terminal, enter these 2 commands from mcpi.minecraft.
Introduction to Programming
Create a Halloween Computer Game in Scratch
Co-ordinates And Geometry Module 6: Investigation 2
Lesson 4 - Challenges.
By Sanjay and Arvind Seshan
Eclipse Navigation & Usage.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Programming Scratch to Control a K’NEX Fairground Ride
43 Order of Operations ÷ ( ) + - X Meet Aunt Sally.
43 Order of Operations ÷ ( ) + - X Meet Aunt Sally.
Hacking Minecraft on the Raspberry Pi using Python
Hacking Minecraft on the Raspberry Pi using Python
Hacking Minecraft on the Raspberry Pi using Python
Frozen Graphics Lesson 3.
BBC Microbit.
Lesson 1 Learning Objectives
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Mr Barton’s Maths Notes
You think you can just do your sums in any order you like. THINK AGAIN
BBC Microbit.
BBC Microbit.
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Teaching London Computing
Alice Variables Pepper.
43 Order of Operations  ( ) + - X.
Go to =>
Recap the basics Lesson 1.
Introduction to TouchDevelop
BBC Microbit.
Go to =>
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Python programming exercise
Code Combat.
This represents 1 liter of water.
Mr Barton’s Maths Notes
43 Order of Operations  ( ) + - X.
Programming In Lesson 4.
Beginning Python Programming
Recap the basics Lesson 1.
43 Order of Operations  ( ) + - X.
Creating and Sending Saved Messages
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Creating a Simple Game in Scratch
43 Order of Operations  ( ) + - X.
Order of Operations  + - X.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Presentation transcript:

Hacking Minecraft on the Raspberry Pi using Python Lesson 3

Starter Switch on your Raspberry Pi. Open Minecraft Open Idle (not Idle 3) Click on File>New File This opens up the Idle editor where you can write and edit your Python code Open Minecraft>Create New World (Minecraft must be open for you to hack it)

Objective of the lesson Use Python to control a game called Minecraft All of you will: Use Python to make a large warehouse block Most of you will: Use code to hollow out the warehouse block to make a shell Some of you will: Change the block type being placed and hollowed out Add warehouse when you press a button

import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() Type the following into the editor You always use these lines first in your Minecraft code This connects your code to Minecraft so that you can hack it. Careful, Python code is case sensitive Remember to have Minecraft open) import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create()

import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() You will be using time. You will need to add a line of code import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create()

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time We will use block 4 for the warehouse which is Cobblestone. I want to use the word cobblestone instead of 4. I need to declare this as a variable. Write a line of code to do this

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() cobblestone = 4 We will use block 0 for the inside of the warehouse which is Air. I want to use the word air instead of 0. I need to declare this as a variable. Write a line of code to do this

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() cobblestone = 4 air = 0 I now need to tell Minecraft where I want to place my warehouse. The bottom left corner of the warehouse will be at x = 10 y = 11 z = 12 Code this in

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() cobblestone = 4 air = 0 x = 10 y = 11 z = 12 I now need to tell Minecraft where I want the top right of my warehouse. I will call these coordinates x2, y2, z2.

If the bottom left corner of the warehouse is x = 10 y = 11 z = 12 and the top right coordinate for the warehouse are called x2, y2 and z2 and it is 10 blocks wide, 5 blocks high and 8 blocks deep What is x2, y2 and z2

Did you get it correct? x = 10 y = 11 z = 12 x2 = 20 y = 16 z = 20 Code this in

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() cobblestone = 4 air = 0 x = 10 y = 11 z = 12 x2 = 20 y2= 16 z2 = 20 You now need to add in a line of code to set these blocks down in the correct position mc.setBlocks(x, y, z, x2, y2, z2, cobblestone)

Did you get it correct? Can you explain this line of code? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() cobblestone = 4 air = 0 x = 10 y = 11 z = 12 x2 = 20 y2= 16 z2 = 20 mc.setBlocks(x, y, z, x2, y2, z2, cobblestone) Can you explain this line of code? mc.setBlocks(x, y, z, x2, y2, z2, cobblestone)

You now need to hollow out the warehouse If the bottom left coordinates of the corner of the warehouse are x, y, z What is are coordinates of the corner of air inside it? HINT – all of the coordinates go up by 1 What are these coordinates? x, y, z

Did you get it correct x+1 y+1 z+1 x, y, z

What is are coordinates of the corner of air inside it? Nearly these If the top right coordinates of the corner of the warehouse are x2, y2, z2 What is are coordinates of the corner of air inside it? HINT – all of the coordinates go down by 1 What are these coordinates? x2, y2, z2

Did you get it correct x2, y2, z2 x2-1 y2-1 z2-1

Let us code this in Can you explain this line of code? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() cobblestone = 4 air = 0 x = 10 y = 11 z = 12 x2 = 20 y2= 16 z2 = 20 mc.setBlocks(x, y, z, x2, y2, z2, cobblestone) mc.setBlocks(x+1, y+1, z+1, x2-1, y2-1, z2-1, air) Can you explain this line of code? mc.setBlocks(x+1, y+1, z+1, x2-1, y2-1, z2-1, air)

Press F5 to save and run the program You should make a warehouse of cobblestone. Steve can break through with his sword to see that it just a shell with air inside

What you have learned Maths operators Addition, subtraction, multiplication and division are all possible in Python. Using them in Python allows you to change the values of variables such as the corners of the warehouse setBlocks() The setBlocks() function sets co-ordinates where lots of blocks can all be set down

Click here for a list of Block IDs Challenge 1 Change the block numbers. Try glass instead of cobblestone (Block ID 20) filled with lava (Block ID 11) instead of air Click here for a list of Block IDs

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() glass = 20 lava = 11 x = 10 y = 11 z = 12 x2 = 20 y2= 16 z2 = 20 mc.setBlocks(x, y, z, x2, y2, z2, glass) mc.setBlocks(x+1, y+1, z+1, x2-1, y2-1, z2-1, lava)

Let the program do the size calculations for you Challenge 2 Let the program do the size calculations for you e.g. if you know that the warehouse is 10 wide then x2 = x+10 e.g. if you know that the warehouse is 5 high then y2 = y+5 e.g. if you know that the warehouse is 8 deep then z2 = z+8 Change your code

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() glass = 20 lave = 11 x = 10 y = 11 z = 12 x2 = x+10 y2= y+5 z2 = z+8 mc.setBlocks(x, y, z, x2, y2, z2, glass) mc.setBlocks(x+1, y+1, z+1, x2-1, y2-1, z2-1, lava)

to check keep checking the button Challenge 3 Now get the program to put the blocks down when you press the pibrella button We need to add a while True: to check keep checking the button If pibrella.button.read(): to see if the button is pressed We need indentation after lines of code with :

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() glass = 20 lava = 11 x = 10 y = 11 z = 12 x2 = x+10 y2= y+5 z2 = z+8 while True: if pibrella.button.read() mc.setBlocks(x, y, z, x2, y2, z2, glass) mc.setBlocks(x+1, y+1, z+1, x2-1, y2-1, z2-1, lava)

Challenge 4 Now get the program to put the light the green light when the blocks are put down and then go off 1 seconds later

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time glass = 20 lava = 11 x = 10 y = 11 z = 12 x2 = x+10 y2= y+5 z2 = z+8 while True: if pibrella.button.read() pibrella.light.green.on() mc.setBlocks(x, y, z, x2, y2, z2, glass) mc.setBlocks(x+1, y+1, z+1, x2-1, y2-1, z2-1, lava) time.sleep(1) pibrella.light.green.off()

You now need to get the player’s position by adding the line of code Challenge 5 Get the warehouse to be built wherever you are rather than at a set position You now need to get the player’s position by adding the line of code pos = mc.player.getPos() It saves the player’s position as pos And saves the players coordinates as pos.x pos.y pos.z We could declare these by adding in the lines x = pos.x y = pos.y z = pos.z

Did you get it correct? Why did I move the x,y,z coordinates into the loop? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time glass = 20 lava = 11 while True: if pibrella.button.read() pos = mc.player.getPos() x = pos.x y=pos.y z=pos.z x2 = x+10 y2= y+5 z2 = z+8 pibrella.light.green.on() mc.setBlocks(x, y, z, x2, y2, z2, glass) mc.setBlocks(x+1, y+1, z+1, x2-1, y2-1, z2-1, lava) time.sleep(1) pibrella.light.green.off()

Clear some space before you place your blocks. Challenge 6 Clear some space before you place your blocks. Clear a space 100 blocks wide, 100 high and 100 deep by filling it with air (Block ID 0)

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time glass = 20 lava = 11 air = 0 while True: if pibrella.button.read() pos = mc.player.getPos() x = pos.x y=pos.y z=pos.z mc.setBlocks(x,y,z, x2+100, y2+100, z2+100, air) x2 = x+10 y2= y+5 z2 = z+8 pibrella.light.green.on() mc.setBlocks(x,y,z, x2, y2, z2, glass) mc.setBlocks(x+1, y+1, z+1, x2-1, y2-1, z2-1, lava) time.sleep(1) pibrella.light.green.off()