Alloy furnace - Can be disabled with a redstone signal

This commit is contained in:
Emmanuel BENOîT 2016-06-25 21:34:33 +02:00
parent 8001cb13a2
commit d322be6c07
3 changed files with 31 additions and 14 deletions

View file

@ -44,7 +44,6 @@ materials.ores No Tin
materials.ores No Zinc
-------------------------------------------------------------------------------------------------------
tech.base No Alloy furnace
-> redstone activation
-> make redstone activation configurable
-> make output hopper configurable
-> comparator signal configuration

View file

@ -118,17 +118,17 @@ public class TBAlloyFurnaceBlock
final TileEntity tileentity = world.getTileEntity( pos );
TBAlloyFurnaceBlock.keepInventory = true;
IBlockState nState;
Block nBlock;
if ( burning ) {
world.setBlockState( pos , TechBase.ALLOY_FURNACE_BLOCK_ACTIVE.getDefaultState( ).withProperty(
TBAlloyFurnaceBlock.FACING , iblockstate.getValue( TBAlloyFurnaceBlock.FACING ) ) , 3 );
world.setBlockState( pos , TechBase.ALLOY_FURNACE_BLOCK_ACTIVE.getDefaultState( ).withProperty(
TBAlloyFurnaceBlock.FACING , iblockstate.getValue( TBAlloyFurnaceBlock.FACING ) ) , 3 );
nBlock = TechBase.ALLOY_FURNACE_BLOCK_ACTIVE;
} else {
world.setBlockState( pos , TechBase.ALLOY_FURNACE_BLOCK_INACTIVE.getDefaultState( ).withProperty(
TBAlloyFurnaceBlock.FACING , iblockstate.getValue( TBAlloyFurnaceBlock.FACING ) ) , 3 );
world.setBlockState( pos , TechBase.ALLOY_FURNACE_BLOCK_INACTIVE.getDefaultState( ).withProperty(
TBAlloyFurnaceBlock.FACING , iblockstate.getValue( TBAlloyFurnaceBlock.FACING ) ) , 3 );
nBlock = TechBase.ALLOY_FURNACE_BLOCK_INACTIVE;
}
nState = nBlock.getDefaultState( ) //
.withProperty( TBAlloyFurnaceBlock.FACING , iblockstate.getValue( TBAlloyFurnaceBlock.FACING ) ) //
.withProperty( TBAlloyFurnaceBlock.POWERED , iblockstate.getValue( TBAlloyFurnaceBlock.POWERED ) );
world.setBlockState( pos , nState , 3 );
TBAlloyFurnaceBlock.keepInventory = false;
if ( tileentity != null ) {
@ -419,10 +419,13 @@ public class TBAlloyFurnaceBlock
{
final boolean powered = worldIn.isBlockPowered( pos );
if ( powered != state.getValue( TBAlloyFurnaceBlock.POWERED ).booleanValue( ) ) {
worldIn.setBlockState( pos ,
state.withProperty( TBAlloyFurnaceBlock.POWERED , Boolean.valueOf( powered ) ) , 4 );
System.err.println( pos + " POWERED? " + ( powered ? "yes" : "no" ) );
worldIn.setBlockState( pos , state.withProperty( TBAlloyFurnaceBlock.POWERED , powered ) , 4 );
}
}
public static boolean isPowered( int meta )
{
return ( meta & 8 ) == 8;
}
}

View file

@ -14,6 +14,8 @@ import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.items.CapabilityItemHandler;
@ -56,6 +58,13 @@ public class TBAlloyFurnaceTileEntity
}
@Override
public boolean shouldRefresh( World world , BlockPos pos , IBlockState oldState , IBlockState newSate )
{
return ! ( newSate.getBlock( ) instanceof TBAlloyFurnaceBlock );
}
@Override
public void readFromNBT( final NBTTagCompound compound )
{
@ -135,7 +144,7 @@ public class TBAlloyFurnaceTileEntity
if ( this.burnCurrent == 0 ) {
if ( this.alloying != null ) {
if ( !this.startBurning( this.alloyCurrent ) ) {
if ( ! ( this.isEnabled( ) && this.startBurning( this.alloyCurrent ) ) ) {
this.cancelAlloying( );
this.burnCurrent = this.burnTotal = 0;
}
@ -146,7 +155,7 @@ public class TBAlloyFurnaceTileEntity
}
if ( !this.isAlloying( ) && this.canAlloy( )
if ( this.isEnabled( ) && !this.isAlloying( ) && this.canAlloy( )
&& ( this.isBurning( ) || this.startBurning( this.recipe.burnTime ) ) ) {
this.startAlloying( );
dirty = true;
@ -164,6 +173,12 @@ public class TBAlloyFurnaceTileEntity
}
public boolean isEnabled( )
{
return !TBAlloyFurnaceBlock.isPowered( this.getBlockMetadata( ) );
}
@Override
public boolean hasCapability( final Capability< ? > capability , final EnumFacing facing )
{