001package net.minecraftforge.common; 002 003import java.lang.reflect.Constructor; 004import java.util.*; 005 006import cpw.mods.fml.common.FMLCommonHandler; 007import cpw.mods.fml.common.FMLLog; 008import cpw.mods.fml.common.Mod; 009import cpw.mods.fml.common.ModContainer; 010 011import net.minecraft.block.Block; 012import net.minecraft.block.material.Material; 013import net.minecraft.entity.monster.EntityEnderman; 014import net.minecraft.item.Item; 015import net.minecraft.item.ItemStack; 016import net.minecraftforge.common.ForgeHooks.GrassEntry; 017import net.minecraftforge.common.ForgeHooks.SeedEntry; 018import net.minecraftforge.event.EventBus; 019import net.minecraftforge.event.ForgeSubscribe; 020import net.minecraftforge.event.entity.EntityEvent; 021import net.minecraftforge.oredict.OreDictionary; 022 023public class MinecraftForge 024{ 025 /** 026 * The core Forge EventBusses, all events for Forge will be fired on these, 027 * you should use this to register all your listeners. 028 * This replaces every register*Handler() function in the old version of Forge. 029 * TERRAIN_GEN_BUS for terrain gen events 030 * ORE_GEN_BUS for ore gen events 031 * EVENT_BUS for everything else 032 */ 033 public static final EventBus EVENT_BUS = new EventBus(); 034 public static final EventBus TERRAIN_GEN_BUS = new EventBus(); 035 public static final EventBus ORE_GEN_BUS = new EventBus(); 036 @Deprecated //Vanilla feature now 037 public static boolean SPAWNER_ALLOW_ON_INVERTED = false; 038 039 private static final ForgeInternalHandler INTERNAL_HANDLER = new ForgeInternalHandler(); 040 041 042 /** Register a new plant to be planted when bonemeal is used on grass. 043 * @param block The block to place. 044 * @param metadata The metadata to set for the block when being placed. 045 * @param weight The weight of the plant, where red flowers are 046 * 10 and yellow flowers are 20. 047 */ 048 public static void addGrassPlant(Block block, int metadata, int weight) 049 { 050 ForgeHooks.grassList.add(new GrassEntry(block, metadata, weight)); 051 } 052 053 /** 054 * Register a new seed to be dropped when breaking tall grass. 055 * 056 * @param seed The item to drop as a seed. 057 * @param weight The relative probability of the seeds, 058 * where wheat seeds are 10. 059 */ 060 public static void addGrassSeed(ItemStack seed, int weight) 061 { 062 ForgeHooks.seedList.add(new SeedEntry(seed, weight)); 063 } 064 065 /** 066 * 067 * Register a tool as a tool class with a given harvest level. 068 * 069 * @param tool The custom tool to register. 070 * @param toolClass The tool class to register as. The predefined tool 071 * clases are "pickaxe", "shovel", "axe". You can add 072 * others for custom tools. 073 * @param harvestLevel The harvest level of the tool. 074 */ 075 public static void setToolClass(Item tool, String toolClass, int harvestLevel) 076 { 077 ForgeHooks.toolClasses.put(tool, Arrays.asList(toolClass, harvestLevel)); 078 } 079 080 /** 081 * Register a block to be harvested by a tool class. This is the metadata 082 * sensitive version, use it if your blocks are using metadata variants. 083 * By default, this sets the block class as effective against that type. 084 * 085 * @param block The block to register. 086 * @param metadata The metadata for the block subtype. 087 * @param toolClass The tool class to register as able to remove this block. 088 * You may register the same block multiple times with different tool 089 * classes, if multiple tool types can be used to harvest this block. 090 * @param harvestLevel The minimum tool harvest level required to successfully 091 * harvest the block. 092 * @see MinecraftForge#setToolClass for details on tool classes. 093 */ 094 public static void setBlockHarvestLevel(Block block, int metadata, String toolClass, int harvestLevel) 095 { 096 List key = Arrays.asList(block, metadata, toolClass); 097 ForgeHooks.toolHarvestLevels.put(key, harvestLevel); 098 ForgeHooks.toolEffectiveness.add(key); 099 } 100 101 /** 102 * Remove a block effectiveness mapping. Since setBlockHarvestLevel 103 * makes the tool class effective against the block by default, this can be 104 * used to remove that mapping. This will force a block to be harvested at 105 * the same speed regardless of tool quality, while still requiring a given 106 * harvesting level. 107 * 108 * @param block The block to remove effectiveness from. 109 * @param metadata The metadata for the block subtype. 110 * @param toolClass The tool class to remove the effectiveness mapping from. 111 * @see MinecraftForge#setToolClass for details on tool classes. 112 */ 113 public static void removeBlockEffectiveness(Block block, int metadata, String toolClass) 114 { 115 List key = Arrays.asList(block, metadata, toolClass); 116 ForgeHooks.toolEffectiveness.remove(key); 117 } 118 119 /** 120 * Register a block to be harvested by a tool class. 121 * By default, this sets the block class as effective against that type. 122 * 123 * @param block The block to register. 124 * @param toolClass The tool class to register as able to remove this block. 125 * You may register the same block multiple times with different tool 126 * classes, if multiple tool types can be used to harvest this block. 127 * @param harvestLevel The minimum tool harvest level required to successfully 128 * harvest the block. 129 * @see MinecraftForge#setToolClass for details on tool classes. 130 */ 131 public static void setBlockHarvestLevel(Block block, String toolClass, int harvestLevel) 132 { 133 for (int metadata = 0; metadata < 16; metadata++) 134 { 135 List key = Arrays.asList(block, metadata, toolClass); 136 ForgeHooks.toolHarvestLevels.put(key, harvestLevel); 137 ForgeHooks.toolEffectiveness.add(key); 138 } 139 } 140 141 /** 142 * Returns the block harvest level for a particular tool class. 143 * 144 * @param block The block to check. 145 * @param metadata The metadata for the block subtype. 146 * @param toolClass The tool class to check as able to remove this block. 147 * @see MinecraftForge#setToolClass for details on tool classes. 148 * @return The harvest level or -1 if no mapping exists. 149 */ 150 public static int getBlockHarvestLevel(Block block, int metadata, String toolClass) 151 { 152 ForgeHooks.initTools(); 153 List key = Arrays.asList(block, metadata, toolClass); 154 Integer harvestLevel = ForgeHooks.toolHarvestLevels.get(key); 155 return (harvestLevel == null ? -1 : harvestLevel); 156 } 157 158 /** 159 * Remove a block effectiveness mapping. Since setBlockHarvestLevel 160 * makes the tool class effective against the block by default, this can be 161 * used to remove that mapping. This will force a block to be harvested at 162 * the same speed regardless of tool quality, while still requiring a given 163 * harvesting level. 164 * 165 * @param block The block to remove effectiveness from. 166 * @param toolClass The tool class to remove the effectiveness mapping from. 167 * @see MinecraftForge#setToolClass for details on tool classes. 168 */ 169 public static void removeBlockEffectiveness(Block block, String toolClass) 170 { 171 for (int metadata = 0; metadata < 16; metadata++) 172 { 173 List key = Arrays.asList(block, metadata, toolClass); 174 ForgeHooks.toolEffectiveness.remove(key); 175 } 176 } 177 178 /** 179 * Method invoked by FML before any other mods are loaded. 180 */ 181 public static void initialize() 182 { 183 System.out.printf("MinecraftForge v%s Initialized\n", ForgeVersion.getVersion()); 184 FMLLog.info("MinecraftForge v%s Initialized", ForgeVersion.getVersion()); 185 186 Block filler = new Block(0, Material.air); 187 Block.blocksList[0] = null; 188 Block.opaqueCubeLookup[0] = false; 189 Block.lightOpacity[0] = 0; 190 191 for (int x = 256; x < 4096; x++) 192 { 193 if (Item.itemsList[x] != null) 194 { 195 Block.blocksList[x] = filler; 196 } 197 } 198 199 boolean[] temp = new boolean[4096]; 200 System.arraycopy(EntityEnderman.carriableBlocks, 0, temp, 0, EntityEnderman.carriableBlocks.length); 201 EntityEnderman.carriableBlocks = temp; 202 203 EVENT_BUS.register(INTERNAL_HANDLER); 204 OreDictionary.getOreName(0); 205 } 206 207 public static String getBrandingVersion() 208 { 209 return "Minecraft Forge "+ ForgeVersion.getVersion(); 210 } 211}