Skip to content

Commit b7db9b1

Browse files
committed
refactor(api): catch IndexOutOfBounds on getDimensionTypeID(int)
1 parent f3d1b0a commit b7db9b1

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/main/java/micdoodle8/mods/galacticraft/api/GalacticraftRegistry.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package micdoodle8.mods.galacticraft.api;
99

1010
import com.google.common.collect.Lists;
11-
import java.lang.reflect.Method;
1211
import java.util.ArrayList;
1312
import java.util.HashMap;
1413
import java.util.LinkedList;
@@ -35,22 +34,21 @@
3534
public class GalacticraftRegistry
3635
{
3736

38-
private static Map<Class<? extends WorldProvider>, ITeleportType> teleportTypeMap = new HashMap<Class<? extends WorldProvider>, ITeleportType>();
39-
private static List<SpaceStationType> spaceStations = new ArrayList<SpaceStationType>();
40-
private static List<INasaWorkbenchRecipe> rocketBenchT1Recipes = new ArrayList<INasaWorkbenchRecipe>();
41-
private static List<INasaWorkbenchRecipe> buggyBenchRecipes = new ArrayList<INasaWorkbenchRecipe>();
42-
private static List<INasaWorkbenchRecipe> rocketBenchT2Recipes = new ArrayList<INasaWorkbenchRecipe>();
43-
private static List<INasaWorkbenchRecipe> cargoRocketRecipes = new ArrayList<INasaWorkbenchRecipe>();
44-
private static List<INasaWorkbenchRecipe> rocketBenchT3Recipes = new ArrayList<INasaWorkbenchRecipe>();
45-
private static List<INasaWorkbenchRecipe> astroMinerRecipes = new ArrayList<INasaWorkbenchRecipe>();
46-
private static Map<Class<? extends WorldProvider>, ResourceLocation> rocketGuiMap = new HashMap<Class<? extends WorldProvider>, ResourceLocation>();
47-
private static Map<Integer, List<ItemStack>> dungeonLootMap = new HashMap<Integer, List<ItemStack>>();
48-
private static List<Integer> dimensionTypeIDs = new ArrayList<Integer>();
49-
private static List<IGameScreen> gameScreens = new ArrayList<IGameScreen>();
37+
private static Map<Class<? extends WorldProvider>, ITeleportType> teleportTypeMap = new HashMap<>();
38+
private static List<SpaceStationType> spaceStations = new ArrayList<>();
39+
private static List<INasaWorkbenchRecipe> rocketBenchT1Recipes = new ArrayList<>();
40+
private static List<INasaWorkbenchRecipe> buggyBenchRecipes = new ArrayList<>();
41+
private static List<INasaWorkbenchRecipe> rocketBenchT2Recipes = new ArrayList<>();
42+
private static List<INasaWorkbenchRecipe> cargoRocketRecipes = new ArrayList<>();
43+
private static List<INasaWorkbenchRecipe> rocketBenchT3Recipes = new ArrayList<>();
44+
private static List<INasaWorkbenchRecipe> astroMinerRecipes = new ArrayList<>();
45+
private static Map<Class<? extends WorldProvider>, ResourceLocation> rocketGuiMap = new HashMap<>();
46+
private static Map<Integer, List<ItemStack>> dungeonLootMap = new HashMap<>();
47+
private static List<Integer> dimensionTypeIDs = new ArrayList<>();
48+
private static List<IGameScreen> gameScreens = new ArrayList<>();
5049
private static int maxScreenTypes;
5150
private static Map<Integer, List<Object>> gearMap = new HashMap<>();
5251
private static Map<Integer, List<EnumExtendedInventorySlot>> gearSlotMap = new HashMap<>();
53-
private static Method gratingRegister = null;
5452

5553
/**
5654
* Register a new Teleport type for the world provider passed
@@ -101,7 +99,7 @@ public static void addDungeonLoot(int tier, ItemStack loot)
10199
dungeonStacks.add(loot);
102100
} else
103101
{
104-
dungeonStacks = new ArrayList<ItemStack>();
102+
dungeonStacks = new ArrayList<>();
105103
dungeonStacks.add(loot);
106104
}
107105

@@ -311,7 +309,16 @@ public static DimensionType registerDimension(String name, String suffix, int id
311309

312310
public static int getDimensionTypeID(int index)
313311
{
314-
return GalacticraftRegistry.dimensionTypeIDs.get(index);
312+
// Not the best solution but is better than the very unuseful IndexOutOfBoundsException message
313+
try
314+
{
315+
return GalacticraftRegistry.dimensionTypeIDs.get(index);
316+
} catch (IndexOutOfBoundsException e)
317+
{
318+
GalacticraftCore.logger.error("Attempted to get index[%d] while 'dimensionTypeIDs' size was %d", index, GalacticraftRegistry.dimensionTypeIDs.size());
319+
return 0;
320+
}
321+
315322
}
316323

317324
public static boolean isDimensionTypeIDRegistered(int typeId)

0 commit comments

Comments
 (0)