1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-06 16:33:00 +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 class BlockCable extends BlockPeripheralBase
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 class BlockCable extends BlockPeripheralBase
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 @@ public class BlockCable extends BlockPeripheralBase
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 class BlockCable extends BlockPeripheralBase
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 class BlockCable extends BlockPeripheralBase
@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 class BlockCable extends BlockPeripheralBase
@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 class BlockCable extends BlockPeripheralBase
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 class BlockCable extends BlockPeripheralBase
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 class BlockCable extends BlockPeripheralBase
}
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 class BlockCable extends BlockPeripheralBase
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 class BlockCable extends BlockPeripheralBase
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 class ItemCable extends ItemPeripheralBase
{
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 class ItemCable extends ItemPeripheralBase
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 class ItemCable extends ItemPeripheralBase
{
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();