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