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:
LexManos 2020-08-26 09:49:34 -07:00
parent 600e68cace
commit d8eaeabf3c
10 changed files with 104 additions and 16 deletions

View file

@ -25,7 +25,7 @@
if (p_150788_1_.func_190926_b()) {
this.writeBoolean(false);
} else {
@@ -300,7 +309,7 @@
@@ -300,8 +309,8 @@
this.func_150787_b(Item.func_150891_b(item));
this.writeByte(p_150788_1_.func_190916_E());
CompoundNBT compoundnbt = null;

View file

@ -0,0 +1,22 @@
--- a/net/minecraft/util/registry/WorldGenRegistries.java
+++ b/net/minecraft/util/registry/WorldGenRegistries.java
@@ -45,7 +45,7 @@
return ProcessorLists.field_244102_b;
});
public static final Registry<JigsawPattern> field_243656_h = func_243667_a(Registry.field_243555_ax, JigsawPatternRegistry::func_244093_a);
- public static final Registry<Biome> field_243657_i = func_243667_a(Registry.field_239720_u_, () -> {
+ @Deprecated public static final Registry<Biome> field_243657_i = forge(Registry.field_239720_u_, () -> {
return BiomeRegistry.field_244200_a;
});
public static final Registry<DimensionSettings> field_243658_j = func_243667_a(Registry.field_243549_ar, DimensionSettings::func_242746_i);
@@ -54,6 +54,10 @@
return func_243665_a(p_243667_0_, Lifecycle.stable(), p_243667_1_);
}
+ private static <T extends net.minecraftforge.registries.IForgeRegistryEntry<T>> Registry<T> forge(RegistryKey<? extends Registry<T>> key, Supplier<T> def) {
+ return func_243666_a(key, net.minecraftforge.registries.GameData.getWrapper(key, Lifecycle.stable()), def, Lifecycle.stable());
+ }
+
private static <T> Registry<T> func_243665_a(RegistryKey<? extends Registry<T>> p_243665_0_, Lifecycle p_243665_1_, Supplier<T> p_243665_2_) {
return func_243666_a(p_243665_0_, new SimpleRegistry<>(p_243665_0_, p_243665_1_), p_243665_2_, p_243665_1_);
}

View file

@ -1,5 +1,14 @@
--- a/net/minecraft/world/biome/Biome.java
+++ b/net/minecraft/world/biome/Biome.java
@@ -53,7 +53,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-public final class Biome {
+public final class Biome extends net.minecraftforge.registries.ForgeRegistryEntry<Biome> {
public static final Logger field_150586_aC = LogManager.getLogger();
public static final Codec<Biome> field_242418_b = RecordCodecBuilder.create((p_235064_0_) -> {
return p_235064_0_.group(Biome.Climate.field_242459_a.forGetter((p_242446_0_) -> {
@@ -200,7 +200,7 @@
} else {
if (p_201850_2_.func_177956_o() >= 0 && p_201850_2_.func_177956_o() < 256 && p_201850_1_.func_226658_a_(LightType.BLOCK, p_201850_2_) < 10) {

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/world/biome/BiomeRegistry.java
+++ b/net/minecraft/world/biome/BiomeRegistry.java
@@ -17,7 +17,7 @@
}
public static RegistryKey<Biome> func_244203_a(int p_244203_0_) {
- return field_244202_c.get(p_244203_0_);
+ return ((net.minecraftforge.registries.ForgeRegistry<Biome>)net.minecraftforge.registries.ForgeRegistries.BIOMES).getKey(p_244203_0_);
}
static {

View file

@ -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");

View file

@ -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)

View file

@ -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();

View file

@ -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.

View file

@ -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)

View file

@ -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)