2012-08-06 00:59:53 +00:00
package net.minecraftforge.oredict ;
2012-08-01 23:35:35 +00:00
import java.util.ArrayList ;
2014-06-11 01:05:09 +00:00
import java.util.Collections ;
2012-08-01 23:35:35 +00:00
import java.util.HashMap ;
2014-06-11 01:05:09 +00:00
import java.util.HashSet ;
2012-08-01 23:35:35 +00:00
import java.util.List ;
import java.util.Map ;
2014-06-11 01:05:09 +00:00
import java.util.Set ;
2012-08-01 23:35:35 +00:00
2016-04-07 18:49:31 +00:00
import net.minecraft.block.BlockPrismarine ;
2015-11-28 08:01:31 +00:00
import net.minecraft.util.ResourceLocation ;
2015-10-29 16:46:12 +00:00
import org.apache.logging.log4j.Level ;
2012-12-13 07:27:57 +00:00
import net.minecraft.block.Block ;
2013-12-10 05:59:12 +00:00
import net.minecraft.init.Blocks ;
import net.minecraft.init.Items ;
2012-12-13 07:27:57 +00:00
import net.minecraft.item.Item ;
import net.minecraft.item.ItemStack ;
import net.minecraft.item.crafting.CraftingManager ;
import net.minecraft.item.crafting.IRecipe ;
import net.minecraft.item.crafting.ShapedRecipes ;
import net.minecraft.item.crafting.ShapelessRecipes ;
2012-08-06 00:59:53 +00:00
import net.minecraftforge.common.MinecraftForge ;
2012-08-01 23:35:35 +00:00
2014-12-07 09:17:48 +00:00
import com.google.common.collect.ImmutableList ;
2014-06-11 01:05:09 +00:00
import com.google.common.collect.Lists ;
import com.google.common.collect.Maps ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
import net.minecraftforge.fml.common.FMLLog ;
2015-11-10 23:35:38 +00:00
import net.minecraftforge.fml.common.Loader ;
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
import net.minecraftforge.fml.common.eventhandler.Event ;
2015-11-10 23:35:38 +00:00
import net.minecraftforge.fml.common.registry.GameData ;
2014-06-11 01:05:09 +00:00
2012-08-01 23:35:35 +00:00
public class OreDictionary
{
2012-11-13 01:07:33 +00:00
private static boolean hasInit = false ;
2014-06-11 01:05:09 +00:00
private static List < String > idToName = new ArrayList < String > ( ) ;
2016-01-21 21:41:26 +00:00
private static Map < String , Integer > nameToId = new HashMap < String , Integer > ( 128 ) ;
2014-12-07 09:17:48 +00:00
private static List < List < ItemStack > > idToStack = Lists . newArrayList ( ) ;
private static List < List < ItemStack > > idToStackUn = Lists . newArrayList ( ) ;
2016-01-21 21:41:26 +00:00
private static Map < Integer , List < Integer > > stackToId = Maps . newHashMapWithExpectedSize ( ( int ) ( 128 * 0 . 75 ) ) ;
2014-12-07 09:17:48 +00:00
public static final ImmutableList < ItemStack > EMPTY_LIST = ImmutableList . of ( ) ;
2013-03-11 21:43:23 +00:00
/ * *
* Minecraft changed from - 1 to Short . MAX_VALUE in 1 . 5 release for the " block wildcard " . Use this in case it
* changes again .
* /
public static final int WILDCARD_VALUE = Short . MAX_VALUE ;
2012-10-28 14:24:01 +00:00
static {
initVanillaEntries ( ) ;
}
2016-03-22 02:57:59 +00:00
private static void initVanillaEntries ( )
2012-11-06 00:15:43 +00:00
{
2012-11-13 01:07:33 +00:00
if ( ! hasInit )
{
2016-04-07 18:49:31 +00:00
// tree- and wood-related things
2013-12-10 05:59:12 +00:00
registerOre ( " logWood " , new ItemStack ( Blocks . log , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " logWood " , new ItemStack ( Blocks . log2 , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " plankWood " , new ItemStack ( Blocks . planks , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " slabWood " , new ItemStack ( Blocks . wooden_slab , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " stairWood " , Blocks . oak_stairs ) ;
registerOre ( " stairWood " , Blocks . spruce_stairs ) ;
registerOre ( " stairWood " , Blocks . birch_stairs ) ;
registerOre ( " stairWood " , Blocks . jungle_stairs ) ;
registerOre ( " stairWood " , Blocks . acacia_stairs ) ;
registerOre ( " stairWood " , Blocks . dark_oak_stairs ) ;
registerOre ( " stickWood " , Items . stick ) ;
registerOre ( " treeSapling " , new ItemStack ( Blocks . sapling , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " treeLeaves " , new ItemStack ( Blocks . leaves , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " treeLeaves " , new ItemStack ( Blocks . leaves2 , 1 , WILDCARD_VALUE ) ) ;
2016-04-07 18:49:31 +00:00
registerOre ( " vine " , Blocks . vine ) ;
// Ores
2013-12-10 05:59:12 +00:00
registerOre ( " oreGold " , Blocks . gold_ore ) ;
registerOre ( " oreIron " , Blocks . iron_ore ) ;
registerOre ( " oreLapis " , Blocks . lapis_ore ) ;
registerOre ( " oreDiamond " , Blocks . diamond_ore ) ;
registerOre ( " oreRedstone " , Blocks . redstone_ore ) ;
registerOre ( " oreEmerald " , Blocks . emerald_ore ) ;
registerOre ( " oreQuartz " , Blocks . quartz_ore ) ;
registerOre ( " oreCoal " , Blocks . coal_ore ) ;
2016-04-07 18:49:31 +00:00
// ingots/nuggets
2014-05-24 20:01:35 +00:00
registerOre ( " ingotIron " , Items . iron_ingot ) ;
registerOre ( " ingotGold " , Items . gold_ingot ) ;
registerOre ( " ingotBrick " , Items . brick ) ;
registerOre ( " ingotBrickNether " , Items . netherbrick ) ;
registerOre ( " nuggetGold " , Items . gold_nugget ) ;
2016-04-07 18:49:31 +00:00
// gems and dusts
2014-02-28 03:48:33 +00:00
registerOre ( " gemDiamond " , Items . diamond ) ;
registerOre ( " gemEmerald " , Items . emerald ) ;
2014-05-24 20:01:35 +00:00
registerOre ( " gemQuartz " , Items . quartz ) ;
2016-04-07 18:49:31 +00:00
registerOre ( " gemPrismarine " , Items . prismarine_shard ) ;
registerOre ( " dustPrismarine " , Items . prismarine_crystals ) ;
2014-02-28 03:48:33 +00:00
registerOre ( " dustRedstone " , Items . redstone ) ;
registerOre ( " dustGlowstone " , Items . glowstone_dust ) ;
2014-06-12 05:43:15 +00:00
registerOre ( " gemLapis " , new ItemStack ( Items . dye , 1 , 4 ) ) ;
2016-04-07 18:49:31 +00:00
// storage blocks
registerOre ( " blockGold " , Blocks . gold_block ) ;
registerOre ( " blockIron " , Blocks . iron_block ) ;
registerOre ( " blockLapis " , Blocks . lapis_block ) ;
registerOre ( " blockDiamond " , Blocks . diamond_block ) ;
registerOre ( " blockRedstone " , Blocks . redstone_block ) ;
registerOre ( " blockEmerald " , Blocks . emerald_block ) ;
registerOre ( " blockQuartz " , Blocks . quartz_block ) ;
registerOre ( " blockCoal " , Blocks . coal_block ) ;
// crops
2014-02-28 03:48:33 +00:00
registerOre ( " cropWheat " , Items . wheat ) ;
registerOre ( " cropPotato " , Items . potato ) ;
registerOre ( " cropCarrot " , Items . carrot ) ;
2016-04-07 18:49:31 +00:00
registerOre ( " cropNetherWart " , Items . nether_wart ) ;
registerOre ( " sugarcane " , Items . reeds ) ;
registerOre ( " blockCactus " , Blocks . cactus ) ;
// misc materials
2014-05-24 20:01:35 +00:00
registerOre ( " dye " , new ItemStack ( Items . dye , 1 , WILDCARD_VALUE ) ) ;
2016-04-07 18:49:31 +00:00
registerOre ( " paper " , new ItemStack ( Items . paper ) ) ;
// mob drops
registerOre ( " slimeball " , Items . slime_ball ) ;
registerOre ( " enderpearl " , Items . ender_pearl ) ;
registerOre ( " bone " , Items . bone ) ;
registerOre ( " gunpowder " , Items . gunpowder ) ;
registerOre ( " string " , Items . string ) ;
registerOre ( " netherStar " , Items . nether_star ) ;
registerOre ( " leather " , Items . leather ) ;
registerOre ( " feather " , Items . feather ) ;
registerOre ( " egg " , Items . egg ) ;
// records
2013-12-10 05:59:12 +00:00
registerOre ( " record " , Items . record_13 ) ;
registerOre ( " record " , Items . record_cat ) ;
registerOre ( " record " , Items . record_blocks ) ;
registerOre ( " record " , Items . record_chirp ) ;
registerOre ( " record " , Items . record_far ) ;
registerOre ( " record " , Items . record_mall ) ;
registerOre ( " record " , Items . record_mellohi ) ;
registerOre ( " record " , Items . record_stal ) ;
registerOre ( " record " , Items . record_strad ) ;
registerOre ( " record " , Items . record_ward ) ;
registerOre ( " record " , Items . record_11 ) ;
registerOre ( " record " , Items . record_wait ) ;
2016-04-07 18:49:31 +00:00
// blocks
registerOre ( " dirt " , Blocks . dirt ) ;
registerOre ( " grass " , Blocks . grass ) ;
registerOre ( " stone " , Blocks . stone ) ;
registerOre ( " cobblestone " , Blocks . cobblestone ) ;
registerOre ( " gravel " , Blocks . gravel ) ;
registerOre ( " sand " , new ItemStack ( Blocks . sand , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " sandstone " , new ItemStack ( Blocks . sandstone , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " sandstone " , new ItemStack ( Blocks . red_sandstone , 1 , WILDCARD_VALUE ) ) ;
registerOre ( " netherrack " , Blocks . netherrack ) ;
registerOre ( " obsidian " , Blocks . obsidian ) ;
registerOre ( " glowstone " , Blocks . glowstone ) ;
registerOre ( " endstone " , Blocks . end_stone ) ;
registerOre ( " torch " , Blocks . torch ) ;
registerOre ( " workbench " , Blocks . crafting_table ) ;
registerOre ( " blockSlime " , Blocks . slime_block ) ;
registerOre ( " blockPrismarine " , new ItemStack ( Blocks . prismarine , 1 , BlockPrismarine . EnumType . ROUGH . getMetadata ( ) ) ) ;
registerOre ( " blockPrismarineBrick " , new ItemStack ( Blocks . prismarine , 1 , BlockPrismarine . EnumType . BRICKS . getMetadata ( ) ) ) ;
registerOre ( " blockPrismarineDark " , new ItemStack ( Blocks . prismarine , 1 , BlockPrismarine . EnumType . DARK . getMetadata ( ) ) ) ;
registerOre ( " stoneGranite " , new ItemStack ( Blocks . stone , 1 , 1 ) ) ;
registerOre ( " stoneGranitePolished " , new ItemStack ( Blocks . stone , 1 , 2 ) ) ;
registerOre ( " stoneDiorite " , new ItemStack ( Blocks . stone , 1 , 3 ) ) ;
registerOre ( " stoneDioritePolished " , new ItemStack ( Blocks . stone , 1 , 4 ) ) ;
registerOre ( " stoneAndesite " , new ItemStack ( Blocks . stone , 1 , 5 ) ) ;
registerOre ( " stoneAndesitePolished " , new ItemStack ( Blocks . stone , 1 , 6 ) ) ;
registerOre ( " blockGlassColorless " , Blocks . glass ) ;
registerOre ( " blockGlass " , Blocks . glass ) ;
registerOre ( " blockGlass " , new ItemStack ( Blocks . stained_glass , 1 , WILDCARD_VALUE ) ) ;
//blockGlass{Color} is added below with dyes
registerOre ( " paneGlassColorless " , Blocks . glass_pane ) ;
registerOre ( " paneGlass " , Blocks . glass_pane ) ;
registerOre ( " paneGlass " , new ItemStack ( Blocks . stained_glass_pane , 1 , WILDCARD_VALUE ) ) ;
//paneGlass{Color} is added below with dyes
// chests
2014-12-23 21:17:44 +00:00
registerOre ( " chest " , Blocks . chest ) ;
registerOre ( " chest " , Blocks . ender_chest ) ;
registerOre ( " chest " , Blocks . trapped_chest ) ;
registerOre ( " chestWood " , Blocks . chest ) ;
registerOre ( " chestEnder " , Blocks . ender_chest ) ;
registerOre ( " chestTrapped " , Blocks . trapped_chest ) ;
2012-11-13 01:07:33 +00:00
}
2012-11-06 00:15:43 +00:00
// Build our list of items to replace with ore tags
Map < ItemStack , String > replacements = new HashMap < ItemStack , String > ( ) ;
2016-04-07 18:49:31 +00:00
// wood-related things
2013-12-10 05:59:12 +00:00
replacements . put ( new ItemStack ( Items . stick ) , " stickWood " ) ;
replacements . put ( new ItemStack ( Blocks . planks ) , " plankWood " ) ;
replacements . put ( new ItemStack ( Blocks . planks , 1 , WILDCARD_VALUE ) , " plankWood " ) ;
2014-12-10 13:18:42 +00:00
replacements . put ( new ItemStack ( Blocks . wooden_slab , 1 , WILDCARD_VALUE ) , " slabWood " ) ;
2016-04-07 18:49:31 +00:00
// ingots/nuggets
2014-05-24 20:01:35 +00:00
replacements . put ( new ItemStack ( Items . gold_ingot ) , " ingotGold " ) ;
replacements . put ( new ItemStack ( Items . iron_ingot ) , " ingotIron " ) ;
2016-04-07 18:49:31 +00:00
// gems and dusts
2014-02-28 03:48:33 +00:00
replacements . put ( new ItemStack ( Items . diamond ) , " gemDiamond " ) ;
replacements . put ( new ItemStack ( Items . emerald ) , " gemEmerald " ) ;
2016-04-07 18:49:31 +00:00
replacements . put ( new ItemStack ( Items . prismarine_shard ) , " gemPrismarine " ) ;
replacements . put ( new ItemStack ( Items . prismarine_crystals ) , " dustPrismarine " ) ;
2014-02-28 03:48:33 +00:00
replacements . put ( new ItemStack ( Items . redstone ) , " dustRedstone " ) ;
2014-02-28 07:54:50 +00:00
replacements . put ( new ItemStack ( Items . glowstone_dust ) , " dustGlowstone " ) ;
2016-04-07 18:49:31 +00:00
// crops
replacements . put ( new ItemStack ( Items . reeds ) , " sugarcane " ) ;
replacements . put ( new ItemStack ( Blocks . cactus ) , " blockCactus " ) ;
// misc materials
replacements . put ( new ItemStack ( Items . paper ) , " paper " ) ;
// mob drops
2014-05-24 20:01:35 +00:00
replacements . put ( new ItemStack ( Items . slime_ball ) , " slimeball " ) ;
2016-04-07 18:49:31 +00:00
replacements . put ( new ItemStack ( Items . string ) , " string " ) ;
replacements . put ( new ItemStack ( Items . leather ) , " leather " ) ;
replacements . put ( new ItemStack ( Items . ender_pearl ) , " enderpearl " ) ;
replacements . put ( new ItemStack ( Items . gunpowder ) , " gunpowder " ) ;
replacements . put ( new ItemStack ( Items . nether_star ) , " netherStar " ) ;
replacements . put ( new ItemStack ( Items . feather ) , " feather " ) ;
replacements . put ( new ItemStack ( Items . bone ) , " bone " ) ;
replacements . put ( new ItemStack ( Items . egg ) , " egg " ) ;
// blocks
replacements . put ( new ItemStack ( Blocks . stone ) , " stone " ) ;
replacements . put ( new ItemStack ( Blocks . cobblestone ) , " cobblestone " ) ;
replacements . put ( new ItemStack ( Blocks . cobblestone , 1 , WILDCARD_VALUE ) , " cobblestone " ) ;
replacements . put ( new ItemStack ( Blocks . glowstone ) , " glowstone " ) ;
2014-05-24 20:01:35 +00:00
replacements . put ( new ItemStack ( Blocks . glass ) , " blockGlassColorless " ) ;
2016-04-07 18:49:31 +00:00
replacements . put ( new ItemStack ( Blocks . prismarine ) , " prismarine " ) ;
replacements . put ( new ItemStack ( Blocks . stone , 1 , 1 ) , " stoneGranite " ) ;
replacements . put ( new ItemStack ( Blocks . stone , 1 , 2 ) , " stoneGranitePolished " ) ;
replacements . put ( new ItemStack ( Blocks . stone , 1 , 3 ) , " stoneDiorite " ) ;
replacements . put ( new ItemStack ( Blocks . stone , 1 , 4 ) , " stoneDioritePolished " ) ;
replacements . put ( new ItemStack ( Blocks . stone , 1 , 5 ) , " stoneAndesite " ) ;
replacements . put ( new ItemStack ( Blocks . stone , 1 , 6 ) , " stoneAndesitePolished " ) ;
// chests
2014-12-23 21:17:44 +00:00
replacements . put ( new ItemStack ( Blocks . chest ) , " chestWood " ) ;
replacements . put ( new ItemStack ( Blocks . ender_chest ) , " chestEnder " ) ;
replacements . put ( new ItemStack ( Blocks . trapped_chest ) , " chestTrapped " ) ;
2012-11-06 00:15:43 +00:00
// Register dyes
2013-03-11 21:43:23 +00:00
String [ ] dyes =
2012-11-06 00:15:43 +00:00
{
2014-05-24 20:01:35 +00:00
" Black " ,
" Red " ,
" Green " ,
" Brown " ,
" Blue " ,
" Purple " ,
" Cyan " ,
" LightGray " ,
" Gray " ,
" Pink " ,
" Lime " ,
" Yellow " ,
" LightBlue " ,
" Magenta " ,
" Orange " ,
" White "
2012-11-06 00:15:43 +00:00
} ;
for ( int i = 0 ; i < 16 ; i + + )
{
2013-12-10 05:59:12 +00:00
ItemStack dye = new ItemStack ( Items . dye , 1 , i ) ;
2014-05-24 20:01:35 +00:00
ItemStack block = new ItemStack ( Blocks . stained_glass , 1 , 15 - i ) ;
ItemStack pane = new ItemStack ( Blocks . stained_glass_pane , 1 , 15 - i ) ;
2012-11-13 01:07:33 +00:00
if ( ! hasInit )
{
2014-05-24 20:01:35 +00:00
registerOre ( " dye " + dyes [ i ] , dye ) ;
registerOre ( " blockGlass " + dyes [ i ] , block ) ;
registerOre ( " paneGlass " + dyes [ i ] , pane ) ;
2012-11-13 01:07:33 +00:00
}
2014-05-24 20:01:35 +00:00
replacements . put ( dye , " dye " + dyes [ i ] ) ;
replacements . put ( block , " blockGlass " + dyes [ i ] ) ;
replacements . put ( pane , " paneGlass " + dyes [ i ] ) ;
2012-11-06 00:15:43 +00:00
}
2012-11-13 01:07:33 +00:00
hasInit = true ;
2012-11-06 00:15:43 +00:00
2013-01-02 04:57:45 +00:00
ItemStack [ ] replaceStacks = replacements . keySet ( ) . toArray ( new ItemStack [ replacements . keySet ( ) . size ( ) ] ) ;
2012-11-06 00:15:43 +00:00
// Ignore recipes for the following items
ItemStack [ ] exclusions = new ItemStack [ ]
{
2013-12-10 05:59:12 +00:00
new ItemStack ( Blocks . lapis_block ) ,
new ItemStack ( Items . cookie ) ,
new ItemStack ( Blocks . stonebrick ) ,
2014-01-25 00:44:23 +00:00
new ItemStack ( Blocks . stone_slab , 1 , WILDCARD_VALUE ) ,
2013-12-10 05:59:12 +00:00
new ItemStack ( Blocks . stone_stairs ) ,
2013-12-21 08:10:35 +00:00
new ItemStack ( Blocks . cobblestone_wall ) ,
2014-12-23 22:14:40 +00:00
new ItemStack ( Blocks . oak_fence ) ,
new ItemStack ( Blocks . oak_fence_gate ) ,
2013-12-21 08:10:35 +00:00
new ItemStack ( Blocks . oak_stairs ) ,
2014-12-23 22:14:40 +00:00
new ItemStack ( Blocks . spruce_fence ) ,
new ItemStack ( Blocks . spruce_fence_gate ) ,
2013-12-21 08:10:35 +00:00
new ItemStack ( Blocks . spruce_stairs ) ,
2014-12-23 22:14:40 +00:00
new ItemStack ( Blocks . birch_fence ) ,
new ItemStack ( Blocks . birch_fence_gate ) ,
2013-12-21 08:10:35 +00:00
new ItemStack ( Blocks . birch_stairs ) ,
2014-12-23 22:14:40 +00:00
new ItemStack ( Blocks . jungle_fence ) ,
new ItemStack ( Blocks . jungle_fence_gate ) ,
2013-12-21 08:10:35 +00:00
new ItemStack ( Blocks . jungle_stairs ) ,
2014-12-23 22:14:40 +00:00
new ItemStack ( Blocks . acacia_fence ) ,
new ItemStack ( Blocks . acacia_fence_gate ) ,
2013-12-21 08:10:35 +00:00
new ItemStack ( Blocks . acacia_stairs ) ,
2014-12-23 22:14:40 +00:00
new ItemStack ( Blocks . dark_oak_fence ) ,
new ItemStack ( Blocks . dark_oak_fence_gate ) ,
2014-05-24 20:01:35 +00:00
new ItemStack ( Blocks . dark_oak_stairs ) ,
2014-12-10 13:18:42 +00:00
new ItemStack ( Blocks . wooden_slab ) ,
2014-12-23 22:14:40 +00:00
new ItemStack ( Blocks . glass_pane ) ,
null //So the above can have a comma and we don't have to keep editing extra lines.
2012-11-06 00:15:43 +00:00
} ;
2014-01-18 05:55:48 +00:00
List < IRecipe > recipes = CraftingManager . getInstance ( ) . getRecipeList ( ) ;
2012-11-06 00:15:43 +00:00
List < IRecipe > recipesToRemove = new ArrayList < IRecipe > ( ) ;
List < IRecipe > recipesToAdd = new ArrayList < IRecipe > ( ) ;
// Search vanilla recipes for recipes to replace
for ( Object obj : recipes )
{
2016-05-08 23:35:01 +00:00
if ( obj . getClass ( ) = = ShapedRecipes . class )
2012-11-06 00:15:43 +00:00
{
ShapedRecipes recipe = ( ShapedRecipes ) obj ;
ItemStack output = recipe . getRecipeOutput ( ) ;
if ( output ! = null & & containsMatch ( false , exclusions , output ) )
{
continue ;
}
if ( containsMatch ( true , recipe . recipeItems , replaceStacks ) )
{
recipesToRemove . add ( recipe ) ;
recipesToAdd . add ( new ShapedOreRecipe ( recipe , replacements ) ) ;
}
}
2016-05-08 23:35:01 +00:00
else if ( obj . getClass ( ) = = ShapelessRecipes . class )
2012-11-06 00:15:43 +00:00
{
ShapelessRecipes recipe = ( ShapelessRecipes ) obj ;
ItemStack output = recipe . getRecipeOutput ( ) ;
if ( output ! = null & & containsMatch ( false , exclusions , output ) )
{
continue ;
}
2016-03-23 14:34:48 +00:00
if ( containsMatch ( true , recipe . recipeItems . toArray ( new ItemStack [ recipe . recipeItems . size ( ) ] ) , replaceStacks ) )
2012-11-06 00:15:43 +00:00
{
recipesToRemove . add ( ( IRecipe ) obj ) ;
IRecipe newRecipe = new ShapelessOreRecipe ( recipe , replacements ) ;
recipesToAdd . add ( newRecipe ) ;
}
}
}
recipes . removeAll ( recipesToRemove ) ;
recipes . addAll ( recipesToAdd ) ;
2012-11-13 01:07:33 +00:00
if ( recipesToRemove . size ( ) > 0 )
{
2016-03-23 14:34:48 +00:00
FMLLog . info ( " Replaced %d ore recipes " , recipesToRemove . size ( ) ) ;
2012-11-13 01:07:33 +00:00
}
2012-10-28 14:24:01 +00:00
}
2012-08-01 23:35:35 +00:00
/ * *
2013-03-11 21:43:23 +00:00
* Gets the integer ID for the specified ore name .
2012-08-01 23:35:35 +00:00
* If the name does not have a ID it assigns it a new one .
2013-03-11 21:43:23 +00:00
*
2012-08-01 23:35:35 +00:00
* @param name The unique name for this ore ' oreIron ' , ' ingotIron ' , etc . .
* @return A number representing the ID for this ore type
* /
public static int getOreID ( String name )
{
2014-06-11 01:05:09 +00:00
Integer val = nameToId . get ( name ) ;
2012-08-01 23:35:35 +00:00
if ( val = = null )
{
2014-06-11 01:05:09 +00:00
idToName . add ( name ) ;
val = idToName . size ( ) - 1 ; //0 indexed
nameToId . put ( name , val ) ;
2014-12-07 09:17:48 +00:00
List < ItemStack > back = Lists . newArrayList ( ) ;
idToStack . add ( back ) ;
idToStackUn . add ( Collections . unmodifiableList ( back ) ) ;
2012-08-01 23:35:35 +00:00
}
return val ;
}
2013-03-11 21:43:23 +00:00
2012-08-01 23:35:35 +00:00
/ * *
* Reverse of getOreID , will not create new entries .
2013-03-11 21:43:23 +00:00
*
2012-08-01 23:35:35 +00:00
* @param id The ID to translate to a string
* @return The String name , or " Unknown " if not found .
* /
public static String getOreName ( int id )
{
2014-06-16 21:00:40 +00:00
return ( id > = 0 & & id < idToName . size ( ) ) ? idToName . get ( id ) : " Unknown " ;
2012-08-01 23:35:35 +00:00
}
2013-03-11 21:43:23 +00:00
2014-05-25 21:20:02 +00:00
/ * *
2016-03-23 14:34:48 +00:00
* Gets all the integer ID for the ores that the specified item stack is registered to .
2014-05-25 21:20:02 +00:00
* If the item stack is not linked to any ore , this will return an empty array and no new entry will be created .
*
2014-06-11 01:05:09 +00:00
* @param stack The item stack of the ore .
2016-03-23 14:34:48 +00:00
* @return An array of ids that this ore is registered as .
2014-05-25 21:20:02 +00:00
* /
2014-06-11 01:05:09 +00:00
public static int [ ] getOreIDs ( ItemStack stack )
2014-05-25 21:20:02 +00:00
{
2014-12-07 09:17:48 +00:00
if ( stack = = null | | stack . getItem ( ) = = null ) throw new IllegalArgumentException ( " Stack can not be null! " ) ;
2014-05-25 21:20:02 +00:00
2014-06-11 01:05:09 +00:00
Set < Integer > set = new HashSet < Integer > ( ) ;
2015-11-09 20:20:53 +00:00
// HACK: use the registry name's ID. It is unique and it knows about substitutions. Fallback to a -1 value (what Item.getIDForItem would have returned) in the case where the registry is not aware of the item yet
// IT should be noted that -1 will fail the gate further down, if an entry already exists with value -1 for this name. This is what is broken and being warned about.
// APPARENTLY it's quite common to do this. OreDictionary should be considered alongside Recipes - you can't make them properly until you've registered with the game.
2016-04-01 21:13:06 +00:00
ResourceLocation registryName = stack . getItem ( ) . delegate . name ( ) ;
2015-11-09 20:20:53 +00:00
int id ;
if ( registryName = = null )
{
FMLLog . log ( Level . DEBUG , " Attempted to find the oreIDs for an unregistered object (%s). This won't work very well. " , stack ) ;
return new int [ 0 ] ;
}
else
{
id = GameData . getItemRegistry ( ) . getId ( registryName ) ;
}
2014-06-11 01:05:09 +00:00
List < Integer > ids = stackToId . get ( id ) ;
if ( ids ! = null ) set . addAll ( ids ) ;
2014-06-11 17:27:28 +00:00
ids = stackToId . get ( id | ( ( stack . getItemDamage ( ) + 1 ) < < 16 ) ) ;
2014-06-11 01:05:09 +00:00
if ( ids ! = null ) set . addAll ( ids ) ;
Integer [ ] tmp = set . toArray ( new Integer [ set . size ( ) ] ) ;
int [ ] ret = new int [ tmp . length ] ;
for ( int x = 0 ; x < tmp . length ; x + + )
ret [ x ] = tmp [ x ] ;
2014-05-25 21:20:02 +00:00
return ret ;
}
2012-08-01 23:35:35 +00:00
/ * *
* Retrieves the ArrayList of items that are registered to this ore type .
* Creates the list as empty if it did not exist .
2014-06-22 18:47:24 +00:00
*
* The returned List is unmodifiable , but will be updated if a new ore
2014-06-11 01:05:09 +00:00
* is registered using registerOre
2013-03-11 21:43:23 +00:00
*
2012-09-11 20:11:17 +00:00
* @param name The ore name , directly calls getOreID
2012-08-01 23:35:35 +00:00
* @return An arrayList containing ItemStacks registered for this ore
* /
2014-12-07 09:17:48 +00:00
public static List < ItemStack > getOres ( String name )
2012-08-01 23:35:35 +00:00
{
return getOres ( getOreID ( name ) ) ;
}
2013-03-11 21:43:23 +00:00
2016-01-21 21:41:26 +00:00
/ * *
* Retrieves the List of items that are registered to this ore type at this instant .
* If the flag is TRUE , then it will create the list as empty if it did not exist .
*
* This option should be used by modders who are doing blanket scans in postInit .
* It greatly reduces clutter in the OreDictionary is the responsible and proper
* way to use the dictionary in a large number of cases .
*
* The other function above is utilized in OreRecipe and is required for the
* operation of that code .
*
* @param name The ore name , directly calls getOreID if the flag is TRUE
* @param alwaysCreateEntry Flag - should a new entry be created if empty
* @return An arraylist containing ItemStacks registered for this ore
* /
public static List < ItemStack > getOres ( String name , boolean alwaysCreateEntry )
{
if ( alwaysCreateEntry ) {
return getOres ( getOreID ( name ) ) ;
}
return nameToId . get ( name ) ! = null ? getOres ( getOreID ( name ) ) : EMPTY_LIST ;
}
/ * *
* Returns whether or not an oreName exists in the dictionary .
* This function can be used to safely query the Ore Dictionary without
* adding needless clutter to the underlying map structure .
*
* Please use this when possible and appropriate .
*
* @param name The ore name
* @return Whether or not that name is in the Ore Dictionary .
* /
public static boolean doesOreNameExist ( String name )
{
return nameToId . get ( name ) ! = null ;
}
2012-08-06 00:59:53 +00:00
/ * *
* Retrieves a list of all unique ore names that are already registered .
2013-03-11 21:43:23 +00:00
*
2012-08-06 00:59:53 +00:00
* @return All unique ore names that are currently registered .
* /
public static String [ ] getOreNames ( )
{
2014-06-11 01:05:09 +00:00
return idToName . toArray ( new String [ idToName . size ( ) ] ) ;
2012-08-06 00:59:53 +00:00
}
2013-03-11 21:43:23 +00:00
2012-08-01 23:35:35 +00:00
/ * *
2014-12-07 09:17:48 +00:00
* Retrieves the List of items that are registered to this ore type .
2012-08-01 23:35:35 +00:00
* Creates the list as empty if it did not exist .
2014-06-22 18:47:24 +00:00
*
2012-08-01 23:35:35 +00:00
* @param id The ore ID , see getOreID
2014-06-11 01:05:09 +00:00
* @return An List containing ItemStacks registered for this ore
2012-08-01 23:35:35 +00:00
* /
2014-12-07 09:17:48 +00:00
private static List < ItemStack > getOres ( int id )
2014-06-11 01:05:09 +00:00
{
2014-06-11 17:27:28 +00:00
return idToStackUn . size ( ) > id ? idToStackUn . get ( id ) : EMPTY_LIST ;
2012-08-01 23:35:35 +00:00
}
2012-11-06 00:15:43 +00:00
private static boolean containsMatch ( boolean strict , ItemStack [ ] inputs , ItemStack . . . targets )
{
for ( ItemStack input : inputs )
{
for ( ItemStack target : targets )
{
if ( itemMatches ( target , input , strict ) )
{
return true ;
}
}
}
return false ;
}
2015-11-27 03:38:21 +00:00
public static boolean containsMatch ( boolean strict , List < ItemStack > inputs , ItemStack . . . targets )
2014-05-25 21:20:02 +00:00
{
for ( ItemStack input : inputs )
{
for ( ItemStack target : targets )
{
if ( itemMatches ( target , input , strict ) )
{
return true ;
}
}
}
return false ;
}
2012-11-06 00:15:43 +00:00
public static boolean itemMatches ( ItemStack target , ItemStack input , boolean strict )
{
if ( input = = null & & target ! = null | | input ! = null & & target = = null )
{
return false ;
}
2013-12-10 05:59:12 +00:00
return ( target . getItem ( ) = = input . getItem ( ) & & ( ( target . getItemDamage ( ) = = WILDCARD_VALUE & & ! strict ) | | target . getItemDamage ( ) = = input . getItemDamage ( ) ) ) ;
2012-11-06 00:15:43 +00:00
}
2012-08-01 23:35:35 +00:00
//Convenience functions that make for cleaner code mod side. They all drill down to registerOre(String, int, ItemStack)
public static void registerOre ( String name , Item ore ) { registerOre ( name , new ItemStack ( ore ) ) ; }
public static void registerOre ( String name , Block ore ) { registerOre ( name , new ItemStack ( ore ) ) ; }
2014-06-11 01:05:09 +00:00
public static void registerOre ( String name , ItemStack ore ) { registerOreImpl ( name , ore ) ; }
2013-03-11 21:43:23 +00:00
2012-08-01 23:35:35 +00:00
/ * *
* Registers a ore item into the dictionary .
* Raises the registerOre function in all registered handlers .
2013-03-11 21:43:23 +00:00
*
2012-08-01 23:35:35 +00:00
* @param name The name of the ore
* @param ore The ore ' s ItemStack
* /
2014-06-11 01:05:09 +00:00
private static void registerOreImpl ( String name , ItemStack ore )
2012-08-01 23:35:35 +00:00
{
2014-06-11 01:05:09 +00:00
if ( " Unknown " . equals ( name ) ) return ; //prevent bad IDs.
2015-04-14 02:40:38 +00:00
if ( ore = = null | | ore . getItem ( ) = = null )
{
2015-11-09 20:20:53 +00:00
FMLLog . bigWarning ( " Invalid registration attempt for an Ore Dictionary item with name %s has occurred. The registration has been denied to prevent crashes. The mod responsible for the registration needs to correct this. " , name ) ;
return ; //prevent bad ItemStacks.
2015-04-14 02:40:38 +00:00
}
2014-06-11 01:05:09 +00:00
int oreID = getOreID ( name ) ;
2015-10-29 16:46:12 +00:00
// HACK: use the registry name's ID. It is unique and it knows about substitutions. Fallback to a -1 value (what Item.getIDForItem would have returned) in the case where the registry is not aware of the item yet
// IT should be noted that -1 will fail the gate further down, if an entry already exists with value -1 for this name. This is what is broken and being warned about.
// APPARENTLY it's quite common to do this. OreDictionary should be considered alongside Recipes - you can't make them properly until you've registered with the game.
2016-04-01 21:13:06 +00:00
ResourceLocation registryName = ore . getItem ( ) . delegate . name ( ) ;
2015-10-29 16:46:12 +00:00
int hash ;
if ( registryName = = null )
{
FMLLog . bigWarning ( " A broken ore dictionary registration with name %s has occurred. It adds an item (type: %s) which is currently unknown to the game registry. This dictionary item can only support a single value when "
+ " registered with ores like this, and NO I am not going to turn this spam off. Just register your ore dictionary entries after the GameRegistry. \ n "
+ " TO USERS: YES this is a BUG in the mod " + Loader . instance ( ) . activeModContainer ( ) . getName ( ) + " report it to them! " , name , ore . getItem ( ) . getClass ( ) ) ;
hash = - 1 ;
}
else
{
hash = GameData . getItemRegistry ( ) . getId ( registryName ) ;
}
2014-06-11 01:05:09 +00:00
if ( ore . getItemDamage ( ) ! = WILDCARD_VALUE )
{
hash | = ( ( ore . getItemDamage ( ) + 1 ) < < 16 ) ; // +1 so 0 is significant
}
//Add things to the baked version, and prevent duplicates
List < Integer > ids = stackToId . get ( hash ) ;
if ( ids ! = null & & ids . contains ( oreID ) ) return ;
if ( ids = = null )
{
ids = Lists . newArrayList ( ) ;
stackToId . put ( hash , ids ) ;
}
ids . add ( oreID ) ;
//Add to the unbaked version
2012-08-01 23:35:35 +00:00
ore = ore . copy ( ) ;
2014-06-11 01:05:09 +00:00
idToStack . get ( oreID ) . add ( ore ) ;
2012-08-06 02:14:02 +00:00
MinecraftForge . EVENT_BUS . post ( new OreRegisterEvent ( name , ore ) ) ;
2012-08-06 00:59:53 +00:00
}
2013-03-11 21:43:23 +00:00
2012-08-06 00:59:53 +00:00
public static class OreRegisterEvent extends Event
{
2016-03-24 08:44:52 +00:00
private final String Name ;
private final ItemStack Ore ;
2013-03-11 21:43:23 +00:00
2012-08-06 00:59:53 +00:00
public OreRegisterEvent ( String name , ItemStack ore )
2012-08-01 23:35:35 +00:00
{
2012-08-06 00:59:53 +00:00
this . Name = name ;
this . Ore = ore ;
2012-08-01 23:35:35 +00:00
}
2016-03-24 08:44:52 +00:00
public String getName ( )
{
return Name ;
}
public ItemStack getOre ( )
{
return Ore ;
}
2012-08-01 23:35:35 +00:00
}
2014-06-11 01:05:09 +00:00
public static void rebakeMap ( )
{
//System.out.println("Baking OreDictionary:");
stackToId . clear ( ) ;
for ( int id = 0 ; id < idToStack . size ( ) ; id + + )
{
List < ItemStack > ores = idToStack . get ( id ) ;
if ( ores = = null ) continue ;
for ( ItemStack ore : ores )
{
2015-10-29 16:46:12 +00:00
// HACK: use the registry name's ID. It is unique and it knows about substitutions
2016-04-01 21:13:06 +00:00
ResourceLocation name = ore . getItem ( ) . delegate . name ( ) ;
2015-10-29 16:46:12 +00:00
int hash ;
if ( name = = null )
{
FMLLog . log ( Level . DEBUG , " Defaulting unregistered ore dictionary entry for ore dictionary %s: type %s to -1 " , getOreName ( id ) , ore . getItem ( ) . getClass ( ) ) ;
hash = - 1 ;
}
else
{
hash = GameData . getItemRegistry ( ) . getId ( name ) ;
}
2014-06-11 01:05:09 +00:00
if ( ore . getItemDamage ( ) ! = WILDCARD_VALUE )
{
hash | = ( ( ore . getItemDamage ( ) + 1 ) < < 16 ) ; // +1 so meta 0 is significant
}
List < Integer > ids = stackToId . get ( hash ) ;
if ( ids = = null )
{
ids = Lists . newArrayList ( ) ;
stackToId . put ( hash , ids ) ;
}
ids . add ( id ) ;
//System.out.println(id + " " + getOreName(id) + " " + Integer.toHexString(hash) + " " + ore);
}
}
}
2012-08-01 23:35:35 +00:00
}