content: package com.mekeng.github.common;
  
  import appeng.block.AEBaseItemBlock;
  import appeng.block.AEBaseTileBlock;
  import appeng.core.features.ActivityState;
  import appeng.core.features.BlockStackSrc;
  import appeng.tile.AEBaseTile;
  import com.mekeng.github.MekEng;
  import net.minecraft.block.Block;
  import net.minecraft.item.Item;
  import net.minecraft.tileentity.TileEntity;
  import net.minecraftforge.event.RegistryEvent;
  import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  import net.minecraftforge.fml.common.registry.ForgeRegistries;
  import net.minecraftforge.fml.common.registry.GameRegistry;
  import org.apache.commons.lang3.tuple.Pair;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class RegistryHandler {
  
      protected final List<Pair<String, Block>> blocks = new ArrayList<>();
      protected final List<Pair<String, Item>> items = new ArrayList<>();
      protected final List<Pair<String, Class<? extends TileEntity>>> tiles = new ArrayList<>();
  
      public void block(String name, Block block) {
          blocks.add(Pair.of(name, block));
      }
  
      public void item(String name, Item item) {
          items.add(Pair.of(name, item));
      }
  
      public void block(String name, Block block, Class<? extends TileEntity> tile) {
          blocks.add(Pair.of(name, block));
          tiles.add(Pair.of(name, tile));
      }
  
      @SubscribeEvent
      public void onRegisterBlocks(RegistryEvent.Register<Block> event) {
          for (Pair<String, Block> entry : blocks) {
              String key = entry.getLeft();
              Block block = entry.getRight();
              block.setRegistryName(key);
              block.setTranslationKey(MekEng.MODID + ":" + key);
              block.setCreativeTab(ItemAndBlocks.TAB);
              event.getRegistry().register(block);
          }
      }
  
      @SubscribeEvent
      public void onRegisterItems(RegistryEvent.Register<Item> event) {
          // TODO some way to handle blocks with custom ItemBlock
          for (Pair<String, Block> entry : blocks) {
              event.getRegistry().register(initItem(entry.getLeft(), new AEBaseItemBlock(entry.getRight())));
          }
          for (Pair<String, Item> entry : items) {
              event.getRegistry().register(initItem(entry.getLeft(), entry.getRight()));
          }
      }
  
      private static Item initItem(String key, Item item) {
          item.setRegistryName(key);
          item.setTranslationKey(MekEng.MODID + ":" + key);
          item.setCreativeTab(ItemAndBlocks.TAB);
          return item;
      }
  
      public void onInit() {
          for (Pair<String, Class<? extends TileEntity>> entry : tiles) {
              GameRegistry.registerTileEntity(entry.getRight(), MekEng.id(entry.getLeft()));
          }
          for (Pair<String, Block> entry : blocks) {
              Block block = ForgeRegistries.BLOCKS.getValue(MekEng.id(entry.getKey()));
              if (block instanceof AEBaseTileBlock) {
                  AEBaseTile.registerTileItem(((AEBaseTileBlock)block).getTileEntityClass(), new BlockStackSrc(block, 0, ActivityState.Enabled));
              }
          }
      }
  
  }
  