2017-05-07 00:18:59 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2019-01-01 01:10:18 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.shared.computer.blocks;
|
|
|
|
|
|
|
|
import dan200.computercraft.ComputerCraft;
|
|
|
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
2018-12-27 11:32:29 +00:00
|
|
|
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
|
2019-04-02 10:50:13 +00:00
|
|
|
import net.minecraft.block.BlockHorizontal;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.properties.PropertyBool;
|
|
|
|
import net.minecraft.block.properties.PropertyDirection;
|
|
|
|
import net.minecraft.block.properties.PropertyEnum;
|
2017-05-01 13:51:26 +00:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2017-05-07 00:16:08 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public class BlockComputer extends BlockComputerBase
|
|
|
|
{
|
|
|
|
// Statics
|
2019-03-29 21:21:39 +00:00
|
|
|
public static final class Properties
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2019-04-02 10:50:13 +00:00
|
|
|
public static final PropertyDirection FACING = BlockHorizontal.FACING;
|
2018-12-23 17:46:58 +00:00
|
|
|
public static final PropertyBool ADVANCED = PropertyBool.create( "advanced" );
|
|
|
|
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create( "state", ComputerState.class );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Members
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public BlockComputer()
|
|
|
|
{
|
2017-05-01 13:51:26 +00:00
|
|
|
super( Material.ROCK );
|
2017-05-01 14:48:44 +00:00
|
|
|
setHardness( 2.0f );
|
2018-07-24 08:27:05 +00:00
|
|
|
setTranslationKey( "computercraft:computer" );
|
2017-05-01 13:32:39 +00:00
|
|
|
setCreativeTab( ComputerCraft.mainCreativeTab );
|
2019-03-29 21:21:39 +00:00
|
|
|
setDefaultState( blockState.getBaseState()
|
2017-05-01 13:32:39 +00:00
|
|
|
.withProperty( Properties.FACING, EnumFacing.NORTH )
|
|
|
|
.withProperty( Properties.ADVANCED, false )
|
2018-12-29 14:36:03 +00:00
|
|
|
.withProperty( Properties.STATE, ComputerState.Off )
|
2017-05-01 13:32:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2017-05-01 13:51:26 +00:00
|
|
|
protected BlockStateContainer createBlockState()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-07 00:16:08 +00:00
|
|
|
return new BlockStateContainer( this, Properties.FACING, Properties.ADVANCED, Properties.STATE );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2017-05-07 00:42:32 +00:00
|
|
|
@Deprecated
|
2017-05-01 13:32:39 +00:00
|
|
|
public IBlockState getStateFromMeta( int meta )
|
|
|
|
{
|
2018-07-24 08:27:05 +00:00
|
|
|
EnumFacing dir = EnumFacing.byIndex( meta & 0x7 );
|
2017-05-01 13:32:39 +00:00
|
|
|
if( dir.getAxis() == EnumFacing.Axis.Y )
|
|
|
|
{
|
|
|
|
dir = EnumFacing.NORTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
IBlockState state = getDefaultState().withProperty( Properties.FACING, dir );
|
|
|
|
if( meta > 8 )
|
|
|
|
{
|
|
|
|
state = state.withProperty( Properties.ADVANCED, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state = state.withProperty( Properties.ADVANCED, false );
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState( IBlockState state )
|
|
|
|
{
|
2017-05-06 23:42:00 +00:00
|
|
|
int meta = state.getValue( Properties.FACING ).getIndex();
|
|
|
|
if( state.getValue( Properties.ADVANCED ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
meta += 8;
|
|
|
|
}
|
|
|
|
return meta;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected IBlockState getDefaultBlockState( ComputerFamily family, EnumFacing placedSide )
|
|
|
|
{
|
2019-01-14 10:27:19 +00:00
|
|
|
return getDefaultState()
|
|
|
|
.withProperty( Properties.FACING, placedSide )
|
|
|
|
.withProperty( Properties.ADVANCED, family == ComputerFamily.Advanced );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2017-05-07 00:42:32 +00:00
|
|
|
@Deprecated
|
2017-05-06 23:07:42 +00:00
|
|
|
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
TileEntity tile = world.getTileEntity( pos );
|
2018-12-29 14:36:03 +00:00
|
|
|
return state.withProperty( Properties.STATE, tile instanceof TileComputer ? ((TileComputer) tile).getState() : ComputerState.Off );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ComputerFamily getFamily( int damage )
|
|
|
|
{
|
2019-01-12 19:01:32 +00:00
|
|
|
return ComputerCraft.Items.computer.getFamily( damage );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ComputerFamily getFamily( IBlockState state )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
if( state.getValue( Properties.ADVANCED ) )
|
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
return ComputerFamily.Advanced;
|
2018-12-23 17:46:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
return ComputerFamily.Normal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected TileComputer createTile( ComputerFamily family )
|
|
|
|
{
|
|
|
|
return new TileComputer();
|
|
|
|
}
|
|
|
|
|
2018-12-27 11:32:29 +00:00
|
|
|
@Nonnull
|
|
|
|
@Override
|
2019-01-25 22:03:44 +00:00
|
|
|
protected ItemStack getItem( TileComputerBase tile )
|
2018-12-27 11:32:29 +00:00
|
|
|
{
|
2019-01-25 22:03:44 +00:00
|
|
|
return tile instanceof TileComputer ? ComputerItemFactory.create( (TileComputer) tile ) : ItemStack.EMPTY;
|
2018-12-27 11:32:29 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|