-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📦 add environment/player detector, geo scanner, inventory manager, an…
…d redstone integrator adapters (closes #64)
- Loading branch information
Showing
10 changed files
with
207 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/telem/lib/input/advancedPeripherals/EnvironmentDetectorInputAdapter.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
local fn = require 'telem.vendor'.fluent.fn | ||
|
||
local base = require 'telem.lib.input.advancedPeripherals.BaseAdvancedPeripheralsInputAdapter' | ||
|
||
local EnvironmentDetectorInputAdapter = base.mintAdapter('EnvironmentDetectorInputAdapter') | ||
|
||
function EnvironmentDetectorInputAdapter:beforeRegister (peripheralName, categories) | ||
self.prefix = 'apenv:' | ||
|
||
self.queries = { | ||
basic = { | ||
block_light_level = fn():call('getBlockLightLevel'), | ||
day_light_level = fn():call('getDayLightLevel'), | ||
sky_light_level = fn():call('getSkyLightLevel'), | ||
moon_id = fn():call('getMoonId'), | ||
time = fn():call('getTime'), | ||
radiation = fn():call('getRadiationRaw'):with('unit', 'Sv/h'), | ||
can_sleep = fn():call('canSleepHere'):toFlag(), | ||
raining = fn():call('isRaining'):toFlag(), | ||
sunny = fn():call('isSunny'):toFlag(), | ||
thundering = fn():call('isThunder'):toFlag(), | ||
slime_chunk = fn():call('isSlimeChunk'):toFlag(), | ||
}, | ||
} | ||
|
||
-- getBiome | ||
-- getDimensionName | ||
-- getDimensionPaN | ||
-- getDimensionProvider | ||
-- getMoonName | ||
-- getOperationCooldown | ||
-- isDimension | ||
-- listDimensions | ||
-- scanCost | ||
-- scanEntities | ||
end | ||
|
||
return EnvironmentDetectorInputAdapter |
24 changes: 24 additions & 0 deletions
24
src/telem/lib/input/advancedPeripherals/GeoScannerInputAdapter.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
local fn = require 'telem.vendor'.fluent.fn | ||
|
||
local base = require 'telem.lib.input.advancedPeripherals.BaseAdvancedPeripheralsInputAdapter' | ||
local Metric = require 'telem.lib.Metric' | ||
|
||
local GeoScannerInputAdapter = base.mintAdapter('GeoScannerInputAdapter') | ||
|
||
function GeoScannerInputAdapter:beforeRegister (peripheralName, categories) | ||
self.prefix = 'apgeo:' | ||
|
||
self.queries = { | ||
basic = {}, | ||
} | ||
|
||
self.storageQueries = { | ||
fn():callElse('chunkAnalyze', {}) | ||
:map(function (k, v) return Metric{ name = k, value = v } end) | ||
:values() | ||
} | ||
|
||
-- scan | ||
end | ||
|
||
return GeoScannerInputAdapter |
33 changes: 33 additions & 0 deletions
33
src/telem/lib/input/advancedPeripherals/InventoryManagerInputAdapter.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local fn = require 'telem.vendor'.fluent.fn | ||
|
||
local base = require 'telem.lib.input.advancedPeripherals.BaseAdvancedPeripheralsInputAdapter' | ||
local Metric = require 'telem.lib.Metric' | ||
|
||
local InventoryManagerInputAdapter = base.mintAdapter('InventoryManagerInputAdapter') | ||
|
||
function InventoryManagerInputAdapter:beforeRegister (peripheralName, categories) | ||
self.prefix = 'apinv:' | ||
|
||
local armor = fn():call('getArmor') | ||
|
||
self.queries = { | ||
basic = { | ||
equipped = fn():call('isPlayerEquipped'):toFlag(), | ||
equipped_helmet = armor:firstWhere('slot', 103):toFlag(), | ||
equipped_chestplate = armor:firstWhere('slot', 102):toFlag(), | ||
equipped_leggings = armor:firstWhere('slot', 101):toFlag(), | ||
equipped_boots = armor:firstWhere('slot', 100):toFlag(), | ||
inventory_available = fn():call('isSpaceAvailable'):toFlag(), | ||
inventory_slots_available = fn():call('getEmptySpace'), | ||
}, | ||
} | ||
|
||
self.storageQueries = { | ||
fn():call('getItems') | ||
:sum('count', 'name') | ||
:map(function (k, v) return Metric{ name = k, value = v, unit = 'item' } end) | ||
:values() | ||
} | ||
end | ||
|
||
return InventoryManagerInputAdapter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/telem/lib/input/advancedPeripherals/PlayerDetectorInputAdapter.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
local fn = require 'telem.vendor'.fluent.fn | ||
|
||
local base = require 'telem.lib.input.advancedPeripherals.BaseAdvancedPeripheralsInputAdapter' | ||
|
||
local PlayerDetectorInputAdapter = base.mintAdapter('PlayerDetectorInputAdapter') | ||
|
||
function PlayerDetectorInputAdapter:beforeRegister (peripheralName, categories, playerName) | ||
self.prefix = 'applayer:' | ||
|
||
self.queries = { | ||
basic = { | ||
online_player_count = fn():call('getOnlinePlayers'):count(), | ||
}, | ||
} | ||
|
||
-- getPlayersInRange | ||
-- getPlayersInCoords | ||
-- getPlayersInCubic | ||
-- isPlayerInRange | ||
-- isPlayerInCoords | ||
-- isPlayerInCubic | ||
-- isPlayersInRange | ||
-- isPlayersInCoords | ||
-- isPlayersInCubic | ||
|
||
-- TODO improve this | ||
if playerName then | ||
local playerPos = fn():call('getPlayerPos', playerName) | ||
|
||
self.queries.player = self.queries.player or {} | ||
|
||
self.queries.player.player_eye_height = playerPos:get('eyeHeight'):with('unit', 'm') | ||
self.queries.player.player_pitch = playerPos:get('pitch'):with('unit', '°') | ||
self.queries.player.player_yaw = playerPos:get('yaw'):with('unit', '°') | ||
self.queries.player.player_health = playerPos:get('health') | ||
self.queries.player.player_air_supply = playerPos:get('airSupply') | ||
|
||
-- TODO there is a typo fix pending release, so for now there will be a fallback to the typo | ||
self.queries.player.player_max_health = playerPos:transform(function (v) | ||
return v.maxHealth or v.maxHeatlh | ||
end) | ||
|
||
-- dimension | ||
-- respawnPosition | ||
-- respawnDimension | ||
-- respawnAngle | ||
-- x | ||
-- y | ||
-- z | ||
end | ||
end | ||
|
||
return PlayerDetectorInputAdapter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/telem/lib/input/advancedPeripherals/RedstoneIntegratorInputAdapter.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
local fl = require 'telem.vendor'.fluent | ||
local fn = fl.fn | ||
|
||
local base = require 'telem.lib.input.advancedPeripherals.BaseAdvancedPeripheralsInputAdapter' | ||
|
||
local RedstoneIntegratorInputAdapter = base.mintAdapter('RedstoneIntegratorInputAdapter') | ||
|
||
function RedstoneIntegratorInputAdapter:beforeRegister (peripheralName, categories, sides) | ||
self.prefix = 'apredstone:' | ||
|
||
self.sides = sides or '*' | ||
|
||
local allRelativeSides = { | ||
'right', 'left', 'front', 'back', 'top', 'bottom', | ||
} | ||
|
||
local allCardinalSides = { | ||
'north', 'south', 'east', 'west', 'up', 'down' | ||
} | ||
|
||
local allSides = fl({allRelativeSides, allCardinalSides}):flatten():result() | ||
|
||
if self.sides == '*' then | ||
self.sides = allRelativeSides | ||
elseif type(self.sides) == 'table' then | ||
self.sides = fl(self.sides):intersect(allSides):result() | ||
else | ||
error('sides must be a list of sides or "*"') | ||
end | ||
|
||
self.queries = { | ||
basic = {} | ||
} | ||
|
||
for _, side in ipairs(self.sides) do | ||
print('doign side', side) | ||
self.queries.basic['input_' .. side] = fn():call('getInput', side):toFlag() | ||
self.queries.basic['input_analog_' .. side] = fn():call('getAnalogInput', side) | ||
|
||
-- TODO is there any reason to include these? | ||
-- self.queries.basic['output_' .. side] = fn():call('getOutput', side):toFlag() | ||
-- self.queries.basic['output_analog_' .. side] = fn():call('getAnalogOutput', side) | ||
end | ||
end | ||
|
||
return RedstoneIntegratorInputAdapter |