Alloy furnace - More configuration options

This commit is contained in:
Emmanuel BENOîT 2016-06-28 16:13:10 +02:00
parent 8174b02091
commit 18b484741a
8 changed files with 236 additions and 49 deletions

View file

@ -44,8 +44,6 @@ materials.ores No Tin
materials.ores No Zinc materials.ores No Zinc
------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------
tech.base No Alloy furnace tech.base No Alloy furnace
-> make redstone activation configurable
-> make output hopper configurable
-> comparator signal configuration -> comparator signal configuration
(inventory mode w/ combinations, valid ingredients, burn time, (inventory mode w/ combinations, valid ingredients, burn time,
alloying time) alloying time)

View file

@ -166,13 +166,41 @@ public class TBAFContainer
@Override @Override
public void setActivationMode( final E_TBActivationMode mode ) public void setActivationMode( final E_TBActivationMode mode )
{
if ( this.world.isRemote ) {
final TileEntity te = this.world.getTileEntity( this.position );
if ( te instanceof TBAFTileEntity ) {
( (TBAFTileEntity) te ).setActivationMode( mode );
}
URegistry.network.sendToServer( new TBActivationModeMessage( mode ) );
} else {
this.tileEntity.setActivationMode( mode );
this.tileEntity.forceUpdate( );
}
}
public int getFlags( )
{ {
final TileEntity te = this.world.getTileEntity( this.position ); final TileEntity te = this.world.getTileEntity( this.position );
if ( te instanceof TBAFTileEntity ) { if ( te instanceof TBAFTileEntity ) {
( (TBAFTileEntity) te ).setActivationMode( mode ); return ( (TBAFTileEntity) te ).flags;
} }
return 0;
}
public void setFlags( final int flags )
{
if ( this.world.isRemote ) { if ( this.world.isRemote ) {
URegistry.network.sendToServer( new TBActivationModeMessage( mode ) ); final TileEntity te = this.world.getTileEntity( this.position );
if ( te instanceof TBAFTileEntity ) {
( (TBAFTileEntity) te ).flags = flags;
URegistry.network.sendToServer( new TBAFMessage( flags ) );
}
} else {
this.tileEntity.flags = flags;
this.tileEntity.forceUpdate( );
} }
} }

View file

