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