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