From c2f11ecc35f9cc1dfea292c5ce9193e7a39599a4 Mon Sep 17 00:00:00 2001 From: cpw Date: Sun, 22 Mar 2015 12:54:34 -0400 Subject: [PATCH] Change iterator behaviour for the registry - include substitutions in the standard iterator, so that vanilla MC methods visit them (so they can get textures etc). The fml special one only visits the absolute set, used mostly for sanity checking and serialization. Closes #618 --- .../functions/GenericIterableFactory.java | 15 ++++++++++++++ .../FMLControlledNamespacedRegistry.java | 20 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) 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()); + } }