mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-07-01 01:23:30 +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 World getWorld()
|
||||||
public Vec3d getPosition()
|
public Vec3d getPosition()
|
||||||
{
|
{
|
||||||
BlockPos pos = m_entity.getPos();
|
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
|
@Nonnull
|
||||||
|
@ -92,10 +92,7 @@ public Map<String, IPeripheral> getPeripherals()
|
||||||
@Override
|
@Override
|
||||||
protected void attachPeripheral( String name, IPeripheral peripheral )
|
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
|
@Override
|
||||||
|
@ -133,6 +130,12 @@ protected ModemPeripheral createPeripheral()
|
||||||
m_node = m_cable.getNode();
|
m_node = m_cable.getNode();
|
||||||
return new WiredModemPeripheral( m_cable )
|
return new WiredModemPeripheral( m_cable )
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
|
protected boolean canSeePeripheral( @Nonnull String peripheralName )
|
||||||
|
{
|
||||||
|
return !peripheralName.equals( getConnectedPeripheralName() );
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Vec3d getPosition()
|
public Vec3d getPosition()
|
||||||
|
|
|
@ -48,10 +48,7 @@ protected void attachPeripheral( String name, IPeripheral peripheral )
|
||||||
for( int i = 0; i < 6; i++ )
|
for( int i = 0; i < 6; i++ )
|
||||||
{
|
{
|
||||||
WiredModemPeripheral modem = m_entity.m_modems[i];
|
WiredModemPeripheral modem = m_entity.m_modems[i];
|
||||||
if( modem != null && !name.equals( m_entity.getCachedPeripheralName( EnumFacing.VALUES[i] ) ) )
|
if( modem != null ) modem.attachPeripheral( name, peripheral );
|
||||||
{
|
|
||||||
modem.attachPeripheral( name, peripheral );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,6 +413,12 @@ public IPeripheral getPeripheral( EnumFacing side )
|
||||||
{
|
{
|
||||||
peripheral = m_modems[side.ordinal()] = new WiredModemPeripheral( m_element )
|
peripheral = m_modems[side.ordinal()] = new WiredModemPeripheral( m_element )
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
|
protected boolean canSeePeripheral( @Nonnull String peripheralName )
|
||||||
|
{
|
||||||
|
return !peripheralName.equals( getCachedPeripheralName( side ) );
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Vec3d getPosition()
|
public Vec3d getPosition()
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
import dan200.computercraft.api.network.wired.IWiredSender;
|
import dan200.computercraft.api.network.wired.IWiredSender;
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -20,7 +19,7 @@
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
|
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;
|
private final WiredModemElement modem;
|
||||||
|
|
||||||
|
@ -57,12 +56,7 @@ public World getWorld()
|
||||||
return modem.getWorld();
|
return modem.getWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
protected abstract boolean canSeePeripheral( @Nonnull String peripheralName );
|
||||||
@Override
|
|
||||||
public Vec3d getPosition()
|
|
||||||
{
|
|
||||||
return modem.getPosition();
|
|
||||||
}
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region IPeripheral
|
//region IPeripheral
|
||||||
|
@ -223,7 +217,7 @@ public void detachPeripheral( String name )
|
||||||
|
|
||||||
private void attachPeripheralImpl( String periphName, IPeripheral peripheral )
|
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 );
|
RemotePeripheralWrapper wrapper = new RemotePeripheralWrapper( modem, peripheral, getComputer(), periphName );
|
||||||
peripheralWrappers.put( periphName, wrapper );
|
peripheralWrappers.put( periphName, wrapper );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user