mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 11:10: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:
parent
a1d77ab8e7
commit
abe917cd54
@ -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
|
||||
@ -92,10 +92,7 @@ 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 );
|
||||
}
|
||||
((WiredModemPeripheral) m_entity.m_modem).attachPeripheral( name, peripheral );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user