diff --git a/build.gradle b/build.gradle index 59cb1157..52724750 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'eclipse' id 'idea' id 'maven-publish' - id 'net.neoforged.gradle.userdev' version '7.0.80' + id 'net.neoforged.gradle.userdev' version '7.0.118' id "me.modmuss50.mod-publish-plugin" version "0.4.5" } @@ -50,7 +50,7 @@ base { archivesName = "${archive_base_name}-${mod_version}+mc${minecraft_version}" } -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(21) runs { // applies to all the run configs below @@ -67,6 +67,8 @@ runs { // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels systemProperty 'forge.logging.console.level', 'debug' + jvmArguments.addAll '-Xmx4G' + modSource project.sourceSets.main } @@ -99,21 +101,22 @@ sourceSets.main.resources { srcDir 'src/generated/resources' } dependencies { implementation "net.neoforged:neoforge:${neo_version}" - //implementation fg.deobf("mcjty.theoneprobe:theoneprobe:${top_version}") { - // exclude group: "net.minecraftforge", module: "forge" - //} - - compileOnly "mcjty.theoneprobe:theoneprobe:${top_version}" + implementation("mcjty.theoneprobe:theoneprobe:${top_version}") { + transitive = false + } - implementation "curse.maven:jade-324717:${jade_curse_id}" + compileOnly "curse.maven:jade-324717:${jade_curse_id}" compileOnly "vazkii.patchouli:Patchouli:${patchouli_version}:api" - runtimeOnly "vazkii.patchouli:Patchouli:${patchouli_version}" + //runtimeOnly "vazkii.patchouli:Patchouli:${patchouli_version}" + - compileOnly "mezz.jei:jei-${minecraft_version}-common-api:${jei_version}" - compileOnly "mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}" - runtimeOnly "mezz.jei:jei-${minecraft_version}-common:${jei_version}" - runtimeOnly "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}" + compileOnly "mezz.jei:jei-1.20.4-common-api:${jei_version}" + compileOnly "mezz.jei:jei-1.20.4-neoforge-api:${jei_version}" +// compileOnly "mezz.jei:jei-${minecraft_version}-common-api:${jei_version}" +// compileOnly "mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}" + //runtimeOnly "mezz.jei:jei-${minecraft_version}-common:${jei_version}" + //runtimeOnly "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}" // Locally sourced extra mods for runtime (i.e. testing) - thanks AE2 for this idea for (extraModJar in fileTree(dir: extraModsDir, include: '*.jar')) { @@ -136,7 +139,7 @@ tasks.withType(ProcessResources).configureEach { ] inputs.properties replaceProperties - filesMatching(['META-INF/mods.toml']) { + filesMatching(['META-INF/neoforge.mods.toml']) { expand replaceProperties + [project: project] } } diff --git a/gradle.properties b/gradle.properties index d89a48eb..11c2deb0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.daemon=false # Mod mod_id=modularrouters archive_base_name=modular-routers -mod_version=12.3.3 +mod_version=12.4.0 mod_name="Modular Routers" mod_group_id=me.desht.modularrouters mod_license=MIT @@ -16,19 +16,19 @@ modrinth_project_id=EuTS81Z3 curse_project_id=250294 # Minecraft/Forge -minecraft_version=1.20.4 -minecraft_version_range=[1.20.4,) -neo_version=20.4.174 -neo_version_range=[20.4.167,) +minecraft_version=1.20.6 +minecraft_version_range=[1.20.6,) +neo_version=20.6.2-beta +neo_version_range=[20.6.2-beta,) loader_version_range=[1,) mappings_channel=parchment -mappings_version=1.20.4-2023.10.22 +mappings_version=1.20.6-2023.10.22 pack_format_number=18 neogradle.subsystems.parchment.minecraftVersion=1.20.2 neogradle.subsystems.parchment.mappingsVersion=2023.12.10 # Dependencies jei_version=17.3.0.48 -jade_curse_id=5109393 -top_version=1.20.4_neo-11.0.1-2 +jade_curse_id=5288504 +top_version=1.20.5_neo-11.1.1-2 patchouli_version=1.20.4-85-NEOFORGE-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3499ded5..20db9ad5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/activator_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/activator_module.json index a798b7ae..3672decf 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/activator_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/activator_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/augment_core.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/augment_core.json index 694e192b..586df11d 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/augment_core.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/augment_core.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/blank_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/blank_module.json index 237dc306..55bcc73e 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/blank_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/blank_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "minecraft:redstone" - ] + "items": "minecraft:redstone" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/blank_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/blank_upgrade.json index 0c3a6682..4c1a6e2c 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/blank_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/blank_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "minecraft:lapis_lazuli" - ] + "items": "minecraft:lapis_lazuli" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/blast_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/blast_upgrade.json index f3b2bf2e..9ad30d51 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/blast_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/blast_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/bulk_item_filter.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/bulk_item_filter.json index 586ce799..4078cd06 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/bulk_item_filter.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/bulk_item_filter.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/camouflage_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/camouflage_upgrade.json index ee793e7e..2fa83d9c 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/camouflage_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/camouflage_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/detector_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/detector_module.json index b4ff4452..983159fb 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/detector_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/detector_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/distributor_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/distributor_module.json index bd6a3d3e..376f79f3 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/distributor_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/distributor_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/dropper_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/dropper_module.json index 417cf973..3c9cc83b 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/dropper_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/dropper_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_distributor_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_distributor_module.json index 8de1e8b7..3fef9962 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_distributor_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_distributor_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_output_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_output_module.json index faa01e87..de350596 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_output_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_output_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_upgrade.json index 116af27f..31d71dc9 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/energy_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/extruder_module_2.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/extruder_module_2.json index 1d2210a7..3c1a7a56 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/extruder_module_2.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/extruder_module_2.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fast_pickup_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fast_pickup_augment.json index e22660c0..1f4ead00 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fast_pickup_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fast_pickup_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/filter_round_robin_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/filter_round_robin_augment.json index 3fc22305..ff53115c 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/filter_round_robin_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/filter_round_robin_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/flinger_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/flinger_module.json index 47354bfd..f41167bd 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/flinger_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/flinger_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module.json index 36381ee5..3969aa61 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module_2.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module_2.json index 7c00f8cf..56990651 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module_2.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module_2.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:fluid_module" - ] + "items": "modularrouters:fluid_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module_2_x4.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module_2_x4.json index b18c616e..1f6bdc40 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module_2_x4.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_module_2_x4.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:fluid_module" - ] + "items": "modularrouters:fluid_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_upgrade.json index abf74235..8771fba9 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/fluid_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/inspection_filter.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/inspection_filter.json index 7a2c1420..51373a01 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/inspection_filter.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/inspection_filter.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:bulk_item_filter" - ] + "items": "modularrouters:bulk_item_filter" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/mimic_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/mimic_augment.json index b4aeac9c..38fcfe3a 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/mimic_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/mimic_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/mod_filter.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/mod_filter.json index 6a7e2529..6887c06d 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/mod_filter.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/mod_filter.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:bulk_item_filter" - ] + "items": "modularrouters:bulk_item_filter" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/modular_router.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/modular_router.json index 04d05738..edee7fb7 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/modular_router.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/modular_router.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "minecraft:iron_ingot" - ] + "items": "minecraft:iron_ingot" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/muffler_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/muffler_upgrade.json index d77a2297..246a6536 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/muffler_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/muffler_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/pickup_delay_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/pickup_delay_augment.json index 2475017a..4de8ef74 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/pickup_delay_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/pickup_delay_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/placer_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/placer_module.json index d6d450f1..608a481b 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/placer_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/placer_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/player_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/player_module.json index f1ce0846..44164bed 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/player_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/player_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_1.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_1.json index dc134be4..e8d8f96a 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_1.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_1.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_2.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_2.json index a44f6b83..fe8a9bb9 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_2.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_2.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_2_x4.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_2_x4.json index bc5f8c25..47c995b1 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_2_x4.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/puller_module_2_x4.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/pushing_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/pushing_augment.json index 1b0933b7..d9978617 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/pushing_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/pushing_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_down_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_down_augment.json index cdf1b0f2..26e1f900 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_down_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_down_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_down_from_up.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_down_from_up.json index 43b8a386..24deb338 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_down_from_up.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_down_from_up.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_up_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_up_augment.json index 3994d67a..93ff8424 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_up_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_up_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_up_from_down.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_up_from_down.json index 106056d4..86e55bb1 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_up_from_down.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/range_up_from_down.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/redstone_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/redstone_augment.json index 9b073ec9..cca2f1cd 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/redstone_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/redstone_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/regex_filter.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/regex_filter.json index ef65c06c..af7ab1d5 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/regex_filter.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/regex_filter.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:bulk_item_filter" - ] + "items": "modularrouters:bulk_item_filter" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/regulator_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/regulator_augment.json index 0c959de7..2b18c627 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/regulator_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/regulator_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/security_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/security_upgrade.json index bd6bdb5a..03a537ae 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/security_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/security_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_1.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_1.json index a82a646d..ded62d13 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_1.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_1.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_1_alt.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_1_alt.json index 8a3397e1..4f24ff9c 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_1_alt.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_1_alt.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_2.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_2.json index 54a3e5f9..afadf1e3 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_2.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_2.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_2_x4.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_2_x4.json index c4dd9ca2..5e86bc20 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_2_x4.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_2_x4.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_3.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_3.json index 970bcf21..a25a9e40 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_3.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sender_module_3.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/speed_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/speed_upgrade.json index 64676d58..ec2496c5 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/speed_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/speed_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/stack_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/stack_augment.json index 2a07fb36..795261ae 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/stack_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/stack_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/stack_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/stack_upgrade.json index 2eb7e77c..bdf7224d 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/stack_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/stack_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sync_upgrade.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sync_upgrade.json index 40a6ee27..8e7c5547 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/sync_upgrade.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/sync_upgrade.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_upgrade" - ] + "items": "modularrouters:blank_upgrade" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/tag_filter.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/tag_filter.json index 99e1e8ad..15f8bc42 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/tag_filter.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/tag_filter.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:bulk_item_filter" - ] + "items": "modularrouters:bulk_item_filter" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/vacuum_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/vacuum_module.json index 039c03e1..83024106 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/vacuum_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/vacuum_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/void_module.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/void_module.json index d7446f99..c2cc76a8 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/void_module.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/void_module.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:blank_module" - ] + "items": "modularrouters:blank_module" } ] }, diff --git a/src/generated/resources/data/modularrouters/advancements/recipes/misc/xp_vacuum_augment.json b/src/generated/resources/data/modularrouters/advancements/recipes/misc/xp_vacuum_augment.json index e375a43e..1f9f0a7a 100644 --- a/src/generated/resources/data/modularrouters/advancements/recipes/misc/xp_vacuum_augment.json +++ b/src/generated/resources/data/modularrouters/advancements/recipes/misc/xp_vacuum_augment.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "modularrouters:augment_core" - ] + "items": "modularrouters:augment_core" } ] }, diff --git a/src/generated/resources/data/modularrouters/loot_tables/blocks/modular_router.json b/src/generated/resources/data/modularrouters/loot_tables/blocks/modular_router.json index a7e4f037..9efec3bd 100644 --- a/src/generated/resources/data/modularrouters/loot_tables/blocks/modular_router.json +++ b/src/generated/resources/data/modularrouters/loot_tables/blocks/modular_router.json @@ -17,35 +17,13 @@ "source": "block_entity" }, { - "function": "minecraft:copy_nbt", - "ops": [ - { - "op": "replace", - "source": "Modules", - "target": "BlockEntityTag.Modules" - }, - { - "op": "replace", - "source": "Upgrades", - "target": "BlockEntityTag.Upgrades" - }, - { - "op": "replace", - "source": "Redstone", - "target": "BlockEntityTag.Redstone" - } + "function": "minecraft:copy_components", + "include": [ + "modularrouters:saved_redstone", + "modularrouters:saved_modules", + "modularrouters:saved_upgrades" ], "source": "block_entity" - }, - { - "type": "modularrouters:modular_router", - "entries": [ - { - "type": "minecraft:dynamic", - "name": "minecraft:contents" - } - ], - "function": "minecraft:set_contents" } ], "name": "modularrouters:modular_router" diff --git a/src/generated/resources/data/modularrouters/recipes/activator_module.json b/src/generated/resources/data/modularrouters/recipes/activator_module.json index b0b4aa31..e53f3416 100644 --- a/src/generated/resources/data/modularrouters/recipes/activator_module.json +++ b/src/generated/resources/data/modularrouters/recipes/activator_module.json @@ -12,10 +12,10 @@ "item": "modularrouters:blank_module" }, "Q": { - "tag": "forge:gems/quartz" + "tag": "c:gems/quartz" }, "R": { - "tag": "forge:dusts/redstone" + "tag": "c:dusts/redstone" } }, "pattern": [ @@ -24,6 +24,7 @@ "RQR" ], "result": { - "item": "modularrouters:activator_module" + "count": 1, + "id": "modularrouters:activator_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/augment_core.json b/src/generated/resources/data/modularrouters/recipes/augment_core.json index 73ac1ff8..f3690ba1 100644 --- a/src/generated/resources/data/modularrouters/recipes/augment_core.json +++ b/src/generated/resources/data/modularrouters/recipes/augment_core.json @@ -11,6 +11,6 @@ ], "result": { "count": 4, - "item": "modularrouters:augment_core" + "id": "modularrouters:augment_core" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/blank_module.json b/src/generated/resources/data/modularrouters/recipes/blank_module.json index 37f7491d..0af10f1a 100644 --- a/src/generated/resources/data/modularrouters/recipes/blank_module.json +++ b/src/generated/resources/data/modularrouters/recipes/blank_module.json @@ -3,13 +3,13 @@ "category": "misc", "key": { "G": { - "tag": "forge:nuggets/gold" + "tag": "c:nuggets/gold" }, "P": { "item": "minecraft:paper" }, "R": { - "tag": "forge:dusts/redstone" + "tag": "c:dusts/redstone" } }, "pattern": [ @@ -19,6 +19,6 @@ ], "result": { "count": 6, - "item": "modularrouters:blank_module" + "id": "modularrouters:blank_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/blank_upgrade.json b/src/generated/resources/data/modularrouters/recipes/blank_upgrade.json index 1668132d..bf1e8b43 100644 --- a/src/generated/resources/data/modularrouters/recipes/blank_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/blank_upgrade.json @@ -3,10 +3,10 @@ "category": "misc", "key": { "G": { - "tag": "forge:nuggets/gold" + "tag": "c:nuggets/gold" }, "L": { - "tag": "forge:gems/lapis" + "tag": "c:gems/lapis" }, "P": { "item": "minecraft:paper" @@ -19,6 +19,6 @@ ], "result": { "count": 4, - "item": "modularrouters:blank_upgrade" + "id": "modularrouters:blank_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/blast_upgrade.json b/src/generated/resources/data/modularrouters/recipes/blast_upgrade.json index 8b2cae2f..7cdbb7f4 100644 --- a/src/generated/resources/data/modularrouters/recipes/blast_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/blast_upgrade.json @@ -9,7 +9,7 @@ "item": "minecraft:iron_bars" }, "O": { - "tag": "forge:obsidian" + "tag": "c:obsidians" } }, "pattern": [ @@ -18,6 +18,7 @@ "IOI" ], "result": { - "item": "modularrouters:blast_upgrade" + "count": 1, + "id": "modularrouters:blast_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/bulk_item_filter.json b/src/generated/resources/data/modularrouters/recipes/bulk_item_filter.json index 8a644990..d1feffae 100644 --- a/src/generated/resources/data/modularrouters/recipes/bulk_item_filter.json +++ b/src/generated/resources/data/modularrouters/recipes/bulk_item_filter.json @@ -3,13 +3,13 @@ "category": "misc", "key": { "D": { - "tag": "forge:gems/diamond" + "tag": "c:gems/diamond" }, "G": { - "tag": "forge:glass" + "tag": "c:glass_blocks" }, "I": { - "tag": "forge:ingots/iron" + "tag": "c:ingots/iron" }, "M": { "item": "modularrouters:blank_module" @@ -21,6 +21,7 @@ "IGI" ], "result": { - "item": "modularrouters:bulk_item_filter" + "count": 1, + "id": "modularrouters:bulk_item_filter" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/camouflage_upgrade.json b/src/generated/resources/data/modularrouters/recipes/camouflage_upgrade.json index 113a767f..d0ee7c7e 100644 --- a/src/generated/resources/data/modularrouters/recipes/camouflage_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/camouflage_upgrade.json @@ -6,16 +6,17 @@ "item": "modularrouters:blank_upgrade" }, { - "tag": "forge:dyes/red" + "tag": "c:dyes/red" }, { - "tag": "forge:dyes/green" + "tag": "c:dyes/green" }, { - "tag": "forge:dyes/blue" + "tag": "c:dyes/blue" } ], "result": { - "item": "modularrouters:camouflage_upgrade" + "count": 1, + "id": "modularrouters:camouflage_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/detector_module.json b/src/generated/resources/data/modularrouters/recipes/detector_module.json index d77e3a73..1ac39bf0 100644 --- a/src/generated/resources/data/modularrouters/recipes/detector_module.json +++ b/src/generated/resources/data/modularrouters/recipes/detector_module.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:detector_module" + "count": 1, + "id": "modularrouters:detector_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/distributor_module.json b/src/generated/resources/data/modularrouters/recipes/distributor_module.json index 7181e316..e935c78c 100644 --- a/src/generated/resources/data/modularrouters/recipes/distributor_module.json +++ b/src/generated/resources/data/modularrouters/recipes/distributor_module.json @@ -14,6 +14,7 @@ "SMS" ], "result": { - "item": "modularrouters:distributor_module" + "count": 1, + "id": "modularrouters:distributor_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/dropper_module.json b/src/generated/resources/data/modularrouters/recipes/dropper_module.json index 9188bc91..0d244445 100644 --- a/src/generated/resources/data/modularrouters/recipes/dropper_module.json +++ b/src/generated/resources/data/modularrouters/recipes/dropper_module.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:dropper_module" + "count": 1, + "id": "modularrouters:dropper_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/energy_distributor_module.json b/src/generated/resources/data/modularrouters/recipes/energy_distributor_module.json index 672115c2..7f91e5d8 100644 --- a/src/generated/resources/data/modularrouters/recipes/energy_distributor_module.json +++ b/src/generated/resources/data/modularrouters/recipes/energy_distributor_module.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:energy_distributor_module" + "count": 1, + "id": "modularrouters:energy_distributor_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/energy_output_module.json b/src/generated/resources/data/modularrouters/recipes/energy_output_module.json index b812d947..2da4e1b7 100644 --- a/src/generated/resources/data/modularrouters/recipes/energy_output_module.json +++ b/src/generated/resources/data/modularrouters/recipes/energy_output_module.json @@ -6,13 +6,13 @@ "item": "modularrouters:blank_module" }, "G": { - "tag": "forge:ingots/gold" + "tag": "c:ingots/gold" }, "Q": { - "tag": "forge:gems/quartz" + "tag": "c:gems/quartz" }, "R": { - "tag": "forge:storage_blocks/redstone" + "tag": "c:storage_blocks/redstone" } }, "pattern": [ @@ -21,6 +21,7 @@ " Q " ], "result": { - "item": "modularrouters:energy_output_module" + "count": 1, + "id": "modularrouters:energy_output_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/energy_upgrade.json b/src/generated/resources/data/modularrouters/recipes/energy_upgrade.json index 81906a4c..ceebe72d 100644 --- a/src/generated/resources/data/modularrouters/recipes/energy_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/energy_upgrade.json @@ -6,13 +6,13 @@ "item": "modularrouters:blank_upgrade" }, "G": { - "tag": "forge:ingots/gold" + "tag": "c:ingots/gold" }, "Q": { - "tag": "forge:gems/quartz" + "tag": "c:gems/quartz" }, "R": { - "tag": "forge:storage_blocks/redstone" + "tag": "c:storage_blocks/redstone" } }, "pattern": [ @@ -21,6 +21,7 @@ "QGQ" ], "result": { - "item": "modularrouters:energy_upgrade" + "count": 1, + "id": "modularrouters:energy_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/extruder_module_2.json b/src/generated/resources/data/modularrouters/recipes/extruder_module_2.json index 746b1f73..e76449ce 100644 --- a/src/generated/resources/data/modularrouters/recipes/extruder_module_2.json +++ b/src/generated/resources/data/modularrouters/recipes/extruder_module_2.json @@ -6,10 +6,11 @@ "item": "modularrouters:blank_module" }, { - "tag": "forge:chests/wooden" + "tag": "c:chests/wooden" } ], "result": { - "item": "modularrouters:extruder_module_2" + "count": 1, + "id": "modularrouters:extruder_module_2" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/fast_pickup_augment.json b/src/generated/resources/data/modularrouters/recipes/fast_pickup_augment.json index f8bdcf5c..c5e2ac15 100644 --- a/src/generated/resources/data/modularrouters/recipes/fast_pickup_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/fast_pickup_augment.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:fast_pickup_augment" + "count": 1, + "id": "modularrouters:fast_pickup_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/filter_round_robin_augment.json b/src/generated/resources/data/modularrouters/recipes/filter_round_robin_augment.json index 2eebf3a6..be8528f1 100644 --- a/src/generated/resources/data/modularrouters/recipes/filter_round_robin_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/filter_round_robin_augment.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:filter_round_robin_augment" + "count": 1, + "id": "modularrouters:filter_round_robin_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/flinger_module.json b/src/generated/resources/data/modularrouters/recipes/flinger_module.json index 9287a40f..3499a9ca 100644 --- a/src/generated/resources/data/modularrouters/recipes/flinger_module.json +++ b/src/generated/resources/data/modularrouters/recipes/flinger_module.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:flinger_module" + "count": 1, + "id": "modularrouters:flinger_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/fluid_module.json b/src/generated/resources/data/modularrouters/recipes/fluid_module.json index 3d6c0dac..a5e95b53 100644 --- a/src/generated/resources/data/modularrouters/recipes/fluid_module.json +++ b/src/generated/resources/data/modularrouters/recipes/fluid_module.json @@ -6,7 +6,7 @@ "item": "minecraft:cauldron" }, "G": { - "tag": "forge:glass" + "tag": "c:glass_blocks" }, "M": { "item": "modularrouters:blank_module" @@ -17,6 +17,7 @@ "GMG" ], "result": { - "item": "modularrouters:fluid_module" + "count": 1, + "id": "modularrouters:fluid_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/fluid_module_2.json b/src/generated/resources/data/modularrouters/recipes/fluid_module_2.json index 3b776cdb..2c3bd097 100644 --- a/src/generated/resources/data/modularrouters/recipes/fluid_module_2.json +++ b/src/generated/resources/data/modularrouters/recipes/fluid_module_2.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:fluid_module_2" + "count": 1, + "id": "modularrouters:fluid_module_2" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/fluid_module_2_x4.json b/src/generated/resources/data/modularrouters/recipes/fluid_module_2_x4.json index c20781a7..4fa15908 100644 --- a/src/generated/resources/data/modularrouters/recipes/fluid_module_2_x4.json +++ b/src/generated/resources/data/modularrouters/recipes/fluid_module_2_x4.json @@ -20,6 +20,6 @@ ], "result": { "count": 4, - "item": "modularrouters:fluid_module_2" + "id": "modularrouters:fluid_module_2" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/fluid_upgrade.json b/src/generated/resources/data/modularrouters/recipes/fluid_upgrade.json index 92a12527..91055944 100644 --- a/src/generated/resources/data/modularrouters/recipes/fluid_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/fluid_upgrade.json @@ -6,7 +6,7 @@ "item": "modularrouters:blank_upgrade" }, "G": { - "tag": "forge:glass" + "tag": "c:glass_blocks" }, "U": { "item": "minecraft:bucket" @@ -18,6 +18,6 @@ ], "result": { "count": 3, - "item": "modularrouters:fluid_upgrade" + "id": "modularrouters:fluid_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/inspection_filter.json b/src/generated/resources/data/modularrouters/recipes/inspection_filter.json index 9c1ada49..bf8ffab7 100644 --- a/src/generated/resources/data/modularrouters/recipes/inspection_filter.json +++ b/src/generated/resources/data/modularrouters/recipes/inspection_filter.json @@ -17,6 +17,7 @@ " P " ], "result": { - "item": "modularrouters:inspection_filter" + "count": 1, + "id": "modularrouters:inspection_filter" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/mimic_augment.json b/src/generated/resources/data/modularrouters/recipes/mimic_augment.json index 2106c4af..da2c94b2 100644 --- a/src/generated/resources/data/modularrouters/recipes/mimic_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/mimic_augment.json @@ -6,16 +6,17 @@ "item": "modularrouters:augment_core" }, { - "tag": "forge:obsidian" + "tag": "c:obsidians" }, { - "tag": "forge:dusts/redstone" + "tag": "c:dusts/redstone" }, { - "tag": "forge:dusts/glowstone" + "tag": "c:dusts/glowstone" } ], "result": { - "item": "modularrouters:mimic_augment" + "count": 1, + "id": "modularrouters:mimic_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/mod_filter.json b/src/generated/resources/data/modularrouters/recipes/mod_filter.json index 042c6ef7..a091fade 100644 --- a/src/generated/resources/data/modularrouters/recipes/mod_filter.json +++ b/src/generated/resources/data/modularrouters/recipes/mod_filter.json @@ -13,6 +13,7 @@ } ], "result": { - "item": "modularrouters:mod_filter" + "count": 1, + "id": "modularrouters:mod_filter" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/modular_router.json b/src/generated/resources/data/modularrouters/recipes/modular_router.json index f6bb4ca2..4c38682c 100644 --- a/src/generated/resources/data/modularrouters/recipes/modular_router.json +++ b/src/generated/resources/data/modularrouters/recipes/modular_router.json @@ -6,7 +6,7 @@ "item": "minecraft:iron_bars" }, "I": { - "tag": "forge:ingots/iron" + "tag": "c:ingots/iron" }, "M": { "item": "modularrouters:blank_module" @@ -19,6 +19,6 @@ ], "result": { "count": 4, - "item": "modularrouters:modular_router" + "id": "modularrouters:modular_router" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/muffler_upgrade.json b/src/generated/resources/data/modularrouters/recipes/muffler_upgrade.json index a39eb466..6ad6ce3a 100644 --- a/src/generated/resources/data/modularrouters/recipes/muffler_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/muffler_upgrade.json @@ -16,6 +16,6 @@ ], "result": { "count": 4, - "item": "modularrouters:muffler_upgrade" + "id": "modularrouters:muffler_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/pickup_delay_augment.json b/src/generated/resources/data/modularrouters/recipes/pickup_delay_augment.json index ef1d847d..8834e28d 100644 --- a/src/generated/resources/data/modularrouters/recipes/pickup_delay_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/pickup_delay_augment.json @@ -6,10 +6,11 @@ "item": "modularrouters:augment_core" }, { - "tag": "forge:slimeballs" + "tag": "c:slimeballs" } ], "result": { - "item": "modularrouters:pickup_delay_augment" + "count": 1, + "id": "modularrouters:pickup_delay_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/placer_module.json b/src/generated/resources/data/modularrouters/recipes/placer_module.json index 9635b56f..41bcf602 100644 --- a/src/generated/resources/data/modularrouters/recipes/placer_module.json +++ b/src/generated/resources/data/modularrouters/recipes/placer_module.json @@ -13,6 +13,7 @@ } ], "result": { - "item": "modularrouters:placer_module" + "count": 1, + "id": "modularrouters:placer_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/player_module.json b/src/generated/resources/data/modularrouters/recipes/player_module.json index 216e6ff0..d1cb216a 100644 --- a/src/generated/resources/data/modularrouters/recipes/player_module.json +++ b/src/generated/resources/data/modularrouters/recipes/player_module.json @@ -24,6 +24,7 @@ " C " ], "result": { - "item": "modularrouters:player_module" + "count": 1, + "id": "modularrouters:player_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/puller_module_1.json b/src/generated/resources/data/modularrouters/recipes/puller_module_1.json index 0c7c7bd1..44e1783b 100644 --- a/src/generated/resources/data/modularrouters/recipes/puller_module_1.json +++ b/src/generated/resources/data/modularrouters/recipes/puller_module_1.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:puller_module_1" + "count": 1, + "id": "modularrouters:puller_module_1" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/puller_module_2.json b/src/generated/resources/data/modularrouters/recipes/puller_module_2.json index c1cbc65e..b6b5aecf 100644 --- a/src/generated/resources/data/modularrouters/recipes/puller_module_2.json +++ b/src/generated/resources/data/modularrouters/recipes/puller_module_2.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:puller_module_2" + "count": 1, + "id": "modularrouters:puller_module_2" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/puller_module_2_x4.json b/src/generated/resources/data/modularrouters/recipes/puller_module_2_x4.json index 6f09aa34..b8b4668e 100644 --- a/src/generated/resources/data/modularrouters/recipes/puller_module_2_x4.json +++ b/src/generated/resources/data/modularrouters/recipes/puller_module_2_x4.json @@ -20,6 +20,6 @@ ], "result": { "count": 4, - "item": "modularrouters:puller_module_2" + "id": "modularrouters:puller_module_2" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/pushing_augment.json b/src/generated/resources/data/modularrouters/recipes/pushing_augment.json index db021d11..034d2521 100644 --- a/src/generated/resources/data/modularrouters/recipes/pushing_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/pushing_augment.json @@ -13,6 +13,7 @@ "PMP" ], "result": { - "item": "modularrouters:pushing_augment" + "count": 1, + "id": "modularrouters:pushing_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/range_down_augment.json b/src/generated/resources/data/modularrouters/recipes/range_down_augment.json index 8b01caf5..1e346dbe 100644 --- a/src/generated/resources/data/modularrouters/recipes/range_down_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/range_down_augment.json @@ -6,10 +6,10 @@ "item": "modularrouters:augment_core" }, "Q": { - "tag": "forge:gems/quartz" + "tag": "c:gems/quartz" }, "S": { - "tag": "forge:rods/wooden" + "tag": "c:rods/wooden" } }, "pattern": [ @@ -19,6 +19,6 @@ ], "result": { "count": 4, - "item": "modularrouters:range_down_augment" + "id": "modularrouters:range_down_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/range_down_from_up.json b/src/generated/resources/data/modularrouters/recipes/range_down_from_up.json index 1dacc54b..6d2261bc 100644 --- a/src/generated/resources/data/modularrouters/recipes/range_down_from_up.json +++ b/src/generated/resources/data/modularrouters/recipes/range_down_from_up.json @@ -7,6 +7,7 @@ } ], "result": { - "item": "modularrouters:range_down_augment" + "count": 1, + "id": "modularrouters:range_down_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/range_up_augment.json b/src/generated/resources/data/modularrouters/recipes/range_up_augment.json index f6437935..9d2ad17c 100644 --- a/src/generated/resources/data/modularrouters/recipes/range_up_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/range_up_augment.json @@ -6,10 +6,10 @@ "item": "modularrouters:augment_core" }, "Q": { - "tag": "forge:gems/quartz" + "tag": "c:gems/quartz" }, "S": { - "tag": "forge:rods/wooden" + "tag": "c:rods/wooden" } }, "pattern": [ @@ -19,6 +19,6 @@ ], "result": { "count": 4, - "item": "modularrouters:range_up_augment" + "id": "modularrouters:range_up_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/range_up_from_down.json b/src/generated/resources/data/modularrouters/recipes/range_up_from_down.json index 2da4975e..8fbcaa62 100644 --- a/src/generated/resources/data/modularrouters/recipes/range_up_from_down.json +++ b/src/generated/resources/data/modularrouters/recipes/range_up_from_down.json @@ -7,6 +7,7 @@ } ], "result": { - "item": "modularrouters:range_up_augment" + "count": 1, + "id": "modularrouters:range_up_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/redstone_augment.json b/src/generated/resources/data/modularrouters/recipes/redstone_augment.json index 5332f57d..092be869 100644 --- a/src/generated/resources/data/modularrouters/recipes/redstone_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/redstone_augment.json @@ -6,7 +6,7 @@ "item": "modularrouters:augment_core" }, "R": { - "tag": "forge:dusts/redstone" + "tag": "c:dusts/redstone" }, "T": { "item": "minecraft:redstone_torch" @@ -18,6 +18,7 @@ " T " ], "result": { - "item": "modularrouters:redstone_augment" + "count": 1, + "id": "modularrouters:redstone_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/regex_filter.json b/src/generated/resources/data/modularrouters/recipes/regex_filter.json index a3888962..b75170d8 100644 --- a/src/generated/resources/data/modularrouters/recipes/regex_filter.json +++ b/src/generated/resources/data/modularrouters/recipes/regex_filter.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:regex_filter" + "count": 1, + "id": "modularrouters:regex_filter" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/regulator_augment.json b/src/generated/resources/data/modularrouters/recipes/regulator_augment.json index 6624aef7..58235335 100644 --- a/src/generated/resources/data/modularrouters/recipes/regulator_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/regulator_augment.json @@ -9,7 +9,7 @@ "item": "modularrouters:augment_core" }, "Q": { - "tag": "forge:gems/quartz" + "tag": "c:gems/quartz" } }, "pattern": [ @@ -18,6 +18,7 @@ " Q " ], "result": { - "item": "modularrouters:regulator_augment" + "count": 1, + "id": "modularrouters:regulator_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/security_upgrade.json b/src/generated/resources/data/modularrouters/recipes/security_upgrade.json index e35f468a..4c9b91ec 100644 --- a/src/generated/resources/data/modularrouters/recipes/security_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/security_upgrade.json @@ -6,13 +6,13 @@ "item": "modularrouters:blank_upgrade" }, "N": { - "tag": "forge:nuggets/gold" + "tag": "c:nuggets/gold" }, "Q": { - "tag": "forge:gems/quartz" + "tag": "c:gems/quartz" }, "R": { - "tag": "forge:dusts/redstone" + "tag": "c:dusts/redstone" } }, "pattern": [ @@ -21,6 +21,7 @@ " R " ], "result": { - "item": "modularrouters:security_upgrade" + "count": 1, + "id": "modularrouters:security_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/sender_module_1.json b/src/generated/resources/data/modularrouters/recipes/sender_module_1.json index a74047a6..54986031 100644 --- a/src/generated/resources/data/modularrouters/recipes/sender_module_1.json +++ b/src/generated/resources/data/modularrouters/recipes/sender_module_1.json @@ -13,6 +13,7 @@ } ], "result": { - "item": "modularrouters:sender_module_1" + "count": 1, + "id": "modularrouters:sender_module_1" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/sender_module_1_alt.json b/src/generated/resources/data/modularrouters/recipes/sender_module_1_alt.json index dafadedb..092b056b 100644 --- a/src/generated/resources/data/modularrouters/recipes/sender_module_1_alt.json +++ b/src/generated/resources/data/modularrouters/recipes/sender_module_1_alt.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:sender_module_1" + "count": 1, + "id": "modularrouters:sender_module_1" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/sender_module_2.json b/src/generated/resources/data/modularrouters/recipes/sender_module_2.json index 869f0bbe..67add555 100644 --- a/src/generated/resources/data/modularrouters/recipes/sender_module_2.json +++ b/src/generated/resources/data/modularrouters/recipes/sender_module_2.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:sender_module_2" + "count": 1, + "id": "modularrouters:sender_module_2" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/sender_module_2_x4.json b/src/generated/resources/data/modularrouters/recipes/sender_module_2_x4.json index 8d2f6ddf..7e91a185 100644 --- a/src/generated/resources/data/modularrouters/recipes/sender_module_2_x4.json +++ b/src/generated/resources/data/modularrouters/recipes/sender_module_2_x4.json @@ -20,6 +20,6 @@ ], "result": { "count": 4, - "item": "modularrouters:sender_module_2" + "id": "modularrouters:sender_module_2" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/sender_module_3.json b/src/generated/resources/data/modularrouters/recipes/sender_module_3.json index 25deeadd..75c2a44d 100644 --- a/src/generated/resources/data/modularrouters/recipes/sender_module_3.json +++ b/src/generated/resources/data/modularrouters/recipes/sender_module_3.json @@ -13,6 +13,7 @@ } ], "result": { - "item": "modularrouters:sender_module_3" + "count": 1, + "id": "modularrouters:sender_module_3" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/speed_upgrade.json b/src/generated/resources/data/modularrouters/recipes/speed_upgrade.json index 2ec634d6..4e014cea 100644 --- a/src/generated/resources/data/modularrouters/recipes/speed_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/speed_upgrade.json @@ -6,19 +6,19 @@ "item": "modularrouters:blank_upgrade" }, "G": { - "tag": "forge:gunpowder" + "tag": "c:gunpowder" }, "I": { - "tag": "forge:ingots/gold" + "tag": "c:ingots/gold" }, "N": { - "tag": "forge:nuggets/gold" + "tag": "c:nuggets/gold" }, "R": { - "tag": "forge:dusts/redstone" + "tag": "c:dusts/redstone" }, "Z": { - "tag": "forge:rods/blaze" + "tag": "c:rods/blaze" } }, "pattern": [ @@ -28,6 +28,6 @@ ], "result": { "count": 3, - "item": "modularrouters:speed_upgrade" + "id": "modularrouters:speed_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/stack_augment.json b/src/generated/resources/data/modularrouters/recipes/stack_augment.json index 6769b372..5735bdd9 100644 --- a/src/generated/resources/data/modularrouters/recipes/stack_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/stack_augment.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:stack_augment" + "count": 1, + "id": "modularrouters:stack_augment" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/stack_upgrade.json b/src/generated/resources/data/modularrouters/recipes/stack_upgrade.json index e6e81cd3..1bfafb57 100644 --- a/src/generated/resources/data/modularrouters/recipes/stack_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/stack_upgrade.json @@ -9,10 +9,11 @@ "tag": "minecraft:stone_bricks" }, { - "tag": "forge:ingots/brick" + "tag": "c:bricks" } ], "result": { - "item": "modularrouters:stack_upgrade" + "count": 1, + "id": "modularrouters:stack_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/sync_upgrade.json b/src/generated/resources/data/modularrouters/recipes/sync_upgrade.json index bae9efc3..dc5d5a99 100644 --- a/src/generated/resources/data/modularrouters/recipes/sync_upgrade.json +++ b/src/generated/resources/data/modularrouters/recipes/sync_upgrade.json @@ -6,10 +6,10 @@ "item": "modularrouters:blank_upgrade" }, "R": { - "tag": "forge:dusts/redstone" + "tag": "c:dusts/redstone" }, "S": { - "tag": "forge:stone" + "tag": "c:stones" }, "T": { "item": "minecraft:redstone_torch" @@ -21,6 +21,6 @@ ], "result": { "count": 16, - "item": "modularrouters:sync_upgrade" + "id": "modularrouters:sync_upgrade" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/tag_filter.json b/src/generated/resources/data/modularrouters/recipes/tag_filter.json index 586bb7d5..53cec200 100644 --- a/src/generated/resources/data/modularrouters/recipes/tag_filter.json +++ b/src/generated/resources/data/modularrouters/recipes/tag_filter.json @@ -9,10 +9,11 @@ "item": "minecraft:paper" }, { - "tag": "forge:dyes/black" + "tag": "c:dyes/black" } ], "result": { - "item": "modularrouters:tag_filter" + "count": 1, + "id": "modularrouters:tag_filter" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/vacuum_module.json b/src/generated/resources/data/modularrouters/recipes/vacuum_module.json index 71dfc898..78916df0 100644 --- a/src/generated/resources/data/modularrouters/recipes/vacuum_module.json +++ b/src/generated/resources/data/modularrouters/recipes/vacuum_module.json @@ -13,6 +13,7 @@ } ], "result": { - "item": "modularrouters:vacuum_module" + "count": 1, + "id": "modularrouters:vacuum_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/void_module.json b/src/generated/resources/data/modularrouters/recipes/void_module.json index a188c033..9ae3985a 100644 --- a/src/generated/resources/data/modularrouters/recipes/void_module.json +++ b/src/generated/resources/data/modularrouters/recipes/void_module.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:void_module" + "count": 1, + "id": "modularrouters:void_module" } } \ No newline at end of file diff --git a/src/generated/resources/data/modularrouters/recipes/xp_vacuum_augment.json b/src/generated/resources/data/modularrouters/recipes/xp_vacuum_augment.json index 6fc71f92..2cf18abf 100644 --- a/src/generated/resources/data/modularrouters/recipes/xp_vacuum_augment.json +++ b/src/generated/resources/data/modularrouters/recipes/xp_vacuum_augment.json @@ -10,6 +10,7 @@ } ], "result": { - "item": "modularrouters:xp_vacuum_augment" + "count": 1, + "id": "modularrouters:xp_vacuum_augment" } } \ No newline at end of file diff --git a/src/main/java/me/desht/modularrouters/ModularRouters.java b/src/main/java/me/desht/modularrouters/ModularRouters.java index 1b06642e..224c4264 100644 --- a/src/main/java/me/desht/modularrouters/ModularRouters.java +++ b/src/main/java/me/desht/modularrouters/ModularRouters.java @@ -13,6 +13,8 @@ import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.common.Mod; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import net.neoforged.fml.loading.FMLEnvironment; @@ -34,8 +36,8 @@ public class ModularRouters { private static WildcardedRLMatcher dimensionBlacklist; - public ModularRouters(IEventBus modBus) { - ConfigHolder.init(modBus); + public ModularRouters(ModContainer container, IEventBus modBus) { + ConfigHolder.init(container, modBus); if (FMLEnvironment.dist == Dist.CLIENT) { ClientSetup.initEarly(modBus); @@ -44,6 +46,10 @@ public ModularRouters(IEventBus modBus) { modBus.addListener(this::commonSetup); modBus.addListener(this::registerCaps); + registerDeferred(modBus); + } + + private static void registerDeferred(IEventBus modBus) { ModBlocks.BLOCKS.register(modBus); ModItems.ITEMS.register(modBus); ModBlockEntities.BLOCK_ENTITIES.register(modBus); @@ -51,6 +57,7 @@ public ModularRouters(IEventBus modBus) { ModSounds.SOUNDS.register(modBus); ModRecipes.RECIPES.register(modBus); ModCreativeModeTabs.TABS.register(modBus); + ModDataComponents.COMPONENTS.register(modBus); } private void registerCaps(RegisterCapabilitiesEvent event) { @@ -88,7 +95,7 @@ private void commonSetup(FMLCommonSetupEvent event) { }); } - @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) + @EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD) public static class DataGenerators { @SubscribeEvent public static void gatherData(GatherDataEvent event) { @@ -96,11 +103,11 @@ public static void gatherData(GatherDataEvent event) { CompletableFuture lookupProvider = event.getLookupProvider(); ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); - generator.addProvider(event.includeServer(), new ModRecipeProvider(generator)); + generator.addProvider(event.includeServer(), new ModRecipeProvider(generator, lookupProvider)); ModBlockTagsProvider blockTagsProvider = new ModBlockTagsProvider(generator, lookupProvider, existingFileHelper); generator.addProvider(event.includeServer(), blockTagsProvider); generator.addProvider(event.includeServer(), new ModItemTagsProvider(generator, lookupProvider, blockTagsProvider.contentsGetter(), existingFileHelper)); - generator.addProvider(event.includeServer(), new ModLootTableProvider(generator)); + generator.addProvider(event.includeServer(), new ModLootTableProvider(generator, lookupProvider)); generator.addProvider(event.includeServer(), new ModEntityTypeTagsProvider(generator, lookupProvider, existingFileHelper)); generator.addProvider(event.includeClient(), new ModBlockStateProvider(generator, existingFileHelper)); diff --git a/src/main/java/me/desht/modularrouters/block/ModularRouterBlock.java b/src/main/java/me/desht/modularrouters/block/ModularRouterBlock.java index 51525ba8..45d4d097 100644 --- a/src/main/java/me/desht/modularrouters/block/ModularRouterBlock.java +++ b/src/main/java/me/desht/modularrouters/block/ModularRouterBlock.java @@ -4,20 +4,22 @@ import me.desht.modularrouters.core.ModBlockEntities; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModSounds; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; +import me.desht.modularrouters.logic.settings.RedstoneBehaviour; import me.desht.modularrouters.network.messages.RouterSettingsMessage; import me.desht.modularrouters.network.messages.RouterUpgradesSyncMessage; import me.desht.modularrouters.util.InventoryUtils; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.BlockPlaceContext; @@ -109,15 +111,16 @@ public int getAnalogOutputSignal(BlockState blockState, Level world, BlockPos po } @Override - public void appendHoverText(ItemStack stack, @Nullable BlockGetter player, List tooltip, TooltipFlag advanced) { - if (stack.hasTag()) { - CompoundTag compound = stack.getTag().getCompound("BlockEntityTag"); + public void appendHoverText(ItemStack stack, Item.TooltipContext context, List tooltip, TooltipFlag advanced) { + HolderLookup.Provider lookupProvider = context.registries(); + if (lookupProvider != null && stack.has(DataComponents.BLOCK_ENTITY_DATA)) { + CompoundTag compound = stack.get(DataComponents.BLOCK_ENTITY_DATA).copyTag(); tooltip.add(xlate("modularrouters.itemText.misc.routerConfigured") .withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)); if (compound.contains(NBT_MODULES)) { List moduleText = new ArrayList<>(); ItemStackHandler modulesHandler = new ItemStackHandler(9); - modulesHandler.deserializeNBT(compound.getCompound(NBT_MODULES)); + modulesHandler.deserializeNBT(lookupProvider, compound.getCompound(NBT_MODULES)); for (int i = 0; i < modulesHandler.getSlots(); i++) { ItemStack moduleStack = modulesHandler.getStackInSlot(i); if (!moduleStack.isEmpty()) { @@ -134,7 +137,7 @@ public void appendHoverText(ItemStack stack, @Nullable BlockGetter player, List< } if (compound.contains(NBT_UPGRADES)) { ItemStackHandler upgradesHandler = new ItemStackHandler(); - upgradesHandler.deserializeNBT(compound.getCompound(NBT_UPGRADES)); + upgradesHandler.deserializeNBT(lookupProvider, compound.getCompound(NBT_UPGRADES)); List upgradeText = new ArrayList<>(); for (int i = 0; i < upgradesHandler.getSlots(); i++) { ItemStack upgradeStack = upgradesHandler.getStackInSlot(i); @@ -152,7 +155,7 @@ public void appendHoverText(ItemStack stack, @Nullable BlockGetter player, List< } if (compound.contains(NBT_REDSTONE_MODE)) { try { - RouterRedstoneBehaviour rrb = RouterRedstoneBehaviour.valueOf(compound.getString(NBT_REDSTONE_MODE)); + RedstoneBehaviour rrb = RedstoneBehaviour.valueOf(compound.getString(NBT_REDSTONE_MODE)); tooltip.add(xlate("modularrouters.guiText.tooltip.redstone.label") .append(": ") .withStyle(ChatFormatting.YELLOW) @@ -166,13 +169,13 @@ public void appendHoverText(ItemStack stack, @Nullable BlockGetter player, List< } @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockRayTraceResult) { - if (!player.isSteppingCarefully()) { + public InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult blockRayTraceResult) { + if (!player.isShiftKeyDown()) { return world.getBlockEntity(pos, ModBlockEntities.MODULAR_ROUTER.get()).map(router -> { if (player instanceof ServerPlayer sp && router.isPermitted(player)) { // TODO combine into one packet? - PacketDistributor.PLAYER.with(sp).send(new RouterSettingsMessage(router)); - PacketDistributor.PLAYER.with(sp).send(RouterUpgradesSyncMessage.forRouter(router)); + PacketDistributor.sendToPlayer(sp, RouterSettingsMessage.forRouter(router)); + PacketDistributor.sendToPlayer(sp, RouterUpgradesSyncMessage.forRouter(router)); sp.openMenu(router, pos); } else if (!router.isPermitted(player) && world.isClientSide) { player.displayClientMessage(xlate("modularrouters.chatText.security.accessDenied").withStyle(ChatFormatting.RED), false); diff --git a/src/main/java/me/desht/modularrouters/block/TemplateFrameBlock.java b/src/main/java/me/desht/modularrouters/block/TemplateFrameBlock.java index 583aa8c5..7f6e6519 100644 --- a/src/main/java/me/desht/modularrouters/block/TemplateFrameBlock.java +++ b/src/main/java/me/desht/modularrouters/block/TemplateFrameBlock.java @@ -3,6 +3,7 @@ import me.desht.modularrouters.block.tile.ICamouflageable; import me.desht.modularrouters.block.tile.TemplateFrameBlockEntity; import net.minecraft.core.BlockPos; +import net.minecraft.core.component.DataComponents; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelReader; @@ -27,7 +28,8 @@ public ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState s return super.getCloneItemStack(level, pos, state); } ItemStack stack = new ItemStack(camo.getCamouflage().getBlock().asItem()); - return stack.setHoverName(stack.getHoverName().plainCopy().append("..?")); + stack.set(DataComponents.ITEM_NAME, stack.getHoverName().copy().append("..?")); + return stack; } @Override diff --git a/src/main/java/me/desht/modularrouters/block/tile/ModularRouterBlockEntity.java b/src/main/java/me/desht/modularrouters/block/tile/ModularRouterBlockEntity.java index 405390f5..d1b4350b 100644 --- a/src/main/java/me/desht/modularrouters/block/tile/ModularRouterBlockEntity.java +++ b/src/main/java/me/desht/modularrouters/block/tile/ModularRouterBlockEntity.java @@ -10,29 +10,29 @@ import me.desht.modularrouters.container.handler.BufferHandler; import me.desht.modularrouters.core.ModBlockEntities; import me.desht.modularrouters.core.ModBlocks; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.event.TickEventHandler; import me.desht.modularrouters.item.module.DetectorModule.SignalType; -import me.desht.modularrouters.item.module.FluidModule1; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.item.module.ModuleItem.RelativeDirection; import me.desht.modularrouters.item.upgrade.CamouflageUpgrade; import me.desht.modularrouters.item.upgrade.SecurityUpgrade; import me.desht.modularrouters.item.upgrade.UpgradeItem; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; import me.desht.modularrouters.logic.compiled.CompiledExtruderModule1; import me.desht.modularrouters.logic.compiled.CompiledModule; +import me.desht.modularrouters.logic.settings.ModuleTermination; +import me.desht.modularrouters.logic.settings.RedstoneBehaviour; +import me.desht.modularrouters.logic.settings.RelativeDirection; +import me.desht.modularrouters.logic.settings.TransferDirection; import me.desht.modularrouters.network.messages.ItemBeamMessage; import me.desht.modularrouters.network.messages.RouterUpgradesSyncMessage; import me.desht.modularrouters.util.BeamData; import me.desht.modularrouters.util.MiscUtil; -import me.desht.modularrouters.util.ModuleHelper; import me.desht.modularrouters.util.TranslatableEnum; import me.desht.modularrouters.util.fake_player.RouterFakePlayer; import net.minecraft.Util; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.GlobalPos; +import net.minecraft.core.*; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; @@ -51,8 +51,9 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.ContainerData; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemContainerContents; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -65,6 +66,7 @@ import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.fluids.capability.IFluidHandlerItem; import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.IItemHandlerModifiable; import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.network.PacketDistributor; @@ -83,9 +85,6 @@ public class ModularRouterBlockEntity extends BlockEntity implements ICamouflage private static final int N_UPGRADE_SLOTS = 5; private static final int N_BUFFER_SLOTS = 1; - public static final int COMPILE_MODULES = 0x01; - public static final int COMPILE_UPGRADES = 0x02; - private static final String NBT_ACTIVE = "Active"; private static final String NBT_ACTIVE_TIMER = "ActiveTimer"; private static final String NBT_ECO_MODE = "EcoMode"; @@ -101,11 +100,11 @@ public class ModularRouterBlockEntity extends BlockEntity implements ICamouflage private int counter = 0; private int pulseCounter = 0; - private RouterRedstoneBehaviour redstoneBehaviour = RouterRedstoneBehaviour.ALWAYS; + private RedstoneBehaviour redstoneBehaviour = RedstoneBehaviour.ALWAYS; private final BufferHandler bufferHandler = new BufferHandler(this); - private final ItemStackHandler modulesHandler = new ModuleHandler(); - private final ItemStackHandler upgradesHandler = new UpgradeHandler(); + private final ModuleHandler modulesHandler = new ModuleHandler(); + private final UpgradeHandler upgradesHandler = new UpgradeHandler(); private final RouterEnergyBuffer energyStorage = new RouterEnergyBuffer(0); @@ -113,7 +112,7 @@ public class ModularRouterBlockEntity extends BlockEntity implements ICamouflage private EnergyDirection energyDirection = EnergyDirection.FROM_ROUTER; private final List compiledModules = new ArrayList<>(); - private byte recompileNeeded = COMPILE_MODULES | COMPILE_UPGRADES; + private final EnumSet recompileNeeded = EnumSet.allOf(RecompileFlag.class); private int tickRate = ConfigHolder.common.router.baseTickRate.get(); private int itemsPerTick = 1; private final Map upgradeCount = new HashMap<>(); @@ -134,7 +133,6 @@ public class ModularRouterBlockEntity extends BlockEntity implements ICamouflage private boolean active; // tracks active state of router private int activeTimer = 0; // used in PULSE mode to time out the active state private final Set permitted = Sets.newHashSet(); // permitted user ID's from security upgrade - private byte sidesOpen; // bitmask of which of the 6 sides are currently open private boolean ecoMode = false; // track eco-mode private int ecoCounter = ConfigHolder.common.router.ecoTimeout.get(); private boolean hasPulsedModules = false; @@ -159,7 +157,7 @@ public IItemHandler getBuffer() { return bufferHandler; } - public IItemHandler getModules() { + public IItemHandlerModifiable getModules() { return modulesHandler; } @@ -173,7 +171,7 @@ public Level nonNullLevel() { } @Override - public CompoundTag getUpdateTag() { + public CompoundTag getUpdateTag(HolderLookup.Provider provider) { return Util.make(new CompoundTag(), tag -> { tag.putInt("x", worldPosition.getX()); tag.putInt("y", worldPosition.getY()); @@ -199,8 +197,8 @@ public CompoundTag getUpdateTag() { } @Override - public void handleUpdateTag(CompoundTag tag) { - super.handleUpdateTag(tag); + public void handleUpdateTag(CompoundTag tag, HolderLookup.Provider provider) { + super.handleUpdateTag(tag, provider); processClientSync(tag); } @@ -210,14 +208,17 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() { } @Override - public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { + public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider provider) { if (pkt.getTag() != null) processClientSync(pkt.getTag()); } private void processClientSync(CompoundTag compound) { // called client-side on receipt of NBT + HolderGetter holderGetter = this.level != null ? + this.level.holderLookup(Registries.BLOCK) : + BuiltInRegistries.BLOCK.asLookup(); if (compound.contains(CamouflageUpgrade.NBT_STATE_NAME)) { - setCamouflage(NbtUtils.readBlockState(this.level.holderLookup(Registries.BLOCK), compound.getCompound(CamouflageUpgrade.NBT_STATE_NAME))); + setCamouflage(NbtUtils.readBlockState(holderGetter, compound.getCompound(CamouflageUpgrade.NBT_STATE_NAME))); } else { setCamouflage(null); } @@ -231,15 +232,15 @@ private void processClientSync(CompoundTag compound) { } @Override - public void load(CompoundTag nbt) { - super.load(nbt); + public void loadAdditional(CompoundTag nbt, HolderLookup.Provider provider) { + super.loadAdditional(nbt, provider); - bufferHandler.deserializeNBT(nbt.getCompound(NBT_BUFFER)); - modulesHandler.deserializeNBT(nbt.getCompound(NBT_MODULES)); - upgradesHandler.deserializeNBT(nbt.getCompound(NBT_UPGRADES)); - energyStorage.deserializeNBT(nbt.getCompound(NBT_ENERGY)); + bufferHandler.deserializeNBT(provider, nbt.getCompound(NBT_BUFFER)); + modulesHandler.deserializeNBT(provider, nbt.getCompound(NBT_MODULES)); + upgradesHandler.deserializeNBT(provider, nbt.getCompound(NBT_UPGRADES)); + energyStorage.deserializeNBT(provider, nbt.getCompound(NBT_ENERGY)); energyDirection = EnergyDirection.forValue(nbt.getString(NBT_ENERGY_DIR)); - redstoneBehaviour = RouterRedstoneBehaviour.forValue(nbt.getString(NBT_REDSTONE_MODE)); + redstoneBehaviour = RedstoneBehaviour.forValue(nbt.getString(NBT_REDSTONE_MODE)); active = nbt.getBoolean(NBT_ACTIVE); activeTimer = nbt.getInt(NBT_ACTIVE_TIMER); ecoMode = nbt.getBoolean(NBT_ECO_MODE); @@ -260,14 +261,14 @@ public void load(CompoundTag nbt) { } @Override - public void saveAdditional(CompoundTag nbt) { - super.saveAdditional(nbt); - - nbt.put(NBT_BUFFER, bufferHandler.serializeNBT()); - if (hasItems(modulesHandler)) nbt.put(NBT_MODULES, modulesHandler.serializeNBT()); - if (hasItems(upgradesHandler)) nbt.put(NBT_UPGRADES, upgradesHandler.serializeNBT()); - if (redstoneBehaviour != RouterRedstoneBehaviour.ALWAYS) nbt.putString(NBT_REDSTONE_MODE, redstoneBehaviour.name()); - if (energyStorage.getCapacity() > 0) nbt.put(NBT_ENERGY, energyStorage.serializeNBT()); + public void saveAdditional(CompoundTag nbt, HolderLookup.Provider provider) { + super.saveAdditional(nbt, provider); + + nbt.put(NBT_BUFFER, bufferHandler.serializeNBT(provider)); + if (hasItems(modulesHandler)) nbt.put(NBT_MODULES, modulesHandler.serializeNBT(provider)); + if (hasItems(upgradesHandler)) nbt.put(NBT_UPGRADES, upgradesHandler.serializeNBT(provider)); + if (redstoneBehaviour != RedstoneBehaviour.ALWAYS) nbt.putString(NBT_REDSTONE_MODE, redstoneBehaviour.name()); + if (energyStorage.getCapacity() > 0) nbt.put(NBT_ENERGY, energyStorage.serializeNBT(provider)); if (energyDirection != EnergyDirection.FROM_ROUTER) nbt.putString(NBT_ENERGY_DIR, energyDirection.name()); if (active) nbt.putBoolean(NBT_ACTIVE, true); if (activeTimer != 0) nbt.putInt(NBT_ACTIVE_TIMER, activeTimer); @@ -280,6 +281,24 @@ public void saveAdditional(CompoundTag nbt) { })); } + @Override + protected void applyImplicitComponents(DataComponentInput input) { + super.applyImplicitComponents(input); + + redstoneBehaviour = input.getOrDefault(ModDataComponents.REDSTONE_BEHAVIOUR, RedstoneBehaviour.ALWAYS); + modulesHandler.fillFrom(input.getOrDefault(ModDataComponents.SAVED_MODULES, ItemContainerContents.EMPTY)); + upgradesHandler.fillFrom(input.getOrDefault(ModDataComponents.SAVED_UPGRADES, ItemContainerContents.EMPTY)); + } + + @Override + protected void collectImplicitComponents(DataComponentMap.Builder builder) { + super.collectImplicitComponents(builder); + + builder.set(ModDataComponents.REDSTONE_BEHAVIOUR, redstoneBehaviour); + builder.set(ModDataComponents.SAVED_MODULES, modulesHandler.getContainerContents()); + builder.set(ModDataComponents.SAVED_UPGRADES, upgradesHandler.getContainerContents()); + } + private boolean hasItems(IItemHandler handler) { for (int i = 0; i < handler.getSlots(); i++) { if (!handler.getStackInSlot(i).isEmpty()) return true; @@ -299,7 +318,7 @@ public void clientTick() { } public void serverTick() { - if (recompileNeeded != 0) { + if (!recompileNeeded.isEmpty()) { compile(); } counter++; @@ -310,7 +329,7 @@ public void serverTick() { fakePlayer.getCooldowns().tick(); } - if (getRedstoneBehaviour() == RouterRedstoneBehaviour.PULSE) { + if (getRedstoneBehaviour() == RedstoneBehaviour.PULSE) { // pulse checking is done by checkRedstonePulse() - called from BlockItemRouter#neighborChanged() // however, we do need to turn the state inactive after a short time if we were set active by a pulse if (activeTimer > 0 && --activeTimer == 0) { @@ -392,9 +411,8 @@ private void executeModules(boolean pulsed) { newActive = runAllModules(powered, pulsed); - if (!pendingBeams.isEmpty()) { - PacketDistributor.TRACKING_CHUNK.with(nonNullLevel().getChunkAt(getBlockPos())) - .send(new ItemBeamMessage(this, pendingBeams)); + if (!pendingBeams.isEmpty() && level instanceof ServerLevel serverLevel) { + PacketDistributor.sendToPlayersTrackingChunk(serverLevel, new ChunkPos(getBlockPos()), ItemBeamMessage.create(this, pendingBeams)); pendingBeams.clear(); } if (prevCanEmit || canEmit) { @@ -422,7 +440,7 @@ private boolean runAllModules(boolean powered, boolean pulsed) { } if (event.isCanceled()) { - if ((newActive && cm.termination() == ModuleItem.Termination.RAN) || cm.termination() == ModuleItem.Termination.NOT_RAN) { + if ((newActive && cm.termination() == ModuleTermination.RAN) || cm.termination() == ModuleTermination.NOT_RAN) { break; } continue; @@ -432,14 +450,14 @@ private boolean runAllModules(boolean powered, boolean pulsed) { if (cm.execute(this)) { cm.getFilter().cycleRoundRobin().ifPresent(counter -> { ItemStack moduleStack = modulesHandler.getStackInSlot(cim.index); - ModuleHelper.setRoundRobinCounter(moduleStack, counter); + ModuleItem.setRoundRobinCounter(moduleStack, counter); }); getEnergyStorage().extractEnergy(cm.getEnergyCost(), false); newActive = true; - if (cm.termination() == ModuleItem.Termination.RAN) { + if (cm.termination() == ModuleTermination.RAN) { break; } - } else if (cm.termination() == ModuleItem.Termination.NOT_RAN) { + } else if (cm.termination() == ModuleTermination.NOT_RAN) { break; } } @@ -451,13 +469,13 @@ public int getTickRate() { return ecoMode && ecoCounter == 0 ? ConfigHolder.common.router.lowPowerTickRate.get() : tickRate; } - public RouterRedstoneBehaviour getRedstoneBehaviour() { + public RedstoneBehaviour getRedstoneBehaviour() { return redstoneBehaviour; } - public void setRedstoneBehaviour(RouterRedstoneBehaviour redstoneBehaviour) { + public void setRedstoneBehaviour(RedstoneBehaviour redstoneBehaviour) { this.redstoneBehaviour = redstoneBehaviour; - if (redstoneBehaviour == RouterRedstoneBehaviour.PULSE) { + if (redstoneBehaviour == RedstoneBehaviour.PULSE) { lastPower = getRedstonePower(); } setChanged(); @@ -473,13 +491,6 @@ private void setActive(boolean newActive) { } } - private void setSidesOpen(byte sidesOpen) { - if (this.sidesOpen != sidesOpen) { - this.sidesOpen = sidesOpen; - handleSync(true); - } - } - public void setEcoMode(boolean newEco) { if (newEco != ecoMode) { ecoMode = newEco; @@ -538,19 +549,18 @@ private void compile() { } else if (counter < 0) { // we've just restored from NBT - start off with a random counter value // to avoid lots of routers all ticking at the same time - counter = new Random().nextInt(tickRate); + counter = nonNullLevel().random.nextInt(tickRate); } BlockState state = getBlockState(); nonNullLevel().updateNeighborsAt(worldPosition, state.getBlock()); setChanged(); - recompileNeeded = 0; + recompileNeeded.clear(); } private void compileModules() { - if ((recompileNeeded & COMPILE_MODULES) != 0) { + if (recompileNeeded.contains(RecompileFlag.MODULES)) { setHasPulsedModules(false); - byte newSidesOpen = 0; for (CompiledIndexedModule cim : compiledModules) { cim.compiledModule.cleanup(this); } @@ -562,18 +572,16 @@ private void compileModules() { CompiledModule cms = moduleItem.compile(this, stack); compiledModules.add(new CompiledIndexedModule(cms, i)); cms.onCompiled(this); - newSidesOpen |= cms.getDirection().getMask(); if (cms.careAboutItemAttributes()) careAboutItemAttributes = true; } } - setSidesOpen(newSidesOpen); } } private void compileUpgrades() { // if called client-side, always recompile (it's due to an upgrade sync) Level level = nonNullLevel(); - if (level.isClientSide || (recompileNeeded & COMPILE_UPGRADES) != 0) { + if (level.isClientSide || recompileNeeded.contains(RecompileFlag.UPGRADES)) { int prevMufflers = getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()); upgradeCount.clear(); permitted.clear(); @@ -582,7 +590,7 @@ private void compileUpgrades() { for (int i = 0; i < N_UPGRADE_SLOTS; i++) { ItemStack stack = upgradesHandler.getStackInSlot(i); if (stack.getItem() instanceof UpgradeItem upgradeItem) { - upgradeCount.put(upgradeItem, getUpgradeCount(stack.getItem()) + stack.getCount()); + upgradeCount.put(upgradeItem, getUpgradeCount(upgradeItem) + stack.getCount()); upgradeItem.onCompiled(stack, this); } } @@ -608,7 +616,7 @@ private void compileUpgrades() { private void notifyWatchingPlayers() { for (Player player : nonNullLevel().players()) { if (player instanceof ServerPlayer sp && player.containerMenu instanceof RouterMenu c && c.getRouter() == this) { - PacketDistributor.PLAYER.with(sp).send(RouterUpgradesSyncMessage.forRouter(this)); + PacketDistributor.sendToPlayer(sp, RouterUpgradesSyncMessage.forRouter(this)); } } } @@ -625,6 +633,7 @@ private int calculateSyncCounter() { int delta = tuning - compileTime; if (delta <= 0) delta += tickRate; + ModularRouters.LOGGER.info("sync counter for {}: tc={} ct={} tuning={} delta={} counter={}", getBlockPos(), TickEventHandler.TickCounter, compileTime,tuning, delta, tickRate - delta); return tickRate - delta; } @@ -633,7 +642,7 @@ public void setAllowRedstoneEmission(boolean allow) { nonNullLevel().setBlockAndUpdate(worldPosition, getBlockState().setValue(ModularRouterBlock.CAN_EMIT, canEmit)); } - public int getUpgradeCount(Item type) { + public int getUpgradeCount(UpgradeItem type) { return upgradeCount.getOrDefault(type, 0); } @@ -641,8 +650,8 @@ public Map getAllUpgrades() { return Collections.unmodifiableMap(upgradeCount); } - public void recompileNeeded(int what) { - recompileNeeded |= what; + public void recompileNeeded(RecompileFlag what) { + recompileNeeded.add(what); } public int getItemsPerTick() { @@ -661,20 +670,20 @@ public int getFluidTransferRate() { return fluidTransferRate; } - public int getCurrentFluidTransferAllowance(FluidModule1.FluidDirection dir) { - return dir == FluidModule1.FluidDirection.IN ? fluidTransferRemainingIn : fluidTransferRemainingOut; + public int getCurrentFluidTransferAllowance(TransferDirection dir) { + return dir == TransferDirection.TO_ROUTER ? fluidTransferRemainingIn : fluidTransferRemainingOut; } - public void transferredFluid(int amount, FluidModule1.FluidDirection dir) { + public void transferredFluid(int amount, TransferDirection dir) { switch (dir) { - case IN -> { + case TO_ROUTER -> { if (fluidTransferRemainingIn < amount) - ModularRouters.LOGGER.warn("fluid transfer: " + fluidTransferRemainingIn + " < " + amount); + ModularRouters.LOGGER.warn("fluid transfer: {} < {}", fluidTransferRemainingIn, amount); fluidTransferRemainingIn = Math.max(0, fluidTransferRemainingIn - amount); } - case OUT -> { + case FROM_ROUTER -> { if (fluidTransferRemainingOut < amount) - ModularRouters.LOGGER.warn("fluid transfer: " + fluidTransferRemainingOut + " < " + amount); + ModularRouters.LOGGER.warn("fluid transfer: {} < {}", fluidTransferRemainingOut, amount); fluidTransferRemainingOut = Math.max(0, fluidTransferRemainingOut - amount); } default -> { @@ -695,8 +704,8 @@ public void checkForRedstonePulse() { if (executing) { return; // avoid recursion from executing module triggering more block updates } - if (redstoneBehaviour == RouterRedstoneBehaviour.PULSE - || hasPulsedModules && redstoneBehaviour == RouterRedstoneBehaviour.ALWAYS) { + if (redstoneBehaviour == RedstoneBehaviour.PULSE + || hasPulsedModules && redstoneBehaviour == RedstoneBehaviour.ALWAYS) { if (redstonePower > lastPower && pulseCounter >= tickRate) { allocateFluidTransfer(Math.min(pulseCounter, ConfigHolder.common.router.baseTickRate.get())); executeModules(true); @@ -981,9 +990,9 @@ public String getTranslationKey() { abstract class RouterItemHandler extends ItemStackHandler { private final Predicate validator; - private final int flag; + private final RecompileFlag flag; - private RouterItemHandler(int flag, int size, Predicate validator) { + private RouterItemHandler(RecompileFlag flag, int size, Predicate validator) { super(size); this.validator = validator; this.flag = flag; @@ -1001,17 +1010,25 @@ protected void onContentsChanged(int slot) { setChanged(); recompileNeeded(flag); } + + public ItemContainerContents getContainerContents() { + return ItemContainerContents.fromItems(stacks); + } + + public void fillFrom(ItemContainerContents contents) { + contents.copyInto(stacks); + } } class ModuleHandler extends RouterItemHandler { ModuleHandler() { - super(ModularRouterBlockEntity.COMPILE_MODULES, getModuleSlotCount(), s -> s.getItem() instanceof ModuleItem); + super(RecompileFlag.MODULES, getModuleSlotCount(), s -> s.getItem() instanceof ModuleItem); } } class UpgradeHandler extends RouterItemHandler { UpgradeHandler() { - super(ModularRouterBlockEntity.COMPILE_UPGRADES, getUpgradeSlotCount(), s -> s.getItem() instanceof UpgradeItem); + super(RecompileFlag.UPGRADES, getUpgradeSlotCount(), s -> s.getItem() instanceof UpgradeItem); } @Override @@ -1093,7 +1110,7 @@ public int getTransferRate() { } @Override - public Tag serializeNBT() { + public Tag serializeNBT(HolderLookup.Provider provider) { return Util.make(new CompoundTag(), tag -> { if (energy > 0) tag.putInt("Energy", energy); if (capacity > 0) tag.putInt("Capacity", capacity); @@ -1102,7 +1119,7 @@ public Tag serializeNBT() { } @Override - public void deserializeNBT(Tag nbt) { + public void deserializeNBT(HolderLookup.Provider provider, Tag nbt) { if (!(nbt instanceof CompoundTag compound)) { throw new IllegalArgumentException("Can not deserialize to an instance that isn't the default implementation"); } @@ -1148,4 +1165,9 @@ public int getCount() { return 2; } } + + public enum RecompileFlag { + MODULES, + UPGRADES + } } diff --git a/src/main/java/me/desht/modularrouters/block/tile/TemplateFrameBlockEntity.java b/src/main/java/me/desht/modularrouters/block/tile/TemplateFrameBlockEntity.java index 53d5a00e..2f3334f7 100644 --- a/src/main/java/me/desht/modularrouters/block/tile/TemplateFrameBlockEntity.java +++ b/src/main/java/me/desht/modularrouters/block/tile/TemplateFrameBlockEntity.java @@ -5,6 +5,7 @@ import me.desht.modularrouters.util.Scheduler; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; @@ -63,15 +64,15 @@ public void setExtendedMimic(boolean mimic) { } @Override - public void load(CompoundTag compound) { - super.load(compound); - camouflage = getCamoStateFromNBT(compound); + public void loadAdditional(CompoundTag compound, HolderLookup.Provider provider) { + super.loadAdditional(compound, provider); + camouflage = getCamoStateFromNBT(compound, provider); extendedMimic = compound.getBoolean(NBT_MIMIC); } @Override - public void saveAdditional(CompoundTag compound) { - super.saveAdditional(compound); + public void saveAdditional(CompoundTag compound, HolderLookup.Provider provider) { + super.saveAdditional(compound, provider); compound.putBoolean(NBT_MIMIC, extendedMimic); if (camouflage != null) { compound.put(NBT_CAMO_NAME, NbtUtils.writeBlockState(camouflage)); @@ -79,9 +80,9 @@ public void saveAdditional(CompoundTag compound) { } @Override - public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { + public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider provider) { if (pkt.getTag() != null) { - camouflage = getCamoStateFromNBT(pkt.getTag()); + camouflage = getCamoStateFromNBT(pkt.getTag(), provider); extendedMimic = pkt.getTag().getBoolean("Mimic"); if (camouflage != null && extendedMimic && camouflage.getLightEmission(getLevel(), getBlockPos()) > 0) { Objects.requireNonNull(getLevel()).getChunkSource().getLightEngine().checkBlock(worldPosition); @@ -90,10 +91,10 @@ public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { } @Override - public void handleUpdateTag(CompoundTag tag) { - super.handleUpdateTag(tag); + public void handleUpdateTag(CompoundTag tag, HolderLookup.Provider provider) { + super.handleUpdateTag(tag, provider); - camouflage = getCamoStateFromNBT(tag); + camouflage = getCamoStateFromNBT(tag, provider); extendedMimic = tag.getBoolean("Mimic"); if (camouflage != null && extendedMimic && camouflage.getLightEmission(getLevel(), getBlockPos()) > 0) { // this needs to be deferred a tick because the chunk isn't fully loaded, @@ -109,7 +110,7 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() { } @Override - public CompoundTag getUpdateTag() { + public CompoundTag getUpdateTag(HolderLookup.Provider provider) { CompoundTag compound = new CompoundTag(); compound.putInt("x", worldPosition.getX()); compound.putInt("y", worldPosition.getY()); @@ -119,9 +120,10 @@ public CompoundTag getUpdateTag() { return getNBTFromCamoState(compound, camouflage); } - private BlockState getCamoStateFromNBT(CompoundTag tag) { + private BlockState getCamoStateFromNBT(CompoundTag tag, HolderLookup.Provider provider) { // level isn't necessarily available here - var lookup = level == null ? BuiltInRegistries.BLOCK.asLookup() : level.holderLookup(Registries.BLOCK); +// var lookup = level == null ? BuiltInRegistries.BLOCK.asLookup() : level.holderLookup(Registries.BLOCK); + var lookup = provider.lookup(Registries.BLOCK).orElse(BuiltInRegistries.BLOCK.asLookup()); if (tag.contains(NBT_CAMO_NAME)) { return NbtUtils.readBlockState(lookup, tag.getCompound(NBT_CAMO_NAME)); } diff --git a/src/main/java/me/desht/modularrouters/client/ClientSetup.java b/src/main/java/me/desht/modularrouters/client/ClientSetup.java index a7b2867b..f166010c 100644 --- a/src/main/java/me/desht/modularrouters/client/ClientSetup.java +++ b/src/main/java/me/desht/modularrouters/client/ClientSetup.java @@ -10,16 +10,15 @@ import me.desht.modularrouters.client.render.area.ModuleTargetRenderer; import me.desht.modularrouters.client.render.blockentity.ModularRouterBER; import me.desht.modularrouters.core.ModBlockEntities; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; -import me.desht.modularrouters.logic.compiled.CompiledDistributorModule; import net.minecraft.client.KeyMapping; import net.minecraft.client.renderer.item.ItemProperties; -import net.minecraft.nbt.CompoundTag; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; import net.neoforged.neoforge.client.event.EntityRenderersEvent; import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; @@ -30,7 +29,7 @@ import static me.desht.modularrouters.util.MiscUtil.RL; -@Mod.EventBusSubscriber(modid = ModularRouters.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) +@EventBusSubscriber(modid = ModularRouters.MODID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD) public class ClientSetup { public static KeyMapping keybindConfigure; public static KeyMapping keybindModuleInfo; @@ -72,7 +71,7 @@ public static void registerKeyBindings(RegisterKeyMappingsEvent event) { public static void registerScreens(RegisterMenuScreensEvent event) { event.register(ModMenuTypes.ROUTER_MENU.get(), ModularRouterScreen::new); - event.register(ModMenuTypes.BASE_MODULE_MENU.get(), AbstractModuleScreen::new); + event.register(ModMenuTypes.BASE_MODULE_MENU.get(), ModuleScreen::new); event.register(ModMenuTypes.ACTIVATOR_MENU.get(), ActivatorModuleScreen::new); event.register(ModMenuTypes.BREAKER_MENU.get(), BreakerModuleScreen::new); event.register(ModMenuTypes.DETECTOR_MENU.get(), DetectorModuleScreen::new); @@ -91,10 +90,7 @@ public static void registerScreens(RegisterMenuScreensEvent event) { private static void registerItemModelOverrides() { ItemProperties.register(ModItems.DISTRIBUTOR_MODULE.get(), RL("mode"), (stack, world, entity, n) -> { if (entity != null) { - CompoundTag compound = stack.getTagElement(ModularRouters.MODID); - if (compound != null) { - return compound.getBoolean(CompiledDistributorModule.NBT_PULLING) ? 1f : 0f; - } + return stack.get(ModDataComponents.DISTRIBUTOR_SETTINGS).isPulling() ? 1f : 0f; } return 0f; }); diff --git a/src/main/java/me/desht/modularrouters/client/ColorHandlers.java b/src/main/java/me/desht/modularrouters/client/ColorHandlers.java index 1ca32dbc..f6882684 100644 --- a/src/main/java/me/desht/modularrouters/client/ColorHandlers.java +++ b/src/main/java/me/desht/modularrouters/client/ColorHandlers.java @@ -9,11 +9,12 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent; import net.neoforged.neoforge.registries.DeferredHolder; -@Mod.EventBusSubscriber(modid = ModularRouters.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) +@EventBusSubscriber(modid = ModularRouters.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class ColorHandlers { @SubscribeEvent public static void registerItemColorHandlers(RegisterColorHandlersEvent.Item event) { diff --git a/src/main/java/me/desht/modularrouters/client/gui/ModularRouterScreen.java b/src/main/java/me/desht/modularrouters/client/gui/ModularRouterScreen.java index 4bbeefc3..96a04e32 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/ModularRouterScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/ModularRouterScreen.java @@ -78,6 +78,7 @@ public void init() { addRenderableWidget(energyWidget = new EnergyWidget(this.leftPos - 22, this.topPos + 15, router.getEnergyStorage())); addRenderableWidget(energyWarning = new EnergyWarningButton(this.leftPos + 4, this.topPos + 4)); energyWidget.visible = energyDirButton.visible = router.getEnergyCapacity() > 0; + energyWarning.visible = false; } @Override @@ -142,7 +143,7 @@ private boolean handleModuleConfig() { return false; } MFLocator locator = MFLocator.moduleInRouter(menu.getRouter().getBlockPos(), slot.index - MODULE_START); - PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openModuleInRouter(locator)); + PacketDistributor.sendToServer(OpenGuiMessage.openModuleInRouter(locator)); return true; } @@ -153,7 +154,7 @@ public void sendToServer() { router.setRedstoneBehaviour(redstoneBehaviourButton.getState()); router.setEcoMode(ecoButton.isToggled()); router.setEnergyDirection(energyDirButton.getState()); - PacketDistributor.SERVER.noArg().send(new RouterSettingsMessage(router)); + PacketDistributor.sendToServer(RouterSettingsMessage.forRouter(router)); } public List getExtraArea() { diff --git a/src/main/java/me/desht/modularrouters/client/gui/filter/AbstractFilterContainerScreen.java b/src/main/java/me/desht/modularrouters/client/gui/filter/AbstractFilterContainerScreen.java index 0f0b97fd..f24dff06 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/filter/AbstractFilterContainerScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/filter/AbstractFilterContainerScreen.java @@ -6,6 +6,7 @@ import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.network.messages.OpenGuiMessage; import me.desht.modularrouters.util.MFLocator; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; @@ -31,13 +32,13 @@ boolean closeGUI() { // need to re-open module GUI for module in router slot MFLocator locator = menu.getLocator(); if (locator.routerPos() != null) { - PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openModuleInRouter(locator)); + PacketDistributor.sendToServer(OpenGuiMessage.openModuleInRouter(locator)); return true; } else if (hand != null) { ItemStack stack = getMinecraft().player.getItemInHand(hand); if (stack.getItem() instanceof ModuleItem) { // need to re-open module GUI for module in player's hand - PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openModuleInHand(locator)); + PacketDistributor.sendToServer(OpenGuiMessage.openModuleInHand(locator)); return true; } } @@ -53,6 +54,13 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { return super.keyPressed(keyCode, scanCode, modifiers); } + @Override + public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) { + super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); + + renderTooltip(pGuiGraphics, pMouseX, pMouseY); + } + @Override public void resync(ItemStack stack) { // nothing by default diff --git a/src/main/java/me/desht/modularrouters/client/gui/filter/AbstractFilterScreen.java b/src/main/java/me/desht/modularrouters/client/gui/filter/AbstractFilterScreen.java index d6d17424..3368d9fa 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/filter/AbstractFilterScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/filter/AbstractFilterScreen.java @@ -3,8 +3,7 @@ import me.desht.modularrouters.client.gui.IResyncableGui; import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.network.FilterOp; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; +import me.desht.modularrouters.network.messages.BulkFilterUpdateMessage; import me.desht.modularrouters.network.messages.OpenGuiMessage; import me.desht.modularrouters.util.MFLocator; import net.minecraft.Util; @@ -17,10 +16,13 @@ public abstract class AbstractFilterScreen extends Screen implements IResyncableGui { protected final Component title; + protected final ItemStack filterStack; final MFLocator locator; AbstractFilterScreen(ItemStack filterStack, MFLocator locator) { super(filterStack.getHoverName()); + + this.filterStack = filterStack; this.locator = locator; this.title = filterStack.getHoverName(); @@ -38,26 +40,26 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { boolean closeGUI() { if (locator.routerPos() != null) { // need to re-open module GUI for module in router slot - PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openModuleInRouter(locator)); + PacketDistributor.sendToServer(OpenGuiMessage.openModuleInRouter(locator)); return true; } else if (locator.hand() != null) { ItemStack stack = getMinecraft().player.getItemInHand(locator.hand()); if (stack.getItem() instanceof ModuleItem) { // need to re-open module GUI for module in player's hand - PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openModuleInHand(locator)); + PacketDistributor.sendToServer(OpenGuiMessage.openModuleInHand(locator)); return true; } } return false; } - void sendAddStringMessage(String key, String s) { - CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putString(key, s)); - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage(FilterOp.ADD_STRING, locator, ext)); - } - - void sendRemovePosMessage(int pos) { - CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putInt("Pos", pos)); - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage(FilterOp.REMOVE_AT, locator, ext)); - } +// void sendAddStringMessage(String key, String s) { +// CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putString(key, s)); +// PacketDistributor.sendToServer(new BulkFilterUpdateMessage(BulkFilterUpdateMessage.FilterOp.ADD_STRING, locator, ext)); +// } +// +// void sendRemovePosMessage(int pos) { +// CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putInt("Pos", pos)); +// PacketDistributor.sendToServer(new BulkFilterUpdateMessage(BulkFilterUpdateMessage.FilterOp.REMOVE_AT, locator, ext)); +// } } diff --git a/src/main/java/me/desht/modularrouters/client/gui/filter/BulkItemFilterScreen.java b/src/main/java/me/desht/modularrouters/client/gui/filter/BulkItemFilterScreen.java index 939a0d4a..49996e2d 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/filter/BulkItemFilterScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/filter/BulkItemFilterScreen.java @@ -9,19 +9,22 @@ import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.logic.ModuleTarget; import me.desht.modularrouters.logic.compiled.CompiledModule; -import me.desht.modularrouters.network.FilterOp; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; +import me.desht.modularrouters.network.messages.BulkFilterUpdateMessage; +import me.desht.modularrouters.network.messages.BulkFilterUpdateMessage.FilterOp; import me.desht.modularrouters.util.MFLocator; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.network.PacketDistributor; +import java.util.function.Consumer; + import static me.desht.modularrouters.client.util.ClientUtil.xlate; public class BulkItemFilterScreen extends AbstractFilterContainerScreen { @@ -44,7 +47,7 @@ public void init() { super.init(); addRenderableWidget(new ClearButton(leftPos + 8, topPos + 130, - p -> PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage(FilterOp.CLEAR_ALL, menu.getLocator(), null)) + p -> PacketDistributor.sendToServer(BulkFilterUpdateMessage.untargeted(FilterOp.CLEAR_ALL, menu.getLocator())) )); MFLocator locator = menu.getLocator(); @@ -60,18 +63,15 @@ public void init() { CompiledModule cm = ((ModuleItem) moduleStack.getItem()).compile(router, moduleStack); target = cm.getEffectiveTarget(router); if (target.hasItemHandlerClientSide()) { - addRenderableWidget(new MergeButton(leftPos + 28, topPos + 130, target.toString(), - xlate(target.blockTranslationKey), p -> { + MutableComponent title = xlate(target.blockTranslationKey); + addRenderableWidget(new MergeButton(leftPos + 28, topPos + 130, target.toString(), title, p -> { if (target != null) { - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage( - FilterOp.MERGE, menu.getLocator(), target.toNBT())); + PacketDistributor.sendToServer(BulkFilterUpdateMessage.targeted(FilterOp.MERGE, menu.getLocator(), target)); } })); - addRenderableWidget(new LoadButton(leftPos + 48, topPos + 130, target.toString(), - xlate(target.blockTranslationKey), p -> { + addRenderableWidget(new LoadButton(leftPos + 48, topPos + 130, target.toString(), title, p -> { if (target != null) { - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage( - FilterOp.LOAD, menu.getLocator(), target.toNBT())); + PacketDistributor.sendToServer(BulkFilterUpdateMessage.targeted(FilterOp.LOAD, menu.getLocator(), target)); } })); } @@ -89,7 +89,7 @@ protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, in } static class ClearButton extends Buttons.DeleteButton { - ClearButton(int x, int y, OnPress pressable) { + ClearButton(int x, int y, Consumer pressable) { super(x, y, 0, pressable); setTooltip(Tooltip.create(xlate("modularrouters.guiText.tooltip.clearFilter"))); } diff --git a/src/main/java/me/desht/modularrouters/client/gui/filter/Buttons.java b/src/main/java/me/desht/modularrouters/client/gui/filter/Buttons.java index cd374df9..e203d38e 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/filter/Buttons.java +++ b/src/main/java/me/desht/modularrouters/client/gui/filter/Buttons.java @@ -2,6 +2,10 @@ import me.desht.modularrouters.client.gui.widgets.button.TexturedButton; import me.desht.modularrouters.client.util.XYPoint; +import net.minecraft.client.gui.components.Button; + +import java.util.List; +import java.util.function.Consumer; class Buttons { static class AddButton extends TexturedButton { @@ -21,8 +25,8 @@ static class DeleteButton extends TexturedButton { private static final XYPoint TEXTURE_XY = new XYPoint(112, 16); private final int id; - DeleteButton(int x, int y, int id, OnPress pressable) { - super(x, y, 16, 16, pressable); + DeleteButton(int x, int y, int id, Consumer pressable) { + super(x, y, 16, 16, b -> pressable.accept((DeleteButton) b)); this.id = id; } @@ -34,7 +38,12 @@ protected XYPoint getTextureXY() { public int getId() { return id; } - } - + public List removeFromList(List list) { + if (id >= 0 && id < list.size()) { + list.remove(id); + } + return list; + } + } } diff --git a/src/main/java/me/desht/modularrouters/client/gui/filter/InspectionFilterScreen.java b/src/main/java/me/desht/modularrouters/client/gui/filter/InspectionFilterScreen.java index f1c50f9e..ff925b81 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/filter/InspectionFilterScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/filter/InspectionFilterScreen.java @@ -1,7 +1,7 @@ package me.desht.modularrouters.client.gui.filter; -import com.google.common.base.Joiner; import me.desht.modularrouters.ModularRouters; +import me.desht.modularrouters.client.gui.filter.Buttons.DeleteButton; import me.desht.modularrouters.client.gui.widgets.button.BackButton; import me.desht.modularrouters.client.gui.widgets.textfield.IntegerTextField; import me.desht.modularrouters.item.smartfilter.InspectionFilter; @@ -9,14 +9,12 @@ import me.desht.modularrouters.logic.filter.matchers.InspectionMatcher.ComparisonList; import me.desht.modularrouters.logic.filter.matchers.InspectionMatcher.InspectionOp; import me.desht.modularrouters.logic.filter.matchers.InspectionMatcher.InspectionSubject; -import me.desht.modularrouters.network.FilterOp; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; +import me.desht.modularrouters.network.messages.FilterUpdateMessage; import me.desht.modularrouters.util.MFLocator; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.client.gui.widget.ExtendedButton; @@ -40,7 +38,7 @@ public class InspectionFilterScreen extends AbstractFilterScreen { private IntegerTextField valueTextField; private InspectionSubject currentSubject = InspectionSubject.NONE; private InspectionOp currentOp = InspectionOp.NONE; - private final List deleteButtons = new ArrayList<>(); + private final List deleteButtons = new ArrayList<>(); private Button matchButton; public InspectionFilterScreen(ItemStack filterStack, MFLocator locator) { @@ -72,15 +70,15 @@ public void init() { addRenderableWidget(new Buttons.AddButton(xPos + 152, yPos + 23, button -> addEntry())); - matchButton = new ExtendedButton(xPos + 8, yPos + 167, 60, 20, xlate("modularrouters.guiText.label.matchAll." + comparisonList.isMatchAll()), button -> { - CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putBoolean("MatchAll", !comparisonList.isMatchAll())); - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage(FilterOp.ANY_ALL_FLAG, locator, ext)); + matchButton = new ExtendedButton(xPos + 8, yPos + 167, 60, 20, xlate("modularrouters.guiText.label.matchAll." + comparisonList.matchAll()), button -> { + ItemStack newStack = Util.make(filterStack.copy(), s -> InspectionFilter.setComparisonList(s, comparisonList.setMatchAll(!comparisonList.matchAll()))); + PacketDistributor.sendToServer(new FilterUpdateMessage(locator, newStack)); }); addRenderableWidget(matchButton); deleteButtons.clear(); for (int i = 0; i < InspectionFilter.MAX_SIZE; i++) { - Buttons.DeleteButton b = new Buttons.DeleteButton(xPos + 8, yPos + 52 + i * 19, i, button -> sendRemovePosMessage(((Buttons.DeleteButton) button).getId())); + DeleteButton b = new DeleteButton(xPos + 8, yPos + 52 + i * 19, i, button -> removeEntry(button.getId())); addRenderableWidget(b); deleteButtons.add(b); } @@ -103,26 +101,32 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { private void updateDeleteButtonVisibility() { for (int i = 0; i < deleteButtons.size(); i++) { - deleteButtons.get(i).visible = i < comparisonList.items.size(); + deleteButtons.get(i).visible = i < comparisonList.items().size(); } } private void addEntry() { if (currentOp != InspectionOp.NONE && currentSubject != InspectionSubject.NONE) { - int val = valueTextField.getIntValue(); - sendAddStringMessage(InspectionFilter.NBT_COMPARISON, Joiner.on(" ").join(currentSubject, currentOp, val)); + InspectionMatcher.Comparison newEntry = new InspectionMatcher.Comparison(currentSubject, currentOp, valueTextField.getIntValue()); + ItemStack newStack = Util.make(filterStack.copy(), s -> InspectionFilter.setComparisonList(s, comparisonList.addComparison(newEntry))); + PacketDistributor.sendToServer(new FilterUpdateMessage(locator, newStack)); valueTextField.setValue(""); } } + private void removeEntry(int pos) { + ItemStack newStack = Util.make(filterStack.copy(), s -> InspectionFilter.setComparisonList(s, comparisonList.removeAt(pos))); + PacketDistributor.sendToServer(new FilterUpdateMessage(locator, newStack)); + } + @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { super.render(graphics, mouseX, mouseY, partialTicks); graphics.drawString(font, title, xPos + GUI_WIDTH / 2 - font.width(title) / 2, yPos + 6, 0x404040, false); - for (int i = 0; i < comparisonList.items.size(); i++) { - InspectionMatcher.Comparison comparison = comparisonList.items.get(i); + for (int i = 0; i < comparisonList.items().size(); i++) { + InspectionMatcher.Comparison comparison = comparisonList.items().get(i); graphics.drawString(font, comparison.asLocalizedText(), xPos + 28, yPos + 55 + i * 19, 0x404080, false); } } @@ -137,7 +141,7 @@ public void renderBackground(GuiGraphics graphics, int pMouseX, int pMouseY, flo @Override public void resync(ItemStack stack) { comparisonList = InspectionFilter.getComparisonList(stack); - matchButton.setMessage(xlate("modularrouters.guiText.label.matchAll." + comparisonList.isMatchAll())); + matchButton.setMessage(xlate("modularrouters.guiText.label.matchAll." + comparisonList.matchAll())); updateDeleteButtonVisibility(); } } diff --git a/src/main/java/me/desht/modularrouters/client/gui/filter/ModFilterScreen.java b/src/main/java/me/desht/modularrouters/client/gui/filter/ModFilterScreen.java index d987e9e0..55cc84a6 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/filter/ModFilterScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/filter/ModFilterScreen.java @@ -6,21 +6,19 @@ import me.desht.modularrouters.client.gui.widgets.button.BackButton; import me.desht.modularrouters.container.AbstractSmartFilterMenu; import me.desht.modularrouters.item.smartfilter.ModFilter; -import me.desht.modularrouters.network.FilterOp; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; +import me.desht.modularrouters.network.messages.FilterUpdateMessage; import me.desht.modularrouters.util.MiscUtil; import me.desht.modularrouters.util.ModNameCache; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.network.PacketDistributor; -import java.util.List; +import java.util.*; import static me.desht.modularrouters.client.util.ClientUtil.xlate; @@ -44,7 +42,6 @@ public ModFilterScreen(AbstractSmartFilterMenu container, Inventory inv, Compone this.imageHeight = GUI_HEIGHT; mods.addAll(ModFilter.getModList(filterStack)); - mods.forEach(s -> ModularRouters.LOGGER.info("mod: " + s)); } @Override @@ -56,16 +53,16 @@ public void init() { } addRenderableWidget(new Buttons.AddButton(leftPos + 154, topPos + 19, p -> { if (!modId.isEmpty()) { - CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putString("ModId", modId)); - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage(FilterOp.ADD_STRING, menu.getLocator(), ext)); - getMenu().slots.get(0).set(ItemStack.EMPTY); + Set updatedMods = new LinkedHashSet<>(mods); + updatedMods.add(modId); + sendModsToServer(updatedMods); + getMenu().slots.getFirst().set(ItemStack.EMPTY); } })); deleteButtons.clear(); for (int i = 0; i < ModFilter.MAX_SIZE; i++) { DeleteButton b = new DeleteButton(leftPos + 8, topPos + 44 + i * 19, i, button -> { - CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putInt("Pos", ((DeleteButton) button).getId())); - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage(FilterOp.REMOVE_AT, menu.getLocator(), ext)); + sendModsToServer(button.removeFromList(new ArrayList<>(mods))); }); addRenderableWidget(b); deleteButtons.add(b); @@ -73,6 +70,11 @@ public void init() { updateDeleteButtonVisibility(); } + private void sendModsToServer(Collection newMods) { + ItemStack newStack = Util.make(filterStack.copy(), s -> ModFilter.setModList(s, List.copyOf(newMods))); + PacketDistributor.sendToServer(new FilterUpdateMessage(menu.getLocator(), newStack)); + } + private void updateDeleteButtonVisibility() { for (int i = 0; i < deleteButtons.size(); i++) { deleteButtons.get(i).visible = i < mods.size(); @@ -100,7 +102,7 @@ protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { public void containerTick() { super.containerTick(); - ItemStack inSlot = getMenu().getItems().get(0); + ItemStack inSlot = getMenu().getItems().getFirst(); if (inSlot.isEmpty() && !prevInSlot.isEmpty()) { modId = modName = ""; } else if (!inSlot.isEmpty() && (prevInSlot.isEmpty() || !MiscUtil.sameItemStackIgnoreDurability(inSlot, prevInSlot))) { diff --git a/src/main/java/me/desht/modularrouters/client/gui/filter/RegexFilterScreen.java b/src/main/java/me/desht/modularrouters/client/gui/filter/RegexFilterScreen.java index e4861df2..88998ea4 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/filter/RegexFilterScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/filter/RegexFilterScreen.java @@ -2,18 +2,25 @@ import com.google.common.collect.Lists; import me.desht.modularrouters.ModularRouters; +import me.desht.modularrouters.client.gui.filter.Buttons.DeleteButton; import me.desht.modularrouters.client.gui.widgets.button.BackButton; import me.desht.modularrouters.client.gui.widgets.textfield.TextFieldWidgetMR; import me.desht.modularrouters.core.ModSounds; +import me.desht.modularrouters.item.smartfilter.ModFilter; import me.desht.modularrouters.item.smartfilter.RegexFilter; +import me.desht.modularrouters.network.messages.FilterUpdateMessage; import me.desht.modularrouters.util.MFLocator; +import net.minecraft.Util; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.network.PacketDistributor; import org.lwjgl.glfw.GLFW; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -31,13 +38,13 @@ public class RegexFilterScreen extends AbstractFilterScreen { private Component errorMsg = Component.empty(); private int errorTimer = 60; // 3 seconds - private final List regexList = Lists.newArrayList(); - private final List deleteButtons = Lists.newArrayList(); + private final List regexList; + private final List deleteButtons = Lists.newArrayList(); public RegexFilterScreen(ItemStack filterStack, MFLocator locator) { super(filterStack, locator); - regexList.addAll(RegexFilter.getRegexList(filterStack)); + regexList = RegexFilter.getRegexList(filterStack); } @Override @@ -47,19 +54,19 @@ public void init() { regexTextField = new RegexTextField(this, font, xPos + 10, yPos + 27, 144, 18); regexTextField.useGuiTextBackground(); + addRenderableWidget(regexTextField); if (locator.filterSlot() >= 0) { addRenderableWidget(new BackButton(xPos - 12, yPos, p -> closeGUI())); } - addRenderableWidget(new Buttons.AddButton(xPos + 155, yPos + 23, button -> { - if (!regexTextField.getValue().isEmpty()) addRegex(); - })); + addRenderableWidget(new Buttons.AddButton(xPos + 155, yPos + 23, button -> addRegex())); deleteButtons.clear(); for (int i = 0; i < RegexFilter.MAX_SIZE; i++) { - Buttons.DeleteButton b = new Buttons.DeleteButton(xPos + 8, yPos + 52 + i * 19, i, - button -> sendRemovePosMessage(((Buttons.DeleteButton) button).getId())); + DeleteButton b = new DeleteButton(xPos + 8, yPos + 52 + i * 19, i, button -> { + sendRegexToServer(button.removeFromList(new ArrayList<>(regexList))); + }); addRenderableWidget(b); deleteButtons.add(b); } @@ -67,6 +74,11 @@ public void init() { updateDeleteButtonVisibility(); } + private void sendRegexToServer(Collection newFilters) { + ItemStack newStack = Util.make(filterStack.copy(), s -> ModFilter.setModList(s, List.copyOf(newFilters))); + PacketDistributor.sendToServer(new FilterUpdateMessage(locator, newStack)); + } + @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { super.render(graphics, mouseX, mouseY, partialTicks); @@ -99,10 +111,15 @@ public void tick() { private void addRegex() { try { String regex = regexTextField.getValue(); - Pattern.compile(regex); - sendAddStringMessage("String", regex); - regexTextField.setValue(""); - errorMsg = Component.empty(); + if (!regex.isEmpty()) { + Pattern.compile(regex); // just to validate syntax + List updatedList = new ArrayList<>(regexList); + updatedList.add(regex); + ItemStack newStack = Util.make(filterStack.copy(), s -> RegexFilter.setRegexList(s, updatedList)); + PacketDistributor.sendToServer(new FilterUpdateMessage(locator, newStack)); + regexTextField.setValue(""); + errorMsg = Component.empty(); + } } catch (PatternSyntaxException e) { minecraft.player.playSound(ModSounds.ERROR.get(), 1.0f, 1.0f); errorMsg = xlate("modularrouters.guiText.label.regexError"); diff --git a/src/main/java/me/desht/modularrouters/client/gui/filter/TagFilterScreen.java b/src/main/java/me/desht/modularrouters/client/gui/filter/TagFilterScreen.java index b5dafbe5..f404157d 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/filter/TagFilterScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/filter/TagFilterScreen.java @@ -8,13 +8,11 @@ import me.desht.modularrouters.container.AbstractSmartFilterMenu; import me.desht.modularrouters.item.smartfilter.ModFilter; import me.desht.modularrouters.item.smartfilter.TagFilter; -import me.desht.modularrouters.network.FilterOp; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; +import me.desht.modularrouters.network.messages.FilterUpdateMessage; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; @@ -24,9 +22,7 @@ import net.neoforged.neoforge.client.gui.widget.ExtendedButton; import net.neoforged.neoforge.network.PacketDistributor; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import java.util.*; import static me.desht.modularrouters.client.util.ClientUtil.xlate; @@ -65,15 +61,15 @@ public void init() { } addRenderableWidget(new Buttons.AddButton(leftPos + 234, topPos + 19, p -> { if (selectedTag != null) { - CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putString("Tag", selectedTag.location().toString())); - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage(FilterOp.ADD_STRING, menu.getLocator(), ext)); + Set> updatedTags = new LinkedHashSet<>(addedTags); + updatedTags.add(selectedTag); + sendTagsToServer(updatedTags); } })); deleteButtons.clear(); for (int i = 0; i < ModFilter.MAX_SIZE; i++) { DeleteButton b = new DeleteButton(leftPos + 8, topPos + 44 + i * 19, i, button -> { - CompoundTag ext = Util.make(new CompoundTag(), tag -> tag.putInt("Pos", ((DeleteButton) button).getId())); - PacketDistributor.SERVER.noArg().send(new FilterSettingsMessage(FilterOp.REMOVE_AT, menu.getLocator(), ext)); + sendTagsToServer(button.removeFromList(new ArrayList<>(addedTags))); }); addRenderableWidget(b); deleteButtons.add(b); @@ -89,6 +85,11 @@ public void init() { updateButtonVisibility(); } + private void sendTagsToServer(Collection> newTags) { + ItemStack newStack = Util.make(filterStack.copy(), s -> TagFilter.setTagList(s, List.copyOf(newTags))); + PacketDistributor.sendToServer(new FilterUpdateMessage(menu.getLocator(), newStack)); + } + private void updateButtonVisibility() { for (int i = 0; i < deleteButtons.size(); i++) { deleteButtons.get(i).visible = i < addedTags.size() && !tagSelectorShowing; diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/ActivatorModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/ActivatorModuleScreen.java index 2ac11fba..3f080c2b 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/ActivatorModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/ActivatorModuleScreen.java @@ -5,13 +5,13 @@ import me.desht.modularrouters.client.gui.widgets.button.TexturedToggleButton; import me.desht.modularrouters.client.util.XYPoint; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.logic.compiled.CompiledActivatorModule; import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.ActionType; import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.EntityMode; import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.LookDirection; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; @@ -19,7 +19,7 @@ import static me.desht.modularrouters.client.util.ClientUtil.xlate; -public class ActivatorModuleScreen extends AbstractModuleScreen { +public class ActivatorModuleScreen extends ModuleScreen { private static final ItemStack ITEM_STACK = new ItemStack(Items.FLINT_AND_STEEL); private static final ItemStack ENTITY_STACK = new ItemStack(Items.PLAYER_HEAD); private static final ItemStack ATTACK_STACK = new ItemStack(Items.IRON_SWORD); @@ -75,13 +75,15 @@ public void containerTick() { } @Override - protected CompoundTag buildMessageData() { - return Util.make(super.buildMessageData(), tag -> { - tag.putInt(CompiledActivatorModule.NBT_ACTION_TYPE, actionTypeButton.getState().ordinal()); - tag.putInt(CompiledActivatorModule.NBT_LOOK_DIRECTION, lookDirectionButton.getState().ordinal()); - tag.putInt(CompiledActivatorModule.NBT_ENTITY_MODE, entityModeButton.getState().ordinal()); - tag.putBoolean(CompiledActivatorModule.NBT_SNEAKING, sneakButton.isToggled()); - }); + protected ItemStack buildModifiedItemStack() { + return Util.make(super.buildModifiedItemStack(), stack -> + stack.set(ModDataComponents.ACTIVATOR_SETTINGS, new CompiledActivatorModule.ActivatorSettings( + actionTypeButton.getState(), + lookDirectionButton.getState(), + entityModeButton.getState(), + sneakButton.isToggled() + )) + ); } private class LookDirectionButton extends TexturedCyclerButton { diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/BreakerModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/BreakerModuleScreen.java index e26ef00c..1f290947 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/BreakerModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/BreakerModuleScreen.java @@ -2,18 +2,18 @@ import me.desht.modularrouters.client.gui.widgets.button.ItemStackCyclerButton; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.logic.compiled.CompiledBreakerModule; import me.desht.modularrouters.logic.compiled.CompiledBreakerModule.MatchType; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Blocks; -public class BreakerModuleScreen extends AbstractModuleScreen { +public class BreakerModuleScreen extends ModuleScreen { private static final ItemStack BLOCK_STACK = new ItemStack(Blocks.IRON_BLOCK); private static final ItemStack ITEM_STACK = new ItemStack(Items.IRON_INGOT); private static final ItemStack[] STACKS = new ItemStack[] { @@ -38,8 +38,12 @@ public void init() { } @Override - protected CompoundTag buildMessageData() { - return Util.make(super.buildMessageData(), tag -> tag.putInt(CompiledBreakerModule.NBT_MATCH_TYPE, matchBlockButton.getState().ordinal())); + protected ItemStack buildModifiedItemStack() { + return Util.make(super.buildModifiedItemStack(), s -> + s.set(ModDataComponents.BREAKER_SETTINGS, new CompiledBreakerModule.BreakerSettings( + matchBlockButton.getState() + )) + ); } @Override diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/DetectorModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/DetectorModuleScreen.java index 830e4a49..2342f41d 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/DetectorModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/DetectorModuleScreen.java @@ -4,12 +4,12 @@ import me.desht.modularrouters.client.gui.widgets.textfield.IntegerTextField; import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.logic.compiled.CompiledDetectorModule; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.sounds.SoundManager; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; @@ -19,7 +19,7 @@ import static me.desht.modularrouters.client.util.ClientUtil.xlate; -public class DetectorModuleScreen extends AbstractModuleScreen { +public class DetectorModuleScreen extends ModuleScreen { private static final ItemStack redstoneStack = new ItemStack(Items.REDSTONE); private boolean isStrong; @@ -63,11 +63,13 @@ protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, in } @Override - protected CompoundTag buildMessageData() { - return Util.make(super.buildMessageData(), compound -> { - compound.putByte(CompiledDetectorModule.NBT_SIGNAL_LEVEL, (byte) intField.getIntValue()); - compound.putBoolean(CompiledDetectorModule.NBT_STRONG_SIGNAL, isStrong); - }); + protected ItemStack buildModifiedItemStack() { + return Util.make(super.buildModifiedItemStack(), stack -> + stack.set(ModDataComponents.DETECTOR_SETTINGS, new CompiledDetectorModule.DetectorSettings( + intField.getIntValue(), + isStrong + )) + ); } private static class TooltipButton extends ItemStackButton { diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/DistributorModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/DistributorModuleScreen.java index aac1694a..34020cbf 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/DistributorModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/DistributorModuleScreen.java @@ -6,22 +6,23 @@ import me.desht.modularrouters.client.util.XYPoint; import me.desht.modularrouters.container.ModuleMenu; import me.desht.modularrouters.core.ModBlocks; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.compiled.CompiledDistributorModule; import me.desht.modularrouters.logic.compiled.CompiledDistributorModule.DistributionStrategy; +import me.desht.modularrouters.logic.settings.TransferDirection; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.sounds.SoundManager; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import static me.desht.modularrouters.client.util.ClientUtil.xlate; -public class DistributorModuleScreen extends AbstractModuleScreen { +public class DistributorModuleScreen extends ModuleScreen { private static final ItemStack ROUTER_STACK = new ItemStack(ModBlocks.MODULAR_ROUTER.get()); private StrategyButton sb; @@ -48,11 +49,13 @@ public void init() { } @Override - protected CompoundTag buildMessageData() { - return Util.make(super.buildMessageData(), tag -> { - tag.putInt(CompiledDistributorModule.NBT_STRATEGY, sb.getState().ordinal()); - tag.putBoolean(CompiledDistributorModule.NBT_PULLING, db.isToggled()); - }); + protected ItemStack buildModifiedItemStack() { + return Util.make(super.buildModifiedItemStack(), stack -> + stack.set(ModDataComponents.DISTRIBUTOR_SETTINGS, new CompiledDistributorModule.DistributorSettings( + sb.getState(), + db.isToggled() ? TransferDirection.TO_ROUTER : TransferDirection.FROM_ROUTER + )) + ); } @Override @@ -80,7 +83,7 @@ private class DirectionButton extends TexturedToggleButton { public DirectionButton(int x, int y, boolean initialVal) { super(x, y, 16, 16, initialVal, DistributorModuleScreen.this); - setTooltips(xlate("modularrouters.itemText.fluid.direction.OUT"),xlate("modularrouters.itemText.fluid.direction.IN")); + setTooltips(xlate("modularrouters.itemText.transfer_direction.from_router"),xlate("modularrouters.itemText.transfer_direction.to_router")); } @Override diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/ExtruderModule2Screen.java b/src/main/java/me/desht/modularrouters/client/gui/module/ExtruderModule2Screen.java index 0d16400d..757e3314 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/ExtruderModule2Screen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/ExtruderModule2Screen.java @@ -7,7 +7,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; -public class ExtruderModule2Screen extends AbstractModuleScreen { +public class ExtruderModule2Screen extends ModuleScreen { public ExtruderModule2Screen(ModuleMenu container, Inventory inv, Component displayName) { super(container, inv, displayName); } diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/FlingerModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/FlingerModuleScreen.java index 5fe8103c..54c5daf6 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/FlingerModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/FlingerModuleScreen.java @@ -5,19 +5,20 @@ import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.client.util.XYPoint; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.item.module.FlingerModule; import me.desht.modularrouters.logic.compiled.CompiledFlingerModule; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.sounds.SoundManager; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; import static me.desht.modularrouters.client.util.ClientUtil.xlate; -public class FlingerModuleScreen extends AbstractModuleScreen { +public class FlingerModuleScreen extends ModuleScreen { private FloatTextField speedField; private FloatTextField pitchField; private FloatTextField yawField; @@ -34,8 +35,6 @@ public void init() { addRenderableWidget(new TooltipButton(1, leftPos + 130, topPos + 33, "pitch", FlingerModule.MIN_PITCH, FlingerModule.MAX_PITCH)); addRenderableWidget(new TooltipButton(2, leftPos + 130, topPos + 51, "yaw", FlingerModule.MIN_YAW, FlingerModule.MAX_YAW)); -// TextFieldManager manager = getOrCreateTextFieldManager(); - CompiledFlingerModule cfm = new CompiledFlingerModule(null, moduleItemStack); speedField = new FloatTextField(font, leftPos + 152, topPos + 19, 35, 12, @@ -62,8 +61,6 @@ public void init() { addRenderableWidget(pitchField); addRenderableWidget(yawField); -// manager.focus(1); // field 0 is the regulator amount textfield - getMouseOverHelp().addHelpRegion(leftPos + 128, topPos + 13, leftPos + 186, topPos + 32, "modularrouters.guiText.popup.flinger.speed"); getMouseOverHelp().addHelpRegion(leftPos + 128, topPos + 31, leftPos + 186, topPos + 50, "modularrouters.guiText.popup.flinger.pitch"); getMouseOverHelp().addHelpRegion(leftPos + 128, topPos + 49, leftPos + 186, topPos + 68, "modularrouters.guiText.popup.flinger.yaw"); @@ -79,12 +76,14 @@ protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, in } @Override - protected CompoundTag buildMessageData() { - return Util.make(super.buildMessageData(), tag -> { - tag.putFloat(CompiledFlingerModule.NBT_SPEED, speedField.getFloatValue()); - tag.putFloat(CompiledFlingerModule.NBT_PITCH, pitchField.getFloatValue()); - tag.putFloat(CompiledFlingerModule.NBT_YAW, yawField.getFloatValue()); - }); + protected ItemStack buildModifiedItemStack() { + return Util.make(super.buildModifiedItemStack(), stack -> + stack.set(ModDataComponents.FLINGER_SETTINGS, new CompiledFlingerModule.FlingerSettings( + speedField.getFloatValue(), + pitchField.getFloatValue(), + yawField.getFloatValue() + )) + ); } private static class TooltipButton extends TexturedButton { diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/FluidModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/FluidModuleScreen.java index b9196c14..88f62dc2 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/FluidModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/FluidModuleScreen.java @@ -9,13 +9,13 @@ import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; import me.desht.modularrouters.core.ModBlocks; -import me.desht.modularrouters.item.module.FluidModule1.FluidDirection; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.logic.compiled.CompiledFluidModule1; +import me.desht.modularrouters.logic.settings.TransferDirection; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.sounds.SoundManager; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.entity.player.Inventory; @@ -29,7 +29,7 @@ import static me.desht.modularrouters.client.util.ClientUtil.xlate; -public class FluidModuleScreen extends AbstractModuleScreen { +public class FluidModuleScreen extends ModuleScreen { private static final ItemStack bucketStack = new ItemStack(Items.BUCKET); private static final ItemStack routerStack = new ItemStack(ModBlocks.MODULAR_ROUTER.get()); private static final ItemStack waterStack = new ItemStack(Items.WATER_BUCKET); @@ -106,17 +106,19 @@ public void containerTick() { regulationTypeButton.visible = regulatorTextField.visible; regulationTypeButton.setText(); regulatorTextField.setRange(Range.of(0, regulationTypeButton.regulateAbsolute ? Integer.MAX_VALUE : 100)); - forceEmptyButton.visible = fluidDirButton.getState() == FluidDirection.OUT; + forceEmptyButton.visible = fluidDirButton.getState() == TransferDirection.FROM_ROUTER; } @Override - protected CompoundTag buildMessageData() { - return Util.make(super.buildMessageData(), compound -> { - compound.putInt(CompiledFluidModule1.NBT_MAX_TRANSFER, maxTransferField.getIntValue()); - compound.putByte(CompiledFluidModule1.NBT_FLUID_DIRECTION, (byte) fluidDirButton.getState().ordinal()); - compound.putBoolean(CompiledFluidModule1.NBT_FORCE_EMPTY, forceEmptyButton.isToggled()); - compound.putBoolean(CompiledFluidModule1.NBT_REGULATE_ABSOLUTE, regulationTypeButton.regulateAbsolute); - }); + protected ItemStack buildModifiedItemStack() { + return Util.make(super.buildModifiedItemStack(), stack -> + stack.set(ModDataComponents.FLUID_SETTINGS, new CompiledFluidModule1.FluidModuleSettings( + maxTransferField.getIntValue(), + fluidDirButton.getState(), + forceEmptyButton.isToggled(), + regulationTypeButton.regulateAbsolute + )) + ); } private class TooltipButton extends ItemStackButton { @@ -147,8 +149,8 @@ private void toggleRegulationType() { sendToServer(); } - private class FluidDirectionButton extends TexturedCyclerButton { - FluidDirectionButton(int x, int y, FluidDirection initialVal) { + private class FluidDirectionButton extends TexturedCyclerButton { + FluidDirectionButton(int x, int y, TransferDirection initialVal) { super(x, y, 16, 16, initialVal, FluidModuleScreen.this); } diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/AbstractModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/ModuleScreen.java similarity index 74% rename from src/main/java/me/desht/modularrouters/client/gui/module/AbstractModuleScreen.java rename to src/main/java/me/desht/modularrouters/client/gui/module/ModuleScreen.java index 15899311..d8663c97 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/AbstractModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/ModuleScreen.java @@ -15,28 +15,23 @@ import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; import me.desht.modularrouters.core.ModBlockEntities; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.item.augment.AugmentItem; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.item.module.ModuleItem.ModuleFlags; -import me.desht.modularrouters.item.module.ModuleItem.RelativeDirection; -import me.desht.modularrouters.item.module.ModuleItem.Termination; import me.desht.modularrouters.item.smartfilter.SmartFilterItem; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.*; import me.desht.modularrouters.network.messages.ModuleSettingsMessage; import me.desht.modularrouters.network.messages.OpenGuiMessage; import me.desht.modularrouters.util.MFLocator; -import me.desht.modularrouters.util.ModuleHelper; import net.minecraft.ChatFormatting; -import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.sounds.SoundManager; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; @@ -56,7 +51,7 @@ import static me.desht.modularrouters.client.util.ClientUtil.xlate; -public class AbstractModuleScreen extends AbstractContainerScreen implements ContainerListener, IMouseOverHelpProvider, ISendToServer { +public class ModuleScreen extends AbstractContainerScreen implements ContainerListener, IMouseOverHelpProvider, ISendToServer { static final ResourceLocation GUI_TEXTURE = new ResourceLocation(ModularRouters.MODID, "textures/gui/module.png"); // locations of extra textures on the gui module texture sheet @@ -74,40 +69,44 @@ public class AbstractModuleScreen extends AbstractContainerScreen im private final BlockPos routerPos; private final int moduleSlotIndex; private final InteractionHand hand; - private RelativeDirection facing; + private final ModuleSettings settings; private int sendDelay; - private int regulatorAmount; private final MouseOverHelp mouseOverHelp; final AugmentItem.AugmentCounter augmentCounter; - private final boolean matchAll; + private int regulatorAmount; + private RelativeDirection facing; private RedstoneBehaviourButton redstoneButton; private RegulatorTooltipButton regulatorTooltipButton; private final EnumMap directionButtons = new EnumMap<>(RelativeDirection.class); - private final EnumMap toggleButtons = new EnumMap<>(ModuleFlags.class); private MouseOverHelp.Button mouseOverHelpButton; private TexturedToggleButton matchAllButton; IntegerTextField regulatorTextField; private TerminationButton terminationButton; + private ModuleToggleButton whiteListButton; + private ModuleToggleButton matchDamageButton; + private ModuleToggleButton matchCompButton; + private ModuleToggleButton matchItemTagButton; - public AbstractModuleScreen(ModuleMenu container, Inventory inventory, Component displayName) { + public ModuleScreen(ModuleMenu container, Inventory inventory, Component displayName) { super(container, inventory, displayName); MFLocator locator = container.getLocator(); - this.moduleSlotIndex = locator.routerSlot(); - this.hand = locator.hand(); - this.routerPos = locator.routerPos(); - this.moduleItemStack = locator.getModuleStack(inventory.player); + moduleSlotIndex = locator.routerSlot(); + hand = locator.hand(); + routerPos = locator.routerPos(); + moduleItemStack = locator.getModuleStack(inventory.player); + + module = (ModuleItem) moduleItemStack.getItem(); - this.module = (ModuleItem) moduleItemStack.getItem(); + settings = ModuleItem.getCommonSettings(moduleItemStack); + regulatorAmount = settings.regulatorAmount(); + facing = settings.facing(); - this.facing = ModuleHelper.getRelativeDirection(moduleItemStack); - this.regulatorAmount = ModuleHelper.getRegulatorAmount(moduleItemStack); - this.augmentCounter = new AugmentItem.AugmentCounter(moduleItemStack); - this.matchAll = ModuleHelper.isMatchAll(moduleItemStack); - this.imageWidth = GUI_WIDTH; - this.imageHeight = GUI_HEIGHT; - this.mouseOverHelp = new MouseOverHelp(this); + augmentCounter = new AugmentItem.AugmentCounter(moduleItemStack); + imageWidth = GUI_WIDTH; + imageHeight = GUI_HEIGHT; + mouseOverHelp = new MouseOverHelp(this); NeoForge.EVENT_BUS.addListener(this::onInitGui); } @@ -116,12 +115,13 @@ public AbstractModuleScreen(ModuleMenu container, Inventory inventory, Component public void init() { super.init(); - addToggleButton(ModuleFlags.BLACKLIST, 7, 75); - addToggleButton(ModuleFlags.IGNORE_DAMAGE, 7, 93); - addToggleButton(ModuleFlags.IGNORE_NBT, 25, 75); - addToggleButton(ModuleFlags.IGNORE_TAGS, 25, 93); - terminationButton = addRenderableWidget(new TerminationButton(leftPos + 45, topPos + 93, ModuleHelper.getTermination(moduleItemStack))); - matchAllButton = addRenderableWidget(new MatchAllButton(leftPos + 45, topPos + 75, matchAll)); + whiteListButton = addToggleButton(7, 75, settings.flags().whiteList(), "whitelist", 0, 32); + matchDamageButton = addToggleButton(7, 93, settings.flags().matchDamage(), "match_damage", 32, 32); + matchCompButton = addToggleButton(25, 75, settings.flags().matchComponents(), "match_components", 64, 32); + matchItemTagButton = addToggleButton(25, 93, settings.flags().matchComponents(), "match_item_tag", 96, 32); + matchAllButton = addToggleButton(45, 75, settings.flags().matchAllItems(), "match_all", 208, 16); + + terminationButton = addRenderableWidget(new TerminationButton(leftPos + 45, topPos + 93, settings.termination())); if (module.isDirectional()) { addDirectionButton(RelativeDirection.NONE, 70, 18); @@ -135,14 +135,14 @@ public void init() { mouseOverHelpButton = addRenderableWidget(new MouseOverHelp.Button(leftPos + 175, topPos + 1)); - redstoneButton = addRenderableWidget(new RedstoneBehaviourButton(this.leftPos + 170, this.topPos + 93, BUTTON_WIDTH, BUTTON_HEIGHT, - ModuleHelper.getRedstoneBehaviour(moduleItemStack), this)); + redstoneButton = addRenderableWidget(new RedstoneBehaviourButton(leftPos + 170, topPos + 93, BUTTON_WIDTH, BUTTON_HEIGHT, + ModuleItem.getRedstoneBehaviour(moduleItemStack), this)); regulatorTextField = addRenderableWidget(buildRegulationTextField()); regulatorTooltipButton = addRenderableWidget(new RegulatorTooltipButton(regulatorTextField.getX() - 16, regulatorTextField.getY() - 2, module.isFluidModule())); if (routerPos != null) { - addRenderableWidget(new BackButton(leftPos + 2, topPos + 1, p -> PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openRouter(menu.getLocator())))); + addRenderableWidget(new BackButton(leftPos + 2, topPos + 1, p -> PacketDistributor.sendToServer(OpenGuiMessage.openRouter(menu.getLocator())))); } mouseOverHelp.addHelpRegion(leftPos + 7, topPos + 16, leftPos + 60, topPos + 69, "modularrouters.guiText.popup.filter"); @@ -183,15 +183,16 @@ public void setRegulatorAmount(int regulatorAmount) { } protected void setupButtonVisibility() { - redstoneButton.visible = augmentCounter.getAugmentCount(ModItems.REDSTONE_AUGMENT.get()) > 0; + redstoneButton.visible = augmentCounter.getAugmentCount(ModItems.REDSTONE_AUGMENT) > 0; - regulatorTooltipButton.visible = augmentCounter.getAugmentCount(ModItems.REGULATOR_AUGMENT.get()) > 0; + regulatorTooltipButton.visible = augmentCounter.getAugmentCount(ModItems.REGULATOR_AUGMENT) > 0; regulatorTextField.setVisible(regulatorTooltipButton.visible); } - private void addToggleButton(ModuleFlags flag, int x, int y) { - toggleButtons.put(flag, new ModuleToggleButton(flag, this.leftPos + x, this.topPos + y, ModuleHelper.checkFlag(moduleItemStack, flag))); - addRenderableWidget(toggleButtons.get(flag)); + private ModuleToggleButton addToggleButton(int x, int y, boolean toggled, String name, int texX, int texY) { + var btn = new ModuleToggleButton(this.leftPos + x, this.topPos + y, toggled, name, texX, texY); + addRenderableWidget(btn); + return btn; } private void addDirectionButton(RelativeDirection dir, int x, int y) { @@ -219,28 +220,33 @@ void sendModuleSettingsDelayed(int delay) { @Override public void sendToServer() { - PacketDistributor.SERVER.noArg().send(new ModuleSettingsMessage(menu.getLocator(), buildMessageData())); + PacketDistributor.sendToServer(new ModuleSettingsMessage(menu.getLocator(), buildModifiedItemStack())); } /** - * Encode the message data to be sent to the server in {@link ModuleSettingsMessage}. This NBT data will - * be copied directly into the module itemstack's NBT when the server receives the packet. - * Overriding subclasses must call the superclass method! + * Build the updated item stack to be sent to the server. Components in this item stack will be copied + * into the server-side item, after validation. + *

+ * Important: Overriding subclasses must call this superclass method! * * @return the message data NBT */ - protected CompoundTag buildMessageData() { - RouterRedstoneBehaviour behaviour = redstoneButton == null ? RouterRedstoneBehaviour.ALWAYS : redstoneButton.getState(); - return Util.make(new CompoundTag(), tag -> { - for (ModuleFlags flag : ModuleFlags.values()) { - tag.putBoolean(flag.getName(), toggleButtons.get(flag).isToggled()); - } - tag.putString(ModuleHelper.NBT_TERMINATION, terminationButton.getState().toString()); - tag.putString(ModuleHelper.NBT_DIRECTION, facing.toString()); - tag.putByte(ModuleHelper.NBT_REDSTONE_MODE, (byte) behaviour.ordinal()); - tag.putInt(ModuleHelper.NBT_REGULATOR_AMOUNT, regulatorAmount); - tag.putBoolean(ModuleHelper.NBT_MATCH_ALL, matchAllButton.isToggled()); - }); + protected ItemStack buildModifiedItemStack() { + ItemStack stack = moduleItemStack.copy(); + stack.set(ModDataComponents.COMMON_MODULE_SETTINGS, new ModuleSettings( + new ModuleFlags( + whiteListButton.isToggled(), + matchDamageButton.isToggled(), + matchCompButton.isToggled(), + matchItemTagButton.isToggled(), + matchAllButton.isToggled() + ), + facing, + terminationButton.getState(), + redstoneButton == null ? RedstoneBehaviour.ALWAYS : redstoneButton.getState(), + regulatorAmount + )); + return stack; } @Override @@ -278,7 +284,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { // Intercept ESC/E and immediately reopen the router GUI - this avoids an // annoying screen flicker between closing the module GUI and reopen the router GUI. // Sending the reopen message will also close this gui, triggering onGuiClosed() - PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openRouter(menu.getLocator())); + PacketDistributor.sendToServer(OpenGuiMessage.openRouter(menu.getLocator())); return true; } else if (ClientSetup.keybindConfigure.getKey().getValue() == keyCode) { // trying to configure an installed smart filter, we're done @@ -303,7 +309,7 @@ private boolean handleFilterConfig() { // module is installed in a router MFLocator locator = MFLocator.filterInInstalledModule(routerPos, moduleSlotIndex, filterSlotIndex); if (filter.hasMenu()) { - PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openFilterInInstalledModule(locator)); + PacketDistributor.sendToServer(OpenGuiMessage.openFilterInInstalledModule(locator)); } else { // no container, just open the client-side GUI directly FilterScreenFactory.openFilterGui(locator); @@ -312,7 +318,7 @@ private boolean handleFilterConfig() { // module is in player's hand MFLocator locator = MFLocator.filterInHeldModule(hand, filterSlotIndex); if (filter.hasMenu()) { - PacketDistributor.SERVER.noArg().send(OpenGuiMessage.openFilterInHeldModule(locator)); + PacketDistributor.sendToServer(OpenGuiMessage.openFilterInHeldModule(locator)); } else { // no container, just open the client-side GUI directly FilterScreenFactory.openFilterGui(locator); @@ -350,8 +356,8 @@ private int getFgColor(TintColor bg) { // calculate a foreground color which suitably contrasts with the given background color int luminance = (int) Math.sqrt( bg.getRed() * bg.getRed() * 0.241 + - bg.getGreen() * bg.getGreen() * 0.691 + - bg.getBlue() * bg.getBlue() * 0.068 + bg.getGreen() * bg.getGreen() * 0.691 + + bg.getBlue() * bg.getBlue() * 0.068 ); return luminance > THRESHOLD ? 0x404040 : 0xffffff; } @@ -388,17 +394,19 @@ public void playDownSound(SoundManager soundHandlerIn) { } private class ModuleToggleButton extends TexturedToggleButton { - private final ModuleFlags flag; - - ModuleToggleButton(ModuleFlags flag, int x, int y, boolean toggled) { - super(x, y, BUTTON_WIDTH, BUTTON_HEIGHT, toggled, AbstractModuleScreen.this); - this.flag = flag; - setTooltips(xlate("modularrouters.guiText.tooltip." + flag + ".1"), xlate("modularrouters.guiText.tooltip." + flag + ".2")); + private final int texX; + private final int texY; + + ModuleToggleButton(int x, int y, boolean toggled, String name, int texX, int texY) { + super(x, y, BUTTON_WIDTH, BUTTON_HEIGHT, toggled, ModuleScreen.this); + this.texX = texX; + this.texY = texY; + setTooltips(xlate("modularrouters.guiText.tooltip." + name + ".false"), xlate("modularrouters.guiText.tooltip." + name + ".true")); } @Override protected XYPoint getTextureXY() { - return new XYPoint(flag.ordinal() * BUTTON_WIDTH * 2 + (isToggled() ? BUTTON_WIDTH : 0), flag.getTextureY()); + return new XYPoint(isToggled() ? texX : texX + 16, texY); } } @@ -407,7 +415,7 @@ private class DirectionButton extends RadioButton { private final RelativeDirection direction; DirectionButton(RelativeDirection dir, ModuleItem module, int x, int y, boolean toggled) { - super(DIRECTION_GROUP, x, y, BUTTON_WIDTH, BUTTON_HEIGHT, toggled, AbstractModuleScreen.this); + super(DIRECTION_GROUP, x, y, BUTTON_WIDTH, BUTTON_HEIGHT, toggled, ModuleScreen.this); this.direction = dir; setTooltips(module.getDirectionString(dir).withStyle(ChatFormatting.GRAY), module.getDirectionString(dir).withStyle(ChatFormatting.YELLOW)); @@ -436,28 +444,13 @@ public void onPress() { } } - private class MatchAllButton extends TexturedToggleButton { - private static final XYPoint TEXTURE_XY = new XYPoint(208, 16); - private static final XYPoint TEXTURE_XY_TOGGLED = new XYPoint(224, 16); - - MatchAllButton(int x, int y, boolean toggled) { - super(x, y, 16, 16, toggled, AbstractModuleScreen.this); - setTooltips(xlate("modularrouters.guiText.tooltip.matchAll.false"), xlate("modularrouters.guiText.tooltip.matchAll.true")); - } - - @Override - protected XYPoint getTextureXY() { - return isToggled() ? TEXTURE_XY_TOGGLED : TEXTURE_XY; - } - } - - private class TerminationButton extends TexturedCyclerButton { - public TerminationButton(int x, int y, Termination initialVal) { - super(x, y, 16, 16, initialVal, AbstractModuleScreen.this); + private class TerminationButton extends TexturedCyclerButton { + public TerminationButton(int x, int y, ModuleTermination initialVal) { + super(x, y, 16, 16, initialVal, ModuleScreen.this); } @Override - protected Tooltip makeTooltip(Termination termination) { + protected Tooltip makeTooltip(ModuleTermination termination) { return Tooltip.create(xlate(termination.getTranslationKey() + ".header").append("\n").append(xlate(termination.getTranslationKey()))); } diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/PlayerModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/PlayerModuleScreen.java index 08def034..5294b06e 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/PlayerModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/PlayerModuleScreen.java @@ -5,19 +5,19 @@ import me.desht.modularrouters.client.util.XYPoint; import me.desht.modularrouters.container.ModuleMenu; import me.desht.modularrouters.core.ModBlocks; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.logic.compiled.CompiledPlayerModule; -import me.desht.modularrouters.logic.compiled.CompiledPlayerModule.Operation; import me.desht.modularrouters.logic.compiled.CompiledPlayerModule.Section; +import me.desht.modularrouters.logic.settings.TransferDirection; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Blocks; -public class PlayerModuleScreen extends AbstractModuleScreen { +public class PlayerModuleScreen extends ModuleScreen { private static final ItemStack MAIN_INV_STACK = new ItemStack(Blocks.CHEST); private static final ItemStack MAIN_NO_HOTBAR_INV_STACK = new ItemStack(Blocks.BARREL); private static final ItemStack ARMOUR_STACK = new ItemStack(Items.DIAMOND_CHESTPLATE); @@ -30,7 +30,7 @@ public class PlayerModuleScreen extends AbstractModuleScreen { }; private ItemStackCyclerButton

secButton; - private OperationButton opButton; + private TransferDirectionButton dirButton; public PlayerModuleScreen(ModuleMenu container, Inventory inv, Component displayName) { super(container, inv, displayName); @@ -40,10 +40,9 @@ public PlayerModuleScreen(ModuleMenu container, Inventory inv, Component display public void init() { super.init(); - CompiledPlayerModule cpm = new CompiledPlayerModule(null, moduleItemStack); - - addRenderableWidget(secButton = new ItemStackCyclerButton<>(leftPos + 169, topPos + 32, 16, 16, true, STACKS, cpm.getSection(), this)); - addRenderableWidget(opButton = new OperationButton(leftPos + 148, topPos + 32, cpm.getOperation())); + CompiledPlayerModule.PlayerSettings settings = moduleItemStack.get(ModDataComponents.PLAYER_SETTINGS); + addRenderableWidget(secButton = new ItemStackCyclerButton<>(leftPos + 169, topPos + 32, 16, 16, true, STACKS, settings.section(), this)); + addRenderableWidget(dirButton = new TransferDirectionButton(leftPos + 148, topPos + 32, settings.direction())); getMouseOverHelp().addHelpRegion(leftPos + 127, topPos + 29, leftPos + 187, topPos + 50, "modularrouters.guiText.popup.player.control"); } @@ -58,15 +57,17 @@ protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, in } @Override - protected CompoundTag buildMessageData() { - return Util.make(super.buildMessageData(), compound -> { - compound.putInt(CompiledPlayerModule.NBT_OPERATION, opButton.getState().ordinal()); - compound.putInt(CompiledPlayerModule.NBT_SECTION, secButton.getState().ordinal()); - }); + protected ItemStack buildModifiedItemStack() { + return Util.make(super.buildModifiedItemStack(), stack -> + stack.set(ModDataComponents.PLAYER_SETTINGS, new CompiledPlayerModule.PlayerSettings( + dirButton.getState(), + secButton.getState() + )) + ); } - private class OperationButton extends TexturedCyclerButton { - OperationButton(int x, int y, Operation initialVal) { + private class TransferDirectionButton extends TexturedCyclerButton { + TransferDirectionButton(int x, int y, TransferDirection initialVal) { super(x, y, 16, 16, initialVal, PlayerModuleScreen.this); } diff --git a/src/main/java/me/desht/modularrouters/client/gui/module/VacuumModuleScreen.java b/src/main/java/me/desht/modularrouters/client/gui/module/VacuumModuleScreen.java index 3f8c744b..b7d8a9ad 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/module/VacuumModuleScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/module/VacuumModuleScreen.java @@ -4,15 +4,15 @@ import me.desht.modularrouters.client.gui.widgets.button.TexturedToggleButton; import me.desht.modularrouters.client.util.XYPoint; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.integration.XPCollection.XPCollectionType; -import me.desht.modularrouters.logic.compiled.CompiledVacuumModule; +import me.desht.modularrouters.logic.compiled.CompiledVacuumModule.VacuumSettings; import me.desht.modularrouters.util.ModNameCache; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; @@ -21,7 +21,7 @@ import static me.desht.modularrouters.client.util.ClientUtil.xlate; -public class VacuumModuleScreen extends AbstractModuleScreen { +public class VacuumModuleScreen extends ModuleScreen { private XPTypeButton xpb; private EjectButton ejb; @@ -33,14 +33,16 @@ public VacuumModuleScreen(ModuleMenu container, Inventory inv, Component display public void init() { super.init(); - CompiledVacuumModule vac = new CompiledVacuumModule(null, moduleItemStack); + VacuumSettings settings = moduleItemStack.getOrDefault(ModDataComponents.VACUUM_SETTINGS, VacuumSettings.DEFAULT); ItemStack[] icons = Arrays.stream(XPCollectionType.values()).map(XPCollectionType::getIcon).toArray(ItemStack[]::new); - addRenderableWidget(xpb = new XPTypeButton(leftPos + 127, topPos + 30, 20, 20, false, icons, vac.getXPCollectionType())); - addRenderableWidget(ejb = new EjectButton(leftPos + 127, topPos + 64, vac.isAutoEjecting())); + addRenderableWidget(xpb = new XPTypeButton(leftPos + 127, topPos + 30, 20, 20, false, icons, settings.collectionType())); + addRenderableWidget(ejb = new EjectButton(leftPos + 127, topPos + 64, settings.autoEject())); - getMouseOverHelp().addHelpRegion(leftPos + 125, topPos + 16, leftPos + 187, topPos + 52, "modularrouters.guiText.popup.xpVacuum", guiContainer -> xpb.visible); - getMouseOverHelp().addHelpRegion(leftPos + 125, topPos + 52, leftPos + 187, topPos + 88, "modularrouters.guiText.popup.xpVacuum.eject", guiContainer -> xpb.visible && ejb.visible); + getMouseOverHelp().addHelpRegion(leftPos + 125, topPos + 16, leftPos + 187, topPos + 52, + "modularrouters.guiText.popup.xpVacuum", guiContainer -> xpb.visible); + getMouseOverHelp().addHelpRegion(leftPos + 125, topPos + 52, leftPos + 187, topPos + 88, + "modularrouters.guiText.popup.xpVacuum.eject", guiContainer -> xpb.visible && ejb.visible); } @Override @@ -63,11 +65,13 @@ protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { } @Override - protected CompoundTag buildMessageData() { - return Util.make(super.buildMessageData(), compound -> { - compound.putInt(CompiledVacuumModule.NBT_XP_FLUID_TYPE, xpb.getState().ordinal()); - compound.putBoolean(CompiledVacuumModule.NBT_AUTO_EJECT, ejb.isToggled()); - }); + protected ItemStack buildModifiedItemStack() { + return Util.make(super.buildModifiedItemStack(), stack -> + stack.set(ModDataComponents.VACUUM_SETTINGS, new VacuumSettings( + ejb.isToggled(), + xpb.getState() + )) + ); } private class XPTypeButton extends ItemStackCyclerButton { diff --git a/src/main/java/me/desht/modularrouters/client/gui/upgrade/SyncUpgradeScreen.java b/src/main/java/me/desht/modularrouters/client/gui/upgrade/SyncUpgradeScreen.java index 0452014d..c57dda45 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/upgrade/SyncUpgradeScreen.java +++ b/src/main/java/me/desht/modularrouters/client/gui/upgrade/SyncUpgradeScreen.java @@ -89,7 +89,7 @@ public boolean isPauseScreen() { public void onClose() { int newVal = intField.getIntValue(); if (currentVal != newVal) { - PacketDistributor.SERVER.noArg().send(new SyncUpgradeSettingsMessage(newVal, hand)); + PacketDistributor.sendToServer(new SyncUpgradeSettingsMessage(newVal, hand)); } super.onClose(); diff --git a/src/main/java/me/desht/modularrouters/client/gui/widgets/button/RedstoneBehaviourButton.java b/src/main/java/me/desht/modularrouters/client/gui/widgets/button/RedstoneBehaviourButton.java index 085585d3..9ffacfd3 100644 --- a/src/main/java/me/desht/modularrouters/client/gui/widgets/button/RedstoneBehaviourButton.java +++ b/src/main/java/me/desht/modularrouters/client/gui/widgets/button/RedstoneBehaviourButton.java @@ -2,14 +2,14 @@ import me.desht.modularrouters.client.gui.ISendToServer; import me.desht.modularrouters.client.util.XYPoint; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; +import me.desht.modularrouters.logic.settings.RedstoneBehaviour; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.components.Tooltip; import static me.desht.modularrouters.client.util.ClientUtil.xlate; -public class RedstoneBehaviourButton extends TexturedCyclerButton { - public RedstoneBehaviourButton(int x, int y, int width, int height, RouterRedstoneBehaviour initialVal, ISendToServer dataSyncer) { +public class RedstoneBehaviourButton extends TexturedCyclerButton { + public RedstoneBehaviourButton(int x, int y, int width, int height, RedstoneBehaviour initialVal, ISendToServer dataSyncer) { super(x, y, width, height, initialVal, dataSyncer); } @@ -19,7 +19,7 @@ protected XYPoint getTextureXY() { } @Override - protected Tooltip makeTooltip(RouterRedstoneBehaviour behaviour) { + protected Tooltip makeTooltip(RedstoneBehaviour behaviour) { return Tooltip.create(xlate("modularrouters.guiText.tooltip.redstone.label") .append(": ").append(xlate(behaviour.getTranslationKey()).withStyle(ChatFormatting.YELLOW))); } diff --git a/src/main/java/me/desht/modularrouters/client/render/area/ModuleTargetRenderer.java b/src/main/java/me/desht/modularrouters/client/render/area/ModuleTargetRenderer.java index ab3fab56..d7af0eca 100644 --- a/src/main/java/me/desht/modularrouters/client/render/area/ModuleTargetRenderer.java +++ b/src/main/java/me/desht/modularrouters/client/render/area/ModuleTargetRenderer.java @@ -13,8 +13,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec3; import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.client.event.ClientTickEvent; import net.neoforged.neoforge.client.event.RenderLevelStageEvent; -import net.neoforged.neoforge.event.TickEvent; import org.joml.Matrix4f; import java.util.BitSet; @@ -30,8 +30,8 @@ public class ModuleTargetRenderer { private static CompiledPosition compiledPos = null; @SubscribeEvent - public static void clientTick(TickEvent.ClientTickEvent event) { - if (event.phase == TickEvent.Phase.START && Minecraft.getInstance().player != null) { + public static void clientTick(ClientTickEvent.Pre event) { + if (Minecraft.getInstance().player != null) { ItemStack curItem = Minecraft.getInstance().player.getMainHandItem(); if (!ItemStack.matches(curItem, lastStack)) { lastStack = curItem.copy(); diff --git a/src/main/java/me/desht/modularrouters/client/render/blockentity/ModularRouterBER.java b/src/main/java/me/desht/modularrouters/client/render/blockentity/ModularRouterBER.java index e973a9db..a3b5d8ec 100644 --- a/src/main/java/me/desht/modularrouters/client/render/blockentity/ModularRouterBER.java +++ b/src/main/java/me/desht/modularrouters/client/render/blockentity/ModularRouterBER.java @@ -128,7 +128,7 @@ private void renderFlyingItem(BeamData beam, PoseStack matrixStack, MultiBufferS matrixStack.pushPose(); matrixStack.translate(ix, iy - 0.15, iz); matrixStack.mulPose(Axis.of(ROTATION).rotationDegrees(progress * 360)); - if (beam.isItemFade()) { + if (beam.fade()) { matrixStack.translate(0, 0.15, 0); matrixStack.scale(1.15f - progress, 1.15f - progress, 1.15f - progress); if (progress > 0.95 && world.random.nextInt(3) == 0) { @@ -136,7 +136,7 @@ private void renderFlyingItem(BeamData beam, PoseStack matrixStack, MultiBufferS } } Minecraft.getInstance().getItemRenderer() - .renderStatic(beam.getStack(), ItemDisplayContext.GROUND, 0x00F000F0, OverlayTexture.NO_OVERLAY, matrixStack, buffer, world, 0); + .renderStatic(beam.stack(), ItemDisplayContext.GROUND, 0x00F000F0, OverlayTexture.NO_OVERLAY, matrixStack, buffer, world, 0); matrixStack.popPose(); } } @@ -153,21 +153,21 @@ private void renderBeamLine(BeamData beam, PoseStack matrixStack, MultiBufferSou VertexConsumer builder = buffer.getBuffer(ModRenderTypes.BEAM_LINE_THICK); ClientUtil.posF(builder, positionMatrix, startPos) .color(colors[0], colors[1], colors[2], alpha) - .normal(matrixStack.last().normal(), xn, yn, zn) + .normal(matrixStack.last(), xn, yn, zn) .endVertex(); ClientUtil.posF(builder, positionMatrix, endPos) .color(colors[0], colors[1], colors[2], alpha) - .normal(matrixStack.last().normal(), xn, yn, zn) + .normal(matrixStack.last(), xn, yn, zn) .endVertex(); VertexConsumer builder2 = buffer.getBuffer(ModRenderTypes.BEAM_LINE_THIN); ClientUtil.posF(builder2, positionMatrix, startPos) .color(colors[0], colors[1], colors[2], 192) - .normal(matrixStack.last().normal(), xn, yn, zn) + .normal(matrixStack.last(), xn, yn, zn) .endVertex(); ClientUtil.posF(builder2, positionMatrix, endPos) .color(colors[0], colors[1], colors[2], 192) - .normal(matrixStack.last().normal(), xn, yn, zn) + .normal(matrixStack.last(), xn, yn, zn) .endVertex(); } diff --git a/src/main/java/me/desht/modularrouters/client/util/ClientUtil.java b/src/main/java/me/desht/modularrouters/client/util/ClientUtil.java index 4f40117b..9a154015 100644 --- a/src/main/java/me/desht/modularrouters/client/util/ClientUtil.java +++ b/src/main/java/me/desht/modularrouters/client/util/ClientUtil.java @@ -3,6 +3,7 @@ import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.vertex.VertexConsumer; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.client.gui.IResyncableGui; import me.desht.modularrouters.client.gui.ModularRouterScreen; import net.minecraft.ChatFormatting; import net.minecraft.client.KeyMapping; @@ -16,6 +17,7 @@ import net.minecraft.network.chat.MutableComponent; import net.minecraft.util.FormattedCharSequence; import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import org.joml.Matrix4f; @@ -37,6 +39,12 @@ public static Optional getOpenItemRouter() { } } + public static void resyncGui(ItemStack stack) { + if (Minecraft.getInstance().screen instanceof IResyncableGui syncable) { + syncable.resync(stack); + } + } + public static MutableComponent xlate(String key, Object... args) { return Component.translatable(key, args); } diff --git a/src/main/java/me/desht/modularrouters/config/ConfigHolder.java b/src/main/java/me/desht/modularrouters/config/ConfigHolder.java index 357aea2a..cd47f3a1 100644 --- a/src/main/java/me/desht/modularrouters/config/ConfigHolder.java +++ b/src/main/java/me/desht/modularrouters/config/ConfigHolder.java @@ -2,6 +2,7 @@ import me.desht.modularrouters.ModularRouters; import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.event.config.ModConfigEvent; @@ -14,7 +15,7 @@ public class ConfigHolder { private static ModConfigSpec configCommonSpec; private static ModConfigSpec configClientSpec; - public static void init(IEventBus modBus) { + public static void init(ModContainer container, IEventBus modBus) { final Pair spec1 = new ModConfigSpec.Builder().configure(ClientConfig::new); client = spec1.getLeft(); configClientSpec = spec1.getRight(); @@ -23,8 +24,8 @@ public static void init(IEventBus modBus) { common = spec2.getLeft(); configCommonSpec = spec2.getRight(); - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigHolder.configCommonSpec); - ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigHolder.configClientSpec); + container.registerConfig(ModConfig.Type.COMMON, ConfigHolder.configCommonSpec); + container.registerConfig(ModConfig.Type.CLIENT, ConfigHolder.configClientSpec); modBus.addListener(ConfigHolder::onConfigChanged); } diff --git a/src/main/java/me/desht/modularrouters/container/AbstractMRContainerMenu.java b/src/main/java/me/desht/modularrouters/container/AbstractMRContainerMenu.java index 7fd6a4c4..ec45c009 100644 --- a/src/main/java/me/desht/modularrouters/container/AbstractMRContainerMenu.java +++ b/src/main/java/me/desht/modularrouters/container/AbstractMRContainerMenu.java @@ -37,7 +37,7 @@ protected boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, Slot slot = this.slots.get(i); ItemStack itemstack = slot.getItem(); - if (!itemstack.isEmpty() && ItemStack.isSameItemSameTags(stack, itemstack)) { + if (!itemstack.isEmpty() && ItemStack.isSameItemSameComponents(stack, itemstack)) { int j = itemstack.getCount() + stack.getCount(); // modified HERE int maxSize = Math.min(slot.getMaxStackSize(itemstack), Math.min(slot.getMaxStackSize(), stack.getMaxStackSize())); diff --git a/src/main/java/me/desht/modularrouters/container/BulkItemFilterMenu.java b/src/main/java/me/desht/modularrouters/container/BulkItemFilterMenu.java index 329c8a76..2b2ade97 100644 --- a/src/main/java/me/desht/modularrouters/container/BulkItemFilterMenu.java +++ b/src/main/java/me/desht/modularrouters/container/BulkItemFilterMenu.java @@ -1,10 +1,11 @@ package me.desht.modularrouters.container; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity.RecompileFlag; import me.desht.modularrouters.container.handler.BaseModuleHandler.BulkFilterHandler; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.item.smartfilter.BulkItemFilter; -import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.ModuleFlags; import me.desht.modularrouters.util.MFLocator; import me.desht.modularrouters.util.SetofItemStack; import net.minecraft.network.FriendlyByteBuf; @@ -14,7 +15,6 @@ import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.items.IItemHandler; -import net.neoforged.neoforge.items.ItemHandlerHelper; import static me.desht.modularrouters.container.Layout.SLOT_X_SPACING; import static me.desht.modularrouters.container.Layout.SLOT_Y_SPACING; @@ -69,11 +69,11 @@ public void clearSlots() { handler.save(); if (getRouter() != null && !getRouter().getLevel().isClientSide) { - getRouter().recompileNeeded(ModularRouterBlockEntity.COMPILE_MODULES); + getRouter().recompileNeeded(RecompileFlag.MODULES); } } - public int mergeInventory(IItemHandler srcInv, Filter.Flags flags, boolean clearFirst) { + public int mergeInventory(IItemHandler srcInv, ModuleFlags flags, boolean clearFirst) { if (srcInv == null) { return 0; } @@ -83,13 +83,13 @@ public int mergeInventory(IItemHandler srcInv, Filter.Flags flags, boolean clear for (int i = 0; i < srcInv.getSlots() && stacks.size() < handler.getSlots(); i++) { ItemStack stack = srcInv.getStackInSlot(i); if (!stack.isEmpty()) { - stacks.add(ItemHandlerHelper.copyStackWithSize(stack, 1)); + stacks.add(stack.copyWithCount(1)); } } int slot = 0; handler.setAutoSave(false); - for (ItemStack stack : stacks.sortedList()) { + for (ItemStack stack : stacks.sorted()) { handler.setStackInSlot(slot++, stack); } while (slot < handler.getSlots()) { @@ -100,7 +100,7 @@ public int mergeInventory(IItemHandler srcInv, Filter.Flags flags, boolean clear handler.save(); if (getRouter() != null && !getRouter().getLevel().isClientSide) { - getRouter().recompileNeeded(ModularRouterBlockEntity.COMPILE_MODULES); + getRouter().recompileNeeded(RecompileFlag.MODULES); } return stacks.size() - origSize; diff --git a/src/main/java/me/desht/modularrouters/container/Extruder2ModuleMenu.java b/src/main/java/me/desht/modularrouters/container/Extruder2ModuleMenu.java index 8b38951a..e07b2a74 100644 --- a/src/main/java/me/desht/modularrouters/container/Extruder2ModuleMenu.java +++ b/src/main/java/me/desht/modularrouters/container/Extruder2ModuleMenu.java @@ -1,7 +1,9 @@ package me.desht.modularrouters.container; +import com.google.common.collect.ImmutableList; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.container.handler.BaseModuleHandler; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.util.MFLocator; import net.minecraft.core.registries.BuiltInRegistries; @@ -17,6 +19,8 @@ import javax.annotation.Nonnull; +import java.util.List; + import static me.desht.modularrouters.container.Layout.SLOT_X_SPACING; public class Extruder2ModuleMenu extends ModuleMenu { @@ -83,15 +87,28 @@ private static boolean isItemOKForTemplate(ItemStack stack) { } public static class TemplateHandler extends BaseModuleHandler { - private static final String NBT_TEMPLATE = "Template"; - public TemplateHandler(ItemStack holderStack, ModularRouterBlockEntity router) { - super(holderStack, router, TEMPLATE_SLOTS, NBT_TEMPLATE); + super(holderStack, router, TEMPLATE_SLOTS, ModDataComponents.EXTRUDER2_TEMPLATE.get()); } @Override public boolean isItemValid(int slot, @Nonnull ItemStack stack) { return isItemOKForTemplate(stack); } + + public List toTemplate(int rangeLimit) { + ImmutableList.Builder b = new ImmutableList.Builder<>(); + for (int i = 0; i < getSlots() && stacks.size() < rangeLimit; i++) { + ItemStack stack1 = getStackInSlot(i); + if (stack1.isEmpty()) { + break; + } else { + for (int j = 0; j < stack1.getCount() && stacks.size() < rangeLimit; j++) { + b.add(stack1.copyWithCount(1)); + } + } + } + return b.build(); + } } } diff --git a/src/main/java/me/desht/modularrouters/container/ModuleMenu.java b/src/main/java/me/desht/modularrouters/container/ModuleMenu.java index a807d87d..ade340cc 100644 --- a/src/main/java/me/desht/modularrouters/container/ModuleMenu.java +++ b/src/main/java/me/desht/modularrouters/container/ModuleMenu.java @@ -15,7 +15,6 @@ import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.items.ItemHandlerHelper; import net.neoforged.neoforge.items.SlotItemHandler; import static me.desht.modularrouters.container.Layout.SLOT_X_SPACING; @@ -39,11 +38,11 @@ public class ModuleMenu extends AbstractMRContainerMenu { private final MFLocator locator; public ModuleMenu(int windowId, Inventory inv, FriendlyByteBuf extra) { - this(ModMenuTypes.BASE_MODULE_MENU.get(), windowId, inv, MFLocator.fromBuffer(extra)); + this(ModMenuTypes.BASE_MODULE_MENU.get(), windowId, inv, MFLocator.STREAM_CODEC.decode(extra)); } public ModuleMenu(MenuType type, int windowId, Inventory inv, FriendlyByteBuf extra) { - this(type, windowId, inv, MFLocator.fromBuffer(extra)); + this(type, windowId, inv, MFLocator.STREAM_CODEC.decode(extra)); } public ModuleMenu(MenuType type, int windowId, Inventory inv, MFLocator locator) { @@ -179,7 +178,7 @@ public void clicked(int slot, int dragType, ClickType clickTypeIn, Player player Slot s = slots.get(slot); ItemStack stackOnCursor = getCarried(); if (stackOnCursor.isEmpty() || isItemOKForFilter(stackOnCursor, slot)) { - s.set(stackOnCursor.isEmpty() ? ItemStack.EMPTY : ItemHandlerHelper.copyStackWithSize(stackOnCursor, 1)); + s.set(stackOnCursor.isEmpty() ? ItemStack.EMPTY : stackOnCursor.copyWithCount(1)); } return; } else if (slot >= AUGMENT_START && slot < AUGMENT_START + AugmentItem.SLOTS && augmentHandler.getHolderStack().getCount() == 1) { diff --git a/src/main/java/me/desht/modularrouters/container/RouterMenu.java b/src/main/java/me/desht/modularrouters/container/RouterMenu.java index 54537c82..a9abaf4d 100644 --- a/src/main/java/me/desht/modularrouters/container/RouterMenu.java +++ b/src/main/java/me/desht/modularrouters/container/RouterMenu.java @@ -17,7 +17,6 @@ import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.SlotItemHandler; -import java.util.Comparator; import java.util.Map; import static me.desht.modularrouters.container.Layout.SLOT_X_SPACING; diff --git a/src/main/java/me/desht/modularrouters/container/handler/AugmentHandler.java b/src/main/java/me/desht/modularrouters/container/handler/AugmentHandler.java index d24ba9c4..e06cb977 100644 --- a/src/main/java/me/desht/modularrouters/container/handler/AugmentHandler.java +++ b/src/main/java/me/desht/modularrouters/container/handler/AugmentHandler.java @@ -1,10 +1,12 @@ package me.desht.modularrouters.container.handler; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity.RecompileFlag; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.item.augment.AugmentItem; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.util.ModuleHelper; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemContainerContents; import net.neoforged.neoforge.items.ItemStackHandler; import org.apache.commons.lang3.Validate; @@ -21,7 +23,15 @@ public AugmentHandler(ItemStack holderStack, ModularRouterBlockEntity router) { Validate.isTrue(holderStack.getItem() instanceof ModuleItem, "holder stack must be a module!"); this.holderStack = holderStack; - deserializeNBT(ModuleHelper.validateNBT(holderStack).getCompound(ModuleHelper.NBT_AUGMENTS)); + + var augmentStacks = holderStack.getOrDefault(ModDataComponents.AUGMENTS, ItemContainerContents.EMPTY).stream() + .limit(AugmentItem.SLOTS) + .toList(); + for (int i = 0; i < AugmentItem.SLOTS && i < augmentStacks.size(); i++) { + if (augmentStacks.get(i).getItem() instanceof AugmentItem) { + setStackInSlot(i, augmentStacks.get(i)); + } + } } public ItemStack getHolderStack() { @@ -44,11 +54,10 @@ public boolean isItemValid(int slot, @Nonnull ItemStack stack) { @Override protected int getStackLimit(int slot, @Nonnull ItemStack stack) { - if (stack.getItem() instanceof AugmentItem augment) { - return augment.getMaxAugments((ModuleItem) holderStack.getItem()); - } - return 0; -} + return stack.getItem() instanceof AugmentItem augment ? + augment.getMaxAugments((ModuleItem) holderStack.getItem()) : + 0; + } @Override protected void onContentsChanged(int slot) { @@ -56,9 +65,10 @@ protected void onContentsChanged(int slot) { } private void save() { - ModuleHelper.validateNBTForWriting(holderStack).put(ModuleHelper.NBT_AUGMENTS, serializeNBT()); + holderStack.set(ModDataComponents.AUGMENTS, ItemContainerContents.fromItems(stacks)); + if (router != null) { - router.recompileNeeded(ModularRouterBlockEntity.COMPILE_MODULES); + router.recompileNeeded(RecompileFlag.MODULES); } } } diff --git a/src/main/java/me/desht/modularrouters/container/handler/BaseModuleHandler.java b/src/main/java/me/desht/modularrouters/container/handler/BaseModuleHandler.java index 7850e3c9..1593eaf0 100644 --- a/src/main/java/me/desht/modularrouters/container/handler/BaseModuleHandler.java +++ b/src/main/java/me/desht/modularrouters/container/handler/BaseModuleHandler.java @@ -1,30 +1,38 @@ package me.desht.modularrouters.container.handler; -import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.item.smartfilter.BulkItemFilter; import me.desht.modularrouters.logic.filter.Filter; -import me.desht.modularrouters.util.ModuleHelper; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.core.component.DataComponentType; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemContainerContents; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.List; +import java.util.stream.IntStream; public abstract class BaseModuleHandler extends GhostItemHandler { private final ItemStack holderStack; protected final ModularRouterBlockEntity router; - private final String tagName; + private final DataComponentType componentType; private boolean autoSave = true; - public BaseModuleHandler(ItemStack holderStack, ModularRouterBlockEntity router, int size, String tagName) { + public BaseModuleHandler(ItemStack holderStack, ModularRouterBlockEntity router, int size, DataComponentType componentType) { super(size); + this.holderStack = holderStack; this.router = router; - this.tagName = tagName; + this.componentType = componentType; - deserializeNBT(ModuleHelper.validateNBT(holderStack).getCompound(tagName)); + List stackList = holderStack.getOrDefault(componentType, ItemContainerContents.EMPTY).stream() + .limit(size) + .toList(); + for (int i = 0; i < size && i < stackList.size(); i++) { + setStackInSlot(i, stackList.get(i)); + } } public void setAutoSave(boolean autoSave) { @@ -46,7 +54,7 @@ protected void onContentsChanged(int slot) { save(); if (router != null) { - router.recompileNeeded(ModularRouterBlockEntity.COMPILE_MODULES); + router.recompileNeeded(ModularRouterBlockEntity.RecompileFlag.MODULES); } } } @@ -55,30 +63,20 @@ protected void onContentsChanged(int slot) { * Get the number of items in the filter of the given itemstack. Counts the items without loading the NBT for * every item. * - * @param tagName name of the NBT tag the data is under * @return number of items in the filter */ - public static int getFilterSize(ItemStack holderStack, String tagName) { - CompoundTag tag = holderStack.getTagElement(ModularRouters.MODID); - if (tag != null && tag.contains(tagName)) { - ModuleFilterHandler handler = new ModuleFilterHandler(holderStack, null); - int n = 0; - for (int i = 0; i < handler.getSlots(); i++) { - if (!handler.getStackInSlot(i).isEmpty()) { - n++; - } - } - return n; - } else { - return 0; - } + public static int getFilterItemCount(ItemStack holderStack) { + ModuleFilterHandler handler = new ModuleFilterHandler(holderStack, null); + return (int) IntStream.range(0, handler.getSlots()) + .filter(i -> !handler.getStackInSlot(i).isEmpty()) + .count(); } /** * Save the contents of the item handler onto the holder item stack's NBT */ public void save() { - ModuleHelper.validateNBTForWriting(holderStack).put(tagName, serializeNBT()); + holderStack.set(componentType, ItemContainerContents.fromItems(stacks)); } public static class BulkFilterHandler extends BaseModuleHandler { @@ -91,7 +89,8 @@ public BulkFilterHandler(ItemStack holderStack, @Nullable ModularRouterBlockEnti } public BulkFilterHandler(ItemStack holderStack, ModularRouterBlockEntity router, ItemStack moduleStack, int filterSlot, boolean shouldSave) { - super(holderStack, router, BulkItemFilter.FILTER_SIZE, ModuleHelper.NBT_FILTER); + super(holderStack, router, BulkItemFilter.FILTER_SIZE, ModDataComponents.FILTER.get()); + this.moduleStack = moduleStack; this.filterSlot = filterSlot; this.shouldSave = shouldSave; @@ -113,7 +112,7 @@ public void save() { public static class ModuleFilterHandler extends BaseModuleHandler { public ModuleFilterHandler(ItemStack holderStack, @Nullable ModularRouterBlockEntity router) { - super(holderStack, router, Filter.FILTER_SIZE, ModuleHelper.NBT_FILTER); + super(holderStack, router, Filter.FILTER_SIZE, ModDataComponents.FILTER.get()); } @Override diff --git a/src/main/java/me/desht/modularrouters/container/handler/BufferHandler.java b/src/main/java/me/desht/modularrouters/container/handler/BufferHandler.java index 6ca85389..95e1af2d 100644 --- a/src/main/java/me/desht/modularrouters/container/handler/BufferHandler.java +++ b/src/main/java/me/desht/modularrouters/container/handler/BufferHandler.java @@ -2,6 +2,7 @@ import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.core.ModBlocks; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.capabilities.Capabilities; @@ -43,8 +44,8 @@ public void onContentsChanged(int slot) { } @Override - public void deserializeNBT(CompoundTag nbt) { - super.deserializeNBT(nbt); + public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) { + super.deserializeNBT(provider, nbt); setupFluidAndEnergyCaps(); } diff --git a/src/main/java/me/desht/modularrouters/container/handler/GhostItemHandler.java b/src/main/java/me/desht/modularrouters/container/handler/GhostItemHandler.java index 38750dd8..4e04344a 100644 --- a/src/main/java/me/desht/modularrouters/container/handler/GhostItemHandler.java +++ b/src/main/java/me/desht/modularrouters/container/handler/GhostItemHandler.java @@ -12,7 +12,7 @@ public GhostItemHandler(int size) { @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { if (!simulate) { - setStackInSlot(slot, ItemHandlerHelper.copyStackWithSize(stack, 1)); + setStackInSlot(slot, stack.copyWithCount(1)); } return stack; } diff --git a/src/main/java/me/desht/modularrouters/core/ModDataComponents.java b/src/main/java/me/desht/modularrouters/core/ModDataComponents.java new file mode 100644 index 00000000..d18d8ee8 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/core/ModDataComponents.java @@ -0,0 +1,168 @@ +package me.desht.modularrouters.core; + +import com.mojang.serialization.Codec; +import me.desht.modularrouters.ModularRouters; +import me.desht.modularrouters.item.smartfilter.ModFilter; +import me.desht.modularrouters.item.upgrade.SecurityUpgrade; +import me.desht.modularrouters.logic.ModuleTargetList; +import me.desht.modularrouters.logic.compiled.*; +import me.desht.modularrouters.logic.filter.matchers.InspectionMatcher.ComparisonList; +import me.desht.modularrouters.logic.settings.ModuleSettings; +import me.desht.modularrouters.logic.settings.RedstoneBehaviour; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.util.StringRepresentable; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemContainerContents; +import net.minecraft.world.item.component.ResolvableProfile; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; +import net.neoforged.neoforge.registries.DeferredRegister; + +import java.util.List; +import java.util.function.Supplier; + +public class ModDataComponents { + public static final DeferredRegister.DataComponents COMPONENTS + = DeferredRegister.createDataComponents(ModularRouters.MODID); + + // a list of targets for a targeted module (usually one target, but distributor modules can have multiple) + public static final Supplier> MODULE_TARGET_LIST + = COMPONENTS.registerComponentType("module_target_list", builder -> builder + .persistent(ModuleTargetList.CODEC) + .networkSynchronized(ModuleTargetList.STREAM_CODEC) + ); + // module settings common to ALL modules + public static final Supplier> COMMON_MODULE_SETTINGS + = COMPONENTS.registerComponentType("common_module_settings", builder -> builder + .persistent(ModuleSettings.CODEC) + .networkSynchronized(ModuleSettings.STREAM_CODEC) + ); + // module-specific settings in the next bunch of components... + public static final Supplier> ACTIVATOR_SETTINGS + = COMPONENTS.registerComponentType("activator_settings", builder -> builder + .persistent(CompiledActivatorModule.ActivatorSettings.CODEC) + .networkSynchronized(CompiledActivatorModule.ActivatorSettings.STREAM_CODEC) + ); + public static final Supplier> BREAKER_SETTINGS + = COMPONENTS.registerComponentType("breaker_settings", builder -> builder + .persistent(CompiledBreakerModule.BreakerSettings.CODEC) + .networkSynchronized(CompiledBreakerModule.BreakerSettings.STREAM_CODEC) + ); + public static final Supplier> DETECTOR_SETTINGS + = COMPONENTS.registerComponentType("detector_settings", builder -> builder + .persistent(CompiledDetectorModule.DetectorSettings.CODEC) + .networkSynchronized(CompiledDetectorModule.DetectorSettings.STREAM_CODEC) + ); + public static final Supplier> DISTRIBUTOR_SETTINGS + = COMPONENTS.registerComponentType("distributor_settings", builder -> builder + .persistent(CompiledDistributorModule.DistributorSettings.CODEC) + .networkSynchronized(CompiledDistributorModule.DistributorSettings.STREAM_CODEC) + ); + public static final Supplier> FLINGER_SETTINGS + = COMPONENTS.registerComponentType("flinger_settings", builder -> builder + .persistent(CompiledFlingerModule.FlingerSettings.CODEC) + .networkSynchronized(CompiledFlingerModule.FlingerSettings.STREAM_CODEC) + ); + public static final Supplier> FLUID_SETTINGS + = COMPONENTS.registerComponentType("fluid_settings", builder -> builder + .persistent(CompiledFluidModule1.FluidModuleSettings.CODEC) + .networkSynchronized(CompiledFluidModule1.FluidModuleSettings.STREAM_CODEC) + ); + public static final Supplier> PLAYER_SETTINGS + = COMPONENTS.registerComponentType("player_settings", builder -> builder + .persistent(CompiledPlayerModule.PlayerSettings.CODEC) + .networkSynchronized(CompiledPlayerModule.PlayerSettings.STREAM_CODEC) + ); + public static final Supplier> VACUUM_SETTINGS + = COMPONENTS.registerComponentType("vacuum_settings", builder -> builder + .persistent(CompiledVacuumModule.VacuumSettings.CODEC) + .networkSynchronized(CompiledVacuumModule.VacuumSettings.STREAM_CODEC) + ); + // a list of filter strings on a mod/tag/regex filter + public static final Supplier>> FILTER_STRINGS + = COMPONENTS.registerComponentType("filter_strings", builder -> builder + .persistent(Codec.STRING.listOf(0, ModFilter.MAX_SIZE)) + .networkSynchronized(ByteBufCodecs.STRING_UTF8.apply(ByteBufCodecs.list(ModFilter.MAX_SIZE))) + ); + // a list of comparison objects on an inspection filter + public static final Supplier> COMPARISON_LIST + = COMPONENTS.registerComponentType("comparison_list", builder -> builder + .persistent(ComparisonList.CODEC) + .networkSynchronized(ComparisonList.STREAM_CODEC) + ); + // pickaxe stored in a Breaker or Extruder Mk1 + public static final Supplier> PICKAXE + = COMPONENTS.registerComponentType("pickaxe", builder -> builder + .persistent(ItemContainerContents.CODEC) + .networkSynchronized(ItemContainerContents.STREAM_CODEC) + ); + // a collection of itemstacks in a module, used for the filter + public static final Supplier> FILTER + = COMPONENTS.registerComponentType("filter", builder -> builder + .persistent(ItemContainerContents.CODEC) + .networkSynchronized(ItemContainerContents.STREAM_CODEC) + ); + // the augment items in a module + public static final Supplier> AUGMENTS + = COMPONENTS.registerComponentType("augments", builder -> builder + .persistent(ItemContainerContents.CODEC) + .networkSynchronized(ItemContainerContents.STREAM_CODEC) + ); + // the template items in an Extruder Mk2 + public static final Supplier> EXTRUDER2_TEMPLATE + = COMPONENTS.registerComponentType("ex2_template", builder -> builder + .persistent(ItemContainerContents.CODEC) + .networkSynchronized(ItemContainerContents.STREAM_CODEC) + ); + // the owner of a player module or security upgrade + public static final Supplier> OWNER + = COMPONENTS.registerComponentType("security_owner", builder -> builder + .persistent(ResolvableProfile.CODEC) + .networkSynchronized(ResolvableProfile.STREAM_CODEC) + ); + // list of permitted players on a security upgrade + public static final Supplier> SECURITY_LIST + = COMPONENTS.registerComponentType("security_list", builder -> builder + .persistent(SecurityUpgrade.SecurityList.CODEC) + .networkSynchronized(SecurityUpgrade.SecurityList.STREAM_CODEC) + ); + // the camouflage blockstate on a camouflage upgrade + public static final Supplier> CAMOUFLAGE + = COMPONENTS.registerComponentType("camouflage", builder -> builder + .persistent(BlockState.CODEC) + .networkSynchronized(ByteBufCodecs.fromCodec(BlockState.CODEC)) + ); + // the tuning value for a sync upgrade + public static final Supplier> SYNC_TUNING + = COMPONENTS.registerComponentType("sync_tuning", builder -> builder + .persistent(ExtraCodecs.intRange(1, 20)) + .networkSynchronized(ByteBufCodecs.VAR_INT) + ); + // the current round-robin value for a module with filter in round-robin mode + public static final Supplier> RR_COUNTER + = COMPONENTS.registerComponentType("rr_counter", builder -> builder + .persistent(ExtraCodecs.NON_NEGATIVE_INT) + .networkSynchronized(ByteBufCodecs.VAR_INT) + ); + + // redstone behaviour stored on a dropped router item + public static final Supplier> REDSTONE_BEHAVIOUR + = COMPONENTS.registerComponentType("saved_redstone", builder -> builder + .persistent(StringRepresentable.fromEnum(RedstoneBehaviour::values)) + .networkSynchronized(NeoForgeStreamCodecs.enumCodec(RedstoneBehaviour.class)) + ); + // saved modules stored on a dropped router item + public static final Supplier> SAVED_MODULES + = COMPONENTS.registerComponentType("saved_modules", builder -> builder + .persistent(ItemContainerContents.CODEC) + .networkSynchronized(ItemContainerContents.STREAM_CODEC) + ); + // saved upgrades stored on a dropped router item + public static final Supplier> SAVED_UPGRADES + = COMPONENTS.registerComponentType("saved_upgrades", builder -> builder + .persistent(ItemContainerContents.CODEC) + .networkSynchronized(ItemContainerContents.STREAM_CODEC) + ); +} diff --git a/src/main/java/me/desht/modularrouters/core/ModItems.java b/src/main/java/me/desht/modularrouters/core/ModItems.java index e1503501..18748797 100644 --- a/src/main/java/me/desht/modularrouters/core/ModItems.java +++ b/src/main/java/me/desht/modularrouters/core/ModItems.java @@ -6,7 +6,9 @@ import me.desht.modularrouters.item.module.*; import me.desht.modularrouters.item.smartfilter.*; import me.desht.modularrouters.item.upgrade.*; +import me.desht.modularrouters.logic.settings.ModuleSettings; import net.minecraft.world.item.Item; +import net.minecraft.world.item.component.ItemContainerContents; import net.neoforged.neoforge.registries.DeferredItem; import net.neoforged.neoforge.registries.DeferredRegister; @@ -47,15 +49,15 @@ public class ModItems { public static final DeferredItem VACUUM_MODULE = register("vacuum_module", VacuumModule::new); public static final DeferredItem VOID_MODULE = register("void_module", VoidModule::new); - public static final DeferredItem BLAST_UPGRADE = register("blast_upgrade", BlastUpgrade::new); - public static final DeferredItem CAMOUFLAGE_UPGRADE = register("camouflage_upgrade", CamouflageUpgrade::new); - public static final DeferredItem ENERGY_UPGRADE = register("energy_upgrade", EnergyUpgrade::new); - public static final DeferredItem FLUID_UPGRADE = register("fluid_upgrade", FluidUpgrade::new); - public static final DeferredItem MUFFLER_UPGRADE = register("muffler_upgrade", MufflerUpgrade::new); - public static final DeferredItem SECURITY_UPGRADE = register("security_upgrade", SecurityUpgrade::new); - public static final DeferredItem SPEED_UPGRADE = register("speed_upgrade", SpeedUpgrade::new); - public static final DeferredItem STACK_UPGRADE = register("stack_upgrade", StackUpgrade::new); - public static final DeferredItem SYNC_UPGRADE = register("sync_upgrade", SyncUpgrade::new); + public static final DeferredItem BLAST_UPGRADE = register("blast_upgrade", BlastUpgrade::new); + public static final DeferredItem CAMOUFLAGE_UPGRADE = register("camouflage_upgrade", CamouflageUpgrade::new); + public static final DeferredItem ENERGY_UPGRADE = register("energy_upgrade", EnergyUpgrade::new); + public static final DeferredItem FLUID_UPGRADE = register("fluid_upgrade", FluidUpgrade::new); + public static final DeferredItem MUFFLER_UPGRADE = register("muffler_upgrade", MufflerUpgrade::new); + public static final DeferredItem SECURITY_UPGRADE = register("security_upgrade", SecurityUpgrade::new); + public static final DeferredItem SPEED_UPGRADE = register("speed_upgrade", SpeedUpgrade::new); + public static final DeferredItem STACK_UPGRADE = register("stack_upgrade", StackUpgrade::new); + public static final DeferredItem SYNC_UPGRADE = register("sync_upgrade", SyncUpgrade::new); public static final DeferredItem FAST_PICKUP_AUGMENT = register("fast_pickup_augment", FastPickupAugment::new); public static final DeferredItem FILTER_ROUND_ROBIN_AUGMENT = register("filter_round_robin_augment", FilterRoundRobinAugment::new); @@ -89,6 +91,14 @@ public static Item.Properties defaultProps() { return new Item.Properties(); } + public static Item.Properties moduleProps() { + return defaultProps() + .component(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettings.DEFAULT) + .component(ModDataComponents.FILTER, ItemContainerContents.EMPTY) + .component(ModDataComponents.AUGMENTS, ItemContainerContents.EMPTY) + .component(ModDataComponents.RR_COUNTER, 0); + } + public interface ITintable { TintColor getItemTint(); } diff --git a/src/main/java/me/desht/modularrouters/datagen/ModLootTableProvider.java b/src/main/java/me/desht/modularrouters/datagen/ModLootTableProvider.java index f2fb61dd..d6155e0a 100644 --- a/src/main/java/me/desht/modularrouters/datagen/ModLootTableProvider.java +++ b/src/main/java/me/desht/modularrouters/datagen/ModLootTableProvider.java @@ -1,40 +1,39 @@ package me.desht.modularrouters.datagen; -import me.desht.modularrouters.core.ModBlockEntities; import me.desht.modularrouters.core.ModBlocks; +import me.desht.modularrouters.core.ModDataComponents; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.WritableRegistry; import net.minecraft.data.DataGenerator; import net.minecraft.data.loot.BlockLootSubProvider; import net.minecraft.data.loot.LootTableProvider; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.ShulkerBoxBlock; import net.minecraft.world.level.storage.loot.LootPool; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.ValidationContext; -import net.minecraft.world.level.storage.loot.entries.DynamicLoot; import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.functions.CopyComponentsFunction; import net.minecraft.world.level.storage.loot.functions.CopyNameFunction; -import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction; -import net.minecraft.world.level.storage.loot.functions.SetContainerContents; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition; -import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider; import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; import java.util.List; -import java.util.Map; import java.util.Set; +import java.util.concurrent.CompletableFuture; public class ModLootTableProvider extends LootTableProvider { - public ModLootTableProvider(DataGenerator dataGeneratorIn) { - super(dataGeneratorIn.getPackOutput(), Set.of(), List.of( - new LootTableProvider.SubProviderEntry(ModularRoutersBlockLoot::new, LootContextParamSets.BLOCK) - )); + public ModLootTableProvider(DataGenerator dataGeneratorIn, CompletableFuture lookupProvider) { + super(dataGeneratorIn.getPackOutput(), + Set.of(), + List.of(new LootTableProvider.SubProviderEntry(ModularRoutersBlockLoot::new, LootContextParamSets.BLOCK)), + lookupProvider); } @Override - protected void validate(Map map, ValidationContext validationtracker) { + protected void validate(WritableRegistry writableregistry, ValidationContext validationcontext, ProblemReporter.Collector problemreporter$collector) { // TODO } @@ -52,17 +51,18 @@ protected Iterable getKnownBlocks() { protected void generate() { Block router = ModBlocks.MODULAR_ROUTER.get(); LootPool.Builder builder = LootPool.lootPool() -// .name(ModBlocks.MODULAR_ROUTER.getId().getPath()) .when(ExplosionCondition.survivesExplosion()) .setRolls(ConstantValue.exactly(1)) .add(LootItem.lootTableItem(router) .apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY)) - .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY) - .copy("Modules", "BlockEntityTag.Modules", CopyNbtFunction.MergeStrategy.REPLACE) - .copy("Upgrades", "BlockEntityTag.Upgrades", CopyNbtFunction.MergeStrategy.REPLACE) - .copy("Redstone", "BlockEntityTag.Redstone", CopyNbtFunction.MergeStrategy.REPLACE)) - .apply(SetContainerContents.setContents(ModBlockEntities.MODULAR_ROUTER.get()) - .withEntry(DynamicLoot.dynamicEntry(ShulkerBoxBlock.CONTENTS)))); + .apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY) + .include(ModDataComponents.REDSTONE_BEHAVIOUR.get()) + .include(ModDataComponents.SAVED_MODULES.get()) + .include(ModDataComponents.SAVED_UPGRADES.get()) + ) +// .apply(SetContainerContents.setContents(ContainerComponentManipulators.CONTAINER) +// .withEntry(DynamicLoot.dynamicEntry(ShulkerBoxBlock.CONTENTS))) + ); add(router, LootTable.lootTable().withPool(builder)); } } diff --git a/src/main/java/me/desht/modularrouters/datagen/ModRecipeProvider.java b/src/main/java/me/desht/modularrouters/datagen/ModRecipeProvider.java index 8ff80bab..ee2c6a1c 100644 --- a/src/main/java/me/desht/modularrouters/datagen/ModRecipeProvider.java +++ b/src/main/java/me/desht/modularrouters/datagen/ModRecipeProvider.java @@ -5,6 +5,7 @@ import me.desht.modularrouters.recipe.GuideBookRecipe; import me.desht.modularrouters.recipe.PickaxeModuleRecipe; import me.desht.modularrouters.recipe.ResetModuleRecipe; +import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.DataGenerator; import net.minecraft.data.recipes.*; @@ -19,12 +20,13 @@ import net.neoforged.neoforge.common.conditions.ModLoadedCondition; import java.util.Arrays; +import java.util.concurrent.CompletableFuture; import static me.desht.modularrouters.util.MiscUtil.RL; public class ModRecipeProvider extends RecipeProvider { - public ModRecipeProvider(DataGenerator generator) { - super(generator.getPackOutput()); + public ModRecipeProvider(DataGenerator generator, CompletableFuture lookupProvider) { + super(generator.getPackOutput(), lookupProvider); } @Override @@ -63,7 +65,7 @@ protected void buildRecipes(RecipeOutput consumer) { ).save(consumer); shapeless(ModItems.MIMIC_AUGMENT.get(), ModItems.AUGMENT_CORE.get(), - ModItems.AUGMENT_CORE.get(), Tags.Items.OBSIDIAN, Tags.Items.DUSTS_REDSTONE, Tags.Items.DUSTS_GLOWSTONE + ModItems.AUGMENT_CORE.get(), Tags.Items.OBSIDIANS, Tags.Items.DUSTS_REDSTONE, Tags.Items.DUSTS_GLOWSTONE ).save(consumer); shaped(ModItems.REDSTONE_AUGMENT.get(), ModItems.AUGMENT_CORE.get(), @@ -127,7 +129,7 @@ protected void buildRecipes(RecipeOutput consumer) { shaped(ModItems.FLUID_MODULE.get(), ModItems.BLANK_MODULE.get(), " C /GMG", - 'G', Tags.Items.GLASS, + 'G', Tags.Items.GLASS_BLOCKS, 'C', Items.CAULDRON, 'M', ModItems.BLANK_MODULE.get() ).save(consumer); @@ -251,7 +253,7 @@ protected void buildRecipes(RecipeOutput consumer) { shaped(ModItems.SPEED_UPGRADE.get(), 3, ModItems.BLANK_UPGRADE.get(), "RIR/NBN/GZG", 'I', Tags.Items.INGOTS_GOLD, - 'G', Tags.Items.GUNPOWDER, + 'G', Tags.Items.GUNPOWDERS, 'R', Tags.Items.DUSTS_REDSTONE, 'B', ModItems.BLANK_UPGRADE.get(), 'N', Tags.Items.NUGGETS_GOLD, @@ -260,7 +262,7 @@ protected void buildRecipes(RecipeOutput consumer) { shaped(ModItems.BLAST_UPGRADE.get(), ModItems.BLANK_UPGRADE.get(), "IOI/OBO/IOI", - 'O', Tags.Items.OBSIDIAN, + 'O', Tags.Items.OBSIDIANS, 'I', Items.IRON_BARS, 'B', ModItems.BLANK_UPGRADE.get() ).save(consumer); @@ -271,21 +273,21 @@ protected void buildRecipes(RecipeOutput consumer) { shaped(ModItems.FLUID_UPGRADE.get(), 3, ModItems.BLANK_UPGRADE.get(), " U /GBG", - 'G', Tags.Items.GLASS, + 'G', Tags.Items.GLASS_BLOCKS, 'U', Items.BUCKET, 'B', ModItems.BLANK_UPGRADE.get() ).save(consumer); shaped(ModItems.SYNC_UPGRADE.get(), 16, ModItems.BLANK_UPGRADE.get(), "RST/RBR", - 'S', Tags.Items.STONE, + 'S', Tags.Items.STONES, 'T', Items.REDSTONE_TORCH, 'B', ModItems.BLANK_UPGRADE.get(), 'R', Tags.Items.DUSTS_REDSTONE ).save(consumer); shapeless(ModItems.STACK_UPGRADE.get(), ModItems.BLANK_UPGRADE.get(), - ModItems.BLANK_UPGRADE.get(), ItemTags.STONE_BRICKS, Tags.Items.INGOTS_BRICK + ModItems.BLANK_UPGRADE.get(), ItemTags.STONE_BRICKS, Tags.Items.BRICKS ).save(consumer); shaped(ModItems.ENERGY_OUTPUT_MODULE.get(), ModItems.BLANK_MODULE.get(), @@ -311,7 +313,7 @@ protected void buildRecipes(RecipeOutput consumer) { // filters shaped(ModItems.BULK_ITEM_FILTER.get(), ModItems.BLANK_MODULE.get(), "IGI/MDM/IGI", - 'G', Tags.Items.GLASS, + 'G', Tags.Items.GLASS_BLOCKS, 'D', Tags.Items.GEMS_DIAMOND, 'I', Tags.Items.INGOTS_IRON, 'M', ModItems.BLANK_MODULE.get() diff --git a/src/main/java/me/desht/modularrouters/event/ClientEventHandler.java b/src/main/java/me/desht/modularrouters/event/ClientEventHandler.java index 53041547..d68eb0c8 100644 --- a/src/main/java/me/desht/modularrouters/event/ClientEventHandler.java +++ b/src/main/java/me/desht/modularrouters/event/ClientEventHandler.java @@ -6,24 +6,22 @@ import me.desht.modularrouters.util.Scheduler; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; -import net.neoforged.neoforge.event.TickEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.event.ClientTickEvent; import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import net.neoforged.neoforge.network.PacketDistributor; -@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = ModularRouters.MODID) +@EventBusSubscriber(value = Dist.CLIENT, modid = ModularRouters.MODID) public class ClientEventHandler { @SubscribeEvent - public static void clientTick(TickEvent.ClientTickEvent event) { - if (event.phase == TickEvent.Phase.END) { - Scheduler.client().tick(); - } + public static void clientTick(ClientTickEvent.Post event) { + Scheduler.client().tick(); } @SubscribeEvent public static void onPlayerLeftClick(PlayerInteractEvent.LeftClickBlock event) { if (event.getLevel().isClientSide && event.getItemStack().getItem() instanceof ModuleItem) { - PacketDistributor.SERVER.noArg().send(new ValidateModuleMessage(event.getHand())); + PacketDistributor.sendToServer(new ValidateModuleMessage(event.getHand())); event.setCanceled(true); } } @@ -31,7 +29,7 @@ public static void onPlayerLeftClick(PlayerInteractEvent.LeftClickBlock event) { @SubscribeEvent public static void onPlayerLeftClick(PlayerInteractEvent.LeftClickEmpty event) { if (event.getLevel().isClientSide && event.getItemStack().getItem() instanceof ModuleItem) { - PacketDistributor.SERVER.noArg().send(new ValidateModuleMessage(event.getHand())); + PacketDistributor.sendToServer(new ValidateModuleMessage(event.getHand())); } } } \ No newline at end of file diff --git a/src/main/java/me/desht/modularrouters/event/MiscEventHandler.java b/src/main/java/me/desht/modularrouters/event/MiscEventHandler.java index 37389516..63c85212 100644 --- a/src/main/java/me/desht/modularrouters/event/MiscEventHandler.java +++ b/src/main/java/me/desht/modularrouters/event/MiscEventHandler.java @@ -8,11 +8,11 @@ import me.desht.modularrouters.item.module.ModuleItem; import net.minecraft.world.item.ItemStack; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.event.entity.player.PlayerEvent; import net.neoforged.neoforge.items.ItemHandlerHelper; -@Mod.EventBusSubscriber(modid = ModularRouters.MODID) +@EventBusSubscriber(modid = ModularRouters.MODID) public class MiscEventHandler { @SubscribeEvent public static void onDigSpeedCheck(PlayerEvent.BreakSpeed event) { diff --git a/src/main/java/me/desht/modularrouters/event/TickEventHandler.java b/src/main/java/me/desht/modularrouters/event/TickEventHandler.java index b335d83d..93a556f3 100644 --- a/src/main/java/me/desht/modularrouters/event/TickEventHandler.java +++ b/src/main/java/me/desht/modularrouters/event/TickEventHandler.java @@ -3,17 +3,17 @@ import me.desht.modularrouters.ModularRouters; import net.minecraft.world.level.Level; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; -import net.neoforged.neoforge.event.TickEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.tick.LevelTickEvent; -@Mod.EventBusSubscriber(modid = ModularRouters.MODID) +@EventBusSubscriber(modid = ModularRouters.MODID) public class TickEventHandler { public static long TickCounter = 0; @SubscribeEvent - public static void onWorldTick(TickEvent.LevelTickEvent event) { - if (event.level.dimension() == Level.OVERWORLD && event.phase == TickEvent.Phase.END) { + public static void onWorldTick(LevelTickEvent.Post event) { + if (event.getLevel().dimension() == Level.OVERWORLD) { TickCounter++; } } diff --git a/src/main/java/me/desht/modularrouters/integration/XPCollection.java b/src/main/java/me/desht/modularrouters/integration/XPCollection.java index 57365d19..5f899971 100644 --- a/src/main/java/me/desht/modularrouters/integration/XPCollection.java +++ b/src/main/java/me/desht/modularrouters/integration/XPCollection.java @@ -4,6 +4,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluids; @@ -50,7 +51,7 @@ public static XPCollectionType getXPType(int type) { return xpType; } - public enum XPCollectionType implements TranslatableEnum { + public enum XPCollectionType implements TranslatableEnum, StringRepresentable { // note: bottles o' enchanting are randomly worth 3-11 experience, so let's use an average of 7 SOLIDIFIED_EXPERIENCE(true, 8, "actuallyadditions:item_solidified_experience"), BOTTLE_O_ENCHANTING(true, 7, "minecraft:experience_bottle"), @@ -110,5 +111,10 @@ public Component getDisplayName() { public String getTranslationKey() { return null; } + + @Override + public String getSerializedName() { + return registryName.toString(); + } } } diff --git a/src/main/java/me/desht/modularrouters/integration/jei/GhostTarget.java b/src/main/java/me/desht/modularrouters/integration/jei/GhostTarget.java index e754c0c5..7842af7c 100644 --- a/src/main/java/me/desht/modularrouters/integration/jei/GhostTarget.java +++ b/src/main/java/me/desht/modularrouters/integration/jei/GhostTarget.java @@ -19,11 +19,11 @@ public Rect2i getArea() { @Override public void accept(I ingredient) { if (ingredient instanceof ItemStack stack) { - PacketDistributor.SERVER.noArg().send(new ModuleFilterMessage(slot.index, stack)); + PacketDistributor.sendToServer(new ModuleFilterMessage(slot.index, stack)); } else if (ingredient instanceof FluidStack fluidStack) { ItemStack bucket = FluidUtil.getFilledBucket(fluidStack); if (!bucket.isEmpty()) { - PacketDistributor.SERVER.noArg().send(new ModuleFilterMessage(slot.index, bucket)); + PacketDistributor.sendToServer(new ModuleFilterMessage(slot.index, bucket)); } } } diff --git a/src/main/java/me/desht/modularrouters/integration/jei/JEIModularRoutersPlugin.java b/src/main/java/me/desht/modularrouters/integration/jei/JEIModularRoutersPlugin.java index 08a49614..06ecfadc 100644 --- a/src/main/java/me/desht/modularrouters/integration/jei/JEIModularRoutersPlugin.java +++ b/src/main/java/me/desht/modularrouters/integration/jei/JEIModularRoutersPlugin.java @@ -2,7 +2,7 @@ import me.desht.modularrouters.client.gui.ModularRouterScreen; import me.desht.modularrouters.client.gui.filter.BulkItemFilterScreen; -import me.desht.modularrouters.client.gui.module.AbstractModuleScreen; +import me.desht.modularrouters.client.gui.module.ModuleScreen; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; import mezz.jei.api.gui.handlers.IGuiContainerHandler; @@ -23,7 +23,7 @@ public ResourceLocation getPluginUid() { @Override public void registerGuiHandlers(IGuiHandlerRegistration registration) { - registration.addGhostIngredientHandler(AbstractModuleScreen.class, new ModuleScreenGhost()); + registration.addGhostIngredientHandler(ModuleScreen.class, new ModuleScreenGhost()); registration.addGhostIngredientHandler(BulkItemFilterScreen.class, new BulkFilterScreenGhost()); registration.addGuiContainerHandler(ModularRouterScreen.class, new IGuiContainerHandler<>() { diff --git a/src/main/java/me/desht/modularrouters/integration/jei/ModuleScreenGhost.java b/src/main/java/me/desht/modularrouters/integration/jei/ModuleScreenGhost.java index b35ae6f2..527ca188 100644 --- a/src/main/java/me/desht/modularrouters/integration/jei/ModuleScreenGhost.java +++ b/src/main/java/me/desht/modularrouters/integration/jei/ModuleScreenGhost.java @@ -1,6 +1,6 @@ package me.desht.modularrouters.integration.jei; -import me.desht.modularrouters.client.gui.module.AbstractModuleScreen; +import me.desht.modularrouters.client.gui.module.ModuleScreen; import me.desht.modularrouters.container.FilterSlot; import mezz.jei.api.gui.handlers.IGhostIngredientHandler; import mezz.jei.api.ingredients.ITypedIngredient; @@ -9,9 +9,9 @@ import java.util.ArrayList; import java.util.List; -public class ModuleScreenGhost implements IGhostIngredientHandler { +public class ModuleScreenGhost implements IGhostIngredientHandler { @Override - public List> getTargetsTyped(AbstractModuleScreen gui, ITypedIngredient ingredient, boolean doStart) { + public List> getTargetsTyped(ModuleScreen gui, ITypedIngredient ingredient, boolean doStart) { List> res = new ArrayList<>(); for (int i = 0; i < gui.getMenu().slots.size(); i++) { Slot s = gui.getMenu().getSlot(i); diff --git a/src/main/java/me/desht/modularrouters/integration/top/ElementModule.java b/src/main/java/me/desht/modularrouters/integration/top/ElementModule.java index 2eadabcc..e91e4bde 100644 --- a/src/main/java/me/desht/modularrouters/integration/top/ElementModule.java +++ b/src/main/java/me/desht/modularrouters/integration/top/ElementModule.java @@ -2,28 +2,30 @@ import mcjty.theoneprobe.api.IElement; import mcjty.theoneprobe.api.IElementFactory; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.util.ModuleHelper; +import me.desht.modularrouters.logic.settings.ModuleSettings; +import me.desht.modularrouters.logic.settings.RelativeDirection; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang3.Validate; public class ElementModule implements IElement { private final ItemStack stack; - private final ModuleItem.RelativeDirection dir; + private final RelativeDirection dir; public ElementModule(ItemStack stack) { Validate.isTrue(stack.getItem() instanceof ModuleItem, "provided item stack is not an ItemModule!"); this.stack = stack; - this.dir = ModuleHelper.getRelativeDirection(stack); + this.dir = ModuleItem.getCommonSettings(stack).facing(); } - public ElementModule(FriendlyByteBuf buf) { - this.stack = buf.readItem(); - this.dir = buf.readEnum(ModuleItem.RelativeDirection.class); + public ElementModule(RegistryFriendlyByteBuf buf) { + this.stack = ItemStack.STREAM_CODEC.decode(buf); + this.dir = buf.readEnum(RelativeDirection.class); } @Override @@ -43,8 +45,8 @@ public int getHeight() { } @Override - public void toBytes(FriendlyByteBuf buffer) { - buffer.writeItem(stack); + public void toBytes(RegistryFriendlyByteBuf buffer) { + ItemStack.STREAM_CODEC.encode(buffer, stack); buffer.writeEnum(dir); } @@ -55,7 +57,7 @@ public ResourceLocation getID() { public static class Factory implements IElementFactory { @Override - public IElement createElement(FriendlyByteBuf buf) { + public IElement createElement(RegistryFriendlyByteBuf buf) { return new ElementModule(buf); } diff --git a/src/main/java/me/desht/modularrouters/integration/waila/RouterComponentProvider.java b/src/main/java/me/desht/modularrouters/integration/waila/RouterComponentProvider.java index a9be829c..a3d9a4ea 100644 --- a/src/main/java/me/desht/modularrouters/integration/waila/RouterComponentProvider.java +++ b/src/main/java/me/desht/modularrouters/integration/waila/RouterComponentProvider.java @@ -1,7 +1,7 @@ package me.desht.modularrouters.integration.waila; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; +import me.desht.modularrouters.logic.settings.RedstoneBehaviour; import net.minecraft.ChatFormatting; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -31,7 +31,7 @@ public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPlugi iTooltip.add(xlate("modularrouters.itemText.misc.upgradeCount", upgrades.getInt(k), xlate(k))); } } - RouterRedstoneBehaviour rrb = RouterRedstoneBehaviour.values()[data.getInt("RedstoneMode")]; + RedstoneBehaviour rrb = RedstoneBehaviour.values()[data.getInt("RedstoneMode")]; iTooltip.add(xlate("modularrouters.guiText.tooltip.redstone.label") .append(": " + ChatFormatting.AQUA) .append(xlate("modularrouters.guiText.tooltip.redstone." + rrb)) diff --git a/src/main/java/me/desht/modularrouters/item/IPlayerOwned.java b/src/main/java/me/desht/modularrouters/item/IPlayerOwned.java index 8b9b98cd..95ff8d6d 100644 --- a/src/main/java/me/desht/modularrouters/item/IPlayerOwned.java +++ b/src/main/java/me/desht/modularrouters/item/IPlayerOwned.java @@ -1,33 +1,39 @@ package me.desht.modularrouters.item; import com.mojang.authlib.GameProfile; +import me.desht.modularrouters.core.ModDataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ResolvableProfile; import java.util.Objects; import java.util.Optional; import java.util.UUID; public interface IPlayerOwned { - String NBT_OWNER = "Owner"; +// String NBT_OWNER = "Owner"; default Optional getOwnerProfile(ItemStack stack) { - if (!stack.hasTag() || !Objects.requireNonNull(stack.getTag()).contains(NBT_OWNER, Tag.TAG_LIST)) return Optional.empty(); + //noinspection DataFlowIssue + return stack.has(ModDataComponents.OWNER) ? + Optional.of(stack.get(ModDataComponents.OWNER).gameProfile()) : + Optional.empty(); - ListTag l = stack.getTag().getList(NBT_OWNER, Tag.TAG_STRING); - return Optional.of(new GameProfile(UUID.fromString(l.getString(1)), l.getString(0))); + // ListTag l = stack.getTag().getList(NBT_OWNER, Tag.TAG_STRING); +// return Optional.of(new GameProfile(UUID.fromString(l.getString(1)), l.getString(0))); } default void setOwner(ItemStack stack, Player player) { - CompoundTag compound = stack.getOrCreateTag(); - ListTag owner = new ListTag(); - owner.add(StringTag.valueOf(player.getGameProfile().getName())); - owner.add(StringTag.valueOf(player.getGameProfile().getId().toString())); - compound.put(NBT_OWNER, owner); - stack.setTag(compound); + stack.set(ModDataComponents.OWNER, new ResolvableProfile(player.getGameProfile())); +// CompoundTag compound = stack.getOrCreateTag(); +// ListTag owner = new ListTag(); +// owner.add(StringTag.valueOf(player.getGameProfile().getName())); +// owner.add(StringTag.valueOf(player.getGameProfile().getId().toString())); +// compound.put(NBT_OWNER, owner); +// stack.setTag(compound); } } diff --git a/src/main/java/me/desht/modularrouters/item/MRBaseItem.java b/src/main/java/me/desht/modularrouters/item/MRBaseItem.java index 22662ee4..cb463499 100644 --- a/src/main/java/me/desht/modularrouters/item/MRBaseItem.java +++ b/src/main/java/me/desht/modularrouters/item/MRBaseItem.java @@ -11,9 +11,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.Level; -import javax.annotation.Nullable; import java.util.List; import static me.desht.modularrouters.client.util.ClientUtil.xlate; @@ -24,8 +22,8 @@ public MRBaseItem(Properties props) { } @Override - public void appendHoverText(ItemStack stack, @Nullable Level world, List list, TooltipFlag flag) { - if (world == null) return; + public void appendHoverText(ItemStack stack, Item.TooltipContext context, List list, TooltipFlag flag) { + if (context.registries() == null) return; MutableComponent text = ClientSetup.keybindModuleInfo.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.DARK_AQUA); diff --git a/src/main/java/me/desht/modularrouters/item/augment/AugmentItem.java b/src/main/java/me/desht/modularrouters/item/augment/AugmentItem.java index 55d26af4..2c4f38c6 100644 --- a/src/main/java/me/desht/modularrouters/item/augment/AugmentItem.java +++ b/src/main/java/me/desht/modularrouters/item/augment/AugmentItem.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Supplier; public abstract class AugmentItem extends MRBaseItem { public static final int SLOTS = 4; @@ -39,7 +40,7 @@ public AugmentCounter(ItemStack moduleStack) { } public void refresh(ItemStack moduleStack) { - Validate.isTrue(moduleStack.getItem() instanceof ModuleItem, "item is not a ItemModule: " + moduleStack); + Validate.isTrue(moduleStack.getItem() instanceof ModuleItem, "item is not a ModuleItem: " + moduleStack); AugmentHandler h = new AugmentHandler(moduleStack, null); counts.clear(); @@ -55,9 +56,12 @@ public Collection getAugments() { return counts.keySet().stream().toList(); } + public int getAugmentCount(Supplier type) { + return getAugmentCount(type.get()); + } + public int getAugmentCount(Item type) { - if (!(type instanceof AugmentItem)) return 0; - return counts.getOrDefault(type, 0); + return type instanceof AugmentItem ? counts.getOrDefault(type, 0) : 0; } } } diff --git a/src/main/java/me/desht/modularrouters/item/augment/RedstoneAugment.java b/src/main/java/me/desht/modularrouters/item/augment/RedstoneAugment.java index 7797feda..5ea31b8c 100644 --- a/src/main/java/me/desht/modularrouters/item/augment/RedstoneAugment.java +++ b/src/main/java/me/desht/modularrouters/item/augment/RedstoneAugment.java @@ -1,8 +1,7 @@ package me.desht.modularrouters.item.augment; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; -import me.desht.modularrouters.util.ModuleHelper; +import me.desht.modularrouters.logic.settings.RedstoneBehaviour; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; @@ -16,7 +15,7 @@ public int getMaxAugments(ModuleItem moduleType) { @Override public Component getExtraInfo(int c, ItemStack moduleStack) { - RouterRedstoneBehaviour rrb = ModuleHelper.getRedstoneBehaviour(moduleStack); - return Component.literal(" - ").append(xlate("modularrouters.guiText.tooltip.redstone." + rrb.toString())); + RedstoneBehaviour rrb = ModuleItem.getRedstoneBehaviour(moduleStack); + return Component.literal(" - ").append(xlate(rrb.getTranslationKey())); } } diff --git a/src/main/java/me/desht/modularrouters/item/augment/RegulatorAugment.java b/src/main/java/me/desht/modularrouters/item/augment/RegulatorAugment.java index f2804983..2c66d8e8 100644 --- a/src/main/java/me/desht/modularrouters/item/augment/RegulatorAugment.java +++ b/src/main/java/me/desht/modularrouters/item/augment/RegulatorAugment.java @@ -1,9 +1,9 @@ package me.desht.modularrouters.item.augment; +import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.item.module.DetectorModule; import me.desht.modularrouters.item.module.ExtruderModule2; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.util.ModuleHelper; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; @@ -17,8 +17,11 @@ public int getMaxAugments(ModuleItem moduleType) { @Override public Component getExtraInfo(int c, ItemStack moduleStack) { - int amount = ModuleHelper.getRegulatorAmount(moduleStack); - String key = ((ModuleItem) moduleStack.getItem()).getRegulatorTranslationKey(moduleStack); - return Component.literal(" - ").append(xlate(key, amount)); + if (moduleStack.getItem() instanceof ModuleItem moduleItem) { + int amount = ModuleItem.getCommonSettings(moduleStack).regulatorAmount(); + return Component.literal(" - ").append(xlate(moduleItem.getRegulatorTranslationKey(moduleStack), amount)); + } else { + return Component.empty(); + } } } diff --git a/src/main/java/me/desht/modularrouters/item/module/ActivatorModule.java b/src/main/java/me/desht/modularrouters/item/module/ActivatorModule.java index 9f1ead72..972fe7eb 100644 --- a/src/main/java/me/desht/modularrouters/item/module/ActivatorModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/ActivatorModule.java @@ -1,12 +1,13 @@ package me.desht.modularrouters.item.module; -import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.logic.compiled.CompiledActivatorModule; +import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.ActivatorSettings; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.MenuType; @@ -14,42 +15,41 @@ import java.util.List; +import static me.desht.modularrouters.client.util.ClientUtil.xlate; + public class ActivatorModule extends ModuleItem { private static final TintColor TINT_COLOR = new TintColor(255, 255, 195); public ActivatorModule() { - super(ModItems.defaultProps(), CompiledActivatorModule::new); + super(ModItems.moduleProps().component(ModDataComponents.ACTIVATOR_SETTINGS, ActivatorSettings.DEFAULT), CompiledActivatorModule::new); } @Override public void addSettingsInformation(ItemStack stack, List list) { super.addSettingsInformation(stack, list); - CompiledActivatorModule cam = new CompiledActivatorModule(null, stack); - list.add(ClientUtil.xlate("modularrouters.guiText.tooltip.activator.action").append(": ") + ActivatorSettings settings = stack.getOrDefault(ModDataComponents.ACTIVATOR_SETTINGS, ActivatorSettings.DEFAULT); + list.add(xlate("modularrouters.guiText.tooltip.activator.action").append(": ") .withStyle(ChatFormatting.YELLOW) - .append(ClientUtil.xlate("modularrouters.itemText.activator.action." + cam.getActionType()) - .withStyle(ChatFormatting.AQUA))); - if (!cam.getActionType().isEntityTarget()) { - list.add(ClientUtil.xlate("modularrouters.guiText.tooltip.activator.lookDirection").append(": ") + .append(xlate(settings.actionType().getTranslationKey()).withStyle(ChatFormatting.AQUA))); + if (!settings.actionType().isEntityTarget()) { + list.add(xlate("modularrouters.guiText.tooltip.activator.lookDirection").append(": ") .withStyle(ChatFormatting.YELLOW) - .append(ClientUtil.xlate("modularrouters.itemText.activator.direction." + cam.getLookDirection()) - .withStyle(ChatFormatting.AQUA))); + .append(xlate(settings.lookDirection().getTranslationKey()).withStyle(ChatFormatting.AQUA))); } else { - list.add(ClientUtil.xlate("modularrouters.guiText.tooltip.activator.entityMode").append(": ") + list.add(xlate("modularrouters.guiText.tooltip.activator.entityMode").append(": ") .withStyle(ChatFormatting.YELLOW) - .append(ClientUtil.xlate("modularrouters.itemText.activator.entityMode." + cam.getEntityMode()) - .withStyle(ChatFormatting.AQUA))); + .append(xlate(settings.entityMode().getTranslationKey()).withStyle(ChatFormatting.AQUA))); } - if (cam.isSneaking()) { - list.add(ClientUtil.xlate("modularrouters.guiText.tooltip.activator.sneak").withStyle(ChatFormatting.YELLOW)); + if (settings.sneaking()) { + list.add(xlate("modularrouters.guiText.tooltip.activator.sneak").withStyle(ChatFormatting.YELLOW)); } } @Override public int getEnergyCost(ItemStack stack) { - CompiledActivatorModule cam = new CompiledActivatorModule(null, stack); - return cam.getActionType() == CompiledActivatorModule.ActionType.ATTACK_ENTITY ? + ActivatorSettings settings = stack.get(ModDataComponents.ACTIVATOR_SETTINGS); + return settings.actionType() == CompiledActivatorModule.ActionType.ATTACK_ENTITY ? ConfigHolder.common.energyCosts.activatorModuleEnergyCostAttack.get() : ConfigHolder.common.energyCosts.activatorModuleEnergyCost.get(); } diff --git a/src/main/java/me/desht/modularrouters/item/module/BreakerModule.java b/src/main/java/me/desht/modularrouters/item/module/BreakerModule.java index d56d5c73..19106c5c 100644 --- a/src/main/java/me/desht/modularrouters/item/module/BreakerModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/BreakerModule.java @@ -4,13 +4,17 @@ import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.logic.compiled.CompiledBreakerModule; +import me.desht.modularrouters.logic.compiled.CompiledBreakerModule.BreakerSettings; import net.minecraft.ChatFormatting; +import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemContainerContents; import java.util.List; @@ -18,7 +22,10 @@ public class BreakerModule extends ModuleItem implements IPickaxeUser { private static final TintColor TINT_COLOR = new TintColor(240, 208, 208); public BreakerModule() { - super(ModItems.defaultProps(), CompiledBreakerModule::new); + super(ModItems.moduleProps() + .component(DataComponents.CONTAINER, ItemContainerContents.EMPTY) + .component(ModDataComponents.BREAKER_SETTINGS, BreakerSettings.DEFAULT), + CompiledBreakerModule::new); } @Override @@ -32,12 +39,11 @@ public int getEnergyCost(ItemStack stack) { } @Override - protected void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); + protected void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); - CompiledBreakerModule cbm = new CompiledBreakerModule(null, itemstack); - CompiledBreakerModule.MatchType type = cbm.getMatchType(); - list.add(ClientUtil.xlate(type.getTranslationKey()).withStyle(ChatFormatting.YELLOW)); + BreakerSettings settings = stack.get(ModDataComponents.BREAKER_SETTINGS); + list.add(ClientUtil.xlate(settings.matchType().getTranslationKey()).withStyle(ChatFormatting.YELLOW)); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/CreativeModule.java b/src/main/java/me/desht/modularrouters/item/module/CreativeModule.java index d7639dd2..5b69f277 100644 --- a/src/main/java/me/desht/modularrouters/item/module/CreativeModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/CreativeModule.java @@ -12,7 +12,7 @@ public class CreativeModule extends ModuleItem { private static final TintColor TINT_COLOR = new TintColor(187, 38, 185); public CreativeModule() { - super(ModItems.defaultProps(), CompiledCreativeModule::new); + super(ModItems.moduleProps(), CompiledCreativeModule::new); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/DetectorModule.java b/src/main/java/me/desht/modularrouters/item/module/DetectorModule.java index ec6ee443..18801c50 100644 --- a/src/main/java/me/desht/modularrouters/item/module/DetectorModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/DetectorModule.java @@ -3,9 +3,11 @@ import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.logic.compiled.CompiledDetectorModule; +import me.desht.modularrouters.logic.compiled.CompiledDetectorModule.DetectorSettings; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.MenuType; @@ -20,7 +22,9 @@ public class DetectorModule extends ModuleItem { private static final TintColor TINT_COLOR = new TintColor(255, 255, 195); public DetectorModule() { - super(ModItems.defaultProps(), CompiledDetectorModule::new); + super(ModItems.moduleProps() + .component(ModDataComponents.DETECTOR_SETTINGS, DetectorSettings.DEFAULT), + CompiledDetectorModule::new); } public enum SignalType { @@ -37,12 +41,13 @@ public MenuType getMenuType() { } @Override - public void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); - CompiledDetectorModule ds = new CompiledDetectorModule(null, itemstack); + public void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); + + DetectorSettings settings = stack.get(ModDataComponents.DETECTOR_SETTINGS); list.add(xlate("modularrouters.itemText.misc.redstoneLevel", - ds.getSignalLevel(), - xlate("modularrouters.itemText.misc.strongSignal." + ds.isStrongSignal()).withStyle(ChatFormatting.AQUA) + settings.signalLevel(), + xlate("modularrouters.itemText.misc.strongSignal." + settings.strongSignal()).withStyle(ChatFormatting.AQUA) ).withStyle(ChatFormatting.YELLOW)); } diff --git a/src/main/java/me/desht/modularrouters/item/module/DistributorModule.java b/src/main/java/me/desht/modularrouters/item/module/DistributorModule.java index a5ed2a10..d3a62244 100644 --- a/src/main/java/me/desht/modularrouters/item/module/DistributorModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/DistributorModule.java @@ -5,9 +5,13 @@ import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.logic.ModuleTarget; +import me.desht.modularrouters.logic.ModuleTargetList; import me.desht.modularrouters.logic.compiled.CompiledDistributorModule; +import me.desht.modularrouters.logic.compiled.CompiledDistributorModule.DistributorSettings; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.MenuType; @@ -17,22 +21,23 @@ import java.util.List; public class DistributorModule extends SenderModule2 { - private static final TintColor TINT_COLOR = new TintColor(240, 240, 60); public DistributorModule() { - super(CompiledDistributorModule::new); + super(ModItems.moduleProps() + .component(ModDataComponents.DISTRIBUTOR_SETTINGS, DistributorSettings.DEFAULT), + CompiledDistributorModule::new); } @Override - public void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); + public void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); - CompiledDistributorModule cdm = new CompiledDistributorModule(null, itemstack); + DistributorSettings settings = stack.get(ModDataComponents.DISTRIBUTOR_SETTINGS); list.add(ClientUtil.xlate("modularrouters.guiText.tooltip.distributor.strategy").withStyle(ChatFormatting.YELLOW) .append(": ").withStyle(ChatFormatting.YELLOW) - .append(ClientUtil.xlate(cdm.getDistributionStrategy().getTranslationKey())).withStyle(ChatFormatting.AQUA)); - list.add(ClientUtil.xlate("modularrouters.itemText.fluid.direction." + (cdm.isPulling() ? "IN" : "OUT")).withStyle(ChatFormatting.YELLOW)); + .append(ClientUtil.xlate(settings.strategy().getTranslationKey())).withStyle(ChatFormatting.AQUA)); + list.add(ClientUtil.xlate(settings.direction().getTranslationKey()).withStyle(ChatFormatting.YELLOW)); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/DropperModule.java b/src/main/java/me/desht/modularrouters/item/module/DropperModule.java index 08aeb431..affc6d82 100644 --- a/src/main/java/me/desht/modularrouters/item/module/DropperModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/DropperModule.java @@ -6,6 +6,7 @@ import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.compiled.CompiledDropperModule; import me.desht.modularrouters.logic.compiled.CompiledModule; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import java.util.function.BiFunction; @@ -14,11 +15,11 @@ public class DropperModule extends ModuleItem { private static final TintColor TINT_COLOR = new TintColor(230, 204, 240); public DropperModule() { - super(ModItems.defaultProps(), CompiledDropperModule::new); + super(ModItems.moduleProps(), CompiledDropperModule::new); } - public DropperModule(BiFunction compiler) { - super(ModItems.defaultProps(), compiler); + protected DropperModule(Item.Properties properties, BiFunction compiler) { + super(properties, compiler); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/EnergyDistributorModule.java b/src/main/java/me/desht/modularrouters/item/module/EnergyDistributorModule.java index 64dc3e3c..4aa97590 100644 --- a/src/main/java/me/desht/modularrouters/item/module/EnergyDistributorModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/EnergyDistributorModule.java @@ -4,8 +4,10 @@ import me.desht.modularrouters.client.render.area.IPositionProvider; import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.ModuleTarget; +import me.desht.modularrouters.logic.ModuleTargetList; import me.desht.modularrouters.logic.compiled.CompiledEnergyDistributorModule; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; @@ -15,15 +17,16 @@ import java.util.List; public class EnergyDistributorModule extends TargetedModule implements IRangedModule, IPositionProvider { - private static final TintColor TINT_COLOR = new TintColor(54, 1, 61); + private static final TintColor TINT_COLOR = new TintColor(79, 9, 90); public EnergyDistributorModule() { - super(ModItems.defaultProps(), CompiledEnergyDistributorModule::new); + super(ModItems.moduleProps(), + CompiledEnergyDistributorModule::new); } @Override public TintColor getItemTint() { - return new TintColor(79, 9, 90); + return TINT_COLOR; } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/EnergyOutputModule.java b/src/main/java/me/desht/modularrouters/item/module/EnergyOutputModule.java index 5c918f2e..c4025d5d 100644 --- a/src/main/java/me/desht/modularrouters/item/module/EnergyOutputModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/EnergyOutputModule.java @@ -7,15 +7,15 @@ import net.minecraft.world.item.ItemStack; public class EnergyOutputModule extends ModuleItem { - private static final TintColor TINT_COLOR = new TintColor(65, 4, 75); + private static final TintColor TINT_COLOR = new TintColor(106, 12, 120); public EnergyOutputModule() { - super(ModItems.defaultProps(), CompiledEnergyOutputModule::new); + super(ModItems.moduleProps(), CompiledEnergyOutputModule::new); } @Override public TintColor getItemTint() { - return new TintColor(106, 12, 120); + return TINT_COLOR; } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/ExtruderModule1.java b/src/main/java/me/desht/modularrouters/item/module/ExtruderModule1.java index d9829441..ba13e031 100644 --- a/src/main/java/me/desht/modularrouters/item/module/ExtruderModule1.java +++ b/src/main/java/me/desht/modularrouters/item/module/ExtruderModule1.java @@ -5,10 +5,12 @@ import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.compiled.CompiledExtruderModule1; -import me.desht.modularrouters.util.ModuleHelper; +import me.desht.modularrouters.logic.settings.ModuleSettings; import net.minecraft.ChatFormatting; +import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemContainerContents; import java.util.List; @@ -17,13 +19,18 @@ public class ExtruderModule1 extends ModuleItem implements IRangedModule, IPicka private static final TintColor TINT_COLOR = new TintColor(227, 174, 27); public ExtruderModule1() { - super(ModItems.defaultProps(), CompiledExtruderModule1::new); + super(ModItems.moduleProps() + .component(DataComponents.CONTAINER, ItemContainerContents.EMPTY), + CompiledExtruderModule1::new); } @Override - public void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); - list.add(ClientUtil.xlate("modularrouters.itemText.extruder.mode." + ModuleHelper.getRedstoneBehaviour(itemstack)).withStyle(ChatFormatting.YELLOW)); + public void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); + + ModuleSettings settings = ModuleItem.getCommonSettings(stack); + list.add(ClientUtil.xlate("modularrouters.itemText.extruder.mode." + settings.redstoneBehaviour().getSerializedName()) + .withStyle(ChatFormatting.YELLOW)); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/ExtruderModule2.java b/src/main/java/me/desht/modularrouters/item/module/ExtruderModule2.java index 8b81ffa2..001861b8 100644 --- a/src/main/java/me/desht/modularrouters/item/module/ExtruderModule2.java +++ b/src/main/java/me/desht/modularrouters/item/module/ExtruderModule2.java @@ -5,6 +5,7 @@ import me.desht.modularrouters.container.Extruder2ModuleMenu; import me.desht.modularrouters.container.Extruder2ModuleMenu.TemplateHandler; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.compiled.CompiledExtruderModule2; import me.desht.modularrouters.util.MFLocator; @@ -12,6 +13,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemContainerContents; import java.util.List; @@ -19,20 +21,22 @@ import static me.desht.modularrouters.util.MiscUtil.asMutableComponent; public class ExtruderModule2 extends ModuleItem implements IRangedModule { - private static final TintColor TINT_COLOR = new TintColor(227, 174, 27); public ExtruderModule2() { - super(ModItems.defaultProps(), CompiledExtruderModule2::new); + super(ModItems.moduleProps() + .component(ModDataComponents.EXTRUDER2_TEMPLATE, ItemContainerContents.EMPTY), + CompiledExtruderModule2::new); } @Override - public void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); + public void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); list.add(xlate("modularrouters.itemText.extruder2.template").withStyle(ChatFormatting.YELLOW)); - TemplateHandler handler = new TemplateHandler(itemstack, null); + int size = list.size(); + TemplateHandler handler = new TemplateHandler(stack, null); for (int i = 0; i < handler.getSlots(); i++) { ItemStack blockStack = handler.getStackInSlot(i); if (!blockStack.isEmpty()) { @@ -42,6 +46,7 @@ public void addSettingsInformation(ItemStack itemstack, List list) { if (list.size() == size) { Component tc = list.get(size - 1); list.set(list.size() - 1, asMutableComponent(tc) + .append(" ") .append(xlate("modularrouters.itemText.misc.noItems").withStyle(ChatFormatting.AQUA, ChatFormatting.ITALIC)) ); diff --git a/src/main/java/me/desht/modularrouters/item/module/FlingerModule.java b/src/main/java/me/desht/modularrouters/item/module/FlingerModule.java index 31edea9a..3aae9af8 100644 --- a/src/main/java/me/desht/modularrouters/item/module/FlingerModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/FlingerModule.java @@ -3,8 +3,11 @@ import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.logic.compiled.CompiledFlingerModule; +import me.desht.modularrouters.logic.compiled.CompiledFlingerModule.FlingerSettings; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.MenuType; @@ -25,17 +28,21 @@ public class FlingerModule extends DropperModule { private static final TintColor TINT_COLOR = new TintColor(230, 204, 240); public FlingerModule() { - super(CompiledFlingerModule::new); + super(ModItems.moduleProps() + .component(ModDataComponents.FLINGER_SETTINGS, FlingerSettings.DEFAULT), + CompiledFlingerModule::new); } @Override - public void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); - CompiledFlingerModule fs = new CompiledFlingerModule(null, itemstack); + public void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); + + FlingerSettings settings = stack.get(ModDataComponents.FLINGER_SETTINGS); + list.add(xlate("modularrouters.itemText.misc.flingerDetails", - colorText(fs.getSpeed(), ChatFormatting.AQUA), - colorText(fs.getPitch(), ChatFormatting.AQUA), - colorText(fs.getYaw(), ChatFormatting.AQUA) + colorText(settings.speed(), ChatFormatting.AQUA), + colorText(settings.pitch(), ChatFormatting.AQUA), + colorText(settings.yaw(), ChatFormatting.AQUA) ).withStyle(ChatFormatting.YELLOW)); } diff --git a/src/main/java/me/desht/modularrouters/item/module/FluidModule1.java b/src/main/java/me/desht/modularrouters/item/module/FluidModule1.java index b676ec8f..aee3719a 100644 --- a/src/main/java/me/desht/modularrouters/item/module/FluidModule1.java +++ b/src/main/java/me/desht/modularrouters/item/module/FluidModule1.java @@ -3,16 +3,15 @@ import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.item.smartfilter.SmartFilterItem; import me.desht.modularrouters.logic.compiled.CompiledFluidModule1; +import me.desht.modularrouters.logic.compiled.CompiledFluidModule1.FluidModuleSettings; import me.desht.modularrouters.logic.filter.matchers.FluidMatcher; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; -import me.desht.modularrouters.util.ModuleHelper; -import me.desht.modularrouters.util.TranslatableEnum; import net.minecraft.ChatFormatting; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; @@ -25,27 +24,15 @@ import static me.desht.modularrouters.client.util.ClientUtil.xlate; public class FluidModule1 extends ModuleItem { - private static final TintColor TINT_COLOR = new TintColor(79, 191, 255); public FluidModule1() { super(ModItems.defaultProps(), CompiledFluidModule1::new); } - public enum FluidDirection implements TranslatableEnum { - IN, // to router - OUT; // from router - - @Override - public String getTranslationKey() { - return "modularrouters.itemText.fluid.direction." + this; - } - } - @Override public String getRegulatorTranslationKey(ItemStack stack) { - CompoundTag compound = ModuleHelper.validateNBT(stack); - boolean isAbsolute = compound.getBoolean(CompiledFluidModule1.NBT_REGULATE_ABSOLUTE); + boolean isAbsolute = stack.getOrDefault(ModDataComponents.FLUID_SETTINGS, FluidModuleSettings.DEFAULT).regulateAbsolute(); return "modularrouters.guiText.tooltip.regulator." + (isAbsolute ? "labelFluidmB" : "labelFluidPct"); } @@ -56,7 +43,7 @@ public MenuType getMenuType() { @Override protected Component getFilterItemDisplayName(ItemStack stack) { - return FluidUtil.getFluidContained(stack).map(FluidStack::getDisplayName).orElse(stack.getHoverName()); + return FluidUtil.getFluidContained(stack).map(FluidStack::getHoverName).orElse(stack.getHoverName()); } @Override @@ -96,10 +83,12 @@ public TintColor getItemTint() { } static void addFluidModuleInformation(ItemStack stack, List list) { - CompiledFluidModule1 cfm = new CompiledFluidModule1(null, stack); - list.add(xlate("modularrouters.itemText.fluid.direction", - xlate(cfm.getFluidDirection().getTranslationKey()).withStyle(ChatFormatting.AQUA)).withStyle(ChatFormatting.YELLOW)); +// CompiledFluidModule1 cfm = new CompiledFluidModule1(null, stack); + FluidModuleSettings settings = stack.getOrDefault(ModDataComponents.FLUID_SETTINGS.get(), FluidModuleSettings.DEFAULT); + list.add(xlate("modularrouters.itemText.transfer_direction", + xlate(settings.direction().getTranslationKey()).withStyle(ChatFormatting.AQUA)).withStyle(ChatFormatting.YELLOW)); list.add(xlate("modularrouters.itemText.fluid.maxTransfer", - colorText(cfm.getMaxTransfer(), ChatFormatting.AQUA)).withStyle(ChatFormatting.YELLOW)); + colorText(settings.maxTransfer(), ChatFormatting.AQUA)).withStyle(ChatFormatting.YELLOW)); } + } diff --git a/src/main/java/me/desht/modularrouters/item/module/FluidModule2.java b/src/main/java/me/desht/modularrouters/item/module/FluidModule2.java index c38c3f7b..5eabecfb 100644 --- a/src/main/java/me/desht/modularrouters/item/module/FluidModule2.java +++ b/src/main/java/me/desht/modularrouters/item/module/FluidModule2.java @@ -4,9 +4,11 @@ import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.item.smartfilter.SmartFilterItem; +import me.desht.modularrouters.logic.ModuleTargetList; import me.desht.modularrouters.logic.compiled.CompiledFluidModule2; import me.desht.modularrouters.logic.filter.matchers.FluidMatcher; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; @@ -20,11 +22,11 @@ import java.util.List; public class FluidModule2 extends TargetedModule implements IRangedModule, IPositionProvider { - private static final TintColor TINT_COLOR = new TintColor(64, 224, 255); public FluidModule2() { - super(ModItems.defaultProps(), CompiledFluidModule2::new); + super(ModItems.moduleProps() + .component(ModDataComponents.MODULE_TARGET_LIST, ModuleTargetList.EMPTY), CompiledFluidModule2::new); } @Override @@ -44,7 +46,7 @@ public MenuType getMenuType() { @Override protected Component getFilterItemDisplayName(ItemStack stack) { - return FluidUtil.getFluidContained(stack).map(FluidStack::getDisplayName).orElse(stack.getHoverName()); + return FluidUtil.getFluidContained(stack).map(FluidStack::getHoverName).orElse(stack.getHoverName()); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/IPickaxeUser.java b/src/main/java/me/desht/modularrouters/item/module/IPickaxeUser.java index b6889f45..87e3355b 100644 --- a/src/main/java/me/desht/modularrouters/item/module/IPickaxeUser.java +++ b/src/main/java/me/desht/modularrouters/item/module/IPickaxeUser.java @@ -1,24 +1,22 @@ package me.desht.modularrouters.item.module; -import me.desht.modularrouters.util.ModuleHelper; -import net.minecraft.nbt.CompoundTag; +import me.desht.modularrouters.core.ModDataComponents; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.ItemContainerContents; + +import java.util.List; public interface IPickaxeUser { - String NBT_PICKAXE = "Pickaxe"; + ItemContainerContents DEFAULT_PICK = ItemContainerContents.fromItems(List.of(new ItemStack(Items.STONE_PICKAXE))); default ItemStack getPickaxe(ItemStack moduleStack) { - CompoundTag tag = ModuleHelper.validateNBT(moduleStack); - if (tag.contains(NBT_PICKAXE)) { - return ItemStack.of(tag.getCompound(NBT_PICKAXE)); - } else { - return new ItemStack(Items.IRON_PICKAXE); - } + return moduleStack.getOrDefault(ModDataComponents.PICKAXE, DEFAULT_PICK) + .copyOne(); } default ItemStack setPickaxe(ItemStack moduleStack, ItemStack pickaxeStack) { - ModuleHelper.validateNBTForWriting(moduleStack).put(NBT_PICKAXE, pickaxeStack.save(new CompoundTag())); + moduleStack.set(ModDataComponents.PICKAXE, ItemContainerContents.fromItems(List.of(pickaxeStack))); return moduleStack; } } diff --git a/src/main/java/me/desht/modularrouters/item/module/IRangedModule.java b/src/main/java/me/desht/modularrouters/item/module/IRangedModule.java index 2b6f158a..4476196c 100644 --- a/src/main/java/me/desht/modularrouters/item/module/IRangedModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/IRangedModule.java @@ -1,14 +1,13 @@ package me.desht.modularrouters.item.module; -import me.desht.modularrouters.util.ModuleHelper; import net.minecraft.world.item.ItemStack; public interface IRangedModule { int getBaseRange(); int getHardMaxRange(); - default int getCurrentRange(ItemStack stack) { // yay java 8 - return Math.max(1, Math.min(getHardMaxRange(), getBaseRange() + ModuleHelper.getRangeModifier(stack))); + default int getCurrentRange(ItemStack stack) { + return Math.max(1, Math.min(getHardMaxRange(), getBaseRange() + ModuleItem.getRangeModifier(stack))); } default int getCurrentRange(int boost) { // yay java 8 diff --git a/src/main/java/me/desht/modularrouters/item/module/ModuleItem.java b/src/main/java/me/desht/modularrouters/item/module/ModuleItem.java index 33824b32..92df5e93 100644 --- a/src/main/java/me/desht/modularrouters/item/module/ModuleItem.java +++ b/src/main/java/me/desht/modularrouters/item/module/ModuleItem.java @@ -8,6 +8,7 @@ import me.desht.modularrouters.container.ModuleMenu; import me.desht.modularrouters.container.RouterMenu; import me.desht.modularrouters.container.handler.BaseModuleHandler.ModuleFilterHandler; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.item.MRBaseItem; @@ -17,11 +18,10 @@ import me.desht.modularrouters.logic.compiled.CompiledModule; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; import me.desht.modularrouters.logic.filter.matchers.SimpleItemMatcher; +import me.desht.modularrouters.logic.settings.*; import me.desht.modularrouters.util.MFLocator; -import me.desht.modularrouters.util.ModuleHelper; -import me.desht.modularrouters.util.TranslatableEnum; import net.minecraft.ChatFormatting; -import net.minecraft.core.Direction; +import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.level.ServerPlayer; @@ -29,14 +29,16 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.MenuProvider; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.ItemEnchantments; import net.minecraft.world.level.Level; import javax.annotation.Nonnull; @@ -49,95 +51,32 @@ import static me.desht.modularrouters.client.util.ClientUtil.xlate; public abstract class ModuleItem extends MRBaseItem implements ModItems.ITintable { - public enum ModuleFlags { - BLACKLIST(true, "F_blacklist"), - IGNORE_DAMAGE(false, "F_ignoreDamage"), - IGNORE_NBT(true, "F_ignoreNBT"), - IGNORE_TAGS(true, "F_ignoreTags"); - - private final boolean defaultValue; - private final String name; - - ModuleFlags(boolean defaultValue, String name) { - this.defaultValue = defaultValue; - this.name = name; - } - - public boolean getDefaultValue() { - return defaultValue; - } - - public String getName() { - return name; - } + private final BiFunction compiler; - public int getTextureY() { - return 32; - } + public ModuleItem(Properties props, BiFunction compiler) { + super(props); + this.compiler = compiler; } - // Direction relative to the facing of the router this module is installed in - public enum RelativeDirection { - NONE(0x00, " "), - DOWN(0x01, "▼"), - UP(0x02, "▲"), - LEFT(0x04, "◀"), - RIGHT(0x08, "▶"), - FRONT(0x10, "▣"), - BACK(0x20, "▤"); - - private final byte mask; - private final String symbol; - - RelativeDirection(int mask, String symbol) { - this.mask = (byte) mask; - this.symbol = symbol; - } - - public Direction toAbsolute(Direction current) { - return switch (this) { - case UP -> Direction.UP; - case DOWN -> Direction.DOWN; - case LEFT -> current.getClockWise(); - case BACK -> current.getOpposite(); - case RIGHT -> current.getCounterClockWise(); - default -> current; // including FRONT - }; - } - - public String getSymbol() { - return symbol; - } - - public byte getMask() { - return mask; - } - - public int getTextureX(boolean toggled) { - return ordinal() * 32 + (toggled ? 16 : 0); - } - - public int getTextureY() { - return 48; - } + public static ModuleSettings getCommonSettings(ItemStack moduleStack) { + return moduleStack.getOrDefault(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettings.DEFAULT); } - public enum Termination implements TranslatableEnum { - NONE, - RAN, - NOT_RAN; + public static void setRoundRobinCounter(ItemStack moduleStack, int counter) { + moduleStack.set(ModDataComponents.RR_COUNTER, counter); + } - @Override - public String getTranslationKey() { - return "modularrouters.guiText.tooltip.terminate." + this; - } + public static int getRoundRobinCounter(ItemStack moduleStack) { + return moduleStack.getOrDefault(ModDataComponents.RR_COUNTER, 0); } - final BiFunction compiler; + public static RedstoneBehaviour getRedstoneBehaviour(ItemStack moduleStack) { + return getCommonSettings(moduleStack).redstoneBehaviour(); + } - public ModuleItem(Properties props, BiFunction compiler) { - super(props); - this.compiler = compiler; + public static int getRangeModifier(ItemStack stack) { + AugmentCounter counter = new AugmentCounter(stack); + return counter.getAugmentCount(ModItems.RANGE_UP_AUGMENT.get()) - counter.getAugmentCount(ModItems.RANGE_DOWN_AUGMENT.get()); } final public CompiledModule compile(ModularRouterBlockEntity router, ItemStack stack) { @@ -192,8 +131,8 @@ public IItemMatcher getFilterItemMatcher(ItemStack stack) { } @Override - public void appendHoverText(ItemStack stack, @Nullable Level world, List list, TooltipFlag flag) { - super.appendHoverText(stack, world, list, flag); + public void appendHoverText(ItemStack stack, Item.TooltipContext context, List list, TooltipFlag flag) { + super.appendHoverText(stack, context, list, flag); if (ClientUtil.getHoveredSlot() instanceof RouterMenu.InstalledModuleSlot && !ClientUtil.isKeyDown(ClientSetup.keybindModuleInfo)) { Component key = ClientSetup.keybindConfigure.getKey().getDisplayName().copy().withStyle(ChatFormatting.DARK_AQUA); @@ -208,56 +147,61 @@ protected void addExtraInformation(ItemStack stack, List list) { addAugmentInformation(stack, list); } - protected void addSettingsInformation(ItemStack itemstack, List list) { + protected void addSettingsInformation(ItemStack stack, List list) { + ModuleSettings settings = getCommonSettings(stack); + if (isDirectional()) { - RelativeDirection dir = ModuleHelper.getRelativeDirection(itemstack); - MutableComponent itc = xlate(isOmniDirectional() && dir == RelativeDirection.NONE ? - "modularrouters.guiText.tooltip.allDirections" : "modularrouters.guiText.tooltip." + dir.toString()); + MutableComponent dirStr = getDirectionString(settings.facing()); list.add(xlate("modularrouters.guiText.label.direction").withStyle(ChatFormatting.YELLOW) .append(Component.literal(": ")) - .append(itc.withStyle(ChatFormatting.AQUA))); + .append(dirStr.withStyle(ChatFormatting.AQUA))); } - addFilterInformation(itemstack, list); + addFilterInformation(stack, list); - Component flags = formatFlag("IGNORE_DAMAGE", ModuleHelper.ignoreDamage(itemstack)) + ModuleFlags flags = ModuleFlags.forItem(stack); + + Component flagText = formatFlag("match_damage", flags.matchDamage()) .append(" | ") - .append(formatFlag("IGNORE_NBT", ModuleHelper.ignoreNBT(itemstack))) + .append(formatFlag("match_components", flags.matchComponents())) .append(" | ") - .append(formatFlag("IGNORE_TAGS", ModuleHelper.ignoreTags(itemstack))); - list.add(xlate("modularrouters.itemText.misc.flags").withStyle(ChatFormatting.YELLOW).append(": ").append(flags)); + .append(formatFlag("match_item_tags", flags.matchItemTags())); + list.add(xlate("modularrouters.itemText.misc.flags").withStyle(ChatFormatting.YELLOW).append(": ").append(flagText)); - boolean matchAll = ModuleHelper.isMatchAll(itemstack); list.add(xlate("modularrouters.itemText.misc.match").withStyle(ChatFormatting.YELLOW) .append(": ") - .append(xlate("modularrouters.itemText.misc." + (matchAll ? "matchAll" : "matchAny")) + .append(xlate("modularrouters.itemText.misc." + (flags.matchAllItems() ? "matchAll" : "matchAny")) .withStyle(ChatFormatting.AQUA))); if (this instanceof IRangedModule rm) { - int curRange = rm.getCurrentRange(itemstack); + int curRange = rm.getCurrentRange(stack); ChatFormatting col = curRange > rm.getBaseRange() ? ChatFormatting.GREEN : curRange < rm.getBaseRange() ? ChatFormatting.RED : ChatFormatting.AQUA; list.add(xlate("modularrouters.itemText.misc.rangeInfo", - colorText(rm.getCurrentRange(itemstack), col), + colorText(rm.getCurrentRange(stack), col), colorText(rm.getBaseRange(), ChatFormatting.AQUA), colorText(rm.getHardMaxRange(), ChatFormatting.AQUA) ).withStyle(ChatFormatting.YELLOW)); } - Termination termination = ModuleHelper.getTermination(itemstack); - if (termination != Termination.NONE) { + ModuleTermination termination = settings.termination(); + if (termination != ModuleTermination.NONE) { list.add(xlate(termination.getTranslationKey() + ".header").withStyle(ChatFormatting.YELLOW)); } if (this instanceof IPickaxeUser pickaxeUser) { - ItemStack pick = pickaxeUser.getPickaxe(itemstack); + ItemStack pick = pickaxeUser.getPickaxe(stack); list.add(xlate("modularrouters.itemText.misc.breakerPick").withStyle(ChatFormatting.YELLOW) .append(pick.getHoverName().plainCopy().withStyle(ChatFormatting.AQUA))); - EnchantmentHelper.getEnchantments(pick).forEach((ench, level) -> - list.add(Component.literal("▶ ").append(ench.getFullname(level).plainCopy().withStyle(ChatFormatting.AQUA)).withStyle(ChatFormatting.YELLOW))); + pick.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).entrySet().forEach(holder -> { + Enchantment ench = holder.getKey().value(); + list.add(Component.literal("▶ ") + .append(ench.getFullname(holder.getIntValue()).copy().withStyle(ChatFormatting.AQUA)) + .withStyle(ChatFormatting.YELLOW)); + }); } - int energy = getEnergyCost(itemstack); + int energy = getEnergyCost(stack); if (energy != 0) { list.add(xlate("modularrouters.itemText.misc.energyUsage", colorText(energy, ChatFormatting.AQUA)).withStyle(ChatFormatting.YELLOW)); } @@ -287,12 +231,12 @@ private void addAugmentInformation(ItemStack stack, List list) { public MutableComponent getDirectionString(RelativeDirection dir) { return isOmniDirectional() && dir == RelativeDirection.NONE ? xlate("modularrouters.guiText.tooltip.allDirections") : - xlate("modularrouters.guiText.tooltip." + dir.toString()); + xlate(dir.getTranslationKey()); } private MutableComponent formatFlag(String key, boolean flag) { return xlate("modularrouters.itemText.misc." + key) - .withStyle(flag ? ChatFormatting.DARK_GRAY : ChatFormatting.AQUA); + .withStyle(flag ? ChatFormatting.AQUA : ChatFormatting.DARK_GRAY); } protected Component getFilterItemDisplayName(ItemStack stack) { @@ -300,7 +244,8 @@ protected Component getFilterItemDisplayName(ItemStack stack) { } protected MutableComponent itemListHeader(ItemStack itemstack) { - return xlate("modularrouters.itemText.misc." + (ModuleHelper.isBlacklist(itemstack) ? "blacklist" : "whitelist")).withStyle(ChatFormatting.YELLOW); + boolean whiteList = ModuleFlags.forItem(itemstack).whiteList(); + return xlate("modularrouters.itemText.misc." + (whiteList ? "whitelist" : "blacklist")).withStyle(ChatFormatting.YELLOW); } private void addFilterInformation(ItemStack itemstack, List list) { @@ -347,7 +292,7 @@ public InteractionResultHolder use(Level world, Player player, Intera public boolean isFoil(ItemStack stack) { if (stack.getItem() instanceof IPickaxeUser pickaxeUser) { ItemStack pick = pickaxeUser.getPickaxe(stack); - return !pick.isEmpty() && !EnchantmentHelper.getEnchantments(pick).isEmpty(); + return !pick.isEmpty() && EnchantmentHelper.hasAnyEnchantments(pick); } return false; } @@ -360,11 +305,6 @@ public InteractionResultHolder onSneakRightClick(ItemStack stack, Lev return new InteractionResultHolder<>(InteractionResult.PASS, stack); } - @Override - public boolean onEntitySwing(ItemStack stack, LivingEntity entity) { - return false; - } - /** * Called server-side from ValidateModuleMessage * diff --git a/src/main/java/me/desht/modularrouters/item/module/PlacerModule.java b/src/main/java/me/desht/modularrouters/item/module/PlacerModule.java index 53d928df..d856f705 100644 --- a/src/main/java/me/desht/modularrouters/item/module/PlacerModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/PlacerModule.java @@ -7,11 +7,10 @@ import net.minecraft.world.item.ItemStack; public class PlacerModule extends ModuleItem { - private static final TintColor TINT_COLOR = new TintColor(240, 208, 208); public PlacerModule() { - super(ModItems.defaultProps(), CompiledPlacerModule::new); + super(ModItems.moduleProps(), CompiledPlacerModule::new); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/PlayerModule.java b/src/main/java/me/desht/modularrouters/item/module/PlayerModule.java index fa2ca9d3..ff7ad78c 100644 --- a/src/main/java/me/desht/modularrouters/item/module/PlayerModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/PlayerModule.java @@ -4,10 +4,12 @@ import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.item.IPlayerOwned; import me.desht.modularrouters.logic.compiled.CompiledPlayerModule; +import me.desht.modularrouters.logic.compiled.CompiledPlayerModule.PlayerSettings; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -15,6 +17,7 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ResolvableProfile; import net.minecraft.world.item.context.UseOnContext; import java.util.List; @@ -23,28 +26,31 @@ import static me.desht.modularrouters.client.util.ClientUtil.xlate; public class PlayerModule extends ModuleItem implements IPlayerOwned { - private static final TintColor TINT_COLOR = new TintColor(255, 208, 144); public PlayerModule() { - super(ModItems.defaultProps(), CompiledPlayerModule::new); + super(ModItems.moduleProps() + .component(ModDataComponents.PLAYER_SETTINGS, PlayerSettings.DEFAULT), + CompiledPlayerModule::new); } @Override - public void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); + public void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); + + PlayerSettings settings = stack.getOrDefault(ModDataComponents.PLAYER_SETTINGS, PlayerSettings.DEFAULT); + ResolvableProfile profile = stack.get(ModDataComponents.OWNER); - CompiledPlayerModule cpm = new CompiledPlayerModule(null, itemstack); - String owner = cpm.getPlayerName() == null ? "-" : cpm.getPlayerName(); + String owner = profile == null ? "-" : profile.gameProfile().getName(); list.add(xlate("modularrouters.itemText.security.owner", colorText(owner, ChatFormatting.AQUA)).withStyle(ChatFormatting.YELLOW)); Component c = xlate("modularrouters.itemText.misc.operation").withStyle(ChatFormatting.YELLOW) .append(": ") .append(xlate("block.modularrouters.modular_router") .append(" ") - .append(cpm.getOperation().getSymbol()) + .append(settings.direction().getSymbol()) .append(" ") - .append(xlate(cpm.getSection().getTranslationKey())) + .append(xlate(settings.section().getTranslationKey())) .withStyle(ChatFormatting.AQUA) ); list.add(c); diff --git a/src/main/java/me/desht/modularrouters/item/module/PullerModule1.java b/src/main/java/me/desht/modularrouters/item/module/PullerModule1.java index c1de1005..b5ef03ea 100644 --- a/src/main/java/me/desht/modularrouters/item/module/PullerModule1.java +++ b/src/main/java/me/desht/modularrouters/item/module/PullerModule1.java @@ -7,11 +7,10 @@ import net.minecraft.world.item.ItemStack; public class PullerModule1 extends ModuleItem { - private static final TintColor TINT_COLOR = new TintColor(192, 192, 255); public PullerModule1() { - super(ModItems.defaultProps(), CompiledPullerModule1::new); + super(ModItems.moduleProps(), CompiledPullerModule1::new); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/PullerModule2.java b/src/main/java/me/desht/modularrouters/item/module/PullerModule2.java index 7b10370f..0f7cdf4e 100644 --- a/src/main/java/me/desht/modularrouters/item/module/PullerModule2.java +++ b/src/main/java/me/desht/modularrouters/item/module/PullerModule2.java @@ -8,11 +8,10 @@ import net.minecraft.world.item.ItemStack; public class PullerModule2 extends TargetedModule implements IRangedModule, IPositionProvider { - private static final TintColor TINT_COLOR = new TintColor(128, 128, 255); public PullerModule2() { - super(ModItems.defaultProps(), CompiledPullerModule2::new); + super(ModItems.moduleProps(), CompiledPullerModule2::new); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/SenderModule1.java b/src/main/java/me/desht/modularrouters/item/module/SenderModule1.java index 62784935..6897dec4 100644 --- a/src/main/java/me/desht/modularrouters/item/module/SenderModule1.java +++ b/src/main/java/me/desht/modularrouters/item/module/SenderModule1.java @@ -7,11 +7,10 @@ import net.minecraft.world.item.ItemStack; public class SenderModule1 extends ModuleItem implements IRangedModule { - private static final TintColor TINT_COLOR = new TintColor(221, 255, 163); public SenderModule1() { - super(ModItems.defaultProps(), CompiledSenderModule1::new); + super(ModItems.moduleProps(), CompiledSenderModule1::new); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/SenderModule2.java b/src/main/java/me/desht/modularrouters/item/module/SenderModule2.java index 68c93eb4..b80d05bb 100644 --- a/src/main/java/me/desht/modularrouters/item/module/SenderModule2.java +++ b/src/main/java/me/desht/modularrouters/item/module/SenderModule2.java @@ -7,20 +7,20 @@ import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.compiled.CompiledModule; import me.desht.modularrouters.logic.compiled.CompiledSenderModule2; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import java.util.function.BiFunction; public class SenderModule2 extends TargetedModule implements IRangedModule, IPositionProvider { - private static final TintColor TINT_COLOR = new TintColor(149, 255, 93); public SenderModule2() { - super(ModItems.defaultProps(), CompiledSenderModule2::new); + super(ModItems.moduleProps(), CompiledSenderModule2::new); } - public SenderModule2(BiFunction compiler) { - super(ModItems.defaultProps(), compiler); + protected SenderModule2(Item.Properties properties, BiFunction compiler) { + super(properties, compiler); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/SenderModule3.java b/src/main/java/me/desht/modularrouters/item/module/SenderModule3.java index c8c4a675..24d23120 100644 --- a/src/main/java/me/desht/modularrouters/item/module/SenderModule3.java +++ b/src/main/java/me/desht/modularrouters/item/module/SenderModule3.java @@ -10,11 +10,10 @@ import net.minecraft.world.item.ItemStack; public class SenderModule3 extends TargetedModule implements IPositionProvider { - private static final TintColor TINT_COLOR = new TintColor(25, 255, 11); public SenderModule3() { - super(ModItems.defaultProps(), CompiledSenderModule3::new); + super(ModItems.moduleProps(), CompiledSenderModule3::new); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/module/TargetedModule.java b/src/main/java/me/desht/modularrouters/item/module/TargetedModule.java index dcf0a753..60eba57b 100644 --- a/src/main/java/me/desht/modularrouters/item/module/TargetedModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/TargetedModule.java @@ -5,27 +5,25 @@ import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModSounds; import me.desht.modularrouters.logic.ModuleTarget; +import me.desht.modularrouters.logic.ModuleTargetList; import me.desht.modularrouters.logic.compiled.CompiledModule; import me.desht.modularrouters.util.BlockUtil; import me.desht.modularrouters.util.InventoryUtils; import me.desht.modularrouters.util.MiscUtil; -import me.desht.modularrouters.util.ModuleHelper; import net.minecraft.ChatFormatting; -import net.minecraft.Util; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.GlobalPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; @@ -43,14 +41,11 @@ import static me.desht.modularrouters.util.MiscUtil.asMutableComponent; /** - * Represents a module with a specific target block or blocks (blockpos stored in itemstack NBT). + * Represents a module with a specific target block or blocks (stored in "modularrouters:module_target_list" component). */ public abstract class TargetedModule extends ModuleItem { - private static final String NBT_TARGET = "Target"; - private static final String NBT_MULTI_TARGET = "MultiTarget"; - - TargetedModule(Item.Properties props, BiFunction compiler) { - super(props, compiler); + protected TargetedModule(Item.Properties props, BiFunction compiler) { + super(props.component(ModDataComponents.MODULE_TARGET_LIST, ModuleTargetList.EMPTY), compiler); } @Override @@ -114,7 +109,7 @@ private void handleMultiTarget(ItemStack stack, Player player, Level world, Bloc world.playSound(null, pos, ModSounds.SUCCESS.get(), SoundSource.BLOCKS, ConfigHolder.client.sound.bleepVolume.get().floatValue(), removing ? 1.1f : 1.3f); - setTargets(stack, targets); + setTargetList(stack, targets); } } @@ -126,15 +121,15 @@ public void addUsageInformation(ItemStack itemstack, List list) { } @Override - protected void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); + protected void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); Set targets; if (getMaxTargets() > 1) { - targets = getTargets(itemstack, false); + targets = getTargets(stack, false); } else { - targets = Sets.newHashSet(getTarget(itemstack)); + targets = Sets.newHashSet(getTarget(stack)); } for (ModuleTarget target : targets) { @@ -143,7 +138,7 @@ protected void addSettingsInformation(ItemStack itemstack, List list) list.add(msg); ClientUtil.getOpenItemRouter().ifPresent(router -> { ModuleTarget moduleTarget = new ModuleTarget(router.getGlobalPos()); - TargetValidation val = validateTarget(itemstack, moduleTarget, target, false); + TargetValidation val = validateTarget(stack, moduleTarget, target, false); if (val != TargetValidation.OK) { list.add(xlate(val.translationKey()).withStyle(val.getColor())); } @@ -176,12 +171,12 @@ private static void setTarget(ItemStack stack, Level world, BlockPos pos, Direct ModularRouters.LOGGER.warn("TargetModule.setTarget() should not be called client-side!"); return; } - CompoundTag compound = ModuleHelper.validateNBTForWriting(stack); + if (pos == null) { - compound.remove(NBT_TARGET); + stack.set(ModDataComponents.MODULE_TARGET_LIST, ModuleTargetList.EMPTY); } else { ModuleTarget mt = new ModuleTarget(MiscUtil.makeGlobalPos(world, pos), face, BlockUtil.getBlockName(world, pos)); - compound.put(NBT_TARGET, mt.toNBT()); + stack.set(ModDataComponents.MODULE_TARGET_LIST, ModuleTargetList.singleTarget(mt)); } } @@ -204,15 +199,12 @@ public static ModuleTarget getTarget(ItemStack stack) { * @return targeting data */ public static ModuleTarget getTarget(ItemStack stack, boolean checkBlockName) { - CompoundTag compound = stack.getTagElement(ModularRouters.MODID); - if (compound != null && compound.getTagType(NBT_TARGET) == Tag.TAG_COMPOUND) { - ModuleTarget target = ModuleTarget.fromNBT(compound.getCompound(NBT_TARGET)); - if (checkBlockName) { - ModuleTarget newTarget = updateTargetBlockName(stack, target); - if (newTarget != null) return newTarget; - } - return target; + ModuleTargetList targetList = stack.getOrDefault(ModDataComponents.MODULE_TARGET_LIST, ModuleTargetList.EMPTY); + + if (!targetList.isEmpty()) { + return checkBlockName ? updateTargetBlockName(stack, targetList.getSingle()) : targetList.getSingle(); } + return null; } @@ -226,35 +218,32 @@ public static ModuleTarget getTarget(ItemStack stack, boolean checkBlockName) { public static Set getTargets(ItemStack stack, boolean checkBlockName) { Set result = Sets.newHashSet(); - CompoundTag compound = stack.getTagElement(ModularRouters.MODID); - if (compound != null && compound.getTagType(NBT_MULTI_TARGET) == Tag.TAG_LIST) { - ListTag list = compound.getList(NBT_MULTI_TARGET, Tag.TAG_COMPOUND); - for (int i = 0; i < list.size(); i++) { - ModuleTarget target = ModuleTarget.fromNBT(list.getCompound(i)); - if (checkBlockName) { - ModuleTarget newTarget = updateTargetBlockName(stack, target); - result.add(newTarget != null ? newTarget : target); - } else { - result.add(target); - } + stack.getOrDefault(ModDataComponents.MODULE_TARGET_LIST, ModuleTargetList.EMPTY).targets().forEach(target -> { + if (checkBlockName) { + target = updateTargetBlockName(stack, target); } - } + if (target != null) { + result.add(target); + } + }); + return result; } - private static void setTargets(ItemStack stack, Set targets) { - CompoundTag compound = ModuleHelper.validateNBTForWriting(stack); - compound.put(NBT_MULTI_TARGET, Util.make(new ListTag(), l -> targets.forEach(t -> l.add(t.toNBT())))); + private static void setTargetList(ItemStack stack, Set targets) { + stack.set(ModDataComponents.MODULE_TARGET_LIST, new ModuleTargetList(List.copyOf(targets))); } private static ModuleTarget updateTargetBlockName(ItemStack stack, ModuleTarget target) { - ServerLevel w = MiscUtil.getWorldForGlobalPos(target.gPos); + ServerLevel level = MiscUtil.getWorldForGlobalPos(target.gPos); BlockPos pos = target.gPos.pos(); - if (w != null && w.getChunkSource().hasChunk(pos.getX() >> 4, pos.getZ() >> 4)) { - String invName = BlockUtil.getBlockName(w, pos); + if (level != null && level.getChunkSource().hasChunk(pos.getX() >> 4, pos.getZ() >> 4)) { + String invName = BlockUtil.getBlockName(level, pos); if (!target.blockTranslationKey.equals(invName)) { - setTarget(stack, w, pos, target.face); + setTarget(stack, level, pos, target.face); return new ModuleTarget(target.gPos, target.face, invName); + } else { + return target; } } return null; @@ -333,19 +322,30 @@ protected boolean isRangeLimited() { return true; } - enum TargetValidation { - OK, - OUT_OF_RANGE, - NOT_LOADED, - NOT_INVENTORY, - BAD_DIMENSION; + enum TargetValidation implements StringRepresentable { + OK("ok"), + OUT_OF_RANGE("out_of_range"), + NOT_LOADED("not_loaded"), + NOT_INVENTORY("no_inventory"), + BAD_DIMENSION("bad_dimension"); + + private final String name; + + TargetValidation(String name) { + this.name = name; + } ChatFormatting getColor() { return this == OK ? ChatFormatting.GREEN : ChatFormatting.RED; } String translationKey() { - return "modularrouters.chatText.targetValidation." + this; + return "modularrouters.chatText.targetValidation." + getSerializedName(); + } + + @Override + public String getSerializedName() { + return name; } } } diff --git a/src/main/java/me/desht/modularrouters/item/module/VacuumModule.java b/src/main/java/me/desht/modularrouters/item/module/VacuumModule.java index 577d340c..91e5bcb4 100644 --- a/src/main/java/me/desht/modularrouters/item/module/VacuumModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/VacuumModule.java @@ -4,10 +4,13 @@ import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModMenuTypes; import me.desht.modularrouters.integration.XPCollection; +import me.desht.modularrouters.item.augment.AugmentItem; import me.desht.modularrouters.logic.compiled.CompiledVacuumModule; +import me.desht.modularrouters.logic.compiled.CompiledVacuumModule.VacuumSettings; import me.desht.modularrouters.util.MiscUtil; import me.desht.modularrouters.util.ModNameCache; import net.minecraft.ChatFormatting; @@ -18,11 +21,12 @@ import java.util.List; public class VacuumModule extends ModuleItem implements IRangedModule { - private static final TintColor TINT_COLOR = new TintColor(120, 48, 191); public VacuumModule() { - super(ModItems.defaultProps(), CompiledVacuumModule::new); + super(ModItems.moduleProps() + .component(ModDataComponents.VACUUM_SETTINGS.get(), VacuumSettings.DEFAULT), + CompiledVacuumModule::new); } @Override @@ -31,18 +35,20 @@ public MenuType getMenuType() { } @Override - public void addSettingsInformation(ItemStack itemstack, List list) { - super.addSettingsInformation(itemstack, list); + public void addSettingsInformation(ItemStack stack, List list) { + super.addSettingsInformation(stack, list); + + boolean xpMode = new AugmentItem.AugmentCounter(stack).getAugmentCount(ModItems.XP_VACUUM_AUGMENT) > 0; - CompiledVacuumModule cvm = new CompiledVacuumModule(null, itemstack); - if (cvm.isXpMode()) { - XPCollection.XPCollectionType type = cvm.getXPCollectionType(); + if (xpMode) { + VacuumSettings settings = stack.get(ModDataComponents.VACUUM_SETTINGS); + XPCollection.XPCollectionType type = settings.collectionType(); Component modName = Component.literal(ModNameCache.getModName(type.getModId())).withStyle(ChatFormatting.BLUE); Component title = type.getDisplayName().plainCopy().withStyle(ChatFormatting.AQUA); list.add(ClientUtil.xlate("modularrouters.guiText.label.xpVacuum") .append(": ").withStyle(ChatFormatting.YELLOW) .append(title).append(" - ").append(modName)); - if (cvm.isAutoEjecting() && !type.isSolid()) { + if (settings.autoEject() && !type.isSolid()) { list.add(MiscUtil.settingsStr(ChatFormatting.GREEN.toString(), ClientUtil.xlate("modularrouters.guiText.tooltip.xpVacuum.ejectFluid"))); } } diff --git a/src/main/java/me/desht/modularrouters/item/module/VoidModule.java b/src/main/java/me/desht/modularrouters/item/module/VoidModule.java index 1d61357a..9a83a0fb 100644 --- a/src/main/java/me/desht/modularrouters/item/module/VoidModule.java +++ b/src/main/java/me/desht/modularrouters/item/module/VoidModule.java @@ -10,7 +10,7 @@ public class VoidModule extends ModuleItem { private static final TintColor TINT_COLOR = new TintColor(255, 0, 0); public VoidModule() { - super(ModItems.defaultProps(), CompiledVoidModule::new); + super(ModItems.moduleProps(), CompiledVoidModule::new); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/smartfilter/BulkItemFilter.java b/src/main/java/me/desht/modularrouters/item/smartfilter/BulkItemFilter.java index 9d4473ad..92ce8fda 100644 --- a/src/main/java/me/desht/modularrouters/item/smartfilter/BulkItemFilter.java +++ b/src/main/java/me/desht/modularrouters/item/smartfilter/BulkItemFilter.java @@ -1,31 +1,30 @@ package me.desht.modularrouters.item.smartfilter; -import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.container.AbstractSmartFilterMenu; import me.desht.modularrouters.container.BulkItemFilterMenu; import me.desht.modularrouters.container.handler.BaseModuleHandler; import me.desht.modularrouters.container.handler.BaseModuleHandler.BulkFilterHandler; import me.desht.modularrouters.core.ModSounds; -import me.desht.modularrouters.logic.filter.Filter.Flags; import me.desht.modularrouters.logic.filter.matchers.BulkItemMatcher; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; +import me.desht.modularrouters.logic.settings.ModuleFlags; +import me.desht.modularrouters.network.messages.BulkFilterUpdateMessage; import me.desht.modularrouters.network.messages.GuiSyncMessage; import me.desht.modularrouters.util.InventoryUtils; import me.desht.modularrouters.util.MFLocator; -import me.desht.modularrouters.util.ModuleHelper; import me.desht.modularrouters.util.SetofItemStack; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.neoforged.neoforge.items.IItemHandler; -import net.neoforged.neoforge.items.ItemHandlerHelper; import java.util.Comparator; import java.util.List; @@ -35,18 +34,15 @@ public class BulkItemFilter extends SmartFilterItem { @Override public IItemMatcher compile(ItemStack filterStack, ItemStack moduleStack) { - Flags flags = moduleStack.isEmpty() ? Flags.DEFAULT_FLAGS : new Flags(moduleStack); + ModuleFlags flags = ModuleFlags.forItem(moduleStack); + SetofItemStack stacks = getFilterItems(filterStack, flags); return new BulkItemMatcher(stacks, flags); } - private static SetofItemStack getFilterItems(ItemStack filterStack, Flags flags) { - if (filterStack.hasTag()) { - BulkFilterHandler handler = new BulkFilterHandler(filterStack, null); - return SetofItemStack.fromItemHandler(handler, flags); - } else { - return new SetofItemStack(Flags.DEFAULT_FLAGS); - } + private static SetofItemStack getFilterItems(ItemStack filterStack, ModuleFlags flags) { + BulkFilterHandler handler = new BulkFilterHandler(filterStack, null); + return SetofItemStack.fromItemHandler(handler, flags); } @Override @@ -70,7 +66,8 @@ public InteractionResult useOn(UseOnContext ctx) { } else if (player != null && player.isShiftKeyDown()) { return InventoryUtils.getInventory(world, ctx.getClickedPos(), ctx.getClickedFace()).map(handler -> { int nAdded = mergeInventory(stack, handler); - player.displayClientMessage(Component.translatable("modularrouters.chatText.misc.inventoryMerged", nAdded, stack.getHoverName()), false); + player.displayClientMessage(Component.translatable("modularrouters.chatText.misc.inventoryMerged", + nAdded, stack.getHoverName()), false); world.playSound(null, ctx.getClickedPos(), ModSounds.SUCCESS.get(), SoundSource.MASTER, ConfigHolder.client.sound.bleepVolume.get().floatValue(), 1.0f); return InteractionResult.SUCCESS; @@ -80,15 +77,15 @@ public InteractionResult useOn(UseOnContext ctx) { } } - @Override - public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack) { - if (player.containerMenu instanceof BulkItemFilterMenu con) { - Flags flags = moduleStack.isEmpty() ? Flags.DEFAULT_FLAGS : new Flags(moduleStack); + public GuiSyncMessage onReceiveSettingsMessage(Player player, BulkFilterUpdateMessage message, ItemStack moduleStack) { + if (player.containerMenu instanceof BulkItemFilterMenu filterMenu) { + ModuleFlags flags = ModuleFlags.forItem(moduleStack); switch (message.op()) { - case CLEAR_ALL -> con.clearSlots(); - case MERGE -> message.getTargetInventory().ifPresent(h -> con.mergeInventory(h, flags, false)); - case LOAD -> message.getTargetInventory().ifPresent(h -> con.mergeInventory(h, flags, true)); - default -> ModularRouters.LOGGER.warn("received unexpected message type " + message.op() + " for " + filterStack); + case CLEAR_ALL -> filterMenu.clearSlots(); + case MERGE -> message.getTargetInventory() + .ifPresent(h -> filterMenu.mergeInventory(h, flags, false)); + case LOAD -> message.getTargetInventory() + .ifPresent(h -> filterMenu.mergeInventory(h, flags, true)); } } return null; @@ -96,23 +93,23 @@ public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMess @Override public int getSize(ItemStack filterStack) { - return BaseModuleHandler.getFilterSize(filterStack, ModuleHelper.NBT_FILTER); + return BaseModuleHandler.getFilterItemCount(filterStack); } private int mergeInventory(ItemStack filterStack, IItemHandler srcInventory) { - SetofItemStack stacks = getFilterItems(filterStack, Flags.DEFAULT_FLAGS); + SetofItemStack stacks = getFilterItems(filterStack, ModuleFlags.DEFAULT); int origSize = stacks.size(); for (int i = 0; i < srcInventory.getSlots() && stacks.size() < FILTER_SIZE; i++) { ItemStack stack = srcInventory.getStackInSlot(i); if (!stack.isEmpty()) { - stacks.add(ItemHandlerHelper.copyStackWithSize(stack, 1)); + stacks.add(stack.copyWithCount(1)); } } BulkFilterHandler handler = new BulkFilterHandler(filterStack, null); int slot = 0; - Comparator comp = (o1, o2) -> o1.getHoverName().toString().compareTo(o2.getHoverName().getString()); + Comparator comp = (s1, s2) -> s1.getHoverName().toString().compareTo(s2.getHoverName().getString()); for (ItemStack stack : stacks.stream().sorted(comp).toList()) { handler.setStackInSlot(slot++, stack); } diff --git a/src/main/java/me/desht/modularrouters/item/smartfilter/InspectionFilter.java b/src/main/java/me/desht/modularrouters/item/smartfilter/InspectionFilter.java index 8a962849..90a4f748 100644 --- a/src/main/java/me/desht/modularrouters/item/smartfilter/InspectionFilter.java +++ b/src/main/java/me/desht/modularrouters/item/smartfilter/InspectionFilter.java @@ -1,33 +1,27 @@ package me.desht.modularrouters.item.smartfilter; -import com.google.common.collect.Lists; -import me.desht.modularrouters.ModularRouters; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; import me.desht.modularrouters.logic.filter.matchers.InspectionMatcher; -import me.desht.modularrouters.logic.filter.matchers.InspectionMatcher.Comparison; import me.desht.modularrouters.logic.filter.matchers.InspectionMatcher.ComparisonList; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; -import me.desht.modularrouters.network.messages.GuiSyncMessage; import net.minecraft.ChatFormatting; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import java.util.List; -import java.util.stream.Collectors; import static me.desht.modularrouters.client.util.ClientUtil.xlate; public class InspectionFilter extends SmartFilterItem { - private static final String NBT_MATCH_ALL = "MatchAll"; - private static final String NBT_ITEMS = "Items"; - public static final String NBT_COMPARISON = "Comparison"; public static final int MAX_SIZE = 6; + public InspectionFilter() { + super(ModItems.defaultProps() + .component(ModDataComponents.COMPARISON_LIST, ComparisonList.DEFAULT) + ); + } + @Override public IItemMatcher compile(ItemStack filterStack, ItemStack moduleStack) { return new InspectionMatcher(getComparisonList(filterStack)); @@ -42,68 +36,52 @@ public boolean hasMenu() { public void addExtraInformation(ItemStack itemstack, List list) { super.addExtraInformation(itemstack, list); ComparisonList comparisonList = getComparisonList(itemstack); - if (!comparisonList.items.isEmpty()) { - list.add(xlate("modularrouters.guiText.label.matchAll." + comparisonList.isMatchAll()).append(":").withStyle(ChatFormatting.YELLOW)); - for (Comparison c : comparisonList.items) { - list.add(Component.literal("• ").append(c.asLocalizedText().withStyle(ChatFormatting.AQUA))); - } + if (!comparisonList.isEmpty()) { + list.add(xlate("modularrouters.guiText.label.matchAll." + comparisonList.matchAll()).append(":").withStyle(ChatFormatting.YELLOW)); + comparisonList.items().stream() + .map(c -> Component.literal("• ").append(c.asLocalizedText().withStyle(ChatFormatting.AQUA))) + .forEach(list::add); } } public static ComparisonList getComparisonList(ItemStack filterStack) { - CompoundTag compound = filterStack.getTagElement(ModularRouters.MODID); - if (compound != null) { - boolean matchAll = compound.getBoolean(NBT_MATCH_ALL); - List l = Lists.newArrayList(); - ListTag items = compound.getList(NBT_ITEMS, Tag.TAG_STRING); - for (int i = 0; i < items.size(); i++) { - l.add(Comparison.fromString(items.getString(i))); - } - return new ComparisonList(l, matchAll); - } else { - return new ComparisonList(Lists.newArrayList(), false); - } + return filterStack.get(ModDataComponents.COMPARISON_LIST.get()); } - private void setComparisonList(ItemStack filterStack, ComparisonList comparisonList) { - ListTag l = comparisonList.items.stream().map(comp -> StringTag.valueOf(comp.toString())).collect(Collectors.toCollection(ListTag::new)); - CompoundTag compound = filterStack.getOrCreateTagElement(ModularRouters.MODID); - compound.putBoolean(NBT_MATCH_ALL, comparisonList.isMatchAll()); - compound.put(NBT_ITEMS, l); + public static void setComparisonList(ItemStack filterStack, ComparisonList comparisonList) { + filterStack.set(ModDataComponents.COMPARISON_LIST.get(), comparisonList); } - @Override - public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack) { - ComparisonList comparisonList = getComparisonList(filterStack); - - switch (message.op()) { - case ADD_STRING -> { - if (comparisonList.items.size() < MAX_SIZE) { - Comparison c = Comparison.fromString(message.payload().getString(NBT_COMPARISON)); - comparisonList.items.add(c); - setComparisonList(filterStack, comparisonList); - return new GuiSyncMessage(filterStack); - } - } - case REMOVE_AT -> { - int pos = message.payload().getInt("Pos"); - if (pos >= 0 && pos < comparisonList.items.size()) { - comparisonList.items.remove(pos); - setComparisonList(filterStack, comparisonList); - return new GuiSyncMessage(filterStack); - } - } - case ANY_ALL_FLAG -> { - comparisonList.setMatchAll(message.payload().getBoolean(NBT_MATCH_ALL)); - setComparisonList(filterStack, comparisonList); - return new GuiSyncMessage(filterStack); - } - } - return null; - } +// @Override +// public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack) { +// ComparisonList comparisonList = getComparisonList(filterStack); +// +// switch (message.op()) { +// case ADD_STRING -> { +// if (comparisonList.items().size() < MAX_SIZE) { +// Comparison.CODEC.parse(NbtOps.INSTANCE, message.payload().getCompound(NBT_COMPARISON)).result().ifPresent(c -> { +// setComparisonList(filterStack, comparisonList.addComparison(c)); +// }); +// return new GuiSyncMessage(filterStack); +// } +// } +// case REMOVE_AT -> { +// int pos = message.payload().getInt("Pos"); +// if (pos >= 0 && pos < comparisonList.items().size()) { +// setComparisonList(filterStack, comparisonList.removeAt(pos)); +// return new GuiSyncMessage(filterStack); +// } +// } +// case ANY_ALL_FLAG -> { +// setComparisonList(filterStack, comparisonList.setMatchAll(message.payload().getBoolean(NBT_MATCH_ALL))); +// return new GuiSyncMessage(filterStack); +// } +// } +// return null; +// } @Override public int getSize(ItemStack filterStack) { - return 0; + return getComparisonList(filterStack).items().size(); } } diff --git a/src/main/java/me/desht/modularrouters/item/smartfilter/ModFilter.java b/src/main/java/me/desht/modularrouters/item/smartfilter/ModFilter.java index 5a7082b4..e33bc579 100644 --- a/src/main/java/me/desht/modularrouters/item/smartfilter/ModFilter.java +++ b/src/main/java/me/desht/modularrouters/item/smartfilter/ModFilter.java @@ -1,70 +1,52 @@ package me.desht.modularrouters.item.smartfilter; -import com.google.common.collect.Lists; -import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.container.AbstractSmartFilterMenu; import me.desht.modularrouters.container.ModFilterMenu; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; import me.desht.modularrouters.logic.filter.matchers.ModMatcher; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; -import me.desht.modularrouters.network.messages.GuiSyncMessage; import me.desht.modularrouters.util.MFLocator; import me.desht.modularrouters.util.ModNameCache; import net.minecraft.ChatFormatting; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import java.util.List; -import java.util.stream.Collectors; public class ModFilter extends SmartFilterItem { - private static final String NBT_MODS = "Mods"; public static final int MAX_SIZE = 6; - @Override - public IItemMatcher compile(ItemStack filterStack, ItemStack moduleStack) { - return new ModMatcher(getModList(filterStack)); + public ModFilter() { + super(ModItems.defaultProps() + .component(ModDataComponents.FILTER_STRINGS, List.of())); } public static List getModList(ItemStack filterStack) { - CompoundTag tag = filterStack.getTagElement(ModularRouters.MODID); - if (tag != null) { - ListTag items = tag.getList(NBT_MODS, Tag.TAG_STRING); - List res = Lists.newArrayListWithExpectedSize(items.size()); - for (int i = 0; i < items.size(); i++) { - res.add(items.getString(i)); - } - return res; - } else { - return Lists.newArrayList(); - } + return filterStack.getOrDefault(ModDataComponents.FILTER_STRINGS, List.of()); } - private static void setModList(ItemStack filterStack, List mods) { - ListTag list = mods.stream().map(StringTag::valueOf).collect(Collectors.toCollection(ListTag::new)); - filterStack.getOrCreateTagElement(ModularRouters.MODID).put(NBT_MODS, list); + public static void setModList(ItemStack filterStack, List mods) { + filterStack.set(ModDataComponents.FILTER_STRINGS, mods); + } + + @Override + public IItemMatcher compile(ItemStack filterStack, ItemStack moduleStack) { + return new ModMatcher(getModList(filterStack)); } @Override public void addExtraInformation(ItemStack stack, List list) { super.addExtraInformation(stack, list); - if (stack.getTagElement(ModularRouters.MODID) != null) { - List l = getModList(stack); - addCountInfo(list, l.size()); - list.addAll(l.stream() - .map(ModNameCache::getModName) - .map(s -> " • " + ChatFormatting.AQUA + s) - .map(Component::literal) - .toList()); - } else { - addCountInfo(list, 0); - } + + List mods = getModList(stack); + addCountInfo(list, mods.size()); + list.addAll(mods.stream() + .map(ModNameCache::getModName) + .map(s -> " • " + ChatFormatting.AQUA + s) + .map(Component::literal) + .toList()); } @Override @@ -72,36 +54,8 @@ public AbstractSmartFilterMenu createMenu(int windowId, Inventory invPlayer, MFL return new ModFilterMenu(windowId, invPlayer, loc); } - @Override - public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack) { - List l; - switch (message.op()) { - case ADD_STRING -> { - String modId = message.payload().getString("ModId"); - l = getModList(filterStack); - if (l.size() < MAX_SIZE && !l.contains(modId)) { - l.add(modId); - setModList(filterStack, l); - return new GuiSyncMessage(filterStack); - } - } - case REMOVE_AT -> { - int pos = message.payload().getInt("Pos"); - l = getModList(filterStack); - if (pos >= 0 && pos < l.size()) { - l.remove(pos); - setModList(filterStack, l); - return new GuiSyncMessage(filterStack); - } - } - default -> ModularRouters.LOGGER.warn("received unexpected message type " + message.op() + " for " + filterStack); - } - return null; - } - @Override public int getSize(ItemStack filterStack) { - CompoundTag tag = filterStack.getTagElement(ModularRouters.MODID); - return tag != null ? tag.getList(NBT_MODS, Tag.TAG_STRING).size() : 0; + return getModList(filterStack).size(); } } diff --git a/src/main/java/me/desht/modularrouters/item/smartfilter/RegexFilter.java b/src/main/java/me/desht/modularrouters/item/smartfilter/RegexFilter.java index b27cc516..9d3e8499 100644 --- a/src/main/java/me/desht/modularrouters/item/smartfilter/RegexFilter.java +++ b/src/main/java/me/desht/modularrouters/item/smartfilter/RegexFilter.java @@ -1,62 +1,44 @@ package me.desht.modularrouters.item.smartfilter; -import com.google.common.collect.Lists; -import me.desht.modularrouters.ModularRouters; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; import me.desht.modularrouters.logic.filter.matchers.RegexMatcher; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; -import me.desht.modularrouters.network.messages.GuiSyncMessage; import net.minecraft.ChatFormatting; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import java.util.List; -import java.util.stream.Collectors; public class RegexFilter extends SmartFilterItem { private static final String NBT_REGEX = "Regex"; public static final int MAX_SIZE = 6; + public RegexFilter() { + super(ModItems.defaultProps() + .component(ModDataComponents.FILTER_STRINGS, List.of())); + } + @Override public boolean hasMenu() { return false; } public static List getRegexList(ItemStack filterStack) { - CompoundTag tag = filterStack.getTagElement(ModularRouters.MODID); - if (tag != null) { - ListTag items = tag.getList(NBT_REGEX, Tag.TAG_STRING); - List res = Lists.newArrayListWithExpectedSize(items.size()); - for (int i = 0; i < items.size(); i++) { - res.add(items.getString(i)); - } - return res; - } else { - return Lists.newArrayList(); - } + return filterStack.getOrDefault(ModDataComponents.FILTER_STRINGS, List.of()); } - private static void setRegexList(ItemStack filterStack, List regex) { - ListTag list = regex.stream().map(StringTag::valueOf).collect(Collectors.toCollection(ListTag::new)); - filterStack.getOrCreateTagElement(ModularRouters.MODID).put(NBT_REGEX, list); + public static void setRegexList(ItemStack filterStack, List regexList) { + filterStack.set(ModDataComponents.FILTER_STRINGS, regexList); } @Override public void addExtraInformation(ItemStack itemstack, List list) { super.addExtraInformation(itemstack, list); - CompoundTag compound = itemstack.getTag(); - if (compound != null) { - List l = getRegexList(itemstack); - addCountInfo(list, l.size()); - list.addAll(l.stream().map(s -> " • " + ChatFormatting.AQUA + "/" + s + "/").map(Component::literal).toList()); - } else { - addCountInfo(list, 0); - } + + List regexList = getRegexList(itemstack); + addCountInfo(list, regexList.size()); + list.addAll(regexList.stream().map(s -> " • " + ChatFormatting.AQUA + "/" + s + "/").map(Component::literal).toList()); } @Override @@ -64,36 +46,35 @@ public IItemMatcher compile(ItemStack filterStack, ItemStack moduleStack) { return new RegexMatcher(getRegexList(filterStack)); } - @Override - public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack) { - List l; - switch (message.op()) { - case ADD_STRING -> { - String regex = message.payload().getString("String"); - l = getRegexList(filterStack); - if (l.size() < MAX_SIZE) { - l.add(regex); - setRegexList(filterStack, l); - return new GuiSyncMessage(filterStack); - } - } - case REMOVE_AT -> { - int pos = message.payload().getInt("Pos"); - l = getRegexList(filterStack); - if (pos >= 0 && pos < l.size()) { - l.remove(pos); - setRegexList(filterStack, l); - return new GuiSyncMessage(filterStack); - } - } - default -> ModularRouters.LOGGER.warn("received unexpected message type " + message.op() + " for " + filterStack); - } - return null; - } +// @Override +// public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack) { +// List l; +// switch (message.op()) { +// case ADD_STRING -> { +// String regex = message.payload().getString("String"); +// l = getRegexList(filterStack); +// if (l.size() < MAX_SIZE) { +// l.add(regex); +// setRegexList(filterStack, l); +// return new GuiSyncMessage(filterStack); +// } +// } +// case REMOVE_AT -> { +// int pos = message.payload().getInt("Pos"); +// l = getRegexList(filterStack); +// if (pos >= 0 && pos < l.size()) { +// l.remove(pos); +// setRegexList(filterStack, l); +// return new GuiSyncMessage(filterStack); +// } +// } +// default -> ModularRouters.LOGGER.warn("received unexpected message type " + message.op() + " for " + filterStack); +// } +// return null; +// } @Override public int getSize(ItemStack filterStack) { - CompoundTag tag = filterStack.getTagElement(ModularRouters.MODID); - return tag != null ? tag.getList(NBT_REGEX, Tag.TAG_STRING).size() : 0; + return getRegexList(filterStack).size(); } } diff --git a/src/main/java/me/desht/modularrouters/item/smartfilter/SmartFilterItem.java b/src/main/java/me/desht/modularrouters/item/smartfilter/SmartFilterItem.java index 80a41d76..35cf57d0 100644 --- a/src/main/java/me/desht/modularrouters/item/smartfilter/SmartFilterItem.java +++ b/src/main/java/me/desht/modularrouters/item/smartfilter/SmartFilterItem.java @@ -6,8 +6,6 @@ import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.item.MRBaseItem; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; -import me.desht.modularrouters.network.messages.GuiSyncMessage; import me.desht.modularrouters.util.MFLocator; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; @@ -19,6 +17,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -31,20 +30,24 @@ public SmartFilterItem() { super(ModItems.defaultProps()); } + public SmartFilterItem(Item.Properties properties) { + super(properties); + } + @Nonnull public abstract IItemMatcher compile(ItemStack filterStack, ItemStack moduleStack); - /** - * Handle a filter settings message received from a client-side GUI by updating the filter itemstack appropriately. - * - * @param player player sending/receiving the message - * @param message received message - * @param filterStack item stack of the filter that needs to be updated - * @param moduleStack item stack of the module the filter is installed in, if any - * @return true a GuiSyncMessage if a response should be sent, null otherwise - */ - @Nullable - public abstract GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack); +// /** +// * Handle a filter settings message received from a client-side GUI by updating the filter itemstack appropriately. +// * +// * @param player player sending/receiving the message +// * @param message received message +// * @param filterStack item stack of the filter that needs to be updated +// * @param moduleStack item stack of the module the filter is installed in, if any +// * @return true a GuiSyncMessage if a response should be sent, null otherwise +// */ +// @Nullable +// public abstract GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack); /** * Get the number of items in this filter, mainly for client display purposes. diff --git a/src/main/java/me/desht/modularrouters/item/smartfilter/TagFilter.java b/src/main/java/me/desht/modularrouters/item/smartfilter/TagFilter.java index c60e6e85..cdfa3d78 100644 --- a/src/main/java/me/desht/modularrouters/item/smartfilter/TagFilter.java +++ b/src/main/java/me/desht/modularrouters/item/smartfilter/TagFilter.java @@ -1,53 +1,36 @@ package me.desht.modularrouters.item.smartfilter; -import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.container.AbstractSmartFilterMenu; import me.desht.modularrouters.container.TagFilterMenu; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; import me.desht.modularrouters.logic.filter.matchers.TagMatcher; -import me.desht.modularrouters.network.messages.FilterSettingsMessage; -import me.desht.modularrouters.network.messages.GuiSyncMessage; import me.desht.modularrouters.util.MFLocator; import net.minecraft.ChatFormatting; import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class TagFilter extends SmartFilterItem { private static final int MAX_SIZE = 6; - private static final String NBT_TAGS = "Tags"; public static List> getTagList(ItemStack filterStack) { - CompoundTag tag = filterStack.getTagElement(ModularRouters.MODID); - if (tag != null) { - return tag.getList(NBT_TAGS, Tag.TAG_STRING).stream() - .map(strTag -> TagKey.create(Registries.ITEM, new ResourceLocation(strTag.getAsString()))) - .toList(); - } else { - return List.of(); - } + List strings = filterStack.getOrDefault(ModDataComponents.FILTER_STRINGS, List.of()); + return strings.stream() + .filter(ResourceLocation::isValidResourceLocation) + .map(s -> TagKey.create(Registries.ITEM, new ResourceLocation(s))) + .toList(); } public static void setTagList(ItemStack filterStack, List> tags) { - ListTag list = tags.stream() - .map(tag -> StringTag.valueOf(tag.location().toString())) - .collect(Collectors.toCollection(ListTag::new)); - filterStack.getOrCreateTagElement(ModularRouters.MODID).put(NBT_TAGS, list); + filterStack.set(ModDataComponents.FILTER_STRINGS, tags.stream().map(t -> t.location().toString()).toList()); } @NotNull @@ -59,53 +42,49 @@ public IItemMatcher compile(ItemStack filterStack, ItemStack moduleStack) { @Override public void addExtraInformation(ItemStack stack, List list) { super.addExtraInformation(stack, list); - if (stack.getTagElement(ModularRouters.MODID) != null) { - List> l = getTagList(stack); - addCountInfo(list, l.size()); - list.addAll(l.stream() - .map(s -> " • " + ChatFormatting.AQUA + s.location()) - .map(Component::literal) - .toList()); - } else { - addCountInfo(list, 0); - } - } - @Nullable - @Override - public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack) { - List> tagList; - switch (message.op()) { - case ADD_STRING -> { - tagList = new ArrayList<>(getTagList(filterStack)); - String t = message.payload().getString("Tag"); - if (tagList.size() < MAX_SIZE && ResourceLocation.isValidResourceLocation(t)) { - TagKey tag = TagKey.create(Registries.ITEM, new ResourceLocation(t)); - if (!tagList.contains(tag)) { - tagList.add(tag); - setTagList(filterStack, tagList); - return new GuiSyncMessage(filterStack); - } - } - } - case REMOVE_AT -> { - int pos = message.payload().getInt("Pos"); - tagList = new ArrayList<>(getTagList(filterStack)); - if (pos >= 0 && pos < tagList.size()) { - tagList.remove(pos); - setTagList(filterStack, tagList); - return new GuiSyncMessage(filterStack); - } - } - default -> ModularRouters.LOGGER.warn("received unexpected message type " + message.op() + " for " + filterStack); - } - return null; + List> l = getTagList(stack); + addCountInfo(list, l.size()); + list.addAll(l.stream() + .map(s -> " • " + ChatFormatting.AQUA + s.location()) + .map(Component::literal) + .toList()); } +// @Nullable +// @Override +// public GuiSyncMessage onReceiveSettingsMessage(Player player, FilterSettingsMessage message, ItemStack filterStack, ItemStack moduleStack) { +// List> tagList; +// switch (message.op()) { +// case ADD_STRING -> { +// tagList = new ArrayList<>(getTagList(filterStack)); +// String t = message.payload().getString("Tag"); +// if (tagList.size() < MAX_SIZE && ResourceLocation.isValidResourceLocation(t)) { +// TagKey tag = TagKey.create(Registries.ITEM, new ResourceLocation(t)); +// if (!tagList.contains(tag)) { +// tagList.add(tag); +// setTagList(filterStack, tagList); +// return new GuiSyncMessage(filterStack); +// } +// } +// } +// case REMOVE_AT -> { +// int pos = message.payload().getInt("Pos"); +// tagList = new ArrayList<>(getTagList(filterStack)); +// if (pos >= 0 && pos < tagList.size()) { +// tagList.remove(pos); +// setTagList(filterStack, tagList); +// return new GuiSyncMessage(filterStack); +// } +// } +// default -> ModularRouters.LOGGER.warn("received unexpected message type " + message.op() + " for " + filterStack); +// } +// return null; +// } + @Override public int getSize(ItemStack filterStack) { - CompoundTag tag = filterStack.getTagElement(ModularRouters.MODID); - return tag != null ? tag.getList(NBT_TAGS, Tag.TAG_STRING).size() : 0; + return getTagList(filterStack).size(); } @Override diff --git a/src/main/java/me/desht/modularrouters/item/upgrade/CamouflageUpgrade.java b/src/main/java/me/desht/modularrouters/item/upgrade/CamouflageUpgrade.java index ba87fe3e..ab886979 100644 --- a/src/main/java/me/desht/modularrouters/item/upgrade/CamouflageUpgrade.java +++ b/src/main/java/me/desht/modularrouters/item/upgrade/CamouflageUpgrade.java @@ -1,14 +1,12 @@ package me.desht.modularrouters.item.upgrade; -import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.core.ModBlocks; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModSounds; import net.minecraft.ChatFormatting; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtUtils; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -28,12 +26,11 @@ public void onCompiled(ItemStack stack, ModularRouterBlockEntity router) { } private static void setCamoState(ItemStack stack, BlockState camoState) { - stack.getOrCreateTagElement(ModularRouters.MODID).put(NBT_STATE_NAME, NbtUtils.writeBlockState(camoState)); + stack.set(ModDataComponents.CAMOUFLAGE, camoState); } private static BlockState getCamoState(ItemStack stack) { - CompoundTag tag = stack.getTagElement(ModularRouters.MODID); - return tag != null ? NbtUtils.readBlockState(BuiltInRegistries.BLOCK.asLookup(), tag.getCompound(NBT_STATE_NAME)) : null; + return stack.get(ModDataComponents.CAMOUFLAGE); } private static Component getCamoStateDisplayName(ItemStack stack) { diff --git a/src/main/java/me/desht/modularrouters/item/upgrade/SecurityUpgrade.java b/src/main/java/me/desht/modularrouters/item/upgrade/SecurityUpgrade.java index 7d8392bf..f97de7cc 100644 --- a/src/main/java/me/desht/modularrouters/item/upgrade/SecurityUpgrade.java +++ b/src/main/java/me/desht/modularrouters/item/upgrade/SecurityUpgrade.java @@ -1,33 +1,49 @@ package me.desht.modularrouters.item.upgrade; -import com.google.common.collect.Sets; import com.mojang.authlib.GameProfile; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModSounds; import me.desht.modularrouters.item.IPlayerOwned; +import me.desht.modularrouters.util.TranslatableEnum; import net.minecraft.ChatFormatting; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ResolvableProfile; import net.minecraft.world.level.Level; -import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; public class SecurityUpgrade extends UpgradeItem implements IPlayerOwned { - private static final String NBT_PLAYERS = "Players"; private static final int MAX_PLAYERS = 6; + public SecurityUpgrade() { + super(ModItems.defaultProps() + .component(ModDataComponents.SECURITY_LIST, SecurityList.DEFAULT) + ); + } + @Override - public void addExtraInformation(ItemStack itemstack, List list) { + public void addExtraInformation(ItemStack itemstack, List list) { String owner = getOwnerProfile(itemstack).map(GameProfile::getName).orElse("-"); list.add(ClientUtil.xlate("modularrouters.itemText.security.owner", ChatFormatting.AQUA + owner)); @@ -45,6 +61,7 @@ public void addExtraInformation(ItemStack itemstack, List list) { @Override public void onCompiled(ItemStack stack, ModularRouterBlockEntity router) { super.onCompiled(stack, router); + router.addPermittedIds(getPlayerIDs(stack)); } @@ -54,21 +71,9 @@ public TintColor getItemTint() { } private Set getPlayerIDs(ItemStack stack) { - CompoundTag compound = stack.getTag(); - if (compound == null) { - return Set.of(); - } - - return getOwnerProfile(stack).map(profile -> { - Set res = Sets.newHashSet(); - res.add(profile.getId()); - - if (compound.contains(NBT_PLAYERS)) { - CompoundTag p = compound.getCompound(NBT_PLAYERS); - res.addAll(p.getAllKeys().stream().map(UUID::fromString).toList()); - } - return res; - }).orElse(Set.of()); + return stack.getOrDefault(ModDataComponents.SECURITY_LIST, SecurityList.DEFAULT).trusted().stream() + .map(tp -> tp.gameProfile().getId()) + .collect(Collectors.toSet()); } /** @@ -78,49 +83,38 @@ private Set getPlayerIDs(ItemStack stack) { * @return set of (displayable) player names */ private static Set getPlayerNames(ItemStack stack) { - CompoundTag compound = stack.getTag(); - if (compound != null && compound.contains(NBT_PLAYERS)) { - CompoundTag p = compound.getCompound(NBT_PLAYERS); - return p.getAllKeys().stream().map(p::getString).sorted().collect(Collectors.toCollection(LinkedHashSet::new)); - } else { - return Collections.emptySet(); - } + return stack.getOrDefault(ModDataComponents.SECURITY_LIST, SecurityList.DEFAULT).trusted().stream() + .map(tp -> tp.gameProfile().getName()) + .collect(Collectors.toSet()); } - private static Result addPlayer(ItemStack stack, String id, String name) { - CompoundTag compound = stack.getTag(); - if (compound != null) { - if (!compound.contains(NBT_PLAYERS)) { - compound.put(NBT_PLAYERS, new CompoundTag()); - } - CompoundTag p = compound.getCompound(NBT_PLAYERS); - if (p.contains(id)) { - return Result.ALREADY_ADDED; // already there, do nothing - } - if (p.size() >= MAX_PLAYERS) { - return Result.FULL; // items full - } - p.putString(id, name); - return Result.ADDED; + private static Result addPlayer(ItemStack stack, GameProfile profile) { + SecurityList securityList = stack.getOrDefault(ModDataComponents.SECURITY_LIST, SecurityList.DEFAULT); + if (securityList.trusted.size() >= MAX_PLAYERS) { + return Result.FULL; } - return Result.ERROR; + + SecurityList newList = securityList.add(profile); + if (newList.trusted.size() == securityList.trusted.size()) { + return Result.ALREADY_ADDED; + } + + stack.set(ModDataComponents.SECURITY_LIST, newList); + + return Result.ADDED; } - private static Result removePlayer(ItemStack stack, String id) { - CompoundTag compound = stack.getTag(); - if (compound != null) { - if (!compound.contains(NBT_PLAYERS)) { - compound.put(NBT_PLAYERS, new CompoundTag()); - } - CompoundTag p = compound.getCompound(NBT_PLAYERS); - if (p.contains(id)) { - p.remove(id); - return Result.REMOVED; - } else { - return Result.NOT_PRESENT; - } + private static Result removePlayer(ItemStack stack, GameProfile profile) { + SecurityList securityList = stack.getOrDefault(ModDataComponents.SECURITY_LIST, SecurityList.DEFAULT); + + SecurityList newList = securityList.remove(profile); + if (newList.trusted.size() == securityList.trusted.size()) { + return Result.NOT_PRESENT; } - return Result.ERROR; + + stack.set(ModDataComponents.SECURITY_LIST, newList); + + return Result.REMOVED; } @Override @@ -137,26 +131,71 @@ public InteractionResultHolder use(Level world, Player player, Intera @Override public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity entity, InteractionHand hand) { if (entity instanceof Player targetPlayer) { - String id = targetPlayer.getUUID().toString(); - String name = targetPlayer.getDisplayName().toString(); - Result res = player.isSteppingCarefully() ? removePlayer(stack, id) : addPlayer(stack, id, name); + GameProfile profile = targetPlayer.getGameProfile(); + Result res = player.isSteppingCarefully() ? removePlayer(stack, profile) : addPlayer(stack, profile); if (player.level().isClientSide) { player.playSound(res.isError() ? ModSounds.ERROR.get() : ModSounds.SUCCESS.get(), ConfigHolder.client.sound.bleepVolume.get().floatValue(), 1.0f); } else { - player.displayClientMessage(Component.translatable("modularrouters.chatText.security." + res.toString(), name), false); + player.displayClientMessage(Component.translatable(res.getTranslationKey(), profile.getName()), false); } return InteractionResult.SUCCESS; } return InteractionResult.PASS; } - enum Result { - ADDED, REMOVED, FULL, ALREADY_ADDED, ERROR, NOT_PRESENT; + enum Result implements TranslatableEnum, StringRepresentable { + ADDED("added"), + REMOVED("removed"), + FULL("full"), + ALREADY_ADDED("already_added"), + ERROR("error"), + NOT_PRESENT("not_present"); + + private final String name; + + Result(String name) { + this.name = name; + } boolean isError() { return this != ADDED && this != REMOVED; } + + @Override + public String getTranslationKey() { + return "modularrouters.chatText.security." + getSerializedName(); + } + + @Override + public String getSerializedName() { + return name; + } } + public record SecurityList(List trusted) { + public static final SecurityList DEFAULT = new SecurityList(List.of()); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + ResolvableProfile.CODEC.listOf(0, MAX_PLAYERS).fieldOf("trusted").forGetter(SecurityList::trusted) + ).apply(builder, SecurityList::new)); + + public static StreamCodec STREAM_CODEC = StreamCodec.composite( + ResolvableProfile.STREAM_CODEC.apply(ByteBufCodecs.list(MAX_PLAYERS)), SecurityList::trusted, + SecurityList::new + ); + + public SecurityList add(GameProfile profile) { + Set l = new HashSet<>(trusted); + l.add(new ResolvableProfile(profile)); + return new SecurityList(List.copyOf(l)); + } + + public SecurityList remove(GameProfile profile) { + List l = trusted.stream() + .filter(rp -> !rp.gameProfile().equals(profile)) + .toList(); + return new SecurityList(l); + } + } } diff --git a/src/main/java/me/desht/modularrouters/item/upgrade/SyncUpgrade.java b/src/main/java/me/desht/modularrouters/item/upgrade/SyncUpgrade.java index 5cbf584f..a281fe55 100644 --- a/src/main/java/me/desht/modularrouters/item/upgrade/SyncUpgrade.java +++ b/src/main/java/me/desht/modularrouters/item/upgrade/SyncUpgrade.java @@ -1,13 +1,13 @@ package me.desht.modularrouters.item.upgrade; -import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.client.gui.upgrade.SyncUpgradeScreen; import me.desht.modularrouters.client.util.TintColor; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModSounds; import net.minecraft.ChatFormatting; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -24,6 +24,10 @@ public class SyncUpgrade extends UpgradeItem { private static final String NBT_TUNING = "Tuning"; + public SyncUpgrade() { + super(ModItems.defaultProps().component(ModDataComponents.SYNC_TUNING, 1)); + } + @Override public void addExtraInformation(ItemStack itemstack, List list) { int val = getTunedValue(itemstack); @@ -37,14 +41,13 @@ public void onCompiled(ItemStack stack, ModularRouterBlockEntity router) { } public static int getTunedValue(ItemStack stack) { - if (!(stack.getItem() instanceof SyncUpgrade) || !stack.hasTag()) return 0; - CompoundTag tag = stack.getTagElement(ModularRouters.MODID); - return tag == null ? 0 : tag.getInt(NBT_TUNING); + if (!(stack.getItem() instanceof SyncUpgrade)) return 0; + return stack.getOrDefault(ModDataComponents.SYNC_TUNING.get(), 0); } public static void setTunedValue(ItemStack stack, int newValue) { if (stack.getItem() instanceof SyncUpgrade) { - stack.getOrCreateTagElement(ModularRouters.MODID).putInt(NBT_TUNING, newValue); + stack.set(ModDataComponents.SYNC_TUNING.get(), newValue); } } diff --git a/src/main/java/me/desht/modularrouters/item/upgrade/UpgradeItem.java b/src/main/java/me/desht/modularrouters/item/upgrade/UpgradeItem.java index 49bf59ae..c2bdc7d0 100644 --- a/src/main/java/me/desht/modularrouters/item/upgrade/UpgradeItem.java +++ b/src/main/java/me/desht/modularrouters/item/upgrade/UpgradeItem.java @@ -5,19 +5,22 @@ import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.item.MRBaseItem; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; import java.util.List; public abstract class UpgradeItem extends MRBaseItem implements ModItems.ITintable { - public UpgradeItem() { super(ModItems.defaultProps()); } + protected UpgradeItem(Item.Properties properties) { + super(properties); + } + public TintColor getItemTint() { return TintColor.WHITE; } diff --git a/src/main/java/me/desht/modularrouters/logic/ModuleTarget.java b/src/main/java/me/desht/modularrouters/logic/ModuleTarget.java index bb886f3b..294140f5 100644 --- a/src/main/java/me/desht/modularrouters/logic/ModuleTarget.java +++ b/src/main/java/me/desht/modularrouters/logic/ModuleTarget.java @@ -1,13 +1,19 @@ package me.desht.modularrouters.logic; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.ChatFormatting; -import net.minecraft.Util; import net.minecraft.core.Direction; import net.minecraft.core.GlobalPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; import net.neoforged.neoforge.capabilities.BlockCapability; @@ -16,16 +22,16 @@ import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.items.IItemHandler; +import org.checkerframework.checker.units.qual.C; import javax.annotation.Nullable; -import java.util.IdentityHashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; +import java.util.function.Function; /** - * Represents the target for a given module, including the dimension, blockpos - * and face of the block where insertion/extraction will occur. + * Represents a target for a given targeted module, including the dimension, blockpos + * and face of the block where insertion/extraction will occur. + * Targeted modules store one or more of these objects; see also {@link ModuleTargetList} */ public class ModuleTarget { public final GlobalPos gPos; @@ -37,6 +43,19 @@ public class ModuleTarget { private BlockCapabilityCache energyCapCache; private final Map, BlockCapabilityCache> capabilityCache = new IdentityHashMap<>(); + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + GlobalPos.CODEC.fieldOf("pos").forGetter(t -> t.gPos), + Direction.CODEC.fieldOf("face").forGetter(t -> t.face), + Codec.STRING.optionalFieldOf("key", "").forGetter(t -> t.blockTranslationKey) + ).apply(builder, ModuleTarget::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + GlobalPos.STREAM_CODEC, t -> t.gPos, + Direction.STREAM_CODEC, t -> t.face, + ByteBufCodecs.STRING_UTF8, t -> t.blockTranslationKey, + ModuleTarget::new + ); + public ModuleTarget(GlobalPos gPos, Direction face, String blockTranslationKey) { this.gPos = gPos; this.face = face; @@ -51,20 +70,6 @@ public ModuleTarget(GlobalPos gPos) { this(gPos, null); } - public CompoundTag toNBT() { - return Util.make(new CompoundTag(), ext -> { - ext.put("Pos", MiscUtil.serializeGlobalPos(gPos)); - ext.putByte("Face", (byte) face.get3DDataValue()); - ext.putString("InvName", blockTranslationKey); - }); - } - - public static ModuleTarget fromNBT(CompoundTag nbt) { - GlobalPos gPos = MiscUtil.deserializeGlobalPos(nbt.getCompound("Pos")); - Direction face = Direction.from3DDataValue(nbt.getByte("Face")); - return new ModuleTarget(gPos, face, nbt.getString("InvName")); - } - public boolean isSameWorld(@Nullable Level world) { return world != null && gPos.dimension() == world.dimension(); } diff --git a/src/main/java/me/desht/modularrouters/logic/ModuleTargetList.java b/src/main/java/me/desht/modularrouters/logic/ModuleTargetList.java new file mode 100644 index 00000000..d4a5c937 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/logic/ModuleTargetList.java @@ -0,0 +1,34 @@ +package me.desht.modularrouters.logic; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; + +import java.util.List; + +public record ModuleTargetList(List targets) { + public static final ModuleTargetList EMPTY = new ModuleTargetList(List.of()); + + public static ModuleTargetList singleTarget(ModuleTarget target) { + return new ModuleTargetList(List.of(target)); + } + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + ModuleTarget.CODEC.listOf().fieldOf("targets").forGetter(ModuleTargetList::targets) + ).apply(builder, ModuleTargetList::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ModuleTarget.STREAM_CODEC.apply(ByteBufCodecs.list()), ModuleTargetList::targets, + ModuleTargetList::new + ); + + public boolean isEmpty() { + return targets.isEmpty(); + } + + public ModuleTarget getSingle() { + return targets.getFirst(); + } +} diff --git a/src/main/java/me/desht/modularrouters/logic/RouterRedstoneBehaviour.java b/src/main/java/me/desht/modularrouters/logic/RouterRedstoneBehaviour.java deleted file mode 100644 index 6df2a0bd..00000000 --- a/src/main/java/me/desht/modularrouters/logic/RouterRedstoneBehaviour.java +++ /dev/null @@ -1,30 +0,0 @@ -package me.desht.modularrouters.logic; - -import me.desht.modularrouters.util.TranslatableEnum; - -public enum RouterRedstoneBehaviour implements TranslatableEnum { - ALWAYS, LOW, HIGH, NEVER, PULSE; - - public static RouterRedstoneBehaviour forValue(String string) { - try { - return RouterRedstoneBehaviour.valueOf(string); - } catch (IllegalArgumentException e) { - return ALWAYS; - } - } - - public boolean shouldRun(boolean powered, boolean pulsed) { - return switch (this) { - case ALWAYS -> true; - case LOW -> !powered; - case HIGH -> powered; - case PULSE -> pulsed; - case NEVER -> false; - }; - } - - @Override - public String getTranslationKey() { - return "modularrouters.guiText.tooltip.redstone." + this; - } -} diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledActivatorModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledActivatorModule.java index 6ca4c810..b270d6a4 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledActivatorModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledActivatorModule.java @@ -1,10 +1,13 @@ package me.desht.modularrouters.logic.compiled; import com.google.common.collect.ImmutableSet; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.ModularRoutersTags; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.util.MiscUtil; import me.desht.modularrouters.util.TranslatableEnum; @@ -13,12 +16,16 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; @@ -32,23 +39,15 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.VoxelShape; -import net.neoforged.neoforge.common.NeoForgeMod; import net.neoforged.neoforge.common.util.FakePlayer; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; import javax.annotation.Nonnull; import java.util.*; import java.util.function.Predicate; public class CompiledActivatorModule extends CompiledModule { - public static final String NBT_ACTION_TYPE = "ActionType2"; - public static final String NBT_LOOK_DIRECTION = "LookDirection"; - public static final String NBT_SNEAKING = "Sneaking"; - public static final String NBT_ENTITY_MODE = "EntityMode"; - - private final ActionType actionType; - private final LookDirection lookDirection; - private final EntityMode entityMode; - private final boolean sneaking; + private final ActivatorSettings settings; private int entityIdx; private final Set BLOCK_METHODS = ImmutableSet.of( @@ -62,70 +61,10 @@ public class CompiledActivatorModule extends CompiledModule { private static final Set itemBlacklist = new HashSet<>(); private static final Set blockBlacklist = new HashSet<>(); - public enum ActionType implements TranslatableEnum { - ITEM_OR_BLOCK(false), - USE_ITEM_ON_ENTITY(true), - ATTACK_ENTITY(true); - - private final boolean entity; - - ActionType(boolean entity) { - this.entity = entity; - } - - @Override - public String getTranslationKey() { - return "modularrouters.itemText.activator.action." + this; - } - - public boolean isEntityTarget() { - return entity; - } - } - - public enum LookDirection implements TranslatableEnum { - LEVEL(0f), - ABOVE(-45f), - BELOW(45f); - - private final float pitch; - - LookDirection(float pitch) { - this.pitch = pitch; - } - - @Override - public String getTranslationKey() { - return "modularrouters.itemText.activator.direction." + this; - } - } - - public enum EntityMode implements TranslatableEnum { - NEAREST, - RANDOM, - ROUND_ROBIN; - - @Override - public String getTranslationKey() { - return "modularrouters.itemText.activator.entityMode." + this; - } - } - public CompiledActivatorModule(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - CompoundTag compound = stack.getTagElement(ModularRouters.MODID); - if (compound != null) { - actionType = ActionType.values()[compound.getInt(NBT_ACTION_TYPE)]; - lookDirection = LookDirection.values()[compound.getInt(NBT_LOOK_DIRECTION)]; - entityMode = EntityMode.values()[compound.getInt(NBT_ENTITY_MODE)]; - sneaking = compound.getBoolean(NBT_SNEAKING); - } else { - actionType = ActionType.ITEM_OR_BLOCK; - lookDirection = LookDirection.LEVEL; - entityMode = EntityMode.NEAREST; - sneaking = false; - } + settings = stack.getOrDefault(ModDataComponents.ACTIVATOR_SETTINGS, ActivatorSettings.DEFAULT); } @Override @@ -136,18 +75,18 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { // we'll allow an empty stack, since right-clicking with an empty hand is a valid operation // - but only if there's an empty or blacklist filter - if (!stack.isEmpty() && !getFilter().test(stack) || stack.isEmpty() && !getFilter().isEmpty() && !getFilter().isBlacklist()) { + if (!stack.isEmpty() && !getFilter().test(stack) || stack.isEmpty() && !getFilter().isEmpty() && getFilter().isWhiteList()) { return false; } RouterFakePlayer fakePlayer = router.getFakePlayer(); Vec3 centre = Vec3.atCenterOf(router.getBlockPos()); // place the fake player just outside the router, on the correct face - fakePlayer.setPos(centre.x() + getFacing().getStepX() * 0.501, centre.y() + getFacing().getStepY() * 0.501, centre.z() + getFacing().getStepZ() * 0.501); - fakePlayer.setShiftKeyDown(sneaking); + fakePlayer.setPos(centre.x() + getAbsoluteFacing().getStepX() * 0.501, centre.y() + getAbsoluteFacing().getStepY() * 0.501, centre.z() + getAbsoluteFacing().getStepZ() * 0.501); + fakePlayer.setShiftKeyDown(settings.sneaking); fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, stack); - boolean didWork = switch (actionType) { + boolean didWork = switch (settings.actionType) { case ITEM_OR_BLOCK -> doUseItem(router, fakePlayer); case USE_ITEM_ON_ENTITY -> doUseItemOnEntity(router, fakePlayer); case ATTACK_ENTITY -> doAttackEntity(router, fakePlayer); @@ -165,8 +104,8 @@ private boolean doUseItem(ModularRouterBlockEntity router, FakePlayer fakePlayer BlockPos pos = router.getBlockPos(); Level world = Objects.requireNonNull(router.getLevel()); ItemStack stack = router.getBufferItemStack(); - fakePlayer.setYRot(MiscUtil.getYawFromFacing(getFacing())); - fakePlayer.setXRot(getFacing().getAxis() == Direction.Axis.Y ? getFacing().getStepY() * -90 : lookDirection.pitch); + fakePlayer.setYRot(MiscUtil.getYawFromFacing(getAbsoluteFacing())); + fakePlayer.setXRot(getAbsoluteFacing().getAxis() == Direction.Axis.Y ? getAbsoluteFacing().getStepY() * -90 : settings.lookDirection.pitch); BlockHitResult hitResult = doRayTrace(pos, fakePlayer); BlockState state = world.getBlockState(hitResult.getBlockPos()); if (hitResult.getType() != HitResult.Type.MISS && blockBlacklist.contains(state.getBlock())) { @@ -202,11 +141,12 @@ private void handleBlacklisting(ItemStack stack, BlockState state, Exception e) private BlockHitResult doRayTrace(BlockPos routerPos, FakePlayer fp) { Vec3 fpVec = fp.position(); // ray trace starts at this point - int xOff = getFacing().getStepX(); - int yOff = getFacing().getStepY(); - int zOff = getFacing().getStepZ(); + int xOff = getAbsoluteFacing().getStepX(); + int yOff = getAbsoluteFacing().getStepY(); + int zOff = getAbsoluteFacing().getStepZ(); - BlockPos.MutableBlockPos targetPos = routerPos.relative(getFacing()).mutable(); + BlockPos.MutableBlockPos targetPos = routerPos.relative(getAbsoluteFacing()).mutable(); + LookDirection lookDirection = settings.lookDirection; if (lookDirection != LookDirection.LEVEL && Block.isShapeFullBlock(fp.level().getBlockState(targetPos).getShape(fp.level(), targetPos))) { @@ -238,7 +178,7 @@ private BlockHitResult doRayTrace(BlockPos routerPos, FakePlayer fp) { if (shape.isEmpty()) { continue; } - Vec3 targetVec = shape.toAabbs().get(0).getCenter().add(Vec3.atLowerCornerOf(targetPos)); + Vec3 targetVec = shape.toAabbs().getFirst().getCenter().add(Vec3.atLowerCornerOf(targetPos)); BlockHitResult res = fp.level().clip( new ClipContext(fpVec, targetVec, ClipContext.Block.OUTLINE, ClipContext.Fluid.SOURCE_ONLY, fp) ); @@ -247,12 +187,12 @@ private BlockHitResult doRayTrace(BlockPos routerPos, FakePlayer fp) { } } - return BlockHitResult.miss(fpVec.add(fp.getLookAngle()), getFacing().getOpposite(), routerPos.relative(getFacing())); + return BlockHitResult.miss(fpVec.add(fp.getLookAngle()), getAbsoluteFacing().getOpposite(), routerPos.relative(getAbsoluteFacing())); } private double getPlayerReachDistance(Player player) { if (player != null) { - AttributeInstance attr = player.getAttribute(NeoForgeMod.BLOCK_REACH.value()); + AttributeInstance attr = player.getAttribute(getActionType().isEntityTarget() ? Attributes.ENTITY_INTERACTION_RANGE : Attributes.BLOCK_INTERACTION_RANGE); if (attr != null) return attr.getValue() + 1D; } return 4.5D; @@ -282,7 +222,7 @@ private boolean doUseItemOnEntity(ModularRouterBlockEntity router, FakePlayer fa } private T findEntity(ModularRouterBlockEntity router, Class cls, Predicate blacklistChecker) { - Direction face = getFacing(); + Direction face = getAbsoluteFacing(); final BlockPos pos = router.getBlockPos(); Vec3 vec = Vec3.atCenterOf(pos); AABB box = new AABB(vec, vec) @@ -293,12 +233,12 @@ private T findEntity(ModularRouterBlockEntity router, Class o.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()))); - return l.get(0); + return l.getFirst(); case ROUND_ROBIN: l.sort(Comparator.comparingDouble(o -> o.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()))); entityIdx = (entityIdx + 1) % l.size(); @@ -321,7 +261,7 @@ private void dropExtraItems(ModularRouterBlockEntity router, Player fakePlayer) // the world, since the router has no access to them, and the player would otherwise lose them // e.g. milking a cow with a stack of buckets in the router slot NonNullList inv = fakePlayer.getInventory().items; - Vec3 where = Vec3.atCenterOf(router.getBlockPos().relative(getFacing())); + Vec3 where = Vec3.atCenterOf(router.getBlockPos().relative(getAbsoluteFacing())); // start at slot 1, since slot 0 is always used for the fake player's held item, which doesn't get dropped Level level = Objects.requireNonNull(router.getLevel()); for (int i = 1; i < inv.size() && !inv.get(i).isEmpty(); i++) { @@ -332,30 +272,134 @@ private void dropExtraItems(ModularRouterBlockEntity router, Player fakePlayer) } public ActionType getActionType() { - return actionType; + return settings.actionType; } public LookDirection getLookDirection() { - return lookDirection; + return settings.lookDirection; } public EntityMode getEntityMode() { - return entityMode; + return settings.entityMode; } public boolean isSneaking() { - return sneaking; + return settings.sneaking; } @Override public int getEnergyCost() { - return actionType == ActionType.ATTACK_ENTITY ? + return settings.actionType == ActionType.ATTACK_ENTITY ? ConfigHolder.common.energyCosts.activatorModuleEnergyCostAttack.get() : ConfigHolder.common.energyCosts.activatorModuleEnergyCost.get(); } @Override public boolean careAboutItemAttributes() { - return actionType == ActionType.ATTACK_ENTITY; + return settings.actionType == ActionType.ATTACK_ENTITY; + } + + public enum ActionType implements TranslatableEnum, StringRepresentable { + ITEM_OR_BLOCK("item_or_block", false), + USE_ITEM_ON_ENTITY("use_item_on_entity", true), + ATTACK_ENTITY("attack_entity", true); + + private final boolean entity; + private final String name; + + ActionType(String name, boolean entity) { + this.entity = entity; + this.name = name; + } + + @Override + public String getTranslationKey() { + return "modularrouters.itemText.activator.action." + name; + } + + public boolean isEntityTarget() { + return entity; + } + + @Override + public String getSerializedName() { + return name; + } + } + + public enum LookDirection implements TranslatableEnum, StringRepresentable { + LEVEL("level", 0f), + ABOVE("above", -45f), + BELOW("below", 45f); + + private final String name; + private final float pitch; + + LookDirection(String name, float pitch) { + this.name = name; + this.pitch = pitch; + } + + @Override + public String getTranslationKey() { + return "modularrouters.itemText.activator.direction." + name; + } + + @Override + public String getSerializedName() { + return name; + } + } + + public enum EntityMode implements TranslatableEnum, StringRepresentable { + NEAREST("nearest"), + RANDOM("random"), + ROUND_ROBIN("round_robin"); + + private final String name; + + EntityMode(String name) { + this.name = name; + } + + @Override + public String getTranslationKey() { + return "modularrouters.itemText.activator.entityMode." + getSerializedName(); + } + + @Override + public String getSerializedName() { + return name; + } + } + + public record ActivatorSettings(ActionType actionType, LookDirection lookDirection, EntityMode entityMode, boolean sneaking) + { + public static final ActivatorSettings DEFAULT = new ActivatorSettings( + ActionType.ITEM_OR_BLOCK, LookDirection.LEVEL, EntityMode.NEAREST, false + ); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + StringRepresentable.fromEnum(ActionType::values) + .optionalFieldOf("action", ActionType.USE_ITEM_ON_ENTITY) + .forGetter(ActivatorSettings::actionType), + StringRepresentable.fromEnum(LookDirection::values) + .optionalFieldOf("action", LookDirection.LEVEL) + .forGetter(ActivatorSettings::lookDirection), + StringRepresentable.fromEnum(EntityMode::values) + .optionalFieldOf("action", EntityMode.NEAREST) + .forGetter(ActivatorSettings::entityMode), + Codec.BOOL + .optionalFieldOf("sneaking", false) + .forGetter(ActivatorSettings::sneaking) + ).apply(builder, ActivatorSettings::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + NeoForgeStreamCodecs.enumCodec(ActionType.class), ActivatorSettings::actionType, + NeoForgeStreamCodecs.enumCodec(LookDirection.class), ActivatorSettings::lookDirection, + NeoForgeStreamCodecs.enumCodec(EntityMode.class), ActivatorSettings::entityMode, + ByteBufCodecs.BOOL, ActivatorSettings::sneaking, + ActivatorSettings::new + ); } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledBreakerModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledBreakerModule.java index 7cc6859a..c9ba1f89 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledBreakerModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledBreakerModule.java @@ -1,42 +1,37 @@ package me.desht.modularrouters.logic.compiled; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.item.module.IPickaxeUser; import me.desht.modularrouters.util.BlockUtil; -import me.desht.modularrouters.util.ModuleHelper; import me.desht.modularrouters.util.TranslatableEnum; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LevelEvent; import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; import javax.annotation.Nonnull; public class CompiledBreakerModule extends CompiledModule { - public static final String NBT_MATCH_TYPE = "MatchType"; - private final ItemStack pickaxe; - private final MatchType matchType; + private final BreakerSettings settings; public CompiledBreakerModule(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - pickaxe = ((IPickaxeUser) stack.getItem()).getPickaxe(stack); - - CompoundTag compound = ModuleHelper.validateNBT(stack); - matchType = MatchType.values()[compound.getInt(NBT_MATCH_TYPE)]; - - // backwards compat - if (!EnchantmentHelper.getEnchantments(stack).isEmpty() && EnchantmentHelper.getEnchantments(pickaxe).isEmpty()) { - EnchantmentHelper.setEnchantments(EnchantmentHelper.getEnchantments(stack), pickaxe); - } + pickaxe = stack.getItem() instanceof IPickaxeUser p ? p.getPickaxe(stack) : ItemStack.EMPTY; + settings = stack.getOrDefault(ModDataComponents.BREAKER_SETTINGS, BreakerSettings.DEFAULT); } @Override @@ -48,7 +43,7 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { } BlockPos pos = getTarget().gPos.pos(); BlockState oldState = world.getBlockState(pos); - BlockUtil.BreakResult breakResult = BlockUtil.tryBreakBlock(router, world, pos, getFilter(), pickaxe, matchType == MatchType.BLOCK); + BlockUtil.BreakResult breakResult = BlockUtil.tryBreakBlock(router, world, pos, getFilter(), pickaxe, getMatchType() == MatchType.BLOCK); if (breakResult.isBlockBroken()) { breakResult.processDrops(world, pos, router.getBuffer()); if (ConfigHolder.common.module.breakerParticles.get() && router.getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()) == 0) { @@ -61,16 +56,43 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { } public MatchType getMatchType() { - return matchType; + return settings.matchType; } - public enum MatchType implements TranslatableEnum { - ITEM, - BLOCK; + public enum MatchType implements TranslatableEnum, StringRepresentable { + ITEM("item"), + BLOCK("block"); + + private final String name; + + MatchType(String name) { + this.name = name; + } @Override public String getTranslationKey() { - return "modularrouters.guiText.label.breakMatchType." + this; + return "modularrouters.guiText.label.breakMatchType." + name; } + + @Override + public String getSerializedName() { + return name; + } + } + + public record BreakerSettings(MatchType matchType) { + public static final BreakerSettings DEFAULT = new BreakerSettings(MatchType.ITEM); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + StringRepresentable.fromEnum(MatchType::values) + .optionalFieldOf("action", MatchType.ITEM) + .forGetter(BreakerSettings::matchType) + + ).apply(builder, BreakerSettings::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + NeoForgeStreamCodecs.enumCodec(MatchType.class), BreakerSettings::matchType, + BreakerSettings::new + ); } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledCreativeModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledCreativeModule.java index a05592ae..744befb7 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledCreativeModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledCreativeModule.java @@ -24,7 +24,7 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { if (pos >= stacks.size()) { pos = 0; } - ItemStack stack = ItemHandlerHelper.copyStackWithSize(stacks.get(pos), getItemsPerTick(router)); + ItemStack stack = stacks.get(pos).copyWithCount(getItemsPerTick(router)); pos++; ItemStack inserted = router.insertBuffer(stack); if (inserted.getCount() < stack.getCount()) { diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDetectorModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDetectorModule.java index cb820531..160d41ef 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDetectorModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDetectorModule.java @@ -1,26 +1,25 @@ package me.desht.modularrouters.logic.compiled; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.item.module.DetectorModule; -import me.desht.modularrouters.util.ModuleHelper; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.item.ItemStack; import javax.annotation.Nonnull; public class CompiledDetectorModule extends CompiledModule { - public static final String NBT_SIGNAL_LEVEL = "SignalLevel"; - public static final String NBT_STRONG_SIGNAL = "StrongSignal"; - - private final int signalLevel; - private final boolean strongSignal; + private final DetectorSettings settings; public CompiledDetectorModule(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - CompoundTag compound = ModuleHelper.validateNBT(stack); - signalLevel = compound.contains(NBT_SIGNAL_LEVEL) ? compound.getByte(NBT_SIGNAL_LEVEL) : 15; - strongSignal = compound.getBoolean(NBT_STRONG_SIGNAL); + settings = stack.getOrDefault(ModDataComponents.DETECTOR_SETTINGS, DetectorSettings.DEFAULT); } @Override @@ -42,11 +41,11 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { } public int getSignalLevel() { - return signalLevel; + return settings.signalLevel; } public boolean isStrongSignal() { - return strongSignal; + return settings.strongSignal; } @Override @@ -60,4 +59,19 @@ public void cleanup(ModularRouterBlockEntity router) { super.cleanup(router); router.setAllowRedstoneEmission(false); } + + public record DetectorSettings(int signalLevel, boolean strongSignal) { + public static final DetectorSettings DEFAULT = new DetectorSettings(15, false); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + ExtraCodecs.intRange(0, 15).optionalFieldOf("signal_level", 15).forGetter(DetectorSettings::signalLevel), + Codec.BOOL.optionalFieldOf("strong", false).forGetter(DetectorSettings::strongSignal) + ).apply(builder, DetectorSettings::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.VAR_INT, DetectorSettings::signalLevel, + ByteBufCodecs.BOOL, DetectorSettings::strongSignal, + DetectorSettings::new + ); + } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDistributorModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDistributorModule.java index 7cc49132..8234b775 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDistributorModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDistributorModule.java @@ -1,19 +1,25 @@ package me.desht.modularrouters.logic.compiled; import com.google.common.collect.Lists; -import me.desht.modularrouters.ModularRouters; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.item.module.TargetedModule; import me.desht.modularrouters.logic.ModuleTarget; +import me.desht.modularrouters.logic.settings.TransferDirection; import me.desht.modularrouters.util.BeamData; import me.desht.modularrouters.util.TranslatableEnum; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.neoforged.neoforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; import javax.annotation.Nonnull; import java.util.Comparator; @@ -21,43 +27,19 @@ import java.util.Set; public class CompiledDistributorModule extends CompiledSenderModule2 { - public static final String NBT_STRATEGY = "DistStrategy"; - public static final String NBT_PULLING = "Pulling"; - - public enum DistributionStrategy implements TranslatableEnum { - ROUND_ROBIN, - RANDOM, - NEAREST_FIRST, - FURTHEST_FIRST; - - @Override - public String getTranslationKey() { - return "modularrouters.itemText.distributor.strategy." + this; - } - } - - private final DistributionStrategy distributionStrategy; - private int nextTarget = 0; - private boolean pulling = false; + private final DistributorSettings settings; + private int nextTarget; public CompiledDistributorModule(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - CompoundTag compound = stack.getTagElement(ModularRouters.MODID); - if (compound != null) { - distributionStrategy = DistributionStrategy.values()[compound.getInt(NBT_STRATEGY)]; - if (distributionStrategy == DistributionStrategy.FURTHEST_FIRST) { - nextTarget = getTargets().size() - 1; - } - pulling = compound.getBoolean(NBT_PULLING); - } else { - distributionStrategy = DistributionStrategy.ROUND_ROBIN; - } + settings = stack.getOrDefault(ModDataComponents.DISTRIBUTOR_SETTINGS, DistributorSettings.DEFAULT); + nextTarget = settings.strategy == DistributionStrategy.FURTHEST_FIRST ? getTargets().size() - 1 : 0; } @Override public boolean execute(@Nonnull ModularRouterBlockEntity router) { - return pulling ? executePull(router) : super.execute(router); + return isPulling() ? executePull(router) : super.execute(router); } private boolean executePull(ModularRouterBlockEntity router) { @@ -78,18 +60,21 @@ private boolean executePull(ModularRouterBlockEntity router) { } public boolean isPulling() { - return pulling; + return settings.direction == TransferDirection.TO_ROUTER; } public DistributionStrategy getDistributionStrategy() { - return distributionStrategy; + return settings.strategy; } @Override void playParticles(ModularRouterBlockEntity router, BlockPos targetPos, ItemStack stack) { if (router.getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()) < 2) { - BeamData data = new BeamData(router.getTickRate(), targetPos, stack, getBeamColor()); - router.addItemBeam(isPulling() ? data.reverseItems() : data); + BeamData d = new BeamData.Builder(router, targetPos, getBeamColor()) + .reversed(isPulling()) + .withItemStack(stack) + .build(); + router.addItemBeam(d); } } @@ -119,11 +104,11 @@ private static double calcDist(ModuleTarget tgt, @Nonnull BlockEntity blockEntit public ModuleTarget getEffectiveTarget(ModularRouterBlockEntity router) { if (getTargets() == null || getTargets().isEmpty()) return null; int nTargets = getTargets().size(); - if (nTargets == 1) return getTargets().get(0); // degenerate case + if (nTargets == 1) return getTargets().getFirst(); // degenerate case ModuleTarget res = null; ItemStack stack = router.peekBuffer(getItemsPerTick(router)); - switch (distributionStrategy) { + switch (getDistributionStrategy()) { case ROUND_ROBIN: for (int i = 1; i <= nTargets; i++) { nextTarget++; @@ -163,4 +148,49 @@ public ModuleTarget getEffectiveTarget(ModularRouterBlockEntity router) { private boolean okToInsert(ModuleTarget target, ItemStack stack) { return target.getItemHandler().map(h -> ItemHandlerHelper.insertItem(h, stack, true).isEmpty()).orElse(false); } + + + public enum DistributionStrategy implements TranslatableEnum, StringRepresentable { + ROUND_ROBIN("round_robin"), + RANDOM("random"), + NEAREST_FIRST("nearest_first"), + FURTHEST_FIRST("furthest_first"); + + private final String name; + + DistributionStrategy(String name) { + this.name = name; + } + + @Override + public String getTranslationKey() { + return "modularrouters.itemText.distributor.strategy." + name; + } + + @Override + public String getSerializedName() { + return name; + } + } + + public record DistributorSettings(DistributionStrategy strategy, TransferDirection direction) { + public static final DistributorSettings DEFAULT = new DistributorSettings(DistributionStrategy.ROUND_ROBIN, TransferDirection.FROM_ROUTER); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + StringRepresentable.fromEnum(DistributionStrategy::values).optionalFieldOf("strategy", DistributionStrategy.ROUND_ROBIN) + .forGetter(DistributorSettings::strategy), + StringRepresentable.fromEnum(TransferDirection::values).optionalFieldOf("pulling", TransferDirection.TO_ROUTER) + .forGetter(DistributorSettings::direction) + ).apply(builder, DistributorSettings::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + NeoForgeStreamCodecs.enumCodec(DistributionStrategy.class), DistributorSettings::strategy, + NeoForgeStreamCodecs.enumCodec(TransferDirection.class), DistributorSettings::direction, + DistributorSettings::new + ); + + public boolean isPulling() { + return direction == TransferDirection.TO_ROUTER; + } + } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDropperModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDropperModule.java index f15de6a8..02a31311 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDropperModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledDropperModule.java @@ -16,7 +16,7 @@ public class CompiledDropperModule extends CompiledModule { public CompiledDropperModule(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - pickupDelay = getAugmentCount(ModItems.PICKUP_DELAY_AUGMENT.get()) * PickupDelayAugment.TICKS_PER_AUGMENT; + pickupDelay = getAugmentCount(ModItems.PICKUP_DELAY_AUGMENT) * PickupDelayAugment.TICKS_PER_AUGMENT; } @Override diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledEnergyDistributorModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledEnergyDistributorModule.java index 59fafe79..cada8fd1 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledEnergyDistributorModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledEnergyDistributorModule.java @@ -37,7 +37,7 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { int sent = handler.receiveEnergy(toExtract, false); storage.extractEnergy(sent, false); if (sent > 0 && doBeam) { - router.addItemBeam(new BeamData(router.getTickRate(), target.gPos.pos(), 0xE04040)); + router.addItemBeam(new BeamData.Builder(router, target.gPos.pos(), 0xE0404040).build()); } return sent; }).orElse(0); diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledExtruderModule1.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledExtruderModule1.java index d210e0ad..b779cb3f 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledExtruderModule1.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledExtruderModule1.java @@ -1,5 +1,6 @@ package me.desht.modularrouters.logic.compiled; +import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.config.ConfigHolder; import me.desht.modularrouters.core.ModItems; @@ -12,7 +13,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LiquidBlock; @@ -35,14 +35,10 @@ public class CompiledExtruderModule1 extends CompiledModule { public CompiledExtruderModule1(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - distance = router == null ? 0 : router.getExtensionData().getInt(NBT_EXTRUDER_DIST + getFacing()); - pushingAugments = getAugmentCount(ModItems.PUSHING_AUGMENT.get()); - pickaxe = stack.getItem() instanceof IPickaxeUser ? ((IPickaxeUser) stack.getItem()).getPickaxe(stack) : ItemStack.EMPTY; - // backwards compat - if (!EnchantmentHelper.getEnchantments(stack).isEmpty() && EnchantmentHelper.getEnchantments(pickaxe).isEmpty()) { - EnchantmentHelper.setEnchantments(EnchantmentHelper.getEnchantments(stack), pickaxe); - } + distance = router == null ? 0 : router.getExtensionData().getInt(NBT_EXTRUDER_DIST + getAbsoluteFacing()); + pushingAugments = getAugmentCount(ModItems.PUSHING_AUGMENT); + pickaxe = stack.getItem() instanceof IPickaxeUser p ? p.getPickaxe(stack) : ItemStack.EMPTY; } @Override @@ -52,33 +48,33 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { if (extend && !router.isBufferEmpty() && distance < getRange() && isRegulationOK(router, false)) { // try to extend - BlockPos placePos = router.getBlockPos().relative(getFacing(), distance + 1); + BlockPos placePos = router.getBlockPos().relative(getAbsoluteFacing(), distance + 1); ItemStack toPlace = router.peekBuffer(1); - BlockState state = BlockUtil.tryPlaceAsBlock(router, toPlace, world, placePos, getFacing()); + BlockState state = BlockUtil.tryPlaceAsBlock(router, toPlace, world, placePos, getAbsoluteFacing()); if (state != null) { router.extractBuffer(1); - router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getFacing(), ++distance); + router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getAbsoluteFacing(), ++distance); if (ConfigHolder.common.module.extruderSound.get()) { router.playSound(null, placePos, state.getBlock().getSoundType(state, world, placePos, null).getPlaceSound(), SoundSource.BLOCKS, 1.0f, 0.5f + distance * 0.1f); } - tryPushEntities(router.getLevel(), placePos, getFacing()); + tryPushEntities(router.getLevel(), placePos, getAbsoluteFacing()); return true; } } else if (!extend && distance > 0 && isRegulationOK(router, true)) { // try to retract - BlockPos breakPos = router.getBlockPos().relative(getFacing(), distance); + BlockPos breakPos = router.getBlockPos().relative(getAbsoluteFacing(), distance); BlockState oldState = world.getBlockState(breakPos); Block oldBlock = oldState.getBlock(); if (world.isEmptyBlock(breakPos) || oldBlock instanceof LiquidBlock) { // nothing there? continue to retract anyway... - router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getFacing(), --distance); + router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getAbsoluteFacing(), --distance); return false; } BlockUtil.BreakResult dropResult = BlockUtil.tryBreakBlock(router, world, breakPos, getFilter(), pickaxe, false); if (dropResult.isBlockBroken()) { - router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getFacing(), --distance); + router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getAbsoluteFacing(), --distance); dropResult.processDrops(world, breakPos, router.getBuffer()); if (ConfigHolder.common.module.extruderSound.get()) { router.playSound(null, breakPos, @@ -103,7 +99,7 @@ void tryPushEntities(Level world, BlockPos placePos, Direction facing) { entity.horizontalCollision = false; entity.verticalCollision = false; if (entity instanceof LivingEntity) ((LivingEntity) entity).setJumping(true); - PacketDistributor.TRACKING_ENTITY.with(entity).send(new PushEntityMessage(entity, v)); + PacketDistributor.sendToPlayersTrackingEntity(entity, PushEntityMessage.forEntity(entity, v)); } } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledExtruderModule2.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledExtruderModule2.java index 66ed6432..71c0bd8e 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledExtruderModule2.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledExtruderModule2.java @@ -1,6 +1,5 @@ package me.desht.modularrouters.logic.compiled; -import com.google.common.collect.ImmutableList; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.container.Extruder2ModuleMenu.TemplateHandler; import me.desht.modularrouters.core.ModBlockEntities; @@ -15,34 +14,19 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.fluids.IFluidBlock; -import net.neoforged.neoforge.items.ItemHandlerHelper; import javax.annotation.Nonnull; -import java.util.ArrayList; import java.util.List; public class CompiledExtruderModule2 extends CompiledExtruderModule1 { - private final List blockList; + private final List blockTemplate; private final boolean mimic; public CompiledExtruderModule2(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - List stacks = new ArrayList<>(); - mimic = getAugmentCount(ModItems.MIMIC_AUGMENT.get()) > 0; - - TemplateHandler handler = new TemplateHandler(stack, router); - for (int i = 0; i < handler.getSlots() && stacks.size() < getRange(); i++) { - ItemStack stack1 = handler.getStackInSlot(i); - if (stack1.isEmpty()) { - break; - } else { - for (int j = 0; j < stack1.getCount() && stacks.size() < getRange(); j++) { - stacks.add(ItemHandlerHelper.copyStackWithSize(stack1, 1)); - } - } - } - blockList = ImmutableList.copyOf(stacks); + mimic = getAugmentCount(ModItems.MIMIC_AUGMENT) > 0; + blockTemplate = new TemplateHandler(stack, router).toTemplate(getRange()); } @Override @@ -50,17 +34,17 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { boolean extend = shouldExtend(router); Level world = router.nonNullLevel(); - if (extend && distance < blockList.size()) { + if (extend && distance < blockTemplate.size()) { // try to extend - if (!(blockList.get(distance).getItem() instanceof BlockItem)) { + if (!(blockTemplate.get(distance).getItem() instanceof BlockItem)) { // non-block item; it's a spacer so just skip over - router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getFacing(), ++distance); + router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getAbsoluteFacing(), ++distance); } else { - BlockPos placePos = router.getBlockPos().relative(getFacing(), distance + 1); + BlockPos placePos = router.getBlockPos().relative(getAbsoluteFacing(), distance + 1); BlockState state = ModBlocks.TEMPLATE_FRAME.get().defaultBlockState(); if (BlockUtil.tryPlaceBlock(router, state, world, placePos)) { world.getBlockEntity(placePos, ModBlockEntities.TEMPLATE_FRAME.get()).ifPresent(te -> { - te.setCamouflage(blockList.get(distance), getFacing(), getRouterFacing()); + te.setCamouflage(blockTemplate.get(distance), getAbsoluteFacing(), getRouterFacing()); te.setExtendedMimic(mimic); if (mimic) { // in case we're mimicking a redstone emitter @@ -70,18 +54,21 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { router.playSound(null, placePos, state.getBlock().getSoundType(state, world, placePos, null).getPlaceSound(), SoundSource.BLOCKS, 1.0f, 0.5f + distance * 0.1f); - router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getFacing(), ++distance); - tryPushEntities(router.getLevel(), placePos, getFacing()); + router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getAbsoluteFacing(), ++distance); + tryPushEntities(router.getLevel(), placePos, getAbsoluteFacing()); return true; } } } else if (!extend && distance > 0) { - BlockPos breakPos = router.getBlockPos().relative(getFacing(), distance); + BlockPos breakPos = router.getBlockPos().relative(getAbsoluteFacing(), distance); BlockState oldState = world.getBlockState(breakPos); - router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getFacing(), --distance); + router.getExtensionData().putInt(NBT_EXTRUDER_DIST + getAbsoluteFacing(), --distance); if (okToBreak(oldState)) { if (oldState.getBlock() == ModBlocks.TEMPLATE_FRAME.get()) { world.removeBlock(breakPos, false); + router.playSound(null, breakPos, + oldState.getBlock().getSoundType(oldState, world, breakPos, null).getPlaceSound(), + SoundSource.BLOCKS, 1.0f, 0.5f + distance * 0.1f); } return true; } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledFlingerModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledFlingerModule.java index ec5ffff5..ff6a7d9b 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledFlingerModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledFlingerModule.java @@ -1,37 +1,35 @@ package me.desht.modularrouters.logic.compiled; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModSounds; -import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.logic.ModuleTarget; -import me.desht.modularrouters.util.ModuleHelper; +import me.desht.modularrouters.logic.settings.RelativeDirection; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; import javax.annotation.Nonnull; public class CompiledFlingerModule extends CompiledDropperModule { - public static final String NBT_SPEED = "Speed"; - public static final String NBT_PITCH = "Pitch"; - public static final String NBT_YAW = "Yaw"; - - private final float speed, pitch, yaw; + private final FlingerSettings settings; public CompiledFlingerModule(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - CompoundTag compound = ModuleHelper.validateNBT(stack); - speed = compound.getFloat(NBT_SPEED); - pitch = compound.getFloat(NBT_PITCH); - yaw = compound.getFloat(NBT_YAW); + settings = stack.getOrDefault(ModDataComponents.FLINGER_SETTINGS, FlingerSettings.DEFAULT); } @Override @@ -40,34 +38,34 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { if (fired && ConfigHolder.common.module.flingerEffects.get()) { ModuleTarget target = getTarget(); - int n = Math.round(speed * 5); + int n = Math.round(getSpeed() * 5); BlockPos pos = target.gPos.pos(); if (router.getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()) < 2 && router.getLevel() instanceof ServerLevel serverLevel) { serverLevel.sendParticles(ParticleTypes.LARGE_SMOKE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, n, 0.0, 0.0, 0.0, 0.0); } - router.playSound(null, pos, ModSounds.THUD.get(), SoundSource.BLOCKS, 0.5f + speed, 1.0f); + router.playSound(null, pos, ModSounds.THUD.get(), SoundSource.BLOCKS, 0.5f + getSpeed(), 1.0f); } return fired; } public float getYaw() { - return yaw; + return settings.yaw; } public float getPitch() { - return pitch; + return settings.pitch; } public float getSpeed() { - return speed; + return settings.speed; } @Override protected void setupItemVelocity(ModularRouterBlockEntity router, ItemEntity item) { - Direction routerFacing = router.getAbsoluteFacing(ModuleItem.RelativeDirection.FRONT); + Direction routerFacing = router.getAbsoluteFacing(RelativeDirection.FRONT); float basePitch = 0.0f; float baseYaw; switch (getDirection()) { @@ -79,16 +77,16 @@ protected void setupItemVelocity(ModularRouterBlockEntity router, ItemEntity ite basePitch = -90.0f; baseYaw = yawFromFacing(routerFacing); } - default -> baseYaw = yawFromFacing(getFacing()); + default -> baseYaw = yawFromFacing(getAbsoluteFacing()); } - double yawRad = Math.toRadians(baseYaw + yaw), pitchRad = Math.toRadians(basePitch + pitch); + double yawRad = Math.toRadians(baseYaw + getYaw()), pitchRad = Math.toRadians(basePitch + getPitch()); double x = (Math.cos(yawRad) * Math.cos(pitchRad)); // east is positive X double y = Math.sin(pitchRad); double z = -(Math.sin(yawRad) * Math.cos(pitchRad)); // north is negative Z - item.setDeltaMovement(x * speed, y * speed, z * speed); + item.setDeltaMovement(new Vec3(x, y, z).scale(getSpeed())); } private float yawFromFacing(Direction absoluteFacing) { @@ -100,4 +98,21 @@ private float yawFromFacing(Direction absoluteFacing) { default -> 0; }; } + + public record FlingerSettings(float speed, float pitch, float yaw) { + public static final FlingerSettings DEFAULT = new FlingerSettings(0f, 0f, 0f); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + Codec.FLOAT.fieldOf("speed").forGetter(FlingerSettings::speed), + Codec.FLOAT.fieldOf("pitch").forGetter(FlingerSettings::pitch), + Codec.FLOAT.optionalFieldOf("yaw", 0f).forGetter(FlingerSettings::yaw) + ).apply(builder, FlingerSettings::new)); + + public static StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.FLOAT, FlingerSettings::speed, + ByteBufCodecs.FLOAT, FlingerSettings::pitch, + ByteBufCodecs.FLOAT, FlingerSettings::yaw, + FlingerSettings::new + ); + } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledFluidModule1.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledFluidModule1.java index a385fa0e..b134163a 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledFluidModule1.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledFluidModule1.java @@ -1,15 +1,21 @@ package me.desht.modularrouters.logic.compiled; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; -import me.desht.modularrouters.item.module.FluidModule1.FluidDirection; -import me.desht.modularrouters.util.ModuleHelper; +import me.desht.modularrouters.logic.settings.TransferDirection; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.tags.FluidTags; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -22,36 +28,24 @@ import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.common.SoundActions; import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.fluids.FluidUtil; import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.fluids.capability.IFluidHandlerItem; import net.neoforged.neoforge.fluids.capability.templates.FluidTank; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; import javax.annotation.Nonnull; import java.util.Objects; import java.util.Optional; public class CompiledFluidModule1 extends CompiledModule { - public static final String NBT_FORCE_EMPTY = "ForceEmpty"; - public static final String NBT_MAX_TRANSFER = "MaxTransfer"; - public static final String NBT_FLUID_DIRECTION = "FluidDir"; - public static final String NBT_REGULATE_ABSOLUTE = "RegulateAbsolute"; - - public static final int BUCKET_VOLUME = 1000; - - private final int maxTransfer; - private final FluidDirection fluidDirection; - private final boolean forceEmpty; // force emptying even if there's a fluid block in the way - private final boolean regulateAbsolute; // true = regulate by mB; false = regulate by % of tank's capacity + private final FluidModuleSettings settings; public CompiledFluidModule1(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - CompoundTag compound = ModuleHelper.validateNBT(stack); - maxTransfer = compound.getInt(NBT_MAX_TRANSFER); - fluidDirection = FluidDirection.values()[compound.getByte(NBT_FLUID_DIRECTION)]; - forceEmpty = compound.getBoolean(NBT_FORCE_EMPTY); - regulateAbsolute = compound.getBoolean(NBT_REGULATE_ABSOLUTE); + settings = stack.getOrDefault(ModDataComponents.FLUID_SETTINGS.get(), FluidModuleSettings.DEFAULT); } @Override @@ -67,19 +61,19 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { boolean didWork; if (targetFluidHandler.isPresent()) { // there's a block entity with a fluid capability; try to interact with that - didWork = switch (fluidDirection) { - case IN -> targetFluidHandler.map(worldHandler -> doTransfer(router, worldHandler, routerHandler, FluidDirection.IN)) + didWork = switch (getFluidDirection()) { + case TO_ROUTER -> targetFluidHandler.map(worldHandler -> doTransfer(router, worldHandler, routerHandler, TransferDirection.TO_ROUTER)) .orElse(false); - case OUT -> targetFluidHandler.map(worldHandler -> doTransfer(router, routerHandler, worldHandler, FluidDirection.OUT)) + case FROM_ROUTER -> targetFluidHandler.map(worldHandler -> doTransfer(router, routerHandler, worldHandler, TransferDirection.FROM_ROUTER)) .orElse(false); }; } else { // no block entity at the target position; try to interact with a fluid block in the world boolean playSound = router.getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()) == 0; BlockPos pos = getTarget().gPos.pos(); - didWork = switch (fluidDirection) { - case IN -> tryPickupFluid(router, routerHandler, world, pos, playSound); - case OUT -> tryPourOutFluid(router, routerHandler, world, pos, playSound); + didWork = switch (getFluidDirection()) { + case TO_ROUTER -> tryPickupFluid(router, routerHandler, world, pos, playSound); + case FROM_ROUTER -> tryPourOutFluid(router, routerHandler, world, pos, playSound); }; } @@ -101,15 +95,15 @@ private boolean tryPickupFluid(ModularRouterBlockEntity router, IFluidHandler ro if (fluid == Fluids.EMPTY || !fluid.isSource(fluidState) || !getFilter().testFluid(fluid)) { return false; } - FluidTank tank = new FluidTank(BUCKET_VOLUME); - tank.setFluid(new FluidStack(fluid, BUCKET_VOLUME)); - FluidStack maybeSent = FluidUtil.tryFluidTransfer(routerHandler, tank, BUCKET_VOLUME, false); - if (maybeSent.getAmount() != BUCKET_VOLUME) { + FluidTank tank = new FluidTank(FluidType.BUCKET_VOLUME); + tank.setFluid(new FluidStack(fluid, FluidType.BUCKET_VOLUME)); + FluidStack maybeSent = FluidUtil.tryFluidTransfer(routerHandler, tank, FluidType.BUCKET_VOLUME, false); + if (maybeSent.getAmount() != FluidType.BUCKET_VOLUME) { return false; } // actually do the pickup & transfer now bucketPickup.pickupBlock(router.getFakePlayer(), world, pos, state); - FluidStack transferred = FluidUtil.tryFluidTransfer(routerHandler, tank, BUCKET_VOLUME, true); + FluidStack transferred = FluidUtil.tryFluidTransfer(routerHandler, tank, FluidType.BUCKET_VOLUME, true); if (!transferred.isEmpty() && playSound) { playFillSound(world, pos, fluid); } @@ -117,14 +111,14 @@ private boolean tryPickupFluid(ModularRouterBlockEntity router, IFluidHandler ro } private boolean tryPourOutFluid(ModularRouterBlockEntity router, IFluidHandler routerHandler, Level world, BlockPos pos, boolean playSound) { - if (!forceEmpty && !(world.isEmptyBlock(pos) || world.getBlockState(pos).getBlock() instanceof LiquidBlockContainer)) { + if (!isForceEmpty() && !(world.isEmptyBlock(pos) || world.getBlockState(pos).getBlock() instanceof LiquidBlockContainer)) { return false; } // code partially lifted from BucketItem - FluidStack toPlace = routerHandler.drain(BUCKET_VOLUME, IFluidHandler.FluidAction.SIMULATE); - if (toPlace.getAmount() < BUCKET_VOLUME) { + FluidStack toPlace = routerHandler.drain(FluidType.BUCKET_VOLUME, IFluidHandler.FluidAction.SIMULATE); + if (toPlace.getAmount() < FluidType.BUCKET_VOLUME) { return false; // must be a full bucket's worth to place in the world } Fluid fluid = toPlace.getFluid(); @@ -157,7 +151,7 @@ private boolean tryPourOutFluid(ModularRouterBlockEntity router, IFluidHandler r } } - routerHandler.drain(BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE); + routerHandler.drain(FluidType.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE); return true; } @@ -189,11 +183,11 @@ private void playEvaporationEffects(Level world, BlockPos pos, Fluid fluid) { } } - private boolean doTransfer(ModularRouterBlockEntity router, IFluidHandler src, IFluidHandler dest, FluidDirection direction) { + private boolean doTransfer(ModularRouterBlockEntity router, IFluidHandler src, IFluidHandler dest, TransferDirection direction) { if (getRegulationAmount() > 0) { - if (direction == FluidDirection.IN && checkFluidInTank(src) <= getRegulationAmount()) { + if (direction == TransferDirection.TO_ROUTER && checkFluidInTank(src) <= getRegulationAmount()) { return false; - } else if (direction == FluidDirection.OUT && checkFluidInTank(dest) >= getRegulationAmount()) { + } else if (direction == TransferDirection.FROM_ROUTER && checkFluidInTank(dest) >= getRegulationAmount()) { return false; } } @@ -226,19 +220,47 @@ private int checkFluidInTank(IFluidHandler handler) { } } - public FluidDirection getFluidDirection() { - return fluidDirection; + public TransferDirection getFluidDirection() { + return settings.direction; } public int getMaxTransfer() { - return maxTransfer == 0 ? BUCKET_VOLUME : maxTransfer; + return settings.maxTransfer == 0 ? FluidType.BUCKET_VOLUME : settings.maxTransfer; } public boolean isForceEmpty() { - return forceEmpty; + return settings.forceEmpty; } public boolean isRegulateAbsolute() { - return regulateAbsolute; + return settings.regulateAbsolute; } + + public record FluidModuleSettings(int maxTransfer, TransferDirection direction, boolean forceEmpty, boolean regulateAbsolute) { + public static final FluidModuleSettings DEFAULT = new FluidModuleSettings(0, TransferDirection.TO_ROUTER, false, false); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + ExtraCodecs.NON_NEGATIVE_INT + .optionalFieldOf("max_transfer", 0) + .forGetter(FluidModuleSettings::maxTransfer), + StringRepresentable.fromEnum(TransferDirection::values) + .optionalFieldOf("direction", TransferDirection.TO_ROUTER) + .forGetter(FluidModuleSettings::direction), + Codec.BOOL + .optionalFieldOf("force_empty", false) + .forGetter(FluidModuleSettings::forceEmpty), + Codec.BOOL + .optionalFieldOf("regulate_absolute", false) + .forGetter(FluidModuleSettings::regulateAbsolute) + ).apply(builder, FluidModuleSettings::new)); + + public static StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.INT, FluidModuleSettings::maxTransfer, + NeoForgeStreamCodecs.enumCodec(TransferDirection.class), FluidModuleSettings::direction, + ByteBufCodecs.BOOL, FluidModuleSettings::forceEmpty, + ByteBufCodecs.BOOL, FluidModuleSettings::regulateAbsolute, + CompiledFluidModule1.FluidModuleSettings::new + ); + } + } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledModule.java index 87aa876e..d9958ebd 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledModule.java @@ -7,40 +7,40 @@ import me.desht.modularrouters.item.augment.AugmentItem.AugmentCounter; import me.desht.modularrouters.item.module.IRangedModule; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.item.module.ModuleItem.RelativeDirection; import me.desht.modularrouters.logic.ModuleTarget; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.ModuleSettings; +import me.desht.modularrouters.logic.settings.ModuleTermination; +import me.desht.modularrouters.logic.settings.RedstoneBehaviour; +import me.desht.modularrouters.logic.settings.RelativeDirection; import me.desht.modularrouters.util.BlockUtil; import me.desht.modularrouters.util.CountedItemStacks; import me.desht.modularrouters.util.MiscUtil; -import me.desht.modularrouters.util.ModuleHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.GlobalPos; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.items.IItemHandler; -import net.neoforged.neoforge.items.ItemHandlerHelper; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.function.Supplier; public abstract class CompiledModule { - private final Filter filter; private final ModuleItem module; - private final RelativeDirection direction; + protected final ModuleSettings commonSettings; + private final Filter filter; + @Nullable + private final Direction absoluteFacing; private final List targets; - private final RouterRedstoneBehaviour behaviour; - private final ModuleItem.Termination termination; - private final Direction facing; + @Nullable private final Direction routerFacing; - private final int regulationAmount; private final AugmentCounter augmentCounter; private final int range, rangeSquared; @Nullable @@ -62,18 +62,14 @@ protected CompiledModule(@Nullable ModularRouterBlockEntity router, ItemStack st module = (ModuleItem) stack.getItem(); augmentCounter = new AugmentCounter(stack); - direction = ModuleHelper.getRelativeDirection(stack); - range = module instanceof IRangedModule ? - ((IRangedModule) module).getCurrentRange(getRangeModifier()) : 0; + commonSettings = ModuleItem.getCommonSettings(stack); + range = module instanceof IRangedModule r ? r.getCurrentRange(getRangeModifier()) : 0; rangeSquared = range * range; targets = setupTargets(router, stack); filter = new Filter(stack, shouldStoreRawFilterItems(), augmentCounter.getAugmentCount(ModItems.FILTER_ROUND_ROBIN_AUGMENT.get()) > 0); - termination = ModuleHelper.getTermination(stack); - behaviour = ModuleHelper.getRedstoneBehaviour(stack); - regulationAmount = ModuleHelper.getRegulatorAmount(stack); - facing = router == null ? null : router.getAbsoluteFacing(direction); + absoluteFacing = router == null ? null : router.getAbsoluteFacing(commonSettings.facing()); routerFacing = router == null ? null : router.getAbsoluteFacing(RelativeDirection.FRONT); - this.event = router == null ? null : new ExecuteModuleEvent(router, this); + event = router == null ? null : new ExecuteModuleEvent(router, this); } /** @@ -91,7 +87,7 @@ public Filter getFilter() { } public final RelativeDirection getDirection() { - return direction; + return commonSettings.facing(); } protected boolean shouldStoreRawFilterItems() { @@ -106,7 +102,7 @@ protected boolean shouldStoreRawFilterItems() { * @return the first target as set up by {@link #setupTargets(ModularRouterBlockEntity, ItemStack)} */ public ModuleTarget getTarget() { - return targets == null || targets.isEmpty() ? null : targets.get(0); + return targets == null || targets.isEmpty() ? null : targets.getFirst(); } /** @@ -121,16 +117,20 @@ public List getTargets() { public boolean hasTarget() { return targets != null && !targets.isEmpty(); } - public ModuleItem.Termination termination() { - return termination; + public ModuleTermination termination() { + return commonSettings.termination(); } - public final RouterRedstoneBehaviour getRedstoneBehaviour() { - return behaviour; + public final RedstoneBehaviour getRedstoneBehaviour() { + return commonSettings.redstoneBehaviour(); } public int getRegulationAmount() { - return augmentCounter.getAugmentCount(ModItems.REGULATOR_AUGMENT.get()) > 0 ? regulationAmount : 0; + return augmentCounter.getAugmentCount(ModItems.REGULATOR_AUGMENT.get()) > 0 ? commonSettings.regulatorAmount() : 0; + } + + public int getAugmentCount(Supplier augmentType) { + return augmentCounter.getAugmentCount(augmentType); } public int getAugmentCount(Item augmentType) { @@ -144,17 +144,32 @@ public int getAugmentCount(Item augmentType) { * * @return absolute direction of the module */ - public final Direction getFacing() { - return facing; + @Nullable + public final Direction getAbsoluteFacing() { + return absoluteFacing; } + /** + * Called immediately after the router compiles or recompiles the module, which happens if a change to any + * installed module item occurs (not necessarily this one). Can be overridden in subclasses to carry out any + * initialisation work needed, but be sure to call this super implementation! + * + * @param router the router this module is installed in + */ @ApiStatus.OverrideOnly - public void onCompiled(ModularRouterBlockEntity router) { - if (behaviour == RouterRedstoneBehaviour.PULSE) { + public void onCompiled(@NotNull ModularRouterBlockEntity router) { + if (getRedstoneBehaviour() == RedstoneBehaviour.PULSE) { router.setHasPulsedModules(true); } } + /** + * Called immediately before the router compiles or recompiles the module, which happens if a change to any + * installed module item occurs (not necessarily this one). Can be overridden in subclasses to carry out any + * cleanup work needed, but be sure to call this super implementation! + * + * @param router the router this module is installed in + */ @ApiStatus.OverrideOnly public void cleanup(ModularRouterBlockEntity router) { // does nothing by default @@ -195,14 +210,14 @@ private void setLastMatchPos(BlockPos key, int lastMatchPos) { * @return a list of router target objects (for most modules this is a singleton list) */ List setupTargets(ModularRouterBlockEntity router, ItemStack stack) { - if (router == null || (module.isDirectional() && direction == RelativeDirection.NONE)) { + if (router == null || (module.isDirectional() && getDirection() == RelativeDirection.NONE)) { return null; } - Direction facing = router.getAbsoluteFacing(direction); + Direction facing = router.getAbsoluteFacing(getDirection()); BlockPos pos = router.getBlockPos().relative(facing); String blockName = BlockUtil.getBlockName(router.getLevel(), pos); GlobalPos gPos = MiscUtil.makeGlobalPos(router.nonNullLevel(), pos); - return Collections.singletonList(new ModuleTarget(gPos, facing.getOpposite(), blockName)); + return List.of(new ModuleTarget(gPos, facing.getOpposite(), blockName)); } public int getItemsPerTick(ModularRouterBlockEntity router) { @@ -237,7 +252,7 @@ public final ItemStack transferToRouter(IItemHandler handler, @Nullable BlockPos setLastMatchPos(key, (slot + 1) % handler.getSlots()); return transferred; } - if (ItemHandlerHelper.canItemStacksStack(wanted, toPull)) { + if (ItemStack.isSameItemSameComponents(wanted, toPull)) { // this item is suitable for pulling ItemStack notInserted = router.insertBuffer(toPull); int inserted = toPull.getCount() - notInserted.getCount(); @@ -258,7 +273,7 @@ private ItemStack findItemToPull(ModularRouterBlockEntity router, IItemHandler h ItemStack stackInRouter = router.peekBuffer(1); if (!stackInRouter.isEmpty() && getFilter().test(stackInRouter) && (count == null || count.getInt(stackInRouter) - nToTake >= getRegulationAmount())) { // something in the router - try to pull more of that - return ItemHandlerHelper.copyStackWithSize(stackInRouter, nToTake); + return stackInRouter.copyWithCount(nToTake); } else if (stackInRouter.isEmpty()) { // router empty - just pull the next item that passes the filter for (int i = 0; i < handler.getSlots(); i++) { @@ -266,7 +281,7 @@ private ItemStack findItemToPull(ModularRouterBlockEntity router, IItemHandler h ItemStack stack = handler.getStackInSlot(pos); if (getFilter().test(stack) && (count == null || count.getInt(stack) - nToTake >= getRegulationAmount())) { setLastMatchPos(key, pos); - return ItemHandlerHelper.copyStackWithSize(stack, nToTake); + return stack.copyWithCount(nToTake); } } } @@ -290,9 +305,9 @@ public boolean shouldRun(boolean powered, boolean pulsed) { } public boolean isRegulationOK(ModularRouterBlockEntity router, boolean inbound) { - if (regulationAmount == 0) return true; // no regulation + if (commonSettings.regulatorAmount() == 0) return true; // no regulation int items = router.getBufferItemStack().getCount(); - return inbound && regulationAmount > items || !inbound && regulationAmount < items; + return inbound && commonSettings.regulatorAmount() > items || !inbound && commonSettings.regulatorAmount() < items; } public int getRange() { @@ -304,7 +319,7 @@ public int getRangeSquared() { } private int getRangeModifier() { - return getAugmentCount(ModItems.RANGE_UP_AUGMENT.get()) - getAugmentCount(ModItems.RANGE_DOWN_AUGMENT.get()); + return getAugmentCount(ModItems.RANGE_UP_AUGMENT) - getAugmentCount(ModItems.RANGE_DOWN_AUGMENT); } protected Direction getRouterFacing() { diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPlacerModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPlacerModule.java index 73f415dc..d4ee06a9 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPlacerModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPlacerModule.java @@ -29,7 +29,7 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { } Level level = router.nonNullLevel(); BlockPos pos = getTarget().gPos.pos(); - BlockState newState = BlockUtil.tryPlaceAsBlock(router, toPlace, level, pos, getFacing()); + BlockState newState = BlockUtil.tryPlaceAsBlock(router, toPlace, level, pos, getAbsoluteFacing()); if (newState != null) { if (ConfigHolder.common.module.placerParticles.get() && router.getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()) == 0) { level.levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, pos, Block.getId(newState)); diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPlayerModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPlayerModule.java index f109846e..fc612b16 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPlayerModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPlayerModule.java @@ -1,13 +1,19 @@ package me.desht.modularrouters.logic.compiled; import com.mojang.authlib.GameProfile; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; -import me.desht.modularrouters.item.module.PlayerModule; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.item.IPlayerOwned; +import me.desht.modularrouters.logic.settings.TransferDirection; import me.desht.modularrouters.util.InventoryUtils; import me.desht.modularrouters.util.TranslatableEnum; import me.desht.modularrouters.util.WildcardedRLMatcher; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -17,6 +23,7 @@ import net.neoforged.neoforge.event.entity.player.PlayerEvent; import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.wrapper.*; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; import net.neoforged.neoforge.server.ServerLifecycleHooks; import javax.annotation.Nonnull; @@ -24,52 +31,22 @@ import java.util.UUID; public class CompiledPlayerModule extends CompiledModule { - public static final String NBT_OPERATION = "Operation"; - public static final String NBT_SECTION = "Section"; - - public enum Operation implements TranslatableEnum { - EXTRACT, INSERT; - - public String getSymbol() { return this == INSERT ? "⟹" : "⟸"; } - - @Override - public String getTranslationKey() { - return "modularrouters.guiText.label.playerOp." + this; - } - } - - public enum Section implements TranslatableEnum { - MAIN, MAIN_NO_HOTBAR, ARMOR, OFFHAND, ENDER; - - @Override - public String getTranslationKey() { - return "modularrouters.guiText.label.playerSect." + this; - } - } - - private final Operation operation; - private final Section section; + private final PlayerSettings settings; private final GameProfile playerProfile; + private WeakReference playerRef; public CompiledPlayerModule(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - CompoundTag compound = stack.getTagElement(ModularRouters.MODID); - if (compound != null) { - playerProfile = ((PlayerModule) stack.getItem()).getOwnerProfile(stack).orElse(null); - operation = Operation.values()[compound.getInt(NBT_OPERATION)]; - section = Section.values()[compound.getInt(NBT_SECTION)]; - if (router != null && !router.nonNullLevel().isClientSide) { - Player player = playerProfile == null ? null : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(playerProfile.getId()); - playerRef = new WeakReference<>(player); - } else { - playerRef = new WeakReference<>(null); - } + settings = stack.getOrDefault(ModDataComponents.PLAYER_SETTINGS, PlayerSettings.DEFAULT); + playerProfile = ((IPlayerOwned) stack.getItem()).getOwnerProfile(stack).orElse(null); + + if (router != null && !router.nonNullLevel().isClientSide) { + Player player = playerProfile == null ? null : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(playerProfile.getId()); + playerRef = new WeakReference<>(player); } else { - operation = Operation.EXTRACT; - section = Section.MAIN; - playerProfile = null; + playerRef = new WeakReference<>(null); } } @@ -87,26 +64,23 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { } IItemHandler itemHandler = getHandler(player); - if (itemHandler == null) { - return false; - } ItemStack bufferStack = router.getBufferItemStack(); - switch (operation) { - case EXTRACT -> { + switch (getTransferDirection()) { + case TO_ROUTER -> { if (bufferStack.getCount() < bufferStack.getMaxStackSize()) { ItemStack taken = transferToRouter(itemHandler, null, router); return !taken.isEmpty(); } } - case INSERT -> { + case FROM_ROUTER -> { if (getFilter().test(bufferStack)) { if (getSection() == Section.ARMOR) { return insertArmor(router, itemHandler, bufferStack); } else { int nToSend = getItemsPerTick(router); if (getRegulationAmount() > 0) { - int existing = InventoryUtils.countItems(bufferStack, itemHandler, getRegulationAmount(), !getFilter().getFlags().isIgnoreDamage()); + int existing = InventoryUtils.countItems(bufferStack, itemHandler, getRegulationAmount(), !getFilter().getFlags().matchDamage()); nToSend = Math.min(nToSend, getRegulationAmount() - existing); if (nToSend <= 0) { return false; @@ -171,12 +145,12 @@ public String getPlayerName() { return playerProfile == null ? null : playerProfile.getName(); } - public Operation getOperation() { - return operation; + public TransferDirection getTransferDirection() { + return settings.direction; } public Section getSection() { - return section; + return settings.section; } private boolean insertArmor(ModularRouterBlockEntity router, IItemHandler itemHandler, ItemStack armorStack) { @@ -204,7 +178,7 @@ private int getSlotForArmorItem(ItemStack stack) { } private IItemHandler getHandler(Player player) { - return switch (section) { + return switch (getSection()) { case MAIN -> new PlayerMainInvWrapper(player.getInventory()); case MAIN_NO_HOTBAR -> new PlayerMainInvNoHotbarWrapper(player.getInventory()); case ARMOR -> new PlayerArmorInvWrapper(player.getInventory()); @@ -218,4 +192,47 @@ public static class PlayerMainInvNoHotbarWrapper extends RangedWrapper { super(new InvWrapper(inv), Inventory.getSelectionSize(), inv.items.size()); } } + + public enum Section implements TranslatableEnum, StringRepresentable { + MAIN("main"), + MAIN_NO_HOTBAR("main_no_hotbar"), + ARMOR("armor"), + OFFHAND("offhand"), + ENDER("ender"); + + private final String name; + + Section(String name) { + this.name = name; + } + + @Override + public String getTranslationKey() { + return "modularrouters.guiText.label.playerSect." + name; + } + + @Override + public String getSerializedName() { + return name; + } + } + + public record PlayerSettings(TransferDirection direction, Section section) { + public static final PlayerSettings DEFAULT = new PlayerSettings(TransferDirection.TO_ROUTER, Section.MAIN); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + StringRepresentable.fromEnum(TransferDirection::values) + .optionalFieldOf("direction", TransferDirection.TO_ROUTER) + .forGetter(PlayerSettings::direction), + StringRepresentable.fromEnum(Section::values) + .optionalFieldOf("section", Section.MAIN) + .forGetter(PlayerSettings::section) + ).apply(builder, PlayerSettings::new)); + + public static StreamCodec STREAM_CODEC = StreamCodec.composite( + NeoForgeStreamCodecs.enumCodec(TransferDirection.class), PlayerSettings::direction, + NeoForgeStreamCodecs.enumCodec(Section.class), PlayerSettings::section, + PlayerSettings::new + ); + } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPullerModule2.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPullerModule2.java index d78c3e0e..e5e745e7 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPullerModule2.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledPullerModule2.java @@ -31,7 +31,7 @@ boolean validateRange(ModularRouterBlockEntity router, ModuleTarget target) { @Override protected void playParticles(ModularRouterBlockEntity router, BlockPos targetPos, ItemStack stack) { if (router.getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()) < 2) { - router.addItemBeam(new BeamData(router.getTickRate(), targetPos, stack, 0x6080FF).reverseItems()); + router.addItemBeam(new BeamData.Builder(router, targetPos, 0x6080FF).reversed(true).withItemStack(stack).build()); } } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledSenderModule1.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledSenderModule1.java index a13dfc65..a08aa76b 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledSenderModule1.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledSenderModule1.java @@ -16,7 +16,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.items.IItemHandler; -import net.neoforged.neoforge.items.ItemHandlerHelper; import javax.annotation.Nonnull; @@ -34,7 +33,7 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { if (positionedItemHandler.isValid()) { int nToSend = getItemsPerTick(router); if (getRegulationAmount() > 0) { - int existing = InventoryUtils.countItems(bufferStack, positionedItemHandler.handler, getRegulationAmount(), !getFilter().getFlags().isIgnoreDamage()); + int existing = InventoryUtils.countItems(bufferStack, positionedItemHandler.handler, getRegulationAmount(), !getFilter().getFlags().matchDamage()); nToSend = Math.min(nToSend, getRegulationAmount() - existing); if (nToSend <= 0) { return false; @@ -43,7 +42,7 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { int sent = InventoryUtils.transferItems(buffer, positionedItemHandler.handler, 0, nToSend); if (sent > 0) { if (ConfigHolder.common.module.senderParticles.get()) { - playParticles(router, positionedItemHandler.pos, ItemHandlerHelper.copyStackWithSize(bufferStack, sent)); + playParticles(router, positionedItemHandler.pos, bufferStack.copyWithCount(sent)); } return true; } else { @@ -56,7 +55,7 @@ public boolean execute(@Nonnull ModularRouterBlockEntity router) { void playParticles(ModularRouterBlockEntity router, BlockPos targetPos, ItemStack stack) { if (router.getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()) < 2) { - router.addItemBeam(new BeamData(router.getTickRate(), targetPos, stack, getBeamColor())); + router.addItemBeam(new BeamData.Builder(router, targetPos, getBeamColor()).withItemStack(stack).build()); } } @@ -85,7 +84,7 @@ public ModuleTarget getEffectiveTarget(ModularRouterBlockEntity router) { } else if (!isPassable(level, pos, face)) { return null; } - pos.move(getFacing()); + pos.move(getAbsoluteFacing()); } return null; } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledSenderModule3.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledSenderModule3.java index b09ff7bb..750da55f 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledSenderModule3.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledSenderModule3.java @@ -5,6 +5,7 @@ import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.logic.ModuleTarget; +import me.desht.modularrouters.logic.settings.RelativeDirection; import me.desht.modularrouters.util.BeamData; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -25,8 +26,12 @@ protected boolean validate(ModularRouterBlockEntity router, ModuleTarget target) @Override protected void playParticles(ModularRouterBlockEntity router, BlockPos targetPos, ItemStack stack) { if (router.getUpgradeCount(ModItems.MUFFLER_UPGRADE.get()) < 2) { - Direction facing = router.getAbsoluteFacing(ModuleItem.RelativeDirection.FRONT); - router.addItemBeam(new BeamData(router.getTickRate(), router.getBlockPos().relative(facing, 1), stack, 0x800080).fadeItems()); + Direction facing = router.getAbsoluteFacing(RelativeDirection.FRONT); + router.addItemBeam(new BeamData.Builder(router, router.getBlockPos().relative(facing, 1), 0x800080) + .fade(true) + .withItemStack(stack) + .build() + ); } } } diff --git a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledVacuumModule.java b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledVacuumModule.java index 6dbaabc7..3817d6ac 100644 --- a/src/main/java/me/desht/modularrouters/logic/compiled/CompiledVacuumModule.java +++ b/src/main/java/me/desht/modularrouters/logic/compiled/CompiledVacuumModule.java @@ -1,21 +1,25 @@ package me.desht.modularrouters.logic.compiled; -import me.desht.modularrouters.ModularRouters; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.config.ConfigHolder; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.core.ModItems; -import me.desht.modularrouters.integration.XPCollection; import me.desht.modularrouters.integration.XPCollection.XPCollectionType; -import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.logic.ModuleTarget; +import me.desht.modularrouters.logic.settings.RelativeDirection; import me.desht.modularrouters.util.InventoryUtils; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.GlobalPos; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.ExperienceOrb; import net.minecraft.world.entity.item.ItemEntity; @@ -28,7 +32,7 @@ import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.capability.IFluidHandler; -import net.neoforged.neoforge.items.ItemHandlerHelper; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -39,9 +43,9 @@ public class CompiledVacuumModule extends CompiledModule { public static final String NBT_XP_FLUID_TYPE = "XPFluidType"; public static final String NBT_AUTO_EJECT = "AutoEject"; + private final VacuumSettings settings; private final boolean fastPickup; private final boolean xpMode; - private final boolean autoEjecting; private final FluidStack xpJuiceStack; private BlockCapabilityCache fluidReceiverCache = null; @@ -50,28 +54,17 @@ public class CompiledVacuumModule extends CompiledModule { // does not survive router recompilation... private int xpBuffered = 0; - // form in which to collect XP orbs - private final XPCollectionType xpCollectionType; - public CompiledVacuumModule(ModularRouterBlockEntity router, ItemStack stack) { super(router, stack); - fastPickup = getAugmentCount(ModItems.FAST_PICKUP_AUGMENT.get()) > 0; - xpMode = getAugmentCount(ModItems.XP_VACUUM_AUGMENT.get()) > 0; - - CompoundTag compound = stack.getTagElement(ModularRouters.MODID); - if (compound != null) { - xpCollectionType = XPCollection.getXPType(compound.getInt(NBT_XP_FLUID_TYPE)); - autoEjecting = compound.getBoolean(NBT_AUTO_EJECT); - - if (xpMode) { - Fluid xpFluid = xpCollectionType.getFluid(); - xpJuiceStack = xpFluid == Fluids.EMPTY ? FluidStack.EMPTY : new FluidStack(xpFluid, 1000); - } else { - xpJuiceStack = FluidStack.EMPTY; - } + + settings = stack.getOrDefault(ModDataComponents.VACUUM_SETTINGS, VacuumSettings.DEFAULT); + fastPickup = getAugmentCount(ModItems.FAST_PICKUP_AUGMENT) > 0; + xpMode = getAugmentCount(ModItems.XP_VACUUM_AUGMENT) > 0; + + if (xpMode) { + Fluid xpFluid = settings.collectionType.getFluid(); + xpJuiceStack = xpFluid == Fluids.EMPTY ? FluidStack.EMPTY : new FluidStack(xpFluid, 1000); } else { - xpCollectionType = XPCollectionType.BOTTLE_O_ENCHANTING; - autoEjecting = false; xpJuiceStack = FluidStack.EMPTY; } } @@ -95,8 +88,8 @@ public List setupTargets(ModularRouterBlockEntity router, ItemStac if (router == null) { return null; } - ModuleItem.RelativeDirection dir = getDirection(); - int offset = dir == ModuleItem.RelativeDirection.NONE ? 0 : getRange() + 1; + RelativeDirection dir = getDirection(); + int offset = dir == RelativeDirection.NONE ? 0 : getRange() + 1; Direction facing = router.getAbsoluteFacing(dir); GlobalPos gPos = MiscUtil.makeGlobalPos(router.nonNullLevel(), router.getBlockPos().relative(facing, offset)); return Collections.singletonList(new ModuleTarget(gPos, facing)); @@ -120,7 +113,7 @@ private boolean handleItemMode(ModularRouterBlockEntity router) { continue; } ItemStack stackOnGround = item.getItem(); - if ((bufferStack.isEmpty() || ItemHandlerHelper.canItemStacksStack(stackOnGround, bufferStack)) && getFilter().test(stackOnGround)) { + if ((bufferStack.isEmpty() || ItemStack.isSameItemSameComponents(stackOnGround, bufferStack)) && getFilter().test(stackOnGround)) { int inRouter = bufferStack.getCount(); int spaceInRouter = getRegulationAmount() > 0 ? Math.min(stackOnGround.getMaxStackSize(), getRegulationAmount()) - inRouter : @@ -149,12 +142,12 @@ private boolean handleXpMode(ModularRouterBlockEntity router) { int spaceForXp; IFluidHandler fluidHandler = null; - if (xpCollectionType.isSolid()) { + if (getXPCollectionType().isSolid()) { ItemStack inRouterStack = router.getBufferItemStack(); - if (!inRouterStack.isEmpty() && !ItemHandlerHelper.canItemStacksStack(inRouterStack, xpCollectionType.getIcon())) { + if (!inRouterStack.isEmpty() && !ItemStack.isSameItemSameComponents(inRouterStack, getXPCollectionType().getIcon())) { return false; } - spaceForXp = (inRouterStack.getMaxStackSize() - inRouterStack.getCount()) * xpCollectionType.getXpRatio(); + spaceForXp = (inRouterStack.getMaxStackSize() - inRouterStack.getCount()) * getXPCollectionType().getXpRatio(); } else { fluidHandler = getFluidReceiver(router); if (fluidHandler == null) { @@ -176,6 +169,8 @@ private boolean handleXpMode(ModularRouterBlockEntity router) { return false; } + XPCollectionType xpCollectionType = getXPCollectionType(); + int initialSpaceForXp = spaceForXp; for (ExperienceOrb orb : orbs) { if (orb.getValue() > spaceForXp) { @@ -185,7 +180,7 @@ private boolean handleXpMode(ModularRouterBlockEntity router) { xpBuffered += orb.getValue(); if (xpBuffered > xpCollectionType.getXpRatio()) { int count = xpBuffered / xpCollectionType.getXpRatio(); - ItemStack stack = ItemHandlerHelper.copyStackWithSize(xpCollectionType.getIcon(), count); + ItemStack stack = xpCollectionType.getIcon().copyWithCount(count); ItemStack excess = router.insertBuffer(stack); xpBuffered -= stack.getCount() * xpCollectionType.getXpRatio(); if (!excess.isEmpty()) { @@ -226,7 +221,7 @@ private boolean doFluidXPFill(ExperienceOrb orb, @Nullable IFluidHandler xpHandl if (xpHandler == null) { return false; } - FluidStack xpStack = new FluidStack(xpJuiceStack.getFluid(), orb.getValue() * xpCollectionType.getXpRatio() + xpBuffered); + FluidStack xpStack = new FluidStack(xpJuiceStack.getFluid(), orb.getValue() * getXPCollectionType().getXpRatio() + xpBuffered); int filled = xpHandler.fill(xpStack, IFluidHandler.FluidAction.EXECUTE); if (filled < xpStack.getAmount()) { // tank is too full to store entire amount... @@ -245,8 +240,8 @@ private int findSpaceForXPFluid(@Nullable IFluidHandler xpHandler) { for (int idx = 0; idx < xpHandler.getTanks(); idx++) { if (xpHandler.isFluidValid(idx, xpJuiceStack)) { FluidStack fluidStack = xpHandler.getFluidInTank(idx); - if (fluidStack.isEmpty() || fluidStack.getFluid() == xpCollectionType.getFluid()) { - space += (xpHandler.getTankCapacity(idx) - fluidStack.getAmount()) / xpCollectionType.getXpRatio(); + if (fluidStack.isEmpty() || fluidStack.getFluid() == getXPCollectionType().getFluid()) { + space += (xpHandler.getTankCapacity(idx) - fluidStack.getAmount()) / getXPCollectionType().getXpRatio(); } } } @@ -255,14 +250,29 @@ private int findSpaceForXPFluid(@Nullable IFluidHandler xpHandler) { } public XPCollectionType getXPCollectionType() { - return xpCollectionType; + return settings.collectionType; } public boolean isAutoEjecting() { - return autoEjecting; + return settings.autoEject; } public boolean isXpMode() { return xpMode; } + + public record VacuumSettings(boolean autoEject, XPCollectionType collectionType) { + public static final VacuumSettings DEFAULT = new VacuumSettings(false, XPCollectionType.BOTTLE_O_ENCHANTING); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + Codec.BOOL.optionalFieldOf("auto_eject", false).forGetter(VacuumSettings::autoEject), + StringRepresentable.fromEnum(XPCollectionType::values).fieldOf("type").forGetter(VacuumSettings::collectionType) + ).apply(builder, VacuumSettings::new)); + + public static StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.BOOL, VacuumSettings::autoEject, + NeoForgeStreamCodecs.enumCodec(XPCollectionType.class), VacuumSettings::collectionType, + VacuumSettings::new + ); + } } diff --git a/src/main/java/me/desht/modularrouters/logic/filter/Filter.java b/src/main/java/me/desht/modularrouters/logic/filter/Filter.java index e9520d52..de47816c 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/Filter.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/Filter.java @@ -1,12 +1,14 @@ package me.desht.modularrouters.logic.filter; import com.google.common.collect.Lists; +import me.desht.modularrouters.ModularRouters; import me.desht.modularrouters.container.handler.BaseModuleHandler.ModuleFilterHandler; +import me.desht.modularrouters.core.ModDataComponents; import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.item.module.ModuleItem.ModuleFlags; import me.desht.modularrouters.item.smartfilter.SmartFilterItem; import me.desht.modularrouters.logic.filter.matchers.IItemMatcher; -import me.desht.modularrouters.util.ModuleHelper; +import me.desht.modularrouters.logic.settings.ModuleFlags; +import me.desht.modularrouters.logic.settings.ModuleSettings; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; import org.apache.commons.lang3.Validate; @@ -19,42 +21,38 @@ public class Filter implements Predicate { public static final int FILTER_SIZE = 9; - private final Flags flags; + private final ModuleFlags flags; private final List matchers = Lists.newArrayList(); private final List rawStacks = Lists.newArrayList(); - private final boolean matchAll; private final boolean roundRobin; private int rrCounter = 0; public Filter() { - flags = Flags.DEFAULT_FLAGS; - matchAll = false; + flags = ModuleFlags.DEFAULT; roundRobin = false; } public Filter(ItemStack moduleStack, boolean storeRaw, boolean roundRobin) { + Validate.isTrue(moduleStack.getItem() instanceof ModuleItem, "item stack is not a module item! " + moduleStack.getItem()); + this.roundRobin = roundRobin; - this.rrCounter = roundRobin ? ModuleHelper.getRoundRobinCounter(moduleStack) : 0; - if (moduleStack.getItem() instanceof ModuleItem && moduleStack.hasTag()) { - flags = new Flags(moduleStack); - matchAll = ModuleHelper.isMatchAll(moduleStack); - ModuleFilterHandler filterHandler = new ModuleFilterHandler(moduleStack, null); - for (int i = 0; i < filterHandler.getSlots(); i++) { - ItemStack filterStack = filterHandler.getStackInSlot(i); - if (!filterStack.isEmpty()) { - IItemMatcher matcher = createMatcher(filterStack, moduleStack); - matchers.add(matcher); - if (storeRaw) { - rawStacks.add(filterStack); - } + this.rrCounter = roundRobin ? ModuleItem.getRoundRobinCounter(moduleStack) : 0; + + flags = ModuleFlags.forItem(moduleStack); + + ModuleFilterHandler filterHandler = new ModuleFilterHandler(moduleStack, null); + for (int i = 0; i < filterHandler.getSlots(); i++) { + ItemStack filterStack = filterHandler.getStackInSlot(i); + if (!filterStack.isEmpty()) { + IItemMatcher matcher = createMatcher(filterStack, moduleStack); + matchers.add(matcher); + if (storeRaw) { + rawStacks.add(filterStack); } } - if (roundRobin && rrCounter >= matchers.size()) { - rrCounter = 0; - } - } else { - flags = Flags.DEFAULT_FLAGS; - matchAll = false; + } + if (roundRobin && rrCounter >= matchers.size()) { + rrCounter = 0; } } @@ -71,13 +69,12 @@ public List getRawStacks() { return rawStacks; } - public boolean isEmpty() { return matchers.isEmpty(); } - public boolean isBlacklist() { - return flags.isBlacklist(); + public boolean isWhiteList() { + return flags.whiteList(); } /** @@ -94,18 +91,20 @@ public boolean test(ItemStack stack) { if (roundRobin && !matchers.isEmpty()) { // just match against a single item in the filter - return matchers.get(rrCounter).matchItem(stack, flags) != flags.isBlacklist(); + return matchers.get(rrCounter).matchItem(stack, flags) == flags.whiteList(); } else { // match against everything in the filter (either match any or match all) + boolean matchAll = flags.matchAllItems(); + for (IItemMatcher matcher : matchers) { boolean matchedOne = matcher.matchItem(stack, flags); if (!matchAll && matchedOne || matchAll && !matchedOne) { - return matchAll == flags.isBlacklist(); + return matchAll != flags.whiteList(); } } // no matches: test succeeds if this is a blacklist, fails if a whitelist - return matchAll != flags.isBlacklist(); + return matchAll == flags.whiteList(); } } @@ -119,53 +118,50 @@ public Optional cycleRoundRobin() { public boolean testFluid(Fluid fluid) { for (IItemMatcher matcher : matchers) { if (matcher.matchFluid(fluid, flags)) { - return !flags.isBlacklist(); + return flags.whiteList(); } } - return flags.isBlacklist(); + return !flags.whiteList(); } - public Flags getFlags() { + public ModuleFlags getFlags() { return flags; } - public static class Flags { - public static final Flags DEFAULT_FLAGS = new Flags(); - - private final boolean blacklist; - private final boolean ignoreDamage; - private final boolean ignoreNBT; - private final boolean ignoreTags; - - public Flags(ItemStack moduleStack) { - Validate.isTrue(moduleStack.getItem() instanceof ModuleItem); - blacklist = ModuleHelper.isBlacklist(moduleStack); - ignoreDamage = ModuleHelper.ignoreDamage(moduleStack); - ignoreNBT = ModuleHelper.ignoreNBT(moduleStack); - ignoreTags = ModuleHelper.ignoreTags(moduleStack); - } - - public Flags() { - blacklist = ModuleFlags.BLACKLIST.getDefaultValue(); - ignoreDamage = ModuleFlags.IGNORE_DAMAGE.getDefaultValue(); - ignoreNBT = ModuleFlags.IGNORE_NBT.getDefaultValue(); - ignoreTags = ModuleFlags.IGNORE_TAGS.getDefaultValue(); - } - - public boolean isBlacklist() { - return blacklist; - } - - public boolean isIgnoreDamage() { - return ignoreDamage; - } - - public boolean isIgnoreNBT() { - return ignoreNBT; - } - - public boolean matchTags() { - return !ignoreTags; - } - } +// public static class Flags { +// public static final Flags DEFAULT_FLAGS = new Flags(); +// +// private final boolean blacklist; +// private final boolean ignoreDamage; +// private final boolean ignoreNBT; +// +// public Flags(ItemStack moduleStack) { +// Validate.isTrue(moduleStack.getItem() instanceof ModuleItem); +// blacklist = ModuleHelper.isBlacklist(moduleStack); +// ignoreDamage = ModuleHelper.ignoreDamage(moduleStack); +// ignoreNBT = ModuleHelper.ignoreNBT(moduleStack); +// } +// +// public Flags() { +// blacklist = ModuleFlags.BLACKLIST.getDefaultValue(); +// ignoreDamage = ModuleFlags.IGNORE_DAMAGE.getDefaultValue(); +// ignoreNBT = ModuleFlags.IGNORE_NBT.getDefaultValue(); +// } +// +// public boolean isBlacklist() { +// return blacklist; +// } +// +// public boolean isIgnoreDamage() { +// return ignoreDamage; +// } +// +// public boolean isIgnoreNBT() { +// return ignoreNBT; +// } +// +// public boolean matchTags() { +// return !ignoreTags; +// } +// } } diff --git a/src/main/java/me/desht/modularrouters/logic/filter/matchers/BulkItemMatcher.java b/src/main/java/me/desht/modularrouters/logic/filter/matchers/BulkItemMatcher.java index c7f8bdc7..6004699a 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/matchers/BulkItemMatcher.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/matchers/BulkItemMatcher.java @@ -1,7 +1,7 @@ package me.desht.modularrouters.logic.filter.matchers; import com.google.common.collect.Sets; -import me.desht.modularrouters.logic.filter.Filter.Flags; +import me.desht.modularrouters.logic.settings.ModuleFlags; import me.desht.modularrouters.util.MiscUtil; import me.desht.modularrouters.util.SetofItemStack; import net.minecraft.tags.TagKey; @@ -14,10 +14,10 @@ public class BulkItemMatcher implements IItemMatcher { private final SetofItemStack stacks; private final Set> tags; - public BulkItemMatcher(SetofItemStack stacks, Flags flags) { + public BulkItemMatcher(SetofItemStack stacks, ModuleFlags flags) { this.stacks = stacks; this.tags = Sets.newHashSet(); - if (flags.matchTags()) { + if (flags.matchItemTags()) { for (ItemStack stack : stacks) { tags.addAll(MiscUtil.itemTags(stack.getItem())); } @@ -25,15 +25,15 @@ public BulkItemMatcher(SetofItemStack stacks, Flags flags) { } @Override - public boolean matchItem(ItemStack stack, Flags flags) { + public boolean matchItem(ItemStack stack, ModuleFlags flags) { if (stacks.contains(stack)) { return true; } else { - return flags.matchTags() && matchTags(stack); + return flags.matchItemTags() && checkForItemTagIntersection(stack); } } - private boolean matchTags(ItemStack stack) { + private boolean checkForItemTagIntersection(ItemStack stack) { return !Sets.intersection(MiscUtil.itemTags(stack.getItem()), tags).isEmpty(); } diff --git a/src/main/java/me/desht/modularrouters/logic/filter/matchers/FluidMatcher.java b/src/main/java/me/desht/modularrouters/logic/filter/matchers/FluidMatcher.java index 60b58987..c1c5c9a5 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/matchers/FluidMatcher.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/matchers/FluidMatcher.java @@ -1,7 +1,7 @@ package me.desht.modularrouters.logic.filter.matchers; import com.google.common.collect.Sets; -import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.ModuleFlags; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; @@ -17,15 +17,15 @@ public FluidMatcher(ItemStack stack) { } @Override - public boolean matchItem(ItemStack stack, Filter.Flags flags) { + public boolean matchItem(ItemStack stack, ModuleFlags flags) { return FluidUtil.getFluidContained(stack) .map(fluidStack -> matchFluid(fluidStack.getFluid(), flags)) .orElse(false); } @Override - public boolean matchFluid(Fluid fluid, Filter.Flags flags) { - return fluid == this.fluid || flags.matchTags() && !Sets.intersection(MiscUtil.fluidTags(fluid), MiscUtil.fluidTags(this.fluid)).isEmpty(); + public boolean matchFluid(Fluid fluid, ModuleFlags flags) { + return fluid == this.fluid || flags.matchItemTags() && !Sets.intersection(MiscUtil.fluidTags(fluid), MiscUtil.fluidTags(this.fluid)).isEmpty(); } } diff --git a/src/main/java/me/desht/modularrouters/logic/filter/matchers/IItemMatcher.java b/src/main/java/me/desht/modularrouters/logic/filter/matchers/IItemMatcher.java index 7db0df75..4ecab2de 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/matchers/IItemMatcher.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/matchers/IItemMatcher.java @@ -1,13 +1,13 @@ package me.desht.modularrouters.logic.filter.matchers; -import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.ModuleFlags; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; public interface IItemMatcher { - boolean matchItem(ItemStack stack, Filter.Flags flags); + boolean matchItem(ItemStack stack, ModuleFlags flags); - default boolean matchFluid(Fluid fluid, Filter.Flags flags) { + default boolean matchFluid(Fluid fluid, ModuleFlags flags) { return false; } } diff --git a/src/main/java/me/desht/modularrouters/logic/filter/matchers/InspectionMatcher.java b/src/main/java/me/desht/modularrouters/logic/filter/matchers/InspectionMatcher.java index 5e2939b2..dc04e9bb 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/matchers/InspectionMatcher.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/matchers/InspectionMatcher.java @@ -1,24 +1,32 @@ package me.desht.modularrouters.logic.filter.matchers; import com.google.common.base.Joiner; -import me.desht.modularrouters.logic.filter.Filter; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import me.desht.modularrouters.logic.settings.ModuleFlags; import me.desht.modularrouters.util.TranslatableEnum; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.ItemEnchantments; import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.fluids.FluidUtil; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; +import static me.desht.modularrouters.client.util.ClientUtil.xlate; + public class InspectionMatcher implements IItemMatcher { private final ComparisonList comparisonList; @@ -27,7 +35,7 @@ public InspectionMatcher(ComparisonList comparisons) { } @Override - public boolean matchItem(ItemStack stack, Filter.Flags flags) { + public boolean matchItem(ItemStack stack, ModuleFlags flags) { int matched = 0; if (comparisonList.items.isEmpty()) { return false; @@ -44,42 +52,62 @@ public boolean matchItem(ItemStack stack, Filter.Flags flags) { return matched >= comparisonList.items.size(); } - public static class ComparisonList { - public final List items; - boolean matchAll; + public record ComparisonList(List items, boolean matchAll) { + public static final ComparisonList DEFAULT = new ComparisonList(List.of(), false); - public ComparisonList(List items, boolean matchAll) { - this.items = items; - this.matchAll = matchAll; - } + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + Comparison.CODEC.listOf().fieldOf("items").forGetter(ComparisonList::items), + Codec.BOOL.fieldOf("match_all").forGetter(ComparisonList::matchAll) + ).apply(builder, ComparisonList::new)); - public void setMatchAll(boolean matchAll) { - this.matchAll = matchAll; - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + Comparison.STREAM_CODEC.apply(ByteBufCodecs.list()), ComparisonList::items, + ByteBufCodecs.BOOL, ComparisonList::matchAll, + ComparisonList::new + ); - public boolean isMatchAll() { - return matchAll; + public List items() { + return Collections.unmodifiableList(items); } - } - public static class Comparison implements Predicate { - static final Comparison BAD_COMPARISON = new Comparison(); + public boolean isEmpty() { + return items.isEmpty(); + } - private final InspectionSubject subject; - private final InspectionOp op; - private final long target; + public ComparisonList setMatchAll(boolean matchAll) { + return new ComparisonList(items(), matchAll); + } - Comparison(InspectionSubject subject, InspectionOp op, int target) { - this.subject = subject; - this.op = op; - this.target = target; + public ComparisonList addComparison(Comparison toAdd) { + List l = new ArrayList<>(items); + l.add(toAdd); + return new ComparisonList(List.copyOf(l), matchAll); } - Comparison() { - subject = null; - op = null; - target = 0; + public ComparisonList removeAt(int pos) { + List l = new ArrayList<>(items); + if (pos >= 0 && pos < l.size()) { + l.remove(pos); + } + return new ComparisonList(List.copyOf(l), matchAll); } + } + + public record Comparison(InspectionSubject subject, InspectionOp op, int target) implements Predicate { + static final Comparison BAD_COMPARISON = new Comparison(null, null, 0); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + InspectionSubject.CODEC.fieldOf("subject").forGetter(Comparison::subject), + InspectionOp.CODEC.fieldOf("op").forGetter(Comparison::op), + Codec.INT.fieldOf("target").forGetter(Comparison::target) + ).apply(builder, Comparison::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + NeoForgeStreamCodecs.enumCodec(InspectionSubject.class), Comparison::subject, + NeoForgeStreamCodecs.enumCodec(InspectionOp.class), Comparison::op, + ByteBufCodecs.INT, Comparison::target, + Comparison::new + ); @Override public boolean test(ItemStack stack) { @@ -87,22 +115,22 @@ public boolean test(ItemStack stack) { return false; } Optional val = subject.evaluator.apply(stack); - return op.test(Long.valueOf(val.orElse(-1)), target); - } - - public static Comparison fromString(String s) { - String[] fields = s.split(" ", 3); - if (fields.length != 3) return BAD_COMPARISON; - try { - InspectionSubject subject = InspectionSubject.valueOf(fields[0]); - InspectionOp op = InspectionOp.valueOf(fields[1]); - int target = Integer.parseInt(fields[2]); - return new Comparison(subject, op, target); - } catch (IllegalArgumentException e) { - return BAD_COMPARISON; - } + return op.test(Long.valueOf(val.orElse(-1)), (long) target); } +// public static Comparison fromString(String s) { +// String[] fields = s.split(" ", 3); +// if (fields.length != 3) return BAD_COMPARISON; +// try { +// InspectionSubject subject = InspectionSubject.valueOf(fields[0]); +// InspectionOp op = InspectionOp.valueOf(fields[1]); +// int target = Integer.parseInt(fields[2]); +// return new Comparison(subject, op, target); +// } catch (IllegalArgumentException e) { +// return BAD_COMPARISON; +// } +// } + @Override public String toString() { return Joiner.on(" ").join(subject, op, target); @@ -110,33 +138,36 @@ public String toString() { public MutableComponent asLocalizedText() { if (subject == null || op == null) return Component.literal(""); - return Component.literal(" ") - .append(Component.translatable("modularrouters.guiText.label.inspectionSubject." + subject)) + return xlate(subject.getTranslationKey()) .append(" ") - .append(Component.translatable("modularrouters.guiText.label.inspectionOp." + op)) + .append(xlate(op.getTranslationKey())) .append(target + subject.suffix); } } - public enum InspectionSubject implements TranslatableEnum { - NONE("", stack -> Optional.empty()), - DURABILITY("%", InspectionSubject::getDurabilityPercent), - FLUID("%", InspectionSubject::getFluidPercent), - ENERGY("%", InspectionSubject::getEnergyPercent), - ENCHANT("", InspectionSubject::getHighestEnchantLevel), - FOOD("", InspectionSubject::getFoodValue); + public enum InspectionSubject implements TranslatableEnum, StringRepresentable { + NONE("none", "", stack -> Optional.empty()), + DURABILITY("durability", "%", InspectionSubject::getDurabilityPercent), + FLUID("fluid", "%", InspectionSubject::getFluidPercent), + ENERGY("energy","%", InspectionSubject::getEnergyPercent), + ENCHANT("enchant", "", InspectionSubject::getHighestEnchantLevel), + FOOD("food","", InspectionSubject::getFoodValue); + + public static final Codec CODEC = StringRepresentable.fromEnum(InspectionSubject::values); + private final String name; private final String suffix; private final Function> evaluator; - InspectionSubject(String suffix, Function> evaluator) { + InspectionSubject(String name, String suffix, Function> evaluator) { + this.name = name; this.suffix = suffix; this.evaluator = evaluator; } @Override public String getTranslationKey() { - return "modularrouters.guiText.label.inspectionSubject." + this; + return "modularrouters.guiText.label.inspectionSubject." + name; } private static Optional getDurabilityPercent(ItemStack stack) { @@ -147,13 +178,15 @@ private static Optional getDurabilityPercent(ItemStack stack) { private static Optional getFoodValue(ItemStack stack) { //noinspection ConstantConditions - return stack.getItem().isEdible() ? - Optional.of(stack.getItem().getFoodProperties(stack, null).getNutrition()) : + return stack.has(DataComponents.FOOD) ? + Optional.of(stack.getFoodProperties(null).nutrition()) : Optional.empty(); } private static Optional getHighestEnchantLevel(ItemStack stack) { - return EnchantmentHelper.getEnchantments(stack).values().stream().max(Comparator.naturalOrder()); + return stack.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).entrySet().stream() + .map(Object2IntMap.Entry::getIntValue) + .max(Comparator.naturalOrder()); } private static Optional getEnergyPercent(ItemStack stack) { @@ -186,9 +219,14 @@ private static int asPercentage(int val, int max) { if (max == 0) return 0; // https://github.com/desht/ModularRouters/issues/82 return (int) (val / (float) max) * 100; } + + @Override + public String getSerializedName() { + return name; + } } - public enum InspectionOp implements TranslatableEnum, BiPredicate { + public enum InspectionOp implements TranslatableEnum, StringRepresentable, BiPredicate { NONE((val, target) -> false), GT((val, target) -> val > target), LT((val, target) -> val < target), @@ -197,6 +235,8 @@ public enum InspectionOp implements TranslatableEnum, BiPredicate { EQ(Objects::equals), NE((val, target) -> !Objects.equals(val, target)); + public static final Codec CODEC = StringRepresentable.fromEnum(InspectionOp::values); + private final BiPredicate predicate; InspectionOp(BiPredicate predicate) { @@ -219,5 +259,10 @@ public InspectionOp cycle(int direction) { else if (n < 0) n = values().length - 1; return values()[n]; } + + @Override + public String getSerializedName() { + return name().toLowerCase(Locale.ROOT); + } } } diff --git a/src/main/java/me/desht/modularrouters/logic/filter/matchers/ModMatcher.java b/src/main/java/me/desht/modularrouters/logic/filter/matchers/ModMatcher.java index ab3accf9..8886ca9f 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/matchers/ModMatcher.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/matchers/ModMatcher.java @@ -1,7 +1,7 @@ package me.desht.modularrouters.logic.filter.matchers; import com.google.common.collect.Sets; -import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.ModuleFlags; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.ItemStack; @@ -16,7 +16,7 @@ public ModMatcher(List mods) { } @Override - public boolean matchItem(ItemStack stack, Filter.Flags flags) { + public boolean matchItem(ItemStack stack, ModuleFlags flags) { return !stack.isEmpty() && modSet.contains(BuiltInRegistries.ITEM.getKey(stack.getItem()).getNamespace()); } } diff --git a/src/main/java/me/desht/modularrouters/logic/filter/matchers/RegexMatcher.java b/src/main/java/me/desht/modularrouters/logic/filter/matchers/RegexMatcher.java index df17a661..eb203670 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/matchers/RegexMatcher.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/matchers/RegexMatcher.java @@ -2,7 +2,7 @@ import com.google.common.collect.Lists; import me.desht.modularrouters.ModularRouters; -import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.ModuleFlags; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.ItemStack; @@ -28,7 +28,7 @@ public RegexMatcher(List regex) { } @Override - public boolean matchItem(ItemStack stack, Filter.Flags flags) { + public boolean matchItem(ItemStack stack, ModuleFlags flags) { if (stack.isEmpty()) return false; String name = BuiltInRegistries.ITEM.getKey(stack.getItem()).getPath(); return patterns.stream().anyMatch(pat -> pat.matcher(name).find()); diff --git a/src/main/java/me/desht/modularrouters/logic/filter/matchers/SimpleItemMatcher.java b/src/main/java/me/desht/modularrouters/logic/filter/matchers/SimpleItemMatcher.java index 751b486b..3af9976a 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/matchers/SimpleItemMatcher.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/matchers/SimpleItemMatcher.java @@ -1,6 +1,6 @@ package me.desht.modularrouters.logic.filter.matchers; -import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.ModuleFlags; import me.desht.modularrouters.util.ItemTagMatcher; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang3.Validate; @@ -15,11 +15,11 @@ public SimpleItemMatcher(ItemStack stack) { } @Override - public boolean matchItem(ItemStack stack, Filter.Flags flags) { + public boolean matchItem(ItemStack stack, ModuleFlags flags) { if (filterStack.getItem() == stack.getItem()) { - return (flags.isIgnoreDamage() || matchDamage(stack, filterStack)) - && (flags.isIgnoreNBT() || ItemStack.isSameItemSameTags(stack, filterStack)); - } else if (flags.matchTags()) { + return (!flags.matchDamage() || matchDamage(stack, filterStack)) + && (!flags.matchComponents() || ItemStack.isSameItemSameComponents(stack, filterStack)); + } else if (flags.matchItemTags()) { return getTagMatcher().match(stack); } else { return false; diff --git a/src/main/java/me/desht/modularrouters/logic/filter/matchers/TagMatcher.java b/src/main/java/me/desht/modularrouters/logic/filter/matchers/TagMatcher.java index c1395b3b..9b0cf149 100644 --- a/src/main/java/me/desht/modularrouters/logic/filter/matchers/TagMatcher.java +++ b/src/main/java/me/desht/modularrouters/logic/filter/matchers/TagMatcher.java @@ -1,6 +1,6 @@ package me.desht.modularrouters.logic.filter.matchers; -import me.desht.modularrouters.logic.filter.Filter; +import me.desht.modularrouters.logic.settings.ModuleFlags; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -15,7 +15,7 @@ public TagMatcher(Collection> tagList) { } @Override - public boolean matchItem(ItemStack stack, Filter.Flags flags) { + public boolean matchItem(ItemStack stack, ModuleFlags flags) { return tagList.stream().anyMatch(stack::is); } } diff --git a/src/main/java/me/desht/modularrouters/logic/settings/ModuleFlags.java b/src/main/java/me/desht/modularrouters/logic/settings/ModuleFlags.java new file mode 100644 index 00000000..228518da --- /dev/null +++ b/src/main/java/me/desht/modularrouters/logic/settings/ModuleFlags.java @@ -0,0 +1,52 @@ +package me.desht.modularrouters.logic.settings; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import io.netty.buffer.ByteBuf; +import me.desht.modularrouters.core.ModDataComponents; +import me.desht.modularrouters.item.module.ModuleItem; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.item.ItemStack; + +public record ModuleFlags(boolean whiteList, boolean matchDamage, boolean matchComponents, boolean matchItemTags, boolean matchAllItems) { + public static final ModuleFlags DEFAULT = new ModuleFlags(false, true, false, false,false); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + Codec.BOOL.optionalFieldOf("white_list", false).forGetter(ModuleFlags::whiteList), + Codec.BOOL.optionalFieldOf("match_damage", false).forGetter(ModuleFlags::matchDamage), + Codec.BOOL.optionalFieldOf("match_components", false).forGetter(ModuleFlags::matchComponents), + Codec.BOOL.optionalFieldOf("match_item_tag", false).forGetter(ModuleFlags::matchItemTags), + Codec.BOOL.optionalFieldOf("match_all", false).forGetter(ModuleFlags::matchAllItems) + ).apply(builder, ModuleFlags::new)); + + public static final StreamCodec STREAM_CODEC = new StreamCodec<>() { + @Override + public ModuleFlags decode(ByteBuf buf) { + byte val = buf.readByte(); + boolean whiteList = (val & 0x01) != 0; + boolean ignoreDamage = (val & 0x02) != 0; + boolean ignoreComp = (val & 0x04) != 0; + boolean ignoreTags = (val & 0x08) != 0; + boolean matchAll = (val & 0x10) != 0; + return new ModuleFlags(whiteList, ignoreDamage, ignoreComp, ignoreTags, matchAll); + } + + @Override + public void encode(ByteBuf buf, ModuleFlags flags) { + byte val = 0; + if (flags.whiteList) val |= 0x01; + if (flags.matchDamage) val |= 0x02; + if (flags.matchComponents) val |= 0x04; + if (flags.matchItemTags) val |= 0x08; + if (flags.matchAllItems) val |= 0x10; + buf.writeByte(val); + } + }; + + public static ModuleFlags forItem(ItemStack stack) { + return stack.getItem() instanceof ModuleItem ? + ModuleItem.getCommonSettings(stack).flags() : + ModuleFlags.DEFAULT; + + } +} diff --git a/src/main/java/me/desht/modularrouters/logic/settings/ModuleSettings.java b/src/main/java/me/desht/modularrouters/logic/settings/ModuleSettings.java new file mode 100644 index 00000000..29ab6445 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/logic/settings/ModuleSettings.java @@ -0,0 +1,51 @@ +package me.desht.modularrouters.logic.settings; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.util.StringRepresentable; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; + +public record ModuleSettings(ModuleFlags flags, RelativeDirection facing, ModuleTermination termination, + RedstoneBehaviour redstoneBehaviour, int regulatorAmount) + implements SyncableSettings +{ + public static final ModuleSettings DEFAULT = new ModuleSettings( + ModuleFlags.DEFAULT, + RelativeDirection.NONE, + ModuleTermination.NONE, + RedstoneBehaviour.ALWAYS, + 0 + ); + + public static final Codec CODEC = RecordCodecBuilder.create(builder -> builder.group( + ModuleFlags.CODEC.fieldOf("flags") + .forGetter(ModuleSettings::flags), + StringRepresentable.fromEnum(RelativeDirection::values).fieldOf("facing") + .forGetter(ModuleSettings::facing), + StringRepresentable.fromEnum(ModuleTermination::values).optionalFieldOf("termination", ModuleTermination.NONE) + .forGetter(ModuleSettings::termination), + StringRepresentable.fromEnum(RedstoneBehaviour::values).optionalFieldOf("redstone", RedstoneBehaviour.ALWAYS) + .forGetter(ModuleSettings::redstoneBehaviour), + ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("regulation", 0) + .forGetter(ModuleSettings::regulatorAmount) + ).apply(builder, ModuleSettings::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ModuleFlags.STREAM_CODEC, ModuleSettings::flags, + NeoForgeStreamCodecs.enumCodec(RelativeDirection.class), ModuleSettings::facing, + NeoForgeStreamCodecs.enumCodec(ModuleTermination.class), ModuleSettings::termination, + NeoForgeStreamCodecs.enumCodec(RedstoneBehaviour.class), ModuleSettings::redstoneBehaviour, + ByteBufCodecs.VAR_INT, ModuleSettings::regulatorAmount, + ModuleSettings::new + ); + + @Override + public StreamCodec streamCodec() { + return STREAM_CODEC; + } + +} diff --git a/src/main/java/me/desht/modularrouters/logic/settings/ModuleTermination.java b/src/main/java/me/desht/modularrouters/logic/settings/ModuleTermination.java new file mode 100644 index 00000000..c22dcf97 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/logic/settings/ModuleTermination.java @@ -0,0 +1,26 @@ +package me.desht.modularrouters.logic.settings; + +import me.desht.modularrouters.util.TranslatableEnum; +import net.minecraft.util.StringRepresentable; + +public enum ModuleTermination implements TranslatableEnum, StringRepresentable { + NONE("none"), + RAN("ran"), + NOT_RAN("not_ran"); + + private final String name; + + ModuleTermination(String name) { + this.name = name; + } + + @Override + public String getTranslationKey() { + return "modularrouters.guiText.tooltip.terminate." + name; + } + + @Override + public String getSerializedName() { + return name; + } +} diff --git a/src/main/java/me/desht/modularrouters/logic/settings/RedstoneBehaviour.java b/src/main/java/me/desht/modularrouters/logic/settings/RedstoneBehaviour.java new file mode 100644 index 00000000..9e3197a6 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/logic/settings/RedstoneBehaviour.java @@ -0,0 +1,46 @@ +package me.desht.modularrouters.logic.settings; + +import me.desht.modularrouters.util.TranslatableEnum; +import net.minecraft.util.StringRepresentable; + +public enum RedstoneBehaviour implements TranslatableEnum, StringRepresentable { + ALWAYS("always"), + LOW("low"), + HIGH("high"), + NEVER("never"), + PULSE("pulse"); + + private final String name; + + RedstoneBehaviour(String name) { + this.name = name; + } + + public static RedstoneBehaviour forValue(String string) { + try { + return RedstoneBehaviour.valueOf(string); + } catch (IllegalArgumentException e) { + return ALWAYS; + } + } + + public boolean shouldRun(boolean powered, boolean pulsed) { + return switch (this) { + case ALWAYS -> true; + case LOW -> !powered; + case HIGH -> powered; + case PULSE -> pulsed; + case NEVER -> false; + }; + } + + @Override + public String getTranslationKey() { + return "modularrouters.guiText.tooltip.redstone." + name; + } + + @Override + public String getSerializedName() { + return name; + } +} diff --git a/src/main/java/me/desht/modularrouters/logic/settings/RelativeDirection.java b/src/main/java/me/desht/modularrouters/logic/settings/RelativeDirection.java new file mode 100644 index 00000000..28beb3d0 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/logic/settings/RelativeDirection.java @@ -0,0 +1,57 @@ +package me.desht.modularrouters.logic.settings; + +import me.desht.modularrouters.util.TranslatableEnum; +import net.minecraft.core.Direction; +import net.minecraft.util.StringRepresentable; + +public enum RelativeDirection implements StringRepresentable, TranslatableEnum { + // Direction relative to the facing of the router this module is installed in + NONE("none", " "), + DOWN("down", "▼"), + UP("up", "▲"), + LEFT("left", "◀"), + RIGHT("right", "▶"), + FRONT("front", "▣"), + BACK("back", "▤"); + + private final String name; + private final String symbol; + + RelativeDirection(String name, String symbol) { + this.name = name; + this.symbol = symbol; + } + + public Direction toAbsolute(Direction current) { + return switch (this) { + case UP -> Direction.UP; + case DOWN -> Direction.DOWN; + case LEFT -> current.getClockWise(); + case BACK -> current.getOpposite(); + case RIGHT -> current.getCounterClockWise(); + default -> current; // including FRONT + }; + } + + public String getSymbol() { + return symbol; + } + + public int getTextureX(boolean toggled) { + return ordinal() * 32 + (toggled ? 16 : 0); + } + + public int getTextureY() { + return 48; + } + + @Override + public String getSerializedName() { + return name; + } + + @Override + public String getTranslationKey() { + return "modularrouters.guiText.tooltip.relative_dir." + name; + } +} diff --git a/src/main/java/me/desht/modularrouters/logic/settings/SyncableSettings.java b/src/main/java/me/desht/modularrouters/logic/settings/SyncableSettings.java new file mode 100644 index 00000000..c74be7e8 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/logic/settings/SyncableSettings.java @@ -0,0 +1,8 @@ +package me.desht.modularrouters.logic.settings; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; + +public interface SyncableSettings { + StreamCodec streamCodec(); +} diff --git a/src/main/java/me/desht/modularrouters/logic/settings/TransferDirection.java b/src/main/java/me/desht/modularrouters/logic/settings/TransferDirection.java new file mode 100644 index 00000000..f8bac7d8 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/logic/settings/TransferDirection.java @@ -0,0 +1,27 @@ +package me.desht.modularrouters.logic.settings; + +import me.desht.modularrouters.util.TranslatableEnum; +import net.minecraft.util.StringRepresentable; + +public enum TransferDirection implements TranslatableEnum, StringRepresentable { + TO_ROUTER("to_router"), + FROM_ROUTER("from_router"); + + private final String name; + + TransferDirection(String name) { + this.name = name; + } + + @Override + public String getTranslationKey() { + return "modularrouters.itemText.transfer_direction." + name; + } + + @Override + public String getSerializedName() { + return name; + } + + public String getSymbol() { return this == FROM_ROUTER ? "⟹" : "⟸"; } +} diff --git a/src/main/java/me/desht/modularrouters/network/ClientPayloadHandler.java b/src/main/java/me/desht/modularrouters/network/ClientPayloadHandler.java deleted file mode 100644 index e4f1d415..00000000 --- a/src/main/java/me/desht/modularrouters/network/ClientPayloadHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.desht.modularrouters.network; - -import me.desht.modularrouters.client.gui.IResyncableGui; -import me.desht.modularrouters.core.ModBlockEntities; -import me.desht.modularrouters.network.messages.GuiSyncMessage; -import me.desht.modularrouters.network.messages.ItemBeamMessage; -import me.desht.modularrouters.network.messages.PushEntityMessage; -import me.desht.modularrouters.network.messages.RouterUpgradesSyncMessage; -import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; -import net.neoforged.neoforge.network.handling.PlayPayloadContext; - -public class ClientPayloadHandler { - public static void handleData(GuiSyncMessage message, PlayPayloadContext context) { - context.workHandler().submitAsync(() -> { - if (Minecraft.getInstance().screen instanceof IResyncableGui syncable) { - syncable.resync(message.newStack()); - } - }); - } - - public static void handleData(ItemBeamMessage message, PlayPayloadContext context) { - context.workHandler().submitAsync(() -> - Minecraft.getInstance().level.getBlockEntity(message.pos(), ModBlockEntities.MODULAR_ROUTER.get()) - .ifPresent(te -> message.beams().forEach(te::addItemBeam))); - } - - public static void handleData(PushEntityMessage message, PlayPayloadContext context) { - context.workHandler().submitAsync(() -> { - Entity entity = Minecraft.getInstance().level.getEntity(message.entityId()); - if (entity != null) { - Vec3 vec = message.vec(); - entity.setDeltaMovement(vec.x, vec.y, vec.z); - entity.horizontalCollision = false; - entity.verticalCollision = false; - if (entity instanceof LivingEntity l) l.setJumping(true); - } - }); - } - - public static void handleData(RouterUpgradesSyncMessage message, PlayPayloadContext context) { - context.workHandler().submitAsync(() -> { - Level level = Minecraft.getInstance().level; - if (level != null && level.isLoaded(message.pos())) { - level.getBlockEntity(message.pos(), ModBlockEntities.MODULAR_ROUTER.get()) - .ifPresent(router -> router.setUpgradesFrom(message.upgradesHandler())); - } - }); - } -} diff --git a/src/main/java/me/desht/modularrouters/network/FilterOp.java b/src/main/java/me/desht/modularrouters/network/FilterOp.java deleted file mode 100644 index 043a9487..00000000 --- a/src/main/java/me/desht/modularrouters/network/FilterOp.java +++ /dev/null @@ -1,5 +0,0 @@ -package me.desht.modularrouters.network; - -public enum FilterOp { - CLEAR_ALL, MERGE, LOAD, ADD_STRING, REMOVE_AT, ANY_ALL_FLAG -} diff --git a/src/main/java/me/desht/modularrouters/network/NetworkHandler.java b/src/main/java/me/desht/modularrouters/network/NetworkHandler.java index 58932aa8..a3c1bda3 100644 --- a/src/main/java/me/desht/modularrouters/network/NetworkHandler.java +++ b/src/main/java/me/desht/modularrouters/network/NetworkHandler.java @@ -1,66 +1,39 @@ package me.desht.modularrouters.network; import me.desht.modularrouters.ModularRouters; -import me.desht.modularrouters.core.ModBlockEntities; import me.desht.modularrouters.network.messages.*; -import net.minecraft.world.level.Level; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; -import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; -import net.neoforged.neoforge.network.handling.PlayPayloadContext; -import net.neoforged.neoforge.network.registration.IPayloadRegistrar; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; -@Mod.EventBusSubscriber(modid = ModularRouters.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) +@EventBusSubscriber(modid = ModularRouters.MODID, bus = EventBusSubscriber.Bus.MOD) public class NetworkHandler { private static final String NETWORK_VERSION = "1.0"; @SuppressWarnings("Convert2MethodRef") @SubscribeEvent - public static void register(final RegisterPayloadHandlerEvent event) { - final IPayloadRegistrar registrar = event.registrar(ModularRouters.MODID) + public static void register(final RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar(ModularRouters.MODID) .versioned(NETWORK_VERSION); // clientbound - registrar.play(GuiSyncMessage.ID, GuiSyncMessage::new, handler -> handler - .client((message, context) -> ClientPayloadHandler.handleData(message, context))); - registrar.play(ItemBeamMessage.ID, ItemBeamMessage::fromNetwork, handler -> handler - .client((message, context) -> ClientPayloadHandler.handleData(message, context))); - registrar.play(PushEntityMessage.ID, PushEntityMessage::new, handler -> handler - .client((message, context) -> ClientPayloadHandler.handleData(message, context))); - registrar.play(RouterUpgradesSyncMessage.ID, RouterUpgradesSyncMessage::new, handler -> handler - .client((message, context) -> ClientPayloadHandler.handleData(message, context))); + registrar.playToClient(GuiSyncMessage.TYPE, GuiSyncMessage.STREAM_CODEC, GuiSyncMessage::handleData); + registrar.playToClient(ItemBeamMessage.TYPE, ItemBeamMessage.STREAM_CODEC, ItemBeamMessage::handleData); + registrar.playToClient(PushEntityMessage.TYPE, PushEntityMessage.STREAM_CODEC, PushEntityMessage::handleData); + registrar.playToClient(RouterUpgradesSyncMessage.TYPE, RouterUpgradesSyncMessage.STREAM_CODEC, RouterUpgradesSyncMessage::handleData); // serverbound - registrar.play(FilterSettingsMessage.ID, FilterSettingsMessage::new, handler -> handler - .server((message, context) -> ServerPayloadHandler.handleData(message, context))); - registrar.play(ModuleFilterMessage.ID, ModuleFilterMessage::new, handler -> handler - .server((message, context) -> ServerPayloadHandler.handleData(message, context))); - registrar.play(ModuleSettingsMessage.ID, ModuleSettingsMessage::new, handler -> handler - .server((message, context) -> ServerPayloadHandler.handleData(message, context))); - registrar.play(OpenGuiMessage.ID, OpenGuiMessage::new, handler -> handler - .server((message, context) -> ServerPayloadHandler.handleData(message, context))); - registrar.play(SyncUpgradeSettingsMessage.ID, SyncUpgradeSettingsMessage::new, handler -> handler - .server((message, context) -> ServerPayloadHandler.handleData(message, context))); - registrar.play(ValidateModuleMessage.ID, ValidateModuleMessage::new, handler -> handler - .server((message, context) -> ServerPayloadHandler.handleData(message, context))); + registrar.playToServer(FilterUpdateMessage.TYPE, FilterUpdateMessage.STREAM_CODEC, FilterUpdateMessage::handleData); + registrar.playToServer(BulkFilterUpdateMessage.TYPE, BulkFilterUpdateMessage.STREAM_CODEC, BulkFilterUpdateMessage::handleData); + registrar.playToServer(ModuleFilterMessage.TYPE, ModuleFilterMessage.STREAM_CODEC, ModuleFilterMessage::handleData); + registrar.playToServer(ModuleSettingsMessage.TYPE, ModuleSettingsMessage.STREAM_CODEC, ModuleSettingsMessage::handleData); + registrar.playToServer(OpenGuiMessage.TYPE, OpenGuiMessage.STREAM_CODEC, OpenGuiMessage::handleData); + registrar.playToServer(SyncUpgradeSettingsMessage.TYPE, SyncUpgradeSettingsMessage.STREAM_CODEC, SyncUpgradeSettingsMessage::handleData); + registrar.playToServer(ValidateModuleMessage.TYPE, ValidateModuleMessage.STREAM_CODEC, ValidateModuleMessage::handleData); // bidirectional - registrar.play(RouterSettingsMessage.ID, RouterSettingsMessage::new, handler -> handler - .server(NetworkHandler::handleData) - .client(NetworkHandler::handleData) - ); + registrar.playBidirectional(RouterSettingsMessage.TYPE, RouterSettingsMessage.STREAM_CODEC, RouterSettingsMessage::handleData); } - public static void handleData(RouterSettingsMessage message, PlayPayloadContext context) { - context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { - Level level = player.level(); - if (level.isLoaded(message.pos())) { - level.getBlockEntity(message.pos(), ModBlockEntities.MODULAR_ROUTER.get()).ifPresent(router -> { - router.setRedstoneBehaviour(message.redstoneBehaviour()); - router.setEcoMode(message.ecoMode()); - router.setEnergyDirection(message.energyDirection()); - }); - } - })); - } } diff --git a/src/main/java/me/desht/modularrouters/network/OpenGuiOp.java b/src/main/java/me/desht/modularrouters/network/OpenGuiOp.java deleted file mode 100644 index 8ce921b9..00000000 --- a/src/main/java/me/desht/modularrouters/network/OpenGuiOp.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.desht.modularrouters.network; - -public enum OpenGuiOp { - ROUTER, - MODULE_HELD, - MODULE_INSTALLED, - FILTER_HELD, - FILTER_INSTALLED -} diff --git a/src/main/java/me/desht/modularrouters/network/ServerPayloadHandler.java b/src/main/java/me/desht/modularrouters/network/ServerPayloadHandler.java deleted file mode 100644 index 67d391f6..00000000 --- a/src/main/java/me/desht/modularrouters/network/ServerPayloadHandler.java +++ /dev/null @@ -1,135 +0,0 @@ -package me.desht.modularrouters.network; - -import me.desht.modularrouters.ModularRouters; -import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; -import me.desht.modularrouters.container.BulkItemFilterMenu; -import me.desht.modularrouters.container.FilterSlot; -import me.desht.modularrouters.container.ModuleMenu; -import me.desht.modularrouters.container.handler.BaseModuleHandler; -import me.desht.modularrouters.core.ModBlockEntities; -import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.item.smartfilter.SmartFilterItem; -import me.desht.modularrouters.item.upgrade.SyncUpgrade; -import me.desht.modularrouters.network.messages.*; -import me.desht.modularrouters.util.MFLocator; -import me.desht.modularrouters.util.ModuleHelper; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.network.PacketDistributor; -import net.neoforged.neoforge.network.handling.PlayPayloadContext; - -import java.util.Objects; - -public class ServerPayloadHandler { - public static void handleData(FilterSettingsMessage message, PlayPayloadContext context) { - context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { - MFLocator locator = message.locator(); - ItemStack moduleStack = locator.getModuleStack(player); - ItemStack filterStack = locator.getTargetItem(player); - if (filterStack.getItem() instanceof SmartFilterItem sf) { - context.workHandler().submitAsync(() -> { - GuiSyncMessage response = sf.onReceiveSettingsMessage(player, message, filterStack, moduleStack); - if (!moduleStack.isEmpty()) { - ModularRouterBlockEntity router = locator.getRouter(player.level()).orElse(null); - BaseModuleHandler.ModuleFilterHandler filterHandler = new BaseModuleHandler.ModuleFilterHandler(moduleStack, router); - filterHandler.setStackInSlot(locator.filterSlot(), filterStack); - filterHandler.save(); - if (locator.hand() != null) { - player.setItemInHand(locator.hand(), filterHandler.getHolderStack()); - } else if (router != null) { - router.recompileNeeded(ModularRouterBlockEntity.COMPILE_MODULES); - } - } - if (response != null) { - // send to any nearby players in case they also have the GUI open - PacketDistributor.TargetPoint tp = new PacketDistributor.TargetPoint(player.getX(), player.getY(), player.getZ(), - 64, player.getCommandSenderWorld().dimension()); - PacketDistributor.NEAR.with(tp).send(response); - } - - }); - } - })); - } - - public static void handleData(ModuleFilterMessage message, PlayPayloadContext context) { - context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { - AbstractContainerMenu c = player.containerMenu; - int slot = message.slot(); - if (isValidContainer(c) && slot >= 0 && slot < c.slots.size() && c.getSlot(slot) instanceof FilterSlot) { - c.getSlot(slot).set(message.stack()); - } - })); - } - - private static boolean isValidContainer(AbstractContainerMenu c) { - return c instanceof ModuleMenu || c instanceof BulkItemFilterMenu; - } - - public static void handleData(ModuleSettingsMessage message, PlayPayloadContext context) { - context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { - MFLocator locator = message.locator(); - CompoundTag payload = message.payload(); - ItemStack moduleStack = locator.getModuleStack(player); - - if (moduleStack.getItem() instanceof ModuleItem) { - CompoundTag compound = ModuleHelper.validateNBTForWriting(moduleStack); - for (String key : payload.getAllKeys()) { - compound.put(key, Objects.requireNonNull(payload.get(key))); - } - if (locator.routerPos() != null) { - player.getCommandSenderWorld().getBlockEntity(locator.routerPos(), ModBlockEntities.MODULAR_ROUTER.get()) - .ifPresent(router -> router.recompileNeeded(ModularRouterBlockEntity.COMPILE_MODULES)); - } - } else { - ModularRouters.LOGGER.warn("ignoring ModuleSettingsMessage for " + player.getGameProfile().getName() + " - expected module not found @ " + locator); - } - })); - } - - public static void handleData(OpenGuiMessage message, PlayPayloadContext context) { - context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { - MFLocator locator = message.locator(); - switch (message.op()) { - case ROUTER -> - // item router GUI - locator.getRouter(player.getCommandSenderWorld()) - .ifPresent(router -> player.openMenu(router, locator.routerPos())); - case MODULE_HELD -> - // module held in player's hand - player.openMenu(new ModuleItem.ModuleMenuProvider(player, locator), locator::writeBuf); - case MODULE_INSTALLED -> - // module installed in a router - locator.getRouter(player.getCommandSenderWorld()) - .ifPresent(router -> player.openMenu(new ModuleItem.ModuleMenuProvider(player, locator), locator::writeBuf)); - case FILTER_HELD -> - // filter is in a module in player's hand - player.openMenu(new SmartFilterItem.FilterMenuProvider(player, locator), locator::writeBuf); - case FILTER_INSTALLED -> - // filter is in a module in a router - locator.getRouter(player.getCommandSenderWorld()) - .ifPresent(router -> player.openMenu(new SmartFilterItem.FilterMenuProvider(player, locator), locator::writeBuf)); - } - })); - } - - public static void handleData(SyncUpgradeSettingsMessage message, PlayPayloadContext context) { - context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { - ItemStack held = player.getItemInHand(message.hand()); - if (held.getItem() instanceof SyncUpgrade) { - SyncUpgrade.setTunedValue(held, message.tunedValue()); - } - })); - } - - public static void handleData(ValidateModuleMessage message, PlayPayloadContext context) { - context.player().ifPresent(player -> context.workHandler().submitAsync(() -> { - ItemStack stack = player.getItemInHand(message.hand()); - if (stack.getItem() instanceof ModuleItem moduleItem && player instanceof ServerPlayer sp) { - moduleItem.doModuleValidation(stack, sp); - } - })); - } -} diff --git a/src/main/java/me/desht/modularrouters/network/messages/BulkFilterUpdateMessage.java b/src/main/java/me/desht/modularrouters/network/messages/BulkFilterUpdateMessage.java new file mode 100644 index 00000000..cb48c206 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/network/messages/BulkFilterUpdateMessage.java @@ -0,0 +1,85 @@ +package me.desht.modularrouters.network.messages; + +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity.RecompileFlag; +import me.desht.modularrouters.container.handler.BaseModuleHandler; +import me.desht.modularrouters.item.smartfilter.BulkItemFilter; +import me.desht.modularrouters.logic.ModuleTarget; +import me.desht.modularrouters.util.MFLocator; +import me.desht.modularrouters.util.MiscUtil; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; +import net.neoforged.neoforge.network.handling.IPayloadContext; + +import java.util.Optional; + +/** + * Received on: SERVER + *

+ * Sent when a bulk filter clear/load/merge button is pressed to modify its contents server-side + * The filter could be in a player's hand, or in a module (which may or may not be in a router...) + */ +public record BulkFilterUpdateMessage(FilterOp op, MFLocator locator, Optional targetInv) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(MiscUtil.RL("filter_settings")); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + NeoForgeStreamCodecs.enumCodec(FilterOp.class), BulkFilterUpdateMessage::op, + MFLocator.STREAM_CODEC, BulkFilterUpdateMessage::locator, + ModuleTarget.STREAM_CODEC.apply(ByteBufCodecs::optional), BulkFilterUpdateMessage::targetInv, + BulkFilterUpdateMessage::new + ); + + public static BulkFilterUpdateMessage targeted(FilterOp op, MFLocator locator, ModuleTarget target) { + return new BulkFilterUpdateMessage(op, locator, Optional.of(target)); + } + + public static BulkFilterUpdateMessage untargeted(FilterOp op, MFLocator locator) { + return new BulkFilterUpdateMessage(op, locator, Optional.empty()); + } + + @Override + public Type type() { + return TYPE; + } + + public Optional getTargetInventory() { + return targetInv.flatMap(ModuleTarget::getItemHandler); + } + + public static void handleData(BulkFilterUpdateMessage message, IPayloadContext context) { + ServerPlayer player = (ServerPlayer) context.player(); + MFLocator locator = message.locator(); + ItemStack moduleStack = locator.getModuleStack(player); + ItemStack filterStack = locator.getTargetItem(player); + if (filterStack.getItem() instanceof BulkItemFilter bulkFilter) { + GuiSyncMessage response = bulkFilter.onReceiveSettingsMessage(player, message, moduleStack); + if (!moduleStack.isEmpty()) { + ModularRouterBlockEntity router = locator.getRouter(player.level()).orElse(null); + BaseModuleHandler.ModuleFilterHandler filterHandler = new BaseModuleHandler.ModuleFilterHandler(moduleStack, router); + filterHandler.setStackInSlot(locator.filterSlot(), filterStack); + filterHandler.save(); + if (locator.hand() != null) { + player.setItemInHand(locator.hand(), filterHandler.getHolderStack()); + } else if (router != null) { + router.recompileNeeded(RecompileFlag.MODULES); + } + } + if (response != null) { + // send to any nearby players in case they also have the GUI open + PacketDistributor.sendToPlayersTrackingChunk((ServerLevel) player.level(), player.chunkPosition(), response); + } + } + } + + public enum FilterOp { + CLEAR_ALL, MERGE, LOAD + } +} diff --git a/src/main/java/me/desht/modularrouters/network/messages/FilterSettingsMessage.java b/src/main/java/me/desht/modularrouters/network/messages/FilterSettingsMessage.java deleted file mode 100644 index e6e2b9cb..00000000 --- a/src/main/java/me/desht/modularrouters/network/messages/FilterSettingsMessage.java +++ /dev/null @@ -1,44 +0,0 @@ -package me.desht.modularrouters.network.messages; - -import me.desht.modularrouters.logic.ModuleTarget; -import me.desht.modularrouters.network.FilterOp; -import me.desht.modularrouters.util.MFLocator; -import me.desht.modularrouters.util.MiscUtil; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; -import net.neoforged.neoforge.items.IItemHandler; - -import java.util.Optional; - -/** - * Received on: SERVER - *

- * Sent when a filter's settings have been changed in any way via its GUI. - * The filter could be in a player's hand, or in a module (which may or may not be in a router...) - */ -public record FilterSettingsMessage(FilterOp op, MFLocator locator, CompoundTag payload) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("filter_settings"); - - public FilterSettingsMessage(FriendlyByteBuf buf) { - this(buf.readEnum(FilterOp.class), MFLocator.fromBuffer(buf), buf.readNbt()); - } - - @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeEnum(op); - locator.writeBuf(buffer); - buffer.writeNbt(payload); - } - - @Override - public ResourceLocation id() { - return ID; - } - - public Optional getTargetInventory() { - return ModuleTarget.fromNBT(payload).getItemHandler(); - } - -} diff --git a/src/main/java/me/desht/modularrouters/network/messages/FilterUpdateMessage.java b/src/main/java/me/desht/modularrouters/network/messages/FilterUpdateMessage.java new file mode 100644 index 00000000..6af8f196 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/network/messages/FilterUpdateMessage.java @@ -0,0 +1,44 @@ +package me.desht.modularrouters.network.messages; + +import me.desht.modularrouters.item.smartfilter.SmartFilterItem; +import me.desht.modularrouters.util.MFLocator; +import me.desht.modularrouters.util.MiscUtil; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.network.handling.IPayloadContext; + +/** + * Received on: SERVER + *

+ * Sent by client when most filters (not the bulk filter) are updated client-side + * The filter could be in a player's hand, or in a module (which may or may not be in a router...) + */ +public record FilterUpdateMessage(MFLocator locator, ItemStack newFilterStack) implements CustomPacketPayload { + public static final CustomPacketPayload.Type TYPE = new CustomPacketPayload.Type<>(MiscUtil.RL("filter_update")); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + MFLocator.STREAM_CODEC, FilterUpdateMessage::locator, + ItemStack.STREAM_CODEC, FilterUpdateMessage::newFilterStack, + FilterUpdateMessage::new + ); + + @Override + public Type type() { + return TYPE; + } + + public static void handleData(FilterUpdateMessage message, IPayloadContext context) { + ServerPlayer player = (ServerPlayer) context.player(); + MFLocator locator = message.locator(); + ItemStack filterStack = locator.getTargetItem(player); + + if (filterStack.getItem() instanceof SmartFilterItem && filterStack.getItem() == message.newFilterStack.getItem()) { + locator.setFilterStack(player, message.newFilterStack); + PacketDistributor.sendToPlayer(player, new GuiSyncMessage(message.newFilterStack)); + } + } +} diff --git a/src/main/java/me/desht/modularrouters/network/messages/GuiSyncMessage.java b/src/main/java/me/desht/modularrouters/network/messages/GuiSyncMessage.java index fc97e5b0..7ea77c0b 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/GuiSyncMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/GuiSyncMessage.java @@ -1,10 +1,15 @@ package me.desht.modularrouters.network.messages; +import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: CLIENT @@ -12,19 +17,19 @@ * Sent when a filter is changed server-side which requires an open GUI to re-read its settings. */ public record GuiSyncMessage(ItemStack newStack) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("gui_sync"); + public static final Type TYPE = new Type<>(MiscUtil.RL("gui_sync")); - public GuiSyncMessage(FriendlyByteBuf buf) { - this(buf.readItem()); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ItemStack.STREAM_CODEC, GuiSyncMessage::newStack, + GuiSyncMessage::new + ); - @Override - public void write(FriendlyByteBuf friendlyByteBuf) { - friendlyByteBuf.writeItem(newStack); + public static void handleData(GuiSyncMessage message, IPayloadContext context) { + ClientUtil.resyncGui(message.newStack()); } @Override - public ResourceLocation id() { - return ID; + public Type type() { + return TYPE; } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/ItemBeamMessage.java b/src/main/java/me/desht/modularrouters/network/messages/ItemBeamMessage.java index e523b4c1..fcaab9c3 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/ItemBeamMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/ItemBeamMessage.java @@ -1,13 +1,16 @@ package me.desht.modularrouters.network.messages; -import com.google.common.collect.ImmutableList; +import me.desht.modularrouters.client.util.ClientUtil; +import me.desht.modularrouters.core.ModBlockEntities; import me.desht.modularrouters.util.BeamData; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.entity.BlockEntity; +import net.neoforged.neoforge.network.handling.IPayloadContext; import java.util.List; @@ -17,37 +20,52 @@ * Sent by server to play an item beam between a router and another inventory */ public record ItemBeamMessage(BlockPos pos, List beams) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("item_beam"); - - /** - * Create a new beam message - * @param te the tile entity responsible for the rendering - * @param beams the beams(s) to send - */ - public ItemBeamMessage(BlockEntity te, List beams) { - this(te.getBlockPos(), List.copyOf(beams)); - } + public static final Type TYPE = new Type<>(MiscUtil.RL("item_beam")); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + BlockPos.STREAM_CODEC, ItemBeamMessage::pos, + BeamData.STREAM_CODEC.apply(ByteBufCodecs.list()), ItemBeamMessage::beams, + ItemBeamMessage::new + ); - public static ItemBeamMessage fromNetwork(FriendlyByteBuf buf) { - BlockPos pos = buf.readBlockPos(); - ImmutableList.Builder builder = ImmutableList.builder(); - int n = buf.readVarInt(); - for (int i = 0; i < n; i++) { - builder.add(new BeamData(buf, pos)); - } - List beams = builder.build(); - return new ItemBeamMessage(pos, beams); + public static ItemBeamMessage create(BlockEntity te, List beams) { + return new ItemBeamMessage(te.getBlockPos(), List.copyOf(beams)); } - @Override - public void write(FriendlyByteBuf buf) { - buf.writeBlockPos(pos); - buf.writeVarInt(beams.size()); - beams.forEach(beam -> beam.toBytes(buf, pos)); + public static void handleData(ItemBeamMessage message, IPayloadContext context) { + ClientUtil.theClientLevel().getBlockEntity(message.pos(), ModBlockEntities.MODULAR_ROUTER.get()) + .ifPresent(te -> message.beams().forEach(te::addItemBeam)); } +// /** +// * Create a new beam message +// * @param te the tile entity responsible for the rendering +// * @param beams the beams(s) to send +// */ +// public ItemBeamMessage(BlockEntity te, List beams) { +// this(te.getBlockPos(), List.copyOf(beams)); +// } +// +// public static ItemBeamMessage fromNetwork(FriendlyByteBuf buf) { +// BlockPos pos = buf.readBlockPos(); +// ImmutableList.Builder builder = ImmutableList.builder(); +// int n = buf.readVarInt(); +// for (int i = 0; i < n; i++) { +// builder.add(new BeamData(buf, pos)); +// } +// List beams = builder.build(); +// return new ItemBeamMessage(pos, beams); +// } +// +// @Override +// public void write(FriendlyByteBuf buf) { +// buf.writeBlockPos(pos); +// buf.writeVarInt(beams.size()); +// beams.forEach(beam -> beam.toBytes(buf, pos)); +// } + @Override - public ResourceLocation id() { - return ID; + public Type type() { + return TYPE; } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/ModuleFilterMessage.java b/src/main/java/me/desht/modularrouters/network/messages/ModuleFilterMessage.java index d7649694..edfefe58 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/ModuleFilterMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/ModuleFilterMessage.java @@ -1,10 +1,16 @@ package me.desht.modularrouters.network.messages; +import me.desht.modularrouters.container.BulkItemFilterMenu; +import me.desht.modularrouters.container.FilterSlot; +import me.desht.modularrouters.container.ModuleMenu; import me.desht.modularrouters.util.MiscUtil; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: SERVER @@ -12,20 +18,28 @@ * Sent by client when a filter slot is updated via the JEI ghost handler */ public record ModuleFilterMessage(int slot, ItemStack stack) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("module_filter"); + public static final Type TYPE = new Type<>(MiscUtil.RL("module_filter")); - public ModuleFilterMessage(FriendlyByteBuf buffer) { - this(buffer.readVarInt(), buffer.readItem()); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.VAR_INT, ModuleFilterMessage::slot, + ItemStack.STREAM_CODEC, ModuleFilterMessage::stack, + ModuleFilterMessage::new + ); @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeVarInt(slot); - buffer.writeItem(stack); + public Type type() { + return TYPE; } - @Override - public ResourceLocation id() { - return ID; + public static void handleData(ModuleFilterMessage message, IPayloadContext context) { + AbstractContainerMenu c = context.player().containerMenu; + int slot = message.slot(); + if (isValidContainer(c) && slot >= 0 && slot < c.slots.size() && c.getSlot(slot) instanceof FilterSlot) { + c.getSlot(slot).set(message.stack()); + } + } + + private static boolean isValidContainer(AbstractContainerMenu c) { + return c instanceof ModuleMenu || c instanceof BulkItemFilterMenu; } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/ModuleSettingsMessage.java b/src/main/java/me/desht/modularrouters/network/messages/ModuleSettingsMessage.java index 3d22a45c..afbfe2be 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/ModuleSettingsMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/ModuleSettingsMessage.java @@ -1,32 +1,51 @@ package me.desht.modularrouters.network.messages; +import me.desht.modularrouters.ModularRouters; +import me.desht.modularrouters.container.ModuleMenu; +import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.util.MFLocator; import me.desht.modularrouters.util.MiscUtil; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: SERVER *

* Sent by client when a player updates a module's settings via its GUI. */ -public record ModuleSettingsMessage(MFLocator locator, CompoundTag payload) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("module_settings"); +public record ModuleSettingsMessage(MFLocator locator, ItemStack newStack) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(MiscUtil.RL("module_settings")); - public ModuleSettingsMessage(FriendlyByteBuf buf) { - this(MFLocator.fromBuffer(buf), buf.readNbt()); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + MFLocator.STREAM_CODEC, ModuleSettingsMessage::locator, + ItemStack.STREAM_CODEC, ModuleSettingsMessage::newStack, + ModuleSettingsMessage::new + ); @Override - public void write(FriendlyByteBuf buffer) { - locator.writeBuf(buffer); - buffer.writeNbt(payload); + public Type type() { + return TYPE; } - @Override - public ResourceLocation id() { - return ID; + public static void handleData(ModuleSettingsMessage message, IPayloadContext context) { + Player player = context.player(); + if (!(player.containerMenu instanceof ModuleMenu)) { + ModularRouters.LOGGER.warn("ignoring ModuleSettingsMessage for {} - player does not have a module GUI open", player.getGameProfile().getName()); + return; + } + + MFLocator locator = message.locator(); + ItemStack newStack = message.newStack(); + ItemStack moduleStack = locator.getModuleStack(player); + + if (moduleStack.getItem() instanceof ModuleItem && newStack.getItem() == moduleStack.getItem()) { + locator.setModuleStack(player, newStack); + } else { + ModularRouters.LOGGER.warn("ignoring ModuleSettingsMessage for {} - expected module not found @ {}", player.getGameProfile().getName(), locator); + } } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/OpenGuiMessage.java b/src/main/java/me/desht/modularrouters/network/messages/OpenGuiMessage.java index 9f16fc93..762e6bd1 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/OpenGuiMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/OpenGuiMessage.java @@ -1,11 +1,15 @@ package me.desht.modularrouters.network.messages; -import me.desht.modularrouters.network.OpenGuiOp; +import me.desht.modularrouters.item.module.ModuleItem; +import me.desht.modularrouters.item.smartfilter.SmartFilterItem; import me.desht.modularrouters.util.MFLocator; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: SERVER @@ -17,22 +21,13 @@ * 4) Open installed filter GUI (only if it is container-based) */ public record OpenGuiMessage(OpenGuiOp op, MFLocator locator) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("open_gui"); + public static final Type TYPE = new Type<>(MiscUtil.RL("open_gui")); - public OpenGuiMessage(FriendlyByteBuf buf) { - this(buf.readEnum(OpenGuiOp.class), MFLocator.fromBuffer(buf)); - } - - @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeEnum(op); - locator.writeBuf(buffer); - } - - @Override - public ResourceLocation id() { - return ID; - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + NeoForgeStreamCodecs.enumCodec(OpenGuiOp.class), OpenGuiMessage::op, + MFLocator.STREAM_CODEC, OpenGuiMessage::locator, + OpenGuiMessage::new + ); public static OpenGuiMessage openRouter(MFLocator locator) { return new OpenGuiMessage(OpenGuiOp.ROUTER, locator); @@ -53,4 +48,42 @@ public static OpenGuiMessage openFilterInHeldModule(MFLocator locator) { public static OpenGuiMessage openFilterInInstalledModule(MFLocator locator) { return new OpenGuiMessage(OpenGuiOp.FILTER_INSTALLED, locator); } + + @Override + public Type type() { + return TYPE; + } + + public static void handleData(OpenGuiMessage message, IPayloadContext context) { + ServerPlayer player = (ServerPlayer) context.player(); + MFLocator locator = message.locator(); + switch (message.op()) { + case ROUTER -> + // item router GUI + locator.getRouter(player.getCommandSenderWorld()) + .ifPresent(router -> player.openMenu(router, locator.routerPos())); + case MODULE_HELD -> + // module held in player's hand + player.openMenu(new ModuleItem.ModuleMenuProvider(player, locator), locator::writeBuf); + case MODULE_INSTALLED -> + // module installed in a router + locator.getRouter(player.getCommandSenderWorld()) + .ifPresent(router -> player.openMenu(new ModuleItem.ModuleMenuProvider(player, locator), locator::writeBuf)); + case FILTER_HELD -> + // filter is in a module in player's hand + player.openMenu(new SmartFilterItem.FilterMenuProvider(player, locator), locator::writeBuf); + case FILTER_INSTALLED -> + // filter is in a module in a router + locator.getRouter(player.getCommandSenderWorld()) + .ifPresent(router -> player.openMenu(new SmartFilterItem.FilterMenuProvider(player, locator), locator::writeBuf)); + } + } + + public enum OpenGuiOp { + ROUTER, + MODULE_HELD, + MODULE_INSTALLED, + FILTER_HELD, + FILTER_INSTALLED + } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/PushEntityMessage.java b/src/main/java/me/desht/modularrouters/network/messages/PushEntityMessage.java index 4631b81b..e6f53c90 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/PushEntityMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/PushEntityMessage.java @@ -1,11 +1,16 @@ package me.desht.modularrouters.network.messages; +import me.desht.modularrouters.client.util.ClientUtil; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.phys.Vec3; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: CLIENT @@ -13,24 +18,31 @@ * Sent by server so clients promptly update an entity's velocity when it gets shoved by an extruded block. */ public record PushEntityMessage(int entityId, Vec3 vec) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("push_entity"); + public static final Type TYPE = new Type<>(MiscUtil.RL("push_entity")); - public PushEntityMessage(Entity entity, Vec3 vec) { - this(entity.getId(), vec); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.INT, PushEntityMessage::entityId, + ByteBufCodecs.fromCodec(Vec3.CODEC), PushEntityMessage::vec, + PushEntityMessage::new + ); - public PushEntityMessage(FriendlyByteBuf buf) { - this(buf.readInt(), buf.readVec3()); + public static PushEntityMessage forEntity(Entity entity, Vec3 vec) { + return new PushEntityMessage(entity.getId(), vec); } @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeInt(entityId); - buffer.writeVec3(vec); + public Type type() { + return TYPE; } - @Override - public ResourceLocation id() { - return ID; + public static void handleData(PushEntityMessage message, IPayloadContext context) { + Entity entity = ClientUtil.theClientLevel().getEntity(message.entityId()); + if (entity != null) { + Vec3 vec = message.vec(); + entity.setDeltaMovement(vec.x, vec.y, vec.z); + entity.horizontalCollision = false; + entity.verticalCollision = false; + if (entity instanceof LivingEntity l) l.setJumping(true); + } } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/RouterSettingsMessage.java b/src/main/java/me/desht/modularrouters/network/messages/RouterSettingsMessage.java index 00035a64..161244a4 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/RouterSettingsMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/RouterSettingsMessage.java @@ -2,12 +2,17 @@ import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity.EnergyDirection; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; +import me.desht.modularrouters.core.ModBlockEntities; +import me.desht.modularrouters.logic.settings.RedstoneBehaviour; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: BOTH @@ -16,27 +21,36 @@ *

* Sent by server to sync router settings when GUI is opened */ -public record RouterSettingsMessage(boolean ecoMode, RouterRedstoneBehaviour redstoneBehaviour, EnergyDirection energyDirection, BlockPos pos) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("router_settings"); +public record RouterSettingsMessage(boolean ecoMode, RedstoneBehaviour redstoneBehaviour, + EnergyDirection energyDirection, BlockPos pos) implements CustomPacketPayload +{ + public static final Type TYPE = new Type<>(MiscUtil.RL("router_settings")); - public RouterSettingsMessage(ModularRouterBlockEntity router) { - this(router.getEcoMode(), router.getRedstoneBehaviour(), router.getEnergyDirection(), router.getBlockPos()); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.BOOL, RouterSettingsMessage::ecoMode, + NeoForgeStreamCodecs.enumCodec(RedstoneBehaviour.class), RouterSettingsMessage::redstoneBehaviour, + NeoForgeStreamCodecs.enumCodec(EnergyDirection.class), RouterSettingsMessage::energyDirection, + BlockPos.STREAM_CODEC, RouterSettingsMessage::pos, + RouterSettingsMessage::new + ); - public RouterSettingsMessage(FriendlyByteBuf buffer) { - this(buffer.readBoolean(), buffer.readEnum(RouterRedstoneBehaviour.class), buffer.readEnum(EnergyDirection.class), buffer.readBlockPos()); + public static RouterSettingsMessage forRouter(ModularRouterBlockEntity router) { + return new RouterSettingsMessage(router.getEcoMode(), router.getRedstoneBehaviour(), router.getEnergyDirection(), router.getBlockPos()); } @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeBoolean(ecoMode); - buffer.writeByte(redstoneBehaviour.ordinal()); - buffer.writeEnum(energyDirection); - buffer.writeBlockPos(pos); + public Type type() { + return TYPE; } - @Override - public ResourceLocation id() { - return ID; + public static void handleData(RouterSettingsMessage message, IPayloadContext context) { + Level level = context.player().level(); + if (level.isLoaded(message.pos())) { + level.getBlockEntity(message.pos(), ModBlockEntities.MODULAR_ROUTER.get()).ifPresent(router -> { + router.setRedstoneBehaviour(message.redstoneBehaviour()); + router.setEcoMode(message.ecoMode()); + router.setEnergyDirection(message.energyDirection()); + }); + } } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/RouterUpgradesSyncMessage.java b/src/main/java/me/desht/modularrouters/network/messages/RouterUpgradesSyncMessage.java index 2b4d4ac6..80b0884c 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/RouterUpgradesSyncMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/RouterUpgradesSyncMessage.java @@ -1,23 +1,34 @@ package me.desht.modularrouters.network.messages; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.client.util.ClientUtil; +import me.desht.modularrouters.core.ModBlockEntities; +import me.desht.modularrouters.util.CodecUtil; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.ItemStackHandler; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: CLIENT *

- * Sent when a router GUI is opened to sync all the upgrades to the clientside TE. + * Sent when a router GUI is opened to sync all the upgrades to the clientside block entity. * Various GUI messages/tooltips/etc. depend on knowing what upgrades the router has. */ public record RouterUpgradesSyncMessage(BlockPos pos, ItemStackHandler upgradesHandler) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("router_upgrades_sync"); + public static final Type TYPE = new Type<>(MiscUtil.RL("router_upgrades_sync")); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + BlockPos.STREAM_CODEC, RouterUpgradesSyncMessage::pos, + CodecUtil.ITEM_HANDLER_STREAM_CODEC, RouterUpgradesSyncMessage::upgradesHandler, + RouterUpgradesSyncMessage::new + ); public static RouterUpgradesSyncMessage forRouter(ModularRouterBlockEntity router) { BlockPos pos = router.getBlockPos(); @@ -29,24 +40,16 @@ public static RouterUpgradesSyncMessage forRouter(ModularRouterBlockEntity route return new RouterUpgradesSyncMessage(pos, handler); } - public RouterUpgradesSyncMessage(FriendlyByteBuf buf) { - this(buf.readBlockPos(), createHandler(buf.readNbt())); - } - - private static ItemStackHandler createHandler(CompoundTag tag) { - ItemStackHandler h = new ItemStackHandler(); - h.deserializeNBT(tag); - return h; - } - @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeBlockPos(pos); - buffer.writeNbt(upgradesHandler.serializeNBT()); + public Type type() { + return TYPE; } - @Override - public ResourceLocation id() { - return ID; + public static void handleData(RouterUpgradesSyncMessage message, IPayloadContext context) { + Level level = ClientUtil.theClientLevel(); + if (level != null && level.isLoaded(message.pos())) { + level.getBlockEntity(message.pos(), ModBlockEntities.MODULAR_ROUTER.get()) + .ifPresent(router -> router.setUpgradesFrom(message.upgradesHandler())); + } } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/SyncUpgradeSettingsMessage.java b/src/main/java/me/desht/modularrouters/network/messages/SyncUpgradeSettingsMessage.java index bc1e058a..92bf1425 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/SyncUpgradeSettingsMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/SyncUpgradeSettingsMessage.java @@ -1,10 +1,15 @@ package me.desht.modularrouters.network.messages; +import me.desht.modularrouters.item.upgrade.SyncUpgrade; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: SERVER @@ -12,20 +17,23 @@ * Sent by client when a new tuning value is entered via Sync Upgrade GUI */ public record SyncUpgradeSettingsMessage(int tunedValue, InteractionHand hand) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("sync_upgrade_settings"); + public static final Type TYPE = new Type<>(MiscUtil.RL("sync_upgrade_settings")); - public SyncUpgradeSettingsMessage(FriendlyByteBuf buf) { - this(buf.readVarInt(), buf.readEnum(InteractionHand.class)); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.VAR_INT, SyncUpgradeSettingsMessage::tunedValue, + NeoForgeStreamCodecs.enumCodec(InteractionHand.class), SyncUpgradeSettingsMessage::hand, + SyncUpgradeSettingsMessage::new + ); @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeVarInt(tunedValue); - buffer.writeEnum(hand); + public Type type() { + return TYPE; } - @Override - public ResourceLocation id() { - return ID; + public static void handleData(SyncUpgradeSettingsMessage message, IPayloadContext context) { + ItemStack held = context.player().getItemInHand(message.hand()); + if (held.getItem() instanceof SyncUpgrade) { + SyncUpgrade.setTunedValue(held, message.tunedValue()); + } } } diff --git a/src/main/java/me/desht/modularrouters/network/messages/ValidateModuleMessage.java b/src/main/java/me/desht/modularrouters/network/messages/ValidateModuleMessage.java index ce461a19..c417056d 100644 --- a/src/main/java/me/desht/modularrouters/network/messages/ValidateModuleMessage.java +++ b/src/main/java/me/desht/modularrouters/network/messages/ValidateModuleMessage.java @@ -1,10 +1,17 @@ package me.desht.modularrouters.network.messages; +import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.util.MiscUtil; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs; +import net.neoforged.neoforge.network.handling.IPayloadContext; /** * Received on: SERVER @@ -13,19 +20,21 @@ * send the player a message. */ public record ValidateModuleMessage(InteractionHand hand) implements CustomPacketPayload { - public static final ResourceLocation ID = MiscUtil.RL("validate_module"); - - public ValidateModuleMessage(FriendlyByteBuf buf) { - this(buf.readEnum(InteractionHand.class)); - } + public static final Type TYPE = new Type<>(MiscUtil.RL("validate_module")); + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + NeoForgeStreamCodecs.enumCodec(InteractionHand.class), ValidateModuleMessage::hand, + ValidateModuleMessage::new + ); @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeEnum(hand); + public Type type() { + return TYPE; } - @Override - public ResourceLocation id() { - return ID; + public static void handleData(ValidateModuleMessage message, IPayloadContext context) { + ItemStack stack = context.player().getItemInHand(message.hand()); + if (stack.getItem() instanceof ModuleItem moduleItem && context.player() instanceof ServerPlayer sp) { + moduleItem.doModuleValidation(stack, sp); + } } } diff --git a/src/main/java/me/desht/modularrouters/recipe/GuideBookRecipe.java b/src/main/java/me/desht/modularrouters/recipe/GuideBookRecipe.java index 5fc182f6..e16a73f9 100644 --- a/src/main/java/me/desht/modularrouters/recipe/GuideBookRecipe.java +++ b/src/main/java/me/desht/modularrouters/recipe/GuideBookRecipe.java @@ -3,6 +3,7 @@ import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModRecipes; import net.minecraft.core.NonNullList; +import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -18,7 +19,7 @@ public class GuideBookRecipe extends ShapelessRecipe { private static final ResourceLocation BOOK_ID = new ResourceLocation("patchouli:guide_book"); - private static final String NBT_KEY = "patchouli:book"; +// private static final String NBT_KEY = "patchouli:book"; private static final String NBT_VAL = "modularrouters:book"; public GuideBookRecipe(CraftingBookCategory category) { @@ -31,12 +32,14 @@ public static ItemStack makeGuideBook() { Item bookItem = BuiltInRegistries.ITEM.get(BOOK_ID); if (bookItem == Items.AIR) { ItemStack stack = new ItemStack(Items.PAPER); - stack.setHoverName(Component.literal("Install Patchouli for the guide book!")); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Install Patchouli for the guide book!")); return stack; } ItemStack book = new ItemStack(bookItem); - CompoundTag tag = book.getOrCreateTag(); - tag.putString(NBT_KEY, NBT_VAL); + + // TODO need to wait till Patchouli is on 1.20.5 and has registered a suitable data component +// CompoundTag tag = book.getOrCreateTag(); +// tag.putString(NBT_KEY, NBT_VAL); return book; } diff --git a/src/main/java/me/desht/modularrouters/recipe/PickaxeModuleRecipe.java b/src/main/java/me/desht/modularrouters/recipe/PickaxeModuleRecipe.java index 35b02839..ee76c630 100644 --- a/src/main/java/me/desht/modularrouters/recipe/PickaxeModuleRecipe.java +++ b/src/main/java/me/desht/modularrouters/recipe/PickaxeModuleRecipe.java @@ -3,8 +3,8 @@ import me.desht.modularrouters.core.ModItems; import me.desht.modularrouters.core.ModRecipes; import me.desht.modularrouters.item.module.IPickaxeUser; +import net.minecraft.core.HolderLookup; import net.minecraft.core.NonNullList; -import net.minecraft.core.RegistryAccess; import net.minecraft.tags.ItemTags; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; @@ -16,9 +16,6 @@ import net.neoforged.neoforge.common.ToolActions; import org.apache.commons.lang3.Validate; -import javax.annotation.Nullable; -import java.util.stream.Stream; - /** * For modules which need a pickaxe in their recipe to set their harvest level. */ @@ -44,7 +41,7 @@ public boolean matches(CraftingContainer inv, Level worldIn) { } @Override - public ItemStack assemble(CraftingContainer inv, RegistryAccess registryAccess) { + public ItemStack assemble(CraftingContainer inv, HolderLookup.Provider registryAccess) { ItemStack pick = ItemStack.EMPTY; for (int i = 0; i < inv.getContainerSize(); i++) { ItemStack stack = inv.getItem(i); @@ -72,7 +69,7 @@ public BreakerModuleRecipe(CraftingBookCategory category) { private static NonNullList ingredients() { return NonNullList.of(Ingredient.EMPTY, Ingredient.of(ModItems.BLANK_MODULE.get()), - new PickaxeIngredient() + Ingredient.of(ItemTags.PICKAXES) ); } @@ -101,25 +98,40 @@ public RecipeSerializer getSerializer() { } } - private static class PickaxeIngredient extends Ingredient { - PickaxeIngredient() { - // this is for the benefit of getMatchingStacks() - super(Stream.of(new TagValue(ItemTags.PICKAXES))); - -// Tags.Items.ImmutableList.of( -// new ItemStack(Items.WOODEN_PICKAXE), -// new ItemStack(Items.STONE_PICKAXE), -// new ItemStack(Items.IRON_PICKAXE), -// new ItemStack(Items.DIAMOND_PICKAXE), -// new ItemStack(Items.NETHERITE_PICKAXE) -// )))); - } - - @Override - public boolean test(@Nullable ItemStack stack) { - return isValidPickaxe(stack); - } - } +// private static class PickaxeIngredient implements ICustomIngredient { +// PickaxeIngredient() { +// // this is for the benefit of getMatchingStacks() +// super(Stream.of(new TagValue(ItemTags.PICKAXES))); +// +//// Tags.Items.ImmutableList.of( +//// new ItemStack(Items.WOODEN_PICKAXE), +//// new ItemStack(Items.STONE_PICKAXE), +//// new ItemStack(Items.IRON_PICKAXE), +//// new ItemStack(Items.DIAMOND_PICKAXE), +//// new ItemStack(Items.NETHERITE_PICKAXE) +//// )))); +// } +// +// @Override +// public boolean test(@Nullable ItemStack stack) { +// return isValidPickaxe(stack); +// } +// +// @Override +// public Stream getItems() { +// return Stream.of(new Ingredient.TagValue(ItemTags.PICKAXES)); +// } +// +// @Override +// public boolean isSimple() { +// return false; +// } +// +// @Override +// public IngredientType getType() { +// return null; +// } +// } private static boolean isValidPickaxe(ItemStack stack) { return stack != null && stack.getItem().canPerformAction(stack, ToolActions.PICKAXE_DIG) && stack.getDamageValue() == 0; diff --git a/src/main/java/me/desht/modularrouters/recipe/ResetModuleRecipe.java b/src/main/java/me/desht/modularrouters/recipe/ResetModuleRecipe.java index 4bae67a4..7e02d285 100644 --- a/src/main/java/me/desht/modularrouters/recipe/ResetModuleRecipe.java +++ b/src/main/java/me/desht/modularrouters/recipe/ResetModuleRecipe.java @@ -3,6 +3,7 @@ import me.desht.modularrouters.core.ModRecipes; import me.desht.modularrouters.item.module.IPickaxeUser; import me.desht.modularrouters.item.module.ModuleItem; +import net.minecraft.core.HolderLookup; import net.minecraft.core.RegistryAccess; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; @@ -32,7 +33,7 @@ public boolean matches(CraftingContainer inv, Level wrldIn) { } @Override - public ItemStack assemble(CraftingContainer inv, RegistryAccess registryAccess) { + public ItemStack assemble(CraftingContainer inv, HolderLookup.Provider registryAccess) { ItemStack moduleStack = ItemStack.EMPTY; for (int i = 0; i < inv.getContainerSize(); i++) { ItemStack stack = inv.getItem(i); diff --git a/src/main/java/me/desht/modularrouters/util/BeamData.java b/src/main/java/me/desht/modularrouters/util/BeamData.java index 80fbea92..e9f93257 100644 --- a/src/main/java/me/desht/modularrouters/util/BeamData.java +++ b/src/main/java/me/desht/modularrouters/util/BeamData.java @@ -1,92 +1,110 @@ package me.desht.modularrouters.util; +import io.netty.buffer.ByteBuf; +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -public class BeamData { - private final BlockPos dest; - private final int color; +import java.util.Objects; + +public final class BeamData { + private final ByteOffset offset; private final int duration; + private final int color; private final ItemStack stack; - private boolean itemFade; - private boolean reversed; + private final boolean fade; + private final boolean reversed; private int ticksLived = 0; - public BeamData(int duration, BlockPos dest, ItemStack stack, int color) { + public static final StreamCodec STREAM_CODEC = new StreamCodec<>() { + @Override + public BeamData decode(RegistryFriendlyByteBuf buf) { + ByteOffset offset = ByteOffset.STREAM_CODEC.decode(buf); + int duration = buf.readVarInt(); + int color = buf.readInt(); + ItemStack stack = ItemStack.OPTIONAL_STREAM_CODEC.decode(buf); + return !stack.isEmpty() ? + new BeamData(offset, duration, color, stack, buf.readBoolean(), buf.readBoolean()) : + new BeamData(offset, duration, color, stack, false, false); + } + + @Override + public void encode(RegistryFriendlyByteBuf buf, BeamData beamData) { + ByteOffset.STREAM_CODEC.encode(buf, beamData.offset); + buf.writeVarInt(beamData.duration); + buf.writeInt(beamData.color); + ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, beamData.stack); + if (!beamData.stack.isEmpty()) { + buf.writeBoolean(beamData.fade); + buf.writeBoolean(beamData.reversed); + } + } + }; + + public BeamData(ByteOffset offset, int duration, int color, ItemStack stack, boolean fade, boolean reversed) { + this.offset = offset; this.duration = duration; - this.dest = dest; - this.stack = stack; this.color = color; + this.stack = stack; + this.fade = fade; + this.reversed = reversed; } - public BeamData(int duration, BlockPos dest, int color) { - this.duration = duration; - this.dest = dest; - this.stack = ItemStack.EMPTY; - this.color = color; + public ItemStack stack() { + return stack; } - public BeamData(FriendlyByteBuf buf, BlockPos pos1) { - byte x = buf.readByte(); - byte y = buf.readByte(); - byte z = buf.readByte(); - this.dest = pos1.offset(-x, -y, -z); - this.color = buf.readInt(); - this.duration = buf.readVarInt(); - this.stack = buf.readItem(); - if (!stack.isEmpty()) { - this.itemFade = buf.readBoolean(); - this.reversed = buf.readBoolean(); - } + public boolean fade() { + return fade; } - public void toBytes(FriendlyByteBuf buf, BlockPos pos1) { - buf.writeByte(pos1.getX() - dest.getX()); - buf.writeByte(pos1.getY() - dest.getY()); - buf.writeByte(pos1.getZ() - dest.getZ()); - buf.writeInt(color); - buf.writeVarInt(duration); - buf.writeItem(stack); - if (!stack.isEmpty()) { - buf.writeBoolean(itemFade); - buf.writeBoolean(reversed); - } + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (BeamData) obj; + return Objects.equals(this.offset, that.offset) && + this.duration == that.duration && + this.color == that.color && + ItemStack.matches(this.stack, that.stack) && + this.fade == that.fade && + this.reversed == that.reversed; } - public BeamData reverseItems() { - this.reversed = true; - return this; + @Override + public int hashCode() { + return Objects.hash(offset, duration, color, ItemStack.hashItemAndComponents(stack), fade, reversed); } - public BeamData fadeItems() { - this.itemFade = true; - return this; + @Override + public String toString() { + return "BeamData[" + + "offset=" + offset + ", " + + "duration=" + duration + ", " + + "color=" + color + ", " + + "stack=" + stack + ", " + + "fade=" + fade + ", " + + "reversed=" + reversed + ']'; } public Vec3 getStart(Vec3 basePos) { - return reversed ? Vec3.atCenterOf(dest) : basePos; + return reversed ? offset.offset(basePos) : basePos; } public Vec3 getEnd(Vec3 basePos) { - return reversed ? basePos : Vec3.atCenterOf(dest); + return reversed ? basePos : offset.offset(basePos); } public AABB getAABB(BlockPos basePos) { - return AABB.of(BoundingBox.fromCorners(basePos, dest)); - } - - public ItemStack getStack() { - return stack; - } - - public boolean isItemFade() { - return itemFade; + Vec3 vec = Vec3.atCenterOf(basePos); + return new AABB(getStart(vec), getEnd(vec)); } public float getProgress(float partialTicks) { @@ -108,4 +126,62 @@ public int[] getRGB() { res[2] = color & 0xff; return res; } + + public record ByteOffset(byte x, byte y, byte z) { + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.BYTE, ByteOffset::x, + ByteBufCodecs.BYTE, ByteOffset::y, + ByteBufCodecs.BYTE, ByteOffset::z, + ByteOffset::new + ); + + public Vec3 offset(Vec3 from) { + return from.add(x, y, z); + } + } + + public static class Builder { + private final BlockPos src; + private final BlockPos dest; + private final int duration; + private final int color; + private ItemStack stack = ItemStack.EMPTY; + private boolean fade = false; + private boolean reversed = false; + + public Builder(ModularRouterBlockEntity router, BlockPos dest, int color) { + this(router.getBlockPos(), dest, router.getTickRate(), color); + } + + public Builder(BlockPos src, BlockPos dest, int duration, int color) { + this.src = src; + this.dest = dest; + this.duration = duration; + this.color = color; + } + + public Builder withItemStack(ItemStack stack) { + this.stack = stack; + return this; + } + + public Builder fade(boolean fade) { + this.fade = fade; + return this; + } + + public Builder reversed(boolean reversed) { + this.reversed = reversed; + return this; + } + + public BeamData build() { + ByteOffset offset = new ByteOffset( + (byte) Mth.clamp(dest.getX() - src.getX(), Byte.MIN_VALUE, Byte.MAX_VALUE), + (byte) Mth.clamp(dest.getY() - src.getY(), Byte.MIN_VALUE, Byte.MAX_VALUE), + (byte) Mth.clamp(dest.getZ() - src.getZ(), Byte.MIN_VALUE, Byte.MAX_VALUE) + ); + return new BeamData(offset, duration, color, stack, fade, reversed); + } + } } diff --git a/src/main/java/me/desht/modularrouters/util/BlockUtil.java b/src/main/java/me/desht/modularrouters/util/BlockUtil.java index ffc88dfc..33b1c50b 100644 --- a/src/main/java/me/desht/modularrouters/util/BlockUtil.java +++ b/src/main/java/me/desht/modularrouters/util/BlockUtil.java @@ -20,7 +20,6 @@ import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.common.IPlantable; import net.neoforged.neoforge.common.NeoForge; -import net.neoforged.neoforge.common.TierSortingRegistry; import net.neoforged.neoforge.common.util.BlockSnapshot; import net.neoforged.neoforge.common.util.FakePlayer; import net.neoforged.neoforge.event.level.BlockEvent; @@ -161,14 +160,14 @@ public static BreakResult tryBreakBlock(ModularRouterBlockEntity router, Level w FakePlayer fakePlayer = router.getFakePlayer(); fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, pickaxe); Tier tier = pickaxe.getItem() instanceof TieredItem t ? t.getTier() : Tiers.STONE; - if (ConfigHolder.common.module.breakerHarvestLevelLimit.get() && !TierSortingRegistry.isCorrectTierForDrops(tier, state)) { + if (ConfigHolder.common.module.breakerHarvestLevelLimit.get() && state.is(tier.getIncorrectBlocksForDrops())) { return BreakResult.NOT_BROKEN; } List allDrops = Block.getDrops(world.getBlockState(pos), serverWorld, pos, world.getBlockEntity(pos), fakePlayer, pickaxe); Map> groups = allDrops.stream().collect(Collectors.partitioningBy(matchByBlock ? s -> true : filter)); - if (!matchByBlock && allDrops.isEmpty() && !filter.isEmpty() && !filter.isBlacklist()) { + if (!matchByBlock && allDrops.isEmpty() && !filter.isEmpty() && filter.isWhiteList()) { return BreakResult.NOT_BROKEN; } diff --git a/src/main/java/me/desht/modularrouters/util/CodecUtil.java b/src/main/java/me/desht/modularrouters/util/CodecUtil.java new file mode 100644 index 00000000..26733b98 --- /dev/null +++ b/src/main/java/me/desht/modularrouters/util/CodecUtil.java @@ -0,0 +1,26 @@ +package me.desht.modularrouters.util; + +import net.minecraft.Util; +import net.minecraft.core.RegistryAccess; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.neoforged.neoforge.items.ItemStackHandler; + +public class CodecUtil { + public static final StreamCodec ITEM_HANDLER_STREAM_CODEC = new StreamCodec<>() { + @Override + public ItemStackHandler decode(RegistryFriendlyByteBuf buf) { + return createHandler(buf.registryAccess(), buf.readNbt()); + } + + @Override + public void encode(RegistryFriendlyByteBuf buf, ItemStackHandler handler) { + buf.writeNbt(handler.serializeNBT(buf.registryAccess())); + } + }; + + private static ItemStackHandler createHandler(RegistryAccess registryAccess, CompoundTag tag) { + return Util.make(new ItemStackHandler(), h -> h.deserializeNBT(registryAccess, tag)); + } +} diff --git a/src/main/java/me/desht/modularrouters/util/CountedItemStacks.java b/src/main/java/me/desht/modularrouters/util/CountedItemStacks.java index d8aeec6f..ccb22410 100644 --- a/src/main/java/me/desht/modularrouters/util/CountedItemStacks.java +++ b/src/main/java/me/desht/modularrouters/util/CountedItemStacks.java @@ -17,7 +17,7 @@ public boolean equals(ItemStack o1, ItemStack o2) { return (o1 == o2) || !(o1 == null || o2 == null) && o1.getItem() == o2.getItem() && o1.getDamageValue() == o2.getDamageValue(); - // ignore NBT for these purposes + // ignore components for these purposes } } diff --git a/src/main/java/me/desht/modularrouters/util/MFLocator.java b/src/main/java/me/desht/modularrouters/util/MFLocator.java index 1ab80688..de711626 100644 --- a/src/main/java/me/desht/modularrouters/util/MFLocator.java +++ b/src/main/java/me/desht/modularrouters/util/MFLocator.java @@ -1,16 +1,21 @@ package me.desht.modularrouters.util; import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; +import me.desht.modularrouters.block.tile.ModularRouterBlockEntity.RecompileFlag; import me.desht.modularrouters.container.handler.BaseModuleHandler; +import me.desht.modularrouters.container.handler.BaseModuleHandler.ModuleFilterHandler; import me.desht.modularrouters.core.ModBlockEntities; import me.desht.modularrouters.item.module.ModuleItem; import me.desht.modularrouters.item.smartfilter.SmartFilterItem; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.neoforged.fml.common.Mod; import org.apache.commons.lang3.Validate; import javax.annotation.Nonnull; @@ -20,7 +25,42 @@ * Unified object to locate a module or filter. */ public record MFLocator(InteractionHand hand, BlockPos routerPos, int routerSlot, int filterSlot, ItemType itemType) { - public enum ItemType { MODULE, FILTER } + public enum ItemType { MODULE, FILTER;} + + public static final StreamCodec STREAM_CODEC = new StreamCodec<>() { + @Override + public MFLocator decode(FriendlyByteBuf buf) { + ItemType type = buf.readEnum(ItemType.class); + InteractionHand hand = null; + BlockPos routerPos = null; + int routerSlot = -1; + if (buf.readBoolean()) { + routerPos = buf.readBlockPos(); + routerSlot = buf.readByte(); + } else { + hand = buf.readEnum(InteractionHand.class); + } + int filterSlot = buf.readByte(); + return create(type, hand, routerPos, routerSlot, filterSlot); + } + + @Override + public void encode(FriendlyByteBuf buf, MFLocator locator) { + buf.writeEnum(locator.itemType); + buf.writeBoolean(locator.routerPos != null); + if (locator.routerPos != null) { + buf.writeBlockPos(locator.routerPos); + buf.writeByte(locator.routerSlot); + } else { + buf.writeEnum(locator.hand); + } + buf.writeByte(locator.filterSlot); + } + }; + + public static MFLocator fromBuffer(FriendlyByteBuf buf) { + return STREAM_CODEC.decode(buf); + } private static MFLocator create(ItemType itemType, InteractionHand hand, BlockPos routerPos, int routerSlot, int filterSlot) { Validate.isTrue(hand != null || routerPos != null && routerSlot >= 0); @@ -28,6 +68,10 @@ private static MFLocator create(ItemType itemType, InteractionHand hand, BlockPo return new MFLocator(hand, routerPos, routerSlot, filterSlot, itemType); } + public void writeBuf(RegistryFriendlyByteBuf buf) { + STREAM_CODEC.encode(buf, this); + } + public static MFLocator heldModule(InteractionHand hand) { return create(ItemType.MODULE, hand, null, -1, -1); } @@ -48,33 +92,6 @@ public static MFLocator filterInInstalledModule(BlockPos routerPos, int routerSl return create(ItemType.FILTER, null, routerPos, routerSlot, filterSlot); } - public static MFLocator fromBuffer(FriendlyByteBuf buf) { - ItemType type = buf.readEnum(ItemType.class); - InteractionHand hand = null; - BlockPos routerPos = null; - int routerSlot = -1; - if (buf.readBoolean()) { - routerPos = buf.readBlockPos(); - routerSlot = buf.readByte(); - } else { - hand = buf.readEnum(InteractionHand.class); - } - int filterSlot = buf.readByte(); - return create(type, hand, routerPos, routerSlot, filterSlot); - } - - public void writeBuf(FriendlyByteBuf buf) { - buf.writeEnum(itemType); - buf.writeBoolean(routerPos != null); - if (routerPos != null) { - buf.writeBlockPos(routerPos); - buf.writeByte(routerSlot); - } else { - buf.writeEnum(hand); - } - buf.writeByte(filterSlot); - } - @Nonnull public ItemStack getTargetItem(Player player) { if (itemType == ItemType.MODULE) { @@ -104,13 +121,53 @@ public ItemStack getModuleStack(Player player) { } } - public Optional getRouter(Level world) { - return routerPos == null ? Optional.empty() : world.getBlockEntity(routerPos, ModBlockEntities.MODULAR_ROUTER.get()); + public void setModuleStack(Player player, ItemStack newStack) { + if (newStack.getItem() instanceof ModuleItem) { + if (hand != null) { + player.setItemInHand(hand, newStack); + } else if (routerPos != null) { + setInstalledModule(player.level(), newStack); + } + } + } + + public Optional getRouter(Level level) { + return routerPos == null ? Optional.empty() : level.getBlockEntity(routerPos, ModBlockEntities.MODULAR_ROUTER.get()); + } + + public void setFilterStack(Player player, ItemStack newFilterStack) { + if (newFilterStack.getItem() instanceof SmartFilterItem) { + if (routerPos == null) { + ItemStack heldStack = player.getItemInHand(hand); + if (heldStack.getItem() instanceof SmartFilterItem) { + // just replace filter in player's hand + player.setItemInHand(hand, newFilterStack); + } else if (heldStack.getItem() instanceof ModuleItem && filterSlot >= 0) { + // update filter in module in player's hand + setFilterInModule(heldStack, newFilterStack); + } + } else { + getRouter(player.level()).ifPresent(router -> { + // update filter in module installed in router + ItemStack moduleStack = router.getModules().getStackInSlot(routerSlot); + setFilterInModule(moduleStack, newFilterStack); + router.setChanged(); + }); + } + } } @Nonnull - private ItemStack getInstalledModule(Level world) { - return getRouter(world).map(router -> router.getModules().getStackInSlot(routerSlot)).orElse(ItemStack.EMPTY); + private ItemStack getInstalledModule(Level level) { + return getRouter(level).map(router -> router.getModules().getStackInSlot(routerSlot)).orElse(ItemStack.EMPTY); + } + + private void setInstalledModule(Level level, ItemStack newStack) { + getRouter(level).ifPresent(router -> { + router.getModules().setStackInSlot(routerSlot, newStack); + router.recompileNeeded(RecompileFlag.MODULES); + router.setChanged(); + }); } @Nonnull @@ -118,9 +175,15 @@ private ItemStack getFilterForStack(@Nonnull ItemStack stack) { if (stack.getItem() instanceof SmartFilterItem) { return stack; } else if (stack.getItem() instanceof ModuleItem && filterSlot >= 0) { - return new BaseModuleHandler.ModuleFilterHandler(stack, null).getStackInSlot(filterSlot); + return new ModuleFilterHandler(stack, null).getStackInSlot(filterSlot); } else { return ItemStack.EMPTY; } } + + private void setFilterInModule(ItemStack moduleStack, ItemStack filterStack) { + ModuleFilterHandler handler = new ModuleFilterHandler(moduleStack, null); + handler.setStackInSlot(filterSlot, filterStack); + handler.save(); + } } diff --git a/src/main/java/me/desht/modularrouters/util/ModuleHelper.java b/src/main/java/me/desht/modularrouters/util/ModuleHelper.java deleted file mode 100644 index 6820b01d..00000000 --- a/src/main/java/me/desht/modularrouters/util/ModuleHelper.java +++ /dev/null @@ -1,121 +0,0 @@ -package me.desht.modularrouters.util; - -import me.desht.modularrouters.ModularRouters; -import me.desht.modularrouters.core.ModItems; -import me.desht.modularrouters.item.augment.AugmentItem; -import me.desht.modularrouters.item.module.ModuleItem; -import me.desht.modularrouters.item.module.ModuleItem.ModuleFlags; -import me.desht.modularrouters.item.module.ModuleItem.RelativeDirection; -import me.desht.modularrouters.item.module.ModuleItem.Termination; -import me.desht.modularrouters.logic.RouterRedstoneBehaviour; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; -import net.minecraft.world.item.ItemStack; - -import javax.annotation.Nonnull; - -/** - * Collection of static convenience methods for managing NBT data in a module itemstack. - */ -public class ModuleHelper { - public static final String NBT_DIRECTION = "Direction"; - public static final String NBT_REDSTONE_MODE = "RedstoneMode"; - public static final String NBT_REGULATOR_AMOUNT = "RegulatorAmount"; - public static final String NBT_FILTER = "ModuleFilter"; - public static final String NBT_AUGMENTS = "Augments"; - public static final String NBT_MATCH_ALL = "MatchAll"; - public static final String NBT_TERMINATION = "Termination"; - private static final String NBT_RR_COUNTER = "RoundRobinCounter"; - - @Nonnull - public static CompoundTag validateNBT(ItemStack stack) { - return stack.hasTag() ? stack.getTag().getCompound(ModularRouters.MODID) : new CompoundTag(); - } - - @Nonnull - public static CompoundTag validateNBTForWriting(ItemStack stack) { - return stack.getOrCreateTagElement(ModularRouters.MODID); - } - - public static boolean isBlacklist(ItemStack stack) { - return checkFlag(stack, ModuleFlags.BLACKLIST); - } - - public static boolean ignoreDamage(ItemStack stack) { - return checkFlag(stack, ModuleFlags.IGNORE_DAMAGE); - } - - public static boolean ignoreNBT(ItemStack stack) { - return checkFlag(stack, ModuleFlags.IGNORE_NBT); - } - - public static boolean ignoreTags(ItemStack stack) { - return checkFlag(stack, ModuleFlags.IGNORE_TAGS); - } - - public static boolean checkFlag(ItemStack stack, ModuleFlags flag) { - CompoundTag tag = validateNBT(stack); - return tag.contains(flag.getName(), Tag.TAG_BYTE) ? tag.getBoolean(flag.getName()) : flag.getDefaultValue(); - } - - public static Termination getTermination(ItemStack stack) { - CompoundTag compound = validateNBT(stack); - try { - return compound.contains(ModuleHelper.NBT_TERMINATION, Tag.TAG_STRING) ? - Termination.valueOf(compound.getString(ModuleHelper.NBT_TERMINATION)) : - Termination.NONE; - } catch (IllegalArgumentException e) { - return Termination.NONE; - } - } - - public static RelativeDirection getRelativeDirection(ItemStack stack) { - if (stack.getItem() instanceof ModuleItem m && m.isDirectional()) { - CompoundTag compound = validateNBT(stack); - try { - String dirStr = compound.getString(NBT_DIRECTION); - return dirStr.isEmpty() ? RelativeDirection.NONE : RelativeDirection.valueOf(dirStr); - } catch (IllegalArgumentException e) { - return RelativeDirection.NONE; - } - } else { - return RelativeDirection.NONE; - } - } - - public static int getRegulatorAmount(ItemStack itemstack) { - return validateNBT(itemstack).getInt(NBT_REGULATOR_AMOUNT); - } - - public static RouterRedstoneBehaviour getRedstoneBehaviour(ItemStack stack) { - AugmentItem.AugmentCounter counter = new AugmentItem.AugmentCounter(stack); - if (counter.getAugmentCount(ModItems.REDSTONE_AUGMENT.get()) > 0) { - CompoundTag compound = validateNBT(stack); - try { - return RouterRedstoneBehaviour.values()[compound.getByte(NBT_REDSTONE_MODE)]; - } catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) { - return RouterRedstoneBehaviour.ALWAYS; - } - } else { - return RouterRedstoneBehaviour.ALWAYS; - } - } - - public static int getRangeModifier(ItemStack stack) { - AugmentItem.AugmentCounter counter = new AugmentItem.AugmentCounter(stack); - return counter.getAugmentCount(ModItems.RANGE_UP_AUGMENT.get()) - counter.getAugmentCount(ModItems.RANGE_DOWN_AUGMENT.get()); - } - - public static boolean isMatchAll(ItemStack stack) { - return validateNBT(stack).getBoolean(NBT_MATCH_ALL); - } - - public static void setRoundRobinCounter(ItemStack moduleStack, int counter) { - CompoundTag tag = validateNBTForWriting(moduleStack); - tag.putInt(NBT_RR_COUNTER, counter); - } - - public static int getRoundRobinCounter(ItemStack moduleStack) { - return validateNBT(moduleStack).getInt(NBT_RR_COUNTER); - } -} diff --git a/src/main/java/me/desht/modularrouters/util/SetofItemStack.java b/src/main/java/me/desht/modularrouters/util/SetofItemStack.java index 189ba851..d8682546 100644 --- a/src/main/java/me/desht/modularrouters/util/SetofItemStack.java +++ b/src/main/java/me/desht/modularrouters/util/SetofItemStack.java @@ -1,7 +1,7 @@ package me.desht.modularrouters.util; import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; -import me.desht.modularrouters.logic.filter.Filter.Flags; +import me.desht.modularrouters.logic.settings.ModuleFlags; import net.minecraft.core.NonNullList; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.Item; @@ -10,38 +10,37 @@ import java.util.Collection; import java.util.Comparator; -import java.util.List; public class SetofItemStack extends ObjectOpenCustomHashSet { - private record ItemStackHashingStrategy(Flags filterFlags) implements Strategy { + private record ItemStackHashingStrategy(ModuleFlags filterFlags) implements Strategy { @Override public int hashCode(ItemStack object) { + if (filterFlags.matchComponents()) { + return ItemStack.hashItemAndComponents(object); + } + int hashCode = Item.getId(object.getItem()); - if (!filterFlags.isIgnoreDamage()) hashCode += 37 * object.getDamageValue(); - if (!filterFlags.isIgnoreNBT() && object.hasTag()) //noinspection ConstantConditions - hashCode += 37 * object.getTag().hashCode(); - return hashCode; + return filterFlags.matchDamage() ? hashCode + 37 * object.getDamageValue() : hashCode; } @Override public boolean equals(ItemStack o1, ItemStack o2) { - //noinspection ConstantConditions return (o1 == o2) || !(o1 == null || o2 == null) && o1.getItem() == o2.getItem() - && (filterFlags.isIgnoreDamage() || o1.getDamageValue() == o2.getDamageValue()) - && (filterFlags.isIgnoreNBT() || !o1.hasTag() || o1.getTag().equals(o2.getTag())); + && (!filterFlags.matchDamage() || o1.getDamageValue() == o2.getDamageValue()) + && (!filterFlags.matchComponents() || ItemStack.isSameItemSameComponents(o1, o2)); } } - public SetofItemStack(Flags filterFlags) { + public SetofItemStack(ModuleFlags filterFlags) { super(new ItemStackHashingStrategy(filterFlags)); } - public SetofItemStack(Collection collection, Flags filterFlags) { + public SetofItemStack(Collection collection, ModuleFlags filterFlags) { super(collection, new ItemStackHashingStrategy(filterFlags)); } - public static SetofItemStack fromItemHandler(IItemHandler handler, Flags filterFlags) { + public static SetofItemStack fromItemHandler(IItemHandler handler, ModuleFlags filterFlags) { NonNullList itemStacks = NonNullList.create(); for (int i = 0; i < handler.getSlots(); i++) { ItemStack stack = handler.getStackInSlot(i); @@ -52,11 +51,11 @@ public static SetofItemStack fromItemHandler(IItemHandler handler, Flags filterF return new SetofItemStack(itemStacks, filterFlags); } - public List sortedList() { + public Collection sorted() { return this.stream().sorted(COMPARE_STACKS).toList(); } - // matches by mod, then by display name + // sort by mod, then by display name private static final Comparator COMPARE_STACKS = Comparator .comparing((ItemStack stack) -> namespace(stack.getItem())) .thenComparing(stack -> stack.getHoverName().getString()); diff --git a/src/main/java/me/desht/modularrouters/util/fake_player/RouterFakePlayer.java b/src/main/java/me/desht/modularrouters/util/fake_player/RouterFakePlayer.java index 1b3f8dc0..1f2af58f 100644 --- a/src/main/java/me/desht/modularrouters/util/fake_player/RouterFakePlayer.java +++ b/src/main/java/me/desht/modularrouters/util/fake_player/RouterFakePlayer.java @@ -5,6 +5,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.common.util.FakePlayer; @@ -37,8 +38,20 @@ public double getEyeY() { public void tick() { attackStrengthTicker++; if (router.caresAboutItemAttributes() && !ItemStack.matches(prevHeldStack, getMainHandItem())) { - getAttributes().removeAttributeModifiers(prevHeldStack.getAttributeModifiers(EquipmentSlot.MAINHAND)); - getAttributes().addTransientAttributeModifiers(getMainHandItem().getAttributeModifiers(EquipmentSlot.MAINHAND)); + prevHeldStack.forEachModifier(EquipmentSlot.MAINHAND, (holder, modifier) -> { + AttributeInstance instance = getAttributes().getInstance(holder); + if (instance != null) { + instance.removeModifier(modifier); + } + }); + getMainHandItem().forEachModifier(EquipmentSlot.MAINHAND, (holder, modifier) -> { + AttributeInstance instance = getAttributes().getInstance(holder); + if (instance != null) { + instance.removeModifier(modifier.id()); + instance.addTransientModifier(modifier); + } + }); + prevHeldStack = getMainHandItem().copy(); } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/neoforge.mods.toml similarity index 100% rename from src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/neoforge.mods.toml diff --git a/src/main/resources/assets/modularrouters/lang/en_us.json b/src/main/resources/assets/modularrouters/lang/en_us.json index 27c5ae25..c137d0df 100644 --- a/src/main/resources/assets/modularrouters/lang/en_us.json +++ b/src/main/resources/assets/modularrouters/lang/en_us.json @@ -65,20 +65,20 @@ "modularrouters.chatText.misc.targetSet" : "Target set: ", "modularrouters.chatText.misc.tooManyTargets" : "Too many targets! (max: %d)", "modularrouters.chatText.security.accessDenied" : "--[Access Denied]--", - "modularrouters.chatText.security.ADDED" : "Added player [%s]", - "modularrouters.chatText.security.ALREADY_ADDED" : "Player [%s] is already on this upgrade", - "modularrouters.chatText.security.ERROR" : "Couldn't add player [%s] (internal error)", - "modularrouters.chatText.security.FULL" : "Security upgrade items full!", - "modularrouters.chatText.security.NOT_PRESENT" : "Player [%s] is not on this uprade", - "modularrouters.chatText.security.REMOVED" : "Removed player [%s]", + "modularrouters.chatText.security.added" : "Added player [%s]", + "modularrouters.chatText.security.already_added" : "Player [%s] is already on this upgrade!", + "modularrouters.chatText.security.error" : "Couldn't add player [%s] (internal error)", + "modularrouters.chatText.security.full" : "Security upgrade items full!", + "modularrouters.chatText.security.not_present" : "Player [%s] is not on this uprade!", + "modularrouters.chatText.security.removed" : "Removed player [%s]", "modularrouters.chatText.subtitle.error" : "Error", "modularrouters.chatText.subtitle.success" : "Success", "modularrouters.chatText.subtitle.thud" : "*THUD*", - "modularrouters.chatText.targetValidation.NOT_INVENTORY" : "✘ No Inventory", - "modularrouters.chatText.targetValidation.NOT_LOADED" : "✘ Not Loaded", - "modularrouters.chatText.targetValidation.OK" : "✔ Target OK", - "modularrouters.chatText.targetValidation.OUT_OF_RANGE" : "✘ Out of Range", - "modularrouters.chatText.targetValidation.BAD_DIMENSION" : "✘ Dimension Blacklisted", + "modularrouters.chatText.targetValidation.not_inventory" : "✘ No Inventory", + "modularrouters.chatText.targetValidation.not_loaded" : "✘ Not Loaded", + "modularrouters.chatText.targetValidation.ok" : "✔ Target OK", + "modularrouters.chatText.targetValidation.out_of_range" : "✘ Out of Range", + "modularrouters.chatText.targetValidation.bad_dimension" : "✘ Dimension Blacklisted", "modularrouters._comment" : "JEI text", "modularrouters.gui.config.alwaysShowModuleSettings" : "Show module settings tooltips without needing to hold down Shift", "modularrouters.gui.config.baseTickRate" : "Base router tick rate (with no Speed Upgrades)", @@ -115,8 +115,8 @@ "modularrouters.gui.config.vacuumBaseRange" : "Base Range for Vacuum Module (no Range Upgrades)", "modularrouters.gui.config.vacuumMaxRange" : "Hard Maximum Range for Vacuum Module (with Range Upgrades)", "modularrouters.gui.config.vacuumParticles" : "Show particle effects when a Vacuum Module absorbs an item", - "modularrouters.guiText.label.breakMatchType.BLOCK" : "Match by Block", - "modularrouters.guiText.label.breakMatchType.ITEM" : "Match by Dropped Item(s)", + "modularrouters.guiText.label.breakMatchType.block" : "Match by Block", + "modularrouters.guiText.label.breakMatchType.item" : "Match by Dropped Item(s)", "modularrouters.guiText.label.buffer" : "Buffer", "modularrouters.guiText.label.direction" : "Direction", "modularrouters.guiText.label.filters" : "Filters", @@ -128,24 +128,22 @@ "modularrouters.guiText.label.inspectionOp.LT" : "<", "modularrouters.guiText.label.inspectionOp.NE" : "!=", "modularrouters.guiText.label.inspectionOp.NONE" : "", - "modularrouters.guiText.label.inspectionSubject.DURABILITY" : "Durability", - "modularrouters.guiText.label.inspectionSubject.ENCHANT" : "Enchantment", - "modularrouters.guiText.label.inspectionSubject.ENERGY" : "Energy Level", - "modularrouters.guiText.label.inspectionSubject.FLUID" : "Fluid Level", - "modularrouters.guiText.label.inspectionSubject.FOOD" : "Food Value", - "modularrouters.guiText.label.inspectionSubject.NONE" : "", + "modularrouters.guiText.label.inspectionSubject.durability" : "Durability", + "modularrouters.guiText.label.inspectionSubject.enchant" : "Enchantment", + "modularrouters.guiText.label.inspectionSubject.energy" : "Energy Level", + "modularrouters.guiText.label.inspectionSubject.fluid" : "Fluid Level", + "modularrouters.guiText.label.inspectionSubject.food" : "Food Value", + "modularrouters.guiText.label.inspectionSubject.none" : "", "modularrouters.guiText.label.installed" : "(installed)", "modularrouters.guiText.label.matchAll.false" : "Match Any", "modularrouters.guiText.label.matchAll.true" : "Match All", "modularrouters.guiText.label.modules" : "Modules", "modularrouters.guiText.label.noTags": "No Item Tags", - "modularrouters.guiText.label.playerOp.EXTRACT" : "From Player to Router", - "modularrouters.guiText.label.playerOp.INSERT" : "From Router to Player", - "modularrouters.guiText.label.playerSect.ARMOR" : "Armor Slots", - "modularrouters.guiText.label.playerSect.ENDER" : "Ender Inventory", - "modularrouters.guiText.label.playerSect.MAIN" : "Main Inventory", - "modularrouters.guiText.label.playerSect.MAIN_NO_HOTBAR" : "Main Inventory (no Hotbar)", - "modularrouters.guiText.label.playerSect.OFFHAND" : "Offhand Slot", + "modularrouters.guiText.label.playerSect.armor" : "Armor Slots", + "modularrouters.guiText.label.playerSect.ender" : "Ender Inventory", + "modularrouters.guiText.label.playerSect.main" : "Main Inventory", + "modularrouters.guiText.label.playerSect.main_no_hotbar" : "Main Inventory (no Hotbar)", + "modularrouters.guiText.label.playerSect.offhand" : "Offhand Slot", "modularrouters.guiText.label.regexError" : "Invalid regular expression", "modularrouters.guiText.label.selectTag": "Select an Item Tag", "modularrouters.guiText.label.upgrades" : "Upgrades", @@ -180,13 +178,13 @@ "modularrouters.guiText.tooltip.activator.lookDirection" : "Look", "modularrouters.guiText.tooltip.activator.sneak" : "Sneak", "modularrouters.guiText.tooltip.allDirections" : "All", - "modularrouters.guiText.tooltip.BACK" : "Back", - "modularrouters.guiText.tooltip.BLACKLIST.1" : "Whitelist\nThe module will run only if the filter matches.\nAn empty whitelist will never allow the module to run.", - "modularrouters.guiText.tooltip.BLACKLIST.2" : "Blacklist\nThe module will not run if the filter matches.\nAn empty blacklist will always allow the module to run.", + "modularrouters.guiText.tooltip.relative_dir.back" : "Back", + "modularrouters.guiText.tooltip.whitelist.true" : "Whitelist\nThe module will run only if the filter matches.\nAn empty whitelist will never allow the module to run.", + "modularrouters.guiText.tooltip.whitelist.false" : "Blacklist\nThe module will not run if the filter matches.\nAn empty blacklist will always allow the module to run.", "modularrouters.guiText.tooltip.clearFilter" : "Clear Filter", "modularrouters.guiText.tooltip.detectorTooltip" : "Redstone Signal Level", "modularrouters.guiText.tooltip.distributor.strategy" : "Distribution Strategy", - "modularrouters.guiText.tooltip.DOWN" : "Down", + "modularrouters.guiText.tooltip.relative_dir.down" : "Down", "modularrouters.guiText.tooltip.eco.false" : "Eco Mode §edisabled \n§7Router will always run at normal speed.", "modularrouters.guiText.tooltip.eco.true" : "Eco Mode §aenabled \n§7If router is idle for >%f seconds, it will enter low-power mode and only run every %f seconds. It will leave low-power mode upon processing any item and return to running at normal speed.", "modularrouters.guiText.tooltip.energy.from_router" : "Transfer energy from router's buffer to item", @@ -201,70 +199,70 @@ "modularrouters.guiText.tooltip.fluidForceEmpty.true" : "§bForce Emptying Enabled \nWhen pouring into the world: fluid will always be poured out of the router if possible. Warning: this can cause fluid to be lost, e.g. emptying lava into an existing lava block. Use with care.", "modularrouters.guiText.tooltip.fluidRegulatorTooltip" : "§bFluid Regulation Enabled\nWhen transferring from router: only insert when destination tank(s) are less than this full.\nWhen transferring to router: only extract if source tank(s) are more than this full.", "modularrouters.guiText.tooltip.fluidTransferTooltip" : "§bMax Fluid Transfer\nMaximum (in mB) that will be attempted in one operation.\nThis is still limited by the router's overall transfer rate (Fluid and Speed Upgrades)", - "modularrouters.guiText.tooltip.FRONT" : "Front", - "modularrouters.guiText.tooltip.IGNORE_DAMAGE.1" : "Match Item Damage\nDistinguish between damageable items of the same type with different damage levels", - "modularrouters.guiText.tooltip.IGNORE_DAMAGE.2" : "Ignore Item Damage\nTreat damageable items of the same type but different damage levels as the same", - "modularrouters.guiText.tooltip.IGNORE_NBT.1" : "Match NBT\ne.g. take the enchantments on an item into account when matching", - "modularrouters.guiText.tooltip.IGNORE_NBT.2" : "Ignore NBT\ne.g. ignore the enchantments on an item when matching", - "modularrouters.guiText.tooltip.IGNORE_TAGS.1" : "Tag Matching Enabled\nItems in the same tag group as any item in the filter will match, e.g. oak and birch logs", - "modularrouters.guiText.tooltip.IGNORE_TAGS.2" : "Tag Matching Disabled", - "modularrouters.guiText.tooltip.LEFT" : "Left", + "modularrouters.guiText.tooltip.relative_dir.front" : "Front", + "modularrouters.guiText.tooltip.match_damage.false" : "Ignore Item Damage\nTreat damageable items of the same type but different damage levels as the same", + "modularrouters.guiText.tooltip.match_damage.true" : "Match Item Damage\nDistinguish between damageable items of the same type with different damage levels", + "modularrouters.guiText.tooltip.match_components.false" : "Ignore Item Components\nIgnore item component data on an item when matching", + "modularrouters.guiText.tooltip.match_components.true" : "Match Item Components\nTake item component data, e.g. enchantments, into account when matching", + "modularrouters.guiText.tooltip.match_item_tag.false" : "Tag Matching Disabled", + "modularrouters.guiText.tooltip.match_item_tag.true" : "Tag Matching Enabled\nItems which share a common item tag with any item in the filter will match\nUse a Tag Filter for more precise item tag matching", + "modularrouters.guiText.tooltip.relative_dir.left" : "Left", "modularrouters.guiText.tooltip.loadFilter" : "Load Filter\n from %s @ %s\n§oExisting filter contents will be overwritten!", - "modularrouters.guiText.tooltip.matchAll.false" : "Match Any\nAny item in the filter may match for the filter to match.\nUse this under most circumstances.", - "modularrouters.guiText.tooltip.matchAll.true" : "Match All\nALL items in the filter must match for the filter to match.\nUsed in specific circumstances, e.g. if you want to test for enchanted leather armor.", + "modularrouters.guiText.tooltip.match_all.false" : "Match Any\nAny item in the filter may match for the filter to match.\nUse this under most circumstances.", + "modularrouters.guiText.tooltip.match_all.true" : "Match All\nALL items in the filter must match for the filter to match.\nUsed in specific circumstances, e.g. if you want to test for enchanted leather armor.", "modularrouters.guiText.tooltip.maxFluidPerOp" : "Transfer Rate: %d mB every %d ticks (%d mB / tick)", "modularrouters.guiText.tooltip.mergeFilter" : "Merge Filter\n from %s @ %s", "modularrouters.guiText.tooltip.mouseOverHelp.false" : "Click to activate mouse-over help", "modularrouters.guiText.tooltip.mouseOverHelp.true" : "Mouse-over help active \n§7Click to deactivate", - "modularrouters.guiText.tooltip.NONE" : "None", + "modularrouters.guiText.tooltip.relative_dir.none" : "None", "modularrouters.guiText.tooltip.numberFieldTooltip" : "• §e§oCursor Up/Down§7 or mouse wheel: adjust\n• Hold §e§oShift§7: coarse adjust\n• Hold §e§oCtrl§7: fine adjust\n• §e§oPage Up/Down§7: set to max/min", - "modularrouters.guiText.tooltip.redstone.ALWAYS" : "Always", - "modularrouters.guiText.tooltip.redstone.HIGH" : "High", + "modularrouters.guiText.tooltip.redstone.always" : "Always", + "modularrouters.guiText.tooltip.redstone.high" : "High", "modularrouters.guiText.tooltip.redstone.label" : "Redstone Mode", - "modularrouters.guiText.tooltip.redstone.LOW" : "Low", - "modularrouters.guiText.tooltip.redstone.NEVER" : "Never", - "modularrouters.guiText.tooltip.redstone.PULSE" : "Pulsed", + "modularrouters.guiText.tooltip.redstone.low" : "Low", + "modularrouters.guiText.tooltip.redstone.never" : "Never", + "modularrouters.guiText.tooltip.redstone.pulse" : "Pulsed", "modularrouters.guiText.tooltip.regulator.label" : "%d Item(s)", "modularrouters.guiText.tooltip.regulator.labelFluidmB" : "%d mB", "modularrouters.guiText.tooltip.regulator.labelFluidPct" : "%d%%", "modularrouters.guiText.tooltip.regulatorTooltip" : "§bItem Regulation Enabled\nWhen inserting: only insert when inventory has fewer than this many of the item.\nWhen extracting: only extract if inventory has more than this many of the item.", - "modularrouters.guiText.tooltip.RIGHT" : "Right", - "modularrouters.guiText.tooltip.terminate.NONE" : "Always continue executing subsequent modules on this tick, regardless of whether this module did anything.", - "modularrouters.guiText.tooltip.terminate.NONE.header" : "Always Continue", - "modularrouters.guiText.tooltip.terminate.NOT_RAN" : "Don't execute any subsequent modules on this tick if this module did NOT do anything.", - "modularrouters.guiText.tooltip.terminate.NOT_RAN.header" : "Terminate on no Match", - "modularrouters.guiText.tooltip.terminate.RAN" : "Don't execute any subsequent modules on this tick if this module did something.", - "modularrouters.guiText.tooltip.terminate.RAN.header" : "Terminate on Match", + "modularrouters.guiText.tooltip.relative_dir.right" : "Right", + "modularrouters.guiText.tooltip.terminate.none" : "Always continue executing subsequent modules on this tick, regardless of whether this module did anything.", + "modularrouters.guiText.tooltip.terminate.none.header" : "Always Continue", + "modularrouters.guiText.tooltip.terminate.not_ran" : "Don't execute any subsequent modules on this tick if this module did NOT do anything.", + "modularrouters.guiText.tooltip.terminate.not_ran.header" : "Terminate on no Match", + "modularrouters.guiText.tooltip.terminate.ran" : "Don't execute any subsequent modules on this tick if this module did something.", + "modularrouters.guiText.tooltip.terminate.ran.header" : "Terminate on Match", "modularrouters.guiText.tooltip.tunedValue" : "Tuned Value (%d → %d)", - "modularrouters.guiText.tooltip.UP" : "Up", + "modularrouters.guiText.tooltip.relative_dir.up" : "Up", "modularrouters.guiText.tooltip.xpVacuum.ejectFluid" : "XP Fluids Ejected", "itemGroup.modularrouters" : "Modular Routers", - "modularrouters.itemText.activator.action.ITEM_OR_BLOCK" : "Right-click", - "modularrouters.itemText.activator.action.USE_ITEM_ON_ENTITY" : "Right-click entity", - "modularrouters.itemText.activator.action.ATTACK_ENTITY" : "Attack nearby entity", - "modularrouters.itemText.activator.direction.ABOVE" : "Look Above", - "modularrouters.itemText.activator.direction.BELOW" : "Look Below", - "modularrouters.itemText.activator.direction.LEVEL" : "Look Level", - "modularrouters.itemText.activator.entityMode.NEAREST" : "Nearest in-range entity", - "modularrouters.itemText.activator.entityMode.RANDOM" : "Random in-range entity", - "modularrouters.itemText.activator.entityMode.ROUND_ROBIN" : "Round Robin in-range entities", + "modularrouters.itemText.activator.action.item_or_block" : "Right-click", + "modularrouters.itemText.activator.action.use_item_on_entity" : "Right-click entity", + "modularrouters.itemText.activator.action.attack_entity" : "Attack nearby entity", + "modularrouters.itemText.activator.direction.above" : "Look Above", + "modularrouters.itemText.activator.direction.below" : "Look Below", + "modularrouters.itemText.activator.direction.level" : "Look Level", + "modularrouters.itemText.activator.entityMode.nearest" : "Nearest in-range entity", + "modularrouters.itemText.activator.entityMode.random" : "Random in-range entity", + "modularrouters.itemText.activator.entityMode.round_robin" : "Round Robin in-range entities", "modularrouters.itemText.augments" : "Augments:", "modularrouters.itemText.augments.pickupDelay" : "%d ticks (%f sec)", "modularrouters.itemText.augments.stackInfo" : "%d items/router tick", "modularrouters.itemText.camouflage.held" : "Camouflage as: ", - "modularrouters.itemText.distributor.strategy.FURTHEST_FIRST" : "Furthest First", - "modularrouters.itemText.distributor.strategy.NEAREST_FIRST" : "Nearest First", - "modularrouters.itemText.distributor.strategy.RANDOM" : "Random", - "modularrouters.itemText.distributor.strategy.ROUND_ROBIN" : "Round Robin", + "modularrouters.itemText.distributor.strategy.furthest_first" : "Furthest First", + "modularrouters.itemText.distributor.strategy.nearest_first" : "Nearest First", + "modularrouters.itemText.distributor.strategy.random" : "Random", + "modularrouters.itemText.distributor.strategy.round_robin" : "Round Robin", "modularrouters.itemText.extruder2.template" : "Template Blocks:", - "modularrouters.itemText.extruder.mode.ALWAYS" : "Extend: §bWith redstone signal > 0", - "modularrouters.itemText.extruder.mode.HIGH" : "Extend: §bWith redstone signal = 15", - "modularrouters.itemText.extruder.mode.LOW" : "Extend: §bWith redstone signal = 0", - "modularrouters.itemText.extruder.mode.NEVER" : "Extend: §bNever", - "modularrouters.itemText.extruder.mode.PULSE" : "Extend: §bNever", - "modularrouters.itemText.fluid.direction" : "Fluid Direction: %s", - "modularrouters.itemText.fluid.direction.IN" : "Transfer into Router", - "modularrouters.itemText.fluid.direction.OUT" : "Transfer out of Router", + "modularrouters.itemText.extruder.mode.always" : "Extend: §bWith redstone signal > 0", + "modularrouters.itemText.extruder.mode.high" : "Extend: §bWith redstone signal = 15", + "modularrouters.itemText.extruder.mode.low" : "Extend: §bWith redstone signal = 0", + "modularrouters.itemText.extruder.mode.never" : "Extend: §bNever", + "modularrouters.itemText.extruder.mode.pulse" : "Extend: §bNever", + "modularrouters.itemText.transfer_direction" : "Transfer Direction: %s", + "modularrouters.itemText.transfer_direction.to_router" : "Transfer into Router", + "modularrouters.itemText.transfer_direction.from_router" : "Transfer out of Router", "modularrouters.itemText.fluid.maxTransfer" : "Fluid Rate: Up to %s mB / operation", "modularrouters.itemText.misc.blacklist" : "Blacklist", "modularrouters.itemText.misc.breakerPick" : "Pickaxe: ", @@ -279,9 +277,9 @@ "modularrouters.itemText.misc.flingerDetails" : "Speed: %s | Pitch: %s | Yaw: %s", "modularrouters.itemText.misc.holdKey" : "▶ Hold [%s] for more info", "modularrouters.itemText.misc.holdShiftKey" : "▶ Hold [%s] for settings, [%s] for more info", - "modularrouters.itemText.misc.IGNORE_DAMAGE" : "Damage", - "modularrouters.itemText.misc.IGNORE_NBT" : "NBT", - "modularrouters.itemText.misc.IGNORE_TAGS" : "Tags", + "modularrouters.itemText.misc.match_damage" : "Damage", + "modularrouters.itemText.misc.match_components" : "Components", + "modularrouters.itemText.misc.match_item_tags" : "Tags", "modularrouters.itemText.misc.itemList" : "Item List", "modularrouters.itemText.misc.matchAll" : "All", "modularrouters.itemText.misc.matchAny" : "Any", diff --git a/src/main/resources/assets/modularrouters/textures/gui/widgets.png b/src/main/resources/assets/modularrouters/textures/gui/widgets.png index 1621fb3b..44ec6901 100644 Binary files a/src/main/resources/assets/modularrouters/textures/gui/widgets.png and b/src/main/resources/assets/modularrouters/textures/gui/widgets.png differ