Solving Coordinates suddenly Changing by an offset of 1

Started by StellaeLux on

Topic category: User side tutorials

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Solving Coordinates suddenly Changing by an offset of 1
Sat, 10/19/2019 - 08:47 (edited)

Are you making a mob and ran into an issue where sometimes you think you spawn something in the right place, test it out and it all works, but when you try it at a later date, perhaps in a new world it is suddenly offset by 1x, 1z or both?

This is an issue related to whether the coordinates you are at in the world are positive or negative. At a positive world coordinate, everything works perfectly, however at a negative coordinate it is offset by 1. You can simply correct this in a procedure through:

https://imgur.com/a/F9Q73ia

if x < 0

set varX to x - 1

else

set varX to x

if z < 0

set varZ to x - 1

else

set varZ to x

Then simply use varX and varZ whenever you spawn something at a specific coordinate and everything will work fine! End of the tutorial.

If you're still not sure what the problem is exactly:

I made a tutorial in which I created an "isUnderwater" check:

https://www.youtube.com/watch?v=nDoclprdfV0&t=77s

At 1:25 you can see that I checked the block at x-1, y, z-1. This is because I tested it previously and whenever I was in the water, it would check the blocks besides it. I hadn't thought much of it and thus checked what the offset was and ended up with x-1, y, z-1. As you can see at 2:54, this yields the correct result. However for those who do understand this issue, you might have guessed my coordinates: yup! It was a negative coordinate for both x and z! The offset I displaced in my tutorial would have malfunctioned in a positive x/z or both!

It is therefore unsurprising to see in the procedure above that if x < 0 and z < 0 both z and z are offset by -1, as that correlates with the offset I showed in my tutorial video, Make sure to always keep this in mind when spawning things into your world! Use varX and varZ not the original ones!

 

Edited by StellaeLux on Sat, 10/19/2019 - 08:47
Joined Oct 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
thank u, i needed this
Sat, 10/19/2019 - 04:20

thank u, i needed this

Joined Jun 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you, it worked :D
Wed, 10/30/2019 - 17:29

Thank you, it worked :D

Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I get those set local…
Tue, 07/07/2020 - 02:33

How do I get those set local x blocks

Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hey how did you get this to…
Tue, 07/07/2020 - 14:37

Hey how did you get this to work. I'm not sure how he got the "local x" and "local z" blocks

Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Does this have to do with…
Tue, 07/07/2020 - 15:35

Does this have to do with custom variables, idk how to get teh local x block

Joined Dec 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how do we do this in 2020.5  
Wed, 12/23/2020 - 02:08

how do we do this in 2020.5