mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 19:50:31 +00:00
Ensure the modem's peripheral is incorrectly invalidated when changed
This commit is contained in:
parent
75ccfbdb3d
commit
7169abcd7b
@ -17,6 +17,7 @@ import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockFaceShape;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@ -76,7 +77,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( this.blockState.getBaseState()
|
||||
.withProperty( Properties.MODEM, BlockCableModemVariant.None )
|
||||
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
|
||||
.withProperty( Properties.CABLE, BlockCableCableVariant.NONE )
|
||||
.withProperty( Properties.NORTH, false )
|
||||
.withProperty( Properties.SOUTH, false )
|
||||
.withProperty( Properties.EAST, false )
|
||||
@ -162,7 +163,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
default:
|
||||
{
|
||||
return getDefaultState()
|
||||
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
|
||||
.withProperty( Properties.CABLE, BlockCableCableVariant.NONE )
|
||||
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
|
||||
}
|
||||
case WiredModemWithCable:
|
||||
@ -344,16 +345,16 @@ public class BlockCable extends BlockPeripheralBase
|
||||
if( WorldUtil.isVecInsideInclusive( bb, hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||
{
|
||||
world.setBlockState( pos, state.withProperty( Properties.MODEM, BlockCableModemVariant.None ), 3 );
|
||||
cable.networkChanged();
|
||||
cable.modemChanged();
|
||||
item = PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
world.setBlockState( pos, state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE ), 3 );
|
||||
cable.networkChanged();
|
||||
item = PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
|
||||
}
|
||||
|
||||
cable.networkChanged();
|
||||
if( !world.isRemote && !player.capabilities.isCreativeMode ) dropItem( world, pos, item );
|
||||
|
||||
return false;
|
||||
@ -393,6 +394,22 @@ public class BlockCable extends BlockPeripheralBase
|
||||
return PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileCable )
|
||||
{
|
||||
TileCable cable = (TileCable) tile;
|
||||
if( cable.getPeripheralType() != PeripheralType.WiredModem )
|
||||
{
|
||||
cable.networkChanged();
|
||||
}
|
||||
}
|
||||
|
||||
super.onBlockPlacedBy( world, pos, state, placer, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isOpaqueCube( IBlockState state )
|
||||
|
@ -359,6 +359,7 @@ public class TileCable extends TileModemBase
|
||||
((BlockGeneric)getBlockType()).dropItem( getWorld(), getPos(), PeripheralItemFactory.create( PeripheralType.WiredModem, getLabel(), 1 ) );
|
||||
setLabel( null );
|
||||
setBlockState( getBlockState().withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.None ) );
|
||||
modemChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -682,7 +683,7 @@ public class TileCable extends TileModemBase
|
||||
{
|
||||
if( !getWorld().isRemote )
|
||||
{
|
||||
if( !m_destroyed )
|
||||
if( !m_destroyed && getPeripheralType() != PeripheralType.WiredModem)
|
||||
{
|
||||
// If this modem is alive, rebuild the network
|
||||
searchNetwork( ( modem, distance ) ->
|
||||
@ -713,6 +714,25 @@ public class TileCable extends TileModemBase
|
||||
}
|
||||
}
|
||||
|
||||
public void modemChanged()
|
||||
{
|
||||
if( getWorld().isRemote ) return;
|
||||
|
||||
PeripheralType type = getPeripheralType();
|
||||
if( type == PeripheralType.Cable )
|
||||
{
|
||||
m_attachedPeripheralID = -1;
|
||||
}
|
||||
|
||||
if( type != PeripheralType.WiredModemWithCable && m_peripheralAccessAllowed )
|
||||
{
|
||||
m_peripheralAccessAllowed = false;
|
||||
}
|
||||
|
||||
markDirty();
|
||||
updateAnim();
|
||||
}
|
||||
|
||||
// private stuff
|
||||
|
||||
// Packet sending
|
||||
|
Loading…
Reference in New Issue
Block a user