コード例 #1
0
ファイル: FMLClientHandler.java プロジェクト: agaricusb/FML
  @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);
    }
  }
コード例 #2
0
    public boolean tryTrackingEntity(EntityTracker entityTracker, Entity entity)
    {

        EntityRegistration er = lookupModSpawn(entity.getClass(), true);
        if (er != null)
        {
            entityTracker.addEntityToTracker(entity, er.getTrackingRange(), er.getUpdateFrequency(), er.sendsVelocityUpdates());
            return true;
        }
        return false;
    }
コード例 #3
0
 public EntityRegistration lookupModSpawn(ModContainer mc, int modEntityId)
 {
     for (EntityRegistration er : entityRegistrations.get(mc))
     {
         if (er.getModEntityId() == modEntityId)
         {
             return er;
         }
     }
     return null;
 }
コード例 #4
0
ファイル: ModLoaderHelper.java プロジェクト: JSut210/ModDev
 public static void buildEntityTracker(
     BaseModProxy mod,
     Class<? extends Entity> entityClass,
     int entityTypeId,
     int updateRange,
     int updateInterval,
     boolean sendVelocityInfo) {
   EntityRegistration er =
       EntityRegistry.registerModLoaderEntity(
           mod, entityClass, entityTypeId, updateRange, updateInterval, sendVelocityInfo);
   er.setCustomSpawning(
       new ModLoaderEntitySpawnCallback(mod, er),
       EntityDragon.class.isAssignableFrom(entityClass)
           || IAnimals.class.isAssignableFrom(entityClass));
 }
コード例 #5
0
  @SuppressWarnings("unchecked")
  @Override
  public EntityEggInfo getEgg(ItemStack safariNet) {
    Class<? extends Entity> entityClass =
        (Class<? extends Entity>)
            EntityList.stringToClassMapping.get(safariNet.getTagCompound().getString("id"));
    if (entityClass == null) {
      return null;
    }

    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(entityClass, true);
    if (er != null && er.getContainer() == TwilightForest.twilightForestContainer) {
      return (EntityEggInfo) TwilightForest.entityEggs.get(er.getModEntityId());
    }
    return null;
  }
コード例 #6
0
  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);
    }
  }