Пример #1
0
  protected void checkChunks() {
    if (this.chunk == null
        || (this.chunk.getX() != ((int) this.x >> 4))
        || this.chunk.getZ() != ((int) this.z >> 4)) {
      if (this.chunk != null) {
        this.chunk.removeEntity(this);
      }
      this.chunk = this.level.getChunk((int) this.x >> 4, (int) this.z >> 4, true);

      if (!this.justCreated) {
        Map<Integer, Player> newChunk =
            this.level.getChunkPlayers((int) this.x >> 4, (int) this.z >> 4);
        for (Player player : new ArrayList<>(this.hasSpawned.values())) {
          if (!newChunk.containsKey(player.getLoaderId())) {
            this.despawnFrom(player);
          } else {
            newChunk.remove(player.getLoaderId());
          }
        }

        for (Player player : newChunk.values()) {
          this.spawnTo(player);
        }
      }

      if (this.chunk == null) {
        return;
      }

      this.chunk.addEntity(this);
    }
  }
Пример #2
0
 public void despawnFrom(Player player) {
   if (this.hasSpawned.containsKey(player.getLoaderId())) {
     RemoveEntityPacket pk = new RemoveEntityPacket();
     pk.eid = this.getId();
     player.dataPacket(pk);
     this.hasSpawned.remove(player.getLoaderId());
   }
 }
Пример #3
0
 public void spawnTo(Player player) {
   if (!this.hasSpawned.containsKey(player.getLoaderId())
       && player.usedChunks.containsKey(Level.chunkHash(this.chunk.getX(), this.chunk.getZ()))) {
     this.hasSpawned.put(player.getLoaderId(), player);
   }
 }