Files
MinecraftForge/src/main/java/net/minecraftforge/registries/DataPackRegistryEvent.java
T
8255d7aed3 Forge 1.19.3
Created a CreativeModeTabEvent to register creative mode tabs and populate entries per tab
Moved datapack registries to DataPackRegistryEvent.NewRegistry event instead of tying them to ForgeRegistry
Made it easier for mods to datagen datapack builtin entries with DatapackBuiltinEntriesProvider
Provided access to lookupProvider for datagen
Updated dependencies to match versions used by vanilla and update JarJar to 0.3.18
Added a test mod for the new CreativeModeTabEvent
Throws better error message for Forge registries in tag datagen
Deleted ForgeRegistryTagsProvider
Updated ClientChatReceivedEvent and ServerChatEvent for Mojang changes
Added patches for both sign related methods in ModelLayers
Changed RegisterShadersEvent to use ResourceProvider
Migrated old Mojang math types to JOML

Co-authored-by: Marc Hermans <marc.hermans@ldtteam.com>
Co-authored-by: LexManos <LexManos@gmail.com>
Co-authored-by: sciwhiz12 <arnoldnunag12@gmail.com>
Co-authored-by: coehlrich <coehlrich@users.noreply.github.com>
2022-12-08 01:45:22 -06:00

95 lines
4.4 KiB
Java

/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.registries;
import com.mojang.serialization.Codec;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.resources.ResourceKey;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.event.IModBusEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
public class DataPackRegistryEvent extends Event implements IModBusEvent
{
@ApiStatus.Internal
public DataPackRegistryEvent() {}
/**
* Fired when datapack registries can be registered.
* Datapack registries are registries which can only load entries through JSON files from datapacks.
* <p>
* Data JSONs will be loaded from {@code data/<datapack_namespace>/modid/registryname/}, where {@code modid} is the namespace of the registry key.
* <p>
* This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
* on both {@linkplain LogicalSide logical sides}.
*/
public static final class NewRegistry extends DataPackRegistryEvent
{
private final List<DataPackRegistryData<?>> registryDataList = new ArrayList<>();
@ApiStatus.Internal
public NewRegistry() {}
/**
* Registers the given registry key as an unsynced datapack registry, which will cause data to be loaded from
* a datapack folder based on the registry's name. The datapack registry is not required to be present
* on clients when connecting to servers with the mod/registry.
* <p>
* Data JSONs will be loaded from {@code data/<datapack_namespace>/modid/registryname/}, where {@code modid} is the namespace of the registry key.
*
* @param registryKey the root registry key of the new datapack registry
* @param codec the codec to be used for loading data from datapacks on servers
* @see #dataPackRegistry(ResourceKey, Codec, Codec)
*/
public <T> void dataPackRegistry(ResourceKey<Registry<T>> registryKey, Codec<T> codec)
{
this.dataPackRegistry(registryKey, codec, null);
}
/**
* Registers the registry key as a datapack registry, which will cause data to be loaded from
* a datapack folder based on the registry's name.
* <p>
* Data JSONs will be loaded from {@code data/<datapack_namespace>/modid/registryname/}, where {@code modid} is the namespace of the registry key.
*
* @param registryKey the root registry key of the new datapack registry
* @param codec the codec to be used for loading data from datapacks on servers
* @param networkCodec the codec to be used for syncing loaded data to clients.
* If {@code networkCodec} is null, data will not be synced, and clients are not required to have this
* datapack registry to join a server.
* <p>
* If {@code networkCodec} is not null, clients must have this datapack registry/mod
* when joining a server that has this datapack registry/mod.
* The data will be synced using the network codec and accessible via {@link ClientPacketListener#registryAccess()}.
* @see #dataPackRegistry(ResourceKey, Codec)
*/
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));
}
void process()
{
for (DataPackRegistryData<?> registryData : this.registryDataList)
{
DataPackRegistriesHooks.addRegistryCodec(registryData);
}
}
}
record DataPackRegistryData<T>(RegistryDataLoader.RegistryData<T> loaderData, @Nullable Codec<T> networkCodec) {}
}