I am trying to code a Minecraft mod using Fabric and the Fabric API. I am unsure of how to get the coordinates of my player every tick. I tried to use net.minecraft.entity.player.PlayerEntity.getPos()
but that returns the error Cannot make a static reference to the non-static method getPos() from the type Entity
. How can I get my player's coordinates every tick as a variable so I can use it? I am new to the Java coding language so a detailed answer would be very appreciated.
Asked
Active
Viewed 2,316 times
-1

Enderbyte09
- 409
- 1
- 5
- 11
2 Answers
1
The error:
Cannot make a static reference to the non-static method getPos() from the type Entity
Means you are trying to use getPos() in a static context (you are calling it on the class)
In java a Class is like an object constructor, or a "blueprint" for creating objects.
net.minecraft.entity.player.PlayerEntity
References the PlayerEntity class
The EntityPlayer class describes everything about the player entity and defines what it can do but is abstract, meaning that by itself it doesn't exist.
net.minecraft.entity.player.PlayerEntity.getPos()
Is (very basically) trying to get the position of the definition of what a player is.
You will need to use .getPos() on a specific PlayerEntity object.
For more about Classes and Objects: https://www.geeksforgeeks.org/classes-objects-java/

Joseph Cato
- 54
- 4
-
1Thank you! It turns out that I failed to get a client instance first. – Enderbyte09 Dec 22 '21 at 02:33
-2
Press F3 and see to the left there will be a part named XYZ -. this is where you can see your cords. every tick!

Human Being
- 1
- 2
-
I am trying to make a mod that uses the coordinates to calculate player speed. I already know how to get them through f3. Is there a way to extract data from the f3 screen so it can be used in the program? – Enderbyte09 Dec 20 '21 at 17:37
-
-
https://forums.minecraftforge.net/topic/87835-solved-update-block-every-tick-for-grass-like-spreading/. this is the answer – Human Being Dec 21 '21 at 09:01