mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Wrap vanilla's 'default' biome registry in ForgeRegistry.
This should allow registering mod dimensions like in 1.16.1, while the data driven system is fleshed out.
This commit is contained in:
1 parent
600e68cace
commit
d8eaeabf3c
10 files changed
+104
-16
No files matched your search
@@ -105,6 +105,9 @@ public class ForgeRegistries
|
||||
public static final IForgeRegistry<FoliagePlacerType<?>> FOLIAGE_PLACER_TYPES = RegistryManager.ACTIVE.getRegistry(FoliagePlacerType.class);
|
||||
public static final IForgeRegistry<TreeDecoratorType<?>> TREE_DECORATOR_TYPES = RegistryManager.ACTIVE.getRegistry(TreeDecoratorType.class);
|
||||
|
||||
// Dynamic/Data driven.
|
||||
public static final IForgeRegistry<Biome> BIOMES = RegistryManager.ACTIVE.getRegistry(Keys.BIOMES);
|
||||
|
||||
// Custom forge registries
|
||||
public static final IForgeRegistry<DataSerializerEntry> DATA_SERIALIZERS = RegistryManager.ACTIVE.getRegistry(DataSerializerEntry.class);
|
||||
public static final IForgeRegistry<GlobalLootModifierSerializer<?>> LOOT_MODIFIER_SERIALIZERS = RegistryManager.ACTIVE.getRegistry(GlobalLootModifierSerializer.class);
|
||||
@@ -143,6 +146,9 @@ public class ForgeRegistries
|
||||
public static final RegistryKey<Registry<FoliagePlacerType<?>>> FOLIAGE_PLACER_TYPES = key("worldgen/foliage_placer_type");
|
||||
public static final RegistryKey<Registry<TreeDecoratorType<?>>> TREE_DECORATOR_TYPES = key("worldgen/tree_decorator_type");
|
||||
|
||||
// Vanilla Dynamic
|
||||
public static final RegistryKey<Registry<Biome>> BIOMES = key("worldgen/biome");
|
||||
|
||||
//Forge
|
||||
public static final RegistryKey<Registry<DataSerializerEntry>> DATA_SERIALIZERS = key("data_serializers");
|
||||
public static final RegistryKey<Registry<GlobalLootModifierSerializer<?>>> LOOT_MODIFIER_SERIALIZERS = key("forge:loot_modifier_serializers");
|
||||
|
||||
@@ -51,7 +51,9 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.StringNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.RegistryEvent.MissingMappings;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -59,14 +61,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import net.minecraftforge.registries.IForgeRegistry.AddCallback;
|
||||
import net.minecraftforge.registries.IForgeRegistry.BakeCallback;
|
||||
import net.minecraftforge.registries.IForgeRegistry.ClearCallback;
|
||||
import net.minecraftforge.registries.IForgeRegistry.CreateCallback;
|
||||
import net.minecraftforge.registries.IForgeRegistry.DummyFactory;
|
||||
import net.minecraftforge.registries.IForgeRegistry.MissingFactory;
|
||||
import net.minecraftforge.registries.IForgeRegistry.ValidateCallback;
|
||||
|
||||
public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V>
|
||||
{
|
||||
public static Marker REGISTRIES = MarkerManager.getMarker("REGISTRIES");
|
||||
@@ -75,6 +69,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
private final RegistryManager stage;
|
||||
private final BiMap<Integer, V> ids = HashBiMap.create();
|
||||
private final BiMap<ResourceLocation, V> names = HashBiMap.create();
|
||||
private final BiMap<RegistryKey<V>, V> keys = HashBiMap.create();
|
||||
private final Class<V> superType;
|
||||
private final Map<ResourceLocation, ResourceLocation> aliases = Maps.newHashMap();
|
||||
final Map<ResourceLocation, ?> slaves = Maps.newHashMap();
|
||||
@@ -101,11 +96,13 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
boolean isFrozen = false;
|
||||
|
||||
private final ResourceLocation name;
|
||||
private final RegistryKey<Registry<V>> key;
|
||||
private final RegistryBuilder<V> builder;
|
||||
|
||||
ForgeRegistry(RegistryManager stage, ResourceLocation name, RegistryBuilder<V> builder)
|
||||
{
|
||||
this.name = name;
|
||||
this.key = RegistryKey.func_240904_a_(name);
|
||||
this.builder = builder;
|
||||
this.stage = stage;
|
||||
this.superType = builder.getType();
|
||||
@@ -167,6 +164,11 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public RegistryKey<Registry<V>> getRegistryKey()
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<V> getRegistrySuperType()
|
||||
{
|
||||
@@ -238,9 +240,9 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<ResourceLocation, V>> getEntries()
|
||||
public Set<Entry<RegistryKey<V>, V>> getEntries()
|
||||
{
|
||||
return Collections.unmodifiableSet(this.names.entrySet());
|
||||
return Collections.unmodifiableSet(this.keys.entrySet());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -285,6 +287,13 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
return ret == null ? this.defaultValue : ret;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public RegistryKey<V> getKey(int id)
|
||||
{
|
||||
V value = getValue(id);
|
||||
return this.keys.inverse().get(value);
|
||||
}
|
||||
|
||||
void validateKey()
|
||||
{
|
||||
if (this.defaultKey != null)
|
||||
@@ -355,6 +364,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
}
|
||||
|
||||
this.names.put(key, value);
|
||||
this.keys.put(RegistryKey.func_240903_a_(this.key, key), value);
|
||||
this.ids.put(idToUse, value);
|
||||
this.availabilityMap.set(idToUse);
|
||||
this.owners.put(new OverrideOwner(owner == null ? key.getPath() : owner, key), value);
|
||||
@@ -418,6 +428,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
LOGGER.trace(REGISTRIES,"Registry {} dummy: {}", this.superType.getSimpleName(), key);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private RegistryDelegate<V> getDelegate(V thing)
|
||||
{
|
||||
if (isDelegated)
|
||||
@@ -526,6 +537,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
|
||||
this.ids.clear();
|
||||
this.names.clear();
|
||||
this.keys.clear();
|
||||
this.availabilityMap.clear(0, this.availabilityMap.length());
|
||||
this.defaultValue = null;
|
||||
this.overrides.clear();
|
||||
@@ -596,6 +608,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
|
||||
this.ids.clear();
|
||||
this.names.clear();
|
||||
this.keys.clear();
|
||||
this.availabilityMap.clear(0, this.availabilityMap.length());
|
||||
}
|
||||
|
||||
@@ -611,6 +624,10 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
V value = this.names.remove(key);
|
||||
if (value != null)
|
||||
{
|
||||
RegistryKey<V> rkey = this.keys.inverse().remove(value);
|
||||
if (rkey == null)
|
||||
throw new IllegalStateException("Removed a entry that did not have an associated RegistryKey: " + key + " " + value.toString() + " This should never happen unless hackery!");
|
||||
|
||||
Integer id = this.ids.inverse().remove(value);
|
||||
if (id == null)
|
||||
throw new IllegalStateException("Removed a entry that did not have an associated id: " + key + " " + value.toString() + " This should never happen unless hackery!");
|
||||
@@ -764,6 +781,9 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
|
||||
if (value == null)
|
||||
throw new IllegalStateException("ContainsKey for " + key + " was true, but removing by name returned no value.. This should never happen unless hackery!");
|
||||
|
||||
RegistryKey<V> rkey = this.keys.inverse().remove(value); // Remove from the RegistryKey -> Value map
|
||||
if (rkey == null)
|
||||
throw new IllegalStateException("Removed a entry that did not have an associated RegistryKey: " + key + " " + value.toString() + " This should never happen unless hackery!");
|
||||
|
||||
Integer oldid = this.ids.inverse().remove(value);
|
||||
if (oldid == null)
|
||||
|
||||
@@ -56,6 +56,7 @@ import net.minecraft.util.registry.DefaultedRegistry;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
import net.minecraft.village.PointOfInterestType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.world.gen.DebugChunkGenerator;
|
||||
import net.minecraft.world.gen.blockplacer.BlockPlacerType;
|
||||
@@ -171,6 +172,9 @@ public class GameData
|
||||
makeRegistry(FOLIAGE_PLACER_TYPES, c(FoliagePlacerType.class)).disableSaving().disableSync().create();
|
||||
makeRegistry(TREE_DECORATOR_TYPES, c(TreeDecoratorType.class)).disableSaving().disableSync().create();
|
||||
|
||||
// Dynamic Worldgen
|
||||
makeRegistry(BIOMES, Biome.class).create();
|
||||
|
||||
// Custom forge registries
|
||||
makeRegistry(DATA_SERIALIZERS, DataSerializerEntry.class, 256 /*vanilla space*/, MAX_VARINT).disableSaving().disableOverrides().addCallback(SerializerCallbacks.INSTANCE).create();
|
||||
makeRegistry(LOOT_MODIFIER_SERIALIZERS, c(GlobalLootModifierSerializer.class)).disableSaving().disableSync().create();
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
@@ -48,9 +50,9 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
|
||||
@Nullable ResourceLocation getKey(V value);
|
||||
@Nullable ResourceLocation getDefaultKey();
|
||||
|
||||
@Nonnull Set<ResourceLocation> getKeys();
|
||||
@Nonnull Collection<V> getValues();
|
||||
@Nonnull Set<Entry<ResourceLocation, V>> getEntries();
|
||||
@Nonnull Set<ResourceLocation> getKeys();
|
||||
@Nonnull Collection<V> getValues();
|
||||
@Nonnull Set<Entry<RegistryKey<V>, V>> getEntries();
|
||||
|
||||
/**
|
||||
* Retrieve the slave map of type T from the registry.
|
||||
|
||||
@@ -21,6 +21,7 @@ package net.minecraftforge.registries;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Random;
|
||||
@@ -46,7 +47,7 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
|
||||
|
||||
private NamespacedDefaultedWrapper(ForgeRegistry<T> owner)
|
||||
{
|
||||
super("empty", RegistryKey.<T>func_240904_a_(owner.getRegistryName()), Lifecycle.experimental());
|
||||
super("empty", owner.getRegistryKey(), Lifecycle.experimental());
|
||||
this.delegate = owner;
|
||||
}
|
||||
|
||||
@@ -133,6 +134,12 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
|
||||
return this.delegate.getKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<RegistryKey<T>, T>> func_239659_c_()
|
||||
{
|
||||
return this.delegate.getEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T getRandom(Random random)
|
||||
|
||||
@@ -21,6 +21,7 @@ package net.minecraftforge.registries;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Random;
|
||||
@@ -44,7 +45,7 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends SimpleRegistry
|
||||
|
||||
public NamespacedWrapper(ForgeRegistry<T> owner)
|
||||
{
|
||||
super(RegistryKey.func_240904_a_(owner.getRegistryName()), Lifecycle.experimental());
|
||||
super(owner.getRegistryKey(), Lifecycle.experimental());
|
||||
this.delegate = owner;
|
||||
}
|
||||
|
||||
@@ -131,6 +132,12 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends SimpleRegistry
|
||||
return this.delegate.getKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<RegistryKey<T>, T>> func_239659_c_()
|
||||
{
|
||||
return this.delegate.getEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T getRandom(Random random)
|
||||
|
||||
Reference in new issue
Block a user