diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4bc8ef..987bc11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v2 with: - java-version: '17' + java-version: '21' distribution: 'temurin' cache: 'gradle' - name: Grant execute permission for gradlew diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index ebb8183..da1d6d5 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,10 +15,11 @@ on: jobs: publish: - uses: MattiDragon/MattiDragon/.github/workflows/publish-mc-mod.yaml@275ad65025060abab92dd3a080dae735e89565e7 + uses: MattiDragon/MattiDragon/.github/workflows/publish-mc-mod.yaml@00051ad2ae1350c882ab08a382d4dda38eff121b with: version-type: ${{ inputs.version-type }} minecraft-versions: ${{ inputs.minecraft-versions }} + java-version: 21 modrinth-id: IF0Y4xFw curseforge-id: 689404 secrets: diff --git a/build.gradle b/build.gradle index 1d94629..637628e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.4-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' } @@ -14,6 +14,7 @@ repositories { maven { url "https://kneelawk.com/maven/" content { + includeGroup "com.kneelawk.graphlib" includeGroup "com.kneelawk" } } @@ -33,7 +34,7 @@ repositories { maven { url "https://maven.isxander.dev/releases" content { - includeGroup "dev.isxander.yacl" + includeGroup "dev.isxander" } } maven { @@ -80,17 +81,18 @@ dependencies { // Core apis modImplementation include("com.github.mattidragon:nodeflow:$nodeflow_version") - modImplementation include("com.kneelawk:graphlib:$graphlib_version") + include modImplementation("com.kneelawk.graphlib:core-fabric:$graphlib_version") + modLocalRuntime("com.kneelawk.graphlib:debugrender-fabric:$graphlib_version") include modApi("teamreborn:energy:$energy_version") { exclude(group: "net.fabricmc.fabric-api") } // Config modImplementation "com.terraformersmc:modmenu:$modmenu_version" - modImplementation include("dev.isxander.yacl:yet-another-config-lib-fabric:$yacl_version") + modImplementation include("dev.isxander:yet-another-config-lib:$yacl_version-fabric") modImplementation annotationProcessor(include("com.github.mattidragon:configtoolkit:$configtoolkit_version")) - modImplementation include("me.luligabi:NoIndium:$noindium_version") +// modImplementation include("me.luligabi:NoIndium:$noindium_version") // Add generated data to runtime classpath (slightly hacky) runtimeOnly files("src/main/generated") diff --git a/changelog/3.0.1+1.20.4.md b/changelog/3.0.1+1.20.4.md deleted file mode 100644 index 176305b..0000000 --- a/changelog/3.0.1+1.20.4.md +++ /dev/null @@ -1,3 +0,0 @@ -* Updated to 1.20.4 - * Tooltips changed slightly due to a change in how minecraft does them -* Fixed typo in config screen \ No newline at end of file diff --git a/changelog/3.1.0+1.20.4.md b/changelog/3.1.0+1.20.4.md deleted file mode 100644 index 06d0b60..0000000 --- a/changelog/3.1.0+1.20.4.md +++ /dev/null @@ -1,12 +0,0 @@ -* Make interfaces use names from attached containers as fallback -* Add interface groups - * They allow you to interact with multiple interfaces as one -* Added support for color tagging nodes -* Added support for setting a custom name for a node -* Made tooltips only show on the config/error button -* Fixed context menu sometimes going outside the screen -* Generally improved the UI -* Missing containers no longer cause an error. - * This was required to get groups working properly - * This is useful if you have containers that might sometimes be missing -* Connection in the editor are now textured \ No newline at end of file diff --git a/changelog/4.0.0-beta.1+1.20.6.md b/changelog/4.0.0-beta.1+1.20.6.md new file mode 100644 index 0000000..c293fc3 --- /dev/null +++ b/changelog/4.0.0-beta.1+1.20.6.md @@ -0,0 +1,4 @@ +* Update to 1.20.6 + * Nbt filtering now converts the component changes of a stack into nbt and the filters that. + I might add a way to filter components directly later. +* Fix adventure mode access toggle not being properly hidden in cables \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index cf5390f..d2839bc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,18 @@ org.gradle.jvmargs=-Xmx1G -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.3 -loader_version=0.15.2 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 +loader_version=0.15.11 -mod_version=3.1.0 +mod_version=4.0.0-beta.1 maven_group=io.github.mattidragon archives_base_name=advanced-networking -fabric_version=0.91.2+1.20.4 -nodeflow_version=1.1.0-mc.1.20.4 -graphlib_version=1.4.0+1.20.4 -energy_version=3.0.0 -yacl_version=3.3.1+1.20.4 -modmenu_version=9.0.0-pre.1 -configtoolkit_version=1.0.0 +fabric_version=0.98.0+1.20.6 +nodeflow_version=2.0.0-mc.1.20.6 +graphlib_version=2.0.0-alpha.17+1.20.6 +energy_version=4.0.1 +yacl_version=3.4.2+1.20.5 +modmenu_version=10.0.0-beta.1 +configtoolkit_version=1.1.1 noindium_version=1.1.0+1.20 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..e644113 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index db9a6b8..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..1aa94a4 100644 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..25da30d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/jitpack.yml b/jitpack.yml index c0a326f..aa4f08f 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,3 +1,3 @@ before_install: - - sdk install java 18.0.1.1-open - - sdk use java 18.0.1.1-open \ No newline at end of file + - sdk install java 21.0.2-open + - sdk use java 21.0.2-open \ No newline at end of file diff --git a/src/client/java/io/github/mattidragon/advancednetworking/client/AdvancedNetworkingClient.java b/src/client/java/io/github/mattidragon/advancednetworking/client/AdvancedNetworkingClient.java index 8d2d6f9..1c78b44 100644 --- a/src/client/java/io/github/mattidragon/advancednetworking/client/AdvancedNetworkingClient.java +++ b/src/client/java/io/github/mattidragon/advancednetworking/client/AdvancedNetworkingClient.java @@ -7,7 +7,7 @@ import io.github.mattidragon.advancednetworking.client.screen.node.InterfaceNodeConfigScreen; import io.github.mattidragon.advancednetworking.client.screen.node.SliderNodeConfigScreen; import io.github.mattidragon.advancednetworking.graph.ModNodeTypes; -import io.github.mattidragon.advancednetworking.misc.RequestInterfacesPacket; +import io.github.mattidragon.advancednetworking.misc.RequestInterfacesPayload; import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandler; import io.github.mattidragon.nodeflow.client.compat.controlify.ControlifyProxy; import io.github.mattidragon.nodeflow.client.ui.NodeConfigScreenRegistry; @@ -16,7 +16,6 @@ import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.gui.screen.ingame.HandledScreens; -import net.minecraft.network.PacketByteBuf; public class AdvancedNetworkingClient implements ClientModInitializer { @Override @@ -58,16 +57,11 @@ public void onInitializeClient() { ModNodeTypes.ITEM_COUNT, ModNodeTypes.FLUID_COUNT); - ClientPlayNetworking.registerGlobalReceiver(RequestInterfacesPacket.RESPONSE_ID, (client, handler, buf, responseSender) -> { - var syncId = buf.readByte(); - var interfaces = buf.readMap(PacketByteBuf::readString, PacketByteBuf::readText); - var groups = buf.readMap(PacketByteBuf::readString, buf1 -> buf1.readList(PacketByteBuf::readString)); - - client.execute(() -> { - if (client.player != null && client.player.currentScreenHandler.syncId == syncId && client.currentScreen instanceof InterfaceNodeConfigScreen configScreen) { - configScreen.setInterfaces(interfaces, groups); - } - }); + ClientPlayNetworking.registerGlobalReceiver(RequestInterfacesPayload.Response.ID, (packet, context) -> { + var player = context.player(); + if (player != null && player.currentScreenHandler.syncId == packet.syncId() && context.client().currentScreen instanceof InterfaceNodeConfigScreen configScreen) { + configScreen.setInterfaces(packet.interfaces(), packet.groups()); + } }); } } diff --git a/src/client/java/io/github/mattidragon/advancednetworking/client/screen/CableConfigScreen.java b/src/client/java/io/github/mattidragon/advancednetworking/client/screen/CableConfigScreen.java index 64c46c4..60dedb1 100644 --- a/src/client/java/io/github/mattidragon/advancednetworking/client/screen/CableConfigScreen.java +++ b/src/client/java/io/github/mattidragon/advancednetworking/client/screen/CableConfigScreen.java @@ -1,5 +1,6 @@ package io.github.mattidragon.advancednetworking.client.screen; +import io.github.mattidragon.advancednetworking.AdvancedNetworking; import io.github.mattidragon.advancednetworking.block.CableBlock; import io.github.mattidragon.advancednetworking.block.CableBlockEntity; import io.github.mattidragon.advancednetworking.misc.InterfaceType; @@ -89,7 +90,7 @@ protected void init() { } buttons[side.getId()].active = false; - if (client != null && client.player != null && client.player.isCreativeLevelTwoOp()) { + if (client != null && client.player != null && client.player.isCreativeLevelTwoOp() && AdvancedNetworking.CONFIG.get().showAdventureModeToggles()) { addDrawableChild(CyclingButtonWidget.onOffBuilder() .initially(adventureModeAccessAllowed) .build(calcLeftX(), 170, 150, 20, Text.translatable("screen.advanced_networking.adventure_mode_access"), (button, value) -> { diff --git a/src/client/java/io/github/mattidragon/advancednetworking/client/screen/node/InterfaceNodeConfigScreen.java b/src/client/java/io/github/mattidragon/advancednetworking/client/screen/node/InterfaceNodeConfigScreen.java index 22e20fb..9c19a3d 100644 --- a/src/client/java/io/github/mattidragon/advancednetworking/client/screen/node/InterfaceNodeConfigScreen.java +++ b/src/client/java/io/github/mattidragon/advancednetworking/client/screen/node/InterfaceNodeConfigScreen.java @@ -2,12 +2,11 @@ import io.github.mattidragon.advancednetworking.client.mixin.CheckboxWidgetAccess; import io.github.mattidragon.advancednetworking.graph.node.base.InterfaceNode; -import io.github.mattidragon.advancednetworking.misc.RequestInterfacesPacket; +import io.github.mattidragon.advancednetworking.misc.RequestInterfacesPayload; import io.github.mattidragon.nodeflow.client.ui.screen.EditorScreen; import io.github.mattidragon.nodeflow.client.ui.screen.HandledEditorScreen; import io.github.mattidragon.nodeflow.client.ui.screen.NodeConfigScreen; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Element; @@ -35,10 +34,7 @@ protected void init() { parent.syncGraph(); interfaceList = addDrawableChild(new InterfaceList(client, width, height)); - - var buf = PacketByteBufs.create(); - buf.writeByte(((HandledEditorScreen) parent).getScreenHandler().syncId); - ClientPlayNetworking.send(RequestInterfacesPacket.ID, buf); + ClientPlayNetworking.send(new RequestInterfacesPayload(((HandledEditorScreen) parent).getScreenHandler().syncId)); } public void setInterfaces(Map interfaces, Map> groups) { @@ -116,7 +112,6 @@ public String getName() { private class InterfaceList extends ElementListWidget { public InterfaceList(MinecraftClient minecraftClient, int screenWidth, int screenHeight) { super(minecraftClient, 150, screenHeight - 50, 30, 25); - setRenderBackground(false); setX(((screenWidth - 200) / 2) - this.width / 2); @@ -124,10 +119,20 @@ public InterfaceList(MinecraftClient minecraftClient, int screenWidth, int scree } @Override - protected int getScrollbarPositionX() { + protected int getScrollbarX() { return getX() + width; } + + @Override + protected void drawHeaderAndFooterSeparators(DrawContext context) { + // Overridden to disable background + } + @Override + protected void drawMenuListBackground(DrawContext context) { + // Overridden to disable background + } + @Override public int getRowWidth() { return width; diff --git a/src/main/generated/data/advanced_networking/advancements/recipes/misc/compound.json b/src/main/generated/data/advanced_networking/advancements/recipes/misc/compound.json index 5706094..2677831 100644 --- a/src/main/generated/data/advanced_networking/advancements/recipes/misc/compound.json +++ b/src/main/generated/data/advanced_networking/advancements/recipes/misc/compound.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "minecraft:amethyst_shard" - ] + "items": "minecraft:amethyst_shard" } ] }, @@ -17,9 +15,7 @@ "conditions": { "items": [ { - "items": [ - "advanced_networking:compound" - ] + "items": "advanced_networking:compound" } ] }, diff --git a/src/main/generated/data/advanced_networking/advancements/recipes/redstone/cable.json b/src/main/generated/data/advanced_networking/advancements/recipes/redstone/cable.json index 23f39ca..ad22784 100644 --- a/src/main/generated/data/advanced_networking/advancements/recipes/redstone/cable.json +++ b/src/main/generated/data/advanced_networking/advancements/recipes/redstone/cable.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "advanced_networking:cable" - ] + "items": "advanced_networking:cable" } ] }, @@ -17,9 +15,7 @@ "conditions": { "items": [ { - "items": [ - "advanced_networking:compound" - ] + "items": "advanced_networking:compound" } ] }, diff --git a/src/main/generated/data/advanced_networking/advancements/recipes/redstone/controller.json b/src/main/generated/data/advanced_networking/advancements/recipes/redstone/controller.json index be5b0b8..85fb2bd 100644 --- a/src/main/generated/data/advanced_networking/advancements/recipes/redstone/controller.json +++ b/src/main/generated/data/advanced_networking/advancements/recipes/redstone/controller.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "advanced_networking:compound" - ] + "items": "advanced_networking:compound" } ] }, @@ -17,9 +15,7 @@ "conditions": { "items": [ { - "items": [ - "advanced_networking:controller" - ] + "items": "advanced_networking:controller" } ] }, diff --git a/src/main/generated/data/advanced_networking/recipes/cable.json b/src/main/generated/data/advanced_networking/recipes/cable.json index 6d173a1..677d256 100644 --- a/src/main/generated/data/advanced_networking/recipes/cable.json +++ b/src/main/generated/data/advanced_networking/recipes/cable.json @@ -11,6 +11,6 @@ ], "result": { "count": 8, - "item": "advanced_networking:cable" + "id": "advanced_networking:cable" } } \ No newline at end of file diff --git a/src/main/generated/data/advanced_networking/recipes/compound.json b/src/main/generated/data/advanced_networking/recipes/compound.json index 7b8668d..19be579 100644 --- a/src/main/generated/data/advanced_networking/recipes/compound.json +++ b/src/main/generated/data/advanced_networking/recipes/compound.json @@ -13,6 +13,7 @@ } ], "result": { - "item": "advanced_networking:compound" + "count": 1, + "id": "advanced_networking:compound" } } \ No newline at end of file diff --git a/src/main/generated/data/advanced_networking/recipes/controller.json b/src/main/generated/data/advanced_networking/recipes/controller.json index abec172..3e0a8d3 100644 --- a/src/main/generated/data/advanced_networking/recipes/controller.json +++ b/src/main/generated/data/advanced_networking/recipes/controller.json @@ -18,6 +18,7 @@ "I#I" ], "result": { - "item": "advanced_networking:controller" + "count": 1, + "id": "advanced_networking:controller" } } \ No newline at end of file diff --git a/src/main/generated/data/advanced_networking/tags/items/wrenches.json b/src/main/generated/data/advanced_networking/tags/items/wrenches.json index 6c9dfcd..6b2a013 100644 --- a/src/main/generated/data/advanced_networking/tags/items/wrenches.json +++ b/src/main/generated/data/advanced_networking/tags/items/wrenches.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ { "id": "#c:wrenches", diff --git a/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/energy.json b/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/energy.json index 79407bd..24f305a 100644 --- a/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/energy.json +++ b/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/energy.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "advanced_networking:energy_source", "advanced_networking:energy_target", diff --git a/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/fluid.json b/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/fluid.json index 4983166..2217f05 100644 --- a/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/fluid.json +++ b/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/fluid.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "advanced_networking:fluid_source", "advanced_networking:fluid_target", diff --git a/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/item.json b/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/item.json index 355161e..850d23d 100644 --- a/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/item.json +++ b/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/item.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "advanced_networking:item_source", "advanced_networking:item_target", diff --git a/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/redstone.json b/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/redstone.json index e4a099b..7d45b3e 100644 --- a/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/redstone.json +++ b/src/main/generated/data/advanced_networking/tags/nodeflow/node_type/redstone.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "advanced_networking:read_redstone", "advanced_networking:write_redstone", diff --git a/src/main/generated/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/main/generated/data/minecraft/tags/blocks/mineable/pickaxe.json index d574d4e..355efa7 100644 --- a/src/main/generated/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/main/generated/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "advanced_networking:cable", "advanced_networking:controller" diff --git a/src/main/java/io/github/mattidragon/advancednetworking/AdvancedNetworking.java b/src/main/java/io/github/mattidragon/advancednetworking/AdvancedNetworking.java index 23cc2b3..17e35e6 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/AdvancedNetworking.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/AdvancedNetworking.java @@ -4,7 +4,7 @@ import io.github.mattidragon.advancednetworking.graph.ModDataTypes; import io.github.mattidragon.advancednetworking.graph.ModNodeTypes; import io.github.mattidragon.advancednetworking.graph.NetworkControllerContext; -import io.github.mattidragon.advancednetworking.misc.RequestInterfacesPacket; +import io.github.mattidragon.advancednetworking.misc.RequestInterfacesPayload; import io.github.mattidragon.advancednetworking.misc.ScreenPosSyncPacket; import io.github.mattidragon.advancednetworking.misc.SetAdventureModeAccessPacket; import io.github.mattidragon.advancednetworking.misc.UpdateInterfacePacket; @@ -12,6 +12,7 @@ import io.github.mattidragon.advancednetworking.registry.ModBlocks; import io.github.mattidragon.advancednetworking.registry.ModItems; import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandler; +import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandlerPayload; import io.github.mattidragon.configloader.api.ConfigManager; import io.github.mattidragon.nodeflow.graph.GraphEnvironment; import io.github.mattidragon.nodeflow.graph.context.ContextType; @@ -32,7 +33,8 @@ public class AdvancedNetworking implements ModInitializer { public static final String MOD_ID = "advanced_networking"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final ConfigManager CONFIG = ConfigManager.create(ConfigData.CODEC, ConfigData.DEFAULT, MOD_ID); - public static final ExtendedScreenHandlerType CONTROLLER_SCREEN = new ExtendedScreenHandlerType<>(ControllerScreenHandler::new); + public static final ExtendedScreenHandlerType CONTROLLER_SCREEN + = new ExtendedScreenHandlerType<>(ControllerScreenHandler::new, ControllerScreenHandlerPayload.CODEC); public static final GraphEnvironment ENVIRONMENT = GraphEnvironment.builder() .addContextTypes(ContextType.SERVER_WORLD, ContextType.BLOCK_POS, ContextType.SERVER, NetworkControllerContext.TYPE) .addDataTypes(DataType.BOOLEAN, DataType.NUMBER, ModDataTypes.ITEM_STREAM, ModDataTypes.FLUID_STREAM, ModDataTypes.ENERGY_STREAM) @@ -65,7 +67,7 @@ public void onInitialize() { NetworkRegistry.register(); ScreenPosSyncPacket.register(); UpdateInterfacePacket.register(); - RequestInterfacesPacket.register(); + RequestInterfacesPayload.register(); SetAdventureModeAccessPacket.register(); NetworkControllerContext.register(); } diff --git a/src/main/java/io/github/mattidragon/advancednetworking/block/CableBlock.java b/src/main/java/io/github/mattidragon/advancednetworking/block/CableBlock.java index 6c2cf7d..3830092 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/block/CableBlock.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/block/CableBlock.java @@ -17,13 +17,11 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; import net.minecraft.server.world.ServerWorld; import net.minecraft.state.StateManager; import net.minecraft.state.property.EnumProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.StringIdentifiable; -import net.minecraft.util.Util; +import net.minecraft.util.*; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -43,8 +41,6 @@ import java.util.Map; import java.util.stream.Collectors; -// Mojank -@SuppressWarnings("deprecation") public class CableBlock extends BlockWithEntity { public static final EnumProperty NORTH = EnumProperty.of("north", ConnectionType.class); public static final EnumProperty EAST = EnumProperty.of("east", ConnectionType.class); @@ -201,7 +197,7 @@ protected void appendProperties(StateManager.Builder builder) @Override public void prepare(BlockState state, WorldAccess world, BlockPos pos, int flags, int maxUpdateDepth) { if (world instanceof ServerWorld serverWorld) { - NetworkRegistry.UNIVERSE.getServerGraphWorld(serverWorld).updateNodes(pos); + NetworkRegistry.UNIVERSE.getGraphWorld(serverWorld).updateNodes(pos); } // Zero power for non-interface faces to be safe @@ -238,27 +234,34 @@ public static void changeMode(World world, BlockState state, BlockPos pos, Direc } if (world instanceof ServerWorld serverWorld) - NetworkRegistry.UNIVERSE.getServerGraphWorld(serverWorld).updateConnections(pos); + NetworkRegistry.UNIVERSE.getGraphWorld(serverWorld).updateConnections(pos); } @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (!(world.getBlockEntity(pos) instanceof CableBlockEntity cable)) return ActionResult.PASS; - if (!player.getAbilities().allowModifyWorld && !cable.isAdventureModeAccessAllowed()) return ActionResult.PASS; - + protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { var direction = calcHitDirection(hit.getPos().subtract(Vec3d.of(pos))); var property = FACING_PROPERTIES.get(direction); - - if (player.getStackInHand(hand).isIn(ModTags.Items.WRENCHES)) { + + if (stack.isIn(ModTags.Items.WRENCHES)) { changeMode(world, state, pos, direction, switch (state.get(property)) { case NONE -> InterfaceType.INTERFACE; case DISABLED -> InterfaceType.DEFAULT; case INTERFACE, INTERFACE_POWERED, CONNECTED -> InterfaceType.BLOCKED; }); - return ActionResult.SUCCESS; + return ItemActionResult.success(world.isClient); } - if (hand == Hand.MAIN_HAND && player.isSneaking()) { + return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + } + + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + if (!(world.getBlockEntity(pos) instanceof CableBlockEntity cable)) return ActionResult.PASS; + if (!player.getAbilities().allowModifyWorld && !cable.isAdventureModeAccessAllowed()) return ActionResult.PASS; + + var direction = calcHitDirection(hit.getPos().subtract(Vec3d.of(pos))); + + if (player.isSneaking()) { ((ClientScreenOpener)player).advancednetworking$openCableConfigScreen( pos.toImmutable(), direction, diff --git a/src/main/java/io/github/mattidragon/advancednetworking/block/CableBlockEntity.java b/src/main/java/io/github/mattidragon/advancednetworking/block/CableBlockEntity.java index f87c630..9abecca 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/block/CableBlockEntity.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/block/CableBlockEntity.java @@ -10,6 +10,7 @@ import net.minecraft.network.listener.ClientPlayPacketListener; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.Nameable; @@ -86,13 +87,13 @@ public Packet toUpdatePacket() { } @Override - public NbtCompound toInitialChunkDataNbt() { - return createNbt(); + public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryLookup) { + return createNbt(registryLookup); } @Override - public void readNbt(NbtCompound nbt) { - super.readNbt(nbt); + public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + super.readNbt(nbt, registryLookup); var power = nbt.getIntArray("power"); System.arraycopy(power, 0, this.power, 0, Math.min(power.length, 6)); allowAdventureModeAccess = nbt.getBoolean("allowAdventureModeAccess"); @@ -109,8 +110,8 @@ public void readNbt(NbtCompound nbt) { } @Override - protected void writeNbt(NbtCompound nbt) { - super.writeNbt(nbt); + protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + super.writeNbt(nbt, registryLookup); nbt.putIntArray("power", power); nbt.putBoolean("allowAdventureModeAccess", allowAdventureModeAccess); @@ -133,5 +134,6 @@ public boolean isAdventureModeAccessAllowed() { public void setAdventureModeAccessAllowed(boolean allowed) { this.allowAdventureModeAccess = allowed; + markDirty(); } } diff --git a/src/main/java/io/github/mattidragon/advancednetworking/block/ControllerBlock.java b/src/main/java/io/github/mattidragon/advancednetworking/block/ControllerBlock.java index f51ca50..ebde89e 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/block/ControllerBlock.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/block/ControllerBlock.java @@ -16,7 +16,6 @@ import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.Properties; import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; @@ -24,7 +23,6 @@ import net.minecraft.world.WorldAccess; import org.jetbrains.annotations.Nullable; -@SuppressWarnings("deprecation") public class ControllerBlock extends BlockWithEntity { public static final BooleanProperty POWERED = Properties.POWERED; public static final BooleanProperty SUCCESS = BooleanProperty.of("success"); @@ -94,7 +92,7 @@ public BlockRenderType getRenderType(BlockState state) { } @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { if (!(world.getBlockEntity(pos) instanceof ControllerBlockEntity controller)) return ActionResult.PASS; if (!controller.isAdventureModeAccessAllowed() && !player.getAbilities().allowModifyWorld) return ActionResult.PASS; if (world.isClient) return ActionResult.SUCCESS; @@ -109,7 +107,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt @Override public void prepare(BlockState state, WorldAccess world, BlockPos pos, int flags, int maxUpdateDepth) { if (world instanceof ServerWorld serverWorld) { - NetworkRegistry.UNIVERSE.getServerGraphWorld(serverWorld).updateNodes(pos); + NetworkRegistry.UNIVERSE.getGraphWorld(serverWorld).updateNodes(pos); } } } diff --git a/src/main/java/io/github/mattidragon/advancednetworking/block/ControllerBlockEntity.java b/src/main/java/io/github/mattidragon/advancednetworking/block/ControllerBlockEntity.java index d8a3db2..bc2c65d 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/block/ControllerBlockEntity.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/block/ControllerBlockEntity.java @@ -13,21 +13,24 @@ import io.github.mattidragon.advancednetworking.network.node.ControllerNode; import io.github.mattidragon.advancednetworking.registry.ModBlocks; import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandler; +import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandlerPayload; import io.github.mattidragon.nodeflow.graph.Graph; import io.github.mattidragon.nodeflow.graph.context.Context; import io.github.mattidragon.nodeflow.graph.context.ContextType; import io.github.mattidragon.nodeflow.misc.EvaluationError; -import io.github.mattidragon.nodeflow.misc.GraphProvidingBlockEntity; +import io.github.mattidragon.nodeflow.misc.GraphProvider; +import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.server.network.ServerPlayerEntity; @@ -43,7 +46,7 @@ import java.util.Optional; import java.util.function.Function; -public class ControllerBlockEntity extends GraphProvidingBlockEntity implements AdventureModeAccessBlockEntity { +public class ControllerBlockEntity extends BlockEntity implements AdventureModeAccessBlockEntity, GraphProvider, ExtendedScreenHandlerFactory { private Graph graph = new Graph(AdvancedNetworking.ENVIRONMENT); private boolean allowAdventureModeAccess = false; @@ -66,8 +69,8 @@ public Text getDisplayName() { } @Override - public void readNbt(NbtCompound nbt) { - super.readNbt(nbt); + public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + super.readNbt(nbt, registryLookup); allowAdventureModeAccess = nbt.getBoolean("allowAdventureModeAccess"); viewX = nbt.getDouble("viewX"); viewY = nbt.getDouble("viewY"); @@ -75,14 +78,14 @@ public void readNbt(NbtCompound nbt) { graph.readNbt(nbt.getCompound("graph")); errors = NbtUtils.readStrings(nbt, "errors").stream() - .map((Function>) json -> Optional.ofNullable(Text.Serialization.fromJson(json))) + .map((Function>) json -> Optional.ofNullable(Text.Serialization.fromJson(json, registryLookup))) .flatMap(Optional::stream) .toList(); } @Override - protected void writeNbt(NbtCompound nbt) { - super.writeNbt(nbt); + protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + super.writeNbt(nbt, registryLookup); nbt.putBoolean("allowAdventureModeAccess", allowAdventureModeAccess); nbt.putDouble("viewX", viewX); nbt.putDouble("viewY", viewY); @@ -91,7 +94,7 @@ protected void writeNbt(NbtCompound nbt) { var graphNbt = new NbtCompound(); graph.writeNbt(graphNbt); nbt.put("graph", graphNbt); - NbtUtils.writeStrings(nbt, "errors", errors.stream().map(Text.Serialization::toJsonString).toList()); + NbtUtils.writeStrings(nbt, "errors", errors.stream().map(text -> Text.Serialization.toJsonString(text, registryLookup)).toList()); } public static void tick(World world, BlockPos pos, BlockState state, ControllerBlockEntity controller) { @@ -128,7 +131,7 @@ public static void tick(World world, BlockPos pos, BlockState state, ControllerB public List evaluate() { if (world == null) return List.of(EvaluationError.Type.MISSING_CONTEXTS.error("World missing (something went very wrong)")); - var graph = NetworkRegistry.UNIVERSE.getServerGraphWorld((ServerWorld) world).getGraphForNode(new NodePos(pos, ControllerNode.INSTANCE)); + var graph = NetworkRegistry.UNIVERSE.getGraphWorld((ServerWorld) world).getGraphForNode(new NodePos(pos, ControllerNode.INSTANCE)); if (graph == null) { AdvancedNetworking.LOGGER.warn("Controller missing graph at {}", pos); return List.of(EvaluationError.Type.MISSING_CONTEXTS.error("Controller missing")); @@ -143,13 +146,8 @@ public List evaluate() { } @Override - public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) { - super.writeScreenOpeningData(player, buf); - buf.writeInt(zoom); - buf.writeDouble(viewX); - buf.writeDouble(viewY); - buf.writeCollection(errors, PacketByteBuf::writeText); - buf.writeBoolean(allowAdventureModeAccess); + public ControllerScreenHandlerPayload getScreenOpeningData(ServerPlayerEntity player) { + return new ControllerScreenHandlerPayload(graph, allowAdventureModeAccess, viewX, viewY, zoom, errors); } @Override diff --git a/src/main/java/io/github/mattidragon/advancednetworking/config/ConfigData.java b/src/main/java/io/github/mattidragon/advancednetworking/config/ConfigData.java index b3ac556..29c1bd8 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/config/ConfigData.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/config/ConfigData.java @@ -3,7 +3,7 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; -import io.github.mattidragon.configloader.api.DefaultedFieldCodec; +import io.github.mattidragon.configloader.api.AlwaysSerializedOptionalFieldCodec; import io.github.mattidragon.configloader.api.GenerateMutable; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; @@ -13,12 +13,12 @@ public record ConfigData(int controllerTickRate, long controllerFluidTransferRate, long controllerItemTransferRate, long controllerEnergyTransferRate, boolean disableRegexFilter, boolean showAdventureModeToggles) implements MutableConfigData.Source { public static final ConfigData DEFAULT = new ConfigData(10, FluidConstants.BUCKET, 64, 256, false, false); public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - DefaultedFieldCodec.of(Codec.intRange(0, 120), "controller_tick_rate", DEFAULT.controllerTickRate).forGetter(ConfigData::controllerTickRate), - DefaultedFieldCodec.of(longRange(FluidConstants.BUCKET * 100), "controller_fluid_transfer_rate", DEFAULT.controllerFluidTransferRate).forGetter(ConfigData::controllerFluidTransferRate), - DefaultedFieldCodec.of(longRange(64 * 10), "controller_item_transfer_rate", DEFAULT.controllerItemTransferRate).forGetter(ConfigData::controllerItemTransferRate), - DefaultedFieldCodec.of(longRange(256 * 100), "controller_energy_transfer_rate", DEFAULT.controllerEnergyTransferRate).forGetter(ConfigData::controllerEnergyTransferRate), - DefaultedFieldCodec.of(Codec.BOOL, "disable_regex_filtering", DEFAULT.disableRegexFilter).forGetter(ConfigData::disableRegexFilter), - DefaultedFieldCodec.of(Codec.BOOL, "show_adventure_mode_toggles", DEFAULT.showAdventureModeToggles).forGetter(ConfigData::showAdventureModeToggles) + AlwaysSerializedOptionalFieldCodec.create(Codec.intRange(0, 120), "controller_tick_rate", DEFAULT.controllerTickRate).forGetter(ConfigData::controllerTickRate), + AlwaysSerializedOptionalFieldCodec.create(longRange(FluidConstants.BUCKET * 100), "controller_fluid_transfer_rate", DEFAULT.controllerFluidTransferRate).forGetter(ConfigData::controllerFluidTransferRate), + AlwaysSerializedOptionalFieldCodec.create(longRange(64 * 10), "controller_item_transfer_rate", DEFAULT.controllerItemTransferRate).forGetter(ConfigData::controllerItemTransferRate), + AlwaysSerializedOptionalFieldCodec.create(longRange(256 * 100), "controller_energy_transfer_rate", DEFAULT.controllerEnergyTransferRate).forGetter(ConfigData::controllerEnergyTransferRate), + AlwaysSerializedOptionalFieldCodec.create(Codec.BOOL, "disable_regex_filtering", DEFAULT.disableRegexFilter).forGetter(ConfigData::disableRegexFilter), + AlwaysSerializedOptionalFieldCodec.create(Codec.BOOL, "show_adventure_mode_toggles", DEFAULT.showAdventureModeToggles).forGetter(ConfigData::showAdventureModeToggles) ).apply(instance, ConfigData::new)); private static Codec longRange(long maxInclusive) { diff --git a/src/main/java/io/github/mattidragon/advancednetworking/datagen/BlockLootTableProvider.java b/src/main/java/io/github/mattidragon/advancednetworking/datagen/BlockLootTableProvider.java index 2fefef7..108b5ca 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/datagen/BlockLootTableProvider.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/datagen/BlockLootTableProvider.java @@ -3,10 +3,13 @@ import io.github.mattidragon.advancednetworking.registry.ModBlocks; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider; +import net.minecraft.registry.RegistryWrapper; + +import java.util.concurrent.CompletableFuture; public class BlockLootTableProvider extends FabricBlockLootTableProvider { - public BlockLootTableProvider(FabricDataOutput output) { - super(output); + public BlockLootTableProvider(FabricDataOutput dataOutput, CompletableFuture registryLookup) { + super(dataOutput, registryLookup); } @Override diff --git a/src/main/java/io/github/mattidragon/advancednetworking/datagen/RecipeProvider.java b/src/main/java/io/github/mattidragon/advancednetworking/datagen/RecipeProvider.java index 84c51a6..ae07f57 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/datagen/RecipeProvider.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/datagen/RecipeProvider.java @@ -8,11 +8,14 @@ import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder; import net.minecraft.item.Items; import net.minecraft.recipe.book.RecipeCategory; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.tag.ItemTags; +import java.util.concurrent.CompletableFuture; + public class RecipeProvider extends FabricRecipeProvider { - public RecipeProvider(FabricDataOutput output) { - super(output); + public RecipeProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + super(output, registriesFuture); } @Override diff --git a/src/main/java/io/github/mattidragon/advancednetworking/graph/node/base/InterfaceNode.java b/src/main/java/io/github/mattidragon/advancednetworking/graph/node/base/InterfaceNode.java index d47dcde..ec33e85 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/graph/node/base/InterfaceNode.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/graph/node/base/InterfaceNode.java @@ -24,7 +24,7 @@ protected InterfaceNode(NodeType type, List> contexts, Graph g } protected final List findInterfaces(ServerWorld world, long graphId) { - var graph = NetworkRegistry.UNIVERSE.getServerGraphWorld(world).getGraph(graphId); + var graph = NetworkRegistry.UNIVERSE.getGraphWorld(world).getGraph(graphId); if (graph == null) return List.of(); diff --git a/src/main/java/io/github/mattidragon/advancednetworking/graph/path/PathEnvironment.java b/src/main/java/io/github/mattidragon/advancednetworking/graph/path/PathEnvironment.java index ef23b7d..6720a01 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/graph/path/PathEnvironment.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/graph/path/PathEnvironment.java @@ -58,7 +58,7 @@ private boolean trySort() { var readyForSort = findSortable(unsortedPhases); while (!readyForSort.isEmpty()) { - var entry = readyForSort.remove(0); + var entry = readyForSort.removeFirst(); paths.add(entry.getValue()); markers: diff --git a/src/main/java/io/github/mattidragon/advancednetworking/misc/InterfaceType.java b/src/main/java/io/github/mattidragon/advancednetworking/misc/InterfaceType.java index f6e36cf..06858ee 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/misc/InterfaceType.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/misc/InterfaceType.java @@ -1,12 +1,20 @@ package io.github.mattidragon.advancednetworking.misc; import io.github.mattidragon.advancednetworking.block.CableBlock; +import io.netty.buffer.ByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.util.function.ValueLists; public enum InterfaceType { INTERFACE("interface"), BLOCKED("blocked"), DEFAULT("default"); + public static final PacketCodec PACKET_CODEC = PacketCodecs.indexed(ValueLists.createIdToValueFunction( + InterfaceType::ordinal, values(), ValueLists.OutOfBoundsHandling.WRAP + ), InterfaceType::ordinal); + public final String id; InterfaceType(String id) { diff --git a/src/main/java/io/github/mattidragon/advancednetworking/misc/RequestInterfacesPacket.java b/src/main/java/io/github/mattidragon/advancednetworking/misc/RequestInterfacesPacket.java deleted file mode 100644 index e348fdd..0000000 --- a/src/main/java/io/github/mattidragon/advancednetworking/misc/RequestInterfacesPacket.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.mattidragon.advancednetworking.misc; - -import io.github.mattidragon.advancednetworking.AdvancedNetworking; -import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandler; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; - -import java.util.List; -import java.util.Map; - -import static io.github.mattidragon.advancednetworking.AdvancedNetworking.id; - -public class RequestInterfacesPacket { - public static final Identifier ID = id("request_interfaces"); - public static final Identifier RESPONSE_ID = id("request_interfaces_response"); - - public static void register() { - ServerPlayNetworking.registerGlobalReceiver(ID, (server, player, handler, buf, responseSender) -> { - var syncId = buf.readByte(); - - server.execute(() -> { - if (player.currentScreenHandler.syncId == syncId && player.currentScreenHandler instanceof ControllerScreenHandler controllerScreenHandler) { - var interfaces = controllerScreenHandler.getInterfaces(); - if (interfaces.isEmpty()) { - AdvancedNetworking.LOGGER.warn("Failed to get interfaces for client, sending empty map"); - respond(Map.of(), Map.of(), syncId, responseSender); - return; - } - var pair = interfaces.get(); - respond(pair.getLeft(), pair.getRight(), syncId, responseSender); - } - }); - }); - } - - private static void respond(Map interfaces, Map> groups, int syncId, PacketSender responseSender) { - var buf = PacketByteBufs.create(); - buf.writeByte(syncId); - buf.writeMap(interfaces, PacketByteBuf::writeString, PacketByteBuf::writeText); - buf.writeMap(groups, PacketByteBuf::writeString, (buf1, list) -> buf1.writeCollection(list, PacketByteBuf::writeString)); - - responseSender.sendPacket(RESPONSE_ID, buf); - } - -} \ No newline at end of file diff --git a/src/main/java/io/github/mattidragon/advancednetworking/misc/RequestInterfacesPayload.java b/src/main/java/io/github/mattidragon/advancednetworking/misc/RequestInterfacesPayload.java new file mode 100644 index 0000000..57dc77f --- /dev/null +++ b/src/main/java/io/github/mattidragon/advancednetworking/misc/RequestInterfacesPayload.java @@ -0,0 +1,64 @@ +package io.github.mattidragon.advancednetworking.misc; + +import io.github.mattidragon.advancednetworking.AdvancedNetworking; +import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandler; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.text.Text; +import net.minecraft.text.TextCodecs; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public record RequestInterfacesPayload(int syncId) implements CustomPayload { + public static final Id ID = new Id<>(AdvancedNetworking.id("request_interfaces")); + public static final PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, RequestInterfacesPayload::syncId, RequestInterfacesPayload::new); + + @Override + public Id getId() { + return ID; + } + + public static void register() { + PayloadTypeRegistry.playC2S().register(ID, CODEC); + PayloadTypeRegistry.playS2C().register(Response.ID, Response.CODEC); + + ServerPlayNetworking.registerGlobalReceiver(ID, (packet, context) -> { + var syncId = packet.syncId(); + var screenHandler = context.player().currentScreenHandler; + + if (screenHandler.syncId == syncId && screenHandler instanceof ControllerScreenHandler controllerScreenHandler) { + var interfaces = controllerScreenHandler.getInterfaces(); + if (interfaces.isEmpty()) { + AdvancedNetworking.LOGGER.warn("Failed to get interfaces for client, sending empty map"); + context.responseSender().sendPacket(new Response(Map.of(), Map.of(), syncId)); + return; + } + var pair = interfaces.get(); + Map interfaces1 = pair.getLeft(); + Map> groups = pair.getRight(); + context.responseSender().sendPacket(new Response(interfaces1, groups, syncId)); + } + }); + } + + public record Response(Map interfaces, Map> groups, int syncId) implements CustomPayload { + public static final Id ID = new Id<>(AdvancedNetworking.id("request_interfaces_response")); + public static final PacketCodec CODEC = PacketCodec.tuple( + PacketCodecs.map(HashMap::new, PacketCodecs.STRING, TextCodecs.PACKET_CODEC), Response::interfaces, + PacketCodecs.map(HashMap::new, PacketCodecs.STRING, PacketCodecs.STRING.collect(PacketCodecs.toList())), Response::groups, + PacketCodecs.VAR_INT, Response::syncId, + Response::new + ); + + @Override + public Id getId() { + return ID; + } + } +} \ No newline at end of file diff --git a/src/main/java/io/github/mattidragon/advancednetworking/misc/ResourceFilter.java b/src/main/java/io/github/mattidragon/advancednetworking/misc/ResourceFilter.java index 025cc3f..a240b76 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/misc/ResourceFilter.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/misc/ResourceFilter.java @@ -5,8 +5,10 @@ import io.github.mattidragon.advancednetworking.AdvancedNetworking; import net.fabricmc.fabric.api.transfer.v1.storage.TransferVariant; import net.minecraft.command.argument.NbtPathArgumentType; +import net.minecraft.component.ComponentChanges; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtOps; import net.minecraft.registry.Registry; import net.minecraft.registry.tag.TagKey; import net.minecraft.text.Text; @@ -45,9 +47,9 @@ public List validate() { list.add(Text.translatable("node.advanced_networking.filter.invalid_id", idFilter)); } else { if (mode == Mode.RESOURCE && !registry.containsId(id)) - list.add(Text.translatable("node.advanced_networking.filter.unknown_resource", id)); + list.add(Text.translatable("node.advanced_networking.filter.unknown_resource", id.toString())); if (mode == Mode.TAG && registry.streamTags().map(TagKey::id).noneMatch(id::equals)) - list.add(Text.translatable("node.advanced_networking.filter.unknown_tag", id)); + list.add(Text.translatable("node.advanced_networking.filter.unknown_tag", id.toString())); } } } @@ -76,7 +78,7 @@ public boolean isAllowed(V resource) { .map(TagKey::id) .anyMatch(this::checkId); }; - var nbtMatches = nbtPath == null || nbtPath.count(resource.getNbt()) > 0; + var nbtMatches = nbtPath == null || nbtPath.count(ComponentChanges.CODEC.encodeStart(NbtOps.INSTANCE, resource.getComponents()).result().orElseGet(NbtCompound::new)) > 0; var matches = idMatches && nbtMatches; if (isWhitelist) { diff --git a/src/main/java/io/github/mattidragon/advancednetworking/misc/ScreenPosSyncPacket.java b/src/main/java/io/github/mattidragon/advancednetworking/misc/ScreenPosSyncPacket.java index e91693e..0406e8a 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/misc/ScreenPosSyncPacket.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/misc/ScreenPosSyncPacket.java @@ -1,25 +1,29 @@ package io.github.mattidragon.advancednetworking.misc; +import io.github.mattidragon.advancednetworking.AdvancedNetworking; import io.github.mattidragon.advancednetworking.screen.ControllerScreenHandler; -import net.fabricmc.fabric.api.networking.v1.FabricPacket; -import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.network.packet.CustomPayload; -import static io.github.mattidragon.advancednetworking.AdvancedNetworking.id; - -public record ScreenPosSyncPacket(int syncId, double x, double y, int zoom) implements FabricPacket { - private static final Identifier ID = id("pos_sync"); - private static final PacketType TYPE = PacketType.create(ID, ScreenPosSyncPacket::new); - - public ScreenPosSyncPacket(PacketByteBuf buf) { - this(buf.readByte(), buf.readDouble(), buf.readDouble(), buf.readInt()); - } +public record ScreenPosSyncPacket(int syncId, double x, double y, int zoom) implements CustomPayload { + private static final Id ID = new Id<>(AdvancedNetworking.id("pos_sync")); + public static final PacketCodec CODEC = PacketCodec.tuple( + PacketCodecs.VAR_INT, ScreenPosSyncPacket::syncId, + PacketCodecs.DOUBLE, ScreenPosSyncPacket::x, + PacketCodecs.DOUBLE, ScreenPosSyncPacket::y, + PacketCodecs.VAR_INT, ScreenPosSyncPacket::zoom, + ScreenPosSyncPacket::new + ); public static void register() { - ServerPlayNetworking.registerGlobalReceiver(TYPE, (packet, player, responseSender) -> { - if (player.currentScreenHandler.syncId == packet.syncId && player.currentScreenHandler instanceof ControllerScreenHandler networking) { + PayloadTypeRegistry.playC2S().register(ID, CODEC); + ServerPlayNetworking.registerGlobalReceiver(ID, (packet, context) -> { + var currentScreenHandler = context.player().currentScreenHandler; + if (currentScreenHandler.syncId == packet.syncId && currentScreenHandler instanceof ControllerScreenHandler networking) { networking.viewX = packet.x; networking.viewY = packet.y; networking.zoom = packet.zoom; @@ -28,15 +32,7 @@ public static void register() { } @Override - public void write(PacketByteBuf buf) { - buf.writeByte(syncId); - buf.writeDouble(x); - buf.writeDouble(y); - buf.writeInt(zoom); - } - - @Override - public PacketType getType() { - return TYPE; + public Id getId() { + return ID; } } \ No newline at end of file diff --git a/src/main/java/io/github/mattidragon/advancednetworking/misc/SetAdventureModeAccessPacket.java b/src/main/java/io/github/mattidragon/advancednetworking/misc/SetAdventureModeAccessPacket.java index 5df1c38..19ce1fe 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/misc/SetAdventureModeAccessPacket.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/misc/SetAdventureModeAccessPacket.java @@ -1,25 +1,27 @@ package io.github.mattidragon.advancednetworking.misc; +import io.github.mattidragon.advancednetworking.AdvancedNetworking; import io.github.mattidragon.advancednetworking.block.AdventureModeAccessBlockEntity; -import net.fabricmc.fabric.api.networking.v1.FabricPacket; -import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.network.packet.CustomPayload; import net.minecraft.util.math.BlockPos; -import static io.github.mattidragon.advancednetworking.AdvancedNetworking.id; - -public record SetAdventureModeAccessPacket(BlockPos pos, boolean allowAccess) implements FabricPacket { - private static final Identifier ID = id("set_adventure_mode_access"); - private static final PacketType TYPE = PacketType.create(ID, SetAdventureModeAccessPacket::new); - - public SetAdventureModeAccessPacket(PacketByteBuf buf) { - this(buf.readBlockPos(), buf.readBoolean()); - } +public record SetAdventureModeAccessPacket(BlockPos pos, boolean allowAccess) implements CustomPayload { + private static final Id ID = new Id<>(AdvancedNetworking.id("set_adventure_mode_access")); + private static final PacketCodec CODEC = PacketCodec.tuple( + BlockPos.PACKET_CODEC, SetAdventureModeAccessPacket::pos, + PacketCodecs.BOOL, SetAdventureModeAccessPacket::allowAccess, + SetAdventureModeAccessPacket::new + ); public static void register() { - ServerPlayNetworking.registerGlobalReceiver(TYPE, (packet, player, responseSender) -> { + PayloadTypeRegistry.playC2S().register(ID, CODEC); + ServerPlayNetworking.registerGlobalReceiver(ID, (packet, context) -> { + var player = context.player(); if (!player.isCreativeLevelTwoOp()) return; var world = player.getWorld(); if (world.getBlockEntity(packet.pos) instanceof AdventureModeAccessBlockEntity blockEntity) { @@ -29,13 +31,7 @@ public static void register() { } @Override - public void write(PacketByteBuf buf) { - buf.writeBlockPos(pos); - buf.writeBoolean(allowAccess); - } - - @Override - public PacketType getType() { - return TYPE; + public Id getId() { + return ID; } } diff --git a/src/main/java/io/github/mattidragon/advancednetworking/misc/UpdateInterfacePacket.java b/src/main/java/io/github/mattidragon/advancednetworking/misc/UpdateInterfacePacket.java index 62be034..0dfce45 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/misc/UpdateInterfacePacket.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/misc/UpdateInterfacePacket.java @@ -1,28 +1,33 @@ package io.github.mattidragon.advancednetworking.misc; +import io.github.mattidragon.advancednetworking.AdvancedNetworking; import io.github.mattidragon.advancednetworking.block.CableBlock; import io.github.mattidragon.advancednetworking.block.CableBlockEntity; import io.github.mattidragon.advancednetworking.registry.ModBlocks; -import net.fabricmc.fabric.api.networking.v1.FabricPacket; -import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.network.packet.CustomPayload; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import static io.github.mattidragon.advancednetworking.AdvancedNetworking.id; - -public record UpdateInterfacePacket(BlockPos pos, Direction side, InterfaceType type, String name, String group) implements FabricPacket { - private static final Identifier ID = id("update_interface"); - private static final PacketType TYPE = PacketType.create(ID, UpdateInterfacePacket::new); - - public UpdateInterfacePacket(PacketByteBuf buf) { - this(buf.readBlockPos(), buf.readEnumConstant(Direction.class), buf.readEnumConstant(InterfaceType.class), buf.readString(), buf.readString()); - } +public record UpdateInterfacePacket(BlockPos pos, Direction side, InterfaceType type, String name, String group) implements CustomPayload { + private static final Id ID = new Id<>(AdvancedNetworking.id("update_interface")); + private static final PacketCodec CODEC = PacketCodec.tuple( + BlockPos.PACKET_CODEC, UpdateInterfacePacket::pos, + Direction.PACKET_CODEC, UpdateInterfacePacket::side, + InterfaceType.PACKET_CODEC, UpdateInterfacePacket::type, + PacketCodecs.STRING, UpdateInterfacePacket::name, + PacketCodecs.STRING, UpdateInterfacePacket::group, + UpdateInterfacePacket::new + ); public static void register() { - ServerPlayNetworking.registerGlobalReceiver(TYPE, (packet, player, responseSender) -> { + PayloadTypeRegistry.playC2S().register(ID, CODEC); + ServerPlayNetworking.registerGlobalReceiver(ID, (packet, context) -> { + var player = context.player(); if (player.squaredDistanceTo(packet.pos.toCenterPos()) > 64.0) return; // Player too far away if (!player.getWorld().getBlockState(packet.pos).isOf(ModBlocks.CABLE)) @@ -37,16 +42,7 @@ public static void register() { } @Override - public void write(PacketByteBuf buf) { - buf.writeBlockPos(pos); - buf.writeEnumConstant(side); - buf.writeEnumConstant(type); - buf.writeString(name); - buf.writeString(group); - } - - @Override - public PacketType getType() { - return TYPE; + public Id getId() { + return ID; } } \ No newline at end of file diff --git a/src/main/java/io/github/mattidragon/advancednetworking/network/node/CableNode.java b/src/main/java/io/github/mattidragon/advancednetworking/network/node/CableNode.java index e9f5e96..63f730b 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/network/node/CableNode.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/network/node/CableNode.java @@ -8,12 +8,10 @@ import com.kneelawk.graphlib.api.wire.WireConnectionDiscoverers; import io.github.mattidragon.advancednetworking.AdvancedNetworking; import io.github.mattidragon.advancednetworking.block.CableBlock; -import net.minecraft.nbt.NbtElement; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class CableNode implements CenterWireBlockNode { public static final Identifier ID = AdvancedNetworking.id("cable"); @@ -27,11 +25,6 @@ private CableNode() {} return TYPE; } - @Override - public @Nullable NbtElement toTag() { - return null; - } - @Override public boolean canConnect(@NotNull NodeHolder self, @NotNull HalfLink other) { return (other.other().getNode() instanceof InterfaceNode && other.other().getPos().equals(self.getPos())) || WireConnectionDiscoverers.centerWireCanConnect(this, self, other); diff --git a/src/main/java/io/github/mattidragon/advancednetworking/network/node/ControllerNode.java b/src/main/java/io/github/mattidragon/advancednetworking/network/node/ControllerNode.java index 91787bd..c7d8ea8 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/network/node/ControllerNode.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/network/node/ControllerNode.java @@ -5,10 +5,8 @@ import com.kneelawk.graphlib.api.graph.user.BlockNodeType; import com.kneelawk.graphlib.api.wire.FullWireBlockNode; import io.github.mattidragon.advancednetworking.AdvancedNetworking; -import net.minecraft.nbt.NbtElement; import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class ControllerNode implements FullWireBlockNode { public static final Identifier ID = AdvancedNetworking.id("controller"); @@ -22,14 +20,8 @@ private ControllerNode() {} return TYPE; } - @Override - public @Nullable NbtElement toTag() { - return null; - } - @Override public void onConnectionsChanged(@NotNull NodeHolder self) { - } @Override diff --git a/src/main/java/io/github/mattidragon/advancednetworking/network/node/InterfaceNode.java b/src/main/java/io/github/mattidragon/advancednetworking/network/node/InterfaceNode.java index 6924422..babbae1 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/network/node/InterfaceNode.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/network/node/InterfaceNode.java @@ -6,16 +6,12 @@ import com.kneelawk.graphlib.api.graph.user.BlockNodeType; import com.kneelawk.graphlib.api.wire.SidedFaceBlockNode; import io.github.mattidragon.advancednetworking.AdvancedNetworking; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; import net.minecraft.util.Identifier; import net.minecraft.util.Util; import net.minecraft.util.math.Direction; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Map; -import java.util.Objects; public class InterfaceNode implements SidedFaceBlockNode { public static final Identifier ID = AdvancedNetworking.id("interface"); @@ -24,9 +20,7 @@ public class InterfaceNode implements SidedFaceBlockNode { builder.put(dir, new InterfaceNode(dir)); } }).build(); - public static final BlockNodeType TYPE = BlockNodeType.of(ID, - tag -> tag == null ? null : InterfaceNode.INSTANCES.get(Direction.byName(((NbtCompound)tag).getString("direction"))), - (buf, ctx) -> Objects.requireNonNull(InterfaceNode.INSTANCES.get(buf.readEnumConstant(Direction.class)))); + public static final BlockNodeType TYPE = BlockNodeType.of(ID, Direction.CODEC.xmap(INSTANCES::get, InterfaceNode::getSide)); private final Direction direction; private InterfaceNode(Direction direction) { @@ -37,17 +31,9 @@ private InterfaceNode(Direction direction) { public @NotNull BlockNodeType getType() { return TYPE; } - - @Override - public @Nullable NbtElement toTag() { - var nbt = new NbtCompound(); - nbt.putString("direction", direction.asString()); - return nbt; - } - + @Override public void onConnectionsChanged(@NotNull NodeHolder self) { - } @Override diff --git a/src/main/java/io/github/mattidragon/advancednetworking/registry/ModBlocks.java b/src/main/java/io/github/mattidragon/advancednetworking/registry/ModBlocks.java index 811b4cc..977677b 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/registry/ModBlocks.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/registry/ModBlocks.java @@ -5,7 +5,7 @@ import io.github.mattidragon.advancednetworking.block.CableBlockEntity; import io.github.mattidragon.advancednetworking.block.ControllerBlock; import io.github.mattidragon.advancednetworking.block.ControllerBlockEntity; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.AbstractBlock; import net.minecraft.block.MapColor; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.enums.Instrument; @@ -13,8 +13,8 @@ import net.minecraft.registry.Registry; public final class ModBlocks { - public static final ControllerBlock CONTROLLER = new ControllerBlock(FabricBlockSettings.create().mapColor(MapColor.IRON_GRAY).instrument(Instrument.BASEDRUM).requiresTool().strength(3.5F)); - public static final CableBlock CABLE = new CableBlock(FabricBlockSettings.create().mapColor(MapColor.DEEPSLATE_GRAY).instrument(Instrument.BASEDRUM).requiresTool().strength(3.5F)); + public static final ControllerBlock CONTROLLER = new ControllerBlock(AbstractBlock.Settings.create().mapColor(MapColor.IRON_GRAY).instrument(Instrument.BASEDRUM).requiresTool().strength(3.5F)); + public static final CableBlock CABLE = new CableBlock(AbstractBlock.Settings.create().mapColor(MapColor.DEEPSLATE_GRAY).instrument(Instrument.BASEDRUM).requiresTool().strength(3.5F)); public static final BlockEntityType CONTROLLER_BLOCK_ENTITY = BlockEntityType.Builder.create(ControllerBlockEntity::new, ModBlocks.CONTROLLER).build(null); public static final BlockEntityType CABLE_BLOCK_ENTITY = BlockEntityType.Builder.create(CableBlockEntity::new, ModBlocks.CABLE).build(null); diff --git a/src/main/java/io/github/mattidragon/advancednetworking/registry/ModItems.java b/src/main/java/io/github/mattidragon/advancednetworking/registry/ModItems.java index abf514d..91423f4 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/registry/ModItems.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/registry/ModItems.java @@ -1,7 +1,6 @@ package io.github.mattidragon.advancednetworking.registry; import io.github.mattidragon.advancednetworking.AdvancedNetworking; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; @@ -11,9 +10,9 @@ import net.minecraft.registry.Registry; public final class ModItems { - public static final BlockItem CONTROLLER = new BlockItem(ModBlocks.CONTROLLER, new FabricItemSettings()); - public static final BlockItem CABLE = new BlockItem(ModBlocks.CABLE, new FabricItemSettings()); - public static final Item COMPOUND = new Item(new FabricItemSettings()); + public static final BlockItem CONTROLLER = new BlockItem(ModBlocks.CONTROLLER, new Item.Settings()); + public static final BlockItem CABLE = new BlockItem(ModBlocks.CABLE, new Item.Settings()); + public static final Item COMPOUND = new Item(new Item.Settings()); private ModItems() { throw new UnsupportedOperationException(); } diff --git a/src/main/java/io/github/mattidragon/advancednetworking/screen/ControllerScreenHandler.java b/src/main/java/io/github/mattidragon/advancednetworking/screen/ControllerScreenHandler.java index d1118df..7a687ba 100644 --- a/src/main/java/io/github/mattidragon/advancednetworking/screen/ControllerScreenHandler.java +++ b/src/main/java/io/github/mattidragon/advancednetworking/screen/ControllerScreenHandler.java @@ -10,7 +10,6 @@ import io.github.mattidragon.nodeflow.screen.EditorScreenHandler; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.network.PacketByteBuf; import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.server.world.ServerWorld; @@ -37,14 +36,14 @@ public ControllerScreenHandler(int syncId, ControllerBlockEntity controller, Scr adventureModeAccessAllowed = controller.isAdventureModeAccessAllowed(); } - public ControllerScreenHandler(int syncId, PlayerInventory inv, PacketByteBuf buf) { - super(syncId, inv, buf); + public ControllerScreenHandler(int syncId, PlayerInventory inv, ControllerScreenHandlerPayload payload) { + super(syncId, inv, payload.graph()); context = ScreenHandlerContext.EMPTY; - zoom = buf.readInt(); - viewX = buf.readDouble(); - viewY = buf.readDouble(); - errors = buf.readList(PacketByteBuf::readText); - adventureModeAccessAllowed = buf.readBoolean(); + zoom = payload.zoom(); + viewX = payload.viewX(); + viewY = payload.viewY(); + errors = payload.errors(); + adventureModeAccessAllowed = payload.adventureModeAccessAllowed(); } @Override @@ -60,7 +59,7 @@ public Optional, Map>>> getInterface if (!(world instanceof ServerWorld serverWorld)) return Optional.empty(); - var graphWorld = NetworkRegistry.UNIVERSE.getServerGraphWorld(serverWorld); + var graphWorld = NetworkRegistry.UNIVERSE.getGraphWorld(serverWorld); var nodes = graphWorld.getLoadedGraphsAt(pos) .flatMap(BlockGraph::getNodes) .toList(); diff --git a/src/main/java/io/github/mattidragon/advancednetworking/screen/ControllerScreenHandlerPayload.java b/src/main/java/io/github/mattidragon/advancednetworking/screen/ControllerScreenHandlerPayload.java new file mode 100644 index 0000000..251f75a --- /dev/null +++ b/src/main/java/io/github/mattidragon/advancednetworking/screen/ControllerScreenHandlerPayload.java @@ -0,0 +1,27 @@ +package io.github.mattidragon.advancednetworking.screen; + +import io.github.mattidragon.nodeflow.graph.Graph; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.text.Text; +import net.minecraft.text.TextCodecs; + +import java.util.List; + +public record ControllerScreenHandlerPayload(Graph graph, + boolean adventureModeAccessAllowed, + double viewX, + double viewY, + int zoom, + List errors) { + public static final PacketCodec CODEC = PacketCodec.tuple( + Graph.PACKET_CODEC, ControllerScreenHandlerPayload::graph, + PacketCodecs.BOOL, ControllerScreenHandlerPayload::adventureModeAccessAllowed, + PacketCodecs.DOUBLE, ControllerScreenHandlerPayload::viewX, + PacketCodecs.DOUBLE, ControllerScreenHandlerPayload::viewY, + PacketCodecs.VAR_INT, ControllerScreenHandlerPayload::zoom, + TextCodecs.PACKET_CODEC.collect(PacketCodecs.toList()), ControllerScreenHandlerPayload::errors, + ControllerScreenHandlerPayload::new + ); +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 53185de..897c656 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -39,11 +39,10 @@ ], "accessWidener": "advanced_networking.accesswidener", "depends": { - "fabricloader": ">=0.15.2", - "fabric-api": ">=0.91.0", - "minecraft": "~1.20.4", + "fabricloader": ">=0.15.11", + "fabric-api": ">=0.98.0", + "minecraft": "1.20.6", "nodeflow": "*", - "graphlib": "*", - "noindium": "*" + "graphlib": "*" } }