mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-07-01 01:23:30 +00:00
Provide a more direct way to get the related computer
Effectively shift extracting the computer away from Plethora into CC:T. Ideally we wouldn't need this at all, but Plethora does some funky things with tick timings. See SquidDev-CC/plethora#125
This commit is contained in:
parent
45a189e834
commit
0bf13562b9
|
@ -3,14 +3,17 @@
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
|
import dan200.computercraft.core.computer.Computer;
|
||||||
|
import dan200.computercraft.core.computer.IComputerOwned;
|
||||||
import dan200.computercraft.core.filesystem.FileSystem;
|
import dan200.computercraft.core.filesystem.FileSystem;
|
||||||
import dan200.computercraft.core.filesystem.FileSystemException;
|
import dan200.computercraft.core.filesystem.FileSystemException;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public abstract class ComputerAccess implements IComputerAccess
|
public abstract class ComputerAccess implements IComputerAccess, IComputerOwned
|
||||||
{
|
{
|
||||||
private final IAPIEnvironment m_environment;
|
private final IAPIEnvironment m_environment;
|
||||||
private final Set<String> m_mounts = new HashSet<>();
|
private final Set<String> m_mounts = new HashSet<>();
|
||||||
|
@ -133,6 +136,13 @@ public void queueEvent( @Nonnull final String event, final Object[] arguments )
|
||||||
m_environment.queueEvent( event, arguments );
|
m_environment.queueEvent( event, arguments );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Computer getComputer()
|
||||||
|
{
|
||||||
|
return m_environment.getComputer();
|
||||||
|
}
|
||||||
|
|
||||||
private String findFreeLocation( String desiredLoc )
|
private String findFreeLocation( String desiredLoc )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -9,17 +9,19 @@
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.core.computer.Computer;
|
import dan200.computercraft.core.computer.Computer;
|
||||||
import dan200.computercraft.core.computer.IComputerEnvironment;
|
import dan200.computercraft.core.computer.IComputerEnvironment;
|
||||||
|
import dan200.computercraft.core.computer.IComputerOwned;
|
||||||
import dan200.computercraft.core.filesystem.FileSystem;
|
import dan200.computercraft.core.filesystem.FileSystem;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.core.tracking.TrackingField;
|
import dan200.computercraft.core.tracking.TrackingField;
|
||||||
|
|
||||||
public interface IAPIEnvironment
|
public interface IAPIEnvironment extends IComputerOwned
|
||||||
{
|
{
|
||||||
interface IPeripheralChangeListener
|
interface IPeripheralChangeListener
|
||||||
{
|
{
|
||||||
void onPeripheralChanged( int side, IPeripheral newPeripheral );
|
void onPeripheralChanged( int side, IPeripheral newPeripheral );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
Computer getComputer();
|
Computer getComputer();
|
||||||
int getComputerID();
|
int getComputerID();
|
||||||
IComputerEnvironment getComputerEnvironment();
|
IComputerEnvironment getComputerEnvironment();
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package dan200.computercraft.core.computer;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public interface IComputerOwned
|
||||||
|
{
|
||||||
|
@Nullable
|
||||||
|
Computer getComputer();
|
||||||
|
}
|
|
@ -10,6 +10,8 @@
|
||||||
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 dan200.computercraft.core.computer.Computer;
|
||||||
|
import dan200.computercraft.core.computer.IComputerOwned;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -273,7 +275,7 @@ private Object[] callMethodRemote( String remoteName, ILuaContext context, Strin
|
||||||
throw new LuaException( "No peripheral: " + remoteName );
|
throw new LuaException( "No peripheral: " + remoteName );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class RemotePeripheralWrapper implements IComputerAccess
|
private static class RemotePeripheralWrapper implements IComputerAccess, IComputerOwned
|
||||||
{
|
{
|
||||||
private final WiredModemElement m_element;
|
private final WiredModemElement m_element;
|
||||||
private final IPeripheral m_peripheral;
|
private final IPeripheral m_peripheral;
|
||||||
|
@ -408,5 +410,12 @@ public IPeripheral getAvailablePeripheral( @Nonnull String name )
|
||||||
return m_element.getRemotePeripherals().get( name );
|
return m_element.getRemotePeripherals().get( name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Computer getComputer()
|
||||||
|
{
|
||||||
|
return m_computer instanceof IComputerOwned ? ((IComputerOwned) m_computer).getComputer() : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user