Posted August 26, 20187 yr A user posted a crash log of the mod throwing an Caused by: java.lang.ArrayIndexOutOfBoundsException: 6 The full crash log can be found here: https://paste.dimdev.org/ziliruyota.mccrash I followed the stack trace and cannot figure out why Biome.getSpawnableList() would throw an exception. The mod works fine on its own, but crashes with other mods that add entity spawns. This only happens when I use my own EnumCreatureType, which is for allowing the mod's entities to spawn without interfering with the animal spawn cap. I'm not sure why it throws an ArrayIndexOutOfBoundsException since getSpawnableList() creates a new, empty ArrayList for non-vanilla EnumCreatureTypes, and I'm not sure why it's 6 in particular. In case it's needed, I call initEntities() during preinit and addSpawns() during init. Here's my entity code: Spoiler public class PVJEntities { public static int id = 1; public static final ArrayList<EntityEntry> ENTITIES = new ArrayList<EntityEntry>(); public static final EnumCreatureType PVJ_ANIMAL = EnumHelper.addCreatureType("pvj_animal", EntityPVJAnimal.class, 15, Material.AIR, true, true); public static void initEntities() { registerEntityWithEgg("pvj_snail", EntitySnail.class, 64, 0x6D453D, 0x677B5C); registerEntityWithEgg("pvj_fly", EntityFly.class, 64, 0x669999, 0x737373); registerEntityWithEgg("pvj_firefly", EntityFirefly.class, 64, 0x3F453D, 0xE8E03D); registerEntityWithEgg("pvj_ghost", EntityGhost.class, 64, 0xb3b3b3, 0x404040); registerEntityWithEgg("pvj_shade", EntityShade.class, 64, 0x333333, 0x595959); registerEntityWithEgg("pvj_icecube", EntityIceCube.class, 64, 0x66e0ff, 0xccf5ff); registerEntityWithEgg("pvj_skeletal_knight", EntitySkeletalKnight.class, 64, 0xa6a6a6, 0x808080); registerEntityWithEgg("pvj_goon", EntityGoon.class, 64, 0xa6a6a6, 0x808080); registerEntity("pvj_boat", EntityPVJBoat.class, 64); } private static <T extends Entity> void registerEntity(String name, Class<T> entityClass, int trackingRange) { ResourceLocation entityResource = new ResourceLocation(Reference.MOD_ID, name); EntityEntry entity = EntityEntryBuilder.create() .entity(entityClass) .id(entityResource, id++) .name(name) .tracker(trackingRange, 3, true) .build(); ENTITIES.add(entity); } private static <T extends Entity> void registerEntityWithEgg(String name, Class<T> entityClass, int trackingRange, int eggPrimary, int eggSecondary) { ResourceLocation entityResource = new ResourceLocation(Reference.MOD_ID, name); EntityEntry entity = EntityEntryBuilder.create() .entity(entityClass) .id(entityResource, id++) .name(name) .tracker(trackingRange, 3, true) .egg(eggPrimary, eggSecondary) .build(); ENTITIES.add(entity); } public static void addSpawns() { //these if condition checks prevent crashes, and allow the config to disable spawning if(PVJConfig.entities.snailSpawnWeight > 0) EntityRegistry.addSpawn(EntitySnail.class, PVJConfig.entities.snailSpawnWeight, 2, 4, PVJ_ANIMAL, BiomeReference.getValidBiomes(BiomeReference.FRESHWATER_BIOMES)); if(PVJConfig.entities.flySpawnWeight > 0) EntityRegistry.addSpawn(EntityFly.class, PVJConfig.entities.flySpawnWeight, 3, 4, EnumCreatureType.AMBIENT, BiomeReference.getValidBiomes(BiomeReference.OVERWORLD_BIOMES)); if(PVJConfig.entities.flySwampSpawnWeight > 0) EntityRegistry.addSpawn(EntityFly.class, PVJConfig.entities.flySwampSpawnWeight, 4, 5, EnumCreatureType.AMBIENT, BiomeDictionary.getBiomes(Type.SWAMP).toArray(new Biome[0])); if(PVJConfig.entities.fireflySpawnWeight > 0) EntityRegistry.addSpawn(EntityFirefly.class, PVJConfig.entities.fireflySpawnWeight, 4, 9, EnumCreatureType.AMBIENT, BiomeReference.getValidBiomes(BiomeReference.OVERWORLD_BIOMES)); if(PVJConfig.entities.ghostSpawnWeight > 0) EntityRegistry.addSpawn(EntityGhost.class, PVJConfig.entities.ghostSpawnWeight, 1, 4, EnumCreatureType.MONSTER, BiomeReference.getValidBiomes(BiomeReference.OVERWORLD_BIOMES)); if(PVJConfig.entities.shadeSpawnWeight > 0) EntityRegistry.addSpawn(EntityShade.class, PVJConfig.entities.shadeSpawnWeight, 1, 3, EnumCreatureType.MONSTER, BiomeReference.getValidBiomes(BiomeReference.OVERWORLD_BIOMES)); if(PVJConfig.entities.skeletalKnightWeight > 0) EntityRegistry.addSpawn(EntitySkeletalKnight.class, PVJConfig.entities.skeletalKnightWeight, 1, 3, EnumCreatureType.MONSTER, BiomeReference.getValidBiomes(BiomeReference.OVERWORLD_BIOMES)); if(PVJConfig.entities.icecubeSpawnWeight > 0) EntityRegistry.addSpawn(EntityIceCube.class, PVJConfig.entities.icecubeSpawnWeight, 2, 3, EnumCreatureType.MONSTER, BiomeReference.getValidBiomes(BiomeReference.SNOWY_BIOMES)); if(PVJConfig.entities.goonSpawnWeight > 0) EntityRegistry.addSpawn(EntityGoon.class, PVJConfig.entities.goonSpawnWeight, 1, 1, EnumCreatureType.MONSTER, BiomeReference.getValidBiomes(BiomeReference.OVERWORLD_BIOMES)); DungeonHooks.addDungeonMob(new ResourceLocation(Reference.MOD_ID, "pvj_shade"), 100); DungeonHooks.addDungeonMob(new ResourceLocation(Reference.MOD_ID, "pvj_skeletal_knight"), 100); } } And here's both Biome.getSpawnableList() as well as EntityRegistry.addSpawn() for reference. Spoiler /** * Returns the correspondent list of the EnumCreatureType informed. */ public List<Biome.SpawnListEntry> getSpawnableList(EnumCreatureType creatureType) { switch (creatureType) { case MONSTER: return this.spawnableMonsterList; case CREATURE: return this.spawnableCreatureList; case WATER_CREATURE: return this.spawnableWaterCreatureList; case AMBIENT: return this.spawnableCaveCreatureList; default: // Forge: Return a non-empty list for non-vanilla EnumCreatureTypes if (!this.modSpawnableLists.containsKey(creatureType)) this.modSpawnableLists.put(creatureType, Lists.<Biome.SpawnListEntry>newArrayList()); return this.modSpawnableLists.get(creatureType); } } Spoiler /** * Add a spawn entry for the supplied entity in the supplied {@link Biome} list * @param entityClass Entity class added * @param weightedProb Probability * @param min Min spawn count * @param max Max spawn count * @param typeOfCreature Type of spawn * @param biomes List of biomes */ public static void addSpawn(Class <? extends EntityLiving > entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, Biome... biomes) { for (Biome biome : biomes) { List<SpawnListEntry> spawns = biome.getSpawnableList(typeOfCreature); boolean found = false; for (SpawnListEntry entry : spawns) { //Adjusting an existing spawn entry if (entry.entityClass == entityClass) { entry.itemWeight = weightedProb; entry.minGroupCount = min; entry.maxGroupCount = max; found = true; break; } } if (!found) spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max)); } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.