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 want to get an entity with a custom name, I manage to get a list of the entity on world but when i try to single out the entity i want i cant do it.

I try setting .contain to get the entity displayname but it always go to the else statement

 

screenshot of entity on the world: http://prntscr.com/7ppth1

 

System.out.println(world.loadedEntityList) outputs: [EntitySlime['Slime'/0, l='New World', x=405.27, y=1.00, z=-433.02], EntityOfflinePlayer['Player109'/1, l='New World', x=420.62, y=1.00, z=-436.08], EntityPlayerMP['Player13'/2, l='New World', x=423.97, y=1.00, z=-432.51]]

 

result: Sysout shows "Not Detected" as stated in the else statement

 

EntityPlayer player = e.player;
	World world = player.getEntityWorld();
	EntityOfflinePlayer offline = new EntityOfflinePlayer(player.getEntityWorld(), player.posX, player.posY, player.posZ);
	PlayerData data = new PlayerData();
	System.out.println(world.loadedEntityList);
	if(world.loadedEntityList.contains("Player109")) {
		System.out.println("Have character");
	} else {
		System.out.println("Not Detected");
	}

 

 

Ignoring other things in your code for now, your problem is that the loaded entity List is a List of Entity objects, not Strings, so calling contains("someString") on it cannot possibly return true.

 

You have to iterate through each entry and compare the entity's custom name tag (or command sender name, since you're dealing with players) to the name you expect.

 

Also, if you are only interested in players, you should use the List referenced by worldObj.playerEntities, and if the player is in game already, you can use the World#getPlayerEntityByName method directly rather than iterating through a list yourself.

  • Author

Thank you, the entity I'm looking for is actually a custom mob that is spawned into the world every time a player logs off and the Entity is called OfflinePlayerEntity ^^

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.