Skip to content

Commit ee5a34d

Browse files
committedApr 11, 2015
The great documentatening!
1 parent be3261f commit ee5a34d

20 files changed

+126
-125
lines changed
 

‎changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
==== 1.4.7 ====
22

33
* ADDED: All Computronics blocks now support the OpenComputers API documentation in NotEnoughItems.
4+
* ADDED: Documentation for every function any Computronics block provides
5+
* CHANGED: Made Camera, Chat Box and Tape Drive functions more consistent in behaviour (The ComputerCraft and OpenComputers functions should do the exact same now)
46

57
==== 1.4.6 ====
68

‎src/main/java/pl/asie/computronics/integration/betterstorage/DriverCrateStorageNew.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ManagedEnvironmentCrate(ICrateStorage tile, String name) {
1919
super(tile, name);
2020
}
2121

22-
@Callback()
22+
@Callback(doc = "function():table; Returns a table of the crate's contents")
2323
public Object[] getContents(Context c, Arguments a) {
2424
List<ItemStack> l = new ArrayList<ItemStack>();
2525
for(ItemStack is : tile.getContents()) {
@@ -28,7 +28,7 @@ public Object[] getContents(Context c, Arguments a) {
2828
return new Object[] { l.toArray(new ItemStack[l.size()]) };
2929
}
3030

31-
@Callback(direct = true)
31+
@Callback(doc = "function():number; Returns the number of slots in the crate", direct = true)
3232
public Object[] getCapacity(Context c, Arguments a) {
3333
return new Object[] { tile.getCapacity() };
3434
}

‎src/main/java/pl/asie/computronics/integration/betterstorage/DriverCrateStorageOld.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ManagedEnvironmentCrate(ICrateStorage tile, String name) {
1919
super(tile, name);
2020
}
2121

22-
@Callback()
22+
@Callback(doc = "function():table; Returns a table of the crate's contents")
2323
public Object[] getContents(Context c, Arguments a) {
2424
List<ItemStack> l = tile.getContents(ForgeDirection.UNKNOWN);
2525
return new Object[] { l.toArray(new ItemStack[l.size()]) };

‎src/main/java/pl/asie/computronics/integration/factorization/DriverChargeConductor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public InternalManagedEnvironment(IChargeConductor tile) {
3131
super(tile, Names.FZ_ChargeConductor);
3232
}
3333

34-
@Callback(direct = true)
34+
@Callback(doc = "function():number; Returns the charge of the block", direct = true)
3535
public Object[] getCharge(Context c, Arguments a) {
3636
return DriverChargeConductor.getCharge(tile);
3737
}

‎src/main/java/pl/asie/computronics/integration/fsp/DriverSteamTransporter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ public InternalManagedEnvironment(ISteamTransporter tile) {
2323
super(tile, Names.FSP_SteamTransporter);
2424
}
2525

26-
@Callback(direct = true)
26+
@Callback(doc = "function():number; Returns the steam pressure of the block", direct = true)
2727
public Object[] getSteamPressure(Context c, Arguments a) {
2828
return new Object[] { tile.getPressure() };
2929
}
3030

31-
@Callback(direct = true)
31+
@Callback(doc = "function():number; Returns the steam capacity of the block", direct = true)
3232
public Object[] getSteamCapacity(Context c, Arguments a) {
3333
return new Object[] { tile.getCapacity() };
3434
}
3535

36-
@Callback(direct = true)
36+
@Callback(doc = "function():number; Returns the steam amount in the block", direct = true)
3737
public Object[] getSteamAmount(Context c, Arguments a) {
3838
return new Object[] { tile.getSteam() };
3939
}

‎src/main/java/pl/asie/computronics/integration/gregtech/DriverBaseMetaTileEntity.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@ public ManagedEnvironmentMachine(BaseMetaTileEntity tile, String name) {
1919
super(tile, name);
2020
}
2121

22-
@Callback(direct = true)
22+
@Callback(doc = "function():number; Returns the EU stored in this block", direct = true)
2323
public Object[] getEUStored(Context c, Arguments a) {
2424
return new Object[] { tile.getStoredEU() };
2525
}
2626

27-
@Callback(direct = true)
27+
@Callback(doc = "function():number; Returns the steam stored in this block", direct = true)
2828
public Object[] getSteamStored(Context c, Arguments a) {
2929
return new Object[] { tile.getStoredSteam() };
3030
}
3131

32-
@Callback(direct = true)
32+
@Callback(doc = "function():number; Returns the max EU that can be stored in this block", direct = true)
3333
public Object[] getEUMaxStored(Context c, Arguments a) {
3434
return new Object[] { tile.getEUCapacity() };
3535
}
3636

37-
@Callback(direct = true)
37+
@Callback(doc = "function():number; Returns the max steam that can be stored in this block", direct = true)
3838
public Object[] getSteamMaxStored(Context c, Arguments a) {
3939
return new Object[] { tile.getSteamCapacity() };
4040
}
4141

42-
@Callback(direct = true)
42+
@Callback(doc = "function():number; Returns the average EU input of this block", direct = true)
4343
public Object[] getEUInputAverage(Context c, Arguments a) {
4444
return new Object[] { tile.getAverageElectricInput() };
4545
}
4646

47-
@Callback(direct = true)
47+
@Callback(doc = "function():number; Returns the average EU output of this block", direct = true)
4848
public Object[] getEUOutputAverage(Context c, Arguments a) {
4949
return new Object[] { tile.getAverageElectricOutput() };
5050
}
5151

52-
@Callback(direct = true)
52+
@Callback(doc = "function():string; Returns the name of this block's owner", direct = true)
5353
public Object[] getOwnerName(Context c, Arguments a) {
5454
return new Object[] { tile.getOwnerName() };
5555
}

‎src/main/java/pl/asie/computronics/integration/gregtech/DriverDeviceInformation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ManagedEnvironmentInfo(IGregTechDeviceInformation tile,
1717
super(tile, name);
1818
}
1919

20-
@Callback(direct = true)
20+
@Callback(doc = "function():table; Returns sensor information about this block", direct = true)
2121
public Object[] getSensorInformation(Context c, Arguments a) {
2222
return new Object[] { tile.getInfoData() };
2323
}

‎src/main/java/pl/asie/computronics/integration/gregtech/DriverDigitalChest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public ManagedEnvironmentDC(IDigitalChest tile, String name) {
1616
super(tile, name);
1717
}
1818

19-
@Callback(direct = true)
19+
@Callback(doc = "function():table; Returns a table of items stored in this block", direct = true)
2020
public Object[] getContents(Context c, Arguments a) {
2121
return new Object[] { tile.getStoredItemData() };
2222
}

‎src/main/java/pl/asie/computronics/integration/gregtech/DriverMachine.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ public int priority() {
2020
return 1;
2121
}
2222

23-
@Callback(direct = true)
23+
@Callback(doc = "function():boolean; Returns true if the machine currently has work to do", direct = true)
2424
public Object[] hasWork(Context c, Arguments a) {
2525
return new Object[] { tile.hasThingsToDo() };
2626
}
2727

28-
@Callback(direct = true)
28+
@Callback(doc = "function():number; Returns the current progress of this block", direct = true)
2929
public Object[] getWorkProgress(Context c, Arguments a) {
3030
return new Object[] { tile.getProgress() };
3131
}
3232

33-
@Callback(direct = true)
33+
@Callback(doc = "function():number; Returns the max progress of this block", direct = true)
3434
public Object[] getWorkMaxProgress(Context c, Arguments a) {
3535
return new Object[] { tile.getMaxProgress() };
3636
}
3737

38-
@Callback(direct = true)
38+
@Callback(doc = "function():boolean; Returns whether this block is currently allowed to work", direct = true)
3939
public Object[] isWorkAllowed(Context c, Arguments a) {
4040
return new Object[] { tile.isAllowedToWork() };
4141
}
4242

43-
@Callback(direct = true)
43+
@Callback(doc = "function(work:boolean); Sets whether this block is currently allowed to work", direct = true)
4444
public Object[] setWorkAllowed(Context c, Arguments a) {
4545
if(a.count() == 1 && a.isBoolean(0)) {
4646
if(a.checkBoolean(0)) {
@@ -52,7 +52,7 @@ public Object[] setWorkAllowed(Context c, Arguments a) {
5252
return null;
5353
}
5454

55-
@Callback(direct = true)
55+
@Callback(doc = "function():boolean; Returns whether the machine is currently active", direct = true)
5656
public Object[] isMachineActive(Context c, Arguments a) {
5757
return new Object[] { tile.isActive() };
5858
}

‎src/main/java/pl/asie/computronics/integration/redlogic/DriverLamp.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ public InternalManagedEnvironment(ILampBlock block, IBlockAccess w, int x, int y
3434
this.setNode(Network.newNode(this, Visibility.Network).withComponent(Names.RedLogic_Lamp, Visibility.Network).create());
3535
}
3636

37-
@Callback(direct = true)
37+
@Callback(doc = "function():string; Returns the type of this lamp", direct = true)
3838
public Object[] getLampType(Context c, Arguments a) {
3939
return new Object[] { block.getType().name() };
4040
}
4141

42-
@Callback(direct = true)
42+
@Callback(doc = "function():number; Returns the color of this lamp", direct = true)
4343
public Object[] getLampColor(Context c, Arguments a) {
4444
return new Object[] { block.getColourRGB(w, x, y, z) };
4545
}
4646

47-
@Callback(direct = true)
47+
@Callback(doc = "function():boolean; Returns whether this lamp is powered", direct = true)
4848
public Object[] isLampPowered(Context c, Arguments a) {
4949
return new Object[] { block.isPowered() };
5050
}

‎src/main/java/pl/asie/computronics/oc/DriverCardFX.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@ public DriverCardFX(EnvironmentHost container) {
2929
// name, the position relative to the block the card is in to spawn
3030
// the particle at, as well as - optionally - the initial velocity.
3131

32-
@Callback(direct = true, limit = 16)
32+
@Callback(doc = "function(name:string, xCoord:number, yCoord:number, zCoord:number [, defaultVelo:number]):boolean;"
33+
+ "function(name:string, xCoord:number, yCoord:number, zCoord:number [, xVelo:number, yVelo:number, zVelo:number]):boolean;"
34+
+ "Spawns a particle effect at the specified relative coordinates optionally with the specified velocity", direct = true, limit = 16)
3335
public Object[] spawn(Context context, Arguments args) {
3436
String name = args.checkString(0);
3537

3638
if(name.length() > Short.MAX_VALUE) {
3739
return new Object[] { false, "name too long" };
3840
}
41+
double xOffset = args.checkDouble(1);
42+
double yOffset = args.checkDouble(2);
43+
double zOffset = args.checkDouble(3);
3944
if(((Connector) this.node()).tryChangeBuffer(0 - Config.FX_ENERGY_COST)) {
4045
Random rng = container.world().rand;
41-
double x = container.xPosition() + 0.5 + args.checkDouble(1);
42-
double y = container.yPosition() + 0.5 + args.checkDouble(2);
43-
double z = container.zPosition() + 0.5 + args.checkDouble(3);
46+
double x = container.xPosition() + 0.5 + xOffset;
47+
double y = container.yPosition() + 0.5 + yOffset;
48+
double z = container.zPosition() + 0.5 + zOffset;
4449
double defaultv = (rng.nextDouble() * 0.1);
4550
if(args.count() >= 5) {
4651
defaultv = args.checkDouble(4);

‎src/main/java/pl/asie/computronics/oc/RobotUpgradeCamera.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ private int getFacingDirection() {
2828
return l;
2929
}
3030

31-
@Callback(direct = true, limit = CALL_LIMIT)
31+
@Callback(doc = "function([x:number, y:number]):number;"
32+
+ "Returns the distance to the block the ray is shot at with the specified x-y offset,"
33+
+ "or of the block directly in front", direct = true, limit = CALL_LIMIT)
3234
public Object[] distance(Context context, Arguments args) {
3335
float x = 0.0f;
3436
float y = 0.0f;
@@ -41,7 +43,9 @@ public Object[] distance(Context context, Arguments args) {
4143
return new Object[]{camera.getDistance()};
4244
}
4345

44-
@Callback(direct = true, limit = CALL_LIMIT)
46+
@Callback(doc = "function([x:number, y:number]):number;"
47+
+ "Returns the distance to the block the ray is shot at with the specified x-y offset facing upwards,"
48+
+ "or of the block directly above", direct = true, limit = CALL_LIMIT)
4549
public Object[] distanceUp(Context context, Arguments args) {
4650
float x = 0.0f;
4751
float y = 0.0f;
@@ -54,7 +58,9 @@ public Object[] distanceUp(Context context, Arguments args) {
5458
return new Object[]{camera.getDistance()};
5559
}
5660

57-
@Callback(direct = true, limit = CALL_LIMIT)
61+
@Callback(doc = "function([x:number, y:number]):number;"
62+
+ "Returns the distance to the block the ray is shot at with the specified x-y offset facing downwards,"
63+
+ "or of the block directly below", direct = true, limit = CALL_LIMIT)
5864
public Object[] distanceDown(Context context, Arguments args) {
5965
float x = 0.0f;
6066
float y = 0.0f;

‎src/main/java/pl/asie/computronics/oc/RobotUpgradeChatBox.java

+10-19
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,34 @@ public void setDistance(int dist) {
6161

6262

6363

64-
@Callback(direct = true)
64+
@Callback(doc = "function():number; Returns the chat distance the chat box is currently set to", direct = true)
6565
@Optional.Method(modid= Mods.OpenComputers)
6666
public Object[] getDistance(Context context, Arguments args) {
6767
return new Object[]{ distance };
6868
}
6969

70-
@Callback(direct = true)
70+
@Callback(doc = "function(distance:number):number; Sets the distance of the chat box. Returns the new distance", direct = true)
7171
@Optional.Method(modid=Mods.OpenComputers)
7272
public Object[] setDistance(Context context, Arguments args) {
73-
if(args.count() == 1) {
74-
if(args.isInteger(0)) {
75-
setDistance(args.checkInteger(0));
76-
return new Object[]{ true };
77-
}
78-
}
79-
return new Object[] { false };
73+
setDistance(args.checkInteger(0));
74+
return new Object[]{ distance };
8075
}
8176

82-
@Callback(direct = true)
77+
@Callback(doc = "function():string; Returns the name of the chat box", direct = true)
8378
@Optional.Method(modid=Mods.OpenComputers)
8479
public Object[] getName(Context context, Arguments args) {
8580
return new Object[]{name};
8681
}
8782

88-
@Callback(direct = true)
83+
@Callback(doc = "function(name:string):string; Sets the name of the chat box. Returns the new name", direct = true)
8984
@Optional.Method(modid=Mods.OpenComputers)
9085
public Object[] setName(Context context, Arguments args) {
91-
if(args.count() == 1) {
92-
if(args.isString(0)){
93-
this.name = args.checkString(0);
94-
return new Object[]{ true };
95-
}
96-
}
97-
return new Object[]{ false };
86+
this.name = args.checkString(0);
87+
return new Object[]{ this.name };
9888
}
9989

100-
@Callback(direct = true, limit = 3)
90+
@Callback(doc = "function(text:string [, distance:number]):boolean;"
91+
+ "Makes the robot say some text with the currently set or the specified distance. Returns true on success", direct = true, limit = 3)
10192
public Object[] say(Context context, Arguments args) {
10293
if(args.count() >= 1) {
10394
//String prefix = robot.player().getDisplayName();

‎src/main/java/pl/asie/computronics/oc/RobotUpgradeRadar.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private AxisAlignedBB getBounds(int d) {
4646
expand(distance, distance, distance);
4747
}
4848

49-
@Callback(direct = true, limit = CALL_LIMIT)
49+
@Callback(doc = "function([distance:number]):table; Returns a list of all entities detected within the specified or the maximum range", direct = true, limit = CALL_LIMIT)
5050
public Object[] getEntities(Context context, Arguments args) {
5151
List<Map> entities = new ArrayList<Map>();
5252
int distance = getDistance(args);
@@ -65,7 +65,7 @@ public Object[] getEntities(Context context, Arguments args) {
6565
return new Object[] { entities.toArray() };
6666
}
6767

68-
@Callback(direct = true, limit = CALL_LIMIT)
68+
@Callback(doc = "function([distance:number]):table; Returns a list of all players detected within the specified or the maximum range", direct = true, limit = CALL_LIMIT)
6969
public Object[] getPlayers(Context context, Arguments args) {
7070
List<Map> entities = new ArrayList<Map>();
7171
int distance = getDistance(args);
@@ -77,7 +77,7 @@ public Object[] getPlayers(Context context, Arguments args) {
7777
return new Object[] { entities.toArray() };
7878
}
7979

80-
@Callback(direct = true, limit = CALL_LIMIT)
80+
@Callback(doc = "function([distance:number]):table; Returns a list of all mobs detected within the specified or the maximum range", direct = true, limit = CALL_LIMIT)
8181
public Object[] getMobs(Context context, Arguments args) {
8282
List<Map> entities = new ArrayList<Map>();
8383
int distance = getDistance(args);
@@ -89,7 +89,7 @@ public Object[] getMobs(Context context, Arguments args) {
8989
return new Object[] { entities.toArray() };
9090
}
9191

92-
@Callback(direct = true, limit = CALL_LIMIT)
92+
@Callback(doc = "function([distance:number]):table; Returns a list of all items detected within the specified or the maximum range", direct = true, limit = CALL_LIMIT)
9393
public Object[] getItems(Context context, Arguments args) {
9494
List<Map> entities = new ArrayList<Map>();
9595
int distance = getDistance(args);

‎src/main/java/pl/asie/computronics/tile/TileCamera.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ public void updateEntity() {
4848
}
4949

5050
// OpenComputers
51-
@Callback(direct = true, limit = CALL_LIMIT)
51+
@Callback(doc = "function([x:number, y:number]):number; "
52+
+ "Returns the distance to the block the ray is shot at with the specified x-y offset, "
53+
+ "or of the block directly in front", direct = true, limit = CALL_LIMIT)
5254
@Optional.Method(modid= Mods.OpenComputers)
5355
public Object[] distance(Context context, Arguments args) {
56+
float x = 0.0f;
57+
float y = 0.0f;
5458
if(args.count() == 2) {
55-
camera.ray(worldObj, xCoord, yCoord, zCoord, getFacingDirection(),
56-
(float)args.checkDouble(0), (float)args.checkDouble(1));
59+
x = (float)args.checkDouble(0);
60+
y = (float)args.checkDouble(1);
5761
}
62+
camera.ray(worldObj, xCoord, yCoord, zCoord, getFacingDirection(), x, y);
5863
return new Object[]{camera.getDistance()};
5964
}
6065

@@ -70,15 +75,18 @@ public Object[] callMethod(IComputerAccess computer, ILuaContext context,
7075
int method, Object[] arguments) throws LuaException,
7176
InterruptedException {
7277
if(camera == null) return null;
73-
Object[] rayDir = null;
74-
if(arguments.length == 2 && arguments[0] instanceof Double && arguments[1] instanceof Double) {
75-
rayDir = new Object[]{
76-
camera.ray(worldObj, xCoord, yCoord, zCoord, getFacingDirection(),
77-
((Double)arguments[0]).floatValue(), ((Double)arguments[1]).floatValue())
78-
};
79-
}
78+
//Object[] rayDir = null;
8079
switch(method) {
8180
case 0: { // distance
81+
float x = 0.0f;
82+
float y = 0.0f;
83+
if(arguments.length == 2 && arguments[0] instanceof Double && arguments[1] instanceof Double) {
84+
//rayDir = new Object[]{
85+
x = ((Double)arguments[0]).floatValue();
86+
y = ((Double)arguments[1]).floatValue();
87+
//};
88+
}
89+
camera.ray(worldObj, xCoord, yCoord, zCoord, getFacingDirection(), x, y);
8290
return new Object[]{ camera.getDistance() };
8391
}
8492
}

‎src/main/java/pl/asie/computronics/tile/TileChatBox.java

+14-23
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public void eventCC(ServerChatEvent event) {
120120

121121
// OpenComputers API
122122

123-
@Callback
123+
@Callback(doc = "function(text:string [, distance:number]):boolean;"
124+
+ "Makes the chat box say some text with the currently set or the specified distance. Returns true on success")
124125
@Optional.Method(modid = Mods.OpenComputers)
125126
public Object[] say(Context context, Arguments args) {
126127
int d = distance;
@@ -139,40 +140,30 @@ public Object[] say(Context context, Arguments args) {
139140
return new Object[] { false };
140141
}
141142

142-
@Callback(direct = true)
143+
@Callback(doc = "function():number; Returns the chat distance the chat box is currently set to", direct = true)
143144
@Optional.Method(modid = Mods.OpenComputers)
144145
public Object[] getDistance(Context context, Arguments args) {
145146
return new Object[] { distance };
146147
}
147148

148-
@Callback(direct = true)
149+
@Callback(doc = "function(distance:number):number; Sets the distance of the chat box. Returns the new distance", direct = true)
149150
@Optional.Method(modid = Mods.OpenComputers)
150151
public Object[] setDistance(Context context, Arguments args) {
151-
if(args.count() == 1) {
152-
if(args.isInteger(0)) {
153-
setDistance(args.checkInteger(0));
154-
return new Object[] { true };
155-
}
156-
}
157-
return new Object[] { false };
152+
setDistance(args.checkInteger(0));
153+
return new Object[] { distance };
158154
}
159155

160-
@Callback(direct = true)
156+
@Callback(doc = "function():string; Returns the name of the chat box", direct = true)
161157
@Optional.Method(modid = Mods.OpenComputers)
162158
public Object[] getName(Context context, Arguments args) {
163159
return new Object[] { name };
164160
}
165161

166-
@Callback(direct = true)
162+
@Callback(doc = "function(name:string):string; Sets the name of the chat box. Returns the new name", direct = true)
167163
@Optional.Method(modid = Mods.OpenComputers)
168164
public Object[] setName(Context context, Arguments args) {
169-
if(args.count() == 1) {
170-
if(args.isString(0)) {
171-
this.name = args.checkString(0);
172-
return new Object[] { true };
173-
}
174-
}
175-
return new Object[] { false };
165+
this.name = args.checkString(0);
166+
return new Object[] { this.name };
176167
}
177168

178169
@Override
@@ -227,19 +218,19 @@ public Object[] callMethod(IComputerAccess computer, ILuaContext context,
227218
case 2: { // setDistance
228219
if(arguments.length == 1 && arguments[0] instanceof Double) {
229220
setDistance(((Double) arguments[0]).intValue());
230-
return new Object[] { true };
221+
return new Object[] { distance };
231222
}
232-
return new Object[] { false };
223+
throw new LuaException("first argument needs to be a number");
233224
}
234225
case 3: { // getName
235226
return new Object[] { name };
236227
}
237228
case 4: { // setName
238229
if(arguments.length == 1 && arguments[0] instanceof String) {
239230
this.name = (String) arguments[0];
240-
return new Object[] { true };
231+
return new Object[] { this.name };
241232
}
242-
return new Object[] { false };
233+
throw new LuaException("first argument needs to be a string");
243234
}
244235
}
245236
return null;

‎src/main/java/pl/asie/computronics/tile/TileCipherBlock.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public String decrypt(String data) throws Exception {
9696
return new String(cipher.doFinal(Base64.decode(data)), "UTF8");
9797
}
9898

99-
@Callback(direct = true)
99+
@Callback(doc = "function(message:string):string; Encrypts the specified message", direct = true)
100100
@Optional.Method(modid=Mods.OpenComputers)
101101
public Object[] encrypt(Context context, Arguments args) throws Exception {
102102
if(args.count() >= 1) {
@@ -108,7 +108,7 @@ else if(args.isString(0))
108108
return null;
109109
}
110110

111-
@Callback(direct = true)
111+
@Callback(doc = "function(message:string):string; Decrypts the specified message", direct = true)
112112
@Optional.Method(modid=Mods.OpenComputers)
113113
public Object[] decrypt(Context context, Arguments args) throws Exception {
114114
if(args.count() >= 1 && args.isString(0)) {
@@ -117,13 +117,13 @@ public Object[] decrypt(Context context, Arguments args) throws Exception {
117117
return null;
118118
}
119119

120-
@Callback(direct = true)
120+
@Callback(doc = "function():boolean; Returns whether the block is currently locked", direct = true)
121121
@Optional.Method(modid=Mods.OpenComputers)
122122
public Object[] isLocked(Context context, Arguments args) throws Exception {
123123
return new Object[]{isLocked};
124124
}
125125

126-
@Callback()
126+
@Callback(doc = "function(locked:boolean); Sets whether the block is currently locked")
127127
@Optional.Method(modid=Mods.OpenComputers)
128128
public Object[] setLocked(Context context, Arguments args) throws Exception {
129129
if(args.count() == 1 && args.isBoolean(0))

‎src/main/java/pl/asie/computronics/tile/TileEEPROMReader.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ public void setData(byte[] data) {
5555
is.getTagCompound().setByteArray("ram", data);
5656
}
5757

58-
@Callback(direct = true)
58+
@Callback(doc = "function():boolean; Returns whether the reader has a valid EEPROM in it",direct = true)
5959
@Optional.Method(modid=Mods.OpenComputers)
6060
public Object[] isReady(Context context, Arguments args) {
6161
return new Object[]{ isReady() };
6262
}
6363

64-
@Callback(direct = true)
64+
@Callback(doc = "function():number; Returns the size of the data on the current EEPROM", direct = true)
6565
@Optional.Method(modid=Mods.OpenComputers)
6666
public Object[] getSize(Context context, Arguments args) {
6767
return new Object[]{ getSize() };
6868
}
6969

70-
@Callback(direct = true)
70+
@Callback(doc = "function(pos:number [, length:number]):number or string; Reads the piece of data at the specified position, with optionally the specified length", direct = true)
7171
@Optional.Method(modid=Mods.OpenComputers)
7272
public Object[] read(Context context, Arguments args) {
7373
byte[] data = getData();
@@ -84,7 +84,7 @@ public Object[] read(Context context, Arguments args) {
8484
} else return null;
8585
}
8686

87-
@Callback(direct = true)
87+
@Callback(doc = "function(pos:number, data:number or string):boolean;Writes the specified data to the specified position. Returns true on success", direct = true)
8888
@Optional.Method(modid=Mods.OpenComputers)
8989
public Object[] write(Context context, Arguments args) {
9090
byte[] data = getData();

‎src/main/java/pl/asie/computronics/tile/TileRadar.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public boolean extractFromBattery(double amount) {
6363
return true;
6464
}
6565

66-
@Callback
66+
@Callback(doc = "function([distance:number]):table; Returns a list of all entities detected within the specified or the maximum range")
6767
@Optional.Method(modid = Mods.OpenComputers)
6868
public Object[] getEntities(Context context, Arguments args) {
6969
Set<Map> entities = new HashSet<Map>();
@@ -85,7 +85,7 @@ public Object[] getEntities(Context context, Arguments args) {
8585
return new Object[] { RadarUtils.convertSetToMap(entities) };
8686
}
8787

88-
@Callback
88+
@Callback(doc = "function([distance:number]):table; Returns a list of all players detected within the specified or the maximum range")
8989
@Optional.Method(modid = Mods.OpenComputers)
9090
public Object[] getPlayers(Context context, Arguments args) {
9191
Set<Map> entities = new HashSet<Map>();
@@ -100,7 +100,7 @@ public Object[] getPlayers(Context context, Arguments args) {
100100
return new Object[] { RadarUtils.convertSetToMap(entities) };
101101
}
102102

103-
@Callback
103+
@Callback(doc = "function([distance:number]):table; Returns a list of all mobs detected within the specified or the maximum range")
104104
@Optional.Method(modid = Mods.OpenComputers)
105105
public Object[] getMobs(Context context, Arguments args) {
106106
Set<Map> entities = new HashSet<Map>();
@@ -115,7 +115,7 @@ public Object[] getMobs(Context context, Arguments args) {
115115
return new Object[] { RadarUtils.convertSetToMap(entities) };
116116
}
117117

118-
@Callback
118+
@Callback(doc = "function([distance:number]):table; Returns a list of all items detected within the specified or the maximum range")
119119
@Optional.Method(modid = Mods.OpenComputers)
120120
public Object[] getItems(Context context, Arguments args) {
121121
Set<Map> entities = new HashSet<Map>();

‎src/main/java/pl/asie/computronics/tile/TileTapeDrive.java

+23-25
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public void readFromRemoteNBT(NBTTagCompound tag) {
292292

293293
// OpenComputers
294294

295-
@Callback(direct = true)
295+
@Callback(doc = "function():boolean; Returns true if the tape drive is empty or the inserted tape has reached its end", direct = true)
296296
@Optional.Method(modid = Mods.OpenComputers)
297297
public Object[] isEnd(Context context, Arguments args) {
298298
if(state.getStorage() != null) {
@@ -302,45 +302,49 @@ public Object[] isEnd(Context context, Arguments args) {
302302
}
303303
}
304304

305-
@Callback(direct = true)
305+
@Callback(doc = "function():boolean; Returns true if there is a tape inserted", direct = true)
306306
@Optional.Method(modid = Mods.OpenComputers)
307307
public Object[] isReady(Context context, Arguments args) {
308308
return new Object[] { state.getStorage() != null };
309309
}
310310

311-
@Callback(direct = true)
311+
@Callback(doc = "function():number; Returns the size of the tape, in bytes", direct = true)
312312
@Optional.Method(modid = Mods.OpenComputers)
313313
public Object[] getSize(Context context, Arguments args) {
314314
return new Object[] { (state.getStorage() != null ? state.getStorage().getSize() : 0) };
315315
}
316316

317-
@Callback
317+
@Callback(doc = "function(label:string):string; Sets the label of the tape. "
318+
+ "Returns the new label, or nil if there is no tape inserted")
318319
@Optional.Method(modid = Mods.OpenComputers)
319320
public Object[] setLabel(Context context, Arguments args) {
320321
if(args.count() == 1) {
321322
if(args.isString(0)) {
322323
setLabel(args.checkString(0));
323324
}
324325
}
325-
return new Object[] { (state.getStorage() != null ? storageName : "") };
326+
return new Object[] { (state.getStorage() != null ? storageName : null) };
326327
}
327328

328-
@Callback
329+
@Callback(doc = "function():string; Returns the current label of the tape, or nil if there is no tape inserted")
329330
@Optional.Method(modid = Mods.OpenComputers)
330331
public Object[] getLabel(Context context, Arguments args) {
331-
return new Object[] { (state.getStorage() != null ? storageName : "") };
332+
return new Object[] { (state.getStorage() != null ? storageName : null) };
332333
}
333334

334-
@Callback
335+
@Callback(doc = "function(length:number):number; Seeks the specified amount of bytes on the tape. "
336+
+ "Negative values for rewinding. Returns the amount of bytes sought, or nil if there is no tape inserted")
335337
@Optional.Method(modid = Mods.OpenComputers)
336338
public Object[] seek(Context context, Arguments args) {
337-
if(state.getStorage() != null && args.count() >= 1 && args.isInteger(0)) {
339+
if(state.getStorage() != null) {
338340
return new Object[] { state.getStorage().seek(args.checkInteger(0)) };
339341
}
340342
return null;
341343
}
342344

343-
@Callback
345+
@Callback(doc = "function([length:number]):string; "
346+
+ "Reads and returns the specified amount of bytes or a single byte from the tape. "
347+
+ "Returns nil if there is no tape inserted")
344348
@Optional.Method(modid = Mods.OpenComputers)
345349
public Object[] read(Context context, Arguments args) {
346350
if(state.getStorage() != null) {
@@ -356,7 +360,7 @@ public Object[] read(Context context, Arguments args) {
356360
}
357361
}
358362

359-
@Callback
363+
@Callback(doc = "function(data:number or string); Writes the specified data to the tape if there is one inserted")
360364
@Optional.Method(modid = Mods.OpenComputers)
361365
public Object[] write(Context context, Arguments args) {
362366
if(state.getStorage() != null && args.count() >= 1) {
@@ -369,40 +373,34 @@ public Object[] write(Context context, Arguments args) {
369373
return null;
370374
}
371375

372-
@Callback
376+
@Callback(doc = "function():boolean; Make the Tape Drive start playing the tape. Returns true on success")
373377
@Optional.Method(modid = Mods.OpenComputers)
374378
public Object[] play(Context context, Arguments args) {
375379
switchState(State.PLAYING);
376-
return new Object[] { state.getStorage() != null };
380+
return new Object[] { state.getStorage() != null && this.getEnumState() == State.PLAYING };
377381
}
378382

379-
@Callback
383+
@Callback(doc = "function():boolean; Make the Tape Drive stop playing the tape. Returns true on success")
380384
@Optional.Method(modid = Mods.OpenComputers)
381385
public Object[] stop(Context context, Arguments args) {
382386
switchState(State.STOPPED);
383387
return new Object[] { state.getStorage() != null };
384388
}
385389

386-
@Callback
390+
@Callback(doc = "function(speed:number):boolean; Sets the speed of the tape drive. Needs to be beween 0.25 and 2. Returns true on success")
387391
@Optional.Method(modid = Mods.OpenComputers)
388392
public Object[] setSpeed(Context context, Arguments args) {
389-
if(args.count() > 0 && args.isDouble(0)) {
390-
return new Object[] { this.state.setSpeed((float) args.checkDouble(0)) };
391-
} else {
392-
return null;
393-
}
393+
return new Object[] { this.state.setSpeed((float) args.checkDouble(0)) };
394394
}
395395

396-
@Callback
396+
@Callback(doc = "function(speed:number); Sets the volume of the tape drive. Needs to be beween 0 and 1")
397397
@Optional.Method(modid = Mods.OpenComputers)
398398
public Object[] setVolume(Context context, Arguments args) {
399-
if(args.count() > 0 && args.isDouble(0)) {
400-
this.state.setVolume((float) args.checkDouble(0));
401-
}
399+
this.state.setVolume((float) args.checkDouble(0));
402400
return null;
403401
}
404402

405-
@Callback
403+
@Callback(doc = "function():string; Returns the current state of the tape drive", direct = true)
406404
@Optional.Method(modid = Mods.OpenComputers)
407405
public Object[] getState(Context context, Arguments args) {
408406
return new Object[] { state.getState().toString() };

0 commit comments

Comments
 (0)
Please sign in to comment.