Revive custom ingredient types.

This commit is contained in:
LexManos committed 2023-10-06 21:14:04 -07:00
1 parent 587b684035
commit 5b0abf97c8
47 files changed
+1891 -1353

No files matched your search

@@ -15,6 +15,7 @@ import net.minecraft.tags.TagKey;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.registries.tags.ITagManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -24,7 +25,6 @@ import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;
@@ -50,8 +50,7 @@ import java.util.function.Supplier;
*
* @param <T> The base registry type
*/
public class DeferredRegister<T>
{
public class DeferredRegister<T> {
/**
* DeferredRegister factory for forge registries that exist <i>before</i> this DeferredRegister is created.
* <p>
@@ -63,11 +62,24 @@ public class DeferredRegister<T>
* @see #create(ResourceKey, String)
* @see #create(ResourceLocation, String)
*/
public static <B> DeferredRegister<B> create(IForgeRegistry<B> reg, String modid)
{
public static <B> DeferredRegister<B> create(IForgeRegistry<B> reg, String modid) {
return new DeferredRegister<>(reg, modid);
}
/**
* DeferredRegister factory for forge registries that exist <i>after</i> this DeferredRegister is created.
*
* @param reg the forge registry to wrap
* @param modid the namespace for all objects registered to this DeferredRegister
* @see #create(ResourceKey, String)
* @see #create(ResourceLocation, String)
*/
public static <B> DeferredRegister<B> create(@Deprecated(forRemoval = true/* change to RegistryHolder */, since = "1.20.2") Supplier<IForgeRegistry<B>> reg, String modid) {
if (reg instanceof RegistryHolder<B> holder)
return create(holder.registryKey, modid);
throw new IllegalArgumentException("Registry argument was not made by DefferredRegister.makeRegistry. Use another create method. This method will be changed to use the hard type in1 1.20.3, but I don't wanna break everything in 1.20.2 so we have this error");
}
/**
* DeferredRegister factory for custom forge registries or {@link BuiltInRegistries vanilla registries}
* to lookup based on the provided registry key. Supports both registries that already exist or do not exist yet.
@@ -81,8 +93,7 @@ public class DeferredRegister<T>
* @see #create(IForgeRegistry, String)
* @see #create(ResourceLocation, String)
*/
public static <B> DeferredRegister<B> create(ResourceKey<? extends Registry<B>> key, String modid)
{
public static <B> DeferredRegister<B> create(ResourceKey<? extends Registry<B>> key, String modid) {
return new DeferredRegister<>(key, modid, false);
}
@@ -99,8 +110,7 @@ public class DeferredRegister<T>
* @see #create(IForgeRegistry, String)
* @see #create(ResourceLocation, String)
*/
public static <B> DeferredRegister<B> createOptional(ResourceKey<? extends Registry<B>> key, String modid)
{
public static <B> DeferredRegister<B> createOptional(ResourceKey<? extends Registry<B>> key, String modid) {
return new DeferredRegister<>(key, modid, true);
}
@@ -117,8 +127,7 @@ public class DeferredRegister<T>
* @see #create(IForgeRegistry, String)
* @see #create(ResourceKey, String)
*/
public static <B> DeferredRegister<B> create(ResourceLocation registryName, String modid)
{
public static <B> DeferredRegister<B> create(ResourceLocation registryName, String modid) {
return new DeferredRegister<>(ResourceKey.createRegistryKey(registryName), modid, false);
}
@@ -135,8 +144,7 @@ public class DeferredRegister<T>
* @see #create(IForgeRegistry, String)
* @see #create(ResourceKey, String)
*/
public static <B> DeferredRegister<B> createOptional(ResourceLocation registryName, String modid)
{
public static <B> DeferredRegister<B> createOptional(ResourceLocation registryName, String modid) {
return new DeferredRegister<>(ResourceKey.createRegistryKey(registryName), modid, true);
}
@@ -152,15 +160,13 @@ public class DeferredRegister<T>
private SetMultimap<TagKey<T>, Supplier<T>> optionalTags;
private boolean seenRegisterEvent = false;
private DeferredRegister(ResourceKey<? extends Registry<T>> registryKey, String modid, boolean optionalRegistry)
{
private DeferredRegister(ResourceKey<? extends Registry<T>> registryKey, String modid, boolean optionalRegistry) {
this.registryKey = registryKey;
this.modid = modid;
this.optionalRegistry = optionalRegistry;
}
private DeferredRegister(IForgeRegistry<T> reg, String modid)
{
private DeferredRegister(IForgeRegistry<T> reg, String modid) {
this(reg.getRegistryKey(), modid, false);
}
@@ -171,26 +177,26 @@ public class DeferredRegister<T>
* @param sup A factory for the new entry, it should return a new instance every time it is called.
* @return A RegistryObject that will be updated with when the entries in the registry change.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public <I extends T> RegistryObject<I> register(final String name, final Supplier<? extends I> sup)
{
@SuppressWarnings("unchecked")
public <I extends T> RegistryObject<I> register(final String name, final Supplier<? extends I> sup) {
if (seenRegisterEvent)
throw new IllegalStateException("Cannot register new entries to DeferredRegister after RegisterEvent has been fired.");
Objects.requireNonNull(name);
Objects.requireNonNull(sup);
final ResourceLocation key = new ResourceLocation(modid, name);
RegistryObject<I> ret;
if (this.registryKey != null)
ret = this.optionalRegistry
? RegistryObject.createOptional(key, this.registryKey, this.modid)
: RegistryObject.create(key, this.registryKey, this.modid);
else
if (this.registryKey != null) {
if (this.optionalRegistry)
ret = RegistryObject.createOptional(key, this.registryKey, this.modid);
else
ret = RegistryObject.create(key, this.registryKey, this.modid);
} else
throw new IllegalStateException("Could not create RegistryObject in DeferredRegister");
if (entries.putIfAbsent((RegistryObject<T>) ret, sup) != null) {
if (entries.putIfAbsent((RegistryObject<T>) ret, sup) != null)
throw new IllegalArgumentException("Duplicate registration " + name);
}
return ret;
}
@@ -204,8 +210,7 @@ public class DeferredRegister<T>
* @return A supplier of the {@link IForgeRegistry} created by the builder.
* Will always return null until after the {@link NewRegistryEvent} event fires.
*/
public Supplier<IForgeRegistry<T>> makeRegistry(final Supplier<RegistryBuilder<T>> sup)
{
public Supplier<IForgeRegistry<T>> makeRegistry(final Supplier<RegistryBuilder<T>> sup) {
return makeRegistry(this.registryKey.location(), sup);
}
@@ -219,8 +224,7 @@ public class DeferredRegister<T>
* @see #createOptionalTagKey(String, Set)
*/
@NotNull
public TagKey<T> createTagKey(@NotNull String path)
{
public TagKey<T> createTagKey(@NotNull String path) {
Objects.requireNonNull(path);
return createTagKey(new ResourceLocation(this.modid, path));
}
@@ -235,8 +239,7 @@ public class DeferredRegister<T>
* @see #createOptionalTagKey(ResourceLocation, Set)
*/
@NotNull
public TagKey<T> createTagKey(@NotNull ResourceLocation location)
{
public TagKey<T> createTagKey(@NotNull ResourceLocation location) {
if (this.registryKey == null)
throw new IllegalStateException("The registry name was not set, cannot create a tag key");
Objects.requireNonNull(location);
@@ -256,8 +259,7 @@ public class DeferredRegister<T>
* @see #addOptionalTagDefaults(TagKey, Set)
*/
@NotNull
public TagKey<T> createOptionalTagKey(@NotNull String path, @NotNull Set<? extends Supplier<T>> defaults)
{
public TagKey<T> createOptionalTagKey(@NotNull String path, @NotNull Set<? extends Supplier<T>> defaults) {
Objects.requireNonNull(path);
return createOptionalTagKey(new ResourceLocation(this.modid, path), defaults);
}
@@ -275,8 +277,7 @@ public class DeferredRegister<T>
* @see #addOptionalTagDefaults(TagKey, Set)
*/
@NotNull
public TagKey<T> createOptionalTagKey(@NotNull ResourceLocation location, @NotNull Set<? extends Supplier<T>> defaults)
{
public TagKey<T> createOptionalTagKey(@NotNull ResourceLocation location, @NotNull Set<? extends Supplier<T>> defaults) {
TagKey<T> tagKey = createTagKey(location);
addOptionalTagDefaults(tagKey, defaults);
@@ -294,8 +295,7 @@ public class DeferredRegister<T>
* @see #createOptionalTagKey(String, Set)
* @see #createOptionalTagKey(ResourceLocation, Set)
*/
public void addOptionalTagDefaults(@NotNull TagKey<T> name, @NotNull Set<? extends Supplier<T>> defaults)
{
public void addOptionalTagDefaults(@NotNull TagKey<T> name, @NotNull Set<? extends Supplier<T>> defaults) {
Objects.requireNonNull(defaults);
if (optionalTags == null)
optionalTags = Multimaps.newSetMultimap(new IdentityHashMap<>(), HashSet::new);
@@ -309,38 +309,21 @@ public class DeferredRegister<T>
*
* @param bus The Mod Specific event bus.
*/
public void register(IEventBus bus)
{
bus.register(new EventDispatcher(this));
if (this.registryFactory != null) {
bus.addListener(this::createRegistry);
}
public void register(IEventBus bus) {
bus.register(new EventDispatcher());
}
public static class EventDispatcher {
private final DeferredRegister<?> register;
public EventDispatcher(final DeferredRegister<?> register) {
this.register = register;
}
@SubscribeEvent
public void handleEvent(RegisterEvent event) {
register.addEntries(event);
}
}
/**
* @return The unmodifiable view of registered entries. Useful for bulk operations on all values.
*/
public Collection<RegistryObject<T>> getEntries()
{
public Collection<RegistryObject<T>> getEntries() {
return entriesView;
}
/**
* @return The registry key stored in this deferred register. Useful for creating new deferred registers based on an existing one.
*/
public ResourceKey<? extends Registry<T>> getRegistryKey()
{
public ResourceKey<? extends Registry<T>> getRegistryKey() {
return this.registryKey;
}
@@ -348,8 +331,7 @@ public class DeferredRegister<T>
* @return The registry name stored in this deferred register. Useful for creating new deferred registers based on an existing one.
*/
@NotNull
public ResourceLocation getRegistryName()
{
public ResourceLocation getRegistryName() {
return Objects.requireNonNull(this.registryKey).location();
}
@@ -364,8 +346,7 @@ public class DeferredRegister<T>
}
@SuppressWarnings("unchecked")
private void onFill(IForgeRegistry<?> registry)
{
private void onFill(IForgeRegistry<?> registry) {
if (this.optionalTags == null)
return;
@@ -376,37 +357,40 @@ public class DeferredRegister<T>
Multimaps.asMap(this.optionalTags).forEach(tagManager::addOptionalTagDefaults);
}
private void addEntries(RegisterEvent event)
{
if (event.getRegistryKey().equals(this.registryKey))
{
this.seenRegisterEvent = true;
for (Entry<RegistryObject<T>, Supplier<? extends T>> e : entries.entrySet())
{
event.register(this.registryKey, e.getKey().getId(), () -> e.getValue().get());
e.getKey().updateReference(event);
private class EventDispatcher {
@SubscribeEvent
public void handleEvent(RegisterEvent event) {
if (event.getRegistryKey().equals(registryKey)) {
seenRegisterEvent = true;
for (var e : entries.entrySet()) {
event.register(registryKey, e.getKey().getId(), () -> e.getValue().get());
e.getKey().updateReference(event);
}
}
}
@SubscribeEvent
public void createRegistry(NewRegistryEvent event) {
if (registryFactory != null)
event.create(registryFactory.get(), DeferredRegister.this::onFill);
}
}
private void createRegistry(NewRegistryEvent event)
{
event.create(this.registryFactory.get(), this::onFill);
}
private static class RegistryHolder<V> implements Supplier<IForgeRegistry<V>>
{
/*
* Make this public API and make `makeRegistry` return this. Thus allowing us to make a new create method that takes this in for a simpler API
* for custom Forge registries. But it requires breaking the core api of makeRegistry and the fields we store forge's custom registries in.
*/
@Deprecated(forRemoval = true, since = "1.20.2")
private static class RegistryHolder<V> implements Supplier<IForgeRegistry<V>> {
private final ResourceKey<? extends Registry<V>> registryKey;
private IForgeRegistry<V> registry = null;
private RegistryHolder(ResourceKey<? extends Registry<V>> registryKey)
{
private RegistryHolder(ResourceKey<? extends Registry<V>> registryKey) {
this.registryKey = registryKey;
}
@Override
public IForgeRegistry<V> get()
{
public IForgeRegistry<V> get() {
// Keep looking up the registry until it's not null
if (this.registry == null)
this.registry = RegistryManager.ACTIVE.getRegistry(this.registryKey);
@@ -5,32 +5,26 @@
package net.minecraftforge.registries;
import org.jetbrains.annotations.ApiStatus;
import net.minecraftforge.eventbus.api.IEventBus;
public class ForgeDeferredRegistriesSetup
{
@ApiStatus.Internal
public class ForgeDeferredRegistriesSetup {
private static boolean setup = false;
/**
* Internal forge method. Modders do not call.
*/
public static void setup(IEventBus modEventBus)
{
synchronized (ForgeDeferredRegistriesSetup.class)
{
public static void setup(IEventBus modEventBus) {
synchronized (ForgeDeferredRegistriesSetup.class) {
if (setup)
throw new IllegalStateException("Setup has already been called!");
setup = true;
}
ForgeRegistries.DEFERRED_ENTITY_DATA_SERIALIZERS.register(modEventBus);
ForgeRegistries.DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS.register(modEventBus);
ForgeRegistries.DEFERRED_BIOME_MODIFIER_SERIALIZERS.register(modEventBus);
ForgeRegistries.DEFERRED_FLUID_TYPES.register(modEventBus);
ForgeRegistries.DEFERRED_STRUCTURE_MODIFIER_SERIALIZERS.register(modEventBus);
ForgeRegistries.DEFERRED_HOLDER_SET_TYPES.register(modEventBus);
ForgeRegistries.DEFERRED_DISPLAY_CONTEXTS.register(modEventBus);
ForgeRegistries.DEFERRED_CONDITION_CODECS.register(modEventBus);
for (var reg : ForgeRegistries.registries)
reg.register(modEventBus);
}
}
@@ -44,112 +44,82 @@ import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerTy
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.common.crafting.ingredients.IIngredientSerializer;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.common.world.BiomeModifier;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.registries.holdersets.HolderSetType;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import net.minecraftforge.common.world.StructureModifier;
/**
* A class that exposes static references to all vanilla and Forge registries.
* Created to have a central place to access the registries directly if modders need.
* It is still advised that if you are registering things to use {@link RegisterEvent} or {@link net.minecraftforge.registries.DeferredRegister}, but queries and iterations can use this.
* It is still advised that if you are registering things to use {@link RegisterEvent} or {@link DeferredRegister}, but queries and iterations can use this.
*/
public class ForgeRegistries
{
public class ForgeRegistries {
static { init(); } // This must be above the fields so we guarantee it's run before getRegistry is called. Yay static initializers
private static <T> IForgeRegistry<T> active(ResourceKey<Registry<T>> key) {
return RegistryManager.ACTIVE.getRegistry(key);
}
static final List<DeferredRegister<?>> registries = new ArrayList<>();
private static final <T> Supplier<IForgeRegistry<T>> registry(ResourceKey<Registry<T>> key, Supplier<RegistryBuilder<T>> factory) {
var dr = DeferredRegister.create(key, key.location().getNamespace());
registries.add(dr);
return dr.makeRegistry(factory);
}
// Game objects
public static final IForgeRegistry<Block> BLOCKS = RegistryManager.ACTIVE.getRegistry(Keys.BLOCKS);
public static final IForgeRegistry<Fluid> FLUIDS = RegistryManager.ACTIVE.getRegistry(Keys.FLUIDS);
public static final IForgeRegistry<Item> ITEMS = RegistryManager.ACTIVE.getRegistry(Keys.ITEMS);
public static final IForgeRegistry<MobEffect> MOB_EFFECTS = RegistryManager.ACTIVE.getRegistry(Keys.MOB_EFFECTS);
public static final IForgeRegistry<SoundEvent> SOUND_EVENTS = RegistryManager.ACTIVE.getRegistry(Keys.SOUND_EVENTS);
public static final IForgeRegistry<Potion> POTIONS = RegistryManager.ACTIVE.getRegistry(Keys.POTIONS);
public static final IForgeRegistry<Enchantment> ENCHANTMENTS = RegistryManager.ACTIVE.getRegistry(Keys.ENCHANTMENTS);
public static final IForgeRegistry<EntityType<?>> ENTITY_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.ENTITY_TYPES);
public static final IForgeRegistry<BlockEntityType<?>> BLOCK_ENTITY_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.BLOCK_ENTITY_TYPES);
public static final IForgeRegistry<ParticleType<?>> PARTICLE_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.PARTICLE_TYPES);
public static final IForgeRegistry<MenuType<?>> MENU_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.MENU_TYPES);
public static final IForgeRegistry<PaintingVariant> PAINTING_VARIANTS = RegistryManager.ACTIVE.getRegistry(Keys.PAINTING_VARIANTS);
public static final IForgeRegistry<RecipeType<?>> RECIPE_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.RECIPE_TYPES);
public static final IForgeRegistry<RecipeSerializer<?>> RECIPE_SERIALIZERS = RegistryManager.ACTIVE.getRegistry(Keys.RECIPE_SERIALIZERS);
public static final IForgeRegistry<Attribute> ATTRIBUTES = RegistryManager.ACTIVE.getRegistry(Keys.ATTRIBUTES);
public static final IForgeRegistry<StatType<?>> STAT_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.STAT_TYPES);
public static final IForgeRegistry<ArgumentTypeInfo<?, ?>> COMMAND_ARGUMENT_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.COMMAND_ARGUMENT_TYPES);
public static final IForgeRegistry<Block> BLOCKS = active(Keys.BLOCKS);
public static final IForgeRegistry<Fluid> FLUIDS = active(Keys.FLUIDS);
public static final IForgeRegistry<Item> ITEMS = active(Keys.ITEMS);
public static final IForgeRegistry<MobEffect> MOB_EFFECTS = active(Keys.MOB_EFFECTS);
public static final IForgeRegistry<SoundEvent> SOUND_EVENTS = active(Keys.SOUND_EVENTS);
public static final IForgeRegistry<Potion> POTIONS = active(Keys.POTIONS);
public static final IForgeRegistry<Enchantment> ENCHANTMENTS = active(Keys.ENCHANTMENTS);
public static final IForgeRegistry<EntityType<?>> ENTITY_TYPES = active(Keys.ENTITY_TYPES);
public static final IForgeRegistry<BlockEntityType<?>> BLOCK_ENTITY_TYPES = active(Keys.BLOCK_ENTITY_TYPES);
public static final IForgeRegistry<ParticleType<?>> PARTICLE_TYPES = active(Keys.PARTICLE_TYPES);
public static final IForgeRegistry<MenuType<?>> MENU_TYPES = active(Keys.MENU_TYPES);
public static final IForgeRegistry<PaintingVariant> PAINTING_VARIANTS = active(Keys.PAINTING_VARIANTS);
public static final IForgeRegistry<RecipeType<?>> RECIPE_TYPES = active(Keys.RECIPE_TYPES);
public static final IForgeRegistry<RecipeSerializer<?>> RECIPE_SERIALIZERS = active(Keys.RECIPE_SERIALIZERS);
public static final IForgeRegistry<Attribute> ATTRIBUTES = active(Keys.ATTRIBUTES);
public static final IForgeRegistry<StatType<?>> STAT_TYPES = active(Keys.STAT_TYPES);
public static final IForgeRegistry<ArgumentTypeInfo<?, ?>> COMMAND_ARGUMENT_TYPES = active(Keys.COMMAND_ARGUMENT_TYPES);
// Villages
public static final IForgeRegistry<VillagerProfession> VILLAGER_PROFESSIONS = RegistryManager.ACTIVE.getRegistry(Keys.VILLAGER_PROFESSIONS);
public static final IForgeRegistry<PoiType> POI_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.POI_TYPES);
public static final IForgeRegistry<MemoryModuleType<?>> MEMORY_MODULE_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.MEMORY_MODULE_TYPES);
public static final IForgeRegistry<SensorType<?>> SENSOR_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.SENSOR_TYPES);
public static final IForgeRegistry<Schedule> SCHEDULES = RegistryManager.ACTIVE.getRegistry(Keys.SCHEDULES);
public static final IForgeRegistry<Activity> ACTIVITIES = RegistryManager.ACTIVE.getRegistry(Keys.ACTIVITIES);
public static final IForgeRegistry<VillagerProfession> VILLAGER_PROFESSIONS = active(Keys.VILLAGER_PROFESSIONS);
public static final IForgeRegistry<PoiType> POI_TYPES = active(Keys.POI_TYPES);
public static final IForgeRegistry<MemoryModuleType<?>> MEMORY_MODULE_TYPES = active(Keys.MEMORY_MODULE_TYPES);
public static final IForgeRegistry<SensorType<?>> SENSOR_TYPES = active(Keys.SENSOR_TYPES);
public static final IForgeRegistry<Schedule> SCHEDULES = active(Keys.SCHEDULES);
public static final IForgeRegistry<Activity> ACTIVITIES = active(Keys.ACTIVITIES);
// Worldgen
public static final IForgeRegistry<WorldCarver<?>> WORLD_CARVERS = RegistryManager.ACTIVE.getRegistry(Keys.WORLD_CARVERS);
public static final IForgeRegistry<Feature<?>> FEATURES = RegistryManager.ACTIVE.getRegistry(Keys.FEATURES);
public static final IForgeRegistry<ChunkStatus> CHUNK_STATUS = RegistryManager.ACTIVE.getRegistry(Keys.CHUNK_STATUS);
public static final IForgeRegistry<BlockStateProviderType<?>> BLOCK_STATE_PROVIDER_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.BLOCK_STATE_PROVIDER_TYPES);
public static final IForgeRegistry<FoliagePlacerType<?>> FOLIAGE_PLACER_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.FOLIAGE_PLACER_TYPES);
public static final IForgeRegistry<TreeDecoratorType<?>> TREE_DECORATOR_TYPES = RegistryManager.ACTIVE.getRegistry(Keys.TREE_DECORATOR_TYPES);
public static final IForgeRegistry<WorldCarver<?>> WORLD_CARVERS = active(Keys.WORLD_CARVERS);
public static final IForgeRegistry<Feature<?>> FEATURES = active(Keys.FEATURES);
public static final IForgeRegistry<ChunkStatus> CHUNK_STATUS = active(Keys.CHUNK_STATUS);
public static final IForgeRegistry<BlockStateProviderType<?>> BLOCK_STATE_PROVIDER_TYPES = active(Keys.BLOCK_STATE_PROVIDER_TYPES);
public static final IForgeRegistry<FoliagePlacerType<?>> FOLIAGE_PLACER_TYPES = active(Keys.FOLIAGE_PLACER_TYPES);
public static final IForgeRegistry<TreeDecoratorType<?>> TREE_DECORATOR_TYPES = active(Keys.TREE_DECORATOR_TYPES);
// Dynamic/Data driven.
public static final IForgeRegistry<Biome> BIOMES = RegistryManager.ACTIVE.getRegistry(Keys.BIOMES);
public static final IForgeRegistry<Biome> BIOMES = active(Keys.BIOMES);
// Custom forge registries
static final DeferredRegister<EntityDataSerializer<?>> DEFERRED_ENTITY_DATA_SERIALIZERS = DeferredRegister.create(Keys.ENTITY_DATA_SERIALIZERS, Keys.ENTITY_DATA_SERIALIZERS.location().getNamespace());
/**
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
* Use {@link Keys#ENTITY_DATA_SERIALIZERS} to create a {@link DeferredRegister}.
*/
public static final Supplier<IForgeRegistry<EntityDataSerializer<?>>> ENTITY_DATA_SERIALIZERS = DEFERRED_ENTITY_DATA_SERIALIZERS.makeRegistry(GameData::getDataSerializersRegistryBuilder);
static final DeferredRegister<Codec<? extends IGlobalLootModifier>> DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS = DeferredRegister.create(Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS.location().getNamespace());
/**
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
* Use {@link Keys#GLOBAL_LOOT_MODIFIER_SERIALIZERS} to create a {@link DeferredRegister}.
*/
public static final Supplier<IForgeRegistry<Codec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS.makeRegistry(GameData::getGLMSerializersRegistryBuilder);
static final DeferredRegister<Codec<? extends BiomeModifier>> DEFERRED_BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(Keys.BIOME_MODIFIER_SERIALIZERS, Keys.BIOME_MODIFIER_SERIALIZERS.location().getNamespace());
/**
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
* Use {@link Keys#BIOME_MODIFIER_SERIALIZERS} to create a {@link DeferredRegister}.
*/
public static final Supplier<IForgeRegistry<Codec<? extends BiomeModifier>>> BIOME_MODIFIER_SERIALIZERS = DEFERRED_BIOME_MODIFIER_SERIALIZERS.makeRegistry(GameData::getBiomeModifierSerializersRegistryBuilder);
static final DeferredRegister<Codec<? extends StructureModifier>> DEFERRED_STRUCTURE_MODIFIER_SERIALIZERS = DeferredRegister.create(Keys.STRUCTURE_MODIFIER_SERIALIZERS, Keys.STRUCTURE_MODIFIER_SERIALIZERS.location().getNamespace());
/**
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
* Use {@link Keys#STRUCTURE_MODIFIER_SERIALIZERS} to create a {@link DeferredRegister}.
*/
public static final Supplier<IForgeRegistry<Codec<? extends StructureModifier>>> STRUCTURE_MODIFIER_SERIALIZERS = DEFERRED_STRUCTURE_MODIFIER_SERIALIZERS.makeRegistry(GameData::getStructureModifierSerializersRegistryBuilder);
static final DeferredRegister<FluidType> DEFERRED_FLUID_TYPES = DeferredRegister.create(Keys.FLUID_TYPES, Keys.FLUID_TYPES.location().getNamespace());
/**
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
* Use {@link Keys#FLUID_TYPES} to create a {@link DeferredRegister}.
*/
public static final Supplier<IForgeRegistry<FluidType>> FLUID_TYPES = DEFERRED_FLUID_TYPES.makeRegistry(GameData::getFluidTypeRegistryBuilder);
static final DeferredRegister<HolderSetType> DEFERRED_HOLDER_SET_TYPES = DeferredRegister.create(Keys.HOLDER_SET_TYPES, "forge");
/**
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
* Use {@link Keys#HOLDER_SET_TYPES} to create a {@link DeferredRegister}.
*/
public static final Supplier<IForgeRegistry<HolderSetType>> HOLDER_SET_TYPES = DEFERRED_HOLDER_SET_TYPES.makeRegistry(GameData::getHolderSetTypeRegistryBuilder);
static final DeferredRegister<ItemDisplayContext> DEFERRED_DISPLAY_CONTEXTS = DeferredRegister.create(Keys.DISPLAY_CONTEXTS, "forge");
/**
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
* Use {@link Keys#DISPLAY_CONTEXTS} to create a {@link DeferredRegister}.
*/
public static final Supplier<IForgeRegistry<ItemDisplayContext>> DISPLAY_CONTEXTS = DEFERRED_DISPLAY_CONTEXTS.makeRegistry(GameData::getItemDisplayContextRegistryBuilder);
static final DeferredRegister<Codec<? extends ICondition>> DEFERRED_CONDITION_CODECS = DeferredRegister.create(Keys.CONDITION_SERIALIZERS, Keys.CONDITION_SERIALIZERS.location().getNamespace());
/**
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
* Use {@link Keys#CONDITION_SERIALIZERS} to create a {@link DeferredRegister}.
*/
public static final Supplier<IForgeRegistry<Codec<? extends ICondition>>> CONDITION_SERIALIZERS = DEFERRED_CONDITION_CODECS.makeRegistry(GameData::getConditionCodecRegistryBuilder);
public static final Supplier<IForgeRegistry<EntityDataSerializer<?>>> ENTITY_DATA_SERIALIZERS = registry(Keys.ENTITY_DATA_SERIALIZERS, GameData::getDataSerializersRegistryBuilder);
public static final Supplier<IForgeRegistry<Codec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = registry(Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, GameData::getGLMSerializersRegistryBuilder);
public static final Supplier<IForgeRegistry<Codec<? extends BiomeModifier>>> BIOME_MODIFIER_SERIALIZERS = registry(Keys.BIOME_MODIFIER_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
public static final Supplier<IForgeRegistry<Codec<? extends StructureModifier>>> STRUCTURE_MODIFIER_SERIALIZERS = registry(Keys.STRUCTURE_MODIFIER_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
public static final Supplier<IForgeRegistry<FluidType>> FLUID_TYPES = registry(Keys.FLUID_TYPES, GameData::getFluidTypeRegistryBuilder);
public static final Supplier<IForgeRegistry<HolderSetType>> HOLDER_SET_TYPES = registry(Keys.HOLDER_SET_TYPES, GameData::makeUnsavedAndUnsynced);
public static final Supplier<IForgeRegistry<ItemDisplayContext>> DISPLAY_CONTEXTS = registry(Keys.DISPLAY_CONTEXTS, GameData::getItemDisplayContextRegistryBuilder);
public static final Supplier<IForgeRegistry<Codec<? extends ICondition>>> CONDITION_SERIALIZERS = registry(Keys.CONDITION_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
public static final Supplier<IForgeRegistry<IIngredientSerializer<?>>> INGREDIENT_SERIALIZERS = registry(Keys.INGREDIENT_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
public static final class Keys {
//Vanilla
@@ -195,23 +165,23 @@ public class ForgeRegistries
public static final ResourceKey<Registry<HolderSetType>> HOLDER_SET_TYPES = key("forge:holder_set_type");
public static final ResourceKey<Registry<ItemDisplayContext>> DISPLAY_CONTEXTS = key("forge:display_contexts");
public static final ResourceKey<Registry<Codec<? extends ICondition>>> CONDITION_SERIALIZERS = key("forge:condition_codecs");
public static final ResourceKey<Registry<IIngredientSerializer<?>>> INGREDIENT_SERIALIZERS = key("forge:ingredient_serializers");
// Forge Dynamic
public static final ResourceKey<Registry<BiomeModifier>> BIOME_MODIFIERS = key("forge:biome_modifier");
public static final ResourceKey<Registry<StructureModifier>> STRUCTURE_MODIFIERS = key("forge:structure_modifier");
private static <T> ResourceKey<Registry<T>> key(String name)
{
private static <T> ResourceKey<Registry<T>> key(String name) {
return ResourceKey.createRegistryKey(new ResourceLocation(name));
}
private static void init() {}
}
/**
* This function is just to make sure static initializers in other classes have run and setup their registries before we query them.
*/
private static void init()
{
private static void init() {
Keys.init();
GameData.init();
Bootstrap.bootStrap();
@@ -5,9 +5,22 @@
package net.minecraftforge.registries;
import java.util.*;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.IntFunction;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
@@ -16,7 +29,6 @@ import com.mojang.serialization.DynamicOps;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraftforge.common.util.LogMessageAdapter;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.registries.tags.ITagManager;
@@ -26,15 +38,11 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import io.netty.buffer.Unpooled;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
@@ -47,11 +55,9 @@ import org.apache.logging.log4j.MarkerManager;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;
@ApiStatus.Internal
public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V>
{
public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V> {
public static Marker REGISTRIES = MarkerManager.getMarker("REGISTRIES");
private static final Marker REGISTRYDUMP = MarkerManager.getMarker("REGISTRYDUMP");
private static final Logger LOGGER = LogManager.getLogger();
@@ -59,10 +65,10 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
private final BiMap<Integer, V> ids = HashBiMap.create();
private final BiMap<ResourceLocation, V> names = HashBiMap.create();
private final BiMap<ResourceKey<V>, V> keys = HashBiMap.create();
private final Map<ResourceLocation, ResourceLocation> aliases = Maps.newHashMap();
final Map<ResourceLocation, ?> slaves = Maps.newHashMap();
private final Map<ResourceLocation, ResourceLocation> aliases = new HashMap<>();
final Map<ResourceLocation, ?> slaves = new HashMap<>();
private final ResourceLocation defaultKey;
private final ResourceKey<V> defaultResourceKey;
//private final ResourceKey<V> defaultResourceKey;
private final CreateCallback<V> create;
private final AddCallback<V> add;
private final ClearCallback<V> clear;
@@ -70,10 +76,10 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
private final BakeCallback<V> bake;
private final MissingFactory<V> missing;
private final BitSet availabilityMap;
private final Set<Integer> blocked = Sets.newHashSet();
private final Set<Integer> blocked = new HashSet<>();
private final Multimap<ResourceLocation, V> overrides = ArrayListMultimap.create();
private final Map<ResourceLocation, Holder.Reference<V>> delegatesByName = Maps.newHashMap();
private final Map<V, Holder.Reference<V>> delegatesByValue = Maps.newHashMap();
private final Map<ResourceLocation, Holder.Reference<V>> delegatesByName = new HashMap<>();
private final Map<V, Holder.Reference<V>> delegatesByValue = new HashMap<>();
private final BiMap<OverrideOwner<V>, V> owners = HashBiMap.create();
private final ForgeRegistryTagManager<V> tagManager;
private final int min;
@@ -91,15 +97,13 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
private final Codec<V> codec = new RegistryCodec();
@SuppressWarnings("unchecked")
ForgeRegistry(RegistryManager stage, ResourceLocation name, RegistryBuilder<V> builder)
{
ForgeRegistry(RegistryManager stage, ResourceLocation name, RegistryBuilder<V> builder) {
this.name = name;
this.key = ResourceKey.createRegistryKey(name);
this.builder = builder;
this.stage = stage;
this.defaultKey = builder.getDefault();
this.defaultResourceKey = ResourceKey.create(key, defaultKey);
//this.defaultResourceKey = ResourceKey.create(key, defaultKey);
this.min = builder.getMinId();
this.max = builder.getMaxId();
this.availabilityMap = new BitSet(Math.min(max + 1, 0x0FFF));
@@ -118,34 +122,29 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@Override
public void register(String key, V value)
{
public void register(String key, V value) {
register(GameData.checkPrefix(key, true), value);
}
@Override
public void register(ResourceLocation key, V value)
{
public void register(ResourceLocation key, V value) {
add(-1, key, value);
}
@Override
public Iterator<V> iterator() {
return new Iterator<V>()
{
return new Iterator<V>() {
int cur = -1;
V next = null;
{ next(); }
@Override
public boolean hasNext()
{
public boolean hasNext() {
return next != null;
}
@Override
public V next()
{
public V next() {
V ret = next;
do {
cur = availabilityMap.nextSetBit(cur + 1);
@@ -158,28 +157,23 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@Override
public ResourceLocation getRegistryName()
{
public ResourceLocation getRegistryName() {
return this.name;
}
@Override
public ResourceKey<Registry<V>> getRegistryKey()
{
public ResourceKey<Registry<V>> getRegistryKey() {
return this.key;
}
@NotNull
public Codec<V> getCodec()
{
public Codec<V> getCodec() {
return this.codec;
}
@Override
public boolean containsKey(ResourceLocation key)
{
while (key != null)
{
public boolean containsKey(ResourceLocation key) {
while (key != null) {
if (this.names.containsKey(key))
return true;
key = this.aliases.get(key);
@@ -188,29 +182,24 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@Override
public boolean containsValue(V value)
{
public boolean containsValue(V value) {
return this.names.containsValue(value);
}
@Override
public boolean isEmpty()
{
public boolean isEmpty() {
return this.names.isEmpty();
}
int size()
{
int size() {
return this.names.size();
}
@Override
public V getValue(ResourceLocation key)
{
public V getValue(ResourceLocation key) {
V ret = this.names.get(key);
key = this.aliases.get(key);
while (ret == null && key != null)
{
while (ret == null && key != null) {
ret = this.names.get(key);
key = this.aliases.get(key);
}
@@ -218,23 +207,20 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@Override
public ResourceLocation getKey(V value)
{
public ResourceLocation getKey(V value) {
return getResourceKey(value).map(ResourceKey::location).orElse(this.defaultKey);
}
@NotNull
@Override
public Optional<ResourceKey<V>> getResourceKey(V value)
{
public Optional<ResourceKey<V>> getResourceKey(V value) {
// We use 'owners' here because we want to return the key for the inactive overridden items, not just the active set.
return Optional.ofNullable(this.owners.inverse().get(value)).map(OverrideOwner::key);
}
@SuppressWarnings("unchecked")
@Nullable
NamespacedWrapper<V> getWrapper()
{
NamespacedWrapper<V> getWrapper() {
if (!this.hasWrapper)
return null;
@@ -244,8 +230,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@NotNull
NamespacedWrapper<V> getWrapperOrThrow()
{
NamespacedWrapper<V> getWrapperOrThrow() {
NamespacedWrapper<V> wrapper = getWrapper();
if (wrapper == null)
@@ -254,131 +239,113 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
return wrapper;
}
void onBindTags(Map<TagKey<V>, HolderSet.Named<V>> tags, Set<TagKey<V>> defaultedTags)
{
void onBindTags(Map<TagKey<V>, HolderSet.Named<V>> tags, Set<TagKey<V>> defaultedTags) {
if (this.tagManager != null)
this.tagManager.bind(tags, defaultedTags);
}
@NotNull
@Override
public Optional<Holder<V>> getHolder(ResourceKey<V> key)
{
public Optional<Holder<V>> getHolder(ResourceKey<V> key) {
return Optional.ofNullable(this.getWrapper()).flatMap(wrapper -> wrapper.getHolder(key));
}
@NotNull
@Override
public Optional<Holder<V>> getHolder(ResourceLocation location)
{
public Optional<Holder<V>> getHolder(ResourceLocation location) {
return Optional.ofNullable(this.getWrapper()).flatMap(wrapper -> wrapper.getHolder(location));
}
@NotNull
@Override
public Optional<Holder<V>> getHolder(V value)
{
public Optional<Holder<V>> getHolder(V value) {
return Optional.ofNullable(this.getWrapper()).flatMap(wrapper -> wrapper.getHolder(value));
}
@Nullable
@Override
public ITagManager<V> tags()
{
public ITagManager<V> tags() {
return this.tagManager;
}
@NotNull
@Override
public Set<ResourceLocation> getKeys()
{
public Set<ResourceLocation> getKeys() {
return Collections.unmodifiableSet(this.names.keySet());
}
@NotNull
Set<ResourceKey<V>> getResourceKeys()
{
Set<ResourceKey<V>> getResourceKeys() {
return Collections.unmodifiableSet(this.keys.keySet());
}
@NotNull
@Override
public Collection<V> getValues()
{
public Collection<V> getValues() {
return Collections.unmodifiableSet(this.names.values());
}
@NotNull
@Override
public Set<Entry<ResourceKey<V>, V>> getEntries()
{
public Set<Entry<ResourceKey<V>, V>> getEntries() {
return Collections.unmodifiableSet(this.keys.entrySet());
}
@SuppressWarnings("unchecked")
@Override
public <T> T getSlaveMap(ResourceLocation name, Class<T> type)
{
public <T> T getSlaveMap(ResourceLocation name, Class<T> type) {
return (T)this.slaves.get(name);
}
@SuppressWarnings("unchecked")
@Override
public void setSlaveMap(ResourceLocation name, Object obj)
{
public void setSlaveMap(ResourceLocation name, Object obj) {
((Map<ResourceLocation, Object>)this.slaves).put(name, obj);
}
public int getID(V value)
{
public int getID(V value) {
Integer ret = this.ids.inverse().get(value);
if (ret == null && this.defaultValue != null)
ret = this.ids.inverse().get(this.defaultValue);
return ret == null ? -1 : ret.intValue();
}
public int getID(ResourceLocation name)
{
public int getID(ResourceLocation name) {
return getID(this.names.get(name));
}
private int getIDRaw(V value)
{
private int getIDRaw(V value) {
Integer ret = this.ids.inverse().get(value);
return ret == null ? -1 : ret.intValue();
}
private int getIDRaw(ResourceLocation name)
{
private int getIDRaw(ResourceLocation name) {
return getIDRaw(this.names.get(name));
}
@Override
public V getValue(int id)
{
public V getValue(int id) {
V ret = this.ids.get(id);
return ret == null ? this.defaultValue : ret;
}
@Nullable
public ResourceKey<V> getKey(int id)
{
public ResourceKey<V> getKey(int id) {
V value = getValue(id);
return this.keys.inverse().get(value);
}
void validateKey()
{
void validateKey() {
if (this.defaultKey != null)
Validate.notNull(this.defaultValue, "Missing default of ForgeRegistry: " + this.defaultKey + " Name: " + this.name);
}
@Nullable
public ResourceLocation getDefaultKey()
{
public ResourceLocation getDefaultKey() {
return this.defaultKey;
}
ForgeRegistry<V> copy(RegistryManager stage)
{
ForgeRegistry<V> copy(RegistryManager stage) {
return new ForgeRegistry<>(stage, name, builder);
}
@@ -387,14 +354,12 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
add(id, key, value, key.getNamespace());
}
int add(int id, ResourceLocation key, V value)
{
int add(int id, ResourceLocation key, V value) {
final String owner = ModLoadingContext.get().getActiveNamespace();
return add(id, key, value, owner);
}
int add(int id, ResourceLocation key, V value, String owner)
{
int add(int id, ResourceLocation key, V value, String owner) {
Preconditions.checkNotNull(key, "Can't use a null-name for the registry, object %s.", value);
Preconditions.checkNotNull(value, "Can't add null-object to the registry, name %s.", key);
@@ -406,13 +371,12 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
throw new RuntimeException(String.format(Locale.ENGLISH, "Invalid id %d - maximum id range exceeded.", idToUse));
V oldEntry = getRaw(key);
if (oldEntry == value) // already registered, return prev registration's id
{
if (oldEntry == value) { // already registered, return prev registration's id
LOGGER.warn(REGISTRIES,"Registry {}: The object {} has been registered twice for the same name {}.", this.name, value, key);
return this.getID(value);
}
if (oldEntry != null) // duplicate name
{
if (oldEntry != null) { // duplicate name
if (!this.allowOverrides)
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "The name %s has been registered twice, for %s and %s.", key, getRaw(key), value));
if (owner == null)
@@ -422,8 +386,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
Integer foundId = this.ids.inverse().get(value); //Is this ever possible to trigger with otherThing being different?
if (foundId != null)
{
if (foundId != null) {
V otherThing = this.ids.get(foundId);
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "The object %s{%x} has been registered twice, using the names %s and %s. (Other object at this id is %s{%x})", value, System.identityHashCode(value), getKey(value), key, otherThing, System.identityHashCode(otherThing)));
}
@@ -431,8 +394,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
if (isLocked())
throw new IllegalStateException(String.format(Locale.ENGLISH, "The object %s (name %s) is being added too late.", value, key));
if (defaultKey != null && defaultKey.equals(key))
{
if (defaultKey != null && defaultKey.equals(key)) {
if (this.defaultValue != null)
throw new IllegalStateException(String.format(Locale.ENGLISH, "Attemped to override already set default value. This is not allowed: The object %s (name %s)", value, key));
this.defaultValue = value;
@@ -445,11 +407,9 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
this.availabilityMap.set(idToUse);
this.owners.put(new OverrideOwner<V>(owner == null ? key.getNamespace() : owner, rkey), value);
if (hasWrapper)
{
Holder.Reference<V> delegate = bindDelegate(rkey, value);
if (oldEntry != null)
{
if (hasWrapper) {
bindDelegate(rkey, value);
if (oldEntry != null) {
if (!this.overrides.get(key).contains(oldEntry))
this.overrides.put(key, oldEntry);
this.overrides.get(key).remove(value);
@@ -464,12 +424,10 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
return idToUse;
}
public V getRaw(ResourceLocation key)
{
public V getRaw(ResourceLocation key) {
V ret = this.names.get(key);
key = this.aliases.get(key);
while (ret == null && key != null)
{
while (ret == null && key != null) {
ret = this.names.get(key);
key = this.aliases.get(key);
}
@@ -484,13 +442,11 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
*
* TODO: Add as public API in IForgeRegistry and DeferredRegister.
*/
public void addAlias(ResourceLocation src, ResourceLocation dst)
{
public void addAlias(ResourceLocation src, ResourceLocation dst) {
if (this.isLocked())
throw new IllegalStateException(String.format(Locale.ENGLISH, "Attempted to register the alias %s -> %s too late", src, dst));
if (src.equals(dst))
{
if (src.equals(dst)) {
LOGGER.warn(REGISTRIES, "Registry {} Ignoring invalid alias: {} -> {}", this.name, src, dst);
return;
}
@@ -501,48 +457,41 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
@NotNull
@Override
public Optional<Holder.Reference<V>> getDelegate(ResourceKey<V> rkey)
{
public Optional<Holder.Reference<V>> getDelegate(ResourceKey<V> rkey) {
return Optional.ofNullable(delegatesByName.get(rkey.location()));
}
@NotNull
@Override
public Holder.Reference<V> getDelegateOrThrow(ResourceKey<V> rkey)
{
public Holder.Reference<V> getDelegateOrThrow(ResourceKey<V> rkey) {
return getDelegate(rkey).orElseThrow(() -> new IllegalArgumentException(String.format(Locale.ENGLISH, "No delegate exists for key %s", rkey)));
}
@NotNull
@Override
public Optional<Holder.Reference<V>> getDelegate(ResourceLocation key)
{
public Optional<Holder.Reference<V>> getDelegate(ResourceLocation key) {
return Optional.ofNullable(delegatesByName.get(key));
}
@NotNull
@Override
public Holder.Reference<V> getDelegateOrThrow(ResourceLocation key)
{
public Holder.Reference<V> getDelegateOrThrow(ResourceLocation key) {
return getDelegate(key).orElseThrow(() -> new IllegalArgumentException(String.format(Locale.ENGLISH, "No delegate exists for key %s", key)));
}
@NotNull
@Override
public Optional<Holder.Reference<V>> getDelegate(V value)
{
public Optional<Holder.Reference<V>> getDelegate(V value) {
return Optional.ofNullable(delegatesByValue.get(value));
}
@NotNull
@Override
public Holder.Reference<V> getDelegateOrThrow(V value)
{
public Holder.Reference<V> getDelegateOrThrow(V value) {
return getDelegate(value).orElseThrow(() -> new IllegalArgumentException(String.format(Locale.ENGLISH, "No delegate exists for value %s", value)));
}
private Holder.Reference<V> bindDelegate(ResourceKey<V> rkey, V value)
{
private Holder.Reference<V> bindDelegate(ResourceKey<V> rkey, V value) {
Holder.Reference<V> delegate = delegatesByName.computeIfAbsent(rkey.location(), k -> Holder.Reference.createStandAlone(this.getWrapperOrThrow().holderOwner(), rkey));
delegate.bindKey(rkey);
delegate.bindValue(value);
@@ -550,8 +499,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
return delegate;
}
void resetDelegates()
{
void resetDelegates() {
if (!this.hasWrapper)
return;
@@ -562,16 +510,12 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
bindDelegate(ResourceKey.create(this.key, entry.getKey()), entry.getValue());
}
V getDefault()
{
V getDefault() {
return this.defaultValue;
}
void validateContent(ResourceLocation registryName)
{
for (V obj : this)
{
void validateContent(ResourceLocation registryName) {
for (V obj : this) {
int id = getID(obj);
ResourceLocation name = getKey(obj);
@@ -607,14 +551,12 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
}
public void bake()
{
public void bake() {
if (this.bake != null)
this.bake.onBake(this, this.stage);
}
void sync(ResourceLocation name, ForgeRegistry<V> from)
{
void sync(ResourceLocation name, ForgeRegistry<V> from) {
LOGGER.debug(REGISTRIES,"Registry {} Sync: {} -> {}", this.name, this.stage.getName(), from.stage.getName());
if (this == from)
throw new IllegalArgumentException("WTF We are the same!?!?!");
@@ -630,12 +572,9 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
this.min = from.min;
*/
// Aliases from the active registry take priority over those from the staged (loaded) registry.
for (var entry : from.aliases.entrySet())
{
for (var entry : from.aliases.entrySet()) {
if (!this.aliases.containsKey(entry.getKey()))
{
this.aliases.put(entry.getKey(), entry.getValue());
}
}
this.ids.clear();
@@ -648,34 +587,27 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
boolean errored = false;
for (Entry<ResourceLocation, V> entry : from.names.entrySet())
{
List<V> overrides = Lists.newArrayList(from.overrides.get(entry.getKey()));
for (Entry<ResourceLocation, V> entry : from.names.entrySet()) {
List<V> overrides = new ArrayList<>(from.overrides.get(entry.getKey()));
int id = from.getID(entry.getKey());
if (overrides.isEmpty())
{
if (overrides.isEmpty()) {
int realId = add(id, entry.getKey(), entry.getValue());
if (id != realId && id != -1)
{
if (id != realId && id != -1) {
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.name, entry.getKey(), id, realId);
errored = true;
}
}
else
{
} else {
overrides.add(entry.getValue());
for (V value : overrides)
{
for (V value : overrides) {
OverrideOwner<V> owner = from.owners.inverse().get(value);
if (owner == null)
{
if (owner == null) {
LOGGER.warn(REGISTRIES,"Registry {}: Override did not have an associated owner object. Name: {} Value: {}", this.name, entry.getKey(), value);
errored = true;
continue;
}
int realId = add(id, entry.getKey(), value, owner.owner);
if (id != realId && id != -1)
{
if (id != realId && id != -1) {
LOGGER.warn(REGISTRIES,"Registry {}: Object did not get ID it asked for. Name: {} Expected: {} Got: {}", this.name, entry.getKey(), id, realId);
errored = true;
}
@@ -688,8 +620,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@Override
public void clear()
{
public void clear() {
if (!this.isModifiable)
throw new UnsupportedOperationException("Attempted to clear a non-modifiable Forge Registry");
@@ -709,8 +640,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@Override
public V remove(ResourceLocation key)
{
public V remove(ResourceLocation key) {
if (!this.isModifiable)
throw new UnsupportedOperationException("Attempted to remove from a non-modifiable Forge Registry");
@@ -718,8 +648,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
throw new IllegalStateException("Attempted to remove from the registry to late.");
V value = this.names.remove(key);
if (value != null)
{
if (value != null) {
ResourceKey<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!");
@@ -734,15 +663,13 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
return value;
}
void block(int id)
{
void block(int id) {
this.blocked.add(id);
this.availabilityMap.set(id);
}
@Override
public boolean isLocked()
{
public boolean isLocked() {
return this.isFrozen;
}
@@ -750,34 +677,29 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
* Used to control the times where people can modify this registry.
* Users should only ever register things in the {@literal Register<?>} events!
*/
public void freeze()
{
public void freeze() {
this.isFrozen = true;
}
public void unfreeze()
{
public void unfreeze() {
this.isFrozen = false;
}
void dump(ResourceLocation name)
{
void dump(ResourceLocation name) {
// Building a good looking table is not cheap, so only do it if the debug logger is enabled.
if (LOGGER.isDebugEnabled(REGISTRYDUMP))
{
if (LOGGER.isDebugEnabled(REGISTRYDUMP)) {
TablePrinter<DumpRow> tab = new TablePrinter<DumpRow>()
.header("ID", r -> r.id)
.header("Key", r -> r.key)
.header("Value", r -> r.value);
LOGGER.debug(REGISTRYDUMP, ()-> LogMessageAdapter.adapt(sb ->
{
LOGGER.debug(REGISTRYDUMP, ()-> LogMessageAdapter.adapt(sb -> {
sb.append("Registry Name: ").append(name).append('\n');
tab.clearRows();
getKeys().stream().map(this::getID).sorted().map(id -> {
V val = getValue(id);
ResourceLocation key = getKey(val);
return new DumpRow(Integer.toString(id), getKey(val).toString(), val.toString());
var key = getKey(val);
return new DumpRow(Integer.toString(id), key.toString(), val.toString());
}).forEach(tab::add);
tab.build(sb);
}));
@@ -786,24 +708,19 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
private record DumpRow(String id, String key, String value) {}
public void loadIds(Map<ResourceLocation, Integer> ids, Map<ResourceLocation, String> overrides, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, IdMappingEvent.IdRemapping> remapped, ForgeRegistry<V> old, ResourceLocation name)
{
Map<ResourceLocation, String> ovs = Maps.newHashMap(overrides);
for (Map.Entry<ResourceLocation, Integer> entry : ids.entrySet())
{
public void loadIds(Map<ResourceLocation, Integer> ids, Map<ResourceLocation, String> overrides, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, IdMappingEvent.IdRemapping> remapped, ForgeRegistry<V> old, ResourceLocation name) {
Map<ResourceLocation, String> ovs = new HashMap<>(overrides);
for (Map.Entry<ResourceLocation, Integer> entry : ids.entrySet()) {
ResourceLocation itemName = entry.getKey();
int newId = entry.getValue();
int currId = old.getIDRaw(itemName);
if (currId == -1)
{
if (currId == -1) {
LOGGER.info(REGISTRIES,"Registry {}: Found a missing id from the world {}", this.name, itemName);
missing.put(itemName, newId);
continue; // no block/item -> nothing to add
}
else if (currId != newId)
{
} else if (currId != newId) {
LOGGER.debug(REGISTRIES,"Registry {}: Fixed {} id mismatch {}: {} (init) -> {} (map).", this.name, name, itemName, currId, newId);
remapped.put(itemName, new IdMappingEvent.IdRemapping(currId, newId));
}
@@ -811,25 +728,20 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
V obj = old.getRaw(itemName);
Preconditions.checkState(obj != null, "objectKey has an ID but no object. Reflection/ASM hackery? Registry bug?");
List<V> lst = Lists.newArrayList(old.overrides.get(itemName));
List<V> lst = new ArrayList<>(old.overrides.get(itemName));
String primaryName = null;
if (old.overrides.containsKey(itemName))
{
if (!overrides.containsKey(itemName))
{
if (old.overrides.containsKey(itemName)) {
if (!overrides.containsKey(itemName)) {
lst.add(obj);
obj = old.overrides.get(itemName).iterator().next(); //Get the first one in the list, Which should be the first one registered
primaryName = old.owners.inverse().get(obj).owner;
}
else
} else
primaryName = overrides.get(itemName);
}
for (V value : lst)
{
for (V value : lst) {
OverrideOwner<V> owner = old.owners.inverse().get(value);
if (owner == null)
{
if (owner == null) {
LOGGER.warn(REGISTRIES,"Registry {}: Override did not have an associated owner object. Name: {} Value: {}", this.name, entry.getKey(), value);
continue;
}
@@ -848,16 +760,13 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
ovs.remove(itemName);
}
for (Map.Entry<ResourceLocation, String> entry : ovs.entrySet())
{
for (Map.Entry<ResourceLocation, String> entry : ovs.entrySet()) {
ResourceLocation itemName = entry.getKey();
String owner = entry.getValue();
String current = this.owners.inverse().get(this.getRaw(itemName)).owner;
if (!owner.equals(current))
{
if (!owner.equals(current)) {
V _new = this.owners.get(new OverrideOwner<V>(owner, ResourceKey.create(this.key, itemName)));
if (_new == null)
{
if (_new == null) {
LOGGER.warn(REGISTRIES,"Registry {}: Skipping override for {}, Unknown owner {}", this.name, itemName, owner);
continue;
}
@@ -873,8 +782,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
//Public for tests
public Snapshot makeSnapshot()
{
public Snapshot makeSnapshot() {
Snapshot ret = new Snapshot();
this.ids.forEach((id, value) -> ret.ids.put(getKey(value), id));
ret.aliases.putAll(this.aliases);
@@ -883,11 +791,9 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
return ret;
}
Map<ResourceLocation, String> getOverrideOwners()
{
Map<ResourceLocation, String> ret = Maps.newHashMap();
for (ResourceLocation key : this.overrides.keySet())
{
Map<ResourceLocation, String> getOverrideOwners() {
Map<ResourceLocation, String> ret = new HashMap<>();
for (ResourceLocation key : this.overrides.keySet()) {
V obj = this.names.get(key);
OverrideOwner<V> owner = this.owners.inverse().get(obj);
if (owner == null)
@@ -897,26 +803,18 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
return ret;
}
private class RegistryCodec implements Codec<V>
{
private class RegistryCodec implements Codec<V> {
@Override
public <T> DataResult<Pair<V, T>> decode(DynamicOps<T> ops, T input)
{
if (ops.compressMaps())
{
return ops.getNumberValue(input).flatMap(n ->
{
public <T> DataResult<Pair<V, T>> decode(DynamicOps<T> ops, T input) {
if (ops.compressMaps()) {
return ops.getNumberValue(input).flatMap(n -> {
int id = n.intValue();
if (ids.get(id) == null)
{
return DataResult.error(() -> "Unknown registry id in " + ForgeRegistry.this.key + ": " + n);
}
V val = ForgeRegistry.this.getValue(id);
return DataResult.success(val);
}).map(v -> Pair.of(v, ops.empty()));
}
else
{
} else {
return ResourceLocation.CODEC.decode(ops, input).flatMap(keyValuePair -> !ForgeRegistry.this.containsKey(keyValuePair.getFirst())
? DataResult.error(() -> "Unknown registry key in " + ForgeRegistry.this.key + ": " + keyValuePair.getFirst())
: DataResult.success(keyValuePair.mapFirst(ForgeRegistry.this::getValue)));
@@ -924,13 +822,10 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@Override
public <T> DataResult<T> encode(V input, DynamicOps<T> ops, T prefix)
{
public <T> DataResult<T> encode(V input, DynamicOps<T> ops, T prefix) {
ResourceLocation key = getKey(input);
if (key == null)
{
return DataResult.error(() -> "Unknown registry element in " + ForgeRegistry.this.key + ": " + input);
}
T toMerge = ops.compressMaps() ? ops.createInt(getID(input)) : ops.createString(key.toString());
return ops.mergeToPrimitive(prefix, toMerge);
}
@@ -938,10 +833,10 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
public static class Snapshot {
private static final Comparator<ResourceLocation> sorter = (a,b) -> a.compareNamespaced(b);
public final Map<ResourceLocation, Integer> ids = Maps.newTreeMap(sorter);
public final Map<ResourceLocation, ResourceLocation> aliases = Maps.newTreeMap(sorter);
public final Set<Integer> blocked = Sets.newTreeSet();
public final Map<ResourceLocation, String> overrides = Maps.newTreeMap(sorter);
public final Map<ResourceLocation, Integer> ids = new TreeMap<>(sorter);
public final Map<ResourceLocation, ResourceLocation> aliases = new TreeMap<>(sorter);
public final Set<Integer> blocked = new TreeSet<>();
public final Map<ResourceLocation, String> overrides = new TreeMap<>(sorter);
private FriendlyByteBuf binary = null;
public CompoundTag write() {
@@ -1037,25 +932,21 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
}
@SuppressWarnings("unchecked")
public MissingMappingsEvent getMissingEvent(ResourceLocation name, Map<ResourceLocation, Integer> map)
{
List<MissingMappingsEvent.Mapping<V>> lst = Lists.newArrayList();
public MissingMappingsEvent getMissingEvent(ResourceLocation name, Map<ResourceLocation, Integer> map) {
List<MissingMappingsEvent.Mapping<V>> lst = new ArrayList<>();
ForgeRegistry<V> pool = RegistryManager.ACTIVE.getRegistry(name);
map.forEach((rl, id) -> lst.add(new MissingMappingsEvent.Mapping<>(this, pool, rl, id)));
return new MissingMappingsEvent(ResourceKey.createRegistryKey(name), this, (Collection<MissingMappingsEvent.Mapping<?>>) (Collection<?>) lst);
}
void processMissingEvent(ResourceLocation name, ForgeRegistry<V> pool, List<MissingMappingsEvent.Mapping<V>> mappings, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, IdMappingEvent.IdRemapping> remaps, Collection<ResourceLocation> defaulted, Collection<ResourceLocation> failed, boolean injectNetworkDummies)
{
void processMissingEvent(ResourceLocation name, ForgeRegistry<V> pool, List<MissingMappingsEvent.Mapping<V>> mappings, Map<ResourceLocation, Integer> missing, Map<ResourceLocation, IdMappingEvent.IdRemapping> remaps, Collection<ResourceLocation> defaulted, Collection<ResourceLocation> failed, boolean injectNetworkDummies) {
LOGGER.debug(REGISTRIES,"Processing missing event for {}:", name);
int ignored = 0;
for (MissingMappingsEvent.Mapping<V> remap : mappings)
{
for (MissingMappingsEvent.Mapping<V> remap : mappings) {
MissingMappingsEvent.Action action = remap.action;
if (action == MissingMappingsEvent.Action.REMAP)
{
if (action == MissingMappingsEvent.Action.REMAP) {
// entry re-mapped, finish the registration with the new name/object, but the old id
int currId = getID(remap.target);
ResourceLocation newName = pool.getKey(remap.target);
@@ -1069,35 +960,25 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
this.addAlias(remap.key, newName);
if (currId != realId)
{
if (currId != realId) {
LOGGER.info(REGISTRIES,"Fixed id mismatch {}: {} (init) -> {} (map).", newName, currId, realId);
remaps.put(newName, new IdMappingEvent.IdRemapping(currId, realId));
}
}
else
{
} else {
// block item missing, warn as requested and block the id
if (action == MissingMappingsEvent.Action.DEFAULT)
{
if (action == MissingMappingsEvent.Action.DEFAULT) {
V m = this.missing == null ? null : this.missing.createMissing(remap.key, injectNetworkDummies);
if (m == null)
defaulted.add(remap.key);
else
this.add(remap.id, remap.key, m, remap.key.getNamespace());
}
else if (action == MissingMappingsEvent.Action.IGNORE)
{
} else if (action == MissingMappingsEvent.Action.IGNORE) {
LOGGER.debug(REGISTRIES,"Ignoring {}", remap.key);
ignored++;
}
else if (action == MissingMappingsEvent.Action.FAIL)
{
} else if (action == MissingMappingsEvent.Action.FAIL) {
LOGGER.debug(REGISTRIES,"Failing {}!", remap.key);
failed.add(remap.key);
}
else if (action == MissingMappingsEvent.Action.WARN)
{
} else if (action == MissingMappingsEvent.Action.WARN) {
LOGGER.warn(REGISTRIES,"{} may cause world breakage!", remap.key);
}
this.block(remap.id);
@@ -1108,8 +989,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
LOGGER.debug(REGISTRIES,"There were {} missing mappings that have been ignored", ignored);
}
RegistryBuilder<V> getBuilder()
{
RegistryBuilder<V> getBuilder() {
return this.builder;
}
@@ -50,11 +50,8 @@ import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.common.CreativeModeTabRegistry;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.common.util.LogMessageAdapter;
import net.minecraftforge.common.world.BiomeModifier;
import net.minecraftforge.common.world.StructureModifier;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingContext;
@@ -62,7 +59,6 @@ import net.minecraftforge.fml.StartupMessageManager;
import net.minecraftforge.fml.util.EnhancedRuntimeException;
import net.minecraftforge.fml.util.thread.EffectiveSide;
import net.minecraftforge.registries.ForgeRegistries.Keys;
import net.minecraftforge.registries.holdersets.HolderSetType;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -154,29 +150,13 @@ public class GameData
return makeRegistry(Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS).disableSaving().disableSync();
}
static RegistryBuilder<Codec<? extends BiomeModifier>> getBiomeModifierSerializersRegistryBuilder()
{
return new RegistryBuilder<Codec<? extends BiomeModifier>>().disableSaving().disableSync();
}
static RegistryBuilder<Codec<? extends StructureModifier>> getStructureModifierSerializersRegistryBuilder()
{
return new RegistryBuilder<Codec<? extends StructureModifier>>().disableSaving().disableSync();
}
static RegistryBuilder<FluidType> getFluidTypeRegistryBuilder()
{
return makeRegistry(Keys.FLUID_TYPES).disableSaving();
}
static RegistryBuilder<HolderSetType> getHolderSetTypeRegistryBuilder()
{
return new RegistryBuilder<HolderSetType>().disableSaving().disableSync();
}
static RegistryBuilder<Codec<? extends ICondition>> getConditionCodecRegistryBuilder()
{
return new RegistryBuilder<Codec<? extends ICondition>>().disableSaving().disableSync();
static <T> RegistryBuilder<T> makeUnsavedAndUnsynced() {
return RegistryBuilder.<T>of().disableSaving().disableSync();
}
static RegistryBuilder<ItemDisplayContext> getItemDisplayContextRegistryBuilder()
@@ -22,6 +22,18 @@ import java.util.function.Function;
public class RegistryBuilder<T>
{
public static <T> RegistryBuilder<T> of() {
return new RegistryBuilder<T>();
}
public static <T> RegistryBuilder<T> of(String name) {
return of(new ResourceLocation(name));
}
public static <T> RegistryBuilder<T> of(ResourceLocation name) {
return new RegistryBuilder<T>().setName(name);
}
private static final int MAX_ID = Integer.MAX_VALUE - 1;
private ResourceLocation registryName;
@@ -12,7 +12,6 @@ import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
@FunctionalInterface
public interface HolderSetType
{
<T> Codec<? extends ICustomHolderSet<T>> makeCodec(ResourceKey<? extends Registry<T>> registryKey, Codec<Holder<T>> holderCodec, boolean forceList);
public interface HolderSetType {
<T> Codec<? extends ICustomHolderSet<T>> makeCodec(ResourceKey<? extends Registry<T>> registryKey, Codec<Holder<T>> holderCodec, boolean forceList);
}