Minecraft Fabric:如何每次都获得玩家坐标?

Minecraft Fabric: How to get player coordinates every tick?

我正在尝试使用 Fabric 和 Fabric API 编写 Minecraft mod。我不确定如何每次都获得玩家的坐标。我尝试使用 net.minecraft.entity.player.PlayerEntity.getPos() 但 returns 错误 Cannot make a static reference to the non-static method getPos() from the type Entity。我怎样才能在每个刻度中获取我的玩家坐标作为变量以便我可以使用它?我是 Java 编码语言的新手,因此非常感谢详细的回答。

按F3,看到左边会有一个名为XYZ-的部分。这是您可以看到电线的地方。每刻!

错误:

Cannot make a static reference to the non-static method getPos() from the type Entity

表示您正尝试在静态上下文中使用 getPos()(您在 class 上调用它)

在 java 中,Class 就像一个对象构造函数,或创建对象的“蓝图”。

net.minecraft.entity.player.PlayerEntity

引用 PlayerEntity class

EntityPlayer class 描述了关于玩家实体的一切,并定义了它可以做什么但是是抽象的,这意味着它本身并不存在。

net.minecraft.entity.player.PlayerEntity.getPos()

是(基本上)试图获得玩家定义的位置。

您需要对特定的 PlayerEntity 对象使用 .getPos()。

有关 Classes 和对象的更多信息:https://www.geeksforgeeks.org/classes-objects-java/