Skip to content

Commit abe917c

Browse files
committed
Fix peripherals showing up when they shouldn't on world load
When initially attaching a modem, the adjacent computer would not show up on its own peripheral list (like in vanilla CC). However, it would show up when the chunk was reloaded as peripherals were added through a different method. This prevents such behaviour, always hiding the remote peripheral from the object which provides it. Closes dan200#20
1 parent a1d77ab commit abe917c

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public World getWorld()
7676
public Vec3d getPosition()
7777
{
7878
BlockPos pos = m_entity.getPos();
79-
return new Vec3d( (double) pos.getX() + 0.5, (double) pos.getY() + 0.5, (double) pos.getZ() + 0.5 );
79+
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
8080
}
8181

8282
@Nonnull
@@ -92,10 +92,7 @@ public Map<String, IPeripheral> getPeripherals()
9292
@Override
9393
protected void attachPeripheral( String name, IPeripheral peripheral )
9494
{
95-
if( !name.equals( m_entity.getConnectedPeripheralName() ) )
96-
{
97-
((WiredModemPeripheral) m_entity.m_modem).attachPeripheral( name, peripheral );
98-
}
95+
((WiredModemPeripheral) m_entity.m_modem).attachPeripheral( name, peripheral );
9996
}
10097

10198
@Override
@@ -133,6 +130,12 @@ protected ModemPeripheral createPeripheral()
133130
m_node = m_cable.getNode();
134131
return new WiredModemPeripheral( m_cable )
135132
{
133+
@Override
134+
protected boolean canSeePeripheral( @Nonnull String peripheralName )
135+
{
136+
return !peripheralName.equals( getConnectedPeripheralName() );
137+
}
138+
136139
@Nonnull
137140
@Override
138141
public Vec3d getPosition()

src/main/java/dan200/computercraft/shared/peripheral/modem/TileWiredModemFull.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ protected void attachPeripheral( String name, IPeripheral peripheral )
4848
for( int i = 0; i < 6; i++ )
4949
{
5050
WiredModemPeripheral modem = m_entity.m_modems[i];
51-
if( modem != null && !name.equals( m_entity.getCachedPeripheralName( EnumFacing.VALUES[i] ) ) )
52-
{
53-
modem.attachPeripheral( name, peripheral );
54-
}
51+
if( modem != null ) modem.attachPeripheral( name, peripheral );
5552
}
5653
}
5754

@@ -416,6 +413,12 @@ public IPeripheral getPeripheral( EnumFacing side )
416413
{
417414
peripheral = m_modems[side.ordinal()] = new WiredModemPeripheral( m_element )
418415
{
416+
@Override
417+
protected boolean canSeePeripheral( @Nonnull String peripheralName )
418+
{
419+
return !peripheralName.equals( getCachedPeripheralName( side ) );
420+
}
421+
419422
@Nonnull
420423
@Override
421424
public Vec3d getPosition()

src/main/java/dan200/computercraft/shared/peripheral/modem/WiredModemPeripheral.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import dan200.computercraft.api.network.wired.IWiredSender;
1111
import dan200.computercraft.api.peripheral.IComputerAccess;
1212
import dan200.computercraft.api.peripheral.IPeripheral;
13-
import net.minecraft.util.math.Vec3d;
1413
import net.minecraft.world.World;
1514

1615
import javax.annotation.Nonnull;
@@ -20,7 +19,7 @@
2019

2120
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
2221

23-
public class WiredModemPeripheral extends ModemPeripheral implements IWiredSender
22+
public abstract class WiredModemPeripheral extends ModemPeripheral implements IWiredSender
2423
{
2524
private final WiredModemElement modem;
2625

@@ -57,12 +56,7 @@ public World getWorld()
5756
return modem.getWorld();
5857
}
5958

60-
@Nonnull
61-
@Override
62-
public Vec3d getPosition()
63-
{
64-
return modem.getPosition();
65-
}
59+
protected abstract boolean canSeePeripheral( @Nonnull String peripheralName );
6660
//endregion
6761

6862
//region IPeripheral
@@ -223,7 +217,7 @@ public void detachPeripheral( String name )
223217

224218
private void attachPeripheralImpl( String periphName, IPeripheral peripheral )
225219
{
226-
if( !peripheralWrappers.containsKey( periphName ) )
220+
if( !peripheralWrappers.containsKey( periphName ) && canSeePeripheral( periphName ) )
227221
{
228222
RemotePeripheralWrapper wrapper = new RemotePeripheralWrapper( modem, peripheral, getComputer(), periphName );
229223
peripheralWrappers.put( periphName, wrapper );

0 commit comments

Comments
 (0)