mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
1.21 Update
Co-authored-by: RealMangoRage <[email protected]> Co-authored-by: Daniel Norris <[email protected]> Co-authored-by: Ven <[email protected]>
This commit is contained in:
941 files changed
+3119
-4266
No files matched your search
@@ -40,7 +40,7 @@ public final class DataPackRegistriesHooks {
|
||||
WORLDGEN_REGISTRIES.add(loaderData);
|
||||
if (data.networkCodec() != null) {
|
||||
SYNCED_CUSTOM_REGISTRIES.add(loaderData.key());
|
||||
NETWORKABLE_REGISTRIES.put(loaderData.key(), new RegistryDataLoader.RegistryData<>(loaderData.key(), data.networkCodec()));
|
||||
NETWORKABLE_REGISTRIES.put(loaderData.key(), new RegistryDataLoader.RegistryData<>(loaderData.key(), data.networkCodec(), false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class DataPackRegistryEvent extends Event implements IModBusEvent
|
||||
*/
|
||||
public <T> void dataPackRegistry(ResourceKey<Registry<T>> registryKey, Codec<T> codec, @Nullable Codec<T> networkCodec)
|
||||
{
|
||||
this.registryDataList.add(new DataPackRegistryData<>(new RegistryDataLoader.RegistryData<>(registryKey, codec), networkCodec));
|
||||
this.registryDataList.add(new DataPackRegistryData<>(new RegistryDataLoader.RegistryData<>(registryKey, codec, false), networkCodec));
|
||||
}
|
||||
|
||||
void process()
|
||||
|
||||
@@ -74,7 +74,7 @@ public class DeferredRegister<T> {
|
||||
* @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) {
|
||||
public static <B> DeferredRegister<B> create(RegistryHolder<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");
|
||||
@@ -184,7 +184,7 @@ public class DeferredRegister<T> {
|
||||
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(sup);
|
||||
final ResourceLocation key = new ResourceLocation(modid, name);
|
||||
var key = ResourceLocation.fromNamespaceAndPath(modid, name);
|
||||
|
||||
RegistryObject<I> ret;
|
||||
if (this.registryKey != null) {
|
||||
@@ -210,7 +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 RegistryHolder<T> makeRegistry(final Supplier<RegistryBuilder<T>> sup) {
|
||||
return makeRegistry(this.registryKey.location(), sup);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public class DeferredRegister<T> {
|
||||
@NotNull
|
||||
public TagKey<T> createTagKey(@NotNull String path) {
|
||||
Objects.requireNonNull(path);
|
||||
return createTagKey(new ResourceLocation(this.modid, path));
|
||||
return createTagKey(ResourceLocation.fromNamespaceAndPath(this.modid, path));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +261,7 @@ public class DeferredRegister<T> {
|
||||
@NotNull
|
||||
public TagKey<T> createOptionalTagKey(@NotNull String path, @NotNull Set<? extends Supplier<T>> defaults) {
|
||||
Objects.requireNonNull(path);
|
||||
return createOptionalTagKey(new ResourceLocation(this.modid, path), defaults);
|
||||
return createOptionalTagKey(ResourceLocation.fromNamespaceAndPath(this.modid, path), defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,7 +335,7 @@ public class DeferredRegister<T> {
|
||||
return Objects.requireNonNull(this.registryKey).location();
|
||||
}
|
||||
|
||||
private Supplier<IForgeRegistry<T>> makeRegistry(final ResourceLocation registryName, final Supplier<RegistryBuilder<T>> sup) {
|
||||
private RegistryHolder<T> makeRegistry(final ResourceLocation registryName, final Supplier<RegistryBuilder<T>> sup) {
|
||||
if (registryName == null)
|
||||
throw new IllegalStateException("Cannot create a registry without specifying a registry name");
|
||||
if (RegistryManager.ACTIVE.getRegistry(registryName) != null || this.registryFactory != null)
|
||||
@@ -376,12 +376,7 @@ public class DeferredRegister<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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>> {
|
||||
public static final class RegistryHolder<V> implements Supplier<IForgeRegistry<V>> {
|
||||
private final ResourceKey<? extends Registry<V>> registryKey;
|
||||
private IForgeRegistry<V> registry = null;
|
||||
|
||||
@@ -389,6 +384,10 @@ public class DeferredRegister<T> {
|
||||
this.registryKey = registryKey;
|
||||
}
|
||||
|
||||
public ResourceKey<? extends Registry<V>> getKey() {
|
||||
return this.registryKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IForgeRegistry<V> get() {
|
||||
// Keep looking up the registry until it's not null
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.registries;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
@@ -14,7 +13,6 @@ import net.minecraft.world.entity.decoration.PaintingVariant;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||
@@ -50,6 +48,7 @@ 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.DeferredRegister.RegistryHolder;
|
||||
import net.minecraftforge.registries.holdersets.HolderSetType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -68,7 +67,7 @@ public class ForgeRegistries {
|
||||
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) {
|
||||
private static final <T> RegistryHolder<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);
|
||||
@@ -81,7 +80,6 @@ public class ForgeRegistries {
|
||||
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);
|
||||
@@ -113,15 +111,15 @@ public class ForgeRegistries {
|
||||
public static final IForgeRegistry<Biome> BIOMES = active(Keys.BIOMES);
|
||||
|
||||
// Custom forge registries
|
||||
public static final Supplier<IForgeRegistry<EntityDataSerializer<?>>> ENTITY_DATA_SERIALIZERS = registry(Keys.ENTITY_DATA_SERIALIZERS, GameData::getDataSerializersRegistryBuilder);
|
||||
public static final Supplier<IForgeRegistry<MapCodec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = registry(Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, GameData::getGLMSerializersRegistryBuilder);
|
||||
public static final Supplier<IForgeRegistry<MapCodec<? extends BiomeModifier>>> BIOME_MODIFIER_SERIALIZERS = registry(Keys.BIOME_MODIFIER_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
|
||||
public static final Supplier<IForgeRegistry<MapCodec<? 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<MapCodec<? 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 RegistryHolder<EntityDataSerializer<?>> ENTITY_DATA_SERIALIZERS = registry(Keys.ENTITY_DATA_SERIALIZERS, GameData::getDataSerializersRegistryBuilder);
|
||||
public static final RegistryHolder<MapCodec<? extends IGlobalLootModifier>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = registry(Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, GameData::getGLMSerializersRegistryBuilder);
|
||||
public static final RegistryHolder<MapCodec<? extends BiomeModifier>> BIOME_MODIFIER_SERIALIZERS = registry(Keys.BIOME_MODIFIER_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
|
||||
public static final RegistryHolder<MapCodec<? extends StructureModifier>> STRUCTURE_MODIFIER_SERIALIZERS = registry(Keys.STRUCTURE_MODIFIER_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
|
||||
public static final RegistryHolder<FluidType> FLUID_TYPES = registry(Keys.FLUID_TYPES, GameData::getFluidTypeRegistryBuilder);
|
||||
public static final RegistryHolder<HolderSetType> HOLDER_SET_TYPES = registry(Keys.HOLDER_SET_TYPES, GameData::makeUnsavedAndUnsynced);
|
||||
public static final RegistryHolder<ItemDisplayContext> DISPLAY_CONTEXTS = registry(Keys.DISPLAY_CONTEXTS, GameData::getItemDisplayContextRegistryBuilder);
|
||||
public static final RegistryHolder<MapCodec<? extends ICondition>> CONDITION_SERIALIZERS = registry(Keys.CONDITION_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
|
||||
public static final RegistryHolder<IIngredientSerializer<?>> INGREDIENT_SERIALIZERS = registry(Keys.INGREDIENT_SERIALIZERS, GameData::makeUnsavedAndUnsynced);
|
||||
|
||||
public static final class Keys {
|
||||
//Vanilla
|
||||
@@ -134,7 +132,6 @@ public class ForgeRegistries {
|
||||
public static final ResourceKey<Registry<StatType<?>>> STAT_TYPES = key("stat_type");
|
||||
public static final ResourceKey<Registry<ArgumentTypeInfo<?, ?>>> COMMAND_ARGUMENT_TYPES = key("command_argument_type");
|
||||
public static final ResourceKey<Registry<SoundEvent>> SOUND_EVENTS = key("sound_event");
|
||||
public static final ResourceKey<Registry<Enchantment>> ENCHANTMENTS = key("enchantment");
|
||||
public static final ResourceKey<Registry<EntityType<?>>> ENTITY_TYPES = key("entity_type");
|
||||
public static final ResourceKey<Registry<PaintingVariant>> PAINTING_VARIANTS = key("painting_variant");
|
||||
public static final ResourceKey<Registry<ParticleType<?>>> PARTICLE_TYPES = key("particle_type");
|
||||
@@ -174,7 +171,7 @@ public class ForgeRegistries {
|
||||
public static final ResourceKey<Registry<StructureModifier>> STRUCTURE_MODIFIERS = key("forge:structure_modifier");
|
||||
|
||||
private static <T> ResourceKey<Registry<T>> key(String name) {
|
||||
return ResourceKey.createRegistryKey(new ResourceLocation(name));
|
||||
return ResourceKey.createRegistryKey(ResourceLocation.parse(name));
|
||||
}
|
||||
|
||||
private static void init() {}
|
||||
|
||||
@@ -893,19 +893,19 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
|
||||
ListTag list = nbt.getList("ids", 10);
|
||||
list.forEach(e -> {
|
||||
CompoundTag comp = (CompoundTag)e;
|
||||
ret.ids.put(new ResourceLocation(comp.getString("K")), comp.getInt("V"));
|
||||
ret.ids.put(ResourceLocation.parse(comp.getString("K")), comp.getInt("V"));
|
||||
});
|
||||
|
||||
list = nbt.getList("aliases", 10);
|
||||
list.forEach(e -> {
|
||||
CompoundTag comp = (CompoundTag)e;
|
||||
ret.aliases.put(new ResourceLocation(comp.getString("K")), new ResourceLocation(comp.getString("V")));
|
||||
ret.aliases.put(ResourceLocation.parse(comp.getString("K")), ResourceLocation.parse(comp.getString("V")));
|
||||
});
|
||||
|
||||
list = nbt.getList("overrides", 10);
|
||||
list.forEach(e -> {
|
||||
CompoundTag comp = (CompoundTag)e;
|
||||
ret.overrides.put(new ResourceLocation(comp.getString("K")), comp.getString("V"));
|
||||
ret.overrides.put(ResourceLocation.parse(comp.getString("K")), comp.getString("V"));
|
||||
});
|
||||
|
||||
int[] blocked = nbt.getIntArray("blocked");
|
||||
|
||||
@@ -44,7 +44,6 @@ import net.minecraft.world.entity.ai.village.poi.PoiType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -114,7 +113,6 @@ public class GameData {
|
||||
makeRegistry(Keys.MOB_EFFECTS).create();
|
||||
makeRegistry(Keys.SOUND_EVENTS).create();
|
||||
makeRegistry(Keys.POTIONS).create();
|
||||
makeRegistry(Keys.ENCHANTMENTS).legacyName("enchantments").intrusiveHolderCallback(Enchantment::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.ENTITY_TYPES, "pig").legacyName("entities").intrusiveHolderCallback(EntityType::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.BLOCK_ENTITY_TYPES).disableSaving().legacyName("blockentities").intrusiveHolderCallback(BlockEntityType::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.PARTICLE_TYPES).disableSaving().create();
|
||||
@@ -165,7 +163,7 @@ public class GameData {
|
||||
static RegistryBuilder<ItemDisplayContext> getItemDisplayContextRegistryBuilder() {
|
||||
return new RegistryBuilder<ItemDisplayContext>()
|
||||
.setMaxID(128 * 2) /* 0 -> 127 gets positive ID, 128 -> 256 gets negative ID */.disableOverrides().disableSaving()
|
||||
.setDefaultKey(new ResourceLocation("minecraft:none"))
|
||||
.setDefaultKey(ResourceLocation.withDefaultNamespace("none"))
|
||||
.onAdd(ItemDisplayContext.ADD_CALLBACK);
|
||||
}
|
||||
|
||||
@@ -178,7 +176,7 @@ public class GameData {
|
||||
}
|
||||
|
||||
private static <T> RegistryBuilder<T> makeRegistry(ResourceKey<? extends Registry<T>> key, String _default) {
|
||||
return new RegistryBuilder<T>().setName(key.location()).setMaxID(MAX_VARINT).hasWrapper().setDefaultKey(new ResourceLocation(_default));
|
||||
return new RegistryBuilder<T>().setName(key.location()).setMaxID(MAX_VARINT).hasWrapper().setDefaultKey(ResourceLocation.parse(_default));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -432,7 +430,6 @@ public class GameData {
|
||||
@Override
|
||||
public void onCreate(IForgeRegistryInternal<Block> owner, RegistryManager stage) {
|
||||
var idMap = new ClearableObjectIntIdentityMap<BlockState>() {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getId(BlockState key) {
|
||||
return this.tToId.containsKey(key) ? this.tToId.getInt(key) : -1;
|
||||
@@ -775,6 +772,6 @@ public class GameData {
|
||||
LogManager.getLogger().debug("Mod `{}` attempting to register `{}` to the namespace `{}`. This could be intended, but likely means an EventBusSubscriber without a modid.", prefix, name, oldPrefix);
|
||||
prefix = oldPrefix;
|
||||
}
|
||||
return new ResourceLocation(prefix, name);
|
||||
return ResourceLocation.fromNamespaceAndPath(prefix, name);
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public interface IForgeRegistry<V> extends Iterable<V> {
|
||||
|
||||
public record SlaveKey<T>(ResourceLocation name) {
|
||||
public static <X> SlaveKey<X> create(String name) {
|
||||
return create(new ResourceLocation(name));
|
||||
return create(ResourceLocation.parse(name));
|
||||
}
|
||||
|
||||
public static <X> SlaveKey<X> create(ResourceLocation name) {
|
||||
|
||||
@@ -54,7 +54,7 @@ class ObjectHolderRef implements Consumer<Predicate<ResourceLocation>>
|
||||
{
|
||||
try
|
||||
{
|
||||
injectedObjectName = new ResourceLocation(injectedObject);
|
||||
injectedObjectName = ResourceLocation.parse(injectedObject);
|
||||
}
|
||||
catch (ResourceLocationException e)
|
||||
{
|
||||
|
||||
@@ -148,7 +148,7 @@ public class ObjectHolderRegistry
|
||||
}
|
||||
if (isClass)
|
||||
{
|
||||
scanClassForFields(classModIds, type, new ResourceLocation(registryName), registryClass, value, clazz, extractFromValue);
|
||||
scanClassForFields(classModIds, type, ResourceLocation.parse(registryName), registryClass, value, clazz, extractFromValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -165,7 +165,7 @@ public class ObjectHolderRegistry
|
||||
try
|
||||
{
|
||||
Field f = clazz.getDeclaredField(annotationTarget);
|
||||
ObjectHolderRef ref = ObjectHolderRef.create(new ResourceLocation(registryName), f, value, extractFromValue);
|
||||
ObjectHolderRef ref = ObjectHolderRef.create(ResourceLocation.parse(registryName), f, value, extractFromValue);
|
||||
if (ref != null)
|
||||
addHandler(ref);
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class ObjectHolderRegistry
|
||||
Type targetClass, Object declaration)
|
||||
{
|
||||
if (registryName != null)
|
||||
return new ResourceLocation(registryName);
|
||||
return ResourceLocation.parse(registryName);
|
||||
|
||||
if (classRegistryNames.containsKey(targetClass))
|
||||
return classRegistryNames.get(targetClass);
|
||||
|
||||
@@ -125,7 +125,7 @@ public class RegisterEvent extends Event implements IModBusEvent
|
||||
*/
|
||||
default void register(String name, T value)
|
||||
{
|
||||
register(new ResourceLocation(ModLoadingContext.get().getActiveNamespace(), name), value);
|
||||
register(ResourceLocation.fromNamespaceAndPath(ModLoadingContext.get().getActiveNamespace(), name), value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ public class RegistryBuilder<T> {
|
||||
}
|
||||
|
||||
public static <T> RegistryBuilder<T> of(String name) {
|
||||
return of(new ResourceLocation(name));
|
||||
return of(ResourceLocation.parse(name));
|
||||
}
|
||||
|
||||
public static <T> RegistryBuilder<T> of(ResourceLocation name) {
|
||||
@@ -174,7 +174,7 @@ public class RegistryBuilder<T> {
|
||||
}
|
||||
|
||||
public RegistryBuilder<T> legacyName(String name) {
|
||||
return legacyName(new ResourceLocation(name));
|
||||
return legacyName(ResourceLocation.parse(name));
|
||||
}
|
||||
|
||||
public RegistryBuilder<T> legacyName(ResourceLocation name) {
|
||||
|
||||
Reference in new issue
Block a user