Ejemplo n.º 1
0
  @Override
  public Entity spawnEntityIntoClientWorld(EntityRegistration er, EntitySpawnPacket packet) {
    WorldClient wc = client.field_71441_e;

    Class<? extends Entity> cls = er.getEntityClass();

    try {
      Entity entity;
      if (er.hasCustomSpawning()) {
        entity = er.doCustomSpawning(packet);
      } else {
        entity = (Entity) (cls.getConstructor(World.class).newInstance(wc));
        int offset = packet.entityId - entity.field_70157_k;
        entity.field_70157_k = packet.entityId;
        entity.func_70012_b(
            packet.scaledX, packet.scaledY, packet.scaledZ, packet.scaledYaw, packet.scaledPitch);
        if (entity instanceof EntityLiving) {
          ((EntityLiving) entity).field_70759_as = packet.scaledHeadYaw;
        }

        Entity parts[] = entity.func_70021_al();
        if (parts != null) {
          for (int j = 0; j < parts.length; j++) {
            parts[j].field_70157_k += offset;
          }
        }
      }

      entity.field_70118_ct = packet.rawX;
      entity.field_70117_cu = packet.rawY;
      entity.field_70116_cv = packet.rawZ;

      if (entity instanceof IThrowableEntity) {
        Entity thrower =
            client.field_71439_g.field_70157_k == packet.throwerId
                ? client.field_71439_g
                : wc.func_73045_a(packet.throwerId);
        ((IThrowableEntity) entity).setThrower(thrower);
      }

      if (packet.metadata != null) {
        entity.func_70096_w().func_75687_a((List) packet.metadata);
      }

      if (packet.throwerId > 0) {
        entity.func_70016_h(packet.speedScaledX, packet.speedScaledY, packet.speedScaledZ);
      }

      if (entity instanceof IEntityAdditionalSpawnData) {
        ((IEntityAdditionalSpawnData) entity).readSpawnData(packet.dataStream);
      }

      wc.func_73027_a(packet.entityId, entity);
      return entity;
    } catch (Exception e) {
      FMLLog.log(Level.SEVERE, e, "A severe problem occurred during the spawning of an entity");
      throw Throwables.propagate(e);
    }
  }
  private void spawnEntity(FMLMessage.EntitySpawnMessage spawnMsg) {
    ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
    WorldClient wc = FMLClientHandler.instance().getWorldClient();
    Class<? extends Entity> cls = er.getEntityClass();
    try {
      Entity entity;
      if (er.hasCustomSpawning()) {
        entity = er.doCustomSpawning(spawnMsg);
      } else {
        entity = (Entity) (cls.getConstructor(World.class).newInstance(wc));

        int offset = spawnMsg.entityId - entity.getEntityId();
        entity.setEntityId(spawnMsg.entityId);
        entity.setLocationAndAngles(
            spawnMsg.scaledX,
            spawnMsg.scaledY,
            spawnMsg.scaledZ,
            spawnMsg.scaledYaw,
            spawnMsg.scaledPitch);
        if (entity instanceof EntityLiving) {
          ((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
        }

        Entity parts[] = entity.getParts();
        if (parts != null) {
          for (int j = 0; j < parts.length; j++) {
            parts[j].setEntityId(parts[j].getEntityId() + offset);
          }
        }
      }

      entity.serverPosX = spawnMsg.rawX;
      entity.serverPosY = spawnMsg.rawY;
      entity.serverPosZ = spawnMsg.rawZ;

      EntityClientPlayerMP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
      if (entity instanceof IThrowableEntity) {
        Entity thrower =
            clientPlayer.getEntityId() == spawnMsg.throwerId
                ? clientPlayer
                : wc.getEntityByID(spawnMsg.throwerId);
        ((IThrowableEntity) entity).setThrower(thrower);
      }

      if (spawnMsg.dataWatcherList != null) {
        entity.getDataWatcher().updateWatchedObjectsFromList((List<?>) spawnMsg.dataWatcherList);
      }

      if (spawnMsg.throwerId > 0) {
        entity.setVelocity(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
      }

      if (entity instanceof IEntityAdditionalSpawnData) {
        ((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
      }
      wc.addEntityToWorld(spawnMsg.entityId, entity);
    } catch (Exception e) {
      FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity");
      throw Throwables.propagate(e);
    }
  }