Jump to content

Player position in RenderGameOverlayEvent? [SOLVED]


Targren
 Share

Recommended Posts

My latest mini-mod practice project is to duplicate an old mod I saw in a let's play once, which would simply tell you on the Debug (F3) screen if you're standing in a slime chunk (I'll find this useful for my future slime-spawning mod since Rei's detection is wonky). I've sussed out how to add the text to the Debug screen, no problem. 

 

Where I'm getting caught up is getting my current position in order to do the calculations. Unlike the other events I've dealt with to date, world, position, and player don't seem to show up in the inheritance chain for RenderGameOverlayEvent. Please forgive me if I'm missing something obvious -- I've been working with a certain other language for several years that has sabotaged my brain's ability to properly map out scoping.

 

I figure that, if the answer to my question is "no", then I can "scrape" the X and Z coords out of the debug text lines and use them, but if there's a way to get posX and posZ straight, it'll be that much cleaner.

 

 

Link to comment
Share on other sites

Most of those things (world, player...) are not needed to be sent in the event, as there exist only a single one for each client.  E.G each client only has a single world object, and is responsible for the position of a single player.  As such, these fields are accessible directly from the Minecraft class, in the form of  Minecraft.getMinecraft().thePlayer  and Minecraft.getMinecraft().theWorld  ..  These are a global reference can be accessed from anywhere (as long as it is client side, trying to use either on server side will crash with a ClassNotFound exception for Minecraft.class)

 

That gets you the 'controlling' client player, and the world he/she is currently residing in.  From there you can easily poll the player.posX/etc to get your positioning to calculate your chunks :)

Link to comment
Share on other sites

One of another problem you could encounter is that I don't think the data which says which chunks are slime chunks is available client sided...

 

Yeah, I was just coming back to post something to that effect. Using Minecraft.getMinecraft().theWorld will return a "Multiplayer" world, even if loaded single player. I'm pretty sure it's the same case for loading .thePlayer.

 

What I've ended up doing was trapping WorldEvent.Load and saving the world and the seed into static values for the mod, and that worked nicely. I've now got my "Slime Chunk: Yes/No" line on the debug screen.

 

Of course, I can't stop there. Now the wild hair has expanded so that I want a line of all spawnable monsters for the given location (I saw a let's play on YT with such a mod once, but it doesn't seem to exist for 1.5.2).

 

Bouncing around the code suggests I'm looking for IChunkProvider.getPossibleCreatures() but I'm still having some trouble sussing that one out. I'm not sure if I'm using the wrong positioning or the wrong provider, but it just keeps returning EntityEnderman and that's it. It's closer than I was yesterday, though.

 

Update: Or possibly I should take a look in WorldEvent.java which seems to obligingly provide a static PotentialSpawns class... Nerp... that seems to be for adding potential spawns...

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

 Share



×
×
  • Create New...

Important Information

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