Avoid copying Forge Registry keys, values, and entries (#4545)

This commit is contained in:
mezz authored and LexManos committed 2018-01-18 12:46:05 -08:00
1 parent 6962678804
commit bc3bbe3d84
6 files changed
+30 -12

No files matched your search

@@ -1,5 +1,6 @@
package net.minecraftforge.registries;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -104,10 +105,8 @@ class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends Regis
@Nullable
public V getRandomObject(Random random)
{
List<V> lst = this.delegate.getValues();
if (lst.isEmpty())
return null;
return lst.get(random.nextInt(lst.size()));
Collection<V> values = this.delegate.getValuesCollection();
return values.stream().skip(random.nextInt(values.size())).findFirst().orElse(null);
}
//internal