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 float xp;
private ItemStack output;
private int slag;
private final ItemStack[] inputs = new ItemStack[ MAlloyRecipe.MAX_ALLOY_INPUTS ];
private int nInputs;
@ -75,6 +76,9 @@ public class MAlloyRecipe
public MAlloyRecipe.Builder setBurnTime( final int burnTime )
{
if ( burnTime <= 0 ) {
throw new IllegalArgumentException( "invalid burn time" );
}
this.burnTime = burnTime;
return this;
}
@ -82,6 +86,9 @@ public class MAlloyRecipe
public MAlloyRecipe.Builder setExperience( final float xp )
{
if ( xp < 0 ) {
throw new IllegalArgumentException( "invalid experience" );
}
this.xp = xp;
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 )
{
return this.addInput( new ItemStack( item ) );
@ -185,8 +202,8 @@ public class MAlloyRecipe
inputs[ i ] = this.inputs[ i ].copy( );
}
final MAlloyRecipe recipe = new MAlloyRecipe( this.name , this.burnTime , this.xp , this.output.copy( ) ,
inputs );
final MAlloyRecipe recipe = new MAlloyRecipe( this.name , this.burnTime , this.xp , this.slag ,
this.output.copy( ) , inputs );
registry.byName.put( this.name , recipe );
registry.list.add( recipe );
this.name = null;
@ -215,16 +232,18 @@ public class MAlloyRecipe
public final ResourceLocation name;
public final int burnTime;
public final float xp;
public final int slag;
public final ItemStack output;
public final ItemStack[] inputs;
private MAlloyRecipe( final ResourceLocation name , final int burnTime , final float xp , final ItemStack output ,
final ItemStack[] inputs )
private MAlloyRecipe( final ResourceLocation name , final int burnTime , final float xp , final int slag ,
final ItemStack output , final ItemStack[] inputs )
{
this.name = name;
this.burnTime = burnTime;
this.xp = xp;
this.slag = slag;
this.output = output;
this.inputs = inputs;
}
@ -264,4 +283,14 @@ public class MAlloyRecipe
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.MOCuprite;
import mmm.materials.ore.MOMalachite;
import mmm.utils.I_URecipeRegistrar;
import mmm.utils.URegistry;
import net.minecraft.block.material.MapColor;
import net.minecraft.creativetab.CreativeTabs;
@ -14,12 +15,14 @@ import net.minecraft.item.Item;
public class Materials
implements I_URecipeRegistrar
{
public static final MMetal GOLD;
public static final MMetal IRON;
public static final MMetal COPPER;
public static final Item ITEM_SLAG;
public static final Item ITEM_MALACHITE;
public static final Item ITEM_CUPRITE;
public static final Item ITEM_COKE;
@ -38,18 +41,18 @@ public class Materials
COPPER = new MMetal( "copper" , 0.4f , 4f , 1 , MapColor.DIRT );
// 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_CUPRITE = Materials.makeItem( "cuprite" ) );
URegistry.addItem( ITEM_COKE = Materials.makeFuel( "coke" , 4800 ) );
URegistry.addItem( ITEM_COKE = Materials.makeFuel( "coke" , 9600 ) );
// Actual ores
URegistry.addBlock( ORE_COPPER = new MOCopper( ) );
URegistry.addBlock( ORE_MALACHITE = new MOMalachite( ) );
URegistry.addBlock( ORE_CUPRITE = new MOCuprite( ) );
// Alloy recipes
MAlloyRecipe.build( ).setName( "materials/coke" ).setBurnTime( 1600 ).setExperience( 0.1f )
.setOutput( ITEM_COKE ).addInput( Items.COAL ).register( );
// Other recipes
URegistry.addRecipeRegistrar( new Materials( ) );
}
@ -75,4 +78,19 @@ public class Materials
// 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.Materials;
import mmm.utils.UInventoryGrid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
@ -111,7 +112,10 @@ public class TBAlloyFurnaceTileEntity
if ( this.alloying != null ) {
this.alloyCurrent--;
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( ) ) {
this.startAlloying( );
} else {
@ -123,7 +127,7 @@ public class TBAlloyFurnaceTileEntity
if ( this.burnCurrent == 0 ) {
if ( this.alloying != null ) {
if ( !this.startBurning( this.alloyCurrent ) ) {
// XXX produce slag
this.addOutput( new ItemStack( Materials.ITEM_SLAG , this.alloying.getTotalInputItems( ) ) );
this.alloying = null;
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( ) );
int added = 0;
for ( int i = 0 ; i < this.output.slotsCount ; i++ ) {

View file

@ -32,7 +32,7 @@ public class TechBase
URegistry.addServerMessage( TBAlloyFurnaceMessage.class );
// 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 )
.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