Skip to content

Commit

Permalink
refactor(next): registry
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Sep 27, 2022
1 parent 6c5f3d2 commit 2987d53
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
Expand Up @@ -6,8 +6,8 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.auioc.mcmod.arnicalib.base.random.RandomUtils;
import org.auioc.mcmod.arnicalib.game.registry.OrderedForgeRegistries;
import org.auioc.mcmod.arnicalib.game.registry.RegistryEntryException;
import org.auioc.mcmod.arnicalib.utils.game.OrderedForgeRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
Expand Down

This file was deleted.

@@ -1,4 +1,4 @@
package org.auioc.mcmod.arnicalib.utils.game;
package org.auioc.mcmod.arnicalib.game.registry;

import static org.auioc.mcmod.arnicalib.ArnicaLib.LOGGER;
import java.util.ArrayList;
Expand Down Expand Up @@ -30,20 +30,20 @@

public class OrderedForgeRegistries {

private static final Marker MARKER = LogUtil.getMarker("OrderedForgeRegistries");
private static final Marker MARKER = LogUtil.getMarker(OrderedForgeRegistries.class);

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));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Block>>> BLOCKS = new LazyObjectHolder<>(() -> create(ForgeRegistries.BLOCKS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Fluid>>> FLUIDS = new LazyObjectHolder<>(() -> create(ForgeRegistries.FLUIDS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Item>>> ITEMS = new LazyObjectHolder<>(() -> create(ForgeRegistries.ITEMS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, SoundEvent>>> SOUND_EVENTS = new LazyObjectHolder<>(() -> create(ForgeRegistries.SOUND_EVENTS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, MobEffect>>> MOB_EFFECTS = new LazyObjectHolder<>(() -> create(ForgeRegistries.MOB_EFFECTS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Potion>>> POTIONS = new LazyObjectHolder<>(() -> create(ForgeRegistries.POTIONS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, Enchantment>>> ENCHANTMENTS = new LazyObjectHolder<>(() -> create(ForgeRegistries.ENCHANTMENTS));
public static final LazyObjectHolder<List<Entry<ResourceLocation, EntityType<?>>>> ENTITIES = new LazyObjectHolder<>(() -> create(ForgeRegistries.ENTITIES));
public static final LazyObjectHolder<List<Entry<ResourceLocation, BlockEntityType<?>>>> BLOCK_ENTITIES = new LazyObjectHolder<>(() -> create(ForgeRegistries.BLOCK_ENTITIES));
public static final LazyObjectHolder<List<Entry<ResourceLocation, ParticleType<?>>>> PARTICLE_TYPES = new LazyObjectHolder<>(() -> create(ForgeRegistries.PARTICLE_TYPES));

private static <V extends IForgeRegistryEntry<V>> List<Entry<ResourceLocation, V>> createEntryList(IForgeRegistry<V> iRegistry) {
private static <V extends IForgeRegistryEntry<V>> List<Entry<ResourceLocation, V>> create(IForgeRegistry<V> iRegistry) {
Validate.isTrue(iRegistry instanceof IForgeRegistryModifiable, "Only supports IForgeRegistryModifiable");

IForgeRegistryModifiable<V> registry = (IForgeRegistryModifiable<V>) iRegistry;
Expand Down
@@ -1,12 +1,11 @@
package org.auioc.mcmod.arnicalib.utils.game;
package org.auioc.mcmod.arnicalib.game.registry;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import org.auioc.mcmod.arnicalib.game.registry.IHRegistry;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.RegistryObject;
Expand All @@ -21,10 +20,10 @@ public static <T extends IForgeRegistryEntry<T>> List<T> getAllRegistryObjects(D

/**
* For special use only,
* please use {@link org.auioc.mcmod.arnicalib.utils.game.RegistryUtils#getAllRegistryObjects(DeferredRegister)} instead generally.
* please use {@link org.auioc.mcmod.arnicalib.game.registry.RegistryUtils#getAllRegistryObjects(DeferredRegister)} instead generally.
*/
@SuppressWarnings("unchecked")
public static <T extends IForgeRegistryEntry<? super T>> List<T> getAllRegistryObjects(Class<? extends IHRegistry> clazz, Class<T> type) {
public static <T extends IForgeRegistryEntry<? super T>> List<T> getAllRegistryObjects(Class<?> clazz, Class<T> type) {
List<T> list = new ArrayList<T>();

Field[] fields = clazz.getDeclaredFields();
Expand Down
Expand Up @@ -4,8 +4,8 @@
import java.util.List;
import org.auioc.mcmod.arnicalib.base.random.RandomUtils;
import org.auioc.mcmod.arnicalib.base.validate.Validate;
import org.auioc.mcmod.arnicalib.game.registry.OrderedForgeRegistries;
import org.auioc.mcmod.arnicalib.mod.server.loot.AHLootItemFunctions;
import org.auioc.mcmod.arnicalib.utils.game.OrderedForgeRegistries;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
Expand Down

0 comments on commit 2987d53

Please sign in to comment.