/** * Register a block with the world, with the specified item class, block name and owning modId * @param block The block to register * @param itemclass The iterm type to register with it * @param name The mod-unique name to register it with * @param modId The modId that will own the block name. null defaults to the active modId */ public static void registerBlock(net.minecraft.block.Block block, Class<? extends ItemBlock> itemclass, String name, String modId) { if (Loader.instance().isInState(LoaderState.CONSTRUCTING)) { FMLLog.warning("The mod %s is attempting to register a block whilst it it being constructed. This is bad modding practice - please use a proper mod lifecycle event.", Loader.instance().activeModContainer()); } try { assert block != null : "registerBlock: block cannot be null"; assert itemclass != null : "registerBlock: itemclass cannot be null"; int blockItemId = block.field_71990_ca - 256; Constructor<? extends ItemBlock> itemCtor; Item i; try { itemCtor = itemclass.getConstructor(int.class); i = itemCtor.newInstance(blockItemId); } catch (NoSuchMethodException e) { itemCtor = itemclass.getConstructor(int.class, net.minecraft.block.Block.class); i = itemCtor.newInstance(blockItemId, block); } GameRegistry.registerItem(i,name, modId); } catch (Exception e) { FMLLog.log(Level.SEVERE, e, "Caught an exception during block registration"); throw new LoaderException(e); } blockRegistry.put(Loader.instance().activeModContainer(), (BlockProxy) block); }
/** * Register a block with the world, with the specified item class, block name and owning modId * @param block The block to register * @param itemclass The iterm type to register with it * @param name The mod-unique name to register it with * @param modId The modId that will own the block name. null defaults to the active modId */ public static void registerBlock(net.minecraft.block.Block block, Class<? extends ItemBlock> itemclass, String name, String modId) { if (Loader.instance().isInState(LoaderState.CONSTRUCTING)) { FMLLog.warning("The mod %s is attempting to register a block whilst it it being constructed. This is bad modding practice - please use a proper mod lifecycle event.", Loader.instance().activeModContainer()); } try { assert block != null : "registerBlock: block cannot be null"; assert itemclass != null : "registerBlock: itemclass cannot be null"; int blockItemId = block.blockID - 256; Constructor<? extends ItemBlock> itemCtor; Item i; try { itemCtor = itemclass.getConstructor(int.class); i = itemCtor.newInstance(blockItemId); } catch (NoSuchMethodException e) { itemCtor = itemclass.getConstructor(int.class, net.minecraft.block.Block.class); i = itemCtor.newInstance(blockItemId, block); } GameRegistry.registerItem(i,name, modId); } catch (Exception e) { FMLLog.log(Level.SEVERE, e, "Caught an exception during block registration"); throw new LoaderException(e); } blockRegistry.put(Loader.instance().activeModContainer(), (BlockProxy) block); }
/** * Register a block with the world * */ @Deprecated public static void registerBlock(net.minecraft.block.Block block) { registerBlock(block, ItemBlock.class); }
/** * Internal method for creating an @Block instance * @param container * @param type * @param annotation * @throws Exception */ public static Object buildBlock(ModContainer container, Class<?> type, Block annotation) throws Exception { Object o = type.getConstructor(int.class).newInstance(findSpareBlockId()); registerBlock((net.minecraft.block.Block) o); return o; }
/** * Register a block with the specified mod specific name : overrides the standard type based name * @param block The block to register * @param name The mod-unique name to register it as */ public static void registerBlock(net.minecraft.block.Block block, String name) { registerBlock(block, ItemBlock.class, name); }
/** * Register a block with the world, with the specified item class * * Deprecated in favour of named versions * * @param block The block to register * @param itemclass The item type to register with it */ @Deprecated public static void registerBlock(net.minecraft.block.Block block, Class<? extends ItemBlock> itemclass) { registerBlock(block, itemclass, null); }
/** * Register a block with the world, with the specified item class and block name * @param block The block to register * @param itemclass The item type to register with it * @param name The mod-unique name to register it with */ public static void registerBlock(net.minecraft.block.Block block, Class<? extends ItemBlock> itemclass, String name) { registerBlock(block, itemclass, name, null); }
/** * Look up a mod block in the global "named item list" * @param modId The modid owning the block * @param name The name of the block itself * @return The block or null if not found */ public static net.minecraft.block.Block findBlock(String modId, String name) { return GameData.findBlock(modId, name); }
/** * Look up the mod identifier data for a block. * Returns null if there is no mod specified mod identifier data, or it is part of a * custom itemstack definition {@link #registerCustomItemStack} * * Note: uniqueness and persistence is only guaranteed by mods using the game registry * correctly. * * @param block to lookup * @return a {@link UniqueIdentifier} for the block or null */ public static UniqueIdentifier findUniqueIdentifierFor(net.minecraft.block.Block block) { return GameData.getUniqueName(block); }