Minecraft Api python can't get mc.player.getDirection() to work

1,043 views
Skip to first unread message

Carl Noble

unread,
Aug 11, 2016, 5:03:04 PM8/11/16
to Adventures in Minecraft Forum
Tried lots of things.  checked the mcpi folder minecrafy.py and the CmdPositioner, CmdPlayer didn't have it.  .  Python script mc.player.getTilePos() and mc.player.getPos() work fine but I get this:
*****

  direction = mc.player.getDirection()

AttributeError: 'CmdPlayer' object has no attribute 'getDirection'  OK I understand becuz the minecraft.py file does NOT have the code.

********

Found the enhanced mcpi on GitHub.  Now added the enhanced code to minecraft.py and got the following errot

*******

 return CmdPositioner.getDirection(self, self.name)

AttributeError: 'CmdPlayer' object has no attribute 'name'  I do not understand this error

*******

But the code for setTilePos(0 and others work fine.  The only difference is the .getDirection reference in the minecradt.py code.


BTW, I'm on a mac OS X 10.11.6 MCraft vesion 1.9 Bukkit server.  (Tried CanaryMod and raspberry juice but got nowhere.)


Thx for any help.


C






Alexander Pruss

unread,
Aug 12, 2016, 1:14:47 AM8/12/16
to Adventures in Minecraft Forum
1. The PI does not support *.getDirection(). See here: http://www.stuffaboutcode.com/p/minecraft-api-reference.html

2. But that doesn't explain the error message you're having. You might want to just grab all the enhanced files in mcpipy/mcpi from the RaspberryJamMod github.

Carl Noble

unread,
Aug 12, 2016, 11:12:04 AM8/12/16
to Adventures in Minecraft Forum
Thx for your reply.  I'm not on the pi, but a Mac OS X 10.11.6 and I did grab those files.  There was one thing that seemed strange.  Look at he minecraft.py file.  At the top there are imports.  The one downloaded for the Mac all have dots in front of the names, e;g;,  " from .connetion import Connection", but the files from github do not. -- and I get lots of errors if I use them. 

Been through things like this before & I'm betting (maybe up to 25 cents) that I'm missing something very basic.  Maybe ship me some extra IQ's & I'll solve this.

best,

Carl

Alexander Pruss

unread,
Aug 12, 2016, 11:48:42 AM8/12/16
to Adventures in Minecraft Forum
The dots are there for Python 3. So if you're using Python 3, you better have a version with them. If, on the other hand, you're using Python 2.x, then the version with the dots may not work (unless it also starts with from __future__ import absolute_mport).

I suggest you grab the scripts zip from the latest Raspberry Jam Mod release. These are designed for dual Python 2.7/3 compatibility, so they are more likely to work on your system. But make sure you grab *all* the files from the mcpi directory--the changes I made may be interdependent.

If you have a Python prior to 2.7, you may need to update. I've only been testing on 2.7 and 3.5.

Carl Noble

unread,
Aug 12, 2016, 12:15:36 PM8/12/16
to Adventures in Minecraft Forum
That makes sense.  I'm using Python 3.  Too old to juggle 2 versions.   Also, I'm using the "Learn to Program with M-Craft" by Craig Richardson.  I'm developing courses (mainly for my grand kids) & they are all M-Craft fanatic -- so I figured that it would be an ideal way to teach them the fundamentals.  Schools do the cutsy-pi approach but none of the teachers have ever lived in the professional software world.   Also have "Adventures in M-Craft by O'hanlon & Whale.  All very good.

What I want to do is to get them to build a python program that will let the player (heck, it could be a block) to navigate though a series of obstacles to reach a goal -- autonomously.  I've use Bergin's Monty Karel, but it isn't as sexy as M-Craft.  Also, they'd have to learn a complex IDE like eclipse.  

I know that I can do it without knowing the direction of the player, but it makes the "turn Right" a lot easier.

I'll do what you said.  Appreciate the suggestions.

C


Carl Noble

unread,
Aug 12, 2016, 4:13:10 PM8/12/16
to Adventures in Minecraft Forum
Almost there.  I downloaded your file for the "beta".  followed you readme file directions & chose client fo the forge install.  All appears to work & I ran you test.py file & got the following: Ran Single player version 10.2. (should I run multiplayer & set up a server?  That's what the books suggested.

@CarliMac:~$ /var/folders/g3/_y8cy6bs7_d8pf7_xjq4lwlw0000gn/T/geany_run_script_BDJXLY.sh ; exit;

Traceback (most recent call last):

  File "test.py", line 9, in <module>

    mc = minecraft.Minecraft.create(server.address)

  File "/Users/cnoblejr/Desktop/PrussM-Craft/mcpipy/mcpi/minecraft.py", line 376, in create

    return Minecraft(Connection(address, port))

  File "/Users/cnoblejr/Desktop/PrussM-Craft/mcpipy/mcpi/connection.py", line 38, in __init__

    self.socket.connect((address, port))

ConnectionRefusedError: [Errno 61] Connection refused



------------------

(program exited with code: 1)

Press return to continue


M-craft is in /Library/Application Server/  Not sure where Python3 is, but it worked fine.


Thx,


C

Alexander Pruss

unread,
Aug 12, 2016, 6:25:58 PM8/12/16
to Adventures in Minecraft Forum
In your Minecraft main menu, do you see a "Mods" option? If not, you don't have Forge installed properly. 

If yes, click on "Mods", and see if RaspberryJamMod is listed. 

Carl Noble

unread,
Aug 12, 2016, 6:40:33 PM8/12/16
to Adventures in Minecraft Forum
Yes to both.  Mods says:
Minecraft Coder Pack 9.19
0 child mods 

Forge Mod Loader 8.0.99.99
0 child mods 

Minecraft Forge 12.18.1.2011
0 child mods 

Raspberry Jam Mod 0.76
0 child mods 

Alexander Pruss

unread,
Aug 12, 2016, 8:36:46 PM8/12/16
to Adventures in Minecraft Forum
Can you run this test script?

from mc import Minecraft
mc = Minecraft()
mc.postToChat("Hello, world")

Carl Noble

unread,
Aug 12, 2016, 10:22:11 PM8/12/16
to Adventures in Minecraft Forum
It worked perfectly.  I see your mc.py which is
#
# Code by Alexander Pruss and under the MIT license
#

from mcpi.minecraft import *
from mcpi.entity import *
from mcpi.block import *
from mcpi.settings import *
from math import *
I added direction = mc.player.getDirection()
print (direction) and it worked just fine.

Wonderful.  BTW I'm a professional musician (late comer) & will send you two of my latest CD's.  How about an address.  (If you are still at Baylor I can find you there)  Here's a low res mp3 sample.
 

17 What a Wonderful World.mp3

Alexander Pruss

unread,
Aug 13, 2016, 12:07:41 AM8/13/16
to Adventures in Minecraft Forum
Glad it works now. I don't know what went wrong with test.py. Maybe server.py didn't have the right address in it? That's my best bet.

By the way, it's more pleasant to put the scripts in the .minecraft/mcpipy directory and launch them from within Minecraft with /py scriptname if you're using RJM.

I use getDirection() in my grenade.py script which hurls grenades in the direction you're facing.

As for the music sample, that sounds lovely (as per the expert opinion of my daughter, who is an amateur musician). Yes, I'm still at the Baylor Philosophy Department.

Carl Noble

unread,
Aug 13, 2016, 9:54:20 AM8/13/16
to Adventures in Minecraft Forum
Thx again.  I have a folder called PrussM-Craft on my (mac desktop.  I put all of your files there.  The Appropriate (10.2) RJM file is in ~/Library/ Application Support/minecraft/mods/.  My scripts will go into the mcpipy folder inside PrussM-Craft.


Cheers,

C

Alexander Pruss

unread,
Aug 13, 2016, 3:21:15 PM8/13/16
to Adventures in Minecraft Forum
That should work, but if you want to run the scripts via /py, then you may want to put the scripts in ~/Library/Application Support/minecraft/mcpipy

I probably should add an option to set an additional scripts directory.
Reply all
Reply to author
Forward
0 new messages