在 Fabric 中获取玩家的相机

问题描述

抱歉,如果这是一个明显的问题 - 我昨天才开始使用 Fabric,从那时起我自己仍然无法弄清楚。

基本上,我想要做的是编写一个代码,通过按下一个按钮将相机与播放器分离,然后再按下一次将其连接回去。很简单的东西。

所以我最初的想法是拿到玩家的相机,然后像这样拆开它: minecraftClient.getInstance().cameraEntity.detach()。但是,这没有任何作用(可能正如预期的那样)。 然后,我想我可以使用以下代码行将相机传送到每个刻度的起始位置: minecraftClient.getInstance().cameraEntity.updatePosition(<x>,<y>,<z>);。 但是,运行此代码将导致玩家卡在给定位置。 所以我试着打印出“相机实体”的名字,它打印出了玩家的名字,而不是相机的名字或类似的东西,这让我觉得我不是获取实际的相机。

我尝试了一大堆我能找到的其他组合,在网上查找 minecraft 方法或在 Wiki 中查找 Fabric 方法都没有弹出任何与我的需求相关的内容

这是我目前使用的代码

public class Main implements ModInitializer {
   private static KeyBinding keyBinding; // The key to press in order to detach or re-attach the camera
   private static boolean teleportCamera; // If this value is true,the camera will teleport constantly to the given X,Y and Z
   private static double x,y,z; // which are these

   @Override
   public void onInitialize() {

        // Setting up the key-binding and that stuff
        [ . . . ]
    
        // Callin' the method below every tick or so
        ClientTickEvents.END_CLIENT_TICK.register(requester -> {

            if (keyBinding.ispressed()) {
                // Key is pressed
                teleportCamera = !teleportCamera; // Reverting the boolean
            
                if (teleportCamera) {
                    final Entity cam = requester.cameraEntity;
                    x = cam.getX();
                    y = cam.getY();
                    z = cam.getZ();
                    requester.player.sendMessage
                        (new LiteralText("The camera will Now constantly teleport to "+cam.getBlockPos()
                        .toShortString()),true);
                } else {
                    requester.player.sendMessage
                        (new LiteralText("The camera is Now attached to you"),true);
                }
            
                keyBinding.setpressed(false); // Reset it
            }
        
            if (teleportCamera) {
                // If the value is true then the camera will constantly teleport to the original position
                requester.cameraEntity.updatePosition(x,z); //FIXME
            }
        });

    }

}

我希望你能得到我想要达到的目标。

为了简化我的问题:在 Fabric 中获取玩家相机实例的正确方法是什么(如果可能)?上面的代码有什么问题? 任何帮助将不胜感激! 先谢谢了!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...