跳到正文
烈焰甘蔗Wiki

AlignmentUtility

基本信息

属性 值
类 com.gtnewhorizon.structurelib.alignment.AlignmentUtility
入口方法 AlignmentUtility.handle(player, world, x, y, z)
触发物品 Front Rotation Tool

AlignmentUtility 是一个纯静态工具类,构造函数私有,唯一对外方法是 handle。它是本 mod 中"旋转结构件朝向"这一交互的全部实现。

handle 逻辑

handle(player, world, x, y, z):
    te = world.getTileEntity(x, y, z)

    若 te 为 null 或 player 是 FakePlayer
        → 直接返回 (player instanceof EntityPlayerMP)

    若 player 是 EntityPlayerMP 且 te 实现 IAlignmentProvider
        alignment = ((IAlignmentProvider) te).getAlignment()
        若 alignment 非 null
            若 player.isSneaking() → alignment.toolSetFlip(null)
            否则                      → alignment.toolSetRotation(null)
            → 返回 true

    → 返回 false

要点:

  • 该方法只在服务端生效。客户端玩家会因不满足 instanceof EntityPlayerMP 而走到最后返回 false,朝向改变后由同步机制把结果告知客户端。
  • FakePlayer 被显式排除,用于防止自动化装置(如某些机器的模拟玩家)误触发朝向旋转。
  • 不潜行改旋转,潜行改翻转,二者的循环尝试逻辑见 Extended Facing 对齐系统。
  • 若方块实体实现了 IAlignmentProvider 但 getAlignment() 返回 null,同样返回 false。
  • 该方法不检查客户端权限,任何玩家对着允许旋转的方块实体使用工具都可以成功。

相关条目:Extended Facing 对齐系统、Front Rotation Tool。

浏览全部模组