Skip to content

Commit 1d2d559

Browse files
committed
RegistryRegistrationSet
1 parent e1a4b61 commit 1d2d559

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/main/java/org/spongepowered/api/event/lifecycle/RegisterRegistryValueEvent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.spongepowered.api.ResourceKey;
2929
import org.spongepowered.api.event.GenericEvent;
3030
import org.spongepowered.api.registry.RegistryHolder;
31+
import org.spongepowered.api.registry.RegistryRegistrationSet;
3132
import org.spongepowered.api.registry.RegistryType;
3233
import org.spongepowered.eventgen.annotations.NoFactoryMethod;
3334

@@ -45,6 +46,10 @@ default <T> void registry(RegistryType<T> registryType, Consumer<RegistryStep<T>
4546

4647
<T> void registry(RegistryType<T> registryType, BiConsumer<RegistryHolder, RegistryStep<T>> consumer, final RegistryType<?>... dependencies);
4748

49+
default <T> void register(RegistryRegistrationSet<T> registrationSet) {
50+
this.registry(registrationSet.registryType(), r -> registrationSet.values().forEach(r::register));
51+
}
52+
4853
interface RegistryStep<T> {
4954

5055
RegistryStep<T> register(ResourceKey key, T value);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.registry;
26+
27+
import org.spongepowered.api.ResourceKey;
28+
import org.spongepowered.api.Sponge;
29+
30+
import java.util.Map;
31+
import java.util.function.Supplier;
32+
33+
public interface RegistryRegistrationSet<T> {
34+
35+
RegistryType<T> registryType();
36+
37+
Map<ResourceKey, T> values();
38+
39+
static <T> Builder<T> builder(RegistryType<T> registryType, Supplier<RegistryHolder> defaultHolder) {
40+
return Sponge.game().factoryProvider().provide(Factory.class).builder(registryType, defaultHolder);
41+
}
42+
43+
interface Builder<T> extends org.spongepowered.api.util.Builder<RegistryRegistrationSet<T>, Builder<T>> {
44+
45+
DefaultedRegistryReference<T> register(ResourceKey key, T value);
46+
}
47+
48+
interface Factory {
49+
50+
<T> Builder<T> builder(RegistryType<T> registryType, Supplier<RegistryHolder> defaultHolder);
51+
}
52+
}

0 commit comments

Comments
 (0)