@ -176,8 +176,7 @@ public class TBAFGui
gui.setRecipe( gui.currentRecipe - 1 ); gui.setRecipe( gui.currentRecipe - 1 );
} else if ( button == this.bConfirm ) { } else if ( button == this.bConfirm ) {
final MAlloyRecipe recipe = gui.recipes.get( gui.currentRecipe ); final MAlloyRecipe recipe = gui.recipes.get( gui.currentRecipe );
URegistry.network.sendToServer( // URegistry.network.sendToServer( new TBAFMessage( recipe.name , true ) );
new TBAFMessage( gui.container.position , recipe.name , true ) );
gui.container.tileEntity.recipe = recipe; gui.container.tileEntity.recipe = recipe;
} else { } else {
return false; return false;
@ -211,6 +210,9 @@ public class TBAFGui
extends A_UGTab extends A_UGTab
{ {
private GuiButton bActivationMode; private GuiButton bActivationMode;
private GuiButton bInputInvalid;
private GuiButton bOutputInvalidInput;
private GuiButton bOutputInvalidFuel;
private ConfigTab( ) private ConfigTab( )
@ -229,9 +231,16 @@ public class TBAFGui
{ {
super.initGui( x , y ); super.initGui( x , y );
this.bActivationMode = new GuiButton( 100 , x + 10 , y + 10 , this.parent.getXSize( ) - 20 , 20 , this.bActivationMode = new GuiButton( 100 , x + 10 , y + 10 , this.parent.getXSize( ) - 20 , 20 , "" );
this.getActivationText( ) );
this.buttons.add( this.bActivationMode ); this.buttons.add( this.bActivationMode );
this.bInputInvalid = new GuiButton( 100 , x + 10 , y + 40 , this.parent.getXSize( ) - 20 , 20 , "" );
this.buttons.add( this.bInputInvalid );
this.bOutputInvalidInput = new GuiButton( 100 , x + 10 , y + 70 , this.parent.getXSize( ) - 20 , 20 , "" );
this.buttons.add( this.bOutputInvalidInput );
this.bOutputInvalidFuel = new GuiButton( 100 , x + 10 , y + 94 , this.parent.getXSize( ) - 20 , 20 , "" );
this.buttons.add( this.bOutputInvalidFuel );
} }
@ -239,6 +248,9 @@ public class TBAFGui
public void drawBackground( final float partialTicks , final int mouseX , final int mouseY ) public void drawBackground( final float partialTicks , final int mouseX , final int mouseY )
{ {
this.bActivationMode.displayString = this.getActivationText( ); this.bActivationMode.displayString = this.getActivationText( );
this.bInputInvalid.displayString = this.getInputHopperText( );
this.bOutputInvalidInput.displayString = this.getOutputHopperInputText( );
this.bOutputInvalidFuel.displayString = this.getOutputHopperFuelText( );
super.drawBackground( partialTicks , mouseX , mouseY ); super.drawBackground( partialTicks , mouseX , mouseY );
} }
@ -246,11 +258,27 @@ public class TBAFGui
@Override @Override
public boolean onActionPerformed( final GuiButton button ) public boolean onActionPerformed( final GuiButton button )
{ {
final TBAFContainer cont = (TBAFContainer) this.parent.container;
if ( button == this.bActivationMode ) { if ( button == this.bActivationMode ) {
final TBAFContainer cont = (TBAFContainer) this.parent.container;
cont.setActivationMode( cont.getActivationMode( ).next( ) ); cont.setActivationMode( cont.getActivationMode( ).next( ) );
return true; return true;
} }
if ( button == this.bInputInvalid ) {
cont.setFlags( cont.getFlags( ) ^ TBAFTileEntity.F_IH_INVALID );
return true;
}
if ( button == this.bOutputInvalidInput ) {
cont.setFlags( cont.getFlags( ) ^ TBAFTileEntity.F_OH_INVALID_INPUT );
return true;
}
if ( button == this.bOutputInvalidFuel ) {
cont.setFlags( cont.getFlags( ) ^ TBAFTileEntity.F_OH_INVALID_FUEL );
return true;
}
return super.onActionPerformed( button ); return super.onActionPerformed( button );
} }
@ -260,6 +288,36 @@ public class TBAFGui
return I18n.format( ( (TBAFContainer) this.parent.container ).getActivationMode( ).getDisplayName( ) ); return I18n.format( ( (TBAFContainer) this.parent.container ).getActivationMode( ).getDisplayName( ) );
} }
private String getInputHopperText( )
{
final boolean active = ( ( (TBAFContainer) this.parent.container ).getFlags( )
& TBAFTileEntity.F_IH_INVALID ) != 0;
return I18n.format( active
? "container.mmm.alloy_furnace.cfg.ihinv.yes" //
: "container.mmm.alloy_furnace.cfg.ihinv.no" );
}
private String getOutputHopperInputText( )
{
final boolean active = ( ( (TBAFContainer) this.parent.container ).getFlags( )
& TBAFTileEntity.F_OH_INVALID_INPUT ) != 0;
return I18n.format( active
? "container.mmm.alloy_furnace.cfg.ohinvin.yes" //
: "container.mmm.alloy_furnace.cfg.ohinvin.no" );
}
private String getOutputHopperFuelText( )
{
final boolean active = ( ( (TBAFContainer) this.parent.container ).getFlags( )
& TBAFTileEntity.F_OH_INVALID_FUEL ) != 0;
return I18n.format( active
? "container.mmm.alloy_furnace.cfg.ohinvf.yes" //
: "container.mmm.alloy_furnace.cfg.ohinvf.no" );
}
} }
private ArrayList< MAlloyRecipe > recipes; private ArrayList< MAlloyRecipe > recipes;
@ -295,8 +353,7 @@ public class TBAFGui
} }
this.container.setCurrentRecipe( rName , false ); this.container.setCurrentRecipe( rName , false );
URegistry.network.sendToServer( // URegistry.network.sendToServer( new TBAFMessage( rName , false ) );
new TBAFMessage( this.container.position , rName , false ) );
( (RecipeTab) this.tabs[ 1 ] ).enableButtons( ); ( (RecipeTab) this.tabs[ 1 ] ).enableButtons( );
} }

View file

