From 1dcf3bfbdccaa7e6f348398532d9b995733b85ee Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 12 Dec 2012 19:23:40 -0500 Subject: [PATCH] Change ID management slightly. IDs are tracked by block type for itemblock items now. This means servers will need to update. Also, ordinal rearrangements within a mod will no longer trigger server disconnection, though a warning will still be logged. --- .../cpw/mods/fml/client/FMLClientHandler.java | 17 ++++++++++++++ .../mods/fml/common/registry/GameData.java | 4 ++++ .../mods/fml/common/registry/ItemData.java | 22 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/fml/client/cpw/mods/fml/client/FMLClientHandler.java b/fml/client/cpw/mods/fml/client/FMLClientHandler.java index 08d29c522..1624be711 100644 --- a/fml/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/client/cpw/mods/fml/client/FMLClientHandler.java @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; @@ -42,6 +43,7 @@ import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.MapDifference; +import com.google.common.collect.MapDifference.ValueDifference; import cpw.mods.fml.client.modloader.ModLoaderClientHelper; import cpw.mods.fml.client.registry.KeyBindingRegistry; @@ -502,6 +504,21 @@ public class FMLClientHandler implements IFMLSidedHandler @Override public void disconnectIDMismatch(MapDifference s, NetHandler toKill, INetworkManager mgr) { + boolean criticalMismatch = !s.entriesOnlyOnLeft().isEmpty(); + for (Entry> mismatch : s.entriesDiffering().entrySet()) + { + ValueDifference vd = mismatch.getValue(); + if (!vd.leftValue().mayDifferByOrdinal(vd.rightValue())) + { + criticalMismatch = true; + } + } + + if (!criticalMismatch) + { + // We'll carry on with this connection, and just log a message instead + return; + } // Nuke the connection ((NetClientHandler)toKill).func_72553_e(); // Stop GuiConnecting diff --git a/fml/common/cpw/mods/fml/common/registry/GameData.java b/fml/common/cpw/mods/fml/common/registry/GameData.java index 3ba4a0fa0..a52cbd1b7 100644 --- a/fml/common/cpw/mods/fml/common/registry/GameData.java +++ b/fml/common/cpw/mods/fml/common/registry/GameData.java @@ -74,8 +74,12 @@ public class GameData { Map worldMap = Maps.uniqueIndex(worldSaveItems,idMapFunction); difference = Maps.difference(worldMap, idMap); + FMLLog.fine("The difference set is %s", difference); if (!difference.entriesDiffering().isEmpty() || !difference.entriesOnlyOnLeft().isEmpty()) { + FMLLog.severe("FML has detected item discrepancies"); + FMLLog.severe("Missing items : %s", difference.entriesOnlyOnLeft()); + FMLLog.severe("Mismatched items : %s", difference.entriesDiffering()); isSaveValid = false; serverValidationLatch.countDown(); } diff --git a/fml/common/cpw/mods/fml/common/registry/ItemData.java b/fml/common/cpw/mods/fml/common/registry/ItemData.java index 255ff542f..f284196e7 100644 --- a/fml/common/cpw/mods/fml/common/registry/ItemData.java +++ b/fml/common/cpw/mods/fml/common/registry/ItemData.java @@ -2,7 +2,9 @@ package cpw.mods.fml.common.registry; import java.util.Map; +import net.minecraft.block.Block; import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraft.nbt.NBTTagCompound; import com.google.common.base.Objects; @@ -23,7 +25,14 @@ public class ItemData { public ItemData(Item item, ModContainer mc) { this.itemId = item.field_77779_bT; - this.itemType = item.getClass().getName(); + if (item.getClass().equals(ItemBlock.class)) + { + this.itemType = Block.field_71973_m[this.itemId].getClass().getName(); + } + else + { + this.itemType = item.getClass().getName(); + } this.modId = mc.getModId(); if (!modOrdinals.containsKey(mc.getModId())) { @@ -69,4 +78,15 @@ public class ItemData { return false; } } + + @Override + public String toString() + { + return String.format("Item %d, Type %s, owned by %s, ordinal %d", itemId, itemType, modId, ordinal); + } + + public boolean mayDifferByOrdinal(ItemData rightValue) + { + return Objects.equal(itemType, rightValue.itemType) && Objects.equal(modId, rightValue.modId); + } }