mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-15 16:32:52 +00:00

illuaminate does not handle Java files, for obvious reasons. In order to get around that, we have a series of stub files within /doc/stub which mirrored the Java ones. While this works, it has a few problems: - The link to source code does not work - it just links to the stub file. - There's no guarantee that documentation remains consistent with the Java code. This change found several methods which were incorrectly documented beforehand. We now replace this with a custom Java doclet[1], which extracts doc comments from @LuaFunction annotated methods and generates stub-files from them. These also contain a @source annotation, which allows us to correctly link them back to the original Java code. There's some issues with this which have yet to be fixed. However, I don't think any of them are major blockers right now: - The custom doclet relies on Java 9 - I think it's /technically/ possible to do this on Java 8, but the API is significantly uglier. This means that we need to run javadoc on a separate JVM. This is possible, and it works locally and on CI, but is definitely not a nice approach. - illuaminate now requires the doc stubs to be generated in order for the linter to pass, which does make running the linter locally much harder (especially given the above bullet point). We could notionally include the generated stubs (or at least a cut down version of them) in the repo, but I'm not 100% sure about that. [1]: https://docs.oracle.com/javase/9/docs/api/jdk/javadoc/doclet/package-summary.html
117 lines
2.5 KiB
Java
117 lines
2.5 KiB
Java
/*
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
*/
|
|
package dan200.computercraft.shared.computer.blocks;
|
|
|
|
import dan200.computercraft.api.lua.LuaFunction;
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
|
import dan200.computercraft.core.apis.OSAPI;
|
|
|
|
import javax.annotation.Nonnull;
|
|
import javax.annotation.Nullable;
|
|
|
|
/**
|
|
* A computer or turtle wrapped as a peripheral.
|
|
*
|
|
* This allows for basic interaction with adjacent computers. Computers wrapped as peripherals will have the type
|
|
* {@code computer} while turtles will be {@code turtle}.
|
|
*
|
|
* @cc.module computer
|
|
*/
|
|
public class ComputerPeripheral implements IPeripheral
|
|
{
|
|
private final String type;
|
|
private final ComputerProxy computer;
|
|
|
|
public ComputerPeripheral( String type, ComputerProxy computer )
|
|
{
|
|
this.type = type;
|
|
this.computer = computer;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public String getType()
|
|
{
|
|
return type;
|
|
}
|
|
|
|
/**
|
|
* Turn the other computer on.
|
|
*/
|
|
@LuaFunction
|
|
public final void turnOn()
|
|
{
|
|
computer.turnOn();
|
|
}
|
|
|
|
/**
|
|
* Shutdown the other computer.
|
|
*/
|
|
@LuaFunction
|
|
public final void shutdown()
|
|
{
|
|
computer.shutdown();
|
|
}
|
|
|
|
/**
|
|
* Reboot or turn on the other computer.
|
|
*/
|
|
@LuaFunction
|
|
public final void reboot()
|
|
{
|
|
computer.reboot();
|
|
}
|
|
|
|
/**
|
|
* Get the other computer's ID.
|
|
*
|
|
* @return The computer's ID.
|
|
* @see OSAPI#getComputerID() To get your computer's ID.
|
|
*/
|
|
@LuaFunction
|
|
public final int getID()
|
|
{
|
|
return computer.assignID();
|
|
}
|
|
|
|
/**
|
|
* Determine if the other computer is on.
|
|
*
|
|
* @return If the computer is on.
|
|
*/
|
|
@LuaFunction
|
|
public final boolean isOn()
|
|
{
|
|
return computer.isOn();
|
|
}
|
|
|
|
/**
|
|
* Get the other computer's label.
|
|
*
|
|
* @return The computer's label.
|
|
* @see OSAPI#getComputerLabel() To get your label.
|
|
*/
|
|
@Nullable
|
|
@LuaFunction
|
|
public final String getLabel()
|
|
{
|
|
return computer.getLabel();
|
|
}
|
|
|
|
@Override
|
|
public boolean equals( IPeripheral other )
|
|
{
|
|
return other instanceof ComputerPeripheral && computer == ((ComputerPeripheral) other).computer;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public Object getTarget()
|
|
{
|
|
return computer.getTile();
|
|
}
|
|
}
|