|
12 | 12 | ---@alias height integer |
13 | 13 | ---@alias position {x: north, y: east, z: height} |
14 | 14 |
|
15 | | ----@alias item {name: string, durabilty: integer, equipable: boolean, fuelgain: integer, placeAble: boolean, maxcount: number, wildcardInfo: any, count: integer} |
| 15 | +---@alias item {name: string, durabilty: integer, equipable: boolean, fuelgain: integer, placeAble: boolean, maxcount: number, wildcardInfo: any, count: integer, tags: table<string, any> | nil} |
16 | 16 | ---@alias inventory { [integer]: item } |
17 | 17 |
|
18 | 18 | ---@alias left string |
19 | 19 | ---@alias right string |
20 | 20 | ---@alias equipslots {left: item, right: item} |
21 | 21 |
|
| 22 | +---@alias inspectResult {name: string, tags: table<string, any> | nil, state: table<string, any> | nil} | nil |
| 23 | + |
22 | 24 | local defaultInteration = require("../defaultInteraction") |
23 | 25 |
|
24 | 26 | ---@class TurtleMock |
@@ -373,6 +375,38 @@ local function dig(turtle, block) |
373 | 375 | return true, "Cannot beak block with this tool" |
374 | 376 | end |
375 | 377 |
|
| 378 | +---@param block block | nil |
| 379 | +---@return boolean |
| 380 | +local function detect(block) |
| 381 | + return block and true or false |
| 382 | +end |
| 383 | + |
| 384 | +---@param block block | nil |
| 385 | +---@param compareItem item | nil |
| 386 | +---@return boolean |
| 387 | +local function compare(block, compareItem) |
| 388 | + if block == nil and compareItem == nil then |
| 389 | + return true |
| 390 | + end |
| 391 | + if block == nil and compareItem ~= nil then |
| 392 | + return false |
| 393 | + end |
| 394 | + if compareItem == nil and block ~= nil then |
| 395 | + return false |
| 396 | + end |
| 397 | + return block.item.name == compareItem.name |
| 398 | +end |
| 399 | + |
| 400 | +---@param block block | nil |
| 401 | +---@return boolean |
| 402 | +---@return inspectResult |
| 403 | +local function inspect(block) |
| 404 | + if block == nil or block.item == nil or block.item.name == nil then |
| 405 | + return false, nil |
| 406 | + end |
| 407 | + return true, { name = block.item.name, tags = block.item.tags, state = block.state } |
| 408 | +end |
| 409 | + |
376 | 410 | ---@param emulator TurtleEmulator |
377 | 411 | ---@return TurtleProxy |
378 | 412 | function turtleMock.createMock(emulator, id) |
@@ -647,6 +681,54 @@ function turtleMock:digDown() |
647 | 681 | return dig(self, blockPos) |
648 | 682 | end |
649 | 683 |
|
| 684 | +function turtleMock:detect() |
| 685 | + local _, _, blockPos = forward(self, false) |
| 686 | + local block = self.emulator:getBlock(blockPos) |
| 687 | + return detect(block) |
| 688 | +end |
| 689 | + |
| 690 | +function turtleMock:detectUp() |
| 691 | + local block = self.emulator:getBlock({x = self.position.x, y = self.position.y + 1, z = self.position.z}) |
| 692 | + return detect(block) |
| 693 | +end |
| 694 | + |
| 695 | +function turtleMock:detectDown() |
| 696 | + local block = self.emulator:getBlock({x = self.position.x, y = self.position.y - 1, z = self.position.z}) |
| 697 | + return detect(block) |
| 698 | +end |
| 699 | + |
| 700 | +function turtleMock:compare() |
| 701 | + local _, _, blockPos = forward(self, false) |
| 702 | + local block = self.emulator:getBlock(blockPos) |
| 703 | + return compare(block, self.inventory[self.selectedSlot]) |
| 704 | +end |
| 705 | + |
| 706 | +function turtleMock:compareUp() |
| 707 | + local block = self.emulator:getBlock({x = self.position.x, y = self.position.y + 1, z = self.position.z}) |
| 708 | + return compare(block, self.inventory[self.selectedSlot]) |
| 709 | +end |
| 710 | + |
| 711 | +function turtleMock:compareDown() |
| 712 | + local block = self.emulator:getBlock({x = self.position.x, y = self.position.y - 1, z = self.position.z}) |
| 713 | + return compare(block, self.inventory[self.selectedSlot]) |
| 714 | +end |
| 715 | + |
| 716 | +function turtleMock:inspect() |
| 717 | + local _, _, blockPos = forward(self, false) |
| 718 | + local block = self.emulator:getBlock(blockPos) |
| 719 | + return inspect(block) |
| 720 | +end |
| 721 | + |
| 722 | +function turtleMock:inspectUp() |
| 723 | + local block = self.emulator:getBlock({x = self.position.x, y = self.position.y + 1, z = self.position.z}) |
| 724 | + return inspect(block) |
| 725 | +end |
| 726 | + |
| 727 | +function turtleMock:inspectDown() |
| 728 | + local block = self.emulator:getBlock({x = self.position.x, y = self.position.y - 1, z = self.position.z}) |
| 729 | + return inspect(block) |
| 730 | +end |
| 731 | + |
650 | 732 | ---will only print content if canPrint is set to true |
651 | 733 | ---@param ... any |
652 | 734 | ---@return nil |
|
0 commit comments