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