Alloy furnace - Comparator output control

This commit is contained in:
Emmanuel BENOîT 2016-06-29 11:02:28 +02:00
parent 67d6f34fcc
commit 63e3c2dbc3
6 changed files with 199 additions and 92 deletions

View file

@ -44,9 +44,7 @@ materials.ores No Tin
materials.ores No Zinc materials.ores No Zinc
------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------
tech.base No Alloy furnace tech.base No Alloy furnace
-> comparator signal configuration -> check item behaviour
(inventory mode w/ combinations, valid ingredients, burn time,
alloying time)
tech.base No Coke oven tech.base No Coke oven
------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------
animals ??? Goats animals ??? Goats

View file

@ -25,7 +25,6 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents; import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryHelper; import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -395,7 +394,7 @@ public class TBAFBlock
if ( ! ( te instanceof TBAFTileEntity ) ) { if ( ! ( te instanceof TBAFTileEntity ) ) {
return 0; return 0;
} }
return Container.calcRedstoneFromInventory( ( (TBAFTileEntity) te ).output ); return ( (TBAFTileEntity) te ).getComparatorValue( );
} }

View file

@ -16,6 +16,7 @@ import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.config.GuiCheckBox;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -210,9 +211,7 @@ public class TBAFGui
extends A_UGTab extends A_UGTab
{ {
private GuiButton bActivationMode; private GuiButton bActivationMode;
private GuiButton bInputInvalid; private GuiCheckBox bFlags[];
private GuiButton bOutputInvalidInput;
private GuiButton bOutputInvalidFuel;
private ConfigTab( ) private ConfigTab( )
@ -231,16 +230,31 @@ 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 , "" ); int id = 100;
this.bActivationMode = new GuiButton( id++ , x + 10 , y + 10 , this.parent.getXSize( ) - 20 , 20 , "" );
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.bFlags = new GuiCheckBox[ 9 ];
this.buttons.add( this.bInputInvalid ); this.bFlags[ 0 ] = this.makeCheckbox( id++ , x , y + 55 , 0 , "hoppers_input_invalid" );
this.bFlags[ 1 ] = this.makeCheckbox( id++ , x , y + 70 , 0 , "hoppers_output_invalid" );
this.bFlags[ 2 ] = this.makeCheckbox( id++ , x , y + 85 , 0 , "hoppers_output_fuel" );
this.bFlags[ 3 ] = this.makeCheckbox( id++ , x , y + 125 , 0 , "cmp_output" );
this.bFlags[ 4 ] = this.makeCheckbox( id++ , x , y + 125 , 1 , "cmp_fuel" );
this.bFlags[ 5 ] = this.makeCheckbox( id++ , x , y + 140 , 0 , "cmp_valid_input" );
this.bFlags[ 6 ] = this.makeCheckbox( id++ , x , y + 140 , 1 , "cmp_invalid_input" );
this.bFlags[ 7 ] = this.makeCheckbox( id++ , x , y + 155 , 0 , "cmp_alloying" );
this.bFlags[ 8 ] = this.makeCheckbox( id++ , x , y + 155 , 1 , "cmp_burning" );
}
this.bOutputInvalidInput = new GuiButton( 100 , x + 10 , y + 70 , this.parent.getXSize( ) - 20 , 20 , "" );
this.buttons.add( this.bOutputInvalidInput ); private GuiCheckBox makeCheckbox( final int id , final int x , final int y , final int column ,
this.bOutputInvalidFuel = new GuiButton( 100 , x + 10 , y + 94 , this.parent.getXSize( ) - 20 , 20 , "" ); final String text )
this.buttons.add( this.bOutputInvalidFuel ); {
final GuiCheckBox checkBox = new GuiCheckBox( id , x + 10 + column * ( this.parent.getXSize( ) / 2 - 8 ) ,
y , I18n.format( "container.mmm.alloy_furnace.cfg." + text ) , false );
checkBox.packedFGColour = 0xffffff;
this.buttons.add( checkBox );
return checkBox;
} }
@ -248,10 +262,20 @@ 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( ); final int flags = ( (TBAFContainer) this.parent.container ).getFlags( );
this.bOutputInvalidFuel.displayString = this.getOutputHopperFuelText( ); for ( int i = 0 ; i < this.bFlags.length ; i++ ) {
this.bFlags[ i ].setIsChecked( ( flags & 1 << i ) != 0 );
}
super.drawBackground( partialTicks , mouseX , mouseY ); super.drawBackground( partialTicks , mouseX , mouseY );
final int x = ( this.parent.width - this.parent.getXSize( ) ) / 2;
final int y = ( this.parent.height - this.parent.getYSize( ) ) / 2;
this.drawString( this.parent.getFontRenderer( ) , I18n.format( "gui.mmm.configure.hoppers" ) , x + 10 ,
y + 40 , 0xffffff );
this.drawString( this.parent.getFontRenderer( ) , I18n.format( "gui.mmm.configure.comparator" ) , x + 10 ,
y + 110 , 0xffffff );
} }
@ -264,18 +288,13 @@ public class TBAFGui
return true; return true;
} }
if ( button == this.bInputInvalid ) { if ( button.id > 100 && button.id <= 100 + this.bFlags.length ) {
cont.setFlags( cont.getFlags( ) ^ TBAFTileEntity.F_IH_INVALID ); final int flags = cont.getFlags( );
return true; if ( this.bFlags[ button.id - 101 ].isChecked( ) ) {
} cont.setFlags( flags | 1 << button.id - 101 );
} else {
if ( button == this.bOutputInvalidInput ) { cont.setFlags( flags & ~ ( 1 << button.id - 101 ) );
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 true;
} }
@ -288,36 +307,6 @@ 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;

View file

@ -35,9 +35,9 @@ public class TBAFMessage
} }
public TBAFMessage( int flags ) public TBAFMessage( final int flags )
{ {
this.type = MT_SET_FLAGS; this.type = TBAFMessage.MT_SET_FLAGS;
this.flags = flags; this.flags = flags;
} }
@ -59,7 +59,7 @@ public class TBAFMessage
break; break;
case MT_SET_FLAGS: case MT_SET_FLAGS:
this.flags = buf.readByte( ); this.flags = buf.readShort( );
break; break;
} }
@ -82,7 +82,7 @@ public class TBAFMessage
break; break;
case MT_SET_FLAGS: case MT_SET_FLAGS:
buf.writeByte( this.flags ); buf.writeShort( this.flags );
break; break;
} }
@ -105,9 +105,9 @@ public class TBAFMessage
case MT_SET_RECIPE: case MT_SET_RECIPE:
container.setCurrentRecipe( this.recipe , this.type == TBAFMessage.MT_SET_RECIPE ); container.setCurrentRecipe( this.recipe , this.type == TBAFMessage.MT_SET_RECIPE );
break; break;
case MT_SET_FLAGS: case MT_SET_FLAGS:
container.setFlags( flags ); container.setFlags( this.flags );
break; break;
} }

