Some refactoring. Also, copper.

This commit is contained in:
Emmanuel BENOîT 2016-06-15 21:36:57 +02:00
parent c9c0a6e31e
commit a43b2730d3
18 changed files with 150 additions and 45 deletions

View file

@ -0,0 +1,14 @@
package mmm.materials;
public enum E_MMetalItemType {
INGOT( "ingot" ) ,
NUGGET( "nugget" );
public final String name;
private E_MMetalItemType( String name )
{
this.name = name;
}
}

View file

@ -0,0 +1,58 @@
package mmm.materials;
import mmm.utils.I_URecipeRegistrar;
import mmm.utils.URegistry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class MMetal
implements I_URecipeRegistrar
{
public final Item INGOT;
public final Item NUGGET;
public MMetal( final String name )
{
this.INGOT = new MMetalItem( E_MMetalItemType.INGOT , name );
this.NUGGET = new MMetalItem( E_MMetalItemType.NUGGET , name );
}
public MMetal( final Item ingot , final Item nugget )
{
this.INGOT = ingot;
this.NUGGET = nugget;
}
public MMetal register( )
{
if ( this.INGOT instanceof MMetalItem ) {
URegistry.addItem( this.INGOT );
}
if ( this.NUGGET instanceof MMetalItem ) {
URegistry.addItem( this.NUGGET );
}
if ( this.INGOT instanceof MMetalItem || this.NUGGET instanceof MMetalItem ) {
this.registerRecipes( );
}
return this;
}
@Override
public void registerRecipes( )
{
GameRegistry.addShapelessRecipe( new ItemStack( this.NUGGET , 9 ) , this.INGOT );
GameRegistry.addRecipe( new ItemStack( this.INGOT ) , //
"NNN" , "NNN" , "NNN" , //
'N' , this.NUGGET );
}
}

View file

@ -7,15 +7,14 @@ import net.minecraft.item.Item;
public class MItem public class MMetalItem
extends Item extends Item
{ {
public MMetalItem( final E_MMetalItemType type , final String name )
public MItem( String name )
{ {
super( ); super( );
this.setCreativeTab( CreativeTabs.MATERIALS ); this.setCreativeTab( CreativeTabs.MATERIALS );
URegistry.setIdentifiers( this , "materials" , name ); URegistry.setIdentifiers( this , "materials" , type.name , name );
} }
} }

View file

@ -5,6 +5,7 @@ import java.util.Random;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import mmm.utils.I_URecipeRegistrar;
import mmm.utils.URegistry; import mmm.utils.URegistry;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
@ -18,11 +19,13 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class DOre public class MOre
extends Block extends Block
implements I_URecipeRegistrar
{ {
private int dropMin , dropMax; private int dropMin , dropMax;
private Item dropItems; private Item dropItems;
@ -30,14 +33,17 @@ public class DOre
private int expMin , expMax; private int expMin , expMax;
private MMetal metal;
private float smeltingXP;
public DOre( final String name , final int harvestLevel )
public MOre( final String name , final int harvestLevel )
{ {
this( name , harvestLevel , Material.ROCK.getMaterialMapColor( ) ); this( name , harvestLevel , Material.ROCK.getMaterialMapColor( ) );
} }
public DOre( final String name , final int harvestLevel , final MapColor color ) public MOre( final String name , final int harvestLevel , final MapColor color )
{ {
super( Material.ROCK , color ); super( Material.ROCK , color );
this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS ); this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS );
@ -45,31 +51,33 @@ public class DOre
this.setHardness( 3.0f ); this.setHardness( 3.0f );
this.setResistance( 5.0f ); this.setResistance( 5.0f );
this.setHarvestLevel( "pickaxe" , harvestLevel ); this.setHarvestLevel( "pickaxe" , harvestLevel );
URegistry.setIdentifiers( this , "materials" , "ores" , name ); URegistry.setIdentifiers( this , "materials" , "ore" , name );
this.dropMin = this.dropMax = 1; this.dropMin = this.dropMax = 1;
this.expMin = this.expMax = 0; this.expMin = this.expMax = 0;
this.metal = null;
this.smeltingXP = 0;
} }
public DOre setDrops( final Item item ) public MOre setDrops( final Item item )
{ {
return this.setDrops( item , 0 , 1 , 1 ); return this.setDrops( item , 0 , 1 , 1 );
} }
public DOre setDrops( final Item item , final int meta ) public MOre setDrops( final Item item , final int meta )
{ {
return this.setDrops( item , meta , 1 , 1 ); return this.setDrops( item , meta , 1 , 1 );
} }
public DOre setDrops( final Item item , final int dropMin , final int dropMax ) public MOre setDrops( final Item item , final int dropMin , final int dropMax )
{ {
return this.setDrops( item , 0 , dropMin , dropMax ); return this.setDrops( item , 0 , dropMin , dropMax );
} }
public DOre setDrops( final Item item , final int meta , final int dropMin , final int dropMax ) public MOre setDrops( final Item item , final int meta , final int dropMin , final int dropMax )
{ {
assert dropMin <= dropMax; assert dropMin <= dropMax;
assert dropMin > 0; assert dropMin > 0;
@ -81,13 +89,13 @@ public class DOre
} }
public DOre setExperience( final int value ) public MOre setExperience( final int value )
{ {
return this.setExperience( value , value ); return this.setExperience( value , value );
} }
public DOre setExperience( final int min , final int max ) public MOre setExperience( final int min , final int max )
{ {
assert min <= max; assert min <= max;
assert min >= 0; assert min >= 0;
@ -97,6 +105,14 @@ public class DOre
} }
public MOre setMetal( final MMetal metal , final float smeltingXP )
{
this.metal = metal;
this.smeltingXP = smeltingXP;
return this;
}
@Override @Override
@Nullable @Nullable
public Item getItemDropped( final IBlockState state , final Random rand , final int fortune ) public Item getItemDropped( final IBlockState state , final Random rand , final int fortune )
@ -152,4 +168,19 @@ public class DOre
{ {
return new ItemStack( this ); return new ItemStack( this );
} }
@Override
public void registerRecipes( )
{
if ( this.metal != null ) {
if ( this.dropItems == null ) {
GameRegistry.addSmelting( this , new ItemStack( this.metal.INGOT ) , this.smeltingXP );
} else {
GameRegistry.addSmelting( this.dropItems , new ItemStack( this.metal.INGOT ) , this.smeltingXP );
}
this.metal = null;
}
}
} }

