diff --git a/fml/src/main/java/cpw/mods/fml/common/functions/GenericIterableFactory.java b/fml/src/main/java/cpw/mods/fml/common/functions/GenericIterableFactory.java index 85be09b2eb..f956d2d3df 100644 --- a/fml/src/main/java/cpw/mods/fml/common/functions/GenericIterableFactory.java +++ b/fml/src/main/java/cpw/mods/fml/common/functions/GenericIterableFactory.java @@ -1,8 +1,23 @@ package cpw.mods.fml.common.functions; +import java.util.Iterator; + import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; public class GenericIterableFactory { + public static Iterable newCastingIterable(final Iterator input, final Class type) + { + return new Iterable() + { + @Override + public Iterator iterator() + { + return Iterators.transform(input, new TypeCastFunction(type)); + } + }; + } + public static Iterable newCastingIterable(Iterable input, Class type) { return Iterables.transform(input, new TypeCastFunction(type)); diff --git a/fml/src/main/java/cpw/mods/fml/common/registry/FMLControlledNamespacedRegistry.java b/fml/src/main/java/cpw/mods/fml/common/registry/FMLControlledNamespacedRegistry.java index 8d2a1112eb..e94753f474 100644 --- a/fml/src/main/java/cpw/mods/fml/common/registry/FMLControlledNamespacedRegistry.java +++ b/fml/src/main/java/cpw/mods/fml/common/registry/FMLControlledNamespacedRegistry.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.BitSet; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -16,6 +17,7 @@ import net.minecraft.util.RegistryNamespaced; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterators; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.functions.GenericIterableFactory; @@ -311,10 +313,13 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespaced { return containsKey(itemName); } + /* + * This iterator is used by FML to visit the actual block sets, it should use the super.iterator method instead + * Compare #iterator() + */ public Iterable typeSafeIterable() { - Iterable self = this; - return GenericIterableFactory.newCastingIterable(self, superType); + return GenericIterableFactory.newCastingIterable(super.iterator(), superType); } // internal @@ -507,4 +512,15 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespaced { } return persistentSubstitutions; } + + /* + * This iterator is used by some regular MC methods to visit all blocks, we need to include substitutions + * Compare #typeSafeIterable() + */ + @SuppressWarnings("unchecked") + @Override + public Iterator iterator() + { + return Iterators.concat(super.iterator(),getPersistentSubstitutions().values().iterator()); + } }