Jump to content

[1.7.10] Detecting the player that loaded a chunk


sickmate

Recommended Posts

Is it possible to find out the player that caused a ChunkEvent.Load event? The only solution I've thought of so far is to register a tick handler or scheduled handler that gets the closest player for each recently loaded chunk. I'm curious if there's a better way to do it.

Link to comment
Share on other sites

On chunk load:

read from chunk NBT

if the chunk has never been loaded:

find nearest player within (16 * chunkload radius)

save this to the chunk NBT

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

Thanks. So I can get the chunk NBT by subscribing to ChunkDataEvent.Load, however this seems to be triggered all the time, even if a player isn't moving. And I can't see a way to get the NBT directly from a Chunk object.

 

So my thinking is this:

- Store the chunk load player info separately (in WorldSavedData or something else)

- On ChunkEvent.Load, check to see whether it's been loaded before

- If not, find nearest player to the chunk with and save them.

 

Thanks for the help.

Link to comment
Share on other sites

	@SubscribeEvent
public void chunkLoad(ChunkDataEvent.Load event) {
	NBTTagCompound nbt = event.getData();
}

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

I know, I've already tested that. As I mentioned above it gets triggered way too often, not just on a chunk load and even periodically when the player is doing absolutely nothing. So making use of ChunkEvent.Load and storing the data myself should be more efficient.

Link to comment
Share on other sites

That's because "save" and "load" events have nothing to do with where the player is or what they're doing.  That's

ChunkEvent.Load

and

ChunkEvent.Unload

, but those events don't give you access to the chunk NBT data.

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

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.