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);
}
}
}
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);
}
}
}
Aggregations