problem with mc.getPlayerEntityIds()

355 views
Skip to first unread message

Kevin Sherwood

unread,
Nov 20, 2014, 11:20:12 PM11/20/14
to adventures-in-...@googlegroups.com
I'm trying to get the list of players from the server.  The example code from your site follows:

entityIds = mc.getPlayerEntityIds()
for entityId in entityIds
    print entityId

It throws the following error: 
Traceback (most recent call last):
  File "C:/AdventuresInMinecraft/MyAdventures/starting_area.py", line 42, in <module>
    entityIds = mc.getPlayerEntityIds()
  File "C:/AdventuresInMinecraft/MyAdventures\mcpi\minecraft.py", line 151, in getPlayerEntityIds
    return map(int, ids.split("|"))
ValueError: invalid literal for int() with base 10: ''

I did a google search and found this link.


So it appears to be a known bug that has been fixed in 1.4 (whatever that is).  Any ideas on how to fix it on the current release or how to upgrade to 1.4?

Best Wishes,

ks

Martin O'Hanlon

unread,
Nov 21, 2014, 2:09:39 AM11/21/14
to adventures-in-...@googlegroups.com
Yes there is a bug with getPlayerEntityIds in RaspberryJuice 1.3.  RaspberryJuice is the plugin which runs on the Minecraft server and allows your program to interact with the Minecraft world.  

Upgrading is pretty easy: 
  • the raspberryjuice plugin is in the folder AdventuresInMinecraft/Bukkit/plugins, open it
  • delete the file raspberryjuice-1.3.jar
  • download raspberry juice version 1.4 from http://dev.bukkit.org/bukkit-plugins/raspberryjuice/files/
  • copy raspberryjuice-1.4.jar to AdventuresInMinecaft/Bukkit/plugins
I didn't change the starter kits to include this new version of raspberryjuice as none of the projects in the book made use of this function and all of the testing had been done using version 1.3.

Alternatively, I have created new versions of the starter kits, which include the latest versions of the plugins and use Minecraft 1.7.10 http://www.stuffaboutcode.com/p/adventures-in-minecraft-forum.html?place=msg%2Fadventures-in-minecraft-forum%2FG3MuBXDwoqw%2FQQS8oeckJX8J

Kevin Sherwood

unread,
Nov 22, 2014, 5:40:44 PM11/22/14
to adventures-in-...@googlegroups.com
Thanks for the help!  I've got the canary mod installed and can now execute the command and get a list of entity id's.  This appears to be a list of integers.  

A quick overview.  The functionality I am trying to create is a multi-player game where every time a block is hit something happens to a random player that is still on the field.  This could be anything from dropping a dynamite block next to the player to teleporting the player up 100 spaces to fall to their death.

The mc.player.getPos() and mc.player.setPos() refer to only one player.  Are there commands for other players?

I feel like there is an API that I am missing!

Thanks again,

Kevin

Martin O'Hanlon

unread,
Nov 23, 2014, 12:24:06 PM11/23/14
to adventures-in-...@googlegroups.com
The standard API (on the Pi edition) doesnt support multi-player but RaspberryJuice on the PC and Mac does.  

You need a modded python library (the files in MyAdventures/mcpi to make it work, which I didnt include in the standard starter kits for obvious reasons, but I have just included them in the latest canarymod starter kit (0.5).

To use the multiplayer functions you need to pass the players name when you create a connection to minecraft.

Syntax is:

mc = minecraft.Minecraft.create(ipaddress, port, name)

The ip address is defaulted to the local host, the port is defaulted to 4711, and the player is defaulted to the 'host player'.

To create a connection to a specific player you can use:

mc = minecraft.Minecraft.create(name = "martinohanlon")

Its brilliant you are pushing the boundaries way outside the adventures in the book.


Martin O'Hanlon

unread,
Nov 24, 2014, 1:27:17 AM11/24/14
to adventures-in-...@googlegroups.com
Reply from Kevin Sherwood (moved):

Version 0.5 downloaded and I can access players by name!  There is a gap here that I do not understand.  I have a getPlayerEntityIds which gives me a list of integers that correspond to the id's of individual players on the servers.  I can connect to a specific player with minecraft.Minecraft.create(name="abc").  

How do I get the player's name from the entityId?  I would like to write a game that is player agnostic (ie the player names are not embedded in my code, instead generated at run time).

So far I have code to generate a staging area for each player.  Now I want to be able to create a connection for each player so I can teleport them to individual staging areas, set a timer so they can grab their stuff, and then teleport them to the battleground where they hit blocks to mess with each other.

Best Wishes,

ks

Martin O'Hanlon

unread,
Nov 24, 2014, 1:44:34 AM11/24/14
to adventures-in-...@googlegroups.com
At the moment, I dont think there is a way of getting player names from entity ids.  
I think the getPlayerEntityIds method is part of an (as yet) unfinished group of api calls which hopefully Mojang will extend in the future.  I think it is meant to tie into the events api's as they also report the entity ids.

It is however a good idea to be able to pull back a list of players to support the multiplayer functions, so i have added an enhancement request to the raspberry juice github. https://github.com/martinohanlon/CanaryRaspberryJuice/issues/7

Martin O'Hanlon

unread,
Nov 25, 2014, 6:09:09 AM11/25/14
to adventures-in-...@googlegroups.com
Hi Kevin,

Your comments started me thinking... It did feel like there was something missing and I started digging into the python api code which mojang supplied (fyi - documentation is EXTREMELY limited) and I found something which isn't documented anywhere..

The api supports the same functions as player supports but against entities, e.g. mc.entity.getPos but you can pass entityId e.g. mc.entity.getPos(entityId).

UNFORTUNATELY...  The raspberryjuice plugin doesn't support the 'entity' functions, I suspect the developers (me included) didnt know of its existance.  I've created an issue for it and will get on it asap.


Mart

Martin O'Hanlon

unread,
Nov 25, 2014, 4:23:38 PM11/25/14
to adventures-in-...@googlegroups.com
I have updated RaspberryJuice (v1.1) to support entity functions and built a new canarymod starter kit (v0.6).  You can download them it from here.

You use the entity functions just like player functions put pass the entity id as the first parameter so:

mc.entity.setPos(entityId, x, y, z)
mc.entity.getPos(entityId)
mc.entity.setTilePos(entityId, x, y, z)
mc.entity.getTilePos(entityId)

Kevin Sherwood

unread,
Nov 26, 2014, 11:08:36 PM11/26/14
to adventures-in-...@googlegroups.com
Just downloaded 0.6 and it is working great for a single player.  I will test multi-player when my son is with me next.  Is there any way to get an entity's player name?  What I want to do is add flavor text to the game like:
    hits = mc.events.pollBlockHits()
    for hit in hits:
        player = hit.entityId
        playerName = mc.entity.getName(player)

        target = entityIds(random.randint(0,NUMPLAYERS)
        targetName = mc.entity.getName(target)

        mc.postToChat(playerName + " strikes " + targetName)

Sooooo close!!!!

Best Wishes,

ks

Martin O'Hanlon

unread,
Nov 27, 2014, 2:00:14 AM11/27/14
to adventures-in-...@googlegroups.com
Again, sorry there isnt a method to get a players name. We are back to waiting for Mojang to lead the way on that one. Does pollBlockHits return hits on other players? I have never used it like that.
Reply all
Reply to author
Forward
0 new messages