只有当物体进入范围时才会触发接近探测器,而不是当它在范围内移动

Bra*_*rad 6 java minecraft

我正在为Minecraft制作一个基于文本的雷达.如果玩家距离你不到20个街区,它会在聊天中说出来.截至目前,它正在骚扰聊天.如何才能让它只写入关于该玩家ONCE的聊天?即使你不玩游戏,也应该很容易理解.

if (Camb.radar)
{
  for (Entity e: (List < Entity > ) mc.theWorld.loadedEntityList)
  {
    if (e instanceof EntityPlayer)
    {
      EntityPlayer player = (EntityPlayer) e;
      if (player == mc.thePlayer || mc.thePlayer.getDistanceToEntity(e) > 20.0)
        continue;
      mc.thePlayer.addChatMessage("\2479[CAMB] \247e" + player.getEntityName() + " has entered your 20 block radius!"); //Write to chat, only want this line done once for every player
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Tro*_*roy 15

你需要跟踪玩家何时离开范围并设置一个标志,这样你才能知道他们何时从"超出范围"过渡到"在范围内".可能还想添加一个计时器,这样你每N秒只能提醒一次.