Jump to content

[1.12] Is there anyway to get EntityPlayer from UUID on client side?


Samaritans

Recommended Posts

Hey all,


First time posting. I have a GUI with a container so when i call player.openGui, it tries to go to my GuiHandler and call getClientGuiElement. However, part of my container requires me to get an EntityPlayer with a UUID, and display some specific info about the player. When my findPlayer function ran on the client side while on a dedicated server, the player just returns null and my gui just displays empty. Is there any way to fix that?

 

Here's how I am finding player right now:

public static EntityPlayer findPlayer(UUID uuid) {
   for (WorldServer ws : DimensionManager.getWorlds()) {
      EntityPlayer player = ws.getPlayerEntityByUUID(uuid);
      if (player != null) return player;
   }
   return null;
}
Link to comment
Share on other sites

8 minutes ago, Samaritans said:

and display some specific info about the player.

What specific info?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Mainly I need to get the player.getRNG to display a random number of info. The info are specific stuff in my mod that checks for stuff like if the player is a witch, if the player has pets, etc. 

 

Here's the container:

public ContainerTarotTable(UUID id) {
   player = Util.findPlayer(id);
   if (player != null) {
      List<Tarot> valid = GameRegistry.findRegistry(Tarot.class).getValuesCollection().stream().filter(f -> f.isCounted(player)).collect(Collectors.toList());
      if (!valid.isEmpty()) {
         while (!valid.isEmpty() && toRead.size() < 4) {
            int i = player.getRNG().nextInt(valid.size());
            toRead.add(valid.get(i));
            valid.remove(i);
         }
      }
   }
}
Edited by Samaritans
Link to comment
Share on other sites

5 minutes ago, Samaritans said:

The info are specific stuff in my mod that checks for stuff like if the player is a witch, if the player has pets, etc.

You need to sync the information from the server to the client through the container. Cause the Client won't always know about the player.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

5 minutes ago, Samaritans said:

Yeah that's what I am asking about, I have no idea how to do that. 

Look at the Furnace's container.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Im pretty new to modding and I'm still so confused. I guess i need to addListener and detectAndSendChanges? But the container doesnt have an inventory, so there's no changes? I just need a way to have a player opengui on client side while on a dedicated server so that these info are depicted.

 

The player would be holding an item with NBTTag that has a UUID on it. I read that NBT and get the UUID out and find an EntityPlayer with that UUID. 

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.