Search in sources :

Example 6 with BlockTile

use of com.builtbroken.mc.prefab.tile.BlockTile in project Engine by VoltzEngine-Project.

the class ModManager method newBlock.

/**
     * Creates a new block based on the Tile class provided
     * Handles most common registration and data input tasks for the creation of the block.
     * This includes registering the block, tile, built in item & tile renders. It also inits
     * the instance used for the block itself.
     *
     * @param spatialClass - class that will provide all the data to be used when creating the block.
     * @param args         - arguments needed to create a new instance of the spatial class
     */
public BlockTile newBlock(String name, Class<? extends Tile> spatialClass, Object... args) {
    try {
        Tile spatial;
        if (args != null && args.length > 0) {
            List<Class> paramTypes = new ArrayList();
            for (Object arg : args) {
                paramTypes.add(arg.getClass());
            }
            spatial = spatialClass.getConstructor(paramTypes.toArray(new Class[paramTypes.size()])).newInstance();
        } else {
            spatial = spatialClass.newInstance();
        }
        return newBlock(name, spatial);
    } catch (Exception e) {
        throw new RuntimeException(name() + " Tile [" + spatialClass.getSimpleName() + "] failed to be created:", e);
    }
}
Also used : ArrayList(java.util.ArrayList) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)6 Tile (com.builtbroken.mc.prefab.tile.Tile)5 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Item (net.minecraft.item.Item)1 ItemBlock (net.minecraft.item.ItemBlock)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 ChatComponentText (net.minecraft.util.ChatComponentText)1