1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 06:33:23 +00:00

Replace "cable variant" with a block model

- Replace BlockCableCableVariant with a boolean, removing any custom
   logic around it.
 - Replace our previous cable Forge-blockstate with a vanilla one, which
   handles cable connections in the model logic.
This commit is contained in:
SquidDev 2018-12-27 10:21:57 +00:00
parent 364d31465e
commit f61f7df2d8
4 changed files with 216 additions and 279 deletions

View File

@ -43,7 +43,7 @@ public class BlockCable extends BlockPeripheralBase
public static class Properties
{
public static final PropertyEnum<BlockCableModemVariant> MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class );
public static final PropertyEnum<BlockCableCableVariant> CABLE = PropertyEnum.create( "cable", BlockCableCableVariant.class );
public static final PropertyBool CABLE = PropertyBool.create( "cable" );
public static final PropertyBool NORTH = PropertyBool.create( "north" );
public static final PropertyBool SOUTH = PropertyBool.create( "south" );
public static final PropertyBool EAST = PropertyBool.create( "east" );
@ -61,7 +61,7 @@ public BlockCable()
setCreativeTab( ComputerCraft.mainCreativeTab );
setDefaultState( this.blockState.getBaseState()
.withProperty( Properties.MODEM, BlockCableModemVariant.None )
.withProperty( Properties.CABLE, BlockCableCableVariant.NONE )
.withProperty( Properties.CABLE, false )
.withProperty( Properties.NORTH, false )
.withProperty( Properties.SOUTH, false )
.withProperty( Properties.EAST, false )
@ -95,17 +95,17 @@ public IBlockState getStateFromMeta( int meta )
IBlockState state = getDefaultState();
if( meta < 6 )
{
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE );
state = state.withProperty( Properties.CABLE, false );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.byIndex( meta ) ) );
}
else if( meta < 12 )
{
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.ANY );
state = state.withProperty( Properties.CABLE, true );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.byIndex( meta - 6 ) ) );
}
else if( meta == 13 )
{
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.ANY );
state = state.withProperty( Properties.CABLE, true );
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.None );
}
return state;
@ -115,7 +115,7 @@ else if( meta == 13 )
public int getMetaFromState( IBlockState state )
{
int meta = 0;
boolean cable = state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE;
boolean cable = state.getValue( Properties.CABLE );
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
if( cable && modem != BlockCableModemVariant.None )
{
@ -138,36 +138,30 @@ public IBlockState getDefaultBlockState( PeripheralType type, EnumFacing placedS
switch( type )
{
case Cable:
{
return getDefaultState()
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.CABLE, true )
.withProperty( Properties.MODEM, BlockCableModemVariant.None );
}
case WiredModem:
default:
{
case WiredModem:
return getDefaultState()
.withProperty( Properties.CABLE, BlockCableCableVariant.NONE )
.withProperty( Properties.CABLE, false )
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
}
case WiredModemWithCable:
{
return getDefaultState()
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
.withProperty( Properties.CABLE, true )
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
}
}
}
public static boolean canConnectIn( IBlockState state, EnumFacing direction )
{
return state.getValue( BlockCable.Properties.CABLE ) != BlockCableCableVariant.NONE
return state.getValue( BlockCable.Properties.CABLE )
&& state.getValue( BlockCable.Properties.MODEM ).getFacing() != direction;
}
public static boolean doesConnectVisually( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction )
{
if( state.getValue( Properties.CABLE ) == BlockCableCableVariant.NONE ) return false;
if( !state.getValue( Properties.CABLE ) ) return false;
if( state.getValue( Properties.MODEM ).getFacing() == direction ) return true;
return ComputerCraft.getWiredElementAt( world, pos.offset( direction ), direction.getOpposite() ) != null;
}
@ -177,50 +171,21 @@ public static boolean doesConnectVisually( IBlockState state, IBlockAccess world
@Deprecated
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
{
state = state.withProperty( Properties.NORTH, doesConnectVisually( state, world, pos, EnumFacing.NORTH ) );
state = state.withProperty( Properties.SOUTH, doesConnectVisually( state, world, pos, EnumFacing.SOUTH ) );
state = state.withProperty( Properties.EAST, doesConnectVisually( state, world, pos, EnumFacing.EAST ) );
state = state.withProperty( Properties.WEST, doesConnectVisually( state, world, pos, EnumFacing.WEST ) );
state = state.withProperty( Properties.UP, doesConnectVisually( state, world, pos, EnumFacing.UP ) );
state = state.withProperty( Properties.DOWN, doesConnectVisually( state, world, pos, EnumFacing.DOWN ) );
state = state
.withProperty( Properties.NORTH, doesConnectVisually( state, world, pos, EnumFacing.NORTH ) )
.withProperty( Properties.SOUTH, doesConnectVisually( state, world, pos, EnumFacing.SOUTH ) )
.withProperty( Properties.EAST, doesConnectVisually( state, world, pos, EnumFacing.EAST ) )
.withProperty( Properties.WEST, doesConnectVisually( state, world, pos, EnumFacing.WEST ) )
.withProperty( Properties.UP, doesConnectVisually( state, world, pos, EnumFacing.UP ) )
.withProperty( Properties.DOWN, doesConnectVisually( 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 )
{
TilePeripheralBase peripheral = (TilePeripheralBase) tile;
anim = peripheral.getAnim();
}
else
{
anim = 0;
}
int anim = tile instanceof TilePeripheralBase ? ((TilePeripheralBase) tile).getAnim() : 0;
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
if( modem != BlockCableModemVariant.None )
{
modem = BlockCableModemVariant.values()[
1 + 6 * anim + modem.getFacing().getIndex()
];
modem = BlockCableModemVariant.values()[1 + 6 * anim + modem.getFacing().getIndex()];
}
state = state.withProperty( Properties.MODEM, modem );
@ -243,7 +208,7 @@ public PeripheralType getPeripheralType( int damage )
@Override
public PeripheralType getPeripheralType( IBlockState state )
{
boolean cable = state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE;
boolean cable = state.getValue( Properties.CABLE );
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
if( cable && modem != BlockCableModemVariant.None )
{
@ -271,7 +236,7 @@ public TilePeripheralBase createTile( PeripheralType type )
public RayTraceResult collisionRayTrace( IBlockState blockState, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d start, @Nonnull Vec3d end )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
if( tile instanceof TileGeneric && tile.hasWorld() )
{
TileGeneric generic = (TileGeneric) tile;
@ -316,7 +281,7 @@ public boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnul
if( hit != null )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileCable && tile.hasWorld() )
if( tile instanceof TileCable && tile.hasWorld() )
{
TileCable cable = (TileCable) tile;
@ -330,7 +295,7 @@ public boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnul
}
else
{
world.setBlockState( pos, state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE ), 3 );
world.setBlockState( pos, state.withProperty( Properties.CABLE, false ), 3 );
item = PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
}
@ -351,7 +316,7 @@ public boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnul
public ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult hit, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileCable && tile.hasWorld() )
if( tile instanceof TileCable && tile.hasWorld() )
{
TileCable cable = (TileCable) tile;
PeripheralType type = getPeripheralType( state );
@ -380,7 +345,7 @@ public ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult hit, @
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack )
{
TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileCable )
if( tile instanceof TileCable )
{
TileCable cable = (TileCable) tile;
if( cable.getPeripheralType() != PeripheralType.WiredModem )

View File

@ -1,35 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.peripheral.modem.wired;
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

@ -90,14 +90,14 @@ public EnumActionResult onItemUse( @Nonnull EntityPlayer player, World world, @N
{
if( !stack.isEmpty() )
{
IBlockState newState = existingState.withProperty( BlockCable.Properties.CABLE, BlockCableCableVariant.ANY );
IBlockState newState = existingState.withProperty( BlockCable.Properties.CABLE, true );
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 )
if( tile instanceof TileCable )
{
TileCable cable = (TileCable) tile;
cable.connectionsChanged();
@ -129,7 +129,7 @@ public EnumActionResult onItemUse( @Nonnull EntityPlayer player, World world, @N
stack.shrink( 1 );
TileEntity tile = world.getTileEntity( offset );
if( tile != null && tile instanceof TileCable )
if( tile instanceof TileCable )
{
TileCable cable = (TileCable) tile;
cable.modemChanged();
@ -145,14 +145,14 @@ public EnumActionResult onItemUse( @Nonnull EntityPlayer player, World world, @N
{
if( !stack.isEmpty() )
{
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.CABLE, BlockCableCableVariant.ANY );
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.CABLE, true );
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 );
stack.shrink( 1 );
TileEntity tile = world.getTileEntity( offset );
if( tile != null && tile instanceof TileCable )
if( tile instanceof TileCable )
{
TileCable cable = (TileCable) tile;
cable.modemChanged();

View File

@ -1,190 +1,197 @@
{
"forge_marker": 1,
"variants": {
"cable": {
"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 } } }
"multipart": [
{
"when": {
"OR": [
{
"cable": "true", "up": "true",
"north": "false", "south": "false", "west": "false", "east": "false"
},
{
"cable": "true", "down": "true",
"north": "false", "south": "false", "west": "false", "east": "false"
}
]
},
"apply": { "model": "computercraft:cable_core_facing", "x": 90 }
},
"up": {
"true": {
"submodel": {
"up": { "model": "computercraft:cable_arm", "x": 90 }
}
{
"when": {
"OR": [
{
"cable": "true", "up": "false", "down": "false",
"north": "false", "south": "false", "west": "false", "east": "false"
},
{
"cable": "true", "north": "true",
"up": "false", "down": "false", "west": "false", "east": "false"
},
{
"cable": "true", "south": "true",
"up": "false", "down": "false", "west": "false", "east": "false"
}
]
},
"false": {
}
"apply": { "model": "computercraft:cable_core_facing", "y": 0 }
},
"down": {
"true": {
"submodel": {
"down": { "model": "computercraft:cable_arm", "x": 270 }
}
{
"when": {
"OR": [
{
"cable": "true", "west": "true",
"up": "false", "down": "false", "north": "false", "south": "false"
},
{
"cable": "true", "east": "true",
"up": "false", "down": "false", "north": "false", "south": "false"
}
]
},
"false": {
}
"apply": { "model": "computercraft:cable_core_facing", "y": 90 }
},
"north": {
"true": {
"submodel": {
"north": { "model": "computercraft:cable_arm", "y": 180 }
}
{
"when": {
"OR": [
{ "cable": "true", "down": "true", "north": "true" },
{ "cable": "true", "down": "true", "south": "true" },
{ "cable": "true", "down": "true", "east": "true" },
{ "cable": "true", "down": "true", "west": "true" },
{ "cable": "true", "up": "true", "north": "true" },
{ "cable": "true", "up": "true", "south": "true" },
{ "cable": "true", "up": "true", "east": "true" },
{ "cable": "true", "up": "true", "west": "true" },
{ "cable": "true", "north": "true", "west": "true" },
{ "cable": "true", "north": "true", "east": "true" },
{ "cable": "true", "south": "true", "west": "true" },
{ "cable": "true", "south": "true", "east": "true" }
]
},
"false": {
}
"apply": { "model": "computercraft:cable_core_any" }
},
"south": {
"true": {
"submodel": {
"south": { "model": "computercraft:cable_arm" }
}
},
"false": {
}
{
"when": { "up": true },
"apply": { "model": "computercraft:cable_arm", "x": 90 }
},
"west": {
"true": {
"submodel": {
"west": { "model": "computercraft:cable_arm", "y": 90 }
}
},
"false": {
}
{
"when": { "down": true },
"apply": { "model": "computercraft:cable_arm", "x": 270 }
},
"east": {
"true": {
"submodel": {
"east": { "model": "computercraft:cable_arm", "y": 270 }
}
},
"false": {
}
{
"when": { "north": true },
"apply": { "model": "computercraft:cable_arm", "y": 180 }
},
"modem": {
"none": {
},
"up_off": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off", "x": 270 }
}
},
"down_off": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off", "x": 90 }
}
},
"north_off": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off" }
}
},
"south_off": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off", "y": 180 }
}
},
"west_off": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off", "y": 270 }
}
},
"east_off": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off", "y": 90 }
}
},
"up_on": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on", "x": 270 }
}
},
"down_on": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on", "x": 90 }
}
},
"north_on": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on" }
}
},
"south_on": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on", "y": 180 }
}
},
"west_on": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on", "y": 270 }
}
},
"east_on": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on", "y": 90 }
}
},
"up_off_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off_peripheral", "x": 270 }
}
},
"down_off_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off_peripheral", "x": 90 }
}
},
"north_off_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off_peripheral" }
}
},
"south_off_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off_peripheral", "y": 180 }
}
},
"west_off_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off_peripheral", "y": 270 }
}
},
"east_off_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_off_peripheral", "y": 90 }
}
},
"up_on_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on_peripheral", "x": 270 }
}
},
"down_on_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on_peripheral", "x": 90 }
}
},
"north_on_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on_peripheral" }
}
},
"south_on_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on_peripheral", "y": 180 }
}
},
"west_on_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on_peripheral", "y": 270 }
}
},
"east_on_peripheral": {
"submodel": {
"modem": { "model": "computercraft:wired_modem_on_peripheral", "y": 90 }
}
}
{
"when": { "south": true },
"apply": { "model": "computercraft:cable_arm" }
},
{
"when": { "west": true },
"apply": { "model": "computercraft:cable_arm", "y": 90 }
},
{
"when": { "east": true },
"apply": { "model": "computercraft:cable_arm", "y": 270 }
},
{
"when": { "modem": "up_off" },
"apply": { "model": "computercraft:wired_modem_off", "x": 270 }
},
{
"when": { "modem": "down_off" },
"apply": { "model": "computercraft:wired_modem_off", "x": 90 }
},
{
"when": { "modem": "north_off" },
"apply": { "model": "computercraft:wired_modem_off" }
},
{
"when": { "modem": "south_off" },
"apply": { "model": "computercraft:wired_modem_off", "y": 180 }
},
{
"when": { "modem": "west_off" },
"apply": { "model": "computercraft:wired_modem_off", "y": 270 }
},
{
"when": { "modem": "east_off" },
"apply": { "model": "computercraft:wired_modem_off", "y": 90 }
},
{
"when": { "modem": "up_on" },
"apply": { "model": "computercraft:wired_modem_on", "x": 270 }
},
{
"when": { "modem": "down_on" },
"apply": { "model": "computercraft:wired_modem_on", "x": 90 }
},
{
"when": { "modem": "north_on" },
"apply": { "model": "computercraft:wired_modem_on" }
},
{
"when": { "modem": "south_on" },
"apply": { "model": "computercraft:wired_modem_on", "y": 180 }
},
{
"when": { "modem": "west_on" },
"apply": { "model": "computercraft:wired_modem_on", "y": 270 }
},
{
"when": { "modem": "east_on" },
"apply": { "model": "computercraft:wired_modem_on", "y": 90 }
},
{
"when": { "modem": "up_off_peripheral" },
"apply": { "model": "computercraft:wired_modem_off_peripheral", "x": 270 }
},
{
"when": { "modem": "down_off_peripheral" },
"apply": { "model": "computercraft:wired_modem_off_peripheral", "x": 90 }
},
{
"when": { "modem": "north_off_peripheral" },
"apply": { "model": "computercraft:wired_modem_off_peripheral" }
},
{
"when": { "modem": "south_off_peripheral" },
"apply": { "model": "computercraft:wired_modem_off_peripheral", "y": 180 }
},
{
"when": { "modem": "west_off_peripheral" },
"apply": { "model": "computercraft:wired_modem_off_peripheral", "y": 270 }
},
{
"when": { "modem": "east_off_peripheral" },
"apply": { "model": "computercraft:wired_modem_off_peripheral", "y": 90 }
},
{
"when": { "modem": "up_on_peripheral" },
"apply": { "model": "computercraft:wired_modem_on_peripheral", "x": 270 }
},
{
"when": { "modem": "down_on_peripheral" },
"apply": { "model": "computercraft:wired_modem_on_peripheral", "x": 90 }
},
{
"when": { "modem": "north_on_peripheral" },
"apply": { "model": "computercraft:wired_modem_on_peripheral" }
},
{
"when": { "modem": "south_on_peripheral" },
"apply": { "model": "computercraft:wired_modem_on_peripheral", "y": 180 }
},
{
"when": { "modem": "west_on_peripheral" },
"apply": { "model": "computercraft:wired_modem_on_peripheral", "y": 270 }
},
{
"when": { "modem": "east_on_peripheral" },
"apply": { "model": "computercraft:wired_modem_on_peripheral", "y": 90 }
}
}
]
}