Improved information about materials

This commit is contained in:
Emmanuel BENOîT 2016-07-15 11:16:37 +02:00
parent d99f7be107
commit 9398e258af
19 changed files with 598 additions and 100 deletions

View file

@ -1,8 +1,6 @@
package mmm; package mmm;
import mmm.core.CRegistry;
import mmm.materials.I_MRock;
import mmm.materials.MAlloys; import mmm.materials.MAlloys;
import mmm.materials.MItems; import mmm.materials.MItems;
import mmm.materials.MMetals; import mmm.materials.MMetals;
@ -12,12 +10,6 @@ import mmm.materials.MWoods;
import mmm.materials.traps.MTraps; import mmm.materials.traps.MTraps;
import mmm.materials.trees.MTrees; import mmm.materials.trees.MTrees;
import mmm.materials.trees.MWoodAchievementHandler; 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; 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( ) public static void preInit( )
{ {
// EMPTY // EMPTY

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,9 @@
package mmm.materials;
public interface I_MAlloy
{
public MMetal[] getComponents( );
}

View file

@ -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( );
}
}

View file

@ -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;
}
}

View file

@ -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 );
}
}

View file

@ -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 );
}
}

View file

@ -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;
}
}

View file

@ -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 );
}
}

View file

@ -31,19 +31,18 @@ public class MItems
CRegistry.addRecipeRegistrar( this ); CRegistry.addRecipeRegistrar( this );
// Items that do not correspond to metals or ores // Items that do not correspond to metals or ores
this.SLAG = MmmMaterials.makeItem( "slag" ); this.SLAG = MItem.makeItem( E_MItemType.MISC , "slag" );
this.COKE = MmmMaterials.makeFuel( "coke" , 9600 ); this.COKE = MItem.makeFuel( "coke" , 9600 );
this.PIG_IRON_INGOT = new MMetalItem( E_MMetalItemType.INGOT , "pig_iron" ); this.PIG_IRON_INGOT = MItem.makeItem( E_MItemType.INGOT , "pig_iron" );
CRegistry.addItem( this.PIG_IRON_INGOT );
// Ore drops // Ore drops
this.MALACHITE = MmmMaterials.makeItem( "malachite" ); this.MALACHITE = MItem.makeItem( E_MItemType.ORE , "malachite" );
this.CUPRITE = MmmMaterials.makeItem( "cuprite" ); this.CUPRITE = MItem.makeItem( E_MItemType.ORE , "cuprite" );
this.CASSITERITE = MmmMaterials.makeItem( "cassiterite" ); this.CASSITERITE = MItem.makeItem( E_MItemType.ORE , "cassiterite" );
this.SPHALERITE = MmmMaterials.makeItem( "sphalerite" ); this.SPHALERITE = MItem.makeItem( E_MItemType.ORE , "sphalerite" );
this.ROCK_SALT = MmmMaterials.makeItem( "rock_salt" ); this.ROCK_SALT = MItem.makeItem( E_MItemType.ORE , "rock_salt" );
this.SULPHUR_POWDER = MmmMaterials.makeItem( "sulphur_powder" ); this.SULPHUR_POWDER = MItem.makeItem( E_MItemType.ORE , "sulphur_powder" );
this.SALTPETER = MmmMaterials.makeItem( "saltpeter_powder" ); this.SALTPETER = MItem.makeItem( E_MItemType.ORE , "saltpeter_powder" );
} }

View file

