Example #1
0
  @Override
  public boolean unload(boolean save, boolean safe) {
    LevelProvider level = this.getProvider();
    if (level == null) {
      return true;
    }
    if (save && this.hasChanged) {
      level.saveChunk(this.vector2);
    }
    if (safe) {
      for (Entity entity : this.getEntities().values()) {
        if (entity instanceof Player) {
          return false;
        }
      }
    }
    for (Entity entity : new ArrayList<>(this.getEntities().values())) {
      if (entity instanceof Player) {
        continue;
      }
      entity.close();
    }

    for (BlockEntity blockEntity : new ArrayList<>(this.getBlockEntities().values())) {
      blockEntity.close();
    }
    this.provider = null;
    return true;
  }
Example #2
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;
    }
  }
Example #3
0
 @Override
 public void removeEntity(Entity entity) {
   this.entities.remove(entity.getId());
   if (!(entity instanceof Player) && this.isInit) {
     this.hasChanged = true;
   }
 }
Example #4
0
 @Override
 public void addEntity(Entity entity) {
   this.entities.put(entity.getId(), entity);
   if (!(entity instanceof Player) && this.isInit) {
     this.hasChanged = true;
   }
 }
Example #5
0
 @Override
 public void doPostAttack(Entity attacker, Entity entity) {
   if (attacker instanceof EntityLiving) {
     if (this.damageType == TYPE.ARTHROPODS && entity instanceof EntityArthropod) {
       int duration = 20 + ThreadLocalRandom.current().nextInt(10 * this.level);
       entity.addEffect(Effect.getEffect(Effect.SLOWNESS).setDuration(duration).setAmplifier(3));
     }
   }
 }
Example #6
0
  public void attackEntity(Entity player) {
    if (this.attackDelay > 10 && this.distanceSquared(player) < 1) {
      this.attackDelay = 0;

      EntityDamageEvent ev =
          new EntityDamageByEntityEvent(
              this, player, EntityDamageEvent.CAUSE_ENTITY_ATTACK, (float) this.getDamage());
      player.attack(ev);
    }
  }