diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java index 4e5d2419b..6a84ff0e4 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java @@ -41,7 +41,7 @@ public class BlockCable extends BlockPeripheralBase public static class Properties { public static final PropertyEnum MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class ); - public static final PropertyBool CABLE = PropertyBool.create( "cable" ); + public static final PropertyEnum 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 ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCableCableVariant.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCableCableVariant.java new file mode 100644 index 000000000..f9a55f7ff --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCableCableVariant.java @@ -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; + } +} diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java index 8ad66a8e4..792fe47b9 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java @@ -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 ); diff --git a/src/main/resources/assets/computercraft/blockstates/cable.json b/src/main/resources/assets/computercraft/blockstates/cable.json index a4cea04e3..b06b69112 100644 --- a/src/main/resources/assets/computercraft/blockstates/cable.json +++ b/src/main/resources/assets/computercraft/blockstates/cable.json @@ -2,13 +2,11 @@ "forge_marker": 1, "variants": { "cable": { - "true": { - "submodel": { - "cable": { "model": "computercraft:cable_core" } - } - }, - "false": { - } + "none": { }, + "any": { "submodel": { "cable": { "model": "computercraft:cable_core_any" } } }, + "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 } } } }, "up": { "true": { diff --git a/src/main/resources/assets/computercraft/models/block/cable_arm.json b/src/main/resources/assets/computercraft/models/block/cable_arm.json index 93d448067..9e407d854 100644 --- a/src/main/resources/assets/computercraft/models/block/cable_arm.json +++ b/src/main/resources/assets/computercraft/models/block/cable_arm.json @@ -6,7 +6,7 @@ }, "elements": [ { - "from": [ 6, 6, 10 ], + "from": [ 6, 6, 10 ], "to": [ 10, 10, 16 ], "faces": { "down": { "uv": [ 6, 0, 10, 6 ], "texture": "#side" }, diff --git a/src/main/resources/assets/computercraft/models/block/cable_core_any.json b/src/main/resources/assets/computercraft/models/block/cable_core_any.json new file mode 100644 index 000000000..05d4daeb6 --- /dev/null +++ b/src/main/resources/assets/computercraft/models/block/cable_core_any.json @@ -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" } + } + } + ] +} diff --git a/src/main/resources/assets/computercraft/models/block/cable_core.json b/src/main/resources/assets/computercraft/models/block/cable_core_facing.json similarity index 89% rename from src/main/resources/assets/computercraft/models/block/cable_core.json rename to src/main/resources/assets/computercraft/models/block/cable_core_facing.json index 52121908d..aa47ecf87 100644 --- a/src/main/resources/assets/computercraft/models/block/cable_core.json +++ b/src/main/resources/assets/computercraft/models/block/cable_core_facing.json @@ -1,22 +1,22 @@ -{ - "parent": "block/block", - "textures": { - "particle": "computercraft:blocks/cable_core", - "side": "computercraft:blocks/cable_side", - "end": "computercraft:blocks/cable_core" - }, - "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" } - } - } - ] -} +{ + "parent": "block/block", + "textures": { + "particle": "computercraft:blocks/cable_core", + "side": "computercraft:blocks/cable_side", + "end": "computercraft:blocks/cable_core" + }, + "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": "#end" }, + "south": { "uv": [ 6, 6, 10, 10 ], "texture": "#end" }, + "west": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" }, + "east": { "uv": [ 6, 6, 10, 10 ], "texture": "#side" } + } + } + ] +}