View file

@ -7,6 +7,7 @@ import mmm.tech.base.E_TBActivationMode;
import mmm.tech.base.I_TBConfigurableActivation; import mmm.tech.base.I_TBConfigurableActivation;
import mmm.utils.UInventoryGrid; import mmm.utils.UInventoryGrid;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
@ -17,6 +18,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable; import net.minecraft.util.ITickable;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.common.util.Constants.NBT;
@ -30,12 +32,60 @@ 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? */ /** Input hopper allows invalid input? */
public static final int F_IH_INVALID = 1 << 2; public static final int F_IH_INVALID = 1 << 0;
/** Output hopper collects invalid input? */
public static final int F_OH_INVALID_INPUT = 1 << 1;
/** Output hopper collects invalid fuel? */
public static final int F_OH_INVALID_FUEL = 1 << 2;
/** Comparators check output? */
public static final int F_CMP_OUTPUT = 1 << 3;
/** Comparators check fuel? */
public static final int F_CMP_FUEL = 1 << 4;
/** Comparators check valid input? */
public static final int F_CMP_INPUT_VALID = 1 << 5;
/** Comparators check invalid input? */
public static final int F_CMP_INPUT_INVALID = 1 << 6;
/** Comparators check alloying progress? */
public static final int F_CMP_ALLOYING = 1 << 7;
/** Comparators check burn time? */
public static final int F_CMP_BURN_TIME = 1 << 8;
private class Inventory
extends UInventoryGrid
{
public Inventory( final String name , final int width , final int height )
{
super( name , width , height );
}
@Override
public void markDirty( )
{
TBAFTileEntity.this.forceUpdate( );
}
}
private class FuelInventory
extends Inventory
{
public FuelInventory( final String name , final int width , final int height )
{
super( name , width , height );
}
@Override
public boolean isItemValidForSlot( final int index , final ItemStack stack )
{
return super.isItemValidForSlot( index , stack ) && TileEntityFurnace.isItemFuel( stack );
}
}
public final UInventoryGrid input; public final UInventoryGrid input;
public final UInventoryGrid fuel; public final UInventoryGrid fuel;
@ -58,20 +108,13 @@ public class TBAFTileEntity
public TBAFTileEntity( ) public TBAFTileEntity( )
{ {
this.input = new UInventoryGrid( "Input" , 3 , 5 ); this.input = new Inventory( "Input" , 3 , 5 );
this.fuel = new UInventoryGrid( "Fuel" , 2 , 2 ) { this.fuel = new FuelInventory( "Fuel" , 2 , 2 );
this.output = new Inventory( "Output" , 2 , 5 );
@Override
public boolean isItemValidForSlot( int index , ItemStack stack )
{
return super.isItemValidForSlot( index , stack ) && TileEntityFurnace.isItemFuel( stack );
}
};
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.flags = TBAFTileEntity.F_OH_INVALID_INPUT | TBAFTileEntity.F_OH_INVALID_FUEL
| TBAFTileEntity.F_CMP_INPUT_VALID;
this.inputHopper = new TBAFInputHopper( this ); this.inputHopper = new TBAFInputHopper( this );
this.fuelHopper = new InvWrapper( this.fuel ); this.fuelHopper = new InvWrapper( this.fuel );
@ -499,7 +542,7 @@ public class TBAFTileEntity
this.activationMode = E_TBActivationMode.DISABLED; this.activationMode = E_TBActivationMode.DISABLED;
break; break;
} }
this.flags = compound.getByte( "Flags" ); this.flags = compound.getShort( "Flags" );
this.burnCurrent = compound.getInteger( "BurnCurrent" ); this.burnCurrent = compound.getInteger( "BurnCurrent" );
this.burnTotal = compound.getInteger( "BurnTotal" ); this.burnTotal = compound.getInteger( "BurnTotal" );
@ -522,7 +565,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 ); compound.setShort( "Flags" , (short) 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 );
@ -533,4 +576,78 @@ public class TBAFTileEntity
} }
} }
public int getComparatorValue( )
{
int nValues = 0;
int total = 0;
if ( ( this.flags & TBAFTileEntity.F_CMP_OUTPUT ) != 0 ) {
nValues++;
total += Container.calcRedstoneFromInventory( this.output );
}
if ( ( this.flags & TBAFTileEntity.F_CMP_FUEL ) != 0 ) {
nValues++;
total += Container.calcRedstoneFromInventory( this.fuel );
}
if ( ( this.flags & ( TBAFTileEntity.F_CMP_INPUT_INVALID | TBAFTileEntity.F_CMP_INPUT_VALID ) ) != 0 ) {
int validInput = 0 , invalidInput = 0;
float validInputSum = 0f , invalidInputSum = 0f;
for ( int i = 0 ; i < this.input.slotsCount ; i++ ) {
final ItemStack stack = this.input.getStackInSlot( i );
if ( stack == null ) {
continue;
}
final float value = stack.stackSize / (float) Math.min( this.input.getInventoryStackLimit( ) , //
stack.getMaxStackSize( ) );
if ( this.recipe.hasInput( stack ) ) {
validInput++;
validInputSum += value;
} else {
invalidInput++;
invalidInputSum += value;
}
}
if ( ( this.flags & TBAFTileEntity.F_CMP_INPUT_VALID ) != 0 ) {
validInputSum /= this.input.slotsCount;
total += MathHelper.floor_float( validInputSum * 14F ) + ( validInput > 0 ? 1 : 0 );
nValues++;
}
if ( ( this.flags & TBAFTileEntity.F_CMP_INPUT_INVALID ) != 0 ) {
invalidInputSum /= this.input.slotsCount;
total += MathHelper.floor_float( invalidInputSum * 14F ) + ( invalidInput > 0 ? 1 : 0 );
nValues++;
}
}
if ( ( this.flags & TBAFTileEntity.F_CMP_ALLOYING ) != 0 ) {
nValues++;
if ( this.alloying != null ) {
int t = this.alloying.burnTime;
if ( t == 0 ) {
t = 200;
}
total += 1 + Math.min( 14 , ( t - this.alloyCurrent ) * 14 / t );
}
}
if ( ( this.flags & TBAFTileEntity.F_CMP_BURN_TIME ) != 0 ) {
nValues++;
if ( this.isBurning( ) ) {
int t = this.burnTotal;
if ( t == 0 ) {
t = 200;
}
total += 1 + Math.min( 14 , ( t - this.burnCurrent ) * 14 / t );
}
}
if ( nValues == 0 ) {
return 0;
}
final float ratio = total / ( 15.0f * nValues );
return MathHelper.floor_float( ratio * 14.0f ) + ( total == 0 ? 0 : 1 );
}
} }

