package com.dairymoose.modernlife.core;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/* loaded from: outputsrg.jar:com/dairymoose/modernlife/core/AutoRegisterProcessor.class */
public class AutoRegisterProcessor {
    private static final Logger LOGGER = LogManager.getLogger();
    private static Map<String, Block> blockInstances = new HashMap();

    public static void processAnnotations(DeferredRegister<Block> BLOCKS, DeferredRegister<Item> ITEMS, Class cls) {
        int registerBlockCount = 0;
        int registerItemCount = 0;
        new HashMap();
        Field[] soundTypeFields = SoundType.class.getDeclaredFields();
        for (Field field : soundTypeFields) {
            if (SoundType.class.isAssignableFrom(field.getType())) {
            }
        }
        new HashMap();
        Field[] itemGroupFields = CreativeModeTab.class.getDeclaredFields();
        for (Field field2 : itemGroupFields) {
            if (CreativeModeTab.class.isAssignableFrom(field2.getType())) {
            }
        }
        new HashMap();
        Field[] materialFields = Material.class.getDeclaredFields();
        for (Field field3 : materialFields) {
            if (Material.class.isAssignableFrom(field3.getType())) {
            }
        }
        new HashMap();
        Field[] inheritBlockFields = Blocks.class.getDeclaredFields();
        for (Field field4 : inheritBlockFields) {
            if (Block.class.isAssignableFrom(field4.getType())) {
            }
        }
        Field[] fields = cls.getDeclaredFields();
        for (Field f : fields) {
            AutoRegister autoReg = (AutoRegister) f.getDeclaredAnnotation(AutoRegister.class);
            if (autoReg != null) {
                if (RegistryObject.class.isAssignableFrom(f.getType()) && (f.getGenericType() instanceof ParameterizedType) && Block.class.getTypeName().equals(((ParameterizedType) f.getGenericType()).getActualTypeArguments()[0].getTypeName())) {
                    Block blockInstance = null;
                    autoReg.blockClass();
                    try {
                        blockInstance = (Block) ((RegistryObject) f.get(null)).get();
                    } catch (IllegalAccessException | IllegalArgumentException e1) {
                        ModernLifeCommon.LOGGER.error("Error getting block instance", e1);
                    }
                    if (blockInstance == null) {
                        ModernLifeCommon.LOGGER.error("blockInstance is null");
                    } else {
                        blockInstances.put(autoReg.name(), blockInstance);
                        ModernLifeCommon.LOGGER.debug("Registered block: " + autoReg.name());
                        registerBlockCount++;
                    }
                } else if (RegistryObject.class.isAssignableFrom(f.getType()) && (f.getGenericType() instanceof ParameterizedType) && Item.class.getTypeName().equals(((ParameterizedType) f.getGenericType()).getActualTypeArguments()[0].getTypeName())) {
                    autoReg.blockClass();
                    try {
                        ((RegistryObject) f.get(null)).get();
                    } catch (IllegalAccessException | IllegalArgumentException e12) {
                        ModernLifeCommon.LOGGER.error("Error getting item instance", e12);
                    }
                    registerItemCount++;
                } else {
                    ModernLifeCommon.LOGGER.error("Not assignable: " + f.getType());
                }
            }
        }
        ModernLifeCommon.LOGGER.debug("Registered " + registerBlockCount + " blocks");
        ModernLifeCommon.LOGGER.debug("Registered " + registerItemCount + " items");
    }

    public static void processRenderTypes(Class cls) {
        RenderType renderType;
        int renderTypeCount = 0;
        Map<String, RenderType> renderTypes = new HashMap<>();
        Method[] renderTypeMethods = RenderType.class.getDeclaredMethods();
        int i = 0;
        while (i < renderTypeMethods.length) {
            Method m = renderTypeMethods[i];
            i = (m.getReturnType() != RenderType.class || m.getParameterCount() == 0) ? i + 1 : i + 1;
        }
        renderTypes.put("solid", RenderType.solid());
        renderTypes.put("translucent", RenderType.translucent());
        renderTypes.put("cutout", RenderType.cutout());
        renderTypes.put("cutoutmipped", RenderType.cutoutMipped());
        Field[] fields = cls.getDeclaredFields();
        for (Field f : fields) {
            AutoRegister autoReg = (AutoRegister) f.getDeclaredAnnotation(AutoRegister.class);
            if (autoReg != null && !autoReg.renderType().isEmpty() && (renderType = renderTypes.get(autoReg.renderType().toLowerCase())) != null) {
                renderTypeCount++;
                Block blockInstance = blockInstances.get(autoReg.name());
                if (blockInstance == null) {
                    ModernLifeCommon.LOGGER.error("blockInstance was null for " + autoReg.name());
                } else {
                    ItemBlockRenderTypes.setRenderLayer(blockInstance, renderType);
                }
            }
        }
        ModernLifeCommon.LOGGER.debug("Set " + renderTypeCount + " render types");
    }
}