View file

@ -1,27 +1,25 @@
package mmm.materials; package mmm.materials;
import mmm.utils.I_URecipeRegistrar;
import mmm.utils.URegistry; import mmm.utils.URegistry;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class Materials public class Materials
implements I_URecipeRegistrar
{ {
public static final DOre ORE_COPPER; public static final MMetal GOLD;
public static final MMetal IRON;
public static final MMetal COPPER;
public static final MItem NUGGET_IRON; public static final MOre ORE_COPPER;
static { static {
URegistry.addBlock( ORE_COPPER = new DOre( "copper" , 1 ) ); GOLD = new MMetal( Items.GOLD_INGOT , Items.GOLD_NUGGET ).register( );
IRON = new MMetal( Items.IRON_INGOT , new MMetalItem( E_MMetalItemType.NUGGET , "iron" ) ).register( );
COPPER = new MMetal( "copper" ).register( );
URegistry.addItem( NUGGET_IRON = new MItem( "iron_nugget" ) ); URegistry.addBlock( ORE_COPPER = new MOre( "copper" , 1 ).setMetal( COPPER , 0.4f ) );
URegistry.addRecipeRegistrar( new Materials( ) );
} }
@ -36,13 +34,4 @@ public class Materials
// EMPTY // EMPTY
} }
@Override
public void registerRecipes( )
{
GameRegistry.addShapelessRecipe( new ItemStack( Materials.NUGGET_IRON , 9 ) , Items.IRON_INGOT );
GameRegistry.addRecipe( new ItemStack( Items.IRON_INGOT ) , //
"NNN" , "NNN" , "NNN" , //
'N' , Materials.NUGGET_IRON );
}
} }

View file

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

View file

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

View file

@ -21,6 +21,8 @@ tile.mmm.deco.chair.jungle.name=Jungle Wood Chair
tile.mmm.deco.chair.dark_oak.name=Dark Oak Chair tile.mmm.deco.chair.dark_oak.name=Dark Oak Chair
tile.mmm.materials.ores.copper.name=Native Copper item.mmm.materials.nugget.iron.name=Iron Nugget
item.mmm.materials.iron_nugget.name=Iron Nugget item.mmm.materials.ingot.copper.name=Copper Ingot
item.mmm.materials.nugget.copper.name=Copper Nugget
tile.mmm.materials.ore.copper.name=Native Copper

View file

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

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "mmm:items/materials/ingots/copper"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "mmm:items/materials/nuggets/copper"
}
}

View file

@ -1,6 +1,6 @@
{ {
"parent": "minecraft:item/generated", "parent": "minecraft:item/generated",
"textures": { "textures": {
"layer0": "mmm:items/materials/iron_nugget" "layer0": "mmm:items/materials/nuggets/iron"
} }
} }

View file

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

View file

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

View file

Before

Width:  |  Height:  |  Size: 294 B

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

View file

Before

Width:  |  Height:  |  Size: 134 B

After

Width:  |  Height:  |  Size: 134 B