Copper blocks

+ mostly-automatic handling of the metal block stuff
This commit is contained in:
Emmanuel BENOîT 2016-06-17 08:36:18 +02:00
parent 0f5b02aea6
commit a4f21d38a1
9 changed files with 89 additions and 19 deletions

View file

@ -1,5 +1,6 @@
package mmm.materials; package mmm.materials;
public enum E_MMetalItemType { public enum E_MMetalItemType {
INGOT( "ingot" ) , INGOT( "ingot" ) ,
NUGGET( "nugget" ); NUGGET( "nugget" );

View file

@ -3,6 +3,8 @@ package mmm.materials;
import mmm.utils.I_URecipeRegistrar; import mmm.utils.I_URecipeRegistrar;
import mmm.utils.URegistry; import mmm.utils.URegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
@ -14,43 +16,53 @@ public class MMetal
{ {
public final float SMELTING_XP; public final float SMELTING_XP;
public final Block BLOCK;
public final Item INGOT; public final Item INGOT;
public final Item NUGGET; public final Item NUGGET;
public MMetal( final String name , float baseSmeltingXP ) public MMetal( final String name , final float baseSmeltingXP , float hardness , int harvestLevel ,
MapColor mapColor )
{ {
this( baseSmeltingXP , // this( baseSmeltingXP , new MMetalBlock( name , hardness , harvestLevel , mapColor ) , //
new MMetalItem( E_MMetalItemType.INGOT , name ) , // new MMetalItem( E_MMetalItemType.INGOT , name ) , //
new MMetalItem( E_MMetalItemType.NUGGET , name ) ); new MMetalItem( E_MMetalItemType.NUGGET , name ) );
} }
public MMetal( final Item ingot , final Item nugget ) public MMetal( final Block block , final Item ingot , final Item nugget )
{ {
this( 0 , ingot , nugget ); this( 0 , block , ingot , nugget );
} }
protected MMetal( float baseSmeltingXP , Item ingot , Item nugget ) protected MMetal( final float baseSmeltingXP , final Block block , final Item ingot , final Item nugget )
{ {
SMELTING_XP = baseSmeltingXP; this.SMELTING_XP = baseSmeltingXP;
INGOT = ingot; this.BLOCK = block;
NUGGET = nugget; this.INGOT = ingot;
this.NUGGET = nugget;
this.register( ); this.register( );
} }
protected MMetal register( ) protected MMetal register( )
{ {
boolean custom = false;
if ( this.BLOCK instanceof MMetalBlock ) {
URegistry.addBlock( this.BLOCK );
custom = true;
}
if ( this.INGOT instanceof MMetalItem ) { if ( this.INGOT instanceof MMetalItem ) {
URegistry.addItem( this.INGOT ); URegistry.addItem( this.INGOT );
custom = true;
} }
if ( this.NUGGET instanceof MMetalItem ) { if ( this.NUGGET instanceof MMetalItem ) {
URegistry.addItem( this.NUGGET ); URegistry.addItem( this.NUGGET );
custom = true;
} }
if ( this.INGOT instanceof MMetalItem || this.NUGGET instanceof MMetalItem ) { if ( custom ) {
this.registerRecipes( ); URegistry.addRecipeRegistrar( this );
} }
return this; return this;
} }
@ -59,10 +71,18 @@ public class MMetal
@Override @Override
public void registerRecipes( ) public void registerRecipes( )
{ {
if ( this.INGOT instanceof MMetalItem || this.NUGGET instanceof MMetalItem ) {
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 ) {
GameRegistry.addShapelessRecipe( new ItemStack( this.INGOT , 9 ) , this.BLOCK );
GameRegistry.addRecipe( new ItemStack( this.BLOCK ) , //
"III" , "III" , "III" , //
'I' , this.INGOT );
}
}
} }

View file

@ -0,0 +1,28 @@
package mmm.materials;
import mmm.utils.URegistry;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
public class MMetalBlock
extends Block
{
public MMetalBlock( String name , float hardness , int harvestLevel , MapColor mapColor )
{
super( Material.IRON , mapColor );
this.setHardness( hardness );
this.setResistance( 10f );
this.setSoundType( SoundType.METAL );
this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS );
this.setHarvestLevel( "pickaxe" , harvestLevel );
URegistry.setIdentifiers( this , "materials" , "block" , name );
}
}

View file

@ -5,7 +5,9 @@ import mmm.materials.ore.MOCopper;
import mmm.materials.ore.MOCuprite; import mmm.materials.ore.MOCuprite;
import mmm.materials.ore.MOMalachite; import mmm.materials.ore.MOMalachite;
import mmm.utils.URegistry; import mmm.utils.URegistry;
import net.minecraft.block.material.MapColor;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -26,13 +28,19 @@ public class Materials
public static final MOre ORE_CUPRITE; public static final MOre ORE_CUPRITE;
static { static {
GOLD = new MMetal( Items.GOLD_INGOT , Items.GOLD_NUGGET ); // Vanilla metals
IRON = new MMetal( Items.IRON_INGOT , new MMetalItem( E_MMetalItemType.NUGGET , "iron" ) ); GOLD = new MMetal( Blocks.GOLD_BLOCK , Items.GOLD_INGOT , Items.GOLD_NUGGET );
COPPER = new MMetal( "copper" , 0.4f ); IRON = new MMetal( Blocks.IRON_BLOCK , Items.IRON_INGOT , //
new MMetalItem( E_MMetalItemType.NUGGET , "iron" ) );
// Custom metals
COPPER = new MMetal( "copper" , 0.4f , 4f , 1 , MapColor.DIRT );
// Stones extracted from ores
URegistry.addItem( STONE_MALACHITE = makeStone( "malachite" ) ); URegistry.addItem( STONE_MALACHITE = makeStone( "malachite" ) );
URegistry.addItem( STONE_CUPRITE = makeStone( "cuprite" ) ); URegistry.addItem( STONE_CUPRITE = makeStone( "cuprite" ) );
// Actual ores
URegistry.addBlock( ORE_COPPER = new MOCopper( ) ); URegistry.addBlock( ORE_COPPER = new MOCopper( ) );
URegistry.addBlock( ORE_MALACHITE = new MOMalachite( ) ); URegistry.addBlock( ORE_MALACHITE = new MOMalachite( ) );
URegistry.addBlock( ORE_CUPRITE = new MOCuprite( ) ); URegistry.addBlock( ORE_CUPRITE = new MOCuprite( ) );

View file

@ -0,0 +1,5 @@
{
"variants": {
"normal": { "model": "mmm:materials/block/copper" }
}
}

View file

@ -25,11 +25,10 @@ item.mmm.materials.nugget.iron.name=Iron Nugget
item.mmm.materials.ingot.copper.name=Copper Ingot item.mmm.materials.ingot.copper.name=Copper Ingot
item.mmm.materials.nugget.copper.name=Copper Nugget item.mmm.materials.nugget.copper.name=Copper Nugget
tile.mmm.materials.block.copper.name=Copper Block
tile.mmm.materials.ore.copper.name=Native Copper tile.mmm.materials.ore.copper.name=Native Copper
item.mmm.materials.stone.malachite.name=Malachite item.mmm.materials.stone.malachite.name=Malachite
tile.mmm.materials.ore.malachite.name=Malachite Ore tile.mmm.materials.ore.malachite.name=Malachite Ore
item.mmm.materials.stone.cuprite.name=Cuprite item.mmm.materials.stone.cuprite.name=Cuprite
tile.mmm.materials.ore.cuprite.name=Cuprite Ore tile.mmm.materials.ore.cuprite.name=Cuprite Ore

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "mmm:blocks/materials/block/copper"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "mmm:block/materials/block/copper"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B