示例#1
0
 private EntityRegistry()
 {
     availableIndicies = new BitSet(256);
     availableIndicies.set(1,255);
     for (Object id : EntityList.IDtoClassMapping.keySet())
     {
         availableIndicies.clear((Integer)id);
     }
 }
 public static void registerEntityEgg(
     Class<? extends Entity> entity, int primaryColor, int secondaryColor) {
   int id = getUniqueEntityId();
   EntityList.IDtoClassMapping.put(id, entity);
   EntityList.entityEggs.put(id, new EntityEggInfo(id, primaryColor, secondaryColor));
 }
示例#3
0
  /** Registers the entities in this mod and adds mob spawns. */
  private void registerMobs() {
    DataWatcherHelper.init();

    int id = 0; // Mod-specific mob id

    // Initialize everything needed to make new spawn eggs
    boolean makeSpawnEggs = Properties.getBoolean(Properties.GENERAL, "spawn_eggs");
    Method eggIdClaimer = null;
    int eggId;
    if (makeSpawnEggs) {
      try {
        eggIdClaimer = EntityRegistry.class.getDeclaredMethod("validateAndClaimId", int.class);
        eggIdClaimer.setAccessible(true);
      } catch (Exception ex) {
        _SpecialMobs.console(
            "Error claiming spawn egg ID! Spawn eggs will probably be overwritten.");
        ex.printStackTrace();
      }
    }

    // Advanced Genetics compatibility
    Method advGeneticsAddAbility = null;
    String[][] advGeneticsAbilities = null;
    try {
      Class regHelper = Class.forName("com.advGenetics.API.RegistrationHelper");
      _SpecialMobs.console("Detected Advanced Genetics API, attempting to register mobs to it...");
      try {
        advGeneticsAddAbility =
            regHelper.getDeclaredMethod("addEntityToAbility", String.class, Class.class);
      } catch (Exception ex) {
        _SpecialMobs.console("Error finding Advanced Genetics registry!");
        ex.printStackTrace();
      }
      if (advGeneticsAddAbility != null) {
        advGeneticsAbilities =
            new String[][] {
              // Blaze
              {"fireballs"},
              // CaveSpider
              {"climb", "poison"},
              // Creeper
              {"selfexplode"},
              // Enderman
              {"deathenderchest", "teleport"},
              // Ghast
              {"fireballsexplode"},
              // LavaSlime
              // { "slimy", "lavaswim" },
              // PigZombie
              {"lavaswim"},
              // Silverfish
              {},
              // Skeleton
              {"infinity"},
              // Slime
              {"slimy"},
              // Spider
              {"climb"},
              // Witch
              {"potionthrower"},
              // Zombie
              {"resistance"}
            };
        for (String ability : advGeneticsAbilities[_SpecialMobs.monsterKey("Enderman")]) {
          try {
            advGeneticsAddAbility.invoke(null, ability, EntityEnderCreeper.class);
          } catch (Exception ex) {
            // Do nothing
          }
        }
      }
    } catch (Exception ex) {
      // Do nothing, Advanced Genetics not found
    }

    // Register main mobs
    String name;
    Class entityClass;
    for (int i = 0; i < _SpecialMobs.MONSTER_KEY.length; i++) {
      // Register vanilla replacement
      try {
        entityClass =
            Class.forName(
                "toast.specialMobs.entity."
                    + _SpecialMobs.MONSTER_KEY[i].toLowerCase()
                    + ".Entity_Special"
                    + _SpecialMobs.MONSTER_KEY[i]);
        EntityRegistry.registerModEntity(
            entityClass, "Special" + _SpecialMobs.MONSTER_KEY[i], id++, this, 80, 3, true);

        // Advanced Genetics compatibility
        if (advGeneticsAddAbility != null && advGeneticsAbilities != null) {
          for (String ability : advGeneticsAbilities[i]) {
            try {
              advGeneticsAddAbility.invoke(null, ability, entityClass);
            } catch (Exception ex) {
              // Do nothing
            }
          }
        }
      } catch (ClassNotFoundException ex) {
        _SpecialMobs.debugException("@" + _SpecialMobs.MONSTER_KEY[i] + ": class not found!");
      }

      // Register special variants
      for (int j = 0; j < _SpecialMobs.MONSTER_TYPES[i].length; j++) {
        name = _SpecialMobs.MONSTER_TYPES[i][j] + _SpecialMobs.MONSTER_KEY[i];
        try {
          entityClass =
              Class.forName(
                  "toast.specialMobs.entity."
                      + _SpecialMobs.MONSTER_KEY[i].toLowerCase()
                      + ".Entity"
                      + name);
          EntityRegistry.registerModEntity(entityClass, name, id++, this, 80, 3, true);

          // Add spawn egg by taking a global mob id
          if (makeSpawnEggs) {
            eggId = EntityRegistry.findGlobalUniqueEntityId();
            try {
              if (eggIdClaimer != null) {
                eggId =
                    ((Integer)
                            eggIdClaimer.invoke(EntityRegistry.instance(), Integer.valueOf(eggId)))
                        .intValue();
              }
            } catch (Exception ex) {
              // Do nothing
            }
            EntityList.IDtoClassMapping.put(Integer.valueOf(eggId), entityClass);
            EntityList.entityEggs.put(
                Integer.valueOf(eggId),
                new EntityEggInfo(
                    eggId,
                    _SpecialMobs.MONSTER_KEY_COLORS[i],
                    _SpecialMobs.MONSTER_TYPE_COLORS[i][j]));
          }

          // Advanced Genetics compatibility
          if (advGeneticsAddAbility != null && advGeneticsAbilities != null) {
            for (String ability : advGeneticsAbilities[i]) {
              try {
                advGeneticsAddAbility.invoke(null, ability, entityClass);
              } catch (Exception ex) {
                // Do nothing
              }
            }
          }
        } catch (ClassNotFoundException ex) {
          _SpecialMobs.debugException("@" + name + ": class not found!");
        }
      }
    }

    // Register other entities (like projectiles)
    EntityRegistry.registerModEntity(
        EntitySpecialFishHook.class, "SMFishHook", id++, this, 64, 5, true);
    EntityRegistry.registerModEntity(
        EntitySpecialSpitball.class, "SMSpitball", id++, this, 64, 5, true);

    // EntityRegistry.registerModEntity(EntitySpecialFireball.class, "SMFireball", id++, this, 64,
    // 10, true);

    DataWatcherHelper.verify();

    // Register extra mob spawns
    int spawnWeight;
    spawnWeight = Properties.getInt(Properties.SPAWNING, "end_ender_creeper");
    if (spawnWeight > 0) {
      EntityRegistry.addSpawn(
          EntityEnderCreeper.class, spawnWeight, 1, 1, EnumCreatureType.monster, BiomeGenBase.sky);
    }
    spawnWeight = Properties.getInt(Properties.SPAWNING, "nether_fire_creeper");
    if (spawnWeight > 0) {
      EntityRegistry.addSpawn(
          EntityFireCreeper.class, spawnWeight, 4, 4, EnumCreatureType.monster, BiomeGenBase.hell);
    }
    spawnWeight = Properties.getInt(Properties.SPAWNING, "overworld_ghast_mount");
    if (spawnWeight > 0) {
      EntityRegistry.addSpawn(
          EntityMiniGhast.class,
          spawnWeight,
          1,
          1,
          EnumCreatureType.monster,
          BiomeGenBase.ocean,
          BiomeGenBase.frozenOcean,
          BiomeGenBase.plains,
          BiomeGenBase.desert,
          BiomeGenBase.desertHills,
          BiomeGenBase.extremeHills,
          BiomeGenBase.extremeHillsEdge,
          BiomeGenBase.forest,
          BiomeGenBase.forestHills,
          BiomeGenBase.taiga,
          BiomeGenBase.taigaHills,
          BiomeGenBase.swampland,
          BiomeGenBase.river,
          BiomeGenBase.frozenRiver,
          BiomeGenBase.icePlains,
          BiomeGenBase.iceMountains,
          BiomeGenBase.beach,
          BiomeGenBase.jungle,
          BiomeGenBase.jungleHills);
    }
  }