Open Python 2 IDLE (not Python 3) by clicking Menu > Programming > Python 2. Use File > New Window to create a new program and save it as myprogram.py. You are going to need 3 modules, the minecraft.py and block.py modules from the api library and the standard time module so you can introduce delays into your program. Type the following code into your program to import the modules.
import mcpi.minecraft as minecraft
import mcpi.block as block
Use the Minecraft python library to create a connection to the game, your program will use this to talk to Minecraft and make things happen. mc = minecraft.Minecraft.create() Using the minecraft connection, mc, you can interact with the game and send the player a message. Then use time.sleep() put in a 5 seconds delay into your program.
mc.postToChat("Hello Minecraft World")
Make sure Minecraft is still running and that you are ‘in a world’, press ESC to return to the main menu so you can run your program. Run the program by clicking 'Run, Run Module' in IDLE. Switch back to Minecraft to see the results of your hard work - be quick though as its only on the screen for a few seconds, if you miss it, re-run the program and try again. Any errors will be shown in red text in the Python Shell, take care to make sure you have typed the code in correctly, be careful of upper and lower case letters as Python is case sensitive.
Last edited by metalj
on Sat Aug 01, 2015 3:54 am, edited 3 times in total.
Backspace 28 times