1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-12 10:20:28 +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 class Properties
{ {
public static final PropertyEnum<BlockCableModemVariant> MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class ); 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 NORTH = PropertyBool.create( "north" );
public static final PropertyBool SOUTH = PropertyBool.create( "south" ); public static final PropertyBool SOUTH = PropertyBool.create( "south" );
public static final PropertyBool EAST = PropertyBool.create( "east" ); public static final PropertyBool EAST = PropertyBool.create( "east" );
@ -76,7 +76,7 @@ public class BlockCable extends BlockPeripheralBase
setCreativeTab( ComputerCraft.mainCreativeTab ); setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( this.blockState.getBaseState() setDefaultState( this.blockState.getBaseState()
.withProperty( Properties.MODEM, BlockCableModemVariant.None ) .withProperty( Properties.MODEM, BlockCableModemVariant.None )
.withProperty( Properties.CABLE, true ) .withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.NORTH, false ) .withProperty( Properties.NORTH, false )
.withProperty( Properties.SOUTH, false ) .withProperty( Properties.SOUTH, false )
.withProperty( Properties.EAST, false ) .withProperty( Properties.EAST, false )
@ -110,17 +110,17 @@ public class BlockCable extends BlockPeripheralBase
IBlockState state = getDefaultState(); IBlockState state = getDefaultState();
if( meta < 6 ) 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 ) ) ); state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.getFront( meta ) ) );
} }
else if( meta < 12 ) 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 ) ) ); state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.getFront( meta - 6 ) ) );
} }
else if( meta == 13 ) else if( meta == 13 )
{ {
state = state.withProperty( Properties.CABLE, true ); state = state.withProperty( Properties.CABLE, BlockCableCableVariant.ANY );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.None ); state = state.withProperty( Properties.MODEM, BlockCableModemVariant.None );
} }
return state; return state;
@ -130,7 +130,7 @@ public class BlockCable extends BlockPeripheralBase
public int getMetaFromState( IBlockState state ) public int getMetaFromState( IBlockState state )
{ {
int meta = 0; int meta = 0;
boolean cable = state.getValue( Properties.CABLE ); boolean cable = state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE;
BlockCableModemVariant modem = state.getValue( Properties.MODEM ); BlockCableModemVariant modem = state.getValue( Properties.MODEM );
if( cable && modem != BlockCableModemVariant.None ) if( cable && modem != BlockCableModemVariant.None )
{ {
@ -155,20 +155,20 @@ public class BlockCable extends BlockPeripheralBase
case Cable: case Cable:
{ {
return getDefaultState() return getDefaultState()
.withProperty( Properties.CABLE, true ) .withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.MODEM, BlockCableModemVariant.None ); .withProperty( Properties.MODEM, BlockCableModemVariant.None );
} }
case WiredModem: case WiredModem:
default: default:
{ {
return getDefaultState() return getDefaultState()
.withProperty( Properties.CABLE, false ) .withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) ); .withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
} }
case WiredModemWithCable: case WiredModemWithCable:
{ {
return getDefaultState() return getDefaultState()
.withProperty( Properties.CABLE, true ) .withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) ); .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 ) 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; 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.UP, doesConnect( state, world, pos, EnumFacing.UP ) );
state = state.withProperty( Properties.DOWN, doesConnect( state, world, pos, EnumFacing.DOWN ) ); 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; int anim;
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TilePeripheralBase ) if( tile != null && tile instanceof TilePeripheralBase )
@ -242,7 +261,7 @@ public class BlockCable extends BlockPeripheralBase
@Override @Override
public PeripheralType getPeripheralType( IBlockState state ) 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 ); BlockCableModemVariant modem = state.getValue( Properties.MODEM );
if( cable && modem != BlockCableModemVariant.None ) if( cable && modem != BlockCableModemVariant.None )
{ {
@ -330,7 +349,7 @@ public class BlockCable extends BlockPeripheralBase
} }
else else
{ {
world.setBlockState( pos, state.withProperty( Properties.CABLE, false ), 3 ); world.setBlockState( pos, state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE ), 3 );
cable.networkChanged(); cable.networkChanged();
item = PeripheralItemFactory.create( PeripheralType.Cable, null, 1 ); 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() ) 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 ); world.setBlockState( pos, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, pos, player ); 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 ); 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 ); stack.shrink( 1 );
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileCable ) if( tile != null && tile instanceof TileCable )
{ {
@ -143,7 +143,7 @@ public class ItemCable extends ItemPeripheralBase
{ {
if( !stack.isEmpty() ) 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 ); world.setBlockState( offset, newState, 3 );
SoundType soundType = newState.getBlock().getSoundType( newState, world, offset, player ); 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 ); 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 );

View File

@ -2,13 +2,11 @@
"forge_marker": 1, "forge_marker": 1,
"variants": { "variants": {
"cable": { "cable": {
"true": { "none": { },
"submodel": { "any": { "submodel": { "cable": { "model": "computercraft:cable_core_any" } } },
"cable": { "model": "computercraft:cable_core" } "x": { "submodel": { "cable": { "model": "computercraft:cable_core_facing", "y": 90 } } },
} "y": { "submodel": { "cable": { "model": "computercraft:cable_core_facing", "x": 90 } } },
}, "z": { "submodel": { "cable": { "model": "computercraft:cable_core_facing", "y": 0 } } }
"false": {
}
}, },
"up": { "up": {
"true": { "true": {

View File

@ -6,7 +6,7 @@
}, },
"elements": [ "elements": [
{ {
"from": [ 6, 6, 10 ], "from": [ 6, 6, 10 ],
"to": [ 10, 10, 16 ], "to": [ 10, 10, 16 ],
"faces": { "faces": {
"down": { "uv": [ 6, 0, 10, 6 ], "texture": "#side" }, "down": { "uv": [ 6, 0, 10, 6 ], "texture": "#side" },

View File

@ -0,0 +1,21 @@
{
"parent": "block/block",
"textures": {
"particle": "computercraft:blocks/cable_core",
"side": "computercraft:blocks/cable_side"
},
"elements": [
{
"from": [ 6, 6, 6 ],
"to": [ 10, 10, 10 ],
"faces": {
"down": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" },
"up": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" },
"north": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" },
"south": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" },
"west": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" },
"east": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" }
}
}
]
}

View File

@ -1,22 +1,22 @@
{ {
"parent": "block/block", "parent": "block/block",
"textures": { "textures": {
"particle": "computercraft:blocks/cable_core", "particle": "computercraft:blocks/cable_core",
"side": "computercraft:blocks/cable_side", "side": "computercraft:blocks/cable_side",
"end": "computercraft:blocks/cable_core" "end": "computercraft:blocks/cable_core"
}, },
"elements": [ "elements": [
{ {
"from": [ 6, 6, 6 ], "from": [ 6, 6, 6 ],
"to": [ 10, 10, 10 ], "to": [ 10, 10, 10 ],
"faces": { "faces": {
"down": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" }, "down": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" },
"up": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" }, "up": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" },
"north": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" }, "north": { "uv": [ 6, 6, 10, 10 ], "texture": "#end" },
"south": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" }, "south": { "uv": [ 6, 6, 10, 10 ], "texture": "#end" },
"west": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" }, "west": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" },
"east": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" } "east": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" }
} }
} }
] ]
} }