mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-06-26 07:03:22 +00:00
Provide .getNameLocal on modems
This provides the local modem's name on the remote network. Let's be honest, I'll probably end up renaming this soon.
This commit is contained in:
parent
a95893b823
commit
984d358930
|
@ -108,10 +108,11 @@ protected ModemPeripheral createPeripheral()
|
|||
m_node = m_cable.getNode();
|
||||
return new WiredModemPeripheral( m_cable )
|
||||
{
|
||||
@Nonnull
|
||||
@Override
|
||||
protected boolean canSeePeripheral( @Nonnull String peripheralName )
|
||||
protected WiredModemLocalPeripheral getLocalPeripheral()
|
||||
{
|
||||
return !peripheralName.equals( m_peripheral.getConnectedName() );
|
||||
return m_peripheral;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -401,12 +401,14 @@ public IPeripheral getPeripheral( EnumFacing side )
|
|||
WiredModemPeripheral peripheral = m_modems[side.ordinal()];
|
||||
if( peripheral == null )
|
||||
{
|
||||
WiredModemLocalPeripheral localPeripheral = m_peripherals[side.ordinal()];
|
||||
peripheral = m_modems[side.ordinal()] = new WiredModemPeripheral( m_element )
|
||||
{
|
||||
@Nonnull
|
||||
@Override
|
||||
protected boolean canSeePeripheral( @Nonnull String peripheralName )
|
||||
protected WiredModemLocalPeripheral getLocalPeripheral()
|
||||
{
|
||||
return !peripheralName.equals( m_peripherals[side.ordinal()].getConnectedName() );
|
||||
return localPeripheral;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -56,7 +56,8 @@ public World getWorld()
|
|||
return modem.getWorld();
|
||||
}
|
||||
|
||||
protected abstract boolean canSeePeripheral( @Nonnull String peripheralName );
|
||||
@Nonnull
|
||||
protected abstract WiredModemLocalPeripheral getLocalPeripheral();
|
||||
//endregion
|
||||
|
||||
//region IPeripheral
|
||||
|
@ -65,13 +66,14 @@ public World getWorld()
|
|||
public String[] getMethodNames()
|
||||
{
|
||||
String[] methods = super.getMethodNames();
|
||||
String[] newMethods = new String[methods.length + 5];
|
||||
String[] newMethods = new String[methods.length + 6];
|
||||
System.arraycopy( methods, 0, newMethods, 0, methods.length );
|
||||
newMethods[methods.length] = "getNamesRemote";
|
||||
newMethods[methods.length + 1] = "isPresentRemote";
|
||||
newMethods[methods.length + 2] = "getTypeRemote";
|
||||
newMethods[methods.length + 3] = "getMethodsRemote";
|
||||
newMethods[methods.length + 4] = "callRemote";
|
||||
newMethods[methods.length + 5] = "getNameLocal";
|
||||
return newMethods;
|
||||
}
|
||||
|
||||
|
@ -135,6 +137,12 @@ public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaCont
|
|||
System.arraycopy( arguments, 2, methodArgs, 0, arguments.length - 2 );
|
||||
return callMethodRemote( remoteName, context, methodName, methodArgs );
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
// getNameLocal
|
||||
String local = getLocalPeripheral().getConnectedName();
|
||||
return local == null ? null : new Object[]{ local };
|
||||
}
|
||||
default:
|
||||
{
|
||||
// The regular modem methods
|
||||
|
@ -217,7 +225,7 @@ public void detachPeripheral( String name )
|
|||
|
||||
private void attachPeripheralImpl( String periphName, IPeripheral peripheral )
|
||||
{
|
||||
if( !peripheralWrappers.containsKey( periphName ) && canSeePeripheral( periphName ) )
|
||||
if( !peripheralWrappers.containsKey( periphName ) && !periphName.equals( getLocalPeripheral().getConnectedName() ) )
|
||||
{
|
||||
RemotePeripheralWrapper wrapper = new RemotePeripheralWrapper( modem, peripheral, getComputer(), periphName );
|
||||
peripheralWrappers.put( periphName, wrapper );
|
||||
|
|
Loading…
Reference in New Issue
Block a user