Alloy furnace - Now aware of redstone power

It doesn't do anything with it yet.
This commit is contained in:
Emmanuel BENOîT 2016-06-25 09:18:17 +02:00
parent 258d8b417e
commit 3cd9d5719c
3 changed files with 71 additions and 20 deletions

View file

@ -15,6 +15,7 @@ import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockHorizontal; import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -55,6 +56,7 @@ public class TBAlloyFurnaceBlock
private static final AxisAlignedBB AABB_TOP = UMaths.makeBlockAABB( 4 , 10 , 4 , 12 , 16 , 12 ); private static final AxisAlignedBB AABB_TOP = UMaths.makeBlockAABB( 4 , 10 , 4 , 12 , 16 , 12 );
public static final PropertyDirection FACING = BlockHorizontal.FACING; public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyBool POWERED = PropertyBool.create( "powered" );
private static boolean keepInventory = false; private static boolean keepInventory = false;
@ -65,14 +67,22 @@ public class TBAlloyFurnaceBlock
{ {
super( Material.ROCK ); super( Material.ROCK );
this.active = active; this.active = active;
this.setCreativeTab( CreativeTabs.DECORATIONS ); this.setCreativeTab( CreativeTabs.DECORATIONS );
this.setResistance( 17.5f ); this.setResistance( 17.5f );
this.setHardness( 3.5f ); this.setHardness( 3.5f );
this.setHarvestLevel( "pickaxe" , 0 ); this.setHarvestLevel( "pickaxe" , 0 );
this.lightOpacity = 0; this.lightOpacity = 0;
this.translucent = false; this.translucent = false;
this.fullBlock = false; this.fullBlock = false;
this.lightValue = active ? 13 : 0; this.lightValue = active ? 13 : 0;
this.setDefaultState( this.blockState.getBaseState( ) //
.withProperty( TBAlloyFurnaceBlock.FACING , EnumFacing.NORTH ) //
.withProperty( TBAlloyFurnaceBlock.POWERED , Boolean.valueOf( false ) ) );
URegistry.setIdentifiers( this , "tech" , "base" , "alloy_furnace" , active ? "active" : "inactive" ); URegistry.setIdentifiers( this , "tech" , "base" , "alloy_furnace" , active ? "active" : "inactive" );
} }
@ -173,7 +183,7 @@ public class TBAlloyFurnaceBlock
} }
if ( rand.nextDouble( ) < .5 ) { if ( rand.nextDouble( ) < .5 ) {
spawnFrontParticles( stateIn , worldIn , pos , rand ); this.spawnFrontParticles( stateIn , worldIn , pos , rand );
} }
for ( int i = 0 ; i < 4 ; i++ ) { for ( int i = 0 ; i < 4 ; i++ ) {
@ -183,7 +193,8 @@ public class TBAlloyFurnaceBlock
} }
private void spawnTopParticles( IBlockState stateIn , World worldIn , BlockPos pos , Random rand ) private void spawnTopParticles( final IBlockState stateIn , final World worldIn , final BlockPos pos ,
final Random rand )
{ {
final double spawnX = pos.getX( ) + .5 + ( rand.nextDouble( ) - .5 ) * 4.5 / 16.; final double spawnX = pos.getX( ) + .5 + ( rand.nextDouble( ) - .5 ) * 4.5 / 16.;
final double spawnY = pos.getY( ) + ( 15. + 3. * rand.nextDouble( ) ) / 16.; final double spawnY = pos.getY( ) + ( 15. + 3. * rand.nextDouble( ) ) / 16.;
@ -265,7 +276,7 @@ public class TBAlloyFurnaceBlock
protected BlockStateContainer createBlockState( ) protected BlockStateContainer createBlockState( )
{ {
return new BlockStateContainer( this , new IProperty[] { return new BlockStateContainer( this , new IProperty[] {
TBAlloyFurnaceBlock.FACING TBAlloyFurnaceBlock.FACING , TBAlloyFurnaceBlock.POWERED
} ); } );
} }
@ -273,20 +284,24 @@ public class TBAlloyFurnaceBlock
@Override @Override
public IBlockState getStateFromMeta( final int meta ) public IBlockState getStateFromMeta( final int meta )
{ {
EnumFacing enumfacing = EnumFacing.getFront( meta ); final boolean powered = ( meta & 8 ) == 8;
EnumFacing enumfacing = EnumFacing.getFront( meta & 7 );
if ( enumfacing.getAxis( ) == EnumFacing.Axis.Y ) { if ( enumfacing.getAxis( ) == EnumFacing.Axis.Y ) {
enumfacing = EnumFacing.NORTH; enumfacing = EnumFacing.NORTH;
} }
return this.getDefaultState( ).withProperty( TBAlloyFurnaceBlock.FACING , enumfacing ); return this.getDefaultState( ) //
.withProperty( TBAlloyFurnaceBlock.FACING , enumfacing ) //
.withProperty( TBAlloyFurnaceBlock.POWERED , powered );
} }
@Override @Override
public int getMetaFromState( final IBlockState state ) public int getMetaFromState( final IBlockState state )
{ {
return state.getValue( TBAlloyFurnaceBlock.FACING ).getIndex( ); return state.getValue( TBAlloyFurnaceBlock.FACING ).getIndex( ) //
| ( state.getValue( TBAlloyFurnaceBlock.POWERED ) ? 8 : 0 );
} }
@ -294,8 +309,8 @@ public class TBAlloyFurnaceBlock
public IBlockState onBlockPlaced( final World worldIn , final BlockPos pos , final EnumFacing facing , public IBlockState onBlockPlaced( final World worldIn , final BlockPos pos , final EnumFacing facing ,
final float hitX , final float hitY , final float hitZ , final int meta , final EntityLivingBase placer ) final float hitX , final float hitY , final float hitZ , final int meta , final EntityLivingBase placer )
{ {
return this.getDefaultState( ).withProperty( TBAlloyFurnaceBlock.FACING , return this.getDefaultState( ).withProperty( //
placer.getHorizontalFacing( ).getOpposite( ) ); TBAlloyFurnaceBlock.FACING , placer.getHorizontalFacing( ).getOpposite( ) );
} }
@ -364,22 +379,50 @@ public class TBAlloyFurnaceBlock
// ************************************************************************************************* // *************************************************************************************************
// COMPARATORS // REDSTONE
// ************************************************************************************************* // *************************************************************************************************
public boolean hasComparatorInputOverride( IBlockState state ) @Override
public boolean hasComparatorInputOverride( final IBlockState state )
{ {
return true; return true;
} }
public int getComparatorInputOverride( IBlockState blockState , World worldIn , BlockPos pos ) @Override
public int getComparatorInputOverride( final IBlockState blockState , final World worldIn , final BlockPos pos )
{ {
TileEntity te = worldIn.getTileEntity( pos ); final TileEntity te = worldIn.getTileEntity( pos );
if ( ! ( te instanceof TBAlloyFurnaceTileEntity ) ) { if ( ! ( te instanceof TBAlloyFurnaceTileEntity ) ) {
return 0; return 0;
} }
return Container.calcRedstoneFromInventory( ( (TBAlloyFurnaceTileEntity) te ).output ); return Container.calcRedstoneFromInventory( ( (TBAlloyFurnaceTileEntity) te ).output );
} }
@Override
public void neighborChanged( final IBlockState state , final World worldIn , final BlockPos pos ,
final Block blockIn )
{
this.checkIfPowered( state , worldIn , pos );
}
@Override
public void onBlockAdded( final World worldIn , final BlockPos pos , final IBlockState state )
{
this.checkIfPowered( state , worldIn , pos );
}
private void checkIfPowered( final IBlockState state , final World worldIn , final BlockPos pos )
{
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" ) );
}
}
} }

