1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-25 02:47:39 +00:00

Migrate cable core block state to an enum

This allows us to render the cable "core", as was done pre-1.8.
This commit is contained in:
SquidDev
2017-05-11 14:57:58 +01:00
parent 728644c104
commit 75ccfbdb3d
7 changed files with 111 additions and 45 deletions

View File

@@ -41,7 +41,7 @@ public class BlockCable extends BlockPeripheralBase
public static class Properties
{
public static final PropertyEnum<BlockCableModemVariant> MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class );
public static final PropertyBool CABLE = PropertyBool.create( "cable" );
public static final PropertyEnum<BlockCableCableVariant> CABLE = PropertyEnum.create( "cable", BlockCableCableVariant.class );
public static final PropertyBool NORTH = PropertyBool.create( "north" );
public static final PropertyBool SOUTH = PropertyBool.create( "south" );
public static final PropertyBool EAST = PropertyBool.create( "east" );
@@ -76,7 +76,7 @@ public class BlockCable extends BlockPeripheralBase
setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( this.blockState.getBaseState()
.withProperty( Properties.MODEM, BlockCableModemVariant.None )
.withProperty( Properties.CABLE, true )
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.NORTH, false )
.withProperty( Properties.SOUTH, false )
.withProperty( Properties.EAST, false )
@@ -110,17 +110,17 @@ public class BlockCable extends BlockPeripheralBase
IBlockState state = getDefaultState();
if( meta < 6 )
{
state = state.withProperty( Properties.CABLE, false );
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.getFront( meta ) ) );
}
else if( meta < 12 )
{
state = state.withProperty( Properties.CABLE, true );
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.ANY );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.getFront( meta - 6 ) ) );
}
else if( meta == 13 )
{
state = state.withProperty( Properties.CABLE, true );
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.ANY );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.None );
}
return state;
@@ -130,7 +130,7 @@ public class BlockCable extends BlockPeripheralBase
public int getMetaFromState( IBlockState state )
{
int meta = 0;
boolean cable = state.getValue( Properties.CABLE );
boolean cable = state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE;
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
if( cable && modem != BlockCableModemVariant.None )
{
@@ -155,20 +155,20 @@ public class BlockCable extends BlockPeripheralBase
case Cable:
{
return getDefaultState()
.withProperty( Properties.CABLE, true )
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.MODEM, BlockCableModemVariant.None );
}
case WiredModem:
default:
{
return getDefaultState()
.withProperty( Properties.CABLE, false )
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
}
case WiredModemWithCable:
{
return getDefaultState()
.withProperty( Properties.CABLE, true )
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
}
}
@@ -176,7 +176,7 @@ public class BlockCable extends BlockPeripheralBase
private boolean doesConnect( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing dir )
{
if( !state.getValue( Properties.CABLE ) )
if( state.getValue( Properties.CABLE ) == BlockCableCableVariant.NONE )
{
return false;
}
@@ -202,6 +202,25 @@ public class BlockCable extends BlockPeripheralBase
state = state.withProperty( Properties.UP, doesConnect( state, world, pos, EnumFacing.UP ) );
state = state.withProperty( Properties.DOWN, doesConnect( state, world, pos, EnumFacing.DOWN ) );
if( state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE )
{
BlockCableCableVariant direction = null;
if( state.getValue( Properties.WEST ) || state.getValue( Properties.EAST ) )
{
direction = direction == null ? BlockCableCableVariant.X_AXIS : BlockCableCableVariant.ANY;
}
if( state.getValue( Properties.DOWN ) || state.getValue( Properties.UP ) )
{
direction = direction == null ? BlockCableCableVariant.Y_AXIS : BlockCableCableVariant.ANY;
}
if( state.getValue( Properties.NORTH ) || state.getValue( Properties.SOUTH ) )
{
direction = direction == null ? BlockCableCableVariant.Z_AXIS : BlockCableCableVariant.ANY;
}
state = state.withProperty( Properties.CABLE, direction == null ? BlockCableCableVariant.Z_AXIS : direction );
}
int anim;
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TilePeripheralBase )
@@ -242,7 +261,7 @@ public class BlockCable extends BlockPeripheralBase
@Override
public PeripheralType getPeripheralType( IBlockState state )
{
boolean cable = state.getValue( Properties.CABLE );
boolean cable = state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE;
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
if( cable && modem != BlockCableModemVariant.None )
{
@@ -330,7 +349,7 @@ public class BlockCable extends BlockPeripheralBase
}
else
{
world.setBlockState( pos, state.withProperty( Properties.CABLE, false ), 3 );
world.setBlockState( pos, state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE ), 3 );
cable.networkChanged();
item = PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
}

View File

@@ -0,0 +1,28 @@
package dan200.computercraft.shared.peripheral.common;
import net.minecraft.util.IStringSerializable;
import javax.annotation.Nonnull;
public enum BlockCableCableVariant implements IStringSerializable
{
NONE( "none" ),
ANY( "any" ),
X_AXIS( "x" ),
Y_AXIS( "y" ),
Z_AXIS( "z" ),;
private final String m_name;
BlockCableCableVariant( String name )
{
m_name = name;
}
@Override
@Nonnull
public String getName()
{
return m_name;
}
}

View File

@@ -89,12 +89,12 @@ public class ItemCable extends ItemPeripheralBase
{
if( !stack.isEmpty() )
{
IBlockState newState = existingState.withProperty( BlockCable.Properties.CABLE, true );
IBlockState newState = existingState.withProperty( BlockCable.Properties.CABLE, BlockCableCableVariant.ANY );
world.setBlockState( pos, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, pos, player );
world.playSound( null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
stack.shrink( 1 );
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileCable )
{
@@ -143,7 +143,7 @@ public class ItemCable extends ItemPeripheralBase
{
if( !stack.isEmpty() )
{
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.CABLE, true );
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.CABLE, BlockCableCableVariant.ANY );
world.setBlockState( offset, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, offset, player );
world.playSound( null, offset.getX() + 0.5, offset.getY() + 0.5, offset.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );