Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I would like to get an EntityPlayer instance inside my ServerTickHandler. So far, I've tried to use a static reference from another class, like this:

 

EntityPlayer player = ClimbingGloveEngine.player;

 

But all that does is pull a NullPointerException. I've seen people getting an instance of the player by using the tickData:

 

EntityPlayer player = (EntityPlayer) tickData[1];

 

But that also causes an error: an out of bounds.

 

If someone could please help me get a server instance of the player, that would be fantastic. I really don't want to use packets. Thanks for your help!

How about:

EntityPlayer player = server.getConfigurationManager().getPlayerForUsername("playerName");

where

server = MinecraftServer.getServer();

 

This is assuming you know which player you want to get an instance of. Not exactly sure what you need to do with the instance though.

If I helped you, thank me. If I didn't, let me know.

Have you had a look at the API you get from getConfigurationManager()?

http://jd.minecraftforge.net/net/minecraft/server/management/ServerConfigurationManager.html

 

There are methods like getAllUsernames() and getPlayerList() which return arrays or lists of all the names of players. You can then iterate over that list using getPlayerForUsername() for each player. I suggest you look through the javadoc and relevant API to get a grasp of what is available to you.

If I helped you, thank me. If I didn't, let me know.

I use this, I hope it helps.


@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) 
{
	if (type.equals(EnumSet.of(TickType.PLAYER)))
	{
		onPlayerTick((EntityPlayer)tickData[0]);
	}	
}


        private void onPlayerTick(EntityPlayer player) 
        {
        }

  • Author

I was actually able to solve the problem.  ;) If any of you are interested, here's how I got a server instance of the player and the world:

 

if(type.equals(EnumSet.of(TickType.SERVER)))
	{
		ArrayList list = (ArrayList) MinecraftServer.getServer().getConfigurationManager().playerEntityList;
		Iterator iterator = list.iterator();

		while(iterator.hasNext())
		{
			EntityPlayerMP player = (EntityPlayerMP) iterator.next();
			WorldServer world = MinecraftServer.getServer().worldServerForDimension(player.dimension);
                        }
                }

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.