diff --git a/src/kernel/peripherals/GeoScanner.hx b/src/kernel/peripherals/GeoScanner.hx new file mode 100644 index 0000000..ccc38ee --- /dev/null +++ b/src/kernel/peripherals/GeoScanner.hx @@ -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 { + 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, String> { + // TODO: Handel fail state + var result:lua.Table + }> = 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, String> { + var result:lua.Table = Peripheral.call(this.addr, "chunkAnalyze"); + + return Success(result.toMap()); + } +} diff --git a/src/kernel/peripherals/Peripherals.hx b/src/kernel/peripherals/Peripherals.hx index 65d7643..6a6bffb 100644 --- a/src/kernel/peripherals/Peripherals.hx +++ b/src/kernel/peripherals/Peripherals.hx @@ -1,6 +1,5 @@ package kernel.peripherals; -import kernel.log.Log; import kernel.peripherals.Modem; import kernel.peripherals.Screen; @@ -83,6 +82,8 @@ class Peripheral { return getRedstone(addr); case Inventory.TYPE_NAME: return getInventory(addr); + case GeoScanner.TYPE_NAME: + return getGeoScanner(addr); } return null; @@ -180,4 +181,15 @@ class Peripheral { public static function getAllInventorys():Array { return [for (addr in findAddrByType(Inventory.TYPE_NAME)) new Inventory(addr)]; } + + public static function getGeoScanner(addr:String):Null { + var addr = safeGetAddr(addr, GeoScanner.TYPE_NAME); + if (addr == null) + return null; + return new GeoScanner(addr); + } + + public static function getAllGeoScanners():Array { + return [for (addr in findAddrByType(GeoScanner.TYPE_NAME)) new GeoScanner(addr)]; + } }