1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 19:20:29 +00:00

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 #20
This commit is contained in:
SquidDev 2018-04-07 10:23:11 +01:00
parent a1d77ab8e7
commit abe917cd54
3 changed files with 18 additions and 18 deletions

View File

@ -76,7 +76,7 @@ public class TileCable extends TileModemBase
public Vec3d getPosition()
{
BlockPos pos = m_entity.getPos();
return new Vec3d( (double) pos.getX() + 0.5, (double) pos.getY() + 0.5, (double) pos.getZ() + 0.5 );
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
}
@Nonnull
@ -91,12 +91,9 @@ public class TileCable extends TileModemBase
@Override
protected void attachPeripheral( String name, IPeripheral peripheral )
{
if( !name.equals( m_entity.getConnectedPeripheralName() ) )
{
((WiredModemPeripheral) m_entity.m_modem).attachPeripheral( name, peripheral );
}
}
@Override
protected void detachPeripheral( String name )
@ -133,6 +130,12 @@ public class TileCable extends TileModemBase
m_node = m_cable.getNode();
return new WiredModemPeripheral( m_cable )
{
@Override
protected boolean canSeePeripheral( @Nonnull String peripheralName )
{
return !peripheralName.equals( getConnectedPeripheralName() );
}
@Nonnull
@Override
public Vec3d getPosition()

View File

@ -48,10 +48,7 @@ public class TileWiredModemFull extends TilePeripheralBase
for( int i = 0; i < 6; i++ )
{
WiredModemPeripheral modem = m_entity.m_modems[i];
if( modem != null && !name.equals( m_entity.getCachedPeripheralName( EnumFacing.VALUES[i] ) ) )
{
modem.attachPeripheral( name, peripheral );
}
if( modem != null ) modem.attachPeripheral( name, peripheral );
}
}
@ -416,6 +413,12 @@ public class TileWiredModemFull extends TilePeripheralBase
{
peripheral = m_modems[side.ordinal()] = new WiredModemPeripheral( m_element )
{
@Override
protected boolean canSeePeripheral( @Nonnull String peripheralName )
{
return !peripheralName.equals( getCachedPeripheralName( side ) );
}
@Nonnull
@Override
public Vec3d getPosition()

View File

@ -10,7 +10,6 @@ import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.network.wired.IWiredSender;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
@ -20,7 +19,7 @@ import java.util.Map;
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
public class WiredModemPeripheral extends ModemPeripheral implements IWiredSender
public abstract class WiredModemPeripheral extends ModemPeripheral implements IWiredSender
{
private final WiredModemElement modem;
@ -57,12 +56,7 @@ public class WiredModemPeripheral extends ModemPeripheral implements IWiredSende
return modem.getWorld();
}
@Nonnull
@Override
public Vec3d getPosition()
{
return modem.getPosition();
}
protected abstract boolean canSeePeripheral( @Nonnull String peripheralName );
//endregion
//region IPeripheral
@ -223,7 +217,7 @@ public class WiredModemPeripheral extends ModemPeripheral implements IWiredSende
private void attachPeripheralImpl( String periphName, IPeripheral peripheral )
{
if( !peripheralWrappers.containsKey( periphName ) )
if( !peripheralWrappers.containsKey( periphName ) && canSeePeripheral( periphName ) )
{
RemotePeripheralWrapper wrapper = new RemotePeripheralWrapper( modem, peripheral, getComputer(), periphName );
peripheralWrappers.put( periphName, wrapper );