From c58433692c72e29cb3ca5bd405d7c4cbd27cbc7a Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 28 Jan 2013 17:26:02 -0800 Subject: [PATCH] Add DimensionManager.unregisterProviderType for PR #388 --- .../common/DimensionManager.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/common/net/minecraftforge/common/DimensionManager.java b/common/net/minecraftforge/common/DimensionManager.java index 2b29e7413..14e4f062c 100644 --- a/common/net/minecraftforge/common/DimensionManager.java +++ b/common/net/minecraftforge/common/DimensionManager.java @@ -2,6 +2,7 @@ package net.minecraftforge.common; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.BitSet; import java.util.HashSet; import java.util.Hashtable; @@ -64,6 +65,38 @@ public class DimensionManager return true; } + /** + * Unregisters a Provider type, and returns a array of all dimensions that are + * registered to this provider type. + * If the return size is greater then 0, it is required that the caller either + * change those dimensions's registered type, or replace this type before the + * world is attempted to load, else the loader will throw an exception. + * + * @param id The provider type ID to unreigster + * @return An array containing all dimension IDs still registered to this provider type. + */ + public static int[] unregisterProviderType(int id) + { + if (!providers.containsKey(id)) + { + return new int[0]; + } + providers.remove(id); + spawnSettings.remove(id); + + int[] ret = new int[dimensions.size()]; + int x = 0; + for (Map.Entry ent : dimensions.entrySet()) + { + if (ent.getValue() == id) + { + ret[x++] = ent.getKey(); + } + } + + return Arrays.copyOf(ret, x); + } + public static void init() { if (hasInit)