mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Avoid copying Forge Registry keys, values, and entries (#4545)
This commit is contained in:
1 parent
6962678804
commit
bc3bbe3d84
6 files changed
+30
-12
No files matched your search
@@ -494,7 +494,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
|
||||
private static void registerAllBiomesAndGenerateEvents()
|
||||
{
|
||||
for (Biome biome : ForgeRegistries.BIOMES.getValues())
|
||||
for (Biome biome : ForgeRegistries.BIOMES.getValuesCollection())
|
||||
{
|
||||
if (biome.decorator instanceof DeferredBiomeDecorator)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
@@ -188,19 +189,30 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
@Override
|
||||
public Set<ResourceLocation> getKeys()
|
||||
{
|
||||
return ImmutableSet.copyOf(this.names.keySet());
|
||||
return Collections.unmodifiableSet(this.names.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getValuesCollection} to avoid copying
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public List<V> getValues()
|
||||
{
|
||||
return ImmutableList.copyOf(this.names.values());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<V> getValuesCollection()
|
||||
{
|
||||
return Collections.unmodifiableSet(this.names.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<ResourceLocation, V>> getEntries()
|
||||
{
|
||||
return ImmutableSet.copyOf(this.names.entrySet());
|
||||
return Collections.unmodifiableSet(this.names.entrySet());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.minecraftforge.registries;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
@@ -48,7 +49,13 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
|
||||
@Nullable ResourceLocation getKey(V value);
|
||||
|
||||
@Nonnull Set<ResourceLocation> getKeys();
|
||||
/** @deprecated use {@link #getValuesCollection} */
|
||||
@Deprecated // TODO: remove in 1.13
|
||||
@Nonnull List<V> getValues();
|
||||
@Nonnull
|
||||
default Collection<V> getValuesCollection() { // TODO rename this to getValues in 1.13
|
||||
return getValues();
|
||||
}
|
||||
@Nonnull Set<Entry<ResourceLocation, V>> getEntries();
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.minecraftforge.registries;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -97,10 +99,8 @@ class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamesp
|
||||
@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
|
||||
|
||||
Reference in new issue
Block a user