Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Datapack Registry to be configured by RegistryBuilder #1447

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8b11e85
Allow Datapack Registry to be configured by RegistryBuilder
Argon4W Aug 12, 2024
e4d1399
Merge branch '1.21.x' into 1.21.x-datapack-registry-improvements
Argon4W Aug 13, 2024
9441ecc
Merge branch '1.21.x' into 1.21.x-datapack-registry-improvements
Argon4W Aug 15, 2024
ca7dfdc
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Aug 17, 2024
7344f72
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Aug 18, 2024
2257738
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Aug 18, 2024
9cc6ecf
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Aug 19, 2024
c4cb1f5
Merge branch '1.21.x' into 1.21.x-datapack-registry-improvements
Argon4W Aug 23, 2024
f68f1ce
make the RegistryBuilder consumer the last parameter of the RegistryData
Argon4W Aug 23, 2024
e1810eb
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Aug 25, 2024
0054682
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Aug 29, 2024
abad01d
Remove new parameter in RegistryBuilder, Edit the comment in the Data…
Argon4W Aug 29, 2024
c5546da
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 1, 2024
c6fba8b
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 2, 2024
d3cc9a0
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 4, 2024
9c8e0ea
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 8, 2024
2055665
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 8, 2024
b054b1d
Rename consumer parameter
Argon4W Sep 12, 2024
85c8bc5
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 12, 2024
611c436
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 14, 2024
2c4b83a
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 18, 2024
9cd23cd
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 18, 2024
050efb3
Merge branch 'neoforged:1.21.x' into 1.21.x-datapack-registry-improve…
Argon4W Sep 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions patches/net/minecraft/resources/RegistryDataLoader.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,26 @@

for (Entry<ResourceLocation, Resource> entry : filetoidconverter.listMatchingResources(p_321535_).entrySet()) {
ResourceLocation resourcelocation = entry.getKey();
@@ -304,13 +_,20 @@
void apply(RegistryDataLoader.Loader<?> p_321864_, RegistryOps.RegistryInfoLookup p_321656_);
}

- public static record RegistryData<T>(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, boolean requiredNonEmpty) {
+ public static record RegistryData<T>(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, boolean requiredNonEmpty, java.util.function.Consumer<net.neoforged.neoforge.registries.RegistryBuilder<T>> registryBuilderConsumer) {
+ public RegistryData(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, boolean requiredNonEmpty) {
+ this(key, elementCodec, requiredNonEmpty, registryBuilder -> {});
+ }
+
RegistryData(ResourceKey<? extends Registry<T>> p_251360_, Codec<T> p_248976_) {
this(p_251360_, p_248976_, false);
}

RegistryDataLoader.Loader<T> create(Lifecycle p_251662_, Map<ResourceKey<?>, Exception> p_251565_) {
- WritableRegistry<T> writableregistry = new MappedRegistry<>(this.key, p_251662_);
+ net.neoforged.neoforge.registries.RegistryBuilder<T> registryBuilder = new net.neoforged.neoforge.registries.RegistryBuilder<>(key);
+ registryBuilderConsumer.accept(registryBuilder);
+
+ WritableRegistry<T> writableregistry = (WritableRegistry<T>) registryBuilder.disableRegistrationCheck().create();
return new RegistryDataLoader.Loader<>(this, writableregistry, p_251565_);
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.serialization.Codec;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryDataLoader;
Expand Down Expand Up @@ -74,6 +75,29 @@ public <T> void dataPackRegistry(ResourceKey<Registry<T>> registryKey, Codec<T>
this.registryDataList.add(new DataPackRegistryData<>(new RegistryDataLoader.RegistryData<>(registryKey, codec, false), networkCodec));
}

/**
* Registers the registry key as a datapack registry with a {@link RegistryBuilder} configurator, 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()}.
* @param consumer A consumer that configures the provided RegistryBuilder
* @see #dataPackRegistry(ResourceKey, Codec)
* @see #dataPackRegistry(ResourceKey, Codec, Codec)
*/
public <T> void dataPackRegistry(ResourceKey<Registry<T>> registryKey, Codec<T> codec, @Nullable Codec<T> networkCodec, Consumer<RegistryBuilder<T>> consumer) {
this.registryDataList.add(new DataPackRegistryData<>(new RegistryDataLoader.RegistryData<>(registryKey, codec, false, consumer), networkCodec));
}

void process() {
for (DataPackRegistryData<?> registryData : this.registryDataList) {
DataPackRegistriesHooks.addRegistryCodec(registryData);
Expand Down