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