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