From 0bff21315cb18f8467fa92a7779f2e09def1638a Mon Sep 17 00:00:00 2001 From: cpw Date: Tue, 31 Mar 2015 15:03:18 -0400 Subject: [PATCH 1/4] Rather than try to fall back to the backup level.dat in case of weirdness in the ID map, just fail hard. There is probably a serious modder derp in this case and there's nothing FML can do to recover the situation except avoid making it worse. --- .../java/cpw/mods/fml/common/FMLContainer.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java index 14c05ac8fe..5b11da1ad2 100644 --- a/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java +++ b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java @@ -272,7 +272,21 @@ public class FMLContainer extends DummyModContainer implements WorldAccessContai itemSubstitutions.add(dataTag.getString("K")); } } - failedElements = GameData.injectWorldIDMap(dataList, blockedIds, blockAliases, itemAliases, blockSubstitutions, itemSubstitutions, true, true); + try + { + failedElements = GameData.injectWorldIDMap(dataList, blockedIds, blockAliases, itemAliases, blockSubstitutions, itemSubstitutions, true, true); + } catch (IllegalArgumentException ex) + { + // In the case of IllegalArgumentException the state map is utterly toast. We should immediately abort + String msg = "The world state is utterly corrupted and this save is NOT loadable\n\n" + + "There is a high probability that a mod has broken the\n" + + "ID map and there is\n" + + "NOTHING FML or Forge can do to recover this save.\n\n" + + "If you changed your mods, try reverting the change"; + FMLLog.log(Level.FATAL, ex, msg); + StartupQuery.notify(msg); + StartupQuery.abort(); + } } if (failedElements != null && !failedElements.isEmpty()) From 0b8ff5890a98d038710d38e36c26f51227f7afc9 Mon Sep 17 00:00:00 2001 From: cpw Date: Tue, 31 Mar 2015 15:11:39 -0400 Subject: [PATCH 2/4] It's an IllegalState not an IllegalArgument *sigh* --- fml/src/main/java/cpw/mods/fml/common/FMLContainer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java index 5b11da1ad2..49ec6b4719 100644 --- a/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java +++ b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java @@ -275,7 +275,7 @@ public class FMLContainer extends DummyModContainer implements WorldAccessContai try { failedElements = GameData.injectWorldIDMap(dataList, blockedIds, blockAliases, itemAliases, blockSubstitutions, itemSubstitutions, true, true); - } catch (IllegalArgumentException ex) + } catch (IllegalStateException ex) { // In the case of IllegalArgumentException the state map is utterly toast. We should immediately abort String msg = "The world state is utterly corrupted and this save is NOT loadable\n\n" From d684a4e066d236672e2dda9e7b3ad0383663d6da Mon Sep 17 00:00:00 2001 From: cpw Date: Tue, 31 Mar 2015 15:29:51 -0400 Subject: [PATCH 3/4] And fix itemblocks being removed, leaving behind a residual block. This is a legitimate action - use the missing mapping event to let the mod tell us about it --- .../fml/common/event/FMLMissingMappingsEvent.java | 12 +++++++++++- .../java/cpw/mods/fml/common/registry/GameData.java | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fml/src/main/java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java b/fml/src/main/java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java index 94ea8e3eaa..8b9dc04d30 100644 --- a/fml/src/main/java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java +++ b/fml/src/main/java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java @@ -52,7 +52,11 @@ public class FMLMissingMappingsEvent extends FMLEvent { /** * Remap this name to a new name (add a migration mapping) */ - REMAP + REMAP, + /** + * Allow a block to exist without itemblock anymore + */ + BLOCKONLY } public static class MissingMapping { public final GameRegistry.Type type; @@ -138,6 +142,12 @@ public class FMLMissingMappingsEvent extends FMLEvent { this.target = target; } + public void skipItemBlock() + { + if (type != GameRegistry.Type.ITEM) throw new IllegalArgumentException("Cannot skip an item that is a block"); + if (GameData.getBlockRegistry().getRaw(id) == null) throw new IllegalArgumentException("Cannot skip an ItemBlock that doesn't have a Block"); + action = Action.BLOCKONLY; + } // internal public Action getAction() diff --git a/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java b/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java index b4c59f189f..ec1f30801d 100644 --- a/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java +++ b/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java @@ -632,6 +632,12 @@ public class GameData { remaps.put(newName, new Integer[] { currId, newId }); } } + else if (action == FMLMissingMappingsEvent.Action.BLOCKONLY) + { + // Pulled out specifically so the block doesn't get reassigned a new ID just because it's + // Item block has gone away + FMLLog.fine("The ItemBlock %s is no longer present in the game. The residual block will remain", remap.name); + } else { // block item missing, warn as requested and block the id From 0d79aa1e0a192285589122596a52fd2caa9bbeb5 Mon Sep 17 00:00:00 2001 From: cpw Date: Tue, 31 Mar 2015 15:38:53 -0400 Subject: [PATCH 4/4] You can't setAction to BLOCKONLY --- .../java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fml/src/main/java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java b/fml/src/main/java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java index 8b9dc04d30..f246922bd7 100644 --- a/fml/src/main/java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java +++ b/fml/src/main/java/cpw/mods/fml/common/event/FMLMissingMappingsEvent.java @@ -77,7 +77,7 @@ public class FMLMissingMappingsEvent extends FMLEvent { @Deprecated public void setAction(Action target) { - if (target == Action.DEFAULT || target == Action.REMAP) throw new IllegalArgumentException(); + if (target == Action.DEFAULT || target == Action.REMAP || target == Action.BLOCKONLY) throw new IllegalArgumentException(); this.action = target; }