diff --git a/src/java/mmm/MmmMaterials.java b/src/java/mmm/MmmMaterials.java index c12e703..02ed4e8 100644 --- a/src/java/mmm/MmmMaterials.java +++ b/src/java/mmm/MmmMaterials.java @@ -1,8 +1,6 @@ package mmm; -import mmm.core.CRegistry; -import mmm.materials.I_MRock; import mmm.materials.MAlloys; import mmm.materials.MItems; import mmm.materials.MMetals; @@ -12,12 +10,6 @@ import mmm.materials.MWoods; import mmm.materials.traps.MTraps; import mmm.materials.trees.MTrees; import mmm.materials.trees.MWoodAchievementHandler; -import net.minecraft.block.Block; -import net.minecraft.block.BlockStone; -import net.minecraft.block.state.IBlockState; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; import net.minecraftforge.common.MinecraftForge; @@ -47,39 +39,6 @@ public class MmmMaterials } - public static Item makeFuel( final String name , final int burnTime ) - { - final Item fuel = MmmMaterials.makeItem( name ); - CRegistry.setFuel( fuel , burnTime ); - return fuel; - } - - - public static Item makeItem( final String name ) - { - final Item stone = new Item( ); - CRegistry.setIdentifiers( stone , "materials" , "stone" , name ); - stone.setCreativeTab( CreativeTabs.MATERIALS ); - CRegistry.addItem( stone ); - return stone; - } - - - public static boolean isRock( final IBlockState bs ) - { - final Block block = bs.getBlock( ); - if ( block instanceof BlockStone ) { - final BlockStone.EnumType variant = bs.getValue( BlockStone.VARIANT ); - return variant == BlockStone.EnumType.ANDESITE || variant == BlockStone.EnumType.DIORITE - || variant == BlockStone.EnumType.GRANITE || variant == BlockStone.EnumType.STONE; - } - if ( block == Blocks.COBBLESTONE ) { - return true; - } - return block instanceof I_MRock; - } - - public static void preInit( ) { // EMPTY diff --git a/src/java/mmm/materials/E_MItemType.java b/src/java/mmm/materials/E_MItemType.java new file mode 100644 index 0000000..bee27a1 --- /dev/null +++ b/src/java/mmm/materials/E_MItemType.java @@ -0,0 +1,30 @@ +package mmm.materials; + + +public enum E_MItemType { + + ORE( "stone" , MOre.class ) , + FUEL( "stone" ) , + INGOT( "ingot" , MMetal.class ) , + NUGGET( "nugget" , MMetal.class ) , + MISC( "stone" ), + // + ; + + public final String path; + public final Class< ? > extraInfoType; + + + private E_MItemType( String path ) + { + this( path , Object.class ); + } + + + private E_MItemType( String path , Class< ? > extraInfoType ) + { + this.path = path; + this.extraInfoType = extraInfoType; + } + +} diff --git a/src/java/mmm/materials/E_MMetalItemType.java b/src/java/mmm/materials/E_MMetalItemType.java deleted file mode 100644 index adcda70..0000000 --- a/src/java/mmm/materials/E_MMetalItemType.java +++ /dev/null @@ -1,15 +0,0 @@ -package mmm.materials; - - -public enum E_MMetalItemType { - INGOT( "ingot" ) , - NUGGET( "nugget" ); - - public final String name; - - - private E_MMetalItemType( final String name ) - { - this.name = name; - } -} \ No newline at end of file diff --git a/src/java/mmm/materials/I_MAlloy.java b/src/java/mmm/materials/I_MAlloy.java new file mode 100644 index 0000000..93dcb89 --- /dev/null +++ b/src/java/mmm/materials/I_MAlloy.java @@ -0,0 +1,9 @@ +package mmm.materials; + + +public interface I_MAlloy +{ + + public MMetal[] getComponents( ); + +} diff --git a/src/java/mmm/materials/MAlloy.java b/src/java/mmm/materials/MAlloy.java new file mode 100644 index 0000000..4a543db --- /dev/null +++ b/src/java/mmm/materials/MAlloy.java @@ -0,0 +1,30 @@ +package mmm.materials; + + +import net.minecraft.block.material.MapColor; + + + +public class MAlloy + extends MMetal + implements I_MAlloy +{ + + private final MMetal[] metals; + + + public MAlloy( final String name , final float baseSmeltingXP , final float hardness , final int harvestLevel , + final MapColor mapColor , final MMetal... metals ) + { + super( name , baseSmeltingXP , hardness , harvestLevel , mapColor ); + this.metals = metals.clone( ); + } + + + @Override + public MMetal[] getComponents( ) + { + return this.metals.clone( ); + } + +} diff --git a/src/java/mmm/materials/MBlockType.java b/src/java/mmm/materials/MBlockType.java new file mode 100644 index 0000000..065bcef --- /dev/null +++ b/src/java/mmm/materials/MBlockType.java @@ -0,0 +1,51 @@ +package mmm.materials; + + +import java.util.function.Predicate; + +import net.minecraft.block.state.IBlockState; + + + +public class MBlockType +{ + + public final String name; + private final Predicate< IBlockState > check; + + + public MBlockType( final String name , final Predicate< IBlockState > check ) + { + this.name = name.intern( ); + this.check = check; + MBlockTypes.add( this ); + } + + + public boolean matches( final IBlockState blockState ) + { + return this.check.test( blockState ); + } + + + @Override + public String toString( ) + { + return "MBlockType{" + this.name + "}"; + } + + + @Override + public int hashCode( ) + { + return this.name.hashCode( ); + } + + + @Override + public boolean equals( final Object obj ) + { + return this == obj; + } + +} diff --git a/src/java/mmm/materials/MBlockTypes.java b/src/java/mmm/materials/MBlockTypes.java new file mode 100644 index 0000000..4cdaec4 --- /dev/null +++ b/src/java/mmm/materials/MBlockTypes.java @@ -0,0 +1,94 @@ +package mmm.materials; + + +import java.util.HashMap; +import java.util.HashSet; + +import mmm.materials.trees.MLog; +import mmm.materials.trees.MPlanks; +import net.minecraft.block.Block; +import net.minecraft.block.BlockStone; +import net.minecraft.init.Blocks; + + + +public class MBlockTypes +{ + private static final HashMap< String , MBlockType > TYPES; + + public static final MBlockType ROCK; + public static final MBlockType LOG; + public static final MBlockType PLANKS; + public static final MBlockType WOOD; + public static final MBlockType ORE; + public static final MBlockType METAL; + + static { + TYPES = new HashMap<>( ); + { + ROCK = new MBlockType( "ROCK" , ( bs ) -> { + final Block block = bs.getBlock( ); + if ( block instanceof BlockStone ) { + final BlockStone.EnumType variant = bs.getValue( BlockStone.VARIANT ); + return variant == BlockStone.EnumType.ANDESITE || variant == BlockStone.EnumType.DIORITE + || variant == BlockStone.EnumType.GRANITE || variant == BlockStone.EnumType.STONE; + } + if ( block == Blocks.COBBLESTONE ) { + return true; + } + return block instanceof I_MRock; + } ); + } + { + LOG = new MBlockType( "LOG" , ( bs ) -> { + final Block block = bs.getBlock( ); + return block == Blocks.LOG || block == Blocks.LOG2 || block instanceof MLog; + } ); + } + { + PLANKS = new MBlockType( "PLANKS" , ( bs ) -> { + final Block block = bs.getBlock( ); + return block == Blocks.PLANKS || block instanceof MPlanks; + } ); + } + { + WOOD = new MBlockType( "WOOD" , ( bs ) -> LOG.matches( bs ) || PLANKS.matches( bs ) ); + } + { + final HashSet< Block > builtinOres = new HashSet<>( ); + builtinOres.add( Blocks.COAL_ORE ); + builtinOres.add( Blocks.IRON_ORE ); + builtinOres.add( Blocks.GOLD_ORE ); + builtinOres.add( Blocks.DIAMOND_ORE ); + builtinOres.add( Blocks.LAPIS_ORE ); + builtinOres.add( Blocks.REDSTONE_ORE ); + builtinOres.add( Blocks.EMERALD_ORE ); + ORE = new MBlockType( "ORE" , ( bs ) -> { + final Block block = bs.getBlock( ); + return builtinOres.contains( block ) || block instanceof MOre; + } ); + } + { + METAL = new MBlockType( "METAL" , ( bs ) -> { + final Block block = bs.getBlock( ); + return block == Blocks.IRON_BLOCK || block == Blocks.GOLD_BLOCK || block instanceof MMetalBlock; + } ); + } + } + + + static void add( final MBlockType mType ) + { + if ( MBlockTypes.TYPES.containsKey( mType.name ) ) { + throw new IllegalArgumentException( "duplicate material type " + mType ); + } + MBlockTypes.TYPES.put( mType.name , mType ); + } + + + public static MBlockType get( final String type ) + { + return MBlockTypes.TYPES.get( type ); + } + +} diff --git a/src/java/mmm/materials/MItem.java b/src/java/mmm/materials/MItem.java new file mode 100644 index 0000000..0dd5ec6 --- /dev/null +++ b/src/java/mmm/materials/MItem.java @@ -0,0 +1,62 @@ +package mmm.materials; + + +import mmm.core.CRegistry; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; + + + +public class MItem + extends Item +{ + + public static Item makeItem( final E_MItemType type , final String name ) + { + final Item item = new MItem( type , name ); + CRegistry.addItem( item ); + return item; + } + + + public static Item makeFuel( final String name , final int burnTime ) + { + final Item fuel = MItem.makeItem( E_MItemType.FUEL , name ); + CRegistry.setFuel( fuel , burnTime ); + return fuel; + } + + public final E_MItemType itemType; + private Object extraInfo; + + + public MItem( final E_MItemType type , final String name ) + { + this( type , name , null ); + } + + + public MItem( final E_MItemType type , final String name , final Object extraInfo ) + { + super( ); + this.setCreativeTab( CreativeTabs.MATERIALS ); + this.itemType = type; + this.setExtraInfo( extraInfo ); + CRegistry.setIdentifiers( this , "materials" , type.path , name ); + } + + + public void setExtraInfo( final Object extraInfo ) + { + if ( extraInfo != null && !this.itemType.extraInfoType.isAssignableFrom( extraInfo.getClass( ) ) ) { + throw new IllegalArgumentException( "invalid extra info type" ); + } + this.extraInfo = extraInfo; + } + + + public < T > T getExtraInfo( Class< T > cls ) + { + return cls.cast( this.extraInfo ); + } +} diff --git a/src/java/mmm/materials/MItemType.java b/src/java/mmm/materials/MItemType.java new file mode 100644 index 0000000..c944841 --- /dev/null +++ b/src/java/mmm/materials/MItemType.java @@ -0,0 +1,53 @@ +package mmm.materials; + + +import net.minecraft.item.Item; + + + +public class MItemType +{ + public static interface I_ItemCheck + { + public boolean test( Item item , int meta ); + } + + public final String name; + private final I_ItemCheck check; + + + public MItemType( final String name , final I_ItemCheck check ) + { + this.name = name.intern( ); + this.check = check; + MItemTypes.add( this ); + } + + + public boolean matches( final Item item , final int meta ) + { + return this.check.test( item , meta ); + } + + + @Override + public String toString( ) + { + return "MItemType{" + this.name + "}"; + } + + + @Override + public int hashCode( ) + { + return this.name.hashCode( ); + } + + + @Override + public boolean equals( final Object obj ) + { + return this == obj; + } + +} diff --git a/src/java/mmm/materials/MItemTypes.java b/src/java/mmm/materials/MItemTypes.java new file mode 100644 index 0000000..5bcab4f --- /dev/null +++ b/src/java/mmm/materials/MItemTypes.java @@ -0,0 +1,77 @@ +package mmm.materials; + + +import java.util.HashMap; + +import net.minecraft.init.Items; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityFurnace; + + + +public class MItemTypes +{ + private static final HashMap< String , MItemType > TYPES; + + public static final MItemType ORE; + public static final MItemType FUEL; + public static final MItemType NUGGET; + public static final MItemType INGOT; + public static final MItemType METAL; + + static { + TYPES = new HashMap<>( ); + { + ORE = new MItemType( "ORE" , ( item , metadata ) -> { + if ( item == Items.COAL && metadata == 0 ) { + return true; + } + if ( item == Items.DYE && metadata == EnumDyeColor.BLUE.getDyeDamage( ) ) { + return true; + } + if ( item == Items.EMERALD || item == Items.DIAMOND || item == Items.REDSTONE ) { + return true; + } + return item instanceof MItem && ( (MItem) item ).itemType == E_MItemType.ORE; + } ); + } + { + FUEL = new MItemType( "FUEL" , + ( item , metadata ) -> TileEntityFurnace.isItemFuel( new ItemStack( item , 1 , metadata ) ) ); + } + { + NUGGET = new MItemType( "NUGGET" , ( item , metadata ) -> { + return item == Items.GOLD_NUGGET + || item instanceof MItem && ( (MItem) item ).itemType == E_MItemType.NUGGET; + } ); + } + { + INGOT = new MItemType( "INGOT" , ( item , metadata ) -> { + return item == Items.GOLD_INGOT || item == Items.IRON_INGOT + || item instanceof MItem && ( (MItem) item ).itemType == E_MItemType.INGOT; + } ); + } + { + METAL = new MItemType( "METAL" , ( item , metadata ) -> { + return MItemTypes.NUGGET.matches( item , metadata ) || MItemTypes.INGOT.matches( item , metadata ); + } ); + } + } + + + static void add( final MItemType mType ) + { + if ( MItemTypes.TYPES.containsKey( mType.name ) ) { + throw new IllegalArgumentException( "duplicate material type " + mType ); + } + MItemTypes.TYPES.put( mType.name , mType ); + } + + + public static MItemType get( final String type ) + { + return MItemTypes.TYPES.get( type ); + } + +} diff --git a/src/java/mmm/materials/MItems.java b/src/java/mmm/materials/MItems.java index 0e9c555..d7fe729 100644 --- a/src/java/mmm/materials/MItems.java +++ b/src/java/mmm/materials/MItems.java @@ -31,19 +31,18 @@ public class MItems CRegistry.addRecipeRegistrar( this ); // Items that do not correspond to metals or ores - this.SLAG = MmmMaterials.makeItem( "slag" ); - this.COKE = MmmMaterials.makeFuel( "coke" , 9600 ); - this.PIG_IRON_INGOT = new MMetalItem( E_MMetalItemType.INGOT , "pig_iron" ); - CRegistry.addItem( this.PIG_IRON_INGOT ); + this.SLAG = MItem.makeItem( E_MItemType.MISC , "slag" ); + this.COKE = MItem.makeFuel( "coke" , 9600 ); + this.PIG_IRON_INGOT = MItem.makeItem( E_MItemType.INGOT , "pig_iron" ); // Ore drops - this.MALACHITE = MmmMaterials.makeItem( "malachite" ); - this.CUPRITE = MmmMaterials.makeItem( "cuprite" ); - this.CASSITERITE = MmmMaterials.makeItem( "cassiterite" ); - this.SPHALERITE = MmmMaterials.makeItem( "sphalerite" ); - this.ROCK_SALT = MmmMaterials.makeItem( "rock_salt" ); - this.SULPHUR_POWDER = MmmMaterials.makeItem( "sulphur_powder" ); - this.SALTPETER = MmmMaterials.makeItem( "saltpeter_powder" ); + this.MALACHITE = MItem.makeItem( E_MItemType.ORE , "malachite" ); + this.CUPRITE = MItem.makeItem( E_MItemType.ORE , "cuprite" ); + this.CASSITERITE = MItem.makeItem( E_MItemType.ORE , "cassiterite" ); + this.SPHALERITE = MItem.makeItem( E_MItemType.ORE , "sphalerite" ); + this.ROCK_SALT = MItem.makeItem( E_MItemType.ORE , "rock_salt" ); + this.SULPHUR_POWDER = MItem.makeItem( E_MItemType.ORE , "sulphur_powder" ); + this.SALTPETER = MItem.makeItem( E_MItemType.ORE , "saltpeter_powder" ); } diff --git a/src/java/mmm/materials/MMetal.java b/src/java/mmm/materials/MMetal.java index 7e02b4e..e27979c 100644 --- a/src/java/mmm/materials/MMetal.java +++ b/src/java/mmm/materials/MMetal.java @@ -25,8 +25,8 @@ public class MMetal final MapColor mapColor ) { this( baseSmeltingXP , new MMetalBlock( name , hardness , harvestLevel , mapColor ) , // - new MMetalItem( E_MMetalItemType.INGOT , name ) , // - new MMetalItem( E_MMetalItemType.NUGGET , name ) ); + new MItem( E_MItemType.INGOT , name ) , // + new MItem( E_MItemType.NUGGET , name ) ); } @@ -49,6 +49,27 @@ public class MMetal this.BLOCK = block; this.INGOT = ingot; this.NUGGET = nugget; + + if ( ingot instanceof MItem ) { + MItem miIngot = (MItem) ingot; + if ( miIngot.itemType != E_MItemType.INGOT ) { + throw new IllegalArgumentException( "invalid ingot item" ); + } + miIngot.setExtraInfo( this ); + } + + if ( nugget instanceof MItem ) { + MItem miNugget = (MItem) nugget; + if ( miNugget.itemType != E_MItemType.NUGGET ) { + throw new IllegalArgumentException( "invalid nugget item" ); + } + miNugget.setExtraInfo( this ); + } + + if ( block instanceof MMetalBlock ) { + ( (MMetalBlock) block ).setMetal( this ); + } + this.register( ); } @@ -60,11 +81,11 @@ public class MMetal CRegistry.addBlock( this.BLOCK ); custom = true; } - if ( this.INGOT instanceof MMetalItem ) { + if ( this.INGOT instanceof MItem ) { CRegistry.addItem( this.INGOT ); custom = true; } - if ( this.NUGGET instanceof MMetalItem ) { + if ( this.NUGGET instanceof MItem ) { CRegistry.addItem( this.NUGGET ); custom = true; } @@ -78,13 +99,13 @@ public class MMetal @Override public void registerRecipes( ) { - if ( this.INGOT instanceof MMetalItem || this.NUGGET instanceof MMetalItem ) { + if ( this.INGOT instanceof MItem || this.NUGGET instanceof MItem ) { GameRegistry.addShapelessRecipe( new ItemStack( this.NUGGET , 9 ) , this.INGOT ); GameRegistry.addRecipe( new ItemStack( this.INGOT ) , // "NNN" , "NNN" , "NNN" , // 'N' , this.NUGGET ); } - if ( this.INGOT instanceof MMetalItem || this.BLOCK instanceof MMetalBlock ) { + if ( this.INGOT instanceof MItem || this.BLOCK instanceof MMetalBlock ) { GameRegistry.addShapelessRecipe( new ItemStack( this.INGOT , 9 ) , this.BLOCK ); GameRegistry.addRecipe( new ItemStack( this.BLOCK ) , // "III" , "III" , "III" , // diff --git a/src/java/mmm/materials/MMetalBlock.java b/src/java/mmm/materials/MMetalBlock.java index fb50cfc..fc57716 100644 --- a/src/java/mmm/materials/MMetalBlock.java +++ b/src/java/mmm/materials/MMetalBlock.java @@ -14,6 +14,9 @@ public class MMetalBlock extends Block { + private MMetal metal; + + public MMetalBlock( final String name , final float hardness , final int harvestLevel , final MapColor mapColor ) { super( Material.IRON , mapColor ); @@ -25,4 +28,16 @@ public class MMetalBlock CRegistry.setIdentifiers( this , "materials" , "block" , name ); } + + void setMetal( final MMetal metal ) + { + this.metal = metal; + } + + + public MMetal getMetal( ) + { + return this.metal; + } + } diff --git a/src/java/mmm/materials/MMetalItem.java b/src/java/mmm/materials/MMetalItem.java deleted file mode 100644 index cf07a27..0000000 --- a/src/java/mmm/materials/MMetalItem.java +++ /dev/null @@ -1,20 +0,0 @@ -package mmm.materials; - - -import mmm.core.CRegistry; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.item.Item; - - - -public class MMetalItem - extends Item -{ - public MMetalItem( final E_MMetalItemType type , final String name ) - { - super( ); - this.setCreativeTab( CreativeTabs.MATERIALS ); - CRegistry.setIdentifiers( this , "materials" , type.name , name ); - } - -} diff --git a/src/java/mmm/materials/MMetals.java b/src/java/mmm/materials/MMetals.java index 1dc6736..cae4ed4 100644 --- a/src/java/mmm/materials/MMetals.java +++ b/src/java/mmm/materials/MMetals.java @@ -20,7 +20,7 @@ public class MMetals { this.GOLD = new MMetal( Blocks.GOLD_BLOCK , Items.GOLD_INGOT , Items.GOLD_NUGGET ); this.IRON = new MMetal( Blocks.IRON_BLOCK , Items.IRON_INGOT , // - new MMetalItem( E_MMetalItemType.NUGGET , "iron" ) ); + new MItem( E_MItemType.NUGGET , "iron" ) ); this.COPPER = new MMetal( "copper" , 0.4f , 4f , 1 , MapColor.DIRT ); this.TIN = new MMetal( "tin" , 0.6f , 1f , 0 , MapColor.GRAY ); diff --git a/src/java/mmm/materials/MOre.java b/src/java/mmm/materials/MOre.java index 67c5dad..ae33fc4 100644 --- a/src/java/mmm/materials/MOre.java +++ b/src/java/mmm/materials/MOre.java @@ -35,7 +35,7 @@ public class MOre private MMetal metal; private int genQuantity; - private E_MMetalItemType smeltingOutput; + private E_MItemType smeltingOutput; public MOre( final String name , final int harvestLevel ) @@ -87,6 +87,13 @@ public class MOre this.dropMax = dropMax; this.dropItems = item; this.dropMeta = meta; + if ( item instanceof MItem ) { + MItem oreItem = (MItem) item; + if ( oreItem.itemType != E_MItemType.ORE ) { + throw new IllegalArgumentException( "ore item expected" ); + } + oreItem.setExtraInfo( this ); + } return this; } @@ -109,17 +116,17 @@ public class MOre public MOre setMetal( final MMetal metal ) { - return this.setMetal( metal , 1 , E_MMetalItemType.INGOT ); + return this.setMetal( metal , 1 , E_MItemType.INGOT ); } public MOre setMetal( final MMetal metal , final int count ) { - return this.setMetal( metal , count , E_MMetalItemType.INGOT ); + return this.setMetal( metal , count , E_MItemType.INGOT ); } - public MOre setMetal( final MMetal metal , final int quantity , final E_MMetalItemType type ) + public MOre setMetal( final MMetal metal , final int quantity , final E_MItemType type ) { assert metal != null && quantity > 0; this.metal = metal; diff --git a/src/java/mmm/materials/MOres.java b/src/java/mmm/materials/MOres.java index 2456cea..22f4636 100644 --- a/src/java/mmm/materials/MOres.java +++ b/src/java/mmm/materials/MOres.java @@ -46,7 +46,7 @@ public class MOres .setDrops( MmmMaterials.ITEM.CUPRITE ) // .setExperience( 2 , 5 ); this.CASSITERITE = new MOre( "cassiterite" , 0 )// - .setMetal( MmmMaterials.METAL.TIN , 1 , E_MMetalItemType.NUGGET ) // + .setMetal( MmmMaterials.METAL.TIN , 1 , E_MItemType.NUGGET ) // .setDrops( MmmMaterials.ITEM.CASSITERITE , 2 , 5 ) // .setExperience( 2 , 5 ); this.SPHALERITE = new MOre( "sphalerite" , 1 ) // diff --git a/src/java/mmm/utils/UMaterials.java b/src/java/mmm/utils/UMaterials.java new file mode 100644 index 0000000..ab4330f --- /dev/null +++ b/src/java/mmm/utils/UMaterials.java @@ -0,0 +1,124 @@ +package mmm.utils; + + +import mmm.materials.MBlockType; +import mmm.materials.MBlockTypes; +import mmm.materials.MItemType; +import mmm.materials.MItemTypes; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + + + +public class UMaterials +{ + + public static boolean hasType( final String type , final ItemStack stack ) + { + return UMaterials.hasType( type , stack.getItem( ) , stack.getMetadata( ) ); + } + + + @SuppressWarnings( "deprecation" ) + public static boolean hasType( final String type , final Item item , final int metadata ) + { + if ( item instanceof ItemBlock ) { + final MBlockType bt = MBlockTypes.get( type ); + if ( bt != null && bt.matches( ( (ItemBlock) item ).block.getStateFromMeta( metadata ) ) ) { + return true; + } + } + final MItemType it = MItemTypes.get( type ); + return it != null && it.matches( item , metadata ); + } + + + public static boolean hasType( final String type , final Block block ) + { + return UMaterials.hasType( type , block.getDefaultState( ) ); + } + + + public static boolean hasType( final String type , final IBlockState state ) + { + final MBlockType bt = MBlockTypes.get( type ); + if ( bt != null && bt.matches( state ) ) { + return true; + } + + final MItemType it = MItemTypes.get( type ); + final Block block = state.getBlock( ); + final Item item = Item.getItemFromBlock( block ); + return it != null && item != null && it.matches( item , block.damageDropped( state ) ); + } + + + public static boolean hasType( final MBlockType type , final ItemStack stack ) + { + return UMaterials.hasType( type , stack.getItem( ) , stack.getMetadata( ) ); + } + + + @SuppressWarnings( "deprecation" ) + public static boolean hasType( final MBlockType type , final Item item , final int metadata ) + { + final MItemType equivalentItemCheck = MItemTypes.get( type.name ); + if ( equivalentItemCheck != null && equivalentItemCheck.matches( item , metadata ) ) { + return true; + } + if ( ! ( item instanceof ItemBlock ) ) { + return false; + } + return UMaterials.hasType( type , ( (ItemBlock) item ).block.getStateFromMeta( metadata ) ); + } + + + public static boolean hasType( final MBlockType type , final Block block ) + { + return UMaterials.hasType( type , block.getDefaultState( ) ); + } + + + public static boolean hasType( final MBlockType type , final IBlockState state ) + { + return type.matches( state ); + } + + + public static boolean hasType( final MItemType type , final ItemStack stack ) + { + return UMaterials.hasType( type , stack.getItem( ) , stack.getMetadata( ) ); + } + + + @SuppressWarnings( "deprecation" ) + public static boolean hasType( final MItemType type , final Item item , final int metadata ) + { + if ( type.matches( item , metadata ) ) { + return true; + } + if ( item instanceof ItemBlock ) { + final MBlockType bt = MBlockTypes.get( type.name ); + return bt != null && bt.matches( ( (ItemBlock) item ).block.getStateFromMeta( metadata ) ); + } + return false; + } + + + public static boolean hasType( final MItemType type , final Block block ) + { + final Item item = Item.getItemFromBlock( block ); + return item != null && type.matches( item , block.damageDropped( block.getDefaultState( ) ) ); + } + + + public static boolean hasType( final MItemType type , final IBlockState state ) + { + final Block block = state.getBlock( ); + final Item item = Item.getItemFromBlock( block ); + return item != null && type.matches( item , block.damageDropped( state ) ); + } +} diff --git a/src/java/mmm/world/gen/WGBasalt.java b/src/java/mmm/world/gen/WGBasalt.java index 28c020e..5d7c13f 100644 --- a/src/java/mmm/world/gen/WGBasalt.java +++ b/src/java/mmm/world/gen/WGBasalt.java @@ -4,6 +4,8 @@ package mmm.world.gen; import java.util.Random; import mmm.MmmMaterials; +import mmm.materials.MBlockTypes; +import mmm.utils.UMaterials; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; @@ -92,7 +94,7 @@ public class WGBasalt mbps.setPos( mbp.getX( ) + i , yb , mbp.getZ( ) + j ); // System.err.println( "pos = " + mbps ); - if ( MmmMaterials.isRock( world.getBlockState( mbps ) ) ) { + if ( UMaterials.hasType( MBlockTypes.ROCK , world.getBlockState( mbps ) ) ) { rockNearLava[ offset ] = true; } }