Alloy furnace - Produce slag

Slag is produced if alloying fails due to missing fuel, as well as a
result of recipes.
This commit is contained in:
Emmanuel BENOîT 2016-06-23 20:39:39 +02:00
parent b5176a9f49
commit fab9b117ab
6 changed files with 69 additions and 13 deletions

View file

@ -56,6 +56,7 @@ public class MAlloyRecipe
private int burnTime; private int burnTime;
private float xp; private float xp;
private ItemStack output; private ItemStack output;
private int slag;
private final ItemStack[] inputs = new ItemStack[ MAlloyRecipe.MAX_ALLOY_INPUTS ]; private final ItemStack[] inputs = new ItemStack[ MAlloyRecipe.MAX_ALLOY_INPUTS ];
private int nInputs; private int nInputs;
@ -75,6 +76,9 @@ public class MAlloyRecipe
public MAlloyRecipe.Builder setBurnTime( final int burnTime ) public MAlloyRecipe.Builder setBurnTime( final int burnTime )
{ {
if ( burnTime <= 0 ) {
throw new IllegalArgumentException( "invalid burn time" );
}
this.burnTime = burnTime; this.burnTime = burnTime;
return this; return this;
} }
@ -82,6 +86,9 @@ public class MAlloyRecipe
public MAlloyRecipe.Builder setExperience( final float xp ) public MAlloyRecipe.Builder setExperience( final float xp )
{ {
if ( xp < 0 ) {
throw new IllegalArgumentException( "invalid experience" );
}
this.xp = xp; this.xp = xp;
return this; return this;
} }
@ -122,6 +129,16 @@ public class MAlloyRecipe
} }
public MAlloyRecipe.Builder setSlag( final int slag )
{
if ( slag < 0 ) {
throw new IllegalArgumentException( "invalid amount of slag" );
}
this.slag = slag;
return this;
}
public MAlloyRecipe.Builder addInput( final Item item ) public MAlloyRecipe.Builder addInput( final Item item )
{ {
return this.addInput( new ItemStack( item ) ); return this.addInput( new ItemStack( item ) );
@ -185,8 +202,8 @@ public class MAlloyRecipe
inputs[ i ] = this.inputs[ i ].copy( ); inputs[ i ] = this.inputs[ i ].copy( );
} }
final MAlloyRecipe recipe = new MAlloyRecipe( this.name , this.burnTime , this.xp , this.output.copy( ) , final MAlloyRecipe recipe = new MAlloyRecipe( this.name , this.burnTime , this.xp , this.slag ,
inputs ); this.output.copy( ) , inputs );
registry.byName.put( this.name , recipe ); registry.byName.put( this.name , recipe );
registry.list.add( recipe ); registry.list.add( recipe );
this.name = null; this.name = null;
@ -215,16 +232,18 @@ public class MAlloyRecipe
public final ResourceLocation name; public final ResourceLocation name;
public final int burnTime; public final int burnTime;
public final float xp; public final float xp;
public final int slag;
public final ItemStack output; public final ItemStack output;
public final ItemStack[] inputs; public final ItemStack[] inputs;
private MAlloyRecipe( final ResourceLocation name , final int burnTime , final float xp , final ItemStack output , private MAlloyRecipe( final ResourceLocation name , final int burnTime , final float xp , final int slag ,
final ItemStack[] inputs ) final ItemStack output , final ItemStack[] inputs )
{ {
this.name = name; this.name = name;
this.burnTime = burnTime; this.burnTime = burnTime;
this.xp = xp; this.xp = xp;
this.slag = slag;
this.output = output; this.output = output;
this.inputs = inputs; this.inputs = inputs;
} }
@ -264,4 +283,14 @@ public class MAlloyRecipe
return true; return true;
} }
public int getTotalInputItems( )
{
int sum = 0;
for ( int i = 0 ; i < this.inputs.length ; i++ ) {
sum += this.inputs[ i ].stackSize;
}
return sum;
}
} }

View file

