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