Search in sources :

Example 1 with RegBlock

use of cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.RegBlock in project FoodCraft-Reloaded by LasmGratel.

the class BlockLoader method registerBlocks.

@Load(value = LoaderState.CONSTRUCTING)
public void registerBlocks() {
    for (Field field : FCRBlocks.class.getFields()) {
        field.setAccessible(true);
        RegBlock anno = field.getAnnotation(RegBlock.class);
        if (anno == null)
            continue;
        try {
            Block block = (Block) field.get(null);
            RegisterManager.getInstance().putRegister(block.setRegistryName(NameBuilder.buildRegistryName(anno.value())).setUnlocalizedName(NameBuilder.buildUnlocalizedName(anno.value())));
            // Register item block.
            Class<? extends ItemBlock> itemClass = anno.itemClass();
            Constructor<? extends ItemBlock> con = itemClass.getConstructor(Block.class);
            con.setAccessible(true);
            RegisterManager.getInstance().putRegister(con.newInstance(block).setRegistryName(block.getRegistryName()).setUnlocalizedName(block.getUnlocalizedName()));
            Arrays.asList(anno.oreDict()).forEach(s -> OreDictionary.registerOre(s, block));
        } catch (Exception e) {
            FoodCraftReloaded.getLogger().warn("Un-able to register block " + field.toGenericString(), e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) RegBlock(cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.RegBlock) RegBlock(cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.RegBlock) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) Load(cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.Load)

Example 2 with RegBlock

use of cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.RegBlock in project FoodCraft-Reloaded by LasmGratel.

the class BlockLoader method registerRenders.

@Load(side = Side.CLIENT)
public void registerRenders() {
    for (Field field : FCRBlocks.class.getFields()) {
        field.setAccessible(true);
        RegBlock anno = field.getAnnotation(RegBlock.class);
        if (anno == null)
            continue;
        try {
            Block block = (Block) field.get(null);
            if (block instanceof CustomModelMasking) {
                ModelLoader.setCustomStateMapper(block, b -> ((CustomModelMasking) b).getStateModelLocations());
                if (((CustomModelMasking) block).getModelLocation() != null) {
                    registerRender(Item.getItemFromBlock(block), 0, ((CustomModelMasking) block).getModelLocation());
                    return;
                }
            }
            registerRender(block, 0);
        } catch (Exception e) {
            FoodCraftReloaded.getLogger().warn("Un-able to register block " + field.toGenericString(), e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) RegBlock(cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.RegBlock) CustomModelMasking(cc.lasmgratel.foodcraftreloaded.minecraft.client.util.masking.CustomModelMasking) RegBlock(cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.RegBlock) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) Load(cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.Load)

Aggregations

Load (cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.Load)2 RegBlock (cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.RegBlock)2 Field (java.lang.reflect.Field)2 Block (net.minecraft.block.Block)2 ItemBlock (net.minecraft.item.ItemBlock)2 CustomModelMasking (cc.lasmgratel.foodcraftreloaded.minecraft.client.util.masking.CustomModelMasking)1