@ -0,0 +1,33 @@
package mmm.tech.base.alloy_furnace;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.wrapper.InvWrapper;
public class TBAFInputHopper
extends InvWrapper
{
private final TBAFTileEntity tileEntity;
public TBAFInputHopper( final TBAFTileEntity tileEntity )
{
super( tileEntity.input );
this.tileEntity = tileEntity;
}
@Override
public ItemStack insertItem( final int slot , final ItemStack stack , final boolean simulate )
{
if ( stack != null && ( this.tileEntity.flags & TBAFTileEntity.F_IH_INVALID ) == 0
&& !this.tileEntity.recipe.hasInput( stack ) ) {
return stack;
}
return super.insertItem( slot , stack , simulate );
}
}

View file

@ -6,7 +6,6 @@ import mmm.utils.I_UMessage;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.ByteBufUtils;
@ -14,9 +13,13 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
public class TBAFMessage public class TBAFMessage
implements I_UMessage implements I_UMessage
{ {
private BlockPos blockPos; private static final int MT_RECIPE = 0;
private ResourceLocation selected; private static final int MT_SET_RECIPE = 1;
private boolean confirm; private static final int MT_SET_FLAGS = 2;
private int type;
private ResourceLocation recipe;
private int flags;
public TBAFMessage( ) public TBAFMessage( )
@ -25,40 +28,64 @@ public class TBAFMessage
} }
public TBAFMessage( final BlockPos blockPos , final ResourceLocation selected , final boolean confirm ) public TBAFMessage( final ResourceLocation selected , final boolean confirm )
{ {
this.blockPos = blockPos; this.type = confirm ? TBAFMessage.MT_SET_RECIPE : TBAFMessage.MT_RECIPE;
this.selected = selected; this.recipe = selected;
this.confirm = confirm; }
public TBAFMessage( int flags )
{
this.type = MT_SET_FLAGS;
this.flags = flags;
} }
@Override @Override
public void fromBytes( final ByteBuf buf ) public void fromBytes( final ByteBuf buf )
{ {
this.blockPos = new BlockPos( buf.readInt( ) , buf.readInt( ) , buf.readInt( ) ); this.type = buf.readByte( );
if ( buf.readBoolean( ) ) { switch ( this.type ) {
this.selected = new ResourceLocation( ByteBufUtils.readUTF8String( buf ) ,
ByteBufUtils.readUTF8String( buf ) ); case MT_RECIPE:
} else { case MT_SET_RECIPE:
this.selected = null; if ( buf.readBoolean( ) ) {
this.recipe = new ResourceLocation( ByteBufUtils.readUTF8String( buf ) ,
ByteBufUtils.readUTF8String( buf ) );
} else {
this.recipe = null;
}
break;
case MT_SET_FLAGS:
this.flags = buf.readByte( );
break;
} }
this.confirm = buf.readBoolean( );
} }
@Override @Override
public void toBytes( final ByteBuf buf ) public void toBytes( final ByteBuf buf )
{ {
buf.writeInt( this.blockPos.getX( ) ); buf.writeByte( this.type );
buf.writeInt( this.blockPos.getY( ) ); switch ( this.type ) {
buf.writeInt( this.blockPos.getZ( ) );
buf.writeBoolean( this.selected != null ); case MT_RECIPE:
if ( this.selected != null ) { case MT_SET_RECIPE:
ByteBufUtils.writeUTF8String( buf , this.selected.getResourceDomain( ) ); buf.writeBoolean( this.recipe != null );
ByteBufUtils.writeUTF8String( buf , this.selected.getResourcePath( ) ); if ( this.recipe != null ) {
ByteBufUtils.writeUTF8String( buf , this.recipe.getResourceDomain( ) );
ByteBufUtils.writeUTF8String( buf , this.recipe.getResourcePath( ) );
}
break;
case MT_SET_FLAGS:
buf.writeByte( this.flags );
break;
} }
buf.writeBoolean( this.confirm );
} }
@ -66,9 +93,23 @@ public class TBAFMessage
public void handleOnServer( final EntityPlayerMP player ) public void handleOnServer( final EntityPlayerMP player )
{ {
final Container curCont = player.openContainer; final Container curCont = player.openContainer;
if ( curCont instanceof TBAFContainer ) { if ( ! ( curCont instanceof TBAFContainer ) ) {
final TBAFContainer container = (TBAFContainer) curCont; return;
container.setCurrentRecipe( this.selected , this.confirm ); }
final TBAFContainer container = (TBAFContainer) curCont;
switch ( this.type ) {
case MT_RECIPE:
case MT_SET_RECIPE:
container.setCurrentRecipe( this.recipe , this.type == TBAFMessage.MT_SET_RECIPE );
break;
case MT_SET_FLAGS:
container.setFlags( flags );
break;
} }
} }