View file

@ -1,5 +1,6 @@
gui.mmm.configure=Configure gui.mmm.configure=Configure
gui.mmm.configure.hoppers=Hoppers
gui.mmm.configure.comparator=Comparator Output
item.mmm.materials.stone.coke.name=Coke item.mmm.materials.stone.coke.name=Coke
@ -25,12 +26,15 @@ 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.hoppers_input_invalid=Allow invalid input
container.mmm.alloy_furnace.cfg.ihinv.no=Block invalid hopper input container.mmm.alloy_furnace.cfg.hoppers_output_invalid=Remove invalid input
container.mmm.alloy_furnace.cfg.ohinvin.yes=Remove invalid input container.mmm.alloy_furnace.cfg.hoppers_output_fuel=Remove spent fuel buckets
container.mmm.alloy_furnace.cfg.ohinvin.no=Keep invalid input container.mmm.alloy_furnace.cfg.cmp_output=Output
container.mmm.alloy_furnace.cfg.ohinvf.yes=Remove spent fuel buckets container.mmm.alloy_furnace.cfg.cmp_fuel=Fuel
container.mmm.alloy_furnace.cfg.ohinvf.no=Keep spent fuel buckets container.mmm.alloy_furnace.cfg.cmp_valid_input=Valid Input
container.mmm.alloy_furnace.cfg.cmp_invalid_input=Invalid Input
container.mmm.alloy_furnace.cfg.cmp_alloying=Alloying Time
container.mmm.alloy_furnace.cfg.cmp_burning=Burn Time
item.mmm.tech.tools.copper.shovel.name=Copper Shovel item.mmm.tech.tools.copper.shovel.name=Copper Shovel