@ -25,8 +25,8 @@ public class MMetal
final MapColor mapColor ) final MapColor mapColor )
{ {
this( baseSmeltingXP , new MMetalBlock( name , hardness , harvestLevel , mapColor ) , // this( baseSmeltingXP , new MMetalBlock( name , hardness , harvestLevel , mapColor ) , //
new MMetalItem( E_MMetalItemType.INGOT , name ) , // new MItem( E_MItemType.INGOT , name ) , //
new MMetalItem( E_MMetalItemType.NUGGET , name ) ); new MItem( E_MItemType.NUGGET , name ) );
} }
@ -49,6 +49,27 @@ public class MMetal
this.BLOCK = block; this.BLOCK = block;
this.INGOT = ingot; this.INGOT = ingot;
this.NUGGET = nugget; 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( ); this.register( );
} }
@ -60,11 +81,11 @@ public class MMetal
CRegistry.addBlock( this.BLOCK ); CRegistry.addBlock( this.BLOCK );
custom = true; custom = true;
} }
if ( this.INGOT instanceof MMetalItem ) { if ( this.INGOT instanceof MItem ) {
CRegistry.addItem( this.INGOT ); CRegistry.addItem( this.INGOT );
custom = true; custom = true;
} }
if ( this.NUGGET instanceof MMetalItem ) { if ( this.NUGGET instanceof MItem ) {
CRegistry.addItem( this.NUGGET ); CRegistry.addItem( this.NUGGET );
custom = true; custom = true;
} }
@ -78,13 +99,13 @@ public class MMetal
@Override @Override
public void registerRecipes( ) 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.addShapelessRecipe( new ItemStack( this.NUGGET , 9 ) , this.INGOT );
GameRegistry.addRecipe( new ItemStack( this.INGOT ) , // GameRegistry.addRecipe( new ItemStack( this.INGOT ) , //
"NNN" , "NNN" , "NNN" , // "NNN" , "NNN" , "NNN" , //
'N' , this.NUGGET ); '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.addShapelessRecipe( new ItemStack( this.INGOT , 9 ) , this.BLOCK );
GameRegistry.addRecipe( new ItemStack( this.BLOCK ) , // GameRegistry.addRecipe( new ItemStack( this.BLOCK ) , //
"III" , "III" , "III" , // "III" , "III" , "III" , //

View file

@ -14,6 +14,9 @@ public class MMetalBlock
extends Block extends Block
{ {
private MMetal metal;
public MMetalBlock( final String name , final float hardness , final int harvestLevel , final MapColor mapColor ) public MMetalBlock( final String name , final float hardness , final int harvestLevel , final MapColor mapColor )
{ {
super( Material.IRON , mapColor ); super( Material.IRON , mapColor );
@ -25,4 +28,16 @@ public class MMetalBlock
CRegistry.setIdentifiers( this , "materials" , "block" , name ); CRegistry.setIdentifiers( this , "materials" , "block" , name );
} }
void setMetal( final MMetal metal )
{
this.metal = metal;
}
public MMetal getMetal( )
{
return this.metal;
}
} }

View file

@ -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 );
}
}

View file

@ -20,7 +20,7 @@ public class MMetals
{ {
this.GOLD = new MMetal( Blocks.GOLD_BLOCK , Items.GOLD_INGOT , Items.GOLD_NUGGET ); this.GOLD = new MMetal( Blocks.GOLD_BLOCK , Items.GOLD_INGOT , Items.GOLD_NUGGET );
this.IRON = new MMetal( Blocks.IRON_BLOCK , Items.IRON_INGOT , // 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.COPPER = new MMetal( "copper" , 0.4f , 4f , 1 , MapColor.DIRT );
this.TIN = new MMetal( "tin" , 0.6f , 1f , 0 , MapColor.GRAY ); this.TIN = new MMetal( "tin" , 0.6f , 1f , 0 , MapColor.GRAY );

View file

@ -35,7 +35,7 @@ public class MOre
private MMetal metal; private MMetal metal;
private int genQuantity; private int genQuantity;
private E_MMetalItemType smeltingOutput; private E_MItemType smeltingOutput;
public MOre( final String name , final int harvestLevel ) public MOre( final String name , final int harvestLevel )
@ -87,6 +87,13 @@ public class MOre
this.dropMax = dropMax; this.dropMax = dropMax;
this.dropItems = item; this.dropItems = item;
this.dropMeta = meta; 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; return this;
} }
@ -109,17 +116,17 @@ public class MOre
public MOre setMetal( final MMetal metal ) 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 ) 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; assert metal != null && quantity > 0;
this.metal = metal; this.metal = metal;

View file

@ -46,7 +46,7 @@ public class MOres
.setDrops( MmmMaterials.ITEM.CUPRITE ) // .setDrops( MmmMaterials.ITEM.CUPRITE ) //
.setExperience( 2 , 5 ); .setExperience( 2 , 5 );
this.CASSITERITE = new MOre( "cassiterite" , 0 )// 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 ) // .setDrops( MmmMaterials.ITEM.CASSITERITE , 2 , 5 ) //
.setExperience( 2 , 5 ); .setExperience( 2 , 5 );
this.SPHALERITE = new MOre( "sphalerite" , 1 ) // this.SPHALERITE = new MOre( "sphalerite" , 1 ) //

View file

@ -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 ) );
}
}

View file

@ -4,6 +4,8 @@ package mmm.world.gen;
import java.util.Random; import java.util.Random;
import mmm.MmmMaterials; import mmm.MmmMaterials;
import mmm.materials.MBlockTypes;
import mmm.utils.UMaterials;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -92,7 +94,7 @@ public class WGBasalt
mbps.setPos( mbp.getX( ) + i , yb , mbp.getZ( ) + j ); mbps.setPos( mbp.getX( ) + i , yb , mbp.getZ( ) + j );
// System.err.println( "pos = " + mbps ); // System.err.println( "pos = " + mbps );
if ( MmmMaterials.isRock( world.getBlockState( mbps ) ) ) { if ( UMaterials.hasType( MBlockTypes.ROCK , world.getBlockState( mbps ) ) ) {
rockNearLava[ offset ] = true; rockNearLava[ offset ] = true;
} }
} }