View file

@ -70,17 +70,18 @@ public class TBAFOutputHopper
// Extracting invalid input items // Extracting invalid input items
final int nInputSlots = this.tileEntity.input.getSizeInventory( ); final int nInputSlots = this.tileEntity.input.getSizeInventory( );
if ( slot < nInputSlots ) { if ( slot < nInputSlots ) {
if ( this.tileEntity.recipe.hasInput( stackInSlot ) ) { if ( ( this.tileEntity.flags & TBAFTileEntity.F_OH_INVALID_INPUT ) == 0
|| this.tileEntity.recipe.hasInput( stackInSlot ) ) {
return null; return null;
} }
// XXX check configuration
return this.doExtractItems( this.tileEntity.input , stackInSlot , slot , amount , simulate ); return this.doExtractItems( this.tileEntity.input , stackInSlot , slot , amount , simulate );
} }
// Extracting invalid fuel items // Extracting invalid fuel items
final int nFuelSlots = this.tileEntity.fuel.getSizeInventory( ); final int nFuelSlots = this.tileEntity.fuel.getSizeInventory( );
if ( slot < nInputSlots + nFuelSlots ) { if ( slot < nInputSlots + nFuelSlots ) {
if ( TileEntityFurnace.isItemFuel( stackInSlot ) ) { if ( ( this.tileEntity.flags & TBAFTileEntity.F_OH_INVALID_FUEL ) == 0
|| TileEntityFurnace.isItemFuel( stackInSlot ) ) {
return null; return null;
} }
return this.doExtractItems( this.tileEntity.fuel , stackInSlot , slot - nInputSlots , amount , simulate ); return this.doExtractItems( this.tileEntity.fuel , stackInSlot , slot - nInputSlots , amount , simulate );

View file

@ -30,6 +30,12 @@ public class TBAFTileEntity
extends TileEntity extends TileEntity
implements ITickable , I_TBConfigurableActivation implements ITickable , I_TBConfigurableActivation
{ {
/** Output hopper collects invalid input? */
public static final int F_OH_INVALID_INPUT = 1 << 0;
/** Output hopper collects invalid fuel? */
public static final int F_OH_INVALID_FUEL = 1 << 1;
/** Input hopper allows invalid input? */
public static final int F_IH_INVALID = 1 << 2;
public final UInventoryGrid input; public final UInventoryGrid input;
public final UInventoryGrid fuel; public final UInventoryGrid fuel;
@ -43,6 +49,8 @@ public class TBAFTileEntity
private int burnTotal; private int burnTotal;
private E_TBActivationMode activationMode; private E_TBActivationMode activationMode;
public int flags;
private final IItemHandler inputHopper; private final IItemHandler inputHopper;
private final IItemHandler fuelHopper; private final IItemHandler fuelHopper;
private final IItemHandler outputHopper; private final IItemHandler outputHopper;
@ -51,12 +59,21 @@ public class TBAFTileEntity
public TBAFTileEntity( ) public TBAFTileEntity( )
{ {
this.input = new UInventoryGrid( "Input" , 3 , 5 ); this.input = new UInventoryGrid( "Input" , 3 , 5 );
this.fuel = new UInventoryGrid( "Fuel" , 2 , 2 ); this.fuel = new UInventoryGrid( "Fuel" , 2 , 2 ) {
@Override
public boolean isItemValidForSlot( int index , ItemStack stack )
{
return super.isItemValidForSlot( index , stack ) && TileEntityFurnace.isItemFuel( stack );
}
};
this.output = new UInventoryGrid( "Output" , 2 , 5 ); this.output = new UInventoryGrid( "Output" , 2 , 5 );
this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 ); this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 );
this.activationMode = E_TBActivationMode.ALWAYS_ACTIVE; this.activationMode = E_TBActivationMode.ALWAYS_ACTIVE;
this.flags = TBAFTileEntity.F_OH_INVALID_INPUT | TBAFTileEntity.F_OH_INVALID_FUEL;
this.inputHopper = new InvWrapper( this.input ); this.inputHopper = new TBAFInputHopper( this );
this.fuelHopper = new InvWrapper( this.fuel ); this.fuelHopper = new InvWrapper( this.fuel );
this.outputHopper = new TBAFOutputHopper( this ); this.outputHopper = new TBAFOutputHopper( this );
} }
@ -171,9 +188,7 @@ public class TBAFTileEntity
} }
if ( dirty ) { if ( dirty ) {
this.markDirty( ); this.forceUpdate( );
final IBlockState state = this.worldObj.getBlockState( this.pos );
this.worldObj.notifyBlockUpdate( this.pos , state , state , 3 );
} }
} }
@ -258,13 +273,19 @@ public class TBAFTileEntity
this.recipe = recipe; this.recipe = recipe;
if ( !this.worldObj.isRemote ) { if ( !this.worldObj.isRemote ) {
this.markDirty( ); this.forceUpdate( );
final IBlockState state = this.worldObj.getBlockState( this.pos );
this.worldObj.notifyBlockUpdate( this.pos , state , state , 3 );
} }
} }
public void forceUpdate( )
{
this.markDirty( );
final IBlockState state = this.worldObj.getBlockState( this.pos );
this.worldObj.notifyBlockUpdate( this.pos , state , state , 3 );
}
public boolean isBurning( ) public boolean isBurning( )
{ {
return this.burnTotal != 0; return this.burnTotal != 0;
@ -461,7 +482,7 @@ public class TBAFTileEntity
this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 ); this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 );
} }
byte am = compound.getByte( "ActivationMode" ); final byte am = compound.getByte( "ActivationMode" );
switch ( am ) { switch ( am ) {
default: default:
// XXX log // XXX log
@ -478,6 +499,7 @@ public class TBAFTileEntity
this.activationMode = E_TBActivationMode.DISABLED; this.activationMode = E_TBActivationMode.DISABLED;
break; break;
} }
this.flags = compound.getByte( "Flags" );
this.burnCurrent = compound.getInteger( "BurnCurrent" ); this.burnCurrent = compound.getInteger( "BurnCurrent" );
this.burnTotal = compound.getInteger( "BurnTotal" ); this.burnTotal = compound.getInteger( "BurnTotal" );
@ -500,6 +522,7 @@ public class TBAFTileEntity
{ {
compound.setString( "Recipe" , this.recipe.name.toString( ) ); compound.setString( "Recipe" , this.recipe.name.toString( ) );
compound.setByte( "ActivationMode" , (byte) this.activationMode.ordinal( ) ); compound.setByte( "ActivationMode" , (byte) this.activationMode.ordinal( ) );
compound.setByte( "Flags" , (byte) this.flags );
if ( this.alloying != null ) { if ( this.alloying != null ) {
compound.setString( "AlloyRecipe" , this.alloying.name.toString( ) ); compound.setString( "AlloyRecipe" , this.alloying.name.toString( ) );
compound.setInteger( "AlloyCurrent" , this.alloyCurrent ); compound.setInteger( "AlloyCurrent" , this.alloyCurrent );

View file

@ -25,6 +25,12 @@ item.mmm.tech.base.alloy_furnace.name=Alloy Furnace
container.mmm.alloy_furnace.contents=Furnace Contents container.mmm.alloy_furnace.contents=Furnace Contents
container.mmm.alloy_furnace.recipe=Alloy Selection container.mmm.alloy_furnace.recipe=Alloy Selection
container.mmm.alloy_furnace.select=Select Alloy container.mmm.alloy_furnace.select=Select Alloy
container.mmm.alloy_furnace.cfg.ihinv.yes=Allow invalid hopper input
container.mmm.alloy_furnace.cfg.ihinv.no=Block invalid hopper input
container.mmm.alloy_furnace.cfg.ohinvin.yes=Remove invalid input
container.mmm.alloy_furnace.cfg.ohinvin.no=Keep invalid input
container.mmm.alloy_furnace.cfg.ohinvf.yes=Remove spent fuel buckets
container.mmm.alloy_furnace.cfg.ohinvf.no=Keep spent fuel buckets
item.mmm.tech.tools.copper.shovel.name=Copper Shovel item.mmm.tech.tools.copper.shovel.name=Copper Shovel