Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
0
  public static boolean registerEntity(String name, Class<? extends Entity> clazz, boolean force) {
    if (clazz == null) {
      return false;
    }
    try {
      int networkId = clazz.getField("NETWORK_ID").getInt(null);
      knownEntities.put(String.valueOf(networkId), clazz);
    } catch (Exception e) {
      if (!force) {
        return false;
      }
    }

    knownEntities.put(name, clazz);
    shortNames.put(clazz.getSimpleName(), name);
    return true;
  }
Ejemplo n.º 3
0
 public final String getSaveId() {
   return shortNames.getOrDefault(this.getClass().getSimpleName(), "");
 }