Jump to content

ArrayIndexOutOfBoundsException when adding new EnumCreatureType


jt9

Recommended Posts

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));
        }
    }

 

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • In the rapidly evolving landscape of cryptocurrency, scams are on the rise, leaving many investors vulnerable to fraudulent schemes. If you've found yourself a victim of a crypto scam, navigating the complex process of recovering your lost funds can be daunting and overwhelming. However, there are some professionals in cryptocurrency recovery, such as Captain WebGenesis, who have specific knowledge and experience in handling complex blockchain technology and comprehending how scammers function in the cryptocurrency space. Captain WebGenesis has extensive expertise helping people who have been duped by investment scams to effectively retrieve their stolen or lost cryptocurrency.  
    • Looking for a semi-vanilla Minecraft server? Maybe one with keep inventory and land claims? I have one for you! Let me introduce you to Safe Survival! Come on and join us at mc.safesurvival.net. It is bedrock supported too!
    • Hi. I'm trying to play RLCraft with Optifine but my game keeps crashing on startup with Exit Code 1. The modpack was working fine yesterday, not sure what changed to make it not wanna work anymore. I was hoping someone here could help me figure out what's going wrong. If I remove Optifine, nothing changes, I still get the same errors. Thanks in advance. Crash Report (I only included the errors+fatal, I’m not sure if more is needed, please let me know): https://pastebin.ai/66ivknz0f4  
    • I am trying to port my mod from 1.20.2 to 1.21, but I am encountering difficulties regarding the classes for rendering the GUI and related events. What are the equivalents of the following classes? net.minecraftforge.client.event.RenderGuiOverlayEvent net.minecraftforge.client.gui.overlay.NamedGuiOverlay net.minecraftforge.client.gui.overlay.ForgeGui net.minecraftforge.client.gui.overlay.GuiOverlayManager net.minecraftforge.client.gui.overlay.IGuiOverlay   thx
    • Hi all! Love the Custom npc mod, it is my favorite mod! That said, I have been using this mod since finding it a few years ago (I only play on 1.12.2) and instantly loved that I caould reskin all of the npc's I created. That worked great until recently. I got locked out of my outlook account, which is what I was logged into windows with at the time, and they locked me out of Windows 10. So, I had to reinstall, and since I have digital entitlements to Windows 10 ( I am part of the insider program) on all three of my outlook accounts, I ust swapped to the one I bought Minecraft for. Reinstalled everything, started MC, crerated my favorite fighter (set to kill everything) to clear an area) set up the stats, went back to the main screen, clicked skin so I can give him the grim reaper skin and crash . . . wtf? Thought it was another mod, so, over the course of the last 2 days, I removed every single mod, reinstalled forge 2860 and then 2859, replaced optifine G5 with G6 and vice versa, all with the same result. So, I created a new world, with only the two mods, and same thing. https://pastebin.com/8raJVHq1 That is the log, I have been through the visual settings and all sorts of stuff and can not figure this out, and being that I only just started a bachelors in software engineer / computer programming, I have no idea what I am looking at, so please, and thank you!  If any one of you know what is causing this, I will be forever grateful for the help! Mor9heus
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.