-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrderedForgeRegistries.java
68 lines (55 loc) · 4.09 KB
/
OrderedForgeRegistries.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.auioc.mcmod.arnicalib.utils.game;
import static org.auioc.mcmod.arnicalib.ArnicaLib.LOGGER;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.logging.log4j.Marker;
import org.auioc.mcmod.arnicalib.api.java.holder.LazyObjectHolder;
import org.auioc.mcmod.arnicalib.utils.LogUtil;
import org.auioc.mcmod.arnicalib.utils.java.Validate;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.alchemy.Potion;
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.material.Fluid;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.IForgeRegistryModifiable;
public class OrderedForgeRegistries {
private static final Marker MARKER = LogUtil.getMarker("OrderedForgeRegistries");
public static final LazyObjectHolder<List<Entry<ResourceLocation, Block>>> BLOCKS = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.BLOCKS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Fluid>>> FLUIDS = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.FLUIDS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Item>>> ITEMS = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.ITEMS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, SoundEvent>>> SOUND_EVENTS = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.SOUND_EVENTS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, MobEffect>>> MOB_EFFECTS = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.MOB_EFFECTS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Potion>>> POTIONS = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.POTIONS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Enchantment>>> ENCHANTMENTS = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.ENCHANTMENTS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, EntityType<?>>>> ENTITIES = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.ENTITIES));
public static final LazyObjectHolder<List<Entry<ResourceLocation, BlockEntityType<?>>>> BLOCK_ENTITIES = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.BLOCK_ENTITIES));
public static final LazyObjectHolder<List<Entry<ResourceLocation, ParticleType<?>>>> PARTICLE_TYPES = new LazyObjectHolder<>(() -> createEntryList(ForgeRegistries.PARTICLE_TYPES));
private static <V extends IForgeRegistryEntry<V>> List<Entry<ResourceLocation, V>> createEntryList(IForgeRegistry<V> iRegistry) {
Validate.isTrue(iRegistry instanceof IForgeRegistryModifiable, "Only supports IForgeRegistryModifiable");
IForgeRegistryModifiable<V> registry = (IForgeRegistryModifiable<V>) iRegistry;
ResourceLocation name = registry.getRegistryName();
LOGGER.info(MARKER, "Creating entry list of registry '" + name + "'");
Validate.isTrue(registry.isLocked(), "The entry list can only be created from a frozen registry");
List<Entry<ResourceLocation, V>> list = new ArrayList<Entry<ResourceLocation, V>>();
Iterator<Entry<ResourceKey<V>, V>> iterator = registry.getEntries().iterator();
while (iterator.hasNext()) {
Entry<ResourceKey<V>, V> entry = iterator.next();
list.add(Map.entry(entry.getKey().location(), entry.getValue()));
}
LOGGER.info(MARKER, "Created entry list of registry '" + name + "'' with " + list.size() + " entries");
return List.copyOf(list);
}
}