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
This commit is contained in:
cpw committed 2015-03-22 12:56:05 -04:00
1 parent 2451e49df2
commit c2f11ecc35
2 files changed
+33 -2

No files matched your search

@@ -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 <T> Iterable<T> newCastingIterable(final Iterator<?> input, final Class<T> type)
{
return new Iterable<T>()
{
@Override
public Iterator<T> iterator()
{
return Iterators.transform(input, new TypeCastFunction<T>(type));
}
};
}
public static <T> Iterable<T> newCastingIterable(Iterable<?> input, Class<T> type)
{
return Iterables.transform(input, new TypeCastFunction<T>(type));
@@ -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<I> 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<I> typeSafeIterable()
{
Iterable<?> self = this;
return GenericIterableFactory.newCastingIterable(self, superType);
return GenericIterableFactory.newCastingIterable(super.iterator(), superType);
}
// internal
@@ -507,4 +512,15 @@ public class FMLControlledNamespacedRegistry<I> 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<I> iterator()
{
return Iterators.concat(super.iterator(),getPersistentSubstitutions().values().iterator());
}
}