Alloy furnace - Output hopper

Takes invalid input and invalid fuel in addition to actual output
This commit is contained in:
Emmanuel BENOîT 2016-06-25 08:54:22 +02:00
parent c30718080e
commit 258d8b417e
3 changed files with 120 additions and 4 deletions

View file

@ -44,10 +44,12 @@ materials.ores No Tin
materials.ores No Zinc
-------------------------------------------------------------------------------------------------------
tech.base No Alloy furnace
-> let output hoppers take empty buckets / invalid input
(make that configurable)
-> redstone activation
-> make redstone activation configurable
-> make output hopper configurable
-> comparator signal configuration
(inventory mode w/ combinations, valid ingredients, burn time, alloying time)
(inventory mode w/ combinations, valid ingredients, burn time,
alloying time)
-> code clean-up
tech.base No Coke oven
-------------------------------------------------------------------------------------------------------

View file

@ -0,0 +1,114 @@
package mmm.tech.base;
import mmm.utils.UInventoryGrid;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.items.IItemHandler;
public class TBAlloyFurnaceOutputHopper
implements IItemHandler
{
private final TBAlloyFurnaceTileEntity tileEntity;
private final int nSlots;
public TBAlloyFurnaceOutputHopper( final TBAlloyFurnaceTileEntity tileEntity )
{
this.tileEntity = tileEntity;
this.nSlots = this.tileEntity.input.getSizeInventory( ) + this.tileEntity.fuel.getSizeInventory( )
+ this.tileEntity.output.getSizeInventory( );
}
@Override
public int getSlots( )
{
return this.nSlots;
}
@Override
public ItemStack getStackInSlot( final int slot )
{
final int nInputSlots = this.tileEntity.input.getSizeInventory( );
if ( slot < nInputSlots ) {
return this.tileEntity.input.getStackInSlot( slot );
} else {
final int nFuelSlots = this.tileEntity.fuel.getSizeInventory( );
if ( slot < nInputSlots + nFuelSlots ) {
return this.tileEntity.fuel.getStackInSlot( slot - nInputSlots );
} else {
return this.tileEntity.output.getStackInSlot( slot - nInputSlots - nFuelSlots );
}
}
}
@Override
public ItemStack insertItem( final int slot , final ItemStack stack , final boolean simulate )
{
return null;
}
@Override
public ItemStack extractItem( final int slot , final int amount , final boolean simulate )
{
if ( amount == 0 ) {
return null;
}
final ItemStack stackInSlot = this.getStackInSlot( slot );
if ( stackInSlot == null ) {
return null;
}
// Extracting invalid input items
final int nInputSlots = this.tileEntity.input.getSizeInventory( );
if ( slot < nInputSlots ) {
if ( this.tileEntity.recipe.hasInput( stackInSlot ) ) {
return null;
}
// XXX check configuration
return this.doExtractItems( this.tileEntity.input , stackInSlot , slot , amount , simulate );
}
// Extracting invalid fuel items
final int nFuelSlots = this.tileEntity.fuel.getSizeInventory( );
if ( slot < nInputSlots + nFuelSlots ) {
if ( TileEntityFurnace.isItemFuel( stackInSlot ) ) {
return null;
}
return this.doExtractItems( this.tileEntity.fuel , stackInSlot , slot - nInputSlots , amount , simulate );
}
return this.doExtractItems( this.tileEntity.output , stackInSlot , slot - ( nInputSlots + nFuelSlots ) ,
amount , simulate );
}
private ItemStack doExtractItems( final UInventoryGrid inventory , final ItemStack stackInSlot , final int slot ,
final int amount , final boolean simulate )
{
if ( simulate ) {
if ( stackInSlot.stackSize < amount ) {
return stackInSlot.copy( );
} else {
final ItemStack copy = stackInSlot.copy( );
copy.stackSize = amount;
return copy;
}
} else {
final int m = Math.min( stackInSlot.stackSize , amount );
final ItemStack decrStackSize = inventory.decrStackSize( slot , m );
inventory.markDirty( );
return decrStackSize;
}
}
}

View file

@ -52,7 +52,7 @@ public class TBAlloyFurnaceTileEntity
this.inputHopper = new InvWrapper( this.input );
this.fuelHopper = new InvWrapper( this.fuel );
this.outputHopper = new InvWrapper( this.output );
this.outputHopper = new TBAlloyFurnaceOutputHopper( this );
}