View file

@ -1,8 +1,12 @@
{ {
"variants": { "variants": {
"facing=north": { "model": "mmm:tech/base/alloy_furnace/active" }, "facing=north,powered=true": { "model": "mmm:tech/base/alloy_furnace/active" },
"facing=east": { "model": "mmm:tech/base/alloy_furnace/active", "y": 90 }, "facing=north,powered=false": { "model": "mmm:tech/base/alloy_furnace/active" },
"facing=south": { "model": "mmm:tech/base/alloy_furnace/active", "y": 180 }, "facing=east,powered=true": { "model": "mmm:tech/base/alloy_furnace/active", "y": 90 },
"facing=west": { "model": "mmm:tech/base/alloy_furnace/active", "y": 270 } "facing=east,powered=false": { "model": "mmm:tech/base/alloy_furnace/active", "y": 90 },
"facing=south,powered=true": { "model": "mmm:tech/base/alloy_furnace/active", "y": 180 },
"facing=south,powered=false": { "model": "mmm:tech/base/alloy_furnace/active", "y": 180 },
"facing=west,powered=true": { "model": "mmm:tech/base/alloy_furnace/active", "y": 270 },
"facing=west,powered=false": { "model": "mmm:tech/base/alloy_furnace/active", "y": 270 }
} }
} }

View file

@ -1,8 +1,12 @@
{ {
"variants": { "variants": {
"facing=north": { "model": "mmm:tech/base/alloy_furnace/inactive" }, "facing=north,powered=true": { "model": "mmm:tech/base/alloy_furnace/inactive" },
"facing=east": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 90 }, "facing=north,powered=false": { "model": "mmm:tech/base/alloy_furnace/inactive" },
"facing=south": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 180 }, "facing=east,powered=true": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 90 },
"facing=west": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 270 } "facing=east,powered=false": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 90 },
"facing=south,powered=true": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 180 },
"facing=south,powered=false": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 180 },
"facing=west,powered=true": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 270 },
"facing=west,powered=false": { "model": "mmm:tech/base/alloy_furnace/inactive", "y": 270 }
} }
} }