Home > Back-end >  Minecraft Fabric: How to get player coordinates every tick?
Minecraft Fabric: How to get player coordinates every tick?

Time:12-21

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.

CodePudding user response:

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/

CodePudding user response:

Press F3 and see to the left there will be a part named XYZ -. this is where you can see your cords. every tick!

  • Related