From e64296e109a17053a4b4278939f37a95d07e23fa Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 14 Aug 2012 13:36:29 -0400 Subject: [PATCH] Handle mod duplicate detection much better. Default the name of a mod to it's id. Fix up the block registry problem. Fix the packetsend from c->s actually being "disconnect" :) --- .../cpw/mods/fml/client/FMLClientHandler.java | 2 +- .../cpw/mods/fml/common/FMLModContainer.java | 5 +++ common/cpw/mods/fml/common/Loader.java | 41 +++++++++++++++++++ .../fml/common/registry/GameRegistry.java | 3 -- common/fml_marker.cfg | 4 +- eclipse/FML-Client/tstann.jpage | 12 +++++- 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/client/cpw/mods/fml/client/FMLClientHandler.java b/client/cpw/mods/fml/client/FMLClientHandler.java index 3a0c53ee24..4a6d301733 100644 --- a/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/client/cpw/mods/fml/client/FMLClientHandler.java @@ -399,6 +399,6 @@ public class FMLClientHandler implements IFMLSidedHandler @Override public void sendPacket(Packet packet) { - client.field_71439_g.field_71174_a.func_72546_b(packet); + client.field_71439_g.field_71174_a.func_72552_c(packet); } } diff --git a/common/cpw/mods/fml/common/FMLModContainer.java b/common/cpw/mods/fml/common/FMLModContainer.java index 2bebe7994e..d47e253956 100644 --- a/common/cpw/mods/fml/common/FMLModContainer.java +++ b/common/cpw/mods/fml/common/FMLModContainer.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import com.google.common.base.Strings; import com.google.common.base.Throwables; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BiMap; @@ -142,6 +143,10 @@ public class FMLModContainer implements ModContainer modMetadata.dependencies = dependencies; modMetadata.dependants = dependants; } + if (Strings.isNullOrEmpty(modMetadata.name)) + { + modMetadata.name = getModId(); + } } @Override diff --git a/common/cpw/mods/fml/common/Loader.java b/common/cpw/mods/fml/common/Loader.java index ce14116ae0..cbf3ee158c 100644 --- a/common/cpw/mods/fml/common/Loader.java +++ b/common/cpw/mods/fml/common/Loader.java @@ -22,6 +22,7 @@ import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.Hashtable; import java.util.List; @@ -43,8 +44,13 @@ import com.google.common.base.Throwables; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultiset; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Multiset.Entry; +import com.google.common.collect.Multisets; +import com.google.common.collect.Ordering; +import com.google.common.collect.TreeMultimap; import cpw.mods.fml.common.LoaderState.ModState; import cpw.mods.fml.common.discovery.ContainerType; @@ -286,11 +292,46 @@ public class Loader discoverer.findModDirMods(canonicalModsDir); mods.addAll(discoverer.identifyMods()); + identifyDuplicates(mods); namedMods = Maps.uniqueIndex(mods, new ModIdFunction()); FMLLog.info("Forge Mod Loader has identified %d mod%s to load", mods.size(), mods.size() != 1 ? "s" : ""); return discoverer; } + private class ModIdComparator implements Comparator + { + @Override + public int compare(ModContainer o1, ModContainer o2) + { + return o1.getModId().compareTo(o2.getModId()); + } + + } + + private void identifyDuplicates(List mods) + { + boolean foundDupe = false; + TreeMultimap dupsearch = TreeMultimap.create(new ModIdComparator(), Ordering.arbitrary()); + for (ModContainer mc : mods) + { + if (mc.getSource() != null) + { + dupsearch.put(mc, mc.getSource()); + } + } + + ImmutableMultiset duplist = Multisets.copyHighestCountFirst(dupsearch.keys()); + for (Entry e : duplist.entrySet()) + { + if (e.getCount() > 1) + { + FMLLog.severe("Found a duplicate mod %s at %s", e.getElement().getModId(), dupsearch.get(e.getElement())); + foundDupe = true; + } + } + if (foundDupe) { throw new LoaderException(); } + } + /** * @return */ diff --git a/common/cpw/mods/fml/common/registry/GameRegistry.java b/common/cpw/mods/fml/common/registry/GameRegistry.java index 946077917e..d9e2eadffa 100644 --- a/common/cpw/mods/fml/common/registry/GameRegistry.java +++ b/common/cpw/mods/fml/common/registry/GameRegistry.java @@ -160,9 +160,6 @@ public class GameRegistry if (Loader.instance().isInState(LoaderState.CONSTRUCTING)) { FMLLog.warning("The mod %s is attempting to register a block whilst it it being constructed. This is bad modding practice - please use a proper mod lifecycle event.", Loader.instance().activeModContainer()); - } else if (!Loader.instance().isInState(LoaderState.PREINITIALIZATION)) - { - FMLLog.warning("The mod %s is attempting to register a block after the statistics have loaded. This will reset the statistics for the game", Loader.instance().activeModContainer().getModId()); } try { diff --git a/common/fml_marker.cfg b/common/fml_marker.cfg index 0ab256dddb..fe046d33fc 100644 --- a/common/fml_marker.cfg +++ b/common/fml_marker.cfg @@ -6,7 +6,7 @@ of cpw/mods/fml/common/network/Player net.minecraft.src.EntityPlayer cpw/mods/fml/common/network/Player # block -> blockproxy aif cpw/mods/fml/common/registry/BlockProxy -net/minecraft/src/Block cpw/mods/fml/common/registry/BlockProxy +net.minecraft.src.Block cpw/mods/fml/common/registry/BlockProxy # item -> itemproxy rg cpw/mods/fml/common/registry/ItemProxy -net/minecraft/src/Item cpw/mods/fml/common/registry/ItemProxy \ No newline at end of file +net.minecraft.src.Item cpw/mods/fml/common/registry/ItemProxy \ No newline at end of file diff --git a/eclipse/FML-Client/tstann.jpage b/eclipse/FML-Client/tstann.jpage index cae9e688c7..d8e96142a1 100644 --- a/eclipse/FML-Client/tstann.jpage +++ b/eclipse/FML-Client/tstann.jpage @@ -31,4 +31,14 @@ org.objectweb.asm.Type.getDescriptor(net.minecraft.src.CraftingManager.class.get com.google.common.collect.Tables.newCustomTable(new HashMap>(), new com.google.common.base.Supplier() { -}); \ No newline at end of file +}); + + + + + + +byte[] bytes = new byte[] {0, 0, 0, 1, 0, 0, 0, -107, 0, 0, 22, 83, 0, 0, 25, -48, 0, 0, 8, 70, 0, 0, 32, 80, 0, 0, 0, 0, 0, 33, 1, 44, 74, 0, 0, 0, 0, 75, 0, 0, 0, 0, 76, 0, 0, 0, 0, 77, 0, 0, 0, 0, 78, 0, 0, 0, 0, 79, 0, 0, 0, 0, 81, 0, 0, 0, 0, 80, 0, 0, 0, 0, 83, 0, 0, 0, 0, 82, 0, 0, 0, 0, 85, 0, 0, 0, 0, 84, 0, 0, 0, 0, 23, 0, 22, 0, 25, 0, 24, 0, -102, 0, 0, 127, 0, 0, 0, 0}; +new cpw.mods.fml.common.network.EntitySpawnPacket().consumePacket(bytes) + +108 - 27 - 4 \ No newline at end of file