Jump to content

[1.7.10][SOLVED]Is it possible to get the player who placed a block?


nosrick

Recommended Posts

For my tamagotchi mod, I need to assign a player as an owner of a 'gotchi. I've got a tile entity representing the egg, which hatches into an entity, at which point it should start following a player around.

 

So, is it possible to get the player who placed the egg down? If not, what might be a good way of assigning an owner to a new 'gotchi?

Link to comment
Share on other sites

Above, and note: you can get player.getUUID() to save player to TileEntity's NBT (one UUID = one player).

To retrieve: MinecraftServer#getEntityFromUuid(UUID uuid) // I think there is player-specific method, yet I don't remember

 

Note: UUIDs are only working on server side.

 

EDIT

Yup, there is: World#getPlayerEntityByUUID(UUID uuid) - but it works per-world.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Note: UUIDs are only working on server side.

 

And only on servers not in offline mode.

(Development dedicated server defaults to offline).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Above, and note: you can get player.getUUID() to save player to TileEntity's NBT (one UUID = one player).

To retrieve: MinecraftServer#getEntityFromUuid(UUID uuid) // I think there is player-specific method, yet I don't remember

 

Note: UUIDs are only working on server side.

 

EDIT

Yup, there is: World#getPlayerEntityByUUID(UUID uuid) - but it works per-world.

 

I can only find World#getPlayerEntityByName(). Is it perhaps a 1.8 feature, or am I missing something?

Link to comment
Share on other sites

Might be, you could implement it on your own.

 

public EntityPlayer getPlayerEntityByUUID(UUID uuid)
    {
        for (int i = 0; i < this.playerEntities.size(); ++i)
        {
            EntityPlayer entityplayer = (EntityPlayer)this.playerEntities.get(i);

            if (uuid.equals(entityplayer.getUniqueID()))
            {
                return entityplayer;
            }
        }

        return null;
    }

 

playerEntities is public (in 1.8 ).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.