Beispiel #1
0
  public void initChunk() {
    if (this.getProvider() != null && !this.isInit) {
      boolean changed = false;
      if (this.NBTentities != null) {
        this.getProvider().getLevel().timings.syncChunkLoadEntitiesTimer.startTiming();
        for (CompoundTag nbt : NBTentities) {
          if (!nbt.contains("id")) {
            this.setChanged();
            continue;
          }
          ListTag pos = nbt.getList("Pos");
          if ((((NumberTag) pos.get(0)).getData().intValue() >> 4) != this.vector2.x
              || ((((NumberTag) pos.get(2)).getData().intValue() >> 4) != this.vector2.z)) {
            changed = true;
            continue;
          }
          Entity entity = Entity.createEntity(nbt.getString("id"), this, nbt);
          if (entity != null) {
            entity.spawnToAll();
          } else {
            changed = true;
            continue;
          }
        }
        this.getProvider().getLevel().timings.syncChunkLoadEntitiesTimer.stopTiming();

        this.getProvider().getLevel().timings.syncChunkLoadBlockEntitiesTimer.startTiming();
        for (CompoundTag nbt : NBTtiles) {
          if (nbt != null) {
            if (!nbt.contains("id")) {
              changed = true;
              continue;
            }
            if ((nbt.getInt("x") >> 4) != this.vector2.x
                || ((nbt.getInt("z") >> 4) != this.vector2.z)) {
              changed = true;
              continue;
            }
            BlockEntity blockEntity = BlockEntity.createBlockEntity(nbt.getString("id"), this, nbt);
            if (blockEntity == null) {
              changed = true;
              continue;
            }
          }
        }

        this.getProvider().getLevel().timings.syncChunkLoadBlockEntitiesTimer.stopTiming();

        this.NBTentities = null;
        this.NBTtiles = null;
      }

      this.setChanged(changed);

      this.isInit = true;
    }
  }
Beispiel #2
0
  protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
      ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
      for (CompoundTag e : effects.getAll()) {
        Effect effect = Effect.getEffect(e.getByte("Id"));
        if (effect == null) {
          continue;
        }

        effect
            .setAmplifier(e.getByte("Amplifier"))
            .setDuration(e.getInt("Duration"))
            .setVisible(e.getBoolean("showParticles"));

        this.addEffect(effect);
      }
    }

    if (this.namedTag.contains("CustomName")) {
      this.setNameTag(this.namedTag.getString("CustomName"));
      if (this.namedTag.contains("CustomNameVisible")) {
        this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
      }
    }

    this.scheduleUpdate();
  }