added GeoScanner peripheral
This commit is contained in:
parent
e527dd5b6a
commit
2799a0be3d
76
src/kernel/peripherals/GeoScanner.hx
Normal file
76
src/kernel/peripherals/GeoScanner.hx
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
import lib.BlockPos;
|
||||||
|
import lib.Tags;
|
||||||
|
import cc.Peripheral;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
using lua.Table;
|
||||||
|
|
||||||
|
@:structInit typedef ScanBlock = {
|
||||||
|
name:String,
|
||||||
|
tags:Tags,
|
||||||
|
pos:BlockPos
|
||||||
|
}
|
||||||
|
|
||||||
|
class GeoScanner implements IPeripheral {
|
||||||
|
public static inline final TYPE_NAME:String = "geoScanner";
|
||||||
|
|
||||||
|
private final addr:String;
|
||||||
|
|
||||||
|
public function new(addr:String) {
|
||||||
|
this.addr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddr():String {
|
||||||
|
return this.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType():String {
|
||||||
|
return TYPE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the current time remaining until then next scan() can be ran.
|
||||||
|
**/
|
||||||
|
public function getScanCooldown():Int {
|
||||||
|
return Peripheral.call(this.addr, "getScanCooldown");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the cost in FE for a scan with the given radius.
|
||||||
|
Returns null of scan of this radius is not posible.
|
||||||
|
**/
|
||||||
|
public function cost(radius:Int):Null<Int> {
|
||||||
|
return Peripheral.call(this.addr, "cost", radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a list of data about all blocks in the radius.
|
||||||
|
X,Y,Z are relative to the geoscanner block.
|
||||||
|
Air blocks are not included.
|
||||||
|
List is unsorted.
|
||||||
|
**/
|
||||||
|
public function scan(radius:Int):Outcome<Array<ScanBlock>, String> {
|
||||||
|
// TODO: Handel fail state
|
||||||
|
var result:lua.Table<Int, {
|
||||||
|
x:Int,
|
||||||
|
y:Int,
|
||||||
|
z:Int,
|
||||||
|
name:String,
|
||||||
|
tags:lua.Table<Int, String>
|
||||||
|
}> = Peripheral.call(this.addr, "scan", radius);
|
||||||
|
|
||||||
|
return Success(result.toArray().map((e) -> {
|
||||||
|
name: e.name,
|
||||||
|
tags: Tags.fromIntTable(e.tags),
|
||||||
|
pos: new BlockPos(e.x, e.y, e.z)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function chunkAnalyze():Outcome<Map<String, Int>, String> {
|
||||||
|
var result:lua.Table<String, Int> = Peripheral.call(this.addr, "chunkAnalyze");
|
||||||
|
|
||||||
|
return Success(result.toMap());
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
import kernel.log.Log;
|
|
||||||
import kernel.peripherals.Modem;
|
import kernel.peripherals.Modem;
|
||||||
import kernel.peripherals.Screen;
|
import kernel.peripherals.Screen;
|
||||||
|
|
||||||
@ -83,6 +82,8 @@ class Peripheral {
|
|||||||
return getRedstone(addr);
|
return getRedstone(addr);
|
||||||
case Inventory.TYPE_NAME:
|
case Inventory.TYPE_NAME:
|
||||||
return getInventory(addr);
|
return getInventory(addr);
|
||||||
|
case GeoScanner.TYPE_NAME:
|
||||||
|
return getGeoScanner(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -180,4 +181,15 @@ class Peripheral {
|
|||||||
public static function getAllInventorys():Array<Inventory> {
|
public static function getAllInventorys():Array<Inventory> {
|
||||||
return [for (addr in findAddrByType(Inventory.TYPE_NAME)) new Inventory(addr)];
|
return [for (addr in findAddrByType(Inventory.TYPE_NAME)) new Inventory(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getGeoScanner(addr:String):Null<GeoScanner> {
|
||||||
|
var addr = safeGetAddr(addr, GeoScanner.TYPE_NAME);
|
||||||
|
if (addr == null)
|
||||||
|
return null;
|
||||||
|
return new GeoScanner(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAllGeoScanners():Array<GeoScanner> {
|
||||||
|
return [for (addr in findAddrByType(GeoScanner.TYPE_NAME)) new GeoScanner(addr)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user