@ -4,6 +4,7 @@ package mmm.materials;
import mmm.materials.ore.MOCopper; 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.I_URecipeRegistrar;
import mmm.utils.URegistry; import mmm.utils.URegistry;
import net.minecraft.block.material.MapColor; import net.minecraft.block.material.MapColor;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
@ -14,12 +15,14 @@ import net.minecraft.item.Item;
public class Materials public class Materials
implements I_URecipeRegistrar
{ {
public static final MMetal GOLD; public static final MMetal GOLD;
public static final MMetal IRON; public static final MMetal IRON;
public static final MMetal COPPER; public static final MMetal COPPER;
public static final Item ITEM_SLAG;
public static final Item ITEM_MALACHITE; public static final Item ITEM_MALACHITE;
public static final Item ITEM_CUPRITE; public static final Item ITEM_CUPRITE;
public static final Item ITEM_COKE; public static final Item ITEM_COKE;
@ -38,18 +41,18 @@ public class Materials
COPPER = new MMetal( "copper" , 0.4f , 4f , 1 , MapColor.DIRT ); COPPER = new MMetal( "copper" , 0.4f , 4f , 1 , MapColor.DIRT );
// Items that do not correspond to metals or ores // Items that do not correspond to metals or ores
URegistry.addItem( ITEM_SLAG = Materials.makeItem( "slag" ) );
URegistry.addItem( ITEM_MALACHITE = Materials.makeItem( "malachite" ) ); URegistry.addItem( ITEM_MALACHITE = Materials.makeItem( "malachite" ) );
URegistry.addItem( ITEM_CUPRITE = Materials.makeItem( "cuprite" ) ); URegistry.addItem( ITEM_CUPRITE = Materials.makeItem( "cuprite" ) );
URegistry.addItem( ITEM_COKE = Materials.makeFuel( "coke" , 4800 ) ); URegistry.addItem( ITEM_COKE = Materials.makeFuel( "coke" , 9600 ) );
// Actual ores // 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( ) );
// Alloy recipes // Other recipes
MAlloyRecipe.build( ).setName( "materials/coke" ).setBurnTime( 1600 ).setExperience( 0.1f ) URegistry.addRecipeRegistrar( new Materials( ) );
.setOutput( ITEM_COKE ).addInput( Items.COAL ).register( );
} }
@ -75,4 +78,19 @@ public class Materials
// EMPTY // EMPTY
} }
private Materials( )
{
// EMPTY
}
@Override
public void registerRecipes( )
{
// Alloy recipes
MAlloyRecipe.build( ).setName( "materials/coke" ).setBurnTime( 3200 ).setExperience( 0.1f )
.addInput( Items.COAL , 2 ).setOutput( ITEM_COKE ).setSlag( 1 ).register( );
}
} }

View file

@ -2,6 +2,7 @@ package mmm.tech.base;
import mmm.materials.MAlloyRecipe; import mmm.materials.MAlloyRecipe;
import mmm.materials.Materials;
import mmm.utils.UInventoryGrid; import mmm.utils.UInventoryGrid;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -111,7 +112,10 @@ public class TBAlloyFurnaceTileEntity
if ( this.alloying != null ) { if ( this.alloying != null ) {
this.alloyCurrent--; this.alloyCurrent--;
if ( this.alloyCurrent == 0 ) { if ( this.alloyCurrent == 0 ) {
this.addOutput( ); this.addOutput( this.alloying.output );
if ( this.alloying.slag != 0 ) {
this.addOutput( new ItemStack( Materials.ITEM_SLAG , this.alloying.slag ) );
}
if ( this.canAlloy( ) ) { if ( this.canAlloy( ) ) {
this.startAlloying( ); this.startAlloying( );
} else { } else {
@ -123,7 +127,7 @@ public class TBAlloyFurnaceTileEntity
if ( this.burnCurrent == 0 ) { if ( this.burnCurrent == 0 ) {
if ( this.alloying != null ) { if ( this.alloying != null ) {
if ( !this.startBurning( this.alloyCurrent ) ) { if ( !this.startBurning( this.alloyCurrent ) ) {
// XXX produce slag this.addOutput( new ItemStack( Materials.ITEM_SLAG , this.alloying.getTotalInputItems( ) ) );
this.alloying = null; this.alloying = null;
this.alloyCurrent = this.burnCurrent = this.burnTotal = 0; this.alloyCurrent = this.burnCurrent = this.burnTotal = 0;
} }
@ -324,9 +328,8 @@ public class TBAlloyFurnaceTileEntity
} }
private void addOutput( ) private void addOutput( ItemStack wanted )
{ {
final ItemStack wanted = this.alloying.output;
final int maxStackSize = Math.min( this.output.getInventoryStackLimit( ) , wanted.getMaxStackSize( ) ); final int maxStackSize = Math.min( this.output.getInventoryStackLimit( ) , wanted.getMaxStackSize( ) );
int added = 0; int added = 0;
for ( int i = 0 ; i < this.output.slotsCount ; i++ ) { for ( int i = 0 ; i < this.output.slotsCount ; i++ ) {

View file

@ -32,7 +32,7 @@ public class TechBase
URegistry.addServerMessage( TBAlloyFurnaceMessage.class ); URegistry.addServerMessage( TBAlloyFurnaceMessage.class );
// FIXME test, remove this later // FIXME test, remove this later
MAlloyRecipe.build( ).setName( "test" ).setBurnTime( 50 ).setExperience( .05f ) MAlloyRecipe.build( ).setName( "test" ).setBurnTime( 50 ).setExperience( .05f ).setSlag( 1 )
.setOutput( Items.COOKED_CHICKEN , 10 ).addInput( Items.COOKED_BEEF ).addInput( Items.COOKED_PORKCHOP ) .setOutput( Items.COOKED_CHICKEN , 10 ).addInput( Items.COOKED_BEEF ).addInput( Items.COOKED_PORKCHOP )
.register( ); .register( );
} }

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B