Esempio n. 1
0
  @Override
  public void onTick(float dt) {
    Controller cont = controllerLive.get();
    // Pulse all player messages here, so they can interact with the entities position safely
    if (cont instanceof PlayerController) {
      Player player = ((PlayerController) cont).getPlayer();
      if (player != null && player.getSession() != null) {
        ((SpoutSession) player.getSession()).pulse();
      }
    }

    // Tick the controller
    if (cont != null) {
      // Sanity check
      if (cont.getParent() != this) {
        if (Spout.debugMode()) {
          throw new IllegalStateException("Controller parent does not match entity");
        } else {
          cont.attachToEntity(this);
        }
      }
      // If this is the first tick, we need to attach the controller
      // Controller is attached here instead of inside of the constructor
      // because the constructor can not access getChunk if the entity is being deserialized
      if (!attached) {
        cont.onAttached();
        attached = true;
      }
      cont.onTick(dt);
    }

    // Copy values last (position may change during controller or session pulses)
    if (!isDead()
        && this.transform.getPosition() != null
        && this.transform.getPosition().getWorld() != null) {
      // Note: if the chunk is null, this effectively kills the entity (since dead: {chunkLive.get()
      // == null})
      chunkLive.set(
          transform.getPosition().getWorld().getChunkFromBlock(transform.getPosition(), false));

      entityManagerLive.set(((SpoutRegion) getRegion()).getEntityManager());
      lastTransform = transform.copy();
    }
  }
Esempio n. 2
0
 public void broadcastMessage(Message message) {
   for (Player player : world.getPlayers()) {
     if (!player.isOnline()) {
       continue;
     }
     if (!player.getEntity().getWorld().getName().equals(world.getName())) {
       continue;
     }
     player.getSession().send(message);
   }
 }
 public VanillaNetworkSynchronizer(Player player, Entity entity) {
   super(player, player.getSession(), entity, 3);
   registerProtocolEvents(this);
 }