From d854a25eaeee7ace06ac091bf34a21ab98bcb5a1 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 14 Jan 2025 21:47:06 +0100 Subject: [PATCH 01/91] RS2 RS Bridge without bridge --- build.gradle | 9 ++- gradle.properties | 1 + .../2f719b8031aed5e605ed8d6694b19245ca45c6ca | 4 +- .../59eb3dbb5f86130e09b3c62d89b9525ee01cf52d | 3 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 4 +- .../b8526e444ae7356037f3a813274f6835d1f3dd16 | 6 +- .../f95c7003282837dabaa33e3ffceec4e6865b5218 | 6 +- .../blockstates/rs_bridge.json | 57 +++++++++++++++++++ .../advancedperipherals/lang/en_us.json | 4 ++ .../models/block/rs_bridge.json | 8 +++ .../recipes/redstone/rs_bridge.json | 38 +++++++++++++ .../loot_table/blocks/rs_bridge.json | 30 ++++++++++ .../advancedperipherals/recipe/rs_bridge.json | 39 +++++++++++++ .../tags/blocks/mineable/pickaxe.json | 1 + .../tags/blocks/needs_iron_tool.json | 1 + .../AdvancedPeripherals.java | 3 + .../common/addons/APAddons.java | 4 +- .../peripheral/RSBridgePeripheral.java | 21 +++++++ .../refinedstorage/RefinedStorageApi.java | 17 ++++++ .../blocks/blockentities/RsBridgeEntity.java | 56 ++++++++++++++++++ .../data/BlockStatesAndModelsProvider.java | 1 + .../common/data/EnUsLanguageProvider.java | 3 +- .../common/data/RecipesProvider.java | 15 +++++ .../common/setup/BlockEntityTypes.java | 2 + .../common/setup/Blocks.java | 1 + 25 files changed, 318 insertions(+), 16 deletions(-) create mode 100644 src/generated/resources/assets/advancedperipherals/blockstates/rs_bridge.json create mode 100644 src/generated/resources/assets/advancedperipherals/models/block/rs_bridge.json create mode 100644 src/generated/resources/data/advancedperipherals/advancement/recipes/redstone/rs_bridge.json create mode 100644 src/generated/resources/data/advancedperipherals/loot_table/blocks/rs_bridge.json create mode 100644 src/generated/resources/data/advancedperipherals/recipe/rs_bridge.json create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java diff --git a/build.gradle b/build.gradle index 60cd4ec88..6a36af0ff 100644 --- a/build.gradle +++ b/build.gradle @@ -172,14 +172,11 @@ repositories { } } maven { - url = uri("https://maven.pkg.github.com/refinedmods/refinedstorage") + url = uri("https://maven.pkg.github.com/refinedmods/refinedstorage2") credentials { username = "anything" password = "\u0067hp_oGjcDFCn8jeTzIj4Ke9pLoEVtpnZMP4VQgaX" } - content { - includeModule("com.refinedmods", "refinedstorage") - } } maven { name = 'Kotlin for Forge' @@ -211,9 +208,11 @@ dependencies { compileOnly "org.jetbrains:annotations:${jb_annotations}" implementation "net.neoforged:neoforge:${neo_version}" implementation "cc.tweaked:cc-tweaked-${minecraft_version}-forge:${cc_version}" - // Minimal requirements end + compileOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorageVersion}") + runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorageVersion}") + // Extended requirements // We don't use the api since we need a specific class from mekanism compileOnly "mekanism:Mekanism:${mekanism_version}" diff --git a/gradle.properties b/gradle.properties index c0e911d29..a70bda92c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,6 +24,7 @@ ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.114.2 minecolonies_version=1.1.846-1.21.1-snapshot +refinedstorageVersion=2.0.0-milestone.4.11 appliedenergistics_version=19.1.2-beta patchouli_version=1.21-87 mekanism_version=1.21.1-10.7.8.70 diff --git a/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca b/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca index e31581614..2f3097413 100644 --- a/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca +++ b/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca @@ -1,2 +1,2 @@ -// 1.21.1 2025-01-13T17:28:09.7116313 Languages: en_us for mod: advancedperipherals -b733229a45f64a6500a00da10265bc71b8320229 assets/advancedperipherals/lang/en_us.json +// 1.21.1 2025-01-14T21:35:41.3213672 Languages: en_us for mod: advancedperipherals +9ca9c60d1ceb2e69c860576cef4ba3095159b16f assets/advancedperipherals/lang/en_us.json diff --git a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d index f4d319548..f5983bb9d 100644 --- a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d +++ b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d @@ -1,4 +1,4 @@ -// 1.21.1 2025-01-14T18:51:29.8897473 Loot Tables +// 1.21.1 2025-01-14T21:35:41.3183672 Loot Tables 9b54955770745d55de988a86cbd08aa9ae23ff86 data/advancedperipherals/loot_table/blocks/block_reader.json d4f1bc579f83dc67ce9f94d35926d34b8894c990 data/advancedperipherals/loot_table/blocks/chat_box.json 9ac96b8e3da827886d8da459a2f146e8ae3ee798 data/advancedperipherals/loot_table/blocks/colony_integrator.json @@ -11,3 +11,4 @@ ae62bfa75e39a59374602c8a87cc2afe8b4923dd data/advancedperipherals/loot_table/blo fa56de9a073f32ab8a65b5f17c57f360a157b5c1 data/advancedperipherals/loot_table/blocks/peripheral_casing.json d61b1c54dd6da8f0213d5eb8a5b40d78bff5ba90 data/advancedperipherals/loot_table/blocks/player_detector.json 6bad9bed7baa7af4b5ca3cae7c4cb8d47dc7b593 data/advancedperipherals/loot_table/blocks/redstone_integrator.json +76cdba2795aafc897a579670afb264b75147f498 data/advancedperipherals/loot_table/blocks/rs_bridge.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 7d5df1cf6..abb520449 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,4 +1,4 @@ -// 1.21.1 2025-01-14T19:12:56.350339 Recipes +// 1.21.1 2025-01-14T21:43:25.122686 Recipes f5ba1f7d129c88dca1a13c8deaae2d269644c7fa data/advancedperipherals/advancement/recipes/redstone/block_reader.json e172645262ade9fc4a1c999a2c0041711c2eab55 data/advancedperipherals/advancement/recipes/redstone/chat_box.json 213de9a7e340c5eb9c01d82a72e7b58921c5290a data/advancedperipherals/advancement/recipes/redstone/chunk_controller.json @@ -17,6 +17,7 @@ f218420f4c94524614229bb2d50e5c7f8e6beb28 data/advancedperipherals/advancement/re 2c38bc3468e8db1caac94d8ddfff68f50d596439 data/advancedperipherals/advancement/recipes/redstone/peripheral_casing.json 7dd96be9f8e31ce60752727119aa9fc738c43e3b data/advancedperipherals/advancement/recipes/redstone/player_detector.json 38be5210a7d2bb22d63674af46867a1b38c022e1 data/advancedperipherals/advancement/recipes/redstone/redstone_integrator.json +a0cab6b6139cd0d6fa86842031a59a3eff69a4ea data/advancedperipherals/advancement/recipes/redstone/rs_bridge.json 6489fff67f0d703c3a087d728eb4801413b686f5 data/advancedperipherals/advancement/recipes/redstone/weak_automata_core.json b48e0eed6f4cfbe62c8b7c411e92e3b38ad4e4f9 data/advancedperipherals/recipe/block_reader.json c8d06dd085c0477f94d90f3a5f0800c3efc08d02 data/advancedperipherals/recipe/chat_box.json @@ -36,4 +37,5 @@ ba80666226c2a0d1aa30709e31756ca27076069a data/advancedperipherals/recipe/overpow 0d659e0d2c832e4eef3e43cb77ddad64e071345a data/advancedperipherals/recipe/peripheral_casing.json 205166613824976d691cd0503f0e399e5b17616e data/advancedperipherals/recipe/player_detector.json b219e8902fcea47776cb23c85e25e58efecc8f00 data/advancedperipherals/recipe/redstone_integrator.json +e0228e5cddd9cc266fadb0fd7c9476285f79143c data/advancedperipherals/recipe/rs_bridge.json 898d1243e5d1038e934f3ef5522aeae2f0468f43 data/advancedperipherals/recipe/weak_automata_core.json diff --git a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 index 7dc9fb650..1198bc8b6 100644 --- a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 +++ b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 @@ -1,6 +1,7 @@ -// 1.21.1 2025-01-13T17:28:09.7101266 Block States: advancedperipherals +// 1.21.1 2025-01-14T21:35:41.3213672 Block States: advancedperipherals 5e28ce1be9a6996d982641e5df1fa7162090b8cc assets/advancedperipherals/blockstates/block_reader.json f42bdde60f84fdb312f7cf3b2be461d9c11ebdc8 assets/advancedperipherals/blockstates/chat_box.json +1227aa092fcf1327547ace6ccc9db230e45891b0 assets/advancedperipherals/blockstates/colony_integrator.json 67420f28031606ca03db9a044141bb22b0fa78b7 assets/advancedperipherals/blockstates/energy_detector.json 340b5baa62e5e6a2c35a05b4411be5937ac2bbb8 assets/advancedperipherals/blockstates/environment_detector.json 57c00996bcf1d783116a9210842f246612089555 assets/advancedperipherals/blockstates/geo_scanner.json @@ -10,8 +11,10 @@ d1fe6188b0b0ce8779cb9795a746177858cbaa41 assets/advancedperipherals/blockstates/ 51d1ce8b8772773acc82895ff6314370138c9d5a assets/advancedperipherals/blockstates/peripheral_casing.json ff12c7217911184266589813a2c8f9b0d46cfd65 assets/advancedperipherals/blockstates/player_detector.json 726cf2599b0c765bcfacda88a1943be74f985877 assets/advancedperipherals/blockstates/redstone_integrator.json +6b176e8fdb048f7b6678bfbc1c4baf2bcfa67a1f assets/advancedperipherals/blockstates/rs_bridge.json 544ff1ecb58622350b58940036b4b1908e1146da assets/advancedperipherals/models/block/block_reader.json b28693973b6bbbb61e0c1ffc59e8ca98d8bb7e97 assets/advancedperipherals/models/block/chat_box.json +8361da86b709e26f17374dfd46637940894a2212 assets/advancedperipherals/models/block/colony_integrator.json 96ef564804fdc2b5184462747935f52baa35c651 assets/advancedperipherals/models/block/energy_detector.json 41556ddf5c5e67def6efd8e2e0645718d950af25 assets/advancedperipherals/models/block/environment_detector.json ba233597a497c1032d884fc3058e27b9d965725e assets/advancedperipherals/models/block/geo_scanner.json @@ -21,3 +24,4 @@ a647b86b8a7862af738136c9375a5d27d3b08860 assets/advancedperipherals/models/block 36b6ac01be085492aa6298eeb89e6ecaa3cb6f82 assets/advancedperipherals/models/block/peripheral_casing.json 40369caaaf2f593d786a9c64284647fed8ae3a47 assets/advancedperipherals/models/block/player_detector.json bed2ba2ba497ccde06c99712483fe220c277b4be assets/advancedperipherals/models/block/redstone_integrator.json +019c10d5062b5e7ae3e641527b9badab7a50878d assets/advancedperipherals/models/block/rs_bridge.json diff --git a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 index 7f7c59f7e..45bd99a68 100644 --- a/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 +++ b/src/generated/resources/.cache/f95c7003282837dabaa33e3ffceec4e6865b5218 @@ -1,4 +1,4 @@ -// 1.21.1 2025-01-14T18:51:29.8886424 Block tags -6566cca83fe6d74441cb2b220aa517b93951dac9 data/minecraft/tags/blocks/mineable/pickaxe.json -5c9d90b6cb82fe772165b794f1eb511db72cb639 data/minecraft/tags/blocks/needs_iron_tool.json +// 1.21.1 2025-01-14T21:35:41.316368 Block tags +ad2dad8f4f2ec5a67735fe462d83d1ac4c3ef006 data/minecraft/tags/blocks/mineable/pickaxe.json +f4459900cde17548776562b1a6f3c12ccc86efa5 data/minecraft/tags/blocks/needs_iron_tool.json e1f71dcb4f9e7e36e29b0ad09d6520dc3adfa4a6 data/neoforge/tags/blocks/needs_wood_tool.json diff --git a/src/generated/resources/assets/advancedperipherals/blockstates/rs_bridge.json b/src/generated/resources/assets/advancedperipherals/blockstates/rs_bridge.json new file mode 100644 index 000000000..a1b1d565a --- /dev/null +++ b/src/generated/resources/assets/advancedperipherals/blockstates/rs_bridge.json @@ -0,0 +1,57 @@ +{ + "variants": { + "orientation=down_east": { + "model": "advancedperipherals:block/rs_bridge", + "x": 90, + "y": 90 + }, + "orientation=down_north": { + "model": "advancedperipherals:block/rs_bridge", + "x": 90 + }, + "orientation=down_south": { + "model": "advancedperipherals:block/rs_bridge", + "x": 90, + "y": 180 + }, + "orientation=down_west": { + "model": "advancedperipherals:block/rs_bridge", + "x": 90, + "y": 270 + }, + "orientation=east_up": { + "model": "advancedperipherals:block/rs_bridge", + "y": 90 + }, + "orientation=north_up": { + "model": "advancedperipherals:block/rs_bridge" + }, + "orientation=south_up": { + "model": "advancedperipherals:block/rs_bridge", + "y": 180 + }, + "orientation=up_east": { + "model": "advancedperipherals:block/rs_bridge", + "x": 270, + "y": 90 + }, + "orientation=up_north": { + "model": "advancedperipherals:block/rs_bridge", + "x": 270 + }, + "orientation=up_south": { + "model": "advancedperipherals:block/rs_bridge", + "x": 270, + "y": 180 + }, + "orientation=up_west": { + "model": "advancedperipherals:block/rs_bridge", + "x": 270, + "y": 270 + }, + "orientation=west_up": { + "model": "advancedperipherals:block/rs_bridge", + "y": 270 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/advancedperipherals/lang/en_us.json b/src/generated/resources/assets/advancedperipherals/lang/en_us.json index 1176cb3fd..15195591a 100644 --- a/src/generated/resources/assets/advancedperipherals/lang/en_us.json +++ b/src/generated/resources/assets/advancedperipherals/lang/en_us.json @@ -18,6 +18,7 @@ "advancements.advancedperipherals.weak_automata_core.description": "Does the afterlife exist in minecraft?", "block.advancedperipherals.block_reader": "Block Reader", "block.advancedperipherals.chat_box": "Chat Box", + "block.advancedperipherals.colony_integrator": "Colony Integrator", "block.advancedperipherals.energy_detector": "Energy Detector", "block.advancedperipherals.environment_detector": "Environment Detector", "block.advancedperipherals.geo_scanner": "Geo Scanner", @@ -27,6 +28,7 @@ "block.advancedperipherals.peripheral_casing": "Peripheral Casing", "block.advancedperipherals.player_detector": "Player Detector", "block.advancedperipherals.redstone_integrator": "Redstone Integrator", + "block.advancedperipherals.rs_bridge": "RS Bridge", "entity.minecraft.villager.advancedperipherals.computer_scientist": "Computer Scientist", "item.advancedperipherals.chunk_controller": "Chunk Controller", "item.advancedperipherals.computer_tool": "Computer Tool", @@ -39,6 +41,7 @@ "item.advancedperipherals.tooltip.block_reader": "&7Reads nbt data of blocks to interact with blocks which do not have computer support.", "item.advancedperipherals.tooltip.chat_box": "&7Interacts with the ingame chat, can read and write messages.", "item.advancedperipherals.tooltip.chunk_controller": "&7A crafting ingredient for the Chunky Turtle.", + "item.advancedperipherals.tooltip.colony_integrator": "&7Interacts with Minecolonies to read data about your colony and citizens.", "item.advancedperipherals.tooltip.computer_tool": "&7This tool was made to tune our blocks. But for now, it's just a blue useless wrench.", "item.advancedperipherals.tooltip.disabled": "&cThis item is disabled in the config, so you can craft it, but it'll not have any functionality.", "item.advancedperipherals.tooltip.end_automata_core": "&7Upgrade for turtles, that allows basic interaction with the world and teleportation in one dimension.", @@ -57,6 +60,7 @@ "item.advancedperipherals.tooltip.peripheral_casing": "&7An empty hull without the love it deserves. Used as a crafting ingredient", "item.advancedperipherals.tooltip.player_detector": "&7This peripheral can be used to interact with players, but don't be a stalker.", "item.advancedperipherals.tooltip.redstone_integrator": "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer.", + "item.advancedperipherals.tooltip.rs_bridge": "&7The RS Bridge interacts with Refined Storage 2 to manage your items.", "item.advancedperipherals.tooltip.show_desc": "&b[&7%s&b] &7For Description", "item.advancedperipherals.tooltip.weak_automata_core": "&7Upgrade for turtles, which makes turtles more useful.", "item.advancedperipherals.weak_automata_core": "Weak Automata Core", diff --git a/src/generated/resources/assets/advancedperipherals/models/block/rs_bridge.json b/src/generated/resources/assets/advancedperipherals/models/block/rs_bridge.json new file mode 100644 index 000000000..10e0f003a --- /dev/null +++ b/src/generated/resources/assets/advancedperipherals/models/block/rs_bridge.json @@ -0,0 +1,8 @@ +{ + "parent": "minecraft:block/cube_all", + "textures": { + "all": "advancedperipherals:block/rs_bridge", + "north": "advancedperipherals:block/rs_bridge_front", + "particle": "advancedperipherals:block/rs_bridge_front" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/advancement/recipes/redstone/rs_bridge.json b/src/generated/resources/data/advancedperipherals/advancement/recipes/redstone/rs_bridge.json new file mode 100644 index 000000000..aff6bdd52 --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/advancement/recipes/redstone/rs_bridge.json @@ -0,0 +1,38 @@ +{ + "neoforge:conditions": [ + { + "type": "neoforge:mod_loaded", + "modid": "refinedstorage" + } + ], + "parent": "minecraft:recipes/root", + "criteria": { + "has_item": { + "conditions": { + "items": [ + { + "items": "advancedperipherals:peripheral_casing" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "advancedperipherals:rs_bridge" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_item" + ] + ], + "rewards": { + "recipes": [ + "advancedperipherals:rs_bridge" + ] + } +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/loot_table/blocks/rs_bridge.json b/src/generated/resources/data/advancedperipherals/loot_table/blocks/rs_bridge.json new file mode 100644 index 000000000..638de0eaf --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/loot_table/blocks/rs_bridge.json @@ -0,0 +1,30 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_components", + "include": [ + "minecraft:custom_name" + ], + "source": "block_entity" + } + ], + "name": "advancedperipherals:rs_bridge" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "advancedperipherals:blocks/rs_bridge" +} \ No newline at end of file diff --git a/src/generated/resources/data/advancedperipherals/recipe/rs_bridge.json b/src/generated/resources/data/advancedperipherals/recipe/rs_bridge.json new file mode 100644 index 000000000..3d0952250 --- /dev/null +++ b/src/generated/resources/data/advancedperipherals/recipe/rs_bridge.json @@ -0,0 +1,39 @@ +{ + "neoforge:conditions": [ + { + "type": "neoforge:mod_loaded", + "modid": "refinedstorage" + } + ], + "type": "minecraft:crafting_shaped", + "category": "redstone", + "key": { + "C": { + "item": "advancedperipherals:peripheral_casing" + }, + "E": { + "tag": "refinedstorage:exporters" + }, + "I": { + "item": "refinedstorage:interface" + }, + "P": { + "item": "refinedstorage:advanced_processor" + }, + "R": { + "tag": "refinedstorage:importers" + }, + "X": { + "tag": "refinedstorage:external_storages" + } + }, + "pattern": [ + "PXP", + "ECR", + "PIP" + ], + "result": { + "count": 1, + "id": "advancedperipherals:rs_bridge" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 7e45c1fe5..ce177bf6b 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -4,6 +4,7 @@ "advancedperipherals:chat_box", "advancedperipherals:player_detector", "advancedperipherals:me_bridge", + "advancedperipherals:rs_bridge", "advancedperipherals:energy_detector", "advancedperipherals:peripheral_casing", "advancedperipherals:inventory_manager", diff --git a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json index 785a3def1..44fdcdc79 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json +++ b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json @@ -4,6 +4,7 @@ "advancedperipherals:chat_box", "advancedperipherals:player_detector", "advancedperipherals:me_bridge", + "advancedperipherals:rs_bridge", "advancedperipherals:energy_detector", "advancedperipherals:inventory_manager", "advancedperipherals:redstone_integrator", diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 95a2f8441..e54a9a54a 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -3,6 +3,7 @@ import dan200.computercraft.api.peripheral.PeripheralCapability; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageApi; import de.srendi.advancedperipherals.common.blocks.base.ICapabilityProvider; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.setup.Registration; @@ -95,5 +96,7 @@ public void registerCapabilities(RegisterCapabilitiesEvent event) { if (APAddons.ae2Loaded) AppEngApi.registerCapabilities(event); + if (APAddons.refinedStorageLoaded) + RefinedStorageApi.registerCapabilities(event); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index 449eb8211..bb3ca75a9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -11,7 +11,7 @@ public class APAddons { public static final String AE2_MODID = "ae2"; public static final String CURIOS_MODID = "curios"; - public static final String REFINEDSTORAGETWO_MODID = "refinedstorage2"; + public static final String REFINEDSTORAGE_MODID = "refinedstorage"; public static final String APP_MEKANISTICS_MODID = "appmek"; public static final String PATCHOULI_MODID = "patchouli"; public static final String MINECOLONIES_MODID = "minecolonies"; @@ -30,7 +30,7 @@ public static void setup() { ModList modList = ModList.get(); ae2Loaded = modList.isLoaded(AE2_MODID); curiosLoaded = modList.isLoaded(CURIOS_MODID); - refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGETWO_MODID); + refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGE_MODID); appMekLoaded = modList.isLoaded(APP_MEKANISTICS_MODID); patchouliLoaded = modList.isLoaded(PATCHOULI_MODID); minecoloniesLoaded = modList.isLoaded(MINECOLONIES_MODID); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java new file mode 100644 index 000000000..98c65f8f8 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -0,0 +1,21 @@ +package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; + +import de.srendi.advancedperipherals.common.addons.APAddons; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; +import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; + +public class RSBridgePeripheral extends BasePeripheral> { + + public static final String PERIPHERAL_TYPE = "rsBridge"; + + public RSBridgePeripheral(RsBridgeEntity owner) { + super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(owner)); + } + + @Override + public boolean isEnabled() { + return APAddons.refinedStorageLoaded && APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java new file mode 100644 index 000000000..ab4359602 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -0,0 +1,17 @@ +package de.srendi.advancedperipherals.common.addons.refinedstorage; + +import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; + +public class RefinedStorageApi { + + public static void registerCapabilities(RegisterCapabilitiesEvent event) { + event.registerBlockEntity( + RefinedStorageNeoForgeApi.INSTANCE.getNetworkNodeContainerProviderCapability(), + BlockEntityTypes.RS_BRIDGE.get(), + (blockEntity, side) -> blockEntity); + } + + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java new file mode 100644 index 000000000..b715902d7 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -0,0 +1,56 @@ +package de.srendi.advancedperipherals.common.blocks.blockentities; + +import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; +import com.refinedmods.refinedstorage.common.api.support.network.NetworkNodeContainerProvider; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RSBridgePeripheral; +import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; +import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.lib.peripherals.IPeripheralTileEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public class RsBridgeEntity extends PeripheralBlockEntity implements IPeripheralTileEntity, NetworkNodeContainerProvider { + + protected CompoundTag peripheralSettings; + + public RsBridgeEntity(BlockPos pos, BlockState state) { + super(BlockEntityTypes.RS_BRIDGE.get(), pos, state); + peripheralSettings = new CompoundTag(); + } + + @NotNull + @Override + protected RSBridgePeripheral createPeripheral() { + return new RSBridgePeripheral(this); + } + + @Override + public CompoundTag getPeripheralSettings() { + return peripheralSettings; + } + + @Override + public void markSettingsChanged() { + setChanged(); + } + + @NotNull + @Override + public Set getContainers() { + return Set.of(); + } + + @Override + public void addContainer(@NotNull InWorldNetworkNodeContainer inWorldNetworkNodeContainer) { + } + + @Override + public boolean canBuild(ServerPlayer serverPlayer) { + return true; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java index 65591a348..853a2257b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/BlockStatesAndModelsProvider.java @@ -28,6 +28,7 @@ protected void registerStatesAndModels() { peripheralBlock(Blocks.CHAT_BOX.get(), "front"); peripheralBlock(Blocks.PLAYER_DETECTOR.get(), "side", "front"); peripheralBlock(Blocks.ME_BRIDGE.get(), "front"); + peripheralBlock(Blocks.RS_BRIDGE.get(), "front"); peripheralBlock(Blocks.ENERGY_DETECTOR.get(), "front", "back"); peripheralBlock(Blocks.PERIPHERAL_CASING.get()); peripheralBlock(Blocks.INVENTORY_MANAGER.get(), "front"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index 2dd231d0c..cb0419334 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -60,6 +60,7 @@ private void addBlocks() { addBlock(Blocks.GEO_SCANNER, "Geo Scanner"); addBlock(Blocks.INVENTORY_MANAGER, "Inventory Manager"); addBlock(Blocks.ME_BRIDGE, "ME Bridge"); + addBlock(Blocks.RS_BRIDGE, "RS Bridge"); addBlock(Blocks.NBT_STORAGE, "NBT Storage"); addBlock(Blocks.PERIPHERAL_CASING, "Peripheral Casing"); addBlock(Blocks.PLAYER_DETECTOR, "Player Detector"); @@ -82,7 +83,6 @@ private void addTurtles() { } private void addPockets() { - addPocket(CCRegistration.ID.COLONY_POCKET, "Colony"); addPocket(CCRegistration.ID.COLONY_POCKET, "Colony"); addPocket(CCRegistration.ID.CHATTY_POCKET, "Chatty"); addPocket(CCRegistration.ID.ENVIRONMENT_POCKET, "Environment"); @@ -110,6 +110,7 @@ private void addTooltips() { addTooltip(Blocks.ENVIRONMENT_DETECTOR.get(), "&7This peripheral interacts with the minecraft world."); addTooltip(Blocks.PLAYER_DETECTOR.get(), "&7This peripheral can be used to interact with players, but don't be a stalker."); addTooltip(Blocks.ME_BRIDGE.get(), "&7The ME Bridge interacts with Applied Energistics to manage your items."); + addTooltip(Blocks.RS_BRIDGE.get(), "&7The RS Bridge interacts with Refined Storage 2 to manage your items."); addTooltip(Blocks.CHAT_BOX.get(), "&7Interacts with the ingame chat, can read and write messages."); addTooltip(Blocks.PERIPHERAL_CASING.get(), "&7An empty hull without the love it deserves. Used as a crafting ingredient"); addTooltip(Items.MEMORY_CARD.get(), "&7Can save the rights of a player to use it in an inventory manager."); diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java index 42af11920..cfcd6be71 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/RecipesProvider.java @@ -3,6 +3,7 @@ import appeng.core.definitions.AEBlocks; import com.minecolonies.api.blocks.ModBlocks; import com.minecolonies.api.items.ModItems; +import com.refinedmods.refinedstorage.common.misc.ProcessorItem; import dan200.computercraft.shared.ModRegistry; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.setup.Blocks; @@ -68,6 +69,20 @@ protected void buildRecipes(RecipeOutput recipeOutput) { ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.ME_BRIDGE.get()).define('F', AEBlocks.FLUIX_BLOCK.asItem()).define('A', CASING).define('I', AEBlocks.INTERFACE.asItem()).pattern("FIF").pattern("IAI").pattern("FIF").unlockedBy(HAS_ITEM, has(CASING)).save(recipeOutput.withConditions(new ModLoadedCondition(APAddons.AE2_MODID))); + + com.refinedmods.refinedstorage.common.content.Items rsItems = com.refinedmods.refinedstorage.common.content.Items.INSTANCE; + com.refinedmods.refinedstorage.common.content.Blocks rsBlocks = com.refinedmods.refinedstorage.common.content.Blocks.INSTANCE; + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.RS_BRIDGE.get()) + .define('P', rsItems.getProcessor(ProcessorItem.Type.ADVANCED)) + .define('C', CASING) + .define('I', rsBlocks.getInterface()) + .define('X', com.refinedmods.refinedstorage.common.content.Tags.EXTERNAL_STORAGES) + .define('E', com.refinedmods.refinedstorage.common.content.Tags.EXPORTERS) + .define('R', com.refinedmods.refinedstorage.common.content.Tags.IMPORTERS) + .pattern("PXP") + .pattern("ECR") + .pattern("PIP").unlockedBy(HAS_ITEM, has(CASING)).save(recipeOutput.withConditions(new ModLoadedCondition(APAddons.REFINEDSTORAGE_MODID))); + ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, Blocks.COLONY_INTEGRATOR.get()).define('O', ItemTags.LOGS).define('A', CASING).define('B', ModItems.buildGoggles).define('S', com.ldtteam.structurize.items.ModItems.buildTool).define('R', ModBlocks.blockRack).pattern("ORO").pattern("BAS").pattern("ORO").unlockedBy(HAS_ITEM, has(CASING)).save(recipeOutput.withConditions(new ModLoadedCondition(APAddons.MINECOLONIES_MODID))); ShapedRecipeBuilder.shaped(RecipeCategory.REDSTONE, de.srendi.advancedperipherals.common.setup.Items.WEAK_AUTOMATA_CORE.get()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java index f2fc2fcfe..87b0a7d2b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java @@ -13,6 +13,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.NBTStorageEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.PlayerDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.RedstoneIntegratorEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.neoforged.neoforge.registries.DeferredHolder; @@ -22,6 +23,7 @@ public class BlockEntityTypes { public static final DeferredHolder, BlockEntityType> ENVIRONMENT_DETECTOR = Registration.BLOCK_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(Blocks.ENVIRONMENT_DETECTOR.get()), null)); public static final DeferredHolder, BlockEntityType> PLAYER_DETECTOR = Registration.BLOCK_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(Blocks.PLAYER_DETECTOR.get()), null)); public static final DeferredHolder, BlockEntityType> ME_BRIDGE = APAddons.ae2Loaded ? Registration.BLOCK_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(Blocks.ME_BRIDGE.get()), null)) : null; + public static final DeferredHolder, BlockEntityType> RS_BRIDGE = APAddons.refinedStorageLoaded ? Registration.BLOCK_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(Blocks.RS_BRIDGE.get()), null)) : null; public static final DeferredHolder, BlockEntityType> ENERGY_DETECTOR = Registration.BLOCK_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(Blocks.ENERGY_DETECTOR.get()), null)); public static final DeferredHolder, BlockEntityType> INVENTORY_MANAGER = Registration.BLOCK_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(Blocks.INVENTORY_MANAGER.get()), null)); public static final DeferredHolder, BlockEntityType> REDSTONE_INTEGRATOR = Registration.BLOCK_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(Blocks.REDSTONE_INTEGRATOR.get()), null)); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java index 52de7d557..636a6b99e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/Blocks.java @@ -23,6 +23,7 @@ public class Blocks { public static final DeferredHolder> CHAT_BOX = register("chat_box", () -> new APBlockEntityBlock<>(BlockEntityTypes.CHAT_BOX, true), () -> new APBlockItem(Blocks.CHAT_BOX.get(), APConfig.PERIPHERALS_CONFIG.enableChatBox::get)); public static final DeferredHolder> PLAYER_DETECTOR = register("player_detector", PlayerDetectorBlock::new, () -> new APBlockItem(Blocks.PLAYER_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enablePlayerDetector::get)); public static final DeferredHolder> ME_BRIDGE = register("me_bridge", () -> new APBlockEntityBlock<>(APAddons.ae2Loaded ? BlockEntityTypes.ME_BRIDGE : null, APAddons.ae2Loaded), () -> new APBlockItem(Blocks.ME_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableMEBridge::get)); + public static final DeferredHolder> RS_BRIDGE = register("rs_bridge", () -> new APBlockEntityBlock<>(APAddons.refinedStorageLoaded ? BlockEntityTypes.RS_BRIDGE : null, APAddons.refinedStorageLoaded), () -> new APBlockItem(Blocks.RS_BRIDGE.get(), APConfig.PERIPHERALS_CONFIG.enableRSBridge::get)); public static final DeferredHolder> ENERGY_DETECTOR = register("energy_detector", () -> new APBlockEntityBlock<>(BlockEntityTypes.ENERGY_DETECTOR, true), () -> new APBlockItem(Blocks.ENERGY_DETECTOR.get(), APConfig.PERIPHERALS_CONFIG.enableEnergyDetector::get)); public static final DeferredHolder PERIPHERAL_CASING = register("peripheral_casing", BaseBlock::new, () -> new APBlockItem(Blocks.PERIPHERAL_CASING.get(), new Item.Properties().stacksTo(16), () -> true)); public static final DeferredHolder> INVENTORY_MANAGER = register("inventory_manager", () -> new APBlockEntityBlock<>(BlockEntityTypes.INVENTORY_MANAGER, false), () -> new APBlockItem(Blocks.INVENTORY_MANAGER.get(), APConfig.PERIPHERALS_CONFIG.enableInventoryManager::get)); From ddb4d2cada27d5d8cbe31aa6141a918bf22ec566 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 14 Jan 2025 22:45:07 +0100 Subject: [PATCH 02/91] RS Bridge can now connect to a RS System --- .../blocks/blockentities/RsBridgeEntity.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java index b715902d7..707d6b7d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -1,26 +1,38 @@ package de.srendi.advancedperipherals.common.blocks.blockentities; +import com.refinedmods.refinedstorage.api.network.impl.node.SimpleNetworkNode; +import com.refinedmods.refinedstorage.api.network.node.NetworkNode; +import com.refinedmods.refinedstorage.common.api.support.network.ConnectionStrategy; import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; import com.refinedmods.refinedstorage.common.api.support.network.NetworkNodeContainerProvider; +import com.refinedmods.refinedstorage.common.support.network.InWorldNetworkNodeContainerImpl; +import com.refinedmods.refinedstorage.common.support.network.SimpleConnectionStrategy; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RSBridgePeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; +import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralTileEntity; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Set; public class RsBridgeEntity extends PeripheralBlockEntity implements IPeripheralTileEntity, NetworkNodeContainerProvider { protected CompoundTag peripheralSettings; + private final InWorldNetworkNodeContainer networkNodeContainer; public RsBridgeEntity(BlockPos pos, BlockState state) { super(BlockEntityTypes.RS_BRIDGE.get(), pos, state); peripheralSettings = new CompoundTag(); + ConnectionStrategy connectionStrategy = new SimpleConnectionStrategy(pos); + NetworkNode node = new SimpleNetworkNode(APConfig.PERIPHERALS_CONFIG.rsConsumption.get()); + networkNodeContainer = new InWorldNetworkNodeContainerImpl(this, node, "RS Bridge", 1, connectionStrategy, null); } @NotNull @@ -42,7 +54,7 @@ public void markSettingsChanged() { @NotNull @Override public Set getContainers() { - return Set.of(); + return Set.of(networkNodeContainer); } @Override @@ -50,7 +62,22 @@ public void addContainer(@NotNull InWorldNetworkNodeContainer inWorldNetworkNode } @Override - public boolean canBuild(ServerPlayer serverPlayer) { + public boolean canBuild(@NotNull ServerPlayer serverPlayer) { return true; } + + @Override + public void update(@Nullable Level level) { + NetworkNodeContainerProvider.super.update(level); + } + + @Override + public void initialize(@Nullable Level level, @Nullable Runnable callback) { + NetworkNodeContainerProvider.super.initialize(level, callback); + } + + @Override + public void remove(@Nullable Level level) { + NetworkNodeContainerProvider.super.remove(level); + } } From 28be7b8eee4522cf3590dad72210da6c211ca86e Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 14 Jan 2025 23:59:28 +0100 Subject: [PATCH 03/91] Use for the RS functions our `IStorageSystemPeripheral` implementation from 0.8 to reduce breaking changes when we port 0.8 to future versions, we will also use that for the me bridge in the near future Some functions implemented for testing --- .../appliedenergistics/MeFluidHandler.java | 3 +- .../appliedenergistics/MeItemHandler.java | 3 +- ...eripheral.java => MEBridgePeripheral.java} | 4 +- .../peripheral/RSBridgePeripheral.java | 313 +++++++++++++++++- .../blocks/blockentities/MeBridgeEntity.java | 8 +- .../blocks/blockentities/RsBridgeEntity.java | 7 +- .../inventory/IStorageSystemPeripheral.java | 116 +++++++ 7 files changed, 444 insertions(+), 10 deletions(-) rename src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/{MeBridgePeripheral.java => MEBridgePeripheral.java} (99%) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java index fb29729b1..cf67ddc39 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java @@ -4,6 +4,7 @@ import appeng.api.networking.security.IActionSource; import appeng.api.stacks.AEFluidKey; import appeng.api.storage.MEStorage; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MEBridgePeripheral; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemFluidHandler; @@ -12,7 +13,7 @@ /** * Used to transfer item between an inventory and the ME system. - * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral + * @see MEBridgePeripheral */ public class MeFluidHandler implements IStorageSystemFluidHandler { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java index ef7c6f71d..36d973ba5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java @@ -4,6 +4,7 @@ import appeng.api.networking.security.IActionSource; import appeng.api.stacks.AEItemKey; import appeng.api.storage.MEStorage; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MEBridgePeripheral; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemItemHandler; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; @@ -13,7 +14,7 @@ /** * Used to transfer item between an inventory and the ME system. * - * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral + * @see MEBridgePeripheral */ public class MeItemHandler implements IStorageSystemItemHandler { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java similarity index 99% rename from src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java index 14cf55fd1..d0b60e362 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java @@ -35,13 +35,13 @@ import java.util.Iterator; import java.util.List; -public class MeBridgePeripheral extends BasePeripheral> { +public class MEBridgePeripheral extends BasePeripheral> { public static final String PERIPHERAL_TYPE = "meBridge"; private final MeBridgeEntity tile; private IGridNode node; - public MeBridgePeripheral(MeBridgeEntity tileEntity) { + public MEBridgePeripheral(MeBridgeEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); this.tile = tileEntity; this.node = tileEntity.getActionableNode(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 98c65f8f8..52e5776bf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -1,12 +1,23 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; +import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.NetworkComponent; +import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage.api.network.node.NetworkNode; +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.api.peripheral.IComputerAccess; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemPeripheral; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import org.jetbrains.annotations.NotNull; -public class RSBridgePeripheral extends BasePeripheral> { +public class RSBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { public static final String PERIPHERAL_TYPE = "rsBridge"; @@ -15,7 +26,307 @@ public RSBridgePeripheral(RsBridgeEntity owner) { } @Override + @LuaFunction(mainThread = true) public boolean isEnabled() { return APAddons.refinedStorageLoaded && APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); } + + private NetworkNode getNode() { + return owner.tileEntity.getNode(); + } + + private Network getNetwork() { + return getNode().getNetwork(); + } + + private MethodResult notConnected() { + return MethodResult.of(null, "NOT_CONNECTED"); + } + + private I getComponent(@NotNull Class componentClass) { + return getNetwork().getComponent(componentClass); + } + + private boolean isAvailable() { + return getNetwork() != null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult isConnected() { + return MethodResult.of(isAvailable()); + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult isOnline() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(getComponent(EnergyNetworkComponent.class).getStored() > 0); + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getItem(IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getFluid(IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult listItems() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult listFluids() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult listCraftableItems() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult listCraftableFluids() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult listCells() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult listDrives() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getPatterns() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getStoredEnergy() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getEnergyCapacity() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getEnergyUsage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getAvgPowerInjection() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getTotalExternItemStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getTotalExternFluidStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getTotalExternChemicalStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getTotalItemStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getTotalFluidStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getTotalChemicalStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getUsedExternItemStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getUsedExternFluidStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getUsedExternChemicalStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getUsedItemStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getUsedFluidStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getUsedChemicalStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getAvailableExternItemStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getAvailableExternFluidStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getAvailableExternChemicalStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getAvailableItemStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getAvailableFluidStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getAvailableChemicalStorage() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult getCraftingTasks() { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult isItemCraftable(IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult isItemCrafting(IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult isFluidCraftable(IArguments arguments) throws LuaException { + return null; + } + + @Override + @LuaFunction(mainThread = true) + public MethodResult isFluidCrafting(IArguments arguments) throws LuaException { + return null; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java index 8e7255c64..9f38752dc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java @@ -13,7 +13,7 @@ import appeng.me.helpers.IGridConnectedBlockEntity; import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob; import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeBridgeEntityListener; -import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MEBridgePeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; @@ -34,7 +34,7 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; -public class MeBridgeEntity extends PeripheralBlockEntity implements IActionSource, IActionHost, IInWorldGridNodeHost, IGridConnectedBlockEntity, ICraftingSimulationRequester { +public class MeBridgeEntity extends PeripheralBlockEntity implements IActionSource, IActionHost, IInWorldGridNodeHost, IGridConnectedBlockEntity, ICraftingSimulationRequester { private final List jobs = new CopyOnWriteArrayList<>(); private boolean initialized = false; @@ -47,8 +47,8 @@ public MeBridgeEntity(BlockPos pos, BlockState state) { @NotNull @Override - protected MeBridgePeripheral createPeripheral() { - return new MeBridgePeripheral(this); + protected MEBridgePeripheral createPeripheral() { + return new MEBridgePeripheral(this); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java index 707d6b7d5..34332c3c7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -25,13 +25,14 @@ public class RsBridgeEntity extends PeripheralBlockEntity implements IPeripheralTileEntity, NetworkNodeContainerProvider { protected CompoundTag peripheralSettings; + private final NetworkNode node; private final InWorldNetworkNodeContainer networkNodeContainer; public RsBridgeEntity(BlockPos pos, BlockState state) { super(BlockEntityTypes.RS_BRIDGE.get(), pos, state); peripheralSettings = new CompoundTag(); ConnectionStrategy connectionStrategy = new SimpleConnectionStrategy(pos); - NetworkNode node = new SimpleNetworkNode(APConfig.PERIPHERALS_CONFIG.rsConsumption.get()); + node = new SimpleNetworkNode(APConfig.PERIPHERALS_CONFIG.rsConsumption.get()); networkNodeContainer = new InWorldNetworkNodeContainerImpl(this, node, "RS Bridge", 1, connectionStrategy, null); } @@ -51,6 +52,10 @@ public void markSettingsChanged() { setChanged(); } + public NetworkNode getNode() { + return node; + } + @NotNull @Override public Set getContainers() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java new file mode 100644 index 000000000..b74ee11cb --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -0,0 +1,116 @@ +package de.srendi.advancedperipherals.common.util.inventory; + +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.MethodResult; +import dan200.computercraft.api.peripheral.IComputerAccess; +import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MEBridgePeripheral; + +/** + * This class is stolen from the dev/0.8 branch to make the 0.8 port + * to 1.21.1 a bit easier + *

+ * Implementation for common storage peripheral functions. Used for AE2 {@link MEBridgePeripheral} + * and RS {@link de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RSBridgePeripheral} + *

+ * This ensures that these both bridges use the same methods. This makes it easier to support both in the same script + * In case there is a new mod which adds new ways to store and craft items, this ensures that the new peripheral + * has the same functions as the other ones + *

+ * Implemented functions need to override {@link dan200.computercraft.api.lua.LuaFunction} + */ +public interface IStorageSystemPeripheral { + + MethodResult isConnected(); + + MethodResult isOnline(); + + MethodResult getItem(IArguments arguments) throws LuaException; + + MethodResult getFluid(IArguments arguments) throws LuaException; + + MethodResult listItems(); + + MethodResult listFluids(); + + MethodResult listCraftableItems(); + + MethodResult listCraftableFluids(); + + MethodResult listCells(); + + MethodResult listDrives(); + + MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException; + + MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException; + + MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException; + + MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; + + MethodResult getFilteredPatterns(IArguments arguments) throws LuaException; + + MethodResult getPatterns(); + + MethodResult getStoredEnergy(); + + MethodResult getEnergyCapacity(); + + MethodResult getEnergyUsage(); + + MethodResult getAvgPowerInjection(); + + MethodResult getTotalExternItemStorage(); + + MethodResult getTotalExternFluidStorage(); + + MethodResult getTotalExternChemicalStorage(); + + MethodResult getTotalItemStorage(); + + MethodResult getTotalFluidStorage(); + + MethodResult getTotalChemicalStorage(); + + MethodResult getUsedExternItemStorage(); + + MethodResult getUsedExternFluidStorage(); + + MethodResult getUsedExternChemicalStorage(); + + MethodResult getUsedItemStorage(); + + MethodResult getUsedFluidStorage(); + + MethodResult getUsedChemicalStorage(); + + MethodResult getAvailableExternItemStorage(); + + MethodResult getAvailableExternFluidStorage(); + + MethodResult getAvailableExternChemicalStorage(); + + MethodResult getAvailableItemStorage(); + + MethodResult getAvailableFluidStorage(); + + MethodResult getAvailableChemicalStorage(); + + MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; + + MethodResult getCraftingTasks(); + + MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException; + + MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; + + MethodResult isItemCraftable(IArguments arguments) throws LuaException; + + MethodResult isItemCrafting(IArguments arguments) throws LuaException; + + MethodResult isFluidCraftable(IArguments arguments) throws LuaException; + + MethodResult isFluidCrafting(IArguments arguments) throws LuaException; + +} From 7daf84808cefbd3b3837f867fc402242dfa05be9 Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 15 Jan 2025 16:07:22 +0100 Subject: [PATCH 04/91] get and list items functions --- .../2f719b8031aed5e605ed8d6694b19245ca45c6ca | 4 +- .../b8526e444ae7356037f3a813274f6835d1f3dd16 | 4 +- .../models/block/rs_bridge.json | 3 +- .../peripheral/RSBridgePeripheral.java | 46 +++++++++++-- .../refinedstorage/RefinedStorageApi.java | 69 ++++++++++++++++++- .../inventory/IStorageSystemPeripheral.java | 8 +-- .../common/util/inventory/ItemFilter.java | 3 + 7 files changed, 121 insertions(+), 16 deletions(-) diff --git a/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca b/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca index f9b340e45..dc8ebf49f 100644 --- a/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca +++ b/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca @@ -1,2 +1,2 @@ -// 1.21.1 2025-01-15T03:22:26.2798836 Languages: en_us for mod: advancedperipherals -df95afe714aeff7559b0093257aeca501dabb1e2 assets/advancedperipherals/lang/en_us.json +// 1.21.1 2025-01-15T15:11:12.9930186 Languages: en_us for mod: advancedperipherals +9ca9c60d1ceb2e69c860576cef4ba3095159b16f assets/advancedperipherals/lang/en_us.json diff --git a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 index 0b5e6c2a4..9ee8b44df 100644 --- a/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 +++ b/src/generated/resources/.cache/b8526e444ae7356037f3a813274f6835d1f3dd16 @@ -1,4 +1,4 @@ -// 1.21.1 2025-01-15T03:30:04.6987737 Block States: advancedperipherals +// 1.21.1 2025-01-15T15:11:12.9901322 Block States: advancedperipherals 5e28ce1be9a6996d982641e5df1fa7162090b8cc assets/advancedperipherals/blockstates/block_reader.json f42bdde60f84fdb312f7cf3b2be461d9c11ebdc8 assets/advancedperipherals/blockstates/chat_box.json 1227aa092fcf1327547ace6ccc9db230e45891b0 assets/advancedperipherals/blockstates/colony_integrator.json @@ -11,6 +11,7 @@ d1fe6188b0b0ce8779cb9795a746177858cbaa41 assets/advancedperipherals/blockstates/ 51d1ce8b8772773acc82895ff6314370138c9d5a assets/advancedperipherals/blockstates/peripheral_casing.json ff12c7217911184266589813a2c8f9b0d46cfd65 assets/advancedperipherals/blockstates/player_detector.json 726cf2599b0c765bcfacda88a1943be74f985877 assets/advancedperipherals/blockstates/redstone_integrator.json +6b176e8fdb048f7b6678bfbc1c4baf2bcfa67a1f assets/advancedperipherals/blockstates/rs_bridge.json 544ff1ecb58622350b58940036b4b1908e1146da assets/advancedperipherals/models/block/block_reader.json dab55424ec184c5495c7ca11e5bbe77210e04c26 assets/advancedperipherals/models/block/chat_box.json 7e207db9b2b170f52565c8ed23bcc92762be6c4d assets/advancedperipherals/models/block/colony_integrator.json @@ -23,3 +24,4 @@ dab55424ec184c5495c7ca11e5bbe77210e04c26 assets/advancedperipherals/models/block 36b6ac01be085492aa6298eeb89e6ecaa3cb6f82 assets/advancedperipherals/models/block/peripheral_casing.json 120df29f21059aa9d4dff53bbb80953dee8d5214 assets/advancedperipherals/models/block/player_detector.json d08b8946e1eb01cc9c8af4fa297b582614d1034b assets/advancedperipherals/models/block/redstone_integrator.json +15685a3c58f78db663609d56ee6fdb29652eef5f assets/advancedperipherals/models/block/rs_bridge.json diff --git a/src/generated/resources/assets/advancedperipherals/models/block/rs_bridge.json b/src/generated/resources/assets/advancedperipherals/models/block/rs_bridge.json index 10e0f003a..585be6406 100644 --- a/src/generated/resources/assets/advancedperipherals/models/block/rs_bridge.json +++ b/src/generated/resources/assets/advancedperipherals/models/block/rs_bridge.json @@ -3,6 +3,7 @@ "textures": { "all": "advancedperipherals:block/rs_bridge", "north": "advancedperipherals:block/rs_bridge_front", - "particle": "advancedperipherals:block/rs_bridge_front" + "particle": "advancedperipherals:block/rs_bridge_front", + "up": "advancedperipherals:block/rs_bridge_top" } } \ No newline at end of file diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 52e5776bf..36cdc8380 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -11,12 +11,18 @@ import dan200.computercraft.api.peripheral.IComputerAccess; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageApi; import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; +import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemPeripheral; +import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import org.jetbrains.annotations.NotNull; +import java.util.Map; +import java.util.Set; + public class RSBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { public static final String PERIPHERAL_TYPE = "rsBridge"; @@ -48,7 +54,7 @@ private I getComponent(@NotNull Class componentC } private boolean isAvailable() { - return getNetwork() != null; + return true; } @Override @@ -69,7 +75,22 @@ public MethodResult isOnline() { @Override @LuaFunction(mainThread = true) public MethodResult getItem(IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + Pair filter = ItemFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + ItemFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(null, "EMPTY_FILTER"); + + Map resourceProperties = RefinedStorageApi.getItem(getNetwork(), parsedFilter); + if (resourceProperties == null) + return MethodResult.of(null, "NOT_FOUND"); + + return MethodResult.of(resourceProperties); } @Override @@ -80,25 +101,36 @@ public MethodResult getFluid(IArguments arguments) throws LuaException { @Override @LuaFunction(mainThread = true) - public MethodResult listItems() { - return null; + public MethodResult listItems(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Pair filter = ItemFilter.parse(arguments.optTable(0, Map.of())); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + ItemFilter parsedFilter = filter.getLeft(); + + Set> resourceProperties = RefinedStorageApi.listItems(getNetwork(), parsedFilter); + + return MethodResult.of(resourceProperties); } @Override @LuaFunction(mainThread = true) - public MethodResult listFluids() { + public MethodResult listFluids(IArguments arguments) { return null; } @Override @LuaFunction(mainThread = true) - public MethodResult listCraftableItems() { + public MethodResult listCraftableItems(IArguments arguments) { return null; } @Override @LuaFunction(mainThread = true) - public MethodResult listCraftableFluids() { + public MethodResult listCraftableFluids(IArguments arguments) { return null; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index ab4359602..6f6295ed3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -1,17 +1,84 @@ package de.srendi.advancedperipherals.common.addons.refinedstorage; +import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.api.storage.EmptyActor; +import com.refinedmods.refinedstorage.api.storage.TrackedResourceAmount; +import com.refinedmods.refinedstorage.common.support.resource.ItemResource; import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.util.LuaConverter; +import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; +import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; +import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import org.jetbrains.annotations.NotNull; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Refined Storage Api helper methods and parsers + * + * TODO use PlayerActor where possible + */ public class RefinedStorageApi { - public static void registerCapabilities(RegisterCapabilitiesEvent event) { + public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event) { event.registerBlockEntity( RefinedStorageNeoForgeApi.INSTANCE.getNetworkNodeContainerProviderCapability(), BlockEntityTypes.RS_BRIDGE.get(), (blockEntity, side) -> blockEntity); } + public static Map getItem(Network network, ItemFilter filter) { + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(EmptyActor.INSTANCE.getClass())) { + if(trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { + return getObjectFromStack(trackedResource); + } + } + return null; + } + + /** + * Returns every item from the system while also checking if the filter test passes for the items + * The filter can be empty, see {@link ItemFilter#empty()} + * + * @param network the rs network + * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource + * @return a set of items + */ + public static Set> listItems(Network network, ItemFilter filter) { + Set> items = new HashSet<>(); + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(EmptyActor.INSTANCE.getClass())) { + if(trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { + items.add(getObjectFromStack(trackedResource)); + } + } + return items; + } + + /** + * Parses an RS TrackedResourceAmount to a lua object + * This method assumes you did an instanceof check before that the {@link ResourceKey} is an {@link ItemResource} + * + * @param trackedResourceAmount the tracked resource amount containing an ItemResource + * @return a Map containing the properties which CC can parse to a lua table + */ + public static Map getObjectFromStack(TrackedResourceAmount trackedResourceAmount) { + ItemResource resource = (ItemResource) trackedResourceAmount.resourceAmount().resource(); + long amount = trackedResourceAmount.resourceAmount().amount(); + ItemStack stack = resource.toItemStack(); + Map properties = LuaConverter.stackToObject(stack); + properties.put("amount", amount); + properties.put("fingerprint", ItemUtil.getFingerprint(stack)); + + return properties; + } + } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index b74ee11cb..b775ea2de 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -29,13 +29,13 @@ public interface IStorageSystemPeripheral { MethodResult getFluid(IArguments arguments) throws LuaException; - MethodResult listItems(); + MethodResult listItems(IArguments arguments) throws LuaException; - MethodResult listFluids(); + MethodResult listFluids(IArguments arguments) throws LuaException; - MethodResult listCraftableItems(); + MethodResult listCraftableItems(IArguments arguments) throws LuaException; - MethodResult listCraftableFluids(); + MethodResult listCraftableFluids(IArguments arguments) throws LuaException; MethodResult listCells(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index 3a2cca625..c8953b985 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -117,6 +117,9 @@ public ItemStack toItemStack() { } public boolean test(ItemStack stack) { + if (isEmpty()) + return true; + if (!fingerprint.isEmpty()) { String testFingerprint = ItemUtil.getFingerprint(stack); return fingerprint.equals(testFingerprint); From 9a76facb766e1e3809e3b2959d70981f73b9ac8b Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 16 Jan 2025 18:15:01 +0100 Subject: [PATCH 05/91] Initialize the network node container --- .../blocks/blockentities/RsBridgeEntity.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java index 34332c3c7..15169389a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -15,10 +15,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -56,6 +54,11 @@ public NetworkNode getNode() { return node; } + public void clearRemoved() { + super.clearRemoved(); + initialize(this.level, null); + } + @NotNull @Override public Set getContainers() { @@ -70,19 +73,4 @@ public void addContainer(@NotNull InWorldNetworkNodeContainer inWorldNetworkNode public boolean canBuild(@NotNull ServerPlayer serverPlayer) { return true; } - - @Override - public void update(@Nullable Level level) { - NetworkNodeContainerProvider.super.update(level); - } - - @Override - public void initialize(@Nullable Level level, @Nullable Runnable callback) { - NetworkNodeContainerProvider.super.initialize(level, callback); - } - - @Override - public void remove(@Nullable Level level) { - NetworkNodeContainerProvider.super.remove(level); - } } From 3c04f09fa4d4d19af21789fd4b847cf36c727103 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 3 Feb 2025 23:11:20 +0100 Subject: [PATCH 06/91] listFluids and getFluid Bump RS --- gradle.properties | 2 +- .../addons/appliedenergistics/AppEngApi.java | 2 +- .../peripheral/RSBridgePeripheral.java | 33 +++++++- .../refinedstorage/RefinedStorageApi.java | 80 ++++++++++++++++--- .../common/util/LuaConverter.java | 16 +++- 5 files changed, 115 insertions(+), 18 deletions(-) diff --git a/gradle.properties b/gradle.properties index 16e7c627d..c2aa87cad 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.113.1 minecolonies_version=1.1.846-1.21.1-snapshot -refinedstorageVersion=2.0.0-milestone.4.11 +refinedstorageVersion=2.0.0-milestone.4.13 appliedenergistics_version=19.1.2-beta patchouli_version=1.21-87 mekanism_version=1.21.1-10.7.8.70 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java index fb2d2d9ec..2f3c4de21 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java @@ -165,7 +165,7 @@ public static Map getObjectFromStack(Pair filter = FluidFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + FluidFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(null, "EMPTY_FILTER"); + + Map resourceProperties = RefinedStorageApi.getFluid(getNetwork(), parsedFilter); + if (resourceProperties == null) + return MethodResult.of(null, "NOT_FOUND"); + + return MethodResult.of(resourceProperties); } @Override @@ -118,8 +134,19 @@ public MethodResult listItems(IArguments arguments) throws LuaException { @Override @LuaFunction(mainThread = true) - public MethodResult listFluids(IArguments arguments) { - return null; + public MethodResult listFluids(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Pair filter = FluidFilter.parse(arguments.optTable(0, Map.of())); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + FluidFilter parsedFilter = filter.getLeft(); + + Set> resourceProperties = RefinedStorageApi.listFluids(getNetwork(), parsedFilter); + + return MethodResult.of(resourceProperties); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index 6f6295ed3..a40700a98 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -3,18 +3,26 @@ import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage.api.resource.ResourceKey; -import com.refinedmods.refinedstorage.api.storage.EmptyActor; +import com.refinedmods.refinedstorage.api.storage.Actor; import com.refinedmods.refinedstorage.api.storage.TrackedResourceAmount; +import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; +import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; +import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.common.util.LuaConverter; +import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; +import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.fluids.FluidStack; +import org.apache.logging.log4j.Level; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -35,9 +43,19 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event public static Map getItem(Network network, ItemFilter filter) { StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); - for (TrackedResourceAmount trackedResource : storage.getResources(EmptyActor.INSTANCE.getClass())) { + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if(trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { - return getObjectFromStack(trackedResource); + return getObjectFromItemResource(trackedResource); + } + } + return null; + } + + public static Map getFluid(Network network, FluidFilter filter) { + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { + if(trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { + return getObjectFromItemResource(trackedResource); } } return null; @@ -54,14 +72,44 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event public static Set> listItems(Network network, ItemFilter filter) { Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); - for (TrackedResourceAmount trackedResource : storage.getResources(EmptyActor.INSTANCE.getClass())) { + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if(trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { - items.add(getObjectFromStack(trackedResource)); + items.add(getObjectFromItemResource(trackedResource)); } } return items; } + /** + * Returns every fluid from the system while also checking if the filter test passes for the fluids + * The filter can be empty, see {@link FluidFilter#empty()} + * + * @param network the rs network + * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource + * @return a set of fluid stacks + */ + public static Set> listFluids(Network network, FluidFilter filter) { + Set> items = new HashSet<>(); + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { + if(trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { + items.add(getObjectFromItemResource(trackedResource)); + } + } + return items; + } + + public static Map getObjectFromResource(@NotNull TrackedResourceAmount trackedResource) { + if (trackedResource.resourceAmount().resource() instanceof ItemResource) { + return getObjectFromItemResource(trackedResource); + } + if (trackedResource.resourceAmount().resource() instanceof FluidResource) { + return getObjectFromFluidResource(trackedResource); + } + AdvancedPeripherals.debug("Could not create table from unknown resource " + trackedResource.resourceAmount().resource().getClass() + " - Report this to the maintainer of ap", Level.WARN); + return Collections.emptyMap(); + } + /** * Parses an RS TrackedResourceAmount to a lua object * This method assumes you did an instanceof check before that the {@link ResourceKey} is an {@link ItemResource} @@ -69,14 +117,28 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event * @param trackedResourceAmount the tracked resource amount containing an ItemResource * @return a Map containing the properties which CC can parse to a lua table */ - public static Map getObjectFromStack(TrackedResourceAmount trackedResourceAmount) { + public static Map getObjectFromItemResource(TrackedResourceAmount trackedResourceAmount) { ItemResource resource = (ItemResource) trackedResourceAmount.resourceAmount().resource(); - long amount = trackedResourceAmount.resourceAmount().amount(); + long count = trackedResourceAmount.resourceAmount().amount(); ItemStack stack = resource.toItemStack(); - Map properties = LuaConverter.stackToObject(stack); - properties.put("amount", amount); + Map properties = LuaConverter.itemStackToObject(stack, count); properties.put("fingerprint", ItemUtil.getFingerprint(stack)); + return properties; + } + /** + * Parses an RS TrackedResourceAmount to a lua object + * This method assumes you did an instanceof check before that the {@link ResourceKey} is an {@link ItemResource} + * + * @param trackedResourceAmount the tracked resource amount containing an ItemResource + * @return a Map containing the properties which CC can parse to a lua table + */ + public static Map getObjectFromFluidResource(TrackedResourceAmount trackedResourceAmount) { + FluidResource resource = (FluidResource) trackedResourceAmount.resourceAmount().resource(); + long count = trackedResourceAmount.resourceAmount().amount(); + FluidStack stack = VariantUtil.toFluidStack(resource, count); + Map properties = LuaConverter.fluidStackToObject(stack, count); + properties.put("fingerprint", FluidUtil.getFingerprint(stack)); return properties; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index a0471897f..a4837a59c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -143,10 +143,18 @@ public static Map fluidTypeToObject(FluidType type) { return map; } - public static Map itemStackToObject(@NotNull ItemStack itemStack, int amount) { - ItemStack stack = itemStack.copy(); - stack.setCount(amount); - return itemStackToObject(stack); + public static Map itemStackToObject(@NotNull ItemStack itemStack, long count) { + if (itemStack.isEmpty()) return Collections.emptyMap(); + Map map = itemStackToObject(itemStack); + map.put("count", count); + return map; + } + + public static Map fluidStackToObject(@NotNull FluidStack itemStack, long count) { + if (itemStack.isEmpty()) return Collections.emptyMap(); + Map map = fluidStackToObject(itemStack); + map.put("count", count); + return map; } /** From fcd6ec4836f9d1209342bbb093d45907c386e985 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 14 Feb 2025 00:34:28 +0100 Subject: [PATCH 07/91] Implement listCraftables functions --- .../peripheral/RSBridgePeripheral.java | 34 ++++- .../refinedstorage/RefinedStorageApi.java | 139 ++++++++++++++---- 2 files changed, 137 insertions(+), 36 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index eeddfba28..8a660c747 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -127,7 +127,7 @@ public MethodResult listItems(IArguments arguments) throws LuaException { ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.listItems(getNetwork(), parsedFilter); + Set> resourceProperties = RefinedStorageApi.listItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -144,21 +144,43 @@ public MethodResult listFluids(IArguments arguments) throws LuaException { FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.listFluids(getNetwork(), parsedFilter); + Set> resourceProperties = RefinedStorageApi.listFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @Override @LuaFunction(mainThread = true) - public MethodResult listCraftableItems(IArguments arguments) { - return null; + public MethodResult listCraftableItems(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Pair filter = ItemFilter.parse(arguments.optTable(0, Map.of())); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + ItemFilter parsedFilter = filter.getLeft(); + + Set> resourceProperties = RefinedStorageApi.listCraftableItems(getNetwork(), parsedFilter); + + return MethodResult.of(resourceProperties); } @Override @LuaFunction(mainThread = true) - public MethodResult listCraftableFluids(IArguments arguments) { - return null; + public MethodResult listCraftableFluids(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Pair filter = FluidFilter.parse(arguments.optTable(0, Map.of())); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + FluidFilter parsedFilter = filter.getLeft(); + + Set> resourceProperties = RefinedStorageApi.listCraftableFluids(getNetwork(), parsedFilter); + + return MethodResult.of(resourceProperties); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index a40700a98..de5e4c11b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -1,7 +1,9 @@ package de.srendi.advancedperipherals.common.addons.refinedstorage; import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.api.storage.Actor; import com.refinedmods.refinedstorage.api.storage.TrackedResourceAmount; @@ -29,8 +31,6 @@ /** * Refined Storage Api helper methods and parsers - * - * TODO use PlayerActor where possible */ public class RefinedStorageApi { @@ -41,21 +41,35 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event (blockEntity, side) -> blockEntity); } - public static Map getItem(Network network, ItemFilter filter) { + /** + * Returns the first item parsed to a lua object which fits to the filter + * + * @param network refined storage network + * @param filter item filter instance - can be an empty filter to get the first item of the system see {@link ItemFilter#empty()} + * @return the first item in the system that fits the item filter + */ + public static Map getItem(Network network, ItemFilter filter) { StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { - if(trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { - return getObjectFromItemResource(trackedResource); + if (trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { + return getObjectFromItemResource(trackedResource.resourceAmount()); } } return null; } - public static Map getFluid(Network network, FluidFilter filter) { + /** + * Returns the first fluid parsed to a lua object which fits to the filter + * + * @param network refined storage network + * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#empty()} + * @return the first fluid in the system that fits the fluid filter + */ + public static Map getFluid(Network network, FluidFilter filter) { StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { - if(trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { - return getObjectFromItemResource(trackedResource); + if (trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { + return getObjectFromItemResource(trackedResource.resourceAmount()); } } return null; @@ -66,15 +80,16 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event * The filter can be empty, see {@link ItemFilter#empty()} * * @param network the rs network - * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource + * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of items */ - public static Set> listItems(Network network, ItemFilter filter) { - Set> items = new HashSet<>(); + public static Set> listItems(Network network, ItemFilter filter) { + Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { - if(trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { - items.add(getObjectFromItemResource(trackedResource)); + if (trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { + items.add(getObjectFromItemResource(trackedResource.resourceAmount())); + } } return items; @@ -85,31 +100,69 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event * The filter can be empty, see {@link FluidFilter#empty()} * * @param network the rs network - * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource + * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of fluid stacks */ - public static Set> listFluids(Network network, FluidFilter filter) { - Set> items = new HashSet<>(); + public static Set> listFluids(Network network, FluidFilter filter) { + Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { - if(trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { - items.add(getObjectFromItemResource(trackedResource)); + if (trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { + items.add(getObjectFromFluidResource(trackedResource.resourceAmount())); + } + } + + return items; + } + + public static Set> listCraftableItems(Network network, ItemFilter filter) { + Set> items = new HashSet<>(); + AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (ResourceKey key : autocrafting.getOutputs()) { + if (key instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { + items.add(getObjectFromKey(key, storage.get(key))); } } return items; } - public static Map getObjectFromResource(@NotNull TrackedResourceAmount trackedResource) { - if (trackedResource.resourceAmount().resource() instanceof ItemResource) { - return getObjectFromItemResource(trackedResource); + public static Set> listCraftableFluids(Network network, FluidFilter filter) { + Set> items = new HashSet<>(); + AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (ResourceKey key : autocrafting.getOutputs()) { + long amount = storage.get(key); + if (key instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, amount))) { + items.add(getObjectFromKey(key, amount)); + } + } + return items; + } + + + private static Map getObjectFromKey(@NotNull ResourceKey resource, long count) { + boolean countZeroOrLower = count <= 0; + if (resource instanceof ItemResource) { + if (countZeroOrLower) { + return getObjectFromItemResource(new ResourceAmount(resource, 1), count); + } + return getObjectFromItemResource(new ResourceAmount(resource, count)); } - if (trackedResource.resourceAmount().resource() instanceof FluidResource) { - return getObjectFromFluidResource(trackedResource); + if (resource instanceof FluidResource) { + if (countZeroOrLower) { + return getObjectFromFluidResource(new ResourceAmount(resource, 1), count); + } + return getObjectFromFluidResource(new ResourceAmount(resource, count)); } - AdvancedPeripherals.debug("Could not create table from unknown resource " + trackedResource.resourceAmount().resource().getClass() + " - Report this to the maintainer of ap", Level.WARN); + AdvancedPeripherals.debug("Could not create table from unknown resource " + resource.getClass() + " - Report this to the maintainer of ap", Level.WARN); return Collections.emptyMap(); } + private static Map getObjectFromKey(@NotNull ResourceKey resource) { + return getObjectFromKey(resource, 0); + } + /** * Parses an RS TrackedResourceAmount to a lua object * This method assumes you did an instanceof check before that the {@link ResourceKey} is an {@link ItemResource} @@ -117,9 +170,9 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event * @param trackedResourceAmount the tracked resource amount containing an ItemResource * @return a Map containing the properties which CC can parse to a lua table */ - public static Map getObjectFromItemResource(TrackedResourceAmount trackedResourceAmount) { - ItemResource resource = (ItemResource) trackedResourceAmount.resourceAmount().resource(); - long count = trackedResourceAmount.resourceAmount().amount(); + public static Map getObjectFromItemResource(ResourceAmount trackedResourceAmount) { + ItemResource resource = (ItemResource) trackedResourceAmount.resource(); + long count = trackedResourceAmount.amount(); ItemStack stack = resource.toItemStack(); Map properties = LuaConverter.itemStackToObject(stack, count); properties.put("fingerprint", ItemUtil.getFingerprint(stack)); @@ -133,14 +186,40 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event * @param trackedResourceAmount the tracked resource amount containing an ItemResource * @return a Map containing the properties which CC can parse to a lua table */ - public static Map getObjectFromFluidResource(TrackedResourceAmount trackedResourceAmount) { - FluidResource resource = (FluidResource) trackedResourceAmount.resourceAmount().resource(); - long count = trackedResourceAmount.resourceAmount().amount(); + public static Map getObjectFromItemResource(ResourceAmount trackedResourceAmount, long alternateCount) { + Map properties = getObjectFromItemResource(trackedResourceAmount); + properties.put("count", alternateCount); + return properties; + } + + /** + * Parses an RS TrackedResourceAmount to a lua object + * This method assumes you did an instanceof check before that the {@link ResourceKey} is an {@link ItemResource} + * + * @param trackedResourceAmount the tracked resource amount containing an ItemResource + * @return a Map containing the properties which CC can parse to a lua table + */ + public static Map getObjectFromFluidResource(ResourceAmount trackedResourceAmount) { + FluidResource resource = (FluidResource) trackedResourceAmount.resource(); + long count = trackedResourceAmount.amount(); FluidStack stack = VariantUtil.toFluidStack(resource, count); Map properties = LuaConverter.fluidStackToObject(stack, count); properties.put("fingerprint", FluidUtil.getFingerprint(stack)); return properties; } + /** + * Parses an RS TrackedResourceAmount to a lua object + * This method assumes you did an instanceof check before that the {@link ResourceKey} is an {@link ItemResource} + * + * @param trackedResourceAmount the tracked resource amount containing an ItemResource + * @param alternateCount a count can be passed to overwrite the count of the object. Useful for patterns and craftable stacks + * @return a Map containing the properties which CC can parse to a lua table + */ + public static Map getObjectFromFluidResource(ResourceAmount trackedResourceAmount, long alternateCount) { + Map properties = getObjectFromFluidResource(trackedResourceAmount); + properties.put("count", alternateCount); + return properties; + } } From c2643fffa0f6aa030ab0eb0c4bc62a4725c19b27 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sat, 22 Feb 2025 18:10:22 +0100 Subject: [PATCH 08/91] Add patterns and filtered patterns support --- .../peripheral/RSBridgePeripheral.java | 64 +++++++- .../refinedstorage/RefinedStorageApi.java | 149 ++++++++++++++++-- .../common/util/inventory/FluidFilter.java | 23 ++- .../common/util/inventory/GenericFilter.java | 85 ++++++++++ .../common/util/inventory/ItemFilter.java | 23 ++- 5 files changed, 324 insertions(+), 20 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 8a660c747..c96d57539 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -1,5 +1,6 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; +import com.refinedmods.refinedstorage.api.autocrafting.Pattern; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.NetworkComponent; import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; @@ -9,6 +10,7 @@ import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.lua.MethodResult; import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageApi; @@ -16,12 +18,14 @@ import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; +import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemPeripheral; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import org.jetbrains.annotations.NotNull; import java.util.Map; +import java.util.Optional; import java.util.Set; public class RSBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { @@ -127,7 +131,7 @@ public MethodResult listItems(IArguments arguments) throws LuaException { ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.listItems(getNetwork(), parsedFilter); + Set> resourceProperties = RefinedStorageApi.getItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -144,7 +148,7 @@ public MethodResult listFluids(IArguments arguments) throws LuaException { FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.listFluids(getNetwork(), parsedFilter); + Set> resourceProperties = RefinedStorageApi.getFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -161,7 +165,7 @@ public MethodResult listCraftableItems(IArguments arguments) throws LuaException ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.listCraftableItems(getNetwork(), parsedFilter); + Set> resourceProperties = RefinedStorageApi.getCraftableItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -178,7 +182,7 @@ public MethodResult listCraftableFluids(IArguments arguments) throws LuaExceptio FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.listCraftableFluids(getNetwork(), parsedFilter); + Set> resourceProperties = RefinedStorageApi.getCraftableFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -221,14 +225,58 @@ public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) @Override @LuaFunction(mainThread = true) - public MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { - return null; + public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + // Expected input is a table with either an input table, an output table or both to filter for both + Map filterTable; + try { + Optional> optionalTable = arguments.optTable(0); + if (optionalTable.isEmpty()) + return MethodResult.of(null, "EMPTY_INPUT"); + filterTable = optionalTable.get(); + } catch (LuaException e) { + return MethodResult.of(null, "NO_TABLE"); + } + + boolean hasInputFilter = filterTable.containsKey("input"); + boolean hasOutputFilter = filterTable.containsKey("output"); + boolean hasAnyFilter = hasInputFilter || hasOutputFilter; + + // If the player tries to filter for nothing, return nothing. + if (!hasAnyFilter) + return MethodResult.of(null, "NO_FILTER"); + + GenericFilter inputFilter = null; + GenericFilter outputFilter = null; + + if (hasInputFilter) { + Map inputFilterTable = TableHelper.getTableField(filterTable, "input"); + + inputFilter = GenericFilter.parseGeneric(inputFilterTable).getLeft(); + } + if (hasOutputFilter) { + Map outputFilterTable = TableHelper.getTableField(filterTable, "output"); + + outputFilter = GenericFilter.parseGeneric(outputFilterTable).getLeft(); + } + + Pair pattern = RefinedStorageApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); + + if (pattern.getRight() != null) + return MethodResult.of(null, pattern.getRight()); + + return MethodResult.of(RefinedStorageApi.parsePattern(pattern.getLeft())); } @Override @LuaFunction(mainThread = true) - public MethodResult getPatterns() { - return null; + public final MethodResult getPatterns() { + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getPatterns(getNetwork())); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index de5e4c11b..dcc265cab 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -1,5 +1,7 @@ package de.srendi.advancedperipherals.common.addons.refinedstorage; +import com.refinedmods.refinedstorage.api.autocrafting.Ingredient; +import com.refinedmods.refinedstorage.api.autocrafting.Pattern; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; @@ -14,8 +16,10 @@ import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.common.util.LuaConverter; +import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; +import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraft.world.item.ItemStack; @@ -23,11 +27,15 @@ import net.neoforged.neoforge.fluids.FluidStack; import org.apache.logging.log4j.Level; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * Refined Storage Api helper methods and parsers @@ -83,7 +91,7 @@ public static Map getFluid(Network network, FluidFilter filter) * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of items */ - public static Set> listItems(Network network, ItemFilter filter) { + public static Set> getItems(Network network, ItemFilter filter) { Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { @@ -103,7 +111,7 @@ public static Set> listItems(Network network, ItemFilter fil * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of fluid stacks */ - public static Set> listFluids(Network network, FluidFilter filter) { + public static Set> getFluids(Network network, FluidFilter filter) { Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { @@ -115,33 +123,124 @@ public static Set> listFluids(Network network, FluidFilter f return items; } - public static Set> listCraftableItems(Network network, ItemFilter filter) { + /** + * Returns every craftable item from the system while also checking if the filter test passes for the items + * The filter can be empty, see {@link ItemFilter#empty()} + * + * @param network the rs network + * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource + * @return a set of parsed item stacks + */ + public static Set> getCraftableItems(Network network, ItemFilter filter) { Set> items = new HashSet<>(); AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (ResourceKey key : autocrafting.getOutputs()) { if (key instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { - items.add(getObjectFromKey(key, storage.get(key))); + items.add(getObjectFromResourceKey(key, storage.get(key))); } } return items; } - public static Set> listCraftableFluids(Network network, FluidFilter filter) { + /** + * Returns every craftable fluid from the system while also checking if the filter test passes for the fluids + * The filter can be empty, see {@link FluidFilter#empty()} + * + * @param network the rs network + * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource + * @return a set of parsed fluids stacks + */ + public static Set> getCraftableFluids(Network network, FluidFilter filter) { Set> items = new HashSet<>(); AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (ResourceKey key : autocrafting.getOutputs()) { long amount = storage.get(key); if (key instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, amount))) { - items.add(getObjectFromKey(key, amount)); + items.add(getObjectFromResourceKey(key, amount)); } } return items; } + public static Set getPatterns(Network network) { + Set patterns = new HashSet<>(); + AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); + + for (Pattern pattern : autocrafting.getPatterns()) { + patterns.add(parsePattern(pattern)); + } + + return patterns; + } + + /** + * Finds a pattern from filters. + * + * @param network The network to search patterns from. + * @param inputFilter The input filter to apply, can be null to ignore input filter. + * @param outputFilter The output filter to apply, can be null to ignore output filter. + * @return A Pair object containing the matched pattern and an error message if no pattern is found. + * The pattern can be null if no pattern is found. + * The error message is "NO_PATTERN_FOUND" if no pattern is found. + */ + public static Pair findPatternFromFilters(Network network, @Nullable GenericFilter inputFilter, @Nullable GenericFilter outputFilter) { + AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); + for (Pattern pattern : autocrafting.getPatterns()) { + if (pattern.layout().ingredients().isEmpty()) + continue; + if (pattern.layout().outputs().isEmpty()) + continue; + + boolean inputMatch = false; + boolean outputMatch = false; + + if (inputFilter != null) { + outerLoop: + for (Ingredient input : pattern.layout().ingredients()) { + for (ResourceKey possibleInput : input.inputs()) { + if (inputFilter.testRS(new ResourceAmount(possibleInput, 1))) { + inputMatch = true; + break outerLoop; + } + } + } + } else { + inputMatch = true; + } + + if (outputFilter != null) { + for (ResourceAmount output : pattern.layout().outputs()) { + if (outputFilter.testRS(output)) { + outputMatch = true; + break; + } + } + } else { + outputMatch = true; + } + + if (inputMatch && outputMatch) + return Pair.of(pattern, null); + } + + return Pair.of(null, "NO_PATTERN_FOUND"); + } + + + private static Map getObjectFromResourceKey(@NotNull ResourceKey resource) { + return getObjectFromResourceKey(resource, 0); + } - private static Map getObjectFromKey(@NotNull ResourceKey resource, long count) { + /** + * Helper method to get a parsed lua resource key. Currently only suppors item and fluid resources + * + * @param resource the resource + * @param count count of the resource - can be 0 and lower + * @return the parsed key to a lua properties map + */ + private static Map getObjectFromResourceKey(@NotNull ResourceKey resource, long count) { boolean countZeroOrLower = count <= 0; if (resource instanceof ItemResource) { if (countZeroOrLower) { @@ -159,8 +258,40 @@ private static Map getObjectFromKey(@NotNull ResourceKey resourc return Collections.emptyMap(); } - private static Map getObjectFromKey(@NotNull ResourceKey resource) { - return getObjectFromKey(resource, 0); + /** + * Helper method to get a parsed lua resourceAmount key. Currently only suppors item and fluid resources + * + * @param resourceAmount the resourceAmount + * @return the parsed key to a lua properties map + */ + private static Map getObjectFromResourceAmount(@NotNull ResourceAmount resourceAmount) { + if (resourceAmount.resource() instanceof ItemResource) { + return getObjectFromItemResource(resourceAmount); + } + if (resourceAmount.resource() instanceof FluidResource) { + return getObjectFromFluidResource(resourceAmount); + } + AdvancedPeripherals.debug("Could not create table from unknown resourceAmount " + resourceAmount.getClass() + " - Report this to the maintainer of ap", Level.WARN); + return Collections.emptyMap(); + } + + public static Object parsePattern(Pattern pattern) { + if (pattern == null) + return null; + + Map map = new HashMap<>(); + map.put("outputs", pattern.layout().outputs().stream().map(RefinedStorageApi::getObjectFromResourceAmount).toList()); + + List>> inputs = pattern.layout().ingredients().stream() + .map(ingredient -> ingredient.inputs().stream() + .map(key -> getObjectFromResourceKey(key, ingredient.amount())) + .collect(Collectors.toList())) + .collect(Collectors.toList()); + + map.put("inputs", inputs); + map.put("patterntype", pattern.layout().type().toString()); + map.put("id", pattern.id().toString()); + return map; } /** diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index 43e3dfb86..5b9c227ef 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -1,5 +1,10 @@ package de.srendi.advancedperipherals.common.util.inventory; +import appeng.api.stacks.AEFluidKey; +import appeng.api.stacks.GenericStack; +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -19,7 +24,7 @@ import java.util.Map; //TODO tag -public class FluidFilter { +public class FluidFilter extends GenericFilter { private Fluid fluid = Fluids.EMPTY; private TagKey tag = null; @@ -94,6 +99,22 @@ public boolean isEmpty() { return fingerprint.isEmpty() && fluid == Fluids.EMPTY && tag == null && componentsAsNbt == null; } + @Override + public boolean testAE(GenericStack genericStack) { + if (genericStack.what() instanceof AEFluidKey aeFluidKey) { + return test(aeFluidKey.toStack(1)); + } + return false; + } + + @Override + public boolean testRS(ResourceAmount resourceAmount) { + if (resourceAmount.resource() instanceof FluidResource fluidResource) { + return test(VariantUtil.toFluidStack(fluidResource, 1)); + } + return false; + } + public FluidStack toFluidStack() { var result = new FluidStack(fluid, count); result.applyComponents(components); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java new file mode 100644 index 000000000..fce07e8df --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -0,0 +1,85 @@ +package de.srendi.advancedperipherals.common.util.inventory; + +import appeng.api.stacks.GenericStack; +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import de.srendi.advancedperipherals.common.util.Pair; +import net.minecraft.core.registries.BuiltInRegistries; + +import java.util.Map; + +public abstract class GenericFilter { + + /** + * Try to parse a raw filter table to any existing filter type. Could be a fluid filter, an item filter, maybe something else + * in the future. + *

+ * If the function can't find a valid type for the given name/resource location, it will return an empty filter with + * a proper error message. + * + * @param rawFilter The raw filter, which is a map of strings and objects + * @return A pair of the parsed filter and an error message, if there is one + */ + public static Pair, String> parseGeneric(Map rawFilter) { + // TODO: Add chemical filter support + + if (!rawFilter.containsKey("name")) { + if (rawFilter.containsKey("type") && rawFilter.get("type") instanceof String type) { + switch (type) { + case "item": + return ItemFilter.parse(rawFilter); + case "fluid": + return FluidFilter.parse(rawFilter); + } + } + // If the filter does not contain a name or a type, which should never happen, but players are players, we will just + // give the ItemFilter the task to parse the filter + return ItemFilter.parse(rawFilter); + } + String name = rawFilter.get("name").toString(); + + // Let's check in which registry this thing is + if (ItemUtil.getRegistryEntry(name, BuiltInRegistries.ITEM) != null) { + return ItemFilter.parse(rawFilter); + } else if (ItemUtil.getRegistryEntry(name, BuiltInRegistries.FLUID) != null) { + return FluidFilter.parse(rawFilter); + } else { + // If the name is in neither of the registries, we will just return an empty filter + return Pair.of(empty(), "NO_VALID_FILTER_TYPE"); + } + } + + public abstract boolean isEmpty(); + + // AE2 stuff + public abstract boolean testAE(GenericStack genericStack); + + // AE2 stuff + public abstract boolean testRS(ResourceAmount resourceAmount); + + public abstract boolean test(T toTest); + + public static GenericFilter empty() { + return new GenericFilter<>() { + @Override + public boolean isEmpty() { + return true; + } + + @Override + public boolean testAE(GenericStack genericStack) { + return false; + } + + @Override + public boolean testRS(ResourceAmount resourceAmount) { + return false; + } + + @Override + public boolean test(Object toTest) { + return false; + } + }; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index c8953b985..e9d5d1f27 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -1,5 +1,9 @@ package de.srendi.advancedperipherals.common.util.inventory; +import appeng.api.stacks.AEItemKey; +import appeng.api.stacks.GenericStack; +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage.common.support.resource.ItemResource; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -18,8 +22,7 @@ import java.util.Map; -//TODO tag -public class ItemFilter { +public class ItemFilter extends GenericFilter { private Item item = Items.AIR; private TagKey tag = null; @@ -110,6 +113,22 @@ public boolean isEmpty() { return fingerprint.isEmpty() && item == Items.AIR && tag == null && componentsAsNbt == null; } + @Override + public boolean testAE(GenericStack genericStack) { + if (genericStack.what() instanceof AEItemKey aeItemKey) { + return test(aeItemKey.toStack()); + } + return false; + } + + @Override + public boolean testRS(ResourceAmount resourceAmount) { + if (resourceAmount.resource() instanceof ItemResource itemResource) { + return test(itemResource.toItemStack(1)); + } + return false; + } + public ItemStack toItemStack() { var result = new ItemStack(item, count); result.applyComponents(components); From 35b226dbeb0b9d94816d32fc729fd8cf19e8820a Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Feb 2025 20:45:15 +0100 Subject: [PATCH 09/91] Implement `listDrives` and `listCells` --- gradle.properties | 2 +- .../peripheral/RSBridgePeripheral.java | 11 ++- .../refinedstorage/RefinedStorageApi.java | 89 ++++++++++++++++++- 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index c2aa87cad..6991b93f6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.113.1 minecolonies_version=1.1.846-1.21.1-snapshot -refinedstorageVersion=2.0.0-milestone.4.13 +refinedstorageVersion=2.0.0-milestone.4.14 appliedenergistics_version=19.1.2-beta patchouli_version=1.21-87 mekanism_version=1.21.1-10.7.8.70 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index c96d57539..695bfae65 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -24,6 +24,7 @@ import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import org.jetbrains.annotations.NotNull; +import java.sql.Ref; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -190,13 +191,19 @@ public MethodResult listCraftableFluids(IArguments arguments) throws LuaExceptio @Override @LuaFunction(mainThread = true) public MethodResult listCells() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.listCells(getNetwork())); } @Override @LuaFunction(mainThread = true) public MethodResult listDrives() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.listDrives(getNetwork())); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index dcc265cab..790700e93 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -4,11 +4,19 @@ import com.refinedmods.refinedstorage.api.autocrafting.Pattern; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.impl.node.storage.StorageNetworkNode; +import com.refinedmods.refinedstorage.api.network.impl.storage.StorageConfiguration; +import com.refinedmods.refinedstorage.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.api.storage.Actor; +import com.refinedmods.refinedstorage.api.storage.StateTrackedStorage; +import com.refinedmods.refinedstorage.api.storage.Storage; import com.refinedmods.refinedstorage.api.storage.TrackedResourceAmount; +import com.refinedmods.refinedstorage.api.storage.composite.CompositeStorage; +import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; +import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; @@ -23,6 +31,8 @@ import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import net.neoforged.neoforge.fluids.FluidStack; import org.apache.logging.log4j.Level; @@ -175,6 +185,36 @@ public static Set getPatterns(Network network) { return patterns; } + public static Set listCells(Network network) { + Set disks = new HashSet<>(); + + GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); + for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { + if (nodeContainer.getNode() instanceof StorageNetworkNode storageNetworkNode) { + CompositeStorage storage = (CompositeStorage) storageNetworkNode.getStorage(); + for (Storage disk : storage.getSources()) { + if (!(disk instanceof StateTrackedStorage stateTrackedStorage)) + continue; + + disks.add(parseStorageDisk(stateTrackedStorage)); + } + } + } + return disks; + } + + public static Set listDrives(Network network) { + Set drives = new HashSet<>(); + + GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); + for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { + if (nodeContainer.getNode() instanceof StorageNetworkNode storageNetworkNode) { + drives.add(parseDiskDrive(storageNetworkNode, nodeContainer)); + } + } + return drives; + } + /** * Finds a pattern from filters. * @@ -228,7 +268,6 @@ public static Pair findPatternFromFilters(Network network, @Nul return Pair.of(null, "NO_PATTERN_FOUND"); } - private static Map getObjectFromResourceKey(@NotNull ResourceKey resource) { return getObjectFromResourceKey(resource, 0); } @@ -275,6 +314,54 @@ private static Map getObjectFromResourceAmount(@NotNull Resource return Collections.emptyMap(); } + public static Object parseDiskDrive(StorageNetworkNode diskDrive, InWorldNetworkNodeContainer nodeContainer) { + Map properties = new HashMap<>(); + + StorageConfiguration storageConfiguration = diskDrive.getStorageConfiguration(); + CompositeStorage storage = (CompositeStorage) diskDrive.getStorage(); + + Set disks = new HashSet<>(); + for (Storage disk : storage.getSources()) { + if (!(disk instanceof StateTrackedStorage stateTrackedStorage)) + continue; + + disks.add(parseStorageDisk(stateTrackedStorage)); + } + + properties.put("used", diskDrive.getStored()); + properties.put("total", diskDrive.getCapacity()); + properties.put("disks", disks); + properties.put("mode", storageConfiguration.getFilterMode().toString()); + //TODO Redstone mode + properties.put("redstone_mode", false); + properties.put("access_type", storageConfiguration.getAccessMode().toString()); + properties.put("position", LuaConverter.posToObject(nodeContainer.getLocalPosition())); + properties.put("priority", nodeContainer.getPriority()); + + return properties; + } + + public static Object parseStorageDisk(StateTrackedStorage disk) { + Map properties = new HashMap<>(); + + properties.put("used", disk.getStored()); + properties.put("capacity", disk.getCapacity()); + properties.put("state", disk.getState().toString()); + if (disk.getDelegate() instanceof SerializableStorage serializableStorage) { + String type; + if (serializableStorage.getType().isAllowed(new ItemResource(Items.DIRT))) { + type = "item"; + } else if (serializableStorage.getType().isAllowed(new FluidResource(Fluids.WATER))) { + type = "fluid"; + } else { + type = "unknown"; + } + properties.put("type", type); + } + + return properties; + } + public static Object parsePattern(Pattern pattern) { if (pattern == null) return null; From faf98c2cb67a8161226d2b13bebbed7f7b20e2e6 Mon Sep 17 00:00:00 2001 From: endi Date: Wed, 26 Feb 2025 15:41:56 +0100 Subject: [PATCH 10/91] Implement `getStoredEnergy` and `getEnergyCapacity`. Remove `getFilteredPatterns` and add the filter option to `getPatterns` --- build.gradle | 2 +- .../peripheral/RSBridgePeripheral.java | 52 ++++++++++--------- .../inventory/IStorageSystemPeripheral.java | 4 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index 6a36af0ff..045c75cea 100644 --- a/build.gradle +++ b/build.gradle @@ -216,7 +216,7 @@ dependencies { // Extended requirements // We don't use the api since we need a specific class from mekanism compileOnly "mekanism:Mekanism:${mekanism_version}" - //runtimeOnly "mekanism:Mekanism:${mekanism_version}" + runtimeOnly "mekanism:Mekanism:${mekanism_version}" // Applied Energistics 2 runtimeOnly "appeng:appliedenergistics2:${appliedenergistics_version}" diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 695bfae65..0a742815c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -4,7 +4,7 @@ import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.NetworkComponent; import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; -import com.refinedmods.refinedstorage.api.network.node.NetworkNode; +import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; @@ -24,9 +24,8 @@ import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; import org.jetbrains.annotations.NotNull; -import java.sql.Ref; +import java.util.Collections; import java.util.Map; -import java.util.Optional; import java.util.Set; public class RSBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { @@ -43,8 +42,8 @@ public boolean isEnabled() { return APAddons.refinedStorageLoaded && APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); } - private NetworkNode getNode() { - return owner.tileEntity.getNode(); + private AbstractNetworkNode getNode() { + return (AbstractNetworkNode) owner.tileEntity.getNode(); } private Network getNetwork() { @@ -60,7 +59,7 @@ private I getComponent(@NotNull Class componentC } private boolean isAvailable() { - return true; + return getNode().isActive(); } @Override @@ -232,19 +231,15 @@ public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) @Override @LuaFunction(mainThread = true) - public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaException { + public final MethodResult getPatterns(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); // Expected input is a table with either an input table, an output table or both to filter for both - Map filterTable; - try { - Optional> optionalTable = arguments.optTable(0); - if (optionalTable.isEmpty()) - return MethodResult.of(null, "EMPTY_INPUT"); - filterTable = optionalTable.get(); - } catch (LuaException e) { - return MethodResult.of(null, "NO_TABLE"); + // If no table is provided or it's empty, return every pattern + Map filterTable = arguments.optTable(0, Collections.emptyMap()); + if (filterTable.isEmpty()) { + return MethodResult.of(RefinedStorageApi.getPatterns(getNetwork())); } boolean hasInputFilter = filterTable.containsKey("input"); @@ -279,35 +274,42 @@ public final MethodResult getFilteredPatterns(IArguments arguments) throws LuaEx @Override @LuaFunction(mainThread = true) - public final MethodResult getPatterns() { + public MethodResult getStoredEnergy() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getPatterns(getNetwork())); - } + EnergyNetworkComponent energyComponent = getNetwork().getComponent(EnergyNetworkComponent.class); - @Override - @LuaFunction(mainThread = true) - public MethodResult getStoredEnergy() { - return null; + return MethodResult.of(energyComponent.getStored()); } @Override @LuaFunction(mainThread = true) public MethodResult getEnergyCapacity() { - return null; + if (!isAvailable()) + return notConnected(); + + EnergyNetworkComponent energyComponent = getNetwork().getComponent(EnergyNetworkComponent.class); + + return MethodResult.of(energyComponent.getCapacity()); } @Override @LuaFunction(mainThread = true) public MethodResult getEnergyUsage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(0); } @Override @LuaFunction(mainThread = true) public MethodResult getAvgPowerInjection() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(0); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index b775ea2de..76a40b350 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -49,9 +49,7 @@ public interface IStorageSystemPeripheral { MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult getFilteredPatterns(IArguments arguments) throws LuaException; - - MethodResult getPatterns(); + MethodResult getPatterns(IArguments arguments) throws LuaException; MethodResult getStoredEnergy(); From 7bb56858f9f09f0d65d5a3367a3bc1e266d7ac94 Mon Sep 17 00:00:00 2001 From: endi Date: Wed, 26 Feb 2025 16:58:39 +0100 Subject: [PATCH 11/91] Implement used, total and available storage functions for internal and external storages with chemical support --- build.gradle | 22 ++++- gradle.properties | 5 +- .../peripheral/RSBridgePeripheral.java | 95 +++++++++++++++---- .../refinedstorage/RefinedStorageApi.java | 85 ++++++++++++++++- 4 files changed, 182 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index 045c75cea..9cb4e430d 100644 --- a/build.gradle +++ b/build.gradle @@ -178,6 +178,17 @@ repositories { password = "\u0067hp_oGjcDFCn8jeTzIj4Ke9pLoEVtpnZMP4VQgaX" } } + maven { + url = uri("https://maven.pkg.github.com/refinedmods/refinedstorage-mekanism-integration") + credentials { + username = "anything" + password = "\u0067hp_oGjcDFCn8jeTzIj4Ke9pLoEVtpnZMP4VQgaX" + } + } + maven { + name = "EMI" + url = uri("https://maven.terraformersmc.com/") + } maven { name = 'Kotlin for Forge' url = 'https://thedarkcolour.github.io/KotlinForForge/' @@ -210,8 +221,15 @@ dependencies { implementation "cc.tweaked:cc-tweaked-${minecraft_version}-forge:${cc_version}" // Minimal requirements end - compileOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorageVersion}") - runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorageVersion}") + compileOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorage_version}") + runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorage_version}") + + compileOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") + runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") + + // Needed for the refined storage mek integration + compileOnlyApi("dev.emi:emi-neoforge:${emiVersion}") + // Extended requirements // We don't use the api since we need a specific class from mekanism diff --git a/gradle.properties b/gradle.properties index 6991b93f6..cad1d50e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,8 @@ ttoolkit_version=0.1.3 # Mod dependencies cc_version=1.113.1 minecolonies_version=1.1.846-1.21.1-snapshot -refinedstorageVersion=2.0.0-milestone.4.14 +refinedstorage_version=2.0.0-milestone.4.14 +refinedstorage_mekanism_version=0.3.0 appliedenergistics_version=19.1.2-beta patchouli_version=1.21-87 mekanism_version=1.21.1-10.7.8.70 @@ -41,6 +42,8 @@ structurize_version=1.0.755-1.21.1-snapshot multipiston_version=1.2.51-1.21.1-snapshot blockui_version=1.0.192-1.21.1-snapshot domumornamentum_version=1.0.204-1.21.1-snapshot +# For refined storage mek integration +emiVersion=1.1.11+1.21 # Mod dependencies for testing stuff(Only used in the dev environment) jei_version=1.21.1-neoforge:19.19.6.235 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 0a742815c..832a5138e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -5,6 +5,8 @@ import com.refinedmods.refinedstorage.api.network.NetworkComponent; import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage.common.storage.StorageTypes; +import com.refinedmods.refinedstorage.mekanism.ChemicalResourceType; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; @@ -59,7 +61,7 @@ private I getComponent(@NotNull Class componentC } private boolean isAvailable() { - return getNode().isActive(); + return true; } @Override @@ -315,109 +317,162 @@ public MethodResult getAvgPowerInjection() { @Override @LuaFunction(mainThread = true) public MethodResult getTotalExternItemStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) public MethodResult getTotalExternFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) public MethodResult getTotalExternChemicalStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @LuaFunction(mainThread = true) public MethodResult getTotalItemStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) public MethodResult getTotalFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) public MethodResult getTotalChemicalStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @LuaFunction(mainThread = true) public MethodResult getUsedExternItemStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getUsedExternStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) public MethodResult getUsedExternFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getUsedExternStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) public MethodResult getUsedExternChemicalStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @LuaFunction(mainThread = true) public MethodResult getUsedItemStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getUsedStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) public MethodResult getUsedFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getUsedStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) public MethodResult getUsedChemicalStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getUsedStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @LuaFunction(mainThread = true) public MethodResult getAvailableExternItemStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), StorageTypes.ITEM) - RefinedStorageApi.getUsedExternStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) public MethodResult getAvailableExternFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), StorageTypes.FLUID) - RefinedStorageApi.getUsedExternStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) public MethodResult getAvailableExternChemicalStorage() { - return null; - } + if (!isAvailable()) + return notConnected(); + return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RefinedStorageApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + } @Override @LuaFunction(mainThread = true) public MethodResult getAvailableItemStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), StorageTypes.ITEM) - RefinedStorageApi.getUsedStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) public MethodResult getAvailableFluidStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), StorageTypes.FLUID) - RefinedStorageApi.getUsedStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) public MethodResult getAvailableChemicalStorage() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RefinedStorageApi.getUsedStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index 790700e93..e1e36e229 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -4,6 +4,8 @@ import com.refinedmods.refinedstorage.api.autocrafting.Pattern; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.impl.node.externalstorage.ExposedExternalStorage; +import com.refinedmods.refinedstorage.api.network.impl.node.externalstorage.ExternalStorageNetworkNode; import com.refinedmods.refinedstorage.api.network.impl.node.storage.StorageNetworkNode; import com.refinedmods.refinedstorage.api.network.impl.storage.StorageConfiguration; import com.refinedmods.refinedstorage.api.network.node.GraphNetworkComponent; @@ -16,9 +18,13 @@ import com.refinedmods.refinedstorage.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage.api.storage.composite.CompositeStorage; import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; +import com.refinedmods.refinedstorage.common.api.storage.StorageType; import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; +import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType; +import com.refinedmods.refinedstorage.common.storage.StorageTypes; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -268,6 +274,81 @@ public static Pair findPatternFromFilters(Network network, @Nul return Pair.of(null, "NO_PATTERN_FOUND"); } + public static long getTotalStorage(Network network, StorageType type) { + long total = 0; + + GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); + for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { + if (nodeContainer.getNode() instanceof StorageNetworkNode storageNetworkNode) { + CompositeStorage storage = (CompositeStorage) storageNetworkNode.getStorage(); + for (Storage disk : storage.getSources()) { + if (!(disk instanceof StateTrackedStorage stateTrackedStorage)) + continue; + + if (stateTrackedStorage.getDelegate() instanceof SerializableStorage serializableStorage) { + if (serializableStorage.getType() != type) + continue; + } + + total += stateTrackedStorage.getCapacity(); + } + } + } + return total; + } + + public static long getUsedStorage(Network network, StorageType type) { + long used = 0; + + GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); + for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { + if (nodeContainer.getNode() instanceof StorageNetworkNode storageNetworkNode) { + CompositeStorage storage = (CompositeStorage) storageNetworkNode.getStorage(); + for (Storage disk : storage.getSources()) { + if (!(disk instanceof StateTrackedStorage stateTrackedStorage)) + continue; + + if (stateTrackedStorage.getDelegate() instanceof SerializableStorage serializableStorage) { + if (serializableStorage.getType() != type) + continue; + } + + used += stateTrackedStorage.getStored(); + } + } + } + return used; + } + + public static long getTotalExternStorage(Network network, StorageType type) { + long total = 0; + + GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); + for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { + if (nodeContainer.getNode() instanceof ExternalStorageNetworkNode storageNetworkNode) { + ExposedExternalStorage storage = (ExposedExternalStorage) storageNetworkNode.getStorage(); + // TODO + } + + } + return total; + } + + public static long getUsedExternStorage(Network network, StorageType type) { + long used = 0; + + GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); + for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { + if (nodeContainer.getNode() instanceof ExternalStorageNetworkNode storageNetworkNode) { + ExposedExternalStorage storage = (ExposedExternalStorage) storageNetworkNode.getStorage(); + + used += storage.getAll().stream().filter(amount -> type.isAllowed(amount.resource())).mapToLong(ResourceAmount::amount).sum(); + } + + } + return used; + } + private static Map getObjectFromResourceKey(@NotNull ResourceKey resource) { return getObjectFromResourceKey(resource, 0); } @@ -349,9 +430,9 @@ public static Object parseStorageDisk(StateTrackedStorage disk) { properties.put("state", disk.getState().toString()); if (disk.getDelegate() instanceof SerializableStorage serializableStorage) { String type; - if (serializableStorage.getType().isAllowed(new ItemResource(Items.DIRT))) { + if (serializableStorage.getType() == StorageTypes.ITEM) { type = "item"; - } else if (serializableStorage.getType().isAllowed(new FluidResource(Fluids.WATER))) { + } else if (serializableStorage.getType() == StorageTypes.FLUID) { type = "fluid"; } else { type = "unknown"; From e1bb4c45c5d2eadb7403efdf4742539f4aba440c Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Feb 2025 15:26:29 +0100 Subject: [PATCH 12/91] implement import and export functions --- .../peripheral/RSBridgePeripheral.java | 122 ++++++++++++++++-- .../refinedstorage/RefinedStorageApi.java | 54 ++++++-- .../addons/refinedstorage/RsFluidHandler.java | 48 +++++++ .../addons/refinedstorage/RsItemHandler.java | 52 ++++++++ .../common/util/inventory/InventoryUtil.java | 6 +- 5 files changed, 260 insertions(+), 22 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 832a5138e..126b8928a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -16,15 +16,22 @@ import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageApi; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RsFluidHandler; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RsItemHandler; import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; +import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemPeripheral; +import de.srendi.advancedperipherals.common.util.inventory.InventoryUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.Map; @@ -64,6 +71,86 @@ private boolean isAvailable() { return true; } + /** + * exports an item out of the system to a valid inventory + * + * @param arguments the arguments given by the computer + * @param targetInventory the give inventory + * @return the exportable amount or null with a string if something went wrong + */ + protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { + RsItemHandler itemHandler = new RsItemHandler(getNetwork()); + Pair filter = ItemFilter.parse(arguments.getTable(0)); + + if (filter.rightPresent()) + return MethodResult.of(0, filter.getRight()); + + if (targetInventory == null) + return MethodResult.of(0, "Target Inventory does not exist"); + + return MethodResult.of(InventoryUtil.moveItem(itemHandler, targetInventory, filter.getLeft()), null); + } + + /** + * exports a fluid out of the system to a valid tank + * + * @param arguments the arguments given by the computer + * @param targetTank the give tank + * @return the exportable amount or null with a string if something went wrong + */ + protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFluidHandler targetTank) throws LuaException { + RsFluidHandler fluidHandler = new RsFluidHandler(getNetwork()); + Pair filter = FluidFilter.parse(arguments.getTable(0)); + + if (filter.rightPresent()) + return MethodResult.of(0, filter.getRight()); + + if (targetTank == null) + return MethodResult.of(0, "Target Tank does not exist"); + + return MethodResult.of(InventoryUtil.moveFluid(fluidHandler, targetTank, filter.getLeft()), null); + } + + /** + * imports an item to the system from a valid inventory + * + * @param arguments the arguments given by the computer + * @param targetInventory the give inventory + * @return the imported amount or null with a string if something went wrong + */ + protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { + RsItemHandler itemHandler = new RsItemHandler(getNetwork()); + Pair filter = ItemFilter.parse(arguments.getTable(0)); + + if (filter.rightPresent()) + return MethodResult.of(0, filter.getRight()); + + if (targetInventory == null) + return MethodResult.of(0, "Target Inventory does not exist"); + + return MethodResult.of(InventoryUtil.moveItem(targetInventory, itemHandler, filter.getLeft()), null); + } + + /** + * imports a fluid to the system from a valid tank + * + * @param arguments the arguments given by the computer + * @param targetTank the give tank + * @return the imported amount or null with a string if something went wrong + */ + protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IFluidHandler targetTank) throws LuaException { + RsFluidHandler fluidHandler = new RsFluidHandler(getNetwork()); + Pair filter = FluidFilter.parse(arguments.getTable(0)); + + if (filter.rightPresent()) + return MethodResult.of(0, filter.getRight()); + + if (targetTank == null) + return MethodResult.of(0, "Target Tank does not exist"); + + return MethodResult.of(InventoryUtil.moveFluid(targetTank, fluidHandler, filter.getLeft()), null); + } + @Override @LuaFunction(mainThread = true) public MethodResult isConnected() { @@ -93,7 +180,7 @@ public MethodResult getItem(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - Map resourceProperties = RefinedStorageApi.getItem(getNetwork(), parsedFilter); + Map resourceProperties = RefinedStorageApi.getParsedItem(getNetwork(), parsedFilter); if (resourceProperties == null) return MethodResult.of(null, "NOT_FOUND"); @@ -114,7 +201,7 @@ public MethodResult getFluid(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - Map resourceProperties = RefinedStorageApi.getFluid(getNetwork(), parsedFilter); + Map resourceProperties = RefinedStorageApi.getParsedFluid(getNetwork(), parsedFilter); if (resourceProperties == null) return MethodResult.of(null, "NOT_FOUND"); @@ -133,7 +220,7 @@ public MethodResult listItems(IArguments arguments) throws LuaException { ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.getItems(getNetwork(), parsedFilter); + Set> resourceProperties = RefinedStorageApi.getParsedItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -150,7 +237,7 @@ public MethodResult listFluids(IArguments arguments) throws LuaException { FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.getFluids(getNetwork(), parsedFilter); + Set> resourceProperties = RefinedStorageApi.getParsedFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -209,26 +296,42 @@ public MethodResult listDrives() { @Override @LuaFunction(mainThread = true) - public MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { - return null; + public final MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + return importToRS(arguments, inventory); } @Override @LuaFunction(mainThread = true) public MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + return exportToChest(arguments, inventory); } @Override @LuaFunction(mainThread = true) public MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + return importToRS(arguments, handler); } @Override @LuaFunction(mainThread = true) public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + return exportToTank(arguments, handler); } @Override @@ -448,6 +551,7 @@ public MethodResult getAvailableExternChemicalStorage() { return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RefinedStorageApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } + @Override @LuaFunction(mainThread = true) public MethodResult getAvailableItemStorage() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index e1e36e229..09f023a89 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -20,11 +20,9 @@ import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; import com.refinedmods.refinedstorage.common.api.storage.StorageType; import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; -import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType; import com.refinedmods.refinedstorage.common.storage.StorageTypes; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; -import com.refinedmods.refinedstorage.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -37,8 +35,6 @@ import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import net.neoforged.neoforge.fluids.FluidStack; import org.apache.logging.log4j.Level; @@ -65,14 +61,51 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event (blockEntity, side) -> blockEntity); } + /** + * Returns the first item resource that fits to the filter + * + * @param network refined storage network + * @param filter item filter instance - can be an empty filter to get the first item of the system see {@link ItemFilter#empty()} + * @return the first item in the system that fits the item filter or null + */ + @Nullable + public static ItemResource getItem(Network network, ItemFilter filter) { + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { + if (trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { + return itemResource; + } + } + return null; + } + + /** + * Returns the first fluid parsed to a lua object which fits to the filter + * + * @param network refined storage network + * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#empty()} + * @return the first fluid in the system that fits the fluid filter or null + */ + @Nullable + public static FluidResource getFluid(Network network, FluidFilter filter) { + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { + if (trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { + return fluidResource; + } + } + return null; + } + /** * Returns the first item parsed to a lua object which fits to the filter * * @param network refined storage network * @param filter item filter instance - can be an empty filter to get the first item of the system see {@link ItemFilter#empty()} - * @return the first item in the system that fits the item filter + * @return the first item in the system that fits the item filter or null */ - public static Map getItem(Network network, ItemFilter filter) { + @Nullable + public static Map getParsedItem(Network network, ItemFilter filter) { StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if (trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { @@ -87,9 +120,10 @@ public static Map getItem(Network network, ItemFilter filter) { * * @param network refined storage network * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#empty()} - * @return the first fluid in the system that fits the fluid filter + * @return the first fluid in the system that fits the fluid filter or null */ - public static Map getFluid(Network network, FluidFilter filter) { + @Nullable + public static Map getParsedFluid(Network network, FluidFilter filter) { StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if (trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { @@ -107,7 +141,7 @@ public static Map getFluid(Network network, FluidFilter filter) * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of items */ - public static Set> getItems(Network network, ItemFilter filter) { + public static Set> getParsedItems(Network network, ItemFilter filter) { Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { @@ -127,7 +161,7 @@ public static Set> getItems(Network network, ItemFilter filt * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of fluid stacks */ - public static Set> getFluids(Network network, FluidFilter filter) { + public static Set> getParsedFluids(Network network, FluidFilter filter) { Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java new file mode 100644 index 000000000..e19c0cf68 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java @@ -0,0 +1,48 @@ +package de.srendi.advancedperipherals.common.addons.refinedstorage; + +import com.refinedmods.refinedstorage.api.core.Action; +import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage.api.storage.Actor; +import com.refinedmods.refinedstorage.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; +import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemFluidHandler; +import net.neoforged.neoforge.fluids.FluidStack; +import org.jetbrains.annotations.NotNull; + +public class RsFluidHandler implements IStorageSystemFluidHandler { + + @NotNull + private final Network network; + private final StorageNetworkComponent component; + + public RsFluidHandler(@NotNull Network network) { + this.network = network; + this.component = network.getComponent(StorageNetworkComponent.class); + + } + + @Override + public int fill(FluidStack resource, @NotNull FluidAction action) { + if (resource.isEmpty()) + return 0; + return (int) (resource.getAmount() - component.insert(VariantUtil.ofFluidStack(resource), resource.getAmount(), action == FluidAction.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + } + + @NotNull + @Override + public FluidStack drain(FluidFilter filter, FluidAction simulate) { + AdvancedPeripherals.debug("Trying to extract fluid from filter: " + filter); + FluidResource fluid = RefinedStorageApi.getFluid(network, filter); + if (fluid == null) + return FluidStack.EMPTY; + + FluidStack extracted = VariantUtil.toFluidStack(fluid, 1); + extracted.setAmount((int) component.extract(fluid, filter.getCount(), simulate == FluidAction.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + + AdvancedPeripherals.debug("Extracted fluid: " + extracted + " from filter: " + filter); + return extracted; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java new file mode 100644 index 000000000..0b9e5d75b --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java @@ -0,0 +1,52 @@ +package de.srendi.advancedperipherals.common.addons.refinedstorage; + +import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage.api.storage.Actor; +import com.refinedmods.refinedstorage.common.support.resource.ItemResource; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemItemHandler; +import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; +import com.refinedmods.refinedstorage.api.core.Action; + +/** + * Used to transfer item between an inventory and the RS system. + * + * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RSBridgePeripheral + */ +public class RsItemHandler implements IStorageSystemItemHandler { + + @NotNull + private final Network network; + private final StorageNetworkComponent component; + + public RsItemHandler(@NotNull Network network) { + this.network = network; + this.component = network.getComponent(StorageNetworkComponent.class); + } + + @NotNull + @Override + public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { + ItemStack inserted = stack.copy(); + inserted.setCount((int) (stack.getCount() - component.insert(ItemResource.ofItemStack(stack), stack.getCount(), simulate ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY))); + return inserted; + } + + @Override + public ItemStack extractItem(ItemFilter filter, int count, boolean simulate) { + AdvancedPeripherals.debug("Trying to extract item from filter: " + filter); + ItemResource itemResource = RefinedStorageApi.getItem(network, filter); + if (itemResource == null) + return ItemStack.EMPTY; + + ItemStack extracted = itemResource.toItemStack(); + extracted.setCount((int) component.extract(itemResource, count, simulate ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + + AdvancedPeripherals.debug("Extracted item: " + extracted + " from filter: " + filter); + return extracted; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java index 9f4a1819a..15cf171b0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java @@ -77,10 +77,10 @@ public static int moveItem(IItemHandler inventoryFrom, IItemHandler inventoryTo, ItemStack extracted = inventoryFrom.extractItem(i, amount - transferableAmount, true); if (extracted.isEmpty()) continue; - ItemStack inserted = storageSystemHandler.insertItem(toSlot, extracted, false); + ItemStack remaining = storageSystemHandler.insertItem(toSlot, extracted, false); - amount -= inserted.getCount(); - transferableAmount += inventoryFrom.extractItem(i, extracted.getCount() - inserted.getCount(), false).getCount(); + amount -= remaining.getCount(); + transferableAmount += inventoryFrom.extractItem(i, extracted.getCount() - remaining.getCount(), false).getCount(); if (transferableAmount >= filter.getCount()) break; } From 2d4f391ca9ecc085790ab27522f557791b1b5af8 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Feb 2025 16:00:44 +0100 Subject: [PATCH 13/91] Added peripheral block support and make some inventory and fluid util methods nullable to support both at once --- .../peripheral/RSBridgePeripheral.java | 26 +++++++++++++++++++ .../common/util/CoordUtil.java | 5 ++-- .../common/util/inventory/FluidUtil.java | 9 +++---- .../common/util/inventory/InventoryUtil.java | 2 ++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 126b8928a..ad2f42abb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -301,6 +301,13 @@ public final MethodResult importItem(IComputerAccess computer, IArguments argume return notConnected(); IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + + if (inventory == null) + inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + + if (inventory == null) + return MethodResult.of(0, "The target inventory does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return importToRS(arguments, inventory); } @@ -311,6 +318,13 @@ public MethodResult exportItem(IComputerAccess computer, IArguments arguments) t return notConnected(); IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); + + if (inventory == null) + inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); + + if (inventory == null) + return MethodResult.of(0, "The target inventory does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return exportToChest(arguments, inventory); } @@ -321,6 +335,12 @@ public MethodResult importFluid(IComputerAccess computer, IArguments arguments) return notConnected(); IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + if (handler == null) + handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + + if (handler == null) + return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return importToRS(arguments, handler); } @@ -331,6 +351,12 @@ public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) return notConnected(); IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); + if (handler == null) + handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); + + if (handler == null) + return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return exportToTank(arguments, handler); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java index d953cbbfd..186aa9beb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java @@ -104,9 +104,10 @@ public static boolean isInRange(@Nullable BlockPos blockPos, @Nullable Player pl return world.getNearbyPlayers(TargetingConditions.forNonCombat(), null, new AABB(firstPos.getX(), firstPos.getY(), firstPos.getZ(), secondPos.getX(), secondPos.getY(), secondPos.getZ())).contains(player); } + @Nullable public static Direction getDirection(FrontAndTop orientation, String computerSide) throws LuaException { if (computerSide == null) { - throw new LuaException("null is not a valid side"); + return null; } computerSide = computerSide.toLowerCase(Locale.ROOT); @@ -118,7 +119,7 @@ public static Direction getDirection(FrontAndTop orientation, String computerSid final ComputerSide side = ComputerSide.valueOfInsensitive(computerSide); if (side == null) { - throw new LuaException(computerSide + " is not a valid side"); + return null; } if (front.getAxis() == Direction.Axis.Y) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java index 67b6e5a08..5218219e3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java @@ -43,19 +43,16 @@ public static IFluidHandler extractHandler(@Nullable Object object, @Nullable Le return null; } - @NotNull + @Nullable public static IFluidHandler getHandlerFromDirection(@NotNull String direction, @NotNull IPeripheralOwner owner) throws LuaException { Level level = owner.getLevel(); Objects.requireNonNull(level); Direction relativeDirection = CoordUtil.getDirection(owner.getOrientation(), direction); BlockEntity target = level.getBlockEntity(owner.getPos().relative(relativeDirection)); if (target == null) - throw new LuaException("Target '" + direction + "' is empty or not a fluid handler"); + return null; - IFluidHandler handler = extractHandler(target, level, owner.getPos().relative(relativeDirection), relativeDirection); - if (handler == null) - throw new LuaException("Target '" + direction + "' is not a fluid handler"); - return handler; + return extractHandler(target, level, owner.getPos().relative(relativeDirection), relativeDirection); } @Nullable diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java index 15cf171b0..b0900f857 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java @@ -158,6 +158,8 @@ public static IItemHandler getHandlerFromDirection(@NotNull String direction, @N Level level = owner.getLevel(); Objects.requireNonNull(level); Direction relativeDirection = CoordUtil.getDirection(owner.getOrientation(), direction); + if (relativeDirection == null) + return null; BlockEntity target = level.getBlockEntity(owner.getPos().relative(relativeDirection)); if (target == null) return null; From a5ccc5a05045f48f43b121623ce77c017e2cfe31 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 3 Mar 2025 23:20:50 +0100 Subject: [PATCH 14/91] Somewhat implemented the craftItems function, but it's not done yet. The items can be requested, but we are currently unable to give the players more information - already in discussion with the rs2 maintainer --- .../peripheral/RSBridgePeripheral.java | 47 +++- .../addons/refinedstorage/RSCraftJob.java | 187 ++++++++++++++++ .../refinedstorage/RefinedStorageApi.java | 4 +- .../blocks/blockentities/RsBridgeEntity.java | 56 ++++- .../common/util/StatusConstants.java | 44 ++++ .../common/util/inventory/BasicCraftJob.java | 206 ++++++++++++++++++ .../inventory/IStorageSystemPeripheral.java | 13 +- 7 files changed, 549 insertions(+), 8 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index ad2f42abb..2839242d5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -3,9 +3,11 @@ import com.refinedmods.refinedstorage.api.autocrafting.Pattern; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.NetworkComponent; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage.common.storage.StorageTypes; +import com.refinedmods.refinedstorage.common.support.resource.ItemResource; import com.refinedmods.refinedstorage.mekanism.ChemicalResourceType; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; @@ -15,6 +17,7 @@ import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSCraftJob; import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageApi; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsFluidHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsItemHandler; @@ -41,8 +44,11 @@ public class RSBridgePeripheral extends BasePeripheral(owner)); + this.bridge = owner; } @Override @@ -608,6 +614,31 @@ public MethodResult getAvailableChemicalStorage() { @Override @LuaFunction(mainThread = true) public MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Pair filter = ItemFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + ItemResource stack = RefinedStorageApi.getItem(getNetwork(), filter.getLeft()); + if (stack == null) + return MethodResult.of(null, "NOT_CRAFTABLE"); + + RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), stack, getNetwork().getComponent(AutocraftingNetworkComponent.class)); + bridge.addJob(job); + return MethodResult.of(job); + } + + + @Override + @LuaFunction(mainThread = true) + public MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + public MethodResult craftChemical(IComputerAccess computer, IArguments arguments) throws LuaException { return null; } @@ -618,17 +649,17 @@ public MethodResult getCraftingTasks() { } @Override - @LuaFunction(mainThread = true) - public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { + public MethodResult getCraftingJob(int id) { return null; } @Override @LuaFunction(mainThread = true) - public MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { return null; } + @Override @LuaFunction(mainThread = true) public MethodResult isItemCraftable(IArguments arguments) throws LuaException { @@ -652,4 +683,14 @@ public MethodResult isFluidCraftable(IArguments arguments) throws LuaException { public MethodResult isFluidCrafting(IArguments arguments) throws LuaException { return null; } + + @Override + public MethodResult isChemicalCraftable(IArguments arguments) throws LuaException { + return null; + } + + @Override + public MethodResult isChemicalCrafting(IArguments arguments) throws LuaException { + return null; + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java new file mode 100644 index 000000000..6c4130f92 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -0,0 +1,187 @@ +package de.srendi.advancedperipherals.common.addons.refinedstorage; + +import com.refinedmods.refinedstorage.api.autocrafting.preview.Preview; +import com.refinedmods.refinedstorage.api.autocrafting.preview.PreviewType; +import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.api.storage.Actor; +import dan200.computercraft.api.peripheral.IComputerAccess; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.util.StatusConstants; +import de.srendi.advancedperipherals.common.util.inventory.BasicCraftJob; +import net.minecraft.world.level.Level; + +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public class RSCraftJob extends BasicCraftJob { + + private final AutocraftingNetworkComponent autocraftingComponent; + private final ResourceKey toCraft; + + private TaskStatus craftingTask; + private Future> futureTask; + + public RSCraftJob(IComputerAccess computer, Level world, long amount, ResourceKey toCraft, AutocraftingNetworkComponent calculationResult) { + super(computer, "rs", world, amount); + this.autocraftingComponent = calculationResult; + this.toCraft = toCraft; + } + + @Override + protected boolean isJobDone() { + return craftingTask != null && craftingTask.percentageCompleted() == 100; + } + + @Override + protected boolean isJobCanceled() { + return craftingTask != null && craftingTask.percentageCompleted() != 100 && autocraftingComponent.getStatuses().stream().noneMatch(task -> task.info().id() == craftingTask.info().id()); + } + + @Override + public Object getParsedRequestedItem() { + return RefinedStorageApi.getObjectFromResourceKey(toCraft, amount); + } + + @Override + public long getElapsedTime() { + if (craftingTask == null) { + return -1; + } + return System.currentTimeMillis() - craftingTask.info().startTime(); + } + + @Override + public long getTotalItems() { + if (craftingTask == null) { + return -1; + } + + return craftingTask.items().size(); + } + + @Override + public long getItemProgress() { + return craftingTask == null ? 0 : craftingTask.items().stream().mapToLong(TaskStatus.Item::stored).sum(); + } + + @Override + public Object getEmittedItems() { + return null; + } + + @Override + public Object getUsedItems() { + return null; + } + + @Override + public Object getMissingItems() { + return null; + } + + @Override + public boolean hasMultiplePaths() { + return false; + } + + @Override + public Object getFinalOutput() { + return null; + } + + public TaskStatus getCraftingTask() { + return craftingTask; + } + + @Override + public boolean cancel() { + if (isJobDone() || isJobCanceled()) { + return false; + } + autocraftingComponent.cancel(craftingTask.info().id()); + return true; + } + + @Override + protected void maybeCraft() { + if (startedCrafting || futureTask == null || !futureTask.isDone()) { + return; + } + + Optional optionalPreview; + + try { + optionalPreview = futureTask.get(); + } catch (ExecutionException | InterruptedException ex) { + AdvancedPeripherals.debug("Tried to get preview, but preview calculation is not done. Should be done.", org.apache.logging.log4j.Level.ERROR); + ex.printStackTrace(); + fireEvent(true, StatusConstants.UNKNOWN_ERROR); + return; + } + + // TODO: I currently don't exactly know when the optional can be empty after the future is done. So I need to evaluate this. + if (optionalPreview.isEmpty()) { + AdvancedPeripherals.debug("preview optional is empty.", org.apache.logging.log4j.Level.ERROR); + fireEvent(true, StatusConstants.UNKNOWN_ERROR); + return; + } + + Preview preview = optionalPreview.orElse(null); + PreviewType previewType = preview.type(); + + if (previewType == PreviewType.MISSING_RESOURCES) { + fireEvent(true, StatusConstants.MISSING_ITEMS); + calculationNotSuccessful = true; + return; + } + + if (previewType != PreviewType.SUCCESS) { + calculationNotSuccessful = true; + fireEvent(true, previewType.toString()); + return; + } + + // How RS2 handles crafting is a bit cursed. We first create a preview which calculates the recipes, and then we check if the preview was successful + // If it was, we again start a task which again calculates the recipes, and then we hope nothing changed from the first calculation + autocraftingComponent.startTask(toCraft, amount, Actor.EMPTY, false); + setStartedCrafting(); + } + + @Override + protected void startCalculation() { + if (startedCalculation) { + return; + } + startedCalculation = true; + + if (autocraftingComponent.getPatternsByOutput(toCraft).isEmpty()) { + fireEvent(true, StatusConstants.NOT_CRAFTABLE); + return; + } + + futureTask = autocraftingComponent.getPreview(toCraft, amount); + fireEvent(false, StatusConstants.CALCULATION_STARTED); + } + + @Override + public void jobStateChanged() { + if (this.craftingTask == null) { + fireEvent(true, StatusConstants.UNKNOWN_ERROR); + return; + } + + if (isJobCanceled() && !isJobCanceled) { + fireEvent(false, StatusConstants.JOB_CANCELED); + setJobCanceled(); + return; + } + + if (isJobDone() && !isJobDone) { + fireEvent(true, StatusConstants.JOB_DONE); + setJobDone(); + } + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index 09f023a89..1c530b362 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -383,7 +383,7 @@ public static long getUsedExternStorage(Network network, StorageType type) { return used; } - private static Map getObjectFromResourceKey(@NotNull ResourceKey resource) { + public static Map getObjectFromResourceKey(@NotNull ResourceKey resource) { return getObjectFromResourceKey(resource, 0); } @@ -394,7 +394,7 @@ private static Map getObjectFromResourceKey(@NotNull ResourceKey * @param count count of the resource - can be 0 and lower * @return the parsed key to a lua properties map */ - private static Map getObjectFromResourceKey(@NotNull ResourceKey resource, long count) { + public static Map getObjectFromResourceKey(@NotNull ResourceKey resource, long count) { boolean countZeroOrLower = count <= 0; if (resource instanceof ItemResource) { if (countZeroOrLower) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java index 15169389a..afd216bcc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -1,5 +1,9 @@ package de.srendi.advancedperipherals.common.blocks.blockentities; +import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; +import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatusListener; +import com.refinedmods.refinedstorage.api.autocrafting.task.TaskId; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage.api.network.node.NetworkNode; import com.refinedmods.refinedstorage.common.api.support.network.ConnectionStrategy; @@ -8,23 +12,32 @@ import com.refinedmods.refinedstorage.common.support.network.InWorldNetworkNodeContainerImpl; import com.refinedmods.refinedstorage.common.support.network.SimpleConnectionStrategy; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RSBridgePeripheral; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSCraftJob; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; +import de.srendi.advancedperipherals.common.util.inventory.BasicCraftJob; import de.srendi.advancedperipherals.lib.peripherals.IPeripheralTileEntity; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; +import java.util.List; import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; -public class RsBridgeEntity extends PeripheralBlockEntity implements IPeripheralTileEntity, NetworkNodeContainerProvider { +public class RsBridgeEntity extends PeripheralBlockEntity implements IPeripheralTileEntity, NetworkNodeContainerProvider, TaskStatusListener { protected CompoundTag peripheralSettings; private final NetworkNode node; private final InWorldNetworkNodeContainer networkNodeContainer; + private final List jobs = new CopyOnWriteArrayList<>(); + private boolean addedListener = false; public RsBridgeEntity(BlockPos pos, BlockState state) { super(BlockEntityTypes.RS_BRIDGE.get(), pos, state); @@ -50,6 +63,31 @@ public void markSettingsChanged() { setChanged(); } + @Override + public void handleTick(Level level, BlockState state, BlockEntityType type) { + if (getNode().getNetwork() != null) { + AutocraftingNetworkComponent manager = getNode().getNetwork().getComponent(AutocraftingNetworkComponent.class); + if (!this.addedListener) { + manager.addListener(this); + this.addedListener = true; + } + } + + // Try to start the job if the job calculation finished + jobs.forEach(BasicCraftJob::tick); + + // Remove the job if the crafting calculation failed, we can't do anything with it anymore + jobs.removeIf(BasicCraftJob::canBePurged); + } + + public void addJob(RSCraftJob job) { + jobs.add(job); + } + + public List getJobs() { + return jobs; + } + public NetworkNode getNode() { return node; } @@ -73,4 +111,20 @@ public void addContainer(@NotNull InWorldNetworkNodeContainer inWorldNetworkNode public boolean canBuild(@NotNull ServerPlayer serverPlayer) { return true; } + + @Override + public void taskStatusChanged(@NotNull TaskStatus taskStatus) { + //jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); + } + + @Override + public void taskRemoved(@NotNull TaskId taskId) { + //jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskId)).forEach(BasicCraftJob::jobStateChanged); + + } + + @Override + public void taskAdded(@NotNull TaskStatus taskStatus) { + //jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java new file mode 100644 index 000000000..03c58657d --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java @@ -0,0 +1,44 @@ +package de.srendi.advancedperipherals.common.util; + +/** + * A collection of constants used as return types for several peripherals + */ +public enum StatusConstants { + + // Crafting Jobs + CALCULATION_STARTED, + CRAFTING_STARTED, + JOB_CANCELED, + JOB_DONE, + NOT_CRAFTABLE, + MISSING_ITEMS, + CPU_DOES_NOT_EXIST, + // Filters + EMPTY_FILTER, + FLUID_NOT_FOUND, + ITEM_NOT_FOUND, + NO_VALID_FLUID, + NO_VALID_ITEM, + NO_VALID_FROMSLOT, + NO_VALID_TOSLOT, + NO_VALID_NBT_HASH, + NO_VALID_NBT, + NO_VALID_FINGERPRINT, + NO_VALID_COUNT, + NO_VALID_FILTER_TYPE, + // Misc + NOT_CONNECTED, + UNKNOWN_ERROR; + + private String info; + + public StatusConstants withInfo(String info) { + this.info = info; + return this; + } + + public String asString() { + return this + "_" + this.info; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java new file mode 100644 index 000000000..24b9261a5 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java @@ -0,0 +1,206 @@ +package de.srendi.advancedperipherals.common.util.inventory; + +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.peripheral.IComputerAccess; +import de.srendi.advancedperipherals.common.util.StatusConstants; +import net.minecraft.world.level.Level; + +import java.util.concurrent.atomic.AtomicLong; + +public abstract class BasicCraftJob { + + protected static final String EVENT = "_crafting"; + private static final int JOB_DONE_PURGE_TIME = 5 * 60 * 1000; + + public static final AtomicLong ID_SEQ = new AtomicLong(); + + protected final long id = ID_SEQ.incrementAndGet(); + protected final IComputerAccess computer; + protected final String eventName; + protected final long amount; + protected final Level world; + + protected boolean startedCrafting = false; + protected boolean startedCalculation = false; + protected boolean calculationNotSuccessful = false; + protected boolean errorOccurred = false; + protected boolean isJobDone = false; + protected long jobDoneTime = 0; + protected boolean isJobCanceled = false; + protected String debugMessage = null; + + public BasicCraftJob(IComputerAccess computer, String eventName, Level world, long amount) { + this.computer = computer; + this.eventName = eventName; + this.world = world; + this.amount = amount; + } + + @LuaFunction + public final long getId() { + return id; + } + + protected abstract boolean isJobDone(); + + @LuaFunction + public final boolean isDone() { + return isJobDone(); + } + + protected abstract boolean isJobCanceled(); + + @LuaFunction + public final boolean isCanceled() { + return isJobCanceled(); + } + + @LuaFunction + public final boolean isCraftingStarted() { + return startedCrafting; + } + + @LuaFunction + public final boolean isCalculationStarted() { + return startedCalculation; + } + + @LuaFunction + public final boolean isCalculationNotSuccessful() { + return calculationNotSuccessful; + } + + @LuaFunction + public final boolean hasErrorOccurred() { + return errorOccurred; + } + + @LuaFunction + public final String getDebugMessage() { + return debugMessage; + } + + @LuaFunction(value = "getRequestedItem") + public final Object getRequestedItemLua() { + return getParsedRequestedItem(); + } + + @LuaFunction(value = "getElapsedTime") + public final long getElapsedTimeLua() { + return getElapsedTime(); + } + + @LuaFunction(value = "getTotalItems") + public final long getTotalItemsLua() { + return getTotalItems(); + } + + @LuaFunction(value = "getItemProgress") + public final long getItemProgressLua() { + return getItemProgress(); + } + + @LuaFunction(value = "getEmittedItems") + public final Object getEmittedItemsLua() { + return getEmittedItems(); + } + + @LuaFunction(value = "getUsedItems") + public final Object getUsedItemsLua() { + return getUsedItems(); + } + + @LuaFunction(value = "getMissingItems") + public final Object getMissingItemsLua() { + return getMissingItems(); + } + + @LuaFunction(value = "hasMultiplePaths") + public final boolean hasMultiplePathsLua() { + return hasMultiplePaths(); + } + + @LuaFunction(value = "getFinalOutput") + public final Object getFinalOutputLua() { + return getFinalOutput(); + } + + @LuaFunction(value = "cancel") + public final boolean cancelLua() { + return cancel(); + } + + public abstract Object getParsedRequestedItem(); + + public abstract long getElapsedTime(); + + public abstract long getTotalItems(); + + public abstract long getItemProgress(); + + public abstract Object getEmittedItems(); + + public abstract Object getUsedItems(); + + public abstract Object getMissingItems(); + + public abstract boolean hasMultiplePaths(); + + public abstract Object getFinalOutput(); + + public abstract boolean cancel(); + + public Level getWorld() { + return world; + } + + public long getAmount() { + return amount; + } + + public boolean canBePurged() { + return calculationNotSuccessful || ((isJobDone || isJobCanceled) && jobDoneTime + JOB_DONE_PURGE_TIME < System.currentTimeMillis()); + } + + protected void fireNotConnected() { + fireEvent(true, StatusConstants.NOT_CONNECTED); + } + + public void setStartedCrafting() { + this.startedCrafting = true; + fireEvent(false, StatusConstants.CRAFTING_STARTED); + } + + public void setJobCanceled() { + this.isJobCanceled = true; + this.jobDoneTime = System.currentTimeMillis(); + } + + public void setJobDone() { + this.isJobDone = true; + this.jobDoneTime = System.currentTimeMillis(); + } + + protected void fireEvent(boolean error, StatusConstants message) { + this.computer.queueEvent(eventName + EVENT, error, this.id, message.toString()); + this.debugMessage = message.toString(); + this.errorOccurred = error; + } + + protected void fireEvent(boolean error, String message) { + this.computer.queueEvent(eventName + EVENT, error, this.id, message); + this.debugMessage = message; + this.errorOccurred = error; + } + + public final void tick() { + startCalculation(); + maybeCraft(); + } + + protected abstract void maybeCraft(); + + protected abstract void startCalculation(); + + public abstract void jobStateChanged(); +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index 76a40b350..de9d699dc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -95,14 +95,19 @@ public interface IStorageSystemPeripheral { MethodResult getAvailableChemicalStorage(); - MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult getCraftingTasks(); + // A function to get our BasicCraftJob object with the id + MethodResult getCraftingJob(int id); + MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException; MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; + MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; + + MethodResult craftChemical(IComputerAccess computer, IArguments arguments) throws LuaException; + MethodResult isItemCraftable(IArguments arguments) throws LuaException; MethodResult isItemCrafting(IArguments arguments) throws LuaException; @@ -111,4 +116,8 @@ public interface IStorageSystemPeripheral { MethodResult isFluidCrafting(IArguments arguments) throws LuaException; + MethodResult isChemicalCraftable(IArguments arguments) throws LuaException; + + MethodResult isChemicalCrafting(IArguments arguments) throws LuaException; + } From b32745d96f8daafacc785eb13ada7505d33868c5 Mon Sep 17 00:00:00 2001 From: endi Date: Tue, 4 Mar 2025 13:57:01 +0100 Subject: [PATCH 15/91] Change order of IStorageSystemPeripheral --- .../peripheral/RSBridgePeripheral.java | 86 +++++++++---------- .../inventory/IStorageSystemPeripheral.java | 4 +- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 2839242d5..ec1f642fb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -366,49 +366,6 @@ public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) return exportToTank(arguments, handler); } - @Override - @LuaFunction(mainThread = true) - public final MethodResult getPatterns(IArguments arguments) throws LuaException { - if (!isAvailable()) - return notConnected(); - - // Expected input is a table with either an input table, an output table or both to filter for both - // If no table is provided or it's empty, return every pattern - Map filterTable = arguments.optTable(0, Collections.emptyMap()); - if (filterTable.isEmpty()) { - return MethodResult.of(RefinedStorageApi.getPatterns(getNetwork())); - } - - boolean hasInputFilter = filterTable.containsKey("input"); - boolean hasOutputFilter = filterTable.containsKey("output"); - boolean hasAnyFilter = hasInputFilter || hasOutputFilter; - - // If the player tries to filter for nothing, return nothing. - if (!hasAnyFilter) - return MethodResult.of(null, "NO_FILTER"); - - GenericFilter inputFilter = null; - GenericFilter outputFilter = null; - - if (hasInputFilter) { - Map inputFilterTable = TableHelper.getTableField(filterTable, "input"); - - inputFilter = GenericFilter.parseGeneric(inputFilterTable).getLeft(); - } - if (hasOutputFilter) { - Map outputFilterTable = TableHelper.getTableField(filterTable, "output"); - - outputFilter = GenericFilter.parseGeneric(outputFilterTable).getLeft(); - } - - Pair pattern = RefinedStorageApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); - - if (pattern.getRight() != null) - return MethodResult.of(null, pattern.getRight()); - - return MethodResult.of(RefinedStorageApi.parsePattern(pattern.getLeft())); - } - @Override @LuaFunction(mainThread = true) public MethodResult getStoredEnergy() { @@ -693,4 +650,47 @@ public MethodResult isChemicalCraftable(IArguments arguments) throws LuaExceptio public MethodResult isChemicalCrafting(IArguments arguments) throws LuaException { return null; } + + @Override + @LuaFunction(mainThread = true) + public final MethodResult getPatterns(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + // Expected input is a table with either an input table, an output table or both to filter for both + // If no table is provided or it's empty, return every pattern + Map filterTable = arguments.optTable(0, Collections.emptyMap()); + if (filterTable.isEmpty()) { + return MethodResult.of(RefinedStorageApi.getPatterns(getNetwork())); + } + + boolean hasInputFilter = filterTable.containsKey("input"); + boolean hasOutputFilter = filterTable.containsKey("output"); + boolean hasAnyFilter = hasInputFilter || hasOutputFilter; + + // If the player tries to filter for nothing, return nothing. + if (!hasAnyFilter) + return MethodResult.of(null, "NO_FILTER"); + + GenericFilter inputFilter = null; + GenericFilter outputFilter = null; + + if (hasInputFilter) { + Map inputFilterTable = TableHelper.getTableField(filterTable, "input"); + + inputFilter = GenericFilter.parseGeneric(inputFilterTable).getLeft(); + } + if (hasOutputFilter) { + Map outputFilterTable = TableHelper.getTableField(filterTable, "output"); + + outputFilter = GenericFilter.parseGeneric(outputFilterTable).getLeft(); + } + + Pair pattern = RefinedStorageApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); + + if (pattern.getRight() != null) + return MethodResult.of(null, pattern.getRight()); + + return MethodResult.of(RefinedStorageApi.parsePattern(pattern.getLeft())); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index de9d699dc..d48d8adaf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -49,8 +49,6 @@ public interface IStorageSystemPeripheral { MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult getPatterns(IArguments arguments) throws LuaException; - MethodResult getStoredEnergy(); MethodResult getEnergyCapacity(); @@ -120,4 +118,6 @@ public interface IStorageSystemPeripheral { MethodResult isChemicalCrafting(IArguments arguments) throws LuaException; + MethodResult getPatterns(IArguments arguments) throws LuaException; + } From 1413ea6cee264f184e3f9cd1bd187b9a86a76bff Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 7 Mar 2025 22:57:19 +0100 Subject: [PATCH 16/91] Basic chemical support --- .../peripheral/RSBridgePeripheral.java | 34 +++- .../refinedstorage/RefinedStorageApi.java | 21 +++ .../common/util/inventory/ChemicalFilter.java | 160 ++++++++++++++++++ .../common/util/inventory/ChemicalUtil.java | 39 +++++ 4 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index ec1f642fb..dae914fc0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -7,7 +7,9 @@ import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage.common.storage.StorageTypes; +import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage.mekanism.ChemicalResource; import com.refinedmods.refinedstorage.mekanism.ChemicalResourceType; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; @@ -24,6 +26,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; +import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; @@ -587,16 +590,41 @@ public MethodResult craftItem(IComputerAccess computer, IArguments arguments) th return MethodResult.of(job); } - @Override @LuaFunction(mainThread = true) public MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + Pair filter = FluidFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + FluidResource stack = RefinedStorageApi.getFluid(getNetwork(), filter.getLeft()); + if (stack == null) + return MethodResult.of(null, "NOT_CRAFTABLE"); + + RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), stack, getNetwork().getComponent(AutocraftingNetworkComponent.class)); + bridge.addJob(job); + return MethodResult.of(job); } @Override public MethodResult craftChemical(IComputerAccess computer, IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + Pair filter = ChemicalFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + ChemicalResource stack = RefinedStorageApi.getChemical(getNetwork(), filter.getLeft()); + if (stack == null) + return MethodResult.of(null, "NOT_CRAFTABLE"); + + RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), stack, getNetwork().getComponent(AutocraftingNetworkComponent.class)); + bridge.addJob(job); + return MethodResult.of(job); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java index 1c530b362..9fd61ef2b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java @@ -23,17 +23,20 @@ import com.refinedmods.refinedstorage.common.storage.StorageTypes; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage.mekanism.ChemicalResource; import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.common.util.Pair; +import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; +import mekanism.api.chemical.ChemicalStack; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import net.neoforged.neoforge.fluids.FluidStack; @@ -97,6 +100,24 @@ public static FluidResource getFluid(Network network, FluidFilter filter) { return null; } + /** + * Returns the first chemical parsed to a lua object which fits to the filter + * + * @param network refined storage network + * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#empty()} + * @return the first fluid in the system that fits the fluid filter or null + */ + @Nullable + public static ChemicalResource getChemical(Network network, ChemicalFilter filter) { + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { + if (trackedResource.resourceAmount().resource() instanceof ChemicalResource chemicalResource && filter.test(new ChemicalStack(chemicalResource.chemical(), trackedResource.resourceAmount().amount()))) { + return chemicalResource; + } + } + return null; + } + /** * Returns the first item parsed to a lua object which fits to the filter * diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java new file mode 100644 index 000000000..905a54594 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java @@ -0,0 +1,160 @@ +package de.srendi.advancedperipherals.common.util.inventory; + +import appeng.api.stacks.GenericStack; +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage.mekanism.ChemicalResource; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.core.apis.TableHelper; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.util.Pair; +import mekanism.api.MekanismAPI; +import mekanism.api.chemical.Chemical; +import mekanism.api.chemical.ChemicalStack; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; + +import java.util.Map; + +public class ChemicalFilter extends GenericFilter { + + private Chemical chemical = MekanismAPI.EMPTY_CHEMICAL; + private TagKey tag = null; + private int count = 64; + private String fingerprint = ""; + public int fromSlot = -1; + public int toSlot = -1; + + private ChemicalFilter() { + } + + public static Pair parse(Map item) { + ChemicalFilter itemFilter = empty(); + // If the map is empty, return a filter without any filters + if (item.isEmpty()) + return Pair.of(itemFilter, null); + if (item.containsKey("name")) { + try { + String name = TableHelper.getStringField(item, "name"); + if (name.startsWith("#")) { + itemFilter.tag = TagKey.create(MekanismAPI.CHEMICAL_REGISTRY_NAME, ResourceLocation.parse(name.substring(1))); + } else if ((itemFilter.chemical = ItemUtil.getRegistryEntry(name, MekanismAPI.CHEMICAL_REGISTRY)) == null) { + return Pair.of(null, "CHEMICAL_NOT_FOUND"); + } + } catch (LuaException luaException) { + return Pair.of(null, "NO_VALID_ITEM"); + } + } + if (item.containsKey("fingerprint")) { + try { + itemFilter.fingerprint = TableHelper.getStringField(item, "fingerprint"); + } catch (LuaException luaException) { + return Pair.of(null, "NO_VALID_FINGERPRINT"); + } + } + if (item.containsKey("fromSlot")) { + try { + itemFilter.fromSlot = TableHelper.getIntField(item, "fromSlot"); + } catch (LuaException luaException) { + return Pair.of(null, "NO_VALID_FROMSLOT"); + } + } + if (item.containsKey("toSlot")) { + try { + itemFilter.toSlot = TableHelper.getIntField(item, "toSlot"); + } catch (LuaException luaException) { + return Pair.of(null, "NO_VALID_TOSLOT"); + } + } + if (item.containsKey("count")) { + try { + itemFilter.count = TableHelper.getIntField(item, "count"); + } catch (LuaException luaException) { + return Pair.of(null, "NO_VALID_COUNT"); + } + } + + AdvancedPeripherals.debug("Parsed item filter: " + itemFilter); + return Pair.of(itemFilter, null); + } + + public static ChemicalFilter fromStack(ChemicalStack stack) { + ChemicalFilter filter = empty(); + filter.chemical = stack.getChemical(); + return filter; + } + + public static ChemicalFilter empty() { + return new ChemicalFilter(); + } + + public boolean isEmpty() { + return fingerprint.isEmpty() && chemical == MekanismAPI.EMPTY_CHEMICAL && tag == null; + } + + @Override + public boolean testAE(GenericStack genericStack) { + //if (genericStack.what() instanceof aeItemKey) { + // return test(aeItemKey.toStack()); + //} + return false; + } + + @Override + public boolean testRS(ResourceAmount resourceAmount) { + if (resourceAmount.resource() instanceof ChemicalResource chemicalResource) { + return test(new ChemicalStack(chemical.getChemical(), resourceAmount.amount())); + } + return false; + } + + public ChemicalStack toChemicalStack() { + return new ChemicalStack(chemical, count); + } + + public boolean test(ChemicalStack stack) { + if (isEmpty()) + return true; + + if (!fingerprint.isEmpty()) { + String testFingerprint = ChemicalUtil.getFingerprint(stack); + return fingerprint.equals(testFingerprint); + } + + if (chemical != MekanismAPI.EMPTY_CHEMICAL && !stack.is(chemical)) { + return false; + } + if (tag != null && !stack.is(tag)) { + return false; + } + + return true; + } + + public int getCount() { + return count; + } + + public Chemical getChemical() { + return chemical; + } + + public int getFromSlot() { + return fromSlot; + } + + public int getToSlot() { + return toSlot; + } + + @Override + public String toString() { + return "ItemFilter{" + + "item=" + ChemicalUtil.getRegistryKey(chemical) + + ", tag=" + tag + + ", count=" + count + + ", fingerprint='" + fingerprint + '\'' + + ", fromSlot=" + fromSlot + + ", toSlot=" + toSlot + + '}'; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java new file mode 100644 index 000000000..449e8d1b4 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java @@ -0,0 +1,39 @@ +package de.srendi.advancedperipherals.common.util.inventory; + +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.util.StringUtil; +import mekanism.api.MekanismAPI; +import mekanism.api.chemical.Chemical; +import mekanism.api.chemical.ChemicalStack; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class ChemicalUtil { + + @NotNull + public static String getFingerprint(@NotNull ChemicalStack stack) { + // A pretty lame fingerprint, a chemical stack does not have any components or other stuff + String fingerprint = getRegistryKey(stack).toString(); + try { + byte[] bytesOfHash = fingerprint.getBytes(StandardCharsets.UTF_8); + MessageDigest md = MessageDigest.getInstance("MD5"); + return StringUtil.toHexString(md.digest(bytesOfHash)); + } catch (NoSuchAlgorithmException ex) { + AdvancedPeripherals.debug("Could not parse fingerprint.", org.apache.logging.log4j.Level.ERROR); + ex.printStackTrace(); + } + return ""; + } + + public static ResourceLocation getRegistryKey(Chemical fluid) { + return MekanismAPI.CHEMICAL_REGISTRY.getKey(fluid); + } + + public static ResourceLocation getRegistryKey(ChemicalStack fluid) { + return MekanismAPI.CHEMICAL_REGISTRY.getKey(fluid.copy().getChemical()); + } +} From db4806a57522d88a2634d019ecf83ca039294482 Mon Sep 17 00:00:00 2001 From: endi Date: Tue, 11 Mar 2025 21:48:57 +0100 Subject: [PATCH 17/91] Implemented all RS functions - the crafting job needs some love but I fixed that it would not have a crafting task to get information. Now needs major testing and refinement --- .../AdvancedPeripherals.java | 4 +- .../peripheral/RSBridgePeripheral.java | 157 +++++++++++------- .../addons/refinedstorage/RSCraftJob.java | 50 +++++- .../{RefinedStorageApi.java => RsApi.java} | 40 ++++- .../addons/refinedstorage/RsFluidHandler.java | 2 +- .../addons/refinedstorage/RsItemHandler.java | 2 +- .../common/util/inventory/BasicCraftJob.java | 2 +- .../common/util/inventory/GenericFilter.java | 8 +- .../inventory/IStorageSystemPeripheral.java | 18 +- 9 files changed, 189 insertions(+), 94 deletions(-) rename src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/{RefinedStorageApi.java => RsApi.java} (95%) diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index e54a9a54a..75225dcd4 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -3,7 +3,7 @@ import dan200.computercraft.api.peripheral.PeripheralCapability; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageApi; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi; import de.srendi.advancedperipherals.common.blocks.base.ICapabilityProvider; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.setup.Registration; @@ -97,6 +97,6 @@ public void registerCapabilities(RegisterCapabilitiesEvent event) { if (APAddons.ae2Loaded) AppEngApi.registerCapabilities(event); if (APAddons.refinedStorageLoaded) - RefinedStorageApi.registerCapabilities(event); + RsApi.registerCapabilities(event); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index dae914fc0..a619b3a7d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -1,11 +1,13 @@ package de.srendi.advancedperipherals.common.addons.computercraft.peripheral; import com.refinedmods.refinedstorage.api.autocrafting.Pattern; +import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.NetworkComponent; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import com.refinedmods.refinedstorage.common.storage.StorageTypes; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; @@ -20,7 +22,7 @@ import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.addons.refinedstorage.RSCraftJob; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RefinedStorageApi; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsFluidHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsItemHandler; import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; @@ -34,6 +36,7 @@ import de.srendi.advancedperipherals.common.util.inventory.InventoryUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; @@ -189,7 +192,7 @@ public MethodResult getItem(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - Map resourceProperties = RefinedStorageApi.getParsedItem(getNetwork(), parsedFilter); + Map resourceProperties = RsApi.getParsedItem(getNetwork(), parsedFilter); if (resourceProperties == null) return MethodResult.of(null, "NOT_FOUND"); @@ -210,7 +213,7 @@ public MethodResult getFluid(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - Map resourceProperties = RefinedStorageApi.getParsedFluid(getNetwork(), parsedFilter); + Map resourceProperties = RsApi.getParsedFluid(getNetwork(), parsedFilter); if (resourceProperties == null) return MethodResult.of(null, "NOT_FOUND"); @@ -229,7 +232,7 @@ public MethodResult listItems(IArguments arguments) throws LuaException { ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.getParsedItems(getNetwork(), parsedFilter); + Set> resourceProperties = RsApi.getParsedItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -246,7 +249,7 @@ public MethodResult listFluids(IArguments arguments) throws LuaException { FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.getParsedFluids(getNetwork(), parsedFilter); + Set> resourceProperties = RsApi.getParsedFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -263,7 +266,7 @@ public MethodResult listCraftableItems(IArguments arguments) throws LuaException ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.getCraftableItems(getNetwork(), parsedFilter); + Set> resourceProperties = RsApi.getCraftableItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -280,7 +283,7 @@ public MethodResult listCraftableFluids(IArguments arguments) throws LuaExceptio FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RefinedStorageApi.getCraftableFluids(getNetwork(), parsedFilter); + Set> resourceProperties = RsApi.getCraftableFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -291,7 +294,7 @@ public MethodResult listCells() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.listCells(getNetwork())); + return MethodResult.of(RsApi.listCells(getNetwork())); } @Override @@ -300,7 +303,7 @@ public MethodResult listDrives() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.listDrives(getNetwork())); + return MethodResult.of(RsApi.listDrives(getNetwork())); } @Override @@ -415,7 +418,7 @@ public MethodResult getTotalExternItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), StorageTypes.ITEM)); } @Override @@ -424,7 +427,7 @@ public MethodResult getTotalExternFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), StorageTypes.FLUID)); } @Override @@ -433,7 +436,7 @@ public MethodResult getTotalExternChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @@ -442,7 +445,7 @@ public MethodResult getTotalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), StorageTypes.ITEM)); } @Override @@ -451,7 +454,7 @@ public MethodResult getTotalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), StorageTypes.FLUID)); } @Override @@ -460,7 +463,7 @@ public MethodResult getTotalChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @@ -469,7 +472,7 @@ public MethodResult getUsedExternItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getUsedExternStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getUsedExternStorage(getNetwork(), StorageTypes.ITEM)); } @Override @@ -478,7 +481,7 @@ public MethodResult getUsedExternFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getUsedExternStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getUsedExternStorage(getNetwork(), StorageTypes.FLUID)); } @Override @@ -487,7 +490,7 @@ public MethodResult getUsedExternChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @@ -496,7 +499,7 @@ public MethodResult getUsedItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getUsedStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getUsedStorage(getNetwork(), StorageTypes.ITEM)); } @Override @@ -505,7 +508,7 @@ public MethodResult getUsedFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getUsedStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getUsedStorage(getNetwork(), StorageTypes.FLUID)); } @Override @@ -514,7 +517,7 @@ public MethodResult getUsedChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getUsedStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getUsedStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @@ -523,7 +526,7 @@ public MethodResult getAvailableExternItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), StorageTypes.ITEM) - RefinedStorageApi.getUsedExternStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), StorageTypes.ITEM) - RsApi.getUsedExternStorage(getNetwork(), StorageTypes.ITEM)); } @Override @@ -532,7 +535,7 @@ public MethodResult getAvailableExternFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), StorageTypes.FLUID) - RefinedStorageApi.getUsedExternStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), StorageTypes.FLUID) - RsApi.getUsedExternStorage(getNetwork(), StorageTypes.FLUID)); } @Override @@ -541,7 +544,7 @@ public MethodResult getAvailableExternChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RefinedStorageApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RsApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @@ -550,7 +553,7 @@ public MethodResult getAvailableItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), StorageTypes.ITEM) - RefinedStorageApi.getUsedStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), StorageTypes.ITEM) - RsApi.getUsedStorage(getNetwork(), StorageTypes.ITEM)); } @Override @@ -559,7 +562,7 @@ public MethodResult getAvailableFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), StorageTypes.FLUID) - RefinedStorageApi.getUsedStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), StorageTypes.FLUID) - RsApi.getUsedStorage(getNetwork(), StorageTypes.FLUID)); } @Override @@ -568,7 +571,7 @@ public MethodResult getAvailableChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RefinedStorageApi.getTotalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RefinedStorageApi.getUsedStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RsApi.getUsedStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @@ -581,7 +584,7 @@ public MethodResult craftItem(IComputerAccess computer, IArguments arguments) th if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - ItemResource stack = RefinedStorageApi.getItem(getNetwork(), filter.getLeft()); + ItemResource stack = RsApi.getItem(getNetwork(), filter.getLeft()); if (stack == null) return MethodResult.of(null, "NOT_CRAFTABLE"); @@ -600,7 +603,7 @@ public MethodResult craftFluid(IComputerAccess computer, IArguments arguments) t if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - FluidResource stack = RefinedStorageApi.getFluid(getNetwork(), filter.getLeft()); + FluidResource stack = RsApi.getFluid(getNetwork(), filter.getLeft()); if (stack == null) return MethodResult.of(null, "NOT_CRAFTABLE"); @@ -618,7 +621,7 @@ public MethodResult craftChemical(IComputerAccess computer, IArguments arguments if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - ChemicalResource stack = RefinedStorageApi.getChemical(getNetwork(), filter.getLeft()); + ChemicalResource stack = RsApi.getChemical(getNetwork(), filter.getLeft()); if (stack == null) return MethodResult.of(null, "NOT_CRAFTABLE"); @@ -630,53 +633,89 @@ public MethodResult craftChemical(IComputerAccess computer, IArguments arguments @Override @LuaFunction(mainThread = true) public MethodResult getCraftingTasks() { - return null; + if (!isAvailable()) + return notConnected(); + + return MethodResult.of(RsApi.getCraftingTasks(bridge)); } @Override - public MethodResult getCraftingJob(int id) { - return null; + public MethodResult getCraftingTask(int id) { + if (!isAvailable()) + return notConnected(); + + RSCraftJob foundJob = null; + + for (RSCraftJob job : bridge.getJobs()) { + if (job.getId() == id) { + foundJob = job; + } + } + return MethodResult.of(foundJob); } @Override @LuaFunction(mainThread = true) public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { - return null; - } + if (!isAvailable()) + return notConnected(); + Pair, String> filter = GenericFilter.parseGeneric(arguments.getTable(0)); + if (filter.getRight() != null) + return MethodResult.of(null, filter.getRight()); - @Override - @LuaFunction(mainThread = true) - public MethodResult isItemCraftable(IArguments arguments) throws LuaException { - return null; - } + GenericFilter parsedFilter = filter.getLeft(); - @Override - @LuaFunction(mainThread = true) - public MethodResult isItemCrafting(IArguments arguments) throws LuaException { - return null; + AutocraftingNetworkComponent craftingManager = getComponent(AutocraftingNetworkComponent.class); + int canceled = 0; + + for (TaskStatus status : craftingManager.getStatuses()) { + if (parsedFilter.testRS(new ResourceAmount(status.info().resource(), 1))) { + craftingManager.cancel(status.info().id()); + canceled++; + } + } + + return MethodResult.of(canceled); } + @Override @LuaFunction(mainThread = true) - public MethodResult isFluidCraftable(IArguments arguments) throws LuaException { - return null; + public MethodResult isCraftable(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); + + Pair, String> filter = GenericFilter.parseGeneric(arguments.getTable(0)); + if (filter.getRight() != null) + return MethodResult.of(null, filter.getRight()); + + GenericFilter parsedFilter = filter.getLeft(); + + return MethodResult.of(RsApi.findPatternFromFilters(getNetwork(), null, parsedFilter).getLeft() != null); } @Override @LuaFunction(mainThread = true) - public MethodResult isFluidCrafting(IArguments arguments) throws LuaException { - return null; - } + public MethodResult isCrafting(IArguments arguments) throws LuaException { + if (!isAvailable()) + return notConnected(); - @Override - public MethodResult isChemicalCraftable(IArguments arguments) throws LuaException { - return null; - } + Pair, String> filter = GenericFilter.parseGeneric(arguments.getTable(0)); + if (filter.getRight() != null) + return MethodResult.of(null, filter.getRight()); - @Override - public MethodResult isChemicalCrafting(IArguments arguments) throws LuaException { - return null; + GenericFilter parsedFilter = filter.getLeft(); + + AutocraftingNetworkComponent craftingManager = getComponent(AutocraftingNetworkComponent.class); + + for (TaskStatus status : craftingManager.getStatuses()) { + if (parsedFilter.testRS(new ResourceAmount(status.info().resource(), 1))) { + return MethodResult.of(true); + } + } + + return MethodResult.of(false); } @Override @@ -689,7 +728,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException // If no table is provided or it's empty, return every pattern Map filterTable = arguments.optTable(0, Collections.emptyMap()); if (filterTable.isEmpty()) { - return MethodResult.of(RefinedStorageApi.getPatterns(getNetwork())); + return MethodResult.of(RsApi.getPatterns(getNetwork())); } boolean hasInputFilter = filterTable.containsKey("input"); @@ -714,11 +753,11 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException outputFilter = GenericFilter.parseGeneric(outputFilterTable).getLeft(); } - Pair pattern = RefinedStorageApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); + Pair pattern = RsApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); if (pattern.getRight() != null) return MethodResult.of(null, pattern.getRight()); - return MethodResult.of(RefinedStorageApi.parsePattern(pattern.getLeft())); + return MethodResult.of(RsApi.parsePattern(pattern.getLeft())); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index 6c4130f92..fefef8fec 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -3,6 +3,7 @@ import com.refinedmods.refinedstorage.api.autocrafting.preview.Preview; import com.refinedmods.refinedstorage.api.autocrafting.preview.PreviewType; import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; +import com.refinedmods.refinedstorage.api.autocrafting.task.TaskId; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.api.storage.Actor; @@ -22,7 +23,8 @@ public class RSCraftJob extends BasicCraftJob { private final ResourceKey toCraft; private TaskStatus craftingTask; - private Future> futureTask; + private Future> futureCalculationResult; + private Future> futureTask; public RSCraftJob(IComputerAccess computer, Level world, long amount, ResourceKey toCraft, AutocraftingNetworkComponent calculationResult) { super(computer, "rs", world, amount); @@ -42,7 +44,7 @@ protected boolean isJobCanceled() { @Override public Object getParsedRequestedItem() { - return RefinedStorageApi.getObjectFromResourceKey(toCraft, amount); + return RsApi.getObjectFromResourceKey(toCraft, amount); } @Override @@ -105,16 +107,51 @@ public boolean cancel() { return true; } + @Override + public void tick() { + super.tick(); + // The following is to get the TaskStatus from the issued task + if (futureTask == null || !futureTask.isDone() || craftingTask != null) { + return; + } + Optional optionalId; + + try { + optionalId = futureTask.get(); + } catch (InterruptedException | ExecutionException e) { + AdvancedPeripherals.debug("Tried to get the task but the task was not done. Should be done", org.apache.logging.log4j.Level.ERROR); + fireEvent(true, StatusConstants.UNKNOWN_ERROR); + return; + } + + if (optionalId.isEmpty()) { + // This indicates that the second calculation was not successful. Well I guess. There is no java doc and I currently + // don't get an answer from the maintainer. So maybe we want to fire the crafting event + return; + } + + TaskId id = optionalId.get(); + for (TaskStatus status : autocraftingComponent.getStatuses()) { + if (status.info().id() == id) { + this.craftingTask = status; + + // And only now we set that the crafting is started. + setStartedCrafting(); + } + + } + } + @Override protected void maybeCraft() { - if (startedCrafting || futureTask == null || !futureTask.isDone()) { + if (startedCrafting || futureTask != null || futureCalculationResult == null || !futureCalculationResult.isDone()) { return; } Optional optionalPreview; try { - optionalPreview = futureTask.get(); + optionalPreview = futureCalculationResult.get(); } catch (ExecutionException | InterruptedException ex) { AdvancedPeripherals.debug("Tried to get preview, but preview calculation is not done. Should be done.", org.apache.logging.log4j.Level.ERROR); ex.printStackTrace(); @@ -146,8 +183,7 @@ protected void maybeCraft() { // How RS2 handles crafting is a bit cursed. We first create a preview which calculates the recipes, and then we check if the preview was successful // If it was, we again start a task which again calculates the recipes, and then we hope nothing changed from the first calculation - autocraftingComponent.startTask(toCraft, amount, Actor.EMPTY, false); - setStartedCrafting(); + futureTask = autocraftingComponent.startTask(toCraft, amount, Actor.EMPTY, false); } @Override @@ -162,7 +198,7 @@ protected void startCalculation() { return; } - futureTask = autocraftingComponent.getPreview(toCraft, amount); + futureCalculationResult = autocraftingComponent.getPreview(toCraft, amount); fireEvent(false, StatusConstants.CALCULATION_STARTED); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java similarity index 95% rename from src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 9fd61ef2b..2b02fb13e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorageApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -2,6 +2,7 @@ import com.refinedmods.refinedstorage.api.autocrafting.Ingredient; import com.refinedmods.refinedstorage.api.autocrafting.Pattern; +import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.node.externalstorage.ExposedExternalStorage; @@ -27,6 +28,7 @@ import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.common.util.Pair; @@ -44,6 +46,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -55,7 +58,7 @@ /** * Refined Storage Api helper methods and parsers */ -public class RefinedStorageApi { +public class RsApi { public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event) { event.registerBlockEntity( @@ -404,6 +407,16 @@ public static long getUsedExternStorage(Network network, StorageType type) { return used; } + public static List getCraftingTasks(RsBridgeEntity entity) { + List tasks = new ArrayList<>(); + + for (RSCraftJob task : entity.getJobs()) { + tasks.add(parseCraftingTask(task)); + } + + return tasks; + } + public static Map getObjectFromResourceKey(@NotNull ResourceKey resource) { return getObjectFromResourceKey(resource, 0); } @@ -498,12 +511,25 @@ public static Object parseStorageDisk(StateTrackedStorage disk) { return properties; } + public static Object parseCraftingTask(RSCraftJob task) { + Map properties = new HashMap<>(); + + TaskStatus status = task.getCraftingTask(); + + properties.put("bridge_id", task.getId()); + properties.put("id", status.info().id().toString()); + properties.put("quantity", status.info().amount()); + properties.put("completion", status.percentageCompleted()); + + return properties; + } + public static Object parsePattern(Pattern pattern) { if (pattern == null) return null; - Map map = new HashMap<>(); - map.put("outputs", pattern.layout().outputs().stream().map(RefinedStorageApi::getObjectFromResourceAmount).toList()); + Map propeties = new HashMap<>(); + propeties.put("outputs", pattern.layout().outputs().stream().map(RsApi::getObjectFromResourceAmount).toList()); List>> inputs = pattern.layout().ingredients().stream() .map(ingredient -> ingredient.inputs().stream() @@ -511,10 +537,10 @@ public static Object parsePattern(Pattern pattern) { .collect(Collectors.toList())) .collect(Collectors.toList()); - map.put("inputs", inputs); - map.put("patterntype", pattern.layout().type().toString()); - map.put("id", pattern.id().toString()); - return map; + propeties.put("inputs", inputs); + propeties.put("patterntype", pattern.layout().type().toString()); + propeties.put("id", pattern.id().toString()); + return propeties; } /** diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java index e19c0cf68..e046d5b54 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java @@ -35,7 +35,7 @@ public int fill(FluidStack resource, @NotNull FluidAction action) { @Override public FluidStack drain(FluidFilter filter, FluidAction simulate) { AdvancedPeripherals.debug("Trying to extract fluid from filter: " + filter); - FluidResource fluid = RefinedStorageApi.getFluid(network, filter); + FluidResource fluid = RsApi.getFluid(network, filter); if (fluid == null) return FluidStack.EMPTY; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java index 0b9e5d75b..edf47b625 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java @@ -38,7 +38,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate @Override public ItemStack extractItem(ItemFilter filter, int count, boolean simulate) { AdvancedPeripherals.debug("Trying to extract item from filter: " + filter); - ItemResource itemResource = RefinedStorageApi.getItem(network, filter); + ItemResource itemResource = RsApi.getItem(network, filter); if (itemResource == null) return ItemStack.EMPTY; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java index 24b9261a5..91f949255 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java @@ -193,7 +193,7 @@ protected void fireEvent(boolean error, String message) { this.errorOccurred = error; } - public final void tick() { + public void tick() { startCalculation(); maybeCraft(); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index fce07e8df..029568aa2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -3,6 +3,7 @@ import appeng.api.stacks.GenericStack; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import de.srendi.advancedperipherals.common.util.Pair; +import mekanism.api.MekanismAPI; import net.minecraft.core.registries.BuiltInRegistries; import java.util.Map; @@ -29,11 +30,10 @@ public static Pair, String> parseGeneric(Map ra return ItemFilter.parse(rawFilter); case "fluid": return FluidFilter.parse(rawFilter); + case "chemical": + return ChemicalFilter.parse(rawFilter); } } - // If the filter does not contain a name or a type, which should never happen, but players are players, we will just - // give the ItemFilter the task to parse the filter - return ItemFilter.parse(rawFilter); } String name = rawFilter.get("name").toString(); @@ -42,6 +42,8 @@ public static Pair, String> parseGeneric(Map ra return ItemFilter.parse(rawFilter); } else if (ItemUtil.getRegistryEntry(name, BuiltInRegistries.FLUID) != null) { return FluidFilter.parse(rawFilter); + } else if (ItemUtil.getRegistryEntry(name, MekanismAPI.CHEMICAL_REGISTRY) != null) { + return ChemicalFilter.parse(rawFilter); } else { // If the name is in neither of the registries, we will just return an empty filter return Pair.of(empty(), "NO_VALID_FILTER_TYPE"); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index d48d8adaf..ad92e39e2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -96,27 +96,19 @@ public interface IStorageSystemPeripheral { MethodResult getCraftingTasks(); // A function to get our BasicCraftJob object with the id - MethodResult getCraftingJob(int id); + MethodResult getCraftingTask(int id); MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException; - MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult craftChemical(IComputerAccess computer, IArguments arguments) throws LuaException; - - MethodResult isItemCraftable(IArguments arguments) throws LuaException; - - MethodResult isItemCrafting(IArguments arguments) throws LuaException; - - MethodResult isFluidCraftable(IArguments arguments) throws LuaException; + MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult isFluidCrafting(IArguments arguments) throws LuaException; + MethodResult craftChemical(IComputerAccess computer, IArguments arguments) throws LuaException; - MethodResult isChemicalCraftable(IArguments arguments) throws LuaException; + MethodResult isCraftable(IArguments arguments) throws LuaException; - MethodResult isChemicalCrafting(IArguments arguments) throws LuaException; + MethodResult isCrafting(IArguments arguments) throws LuaException; MethodResult getPatterns(IArguments arguments) throws LuaException; From 6b3ad98cc61f3c375a55d311aab307bb1ec4c67c Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 12 Mar 2025 00:43:00 +0100 Subject: [PATCH 18/91] more chemical functions --- .../peripheral/RSBridgePeripheral.java | 30 +++++++++++++++++-- .../inventory/IStorageSystemPeripheral.java | 10 +++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index a619b3a7d..69c27ced7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -36,7 +36,6 @@ import de.srendi.advancedperipherals.common.util.inventory.InventoryUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; @@ -220,6 +219,11 @@ public MethodResult getFluid(IArguments arguments) throws LuaException { return MethodResult.of(resourceProperties); } + @Override + public MethodResult getChemical(IArguments arguments) throws LuaException { + return null; + } + @Override @LuaFunction(mainThread = true) public MethodResult listItems(IArguments arguments) throws LuaException { @@ -254,6 +258,11 @@ public MethodResult listFluids(IArguments arguments) throws LuaException { return MethodResult.of(resourceProperties); } + @Override + public MethodResult listChemicals(IArguments arguments) throws LuaException { + return null; + } + @Override @LuaFunction(mainThread = true) public MethodResult listCraftableItems(IArguments arguments) throws LuaException { @@ -288,6 +297,11 @@ public MethodResult listCraftableFluids(IArguments arguments) throws LuaExceptio return MethodResult.of(resourceProperties); } + @Override + public MethodResult listCraftableChemicals(IArguments arguments) throws LuaException { + return null; + } + @Override @LuaFunction(mainThread = true) public MethodResult listCells() { @@ -372,6 +386,16 @@ public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) return exportToTank(arguments, handler); } + @Override + public MethodResult importChemical(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + + @Override + public MethodResult exportChemical(IComputerAccess computer, IArguments arguments) throws LuaException { + return null; + } + @Override @LuaFunction(mainThread = true) public MethodResult getStoredEnergy() { @@ -692,7 +716,7 @@ public MethodResult isCraftable(IArguments arguments) throws LuaException { GenericFilter parsedFilter = filter.getLeft(); - return MethodResult.of(RsApi.findPatternFromFilters(getNetwork(), null, parsedFilter).getLeft() != null); + return MethodResult.of(RsApi.findPatternFromFilters(getNetwork(), null, parsedFilter).getLeft() != null); } @Override @@ -711,7 +735,7 @@ public MethodResult isCrafting(IArguments arguments) throws LuaException { for (TaskStatus status : craftingManager.getStatuses()) { if (parsedFilter.testRS(new ResourceAmount(status.info().resource(), 1))) { - return MethodResult.of(true); + return MethodResult.of(true); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index ad92e39e2..a83ba50e3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -29,14 +29,20 @@ public interface IStorageSystemPeripheral { MethodResult getFluid(IArguments arguments) throws LuaException; + MethodResult getChemical(IArguments arguments) throws LuaException; + MethodResult listItems(IArguments arguments) throws LuaException; MethodResult listFluids(IArguments arguments) throws LuaException; + MethodResult listChemicals(IArguments arguments) throws LuaException; + MethodResult listCraftableItems(IArguments arguments) throws LuaException; MethodResult listCraftableFluids(IArguments arguments) throws LuaException; + MethodResult listCraftableChemicals(IArguments arguments) throws LuaException; + MethodResult listCells(); MethodResult listDrives(); @@ -49,6 +55,10 @@ public interface IStorageSystemPeripheral { MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException; + MethodResult importChemical(IComputerAccess computer, IArguments arguments) throws LuaException; + + MethodResult exportChemical(IComputerAccess computer, IArguments arguments) throws LuaException; + MethodResult getStoredEnergy(); MethodResult getEnergyCapacity(); From 8740678961fed98eb9cc888bad620b722ca003ec Mon Sep 17 00:00:00 2001 From: endi Date: Thu, 13 Mar 2025 17:34:34 +0100 Subject: [PATCH 19/91] Chemical support for listing functions --- .../peripheral/RSBridgePeripheral.java | 44 ++++++++++++- .../common/addons/refinedstorage/RsApi.java | 63 ++++++++++++++++++- 2 files changed, 102 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 69c27ced7..993229c30 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -36,6 +36,7 @@ import de.srendi.advancedperipherals.common.util.inventory.InventoryUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; +import mekanism.api.chemical.Chemical; import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; @@ -221,7 +222,22 @@ public MethodResult getFluid(IArguments arguments) throws LuaException { @Override public MethodResult getChemical(IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + Pair filter = ChemicalFilter.parse(arguments.getTable(0)); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + ChemicalFilter parsedFilter = filter.getLeft(); + if (parsedFilter.isEmpty()) + return MethodResult.of(null, "EMPTY_FILTER"); + + Map resourceProperties = RsApi.getParsedChemical(getNetwork(), parsedFilter); + if (resourceProperties == null) + return MethodResult.of(null, "NOT_FOUND"); + + return MethodResult.of(resourceProperties); } @Override @@ -260,7 +276,18 @@ public MethodResult listFluids(IArguments arguments) throws LuaException { @Override public MethodResult listChemicals(IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + Pair filter = ChemicalFilter.parse(arguments.optTable(0, Map.of())); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + ChemicalFilter parsedFilter = filter.getLeft(); + + Set> resourceProperties = RsApi.getParsedCnemicals(getNetwork(), parsedFilter); + + return MethodResult.of(resourceProperties); } @Override @@ -299,7 +326,18 @@ public MethodResult listCraftableFluids(IArguments arguments) throws LuaExceptio @Override public MethodResult listCraftableChemicals(IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + Pair filter = ChemicalFilter.parse(arguments.optTable(0, Map.of())); + if (filter.rightPresent()) + return MethodResult.of(null, filter.getRight()); + + ChemicalFilter parsedFilter = filter.getLeft(); + + Set> resourceProperties = RsApi.getCraftableChemicals(getNetwork(), parsedFilter); + + return MethodResult.of(resourceProperties); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 2b02fb13e..b01584cc5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -157,6 +157,24 @@ public static Map getParsedFluid(Network network, FluidFilter fi return null; } + /** + * Returns the first mekanism chemical parsed to a lua object which fits to the filter + * + * @param network refined storage network + * @param filter chemical filter instance - can be an empty filter to get the first chemical of the system see {@link ChemicalFilter#empty()} + * @return the first chemical in the system that fits the chemical filter or null + */ + @Nullable + public static Map getParsedChemical(Network network, ChemicalFilter filter) { + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { + if (trackedResource.resourceAmount().resource() instanceof ChemicalResource chemicalResource && filter.test(new ChemicalStack(chemicalResource.chemical(), trackedResource.resourceAmount().amount()))) { + return getObjectFromItemResource(trackedResource.resourceAmount()); + } + } + return null; + } + /** * Returns every item from the system while also checking if the filter test passes for the items * The filter can be empty, see {@link ItemFilter#empty()} @@ -197,6 +215,26 @@ public static Set> getParsedFluids(Network network, FluidFil return items; } + /** + * Returns every fluid from the system while also checking if the filter test passes for the fluids + * The filter can be empty, see {@link FluidFilter#empty()} + * + * @param network the rs network + * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource + * @return a set of fluid stacks + */ + public static Set> getParsedCnemicals(Network network, ChemicalFilter filter) { + Set> items = new HashSet<>(); + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { + if (trackedResource.resourceAmount().resource() instanceof ChemicalResource fluidResource && filter.test(new ChemicalStack(fluidResource.chemical(), trackedResource.resourceAmount().amount()))) { + items.add(getObjectFromFluidResource(trackedResource.resourceAmount())); + } + } + + return items; + } + /** * Returns every craftable item from the system while also checking if the filter test passes for the items * The filter can be empty, see {@link ItemFilter#empty()} @@ -238,6 +276,27 @@ public static Set> getCraftableFluids(Network network, Fluid return items; } + /** + * Returns every craftable mekanism chemical from the system while also checking if the filter test passes for the chemicals + * The filter can be empty, see {@link ChemicalFilter#empty()} + * + * @param network the rs network + * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource + * @return a set of parsed chemical stacks + */ + public static Set> getCraftableChemicals(Network network, ChemicalFilter filter) { + Set> items = new HashSet<>(); + AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); + StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); + for (ResourceKey key : autocrafting.getOutputs()) { + long amount = storage.get(key); + if (key instanceof ChemicalResource chemicalResource && filter.test(new ChemicalStack(chemicalResource.chemical(), amount))) { + items.add(getObjectFromResourceKey(key, amount)); + } + } + return items; + } + public static Set getPatterns(Network network) { Set patterns = new HashSet<>(); AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); @@ -290,8 +349,8 @@ public static Set listDrives(Network network) { * The error message is "NO_PATTERN_FOUND" if no pattern is found. */ public static Pair findPatternFromFilters(Network network, @Nullable GenericFilter inputFilter, @Nullable GenericFilter outputFilter) { - AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); - for (Pattern pattern : autocrafting.getPatterns()) { + AutocraftingNetworkComponent autocraftingComponent = network.getComponent(AutocraftingNetworkComponent.class); + for (Pattern pattern : autocraftingComponent.getPatterns()) { if (pattern.layout().ingredients().isEmpty()) continue; if (pattern.layout().outputs().isEmpty()) From a4b851b452e7af89768cd8fdc080450e3471eade Mon Sep 17 00:00:00 2001 From: endi Date: Fri, 14 Mar 2025 01:01:41 +0100 Subject: [PATCH 20/91] Full chemical support --- gradle.properties | 2 +- .../peripheral/MEBridgePeripheral.java | 4 +- .../peripheral/RSBridgePeripheral.java | 72 +++++++++++++- .../common/addons/refinedstorage/RsApi.java | 15 +++ .../refinedstorage/RsChemicalHandler.java | 50 ++++++++++ .../common/util/inventory/ChemicalFilter.java | 42 +++++---- .../common/util/inventory/ChemicalUtil.java | 93 +++++++++++++++++++ .../common/util/inventory/FluidUtil.java | 35 +++++++ .../IStorageSystemChemicalHandler.java | 60 ++++++++++++ .../common/util/inventory/InventoryUtil.java | 38 -------- 10 files changed, 345 insertions(+), 66 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemChemicalHandler.java diff --git a/gradle.properties b/gradle.properties index cad1d50e1..f28b6b8da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,7 +31,7 @@ refinedstorage_version=2.0.0-milestone.4.14 refinedstorage_mekanism_version=0.3.0 appliedenergistics_version=19.1.2-beta patchouli_version=1.21-87 -mekanism_version=1.21.1-10.7.8.70 +mekanism_version=1.21.1-10.7.12.77 ae2things_version=5637783 powah_version=4638301 appliedmekanistics_version=5978711 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java index b3d782e5e..b476d4455 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java @@ -99,7 +99,7 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFl if (targetTank == null) return MethodResult.of(0, "Target Tank does not exist"); - return MethodResult.of(InventoryUtil.moveFluid(fluidHandler, targetTank, filter.getLeft()), null); + return MethodResult.of(FluidUtil.moveFluid(fluidHandler, targetTank, filter.getLeft()), null); } /** @@ -141,7 +141,7 @@ protected MethodResult importToME(@NotNull IArguments arguments, @Nullable IFlui if (targetTank == null) return MethodResult.of(0, "Target Tank does not exist"); - return MethodResult.of(InventoryUtil.moveFluid(targetTank, fluidHandler, filter.getLeft()), null); + return MethodResult.of(FluidUtil.moveFluid(targetTank, fluidHandler, filter.getLeft()), null); } private MethodResult notConnected() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 993229c30..64fcd2e41 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -23,12 +23,14 @@ import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.addons.refinedstorage.RSCraftJob; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RsChemicalHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsFluidHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsItemHandler; import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter; +import de.srendi.advancedperipherals.common.util.inventory.ChemicalUtil; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; @@ -36,7 +38,7 @@ import de.srendi.advancedperipherals.common.util.inventory.InventoryUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.lib.peripherals.BasePeripheral; -import mekanism.api.chemical.Chemical; +import mekanism.api.chemical.IChemicalHandler; import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; @@ -120,7 +122,27 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFl if (targetTank == null) return MethodResult.of(0, "Target Tank does not exist"); - return MethodResult.of(InventoryUtil.moveFluid(fluidHandler, targetTank, filter.getLeft()), null); + return MethodResult.of(FluidUtil.moveFluid(fluidHandler, targetTank, filter.getLeft()), null); + } + + /** + * exports a fluid out of the system to a valid tank + * + * @param arguments the arguments given by the computer + * @param targetTank the give tank + * @return the exportable amount or null with a string if something went wrong + */ + protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IChemicalHandler targetTank) throws LuaException { + RsChemicalHandler chemicalHandler = new RsChemicalHandler(getNetwork()); + Pair filter = ChemicalFilter.parse(arguments.getTable(0)); + + if (filter.rightPresent()) + return MethodResult.of(0, filter.getRight()); + + if (targetTank == null) + return MethodResult.of(0, "Target Tank does not exist"); + + return MethodResult.of(ChemicalUtil.moveChemical(chemicalHandler, targetTank, filter.getLeft()), null); } /** @@ -160,7 +182,27 @@ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IFlui if (targetTank == null) return MethodResult.of(0, "Target Tank does not exist"); - return MethodResult.of(InventoryUtil.moveFluid(targetTank, fluidHandler, filter.getLeft()), null); + return MethodResult.of(FluidUtil.moveFluid(targetTank, fluidHandler, filter.getLeft()), null); + } + + /** + * imports a fluid to the system from a valid tank + * + * @param arguments the arguments given by the computer + * @param targetTank the give tank + * @return the imported amount or null with a string if something went wrong + */ + protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IChemicalHandler targetTank) throws LuaException { + RsChemicalHandler chemicalHandler = new RsChemicalHandler(getNetwork()); + Pair filter = ChemicalFilter.parse(arguments.getTable(0)); + + if (filter.rightPresent()) + return MethodResult.of(0, filter.getRight()); + + if (targetTank == null) + return MethodResult.of(0, "Target Tank does not exist"); + + return MethodResult.of(ChemicalUtil.moveChemical(targetTank, chemicalHandler, filter.getLeft()), null); } @Override @@ -426,12 +468,32 @@ public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) @Override public MethodResult importChemical(IComputerAccess computer, IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); + if (handler == null) + handler = ChemicalUtil.getHandlerFromName(computer, arguments.getString(1)); + + if (handler == null) + return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + + return importToRS(arguments, handler); } @Override public MethodResult exportChemical(IComputerAccess computer, IArguments arguments) throws LuaException { - return null; + if (!isAvailable()) + return notConnected(); + + IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); + if (handler == null) + handler = ChemicalUtil.getHandlerFromName(computer, arguments.getString(1)); + + if (handler == null) + return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + + return exportToTank(arguments, handler); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index b01584cc5..13055df9c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -38,6 +38,7 @@ import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemFilter; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; +import mekanism.api.MekanismAPI; import mekanism.api.chemical.ChemicalStack; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; @@ -661,4 +662,18 @@ public static Map getObjectFromFluidResource(ResourceAmount trac return properties; } + public static ChemicalStack resourceToChemicalStack(ResourceAmount resourceAmount) { + if (resourceAmount.resource() instanceof ChemicalResource chemicalResource) + return new ChemicalStack(MekanismAPI.CHEMICAL_REGISTRY.createIntrusiveHolder(chemicalResource.chemical()), resourceAmount.amount()); + + return ChemicalStack.EMPTY; + } + + public static ChemicalStack resourceToChemicalStack(ChemicalResource resource, long alternateCount) { + return new ChemicalStack(MekanismAPI.CHEMICAL_REGISTRY.createIntrusiveHolder(resource.chemical()), alternateCount); + } + + public static ChemicalStack resourceToChemicalStack(ChemicalResource resource) { + return resourceToChemicalStack(resource, 1); + } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java new file mode 100644 index 000000000..5a2e89e35 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java @@ -0,0 +1,50 @@ +package de.srendi.advancedperipherals.common.addons.refinedstorage; + +import com.refinedmods.refinedstorage.api.core.Action; +import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage.api.storage.Actor; +import com.refinedmods.refinedstorage.mekanism.ChemicalResource; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter; +import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemChemicalHandler; +import mekanism.api.chemical.ChemicalStack; +import org.jetbrains.annotations.NotNull; + +public class RsChemicalHandler implements IStorageSystemChemicalHandler { + + @NotNull + private final Network network; + private final StorageNetworkComponent component; + + public RsChemicalHandler(@NotNull Network network) { + this.network = network; + this.component = network.getComponent(StorageNetworkComponent.class); + } + + @NotNull + @Override + public ChemicalStack insertChemical(int tank, ChemicalStack resource, mekanism.api.Action action) { + if (resource.isEmpty()) + return resource; + + ChemicalStack chemical = resource.copy(); + chemical.setAmount(resource.getAmount() - component.insert(ChemicalResource.ofChemicalStack(chemical), resource.getAmount(), action == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + return chemical; + } + + @Override + public ChemicalStack extractChemical(ChemicalFilter filter, long count, mekanism.api.Action simulate) { + AdvancedPeripherals.debug("Trying to extract fluid from filter: " + filter); + ChemicalResource fluid = RsApi.getChemical(network, filter); + if (fluid == null) + return ChemicalStack.EMPTY; + + ChemicalStack extracted = new ChemicalStack(fluid.chemical(), 1); + extracted.setAmount((int) component.extract(fluid, filter.getCount(), simulate == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + + AdvancedPeripherals.debug("Extracted fluid: " + extracted + " from filter: " + filter); + return extracted; + } + +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java index 905a54594..b6510bfa9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java @@ -6,10 +6,12 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi; import de.srendi.advancedperipherals.common.util.Pair; import mekanism.api.MekanismAPI; import mekanism.api.chemical.Chemical; import mekanism.api.chemical.ChemicalStack; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; @@ -17,9 +19,9 @@ public class ChemicalFilter extends GenericFilter { - private Chemical chemical = MekanismAPI.EMPTY_CHEMICAL; + private Holder chemical = MekanismAPI.EMPTY_CHEMICAL_HOLDER; private TagKey tag = null; - private int count = 64; + private long count = 64; private String fingerprint = ""; public int fromSlot = -1; public int toSlot = -1; @@ -28,16 +30,16 @@ private ChemicalFilter() { } public static Pair parse(Map item) { - ChemicalFilter itemFilter = empty(); + ChemicalFilter chemicalFilter = empty(); // If the map is empty, return a filter without any filters if (item.isEmpty()) - return Pair.of(itemFilter, null); + return Pair.of(chemicalFilter, null); if (item.containsKey("name")) { try { String name = TableHelper.getStringField(item, "name"); if (name.startsWith("#")) { - itemFilter.tag = TagKey.create(MekanismAPI.CHEMICAL_REGISTRY_NAME, ResourceLocation.parse(name.substring(1))); - } else if ((itemFilter.chemical = ItemUtil.getRegistryEntry(name, MekanismAPI.CHEMICAL_REGISTRY)) == null) { + chemicalFilter.tag = TagKey.create(MekanismAPI.CHEMICAL_REGISTRY_NAME, ResourceLocation.parse(name.substring(1))); + } else if ((chemicalFilter.chemical = MekanismAPI.CHEMICAL_REGISTRY.getHolder(ResourceLocation.parse(name)).orElse(null)) == null) { return Pair.of(null, "CHEMICAL_NOT_FOUND"); } } catch (LuaException luaException) { @@ -46,40 +48,40 @@ public static Pair parse(Map item) { } if (item.containsKey("fingerprint")) { try { - itemFilter.fingerprint = TableHelper.getStringField(item, "fingerprint"); + chemicalFilter.fingerprint = TableHelper.getStringField(item, "fingerprint"); } catch (LuaException luaException) { return Pair.of(null, "NO_VALID_FINGERPRINT"); } } if (item.containsKey("fromSlot")) { try { - itemFilter.fromSlot = TableHelper.getIntField(item, "fromSlot"); + chemicalFilter.fromSlot = TableHelper.getIntField(item, "fromSlot"); } catch (LuaException luaException) { return Pair.of(null, "NO_VALID_FROMSLOT"); } } if (item.containsKey("toSlot")) { try { - itemFilter.toSlot = TableHelper.getIntField(item, "toSlot"); + chemicalFilter.toSlot = TableHelper.getIntField(item, "toSlot"); } catch (LuaException luaException) { return Pair.of(null, "NO_VALID_TOSLOT"); } } if (item.containsKey("count")) { try { - itemFilter.count = TableHelper.getIntField(item, "count"); + chemicalFilter.count = TableHelper.getIntField(item, "count"); } catch (LuaException luaException) { return Pair.of(null, "NO_VALID_COUNT"); } } - AdvancedPeripherals.debug("Parsed item filter: " + itemFilter); - return Pair.of(itemFilter, null); + AdvancedPeripherals.debug("Parsed item filter: " + chemicalFilter); + return Pair.of(chemicalFilter, null); } public static ChemicalFilter fromStack(ChemicalStack stack) { ChemicalFilter filter = empty(); - filter.chemical = stack.getChemical(); + filter.chemical = stack.getChemicalHolder(); return filter; } @@ -88,7 +90,7 @@ public static ChemicalFilter empty() { } public boolean isEmpty() { - return fingerprint.isEmpty() && chemical == MekanismAPI.EMPTY_CHEMICAL && tag == null; + return fingerprint.isEmpty() && chemical.is(MekanismAPI.EMPTY_CHEMICAL_KEY) && tag == null; } @Override @@ -102,7 +104,7 @@ public boolean testAE(GenericStack genericStack) { @Override public boolean testRS(ResourceAmount resourceAmount) { if (resourceAmount.resource() instanceof ChemicalResource chemicalResource) { - return test(new ChemicalStack(chemical.getChemical(), resourceAmount.amount())); + return test(RsApi.resourceToChemicalStack(chemicalResource)); } return false; } @@ -120,7 +122,7 @@ public boolean test(ChemicalStack stack) { return fingerprint.equals(testFingerprint); } - if (chemical != MekanismAPI.EMPTY_CHEMICAL && !stack.is(chemical)) { + if (!chemical.is(MekanismAPI.EMPTY_CHEMICAL_KEY) && !stack.is(chemical)) { return false; } if (tag != null && !stack.is(tag)) { @@ -130,11 +132,11 @@ public boolean test(ChemicalStack stack) { return true; } - public int getCount() { + public long getCount() { return count; } - public Chemical getChemical() { + public Holder getChemical() { return chemical; } @@ -148,8 +150,8 @@ public int getToSlot() { @Override public String toString() { - return "ItemFilter{" + - "item=" + ChemicalUtil.getRegistryKey(chemical) + + return "ChemicalFilter{" + + "item=" + chemical.getRegisteredName() + ", tag=" + tag + ", count=" + count + ", fingerprint='" + fingerprint + '\'' + diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java index 449e8d1b4..2e1588173 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java @@ -1,19 +1,112 @@ package de.srendi.advancedperipherals.common.util.inventory; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.peripheral.IPeripheral; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.computercraft.owner.IPeripheralOwner; +import de.srendi.advancedperipherals.common.util.CoordUtil; import de.srendi.advancedperipherals.common.util.StringUtil; +import mekanism.api.Action; import mekanism.api.MekanismAPI; import mekanism.api.chemical.Chemical; import mekanism.api.chemical.ChemicalStack; +import mekanism.api.chemical.IChemicalHandler; +import mekanism.common.capabilities.Capabilities; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Objects; public class ChemicalUtil { + public static long moveChemical(IChemicalHandler inventoryFrom, IChemicalHandler inventoryTo, ChemicalFilter filter) { + if (inventoryFrom == null) return 0; + + long amount = filter.getCount(); + long transferableAmount = 0; + + // The logic changes with storage systems since these systems do not have slots + if (inventoryFrom instanceof IStorageSystemChemicalHandler storageSystemHandler) { + ChemicalStack extracted = storageSystemHandler.extractChemical(filter, amount, Action.SIMULATE); + ChemicalStack remaining = inventoryTo.insertChemical(extracted, Action.EXECUTE); + + transferableAmount += storageSystemHandler.extractChemical(filter, amount - remaining.getAmount(), Action.EXECUTE).getAmount(); + + return transferableAmount; + } + + if (inventoryTo instanceof IStorageSystemChemicalHandler storageSystemHandler) { + if (filter.test(inventoryFrom.getChemicalInTank(0))) { + ChemicalStack toExtract = inventoryFrom.getChemicalInTank(0).copy(); + toExtract.setAmount(amount); + ChemicalStack extracted = inventoryFrom.extractChemical(toExtract, Action.SIMULATE); + if (extracted.isEmpty()) + return 0; + long remaining = storageSystemHandler.insertChemical(extracted, Action.EXECUTE).getAmount(); + + extracted.setAmount(extracted.getAmount() + remaining); + transferableAmount += inventoryFrom.extractChemical(extracted, Action.EXECUTE).getAmount(); + } + + return transferableAmount; + } + + return transferableAmount; + } + + public static IChemicalHandler extractHandler(@Nullable Object object, @Nullable Level level, @Nullable BlockPos pos, @Nullable Direction direction) { + if (object instanceof IChemicalHandler itemHandler) + return itemHandler; + if (object instanceof BlockEntity blockEntity && level == null && pos == null) { + pos = blockEntity.getBlockPos(); + level = blockEntity.getLevel(); + } + if (level != null && pos != null) { + return level.getCapability(Capabilities.CHEMICAL.block(), pos, direction != null ? direction : Direction.NORTH); + } + return null; + } + + @Nullable + public static IChemicalHandler getHandlerFromDirection(@NotNull String direction, @NotNull IPeripheralOwner owner) throws LuaException { + Level level = owner.getLevel(); + Objects.requireNonNull(level); + Direction relativeDirection = CoordUtil.getDirection(owner.getOrientation(), direction); + BlockEntity target = level.getBlockEntity(owner.getPos().relative(relativeDirection)); + if (target == null) + return null; + + return extractHandler(target, level, owner.getPos().relative(relativeDirection), relativeDirection); + } + + @Nullable + public static IChemicalHandler getHandlerFromName(@NotNull IComputerAccess access, String name) throws LuaException { + IPeripheral location = access.getAvailablePeripheral(name); + + // Tanks/Block Entities can't be accessed if the bridge is not exposed to the same network as the target tank/block entity + // This can occur when the bridge was wrapped via a side and not via modems + if (location == null) + return null; + + IChemicalHandler handler = extractHandler(location.getTarget(), null, null, null); + if (handler == null) + throw new LuaException("Target '" + name + "' is not a fluid handler"); + return handler; + } + + public static ChemicalStack toChemicalStack(Chemical chemical, long amount) { + return new ChemicalStack(MekanismAPI.CHEMICAL_REGISTRY.wrapAsHolder(chemical), amount); + } + @NotNull public static String getFingerprint(@NotNull ChemicalStack stack) { // A pretty lame fingerprint, a chemical stack does not have any components or other stuff diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java index 5218219e3..da5dda72b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidUtil.java @@ -30,6 +30,41 @@ public class FluidUtil { private FluidUtil() { } + public static int moveFluid(IFluidHandler inventoryFrom, IFluidHandler inventoryTo, FluidFilter filter) { + if (inventoryFrom == null) return 0; + + int amount = filter.getCount(); + int transferableAmount = 0; + + // The logic changes with storage systems since these systems do not have slots + if (inventoryFrom instanceof IStorageSystemFluidHandler storageSystemHandler) { + FluidStack extracted = storageSystemHandler.drain(filter, IFluidHandler.FluidAction.SIMULATE); + int inserted = inventoryTo.fill(extracted, IFluidHandler.FluidAction.EXECUTE); + + transferableAmount += storageSystemHandler.drain(filter.setCount(inserted), IFluidHandler.FluidAction.EXECUTE).getAmount(); + + return transferableAmount; + } + + if (inventoryTo instanceof IStorageSystemFluidHandler storageSystemHandler) { + if (filter.test(inventoryFrom.getFluidInTank(0))) { + FluidStack toExtract = inventoryFrom.getFluidInTank(0).copy(); + toExtract.setAmount(amount); + FluidStack extracted = inventoryFrom.drain(toExtract, IFluidHandler.FluidAction.SIMULATE); + if (extracted.isEmpty()) + return 0; + int inserted = storageSystemHandler.fill(extracted, IFluidHandler.FluidAction.EXECUTE); + + extracted.setAmount(inserted); + transferableAmount += inventoryFrom.drain(extracted, IFluidHandler.FluidAction.EXECUTE).getAmount(); + } + + return transferableAmount; + } + + return transferableAmount; + } + public static IFluidHandler extractHandler(@Nullable Object object, @Nullable Level level, @Nullable BlockPos pos, @Nullable Direction direction) { if (object instanceof IFluidHandler itemHandler) return itemHandler; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemChemicalHandler.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemChemicalHandler.java new file mode 100644 index 000000000..a87de0b8a --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemChemicalHandler.java @@ -0,0 +1,60 @@ +package de.srendi.advancedperipherals.common.util.inventory; + +import mekanism.api.Action; +import mekanism.api.chemical.ChemicalStack; +import mekanism.api.chemical.IChemicalHandler; + +public interface IStorageSystemChemicalHandler extends IChemicalHandler { + + /** + * Used to extract an item from the system via a peripheral. + * Uses a filter to find the right item. The amount should never be greater than 64 + * stack sizes greater than 64. + * + * @param filter The parsed filter + * @param count The amount to extract + * @param simulate Should this action be simulated + * @return extracted from the slot, must be empty if nothing can be extracted. The returned ItemStack can be safely modified after, so item handlers should return a new or copied stack. + */ + ChemicalStack extractChemical(ChemicalFilter filter, long count, Action simulate); + + @Override + default int getChemicalTanks() { + return 1; + } + + @Override + default long getChemicalTankCapacity(int tank) { + return Integer.MAX_VALUE; + } + + @Override + default ChemicalStack getChemicalInTank(int tank) { + return ChemicalStack.EMPTY; + } + + @Override + default ChemicalStack extractChemical(long amount, Action action) { + return ChemicalStack.EMPTY; + } + + @Override + default ChemicalStack extractChemical(ChemicalStack stack, Action action) { + return ChemicalStack.EMPTY; + } + + @Override + default ChemicalStack extractChemical(int tank, long amount, Action action) { + return ChemicalStack.EMPTY; + } + + @Override + default void setChemicalInTank(int tank, ChemicalStack stack) { + + } + + @Override + default boolean isValid(int tank, ChemicalStack stack) { + return true; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java index b0900f857..e8a6fb7a1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/InventoryUtil.java @@ -12,8 +12,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.neoforged.neoforge.capabilities.Capabilities; -import net.neoforged.neoforge.fluids.FluidStack; -import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.ItemHandlerHelper; import net.neoforged.neoforge.items.wrapper.InvWrapper; @@ -108,42 +106,6 @@ public static int moveItem(IItemHandler inventoryFrom, IItemHandler inventoryTo, return transferableAmount; } - public static int moveFluid(IFluidHandler inventoryFrom, IFluidHandler inventoryTo, FluidFilter filter) { - if (inventoryFrom == null) return 0; - - int amount = filter.getCount(); - int transferableAmount = 0; - - // The logic changes with storage systems since these systems do not have slots - if (inventoryFrom instanceof IStorageSystemFluidHandler storageSystemHandler) { - FluidStack extracted = storageSystemHandler.drain(filter, IFluidHandler.FluidAction.SIMULATE); - int inserted = inventoryTo.fill(extracted, IFluidHandler.FluidAction.EXECUTE); - - transferableAmount += storageSystemHandler.drain(filter.setCount(inserted), IFluidHandler.FluidAction.EXECUTE).getAmount(); - - return transferableAmount; - } - - if (inventoryTo instanceof IStorageSystemFluidHandler storageSystemHandler) { - if (filter.test(inventoryFrom.getFluidInTank(0))) { - FluidStack toExtract = inventoryFrom.getFluidInTank(0).copy(); - toExtract.setAmount(amount); - FluidStack extracted = inventoryFrom.drain(toExtract, IFluidHandler.FluidAction.SIMULATE); - if (extracted.isEmpty()) - return 0; - int inserted = storageSystemHandler.fill(extracted, IFluidHandler.FluidAction.EXECUTE); - - extracted.setAmount(inserted); - transferableAmount += inventoryFrom.drain(extracted, IFluidHandler.FluidAction.EXECUTE).getAmount(); - } - - return transferableAmount; - } - - return transferableAmount; - } - - @Nullable public static IItemHandler getHandlerFromName(@NotNull IComputerAccess access, String name) throws LuaException { IPeripheral location = access.getAvailablePeripheral(name); From 8e72c637011306296c9d7000b41a0e293053d43d Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 20 Mar 2025 00:11:01 +0100 Subject: [PATCH 21/91] More cursed RS2 implementations but the bridge should be completed by now. We may change some api design before we release the update --- gradle.properties | 2 +- .../addons/refinedstorage/RSCraftJob.java | 40 +++++++++++++++---- .../common/addons/refinedstorage/RsApi.java | 2 +- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index f28b6b8da..9bbbf2a9e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ mod_id=advancedperipherals mod_version=0.7.49a minecraft_version=1.21.1 mod_artifact_suffix= -neo_version=21.1.115 +neo_version=21.1.133 parchment_minecraft_version=1.21.1 parchment_mappings_version=2024.11.17 loader_version=4 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index fefef8fec..48de38049 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -13,9 +13,11 @@ import de.srendi.advancedperipherals.common.util.inventory.BasicCraftJob; import net.minecraft.world.level.Level; +import java.util.Collections; import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.stream.Collectors; public class RSCraftJob extends BasicCraftJob { @@ -23,6 +25,7 @@ public class RSCraftJob extends BasicCraftJob { private final ResourceKey toCraft; private TaskStatus craftingTask; + private Preview preview; private Future> futureCalculationResult; private Future> futureTask; @@ -71,27 +74,41 @@ public long getItemProgress() { @Override public Object getEmittedItems() { - return null; + if (preview == null) { + return Collections.emptyList(); + } + + return preview.items().stream().filter(item -> item.toCraft() > 0).map(item -> RsApi.getObjectFromResourceKey(item.resource(), item.toCraft())).collect(Collectors.toList()); } @Override public Object getUsedItems() { - return null; + // Not supported for rs2 + return Collections.emptyList(); } @Override public Object getMissingItems() { - return null; + if (preview == null) { + return Collections.emptyList(); + } + + return preview.items().stream().filter(item -> item.missing() > 0).map(item -> RsApi.getObjectFromResourceKey(item.resource(), item.missing())).collect(Collectors.toList()); } @Override public boolean hasMultiplePaths() { + // Not supported for rs2 return false; } @Override public Object getFinalOutput() { - return null; + if (preview == null) { + return Collections.emptyList(); + } + + return preview.outputsOfPatternWithCycle().stream().map(RsApi::getObjectFromResourceAmount).collect(Collectors.toList()); } public TaskStatus getCraftingTask() { @@ -110,6 +127,15 @@ public boolean cancel() { @Override public void tick() { super.tick(); + // RS2 does re-create a new instance of the TaskStatus when something changes - so we actually need to re fetch that from the system + // It's cursed, but the only way currently + if (craftingTask != null) { + for (TaskStatus status : autocraftingComponent.getStatuses()) { + if (status.info().id() == craftingTask.info().id()) { + this.craftingTask = status; + } + } + } // The following is to get the TaskStatus from the issued task if (futureTask == null || !futureTask.isDone() || craftingTask != null) { return; @@ -134,11 +160,9 @@ public void tick() { for (TaskStatus status : autocraftingComponent.getStatuses()) { if (status.info().id() == id) { this.craftingTask = status; - // And only now we set that the crafting is started. setStartedCrafting(); } - } } @@ -166,7 +190,9 @@ protected void maybeCraft() { return; } - Preview preview = optionalPreview.orElse(null); + Preview preview = optionalPreview.get(); + this.preview = preview; + PreviewType previewType = preview.type(); if (previewType == PreviewType.MISSING_RESOURCES) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 13055df9c..4c7aa50cf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -512,7 +512,7 @@ public static Map getObjectFromResourceKey(@NotNull ResourceKey * @param resourceAmount the resourceAmount * @return the parsed key to a lua properties map */ - private static Map getObjectFromResourceAmount(@NotNull ResourceAmount resourceAmount) { + public static Map getObjectFromResourceAmount(@NotNull ResourceAmount resourceAmount) { if (resourceAmount.resource() instanceof ItemResource) { return getObjectFromItemResource(resourceAmount); } From a0dabec42c729f5d8a4c805b56a9fff663b52943 Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 20 Mar 2025 00:20:12 +0100 Subject: [PATCH 22/91] Update src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../common/addons/refinedstorage/RSCraftJob.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index 48de38049..d6e7ab60a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -162,6 +162,7 @@ public void tick() { this.craftingTask = status; // And only now we set that the crafting is started. setStartedCrafting(); + break; } } } From cef035c9a74e1a4d4649825d54d39aaedeb65edf Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 20 Mar 2025 00:20:18 +0100 Subject: [PATCH 23/91] Update src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../common/addons/refinedstorage/RSCraftJob.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index d6e7ab60a..4dbc5e327 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -133,6 +133,7 @@ public void tick() { for (TaskStatus status : autocraftingComponent.getStatuses()) { if (status.info().id() == craftingTask.info().id()) { this.craftingTask = status; + break; } } } From 31a71185bec71d499f0044f9353fd3b1587c5c54 Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 20 Mar 2025 00:31:44 +0100 Subject: [PATCH 24/91] Add missing final keywords and lua function annotations --- .../peripheral/RSBridgePeripheral.java | 104 +++++++++--------- 1 file changed, 55 insertions(+), 49 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 64fcd2e41..fc66a0516 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -60,7 +60,6 @@ public RSBridgePeripheral(RsBridgeEntity owner) { } @Override - @LuaFunction(mainThread = true) public boolean isEnabled() { return APAddons.refinedStorageLoaded && APConfig.PERIPHERALS_CONFIG.enableRSBridge.get(); } @@ -207,13 +206,13 @@ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IChem @Override @LuaFunction(mainThread = true) - public MethodResult isConnected() { + public final MethodResult isConnected() { return MethodResult.of(isAvailable()); } @Override @LuaFunction(mainThread = true) - public MethodResult isOnline() { + public final MethodResult isOnline() { if (!isAvailable()) return notConnected(); @@ -222,7 +221,7 @@ public MethodResult isOnline() { @Override @LuaFunction(mainThread = true) - public MethodResult getItem(IArguments arguments) throws LuaException { + public final MethodResult getItem(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -243,7 +242,7 @@ public MethodResult getItem(IArguments arguments) throws LuaException { @Override @LuaFunction(mainThread = true) - public MethodResult getFluid(IArguments arguments) throws LuaException { + public final MethodResult getFluid(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -263,7 +262,8 @@ public MethodResult getFluid(IArguments arguments) throws LuaException { } @Override - public MethodResult getChemical(IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult getChemical(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -284,7 +284,7 @@ public MethodResult getChemical(IArguments arguments) throws LuaException { @Override @LuaFunction(mainThread = true) - public MethodResult listItems(IArguments arguments) throws LuaException { + public final MethodResult listItems(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -301,7 +301,7 @@ public MethodResult listItems(IArguments arguments) throws LuaException { @Override @LuaFunction(mainThread = true) - public MethodResult listFluids(IArguments arguments) throws LuaException { + public final MethodResult listFluids(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -317,7 +317,8 @@ public MethodResult listFluids(IArguments arguments) throws LuaException { } @Override - public MethodResult listChemicals(IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult listChemicals(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -334,7 +335,7 @@ public MethodResult listChemicals(IArguments arguments) throws LuaException { @Override @LuaFunction(mainThread = true) - public MethodResult listCraftableItems(IArguments arguments) throws LuaException { + public final MethodResult listCraftableItems(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -351,7 +352,7 @@ public MethodResult listCraftableItems(IArguments arguments) throws LuaException @Override @LuaFunction(mainThread = true) - public MethodResult listCraftableFluids(IArguments arguments) throws LuaException { + public final MethodResult listCraftableFluids(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -367,7 +368,8 @@ public MethodResult listCraftableFluids(IArguments arguments) throws LuaExceptio } @Override - public MethodResult listCraftableChemicals(IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult listCraftableChemicals(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -384,7 +386,7 @@ public MethodResult listCraftableChemicals(IArguments arguments) throws LuaExcep @Override @LuaFunction(mainThread = true) - public MethodResult listCells() { + public final MethodResult listCells() { if (!isAvailable()) return notConnected(); @@ -393,7 +395,7 @@ public MethodResult listCells() { @Override @LuaFunction(mainThread = true) - public MethodResult listDrives() { + public final MethodResult listDrives() { if (!isAvailable()) return notConnected(); @@ -419,7 +421,7 @@ public final MethodResult importItem(IComputerAccess computer, IArguments argume @Override @LuaFunction(mainThread = true) - public MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException { + public final MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -436,7 +438,7 @@ public MethodResult exportItem(IComputerAccess computer, IArguments arguments) t @Override @LuaFunction(mainThread = true) - public MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + public final MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -452,7 +454,7 @@ public MethodResult importFluid(IComputerAccess computer, IArguments arguments) @Override @LuaFunction(mainThread = true) - public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + public final MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -467,7 +469,8 @@ public MethodResult exportFluid(IComputerAccess computer, IArguments arguments) } @Override - public MethodResult importChemical(IComputerAccess computer, IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult importChemical(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -482,7 +485,8 @@ public MethodResult importChemical(IComputerAccess computer, IArguments argument } @Override - public MethodResult exportChemical(IComputerAccess computer, IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult exportChemical(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -498,7 +502,7 @@ public MethodResult exportChemical(IComputerAccess computer, IArguments argument @Override @LuaFunction(mainThread = true) - public MethodResult getStoredEnergy() { + public final MethodResult getStoredEnergy() { if (!isAvailable()) return notConnected(); @@ -509,7 +513,7 @@ public MethodResult getStoredEnergy() { @Override @LuaFunction(mainThread = true) - public MethodResult getEnergyCapacity() { + public final MethodResult getEnergyCapacity() { if (!isAvailable()) return notConnected(); @@ -520,7 +524,7 @@ public MethodResult getEnergyCapacity() { @Override @LuaFunction(mainThread = true) - public MethodResult getEnergyUsage() { + public final MethodResult getEnergyUsage() { if (!isAvailable()) return notConnected(); @@ -529,7 +533,7 @@ public MethodResult getEnergyUsage() { @Override @LuaFunction(mainThread = true) - public MethodResult getAvgPowerInjection() { + public final MethodResult getAvgPowerInjection() { if (!isAvailable()) return notConnected(); @@ -538,7 +542,7 @@ public MethodResult getAvgPowerInjection() { @Override @LuaFunction(mainThread = true) - public MethodResult getTotalExternItemStorage() { + public final MethodResult getTotalExternItemStorage() { if (!isAvailable()) return notConnected(); @@ -547,7 +551,7 @@ public MethodResult getTotalExternItemStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getTotalExternFluidStorage() { + public final MethodResult getTotalExternFluidStorage() { if (!isAvailable()) return notConnected(); @@ -556,7 +560,7 @@ public MethodResult getTotalExternFluidStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getTotalExternChemicalStorage() { + public final MethodResult getTotalExternChemicalStorage() { if (!isAvailable()) return notConnected(); @@ -565,7 +569,7 @@ public MethodResult getTotalExternChemicalStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getTotalItemStorage() { + public final MethodResult getTotalItemStorage() { if (!isAvailable()) return notConnected(); @@ -574,7 +578,7 @@ public MethodResult getTotalItemStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getTotalFluidStorage() { + public final MethodResult getTotalFluidStorage() { if (!isAvailable()) return notConnected(); @@ -583,7 +587,7 @@ public MethodResult getTotalFluidStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getTotalChemicalStorage() { + public final MethodResult getTotalChemicalStorage() { if (!isAvailable()) return notConnected(); @@ -592,7 +596,7 @@ public MethodResult getTotalChemicalStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getUsedExternItemStorage() { + public final MethodResult getUsedExternItemStorage() { if (!isAvailable()) return notConnected(); @@ -601,7 +605,7 @@ public MethodResult getUsedExternItemStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getUsedExternFluidStorage() { + public final MethodResult getUsedExternFluidStorage() { if (!isAvailable()) return notConnected(); @@ -610,7 +614,7 @@ public MethodResult getUsedExternFluidStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getUsedExternChemicalStorage() { + public final MethodResult getUsedExternChemicalStorage() { if (!isAvailable()) return notConnected(); @@ -619,7 +623,7 @@ public MethodResult getUsedExternChemicalStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getUsedItemStorage() { + public final MethodResult getUsedItemStorage() { if (!isAvailable()) return notConnected(); @@ -628,7 +632,7 @@ public MethodResult getUsedItemStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getUsedFluidStorage() { + public final MethodResult getUsedFluidStorage() { if (!isAvailable()) return notConnected(); @@ -637,7 +641,7 @@ public MethodResult getUsedFluidStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getUsedChemicalStorage() { + public final MethodResult getUsedChemicalStorage() { if (!isAvailable()) return notConnected(); @@ -646,7 +650,7 @@ public MethodResult getUsedChemicalStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getAvailableExternItemStorage() { + public final MethodResult getAvailableExternItemStorage() { if (!isAvailable()) return notConnected(); @@ -655,7 +659,7 @@ public MethodResult getAvailableExternItemStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getAvailableExternFluidStorage() { + public final MethodResult getAvailableExternFluidStorage() { if (!isAvailable()) return notConnected(); @@ -664,7 +668,7 @@ public MethodResult getAvailableExternFluidStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getAvailableExternChemicalStorage() { + public final MethodResult getAvailableExternChemicalStorage() { if (!isAvailable()) return notConnected(); @@ -673,7 +677,7 @@ public MethodResult getAvailableExternChemicalStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getAvailableItemStorage() { + public final MethodResult getAvailableItemStorage() { if (!isAvailable()) return notConnected(); @@ -682,7 +686,7 @@ public MethodResult getAvailableItemStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getAvailableFluidStorage() { + public final MethodResult getAvailableFluidStorage() { if (!isAvailable()) return notConnected(); @@ -691,7 +695,7 @@ public MethodResult getAvailableFluidStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult getAvailableChemicalStorage() { + public final MethodResult getAvailableChemicalStorage() { if (!isAvailable()) return notConnected(); @@ -700,7 +704,7 @@ public MethodResult getAvailableChemicalStorage() { @Override @LuaFunction(mainThread = true) - public MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { + public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -719,7 +723,7 @@ public MethodResult craftItem(IComputerAccess computer, IArguments arguments) th @Override @LuaFunction(mainThread = true) - public MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { + public final MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -737,7 +741,8 @@ public MethodResult craftFluid(IComputerAccess computer, IArguments arguments) t } @Override - public MethodResult craftChemical(IComputerAccess computer, IArguments arguments) throws LuaException { + @LuaFunction(mainThread = true) + public final MethodResult craftChemical(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -756,7 +761,7 @@ public MethodResult craftChemical(IComputerAccess computer, IArguments arguments @Override @LuaFunction(mainThread = true) - public MethodResult getCraftingTasks() { + public final MethodResult getCraftingTasks() { if (!isAvailable()) return notConnected(); @@ -764,7 +769,8 @@ public MethodResult getCraftingTasks() { } @Override - public MethodResult getCraftingTask(int id) { + @LuaFunction(mainThread = true) + public final MethodResult getCraftingTask(int id) { if (!isAvailable()) return notConnected(); @@ -780,7 +786,7 @@ public MethodResult getCraftingTask(int id) { @Override @LuaFunction(mainThread = true) - public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { + public final MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -806,7 +812,7 @@ public MethodResult cancelCraftingTasks(IArguments arguments) throws LuaExceptio @Override @LuaFunction(mainThread = true) - public MethodResult isCraftable(IArguments arguments) throws LuaException { + public final MethodResult isCraftable(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); @@ -821,7 +827,7 @@ public MethodResult isCraftable(IArguments arguments) throws LuaException { @Override @LuaFunction(mainThread = true) - public MethodResult isCrafting(IArguments arguments) throws LuaException { + public final MethodResult isCrafting(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); From 9786d9db1e820f33c7d24e34a7380fc17c540375 Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 20 Mar 2025 00:33:31 +0100 Subject: [PATCH 25/91] Refined Storage 2 -> Refined Storage for the RS Bridge's description --- .../resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca | 4 ++-- .../resources/assets/advancedperipherals/lang/en_us.json | 2 +- .../advancedperipherals/common/data/EnUsLanguageProvider.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca b/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca index dc8ebf49f..78f757f2c 100644 --- a/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca +++ b/src/generated/resources/.cache/2f719b8031aed5e605ed8d6694b19245ca45c6ca @@ -1,2 +1,2 @@ -// 1.21.1 2025-01-15T15:11:12.9930186 Languages: en_us for mod: advancedperipherals -9ca9c60d1ceb2e69c860576cef4ba3095159b16f assets/advancedperipherals/lang/en_us.json +// 1.21.1 2025-03-20T00:32:42.9859105 Languages: en_us for mod: advancedperipherals +d2006c7f1d9c5f1f768b50a3c445dc8b566bf9dd assets/advancedperipherals/lang/en_us.json diff --git a/src/generated/resources/assets/advancedperipherals/lang/en_us.json b/src/generated/resources/assets/advancedperipherals/lang/en_us.json index 15195591a..ed66cc743 100644 --- a/src/generated/resources/assets/advancedperipherals/lang/en_us.json +++ b/src/generated/resources/assets/advancedperipherals/lang/en_us.json @@ -60,7 +60,7 @@ "item.advancedperipherals.tooltip.peripheral_casing": "&7An empty hull without the love it deserves. Used as a crafting ingredient", "item.advancedperipherals.tooltip.player_detector": "&7This peripheral can be used to interact with players, but don't be a stalker.", "item.advancedperipherals.tooltip.redstone_integrator": "&7This block is able to interact with redstone. Works exactly like the redstone api of an computer.", - "item.advancedperipherals.tooltip.rs_bridge": "&7The RS Bridge interacts with Refined Storage 2 to manage your items.", + "item.advancedperipherals.tooltip.rs_bridge": "&7The RS Bridge interacts with Refined Storage to manage your items.", "item.advancedperipherals.tooltip.show_desc": "&b[&7%s&b] &7For Description", "item.advancedperipherals.tooltip.weak_automata_core": "&7Upgrade for turtles, which makes turtles more useful.", "item.advancedperipherals.weak_automata_core": "Weak Automata Core", diff --git a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java index cb0419334..92ff691c9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java +++ b/src/main/java/de/srendi/advancedperipherals/common/data/EnUsLanguageProvider.java @@ -110,7 +110,7 @@ private void addTooltips() { addTooltip(Blocks.ENVIRONMENT_DETECTOR.get(), "&7This peripheral interacts with the minecraft world."); addTooltip(Blocks.PLAYER_DETECTOR.get(), "&7This peripheral can be used to interact with players, but don't be a stalker."); addTooltip(Blocks.ME_BRIDGE.get(), "&7The ME Bridge interacts with Applied Energistics to manage your items."); - addTooltip(Blocks.RS_BRIDGE.get(), "&7The RS Bridge interacts with Refined Storage 2 to manage your items."); + addTooltip(Blocks.RS_BRIDGE.get(), "&7The RS Bridge interacts with Refined Storage to manage your items."); addTooltip(Blocks.CHAT_BOX.get(), "&7Interacts with the ingame chat, can read and write messages."); addTooltip(Blocks.PERIPHERAL_CASING.get(), "&7An empty hull without the love it deserves. Used as a crafting ingredient"); addTooltip(Items.MEMORY_CARD.get(), "&7Can save the rights of a player to use it in an inventory manager."); From aa0475002f11019ba875f01001b8402599647eaa Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 20 Mar 2025 19:48:48 +0100 Subject: [PATCH 26/91] getAvgPowerInjection -> getAverageEnergyInput --- .../common/util/inventory/IStorageSystemPeripheral.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index a83ba50e3..b41d1e1d7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -65,7 +65,7 @@ public interface IStorageSystemPeripheral { MethodResult getEnergyUsage(); - MethodResult getAvgPowerInjection(); + MethodResult getAverageEnergyInput(); MethodResult getTotalExternItemStorage(); From f9e471815ac7f68d8a6f848a133f13f55088fe3c Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 20 Mar 2025 19:58:48 +0100 Subject: [PATCH 27/91] Also rename the method that uses it --- .../addons/computercraft/peripheral/RSBridgePeripheral.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index fc66a0516..14b819305 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -533,7 +533,7 @@ public final MethodResult getEnergyUsage() { @Override @LuaFunction(mainThread = true) - public final MethodResult getAvgPowerInjection() { + public final MethodResult getAverageEnergyInput() { if (!isAvailable()) return notConnected(); From 0e034f613187e0487260babff86f27a30f90dbf8 Mon Sep 17 00:00:00 2001 From: Srendi Date: Thu, 20 Mar 2025 21:52:13 +0100 Subject: [PATCH 28/91] Make StatusConstants.withInfo return a String directly The `withInfo` method now directly returns the concatenation of the enum value and the provided info string, instead of attempting to store it internally. Implementing this for anything is out of scope for this PR for now --- .../common/util/StatusConstants.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java index 03c58657d..708cab93a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java @@ -30,15 +30,8 @@ public enum StatusConstants { NOT_CONNECTED, UNKNOWN_ERROR; - private String info; - - public StatusConstants withInfo(String info) { - this.info = info; - return this; - } - - public String asString() { - return this + "_" + this.info; + public String withInfo(String extraInfo) { + return this + "_" + extraInfo; } } From 1eb2ec6a920a1e9d337798df9394ec10e444307d Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:26:39 +0100 Subject: [PATCH 29/91] Remove redundant null arguments --- .../computercraft/peripheral/RSBridgePeripheral.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 14b819305..037748504 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -101,7 +101,7 @@ protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable II if (targetInventory == null) return MethodResult.of(0, "Target Inventory does not exist"); - return MethodResult.of(InventoryUtil.moveItem(itemHandler, targetInventory, filter.getLeft()), null); + return MethodResult.of(InventoryUtil.moveItem(itemHandler, targetInventory, filter.getLeft())); } /** @@ -121,7 +121,7 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFl if (targetTank == null) return MethodResult.of(0, "Target Tank does not exist"); - return MethodResult.of(FluidUtil.moveFluid(fluidHandler, targetTank, filter.getLeft()), null); + return MethodResult.of(FluidUtil.moveFluid(fluidHandler, targetTank, filter.getLeft())); } /** @@ -141,7 +141,7 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable ICh if (targetTank == null) return MethodResult.of(0, "Target Tank does not exist"); - return MethodResult.of(ChemicalUtil.moveChemical(chemicalHandler, targetTank, filter.getLeft()), null); + return MethodResult.of(ChemicalUtil.moveChemical(chemicalHandler, targetTank, filter.getLeft())); } /** @@ -161,7 +161,7 @@ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IItem if (targetInventory == null) return MethodResult.of(0, "Target Inventory does not exist"); - return MethodResult.of(InventoryUtil.moveItem(targetInventory, itemHandler, filter.getLeft()), null); + return MethodResult.of(InventoryUtil.moveItem(targetInventory, itemHandler, filter.getLeft())); } /** @@ -181,7 +181,7 @@ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IFlui if (targetTank == null) return MethodResult.of(0, "Target Tank does not exist"); - return MethodResult.of(FluidUtil.moveFluid(targetTank, fluidHandler, filter.getLeft()), null); + return MethodResult.of(FluidUtil.moveFluid(targetTank, fluidHandler, filter.getLeft())); } /** @@ -201,7 +201,7 @@ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IChem if (targetTank == null) return MethodResult.of(0, "Target Tank does not exist"); - return MethodResult.of(ChemicalUtil.moveChemical(targetTank, chemicalHandler, filter.getLeft()), null); + return MethodResult.of(ChemicalUtil.moveChemical(targetTank, chemicalHandler, filter.getLeft())); } @Override From 339ce6a056d242caed380cd7db548533a16c9a19 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:28:27 +0100 Subject: [PATCH 30/91] Don't create new Map instances when using the default parameter for tables --- .../computercraft/peripheral/RSBridgePeripheral.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 037748504..a202592d9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -288,7 +288,7 @@ public final MethodResult listItems(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); - Pair filter = ItemFilter.parse(arguments.optTable(0, Map.of())); + Pair filter = ItemFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); @@ -305,7 +305,7 @@ public final MethodResult listFluids(IArguments arguments) throws LuaException { if (!isAvailable()) return notConnected(); - Pair filter = FluidFilter.parse(arguments.optTable(0, Map.of())); + Pair filter = FluidFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); @@ -322,7 +322,7 @@ public final MethodResult listChemicals(IArguments arguments) throws LuaExceptio if (!isAvailable()) return notConnected(); - Pair filter = ChemicalFilter.parse(arguments.optTable(0, Map.of())); + Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); @@ -339,7 +339,7 @@ public final MethodResult listCraftableItems(IArguments arguments) throws LuaExc if (!isAvailable()) return notConnected(); - Pair filter = ItemFilter.parse(arguments.optTable(0, Map.of())); + Pair filter = ItemFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); @@ -356,7 +356,7 @@ public final MethodResult listCraftableFluids(IArguments arguments) throws LuaEx if (!isAvailable()) return notConnected(); - Pair filter = FluidFilter.parse(arguments.optTable(0, Map.of())); + Pair filter = FluidFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); @@ -373,7 +373,7 @@ public final MethodResult listCraftableChemicals(IArguments arguments) throws Lu if (!isAvailable()) return notConnected(); - Pair filter = ChemicalFilter.parse(arguments.optTable(0, Map.of())); + Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); From 3bbfa010bd4ea83a5172a4a91549f36a7f14e4bc Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:31:52 +0100 Subject: [PATCH 31/91] use present functions of Pair's instead --- .../addons/computercraft/peripheral/RSBridgePeripheral.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index a202592d9..5bfe07c0e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -537,6 +537,7 @@ public final MethodResult getAverageEnergyInput() { if (!isAvailable()) return notConnected(); + // Not supported for Refined Storage return MethodResult.of(0); } @@ -822,7 +823,7 @@ public final MethodResult isCraftable(IArguments arguments) throws LuaException GenericFilter parsedFilter = filter.getLeft(); - return MethodResult.of(RsApi.findPatternFromFilters(getNetwork(), null, parsedFilter).getLeft() != null); + return MethodResult.of(RsApi.findPatternFromFilters(getNetwork(), null, parsedFilter).leftPresent()); } @Override @@ -885,7 +886,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException Pair pattern = RsApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); - if (pattern.getRight() != null) + if (pattern.rightPresent()) return MethodResult.of(null, pattern.getRight()); return MethodResult.of(RsApi.parsePattern(pattern.getLeft())); From f0f71810c9ce3c83fd11c6846d4a974a1b3f6522 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:37:49 +0100 Subject: [PATCH 32/91] Validate filters for `getPatterns` --- .../peripheral/RSBridgePeripheral.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 5bfe07c0e..5abb18a36 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -876,12 +876,22 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException if (hasInputFilter) { Map inputFilterTable = TableHelper.getTableField(filterTable, "input"); - inputFilter = GenericFilter.parseGeneric(inputFilterTable).getLeft(); + Pair, String> parsedFilter = GenericFilter.parseGeneric(inputFilterTable); + + if (parsedFilter.rightPresent()) + return MethodResult.of(null, parsedFilter.getRight()); + + inputFilter = parsedFilter.getLeft(); } if (hasOutputFilter) { Map outputFilterTable = TableHelper.getTableField(filterTable, "output"); - outputFilter = GenericFilter.parseGeneric(outputFilterTable).getLeft(); + Pair, String> parsedFilter = GenericFilter.parseGeneric(outputFilterTable); + + if (parsedFilter.rightPresent()) + return MethodResult.of(null, parsedFilter.getRight()); + + outputFilter = parsedFilter.getLeft(); } Pair pattern = RsApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); From 0524358797340cae6278b54cac7c4f8d69b9a888 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:41:06 +0100 Subject: [PATCH 33/91] Improve debug message for import and export functions when no inventory was found --- .../peripheral/RSBridgePeripheral.java | 13 +++++++------ .../common/util/StatusConstants.java | 9 +++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 5abb18a36..462d1e0ce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -29,6 +29,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; +import de.srendi.advancedperipherals.common.util.StatusConstants; import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter; import de.srendi.advancedperipherals.common.util.inventory.ChemicalUtil; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; @@ -414,7 +415,7 @@ public final MethodResult importItem(IComputerAccess computer, IArguments argume inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); if (inventory == null) - return MethodResult.of(0, "The target inventory does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); return importToRS(arguments, inventory); } @@ -431,7 +432,7 @@ public final MethodResult exportItem(IComputerAccess computer, IArguments argume inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); if (inventory == null) - return MethodResult.of(0, "The target inventory does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); return exportToChest(arguments, inventory); } @@ -447,7 +448,7 @@ public final MethodResult importFluid(IComputerAccess computer, IArguments argum handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); if (handler == null) - return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); return importToRS(arguments, handler); } @@ -463,7 +464,7 @@ public final MethodResult exportFluid(IComputerAccess computer, IArguments argum handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); if (handler == null) - return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); return exportToTank(arguments, handler); } @@ -479,7 +480,7 @@ public final MethodResult importChemical(IComputerAccess computer, IArguments ar handler = ChemicalUtil.getHandlerFromName(computer, arguments.getString(1)); if (handler == null) - return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); return importToRS(arguments, handler); } @@ -495,7 +496,7 @@ public final MethodResult exportChemical(IComputerAccess computer, IArguments ar handler = ChemicalUtil.getHandlerFromName(computer, arguments.getString(1)); if (handler == null) - return MethodResult.of(0, "The target tank does not exist. Make sure the bridge is exposed in the computer network. Reach out to our discord or our documentation for help."); + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); return exportToTank(arguments, handler); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java index 708cab93a..5c137e162 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java @@ -15,8 +15,8 @@ public enum StatusConstants { CPU_DOES_NOT_EXIST, // Filters EMPTY_FILTER, - FLUID_NOT_FOUND, - ITEM_NOT_FOUND, + FILTER_FLUID_NOT_FOUND, + FILTER_ITEM_NOT_FOUND, NO_VALID_FLUID, NO_VALID_ITEM, NO_VALID_FROMSLOT, @@ -26,6 +26,11 @@ public enum StatusConstants { NO_VALID_FINGERPRINT, NO_VALID_COUNT, NO_VALID_FILTER_TYPE, + // Inventory, + INVENTORY_NOT_FOUND, + ITEM_NOT_FOUND, + FLUID_NOT_FOUND, + CHEMICAL_NOT_FOUND, // Misc NOT_CONNECTED, UNKNOWN_ERROR; From 4512968c0e5ae624f753399271a12f26d864a6a8 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:46:42 +0100 Subject: [PATCH 34/91] Improve readability of RsChemicalHandler --- .../common/addons/refinedstorage/RsApi.java | 9 ++++---- .../refinedstorage/RsChemicalHandler.java | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 4c7aa50cf..0f324a238 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -33,6 +33,7 @@ import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter; +import de.srendi.advancedperipherals.common.util.inventory.ChemicalUtil; import de.srendi.advancedperipherals.common.util.inventory.FluidFilter; import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.GenericFilter; @@ -115,7 +116,7 @@ public static FluidResource getFluid(Network network, FluidFilter filter) { public static ChemicalResource getChemical(Network network, ChemicalFilter filter) { StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { - if (trackedResource.resourceAmount().resource() instanceof ChemicalResource chemicalResource && filter.test(new ChemicalStack(chemicalResource.chemical(), trackedResource.resourceAmount().amount()))) { + if (trackedResource.resourceAmount().resource() instanceof ChemicalResource chemicalResource && filter.test(ChemicalUtil.toChemicalStack(chemicalResource.chemical(), trackedResource.resourceAmount().amount()))) { return chemicalResource; } } @@ -169,7 +170,7 @@ public static Map getParsedFluid(Network network, FluidFilter fi public static Map getParsedChemical(Network network, ChemicalFilter filter) { StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { - if (trackedResource.resourceAmount().resource() instanceof ChemicalResource chemicalResource && filter.test(new ChemicalStack(chemicalResource.chemical(), trackedResource.resourceAmount().amount()))) { + if (trackedResource.resourceAmount().resource() instanceof ChemicalResource chemicalResource && filter.test(ChemicalUtil.toChemicalStack(chemicalResource.chemical(), trackedResource.resourceAmount().amount()))) { return getObjectFromItemResource(trackedResource.resourceAmount()); } } @@ -228,7 +229,7 @@ public static Set> getParsedCnemicals(Network network, Chemi Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { - if (trackedResource.resourceAmount().resource() instanceof ChemicalResource fluidResource && filter.test(new ChemicalStack(fluidResource.chemical(), trackedResource.resourceAmount().amount()))) { + if (trackedResource.resourceAmount().resource() instanceof ChemicalResource fluidResource && filter.test(ChemicalUtil.toChemicalStack(fluidResource.chemical(), trackedResource.resourceAmount().amount()))) { items.add(getObjectFromFluidResource(trackedResource.resourceAmount())); } } @@ -291,7 +292,7 @@ public static Set> getCraftableChemicals(Network network, Ch StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (ResourceKey key : autocrafting.getOutputs()) { long amount = storage.get(key); - if (key instanceof ChemicalResource chemicalResource && filter.test(new ChemicalStack(chemicalResource.chemical(), amount))) { + if (key instanceof ChemicalResource chemicalResource && filter.test(ChemicalUtil.toChemicalStack(chemicalResource.chemical(), amount))) { items.add(getObjectFromResourceKey(key, amount)); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java index 5a2e89e35..d14b68add 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java @@ -7,6 +7,7 @@ import com.refinedmods.refinedstorage.mekanism.ChemicalResource; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.util.inventory.ChemicalFilter; +import de.srendi.advancedperipherals.common.util.inventory.ChemicalUtil; import de.srendi.advancedperipherals.common.util.inventory.IStorageSystemChemicalHandler; import mekanism.api.chemical.ChemicalStack; import org.jetbrains.annotations.NotNull; @@ -24,26 +25,28 @@ public RsChemicalHandler(@NotNull Network network) { @NotNull @Override - public ChemicalStack insertChemical(int tank, ChemicalStack resource, mekanism.api.Action action) { + public ChemicalStack insertChemical(int tank, ChemicalStack resource, @NotNull mekanism.api.Action action) { if (resource.isEmpty()) return resource; - ChemicalStack chemical = resource.copy(); - chemical.setAmount(resource.getAmount() - component.insert(ChemicalResource.ofChemicalStack(chemical), resource.getAmount(), action == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); - return chemical; + ChemicalStack inserted = resource.copy(); + long amountInserted = component.insert(ChemicalResource.ofChemicalStack(inserted), resource.getAmount(), action == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY) + inserted.setAmount(resource.getAmount() - amountInserted); + return inserted; } @Override public ChemicalStack extractChemical(ChemicalFilter filter, long count, mekanism.api.Action simulate) { - AdvancedPeripherals.debug("Trying to extract fluid from filter: " + filter); - ChemicalResource fluid = RsApi.getChemical(network, filter); - if (fluid == null) + AdvancedPeripherals.debug("Trying to extract chemical from filter: " + filter); + ChemicalResource chemical = RsApi.getChemical(network, filter); + if (chemical == null) return ChemicalStack.EMPTY; - ChemicalStack extracted = new ChemicalStack(fluid.chemical(), 1); - extracted.setAmount((int) component.extract(fluid, filter.getCount(), simulate == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + ChemicalStack extracted = ChemicalUtil.toChemicalStack(chemical.chemical(), 1); + long amountExtracted = component.extract(chemical, filter.getCount(), simulate == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); + extracted.setAmount(amountExtracted); - AdvancedPeripherals.debug("Extracted fluid: " + extracted + " from filter: " + filter); + AdvancedPeripherals.debug("Extracted chemical: " + extracted + " from filter: " + filter); return extracted; } From eb51d7673410dae624d9067e7dcb8831d7f4e1f3 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:47:26 +0100 Subject: [PATCH 35/91] Remove redstone mode since it is not possible to get that state via the api --- .../advancedperipherals/common/addons/refinedstorage/RsApi.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 0f324a238..6ecea2b4a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -542,8 +542,6 @@ public static Object parseDiskDrive(StorageNetworkNode diskDrive, InWorldNetwork properties.put("total", diskDrive.getCapacity()); properties.put("disks", disks); properties.put("mode", storageConfiguration.getFilterMode().toString()); - //TODO Redstone mode - properties.put("redstone_mode", false); properties.put("access_type", storageConfiguration.getAccessMode().toString()); properties.put("position", LuaConverter.posToObject(nodeContainer.getLocalPosition())); properties.put("priority", nodeContainer.getPriority()); From 56db1d4e946d077f1e7141fd3b733c349a4d4b29 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:49:42 +0100 Subject: [PATCH 36/91] Extract method calls from storage handlers to improve readability --- .../common/addons/refinedstorage/RsChemicalHandler.java | 2 +- .../common/addons/refinedstorage/RsFluidHandler.java | 6 ++++-- .../common/addons/refinedstorage/RsItemHandler.java | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java index d14b68add..2f0a452aa 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java @@ -30,7 +30,7 @@ public ChemicalStack insertChemical(int tank, ChemicalStack resource, @NotNull m return resource; ChemicalStack inserted = resource.copy(); - long amountInserted = component.insert(ChemicalResource.ofChemicalStack(inserted), resource.getAmount(), action == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY) + long amountInserted = component.insert(ChemicalResource.ofChemicalStack(inserted), resource.getAmount(), action == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); inserted.setAmount(resource.getAmount() - amountInserted); return inserted; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java index e046d5b54..28def8240 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java @@ -28,7 +28,8 @@ public RsFluidHandler(@NotNull Network network) { public int fill(FluidStack resource, @NotNull FluidAction action) { if (resource.isEmpty()) return 0; - return (int) (resource.getAmount() - component.insert(VariantUtil.ofFluidStack(resource), resource.getAmount(), action == FluidAction.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + long inserted = component.insert(VariantUtil.ofFluidStack(resource), resource.getAmount(), action == FluidAction.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); + return (int) (resource.getAmount() - inserted); } @NotNull @@ -40,7 +41,8 @@ public FluidStack drain(FluidFilter filter, FluidAction simulate) { return FluidStack.EMPTY; FluidStack extracted = VariantUtil.toFluidStack(fluid, 1); - extracted.setAmount((int) component.extract(fluid, filter.getCount(), simulate == FluidAction.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + long amountExtracted = component.extract(fluid, filter.getCount(), simulate == FluidAction.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); + extracted.setAmount((int) amountExtracted); AdvancedPeripherals.debug("Extracted fluid: " + extracted + " from filter: " + filter); return extracted; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java index edf47b625..4b6a1e1b2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java @@ -31,7 +31,8 @@ public RsItemHandler(@NotNull Network network) { @Override public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { ItemStack inserted = stack.copy(); - inserted.setCount((int) (stack.getCount() - component.insert(ItemResource.ofItemStack(stack), stack.getCount(), simulate ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY))); + long insertedAmount = component.insert(ItemResource.ofItemStack(stack), stack.getCount(), simulate ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); + inserted.setCount((int) (stack.getCount() - insertedAmount)); return inserted; } @@ -43,7 +44,8 @@ public ItemStack extractItem(ItemFilter filter, int count, boolean simulate) { return ItemStack.EMPTY; ItemStack extracted = itemResource.toItemStack(); - extracted.setCount((int) component.extract(itemResource, count, simulate ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY)); + long extractedAmount = component.extract(itemResource, count, simulate ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); + extracted.setCount((int) extractedAmount); AdvancedPeripherals.debug("Extracted item: " + extracted + " from filter: " + filter); return extracted; From 3ee0bfa4d8d9ddc309fdd369a1dd49d3f074fdda Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:50:39 +0100 Subject: [PATCH 37/91] Uncomment forgotten jobStateChanged from our TaskStatusListener the bridge to listen for task changes --- .../common/blocks/blockentities/RsBridgeEntity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java index afd216bcc..d946a01b5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -114,17 +114,17 @@ public boolean canBuild(@NotNull ServerPlayer serverPlayer) { @Override public void taskStatusChanged(@NotNull TaskStatus taskStatus) { - //jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); + jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); } @Override public void taskRemoved(@NotNull TaskId taskId) { - //jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskId)).forEach(BasicCraftJob::jobStateChanged); + jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskId)).forEach(BasicCraftJob::jobStateChanged); } @Override public void taskAdded(@NotNull TaskStatus taskStatus) { - //jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); + jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); } } From 81452b890f8d5c878f756a1679b8a0af126ca694 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 17:58:44 +0100 Subject: [PATCH 38/91] Refactor how we call our methods for implementation and lua functions in our craft job --- .../addons/refinedstorage/RSCraftJob.java | 20 ++--- .../common/util/inventory/BasicCraftJob.java | 90 +++++++++---------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index 4dbc5e327..6df656a67 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -46,12 +46,12 @@ protected boolean isJobCanceled() { } @Override - public Object getParsedRequestedItem() { + public Object getParsedRequestedItemImpl() { return RsApi.getObjectFromResourceKey(toCraft, amount); } @Override - public long getElapsedTime() { + public long getElapsedTimeImpl() { if (craftingTask == null) { return -1; } @@ -59,7 +59,7 @@ public long getElapsedTime() { } @Override - public long getTotalItems() { + public long getTotalItemsImpl() { if (craftingTask == null) { return -1; } @@ -68,12 +68,12 @@ public long getTotalItems() { } @Override - public long getItemProgress() { + public long getItemProgressImpl() { return craftingTask == null ? 0 : craftingTask.items().stream().mapToLong(TaskStatus.Item::stored).sum(); } @Override - public Object getEmittedItems() { + public Object getEmittedItemsImpl() { if (preview == null) { return Collections.emptyList(); } @@ -82,13 +82,13 @@ public Object getEmittedItems() { } @Override - public Object getUsedItems() { + public Object getUsedItemsImpl() { // Not supported for rs2 return Collections.emptyList(); } @Override - public Object getMissingItems() { + public Object getMissingItemsImpl() { if (preview == null) { return Collections.emptyList(); } @@ -97,13 +97,13 @@ public Object getMissingItems() { } @Override - public boolean hasMultiplePaths() { + public boolean hasMultiplePathsImpl() { // Not supported for rs2 return false; } @Override - public Object getFinalOutput() { + public Object getFinalOutputImpl() { if (preview == null) { return Collections.emptyList(); } @@ -116,7 +116,7 @@ public TaskStatus getCraftingTask() { } @Override - public boolean cancel() { + public boolean cancelImpl() { if (isJobDone() || isJobCanceled()) { return false; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java index 91f949255..c4a7b2af0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java @@ -80,81 +80,81 @@ public final String getDebugMessage() { return debugMessage; } - @LuaFunction(value = "getRequestedItem") - public final Object getRequestedItemLua() { - return getParsedRequestedItem(); + @LuaFunction + public final Object getRequestedItem() { + return getParsedRequestedItemImpl(); } - @LuaFunction(value = "getElapsedTime") - public final long getElapsedTimeLua() { - return getElapsedTime(); + @LuaFunction + public final long getElapsedTime() { + return getElapsedTimeImpl(); } - @LuaFunction(value = "getTotalItems") - public final long getTotalItemsLua() { - return getTotalItems(); + @LuaFunction + public final long getTotalItems() { + return getTotalItemsImpl(); } - @LuaFunction(value = "getItemProgress") - public final long getItemProgressLua() { - return getItemProgress(); + @LuaFunction + public final long getItemProgress() { + return getItemProgressImpl(); } - @LuaFunction(value = "getEmittedItems") - public final Object getEmittedItemsLua() { - return getEmittedItems(); + @LuaFunction + public final Object getEmittedItems() { + return getEmittedItemsImpl(); } - @LuaFunction(value = "getUsedItems") - public final Object getUsedItemsLua() { - return getUsedItems(); + @LuaFunction + public final Object getUsedItems() { + return getUsedItemsImpl(); } - @LuaFunction(value = "getMissingItems") - public final Object getMissingItemsLua() { - return getMissingItems(); + @LuaFunction + public final Object getMissingItems() { + return getMissingItemsImpl(); } - @LuaFunction(value = "hasMultiplePaths") - public final boolean hasMultiplePathsLua() { - return hasMultiplePaths(); + @LuaFunction + public final boolean hasMultiplePaths() { + return hasMultiplePathsImpl(); } - @LuaFunction(value = "getFinalOutput") - public final Object getFinalOutputLua() { - return getFinalOutput(); + @LuaFunction + public final Object getFinalOutput() { + return getFinalOutputImpl(); } - @LuaFunction(value = "cancel") - public final boolean cancelLua() { - return cancel(); + @LuaFunction + public final boolean cancel() { + return cancelImpl(); } - public abstract Object getParsedRequestedItem(); + protected abstract Object getParsedRequestedItemImpl(); - public abstract long getElapsedTime(); + protected abstract long getElapsedTimeImpl(); - public abstract long getTotalItems(); + protected abstract long getTotalItemsImpl(); - public abstract long getItemProgress(); + protected abstract long getItemProgressImpl(); - public abstract Object getEmittedItems(); + protected abstract Object getEmittedItemsImpl(); - public abstract Object getUsedItems(); + protected abstract Object getUsedItemsImpl(); - public abstract Object getMissingItems(); + protected abstract Object getMissingItemsImpl(); - public abstract boolean hasMultiplePaths(); + protected abstract boolean hasMultiplePathsImpl(); - public abstract Object getFinalOutput(); + protected abstract Object getFinalOutputImpl(); - public abstract boolean cancel(); + protected abstract boolean cancelImpl(); - public Level getWorld() { + protected Level getWorld() { return world; } - public long getAmount() { + protected long getAmount() { return amount; } @@ -166,17 +166,17 @@ protected void fireNotConnected() { fireEvent(true, StatusConstants.NOT_CONNECTED); } - public void setStartedCrafting() { + protected void setStartedCrafting() { this.startedCrafting = true; fireEvent(false, StatusConstants.CRAFTING_STARTED); } - public void setJobCanceled() { + protected void setJobCanceled() { this.isJobCanceled = true; this.jobDoneTime = System.currentTimeMillis(); } - public void setJobDone() { + protected void setJobDone() { this.isJobDone = true; this.jobDoneTime = System.currentTimeMillis(); } From 2e77c943beb12e1305cdfb4dd52320991b33dc80 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 18:06:47 +0100 Subject: [PATCH 39/91] Use a global EMPTY instance for our filters and don't always create a new empty instance --- .../common/addons/refinedstorage/RsApi.java | 24 +++++++++---------- .../common/util/inventory/ChemicalFilter.java | 14 +++++++---- .../common/util/inventory/FluidFilter.java | 14 +++++++---- .../common/util/inventory/GenericFilter.java | 1 + .../common/util/inventory/ItemFilter.java | 14 +++++++---- 5 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 6ecea2b4a..28667d4b5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -73,7 +73,7 @@ public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event * Returns the first item resource that fits to the filter * * @param network refined storage network - * @param filter item filter instance - can be an empty filter to get the first item of the system see {@link ItemFilter#empty()} + * @param filter item filter instance - can be an empty filter to get the first item of the system see {@link ItemFilter#createEmpty()} * @return the first item in the system that fits the item filter or null */ @Nullable @@ -91,7 +91,7 @@ public static ItemResource getItem(Network network, ItemFilter filter) { * Returns the first fluid parsed to a lua object which fits to the filter * * @param network refined storage network - * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#empty()} + * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#createEmpty()} * @return the first fluid in the system that fits the fluid filter or null */ @Nullable @@ -109,7 +109,7 @@ public static FluidResource getFluid(Network network, FluidFilter filter) { * Returns the first chemical parsed to a lua object which fits to the filter * * @param network refined storage network - * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#empty()} + * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#createEmpty()} * @return the first fluid in the system that fits the fluid filter or null */ @Nullable @@ -127,7 +127,7 @@ public static ChemicalResource getChemical(Network network, ChemicalFilter filte * Returns the first item parsed to a lua object which fits to the filter * * @param network refined storage network - * @param filter item filter instance - can be an empty filter to get the first item of the system see {@link ItemFilter#empty()} + * @param filter item filter instance - can be an empty filter to get the first item of the system see {@link ItemFilter#createEmpty()} * @return the first item in the system that fits the item filter or null */ @Nullable @@ -145,7 +145,7 @@ public static Map getParsedItem(Network network, ItemFilter filt * Returns the first fluid parsed to a lua object which fits to the filter * * @param network refined storage network - * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#empty()} + * @param filter fluid filter instance - can be an empty filter to get the first fluid of the system see {@link FluidFilter#createEmpty()} * @return the first fluid in the system that fits the fluid filter or null */ @Nullable @@ -163,7 +163,7 @@ public static Map getParsedFluid(Network network, FluidFilter fi * Returns the first mekanism chemical parsed to a lua object which fits to the filter * * @param network refined storage network - * @param filter chemical filter instance - can be an empty filter to get the first chemical of the system see {@link ChemicalFilter#empty()} + * @param filter chemical filter instance - can be an empty filter to get the first chemical of the system see {@link ChemicalFilter#createEmpty()} * @return the first chemical in the system that fits the chemical filter or null */ @Nullable @@ -179,7 +179,7 @@ public static Map getParsedChemical(Network network, ChemicalFil /** * Returns every item from the system while also checking if the filter test passes for the items - * The filter can be empty, see {@link ItemFilter#empty()} + * The filter can be empty, see {@link ItemFilter#createEmpty()} * * @param network the rs network * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource @@ -199,7 +199,7 @@ public static Set> getParsedItems(Network network, ItemFilte /** * Returns every fluid from the system while also checking if the filter test passes for the fluids - * The filter can be empty, see {@link FluidFilter#empty()} + * The filter can be empty, see {@link FluidFilter#createEmpty()} * * @param network the rs network * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource @@ -219,7 +219,7 @@ public static Set> getParsedFluids(Network network, FluidFil /** * Returns every fluid from the system while also checking if the filter test passes for the fluids - * The filter can be empty, see {@link FluidFilter#empty()} + * The filter can be empty, see {@link FluidFilter#createEmpty()} * * @param network the rs network * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource @@ -239,7 +239,7 @@ public static Set> getParsedCnemicals(Network network, Chemi /** * Returns every craftable item from the system while also checking if the filter test passes for the items - * The filter can be empty, see {@link ItemFilter#empty()} + * The filter can be empty, see {@link ItemFilter#createEmpty()} * * @param network the rs network * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource @@ -259,7 +259,7 @@ public static Set> getCraftableItems(Network network, ItemFi /** * Returns every craftable fluid from the system while also checking if the filter test passes for the fluids - * The filter can be empty, see {@link FluidFilter#empty()} + * The filter can be empty, see {@link FluidFilter#createEmpty()} * * @param network the rs network * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource @@ -280,7 +280,7 @@ public static Set> getCraftableFluids(Network network, Fluid /** * Returns every craftable mekanism chemical from the system while also checking if the filter test passes for the chemicals - * The filter can be empty, see {@link ChemicalFilter#empty()} + * The filter can be empty, see {@link ChemicalFilter#createEmpty()} * * @param network the rs network * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java index b6510bfa9..83007da68 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java @@ -19,6 +19,8 @@ public class ChemicalFilter extends GenericFilter { + public static final ChemicalFilter EMPTY = new ChemicalFilter(); + private Holder chemical = MekanismAPI.EMPTY_CHEMICAL_HOLDER; private TagKey tag = null; private long count = 64; @@ -30,10 +32,12 @@ private ChemicalFilter() { } public static Pair parse(Map item) { - ChemicalFilter chemicalFilter = empty(); // If the map is empty, return a filter without any filters if (item.isEmpty()) - return Pair.of(chemicalFilter, null); + return Pair.of(EMPTY, null); + + ChemicalFilter chemicalFilter = createEmpty(); + if (item.containsKey("name")) { try { String name = TableHelper.getStringField(item, "name"); @@ -80,17 +84,17 @@ public static Pair parse(Map item) { } public static ChemicalFilter fromStack(ChemicalStack stack) { - ChemicalFilter filter = empty(); + ChemicalFilter filter = createEmpty(); filter.chemical = stack.getChemicalHolder(); return filter; } - public static ChemicalFilter empty() { + public static ChemicalFilter createEmpty() { return new ChemicalFilter(); } public boolean isEmpty() { - return fingerprint.isEmpty() && chemical.is(MekanismAPI.EMPTY_CHEMICAL_KEY) && tag == null; + return this == EMPTY || (fingerprint.isEmpty() && chemical.is(MekanismAPI.EMPTY_CHEMICAL_KEY) && tag == null); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index 5b6c906b2..5054c42a6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -26,6 +26,8 @@ //TODO tag public class FluidFilter extends GenericFilter { + public static final FluidFilter EMPTY = new FluidFilter(); + private Fluid fluid = Fluids.EMPTY; private TagKey tag = null; private Tag componentsAsNbt = null; @@ -37,10 +39,12 @@ private FluidFilter() { } public static Pair parse(Map item) { - FluidFilter fluidFilter = empty(); // If the map is empty, return a filter without any filters if (item.isEmpty()) - return Pair.of(fluidFilter, null); + return Pair.of(EMPTY, null); + + FluidFilter fluidFilter = createEmpty(); + if (item.containsKey("name")) { try { String name = TableHelper.getStringField(item, "name"); @@ -84,19 +88,19 @@ public static Pair parse(Map item) { } public static FluidFilter fromStack(FluidStack stack) { - FluidFilter filter = empty(); + FluidFilter filter = createEmpty(); filter.fluid = stack.getFluid(); filter.componentsAsNbt = DataComponentUtil.toNbt(stack.getComponentsPatch()); filter.components = stack.getComponents(); return filter; } - public static FluidFilter empty() { + public static FluidFilter createEmpty() { return new FluidFilter(); } public boolean isEmpty() { - return fingerprint.isEmpty() && fluid == Fluids.EMPTY && tag == null && componentsAsNbt == null; + return this == EMPTY || (fingerprint.isEmpty() && fluid == Fluids.EMPTY && tag == null && componentsAsNbt == null); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index 029568aa2..3be484900 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -5,6 +5,7 @@ import de.srendi.advancedperipherals.common.util.Pair; import mekanism.api.MekanismAPI; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.item.ItemStack; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index b0b94bc00..2ab139227 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -24,6 +24,8 @@ public class ItemFilter extends GenericFilter { + public static final ItemFilter EMPTY = new ItemFilter(); + private Item item = Items.AIR; private TagKey tag = null; private Tag componentsAsNbt = null; @@ -37,10 +39,12 @@ private ItemFilter() { } public static Pair parse(Map item) { - ItemFilter itemFilter = empty(); // If the map is empty, return a filter without any filters if (item.isEmpty()) - return Pair.of(itemFilter, null); + return Pair.of(EMPTY, null); + + ItemFilter itemFilter = createEmpty(); + if (item.containsKey("name")) { try { String name = TableHelper.getStringField(item, "name"); @@ -98,19 +102,19 @@ public static Pair parse(Map item) { } public static ItemFilter fromStack(ItemStack stack) { - ItemFilter filter = empty(); + ItemFilter filter = createEmpty(); filter.item = stack.getItem(); filter.componentsAsNbt = DataComponentUtil.toNbt(stack.getComponentsPatch()); filter.components = (PatchedDataComponentMap) stack.getComponents(); return filter; } - public static ItemFilter empty() { + public static ItemFilter createEmpty() { return new ItemFilter(); } public boolean isEmpty() { - return fingerprint.isEmpty() && item == Items.AIR && tag == null && componentsAsNbt == null; + return this == EMPTY || (fingerprint.isEmpty() && item == Items.AIR && tag == null && componentsAsNbt == null); } @Override From 9d0e53ed7fa1bb314aae67c7846eaaebd0426a5f Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 18:08:12 +0100 Subject: [PATCH 40/91] Fix typo --- .../addons/computercraft/peripheral/RSBridgePeripheral.java | 2 +- .../advancedperipherals/common/addons/refinedstorage/RsApi.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 462d1e0ce..7079f7764 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -329,7 +329,7 @@ public final MethodResult listChemicals(IArguments arguments) throws LuaExceptio ChemicalFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RsApi.getParsedCnemicals(getNetwork(), parsedFilter); + Set> resourceProperties = RsApi.getParsedChemicals(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 28667d4b5..b322135ad 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -225,7 +225,7 @@ public static Set> getParsedFluids(Network network, FluidFil * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of fluid stacks */ - public static Set> getParsedCnemicals(Network network, ChemicalFilter filter) { + public static Set> getParsedChemicals(Network network, ChemicalFilter filter) { Set> items = new HashSet<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { From 3ee4f8304dbeef30f77c9d8739d0c2e9af53f14b Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 18:39:26 +0100 Subject: [PATCH 41/91] Print the craft job exceptions using log4j --- .../de/srendi/advancedperipherals/AdvancedPeripherals.java | 5 +++++ .../common/addons/refinedstorage/RSCraftJob.java | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 75225dcd4..32607eadc 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -50,6 +50,11 @@ public static void debug(String message, Level level) { LOGGER.log(level, "[DEBUG] {}", message); } + public static void debug(String message, Throwable throwable) { + if (APConfig.GENERAL_CONFIG.enableDebugMode.get()) + LOGGER.error("[DEBUG] " + message, throwable); + } + public static ResourceLocation getRL(String resource) { return ResourceLocation.fromNamespaceAndPath(MOD_ID, resource); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index 6df656a67..535f389f4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -145,8 +145,8 @@ public void tick() { try { optionalId = futureTask.get(); - } catch (InterruptedException | ExecutionException e) { - AdvancedPeripherals.debug("Tried to get the task but the task was not done. Should be done", org.apache.logging.log4j.Level.ERROR); + } catch (InterruptedException | ExecutionException ex) { + AdvancedPeripherals.debug("Tried to get the task but the task was not done. Should be done", ex); fireEvent(true, StatusConstants.UNKNOWN_ERROR); return; } @@ -179,8 +179,7 @@ protected void maybeCraft() { try { optionalPreview = futureCalculationResult.get(); } catch (ExecutionException | InterruptedException ex) { - AdvancedPeripherals.debug("Tried to get preview, but preview calculation is not done. Should be done.", org.apache.logging.log4j.Level.ERROR); - ex.printStackTrace(); + AdvancedPeripherals.debug("Tried to get preview, but preview calculation is not done. Should be done.", ex); fireEvent(true, StatusConstants.UNKNOWN_ERROR); return; } From f6bac59baa6d4a00b876395d2a083126fe5cf1a1 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 18:44:33 +0100 Subject: [PATCH 42/91] Change how we compare percentage completed of the rs craft job to prevent issues with floating point number precision --- .../common/addons/refinedstorage/RSCraftJob.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index 535f389f4..e47126473 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -37,12 +37,12 @@ public RSCraftJob(IComputerAccess computer, Level world, long amount, ResourceKe @Override protected boolean isJobDone() { - return craftingTask != null && craftingTask.percentageCompleted() == 100; + return craftingTask != null && craftingTask.percentageCompleted() >= 100; } @Override protected boolean isJobCanceled() { - return craftingTask != null && craftingTask.percentageCompleted() != 100 && autocraftingComponent.getStatuses().stream().noneMatch(task -> task.info().id() == craftingTask.info().id()); + return craftingTask != null && craftingTask.percentageCompleted() < 100 && autocraftingComponent.getStatuses().stream().noneMatch(task -> task.info().id() == craftingTask.info().id()); } @Override From c11e3930f75c557c595b6f3ab42e4dd376442fbe Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 18:48:47 +0100 Subject: [PATCH 43/91] Rename extern to external for our lua functions and implementatioons --- .../peripheral/RSBridgePeripheral.java | 36 +++++++++---------- .../common/addons/refinedstorage/RsApi.java | 4 +-- .../common/util/inventory/GenericFilter.java | 1 - .../inventory/IStorageSystemPeripheral.java | 18 +++++----- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 7079f7764..a190eb746 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -544,29 +544,29 @@ public final MethodResult getAverageEnergyInput() { @Override @LuaFunction(mainThread = true) - public final MethodResult getTotalExternItemStorage() { + public final MethodResult getTotalExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) - public final MethodResult getTotalExternFluidStorage() { + public final MethodResult getTotalExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) - public final MethodResult getTotalExternChemicalStorage() { + public final MethodResult getTotalExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @@ -598,29 +598,29 @@ public final MethodResult getTotalChemicalStorage() { @Override @LuaFunction(mainThread = true) - public final MethodResult getUsedExternItemStorage() { + public final MethodResult getUsedExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedExternStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) - public final MethodResult getUsedExternFluidStorage() { + public final MethodResult getUsedExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedExternStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) - public final MethodResult getUsedExternChemicalStorage() { + public final MethodResult getUsedExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override @@ -652,29 +652,29 @@ public final MethodResult getUsedChemicalStorage() { @Override @LuaFunction(mainThread = true) - public final MethodResult getAvailableExternItemStorage() { + public final MethodResult getAvailableExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), StorageTypes.ITEM) - RsApi.getUsedExternStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), StorageTypes.ITEM) - RsApi.getUsedExternalStorage(getNetwork(), StorageTypes.ITEM)); } @Override @LuaFunction(mainThread = true) - public final MethodResult getAvailableExternFluidStorage() { + public final MethodResult getAvailableExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), StorageTypes.FLUID) - RsApi.getUsedExternStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), StorageTypes.FLUID) - RsApi.getUsedExternalStorage(getNetwork(), StorageTypes.FLUID)); } @Override @LuaFunction(mainThread = true) - public final MethodResult getAvailableExternChemicalStorage() { + public final MethodResult getAvailableExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RsApi.getUsedExternStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RsApi.getUsedExternalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index b322135ad..e61955a51 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -439,7 +439,7 @@ public static long getUsedStorage(Network network, StorageType type) { return used; } - public static long getTotalExternStorage(Network network, StorageType type) { + public static long getTotalExternalStorage(Network network, StorageType type) { long total = 0; GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); @@ -453,7 +453,7 @@ public static long getTotalExternStorage(Network network, StorageType type) { return total; } - public static long getUsedExternStorage(Network network, StorageType type) { + public static long getUsedExternalStorage(Network network, StorageType type) { long used = 0; GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index 3be484900..029568aa2 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -5,7 +5,6 @@ import de.srendi.advancedperipherals.common.util.Pair; import mekanism.api.MekanismAPI; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.item.ItemStack; import java.util.Map; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index b41d1e1d7..257cae44c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -67,11 +67,11 @@ public interface IStorageSystemPeripheral { MethodResult getAverageEnergyInput(); - MethodResult getTotalExternItemStorage(); + MethodResult getTotalExternalItemStorage(); - MethodResult getTotalExternFluidStorage(); + MethodResult getTotalExternalFluidStorage(); - MethodResult getTotalExternChemicalStorage(); + MethodResult getTotalExternalChemicalStorage(); MethodResult getTotalItemStorage(); @@ -79,11 +79,11 @@ public interface IStorageSystemPeripheral { MethodResult getTotalChemicalStorage(); - MethodResult getUsedExternItemStorage(); + MethodResult getUsedExternalItemStorage(); - MethodResult getUsedExternFluidStorage(); + MethodResult getUsedExternalFluidStorage(); - MethodResult getUsedExternChemicalStorage(); + MethodResult getUsedExternalChemicalStorage(); MethodResult getUsedItemStorage(); @@ -91,11 +91,11 @@ public interface IStorageSystemPeripheral { MethodResult getUsedChemicalStorage(); - MethodResult getAvailableExternItemStorage(); + MethodResult getAvailableExternalItemStorage(); - MethodResult getAvailableExternFluidStorage(); + MethodResult getAvailableExternalFluidStorage(); - MethodResult getAvailableExternChemicalStorage(); + MethodResult getAvailableExternalChemicalStorage(); MethodResult getAvailableItemStorage(); From d5af46c060744dc6b0b48aac5ed70cd02b6c5fb6 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 21 Mar 2025 18:58:41 +0100 Subject: [PATCH 44/91] implement getEnergyUsage for the RS Bridge --- .../peripheral/RSBridgePeripheral.java | 2 +- .../common/addons/refinedstorage/RsApi.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index a190eb746..7cfba4dcc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -529,7 +529,7 @@ public final MethodResult getEnergyUsage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(0); + return MethodResult.of(RsApi.getEnergyUsage(getNetwork())); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index e61955a51..b591bb037 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -5,6 +5,7 @@ import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage.api.network.impl.node.externalstorage.ExposedExternalStorage; import com.refinedmods.refinedstorage.api.network.impl.node.externalstorage.ExternalStorageNetworkNode; import com.refinedmods.refinedstorage.api.network.impl.node.storage.StorageNetworkNode; @@ -478,6 +479,19 @@ public static List getCraftingTasks(RsBridgeEntity entity) { return tasks; } + public static long getEnergyUsage(Network network) { + long energyUsage = 0; + + GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); + for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { + if (nodeContainer.getNode() instanceof AbstractNetworkNode abstractNetworkNode) { + energyUsage += abstractNetworkNode.getEnergyUsage(); + } + } + + return energyUsage; + } + public static Map getObjectFromResourceKey(@NotNull ResourceKey resource) { return getObjectFromResourceKey(resource, 0); } From 4f7a74556a84a55a96a6dda1a8dee86727776cfb Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 23 Mar 2025 15:35:04 +0100 Subject: [PATCH 45/91] CPU_DOES_NOT_EXIST -> CPU_NOT_FOUND Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../srendi/advancedperipherals/common/util/StatusConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java index 5c137e162..0680973b9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java @@ -12,7 +12,7 @@ public enum StatusConstants { JOB_DONE, NOT_CRAFTABLE, MISSING_ITEMS, - CPU_DOES_NOT_EXIST, + CPU_NOT_FOUND, // Filters EMPTY_FILTER, FILTER_FLUID_NOT_FOUND, From 18e3ab8614206f32ebc96a9327851f9f90488d17 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:21:03 +0100 Subject: [PATCH 46/91] Remove old todos --- .../advancedperipherals/common/util/inventory/FluidFilter.java | 1 - .../advancedperipherals/common/util/inventory/GenericFilter.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index 5054c42a6..a6233ee8e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -23,7 +23,6 @@ import java.util.Map; -//TODO tag public class FluidFilter extends GenericFilter { public static final FluidFilter EMPTY = new FluidFilter(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index 029568aa2..471d33a77 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -21,7 +21,6 @@ public abstract class GenericFilter { * @return A pair of the parsed filter and an error message, if there is one */ public static Pair, String> parseGeneric(Map rawFilter) { - // TODO: Add chemical filter support if (!rawFilter.containsKey("name")) { if (rawFilter.containsKey("type") && rawFilter.get("type") instanceof String type) { From 0854a3cb09996746fbb2a3c7857a393e72dd7a3d Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:29:29 +0100 Subject: [PATCH 47/91] Add comments to status constants --- .../common/util/StatusConstants.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java index 0680973b9..1e68bab7d 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java @@ -11,14 +11,15 @@ public enum StatusConstants { JOB_CANCELED, JOB_DONE, NOT_CRAFTABLE, - MISSING_ITEMS, + MISSING_ITEMS, // If there are missing items for a crafting recipe/job after the calculation is done CPU_NOT_FOUND, // Filters EMPTY_FILTER, - FILTER_FLUID_NOT_FOUND, - FILTER_ITEM_NOT_FOUND, - NO_VALID_FLUID, - NO_VALID_ITEM, + FILTER_ITEM_NOT_FOUND, // Item could not be found in registry + FILTER_FLUID_NOT_FOUND, // Fluid could not be found in registry + FILTER_CHEMICAL_NOT_FOUND, // Chemical could not be found in registry + NO_VALID_FLUID, // Fluid property of filter is not a string + NO_VALID_ITEM, // Item property of filter is not a string NO_VALID_FROMSLOT, NO_VALID_TOSLOT, NO_VALID_NBT_HASH, @@ -28,7 +29,7 @@ public enum StatusConstants { NO_VALID_FILTER_TYPE, // Inventory, INVENTORY_NOT_FOUND, - ITEM_NOT_FOUND, + ITEM_NOT_FOUND, // Debug message when an item couldn't be found in an/the target inventory FLUID_NOT_FOUND, CHEMICAL_NOT_FOUND, // Misc From 70accc0d5a142a53b496f9480851b696eb5b9da2 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:33:19 +0100 Subject: [PATCH 48/91] protected static -> private static event field Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../common/util/inventory/BasicCraftJob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java index c4a7b2af0..1ab36f607 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/BasicCraftJob.java @@ -9,7 +9,7 @@ public abstract class BasicCraftJob { - protected static final String EVENT = "_crafting"; + private static final String EVENT = "_crafting"; private static final int JOB_DONE_PURGE_TIME = 5 * 60 * 1000; public static final AtomicLong ID_SEQ = new AtomicLong(); From 4eeab7b5aff84630cbe123657f514549ba03597e Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:33:33 +0100 Subject: [PATCH 49/91] remove empty line Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../common/blocks/blockentities/RsBridgeEntity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java index d946a01b5..91bff4567 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java @@ -120,7 +120,6 @@ public void taskStatusChanged(@NotNull TaskStatus taskStatus) { @Override public void taskRemoved(@NotNull TaskId taskId) { jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskId)).forEach(BasicCraftJob::jobStateChanged); - } @Override From 667dd4b168d1643d0eb9fc09ff1298977b7d8ea4 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:35:17 +0100 Subject: [PATCH 50/91] change logic of listCells helper method --- .../common/addons/refinedstorage/RsApi.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index b591bb037..7c129adce 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -316,12 +316,12 @@ public static Set listCells(Network network) { GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { - if (nodeContainer.getNode() instanceof StorageNetworkNode storageNetworkNode) { - CompositeStorage storage = (CompositeStorage) storageNetworkNode.getStorage(); - for (Storage disk : storage.getSources()) { - if (!(disk instanceof StateTrackedStorage stateTrackedStorage)) - continue; - + if (!(nodeContainer.getNode() instanceof StorageNetworkNode storageNetworkNode)) { + continue; + } + CompositeStorage storage = (CompositeStorage) storageNetworkNode.getStorage(); + for (Storage disk : storage.getSources()) { + if (disk instanceof StateTrackedStorage stateTrackedStorage) { disks.add(parseStorageDisk(stateTrackedStorage)); } } From 05f63a49a6e98043def59a47774383878d53fda3 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:36:53 +0100 Subject: [PATCH 51/91] Change order of fireEvent to improve readability Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../common/addons/refinedstorage/RSCraftJob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index e47126473..2b467f917 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -197,8 +197,8 @@ protected void maybeCraft() { PreviewType previewType = preview.type(); if (previewType == PreviewType.MISSING_RESOURCES) { - fireEvent(true, StatusConstants.MISSING_ITEMS); calculationNotSuccessful = true; + fireEvent(true, StatusConstants.MISSING_ITEMS); return; } From 622ad7853a0e653aaae1187433ca9067bfca6bb7 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:37:08 +0100 Subject: [PATCH 52/91] Add chemical type to storage disk property --- .../common/addons/refinedstorage/RsApi.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 7c129adce..202a7e3dd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -26,6 +26,7 @@ import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; import com.refinedmods.refinedstorage.mekanism.ChemicalResource; +import com.refinedmods.refinedstorage.mekanism.ChemicalResourceType; import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; @@ -575,6 +576,8 @@ public static Object parseStorageDisk(StateTrackedStorage disk) { type = "item"; } else if (serializableStorage.getType() == StorageTypes.FLUID) { type = "fluid"; + } else if (serializableStorage.getType() == ChemicalResourceType.STORAGE_TYPE) { + type = "chemical"; } else { type = "unknown"; } From 3b4f3d849e8bf5536d870189f147359b5755e507 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:41:07 +0100 Subject: [PATCH 53/91] Change == to equals for TaskId check --- .../common/addons/refinedstorage/RSCraftJob.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index 2b467f917..b1bcea435 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -131,7 +131,7 @@ public void tick() { // It's cursed, but the only way currently if (craftingTask != null) { for (TaskStatus status : autocraftingComponent.getStatuses()) { - if (status.info().id() == craftingTask.info().id()) { + if (status.info().id().equals(craftingTask.info().id())) { this.craftingTask = status; break; } @@ -159,7 +159,7 @@ public void tick() { TaskId id = optionalId.get(); for (TaskStatus status : autocraftingComponent.getStatuses()) { - if (status.info().id() == id) { + if (status.info().id().equals(id)) { this.craftingTask = status; // And only now we set that the crafting is started. setStartedCrafting(); From 18dbed2d89b86e365428b16c75a29c9e0a07599a Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 24 Mar 2025 22:47:47 +0100 Subject: [PATCH 54/91] use boolean instead of MethodResult for isConnected() lua function --- .../addons/computercraft/peripheral/RSBridgePeripheral.java | 4 ++-- .../common/util/inventory/IStorageSystemPeripheral.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 7cfba4dcc..79289fd73 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -207,8 +207,8 @@ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IChem @Override @LuaFunction(mainThread = true) - public final MethodResult isConnected() { - return MethodResult.of(isAvailable()); + public final boolean isConnected() { + return isAvailable(); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java index 257cae44c..656755901 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/IStorageSystemPeripheral.java @@ -21,7 +21,7 @@ */ public interface IStorageSystemPeripheral { - MethodResult isConnected(); + boolean isConnected(); MethodResult isOnline(); From 357601b84d9080239c8b5ae3e0e1e364043b8a00 Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 26 Mar 2025 22:17:11 +0100 Subject: [PATCH 55/91] Prevent peripheral creation issues when third party addons are not loaded like mekanism or the rs mekanism integration --- build.gradle | 5 +- .../common/addons/APAddons.java | 8 +- .../peripheral/RSBridgePeripheral.java | 95 +++++++++++-------- .../common/addons/refinedstorage/RsApi.java | 14 +-- .../addons/refinedstorage/RsStorageTypes.java | 25 +++++ .../common/util/inventory/ChemicalFilter.java | 6 +- .../common/util/inventory/FluidFilter.java | 7 ++ .../common/util/inventory/ItemFilter.java | 7 ++ 8 files changed, 113 insertions(+), 54 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsStorageTypes.java diff --git a/build.gradle b/build.gradle index 4e6369fff..b61039c43 100644 --- a/build.gradle +++ b/build.gradle @@ -228,16 +228,15 @@ dependencies { runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorage_version}") compileOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") - runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") + // runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") // Needed for the refined storage mek integration compileOnlyApi("dev.emi:emi-neoforge:${emiVersion}") - // Extended requirements // We don't use the api since we need a specific class from mekanism compileOnly "mekanism:Mekanism:${mekanism_version}" - // runtimeOnly "mekanism:Mekanism:${mekanism_version}" + runtimeOnly "mekanism:Mekanism:${mekanism_version}" // Applied Energistics 2 compileOnly "appeng:appliedenergistics2:${appliedenergistics_version}" diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java index e91927f8b..bfd2356b8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/APAddons.java @@ -12,15 +12,18 @@ public class APAddons { public static final String AE2_MODID = "ae2"; public static final String CURIOS_MODID = "curios"; public static final String REFINEDSTORAGE_MODID = "refinedstorage"; + public static final String REFINEDSTORAGE_MEKANISM_MODID = "refinedstorage_mekanism_integration"; + public static final String MEKANISM_MODID = "mekanism"; public static final String APP_MEKANISTICS_MODID = "appmek"; public static final String MINECOLONIES_MODID = "minecolonies"; public static final String PATCHOULI_MODID = "patchouli"; public static final String POWAH_MODID = "powah"; - public static final String REFINEDSTORAGETWO_MODID = "refinedstorage2"; public static boolean ae2Loaded; public static boolean curiosLoaded; public static boolean refinedStorageLoaded; + public static boolean refinedStorageMekanismLoaded; + public static boolean mekanismLoaded; public static boolean appMekLoaded; public static boolean patchouliLoaded; public static boolean powahLoaded; @@ -34,12 +37,13 @@ public static void setup() { ae2Loaded = modList.isLoaded(AE2_MODID); curiosLoaded = modList.isLoaded(CURIOS_MODID); refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGE_MODID); + refinedStorageMekanismLoaded = modList.isLoaded(REFINEDSTORAGE_MEKANISM_MODID); + mekanismLoaded = modList.isLoaded(MEKANISM_MODID); appMekLoaded = modList.isLoaded(APP_MEKANISTICS_MODID); curiosLoaded = modList.isLoaded(CURIOS_MODID); minecoloniesLoaded = modList.isLoaded(MINECOLONIES_MODID); patchouliLoaded = modList.isLoaded(PATCHOULI_MODID); powahLoaded = modList.isLoaded(POWAH_MODID); - refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGETWO_MODID); } @SubscribeEvent diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 79289fd73..26fa5d970 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -8,11 +8,8 @@ import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage.common.storage.StorageTypes; -import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; -import com.refinedmods.refinedstorage.mekanism.ChemicalResource; -import com.refinedmods.refinedstorage.mekanism.ChemicalResourceType; +import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaFunction; @@ -26,6 +23,7 @@ import de.srendi.advancedperipherals.common.addons.refinedstorage.RsChemicalHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsFluidHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsItemHandler; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RsStorageTypes; import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; @@ -374,6 +372,9 @@ public final MethodResult listCraftableChemicals(IArguments arguments) throws Lu if (!isAvailable()) return notConnected(); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); @@ -475,6 +476,9 @@ public final MethodResult importChemical(IComputerAccess computer, IArguments ar if (!isAvailable()) return notConnected(); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); if (handler == null) handler = ChemicalUtil.getHandlerFromName(computer, arguments.getString(1)); @@ -491,6 +495,9 @@ public final MethodResult exportChemical(IComputerAccess computer, IArguments ar if (!isAvailable()) return notConnected(); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); if (handler == null) handler = ChemicalUtil.getHandlerFromName(computer, arguments.getString(1)); @@ -548,7 +555,7 @@ public final MethodResult getTotalExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -557,7 +564,7 @@ public final MethodResult getTotalExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -566,7 +573,10 @@ public final MethodResult getTotalExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -575,7 +585,7 @@ public final MethodResult getTotalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -584,7 +594,7 @@ public final MethodResult getTotalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -593,7 +603,10 @@ public final MethodResult getTotalChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -602,7 +615,7 @@ public final MethodResult getUsedExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -611,7 +624,7 @@ public final MethodResult getUsedExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -620,7 +633,10 @@ public final MethodResult getUsedExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + + return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -629,7 +645,7 @@ public final MethodResult getUsedItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getUsedStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -638,7 +654,7 @@ public final MethodResult getUsedFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getUsedStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -647,7 +663,10 @@ public final MethodResult getUsedChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + + return MethodResult.of(RsApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -656,7 +675,7 @@ public final MethodResult getAvailableExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), StorageTypes.ITEM) - RsApi.getUsedExternalStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.ITEM) - RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -665,7 +684,7 @@ public final MethodResult getAvailableExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), StorageTypes.FLUID) - RsApi.getUsedExternalStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.FLUID) - RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -674,7 +693,10 @@ public final MethodResult getAvailableExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RsApi.getUsedExternalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + + return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -683,7 +705,7 @@ public final MethodResult getAvailableItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), StorageTypes.ITEM) - RsApi.getUsedStorage(getNetwork(), StorageTypes.ITEM)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.ITEM) - RsApi.getUsedStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -692,7 +714,7 @@ public final MethodResult getAvailableFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), StorageTypes.FLUID) - RsApi.getUsedStorage(getNetwork(), StorageTypes.FLUID)); + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.FLUID) - RsApi.getUsedStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -701,7 +723,10 @@ public final MethodResult getAvailableChemicalStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE) - RsApi.getUsedStorage(getNetwork(), ChemicalResourceType.STORAGE_TYPE)); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + + return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RsApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -714,11 +739,7 @@ public final MethodResult craftItem(IComputerAccess computer, IArguments argumen if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - ItemResource stack = RsApi.getItem(getNetwork(), filter.getLeft()); - if (stack == null) - return MethodResult.of(null, "NOT_CRAFTABLE"); - - RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), stack, getNetwork().getComponent(AutocraftingNetworkComponent.class)); + RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), ItemResource.ofItemStack(filter.getLeft().toItemStack()), getNetwork().getComponent(AutocraftingNetworkComponent.class)); bridge.addJob(job); return MethodResult.of(job); } @@ -733,11 +754,7 @@ public final MethodResult craftFluid(IComputerAccess computer, IArguments argume if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - FluidResource stack = RsApi.getFluid(getNetwork(), filter.getLeft()); - if (stack == null) - return MethodResult.of(null, "NOT_CRAFTABLE"); - - RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), stack, getNetwork().getComponent(AutocraftingNetworkComponent.class)); + RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), VariantUtil.ofFluidStack(filter.getLeft().toFluidStack()), getNetwork().getComponent(AutocraftingNetworkComponent.class)); bridge.addJob(job); return MethodResult.of(job); } @@ -748,17 +765,17 @@ public final MethodResult craftChemical(IComputerAccess computer, IArguments arg if (!isAvailable()) return notConnected(); + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(Collections.emptyList()); + Pair filter = ChemicalFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - ChemicalResource stack = RsApi.getChemical(getNetwork(), filter.getLeft()); - if (stack == null) - return MethodResult.of(null, "NOT_CRAFTABLE"); - - RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), stack, getNetwork().getComponent(AutocraftingNetworkComponent.class)); - bridge.addJob(job); - return MethodResult.of(job); + //RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), ChemicalResource.ofChemicalStack(filter.getLeft().toChemicalStack()), getNetwork().getComponent(AutocraftingNetworkComponent.class)); + //bridge.addJob(job); + //return MethodResult.of(job); + return MethodResult.of(0); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 202a7e3dd..7f4954205 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -395,7 +395,7 @@ public static Pair findPatternFromFilters(Network network, @Nul return Pair.of(null, "NO_PATTERN_FOUND"); } - public static long getTotalStorage(Network network, StorageType type) { + public static long getTotalStorage(Network network, RsStorageTypes type) { long total = 0; GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); @@ -407,7 +407,7 @@ public static long getTotalStorage(Network network, StorageType type) { continue; if (stateTrackedStorage.getDelegate() instanceof SerializableStorage serializableStorage) { - if (serializableStorage.getType() != type) + if (serializableStorage.getType() != type.getStorageType()) continue; } @@ -418,7 +418,7 @@ public static long getTotalStorage(Network network, StorageType type) { return total; } - public static long getUsedStorage(Network network, StorageType type) { + public static long getUsedStorage(Network network, RsStorageTypes type) { long used = 0; GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); @@ -430,7 +430,7 @@ public static long getUsedStorage(Network network, StorageType type) { continue; if (stateTrackedStorage.getDelegate() instanceof SerializableStorage serializableStorage) { - if (serializableStorage.getType() != type) + if (serializableStorage.getType() != type.getStorageType()) continue; } @@ -441,7 +441,7 @@ public static long getUsedStorage(Network network, StorageType type) { return used; } - public static long getTotalExternalStorage(Network network, StorageType type) { + public static long getTotalExternalStorage(Network network, RsStorageTypes type) { long total = 0; GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); @@ -455,7 +455,7 @@ public static long getTotalExternalStorage(Network network, StorageType type) { return total; } - public static long getUsedExternalStorage(Network network, StorageType type) { + public static long getUsedExternalStorage(Network network, RsStorageTypes type) { long used = 0; GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); @@ -463,7 +463,7 @@ public static long getUsedExternalStorage(Network network, StorageType type) { if (nodeContainer.getNode() instanceof ExternalStorageNetworkNode storageNetworkNode) { ExposedExternalStorage storage = (ExposedExternalStorage) storageNetworkNode.getStorage(); - used += storage.getAll().stream().filter(amount -> type.isAllowed(amount.resource())).mapToLong(ResourceAmount::amount).sum(); + used += storage.getAll().stream().filter(amount -> type.getStorageType().isAllowed(amount.resource())).mapToLong(ResourceAmount::amount).sum(); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsStorageTypes.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsStorageTypes.java new file mode 100644 index 000000000..8c632c523 --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsStorageTypes.java @@ -0,0 +1,25 @@ +package de.srendi.advancedperipherals.common.addons.refinedstorage; + +import com.refinedmods.refinedstorage.common.api.storage.StorageType; +import com.refinedmods.refinedstorage.common.storage.StorageTypes; +import com.refinedmods.refinedstorage.mekanism.ChemicalResourceType; + +/** + * To better support third party RS addons and to prevent any jvm loading issues when third party addons are not loaded + */ +public enum RsStorageTypes { + + ITEM(StorageTypes.ITEM), + FLUID(StorageTypes.FLUID), + CHEMICAL(ChemicalResourceType.STORAGE_TYPE); + + private final StorageType storageType; + + RsStorageTypes(StorageType storageType) { + this.storageType = storageType; + } + + public StorageType getStorageType() { + return storageType; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java index 83007da68..0a573c45e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java @@ -6,6 +6,7 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi; import de.srendi.advancedperipherals.common.util.Pair; import mekanism.api.MekanismAPI; @@ -99,14 +100,13 @@ public boolean isEmpty() { @Override public boolean testAE(GenericStack genericStack) { - //if (genericStack.what() instanceof aeItemKey) { - // return test(aeItemKey.toStack()); - //} return false; } @Override public boolean testRS(ResourceAmount resourceAmount) { + if (!APAddons.mekanismLoaded || !APAddons.refinedStorageLoaded || !APAddons.refinedStorageMekanismLoaded) + return false; if (resourceAmount.resource() instanceof ChemicalResource chemicalResource) { return test(RsApi.resourceToChemicalStack(chemicalResource)); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java index a6233ee8e..ada5f1c9f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/FluidFilter.java @@ -8,6 +8,7 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.util.DataComponentUtil; import de.srendi.advancedperipherals.common.util.NBTUtil; import de.srendi.advancedperipherals.common.util.Pair; @@ -104,6 +105,9 @@ public boolean isEmpty() { @Override public boolean testAE(GenericStack genericStack) { + if (!APAddons.ae2Loaded) + return false; + if (genericStack.what() instanceof AEFluidKey aeFluidKey) { return test(aeFluidKey.toStack(1)); } @@ -112,6 +116,9 @@ public boolean testAE(GenericStack genericStack) { @Override public boolean testRS(ResourceAmount resourceAmount) { + if (!APAddons.refinedStorageLoaded) + return false; + if (resourceAmount.resource() instanceof FluidResource fluidResource) { return test(VariantUtil.toFluidStack(fluidResource, 1)); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java index 2ab139227..b73897f58 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ItemFilter.java @@ -7,6 +7,7 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.util.DataComponentUtil; import de.srendi.advancedperipherals.common.util.NBTUtil; import de.srendi.advancedperipherals.common.util.Pair; @@ -119,6 +120,9 @@ public boolean isEmpty() { @Override public boolean testAE(GenericStack genericStack) { + if (!APAddons.ae2Loaded) + return false; + if (genericStack.what() instanceof AEItemKey aeItemKey) { return test(aeItemKey.toStack()); } @@ -127,6 +131,9 @@ public boolean testAE(GenericStack genericStack) { @Override public boolean testRS(ResourceAmount resourceAmount) { + if (!APAddons.refinedStorageLoaded) + return false; + if (resourceAmount.resource() instanceof ItemResource itemResource) { return test(itemResource.toItemStack(1)); } From ff27797a95a7c53810bcc1c7cfd4c49039c95bfe Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 26 Mar 2025 22:17:43 +0100 Subject: [PATCH 56/91] Improve todo comment on getTotalExternalStorage --- .../advancedperipherals/common/addons/refinedstorage/RsApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 7f4954205..9f18e34b0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -448,7 +448,7 @@ public static long getTotalExternalStorage(Network network, RsStorageTypes type) for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { if (nodeContainer.getNode() instanceof ExternalStorageNetworkNode storageNetworkNode) { ExposedExternalStorage storage = (ExposedExternalStorage) storageNetworkNode.getStorage(); - // TODO + // TODO - Waiting for next rs beta/milestone patch } } From 9f9e8b242e3b057225559b2a06e6cb0a6b92d09d Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 26 Mar 2025 22:40:27 +0100 Subject: [PATCH 57/91] begone import --- .../advancedperipherals/common/addons/refinedstorage/RsApi.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 9f18e34b0..1e38e9f58 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -20,7 +20,6 @@ import com.refinedmods.refinedstorage.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage.api.storage.composite.CompositeStorage; import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; -import com.refinedmods.refinedstorage.common.api.storage.StorageType; import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; import com.refinedmods.refinedstorage.common.storage.StorageTypes; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; From e94c125244c70b8b9c0fee29224907b7f5eb7367 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Mar 2025 21:38:19 +0100 Subject: [PATCH 58/91] Changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f7ec54d5..d339cb196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- We enhanced the RS Bridge in a major way including new functions, a better crafting system and more. Refer to the [docs](https://docs.advanced-peripherals.de/0.7-bridges/guides/storage_system_functions/) + ### Fixed - [#711] Fixed that the block reader would not be able to access registries for component information From a327ed92d210c5d5a1ff9fee539db6fb9c75334f Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Mar 2025 21:52:35 +0100 Subject: [PATCH 59/91] AE2 Stuff -> RS Stuff Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../common/util/inventory/GenericFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index 471d33a77..4d2acc2e3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -54,7 +54,7 @@ public static Pair, String> parseGeneric(Map ra // AE2 stuff public abstract boolean testAE(GenericStack genericStack); - // AE2 stuff + // RS stuff public abstract boolean testRS(ResourceAmount resourceAmount); public abstract boolean test(T toTest); From 9f7c1dcec170d6510dc8b9c57afd63228c150d47 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Mar 2025 22:06:46 +0100 Subject: [PATCH 60/91] Remove unnecessary copy --- .../advancedperipherals/common/util/inventory/ChemicalUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java index 2e1588173..a6d9f50df 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java @@ -127,6 +127,6 @@ public static ResourceLocation getRegistryKey(Chemical fluid) { } public static ResourceLocation getRegistryKey(ChemicalStack fluid) { - return MekanismAPI.CHEMICAL_REGISTRY.getKey(fluid.copy().getChemical()); + return MekanismAPI.CHEMICAL_REGISTRY.getKey(fluid.getChemical()); } } From 247013e6e8744db9bb2698a092ea94645bee4249 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Mar 2025 22:07:31 +0100 Subject: [PATCH 61/91] remove print stack trace and use log4j --- .../common/util/inventory/ChemicalUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java index a6d9f50df..da43b5c6c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java @@ -116,8 +116,7 @@ public static String getFingerprint(@NotNull ChemicalStack stack) { MessageDigest md = MessageDigest.getInstance("MD5"); return StringUtil.toHexString(md.digest(bytesOfHash)); } catch (NoSuchAlgorithmException ex) { - AdvancedPeripherals.debug("Could not parse fingerprint.", org.apache.logging.log4j.Level.ERROR); - ex.printStackTrace(); + AdvancedPeripherals.debug("Could not parse fingerprint", ex); } return ""; } From 3ce9dd27e73ad4ca3cca602958585a5e8de27737 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Mar 2025 22:13:09 +0100 Subject: [PATCH 62/91] Fixed that filters can't specify a type while having a name property --- .../common/util/inventory/GenericFilter.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index 4d2acc2e3..584d893cb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -22,18 +22,19 @@ public abstract class GenericFilter { */ public static Pair, String> parseGeneric(Map rawFilter) { - if (!rawFilter.containsKey("name")) { - if (rawFilter.containsKey("type") && rawFilter.get("type") instanceof String type) { - switch (type) { - case "item": - return ItemFilter.parse(rawFilter); - case "fluid": - return FluidFilter.parse(rawFilter); - case "chemical": - return ChemicalFilter.parse(rawFilter); - } + if (rawFilter.containsKey("type") && rawFilter.get("type") instanceof String type) { + switch (type) { + case "item": + return ItemFilter.parse(rawFilter); + case "fluid": + return FluidFilter.parse(rawFilter); + case "chemical": + return ChemicalFilter.parse(rawFilter); } } + if (!rawFilter.containsKey("name")) + return Pair.of(empty(), "NO_NAME_OR_TYPE"); + String name = rawFilter.get("name").toString(); // Let's check in which registry this thing is From 0359a50914d0925302b6f48b0f02a2cdc5151adb Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Mar 2025 22:17:50 +0100 Subject: [PATCH 63/91] Use constant instead of creating a new object everytime for an empty generic filter --- .../common/util/inventory/GenericFilter.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java index 584d893cb..e7cc4cce4 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/GenericFilter.java @@ -10,6 +10,28 @@ public abstract class GenericFilter { + private static final GenericFilter EMPTY = new GenericFilter<>() { + @Override + public boolean isEmpty() { + return true; + } + + @Override + public boolean testAE(GenericStack genericStack) { + return false; + } + + @Override + public boolean testRS(ResourceAmount resourceAmount) { + return false; + } + + @Override + public boolean test(Object toTest) { + return false; + } + }; + /** * Try to parse a raw filter table to any existing filter type. Could be a fluid filter, an item filter, maybe something else * in the future. @@ -61,27 +83,7 @@ public static Pair, String> parseGeneric(Map ra public abstract boolean test(T toTest); public static GenericFilter empty() { - return new GenericFilter<>() { - @Override - public boolean isEmpty() { - return true; - } - - @Override - public boolean testAE(GenericStack genericStack) { - return false; - } - - @Override - public boolean testRS(ResourceAmount resourceAmount) { - return false; - } - - @Override - public boolean test(Object toTest) { - return false; - } - }; + return EMPTY; } } From 9a20cf02afc87a2aec42c4aa9bd20a025df75815 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 28 Mar 2025 22:23:17 +0100 Subject: [PATCH 64/91] Uncomment methods from testing and improve `getCraftingTask` --- .../peripheral/RSBridgePeripheral.java | 14 ++++++-------- .../common/util/StatusConstants.java | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 26fa5d970..a03304e17 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -9,6 +9,7 @@ import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage.mekanism.ChemicalResource; import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; @@ -772,10 +773,9 @@ public final MethodResult craftChemical(IComputerAccess computer, IArguments arg if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); - //RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), ChemicalResource.ofChemicalStack(filter.getLeft().toChemicalStack()), getNetwork().getComponent(AutocraftingNetworkComponent.class)); - //bridge.addJob(job); - //return MethodResult.of(job); - return MethodResult.of(0); + RSCraftJob job = new RSCraftJob(computer, getLevel(), filter.getLeft().getCount(), ChemicalResource.ofChemicalStack(filter.getLeft().toChemicalStack()), getNetwork().getComponent(AutocraftingNetworkComponent.class)); + bridge.addJob(job); + return MethodResult.of(job); } @Override @@ -793,14 +793,12 @@ public final MethodResult getCraftingTask(int id) { if (!isAvailable()) return notConnected(); - RSCraftJob foundJob = null; - for (RSCraftJob job : bridge.getJobs()) { if (job.getId() == id) { - foundJob = job; + return MethodResult.of(job); } } - return MethodResult.of(foundJob); + return MethodResult.of(null, StatusConstants.NOT_FOUND); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java index 1e68bab7d..72fc081fb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java @@ -34,6 +34,7 @@ public enum StatusConstants { CHEMICAL_NOT_FOUND, // Misc NOT_CONNECTED, + NOT_FOUND, // Generic not found state UNKNOWN_ERROR; public String withInfo(String extraInfo) { From b834284c06a60d4efa94ad9e69415ce2c8f99cb8 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 22:07:00 +0200 Subject: [PATCH 65/91] rename Me bridge to ME bridge --- ...dgeEntityListener.java => MEBridgeEntityListener.java} | 8 ++++---- .../computercraft/peripheral/MEBridgePeripheral.java | 8 ++++---- .../{MeBridgeEntity.java => MEBridgeEntity.java} | 8 ++++---- .../common/setup/BlockEntityTypes.java | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) rename src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/{MeBridgeEntityListener.java => MEBridgeEntityListener.java} (59%) rename src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/{MeBridgeEntity.java => MEBridgeEntity.java} (96%) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEBridgeEntityListener.java similarity index 59% rename from src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEBridgeEntityListener.java index f9ad68b12..135d3dd39 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeBridgeEntityListener.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEBridgeEntityListener.java @@ -2,15 +2,15 @@ import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNodeListener; -import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.MEBridgeEntity; //TODO: Maybe do something special with these methods? -public class MeBridgeEntityListener implements IGridNodeListener { +public class MEBridgeEntityListener implements IGridNodeListener { - public static final MeBridgeEntityListener INSTANCE = new MeBridgeEntityListener(); + public static final MEBridgeEntityListener INSTANCE = new MEBridgeEntityListener(); @Override - public void onSaveChanges(MeBridgeEntity nodeOwner, IGridNode node) { + public void onSaveChanges(MEBridgeEntity nodeOwner, IGridNode node) { } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java index b476d4455..eba665ab1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java @@ -17,7 +17,7 @@ import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeFluidHandler; import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeItemHandler; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; -import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.MEBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.ServerWorker; @@ -35,13 +35,13 @@ import java.util.Iterator; import java.util.List; -public class MEBridgePeripheral extends BasePeripheral> { +public class MEBridgePeripheral extends BasePeripheral> { public static final String PERIPHERAL_TYPE = "meBridge"; - private final MeBridgeEntity tile; + private final MEBridgeEntity tile; private IGridNode node; - public MEBridgePeripheral(MeBridgeEntity tileEntity) { + public MEBridgePeripheral(MEBridgeEntity tileEntity) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(tileEntity)); this.tile = tileEntity; this.node = tileEntity.getActionableNode(); diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MEBridgeEntity.java similarity index 96% rename from src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java rename to src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MEBridgeEntity.java index 9f38752dc..82f7116bb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MeBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/MEBridgeEntity.java @@ -12,7 +12,7 @@ import appeng.api.util.AECableType; import appeng.me.helpers.IGridConnectedBlockEntity; import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob; -import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeBridgeEntityListener; +import de.srendi.advancedperipherals.common.addons.appliedenergistics.MEBridgeEntityListener; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MEBridgePeripheral; import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; @@ -34,13 +34,13 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; -public class MeBridgeEntity extends PeripheralBlockEntity implements IActionSource, IActionHost, IInWorldGridNodeHost, IGridConnectedBlockEntity, ICraftingSimulationRequester { +public class MEBridgeEntity extends PeripheralBlockEntity implements IActionSource, IActionHost, IInWorldGridNodeHost, IGridConnectedBlockEntity, ICraftingSimulationRequester { private final List jobs = new CopyOnWriteArrayList<>(); private boolean initialized = false; - private final IManagedGridNode mainNode = GridHelper.createManagedNode(this, MeBridgeEntityListener.INSTANCE); + private final IManagedGridNode mainNode = GridHelper.createManagedNode(this, MEBridgeEntityListener.INSTANCE); - public MeBridgeEntity(BlockPos pos, BlockState state) { + public MEBridgeEntity(BlockPos pos, BlockState state) { super(BlockEntityTypes.ME_BRIDGE.get(), pos, state); getMainNode().setExposedOnSides(getGridConnectableSides(null)); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java index 87b0a7d2b..f69fbcf33 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java @@ -9,7 +9,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.EnvironmentDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.GeoScannerEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.InventoryManagerEntity; -import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.MEBridgeEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.NBTStorageEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.PlayerDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.RedstoneIntegratorEntity; @@ -22,7 +22,7 @@ public class BlockEntityTypes { public static final DeferredHolder, BlockEntityType> CHAT_BOX = Registration.BLOCK_ENTITIES.register("chat_box", () -> new BlockEntityType<>(ChatBoxEntity::new, Sets.newHashSet(Blocks.CHAT_BOX.get()), null)); public static final DeferredHolder, BlockEntityType> ENVIRONMENT_DETECTOR = Registration.BLOCK_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(Blocks.ENVIRONMENT_DETECTOR.get()), null)); public static final DeferredHolder, BlockEntityType> PLAYER_DETECTOR = Registration.BLOCK_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(Blocks.PLAYER_DETECTOR.get()), null)); - public static final DeferredHolder, BlockEntityType> ME_BRIDGE = APAddons.ae2Loaded ? Registration.BLOCK_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MeBridgeEntity::new, Sets.newHashSet(Blocks.ME_BRIDGE.get()), null)) : null; + public static final DeferredHolder, BlockEntityType> ME_BRIDGE = APAddons.ae2Loaded ? Registration.BLOCK_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MEBridgeEntity::new, Sets.newHashSet(Blocks.ME_BRIDGE.get()), null)) : null; public static final DeferredHolder, BlockEntityType> RS_BRIDGE = APAddons.refinedStorageLoaded ? Registration.BLOCK_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(Blocks.RS_BRIDGE.get()), null)) : null; public static final DeferredHolder, BlockEntityType> ENERGY_DETECTOR = Registration.BLOCK_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(Blocks.ENERGY_DETECTOR.get()), null)); public static final DeferredHolder, BlockEntityType> INVENTORY_MANAGER = Registration.BLOCK_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(Blocks.INVENTORY_MANAGER.get()), null)); From fdc72b7597bb8213315cc43b2e7138bc6d2370c8 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 22:09:04 +0200 Subject: [PATCH 66/91] Switch to a nested if statement in inventory logic for better readability Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../computercraft/peripheral/RSBridgePeripheral.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index a03304e17..bcd9c2a35 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -413,11 +413,12 @@ public final MethodResult importItem(IComputerAccess computer, IArguments argume IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - if (inventory == null) + if (inventory == null) { inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - - if (inventory == null) - return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + if (inventory == null) { + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + } + } return importToRS(arguments, inventory); } From 168c206e25e6f1ab7f83eaafcaf4072155e983f5 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 22:10:15 +0200 Subject: [PATCH 67/91] remove useless mekanism check --- .../peripheral/RSBridgePeripheral.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index bcd9c2a35..e69398d2f 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -373,7 +373,7 @@ public final MethodResult listCraftableChemicals(IArguments arguments) throws Lu if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); @@ -478,7 +478,7 @@ public final MethodResult importChemical(IComputerAccess computer, IArguments ar if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); @@ -497,7 +497,7 @@ public final MethodResult exportChemical(IComputerAccess computer, IArguments ar if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); @@ -575,7 +575,7 @@ public final MethodResult getTotalExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); @@ -605,7 +605,7 @@ public final MethodResult getTotalChemicalStorage() { if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); @@ -635,7 +635,7 @@ public final MethodResult getUsedExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); @@ -665,7 +665,7 @@ public final MethodResult getUsedChemicalStorage() { if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); return MethodResult.of(RsApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); @@ -695,7 +695,7 @@ public final MethodResult getAvailableExternalChemicalStorage() { if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); @@ -725,7 +725,7 @@ public final MethodResult getAvailableChemicalStorage() { if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RsApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); @@ -767,7 +767,7 @@ public final MethodResult craftChemical(IComputerAccess computer, IArguments arg if (!isAvailable()) return notConnected(); - if (!APAddons.mekanismLoaded || !APAddons.refinedStorageMekanismLoaded) + if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); Pair filter = ChemicalFilter.parse(arguments.getTable(0)); From c9744fd6b779104222c9a2cc7cf568b2d372b4f4 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 22:24:50 +0200 Subject: [PATCH 68/91] Fixed crash with storage functions when the mekanism addon is not loaded Bump RS Return 0 instead of empty list when mekanism addon is not loaded --- gradle.properties | 4 ++-- .../peripheral/RSBridgePeripheral.java | 12 ++++++------ .../common/addons/refinedstorage/RsApi.java | 6 +++--- .../addons/refinedstorage/RsStorageTypes.java | 19 +++++++++++++------ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7150349f8..33db36b5f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,8 +30,8 @@ cc_version=1.113.1 ae2things_version=5637783 appliedenergistics_version=19.1.2-beta appliedmekanistics_version=5978711 -refinedstorage_version=2.0.0-milestone.4.14 -refinedstorage_mekanism_version=0.3.0 +refinedstorage_version=2.0.0-beta.2 +refinedstorage_mekanism_version=1.0.0 minecolonies_version=1.1.846-1.21.1-snapshot patchouli_version=1.21-87 mekanism_version=1.21.1-10.7.12.77 diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index e69398d2f..d152b0e8b 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -576,7 +576,7 @@ public final MethodResult getTotalExternalChemicalStorage() { return notConnected(); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(0); return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -606,7 +606,7 @@ public final MethodResult getTotalChemicalStorage() { return notConnected(); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(0); return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -636,7 +636,7 @@ public final MethodResult getUsedExternalChemicalStorage() { return notConnected(); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(0); return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -666,7 +666,7 @@ public final MethodResult getUsedChemicalStorage() { return notConnected(); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(0); return MethodResult.of(RsApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -696,7 +696,7 @@ public final MethodResult getAvailableExternalChemicalStorage() { return notConnected(); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(0); return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -726,7 +726,7 @@ public final MethodResult getAvailableChemicalStorage() { return notConnected(); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(0); return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RsApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java index 1e38e9f58..a88d7e889 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java @@ -406,7 +406,7 @@ public static long getTotalStorage(Network network, RsStorageTypes type) { continue; if (stateTrackedStorage.getDelegate() instanceof SerializableStorage serializableStorage) { - if (serializableStorage.getType() != type.getStorageType()) + if (type.getStorageType() != null && serializableStorage.getType() != type.getStorageType()) continue; } @@ -429,7 +429,7 @@ public static long getUsedStorage(Network network, RsStorageTypes type) { continue; if (stateTrackedStorage.getDelegate() instanceof SerializableStorage serializableStorage) { - if (serializableStorage.getType() != type.getStorageType()) + if (type.getStorageType() != null && serializableStorage.getType() != type.getStorageType()) continue; } @@ -462,7 +462,7 @@ public static long getUsedExternalStorage(Network network, RsStorageTypes type) if (nodeContainer.getNode() instanceof ExternalStorageNetworkNode storageNetworkNode) { ExposedExternalStorage storage = (ExposedExternalStorage) storageNetworkNode.getStorage(); - used += storage.getAll().stream().filter(amount -> type.getStorageType().isAllowed(amount.resource())).mapToLong(ResourceAmount::amount).sum(); + used += storage.getAll().stream().filter(amount -> type.getStorageType() != null && type.getStorageType().isAllowed(amount.resource())).mapToLong(ResourceAmount::amount).sum(); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsStorageTypes.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsStorageTypes.java index 8c632c523..d61ff4424 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsStorageTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsStorageTypes.java @@ -3,23 +3,30 @@ import com.refinedmods.refinedstorage.common.api.storage.StorageType; import com.refinedmods.refinedstorage.common.storage.StorageTypes; import com.refinedmods.refinedstorage.mekanism.ChemicalResourceType; +import de.srendi.advancedperipherals.common.addons.APAddons; + +import java.util.function.Supplier; /** * To better support third party RS addons and to prevent any jvm loading issues when third party addons are not loaded */ public enum RsStorageTypes { - ITEM(StorageTypes.ITEM), - FLUID(StorageTypes.FLUID), - CHEMICAL(ChemicalResourceType.STORAGE_TYPE); + ITEM(() -> StorageTypes.ITEM), + FLUID(() -> StorageTypes.FLUID), + CHEMICAL(() -> { + if (APAddons.refinedStorageMekanismLoaded) + return ChemicalResourceType.STORAGE_TYPE; + return null; + }); - private final StorageType storageType; + private final Supplier storageType; - RsStorageTypes(StorageType storageType) { + RsStorageTypes(Supplier storageType) { this.storageType = storageType; } public StorageType getStorageType() { - return storageType; + return storageType.get(); } } From aeb66883f945418ff028d8d72b0cdd76f8f4f999 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 23:40:20 +0200 Subject: [PATCH 69/91] More nested if statements Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../computercraft/peripheral/RSBridgePeripheral.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index d152b0e8b..886412ef5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -482,11 +482,12 @@ public final MethodResult importChemical(IComputerAccess computer, IArguments ar return MethodResult.of(Collections.emptyList()); IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); - if (handler == null) + if (handler == null) { handler = ChemicalUtil.getHandlerFromName(computer, arguments.getString(1)); - - if (handler == null) - return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + if (handler == null) { + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + } + } return importToRS(arguments, handler); } From 93485152d3c099060f64e0c49fb010e8e3a8747e Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 23:40:27 +0200 Subject: [PATCH 70/91] More nested if statements Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../computercraft/peripheral/RSBridgePeripheral.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 886412ef5..69e25d623 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -431,11 +431,12 @@ public final MethodResult exportItem(IComputerAccess computer, IArguments argume IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); - if (inventory == null) + if (inventory == null) { inventory = InventoryUtil.getHandlerFromName(computer, arguments.getString(1)); - - if (inventory == null) - return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + if (inventory == null) { + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + } + } return exportToChest(arguments, inventory); } From 7f34eaf0460b870e486735dd50716ff23f7c6a19 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 23:40:33 +0200 Subject: [PATCH 71/91] More nested if statements Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../computercraft/peripheral/RSBridgePeripheral.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 69e25d623..52f0b7ff6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -448,11 +448,12 @@ public final MethodResult importFluid(IComputerAccess computer, IArguments argum return notConnected(); IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - if (handler == null) + if (handler == null) { handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - - if (handler == null) - return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + if (handler == null) { + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + } + } return importToRS(arguments, handler); } From ab032aaa8f47cb642aac23f28fc45fb4df3c7e7c Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 23:40:50 +0200 Subject: [PATCH 72/91] More nested if statements Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../computercraft/peripheral/RSBridgePeripheral.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 52f0b7ff6..939d8fb36 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -465,11 +465,12 @@ public final MethodResult exportFluid(IComputerAccess computer, IArguments argum return notConnected(); IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); - if (handler == null) + if (handler == null) { handler = FluidUtil.getHandlerFromName(computer, arguments.getString(1)); - - if (handler == null) - return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + if (handler == null) { + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + } + } return exportToTank(arguments, handler); } From 703f022d2f8c4f313060fcb37390c6b842138eee Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 18 Apr 2025 23:40:57 +0200 Subject: [PATCH 73/91] More nested if statements Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../computercraft/peripheral/RSBridgePeripheral.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 939d8fb36..0f782ddb9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -505,11 +505,12 @@ public final MethodResult exportChemical(IComputerAccess computer, IArguments ar return MethodResult.of(Collections.emptyList()); IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); - if (handler == null) + if (handler == null) { handler = ChemicalUtil.getHandlerFromName(computer, arguments.getString(1)); - - if (handler == null) - return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + if (handler == null) { + return MethodResult.of(0, StatusConstants.INVENTORY_NOT_FOUND.name()); + } + } return exportToTank(arguments, handler); } From 6a3133e11850667b49f87b5dc0d0134101f6eca7 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sat, 19 Apr 2025 15:03:44 +0200 Subject: [PATCH 74/91] Rename Me -> ME and Rs -> RS --- .../AdvancedPeripherals.java | 4 +- ...eFluidHandler.java => MEFluidHandler.java} | 4 +- ...{MeItemHandler.java => MEItemHandler.java} | 4 +- .../peripheral/MEBridgePeripheral.java | 12 +-- .../peripheral/RSBridgePeripheral.java | 90 +++++++++---------- .../refinedstorage/{RsApi.java => RSApi.java} | 4 +- ...calHandler.java => RSChemicalHandler.java} | 6 +- .../addons/refinedstorage/RSCraftJob.java | 8 +- ...sFluidHandler.java => RSFluidHandler.java} | 6 +- ...{RsItemHandler.java => RSItemHandler.java} | 6 +- .../common/util/inventory/ChemicalFilter.java | 4 +- 11 files changed, 74 insertions(+), 74 deletions(-) rename src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/{MeFluidHandler.java => MEFluidHandler.java} (93%) rename src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/{MeItemHandler.java => MEItemHandler.java} (94%) rename src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/{RsApi.java => RSApi.java} (99%) rename src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/{RsChemicalHandler.java => RSChemicalHandler.java} (92%) rename src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/{RsFluidHandler.java => RSFluidHandler.java} (91%) rename src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/{RsItemHandler.java => RSItemHandler.java} (92%) diff --git a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java index 32607eadc..8980ef8f6 100644 --- a/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java +++ b/src/main/java/de/srendi/advancedperipherals/AdvancedPeripherals.java @@ -3,7 +3,7 @@ import dan200.computercraft.api.peripheral.PeripheralCapability; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSApi; import de.srendi.advancedperipherals.common.blocks.base.ICapabilityProvider; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.setup.Registration; @@ -102,6 +102,6 @@ public void registerCapabilities(RegisterCapabilitiesEvent event) { if (APAddons.ae2Loaded) AppEngApi.registerCapabilities(event); if (APAddons.refinedStorageLoaded) - RsApi.registerCapabilities(event); + RSApi.registerCapabilities(event); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEFluidHandler.java similarity index 93% rename from src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEFluidHandler.java index cf67ddc39..1c554e442 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEFluidHandler.java @@ -15,14 +15,14 @@ * Used to transfer item between an inventory and the ME system. * @see MEBridgePeripheral */ -public class MeFluidHandler implements IStorageSystemFluidHandler { +public class MEFluidHandler implements IStorageSystemFluidHandler { @NotNull private final MEStorage storageMonitor; @NotNull private final IActionSource actionSource; - public MeFluidHandler(@NotNull MEStorage storageMonitor, @NotNull IActionSource actionSource) { + public MEFluidHandler(@NotNull MEStorage storageMonitor, @NotNull IActionSource actionSource) { this.storageMonitor = storageMonitor; this.actionSource = actionSource; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEItemHandler.java similarity index 94% rename from src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEItemHandler.java index 36d973ba5..cc806f907 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MeItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEItemHandler.java @@ -16,14 +16,14 @@ * * @see MEBridgePeripheral */ -public class MeItemHandler implements IStorageSystemItemHandler { +public class MEItemHandler implements IStorageSystemItemHandler { @NotNull private final MEStorage storageMonitor; @NotNull private final IActionSource actionSource; - public MeItemHandler(@NotNull MEStorage storageMonitor, @NotNull IActionSource actionSource) { + public MEItemHandler(@NotNull MEStorage storageMonitor, @NotNull IActionSource actionSource) { this.storageMonitor = storageMonitor; this.actionSource = actionSource; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java index eba665ab1..632024cbd 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MEBridgePeripheral.java @@ -14,8 +14,8 @@ import dan200.computercraft.api.peripheral.IComputerAccess; import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi; import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob; -import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeFluidHandler; -import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeItemHandler; +import de.srendi.advancedperipherals.common.addons.appliedenergistics.MEFluidHandler; +import de.srendi.advancedperipherals.common.addons.appliedenergistics.MEItemHandler; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.blocks.blockentities.MEBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; @@ -69,7 +69,7 @@ private ICraftingService getCraftingService() { */ protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { MEStorage monitor = AppEngApi.getMonitor(node); - MeItemHandler itemHandler = new MeItemHandler(monitor, tile); + MEItemHandler itemHandler = new MEItemHandler(monitor, tile); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -90,7 +90,7 @@ protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable II */ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFluidHandler targetTank) throws LuaException { MEStorage monitor = AppEngApi.getMonitor(node); - MeFluidHandler fluidHandler = new MeFluidHandler(monitor, tile); + MEFluidHandler fluidHandler = new MEFluidHandler(monitor, tile); Pair filter = FluidFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -111,7 +111,7 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFl */ protected MethodResult importToME(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { MEStorage monitor = AppEngApi.getMonitor(node); - MeItemHandler itemHandler = new MeItemHandler(monitor, tile); + MEItemHandler itemHandler = new MEItemHandler(monitor, tile); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -132,7 +132,7 @@ protected MethodResult importToME(@NotNull IArguments arguments, @Nullable IItem */ protected MethodResult importToME(@NotNull IArguments arguments, @Nullable IFluidHandler targetTank) throws LuaException { MEStorage monitor = AppEngApi.getMonitor(node); - MeFluidHandler fluidHandler = new MeFluidHandler(monitor, tile); + MEFluidHandler fluidHandler = new MEFluidHandler(monitor, tile); Pair filter = FluidFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 0f782ddb9..b5e0c04a3 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -20,10 +20,10 @@ import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; import de.srendi.advancedperipherals.common.addons.refinedstorage.RSCraftJob; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RsChemicalHandler; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RsFluidHandler; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RsItemHandler; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSApi; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSChemicalHandler; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSFluidHandler; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSItemHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsStorageTypes; import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; @@ -92,7 +92,7 @@ private boolean isAvailable() { * @return the exportable amount or null with a string if something went wrong */ protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { - RsItemHandler itemHandler = new RsItemHandler(getNetwork()); + RSItemHandler itemHandler = new RSItemHandler(getNetwork()); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -112,7 +112,7 @@ protected MethodResult exportToChest(@NotNull IArguments arguments, @Nullable II * @return the exportable amount or null with a string if something went wrong */ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFluidHandler targetTank) throws LuaException { - RsFluidHandler fluidHandler = new RsFluidHandler(getNetwork()); + RSFluidHandler fluidHandler = new RSFluidHandler(getNetwork()); Pair filter = FluidFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -132,7 +132,7 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IFl * @return the exportable amount or null with a string if something went wrong */ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable IChemicalHandler targetTank) throws LuaException { - RsChemicalHandler chemicalHandler = new RsChemicalHandler(getNetwork()); + RSChemicalHandler chemicalHandler = new RSChemicalHandler(getNetwork()); Pair filter = ChemicalFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -152,7 +152,7 @@ protected MethodResult exportToTank(@NotNull IArguments arguments, @Nullable ICh * @return the imported amount or null with a string if something went wrong */ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IItemHandler targetInventory) throws LuaException { - RsItemHandler itemHandler = new RsItemHandler(getNetwork()); + RSItemHandler itemHandler = new RSItemHandler(getNetwork()); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -172,7 +172,7 @@ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IItem * @return the imported amount or null with a string if something went wrong */ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IFluidHandler targetTank) throws LuaException { - RsFluidHandler fluidHandler = new RsFluidHandler(getNetwork()); + RSFluidHandler fluidHandler = new RSFluidHandler(getNetwork()); Pair filter = FluidFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -192,7 +192,7 @@ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IFlui * @return the imported amount or null with a string if something went wrong */ protected MethodResult importToRS(@NotNull IArguments arguments, @Nullable IChemicalHandler targetTank) throws LuaException { - RsChemicalHandler chemicalHandler = new RsChemicalHandler(getNetwork()); + RSChemicalHandler chemicalHandler = new RSChemicalHandler(getNetwork()); Pair filter = ChemicalFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -233,7 +233,7 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - Map resourceProperties = RsApi.getParsedItem(getNetwork(), parsedFilter); + Map resourceProperties = RSApi.getParsedItem(getNetwork(), parsedFilter); if (resourceProperties == null) return MethodResult.of(null, "NOT_FOUND"); @@ -254,7 +254,7 @@ public final MethodResult getFluid(IArguments arguments) throws LuaException { if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - Map resourceProperties = RsApi.getParsedFluid(getNetwork(), parsedFilter); + Map resourceProperties = RSApi.getParsedFluid(getNetwork(), parsedFilter); if (resourceProperties == null) return MethodResult.of(null, "NOT_FOUND"); @@ -275,7 +275,7 @@ public final MethodResult getChemical(IArguments arguments) throws LuaException if (parsedFilter.isEmpty()) return MethodResult.of(null, "EMPTY_FILTER"); - Map resourceProperties = RsApi.getParsedChemical(getNetwork(), parsedFilter); + Map resourceProperties = RSApi.getParsedChemical(getNetwork(), parsedFilter); if (resourceProperties == null) return MethodResult.of(null, "NOT_FOUND"); @@ -294,7 +294,7 @@ public final MethodResult listItems(IArguments arguments) throws LuaException { ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RsApi.getParsedItems(getNetwork(), parsedFilter); + Set> resourceProperties = RSApi.getParsedItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -311,7 +311,7 @@ public final MethodResult listFluids(IArguments arguments) throws LuaException { FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RsApi.getParsedFluids(getNetwork(), parsedFilter); + Set> resourceProperties = RSApi.getParsedFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -328,7 +328,7 @@ public final MethodResult listChemicals(IArguments arguments) throws LuaExceptio ChemicalFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RsApi.getParsedChemicals(getNetwork(), parsedFilter); + Set> resourceProperties = RSApi.getParsedChemicals(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -345,7 +345,7 @@ public final MethodResult listCraftableItems(IArguments arguments) throws LuaExc ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RsApi.getCraftableItems(getNetwork(), parsedFilter); + Set> resourceProperties = RSApi.getCraftableItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -362,7 +362,7 @@ public final MethodResult listCraftableFluids(IArguments arguments) throws LuaEx FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RsApi.getCraftableFluids(getNetwork(), parsedFilter); + Set> resourceProperties = RSApi.getCraftableFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -382,7 +382,7 @@ public final MethodResult listCraftableChemicals(IArguments arguments) throws Lu ChemicalFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RsApi.getCraftableChemicals(getNetwork(), parsedFilter); + Set> resourceProperties = RSApi.getCraftableChemicals(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -393,7 +393,7 @@ public final MethodResult listCells() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.listCells(getNetwork())); + return MethodResult.of(RSApi.listCells(getNetwork())); } @Override @@ -402,7 +402,7 @@ public final MethodResult listDrives() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.listDrives(getNetwork())); + return MethodResult.of(RSApi.listDrives(getNetwork())); } @Override @@ -543,7 +543,7 @@ public final MethodResult getEnergyUsage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getEnergyUsage(getNetwork())); + return MethodResult.of(RSApi.getEnergyUsage(getNetwork())); } @Override @@ -562,7 +562,7 @@ public final MethodResult getTotalExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.ITEM)); + return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -571,7 +571,7 @@ public final MethodResult getTotalExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.FLUID)); + return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -583,7 +583,7 @@ public final MethodResult getTotalExternalChemicalStorage() { if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); + return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -592,7 +592,7 @@ public final MethodResult getTotalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.ITEM)); + return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -601,7 +601,7 @@ public final MethodResult getTotalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.FLUID)); + return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -613,7 +613,7 @@ public final MethodResult getTotalChemicalStorage() { if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); + return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -622,7 +622,7 @@ public final MethodResult getUsedExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.ITEM)); + return MethodResult.of(RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -631,7 +631,7 @@ public final MethodResult getUsedExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.FLUID)); + return MethodResult.of(RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -643,7 +643,7 @@ public final MethodResult getUsedExternalChemicalStorage() { if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); - return MethodResult.of(RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); + return MethodResult.of(RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -652,7 +652,7 @@ public final MethodResult getUsedItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedStorage(getNetwork(), RsStorageTypes.ITEM)); + return MethodResult.of(RSApi.getUsedStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -661,7 +661,7 @@ public final MethodResult getUsedFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getUsedStorage(getNetwork(), RsStorageTypes.FLUID)); + return MethodResult.of(RSApi.getUsedStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -673,7 +673,7 @@ public final MethodResult getUsedChemicalStorage() { if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); - return MethodResult.of(RsApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); + return MethodResult.of(RSApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -682,7 +682,7 @@ public final MethodResult getAvailableExternalItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.ITEM) - RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.ITEM)); + return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.ITEM) - RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -691,7 +691,7 @@ public final MethodResult getAvailableExternalFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.FLUID) - RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.FLUID)); + return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.FLUID) - RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -703,7 +703,7 @@ public final MethodResult getAvailableExternalChemicalStorage() { if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); - return MethodResult.of(RsApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RsApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); + return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -712,7 +712,7 @@ public final MethodResult getAvailableItemStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.ITEM) - RsApi.getUsedStorage(getNetwork(), RsStorageTypes.ITEM)); + return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.ITEM) - RSApi.getUsedStorage(getNetwork(), RsStorageTypes.ITEM)); } @Override @@ -721,7 +721,7 @@ public final MethodResult getAvailableFluidStorage() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.FLUID) - RsApi.getUsedStorage(getNetwork(), RsStorageTypes.FLUID)); + return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.FLUID) - RSApi.getUsedStorage(getNetwork(), RsStorageTypes.FLUID)); } @Override @@ -733,7 +733,7 @@ public final MethodResult getAvailableChemicalStorage() { if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); - return MethodResult.of(RsApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RsApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); + return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RSApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @Override @@ -790,7 +790,7 @@ public final MethodResult getCraftingTasks() { if (!isAvailable()) return notConnected(); - return MethodResult.of(RsApi.getCraftingTasks(bridge)); + return MethodResult.of(RSApi.getCraftingTasks(bridge)); } @Override @@ -845,7 +845,7 @@ public final MethodResult isCraftable(IArguments arguments) throws LuaException GenericFilter parsedFilter = filter.getLeft(); - return MethodResult.of(RsApi.findPatternFromFilters(getNetwork(), null, parsedFilter).leftPresent()); + return MethodResult.of(RSApi.findPatternFromFilters(getNetwork(), null, parsedFilter).leftPresent()); } @Override @@ -881,7 +881,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException // If no table is provided or it's empty, return every pattern Map filterTable = arguments.optTable(0, Collections.emptyMap()); if (filterTable.isEmpty()) { - return MethodResult.of(RsApi.getPatterns(getNetwork())); + return MethodResult.of(RSApi.getPatterns(getNetwork())); } boolean hasInputFilter = filterTable.containsKey("input"); @@ -916,11 +916,11 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException outputFilter = parsedFilter.getLeft(); } - Pair pattern = RsApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); + Pair pattern = RSApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); if (pattern.rightPresent()) return MethodResult.of(null, pattern.getRight()); - return MethodResult.of(RsApi.parsePattern(pattern.getLeft())); + return MethodResult.of(RSApi.parsePattern(pattern.getLeft())); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java similarity index 99% rename from src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index a88d7e889..982597c95 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -61,7 +61,7 @@ /** * Refined Storage Api helper methods and parsers */ -public class RsApi { +public class RSApi { public static void registerCapabilities(@NotNull RegisterCapabilitiesEvent event) { event.registerBlockEntity( @@ -604,7 +604,7 @@ public static Object parsePattern(Pattern pattern) { return null; Map propeties = new HashMap<>(); - propeties.put("outputs", pattern.layout().outputs().stream().map(RsApi::getObjectFromResourceAmount).toList()); + propeties.put("outputs", pattern.layout().outputs().stream().map(RSApi::getObjectFromResourceAmount).toList()); List>> inputs = pattern.layout().ingredients().stream() .map(ingredient -> ingredient.inputs().stream() diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java similarity index 92% rename from src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java index 2f0a452aa..b73ce8d85 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsChemicalHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java @@ -12,13 +12,13 @@ import mekanism.api.chemical.ChemicalStack; import org.jetbrains.annotations.NotNull; -public class RsChemicalHandler implements IStorageSystemChemicalHandler { +public class RSChemicalHandler implements IStorageSystemChemicalHandler { @NotNull private final Network network; private final StorageNetworkComponent component; - public RsChemicalHandler(@NotNull Network network) { + public RSChemicalHandler(@NotNull Network network) { this.network = network; this.component = network.getComponent(StorageNetworkComponent.class); } @@ -38,7 +38,7 @@ public ChemicalStack insertChemical(int tank, ChemicalStack resource, @NotNull m @Override public ChemicalStack extractChemical(ChemicalFilter filter, long count, mekanism.api.Action simulate) { AdvancedPeripherals.debug("Trying to extract chemical from filter: " + filter); - ChemicalResource chemical = RsApi.getChemical(network, filter); + ChemicalResource chemical = RSApi.getChemical(network, filter); if (chemical == null) return ChemicalStack.EMPTY; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java index b1bcea435..f0ef889d7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSCraftJob.java @@ -47,7 +47,7 @@ protected boolean isJobCanceled() { @Override public Object getParsedRequestedItemImpl() { - return RsApi.getObjectFromResourceKey(toCraft, amount); + return RSApi.getObjectFromResourceKey(toCraft, amount); } @Override @@ -78,7 +78,7 @@ public Object getEmittedItemsImpl() { return Collections.emptyList(); } - return preview.items().stream().filter(item -> item.toCraft() > 0).map(item -> RsApi.getObjectFromResourceKey(item.resource(), item.toCraft())).collect(Collectors.toList()); + return preview.items().stream().filter(item -> item.toCraft() > 0).map(item -> RSApi.getObjectFromResourceKey(item.resource(), item.toCraft())).collect(Collectors.toList()); } @Override @@ -93,7 +93,7 @@ public Object getMissingItemsImpl() { return Collections.emptyList(); } - return preview.items().stream().filter(item -> item.missing() > 0).map(item -> RsApi.getObjectFromResourceKey(item.resource(), item.missing())).collect(Collectors.toList()); + return preview.items().stream().filter(item -> item.missing() > 0).map(item -> RSApi.getObjectFromResourceKey(item.resource(), item.missing())).collect(Collectors.toList()); } @Override @@ -108,7 +108,7 @@ public Object getFinalOutputImpl() { return Collections.emptyList(); } - return preview.outputsOfPatternWithCycle().stream().map(RsApi::getObjectFromResourceAmount).collect(Collectors.toList()); + return preview.outputsOfPatternWithCycle().stream().map(RSApi::getObjectFromResourceAmount).collect(Collectors.toList()); } public TaskStatus getCraftingTask() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java similarity index 91% rename from src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java index 28def8240..102d801a5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java @@ -12,13 +12,13 @@ import net.neoforged.neoforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; -public class RsFluidHandler implements IStorageSystemFluidHandler { +public class RSFluidHandler implements IStorageSystemFluidHandler { @NotNull private final Network network; private final StorageNetworkComponent component; - public RsFluidHandler(@NotNull Network network) { + public RSFluidHandler(@NotNull Network network) { this.network = network; this.component = network.getComponent(StorageNetworkComponent.class); @@ -36,7 +36,7 @@ public int fill(FluidStack resource, @NotNull FluidAction action) { @Override public FluidStack drain(FluidFilter filter, FluidAction simulate) { AdvancedPeripherals.debug("Trying to extract fluid from filter: " + filter); - FluidResource fluid = RsApi.getFluid(network, filter); + FluidResource fluid = RSApi.getFluid(network, filter); if (fluid == null) return FluidStack.EMPTY; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSItemHandler.java similarity index 92% rename from src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java rename to src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSItemHandler.java index 4b6a1e1b2..bf9b9d7d6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RsItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSItemHandler.java @@ -16,13 +16,13 @@ * * @see de.srendi.advancedperipherals.common.addons.computercraft.peripheral.RSBridgePeripheral */ -public class RsItemHandler implements IStorageSystemItemHandler { +public class RSItemHandler implements IStorageSystemItemHandler { @NotNull private final Network network; private final StorageNetworkComponent component; - public RsItemHandler(@NotNull Network network) { + public RSItemHandler(@NotNull Network network) { this.network = network; this.component = network.getComponent(StorageNetworkComponent.class); } @@ -39,7 +39,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate @Override public ItemStack extractItem(ItemFilter filter, int count, boolean simulate) { AdvancedPeripherals.debug("Trying to extract item from filter: " + filter); - ItemResource itemResource = RsApi.getItem(network, filter); + ItemResource itemResource = RSApi.getItem(network, filter); if (itemResource == null) return ItemStack.EMPTY; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java index 0a573c45e..26d2f97b0 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalFilter.java @@ -7,7 +7,7 @@ import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.common.addons.APAddons; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RsApi; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSApi; import de.srendi.advancedperipherals.common.util.Pair; import mekanism.api.MekanismAPI; import mekanism.api.chemical.Chemical; @@ -108,7 +108,7 @@ public boolean testRS(ResourceAmount resourceAmount) { if (!APAddons.mekanismLoaded || !APAddons.refinedStorageLoaded || !APAddons.refinedStorageMekanismLoaded) return false; if (resourceAmount.resource() instanceof ChemicalResource chemicalResource) { - return test(RsApi.resourceToChemicalStack(chemicalResource)); + return test(RSApi.resourceToChemicalStack(chemicalResource)); } return false; } From 4b0e9eb1f5a5b3d08b0ca255df9ad03290e180c2 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 25 Apr 2025 23:00:33 +0200 Subject: [PATCH 75/91] Bump CC to fix a runtime bug --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 33db36b5f..02593d2b1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ kotlinx_coroutines_version=1.6.0-RC3 ttoolkit_version=0.1.3 # Mod dependencies -cc_version=1.113.1 +cc_version=1.115.1 ae2things_version=5637783 appliedenergistics_version=19.1.2-beta From 0d93afa17b1f82f2ee36f32bddc541ddf80b52c7 Mon Sep 17 00:00:00 2001 From: Srendi Date: Fri, 25 Apr 2025 23:12:12 +0200 Subject: [PATCH 76/91] Add a custom default to the notConnected helper method. And changed every "error" return value to a specific default value depending on the function: Functions that return a number return 0. Functions that return a collection return a final read only list. Functions that return a boolean return false. Functions that return an object return null. --- .../peripheral/RSBridgePeripheral.java | 137 +++++++++--------- 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index b5e0c04a3..04206e182 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -19,9 +19,9 @@ import dan200.computercraft.core.apis.TableHelper; import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner; -import de.srendi.advancedperipherals.common.addons.refinedstorage.RSCraftJob; import de.srendi.advancedperipherals.common.addons.refinedstorage.RSApi; import de.srendi.advancedperipherals.common.addons.refinedstorage.RSChemicalHandler; +import de.srendi.advancedperipherals.common.addons.refinedstorage.RSCraftJob; import de.srendi.advancedperipherals.common.addons.refinedstorage.RSFluidHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RSItemHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsStorageTypes; @@ -72,8 +72,8 @@ private Network getNetwork() { return getNode().getNetwork(); } - private MethodResult notConnected() { - return MethodResult.of(null, "NOT_CONNECTED"); + private MethodResult notConnected(Object defaultValue) { + return MethodResult.of(defaultValue, "NOT_CONNECTED"); } private I getComponent(@NotNull Class componentClass) { @@ -214,7 +214,7 @@ public final boolean isConnected() { @LuaFunction(mainThread = true) public final MethodResult isOnline() { if (!isAvailable()) - return notConnected(); + return notConnected(false); return MethodResult.of(getComponent(EnergyNetworkComponent.class).getStored() > 0); } @@ -223,7 +223,7 @@ public final MethodResult isOnline() { @LuaFunction(mainThread = true) public final MethodResult getItem(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(null); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -244,7 +244,7 @@ public final MethodResult getItem(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final MethodResult getFluid(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(null); Pair filter = FluidFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -265,7 +265,7 @@ public final MethodResult getFluid(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final MethodResult getChemical(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(null); Pair filter = ChemicalFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -286,11 +286,11 @@ public final MethodResult getChemical(IArguments arguments) throws LuaException @LuaFunction(mainThread = true) public final MethodResult listItems(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); Pair filter = ItemFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(Collections.emptyList(), filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); @@ -303,11 +303,11 @@ public final MethodResult listItems(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final MethodResult listFluids(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); Pair filter = FluidFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(Collections.emptyList(), filter.getRight()); FluidFilter parsedFilter = filter.getLeft(); @@ -320,11 +320,11 @@ public final MethodResult listFluids(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final MethodResult listChemicals(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(Collections.emptyList(), filter.getRight()); ChemicalFilter parsedFilter = filter.getLeft(); @@ -337,11 +337,11 @@ public final MethodResult listChemicals(IArguments arguments) throws LuaExceptio @LuaFunction(mainThread = true) public final MethodResult listCraftableItems(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); Pair filter = ItemFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(Collections.emptyList(), filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); @@ -354,11 +354,11 @@ public final MethodResult listCraftableItems(IArguments arguments) throws LuaExc @LuaFunction(mainThread = true) public final MethodResult listCraftableFluids(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); Pair filter = FluidFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(Collections.emptyList(), filter.getRight()); FluidFilter parsedFilter = filter.getLeft(); @@ -371,14 +371,14 @@ public final MethodResult listCraftableFluids(IArguments arguments) throws LuaEx @LuaFunction(mainThread = true) public final MethodResult listCraftableChemicals(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(Collections.emptyList()); Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(Collections.emptyList(), filter.getRight()); ChemicalFilter parsedFilter = filter.getLeft(); @@ -391,7 +391,7 @@ public final MethodResult listCraftableChemicals(IArguments arguments) throws Lu @LuaFunction(mainThread = true) public final MethodResult listCells() { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); return MethodResult.of(RSApi.listCells(getNetwork())); } @@ -400,7 +400,7 @@ public final MethodResult listCells() { @LuaFunction(mainThread = true) public final MethodResult listDrives() { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); return MethodResult.of(RSApi.listDrives(getNetwork())); } @@ -409,7 +409,7 @@ public final MethodResult listDrives() { @LuaFunction(mainThread = true) public final MethodResult importItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(0); IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); @@ -427,7 +427,7 @@ public final MethodResult importItem(IComputerAccess computer, IArguments argume @LuaFunction(mainThread = true) public final MethodResult exportItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(0); IItemHandler inventory = InventoryUtil.getHandlerFromDirection(arguments.getString(1), owner); @@ -445,7 +445,7 @@ public final MethodResult exportItem(IComputerAccess computer, IArguments argume @LuaFunction(mainThread = true) public final MethodResult importFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(0); IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); if (handler == null) { @@ -462,7 +462,7 @@ public final MethodResult importFluid(IComputerAccess computer, IArguments argum @LuaFunction(mainThread = true) public final MethodResult exportFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(0); IFluidHandler handler = FluidUtil.getHandlerFromDirection(arguments.getString(1), owner); if (handler == null) { @@ -479,10 +479,10 @@ public final MethodResult exportFluid(IComputerAccess computer, IArguments argum @LuaFunction(mainThread = true) public final MethodResult importChemical(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(0); IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); if (handler == null) { @@ -499,10 +499,10 @@ public final MethodResult importChemical(IComputerAccess computer, IArguments ar @LuaFunction(mainThread = true) public final MethodResult exportChemical(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(0); IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); if (handler == null) { @@ -519,7 +519,7 @@ public final MethodResult exportChemical(IComputerAccess computer, IArguments ar @LuaFunction(mainThread = true) public final MethodResult getStoredEnergy() { if (!isAvailable()) - return notConnected(); + return notConnected(0); EnergyNetworkComponent energyComponent = getNetwork().getComponent(EnergyNetworkComponent.class); @@ -530,7 +530,7 @@ public final MethodResult getStoredEnergy() { @LuaFunction(mainThread = true) public final MethodResult getEnergyCapacity() { if (!isAvailable()) - return notConnected(); + return notConnected(0); EnergyNetworkComponent energyComponent = getNetwork().getComponent(EnergyNetworkComponent.class); @@ -541,7 +541,7 @@ public final MethodResult getEnergyCapacity() { @LuaFunction(mainThread = true) public final MethodResult getEnergyUsage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getEnergyUsage(getNetwork())); } @@ -550,7 +550,7 @@ public final MethodResult getEnergyUsage() { @LuaFunction(mainThread = true) public final MethodResult getAverageEnergyInput() { if (!isAvailable()) - return notConnected(); + return notConnected(0); // Not supported for Refined Storage return MethodResult.of(0); @@ -560,7 +560,7 @@ public final MethodResult getAverageEnergyInput() { @LuaFunction(mainThread = true) public final MethodResult getTotalExternalItemStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @@ -569,7 +569,7 @@ public final MethodResult getTotalExternalItemStorage() { @LuaFunction(mainThread = true) public final MethodResult getTotalExternalFluidStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @@ -578,7 +578,7 @@ public final MethodResult getTotalExternalFluidStorage() { @LuaFunction(mainThread = true) public final MethodResult getTotalExternalChemicalStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); @@ -590,7 +590,7 @@ public final MethodResult getTotalExternalChemicalStorage() { @LuaFunction(mainThread = true) public final MethodResult getTotalItemStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.ITEM)); } @@ -599,7 +599,7 @@ public final MethodResult getTotalItemStorage() { @LuaFunction(mainThread = true) public final MethodResult getTotalFluidStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.FLUID)); } @@ -608,7 +608,7 @@ public final MethodResult getTotalFluidStorage() { @LuaFunction(mainThread = true) public final MethodResult getTotalChemicalStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); @@ -620,7 +620,7 @@ public final MethodResult getTotalChemicalStorage() { @LuaFunction(mainThread = true) public final MethodResult getUsedExternalItemStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @@ -629,7 +629,7 @@ public final MethodResult getUsedExternalItemStorage() { @LuaFunction(mainThread = true) public final MethodResult getUsedExternalFluidStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @@ -638,7 +638,7 @@ public final MethodResult getUsedExternalFluidStorage() { @LuaFunction(mainThread = true) public final MethodResult getUsedExternalChemicalStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); @@ -650,7 +650,7 @@ public final MethodResult getUsedExternalChemicalStorage() { @LuaFunction(mainThread = true) public final MethodResult getUsedItemStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getUsedStorage(getNetwork(), RsStorageTypes.ITEM)); } @@ -659,7 +659,7 @@ public final MethodResult getUsedItemStorage() { @LuaFunction(mainThread = true) public final MethodResult getUsedFluidStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getUsedStorage(getNetwork(), RsStorageTypes.FLUID)); } @@ -668,7 +668,7 @@ public final MethodResult getUsedFluidStorage() { @LuaFunction(mainThread = true) public final MethodResult getUsedChemicalStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); @@ -680,7 +680,7 @@ public final MethodResult getUsedChemicalStorage() { @LuaFunction(mainThread = true) public final MethodResult getAvailableExternalItemStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.ITEM) - RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.ITEM)); } @@ -689,7 +689,7 @@ public final MethodResult getAvailableExternalItemStorage() { @LuaFunction(mainThread = true) public final MethodResult getAvailableExternalFluidStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.FLUID) - RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.FLUID)); } @@ -698,7 +698,7 @@ public final MethodResult getAvailableExternalFluidStorage() { @LuaFunction(mainThread = true) public final MethodResult getAvailableExternalChemicalStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); @@ -710,7 +710,7 @@ public final MethodResult getAvailableExternalChemicalStorage() { @LuaFunction(mainThread = true) public final MethodResult getAvailableItemStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.ITEM) - RSApi.getUsedStorage(getNetwork(), RsStorageTypes.ITEM)); } @@ -719,7 +719,7 @@ public final MethodResult getAvailableItemStorage() { @LuaFunction(mainThread = true) public final MethodResult getAvailableFluidStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.FLUID) - RSApi.getUsedStorage(getNetwork(), RsStorageTypes.FLUID)); } @@ -728,7 +728,7 @@ public final MethodResult getAvailableFluidStorage() { @LuaFunction(mainThread = true) public final MethodResult getAvailableChemicalStorage() { if (!isAvailable()) - return notConnected(); + return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) return MethodResult.of(0); @@ -740,7 +740,7 @@ public final MethodResult getAvailableChemicalStorage() { @LuaFunction(mainThread = true) public final MethodResult craftItem(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(null); Pair filter = ItemFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -755,7 +755,7 @@ public final MethodResult craftItem(IComputerAccess computer, IArguments argumen @LuaFunction(mainThread = true) public final MethodResult craftFluid(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(null); Pair filter = FluidFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -770,10 +770,10 @@ public final MethodResult craftFluid(IComputerAccess computer, IArguments argume @LuaFunction(mainThread = true) public final MethodResult craftChemical(IComputerAccess computer, IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(null); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(null); Pair filter = ChemicalFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) @@ -788,7 +788,7 @@ public final MethodResult craftChemical(IComputerAccess computer, IArguments arg @LuaFunction(mainThread = true) public final MethodResult getCraftingTasks() { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); return MethodResult.of(RSApi.getCraftingTasks(bridge)); } @@ -797,7 +797,7 @@ public final MethodResult getCraftingTasks() { @LuaFunction(mainThread = true) public final MethodResult getCraftingTask(int id) { if (!isAvailable()) - return notConnected(); + return notConnected(null); for (RSCraftJob job : bridge.getJobs()) { if (job.getId() == id) { @@ -811,11 +811,11 @@ public final MethodResult getCraftingTask(int id) { @LuaFunction(mainThread = true) public final MethodResult cancelCraftingTasks(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(0); Pair, String> filter = GenericFilter.parseGeneric(arguments.getTable(0)); if (filter.getRight() != null) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(0, filter.getRight()); GenericFilter parsedFilter = filter.getLeft(); @@ -832,16 +832,15 @@ public final MethodResult cancelCraftingTasks(IArguments arguments) throws LuaEx return MethodResult.of(canceled); } - @Override @LuaFunction(mainThread = true) public final MethodResult isCraftable(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(false); Pair, String> filter = GenericFilter.parseGeneric(arguments.getTable(0)); if (filter.getRight() != null) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(false, filter.getRight()); GenericFilter parsedFilter = filter.getLeft(); @@ -852,11 +851,11 @@ public final MethodResult isCraftable(IArguments arguments) throws LuaException @LuaFunction(mainThread = true) public final MethodResult isCrafting(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(false); Pair, String> filter = GenericFilter.parseGeneric(arguments.getTable(0)); if (filter.getRight() != null) - return MethodResult.of(null, filter.getRight()); + return MethodResult.of(false, filter.getRight()); GenericFilter parsedFilter = filter.getLeft(); @@ -875,7 +874,7 @@ public final MethodResult isCrafting(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final MethodResult getPatterns(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(); + return notConnected(Collections.emptyList()); // Expected input is a table with either an input table, an output table or both to filter for both // If no table is provided or it's empty, return every pattern @@ -890,7 +889,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException // If the player tries to filter for nothing, return nothing. if (!hasAnyFilter) - return MethodResult.of(null, "NO_FILTER"); + return MethodResult.of(Collections.emptyList(), "NO_FILTER"); GenericFilter inputFilter = null; GenericFilter outputFilter = null; @@ -901,7 +900,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException Pair, String> parsedFilter = GenericFilter.parseGeneric(inputFilterTable); if (parsedFilter.rightPresent()) - return MethodResult.of(null, parsedFilter.getRight()); + return MethodResult.of(Collections.emptyList(), parsedFilter.getRight()); inputFilter = parsedFilter.getLeft(); } @@ -911,7 +910,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException Pair, String> parsedFilter = GenericFilter.parseGeneric(outputFilterTable); if (parsedFilter.rightPresent()) - return MethodResult.of(null, parsedFilter.getRight()); + return MethodResult.of(Collections.emptyList(), parsedFilter.getRight()); outputFilter = parsedFilter.getLeft(); } @@ -919,7 +918,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException Pair pattern = RSApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); if (pattern.rightPresent()) - return MethodResult.of(null, pattern.getRight()); + return MethodResult.of(Collections.emptyList(), pattern.getRight()); return MethodResult.of(RSApi.parsePattern(pattern.getLeft())); } From 9fcfa81e7b0b3f5b4d9ab6a7690faff5ec38b5e0 Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 27 Apr 2025 03:02:40 +0200 Subject: [PATCH 77/91] Use null as a default return type for collections --- .../peripheral/RSBridgePeripheral.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 04206e182..6c5eff1dc 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -286,11 +286,11 @@ public final MethodResult getChemical(IArguments arguments) throws LuaException @LuaFunction(mainThread = true) public final MethodResult listItems(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); Pair filter = ItemFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(Collections.emptyList(), filter.getRight()); + return MethodResult.of(null, filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); @@ -303,11 +303,11 @@ public final MethodResult listItems(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final MethodResult listFluids(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); Pair filter = FluidFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(Collections.emptyList(), filter.getRight()); + return MethodResult.of(null, filter.getRight()); FluidFilter parsedFilter = filter.getLeft(); @@ -320,11 +320,11 @@ public final MethodResult listFluids(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final MethodResult listChemicals(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(Collections.emptyList(), filter.getRight()); + return MethodResult.of(null, filter.getRight()); ChemicalFilter parsedFilter = filter.getLeft(); @@ -337,11 +337,11 @@ public final MethodResult listChemicals(IArguments arguments) throws LuaExceptio @LuaFunction(mainThread = true) public final MethodResult listCraftableItems(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); Pair filter = ItemFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(Collections.emptyList(), filter.getRight()); + return MethodResult.of(null, filter.getRight()); ItemFilter parsedFilter = filter.getLeft(); @@ -354,11 +354,11 @@ public final MethodResult listCraftableItems(IArguments arguments) throws LuaExc @LuaFunction(mainThread = true) public final MethodResult listCraftableFluids(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); Pair filter = FluidFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(Collections.emptyList(), filter.getRight()); + return MethodResult.of(null, filter.getRight()); FluidFilter parsedFilter = filter.getLeft(); @@ -371,14 +371,14 @@ public final MethodResult listCraftableFluids(IArguments arguments) throws LuaEx @LuaFunction(mainThread = true) public final MethodResult listCraftableChemicals(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(Collections.emptyList()); + return MethodResult.of(null); Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) - return MethodResult.of(Collections.emptyList(), filter.getRight()); + return MethodResult.of(null, filter.getRight()); ChemicalFilter parsedFilter = filter.getLeft(); @@ -391,7 +391,7 @@ public final MethodResult listCraftableChemicals(IArguments arguments) throws Lu @LuaFunction(mainThread = true) public final MethodResult listCells() { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); return MethodResult.of(RSApi.listCells(getNetwork())); } @@ -400,7 +400,7 @@ public final MethodResult listCells() { @LuaFunction(mainThread = true) public final MethodResult listDrives() { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); return MethodResult.of(RSApi.listDrives(getNetwork())); } @@ -788,7 +788,7 @@ public final MethodResult craftChemical(IComputerAccess computer, IArguments arg @LuaFunction(mainThread = true) public final MethodResult getCraftingTasks() { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); return MethodResult.of(RSApi.getCraftingTasks(bridge)); } @@ -874,7 +874,7 @@ public final MethodResult isCrafting(IArguments arguments) throws LuaException { @LuaFunction(mainThread = true) public final MethodResult getPatterns(IArguments arguments) throws LuaException { if (!isAvailable()) - return notConnected(Collections.emptyList()); + return notConnected(null); // Expected input is a table with either an input table, an output table or both to filter for both // If no table is provided or it's empty, return every pattern @@ -889,7 +889,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException // If the player tries to filter for nothing, return nothing. if (!hasAnyFilter) - return MethodResult.of(Collections.emptyList(), "NO_FILTER"); + return MethodResult.of(null, "NO_FILTER"); GenericFilter inputFilter = null; GenericFilter outputFilter = null; @@ -900,7 +900,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException Pair, String> parsedFilter = GenericFilter.parseGeneric(inputFilterTable); if (parsedFilter.rightPresent()) - return MethodResult.of(Collections.emptyList(), parsedFilter.getRight()); + return MethodResult.of(null, parsedFilter.getRight()); inputFilter = parsedFilter.getLeft(); } @@ -910,7 +910,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException Pair, String> parsedFilter = GenericFilter.parseGeneric(outputFilterTable); if (parsedFilter.rightPresent()) - return MethodResult.of(Collections.emptyList(), parsedFilter.getRight()); + return MethodResult.of(null, parsedFilter.getRight()); outputFilter = parsedFilter.getLeft(); } @@ -918,7 +918,7 @@ public final MethodResult getPatterns(IArguments arguments) throws LuaException Pair pattern = RSApi.findPatternFromFilters(getNetwork(), inputFilter, outputFilter); if (pattern.rightPresent()) - return MethodResult.of(Collections.emptyList(), pattern.getRight()); + return MethodResult.of(null, pattern.getRight()); return MethodResult.of(RSApi.parsePattern(pattern.getLeft())); } From 78cb6080f204badddf2f32219d5c0b537baeb845 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 28 Apr 2025 21:26:41 +0200 Subject: [PATCH 78/91] RsBridgeEntity -> RSBridgeEntity --- .../computercraft/peripheral/RSBridgePeripheral.java | 8 ++++---- .../common/addons/refinedstorage/RSApi.java | 4 ++-- .../{RsBridgeEntity.java => RSBridgeEntity.java} | 4 ++-- .../common/setup/BlockEntityTypes.java | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) rename src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/{RsBridgeEntity.java => RSBridgeEntity.java} (97%) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 6c5eff1dc..33def5519 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -25,7 +25,7 @@ import de.srendi.advancedperipherals.common.addons.refinedstorage.RSFluidHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RSItemHandler; import de.srendi.advancedperipherals.common.addons.refinedstorage.RsStorageTypes; -import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.RSBridgeEntity; import de.srendi.advancedperipherals.common.configuration.APConfig; import de.srendi.advancedperipherals.common.util.Pair; import de.srendi.advancedperipherals.common.util.StatusConstants; @@ -48,13 +48,13 @@ import java.util.Map; import java.util.Set; -public class RSBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { +public class RSBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { public static final String PERIPHERAL_TYPE = "rsBridge"; - private final RsBridgeEntity bridge; + private final RSBridgeEntity bridge; - public RSBridgePeripheral(RsBridgeEntity owner) { + public RSBridgePeripheral(RSBridgeEntity owner) { super(PERIPHERAL_TYPE, new BlockEntityPeripheralOwner<>(owner)); this.bridge = owner; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index 982597c95..4ff5a8296 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -29,7 +29,7 @@ import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; -import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.RSBridgeEntity; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.common.util.LuaConverter; import de.srendi.advancedperipherals.common.util.Pair; @@ -469,7 +469,7 @@ public static long getUsedExternalStorage(Network network, RsStorageTypes type) return used; } - public static List getCraftingTasks(RsBridgeEntity entity) { + public static List getCraftingTasks(RSBridgeEntity entity) { List tasks = new ArrayList<>(); for (RSCraftJob task : entity.getJobs()) { diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RSBridgeEntity.java similarity index 97% rename from src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java rename to src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RSBridgeEntity.java index 91bff4567..1043bc7b8 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RsBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RSBridgeEntity.java @@ -31,7 +31,7 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; -public class RsBridgeEntity extends PeripheralBlockEntity implements IPeripheralTileEntity, NetworkNodeContainerProvider, TaskStatusListener { +public class RSBridgeEntity extends PeripheralBlockEntity implements IPeripheralTileEntity, NetworkNodeContainerProvider, TaskStatusListener { protected CompoundTag peripheralSettings; private final NetworkNode node; @@ -39,7 +39,7 @@ public class RsBridgeEntity extends PeripheralBlockEntity im private final List jobs = new CopyOnWriteArrayList<>(); private boolean addedListener = false; - public RsBridgeEntity(BlockPos pos, BlockState state) { + public RSBridgeEntity(BlockPos pos, BlockState state) { super(BlockEntityTypes.RS_BRIDGE.get(), pos, state); peripheralSettings = new CompoundTag(); ConnectionStrategy connectionStrategy = new SimpleConnectionStrategy(pos); diff --git a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java index f69fbcf33..4f9dc859e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java +++ b/src/main/java/de/srendi/advancedperipherals/common/setup/BlockEntityTypes.java @@ -13,7 +13,7 @@ import de.srendi.advancedperipherals.common.blocks.blockentities.NBTStorageEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.PlayerDetectorEntity; import de.srendi.advancedperipherals.common.blocks.blockentities.RedstoneIntegratorEntity; -import de.srendi.advancedperipherals.common.blocks.blockentities.RsBridgeEntity; +import de.srendi.advancedperipherals.common.blocks.blockentities.RSBridgeEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.neoforged.neoforge.registries.DeferredHolder; @@ -23,7 +23,7 @@ public class BlockEntityTypes { public static final DeferredHolder, BlockEntityType> ENVIRONMENT_DETECTOR = Registration.BLOCK_ENTITIES.register("environment_detector", () -> new BlockEntityType<>(EnvironmentDetectorEntity::new, Sets.newHashSet(Blocks.ENVIRONMENT_DETECTOR.get()), null)); public static final DeferredHolder, BlockEntityType> PLAYER_DETECTOR = Registration.BLOCK_ENTITIES.register("player_detector", () -> new BlockEntityType<>(PlayerDetectorEntity::new, Sets.newHashSet(Blocks.PLAYER_DETECTOR.get()), null)); public static final DeferredHolder, BlockEntityType> ME_BRIDGE = APAddons.ae2Loaded ? Registration.BLOCK_ENTITIES.register("me_bridge", () -> new BlockEntityType<>(MEBridgeEntity::new, Sets.newHashSet(Blocks.ME_BRIDGE.get()), null)) : null; - public static final DeferredHolder, BlockEntityType> RS_BRIDGE = APAddons.refinedStorageLoaded ? Registration.BLOCK_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RsBridgeEntity::new, Sets.newHashSet(Blocks.RS_BRIDGE.get()), null)) : null; + public static final DeferredHolder, BlockEntityType> RS_BRIDGE = APAddons.refinedStorageLoaded ? Registration.BLOCK_ENTITIES.register("rs_bridge", () -> new BlockEntityType<>(RSBridgeEntity::new, Sets.newHashSet(Blocks.RS_BRIDGE.get()), null)) : null; public static final DeferredHolder, BlockEntityType> ENERGY_DETECTOR = Registration.BLOCK_ENTITIES.register("energy_detector", () -> new BlockEntityType<>(EnergyDetectorEntity::new, Sets.newHashSet(Blocks.ENERGY_DETECTOR.get()), null)); public static final DeferredHolder, BlockEntityType> INVENTORY_MANAGER = Registration.BLOCK_ENTITIES.register("inventory_manager", () -> new BlockEntityType<>(InventoryManagerEntity::new, Sets.newHashSet(Blocks.INVENTORY_MANAGER.get()), null)); public static final DeferredHolder, BlockEntityType> REDSTONE_INTEGRATOR = Registration.BLOCK_ENTITIES.register("redstone_integrator", () -> new BlockEntityType<>(RedstoneIntegratorEntity::new, Sets.newHashSet(Blocks.REDSTONE_INTEGRATOR.get()), null)); From 4a3ba977e3cd08f124046fad18a54e03e60a47ce Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 28 Apr 2025 21:28:02 +0200 Subject: [PATCH 79/91] Chain stream filters in RSBridgeEntity for craft jobs --- .../common/blocks/blockentities/RSBridgeEntity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RSBridgeEntity.java b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RSBridgeEntity.java index 1043bc7b8..b2385707e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RSBridgeEntity.java +++ b/src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/RSBridgeEntity.java @@ -114,16 +114,16 @@ public boolean canBuild(@NotNull ServerPlayer serverPlayer) { @Override public void taskStatusChanged(@NotNull TaskStatus taskStatus) { - jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); + jobs.stream().filter(BasicCraftJob::isCraftingStarted).filter(job -> job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); } @Override public void taskRemoved(@NotNull TaskId taskId) { - jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskId)).forEach(BasicCraftJob::jobStateChanged); + jobs.stream().filter(BasicCraftJob::isCraftingStarted).filter(job -> job.getCraftingTask().info().id().equals(taskId)).forEach(BasicCraftJob::jobStateChanged); } @Override public void taskAdded(@NotNull TaskStatus taskStatus) { - jobs.stream().filter(job -> job.isCraftingStarted() && job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); + jobs.stream().filter(BasicCraftJob::isCraftingStarted).filter(job -> job.getCraftingTask().info().id().equals(taskStatus.info().id())).forEach(BasicCraftJob::jobStateChanged); } } From 6ee5474012580cc930c481f7296c8fc589a07fba Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 28 Apr 2025 21:29:15 +0200 Subject: [PATCH 80/91] fluid -> chemical in ChemicalUtil.java --- .../common/util/inventory/ChemicalUtil.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java index da43b5c6c..4cb2bf72c 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/inventory/ChemicalUtil.java @@ -99,7 +99,7 @@ public static IChemicalHandler getHandlerFromName(@NotNull IComputerAccess acces IChemicalHandler handler = extractHandler(location.getTarget(), null, null, null); if (handler == null) - throw new LuaException("Target '" + name + "' is not a fluid handler"); + throw new LuaException("Target '" + name + "' is not a chemical handler"); return handler; } @@ -121,11 +121,11 @@ public static String getFingerprint(@NotNull ChemicalStack stack) { return ""; } - public static ResourceLocation getRegistryKey(Chemical fluid) { - return MekanismAPI.CHEMICAL_REGISTRY.getKey(fluid); + public static ResourceLocation getRegistryKey(Chemical chemical) { + return MekanismAPI.CHEMICAL_REGISTRY.getKey(chemical); } - public static ResourceLocation getRegistryKey(ChemicalStack fluid) { - return MekanismAPI.CHEMICAL_REGISTRY.getKey(fluid.getChemical()); + public static ResourceLocation getRegistryKey(ChemicalStack chemicalStack) { + return MekanismAPI.CHEMICAL_REGISTRY.getKey(chemicalStack.getChemical()); } } From 7d4e6088da96f835ca6d6985bc63c84397dc810b Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 28 Apr 2025 21:30:23 +0200 Subject: [PATCH 81/91] Remove empty line --- .../advancedperipherals/common/addons/refinedstorage/RSApi.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index 4ff5a8296..92737183e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -192,7 +192,6 @@ public static Set> getParsedItems(Network network, ItemFilte for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if (trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { items.add(getObjectFromItemResource(trackedResource.resourceAmount())); - } } return items; From 7a32929a72e37c421711001a1b3a13bf6f3e3b56 Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 28 Apr 2025 21:33:53 +0200 Subject: [PATCH 82/91] Fully upper case loop label --- .../common/addons/refinedstorage/RSApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index 92737183e..2a1aeea36 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -362,12 +362,12 @@ public static Pair findPatternFromFilters(Network network, @Nul boolean outputMatch = false; if (inputFilter != null) { - outerLoop: + OUTERLOOP: for (Ingredient input : pattern.layout().ingredients()) { for (ResourceKey possibleInput : input.inputs()) { if (inputFilter.testRS(new ResourceAmount(possibleInput, 1))) { inputMatch = true; - break outerLoop; + break OUTERLOOP; } } } From e4df39f6acb9aff1883279f5f0199951a442f4bd Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 28 Apr 2025 22:03:33 +0200 Subject: [PATCH 83/91] Implement the actual support for chemical resources and fixed some crashes when the rs mekanism addon is not installed --- .../common/addons/refinedstorage/RSApi.java | 47 ++++++++++++- .../common/util/LuaConverter.java | 66 +++++++++++++++++-- 2 files changed, 106 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index 2a1aeea36..555be56e9 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -29,6 +29,7 @@ import com.refinedmods.refinedstorage.neoforge.api.RefinedStorageNeoForgeApi; import com.refinedmods.refinedstorage.neoforge.support.resource.VariantUtil; import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.blocks.blockentities.RSBridgeEntity; import de.srendi.advancedperipherals.common.setup.BlockEntityTypes; import de.srendi.advancedperipherals.common.util.LuaConverter; @@ -496,13 +497,15 @@ public static Map getObjectFromResourceKey(@NotNull ResourceKey } /** - * Helper method to get a parsed lua resource key. Currently only suppors item and fluid resources + * Helper method to get a parsed lua resource key. * * @param resource the resource * @param count count of the resource - can be 0 and lower * @return the parsed key to a lua properties map */ public static Map getObjectFromResourceKey(@NotNull ResourceKey resource, long count) { + // Resource amounts can't be zero or the client will just crash, + // So we need to check that and set it to one boolean countZeroOrLower = count <= 0; if (resource instanceof ItemResource) { if (countZeroOrLower) { @@ -516,6 +519,12 @@ public static Map getObjectFromResourceKey(@NotNull ResourceKey } return getObjectFromFluidResource(new ResourceAmount(resource, count)); } + if (APAddons.refinedStorageMekanismLoaded && resource instanceof ChemicalResource) { + if (countZeroOrLower) { + return getObjectFromChemicalResource(new ResourceAmount(resource, 1), count); + } + return getObjectFromChemicalResource(new ResourceAmount(resource, count)); + } AdvancedPeripherals.debug("Could not create table from unknown resource " + resource.getClass() + " - Report this to the maintainer of ap", Level.WARN); return Collections.emptyMap(); } @@ -533,6 +542,9 @@ public static Map getObjectFromResourceAmount(@NotNull ResourceA if (resourceAmount.resource() instanceof FluidResource) { return getObjectFromFluidResource(resourceAmount); } + if (APAddons.refinedStorageMekanismLoaded && resourceAmount.resource() instanceof ChemicalResource) { + return getObjectFromChemicalResource(resourceAmount); + } AdvancedPeripherals.debug("Could not create table from unknown resourceAmount " + resourceAmount.getClass() + " - Report this to the maintainer of ap", Level.WARN); return Collections.emptyMap(); } @@ -574,7 +586,7 @@ public static Object parseStorageDisk(StateTrackedStorage disk) { type = "item"; } else if (serializableStorage.getType() == StorageTypes.FLUID) { type = "fluid"; - } else if (serializableStorage.getType() == ChemicalResourceType.STORAGE_TYPE) { + } else if (APAddons.refinedStorageMekanismLoaded && serializableStorage.getType() == ChemicalResourceType.STORAGE_TYPE) { type = "chemical"; } else { type = "unknown"; @@ -676,6 +688,37 @@ public static Map getObjectFromFluidResource(ResourceAmount trac return properties; } + + /** + * Parses an RS TrackedResourceAmount to a lua object + * This method assumes you did an instanceof check before that the {@link ResourceKey} is an {@link ChemicalResource} + * + * @param trackedResourceAmount the tracked resource amount containing a ChemicalResource + * @return a Map containing the properties which CC can parse to a lua table + */ + public static Map getObjectFromChemicalResource(ResourceAmount trackedResourceAmount) { + ChemicalResource resource = (ChemicalResource) trackedResourceAmount.resource(); + long count = trackedResourceAmount.amount(); + ChemicalStack stack = resourceToChemicalStack(resource, count); + Map properties = LuaConverter.chemicalStackToObject(stack, count); + properties.put("fingerprint", ChemicalUtil.getFingerprint(stack)); + return properties; + } + + /** + * Parses an RS TrackedResourceAmount to a lua object + * This method assumes you did an instanceof check before that the {@link ResourceKey} is an {@link ChemicalResource} + * + * @param trackedResourceAmount the tracked resource amount containing a ChemicalResource + * @param alternateCount a count can be passed to overwrite the count of the object. Useful for patterns and craftable stacks + * @return a Map containing the properties which CC can parse to a lua table + */ + public static Map getObjectFromChemicalResource(ResourceAmount trackedResourceAmount, long alternateCount) { + Map properties = getObjectFromChemicalResource(trackedResourceAmount); + properties.put("count", alternateCount); + return properties; + } + public static ChemicalStack resourceToChemicalStack(ResourceAmount resourceAmount) { if (resourceAmount.resource() instanceof ChemicalResource chemicalResource) return new ChemicalStack(MekanismAPI.CHEMICAL_REGISTRY.createIntrusiveHolder(chemicalResource.chemical()), resourceAmount.amount()); diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index 5f73f3ee0..919051fb1 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -2,9 +2,15 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.shared.util.NBTUtil; +import de.srendi.advancedperipherals.common.addons.APAddons; import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.InventoryManagerPeripheral; +import de.srendi.advancedperipherals.common.util.inventory.ChemicalUtil; import de.srendi.advancedperipherals.common.util.inventory.FluidUtil; import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; +import mekanism.api.MekanismAPI; +import mekanism.api.MekanismAPITags; +import mekanism.api.chemical.Chemical; +import mekanism.api.chemical.ChemicalStack; import net.minecraft.core.BlockPos; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.tags.TagKey; @@ -95,7 +101,9 @@ public static Object stateToObject(Comparable blockStateValue) { } public static Object posToObject(BlockPos pos) { - if (pos == null) return null; + if (pos == null) { + return null; + } Map map = new HashMap<>(3); map.put("x", pos.getX()); @@ -132,6 +140,22 @@ public static Map fluidStackToObject(@NotNull FluidStack stack) return map; } + public static Map chemicalStackToObject(@NotNull ChemicalStack stack) { + // In theory should not be called if the addon is not installed, but just to be save + if (!APAddons.refinedStorageMekanismLoaded) { + return null; + } + + if (stack.isEmpty()) { + return null; + } + Map map = chemicalToObject(stack.getChemical()); + map.put("count", stack.getAmount()); + map.put("displayName", stack.getTextComponent().getString()); + map.put("fingerprint", ChemicalUtil.getFingerprint(stack)); + return map; + } + public static Map fluidTypeToObject(FluidType type) { Map map = new HashMap<>(); map.put("viscosity", type.getViscosity()); @@ -148,15 +172,33 @@ public static Map fluidTypeToObject(FluidType type) { } public static Map itemStackToObject(@NotNull ItemStack itemStack, long count) { - if (itemStack.isEmpty()) return Collections.emptyMap(); + if (itemStack.isEmpty()) { + return null; + } Map map = itemStackToObject(itemStack); map.put("count", count); return map; } - public static Map fluidStackToObject(@NotNull FluidStack itemStack, long count) { - if (itemStack.isEmpty()) return Collections.emptyMap(); - Map map = fluidStackToObject(itemStack); + public static Map fluidStackToObject(@NotNull FluidStack fluidStack, long count) { + if (fluidStack.isEmpty()) { + return null; + } + Map map = fluidStackToObject(fluidStack); + map.put("count", count); + return map; + } + + public static Map chemicalStackToObject(@NotNull ChemicalStack chemicalStack, long count) { + // In theory should not be called if the addon is not installed, but just to be save + if (!APAddons.refinedStorageMekanismLoaded) { + return null; + } + + if (chemicalStack.isEmpty()) { + return null; + } + Map map = chemicalStackToObject(chemicalStack); map.put("count", count); return map; } @@ -192,6 +234,20 @@ public static Map fluidToObject(@NotNull Fluid fluid) { return map; } + public static Map chemicalToObject(@NotNull Chemical chemical) { + // In theory should not be called if the addon is not installed, but just to be save + if (!APAddons.refinedStorageMekanismLoaded) { + return null; + } + + Map map = new HashMap<>(); + map.put("tags", tagsToList(() -> MekanismAPI.CHEMICAL_REGISTRY.wrapAsHolder(chemical).tags())); + map.put("isGaseous", MekanismAPI.CHEMICAL_REGISTRY.wrapAsHolder(chemical).is(MekanismAPITags.Chemicals.GASEOUS)); + map.put("radioactivity", chemical.getRadioactivity()); + map.put("name", ChemicalUtil.getRegistryKey(chemical).toString()); + return map; + } + public static List tagsToList(@NotNull Supplier>> tags) { if (tags.get().findAny().isEmpty()) { return Collections.emptyList(); From 8978dfbf58c260992767629b0b179fa66baca8af Mon Sep 17 00:00:00 2001 From: Srendi Date: Mon, 28 Apr 2025 23:52:24 +0200 Subject: [PATCH 84/91] Fixed IllegalStateException when trying to get a holder from the registry, before we created a new holder instead of getting one from the registry --- build.gradle | 2 +- .../common/addons/refinedstorage/RSApi.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index b61039c43..6599f3fe3 100644 --- a/build.gradle +++ b/build.gradle @@ -228,7 +228,7 @@ dependencies { runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorage_version}") compileOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") - // runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") + runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-mekanism-integration:${refinedstorage_mekanism_version}") // Needed for the refined storage mek integration compileOnlyApi("dev.emi:emi-neoforge:${emiVersion}") diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index 555be56e9..079bddb50 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -721,13 +721,13 @@ public static Map getObjectFromChemicalResource(ResourceAmount t public static ChemicalStack resourceToChemicalStack(ResourceAmount resourceAmount) { if (resourceAmount.resource() instanceof ChemicalResource chemicalResource) - return new ChemicalStack(MekanismAPI.CHEMICAL_REGISTRY.createIntrusiveHolder(chemicalResource.chemical()), resourceAmount.amount()); + return new ChemicalStack(MekanismAPI.CHEMICAL_REGISTRY.wrapAsHolder(chemicalResource.chemical()), resourceAmount.amount()); return ChemicalStack.EMPTY; } public static ChemicalStack resourceToChemicalStack(ChemicalResource resource, long alternateCount) { - return new ChemicalStack(MekanismAPI.CHEMICAL_REGISTRY.createIntrusiveHolder(resource.chemical()), alternateCount); + return new ChemicalStack(MekanismAPI.CHEMICAL_REGISTRY.wrapAsHolder(resource.chemical()), alternateCount); } public static ChemicalStack resourceToChemicalStack(ChemicalResource resource) { From f82228cb1747dff1e0a51d491da5a868dc953389 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 29 Apr 2025 02:21:25 +0200 Subject: [PATCH 85/91] Also return crafting tasks that weren't submitted by the Bridge Add a crafted and resource attribute to the crafting task object --- .../peripheral/RSBridgePeripheral.java | 2 +- .../common/addons/refinedstorage/RSApi.java | 62 ++++++++++++++++--- .../common/util/LuaConverter.java | 2 +- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 33def5519..3f03a5443 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -790,7 +790,7 @@ public final MethodResult getCraftingTasks() { if (!isAvailable()) return notConnected(null); - return MethodResult.of(RSApi.getCraftingTasks(bridge)); + return MethodResult.of(RSApi.getCraftingTasks(getNetwork(), bridge)); } @Override diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index 079bddb50..a8c2e29ed 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -21,6 +21,7 @@ import com.refinedmods.refinedstorage.api.storage.composite.CompositeStorage; import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; import com.refinedmods.refinedstorage.common.api.support.network.InWorldNetworkNodeContainer; +import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage.common.storage.StorageTypes; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; @@ -173,7 +174,7 @@ public static Map getParsedChemical(Network network, ChemicalFil StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if (trackedResource.resourceAmount().resource() instanceof ChemicalResource chemicalResource && filter.test(ChemicalUtil.toChemicalStack(chemicalResource.chemical(), trackedResource.resourceAmount().amount()))) { - return getObjectFromItemResource(trackedResource.resourceAmount()); + return getObjectFromChemicalResource(trackedResource.resourceAmount()); } } return null; @@ -469,11 +470,20 @@ public static long getUsedExternalStorage(Network network, RsStorageTypes type) return used; } - public static List getCraftingTasks(RSBridgeEntity entity) { + public static List getCraftingTasks(Network network, RSBridgeEntity entity) { List tasks = new ArrayList<>(); - for (RSCraftJob task : entity.getJobs()) { - tasks.add(parseCraftingTask(task)); + AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); + + OUTERLOOP: + for (TaskStatus status : autocrafting.getStatuses()) { + for (RSCraftJob task : entity.getJobs()) { + if (status.info().id().equals(task.getCraftingTask().info().id())) { + tasks.add(parseCraftingTask(task, status)); + continue OUTERLOOP; + } + } + tasks.add(parseCraftingTask(null, status)); } return tasks; @@ -549,6 +559,40 @@ public static Map getObjectFromResourceAmount(@NotNull ResourceA return Collections.emptyMap(); } + /** + * Tries to compare two resources + * + * @return true if the registry key of the resources matches + */ + public static boolean isSameResource(ResourceKey resource, ResourceKey toCompare) { + if (resource == null || toCompare == null) { + return false; + } + + // If the resource types do not match, return false early + if (resource instanceof PlatformResourceKey platformResource && toCompare instanceof PlatformResourceKey toComparePlatformResource) { + if (platformResource.getResourceType() != toComparePlatformResource.getResourceType()) { + return false; + } + } + + if (resource instanceof ItemResource itemResource && toCompare instanceof ItemResource toCompareItemResource) { + return ItemUtil.getRegistryKey(itemResource.item()).equals(ItemUtil.getRegistryKey(toCompareItemResource.item())); + } + + if (resource instanceof FluidResource fluidResource && toCompare instanceof FluidResource toCompareFluidResource) { + return FluidUtil.getRegistryKey(fluidResource.fluid()).equals(FluidUtil.getRegistryKey(toCompareFluidResource.fluid())); + } + + if (APAddons.refinedStorageMekanismLoaded) { + if (resource instanceof ChemicalResource chemicalResource && toCompare instanceof ChemicalResource toCompareChemicalResource) { + return ChemicalUtil.getRegistryKey(chemicalResource.chemical()).equals(ChemicalUtil.getRegistryKey(toCompareChemicalResource.chemical())); + } + } + + return false; + } + public static Object parseDiskDrive(StorageNetworkNode diskDrive, InWorldNetworkNodeContainer nodeContainer) { Map properties = new HashMap<>(); @@ -597,14 +641,16 @@ public static Object parseStorageDisk(StateTrackedStorage disk) { return properties; } - public static Object parseCraftingTask(RSCraftJob task) { + public static Object parseCraftingTask(@Nullable RSCraftJob task, TaskStatus status) { Map properties = new HashMap<>(); - TaskStatus status = task.getCraftingTask(); - - properties.put("bridge_id", task.getId()); + properties.put("bridge_id", task == null ? -1 : task.getId()); properties.put("id", status.info().id().toString()); properties.put("quantity", status.info().amount()); + // The "stored" attribute of the Item does not always work. I guess this is a bug, I at least reported it. + // So currently we just calculate it by subtracting the currently crafting from the requested amount + properties.put("crafted", status.items().stream().filter(item -> isSameResource(item.resource(), status.info().resource())).map(item -> status.info().amount() - item.crafting()).findFirst().orElse(-1L)); + properties.put("resource", getObjectFromResourceKey(status.info().resource(), status.info().amount())); properties.put("completion", status.percentageCompleted()); return properties; diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java index 919051fb1..ed97fd425 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java @@ -181,7 +181,7 @@ public static Map itemStackToObject(@NotNull ItemStack itemStack } public static Map fluidStackToObject(@NotNull FluidStack fluidStack, long count) { - if (fluidStack.isEmpty()) { + if (fluidStack.isEmpty()) { return null; } Map map = fluidStackToObject(fluidStack); From 6c263cfbbaf6949bc2c41b326796b252cc647fdf Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 30 Apr 2025 17:24:07 +0200 Subject: [PATCH 86/91] add debug message to RS mekanism addon specific functions when the addon is not loaded --- .../peripheral/RSBridgePeripheral.java | 26 ++++++++++++------- .../common/util/StatusConstants.java | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 3f03a5443..12bbaa21e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -267,6 +267,9 @@ public final MethodResult getChemical(IArguments arguments) throws LuaException if (!isAvailable()) return notConnected(null); + if (!APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(null, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); + Pair filter = ChemicalFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); @@ -322,6 +325,9 @@ public final MethodResult listChemicals(IArguments arguments) throws LuaExceptio if (!isAvailable()) return notConnected(null); + if (!APAddons.refinedStorageMekanismLoaded) + return MethodResult.of(null, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); + Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) return MethodResult.of(null, filter.getRight()); @@ -374,7 +380,7 @@ public final MethodResult listCraftableChemicals(IArguments arguments) throws Lu return notConnected(null); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(null); + return MethodResult.of(null, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); Pair filter = ChemicalFilter.parse(arguments.optTable(0, Collections.emptyMap())); if (filter.rightPresent()) @@ -482,7 +488,7 @@ public final MethodResult importChemical(IComputerAccess computer, IArguments ar return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(0); + return MethodResult.of(0, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); if (handler == null) { @@ -502,7 +508,7 @@ public final MethodResult exportChemical(IComputerAccess computer, IArguments ar return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(0); + return MethodResult.of(0, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); IChemicalHandler handler = ChemicalUtil.getHandlerFromDirection(arguments.getString(1), owner); if (handler == null) { @@ -581,7 +587,7 @@ public final MethodResult getTotalExternalChemicalStorage() { return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(0); + return MethodResult.of(0, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -611,7 +617,7 @@ public final MethodResult getTotalChemicalStorage() { return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(0); + return MethodResult.of(0, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -641,7 +647,7 @@ public final MethodResult getUsedExternalChemicalStorage() { return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(0); + return MethodResult.of(0, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); return MethodResult.of(RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -671,7 +677,7 @@ public final MethodResult getUsedChemicalStorage() { return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(0); + return MethodResult.of(0, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); return MethodResult.of(RSApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -701,7 +707,7 @@ public final MethodResult getAvailableExternalChemicalStorage() { return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(0); + return MethodResult.of(0, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); return MethodResult.of(RSApi.getTotalExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RSApi.getUsedExternalStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -731,7 +737,7 @@ public final MethodResult getAvailableChemicalStorage() { return notConnected(0); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(0); + return MethodResult.of(0, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); return MethodResult.of(RSApi.getTotalStorage(getNetwork(), RsStorageTypes.CHEMICAL) - RSApi.getUsedStorage(getNetwork(), RsStorageTypes.CHEMICAL)); } @@ -773,7 +779,7 @@ public final MethodResult craftChemical(IComputerAccess computer, IArguments arg return notConnected(null); if (!APAddons.refinedStorageMekanismLoaded) - return MethodResult.of(null); + return MethodResult.of(null, StatusConstants.ADDON_NOT_LOADED.withInfo("RS_MEKANISM")); Pair filter = ChemicalFilter.parse(arguments.getTable(0)); if (filter.rightPresent()) diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java index 72fc081fb..561fac552 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java +++ b/src/main/java/de/srendi/advancedperipherals/common/util/StatusConstants.java @@ -35,6 +35,7 @@ public enum StatusConstants { // Misc NOT_CONNECTED, NOT_FOUND, // Generic not found state + ADDON_NOT_LOADED, UNKNOWN_ERROR; public String withInfo(String extraInfo) { From 42bb7c2d48bc4d3e4a1a53f290581d6fbb02d64e Mon Sep 17 00:00:00 2001 From: Srendi Date: Sun, 4 May 2025 20:39:36 +0200 Subject: [PATCH 87/91] Update src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java Co-authored-by: Kevin Z Signed-off-by: Srendi --- .../common/addons/refinedstorage/RSFluidHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java index 102d801a5..0b8550def 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java @@ -21,7 +21,6 @@ public class RSFluidHandler implements IStorageSystemFluidHandler { public RSFluidHandler(@NotNull Network network) { this.network = network; this.component = network.getComponent(StorageNetworkComponent.class); - } @Override From 1c9dc3943bb51babbd705bef183c288527031ae0 Mon Sep 17 00:00:00 2001 From: Kevin Z Date: Sun, 4 May 2025 13:19:31 -0600 Subject: [PATCH 88/91] clean up RS insert/extracts Signed-off-by: Kevin Z --- .../common/addons/refinedstorage/RSChemicalHandler.java | 8 +++----- .../common/addons/refinedstorage/RSFluidHandler.java | 3 +-- .../common/addons/refinedstorage/RSItemHandler.java | 8 +++----- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java index b73ce8d85..a93b27592 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java @@ -29,10 +29,9 @@ public ChemicalStack insertChemical(int tank, ChemicalStack resource, @NotNull m if (resource.isEmpty()) return resource; - ChemicalStack inserted = resource.copy(); long amountInserted = component.insert(ChemicalResource.ofChemicalStack(inserted), resource.getAmount(), action == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); - inserted.setAmount(resource.getAmount() - amountInserted); - return inserted; + ChemicalStack remain = resource.copyWithAmount(resource.getAmount() - amountInserted); + return remain; } @Override @@ -42,9 +41,8 @@ public ChemicalStack extractChemical(ChemicalFilter filter, long count, mekanism if (chemical == null) return ChemicalStack.EMPTY; - ChemicalStack extracted = ChemicalUtil.toChemicalStack(chemical.chemical(), 1); long amountExtracted = component.extract(chemical, filter.getCount(), simulate == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); - extracted.setAmount(amountExtracted); + ChemicalStack extracted = ChemicalUtil.toChemicalStack(chemical.chemical(), amountExtracted); AdvancedPeripherals.debug("Extracted chemical: " + extracted + " from filter: " + filter); return extracted; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java index 0b8550def..e0fb3362e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSFluidHandler.java @@ -39,9 +39,8 @@ public FluidStack drain(FluidFilter filter, FluidAction simulate) { if (fluid == null) return FluidStack.EMPTY; - FluidStack extracted = VariantUtil.toFluidStack(fluid, 1); long amountExtracted = component.extract(fluid, filter.getCount(), simulate == FluidAction.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); - extracted.setAmount((int) amountExtracted); + FluidStack extracted = VariantUtil.toFluidStack(fluid, (int) amountExtracted); AdvancedPeripherals.debug("Extracted fluid: " + extracted + " from filter: " + filter); return extracted; diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSItemHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSItemHandler.java index bf9b9d7d6..7753a3701 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSItemHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSItemHandler.java @@ -30,10 +30,9 @@ public RSItemHandler(@NotNull Network network) { @NotNull @Override public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { - ItemStack inserted = stack.copy(); long insertedAmount = component.insert(ItemResource.ofItemStack(stack), stack.getCount(), simulate ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); - inserted.setCount((int) (stack.getCount() - insertedAmount)); - return inserted; + ItemStack remain = stack.copyWithCount((int) (stack.getCount() - insertedAmount)); + return remain; } @Override @@ -43,9 +42,8 @@ public ItemStack extractItem(ItemFilter filter, int count, boolean simulate) { if (itemResource == null) return ItemStack.EMPTY; - ItemStack extracted = itemResource.toItemStack(); long extractedAmount = component.extract(itemResource, count, simulate ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); - extracted.setCount((int) extractedAmount); + ItemStack extracted = itemResource.toItemStack(extractedAmount); AdvancedPeripherals.debug("Extracted item: " + extracted + " from filter: " + filter); return extracted; From acb51ee38bee5b2bf2e36e19e841d78baa44e611 Mon Sep 17 00:00:00 2001 From: Kevin Z Date: Sun, 4 May 2025 14:04:02 -0600 Subject: [PATCH 89/91] fix insertChemical Signed-off-by: Kevin Z --- .../common/addons/refinedstorage/RSChemicalHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java index a93b27592..5d287837e 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSChemicalHandler.java @@ -29,7 +29,7 @@ public ChemicalStack insertChemical(int tank, ChemicalStack resource, @NotNull m if (resource.isEmpty()) return resource; - long amountInserted = component.insert(ChemicalResource.ofChemicalStack(inserted), resource.getAmount(), action == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); + long amountInserted = component.insert(ChemicalResource.ofChemicalStack(resource), resource.getAmount(), action == mekanism.api.Action.SIMULATE ? Action.SIMULATE : Action.EXECUTE, Actor.EMPTY); ChemicalStack remain = resource.copyWithAmount(resource.getAmount() - amountInserted); return remain; } From 71dcd022c90c4985b69e365e53d313344c099a7c Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 6 May 2025 22:23:05 +0200 Subject: [PATCH 90/91] Switch to Lists instead of using HashSet implementations for the RS Bridge --- .../peripheral/RSBridgePeripheral.java | 14 +++---- .../common/addons/refinedstorage/RSApi.java | 40 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java index 12bbaa21e..da1a3c764 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RSBridgePeripheral.java @@ -45,8 +45,8 @@ import org.jetbrains.annotations.Nullable; import java.util.Collections; +import java.util.List; import java.util.Map; -import java.util.Set; public class RSBridgePeripheral extends BasePeripheral> implements IStorageSystemPeripheral { @@ -297,7 +297,7 @@ public final MethodResult listItems(IArguments arguments) throws LuaException { ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RSApi.getParsedItems(getNetwork(), parsedFilter); + List> resourceProperties = RSApi.getParsedItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -314,7 +314,7 @@ public final MethodResult listFluids(IArguments arguments) throws LuaException { FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RSApi.getParsedFluids(getNetwork(), parsedFilter); + List> resourceProperties = RSApi.getParsedFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -334,7 +334,7 @@ public final MethodResult listChemicals(IArguments arguments) throws LuaExceptio ChemicalFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RSApi.getParsedChemicals(getNetwork(), parsedFilter); + List> resourceProperties = RSApi.getParsedChemicals(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -351,7 +351,7 @@ public final MethodResult listCraftableItems(IArguments arguments) throws LuaExc ItemFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RSApi.getCraftableItems(getNetwork(), parsedFilter); + List> resourceProperties = RSApi.getCraftableItems(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -368,7 +368,7 @@ public final MethodResult listCraftableFluids(IArguments arguments) throws LuaEx FluidFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RSApi.getCraftableFluids(getNetwork(), parsedFilter); + List> resourceProperties = RSApi.getCraftableFluids(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } @@ -388,7 +388,7 @@ public final MethodResult listCraftableChemicals(IArguments arguments) throws Lu ChemicalFilter parsedFilter = filter.getLeft(); - Set> resourceProperties = RSApi.getCraftableChemicals(getNetwork(), parsedFilter); + List> resourceProperties = RSApi.getCraftableChemicals(getNetwork(), parsedFilter); return MethodResult.of(resourceProperties); } diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index a8c2e29ed..029a87d40 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -54,10 +54,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; /** @@ -188,8 +186,8 @@ public static Map getParsedChemical(Network network, ChemicalFil * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of items */ - public static Set> getParsedItems(Network network, ItemFilter filter) { - Set> items = new HashSet<>(); + public static List> getParsedItems(Network network, ItemFilter filter) { + List> items = new ArrayList<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if (trackedResource.resourceAmount().resource() instanceof ItemResource itemResource && filter.test(itemResource.toItemStack())) { @@ -207,8 +205,8 @@ public static Set> getParsedItems(Network network, ItemFilte * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of fluid stacks */ - public static Set> getParsedFluids(Network network, FluidFilter filter) { - Set> items = new HashSet<>(); + public static List> getParsedFluids(Network network, FluidFilter filter) { + List> items = new ArrayList<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if (trackedResource.resourceAmount().resource() instanceof FluidResource fluidResource && filter.test(VariantUtil.toFluidStack(fluidResource, trackedResource.resourceAmount().amount()))) { @@ -227,8 +225,8 @@ public static Set> getParsedFluids(Network network, FluidFil * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of fluid stacks */ - public static Set> getParsedChemicals(Network network, ChemicalFilter filter) { - Set> items = new HashSet<>(); + public static List> getParsedChemicals(Network network, ChemicalFilter filter) { + List> items = new ArrayList<>(); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (TrackedResourceAmount trackedResource : storage.getResources(Actor.EMPTY.getClass())) { if (trackedResource.resourceAmount().resource() instanceof ChemicalResource fluidResource && filter.test(ChemicalUtil.toChemicalStack(fluidResource.chemical(), trackedResource.resourceAmount().amount()))) { @@ -247,8 +245,8 @@ public static Set> getParsedChemicals(Network network, Chemi * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of parsed item stacks */ - public static Set> getCraftableItems(Network network, ItemFilter filter) { - Set> items = new HashSet<>(); + public static List> getCraftableItems(Network network, ItemFilter filter) { + List> items = new ArrayList<>(); AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (ResourceKey key : autocrafting.getOutputs()) { @@ -267,8 +265,8 @@ public static Set> getCraftableItems(Network network, ItemFi * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of parsed fluids stacks */ - public static Set> getCraftableFluids(Network network, FluidFilter filter) { - Set> items = new HashSet<>(); + public static List> getCraftableFluids(Network network, FluidFilter filter) { + List> items = new ArrayList<>(); AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (ResourceKey key : autocrafting.getOutputs()) { @@ -288,8 +286,8 @@ public static Set> getCraftableFluids(Network network, Fluid * @param filter The filter here is optional, if an empty filter is provided, the method will return every resource * @return a set of parsed chemical stacks */ - public static Set> getCraftableChemicals(Network network, ChemicalFilter filter) { - Set> items = new HashSet<>(); + public static List> getCraftableChemicals(Network network, ChemicalFilter filter) { + List> items = new ArrayList<>(); AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); for (ResourceKey key : autocrafting.getOutputs()) { @@ -301,8 +299,8 @@ public static Set> getCraftableChemicals(Network network, Ch return items; } - public static Set getPatterns(Network network) { - Set patterns = new HashSet<>(); + public static List getPatterns(Network network) { + List patterns = new ArrayList<>(); AutocraftingNetworkComponent autocrafting = network.getComponent(AutocraftingNetworkComponent.class); for (Pattern pattern : autocrafting.getPatterns()) { @@ -312,8 +310,8 @@ public static Set getPatterns(Network network) { return patterns; } - public static Set listCells(Network network) { - Set disks = new HashSet<>(); + public static List listCells(Network network) { + List disks = new ArrayList<>(); GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { @@ -330,8 +328,8 @@ public static Set listCells(Network network) { return disks; } - public static Set listDrives(Network network) { - Set drives = new HashSet<>(); + public static List listDrives(Network network) { + List drives = new ArrayList<>(); GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { @@ -599,7 +597,7 @@ public static Object parseDiskDrive(StorageNetworkNode diskDrive, InWorldNetwork StorageConfiguration storageConfiguration = diskDrive.getStorageConfiguration(); CompositeStorage storage = (CompositeStorage) diskDrive.getStorage(); - Set disks = new HashSet<>(); + List disks = new ArrayList<>(); for (Storage disk : storage.getSources()) { if (!(disk instanceof StateTrackedStorage stateTrackedStorage)) continue; From 88c270cae5452b25cc4cda5eea91ed2d4b88d6b4 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 6 May 2025 22:27:26 +0200 Subject: [PATCH 91/91] Move Storage Type check to the beginning of the function to save time --- .../common/addons/refinedstorage/RSApi.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java index 029a87d40..7613bd525 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java +++ b/src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java @@ -456,12 +456,17 @@ public static long getTotalExternalStorage(Network network, RsStorageTypes type) public static long getUsedExternalStorage(Network network, RsStorageTypes type) { long used = 0; + // If the storage type if null, it just means that the supplier returns no storage type. That happens when an addon is not loaded + if (type.getStorageType() == null) { + return used; + } + GraphNetworkComponent graphNetworkComponent = network.getComponent(GraphNetworkComponent.class); for (InWorldNetworkNodeContainer nodeContainer : graphNetworkComponent.getContainers(InWorldNetworkNodeContainer.class)) { if (nodeContainer.getNode() instanceof ExternalStorageNetworkNode storageNetworkNode) { ExposedExternalStorage storage = (ExposedExternalStorage) storageNetworkNode.getStorage(); - used += storage.getAll().stream().filter(amount -> type.getStorageType() != null && type.getStorageType().isAllowed(amount.resource())).mapToLong(ResourceAmount::amount).sum(); + used += storage.getAll().stream().filter(amount -> type.getStorageType().isAllowed(amount.resource())).mapToLong(ResourceAmount::amount).sum(); } }