2020-06-26 11:44:47 +02:00
|
|
|
package com.minelittlepony.unicopia.util;
|
|
|
|
|
2022-03-26 20:34:15 +01:00
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
2020-06-26 11:44:47 +02:00
|
|
|
import com.mojang.serialization.Lifecycle;
|
|
|
|
|
|
|
|
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
|
2022-03-26 20:34:15 +01:00
|
|
|
import net.minecraft.tag.TagKey;
|
2020-06-26 11:44:47 +02:00
|
|
|
import net.minecraft.util.Identifier;
|
2022-08-27 15:07:29 +02:00
|
|
|
import net.minecraft.util.registry.*;
|
2022-03-26 20:34:15 +01:00
|
|
|
import net.minecraft.world.World;
|
2020-06-26 11:44:47 +02:00
|
|
|
|
|
|
|
public interface Registries {
|
|
|
|
static <T> Registry<T> createSimple(Identifier id) {
|
2022-03-26 20:34:15 +01:00
|
|
|
return FabricRegistryBuilder.from(new SimpleRegistry<T>(RegistryKey.ofRegistry(id), Lifecycle.stable(), null)).buildAndRegister();
|
|
|
|
}
|
|
|
|
|
2022-08-27 15:07:29 +02:00
|
|
|
static <T> Registry<T> createDefaulted(Identifier id, String def) {
|
|
|
|
return FabricRegistryBuilder.from(new DefaultedRegistry<T>(def, RegistryKey.ofRegistry(id), Lifecycle.stable(), null)).buildAndRegister();
|
|
|
|
}
|
|
|
|
|
2022-03-26 20:34:15 +01:00
|
|
|
static <T> RegistryEntryList<T> entriesForTag(World world, TagKey<T> key) {
|
|
|
|
return world.getRegistryManager().get(key.registry()).getOrCreateEntryList(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static <T> Stream<T> valuesForTag(World world, TagKey<T> key) {
|
|
|
|
return entriesForTag(world, key).stream().map(RegistryEntry::value);
|
2020-06-26 11:44:47 +02:00
|
|
|
}
|
|
|
|
}
|