How To Detect Looking At Sun?

Started by MamaLuigi on

Topic category: Help with modding (Java Edition)

Last seen on 00:56, 6. May 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How To Detect Looking At Sun?

I am making a mod where if you are looking at the sun, and you are holding a specific item, (in my case being a Sun Medallion), then something will happen.

But how would I detect if you are looking at the sun at all?

 

Is this even possible?

If so, how would I do it, and if not, what could I do instead?

 

Any help would be greatly appreciated!

Last seen on 00:56, 6. May 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What i mean is, how would i…
Fri, 02/09/2024 - 23:40

What i mean is, how would i fix the thing where early or late in the day, you have to look below?

Last seen on 00:56, 6. May 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also, i probably should've…
Fri, 02/09/2024 - 23:45

Also, i probably should've asked this earlier, but how would i check if the player is looking at a block or not?

Last seen on 00:25, 9. May 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can just use the look x…
Sat, 02/10/2024 - 00:06

You can just use the look x/y/z position to get the position of the block the entity is looking at. It returns 0/0/0 if the entity is looking into empty space. 

As for fixing the offset, I'm not totally sure. The issue is that it's not a perfect sync- the sun rises a little before time 0, and sets a little after time 12000, so it doesn't match up perfectly. (According to the wiki, true sunrise is at 23000, and true sunset is closer to 13000.) The idea is still the same, but it totally messes with the math- you would need to do a separate conversion in which 23000 is the new 0, and 13000 becomes 12000, and I'm not 100% sure what the exact numbers would be.

Last seen on 00:56, 6. May 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Could you show me the…
Sat, 02/10/2024 - 00:58

Could you show me the procedure i could use to detect if the player can see the sun and the new math procedure? 

Last seen on 00:25, 9. May 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
...I'll, uh, give it a try I…
Sat, 02/10/2024 - 15:06

...I'll, uh, give it a try I guess. Like I said, I'm not 100% sure how this would work, but it's likely going to be complicated.

Last seen on 00:56, 6. May 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks!
Sat, 02/10/2024 - 16:02

Thanks!

Last seen on 00:25, 9. May 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here's the (mostly) fixed…
Sat, 02/10/2024 - 16:34

Here's the (mostly) fixed version. It's not pretty, basically just has different math for every edge case, but I'm gonna call it good enough.

Last seen on 00:56, 6. May 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks! I'll try it out!
Sun, 02/11/2024 - 00:52

Thanks! I'll try it out!

Last seen on 00:56, 6. May 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I got it to work, but would…
Sun, 02/11/2024 - 02:27

I got it to work, but would you be able to make a procedure that detects if there aren't any solid blocks in front of you?

Last seen on 00:25, 9. May 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You should be able to just…
Sun, 02/11/2024 - 02:30

You should be able to just check if the block at the player's x/y/z look position is non-solid. The only time this won't return a block is when the player is looking at the sky.