diff --git a/.gitignore b/.gitignore index 1f117399..65148347 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,10 @@ classes/ .vscode .settings *.launch -.architectury-transformer +runs/ + +# Ignore markdown files except the ones we want tracked +*.md +!README.md +!LICENSE.md +!CHANGES.md diff --git a/README.md b/README.md index e61c1de8..4c401320 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# EyeMineArchitectury -A version of [EyeMineMods](https://github.com/SpecialEffect/EyeMineMods) that is build upon the [Architectury API](https://github.com/architectury/architectury-api) allowing it to work on either NeoForge, Forge or Fabric. +# EyeMineMods +A version of [EyeMineMods](https://github.com/SpecialEffect/EyeMineMods) using Jared's [MultiLoader Template](https://github.com/jaredlll08/MultiLoader-Template) to support both NeoForge and Fabric. This repository contains the Minecraft mods used with [EyeMine](https://github.com/SpecialEffect/EyeMine), which provides a gaze-controlled keyboard for in-game actions. @@ -21,18 +21,19 @@ A version of the mod ported by [Mrbysco](https://github.com/Mrbysco) supports ** ## Information for developers -Code for different versions of Minecraft Forge can be found on different branches: +Code for different versions of Minecraft can be found on different branches: - Minecraft Forge v1.11.2 (via the [eyemineClassic_mc1_11_2 branch](https://github.com/SpecialEffect/EyeMineMods/tree/eyemineClassic_mc1_11_2)) - Minecraft Forge v1.14.4 (via the [eyemineV2_mc1_14_4 branch](https://github.com/SpecialEffect/EyeMineMods/tree/eyemineV2_mc1_14_4)). - Minecraft Forge v1.16.5 (via the [eyemineV2_mc1_16_5 branch](https://github.com/SpecialEffect/EyeMineMods/tree/eyemineV2_mc1_16_5)). +- Minecraft 1.21.1 NeoForge + Fabric via Architectury (via the [architectury_1.21 branch](https://github.com/SpecialEffect/EyeMineMods/tree/architectury_1.21)). +- Minecraft 26.1.1 NeoForge + Fabric via MultiLoader (via the [multiloader_26.1.1 branch](https://github.com/SpecialEffect/EyeMineMods/tree/multiloader_26.1.1)). All the code comprising EyeMine is GPL3 licensed. We would love contributions to port to other versions of Minecraft. If you're interested in doing this, please email eyemine@specialeffect.org.uk to let us know what you're working on! ## Dev setup -These instructions are based on Windows 10 and using Eclipse as an IDE. If you are using a different setup, some details may vary. ### Pre-requisites -- Java SDK ("JDK") +- Java 25 JDK ### Instructions Get the code. @@ -41,17 +42,13 @@ git clone git@github.com:SpecialEffect/EyeMineMods.git cd EyeMineMods ``` -Build the code. The built mod file will be found in the `build/libs` directory. +Build the code. Output JARs will be in `neoforge/build/libs/` and `fabric/build/libs/`. ``` -gradlew build +./gradlew build ``` -Optionally set up to build and run from Eclipse: +Run the client in dev: ``` -gradlew genEclipseRuns -gradlew eclipse +./gradlew :neoforge:runClient +./gradlew :fabric:runClient ``` -Now you can open the project in Eclipse: -File -> Import -> Gradle -> Existing Gradle project -> Set Project Root Directory to the EyeMineMods folder -> Finish -Once the project is loaded, select the project in Package Explorer, hit the green "Run" or "Debug" button and select "runClient" as the configuration to run. - diff --git a/build.gradle b/build.gradle index 9c42df26..b8465aed 100644 --- a/build.gradle +++ b/build.gradle @@ -1,64 +1,6 @@ plugins { - id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.9-SNAPSHOT" apply false + // https://fabricmc.net/develop/ + id 'net.fabricmc.fabric-loom' version '1.16.1' apply false + // https://projects.neoforged.net/neoforged/moddevgradle + id 'net.neoforged.moddev' version '2.0.141' apply false } - -architectury { - minecraft = rootProject.minecraft_version -} - -subprojects { - apply plugin: "dev.architectury.loom" - - loom { - silentMojangMappingsLicense() - } - - dependencies { - minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" - // The following line declares the mojmap mappings, you may use other mappings as well - mappings loom.officialMojangMappings() - // The following line declares the yarn mappings you may select this one as well. - // mappings "net.fabricmc:yarn:1.19.4+build.2:v2" - } -} - -allprojects { - apply plugin: "java" - apply plugin: "architectury-plugin" - apply plugin: "maven-publish" - - base { - archivesName = rootProject.archives_base_name - } - version = rootProject.mod_version - group = rootProject.maven_group - - repositories { - mavenCentral() - maven { - url "https://maven.neoforged.net/releases/" - } - maven { - url "https://maven.terraformersmc.com/" - content { - includeGroup "com.terraformersmc" - } - } - maven { - url "https://cursemaven.com" - content { - includeGroup "curse.maven" - } - } - } - - tasks.withType(JavaCompile).configureEach { - it.options.encoding = 'UTF-8' - it.options.getRelease().set(21) - } - - java { - withSourcesJar() - } -} \ No newline at end of file diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 00000000..67840524 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,3 @@ +plugins { + id 'groovy-gradle-plugin' +} diff --git a/buildSrc/src/main/groovy/multiloader-common.gradle b/buildSrc/src/main/groovy/multiloader-common.gradle new file mode 100644 index 00000000..9aee2054 --- /dev/null +++ b/buildSrc/src/main/groovy/multiloader-common.gradle @@ -0,0 +1,99 @@ +plugins { + id 'java-library' + id 'maven-publish' +} + +base { + archivesName = "${mod_id}-${project.name}-${minecraft_version}" +} + +java { + toolchain.languageVersion = JavaLanguageVersion.of(java_version) + withSourcesJar() + withJavadocJar() +} + +repositories { + mavenCentral() + exclusiveContent { + forRepository { + maven { + name = 'Sponge' + url = 'https://repo.spongepowered.org/repository/maven-public' + } + } + filter { includeGroupAndSubgroups('org.spongepowered') } + } +} + +sourcesJar { + from(rootProject.file('LICENSE')) { + rename { "${it}_${mod_name}" } + } +} + +jar { + from(rootProject.file('LICENSE')) { + rename { "${it}_${mod_name}" } + } + + manifest { + attributes([ + 'Specification-Title' : mod_name, + 'Specification-Vendor' : mod_author, + 'Specification-Version' : project.jar.archiveVersion, + 'Implementation-Title' : project.name, + 'Implementation-Version': project.jar.archiveVersion, + 'Implementation-Vendor' : mod_author, + 'Built-On-Minecraft' : minecraft_version + ]) + } +} + +processResources { + var expandProps = [ + 'version' : version, + 'group' : project.group, + 'minecraft_version' : minecraft_version, + 'minecraft_version_range' : minecraft_version_range, + 'fabric_version' : fabric_version, + 'fabric_loader_version' : fabric_loader_version, + 'mod_name' : mod_name, + 'mod_author' : mod_author, + 'mod_id' : mod_id, + 'license' : license, + 'description' : project.description, + 'neoforge_version' : neoforge_version, + 'neoforge_loader_version_range': neoforge_loader_version_range, + 'credits' : credits, + 'java_version' : java_version + ] + + var jsonExpandProps = expandProps.collectEntries { + key, value -> [(key): value instanceof String ? value.replace("\n", "\\\\n") : value] + } + + filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml']) { + expand expandProps + } + + filesMatching(['pack.mcmeta', 'fabric.mod.json', '*.mixins.json']) { + expand jsonExpandProps + } + + inputs.properties(expandProps) +} + +publishing { + publications { + register('mavenJava', MavenPublication) { + artifactId base.archivesName.get() + from components.java + } + } + repositories { + maven { + url System.getenv('local_maven_url') ?: 'file://invalid' + } + } +} diff --git a/buildSrc/src/main/groovy/multiloader-loader.gradle b/buildSrc/src/main/groovy/multiloader-loader.gradle new file mode 100644 index 00000000..5f45bb43 --- /dev/null +++ b/buildSrc/src/main/groovy/multiloader-loader.gradle @@ -0,0 +1,95 @@ +// Loader convention plugin - injects common sources into platform builds. + +plugins { + id 'java' +} + +base { + archivesName = "${mod_id}-${minecraft_version}-${version}-${project.name}" +} + +tasks.withType(AbstractArchiveTask).configureEach { + archiveVersion.set('') +} + +java { + toolchain.languageVersion = JavaLanguageVersion.of(java_version) +} + +configurations { + commonJava { + canBeConsumed = false + canBeResolved = true + } + commonResources { + canBeConsumed = false + canBeResolved = true + } +} + +dependencies { + commonJava project(path: ':common', configuration: 'commonJava') + commonResources project(path: ':common', configuration: 'commonResources') +} + +tasks.named('compileJava').configure { + dependsOn(configurations.commonJava) + source(configurations.commonJava.incoming.artifactView { + attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) } + }.files) +} + +tasks.named('processResources').configure { + dependsOn(configurations.commonResources) + from(configurations.commonResources.incoming.artifactView { + attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) } + }.files) + + // Property expansion for mod metadata files + var expandProps = [ + 'version' : version, + 'group' : project.group, + 'minecraft_version' : minecraft_version, + 'minecraft_version_range' : minecraft_version_range, + 'fabric_version' : fabric_version, + 'fabric_loader_version' : fabric_loader_version, + 'mod_name' : mod_name, + 'mod_author' : mod_author, + 'mod_id' : mod_id, + 'license' : license, + 'description' : project.description ?: '', + 'neoforge_version' : neoforge_version, + 'neoforge_loader_version_range': neoforge_loader_version_range, + 'credits' : credits, + 'java_version' : java_version + ] + + var jsonExpandProps = expandProps.collectEntries { + key, value -> [(key): value instanceof String ? value.replace("\n", "\\\\n") : value] + } + + filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml']) { + expand expandProps + } + + filesMatching(['pack.mcmeta', 'fabric.mod.json', '*.mixins.json']) { + expand jsonExpandProps + } + + inputs.properties(expandProps) +} + +tasks.matching { it.name == 'javadoc' }.configureEach { + source(configurations.commonJava.incoming.artifactView { + attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) } + }.files) +} + +tasks.matching { it.name == 'sourcesJar' }.configureEach { + from(configurations.commonJava.incoming.artifactView { + attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) } + }.files) + from(configurations.commonResources.incoming.artifactView { + attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) } + }.files) +} diff --git a/changes.md b/changes.md index 26a9aac3..0b58da9c 100644 --- a/changes.md +++ b/changes.md @@ -1,41 +1,49 @@ # EyeMine Changelog -## Version 6.0.2 +## Version 7.0.0 - MC 26.1.1 (NeoForge + Fabric) -### Bug Fixes +### Major Changes -#### Gaze-Based Walking Refinements +- **Migrated from Architectury to MultiLoader Template** - the mod now uses Jared's MultiLoader Template with Java ServiceLoader for platform abstraction +- **Upgraded to MC 26.1.1** from MC 1.21.1 +- **Upgraded to Java 25** from Java 21 +- **Dropped Forge support** - Only NeoForge and Fabric are supported -- **Walking now fully stops when gaze is at the on-screen keyboard or outside the window**: In 6.0.1, walking was reduced to 15% speed in these cases. After further testing, full stop is the correct behavior — the original "don't stop completely" feedback from Kirsty was about in-game camera pitch (looking up/down hills), not the on-screen keyboard area. +### Build System -- **Extreme pitch angles no longer fully stop walking**: Looking straight up or down (beyond 80°) now slows movement to 5% instead of stopping entirely. This preserves the ability to navigate hills and look around without losing all momentum. +- Replaced Architectury Loom with buildSrc convention plugins (multiloader-common, multiloader-loader) +- NeoForge uses ModDevGradle, Fabric uses Fabric Loom 1.16.1 +- Gradle upgraded to 9.4.1 -#### Dwell Action Improvements +### Platform Abstraction -- **Dwell actions now suppressed when gaze is at keyboard area or outside window**: Prevents unintended dwell-triggered interactions (e.g., block placement, item use) while the user is interacting with the on-screen keyboard. +- Replaced `@ExpectPlatform` with Java ServiceLoader pattern +- Created service interfaces: `IEyeMineConfigService`, `IInventoryConfigService`, `IPlatformHelper`, `NetworkService` +- Static facade classes delegate to services transparently - no changes needed in calling code ---- +### Event System -## Version 6.0.1 +- Created custom common event bus (`EyeMineEvents`) replacing Architectury events +- Platform entry points forward native events into the common bus +- Fabric: Custom mixins for key input (`FabricKeyboardHandlerMixin`) and screen events (`FabricSetScreenMixin`) -### Bug Fixes +### Rendering -#### Gaze Detection Improvements +- Overlay rendering uses `RenderPipelines.GUI_TEXTURED` with ARGB color int for alpha support +- In-world dwell visualization now uses `RenderTypes.debugQuads()` +- NeoForge block outline is now accomplished via `ExtractBlockOutlineRenderStateEvent` + `CustomBlockOutlineRenderer` +- Fabric block outline is handled via `LevelRenderEvents.BEFORE_BLOCK_OUTLINE` +- Fabric HUD rendering done with `HudElementRegistry` -- **Fixed auto-walking not stopping when looking at keyboard area**: The GLFW cursor reset events at position (0,0) were incorrectly clearing the gaze-below-threshold state. The fix now properly detects and ignores these cursor reset events to preserve the gaze state. +### Mixin Updates -- **Added outside-window gaze detection**: Walking now also pauses/slows when gaze is detected outside the game window, matching the original intended behavior. +- `LivingEntityMixin` rewritten to use `AttributeModifier` on `STEP_HEIGHT` +- `KeyboardInputMixin` rewritten for immutable `Input` record system; fractional walk speed preserved via `moveVector` + - this was an internal change from mojang that just didnt work well for what we needed +- `TitleScreenMixin` updated for `extractRenderState()` and `Matrix3x2fStack` +- Added Fabric-specific mixins for key and screen event forwarding -#### Walking Behavior Changes +### Removed -- **Walking now slows down instead of stopping completely when looking at keyboard**: Per feedback from Kirsty (original developer), stopping completely wasn't intuitive when looking up/down hills. Walking now reduces to 15% speed when gaze is at the keyboard area or outside the window. - -#### Mining and Attacking Fixes - -- **Toggle mining now pauses when looking at keyboard**: Per EyeGazeGirl's feedback ("toggle mining meant to stop too"), continuous mining now pauses when gaze is below the hotbar or outside the window. - -- **Toggle attacking now pauses when looking at keyboard**: Continuous attacking now pauses when gaze is at the keyboard area or outside the window, consistent with mining behavior. - -#### Keybinding Persistence Fix - -- **Fixed keybindings resetting on every game launch**: The AutoJump module was calling `options.save()` and `options.load()` during startup config sync, which could interfere with Minecraft's keybinding loading process. The fix now only persists settings when the user manually toggles them, not during startup. +- Forge subproject +- ModMenu integration (commented out pending 26.1.1-compatible release) diff --git a/common/build.gradle b/common/build.gradle index 5ad2326c..b60b20ac 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,29 +1,32 @@ -architectury { - common(rootProject.enabled_platforms.split(",")) +plugins { + id 'multiloader-common' + id 'net.neoforged.moddev' } -loom { - accessWidenerPath = file("src/main/resources/eyemine.accesswidener") +neoForge { + neoFormVersion = neo_form_version +} + +configurations { + commonJava { + canBeConsumed = true + canBeResolved = false + } + commonResources { + canBeConsumed = true + canBeResolved = false + } } dependencies { - // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies - // Do NOT use other classes from fabric loader - modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" - // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury:${rootProject.architectury_version}" + compileOnly "org.spongepowered:mixin:0.8.7" } -publishing { - publications { - mavenCommon(MavenPublication) { - artifactId = rootProject.archives_base_name - from components.java - } +artifacts { + commonJava(sourceSets.main.java.sourceDirectories.singleFile) { + builtBy(tasks.named('classes')) } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. + commonResources(sourceSets.main.resources.sourceDirectories.singleFile) { + builtBy(tasks.named('classes')) } } diff --git a/common/src/main/java/com/irtimaled/bbor/client/Camera.java b/common/src/main/java/com/irtimaled/bbor/client/Camera.java index 6591103e..c6b95112 100644 --- a/common/src/main/java/com/irtimaled/bbor/client/Camera.java +++ b/common/src/main/java/com/irtimaled/bbor/client/Camera.java @@ -5,7 +5,7 @@ public class Camera { private static Vec3 getPos() { - return Minecraft.getInstance().gameRenderer.getMainCamera().getPosition(); + return Minecraft.getInstance().gameRenderer.getMainCamera().position(); } public static double getX() { diff --git a/common/src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java b/common/src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java index 599815be..e822ad20 100644 --- a/common/src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java +++ b/common/src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java @@ -1,23 +1,15 @@ package com.irtimaled.bbor.client.renderers; -import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.phys.Vec3; import org.joml.Matrix4f; -import org.lwjgl.opengl.GL11; import java.awt.Color; -import java.util.HashSet; -import java.util.Set; public abstract class AbstractRenderer { - private static double TAU = 6.283185307179586D; - private static double PI = TAU / 2D; public static void renderBlockFace(PoseStack poseStack, VertexConsumer vertexConsumer, BlockPos pos, Direction facing, Color color, int opacity) { OffsetPoint min = new OffsetPoint(pos.getX(), pos.getY(), pos.getZ()); @@ -187,9 +179,6 @@ public static void renderBlockFaceCentralisedDwell(PoseStack poseStack, VertexCo public static void renderCubeAtPosition(PoseStack poseStack, VertexConsumer vertexConsumer, Vec3 pos, Color color, int opacity, double size) { -// RenderSystem.polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); -// RenderSystem.enableBlend(); -// RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); // Set up bounding cube corners OffsetPoint min = new OffsetPoint(pos.x() - size, pos.y() - size, pos.z() - size); @@ -236,152 +225,6 @@ public static void renderCubeAtPosition(PoseStack poseStack, VertexConsumer vert vertexConsumer.addVertex(matrix4f, minX, maxY, maxZ).setColor(r, g, b, opacity); vertexConsumer.addVertex(matrix4f, minX, maxY, minZ).setColor(r, g, b, opacity); -// RenderSystem.disableBlend(); -// RenderSystem.enablePolygonOffset(); -// RenderSystem.polygonOffset(-1.f, -1.f); } - public static void renderFaces(OffsetPoint min, OffsetPoint max, Color color, int alpha) { - double minX = min.getX(); - double minY = min.getY(); - double minZ = min.getZ(); - - double maxX = max.getX(); - double maxY = max.getY(); - double maxZ = max.getZ(); - - Renderer renderer = Renderer.startQuads() - .setColor(color) - .setAlpha(alpha); - - if (minX != maxX && minZ != maxZ) { - renderer.addPoint(minX, minY, minZ) - .addPoint(maxX, minY, minZ) - .addPoint(maxX, minY, maxZ) - .addPoint(minX, minY, maxZ); - - if (minY != maxY) { - renderer.addPoint(minX, maxY, minZ) - .addPoint(maxX, maxY, minZ) - .addPoint(maxX, maxY, maxZ) - .addPoint(minX, maxY, maxZ); - } - } - - if (minX != maxX && minY != maxY) { - renderer.addPoint(minX, minY, maxZ) - .addPoint(minX, maxY, maxZ) - .addPoint(maxX, maxY, maxZ) - .addPoint(maxX, minY, maxZ); - - if (minZ != maxZ) { - renderer.addPoint(minX, minY, minZ) - .addPoint(minX, maxY, minZ) - .addPoint(maxX, maxY, minZ) - .addPoint(maxX, minY, minZ); - } - } - if (minY != maxY && minZ != maxZ) { - renderer.addPoint(minX, minY, minZ) - .addPoint(minX, minY, maxZ) - .addPoint(minX, maxY, maxZ) - .addPoint(minX, maxY, minZ); - - if (minX != maxX) { - renderer.addPoint(maxX, minY, minZ) - .addPoint(maxX, minY, maxZ) - .addPoint(maxX, maxY, maxZ) - .addPoint(maxX, maxY, minZ); - } - } - } - - void renderLine(OffsetPoint startPoint, OffsetPoint endPoint, Color color) { - RenderSystem.polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); - - Renderer.startLines() - .setColor(color) - .addPoint(startPoint) - .addPoint(endPoint); - } - - void renderFilledFaces(OffsetPoint min, OffsetPoint max, Color color, int alpha) { - RenderSystem.polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); - RenderSystem.enableBlend(); - - renderFaces(min, max, color, alpha); - - RenderSystem.disableBlend(); - RenderSystem.enablePolygonOffset(); - RenderSystem.polygonOffset(-1.f, -1.f); - } - - void renderText(PoseStack poseStack, OffsetPoint offsetPoint, String... texts) { - Font fontRenderer = Minecraft.getInstance().font; - -// RenderSystem.pushMatrix(); TODO: Redo when renderText() is required -// RenderSystem.polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); -// RenderSystem.translated(offsetPoint.getX(), offsetPoint.getY() + 0.002D, offsetPoint.getZ()); -// GL11.glNormal3f(0.0F, 1.0F, 0.0F); -// RenderSystem.rotatef(0.0F, 0.0F, 1.0F, 0.0F); -// RenderSystem.rotatef(90.0F, 1.0F, 0.0F, 0.0F); -// RenderSystem.scalef(-0.0175F, -0.0175F, 0.0175F); -// -// RenderSystem.enableBlend(); -// RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); -// -// RenderSystem.disableDepthTest(); -// RenderSystem.enableDepthTest(); -// RenderSystem.depthMask(true); -// float top = -(fontRenderer.lineHeight * texts.length) / 2f; -// for (String text : texts) { -// float left = fontRenderer.width(text) / 2f; -// fontRenderer.draw(poseStack, text, -left, top, -1); -// top += fontRenderer.lineHeight; -// } -// RenderSystem.disableTexture(); -// RenderSystem.disableBlend(); - } - - private static void enablePointSmooth() { - RenderSystem.assertOnRenderThread(); - GL11.glEnable(GL11.GL_POINT_SMOOTH); - } - - private static void pointSize(float dotSize) { - RenderSystem.assertOnRenderThread(); - GL11.glPointSize(dotSize); - } - - void renderSphere(OffsetPoint center, double radius, Color color, int density, int dotSize) { - enablePointSmooth(); -// GL11.glEnable(GL11.GL_POINT_SMOOTH); - pointSize(dotSize); -// GL11.glPointSize(dotSize); -// Renderer renderer = Renderer.startPoints() TODO: Redo when renderSphere is required -// .setColor(color); -// buildPoints(center, radius, density) -// .forEach(renderer::addPoint); -// renderer.render(); - } - - private Set buildPoints(OffsetPoint center, double radius, int density) { - int segments = 24 + (density * 8); - - Set points = new HashSet<>(segments * segments); - - double thetaSegment = PI / (double) segments; - double phiSegment = TAU / (double) segments; - - for (double phi = 0.0D; phi < TAU; phi += phiSegment) { - for (double theta = 0.0D; theta < PI; theta += thetaSegment) { - double dx = radius * Math.sin(phi) * Math.cos(theta); - double dz = radius * Math.sin(phi) * Math.sin(theta); - double dy = radius * Math.cos(phi); - - points.add(center.offset(dx, dy, dz)); - } - } - return points; - } } diff --git a/common/src/main/java/com/irtimaled/bbor/client/renderers/Renderer.java b/common/src/main/java/com/irtimaled/bbor/client/renderers/Renderer.java index e2669e86..40e9aa45 100644 --- a/common/src/main/java/com/irtimaled/bbor/client/renderers/Renderer.java +++ b/common/src/main/java/com/irtimaled/bbor/client/renderers/Renderer.java @@ -1,8 +1,8 @@ package com.irtimaled.bbor.client.renderers; import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.BufferUploader; import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.MeshData; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormat.Mode; @@ -20,15 +20,10 @@ static Renderer startQuads() { return new Renderer(Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); } -// static Renderer startPoints() { -// return new Renderer(GL11.GL_POINTS, DefaultVertexFormat.POSITION_COLOR); -// } - public static Renderer startTextured() { return new Renderer(Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); } - private static final Tesselator tessellator = new Tesselator(2097152); private static BufferBuilder bufferBuilder; private int red; @@ -37,7 +32,7 @@ public static Renderer startTextured() { private int alpha; private Renderer(Mode glMode, VertexFormat vertexFormat) { - this.bufferBuilder = tessellator.begin(glMode, vertexFormat); + bufferBuilder = Tesselator.getInstance().begin(glMode, vertexFormat); this.glMode = glMode; } @@ -73,7 +68,6 @@ public Renderer addPoints(OffsetPoint[] points) { Renderer addPoint(double x, double y, double z) { pos((float) x, (float) y, (float) z); color(); - draw(); return this; } @@ -81,11 +75,9 @@ public Renderer addPoint(double x, double y, double z, float u, float v) { pos((float) x, (float) y, (float) z); tex(u, v); color(); - draw(); return this; } - private void pos(float x, float y, float z) { bufferBuilder.addVertex(x, y, z); } @@ -99,6 +91,9 @@ private void color() { } public void draw() { - BufferUploader.drawWithShader(bufferBuilder.buildOrThrow()); + MeshData mesh = bufferBuilder.build(); + if (mesh != null) { + mesh.close(); + } } } diff --git a/common/src/main/java/com/specialeffect/eyemine/EyeMineClient.java b/common/src/main/java/com/specialeffect/eyemine/EyeMineClient.java index f3243fe2..9fdda8ec 100644 --- a/common/src/main/java/com/specialeffect/eyemine/EyeMineClient.java +++ b/common/src/main/java/com/specialeffect/eyemine/EyeMineClient.java @@ -3,6 +3,7 @@ import com.specialeffect.eyemine.client.CreativeClientHelper; import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.client.MainClientHandler; +import com.specialeffect.eyemine.event.EyeMineEvents; import com.specialeffect.eyemine.submod.IConfigListener; import com.specialeffect.eyemine.submod.SubMod; import com.specialeffect.eyemine.submod.mining.ContinuouslyMine; @@ -32,11 +33,6 @@ import com.specialeffect.eyemine.submod.movement.Sneak; import com.specialeffect.eyemine.submod.movement.Swim; import com.specialeffect.eyemine.submod.utils.DebugAverageFps; -import dev.architectury.event.events.client.ClientGuiEvent; -import dev.architectury.event.events.client.ClientLifecycleEvent; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.registry.client.keymappings.KeyMappingRegistry; -import net.minecraft.client.KeyMapping; import java.util.ArrayList; import java.util.List; @@ -54,17 +50,13 @@ public static void init() { // Setup all other sub mods instantiateSubMods(); - ClientGuiEvent.SET_SCREEN.register(MainClientHandler::onGuiOpen); - ClientGuiEvent.RENDER_HUD.register(MainClientHandler::onRenderGameOverlayEvent); - ClientRawInputEvent.KEY_PRESSED.register(CreativeClientHelper::onKeyInput); + EyeMineEvents.SCREEN_SET.register(MainClientHandler::onGuiOpen); + EyeMineEvents.RENDER_HUD.register(MainClientHandler::onRenderGameOverlayEvent); + EyeMineEvents.KEY_PRESSED.register(CreativeClientHelper::onKeyInput); - if (!Keybindings.keybindings.isEmpty()) { - for (KeyMapping keyBinding : Keybindings.keybindings) { - KeyMappingRegistry.register(keyBinding); - } - } + // Key mappings are registered by platform entry points via Keybindings.keybindings list - ClientLifecycleEvent.CLIENT_SETUP.register((client) -> { + EyeMineEvents.CLIENT_SETUP.register((client) -> { if (!setupComplete) { setupComplete = true; refresh(); diff --git a/common/src/main/java/com/specialeffect/eyemine/client/CreativeClientHelper.java b/common/src/main/java/com/specialeffect/eyemine/client/CreativeClientHelper.java index 37d37321..065e034a 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/CreativeClientHelper.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/CreativeClientHelper.java @@ -17,7 +17,7 @@ import com.specialeffect.inventory.manager.ChestInventoryManager; import com.specialeffect.inventory.manager.CreativeInventoryManager; import com.specialeffect.inventory.manager.SurvivalInventoryManager; -import dev.architectury.event.EventResult; +import com.specialeffect.eyemine.event.EventResult; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.ContainerScreen; @@ -27,7 +27,7 @@ public class CreativeClientHelper { public static EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { + if (InputConstants.isKeyDown(minecraft.getWindow(), 292)) { return EventResult.pass(); } diff --git a/common/src/main/java/com/specialeffect/eyemine/client/EyeMineRenderType.java b/common/src/main/java/com/specialeffect/eyemine/client/EyeMineRenderType.java index 289c97a1..6db7ca54 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/EyeMineRenderType.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/EyeMineRenderType.java @@ -11,46 +11,23 @@ package com.specialeffect.eyemine.client; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.VertexFormat; -import com.mojang.blaze3d.vertex.VertexFormat.Mode; -import net.minecraft.client.renderer.RenderStateShard; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.rendertype.RenderType; +import net.minecraft.client.renderer.rendertype.RenderTypes; -public class EyeMineRenderType extends RenderType { - public EyeMineRenderType(String nameIn, VertexFormat formatIn, Mode drawModeIn, int bufferSizeIn, boolean useDelegateIn, boolean needsSortingIn, Runnable setupTaskIn, Runnable clearTaskIn) { - super(nameIn, formatIn, drawModeIn, bufferSizeIn, useDelegateIn, needsSortingIn, setupTaskIn, clearTaskIn); - } - - public static RenderType dwellRenderType() { - return RenderType.create("eyemine:dwell", DefaultVertexFormat.POSITION_COLOR, Mode.QUADS, 2097152, false, false, getDwellState()); - } - - private static CompositeState getDwellState() { - return CompositeState.builder() - .setShaderState(RenderStateShard.POSITION_COLOR_SHADER) - .setLightmapState(LIGHTMAP) - .setTransparencyState(TRANSLUCENT_TRANSPARENCY) - .setOutputState(TRANSLUCENT_TARGET) - .setLayeringState(VIEW_OFFSET_Z_LAYERING) - .setCullState(NO_CULL) - .setDepthTestState(NO_DEPTH_TEST) - .createCompositeState(true); - } +/** + * Custom RenderTypes for EyeMine's in-world rendering (dwell indicators, block outlines). + * In MC 26.1.1, uses RenderTypes utility for translucent position-color rendering. + */ +public class EyeMineRenderType { - public static RenderType cubeRenderType() { - return RenderType.create("eyemine:cube", DefaultVertexFormat.POSITION_COLOR, Mode.QUADS, 2097152, false, false, getCubeState()); - } + public static RenderType dwellRenderType() { + // Use the debug quads type for translucent position-color quads + // TODO: If this doesn't render correctly, create a proper custom RenderType + // using the new RenderSetup/RenderPipeline API + return RenderTypes.debugQuads(); + } - private static CompositeState getCubeState() { - return CompositeState.builder() - .setShaderState(RenderStateShard.POSITION_COLOR_SHADER) - .setLightmapState(LIGHTMAP) - .setTransparencyState(TRANSLUCENT_TRANSPARENCY) - .setOutputState(TRANSLUCENT_TARGET) - .setLayeringState(VIEW_OFFSET_Z_LAYERING) - .setCullState(NO_CULL) - .setDepthTestState(NO_DEPTH_TEST) - .createCompositeState(true); - } + public static RenderType cubeRenderType() { + return dwellRenderType(); + } } diff --git a/common/src/main/java/com/specialeffect/eyemine/client/Keybindings.java b/common/src/main/java/com/specialeffect/eyemine/client/Keybindings.java index 82e82579..31298c95 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/Keybindings.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/Keybindings.java @@ -12,10 +12,21 @@ package com.specialeffect.eyemine.client; import net.minecraft.client.KeyMapping; +import net.minecraft.resources.Identifier; import java.util.ArrayList; import java.util.List; public class Keybindings { public static final List keybindings = new ArrayList<>(); + + // Custom key mapping categories for EyeMine + public static final KeyMapping.Category EYEGAZE_SETTINGS = KeyMapping.Category.register( + Identifier.fromNamespaceAndPath("eyemine", "eyegaze_settings")); + public static final KeyMapping.Category EYEGAZE_COMMON = KeyMapping.Category.register( + Identifier.fromNamespaceAndPath("eyemine", "eyegaze_common")); + public static final KeyMapping.Category EYEGAZE_EXTRA = KeyMapping.Category.register( + Identifier.fromNamespaceAndPath("eyemine", "eyegaze_extra")); + public static final KeyMapping.Category EYEGAZE_ADVANCED = KeyMapping.Category.register( + Identifier.fromNamespaceAndPath("eyemine", "eyegaze_advanced")); } diff --git a/common/src/main/java/com/specialeffect/eyemine/client/MainClientHandler.java b/common/src/main/java/com/specialeffect/eyemine/client/MainClientHandler.java index 99e71918..dadf329c 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/MainClientHandler.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/MainClientHandler.java @@ -17,10 +17,10 @@ import com.specialeffect.eyemine.mixin.AbstractContainerScreenAccessor; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.inventory.manager.CreativeInventoryManager; -import dev.architectury.event.CompoundEventResult; +import com.specialeffect.eyemine.event.ScreenSetResult; import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; @@ -31,7 +31,7 @@ public class MainClientHandler { public static final List crosshairOverlayList = new ArrayList<>(); private static StateOverlay mStateOverlay; - public static void onRenderGameOverlayEvent(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { + public static void onRenderGameOverlayEvent(GuiGraphicsExtractor guiGraphics, DeltaTracker deltaTracker) { if (!MainClientHandler.crosshairOverlayList.isEmpty()) { Minecraft minecraft = Minecraft.getInstance(); for (ICrosshairOverlay overlay : MainClientHandler.crosshairOverlayList) { @@ -41,15 +41,7 @@ public static void onRenderGameOverlayEvent(GuiGraphics guiGraphics, DeltaTracke } // Replace / augment some GUIs - public static CompoundEventResult onGuiOpen(Screen screen) { - Screen currentScreen = Minecraft.getInstance().screen; -// if (!EyeMineClient.disableCustomNewWorld && screen instanceof CreateWorldScreen && !(currentScreen instanceof CustomCreateWorldScreen)) { -// if (!EyeMineClient.allowMoreOptions) { -// // override the CreateWorldScreen, unless it's been requested from within our own CustomCreateWorldScreen -// return CompoundEventResult.interruptTrue(CustomCreateWorldScreen.create(Minecraft.getInstance(), screen)); -// } -// EyeMineClient.allowMoreOptions = false; -// } + public static ScreenSetResult onGuiOpen(Screen screen) { if (screen instanceof CreativeModeInventoryScreen gui) { // Make sure mouse starts outside container, so we have a sensible reference point AbstractContainerScreenAccessor accessor = (AbstractContainerScreenAccessor) gui; @@ -60,7 +52,7 @@ public static CompoundEventResult onGuiOpen(Screen screen) { gui.getMenu()); con.resetMouse(); } - return CompoundEventResult.pass(); + return ScreenSetResult.pass(); } public static void initialize() { diff --git a/common/src/main/java/com/specialeffect/eyemine/client/gui/CustomCreateWorldScreen.java b/common/src/main/java/com/specialeffect/eyemine/client/gui/CustomCreateWorldScreen.java index 843ee6c2..2327972c 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/gui/CustomCreateWorldScreen.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/gui/CustomCreateWorldScreen.java @@ -19,7 +19,7 @@ //import com.specialeffect.eyemine.submod.misc.DefaultConfigForNewWorld; //import it.unimi.dsi.fastutil.booleans.BooleanConsumer; //import net.minecraft.FileUtil; -//import net.minecraft.Util; +// //import net.minecraft.client.Minecraft; //import net.minecraft.client.gui.components.Button; //import net.minecraft.client.gui.components.EditBox; @@ -41,7 +41,7 @@ //import net.minecraft.server.packs.repository.ServerPacksSource; //import net.minecraft.world.Difficulty; //import net.minecraft.world.level.DataPackConfig; -//import net.minecraft.world.level.GameRules; +//import net.minecraft.world.level.gamerules.GameRules; //import net.minecraft.world.level.GameType; //import net.minecraft.world.level.LevelSettings; //import net.minecraft.world.level.levelgen.WorldGenSettings; @@ -264,9 +264,9 @@ // LevelSettings levelSettings = new LevelSettings(this.worldNameField.getValue().trim(), GameType.CREATIVE, hardcoreMode, Difficulty.NORMAL, true, new GameRules(), DataPackConfig.DEFAULT); // // GameRules gameRules = levelSettings.gameRules(); -// gameRules.getRule(GameRules.RULE_DAYLIGHT).set(!btnDaytime.getValue(), (MinecraftServer) null); -// gameRules.getRule(GameRules.RULE_WEATHER_CYCLE).set(!btnSunny.getValue(), (MinecraftServer) null); -// gameRules.getRule(GameRules.RULE_KEEPINVENTORY).set(btnInventory.getValue(), (MinecraftServer) null); +// gameRules.getRule(GameRules.ADVANCE_TIME).set(!btnDaytime.getValue(), (MinecraftServer) null); +// gameRules.getRule(GameRules.ADVANCE_WEATHER).set(!btnSunny.getValue(), (MinecraftServer) null); +// gameRules.getRule(GameRules.KEEP_INVENTORY).set(btnInventory.getValue(), (MinecraftServer) null); // // // TODO: more options here? // levelSettings.allowCommands(); diff --git a/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/ICrosshairOverlay.java b/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/ICrosshairOverlay.java index a89e68b4..5b479b90 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/ICrosshairOverlay.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/ICrosshairOverlay.java @@ -12,8 +12,8 @@ package com.specialeffect.eyemine.client.gui.crosshair; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; public interface ICrosshairOverlay { - void renderOverlay(GuiGraphics guiGraphics, Minecraft minecraft); + void renderOverlay(GuiGraphicsExtractor guiGraphics, Minecraft minecraft); } diff --git a/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/IconOverlay.java b/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/IconOverlay.java index 8fa97f92..24fbac12 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/IconOverlay.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/IconOverlay.java @@ -11,22 +11,15 @@ package com.specialeffect.eyemine.client.gui.crosshair; -import com.mojang.blaze3d.systems.RenderSystem; -import com.specialeffect.utils.ModUtils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.resources.ResourceLocation; -import org.lwjgl.opengl.GL11; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.resources.Identifier; public class IconOverlay implements ICrosshairOverlay { - private ResourceLocation mResource; + private Identifier mResource; - // Current state public boolean mVisible = false; - - // Position/appearance (see setters) - // Position/size are relative to screen public float mCentreX = 0.5f; public float mCentreY = 0.5f; public float mHeight = 1.0f; @@ -36,7 +29,7 @@ public class IconOverlay implements ICrosshairOverlay { public int fadeCountdown = 0; public IconOverlay(Minecraft mc, String resourcePath) { - mResource = ResourceLocation.tryParse(resourcePath); + mResource = Identifier.tryParse(resourcePath); } public void setPosition(float centreX, float centreY, float height, float aspectRatio) { @@ -50,42 +43,36 @@ public void setVisible(boolean visible) { if (visible != mVisible) { fadeCountdown = fadeTime; } - mVisible = visible; } public void setAlpha(float alpha) { - // Minecraft clips alpha at 0.1, so we add 0.1 back in to get reasonable user-facing behaviour if (alpha > 0.0f && alpha < 0.9f) { alpha += 0.1f; } mAlpha = alpha; } - // A helper function to draw a texture scaled to fit. - public void drawTexture(Minecraft minecraft, int screenHeight, int screenWidth, float fade) { - // calculate position + private static int colorWithAlpha(float alpha) { + int a = Math.clamp((int) (alpha * 255), 0, 255); + return (a << 24) | 0xFFFFFF; + } + + public void drawTexture(GuiGraphicsExtractor guiGraphics, int screenHeight, int screenWidth, float fade) { int height = (int) (screenWidth * mHeight); int width = (int) (height * mAspectRatio); int centreX = (int) (mCentreX * screenWidth); int centreY = (int) (mCentreY * screenHeight); - // render the texture - // TODO:white? black? drop shadow? - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, mResource); - ModUtils.drawTexQuad(centreX - (double) width / 2, centreY - (double) height / 2, - width, height, mAlpha * fade); + float alpha = mAlpha * fade; + int x = centreX - width / 2; + int y = centreY - height / 2; + guiGraphics.blit(RenderPipelines.GUI_TEXTURED, mResource, x, y, 0, 0, width, height, width, height, colorWithAlpha(alpha)); } @Override - public void renderOverlay(GuiGraphics guiGraphics, Minecraft minecraft) { + public void renderOverlay(GuiGraphicsExtractor guiGraphics, Minecraft minecraft) { if (mAlpha > 0.0 && (mVisible || fadeCountdown > 0)) { - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); - - // Update fading ticks float fade = 1.0f; if (fadeCountdown > 0) { fadeCountdown--; @@ -95,16 +82,13 @@ public void renderOverlay(GuiGraphics guiGraphics, Minecraft minecraft) { } } - // Don't show if the debug screen is open if (minecraft.getDebugOverlay().showDebugScreen()) { return; } int w = minecraft.getWindow().getGuiScaledWidth(); int h = minecraft.getWindow().getGuiScaledHeight(); - drawTexture(minecraft, h, w, fade); - - RenderSystem.disableBlend(); + drawTexture(guiGraphics, h, w, fade); } } -} \ No newline at end of file +} diff --git a/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/JoystickControlOverlay.java b/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/JoystickControlOverlay.java index 8d8aaaa9..36c12b42 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/JoystickControlOverlay.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/JoystickControlOverlay.java @@ -11,21 +11,18 @@ package com.specialeffect.eyemine.client.gui.crosshair; -import com.mojang.blaze3d.systems.RenderSystem; -import com.specialeffect.utils.ModUtils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.resources.ResourceLocation; -import org.lwjgl.opengl.GL11; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.resources.Identifier; public class JoystickControlOverlay implements ICrosshairOverlay { public JoystickControlOverlay() { - mResource = ResourceLocation.fromNamespaceAndPath("eyemine", "textures/icons/overlay.png"); + mResource = Identifier.fromNamespaceAndPath("eyemine", "textures/icons/overlay.png"); } - ResourceLocation mResource; + Identifier mResource; private boolean mVisible = false; @@ -36,7 +33,6 @@ public void setVisible(boolean bVisible) { } public void setAlpha(float alpha) { - // Minecraft clips alpha at 0.1, so we add 0.1 back in to get reasonable user-facing behaviour if (alpha > 0.0f && alpha < 0.9f) { alpha += 0.1f; } @@ -44,20 +40,16 @@ public void setAlpha(float alpha) { } @Override - public void renderOverlay(GuiGraphics guiGraphics, Minecraft minecraft) { + public void renderOverlay(GuiGraphicsExtractor guiGraphics, Minecraft minecraft) { if (mVisible && mAlpha > 0.0f) { - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); int w = minecraft.getWindow().getGuiScaledWidth(); int h = minecraft.getWindow().getGuiScaledHeight(); - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, mResource); - ModUtils.drawTexQuad(0, 0, w, h, mAlpha); + int a = Math.clamp((int) (mAlpha * 255), 0, 255); + int color = (a << 24) | 0xFFFFFF; + guiGraphics.blit(RenderPipelines.GUI_TEXTURED, mResource, 0, 0, 0, 0, w, h, w, h, color); - RenderSystem.disableBlend(); } } -} \ No newline at end of file +} diff --git a/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/StateOverlay.java b/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/StateOverlay.java index 36a9f606..c9620c93 100644 --- a/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/StateOverlay.java +++ b/common/src/main/java/com/specialeffect/eyemine/client/gui/crosshair/StateOverlay.java @@ -11,19 +11,16 @@ package com.specialeffect.eyemine.client.gui.crosshair; -import com.mojang.blaze3d.systems.RenderSystem; -import com.specialeffect.utils.ModUtils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.resources.ResourceLocation; -import org.lwjgl.opengl.GL11; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.resources.Identifier; import java.util.ArrayList; import java.util.List; // -// StateOverlay implements a simple status bar at the top of the screen which +// StateOverlay implements a simple status bar at the top of the screen which // shows the current states such as attacking, walking, etc. // public class StateOverlay implements ICrosshairOverlay { @@ -35,12 +32,9 @@ public StateOverlay() { } private void rescale() { - // Scale icon sizes to fit screen - int maxSizeByWidth = mDisplayWidth / (mIconsPerRow + mIconPadding); int maxSizeByHeight = 2 * mDisplayHeight / (mIconsPerRow + mIconPadding); mIconSize = Math.min(maxSizeByWidth, maxSizeByHeight); - } private static int mIconSize = 30; @@ -49,71 +43,48 @@ private void rescale() { private int mDisplayHeight; private static final int mIconsPerRow = 10; - // Lists of icons to draw on each half of screen - private static List mResourcesLeft; - private static List mResourcesRight; + private static List mResourcesLeft; + private static List mResourcesRight; private static List mFlagsLeft; private static List mFlagsRight; - // Add texture to list of icons, return position. - // You need to hang onto the position to later turn the - // icon on/off. public synchronized static int registerTextureLeft(String filepath) { - ResourceLocation res = ResourceLocation.tryParse(filepath); + Identifier res = Identifier.tryParse(filepath); mResourcesLeft.add(res); mFlagsLeft.add(false); return mResourcesLeft.size() - 1; } - // Add texture to list of icons, return position. - // You need to hang onto the position to later turn the - // icon on/off. public synchronized static int registerTextureRight(String filepath) { - ResourceLocation res = ResourceLocation.tryParse(filepath); + Identifier res = Identifier.tryParse(filepath); mResourcesRight.add(res); mFlagsRight.add(false); return mResourcesRight.size() - 1; } - // A helper function to draw a texture scaled to fit. - private void drawScaledTextureWithGlow(Minecraft minecraft, ResourceLocation res, int x, int y, int width, int height) { - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, res); - - // First draw enlarged and blurred, for glow. - RenderSystem.texParameter(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_MIN_FILTER, - GL11.GL_LINEAR); - RenderSystem.texParameter(GL11.GL_TEXTURE_2D, - GL11.GL_TEXTURE_MAG_FILTER, - GL11.GL_LINEAR); - -// GlStateManager._texEnv(GL11.GL_TEXTURE_ENV, -// GL11.GL_TEXTURE_ENV_MODE, //TODO: figure out what this was -// GL11.GL_ADD ); - - // We draw the texture larger, in white, at progressive levels of alpha - // for blur effect (the alpha gets added on each layer) - int blurSteps = 4; // how many levels of progressive blur - double totalBlur = (double) width / 12; // in pixels + /** Pack ARGB color int from alpha (0.0-1.0) and white RGB */ + private static int colorWithAlpha(float alpha) { + int a = Math.clamp((int) (alpha * 255), 0, 255); + return (a << 24) | 0xFFFFFF; + } + + private void drawScaledTextureWithGlow(GuiGraphicsExtractor guiGraphics, Identifier res, int x, int y, int width, int height) { + // Draw blur glow effect - progressive larger blits at low alpha + int blurSteps = 4; + double totalBlur = (double) width / 12; for (int i = 0; i < blurSteps; i++) { double blurAmount = totalBlur / blurSteps * (i + 1); - ModUtils.drawTexQuad(x - blurAmount, - y - blurAmount, - width + 2 * blurAmount, - height + 2 * blurAmount, - 1.0f / blurSteps); + float alpha = 1.0f / blurSteps; + int bx = (int) (x - blurAmount); + int by = (int) (y - blurAmount); + int bw = (int) (width + 2 * blurAmount); + int bh = (int) (height + 2 * blurAmount); + guiGraphics.blit(RenderPipelines.GUI_TEXTURED, res, bx, by, 0, 0, bw, bh, bw, bh, colorWithAlpha(alpha)); } -// GlStateManager._texEnv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE ); - - // TODO: it would be nice if we could modulate the alpha of these overlays, but that doesn't - // work naively with the GL_REPLACE strategy we're using here. Will have to brush up my - // OpenGL knowledge to get alpha-icon with drop-shadow - RenderSystem.setShaderTexture(0, res); - ModUtils.drawTexQuad(x, y, width, height, 1.0f); + // Draw the actual icon at full alpha + guiGraphics.blit(RenderPipelines.GUI_TEXTURED, res, x, y, 0, 0, width, height, width, height, colorWithAlpha(1.0f)); } public static void setStateLeftIcon(int i, boolean b) { @@ -125,17 +96,11 @@ public static void setStateRightIcon(int i, boolean b) { } @Override - public void renderOverlay(GuiGraphics guiGraphics, Minecraft minecraft) { - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); - - // Don't show if the debug screen is open + public void renderOverlay(GuiGraphicsExtractor guiGraphics, Minecraft minecraft) { if (minecraft.getDebugOverlay().showDebugScreen()) { return; } -// RenderSystem.disableLighting(); - mDisplayWidth = minecraft.getWindow().getGuiScaledWidth(); mDisplayHeight = minecraft.getWindow().getGuiScaledHeight(); this.rescale(); @@ -145,7 +110,7 @@ public void renderOverlay(GuiGraphics guiGraphics, Minecraft minecraft) { int yPos = mIconPadding; for (int i = 0; i < mResourcesLeft.size(); i++) { if (mFlagsLeft.get(i)) { - drawScaledTextureWithGlow(minecraft, mResourcesLeft.get(i), xPos, yPos, mIconSize, mIconSize); + drawScaledTextureWithGlow(guiGraphics, mResourcesLeft.get(i), xPos, yPos, mIconSize, mIconSize); } xPos += mIconSize + mIconPadding; } @@ -154,11 +119,9 @@ public void renderOverlay(GuiGraphics guiGraphics, Minecraft minecraft) { xPos = mDisplayWidth - mIconSize - mIconPadding; for (int i = 0; i < mResourcesRight.size(); i++) { if (mFlagsRight.get(i)) { - drawScaledTextureWithGlow(minecraft, mResourcesRight.get(i), xPos, yPos, mIconSize, mIconSize); + drawScaledTextureWithGlow(guiGraphics, mResourcesRight.get(i), xPos, yPos, mIconSize, mIconSize); } xPos -= (mIconSize + mIconPadding); } - - RenderSystem.disableBlend(); } -} \ No newline at end of file +} diff --git a/common/src/main/java/com/specialeffect/eyemine/event/BlockOutlineEvent.java b/common/src/main/java/com/specialeffect/eyemine/event/BlockOutlineEvent.java index f01d8ead..0e1f9854 100644 --- a/common/src/main/java/com/specialeffect/eyemine/event/BlockOutlineEvent.java +++ b/common/src/main/java/com/specialeffect/eyemine/event/BlockOutlineEvent.java @@ -1,15 +1,9 @@ package com.specialeffect.eyemine.event; -import com.mojang.blaze3d.vertex.PoseStack; -import dev.architectury.event.Event; -import dev.architectury.event.EventFactory; -import dev.architectury.event.EventResult; -import net.minecraft.client.renderer.MultiBufferSource; - -public interface BlockOutlineEvent { - Event OUTLINE = EventFactory.createLoop(new BlockOutlineEvent.BlockOutline[0]); - - public interface BlockOutline { - EventResult renderOutline(MultiBufferSource bufferSource, PoseStack poseStack); - } +/** + * Block outline event - now delegates to EyeMineEvents.BLOCK_OUTLINE. + * Kept for compatibility with existing code that references OUTLINE. + */ +public class BlockOutlineEvent { + public static final EventHolder OUTLINE = EyeMineEvents.BLOCK_OUTLINE; } diff --git a/common/src/main/java/com/specialeffect/eyemine/event/EventHolder.java b/common/src/main/java/com/specialeffect/eyemine/event/EventHolder.java new file mode 100644 index 00000000..97477241 --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/event/EventHolder.java @@ -0,0 +1,16 @@ +package com.specialeffect.eyemine.event; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +public class EventHolder { + private final List listeners = new CopyOnWriteArrayList<>(); + + public void register(T listener) { + listeners.add(listener); + } + + public List getListeners() { + return listeners; + } +} diff --git a/common/src/main/java/com/specialeffect/eyemine/event/EventResult.java b/common/src/main/java/com/specialeffect/eyemine/event/EventResult.java new file mode 100644 index 00000000..346a2683 --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/event/EventResult.java @@ -0,0 +1,12 @@ +package com.specialeffect.eyemine.event; + +public enum EventResult { + PASS, + INTERRUPT_TRUE, + INTERRUPT_FALSE; + + public static EventResult pass() { return PASS; } + public static EventResult interruptTrue() { return INTERRUPT_TRUE; } + public static EventResult interruptFalse() { return INTERRUPT_FALSE; } + public boolean isPresent() { return this != PASS; } +} diff --git a/common/src/main/java/com/specialeffect/eyemine/event/EyeMineEvents.java b/common/src/main/java/com/specialeffect/eyemine/event/EyeMineEvents.java new file mode 100644 index 00000000..85ab31d9 --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/event/EyeMineEvents.java @@ -0,0 +1,77 @@ +package com.specialeffect.eyemine.event; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.DeltaTracker; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; + +public final class EyeMineEvents { + public static final EventHolder CLIENT_TICK = new EventHolder<>(); + public static final EventHolder KEY_PRESSED = new EventHolder<>(); + public static final EventHolder SCREEN_SET = new EventHolder<>(); + public static final EventHolder RENDER_HUD = new EventHolder<>(); + public static final EventHolder CLIENT_SETUP = new EventHolder<>(); + public static final EventHolder ENTITY_DEATH = new EventHolder<>(); + public static final EventHolder ENTITY_ADD = new EventHolder<>(); + public static final EventHolder WORLD_LOAD = new EventHolder<>(); + public static final EventHolder PLAYER_TICK = new EventHolder<>(); + public static final EventHolder BLOCK_OUTLINE = new EventHolder<>(); + + @FunctionalInterface + public interface ClientTickListener { + void onClientTick(Minecraft minecraft); + } + + @FunctionalInterface + public interface KeyPressedListener { + EventResult onKeyPressed(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers); + } + + @FunctionalInterface + public interface ScreenSetListener { + ScreenSetResult onScreenSet(Screen screen); + } + + @FunctionalInterface + public interface RenderHudListener { + void onRenderHud(GuiGraphicsExtractor graphics, DeltaTracker deltaTracker); + } + + @FunctionalInterface + public interface ClientSetupListener { + void onClientSetup(Minecraft minecraft); + } + + @FunctionalInterface + public interface EntityDeathListener { + EventResult onDeath(LivingEntity entity, DamageSource source); + } + + @FunctionalInterface + public interface EntityAddListener { + EventResult onAdd(Entity entity, Level level); + } + + @FunctionalInterface + public interface WorldLoadListener { + void onWorldLoad(ServerLevel level); + } + + @FunctionalInterface + public interface PlayerTickListener { + void onPlayerTick(Player player); + } + + @FunctionalInterface + public interface BlockOutlineListener { + EventResult renderOutline(MultiBufferSource bufferSource, PoseStack poseStack); + } +} diff --git a/common/src/main/java/com/specialeffect/eyemine/event/ScreenSetResult.java b/common/src/main/java/com/specialeffect/eyemine/event/ScreenSetResult.java new file mode 100644 index 00000000..3dd042a1 --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/event/ScreenSetResult.java @@ -0,0 +1,8 @@ +package com.specialeffect.eyemine.event; + +import net.minecraft.client.gui.screens.Screen; + +public record ScreenSetResult(boolean handled, Screen screen) { + public static ScreenSetResult pass() { return new ScreenSetResult(false, null); } + public static ScreenSetResult set(Screen screen) { return new ScreenSetResult(true, screen); } +} diff --git a/common/src/main/java/com/specialeffect/eyemine/mixin/KeyboardInputMixin.java b/common/src/main/java/com/specialeffect/eyemine/mixin/KeyboardInputMixin.java index c1ae4630..5a7d9ea9 100644 --- a/common/src/main/java/com/specialeffect/eyemine/mixin/KeyboardInputMixin.java +++ b/common/src/main/java/com/specialeffect/eyemine/mixin/KeyboardInputMixin.java @@ -12,44 +12,43 @@ package com.specialeffect.eyemine.mixin; import com.specialeffect.eyemine.utils.KeyboardInputHelper; -import net.minecraft.client.Options; -import net.minecraft.client.player.Input; +import net.minecraft.client.player.ClientInput; import net.minecraft.client.player.KeyboardInput; -import org.spongepowered.asm.mixin.Final; +import net.minecraft.world.entity.player.Input; +import net.minecraft.world.phys.Vec2; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(KeyboardInput.class) -public class KeyboardInputMixin extends Input { - @Shadow - @Final - private Options options; +public class KeyboardInputMixin extends ClientInput { - @Inject(method = "tick(ZF)V", - locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At( - value = "FIELD", - target = "Lnet/minecraft/client/player/KeyboardInput;up:Z", - shift = Shift.AFTER, - ordinal = 0)) - public void EyeMineTickSetUp(boolean bl, float f, CallbackInfo ci) { - this.up = this.options.keyUp.isDown() || KeyboardInputHelper.mWalkForwardOverride.get(); - } - - @Inject(method = "tick(ZF)V", - locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At( - value = "FIELD", - target = "Lnet/minecraft/client/player/KeyboardInput;forwardImpulse:F", - shift = Shift.AFTER, - ordinal = 0)) - public void EyeMineTick(boolean bl, float f, CallbackInfo ci) { + /** + * After tick() computes key presses and moveVector, override forward movement + * if EyeMine walk override is active. + * + * In 26.1.1, Input is an immutable record (boolean flags only), so we: + * 1. Set the forward flag to true in keyPresses + * 2. Override moveVector.x (forward impulse) with the fractional walk speed + * + * moveVector is a Vec2 where x = left/right (strafe) impulse, y = forward/backward impulse + */ + @Inject(method = "tick()V", at = @At("TAIL")) + public void eyemine$overrideWalkForward(CallbackInfo ci) { if (KeyboardInputHelper.mWalkForwardOverride.get()) { - this.forwardImpulse = Math.max(-1, Math.min(1, KeyboardInputHelper.mOverrideWalkSpeed)); - // TODO: do we still want as drastic a sneak-slowing-down with eyemine?? + Input current = this.keyPresses; + this.keyPresses = new Input( + true, + current.backward(), + current.left(), + current.right(), + current.jump(), + current.shift(), + current.sprint() + ); + float speed = Math.max(-1, Math.min(1, KeyboardInputHelper.mOverrideWalkSpeed)); + this.moveVector = new Vec2(this.moveVector.x, speed); } } } diff --git a/common/src/main/java/com/specialeffect/eyemine/mixin/LivingEntityMixin.java b/common/src/main/java/com/specialeffect/eyemine/mixin/LivingEntityMixin.java index 864a48c3..6b59516d 100644 --- a/common/src/main/java/com/specialeffect/eyemine/mixin/LivingEntityMixin.java +++ b/common/src/main/java/com/specialeffect/eyemine/mixin/LivingEntityMixin.java @@ -1,22 +1,20 @@ package com.specialeffect.eyemine.mixin; import com.specialeffect.eyemine.submod.movement.IStepUp; -import net.minecraft.core.Holder; +import net.minecraft.resources.Identifier; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(LivingEntity.class) public abstract class LivingEntityMixin implements IStepUp { - @Shadow - public abstract double getAttributeValue(Holder holder); + + @Unique + private static final Identifier EYEMINE_STEP_UP_ID = Identifier.fromNamespaceAndPath("eyemine", "extra_step_up"); @Unique public float eyemine$extraStepUp = 0.0F; @@ -29,15 +27,21 @@ public abstract class LivingEntityMixin implements IStepUp { @Override public void eyemine$setExtraStepUp(float stepUp) { this.eyemine$extraStepUp = stepUp; - } - - @Inject(method = "maxUpStep()F", at = @At(value = "RETURN"), cancellable = true) - public void maxUpStep(CallbackInfoReturnable cir) { - LivingEntity livingEntity = (LivingEntity) (Object) this; - if (livingEntity instanceof Player && eyemine$getExtraStepUp() > 0.0F) { - float f = (float) this.getAttributeValue(Attributes.STEP_HEIGHT); - float value = livingEntity.getControllingPassenger() instanceof Player ? Math.max(f, 1.0F) : f; - cir.setReturnValue(value + this.eyemine$getExtraStepUp()); + LivingEntity self = (LivingEntity) (Object) this; + if (self instanceof Player) { + AttributeInstance attr = self.getAttribute(Attributes.STEP_HEIGHT); + if (attr != null) { + // Remove old modifier if present + attr.removeModifier(EYEMINE_STEP_UP_ID); + // Add new modifier if non-zero + if (stepUp > 0.0F) { + attr.addTransientModifier(new AttributeModifier( + EYEMINE_STEP_UP_ID, + stepUp, + AttributeModifier.Operation.ADD_VALUE + )); + } + } } } } diff --git a/common/src/main/java/com/specialeffect/eyemine/mixin/MouseHandlerAccessor.java b/common/src/main/java/com/specialeffect/eyemine/mixin/MouseHandlerAccessor.java index 0c426c80..175cbb13 100644 --- a/common/src/main/java/com/specialeffect/eyemine/mixin/MouseHandlerAccessor.java +++ b/common/src/main/java/com/specialeffect/eyemine/mixin/MouseHandlerAccessor.java @@ -1,6 +1,7 @@ package com.specialeffect.eyemine.mixin; import net.minecraft.client.MouseHandler; +import net.minecraft.client.input.MouseButtonInfo; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; @@ -12,6 +13,6 @@ public interface MouseHandlerAccessor { @Invoker("onScroll") void invokeOnScroll(long l, double d, double e); - @Invoker("onPress") - void invokeOnPress(long l, int i, int j, int k); + @Invoker("onButton") + void invokeOnButton(long l, MouseButtonInfo buttonInfo, int action); } diff --git a/common/src/main/java/com/specialeffect/eyemine/mixin/MouseHandlerMixin.java b/common/src/main/java/com/specialeffect/eyemine/mixin/MouseHandlerMixin.java index 506cd704..18029ebb 100644 --- a/common/src/main/java/com/specialeffect/eyemine/mixin/MouseHandlerMixin.java +++ b/common/src/main/java/com/specialeffect/eyemine/mixin/MouseHandlerMixin.java @@ -99,16 +99,6 @@ public abstract class MouseHandlerMixin { MouseHelper.addPendingEvent(); } - /** - * Set cursor to normal mode before vanilla processes - this allows us to read position - */ - @Inject(method = "onMove(JDD)V", at = @At(value = "FIELD", - target = "Lnet/minecraft/client/MouseHandler;minecraft:Lnet/minecraft/client/Minecraft;", - ordinal = 0)) - public void eyemine$setInputMode(long handle, double xpos, double ypos, CallbackInfo ci) { - GLFW.glfwSetInputMode(this.minecraft.getWindow().getWindow(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL); - } - /** * Main injection point - replaces vanilla onMove logic after the window handle check */ @@ -168,7 +158,7 @@ public abstract class MouseHandlerMixin { // In grabbed mode (eye tracker), reset cursor to origin after each move // This makes each subsequent position effectively a delta if (!MouseHelper.ungrabbedMouseMode) { - GLFW.glfwSetCursorPos(this.minecraft.getWindow().getWindow(), 0, 0); + GLFW.glfwSetCursorPos(this.minecraft.getWindow().handle(), 0, 0); this.xpos = 0; this.ypos = 0; // In grabbed mode, call turnPlayer immediately since position IS the delta @@ -341,7 +331,7 @@ public abstract class MouseHandlerMixin { } this.eyemine$resetVelocity(); - int i = this.minecraft.options.invertYMouse().get() ? -1 : 1; + int i = this.minecraft.options.invertMouseY().get() ? -1 : 1; this.minecraft.getTutorial().onMouse(d2, d3); if (this.minecraft.player != null) { @@ -427,11 +417,11 @@ public abstract class MouseHandlerMixin { } @Inject(method = "grabMouse()V", at = @At(value = "INVOKE", - target = "Lcom/mojang/blaze3d/platform/InputConstants;grabOrReleaseMouse(JIDD)V", + target = "Lcom/mojang/blaze3d/platform/InputConstants;grabOrReleaseMouse(Lcom/mojang/blaze3d/platform/Window;IDD)V", ordinal = 0), cancellable = true) public void eyemine$onlyGrabWhenUngrabbed(CallbackInfo ci) { if (!MouseHelper.ungrabbedMouseMode) { - InputConstants.grabOrReleaseMouse(this.minecraft.getWindow().getWindow(), 212995, this.xpos, this.ypos); + InputConstants.grabOrReleaseMouse(this.minecraft.getWindow(), 212995, this.xpos, this.ypos); } this.minecraft.setScreen((Screen) null); diff --git a/common/src/main/java/com/specialeffect/eyemine/mixin/TitleScreenMixin.java b/common/src/main/java/com/specialeffect/eyemine/mixin/TitleScreenMixin.java index bd54dc6c..274c622f 100644 --- a/common/src/main/java/com/specialeffect/eyemine/mixin/TitleScreenMixin.java +++ b/common/src/main/java/com/specialeffect/eyemine/mixin/TitleScreenMixin.java @@ -11,13 +11,13 @@ package com.specialeffect.eyemine.mixin; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.Util; -import net.minecraft.client.gui.GuiGraphics; + +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; +import org.joml.Matrix3x2fStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -38,29 +38,28 @@ protected TitleScreenMixin(Component component) { super(component); } - @Inject(at = @At("HEAD"), method = "render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V") - public void eyemineTitleHeadRender(GuiGraphics guiGraphics, int p_render_1_, int p_render_2_, float p_render_3_, CallbackInfo ci) { + @Inject(at = @At("HEAD"), method = "extractRenderState(Lnet/minecraft/client/gui/GuiGraphicsExtractor;IIF)V") + public void eyemineTitleHeadRender(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float partialTick, CallbackInfo ci) { if (this.eyemine$firstRenderTime == 0L && this.eyemine$showFadeInAnimation) { - this.eyemine$firstRenderTime = Util.getMillis(); + this.eyemine$firstRenderTime = System.currentTimeMillis(); } - - eyemine$animationTime = this.eyemine$showFadeInAnimation ? (float) (Util.getMillis() - this.eyemine$firstRenderTime) / 1000.0F : 1.0F; + eyemine$animationTime = this.eyemine$showFadeInAnimation ? (float) (System.currentTimeMillis() - this.eyemine$firstRenderTime) / 1000.0F : 1.0F; } - @Inject(at = @At("TAIL"), method = "render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V") - public void eyemineTitleTailRender(GuiGraphics guiGraphics, int p_render_1_, int p_render_2_, float p_render_3_, CallbackInfo ci) { + @Inject(at = @At("TAIL"), method = "extractRenderState(Lnet/minecraft/client/gui/GuiGraphicsExtractor;IIF)V") + public void eyemineTitleTailRender(GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float partialTick, CallbackInfo ci) { float f1 = this.eyemine$showFadeInAnimation ? Mth.clamp(eyemine$animationTime - 1.0F, 0.0F, 1.0F) : 1.0F; int l = Mth.ceil(f1 * 255.0F) << 24; String subtitle = "EyeMine Edition"; if ((l & -67108864) != 0) { - PoseStack poseStack = guiGraphics.pose(); - poseStack.pushPose(); - poseStack.translate((float) (this.width / 2), 25.0F, 0.0F); + Matrix3x2fStack pose = guiGraphics.pose(); + pose.pushMatrix(); + pose.translate((float) (this.width / 2), 25.0F); float f2 = 1.5f; - poseStack.scale(f2, f2, f2); - guiGraphics.drawCenteredString(this.font, subtitle, 0, -8, 16776960 | l); - poseStack.popPose(); + pose.scale(f2, f2); + guiGraphics.centeredText(this.font, subtitle, 0, -8, 16776960 | l); + pose.popMatrix(); } } } diff --git a/common/src/main/java/com/specialeffect/eyemine/packets/NetworkService.java b/common/src/main/java/com/specialeffect/eyemine/packets/NetworkService.java new file mode 100644 index 00000000..5f689852 --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/packets/NetworkService.java @@ -0,0 +1,25 @@ +package com.specialeffect.eyemine.packets; + +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.world.entity.player.Player; + +public interface NetworkService { + void registerC2S( + CustomPacketPayload.Type type, + StreamCodec codec, + PacketHandler handler); + + void sendToServer(CustomPacketPayload payload); + + @FunctionalInterface + interface PacketHandler { + void handle(T payload, PacketContext context); + } + + interface PacketContext { + void queue(Runnable work); + Player getPlayer(); + } +} diff --git a/common/src/main/java/com/specialeffect/eyemine/packets/PacketHandler.java b/common/src/main/java/com/specialeffect/eyemine/packets/PacketHandler.java index d4dd143d..118f84eb 100644 --- a/common/src/main/java/com/specialeffect/eyemine/packets/PacketHandler.java +++ b/common/src/main/java/com/specialeffect/eyemine/packets/PacketHandler.java @@ -17,43 +17,17 @@ import com.specialeffect.eyemine.packets.messages.GatherBlockMessage; import com.specialeffect.eyemine.packets.messages.SendCommandMessage; import com.specialeffect.eyemine.packets.messages.TeleportPlayerToSpawnPointMessage; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.platform.Services; public class PacketHandler { - private static final String PROTOCOL_VERSION = "1"; -// public static final Predicate validator = v -> PROTOCOL_VERSION.equals(v) || NetworkRegistry.ABSENT.equals(v) || NetworkRegistry.ACCEPTVANILLA.equals(v); -// public static final SimpleChannel CHANNEL = NetworkRegistry.ChannelBuilder.named(ResourceLocation.fromNamespaceAndPath("specialeffect", EyeMine.MOD_ID)) -// .clientAcceptedVersions(validator) -// .serverAcceptedVersions(validator) -// .networkProtocolVersion(() -> PROTOCOL_VERSION) -// .simpleChannel(); - - -// public static final NetworkChannel CHANNEL = NetworkChannel.create(ResourceLocation.fromNamespaceAndPath("specialeffect", EyeMine.MOD_ID)); - public static void init() { - NetworkManager.registerReceiver(NetworkManager.c2s(), AddItemToHotbar.ID, AddItemToHotbar.CODEC, AddItemToHotbar.Handler::handle); -// CHANNEL.register(AddItemToHotbar.class, AddItemToHotbar::write, AddItemToHotbar::decode, -// AddItemToHotbar.Handler::handle); - - NetworkManager.registerReceiver(NetworkManager.c2s(), SendCommandMessage.ID, SendCommandMessage.CODEC, SendCommandMessage.Handler::handle); -// CHANNEL.register(SendCommandMessage.class, SendCommandMessage::encode, -// SendCommandMessage::decode, SendCommandMessage.Handler::handle); - - NetworkManager.registerReceiver(NetworkManager.c2s(), TeleportPlayerToSpawnPointMessage.ID, TeleportPlayerToSpawnPointMessage.CODEC, TeleportPlayerToSpawnPointMessage.Handler::handle); -// CHANNEL.register(TeleportPlayerToSpawnPointMessage.class, TeleportPlayerToSpawnPointMessage::encode, -// TeleportPlayerToSpawnPointMessage::decode, TeleportPlayerToSpawnPointMessage.Handler::handle); - - NetworkManager.registerReceiver(NetworkManager.c2s(), GatherBlockMessage.ID, GatherBlockMessage.CODEC, GatherBlockMessage.Handler::handle); -// CHANNEL.register(GatherBlockMessage.class, GatherBlockMessage::encode, -// GatherBlockMessage::decode, GatherBlockMessage.Handler::handle); - - NetworkManager.registerReceiver(NetworkManager.c2s(), ActivateBlockAtPosition.ID, ActivateBlockAtPosition.CODEC, ActivateBlockAtPosition.Handler::handle); -// CHANNEL.register(ActivateBlockAtPosition.class, ActivateBlockAtPosition::encode, -// ActivateBlockAtPosition::decode, ActivateBlockAtPosition.Handler::handle); - - NetworkManager.registerReceiver(NetworkManager.c2s(), ChangeFlyingStateMessage.ID, ChangeFlyingStateMessage.CODEC, ChangeFlyingStateMessage.Handler::handle); -// CHANNEL.register(ChangeFlyingStateMessage.class, ChangeFlyingStateMessage::encode, -// ChangeFlyingStateMessage::decode, ChangeFlyingStateMessage.Handler::handle); + NetworkService net = Services.NETWORK; + + net.registerC2S(AddItemToHotbar.ID, AddItemToHotbar.CODEC, AddItemToHotbar.Handler::handle); + net.registerC2S(SendCommandMessage.ID, SendCommandMessage.CODEC, SendCommandMessage.Handler::handle); + net.registerC2S(TeleportPlayerToSpawnPointMessage.ID, TeleportPlayerToSpawnPointMessage.CODEC, TeleportPlayerToSpawnPointMessage.Handler::handle); + net.registerC2S(GatherBlockMessage.ID, GatherBlockMessage.CODEC, GatherBlockMessage.Handler::handle); + net.registerC2S(ActivateBlockAtPosition.ID, ActivateBlockAtPosition.CODEC, ActivateBlockAtPosition.Handler::handle); + net.registerC2S(ChangeFlyingStateMessage.ID, ChangeFlyingStateMessage.CODEC, ChangeFlyingStateMessage.Handler::handle); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/packets/messages/ActivateBlockAtPosition.java b/common/src/main/java/com/specialeffect/eyemine/packets/messages/ActivateBlockAtPosition.java index 54150bd8..bb6664a3 100644 --- a/common/src/main/java/com/specialeffect/eyemine/packets/messages/ActivateBlockAtPosition.java +++ b/common/src/main/java/com/specialeffect/eyemine/packets/messages/ActivateBlockAtPosition.java @@ -12,16 +12,15 @@ package com.specialeffect.eyemine.packets.messages; import com.specialeffect.eyemine.EyeMine; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.packets.NetworkService; import net.minecraft.core.BlockPos; 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.resources.Identifier; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; @@ -32,7 +31,7 @@ public record ActivateBlockAtPosition(BlockPos pos) implements CustomPacketPaylo ActivateBlockAtPosition::new ); public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>( - ResourceLocation.fromNamespaceAndPath(EyeMine.MOD_ID, "activate_block_at_position")); + Identifier.fromNamespaceAndPath(EyeMine.MOD_ID, "activate_block_at_position")); @Override public Type type() { @@ -41,7 +40,7 @@ public Type type() { public static class Handler { @SuppressWarnings("deprecation") - public static void handle(final ActivateBlockAtPosition pkt, NetworkManager.PacketContext context) { + public static void handle(final ActivateBlockAtPosition pkt, NetworkService.PacketContext context) { context.queue(() -> { Player player = context.getPlayer(); if (player == null) { @@ -50,13 +49,13 @@ public static void handle(final ActivateBlockAtPosition pkt, NetworkManager.Pack Level level = player.level(); BlockState state = level.getBlockState(pkt.pos); - Block block = state.getBlock(); - // NOTE this assumes hit is not used by onBlockActivated: could be a problem with some blocks - BlockHitResult hit = null; + // Create a synthetic hit result pointing at the top of the block + BlockHitResult hit = new BlockHitResult( + pkt.pos.getCenter(), net.minecraft.core.Direction.UP, pkt.pos, false); - // NOTE: should use state.onBlockActivated, but this requires non-null hit, so we suppress warning - block.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), state, level, pkt.pos, player, InteractionHand.MAIN_HAND, hit); + // Use the BlockState's useItemOn which is public + state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, hit); }); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/packets/messages/AddItemToHotbar.java b/common/src/main/java/com/specialeffect/eyemine/packets/messages/AddItemToHotbar.java index 834193ce..65b3f54a 100644 --- a/common/src/main/java/com/specialeffect/eyemine/packets/messages/AddItemToHotbar.java +++ b/common/src/main/java/com/specialeffect/eyemine/packets/messages/AddItemToHotbar.java @@ -12,12 +12,12 @@ package com.specialeffect.eyemine.packets.messages; import com.specialeffect.eyemine.EyeMine; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.packets.NetworkService; 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.resources.Identifier; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -31,7 +31,7 @@ public record AddItemToHotbar(ItemStack item, int slotId) implements CustomPacke AddItemToHotbar::new ); public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>( - ResourceLocation.fromNamespaceAndPath(EyeMine.MOD_ID, "add_item_to_hotbar")); + Identifier.fromNamespaceAndPath(EyeMine.MOD_ID, "add_item_to_hotbar")); @Override public Type type() { @@ -43,7 +43,7 @@ public AddItemToHotbar(ItemStack item) { } public static class Handler { - public static void handle(final AddItemToHotbar pkt, NetworkManager.PacketContext context) { + public static void handle(final AddItemToHotbar pkt, NetworkService.PacketContext context) { context.queue(() -> { Player player = context.getPlayer(); if (player == null) { @@ -56,7 +56,7 @@ public static void handle(final AddItemToHotbar pkt, NetworkManager.PacketContex slot = inventory.getSuitableHotbarSlot(); } inventory.setItem(slot, pkt.item); - inventory.selected = slot; + inventory.setSelectedSlot(slot); }); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/packets/messages/ChangeFlyingStateMessage.java b/common/src/main/java/com/specialeffect/eyemine/packets/messages/ChangeFlyingStateMessage.java index 1083294e..6a81fd8a 100644 --- a/common/src/main/java/com/specialeffect/eyemine/packets/messages/ChangeFlyingStateMessage.java +++ b/common/src/main/java/com/specialeffect/eyemine/packets/messages/ChangeFlyingStateMessage.java @@ -12,12 +12,12 @@ package com.specialeffect.eyemine.packets.messages; import com.specialeffect.eyemine.EyeMine; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.packets.NetworkService; 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.resources.Identifier; import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; @@ -31,7 +31,7 @@ public record ChangeFlyingStateMessage(boolean shouldBeFlying, int flyHeight) im ChangeFlyingStateMessage::new ); public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>( - ResourceLocation.fromNamespaceAndPath(EyeMine.MOD_ID, "change_flying_state")); + Identifier.fromNamespaceAndPath(EyeMine.MOD_ID, "change_flying_state")); @Override public Type type() { @@ -39,7 +39,7 @@ public Type type() { } public static class Handler { - public static void handle(final ChangeFlyingStateMessage pkt, NetworkManager.PacketContext context) { + public static void handle(final ChangeFlyingStateMessage pkt, NetworkService.PacketContext context) { context.queue(() -> { Player player = context.getPlayer(); if (player == null) { diff --git a/common/src/main/java/com/specialeffect/eyemine/packets/messages/GatherBlockMessage.java b/common/src/main/java/com/specialeffect/eyemine/packets/messages/GatherBlockMessage.java index 4d99f00a..5850ec64 100644 --- a/common/src/main/java/com/specialeffect/eyemine/packets/messages/GatherBlockMessage.java +++ b/common/src/main/java/com/specialeffect/eyemine/packets/messages/GatherBlockMessage.java @@ -12,12 +12,12 @@ package com.specialeffect.eyemine.packets.messages; import com.specialeffect.eyemine.EyeMine; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.packets.NetworkService; 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.resources.Identifier; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; @@ -30,7 +30,7 @@ public record GatherBlockMessage(int entityId) implements CustomPacketPayload { GatherBlockMessage::new ); public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>( - ResourceLocation.fromNamespaceAndPath(EyeMine.MOD_ID, "gather_block")); + Identifier.fromNamespaceAndPath(EyeMine.MOD_ID, "gather_block")); @Override public Type type() { @@ -38,14 +38,14 @@ public Type type() { } public static class Handler { - public static void handle(final GatherBlockMessage pkt, NetworkManager.PacketContext context) { + public static void handle(final GatherBlockMessage pkt, NetworkService.PacketContext context) { context.queue(() -> { Player player = context.getPlayer(); if (player == null) { return; } - Level level = player.getCommandSenderWorld(); + Level level = player.level(); Entity target = level.getEntity(pkt.entityId); if (target != null && target instanceof ItemEntity) { // Move item next to player to be picked up automatically diff --git a/common/src/main/java/com/specialeffect/eyemine/packets/messages/SendCommandMessage.java b/common/src/main/java/com/specialeffect/eyemine/packets/messages/SendCommandMessage.java index 190864be..f706fba7 100644 --- a/common/src/main/java/com/specialeffect/eyemine/packets/messages/SendCommandMessage.java +++ b/common/src/main/java/com/specialeffect/eyemine/packets/messages/SendCommandMessage.java @@ -12,13 +12,13 @@ package com.specialeffect.eyemine.packets.messages; import com.specialeffect.eyemine.EyeMine; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.packets.NetworkService; import net.minecraft.commands.Commands; 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.resources.Identifier; import net.minecraft.server.MinecraftServer; public record SendCommandMessage(String command) implements CustomPacketPayload { @@ -28,7 +28,7 @@ public record SendCommandMessage(String command) implements CustomPacketPayload SendCommandMessage::new ); public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>( - ResourceLocation.fromNamespaceAndPath(EyeMine.MOD_ID, "send_command")); + Identifier.fromNamespaceAndPath(EyeMine.MOD_ID, "send_command")); @Override public Type type() { @@ -36,15 +36,15 @@ public Type type() { } public static class Handler { - public static void handle(final SendCommandMessage pkt, NetworkManager.PacketContext context) { + public static void handle(final SendCommandMessage pkt, NetworkService.PacketContext context) { context.queue(() -> { - MinecraftServer server = context.getPlayer().getServer(); + MinecraftServer server = context.getPlayer().level().getServer(); if (server == null) { - System.out.println("Server is null, cannot send command"); + EyeMine.LOGGER.warn("Server is null, cannot send command"); } else { Commands mgr = server.getCommands(); if (null == mgr) { - System.out.println("CommandManager is null, cannot send command"); + EyeMine.LOGGER.warn("CommandManager is null, cannot send command"); } else { mgr.performPrefixedCommand(server.createCommandSourceStack(), pkt.command); } diff --git a/common/src/main/java/com/specialeffect/eyemine/packets/messages/TeleportPlayerToSpawnPointMessage.java b/common/src/main/java/com/specialeffect/eyemine/packets/messages/TeleportPlayerToSpawnPointMessage.java index ffc1f37e..8d50fabc 100644 --- a/common/src/main/java/com/specialeffect/eyemine/packets/messages/TeleportPlayerToSpawnPointMessage.java +++ b/common/src/main/java/com/specialeffect/eyemine/packets/messages/TeleportPlayerToSpawnPointMessage.java @@ -12,13 +12,13 @@ package com.specialeffect.eyemine.packets.messages; import com.specialeffect.eyemine.EyeMine; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.packets.NetworkService; import net.minecraft.core.BlockPos; 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.resources.Identifier; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; @@ -27,7 +27,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.portal.DimensionTransition; +import net.minecraft.world.level.portal.TeleportTransition; +import net.minecraft.world.level.storage.LevelData; import net.minecraft.world.phys.Vec3; public record TeleportPlayerToSpawnPointMessage() implements CustomPacketPayload { @@ -35,7 +36,7 @@ public record TeleportPlayerToSpawnPointMessage() implements CustomPacketPayload TeleportPlayerToSpawnPointMessage::write, TeleportPlayerToSpawnPointMessage::new); public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>( - ResourceLocation.fromNamespaceAndPath(EyeMine.MOD_ID, "teleport_to_spawn_point")); + Identifier.fromNamespaceAndPath(EyeMine.MOD_ID, "teleport_to_spawn_point")); @Override public Type type() { @@ -51,39 +52,43 @@ public void write(FriendlyByteBuf buf) { } public static class Handler { - public static void handle(final TeleportPlayerToSpawnPointMessage pkt, NetworkManager.PacketContext context) { + public static void handle(final TeleportPlayerToSpawnPointMessage pkt, NetworkService.PacketContext context) { context.queue(() -> { Player player = context.getPlayer(); if (player == null) { return; } - if (!player.level().isClientSide) { - MinecraftServer server = player.getServer(); + if (!player.level().isClientSide()) { + MinecraftServer server = player.level().getServer(); ServerPlayer serverPlayer = (ServerPlayer) player; - ServerLevel respawnDimension = server.getLevel(serverPlayer.getRespawnDimension()); - BlockPos respawnPos = serverPlayer.getRespawnPosition(); - float respawnAngle = serverPlayer.getRespawnAngle(); - DimensionTransition transition; - if (serverPlayer != null && respawnPos != null) { - transition = serverPlayer.findRespawnPositionAndUseSpawnBlock(false, DimensionTransition.DO_NOTHING); - } else { - transition = null; - } + ServerPlayer.RespawnConfig respawnConfig = serverPlayer.getRespawnConfig(); + TeleportTransition transition; + if (respawnConfig != null) { + LevelData.RespawnData respawnData = respawnConfig.respawnData(); + BlockPos respawnPos = respawnData.pos(); + float respawnAngle = respawnData.yaw(); + ServerLevel respawnDimension = server.getLevel(respawnData.dimension()); + transition = serverPlayer.findRespawnPositionAndUseSpawnBlock(false, TeleportTransition.DO_NOTHING); - if (transition != null) { - BlockState state = respawnDimension.getBlockState(respawnPos); - boolean blockIsRespawnAnchor = state.is(Blocks.RESPAWN_ANCHOR); - Vec3 vector3d = transition.pos(); - float f1; - if (!state.is(BlockTags.BEDS) && !blockIsRespawnAnchor) { - f1 = respawnAngle; - } else { - Vec3 vector3d1 = Vec3.atBottomCenterOf(respawnPos).subtract(vector3d).normalize(); - f1 = (float) Mth.wrapDegrees(Mth.atan2(vector3d1.z, vector3d1.x) * (double) (180F / (float) Math.PI) - 90.0D); + if (transition != null && respawnDimension != null) { + BlockState state = respawnDimension.getBlockState(respawnPos); + boolean blockIsRespawnAnchor = state.is(Blocks.RESPAWN_ANCHOR); + Vec3 vector3d = transition.position(); + float f1; + if (!state.is(BlockTags.BEDS) && !blockIsRespawnAnchor) { + f1 = respawnAngle; + } else { + Vec3 vector3d1 = Vec3.atBottomCenterOf(respawnPos).subtract(vector3d).normalize(); + f1 = (float) Mth.wrapDegrees(Mth.atan2(vector3d1.z, vector3d1.x) * (double) (180F / (float) Math.PI) - 90.0D); + } + serverPlayer.teleportTo(respawnDimension, vector3d.x, vector3d.y, vector3d.z, java.util.Set.of(), f1, 0.0F, false); + serverPlayer.setRespawnPosition( + new ServerPlayer.RespawnConfig( + LevelData.RespawnData.of(respawnDimension.dimension(), BlockPos.containing(vector3d), respawnAngle, 0.0F), + false + ), false); } - serverPlayer.moveTo(vector3d.x, vector3d.y, vector3d.z, f1, 0.0F); - serverPlayer.setRespawnPosition(respawnDimension.dimension(), BlockPos.containing(vector3d), respawnAngle, false, false); } } }); diff --git a/common/src/main/java/com/specialeffect/eyemine/platform/EyeMineConfig.java b/common/src/main/java/com/specialeffect/eyemine/platform/EyeMineConfig.java index e8d4e627..ffd7dfc6 100644 --- a/common/src/main/java/com/specialeffect/eyemine/platform/EyeMineConfig.java +++ b/common/src/main/java/com/specialeffect/eyemine/platform/EyeMineConfig.java @@ -1,197 +1,36 @@ package com.specialeffect.eyemine.platform; -import dev.architectury.injectables.annotations.ExpectPlatform; - public class EyeMineConfig { - @ExpectPlatform - public static boolean getDisableCustomNewWorld() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static void setCustomSpeedFactor(float speed) { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getUsingMouseEmulation() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getAutoSelectTool() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getAutoSelectSword() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getTicksBetweenMining() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getRadiusChests() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static double getBowDrawTime() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static float getFullscreenOverlayAlpha() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getIronsightsFovReduction() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static double getIronsightsSensitivityReduction() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getUseDwellForSingleUseItem() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getUseDwellForSingleMine() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getServerCompatibilityMode() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getRadiusDoors() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getFlyHeightManual() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getFlyHeightAuto() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getDefaultDoAutoJump() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getDisableAutoJumpFixes() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getMoveWhenMouseStationary() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getSlowdownOnCorners() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getWalkingSlowdownFilter() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getAllowLadderDescent() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static float getCustomSpeedFactor() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static float getBoatMaxTurnAtSpeed() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static double getBoatSlowdown() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static double getDwellTimeSeconds() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static double getDwellLockonTimeSeconds() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getDwellShowWithTransparency() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getDwellShowExpanding() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean getSlowdownOnAttack() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getGazeIdleThreshold() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } + public static boolean getDisableCustomNewWorld() { return Services.CONFIG.getDisableCustomNewWorld(); } + public static void setCustomSpeedFactor(float speed) { Services.CONFIG.setCustomSpeedFactor(speed); } + public static boolean getUsingMouseEmulation() { return Services.CONFIG.getUsingMouseEmulation(); } + public static boolean getAutoSelectTool() { return Services.CONFIG.getAutoSelectTool(); } + public static boolean getAutoSelectSword() { return Services.CONFIG.getAutoSelectSword(); } + public static int getTicksBetweenMining() { return Services.CONFIG.getTicksBetweenMining(); } + public static int getRadiusChests() { return Services.CONFIG.getRadiusChests(); } + public static double getBowDrawTime() { return Services.CONFIG.getBowDrawTime(); } + public static float getFullscreenOverlayAlpha() { return Services.CONFIG.getFullscreenOverlayAlpha(); } + public static int getIronsightsFovReduction() { return Services.CONFIG.getIronsightsFovReduction(); } + public static double getIronsightsSensitivityReduction() { return Services.CONFIG.getIronsightsSensitivityReduction(); } + public static boolean getUseDwellForSingleUseItem() { return Services.CONFIG.getUseDwellForSingleUseItem(); } + public static boolean getUseDwellForSingleMine() { return Services.CONFIG.getUseDwellForSingleMine(); } + public static boolean getServerCompatibilityMode() { return Services.CONFIG.getServerCompatibilityMode(); } + public static int getRadiusDoors() { return Services.CONFIG.getRadiusDoors(); } + public static int getFlyHeightManual() { return Services.CONFIG.getFlyHeightManual(); } + public static int getFlyHeightAuto() { return Services.CONFIG.getFlyHeightAuto(); } + public static boolean getDefaultDoAutoJump() { return Services.CONFIG.getDefaultDoAutoJump(); } + public static boolean getDisableAutoJumpFixes() { return Services.CONFIG.getDisableAutoJumpFixes(); } + public static boolean getMoveWhenMouseStationary() { return Services.CONFIG.getMoveWhenMouseStationary(); } + public static boolean getSlowdownOnCorners() { return Services.CONFIG.getSlowdownOnCorners(); } + public static int getWalkingSlowdownFilter() { return Services.CONFIG.getWalkingSlowdownFilter(); } + public static boolean getAllowLadderDescent() { return Services.CONFIG.getAllowLadderDescent(); } + public static float getCustomSpeedFactor() { return Services.CONFIG.getCustomSpeedFactor(); } + public static float getBoatMaxTurnAtSpeed() { return Services.CONFIG.getBoatMaxTurnAtSpeed(); } + public static double getBoatSlowdown() { return Services.CONFIG.getBoatSlowdown(); } + public static double getDwellTimeSeconds() { return Services.CONFIG.getDwellTimeSeconds(); } + public static double getDwellLockonTimeSeconds() { return Services.CONFIG.getDwellLockonTimeSeconds(); } + public static boolean getDwellShowWithTransparency() { return Services.CONFIG.getDwellShowWithTransparency(); } + public static boolean getDwellShowExpanding() { return Services.CONFIG.getDwellShowExpanding(); } + public static boolean getSlowdownOnAttack() { return Services.CONFIG.getSlowdownOnAttack(); } + public static int getGazeIdleThreshold() { return Services.CONFIG.getGazeIdleThreshold(); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/platform/InventoryConfig.java b/common/src/main/java/com/specialeffect/eyemine/platform/InventoryConfig.java index f17b2348..b44795bc 100644 --- a/common/src/main/java/com/specialeffect/eyemine/platform/InventoryConfig.java +++ b/common/src/main/java/com/specialeffect/eyemine/platform/InventoryConfig.java @@ -1,155 +1,29 @@ package com.specialeffect.eyemine.platform; -import dev.architectury.injectables.annotations.ExpectPlatform; - public class InventoryConfig { - @ExpectPlatform - public static int getKey0() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey1() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey2() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey3() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey4() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey5() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey6() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey7() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey8() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKey9() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeySurvPrevTab() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeySurvNextTab() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeySurvRecipes() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeySurvCraftable() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getkeySurvPrevPage() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getkeySurvNextPage() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeySurvOutput() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeyPrev() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeyNext() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeyNextItemRow() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeyNextItemCol() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeyScrollUp() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeyScrollDown() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeySearch() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } - - @ExpectPlatform - public static int getKeyDrop() { - // Just throw an error, the content should get replaced at runtime. - throw new AssertionError(); - } + public static int getKey0() { return Services.INVENTORY_CONFIG.getKey0(); } + public static int getKey1() { return Services.INVENTORY_CONFIG.getKey1(); } + public static int getKey2() { return Services.INVENTORY_CONFIG.getKey2(); } + public static int getKey3() { return Services.INVENTORY_CONFIG.getKey3(); } + public static int getKey4() { return Services.INVENTORY_CONFIG.getKey4(); } + public static int getKey5() { return Services.INVENTORY_CONFIG.getKey5(); } + public static int getKey6() { return Services.INVENTORY_CONFIG.getKey6(); } + public static int getKey7() { return Services.INVENTORY_CONFIG.getKey7(); } + public static int getKey8() { return Services.INVENTORY_CONFIG.getKey8(); } + public static int getKey9() { return Services.INVENTORY_CONFIG.getKey9(); } + public static int getKeySurvPrevTab() { return Services.INVENTORY_CONFIG.getKeySurvPrevTab(); } + public static int getKeySurvNextTab() { return Services.INVENTORY_CONFIG.getKeySurvNextTab(); } + public static int getKeySurvRecipes() { return Services.INVENTORY_CONFIG.getKeySurvRecipes(); } + public static int getKeySurvCraftable() { return Services.INVENTORY_CONFIG.getKeySurvCraftable(); } + public static int getkeySurvPrevPage() { return Services.INVENTORY_CONFIG.getkeySurvPrevPage(); } + public static int getkeySurvNextPage() { return Services.INVENTORY_CONFIG.getkeySurvNextPage(); } + public static int getKeySurvOutput() { return Services.INVENTORY_CONFIG.getKeySurvOutput(); } + public static int getKeyPrev() { return Services.INVENTORY_CONFIG.getKeyPrev(); } + public static int getKeyNext() { return Services.INVENTORY_CONFIG.getKeyNext(); } + public static int getKeyNextItemRow() { return Services.INVENTORY_CONFIG.getKeyNextItemRow(); } + public static int getKeyNextItemCol() { return Services.INVENTORY_CONFIG.getKeyNextItemCol(); } + public static int getKeyScrollUp() { return Services.INVENTORY_CONFIG.getKeyScrollUp(); } + public static int getKeyScrollDown() { return Services.INVENTORY_CONFIG.getKeyScrollDown(); } + public static int getKeySearch() { return Services.INVENTORY_CONFIG.getKeySearch(); } + public static int getKeyDrop() { return Services.INVENTORY_CONFIG.getKeyDrop(); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/platform/Services.java b/common/src/main/java/com/specialeffect/eyemine/platform/Services.java new file mode 100644 index 00000000..3a89e2a1 --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/platform/Services.java @@ -0,0 +1,27 @@ +package com.specialeffect.eyemine.platform; + +import com.specialeffect.eyemine.packets.NetworkService; +import com.specialeffect.eyemine.platform.services.IEyeMineConfigService; +import com.specialeffect.eyemine.platform.services.IInventoryConfigService; +import com.specialeffect.eyemine.platform.services.IPlatformHelper; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.ServiceLoader; + +public class Services { + private static final Logger LOGGER = LogManager.getLogger(); + + public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class); + public static final IEyeMineConfigService CONFIG = load(IEyeMineConfigService.class); + public static final IInventoryConfigService INVENTORY_CONFIG = load(IInventoryConfigService.class); + public static final NetworkService NETWORK = load(NetworkService.class); + + public static T load(Class clazz) { + final T loadedService = ServiceLoader.load(clazz) + .findFirst() + .orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName())); + LOGGER.debug("Loaded {} for service {}", loadedService, clazz); + return loadedService; + } +} diff --git a/common/src/main/java/com/specialeffect/eyemine/platform/services/IEyeMineConfigService.java b/common/src/main/java/com/specialeffect/eyemine/platform/services/IEyeMineConfigService.java new file mode 100644 index 00000000..d9a3ca4a --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/platform/services/IEyeMineConfigService.java @@ -0,0 +1,36 @@ +package com.specialeffect.eyemine.platform.services; + +public interface IEyeMineConfigService { + boolean getDisableCustomNewWorld(); + void setCustomSpeedFactor(float speed); + boolean getUsingMouseEmulation(); + boolean getAutoSelectTool(); + boolean getAutoSelectSword(); + int getTicksBetweenMining(); + int getRadiusChests(); + double getBowDrawTime(); + float getFullscreenOverlayAlpha(); + int getIronsightsFovReduction(); + double getIronsightsSensitivityReduction(); + boolean getUseDwellForSingleUseItem(); + boolean getUseDwellForSingleMine(); + boolean getServerCompatibilityMode(); + int getRadiusDoors(); + int getFlyHeightManual(); + int getFlyHeightAuto(); + boolean getDefaultDoAutoJump(); + boolean getDisableAutoJumpFixes(); + boolean getMoveWhenMouseStationary(); + boolean getSlowdownOnCorners(); + int getWalkingSlowdownFilter(); + boolean getAllowLadderDescent(); + float getCustomSpeedFactor(); + float getBoatMaxTurnAtSpeed(); + double getBoatSlowdown(); + double getDwellTimeSeconds(); + double getDwellLockonTimeSeconds(); + boolean getDwellShowWithTransparency(); + boolean getDwellShowExpanding(); + boolean getSlowdownOnAttack(); + int getGazeIdleThreshold(); +} diff --git a/common/src/main/java/com/specialeffect/eyemine/platform/services/IInventoryConfigService.java b/common/src/main/java/com/specialeffect/eyemine/platform/services/IInventoryConfigService.java new file mode 100644 index 00000000..40f3b0a3 --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/platform/services/IInventoryConfigService.java @@ -0,0 +1,29 @@ +package com.specialeffect.eyemine.platform.services; + +public interface IInventoryConfigService { + int getKey0(); + int getKey1(); + int getKey2(); + int getKey3(); + int getKey4(); + int getKey5(); + int getKey6(); + int getKey7(); + int getKey8(); + int getKey9(); + int getKeySurvPrevTab(); + int getKeySurvNextTab(); + int getKeySurvRecipes(); + int getKeySurvCraftable(); + int getkeySurvPrevPage(); + int getkeySurvNextPage(); + int getKeySurvOutput(); + int getKeyPrev(); + int getKeyNext(); + int getKeyNextItemRow(); + int getKeyNextItemCol(); + int getKeyScrollUp(); + int getKeyScrollDown(); + int getKeySearch(); + int getKeyDrop(); +} diff --git a/common/src/main/java/com/specialeffect/eyemine/platform/services/IPlatformHelper.java b/common/src/main/java/com/specialeffect/eyemine/platform/services/IPlatformHelper.java new file mode 100644 index 00000000..05129278 --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/platform/services/IPlatformHelper.java @@ -0,0 +1,7 @@ +package com.specialeffect.eyemine.platform.services; + +public interface IPlatformHelper { + String getPlatformName(); + boolean isModLoaded(String modId); + boolean isDevelopmentEnvironment(); +} diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/KeyInputUtil.java b/common/src/main/java/com/specialeffect/eyemine/submod/KeyInputUtil.java new file mode 100644 index 00000000..aec372da --- /dev/null +++ b/common/src/main/java/com/specialeffect/eyemine/submod/KeyInputUtil.java @@ -0,0 +1,29 @@ +package com.specialeffect.eyemine.submod; + +import com.mojang.blaze3d.platform.InputConstants; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.utils.ModUtils; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; +import net.minecraft.client.input.KeyEvent; + +/** + * Utility to reduce boilerplate in submod key input handlers. + * Most submods follow the same pattern: check GUI, check F11, check keybinding, run action. + */ +public class KeyInputUtil { + + /** + * Returns true if key events should be ignored (GUI open or F11 debug key held). + */ + public static boolean shouldIgnoreKeyInput(Minecraft minecraft) { + return ModUtils.hasActiveGui() || InputConstants.isKeyDown(minecraft.getWindow(), 292); + } + + /** + * Check if a keybinding was just pressed. Call after shouldIgnoreKeyInput(). + */ + public static boolean wasKeyPressed(KeyMapping binding, int keyCode, int scanCode, int modifiers) { + return binding.matches(new KeyEvent(keyCode, scanCode, modifiers)) && binding.consumeClick(); + } +} diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/mining/ContinuouslyMine.java b/common/src/main/java/com/specialeffect/eyemine/submod/mining/ContinuouslyMine.java index 81e6fcb4..48c3f140 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/mining/ContinuouslyMine.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/mining/ContinuouslyMine.java @@ -11,6 +11,7 @@ package com.specialeffect.eyemine.submod.mining; +import com.specialeffect.eyemine.EyeMine; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.InputConstants.Type; import com.specialeffect.eyemine.client.Keybindings; @@ -19,14 +20,18 @@ import com.specialeffect.eyemine.packets.messages.AddItemToHotbar; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.misc.ContinuouslyAttack; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.mouse.MouseHandlerMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.packets.NetworkService; +import com.specialeffect.eyemine.platform.Services; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -34,7 +39,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.item.PickaxeItem; +import net.minecraft.tags.ItemTags; import org.lwjgl.glfw.GLFW; import com.specialeffect.eyemine.utils.MouseHelper; @@ -67,14 +72,14 @@ public void onInitializeClient() { "key.eyemine.continious_destroy", Type.KEYSYM, GLFW.GLFW_KEY_M, - "category.eyemine.category.eyegaze_common" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_COMMON // The translation key of the keybinding's category. )); // Register an icon for the overlay mIconIndex = StateOverlay.registerTextureRight("eyemine:textures/icons/mine.png"); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } @Override @@ -130,14 +135,14 @@ public void onClientTick(Minecraft event) { // accompanying mouse movement. if (MouseHandlerMod.hasPendingEvent() || mMouseEventLastTick) { if (miningTimer == 0) { - System.out.println("attack"); + EyeMine.LOGGER.debug("attack"); KeyMapping.click(((KeyMappingAccessor) attackBinding).getActualKey()); if (player.isCreative()) { miningTimer = miningCooldown.getAsInt(); } } else { if (player.attackAnim == 0) { - System.out.println("swing"); + EyeMine.LOGGER.debug("swing"); player.swing(InteractionHand.MAIN_HAND); } } @@ -161,15 +166,11 @@ public void onClientTick(Minecraft event) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mDestroyKB.matches(keyCode, scanCode) && mDestroyKB.consumeClick()) { + if (mDestroyKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDestroyKB.consumeClick()) { mIsAttacking = !mIsAttacking; StateOverlay.setStateRightIcon(mIconIndex, mIsAttacking); @@ -197,12 +198,12 @@ static boolean choosePickaxe(Inventory inventory) { // In creative mode, we can either select a pickaxe from the hotbar // or just rustle up a new one - if (inventory.getSelected().getItem() instanceof PickaxeItem) { + if (inventory.getSelectedItem().is(ItemTags.PICKAXES)) { return true; } else { - int pickaxeId = ModUtils.findItemInHotbar(inventory, (item -> item instanceof PickaxeItem)); + int pickaxeId = ModUtils.findItemInHotbar(inventory, (item -> item.builtInRegistryHolder().is(ItemTags.PICKAXES))); if (pickaxeId > -1) { - inventory.selected = pickaxeId; + inventory.setSelectedSlot(pickaxeId); return true; } else { return false; @@ -212,6 +213,6 @@ static boolean choosePickaxe(Inventory inventory) { static void requestCreatePickaxe() { // Ask server to put new item in hotbar - NetworkManager.sendToServer(new AddItemToHotbar(new ItemStack(Items.DIAMOND_PICKAXE))); + Services.NETWORK.sendToServer(new AddItemToHotbar(new ItemStack(Items.DIAMOND_PICKAXE))); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/mining/DwellMine.java b/common/src/main/java/com/specialeffect/eyemine/submod/mining/DwellMine.java index 98b0b5f7..669ca71e 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/mining/DwellMine.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/mining/DwellMine.java @@ -16,11 +16,12 @@ import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.submod.utils.DwellAction; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.utils.TargetBlock; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; @@ -41,18 +42,18 @@ public void onInitializeClient() { "key.eyemine.toggle_dwell", Type.KEYSYM, GLFW.GLFW_KEY_KP_6, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mDwellMineOnceKB = new KeyMapping( "key.eyemine.dwell_once", Type.KEYSYM, GLFW.GLFW_KEY_KP_8, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); //Initialize variables super.onInitializeClient(); @@ -65,15 +66,11 @@ public void performAction(TargetBlock block) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mDwellMineKB.matches(keyCode, scanCode) && mDwellMineKB.consumeClick()) { + if (mDwellMineKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDwellMineKB.consumeClick()) { if (mDwelling) { // Turn off dwell mine this.setDwelling(false); @@ -86,7 +83,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i return EventResult.pass(); } - if (mDwellMineOnceKB.matches(keyCode, scanCode) && mDwellMineOnceKB.consumeClick()) { + if (mDwellMineOnceKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDwellMineOnceKB.consumeClick()) { this.dwellOnce(); return EventResult.pass(); } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/mining/GatherDrops.java b/common/src/main/java/com/specialeffect/eyemine/submod/mining/GatherDrops.java index 957619c7..30748306 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/mining/GatherDrops.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/mining/GatherDrops.java @@ -16,10 +16,12 @@ import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.packets.messages.GatherBlockMessage; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.packets.NetworkService; +import com.specialeffect.eyemine.platform.Services; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -47,23 +49,19 @@ public void onInitializeClient() { "key.eyemine.gather", Type.KEYSYM, GLFW.GLFW_KEY_KP_MULTIPLY, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { - return EventResult.pass(); - } - - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (mGatherKB.matches(keyCode, scanCode) && mGatherKB.consumeClick()) { + if (mGatherKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mGatherKB.consumeClick()) { LocalPlayer player = minecraft.player; gatherBlocks(player); } @@ -82,7 +80,7 @@ public static void gatherBlocks(LocalPlayer player) { LOGGER.debug("gathering " + items.size() + " nearby items"); // Ask server to move items for (ItemEntity itemEntity : items) { - NetworkManager.sendToServer(new GatherBlockMessage(itemEntity.getId())); + Services.NETWORK.sendToServer(new GatherBlockMessage(itemEntity.getId())); } } } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/mining/MineOne.java b/common/src/main/java/com/specialeffect/eyemine/submod/mining/MineOne.java index e0bc5b45..db780c25 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/mining/MineOne.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/mining/MineOne.java @@ -17,18 +17,19 @@ import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.utils.DwellAction; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.utils.TargetBlock; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; -import net.minecraft.world.item.SwordItem; +import net.minecraft.tags.ItemTags; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import org.lwjgl.glfw.GLFW; @@ -49,11 +50,11 @@ public void onInitializeClient() { "key.eyemine.mine_singular", Type.KEYSYM, GLFW.GLFW_KEY_N, - "category.eyemine.category.eyegaze_common" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_COMMON // The translation key of the keybinding's category. )); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); //Initialize variables super.onInitializeClient(); @@ -70,7 +71,7 @@ public void onClientTick(Minecraft minecraft) { ClientLevel level = minecraft.level; // Swords can't destroy blocks: warn user - if (player.getMainHandItem().getItem() instanceof SwordItem) { + if (player.getMainHandItem().is(ItemTags.SWORDS)) { String message = "Can't destroy blocks with a sword, please select another item"; player.sendSystemMessage(Component.literal(message)); @@ -121,15 +122,11 @@ private BlockPos getMouseOverBlockPos() { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mDestroyKB.matches(keyCode, scanCode) && mDestroyKB.consumeClick()) { + if (mDestroyKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDestroyKB.consumeClick()) { // turn off continuous mining ContinuouslyMine.stop(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/AutoOpenDoors.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/AutoOpenDoors.java index 022c579d..76eddc27 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/AutoOpenDoors.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/AutoOpenDoors.java @@ -15,7 +15,7 @@ import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; import com.specialeffect.eyemine.submod.SubMod; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.prediction.BlockStatePredictionHandler; @@ -25,7 +25,7 @@ import net.minecraft.core.Vec3i; import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; import net.minecraft.world.InteractionHand; -import net.minecraft.world.ItemInteractionResult; +import net.minecraft.world.InteractionResult; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.phys.BlockHitResult; @@ -38,7 +38,7 @@ public class AutoOpenDoors extends SubMod implements IConfigListener { public final String MODID = "autoopendoors"; public void onInitializeClient() { - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); } public void syncConfig() { @@ -89,7 +89,7 @@ public void onClientTick(Minecraft event) { } BlockHitResult blockHitResult = new BlockHitResult(hitVec, fakeDirection, blockPos, true); - ItemInteractionResult result = state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, blockHitResult); + InteractionResult result = state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, blockHitResult); if (result.consumesAction()) { BlockStatePredictionHandler blockstatepredictionhandler = ((ClientLevelAccessor) level).eyemineGetPredictionHandler().startPredicting(); int i = blockstatepredictionhandler.currentSequence(); @@ -124,7 +124,7 @@ public void onClientTick(Minecraft event) { } } BlockHitResult blockHitResult = new BlockHitResult(hitVec, fakeDirection, pos, true); - ItemInteractionResult result = state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, blockHitResult); + InteractionResult result = state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, blockHitResult); if (result.consumesAction()) { BlockStatePredictionHandler blockstatepredictionhandler = ((ClientLevelAccessor) level).eyemineGetPredictionHandler().startPredicting(); int i = blockstatepredictionhandler.currentSequence(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/AutoPillar.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/AutoPillar.java index 81a0a9db..3ab75d60 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/AutoPillar.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/AutoPillar.java @@ -18,16 +18,18 @@ import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.packets.messages.AddItemToHotbar; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.packets.NetworkService; +import com.specialeffect.eyemine.platform.Services; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket; +import net.minecraft.world.entity.player.Input; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.BlockItem; @@ -58,11 +60,11 @@ public void onInitializeClient() { "key.eyemine.pillar", Type.KEYSYM, GLFW.GLFW_KEY_0, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } private float lastPlayerPitch; @@ -95,11 +97,7 @@ protected void queueOnLivingCallback(OnLivingCallback onLivingCallback) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { - return EventResult.pass(); - } - - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } @@ -109,7 +107,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i // - next few ticks, gradually reset view // Technically there is no need to change player's view, but the user experience // is weird if you don't (you don't really know what just happened). - if (autoPlaceKeyBinding.matches(keyCode, scanCode) && autoPlaceKeyBinding.consumeClick()) { + if (autoPlaceKeyBinding.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && autoPlaceKeyBinding.consumeClick()) { float origPitchTemp; synchronized (mOnLivingQueue) { origPitchTemp = lastPlayerPitch; @@ -124,7 +122,9 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i Minecraft mc = Minecraft.getInstance(); LocalPlayer player = mc.player; - player.connection.send(new ServerboundPlayerInputPacket(player.xxa, player.zza, true, player.input.shiftKeyDown)); + player.connection.send(new ServerboundPlayerInputPacket(new Input( + player.zza > 0, player.zza < 0, player.xxa > 0, player.xxa < 0, + true, player.isShiftKeyDown(), false))); player.jumpFromGround(); player.setXRot(90); @@ -176,10 +176,10 @@ static void chooseBlock(Inventory inventory) { // or just rustle up a new one int blockId = ModUtils.findItemInHotbar(inventory, (item -> item instanceof BlockItem)); if (blockId > -1) { - inventory.selected = blockId; + inventory.setSelectedSlot(blockId); } else { // Ask server to put new item in hotbar - NetworkManager.sendToServer(new AddItemToHotbar(new ItemStack(Blocks.SHORT_GRASS))); + Services.NETWORK.sendToServer(new AddItemToHotbar(new ItemStack(Blocks.SHORT_GRASS))); } } } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/ContinuouslyAttack.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/ContinuouslyAttack.java index a37834cd..8f35dbec 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/ContinuouslyAttack.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/ContinuouslyAttack.java @@ -19,24 +19,27 @@ import com.specialeffect.eyemine.packets.messages.AddItemToHotbar; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.mining.ContinuouslyMine; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.utils.MouseHelper; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.packets.NetworkService; +import com.specialeffect.eyemine.platform.Services; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.network.protocol.game.ServerboundInteractPacket; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.item.SwordItem; +import net.minecraft.tags.ItemTags; import net.minecraft.world.phys.EntityHitResult; import org.lwjgl.glfw.GLFW; @@ -56,14 +59,14 @@ public void onInitializeClient() { "key.eyemine.continious_attack", Type.KEYSYM, GLFW.GLFW_KEY_R, - "category.eyemine.category.eyegaze_common" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_COMMON // The translation key of the keybinding's category. )); // Register an icon for the overlay mIconIndex = StateOverlay.registerTextureRight("eyemine:textures/icons/attack.png"); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } @Override @@ -114,9 +117,11 @@ public void onClientTick(Minecraft minecraft) { final KeyMapping attackBinding = Minecraft.getInstance().options.keyAttack; KeyMapping.click(((KeyMappingAccessor) attackBinding).getActualKey()); } else { - player.attack(entity); -// channel.sendToServer(new AttackEntityMessage(entity)); - player.connection.send(ServerboundInteractPacket.createAttackPacket(entity, player.isShiftKeyDown())); + // Use gameMode.attack which handles both local and server-side + MultiPlayerGameMode gameMode = Minecraft.getInstance().gameMode; + if (gameMode != null) { + gameMode.attack(player, entity); + } } } else { recharging = true; @@ -133,15 +138,11 @@ public void onClientTick(Minecraft minecraft) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mAttackKB.matches(keyCode, scanCode) && mAttackKB.consumeClick()) { + if (mAttackKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mAttackKB.consumeClick()) { mIsAttacking = !mIsAttacking; StateOverlay.setStateRightIcon(mIconIndex, mIsAttacking); @@ -156,12 +157,12 @@ private boolean chooseWeapon(Inventory inventory) { // In creative mode, we can either select a sword from the hotbar // or just rustle up a new one - if (inventory.getSelected().getItem() instanceof SwordItem) { + if (inventory.getSelectedItem().is(ItemTags.SWORDS)) { return true; } else { - int swordId = ModUtils.findItemInHotbar(inventory, (item) -> item instanceof SwordItem); + int swordId = ModUtils.findItemInHotbar(inventory, (item) -> item.builtInRegistryHolder().is(ItemTags.SWORDS)); if (swordId > -1) { - inventory.selected = swordId; + inventory.setSelectedSlot(swordId); return true; } else { return false; @@ -171,6 +172,6 @@ private boolean chooseWeapon(Inventory inventory) { private void requestCreateSword() { // Ask server to put new item in hotbar - NetworkManager.sendToServer(new AddItemToHotbar(new ItemStack(Items.DIAMOND_SWORD))); + Services.NETWORK.sendToServer(new AddItemToHotbar(new ItemStack(Items.DIAMOND_SWORD))); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/DefaultConfigForNewWorld.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/DefaultConfigForNewWorld.java index 3f7b8804..f32160bc 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/DefaultConfigForNewWorld.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/DefaultConfigForNewWorld.java @@ -11,17 +11,17 @@ package com.specialeffect.eyemine.submod.misc; +import com.specialeffect.eyemine.EyeMine; import com.specialeffect.eyemine.EyeMineClient; import com.specialeffect.eyemine.packets.messages.AddItemToHotbar; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; import com.specialeffect.eyemine.submod.SubMod; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.common.EntityEvent; -import dev.architectury.event.events.common.LifecycleEvent; -import dev.architectury.event.events.common.TickEvent; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.packets.NetworkService; +import com.specialeffect.eyemine.platform.Services; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.NonNullList; import net.minecraft.server.MinecraftServer; @@ -32,11 +32,13 @@ import net.minecraft.world.item.AirItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.gamerules.GameRule; +import net.minecraft.world.level.gamerules.GameRules; import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.storage.LevelData; +import net.minecraft.world.level.storage.ServerLevelData; import java.lang.reflect.Field; @@ -59,9 +61,9 @@ public static void setNewWorldOptions(boolean daytime, boolean sunny, boolean ke } public void onInitializeClient() { - EntityEvent.ADD.register(this::onSpawn); - TickEvent.PLAYER_POST.register(this::onLiving); - LifecycleEvent.SERVER_LEVEL_LOAD.register(this::onWorldLoad); + EyeMineEvents.ENTITY_ADD.register(this::onSpawn); + EyeMineEvents.PLAYER_TICK.register(this::onLiving); + EyeMineEvents.WORLD_LOAD.register(this::onWorldLoad); } @Override @@ -89,7 +91,7 @@ private void onLiving(Player player) { firstOnLivingTick = false; if (player.isCreative()) { - NonNullList inventory = player.getInventory().items; + NonNullList inventory = player.getInventory().getNonEquipmentItems(); boolean hasSomeItems = false; for (ItemStack itemStack : inventory) { if (itemStack != null && !(itemStack.getItem() instanceof AirItem)) { @@ -114,21 +116,23 @@ private void onWorldLoad(ServerLevel serverLevel) { MinecraftServer server = serverLevel.getServer(); LevelData info = serverLevel.getLevelData(); - GameRules rules = info.getGameRules(); + GameRules rules = serverLevel.getGameRules(); if (info.getGameTime() < 60) { // First time loading, set rules according to user preference if (server != null && server.getDefaultGameType() == GameType.CREATIVE) { - rules.getRule(GameRules.RULE_DAYLIGHT).set(!alwaysDayTimeSetting, server); - rules.getRule(GameRules.RULE_WEATHER_CYCLE).set(!alwaysSunnySetting, server); - rules.getRule(GameRules.RULE_KEEPINVENTORY).set(keepInventorySetting, server); + rules.set(GameRules.ADVANCE_TIME, !alwaysDayTimeSetting, server); + rules.set(GameRules.ADVANCE_WEATHER, !alwaysSunnySetting, server); + rules.set(GameRules.KEEP_INVENTORY, keepInventorySetting, server); // Extra settings as a result of the above if (alwaysDayTimeSetting) { // we've just turned off daylightcycle while time = morning... - // we prefer full daylight! + // we prefer full daylight! Advance game time to noon. for (ServerLevel level : server.getAllLevels()) { - level.setDayTime(level.getDayTime() + (long) 2000); + if (level.getLevelData() instanceof ServerLevelData sld) { + sld.setGameTime(sld.getGameTime() + 2000L); + } } } } @@ -138,7 +142,7 @@ private void onWorldLoad(ServerLevel serverLevel) { @SuppressWarnings("unused") private void printGameRules(GameRules rules) { - System.out.println("Game rules:"); + EyeMine.LOGGER.debug("Game rules:"); // We use reflection to print out any relevant fields Field[] fields = rules.getClass().getFields(); @@ -146,8 +150,8 @@ private void printGameRules(GameRules rules) { try { Object v = f.get(rules); - if (v instanceof GameRules.Key key) { - LOGGER.debug(key + ": " + rules.getRule(key).toString()); + if (v instanceof GameRule rule) { + LOGGER.debug(f.getName() + ": " + rules.get(rule).toString()); } } catch (Exception e) { e.printStackTrace(); @@ -157,22 +161,22 @@ private void printGameRules(GameRules rules) { private void equipPlayer(Inventory inventory) { // Ask server to put new item in hotbar - NetworkManager.sendToServer(new AddItemToHotbar( + Services.NETWORK.sendToServer(new AddItemToHotbar( new ItemStack(Blocks.BRICKS), 0)); - NetworkManager.sendToServer(new AddItemToHotbar( + Services.NETWORK.sendToServer(new AddItemToHotbar( new ItemStack(Blocks.SANDSTONE), 1)); - NetworkManager.sendToServer(new AddItemToHotbar( + Services.NETWORK.sendToServer(new AddItemToHotbar( new ItemStack(Blocks.GLASS_PANE), 2)); - NetworkManager.sendToServer(new AddItemToHotbar( + Services.NETWORK.sendToServer(new AddItemToHotbar( new ItemStack(Blocks.MOSSY_COBBLESTONE), 3)); - NetworkManager.sendToServer(new AddItemToHotbar( + Services.NETWORK.sendToServer(new AddItemToHotbar( new ItemStack(Blocks.TORCH), 6)); - NetworkManager.sendToServer(new AddItemToHotbar( + Services.NETWORK.sendToServer(new AddItemToHotbar( new ItemStack(Items.DIAMOND_PICKAXE), 7)); - NetworkManager.sendToServer(new AddItemToHotbar( + Services.NETWORK.sendToServer(new AddItemToHotbar( new ItemStack(Items.DIAMOND_SWORD), 8)); - inventory.selected = 1; + inventory.setSelectedSlot(1); } -} \ No newline at end of file +} diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/DwellBuild.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/DwellBuild.java index 39946e2e..c3e919de 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/DwellBuild.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/DwellBuild.java @@ -16,11 +16,12 @@ import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.submod.utils.DwellAction; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.utils.TargetBlock; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; @@ -45,17 +46,17 @@ public void onInitializeClient() { "key.eyemine.toggle_dwell_build", Type.KEYSYM, GLFW.GLFW_KEY_KP_3, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mDwellBuildOnceKB = new KeyMapping( "key.eyemine.dwell_build_once", Type.KEYSYM, GLFW.GLFW_KEY_KP_7, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); //Initialize variables super.onInitializeClient(); @@ -68,15 +69,11 @@ public void performAction(TargetBlock block) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mDwellBuildKB.matches(keyCode, scanCode) && mDwellBuildKB.consumeClick()) { + if (mDwellBuildKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDwellBuildKB.consumeClick()) { Player player = Minecraft.getInstance().player; if (mDwelling) { // Turn off dwell build @@ -84,7 +81,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i ModUtils.sendPlayerMessage("Dwell building: OFF"); } else { // Turn on dwell build - ItemStack itemStack = player.getInventory().getSelected(); + ItemStack itemStack = player.getInventory().getSelectedItem(); if (itemStack.isEmpty()) { player.sendSystemMessage(Component.literal("Nothing in hand to use")); return EventResult.pass(); @@ -94,11 +91,11 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i ModUtils.sendPlayerMessage("Dwell building: ON"); } } - if (mDwellBuildOnceKB.matches(keyCode, scanCode) && mDwellBuildOnceKB.consumeClick()) { + if (mDwellBuildOnceKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDwellBuildOnceKB.consumeClick()) { Player player = Minecraft.getInstance().player; // Turn on dwell once - ItemStack itemStack = player.getInventory().getSelected(); + ItemStack itemStack = player.getInventory().getSelectedItem(); if (itemStack.isEmpty()) { player.sendSystemMessage(Component.literal("Nothing in hand to use")); return EventResult.pass(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/IronSights.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/IronSights.java index 3c33c00d..db072fd7 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/IronSights.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/IronSights.java @@ -18,10 +18,12 @@ import com.specialeffect.eyemine.client.gui.crosshair.IconOverlay; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; @@ -43,7 +45,7 @@ public void onInitializeClient() { "key.eyemine.toggle_ironsights", Type.KEYSYM, GLFW.GLFW_KEY_P, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); // Set up icon rendering @@ -54,7 +56,7 @@ public void onInitializeClient() { mIcon.setVisible(false); MainClientHandler.addOverlayToRender(mIcon); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } @Override @@ -64,15 +66,11 @@ public void syncConfig() { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mToggleIronsight.matches(keyCode, scanCode) && mToggleIronsight.consumeClick()) { + if (mToggleIronsight.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mToggleIronsight.consumeClick()) { ironsightsOn = !ironsightsOn; if (ironsightsOn) { minecraft.options.fov().set(minecraft.options.fov().get() - fovReduction); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/NightVisionHelper.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/NightVisionHelper.java index b32ad152..39481c6e 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/NightVisionHelper.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/NightVisionHelper.java @@ -13,16 +13,12 @@ import com.specialeffect.eyemine.submod.SubMod; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientGuiEvent; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; -import dev.architectury.event.events.common.EntityEvent; -import dev.architectury.event.events.common.LifecycleEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; @@ -58,12 +54,12 @@ public static void cancelAndHide() { } public void onInitializeClient() { - LifecycleEvent.SERVER_LEVEL_LOAD.register(this::onWorldLoad); - EntityEvent.LIVING_DEATH.register(this::onDeath); - EntityEvent.ADD.register(this::onSpawn); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); - ClientGuiEvent.RENDER_HUD.register(this::onRenderExperienceBar); + EyeMineEvents.WORLD_LOAD.register(this::onWorldLoad); + EyeMineEvents.ENTITY_DEATH.register(this::onDeath); + EyeMineEvents.ENTITY_ADD.register(this::onSpawn); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.RENDER_HUD.register(this::onRenderExperienceBar); } private void onWorldLoad(ServerLevel serverLevel) { @@ -153,7 +149,7 @@ public void onClientTick(Minecraft event) { } // Get lightness of block(s) we're looking at and where player is - boolean isDark = isDark(level, pos, level.random); + boolean isDark = isDark(level, pos, level.getRandom()); // If it's really dark, put message up to remind of night vision if (isDark) { @@ -184,7 +180,7 @@ public static boolean isDark(Level level, BlockPos blockPos, RandomSource random } } - public void onRenderExperienceBar(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { + public void onRenderExperienceBar(GuiGraphicsExtractor guiGraphics, DeltaTracker deltaTracker) { if (mShowMessage) { Minecraft mc = Minecraft.getInstance(); @@ -204,9 +200,9 @@ public void onRenderExperienceBar(GuiGraphics guiGraphics, DeltaTracker deltaTra } } - private void drawCenteredString(GuiGraphics guiGraphics, Font font, String msg, int x, int y, int c) { //TODO: check if we can just use GuiGraphics#drawCenteredString + private void drawCenteredString(GuiGraphicsExtractor guiGraphics, Font font, String msg, int x, int y, int c) { //TODO: check if we can just use GuiGraphics#drawCenteredString int stringWidth = font.width(msg); - guiGraphics.drawString(font, msg, x - stringWidth / 2, y, c); + guiGraphics.text(font, msg, x - stringWidth / 2, y, c); } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/OpenChat.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/OpenChat.java index d016b58d..573710c3 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/OpenChat.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/OpenChat.java @@ -16,9 +16,10 @@ import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; @@ -34,22 +35,18 @@ public void onInitializeClient() { "key.eyemine.open_chat", Type.KEYSYM, GLFW.GLFW_KEY_END, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mOpenChatKB.matches(keyCode, scanCode) && mOpenChatKB.consumeClick()) { + if (mOpenChatKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mOpenChatKB.consumeClick()) { KeyMapping.click(((KeyMappingAccessor) minecraft.options.keyChat).getActualKey()); } return EventResult.pass(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/OpenTablesChests.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/OpenTablesChests.java index 9045c9e3..bf0559a4 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/OpenTablesChests.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/OpenTablesChests.java @@ -17,10 +17,12 @@ import com.specialeffect.eyemine.mixin.ClientLevelAccessor; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -32,7 +34,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; import net.minecraft.world.InteractionHand; -import net.minecraft.world.ItemInteractionResult; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.AbstractChestBlock; import net.minecraft.world.level.block.Block; @@ -58,16 +60,16 @@ public void onInitializeClient() { "key.eyemine.open_chest", Type.KEYSYM, GLFW.GLFW_KEY_LEFT_BRACKET, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mOpenCraftingTableKB = new KeyMapping( "key.eyemine.open_crafting_table", Type.KEYSYM, GLFW.GLFW_KEY_RIGHT_BRACKET, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } public void syncConfig() { @@ -116,17 +118,13 @@ public BlockHitResult getSimulatedHitResult(ClientLevel level, BlockPos pos) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { - return EventResult.pass(); - } - - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } final LocalPlayer player = Minecraft.getInstance().player; final ClientLevel level = minecraft.level; - if (mOpenChestKB.matches(keyCode, scanCode) && mOpenChestKB.consumeClick()) { + if (mOpenChestKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mOpenChestKB.consumeClick()) { BlockPos closestBlockPos = OpenTablesChests.findClosestBlockOfType((block -> block instanceof AbstractChestBlock), player, level, mRadius); // Ask server to open @@ -136,14 +134,14 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i BlockState state = level.getBlockState(closestBlockPos); BlockHitResult simulatedHit = getSimulatedHitResult(level, closestBlockPos); - ItemInteractionResult result = state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, simulatedHit); + InteractionResult result = state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, simulatedHit); if (result.consumesAction()) { BlockStatePredictionHandler blockstatepredictionhandler = ((ClientLevelAccessor) level).eyemineGetPredictionHandler().startPredicting(); int i = blockstatepredictionhandler.currentSequence(); player.connection.send(new ServerboundUseItemOnPacket(InteractionHand.MAIN_HAND, simulatedHit, i)); } } - } else if (mOpenCraftingTableKB.matches(keyCode, scanCode) && mOpenCraftingTableKB.consumeClick()) { + } else if (mOpenCraftingTableKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mOpenCraftingTableKB.consumeClick()) { BlockPos closestBlockPos = OpenTablesChests.findClosestBlockOfType((block -> block instanceof CraftingTableBlock), player, level, mRadius); // Ask server to open @@ -154,7 +152,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i BlockState state = level.getBlockState(closestBlockPos); BlockHitResult simulatedHit = getSimulatedHitResult(level, closestBlockPos); - ItemInteractionResult result = state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, simulatedHit); + InteractionResult result = state.useItemOn(player.getItemInHand(InteractionHand.MAIN_HAND), level, player, InteractionHand.MAIN_HAND, simulatedHit); if (result.consumesAction()) { BlockStatePredictionHandler blockstatepredictionhandler = ((ClientLevelAccessor) level).eyemineGetPredictionHandler().startPredicting(); int i = blockstatepredictionhandler.currentSequence(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/PickBlock.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/PickBlock.java index 7964a5ce..d876c455 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/PickBlock.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/PickBlock.java @@ -16,9 +16,10 @@ import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; @@ -34,22 +35,18 @@ public void onInitializeClient() { "key.eyemine.pick_block", Type.KEYSYM, GLFW.GLFW_KEY_KP_2, - "category.eyemine.category.eyegaze_common" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_COMMON // The translation key of the keybinding's category. )); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mPickBlockKB.matches(keyCode, scanCode) && mPickBlockKB.consumeClick()) { + if (mPickBlockKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mPickBlockKB.consumeClick()) { KeyMapping pickBlockKey = minecraft.options.keyPickItem; KeyMapping.click(((KeyMappingAccessor) pickBlockKey).getActualKey()); } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/QuickCommands.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/QuickCommands.java index b1fced6d..fa7ece0f 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/QuickCommands.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/QuickCommands.java @@ -17,26 +17,29 @@ import com.specialeffect.eyemine.packets.messages.SendCommandMessage; import com.specialeffect.eyemine.packets.messages.TeleportPlayerToSpawnPointMessage; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.packets.NetworkService; +import com.specialeffect.eyemine.platform.Services; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.Holder; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.GameRules; -import net.minecraft.world.level.GameRules.BooleanValue; +import net.minecraft.world.level.gamerules.GameRules; import org.lwjgl.glfw.GLFW; public class QuickCommands extends SubMod { public final String MODID = "quickcommands"; + // Track day/night cycle toggle state locally since GameRules aren't accessible on client in 26.1.1 + private boolean dayNightCycleEnabled = true; + private static KeyMapping mNightVisionKB; private static KeyMapping mDayNightKB; private static KeyMapping mRespawnKB; @@ -48,45 +51,40 @@ public void onInitializeClient() { "key.eyemine.night_vision", Type.KEYSYM, GLFW.GLFW_KEY_F12, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mDayNightKB = new KeyMapping( "key.eyemine.day_cycle", Type.KEYSYM, GLFW.GLFW_KEY_F14, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mRespawnKB = new KeyMapping( "key.eyemine.respawn", Type.KEYSYM, GLFW.GLFW_KEY_HOME, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mDropItemKB = new KeyMapping( "key.eyemine.drop_item", Type.KEYSYM, GLFW.GLFW_KEY_MINUS, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { - return EventResult.pass(); - } - - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } final LocalPlayer player = Minecraft.getInstance().player; - final ClientLevel level = minecraft.level; - if (mNightVisionKB.matches(keyCode, scanCode) && mNightVisionKB.consumeClick()) { + if (mNightVisionKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mNightVisionKB.consumeClick()) { // Toggle night vision effect Holder nightVision = MobEffects.NIGHT_VISION; @@ -102,27 +100,26 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i return EventResult.pass(); } - if (mDropItemKB.matches(keyCode, scanCode) && mDropItemKB.consumeClick()) { + if (mDropItemKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDropItemKB.consumeClick()) { // Drop item // This is a duplicate key binding to the built-in one, so we can use the same for discarding // an item while the inventory is open. The inventory keybinding needs to be a key not used // for typing. - ItemStack stack = player.getInventory().getSelected(); + ItemStack stack = player.getInventory().getSelectedItem(); player.drop(stack, true); //TODO: see if this still drops all? } - if (mDayNightKB.matches(keyCode, scanCode) && mDayNightKB.consumeClick()) { - GameRules rules = level.getGameRules(); - - GameRules.Key gameRule = GameRules.RULE_DAYLIGHT; - boolean newBool = !rules.getBoolean(gameRule); + if (mDayNightKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDayNightKB.consumeClick()) { + // Toggle the day/night cycle - track state locally since GameRules + // are not accessible on the client side in 26.1.1 + dayNightCycleEnabled = !dayNightCycleEnabled; - String cmd = "/gamerule " + gameRule + " " + newBool; - NetworkManager.sendToServer(new SendCommandMessage(cmd)); + String cmd = "/gamerule " + GameRules.ADVANCE_TIME.id() + " " + dayNightCycleEnabled; + Services.NETWORK.sendToServer(new SendCommandMessage(cmd)); } - if (mRespawnKB.matches(keyCode, scanCode) && mRespawnKB.consumeClick()) { - NetworkManager.sendToServer(new TeleportPlayerToSpawnPointMessage()); + if (mRespawnKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mRespawnKB.consumeClick()) { + Services.NETWORK.sendToServer(new TeleportPlayerToSpawnPointMessage()); NightVisionHelper.cancelAndHide(); } return EventResult.pass(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/SwapMinePlace.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/SwapMinePlace.java index ac0bfe25..aa366521 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/SwapMinePlace.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/SwapMinePlace.java @@ -17,15 +17,15 @@ import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientGuiEvent; -import dev.architectury.event.events.client.ClientRawInputEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.DeltaTracker; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import org.lwjgl.glfw.GLFW; public class SwapMinePlace extends SubMod { @@ -35,31 +35,27 @@ public void onInitializeClient() { "key.eyemine.swap_mine_place", Type.KEYSYM, GLFW.GLFW_KEY_F10, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); - ClientGuiEvent.RENDER_HUD.register(this::onRenderGameOverlayEvent); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.RENDER_HUD.register(this::onRenderGameOverlayEvent); } private static KeyMapping mSwapKB; private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mSwapKB.matches(keyCode, scanCode) && mSwapKB.consumeClick()) { + if (mSwapKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mSwapKB.consumeClick()) { Key attackInput = ((KeyMappingAccessor) Minecraft.getInstance().options.keyAttack).getActualKey(); Key useInput = ((KeyMappingAccessor) Minecraft.getInstance().options.keyUse).getActualKey(); - Minecraft.getInstance().options.setKey(Minecraft.getInstance().options.keyAttack, useInput); - Minecraft.getInstance().options.setKey(Minecraft.getInstance().options.keyUse, attackInput); + Minecraft.getInstance().options.keyAttack.setKey(useInput); + Minecraft.getInstance().options.keyUse.setKey(attackInput); // It's important to force a reload Minecraft.getInstance().options.save(); @@ -71,7 +67,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i return EventResult.pass(); } - public void onRenderGameOverlayEvent(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { + public void onRenderGameOverlayEvent(GuiGraphicsExtractor guiGraphics, DeltaTracker deltaTracker) { // If these are swapped, show a warning message KeyMapping attackBinding = Minecraft.getInstance().options.keyAttack; KeyMapping useBinding = Minecraft.getInstance().options.keyUse; @@ -97,8 +93,8 @@ public void onRenderGameOverlayEvent(GuiGraphics guiGraphics, DeltaTracker delta int delta = (msg1width - msg2width) / 2; final Font font = mc.font; - guiGraphics.drawString(font, msg1, w - msg2width - delta - 10, h - 22, 0xffFFFFFF); - guiGraphics.drawString(font, msg2, w - msg2width - 10, h - 12, 0xffFFFFFF); + guiGraphics.text(font, msg1, w - msg2width - delta - 10, h - 22, 0xffFFFFFF); + guiGraphics.text(font, msg2, w - msg2width - 10, h - 12, 0xffFFFFFF); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/misc/UseItem.java b/common/src/main/java/com/specialeffect/eyemine/submod/misc/UseItem.java index bff3dda0..2821096c 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/misc/UseItem.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/misc/UseItem.java @@ -17,16 +17,18 @@ import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.utils.DwellAction; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.utils.TargetBlock; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.DeltaTracker; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; 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.BowItem; import net.minecraft.world.item.CrossbowItem; @@ -48,32 +50,32 @@ public void onInitializeClient() { "key.eyemine.use_item", Type.KEYSYM, GLFW.GLFW_KEY_KP_0, - "category.eyemine.category.eyegaze_common" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_COMMON // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mUseItemContinuouslyKB = new KeyMapping( "key.eyemine.use_item_continuously", Type.KEYSYM, GLFW.GLFW_KEY_KP_1, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mPrevItemKB = new KeyMapping( "key.eyemine.select_previous_item", Type.KEYSYM, GLFW.GLFW_KEY_KP_4, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mNextItemKB = new KeyMapping( "key.eyemine.select_next_item", Type.KEYSYM, GLFW.GLFW_KEY_KP_5, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); //Initialize variables super.onInitializeClient(); @@ -114,7 +116,7 @@ public void onClientTick(Minecraft minecraft) { // If it was a crossbow we'll need to re-click to actually fire it Player player = Minecraft.getInstance().player; - Item item = player.getInventory().getSelected().getItem(); + Item item = player.getInventory().getSelectedItem().getItem(); if (item instanceof CrossbowItem) { // Crossbows don't fire on mouse-release, they need another 'click' on the next tick to be shot needBowFire = true; @@ -130,18 +132,14 @@ public void onClientTick(Minecraft minecraft) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { - return EventResult.pass(); - } - - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } final KeyMapping useItemKeyBinding = Minecraft.getInstance().options.keyUse; Player player = Minecraft.getInstance().player; - if (mUseItemContinuouslyKB.matches(keyCode, scanCode) && mUseItemContinuouslyKB.consumeClick()) { + if (mUseItemContinuouslyKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mUseItemContinuouslyKB.consumeClick()) { if (mUsingItem) { // Turn off mUsingItem = false; @@ -150,7 +148,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i } else { // Turn on continuous-building - ItemStack itemStack = player.getInventory().getSelected(); + ItemStack itemStack = player.getInventory().getSelectedItem(); if (itemStack.isEmpty()) { player.sendSystemMessage(Component.literal("Nothing in hand to use")); return EventResult.pass(); @@ -161,9 +159,9 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i ModUtils.sendPlayerMessage("Using item: ON"); } - } else if (mUseItemOnceKB.matches(keyCode, scanCode) && mUseItemOnceKB.consumeClick()) { + } else if (mUseItemOnceKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mUseItemOnceKB.consumeClick()) { - ItemStack stack = player.getInventory().getSelected(); + ItemStack stack = player.getInventory().getSelectedItem(); Item item = stack.getItem(); // Special case for shootable items @@ -192,15 +190,17 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i this.performAction(null); } - } else if (mPrevItemKB.matches(keyCode, scanCode) && mPrevItemKB.consumeClick()) { - player.getInventory().swapPaint(1); - } else if (mNextItemKB.matches(keyCode, scanCode) && mNextItemKB.consumeClick()) { - player.getInventory().swapPaint(-1); + } else if (mPrevItemKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mPrevItemKB.consumeClick()) { + int current = player.getInventory().getSelectedSlot(); + player.getInventory().setSelectedSlot((current + Inventory.getSelectionSize() - 1) % Inventory.getSelectionSize()); + } else if (mNextItemKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mNextItemKB.consumeClick()) { + int current = player.getInventory().getSelectedSlot(); + player.getInventory().setSelectedSlot((current + 1) % Inventory.getSelectionSize()); } return EventResult.pass(); } - public void onRenderGameOverlayEvent(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { + public void onRenderGameOverlayEvent(GuiGraphicsExtractor guiGraphics, DeltaTracker deltaTracker) { super.onRenderGameOverlayEvent(guiGraphics, deltaTracker); // If use-item is on, show a warning message @@ -212,7 +212,7 @@ public void onRenderGameOverlayEvent(GuiGraphics guiGraphics, DeltaTracker delta int msgWidth = mc.font.width(msg); - guiGraphics.drawString(mc.font, msg, (int) (w / 2.0) - (int) (msgWidth / 2.0), (int) (h / 2.0) - 20, 0xffFFFFFF); + guiGraphics.text(mc.font, msg, (int) (w / 2.0) - (int) (msgWidth / 2.0), (int) (h / 2.0) - 20, 0xffFFFFFF); } } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/mouse/MouseHandlerMod.java b/common/src/main/java/com/specialeffect/eyemine/submod/mouse/MouseHandlerMod.java index 12dc3bee..f59f5fcc 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/mouse/MouseHandlerMod.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/mouse/MouseHandlerMod.java @@ -18,18 +18,19 @@ import com.specialeffect.eyemine.client.gui.crosshair.IconOverlay; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.movement.MoveWithGaze; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.movement.MoveWithGaze2; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.utils.MouseHelper; import com.specialeffect.eyemine.utils.MouseHelper.PlayerMovement; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.CompoundEventResult; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientGuiEvent; -import dev.architectury.event.events.client.ClientLifecycleEvent; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.ScreenSetResult; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; @@ -63,11 +64,11 @@ public enum InteractionState { private boolean hasPendingConfigChange = false; public void onInitializeClient() { - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); - ClientGuiEvent.SET_SCREEN.register(MouseHandlerMod::onGuiOpen); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.SCREEN_SET.register(MouseHandlerMod::onGuiOpen); - ClientLifecycleEvent.CLIENT_SETUP.register((state) -> setupInitialState()); + EyeMineEvents.CLIENT_SETUP.register((state) -> setupInitialState()); // Set up icon rendering mIconEye = new IconOverlay(Minecraft.getInstance(), "eyemine:textures/icons/eye.png"); @@ -81,14 +82,14 @@ public void onInitializeClient() { "key.eyemine.sensitivity_up", Type.KEYSYM, GLFW.GLFW_KEY_RIGHT, - "category.eyemine.category.eyegaze_settings" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_SETTINGS // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mSensitivityDownKB = new KeyMapping( "key.eyemine.sensitivity_down", Type.KEYSYM, GLFW.GLFW_KEY_LEFT, - "category.eyemine.category.eyegaze_settings" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_SETTINGS // The translation key of the keybinding's category. )); // Used to turn 'look with gaze' on and off when using mouse emulation @@ -98,7 +99,7 @@ public void onInitializeClient() { "key.eyemine.toggle_mouse_look", Type.KEYSYM, GLFW.GLFW_KEY_Y, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); } @@ -203,21 +204,17 @@ public void onClientTick(Minecraft minecraft) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mSensitivityUpKB.matches(keyCode, scanCode) && mSensitivityUpKB.consumeClick()) { + if (mSensitivityUpKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mSensitivityUpKB.consumeClick()) { increaseSens(); ModUtils.sendPlayerMessage("Sensitivity: " + toPercent(2.0d * minecraft.options.sensitivity().get())); - } else if (mSensitivityDownKB.matches(keyCode, scanCode) && mSensitivityDownKB.consumeClick()) { + } else if (mSensitivityDownKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mSensitivityDownKB.consumeClick()) { decreaseSens(); ModUtils.sendPlayerMessage("Sensitivity: " + toPercent(2.0d * minecraft.options.sensitivity().get())); - } else if (mToggleMouseViewControlKB.matches(keyCode, scanCode) && mToggleMouseViewControlKB.consumeClick()) { + } else if (mToggleMouseViewControlKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mToggleMouseViewControlKB.consumeClick()) { if (mInputSource == InputSource.EyeTracker) { LOGGER.debug("this key doesn't do anything in eyetracker mode"); ModUtils.sendPlayerMessage("Warning: Minecraft expects eye tracker input, not mouse"); @@ -260,13 +257,13 @@ private void increaseSens() { } private static void setEmptyCursor() { - GLFW.glfwSetInputMode(Minecraft.getInstance().getWindow().getWindow(), + GLFW.glfwSetInputMode(Minecraft.getInstance().getWindow().handle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN); } private static void setNativeCursor() { - GLFW.glfwSetInputMode(Minecraft.getInstance().getWindow().getWindow(), + GLFW.glfwSetInputMode(Minecraft.getInstance().getWindow().handle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL); } @@ -280,7 +277,7 @@ public static boolean hasPendingEvent() { return mTicksSinceMouseEvent < 5; } - public static CompoundEventResult onGuiOpen(Screen screen) { + public static ScreenSetResult onGuiOpen(Screen screen) { // For any open event, make sure cursor not overridden if (screen != null) { setNativeCursor(); @@ -291,7 +288,7 @@ public static CompoundEventResult onGuiOpen(Screen screen) { setEmptyCursor(); } } - return CompoundEventResult.interruptTrue(screen); + return ScreenSetResult.set(screen); } // This is the constant offset applied in MC source, corresponding diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/AutoFly.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/AutoFly.java index 954b67df..3fb6f88c 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/AutoFly.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/AutoFly.java @@ -18,12 +18,14 @@ import com.specialeffect.eyemine.packets.messages.ChangeFlyingStateMessage; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; -import dev.architectury.networking.NetworkManager; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.packets.NetworkService; +import com.specialeffect.eyemine.platform.Services; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; @@ -52,29 +54,29 @@ public void onInitializeClient() { "key.eyemine.toggle_manual_flying", Type.KEYSYM, GLFW.GLFW_KEY_COMMA, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mFlyAutoKB = new KeyMapping( "key.eyemine.toggle_auto_flying", Type.KEYSYM, GLFW.GLFW_KEY_G, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mFlyUpKB = new KeyMapping( "key.eyemine.fly_higher", Type.KEYSYM, GLFW.GLFW_KEY_PERIOD, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mFlyDownKB = new KeyMapping( "key.eyemine.fly_lower", Type.KEYSYM, GLFW.GLFW_KEY_APOSTROPHE, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); // Register an icon for the overlay mIconIndexAuto = StateOverlay.registerTextureLeft("eyemine:textures/icons/fly-auto.png"); @@ -153,7 +155,7 @@ private void stopFlying() { Player player = Minecraft.getInstance().player; player.getAbilities().flying = false; - NetworkManager.sendToServer(new ChangeFlyingStateMessage(false, 0)); + Services.NETWORK.sendToServer(new ChangeFlyingStateMessage(false, 0)); updateIcons(); } @@ -186,7 +188,7 @@ private void setFlying(final boolean bFlyUp, final boolean isAuto) { player.move(MoverType.SELF, new Vec3(0, flyHeight, 0)); } - NetworkManager.sendToServer(new ChangeFlyingStateMessage(true, flyHeight)); + Services.NETWORK.sendToServer(new ChangeFlyingStateMessage(true, flyHeight)); updateIcons(); @@ -220,15 +222,11 @@ private void flyDown() { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mFlyManualKB.matches(keyCode, scanCode) && mFlyManualKB.consumeClick()) { + if (mFlyManualKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mFlyManualKB.consumeClick()) { if (mIsFlyingManual) { ModUtils.sendPlayerMessage("Fly manual: OFF"); this.stopFlying(); @@ -237,7 +235,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i boolean doFlyUp = !mIsFlyingAuto; this.setFlying(doFlyUp, false); } - } else if (mFlyAutoKB.matches(keyCode, scanCode) && mFlyAutoKB.consumeClick()) { + } else if (mFlyAutoKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mFlyAutoKB.consumeClick()) { if (mIsFlyingAuto) { ModUtils.sendPlayerMessage("Fly auto: OFF"); this.stopFlying(); @@ -246,9 +244,9 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i boolean doFlyUp = !mIsFlyingManual; this.setFlying(doFlyUp, true); } - } else if (mFlyUpKB.matches(keyCode, scanCode) && mFlyUpKB.consumeClick()) { + } else if (mFlyUpKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mFlyUpKB.consumeClick()) { this.setFlying(true, mIsFlyingAuto); - } else if (mFlyDownKB.matches(keyCode, scanCode) && mFlyDownKB.consumeClick()) { + } else if (mFlyDownKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mFlyDownKB.consumeClick()) { flyDown(); } AutoFly.updateIcons(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/AutoJump.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/AutoJump.java index bbe4ea3c..b42e8e2a 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/AutoJump.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/AutoJump.java @@ -17,11 +17,12 @@ import com.specialeffect.eyemine.client.gui.crosshair.StateOverlay; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.Options; @@ -43,14 +44,14 @@ public void onInitializeClient() { "key.eyemine.toggle_auto_jump", Type.KEYSYM, GLFW.GLFW_KEY_J, - "category.eyemine.category.eyegaze_common" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_COMMON // The translation key of the keybinding's category. )); // Register an icon for the overlay mIconIndex = StateOverlay.registerTextureLeft("eyemine:textures/icons/jump.png"); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } private void updateSettings(boolean autoJump, boolean persist) { @@ -97,15 +98,11 @@ public void onClientTick(Minecraft minecraft) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (!mAutoJumpDisabled && autoJumpKeyBinding.matches(keyCode, scanCode) && autoJumpKeyBinding.consumeClick()) { + if (!mAutoJumpDisabled && autoJumpKeyBinding.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && autoJumpKeyBinding.consumeClick()) { mDoingAutoJump = !mDoingAutoJump; // User toggled the setting, so persist it this.updateSettings(mDoingAutoJump, true); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/BoatController.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/BoatController.java index a79017e2..4f5086e4 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/BoatController.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/BoatController.java @@ -11,10 +11,11 @@ package com.specialeffect.eyemine.submod.movement; +import com.specialeffect.eyemine.EyeMine; import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.vehicle.Boat; +import net.minecraft.world.entity.vehicle.boat.AbstractBoat; public class BoatController { // Boats are steered with left, right arrow keys to control the paddles @@ -57,7 +58,7 @@ public void releaseKeys() { // speed [-1, +1] where +1 is for turning right // if abs(speed) > 1, it will just clip the effect private void steer(double speed) { - System.out.println("steer " + speed); + EyeMine.LOGGER.debug("steer {}", speed); final KeyMapping kbLeft = Minecraft.getInstance().options.keyLeft; final KeyMapping kbRight = Minecraft.getInstance().options.keyRight; @@ -87,7 +88,7 @@ private void control_model(double control_input) { this.steer(steer_amount); } - public void pid_step(Boat boat, double yaw_error) { + public void pid_step(AbstractBoat boat, double yaw_error) { // Reset if new boat if (boat.getId() != this.boat_id) { this.yaw_error = 0; diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/Dismount.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/Dismount.java index 85e3417f..45e6119a 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/Dismount.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/Dismount.java @@ -15,21 +15,23 @@ import com.mojang.blaze3d.platform.InputConstants.Type; import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.protocol.game.ServerboundInteractPacket; import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket; +import net.minecraft.world.entity.player.Input; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.Saddleable; -import net.minecraft.world.entity.animal.horse.Horse; -import net.minecraft.world.entity.vehicle.Boat; -import net.minecraft.world.entity.vehicle.Minecart; +import net.minecraft.world.entity.animal.equine.AbstractHorse; +import net.minecraft.world.entity.animal.equine.Horse; +import net.minecraft.world.entity.vehicle.boat.AbstractBoat; +import net.minecraft.world.entity.vehicle.minecart.Minecart; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.EntityHitResult; @@ -49,22 +51,18 @@ public void onInitializeClient() { "key.eyemine.ride_or_dismount", Type.KEYSYM, GLFW.GLFW_KEY_F15, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mDismountKB.matches(keyCode, scanCode) && mDismountKB.consumeClick()) { + if (mDismountKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDismountKB.consumeClick()) { LocalPlayer player = Minecraft.getInstance().player; if (player.isPassenger()) { // Dismount player locally @@ -72,7 +70,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i player.jumpFromGround(); // Dismount player on server // channel.sendToServer(new DismountPlayerMessage()); - player.connection.send(new ServerboundPlayerInputPacket(player.xxa, player.zza, false, true)); + player.connection.send(new ServerboundPlayerInputPacket(new Input(false, false, false, false, false, true, false))); } else { EntityHitResult entityResult = ModUtils.getMouseOverEntity(); Entity entity = entityResult == null ? null : entityResult.getEntity(); @@ -86,7 +84,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i AABB box = player.getBoundingBox().inflate(2); List mobEntities = level.getEntitiesOfClass(Mob.class, box); - List boatEntities = level.getEntitiesOfClass(Boat.class, box); + List boatEntities = level.getEntitiesOfClass(AbstractBoat.class, box); List minecartEntities = level.getEntitiesOfClass(Minecart.class, box); List entities = new ArrayList<>(); @@ -101,7 +99,7 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i ModUtils.sendPlayerMessage("Nothing found to ride"); } else if (entities.size() == 1) { entity = entities.get(0); - if (entity instanceof Saddleable || entity instanceof Minecart || entity instanceof Boat) { + if (entity instanceof AbstractHorse || entity instanceof Minecart || entity instanceof AbstractBoat) { ModUtils.sendPlayerMessage("Attempting to mount nearby " + entity.getName().getString()); } } else { @@ -126,8 +124,8 @@ else if (entity instanceof Horse && ModUtils.sendPlayerMessage("You need an empty hand to ride a horse"); } - entity.interact(player, hand); - player.connection.send(ServerboundInteractPacket.createInteractionPacket(entity, player.isShiftKeyDown(), hand)); + entity.interact(player, hand, entity.position()); + player.connection.send(new ServerboundInteractPacket(entity.getId(), hand, entity.position(), player.isShiftKeyDown())); } } } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/EasyLadderClimb.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/EasyLadderClimb.java index c68c15c5..d0fb6a23 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/EasyLadderClimb.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/EasyLadderClimb.java @@ -18,12 +18,12 @@ import com.specialeffect.eyemine.event.BlockOutlineEvent; import com.specialeffect.eyemine.submod.SubMod; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.rendertype.RenderType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.Level; @@ -42,7 +42,7 @@ public class EasyLadderClimb extends SubMod { // You'll get nudged toward the centre of the ladder a little bit. public void onInitializeClient() { - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); BlockOutlineEvent.OUTLINE.register(this::onBlockOutlineRender); } diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/MoveWithGaze.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/MoveWithGaze.java index 0e2b0c90..5f108c1c 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/MoveWithGaze.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/MoveWithGaze.java @@ -19,26 +19,30 @@ import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.misc.ContinuouslyAttack; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.mouse.MouseHandlerMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.utils.KeyboardInputHelper; import com.specialeffect.eyemine.utils.MouseHelper; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket; import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket; +import net.minecraft.world.entity.player.Input; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.vehicle.Boat; -import net.minecraft.world.entity.vehicle.Minecart; +import net.minecraft.world.entity.vehicle.boat.AbstractBoat; +import net.minecraft.world.entity.vehicle.minecart.Minecart; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.EntityHitResult; @@ -77,20 +81,20 @@ public void onInitializeClient() { "key.eyemine.toggle_walking_forward", Type.KEYSYM, GLFW.GLFW_KEY_H, - "category.eyemine.category.eyegaze_common" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_COMMON // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mIncreaseWalkSpeedKB = new KeyMapping( "key.eyemine.increase_walk_speed", Type.KEYSYM, GLFW.GLFW_KEY_UP, - "category.eyemine.category.eyegaze_settings" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_SETTINGS // The translation key of the keybinding's category. )); Keybindings.keybindings.add(mDecreaseWalkSpeedKB = new KeyMapping( "key.eyemine.decrease_walk_speed", Type.KEYSYM, GLFW.GLFW_KEY_DOWN, - "category.eyemine.category.eyegaze_settings" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_SETTINGS // The translation key of the keybinding's category. )); mPrevLookDirs = new LinkedBlockingQueue<>(); @@ -98,8 +102,8 @@ public void onInitializeClient() { // Register an icon for the overlay mIconIndex = StateOverlay.registerTextureLeft("eyemine:textures/icons/walk.png"); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } @Override @@ -216,7 +220,9 @@ public void onClientTick(Minecraft event) { if ((stateInFront != null && stateInFront.isSolid()) && (stateAboveInFront != null && !stateAboveInFront.isSolid())) { if (jumpTicks == 0) { - player.connection.send(new ServerboundPlayerInputPacket(player.xxa, player.zza, true, player.input.shiftKeyDown)); + player.connection.send(new ServerboundPlayerInputPacket(new Input( + player.zza > 0, player.zza < 0, player.xxa > 0, player.xxa < 0, + true, player.isShiftKeyDown(), false))); player.jumpFromGround(); // only jump every N ticks... @@ -231,12 +237,12 @@ public void onClientTick(Minecraft event) { Entity riddenEntity = player.getVehicle(); if (null != riddenEntity) { - if (riddenEntity instanceof Boat boat) { + if (riddenEntity instanceof AbstractBoat boat) { // very special case: you can't steer a boat without keys, // so we first steer left/right with keys until the boat // and the player's view are aligned, only then move // forward - if (boat.isControlledByLocalInstance()) { + if (boat.isLocalInstanceAuthoritative()) { float yawError = boat.getYRot() - player.getYRot(); yawError %= 360; if (yawError < -180) { @@ -270,7 +276,7 @@ public void onClientTick(Minecraft event) { // It's critical we add motion to player on the server, not just // locally player.setDeltaMovement(motionAligned); - player.connection.send(new ServerboundMoveVehiclePacket(riddenEntity)); //TEST IF WORKS + player.connection.send(ServerboundMoveVehiclePacket.fromEntity(riddenEntity)); //TEST IF WORKS } else { // Any other ridden entities that don't work with the movement override?? @@ -364,15 +370,11 @@ public static boolean isWalking() { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mToggleAutoWalkKB.matches(keyCode, scanCode) && mToggleAutoWalkKB.consumeClick()) { + if (mToggleAutoWalkKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mToggleAutoWalkKB.consumeClick()) { mDoingAutoWalk = !mDoingAutoWalk; MouseHandlerMod.setWalking(mDoingAutoWalk); StateOverlay.setStateLeftIcon(mIconIndex, mDoingAutoWalk); @@ -381,12 +383,12 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i } ModUtils.sendPlayerMessage("Auto walk: " + (mDoingAutoWalk ? "ON" : "OFF")); } - if (mDecreaseWalkSpeedKB.matches(keyCode, scanCode) && mDecreaseWalkSpeedKB.consumeClick()) { + if (mDecreaseWalkSpeedKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mDecreaseWalkSpeedKB.consumeClick()) { float newSpeed = (float) Math.max(0.1d, 0.9d * EyeMineConfig.getCustomSpeedFactor()); MainClientHandler.saveWalkingSpeed(newSpeed); displayCurrentSpeed(); } - if (mIncreaseWalkSpeedKB.matches(keyCode, scanCode) && mIncreaseWalkSpeedKB.consumeClick()) { + if (mIncreaseWalkSpeedKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mIncreaseWalkSpeedKB.consumeClick()) { float newSpeed = (float) Math.min(2.0d, EyeMineConfig.getCustomSpeedFactor() * 1.1d); MainClientHandler.saveWalkingSpeed(newSpeed); displayCurrentSpeed(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/MoveWithGaze2.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/MoveWithGaze2.java index 3950a68d..47b37f61 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/MoveWithGaze2.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/MoveWithGaze2.java @@ -19,14 +19,16 @@ import com.specialeffect.eyemine.client.gui.crosshair.StateOverlay; import com.specialeffect.eyemine.platform.EyeMineConfig; import com.specialeffect.eyemine.submod.IConfigListener; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.submod.mouse.MouseHandlerMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.utils.KeyboardInputHelper; import com.specialeffect.eyemine.utils.MouseHelper; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -50,14 +52,14 @@ public void onInitializeClient() { "key.eyemine.toggle_walking", //Careful walk Type.KEYSYM, GLFW.GLFW_KEY_B, - "category.eyemine.category.eyegaze_common" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_COMMON // The translation key of the keybinding's category. )); // Register an icon for the overlay mIconIndex = StateOverlay.registerTextureLeft("eyemine:textures/icons/legacy-mode.png"); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } private static int mIconIndex; @@ -146,15 +148,11 @@ public void onClientTick(Minecraft minecraft) { private static boolean mDoingAutoWalk = false; private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mToggleAutoWalkKB.matches(keyCode, scanCode) && mToggleAutoWalkKB.consumeClick()) { + if (mToggleAutoWalkKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mToggleAutoWalkKB.consumeClick()) { mDoingAutoWalk = !mDoingAutoWalk; MouseHandlerMod.setLegacyWalking(mDoingAutoWalk); @@ -164,4 +162,4 @@ private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, i } return EventResult.pass(); } -} \ No newline at end of file +} diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/Sneak.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/Sneak.java index d49f9cd2..15a56dad 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/Sneak.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/Sneak.java @@ -17,11 +17,11 @@ import com.specialeffect.eyemine.client.gui.crosshair.StateOverlay; import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.eyemine.utils.KeyboardInputHelper; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -44,14 +44,14 @@ public void onInitializeClient() { "key.eyemine.toggle_sneaking", Type.KEYSYM, GLFW.GLFW_KEY_Z, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); // Register an icon for the overlay mIconIndex = StateOverlay.registerTextureLeft("eyemine:textures/icons/sneak.png"); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } public void onClientTick(Minecraft minecraft) { @@ -86,15 +86,11 @@ private static void updateSneak(boolean bSneak) { } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mSneakKB.matches(keyCode, scanCode) && mSneakKB.consumeClick()) { + if (mSneakKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mSneakKB.consumeClick()) { updateSneak(!mIsSneaking); } return EventResult.pass(); diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/movement/Swim.java b/common/src/main/java/com/specialeffect/eyemine/submod/movement/Swim.java index 4357639c..fcf0388f 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/movement/Swim.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/movement/Swim.java @@ -17,10 +17,10 @@ import com.specialeffect.eyemine.client.gui.crosshair.StateOverlay; import com.specialeffect.eyemine.mixin.KeyMappingAccessor; import com.specialeffect.eyemine.submod.SubMod; +import com.specialeffect.eyemine.submod.KeyInputUtil; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientRawInputEvent; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -43,7 +43,7 @@ public void onInitializeClient() { "key.eyemine.toggle_swimming", Type.KEYSYM, GLFW.GLFW_KEY_V, - "category.eyemine.category.eyegaze_extra" // The translation key of the keybinding's category. + Keybindings.EYEGAZE_EXTRA // The translation key of the keybinding's category. )); // Register an icon for the overlay @@ -51,8 +51,8 @@ public void onInitializeClient() { StateOverlay.setStateLeftIcon(mIconIndex, mSwimmingTurnedOn); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); - ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); + EyeMineEvents.KEY_PRESSED.register(this::onKeyInput); } public static void stopActivelySwimming() { @@ -113,15 +113,11 @@ else if ((player.onGround() || isPlayerInAir(player)) && } private EventResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) { - if (ModUtils.hasActiveGui()) { + if (KeyInputUtil.shouldIgnoreKeyInput(minecraft)) { return EventResult.pass(); } - if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { - return EventResult.pass(); - } - - if (mSwimKB.matches(keyCode, scanCode) && mSwimKB.consumeClick()) { + if (mSwimKB.matches(new net.minecraft.client.input.KeyEvent(keyCode, scanCode, modifiers)) && mSwimKB.consumeClick()) { final KeyMapping swimBinding = minecraft.options.keyJump; mSwimmingTurnedOn = !mSwimmingTurnedOn; diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/utils/DebugAverageFps.java b/common/src/main/java/com/specialeffect/eyemine/submod/utils/DebugAverageFps.java index d2eee645..77e8e6c9 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/utils/DebugAverageFps.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/utils/DebugAverageFps.java @@ -13,7 +13,7 @@ import com.specialeffect.eyemine.mixin.MinecraftAccessor; import com.specialeffect.eyemine.submod.SubMod; -import dev.architectury.event.events.client.ClientTickEvent; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -35,7 +35,7 @@ public DebugAverageFps() { public void onInitializeClient() { mPrevFps = new LinkedBlockingQueue<>(); - ClientTickEvent.CLIENT_PRE.register(this::onClientTick); + EyeMineEvents.CLIENT_TICK.register(this::onClientTick); } public void onClientTick(Minecraft event) { diff --git a/common/src/main/java/com/specialeffect/eyemine/submod/utils/DwellAction.java b/common/src/main/java/com/specialeffect/eyemine/submod/utils/DwellAction.java index b7df8d93..f7fa1ad2 100644 --- a/common/src/main/java/com/specialeffect/eyemine/submod/utils/DwellAction.java +++ b/common/src/main/java/com/specialeffect/eyemine/submod/utils/DwellAction.java @@ -11,6 +11,7 @@ package com.specialeffect.eyemine.submod.utils; +import com.specialeffect.eyemine.EyeMine; import com.irtimaled.bbor.client.renderers.AbstractRenderer; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -22,15 +23,15 @@ import com.specialeffect.eyemine.submod.mouse.MouseHandlerMod; import com.specialeffect.eyemine.utils.MouseHelper; import com.specialeffect.utils.ModUtils; -import dev.architectury.event.EventResult; -import dev.architectury.event.events.client.ClientGuiEvent; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.EyeMineEvents; import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.rendertype.RenderType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult.Type; @@ -70,7 +71,7 @@ public DwellAction(String name, int labelOffset) { } public void onInitializeClient() { - ClientGuiEvent.RENDER_HUD.register(this::onRenderGameOverlayEvent); + EyeMineEvents.RENDER_HUD.register(this::onRenderGameOverlayEvent); BlockOutlineEvent.OUTLINE.register(this::onBlockOutlineRender); } @@ -135,7 +136,7 @@ public void onClientTick(Minecraft minecraft) { // Place block if dwell complete if (currentTarget != null && liveTargets.get(currentTarget).hasCompleted()) { - System.out.println("Performing"); + EyeMine.LOGGER.debug("Performing dwell action"); this.performAction(currentTarget); liveTargets.remove(currentTarget); if (oneShot) { @@ -225,7 +226,7 @@ public EventResult onBlockOutlineRender(MultiBufferSource bufferSource, PoseStac return EventResult.pass(); } - public void onRenderGameOverlayEvent(GuiGraphics guiGraphics, DeltaTracker deltaTracker) { + public void onRenderGameOverlayEvent(GuiGraphicsExtractor guiGraphics, DeltaTracker deltaTracker) { // If dwell is on, show a warning message if (mDwelling && showLabel) { Minecraft minecraft = Minecraft.getInstance(); @@ -237,7 +238,7 @@ public void onRenderGameOverlayEvent(GuiGraphics guiGraphics, DeltaTracker delta final Font font = minecraft.font; float msgWidth = (float) font.width(msg); - guiGraphics.drawString(font, msg, (int) (w / 2.0f - msgWidth / 2.0f), (int)(h / 2.0f - 20 - labelOffset), 0xffFFFFFF); + guiGraphics.text(font, msg, (int) (w / 2.0f - msgWidth / 2.0f), (int)(h / 2.0f - 20 - labelOffset), 0xffFFFFFF); } } } diff --git a/common/src/main/java/com/specialeffect/eyemine/utils/MouseHelper.java b/common/src/main/java/com/specialeffect/eyemine/utils/MouseHelper.java index 992e0f32..21bd905f 100644 --- a/common/src/main/java/com/specialeffect/eyemine/utils/MouseHelper.java +++ b/common/src/main/java/com/specialeffect/eyemine/utils/MouseHelper.java @@ -86,8 +86,8 @@ public enum PlayerMovement { **/ public void moveCursor(MouseHandler mouseHelper, double xpos, double ypos) { if (mouseHelper != null) { - long handle = Minecraft.getInstance().getWindow().getWindow(); - GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().getWindow(), xpos, ypos); + long handle = Minecraft.getInstance().getWindow().handle(); + GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().handle(), xpos, ypos); ((MouseHandlerAccessor) mouseHelper).invokeOnMove(handle, xpos, ypos); } } @@ -110,7 +110,7 @@ public void leftShiftMouseClickAtPosition(MouseHandler mouseHelper, double xpos, public void scroll(MouseHandler mouseHandler, double amount) { if (mouseHandler != null) { - long handle = Minecraft.getInstance().getWindow().getWindow(); + long handle = Minecraft.getInstance().getWindow().handle(); ((MouseHandlerAccessor) mouseHandler).invokeOnScroll(handle, 0, amount); } } @@ -125,8 +125,9 @@ public void scroll(MouseHandler mouseHandler, double amount) { * mods: GLFW.GLFW_MOD_[SHIFT/CONTROL/ALT/SUPER] */ public void mouseButton(int button, int action, int mods) { - long handle = Minecraft.getInstance().getWindow().getWindow(); - ((MouseHandlerAccessor) Minecraft.getInstance().mouseHandler).invokeOnPress(handle, button, action, mods); + long handle = Minecraft.getInstance().getWindow().handle(); + ((MouseHandlerAccessor) Minecraft.getInstance().mouseHandler).invokeOnButton( + handle, new net.minecraft.client.input.MouseButtonInfo(button, mods), action); } public static void setMovementState(PlayerMovement state) { diff --git a/common/src/main/java/com/specialeffect/inventory/manager/ChestInventoryManager.java b/common/src/main/java/com/specialeffect/inventory/manager/ChestInventoryManager.java index 0205c83c..aa6d75a6 100644 --- a/common/src/main/java/com/specialeffect/inventory/manager/ChestInventoryManager.java +++ b/common/src/main/java/com/specialeffect/inventory/manager/ChestInventoryManager.java @@ -166,6 +166,6 @@ private void hoverItem() { int yPos = containerTop + itemRow * itemWidth; int xPos = containerLeft + itemCol * itemWidth; - GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().getWindow(), xPos * this.xScale, yPos * this.yScale); + GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().handle(), xPos * this.xScale, yPos * this.yScale); } } \ No newline at end of file diff --git a/common/src/main/java/com/specialeffect/inventory/manager/CreativeInventoryManager.java b/common/src/main/java/com/specialeffect/inventory/manager/CreativeInventoryManager.java index 403e1baf..d96bb2cd 100644 --- a/common/src/main/java/com/specialeffect/inventory/manager/CreativeInventoryManager.java +++ b/common/src/main/java/com/specialeffect/inventory/manager/CreativeInventoryManager.java @@ -11,6 +11,7 @@ package com.specialeffect.inventory.manager; +import com.specialeffect.eyemine.EyeMine; import com.specialeffect.eyemine.platform.InventoryConfig; import com.specialeffect.eyemine.utils.MouseHelper; import com.specialeffect.utils.ModUtils; @@ -139,7 +140,7 @@ private void updateItemPos() { // This allows users to set cursor position manually and then make adjustments // with prev/next MouseHandler helper = Minecraft.getInstance().mouseHandler; - System.out.println(helper.xpos() + ", " + helper.ypos()); + EyeMine.LOGGER.debug("Creative inventory pos: {}, {}", helper.xpos(), helper.ypos()); int x = (int) (helper.xpos() / this.xScale); int y = (int) (helper.ypos() / this.yScale); int i = ModUtils.findSlotInContainer(creativeContainer, guiLeft, guiTop, x, y, itemWidth); @@ -242,7 +243,7 @@ private void hoverItem() { int yPos = containerTop + itemRow * itemWidth; int xPos = containerLeft + itemCol * itemWidth; - GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().getWindow(), xPos * this.xScale, yPos * this.yScale); + GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().handle(), xPos * this.xScale, yPos * this.yScale); } private void switchToTab(int iTab) { @@ -318,7 +319,7 @@ private void switchToTab(int iTab) { // the same tab again (otherwise this gets missed) this.onTabChanged(); - GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().getWindow(), xPos * this.xScale, yPos * this.yScale); + GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().handle(), xPos * this.xScale, yPos * this.yScale); } } diff --git a/common/src/main/java/com/specialeffect/inventory/manager/SurvivalInventoryManager.java b/common/src/main/java/com/specialeffect/inventory/manager/SurvivalInventoryManager.java index 627dc55f..6e804646 100644 --- a/common/src/main/java/com/specialeffect/inventory/manager/SurvivalInventoryManager.java +++ b/common/src/main/java/com/specialeffect/inventory/manager/SurvivalInventoryManager.java @@ -123,7 +123,7 @@ private void updateCoordinates(int left, int top, int width, int height, Invento List slots = playerContainer.slots; - int iSlotOutput = playerContainer.getResultSlotIndex(); + int iSlotOutput = InventoryMenu.RESULT_SLOT; for (Slot slot : slots) { @@ -148,7 +148,7 @@ private void processSlots() { List slots = playerContainer.slots; - this.outputSlot = slots.get(playerContainer.getResultSlotIndex()); + this.outputSlot = slots.get(InventoryMenu.RESULT_SLOT); this.slotFirstX = slots.get(10).x; this.slotFirstY = slots.get(10).y; @@ -166,7 +166,7 @@ private void processSlots() { // Parse the list of slots to work out the location of things List slots = playerContainer.inventorySlots; - int iSlotOutput = playerContainer.getResultSlotIndex(); + int iSlotOutput = InventoryMenu.RESULT_SLOT; for (Slot slot : slots) { // if (slot instanceof ) LOGGER.debug(slot.xPos+ ", "+ slot.yPos); @@ -193,7 +193,7 @@ public void hoverOutput() { MouseHelper.instance().moveCursor(helper, xPos * this.xScale, yPos * this.yScale); - playerContainer.quickMoveStack(Minecraft.getInstance().player, playerContainer.getResultSlotIndex()); + playerContainer.quickMoveStack(Minecraft.getInstance().player, InventoryMenu.RESULT_SLOT); } @@ -273,7 +273,7 @@ private void hoverItem() { int yPos = topItemYPos + itemRow * itemWidth; int xPos = leftItemXPos + itemCol * itemWidth; - GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().getWindow(), xPos * this.xScale, yPos * this.yScale); + GLFW.glfwSetCursorPos(Minecraft.getInstance().getWindow().handle(), xPos * this.xScale, yPos * this.yScale); } private void switchToTab(int iTab) { diff --git a/common/src/main/java/com/specialeffect/utils/ModUtils.java b/common/src/main/java/com/specialeffect/utils/ModUtils.java index 9b8ba518..6a39a9f9 100644 --- a/common/src/main/java/com/specialeffect/utils/ModUtils.java +++ b/common/src/main/java/com/specialeffect/utils/ModUtils.java @@ -11,12 +11,6 @@ package com.specialeffect.utils; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.BufferUploader; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat.Mode; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -37,8 +31,6 @@ import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; -import org.lwjgl.opengl.GL11; - import java.awt.Point; import java.util.ArrayList; import java.util.List; @@ -114,39 +106,13 @@ public static Point getCompassPoint(int i) { } return p; } -// -// public static Point getScaledDisplaySize(Minecraft mc) { -// Point p = new Point(0, 0); -// ScaledResolution res = new ScaledResolution(mc); -// p.setLocation(res.getScaledWidth(), res.getScaledHeight()); -// -// return p; -// -// } - - - public static void drawTexQuad(double x, double y, double width, double height, float alpha) { - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha); - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); - - Tesselator tesselator = Tesselator.getInstance(); - - int z = 10; - BufferBuilder bufferbuilder = tesselator.begin(Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - bufferbuilder.addVertex((float) x, (float) (y + height), z).setUv(0.0f, 1.0f); - bufferbuilder.addVertex((float) (x + width), (float) (y + height), z).setUv(1.0f, 1.0f); - bufferbuilder.addVertex((float) (x + width), (float) y, z).setUv(1.0f, 0.0f); - bufferbuilder.addVertex((float) x, (float) y, z).setUv(0.0f, 0.0f); - BufferUploader.drawWithShader(bufferbuilder.buildOrThrow()); - } // Find an item in the hotbar which matches the given class // (this includes all subclasses) public static int findItemInHotbar(Inventory inventory, Predicate Itempredicate) { int itemId = -1; - int currentItemId = inventory.selected; - NonNullList items = inventory.items; + int currentItemId = inventory.getSelectedSlot(); + NonNullList items = inventory.getNonEquipmentItems(); if (items != null) { for (int i = 0; i < Inventory.getSelectionSize(); i++) { ItemStack stack = items.get(i); @@ -211,44 +177,6 @@ public static BlockHitResult getMouseOverBlock() { } } - // Check if there's a block at the given position which - // blocks movement. - @SuppressWarnings("unused") - private boolean doesBlockMovement(BlockPos pos) { - Level world = Minecraft.getInstance().level; - return world.getBlockState(pos).blocksMotion(); - } - - @SuppressWarnings("unused") - private boolean isDirectlyFacingSideHit(Direction sideHit, Vec3 lookVec) { - double thresh = 0.8; - switch (sideHit) { - case NORTH: - if (lookVec.z > thresh) { - return true; - } - break; - case EAST: - if (lookVec.x < -thresh) { - return true; - } - break; - case SOUTH: - if (lookVec.z < -thresh) { - return true; - } - break; - case WEST: - if (lookVec.x > thresh) { - return true; - } - break; - default: - break; - } - return false; - } - public static BlockPos highestSolidPoint(BlockPos pos) { // Gets a spawn-able location above the point // Highest solid block that isn't foliage @@ -258,7 +186,7 @@ public static BlockPos highestSolidPoint(BlockPos pos) { BlockPos blockpos; BlockPos blockpos1; // Start from max build height and search downward - for (blockpos = new BlockPos(pos.getX(), world.getMaxBuildHeight(), pos.getZ()); blockpos.getY() >= world.getMinBuildHeight(); blockpos = blockpos1) { + for (blockpos = new BlockPos(pos.getX(), world.getMaxY(), pos.getZ()); blockpos.getY() >= world.getMinY(); blockpos = blockpos1) { blockpos1 = blockpos.below(); BlockState state = chunk.getBlockState(blockpos1); diff --git a/common/src/main/resources/META-INF/accesstransformer.cfg b/common/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 00000000..cd38b37b --- /dev/null +++ b/common/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1,3 @@ +# EyeMine Access Transformer for NeoForge +public net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen selectedTab # CreativeModeTab +public net.minecraft.client.Minecraft missTime # I diff --git a/common/src/main/resources/eyemine-common.mixins.json b/common/src/main/resources/eyemine-common.mixins.json index 7ce8f54e..af30c30e 100644 --- a/common/src/main/resources/eyemine-common.mixins.json +++ b/common/src/main/resources/eyemine-common.mixins.json @@ -1,7 +1,7 @@ { "required": true, "minVersion": "0.8.4", - "compatibilityLevel": "JAVA_21", + "compatibilityLevel": "JAVA_22", "package": "com.specialeffect.eyemine.mixin", "target": "@env(DEFAULT)", "mixins": [ diff --git a/common/src/main/resources/eyemine.accesswidener b/common/src/main/resources/eyemine.accesswidener index 13aa3492..a261abf1 100644 --- a/common/src/main/resources/eyemine.accesswidener +++ b/common/src/main/resources/eyemine.accesswidener @@ -1,5 +1,5 @@ -accessWidener v2 named +accessWidener v2 official accessible field net/minecraft/client/gui/screens/inventory/CreativeModeInventoryScreen selectedTab Lnet/minecraft/world/item/CreativeModeTab; -accessible method net/minecraft/world/level/block/state/BlockBehaviour useItemOn (Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/ItemInteractionResult; -accessible field net/minecraft/client/Minecraft missTime I \ No newline at end of file +accessible method net/minecraft/world/level/block/state/BlockBehaviour useItemOn (Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult; +accessible field net/minecraft/client/Minecraft missTime I diff --git a/common/src/main/resources/eyemine.common.json b/common/src/main/resources/eyemine.common.json deleted file mode 100644 index cd3672f2..00000000 --- a/common/src/main/resources/eyemine.common.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "accessWidener": "eyemine.accesswidener" -} \ No newline at end of file diff --git a/common/src/main/resources/pack.mcmeta b/common/src/main/resources/pack.mcmeta index a939321a..eb5231a1 100644 --- a/common/src/main/resources/pack.mcmeta +++ b/common/src/main/resources/pack.mcmeta @@ -1,8 +1,10 @@ { "pack": { "description": { - "text": "EyeMine Mod" + "text": "${mod_name}" }, - "pack_format": 32 + "pack_format": 84, + "min_format": 84, + "max_format": 84 } } diff --git a/fabric/build.gradle b/fabric/build.gradle index fbcc8747..b240301b 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,88 +1,43 @@ plugins { - id "com.github.johnrengelman.shadow" version "8.1.1" + id 'multiloader-loader' + id 'net.fabricmc.fabric-loom' } -architectury { - platformSetupLoomIde() - fabric() -} - -loom { - accessWidenerPath = project(":common").loom.accessWidenerPath -} - -configurations { - common - shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. - compileClasspath.extendsFrom common - runtimeClasspath.extendsFrom common - developmentFabric.extendsFrom common -} - -dependencies { - modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" - modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}" - // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}" - - common(project(path: ":common", configuration: "namedElements")) { transitive false } - shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } - - modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { - exclude(group: "net.fabricmc.fabric-api") - } - modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}" -} - -processResources { - inputs.property "version", project.version - - filesMatching("fabric.mod.json") { - expand "version": project.version +repositories { + maven { + url "https://cursemaven.com" + content { + includeGroup "curse.maven" + } } } -shadowJar { - exclude "eyemine.common.json" - - configurations = [project.configurations.shadowCommon] - archiveClassifier.set("dev-shadow") -} - -remapJar { - injectAccessWidener = true - input.set shadowJar.archiveFile - dependsOn shadowJar - archiveBaseName.set "${rootProject.archives_base_name}-${project.minecraft_version}-${project.name}" - archiveClassifier.set('') -} - -jar { - archiveClassifier.set("dev") -} +dependencies { + minecraft "com.mojang:minecraft:${minecraft_version}" + implementation "net.fabricmc:fabric-loader:${fabric_loader_version}" + implementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" -sourcesJar { - def commonSources = project(":common").sourcesJar - dependsOn commonSources - from commonSources.archiveFile.map { zipTree(it) } + // Cloth Config for Fabric config GUI + implementation "curse.maven:cloth-config-348521:7817582" } -components.java { - withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - skip() +loom { + def aw = project(':common').file("src/main/resources/${mod_id}.accesswidener") + if (aw.exists()) { + accessWidenerPath.set(aw) } -} - -publishing { - publications { - mavenFabric(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.minecraft_version + "-" + project.name - from components.java + runs { + client { + client() + setConfigName('Fabric Client') + ideConfigGenerated(true) + runDir('runs/client') + } + server { + server() + setConfigName('Fabric Server') + ideConfigGenerated(true) + runDir('runs/server') } } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - } -} \ No newline at end of file +} diff --git a/fabric/src/main/java/com/specialeffect/eyemine/EyeMineClientFabric.java b/fabric/src/main/java/com/specialeffect/eyemine/EyeMineClientFabric.java index 37b19177..2a9bfff0 100644 --- a/fabric/src/main/java/com/specialeffect/eyemine/EyeMineClientFabric.java +++ b/fabric/src/main/java/com/specialeffect/eyemine/EyeMineClientFabric.java @@ -2,28 +2,113 @@ import com.specialeffect.eyemine.config.EyeMineConfig; import com.specialeffect.eyemine.config.InventoryConfig; -import com.specialeffect.eyemine.event.BlockOutlineEvent; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.event.EventResult; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper; +import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderEvents; +import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLevelEvents; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; +import net.minecraft.resources.Identifier; import net.minecraft.world.InteractionResult; public class EyeMineClientFabric implements ClientModInitializer { - @Override - public void onInitializeClient() { - AutoConfig.register(EyeMineConfig.class, Toml4jConfigSerializer::new); - AutoConfig.register(InventoryConfig.class, Toml4jConfigSerializer::new); - WorldRenderEvents.BLOCK_OUTLINE.register((blockOutline, blockOutlineContext) -> { - BlockOutlineEvent.OUTLINE.invoker().renderOutline(blockOutline.consumers(), blockOutline.matrixStack()); - return true; - }); - - AutoConfig.getConfigHolder(EyeMineConfig.class).registerSaveListener((manager, data) -> { - EyeMineClient.refresh(); - return InteractionResult.PASS; - }); - EyeMineClient.init(); - } -} \ No newline at end of file + @Override + public void onInitializeClient() { + AutoConfig.register(EyeMineConfig.class, Toml4jConfigSerializer::new); + AutoConfig.register(InventoryConfig.class, Toml4jConfigSerializer::new); + + AutoConfig.getConfigHolder(EyeMineConfig.class).registerSaveListener((manager, data) -> { + EyeMineClient.refresh(); + return InteractionResult.PASS; + }); + + EyeMineClient.init(); + + for (KeyMapping keyBinding : com.specialeffect.eyemine.client.Keybindings.keybindings) { + KeyMappingHelper.registerKeyMapping(keyBinding); + } + + registerEventForwarders(); + + EyeMineClient.setupComplete = true; + EyeMineClient.refresh(); + for (var listener : EyeMineEvents.CLIENT_SETUP.getListeners()) { + listener.onClientSetup(Minecraft.getInstance()); + } + } + + private void registerEventForwarders() { + // Client tick + ClientTickEvents.START_CLIENT_TICK.register(client -> { + for (var listener : EyeMineEvents.CLIENT_TICK.getListeners()) { + listener.onClientTick(client); + } + }); + + // HUD rendering + HudElementRegistry.addLast( + Identifier.fromNamespaceAndPath("eyemine", "overlay"), + (graphics, deltaTracker) -> { + for (var listener : EyeMineEvents.RENDER_HUD.getListeners()) { + listener.onRenderHud(graphics, deltaTracker); + } + } + ); + + // Block outline rendering + LevelRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, outlineState) -> { + if (outlineState != null) { + for (var listener : EyeMineEvents.BLOCK_OUTLINE.getListeners()) { + EventResult result = listener.renderOutline(context.bufferSource(), context.poseStack()); + if (result.isPresent()) return false; + } + } + return true; + }); + + // Key input forwarded via FabricKeyboardHandlerMixin + + // Screen set forwarded via FabricSetScreenMixin + + // Server-side: Entity death + ServerLivingEntityEvents.ALLOW_DEATH.register((entity, source, amount) -> { + for (var listener : EyeMineEvents.ENTITY_DEATH.getListeners()) { + EventResult result = listener.onDeath(entity, source); + if (result == EventResult.INTERRUPT_FALSE) return false; + } + return true; + }); + + // Server-side: Entity added to world + ServerEntityEvents.ENTITY_LOAD.register((entity, level) -> { + for (var listener : EyeMineEvents.ENTITY_ADD.getListeners()) { + listener.onAdd(entity, level); + } + }); + + // Server-side: World load + ServerLevelEvents.LOAD.register((server, level) -> { + for (var listener : EyeMineEvents.WORLD_LOAD.getListeners()) { + listener.onWorldLoad(level); + } + }); + + // Server-side: Player tick - Fabric uses ClientTickEvents for client-side player tick + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (client.player != null) { + for (var listener : EyeMineEvents.PLAYER_TICK.getListeners()) { + listener.onPlayerTick(client.player); + } + } + }); + } +} diff --git a/fabric/src/main/java/com/specialeffect/eyemine/config/EyeMineModMenuIntegration.java b/fabric/src/main/java/com/specialeffect/eyemine/config/EyeMineModMenuIntegration.java index 7d8cde66..e446112f 100644 --- a/fabric/src/main/java/com/specialeffect/eyemine/config/EyeMineModMenuIntegration.java +++ b/fabric/src/main/java/com/specialeffect/eyemine/config/EyeMineModMenuIntegration.java @@ -1,12 +1,20 @@ package com.specialeffect.eyemine.config; -import com.terraformersmc.modmenu.api.ConfigScreenFactory; -import com.terraformersmc.modmenu.api.ModMenuApi; -import me.shedaniel.autoconfig.AutoConfig; +// TODO: Uncomment when ModMenu is available for MC 26.1.1 +// Requires: modImplementation "com.terraformersmc:modmenu:" in fabric/build.gradle +// And add "modmenu" entrypoint back to fabric.mod.json -public class EyeMineModMenuIntegration implements ModMenuApi { - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return parent -> AutoConfig.getConfigScreen(EyeMineConfig.class, parent).get(); - } +//import com.terraformersmc.modmenu.api.ConfigScreenFactory; +//import com.terraformersmc.modmenu.api.ModMenuApi; +//import me.shedaniel.autoconfig.AutoConfig; +// +//public class EyeMineModMenuIntegration implements ModMenuApi { +// @Override +// public ConfigScreenFactory getModConfigScreenFactory() { +// return parent -> AutoConfig.getConfigScreen(EyeMineConfig.class, parent).get(); +// } +//} + +public class EyeMineModMenuIntegration { + // Stub class - ModMenu integration disabled until available for 26.1.1 } diff --git a/fabric/src/main/java/com/specialeffect/eyemine/mixin/FabricKeyboardHandlerMixin.java b/fabric/src/main/java/com/specialeffect/eyemine/mixin/FabricKeyboardHandlerMixin.java new file mode 100644 index 00000000..7ad574bb --- /dev/null +++ b/fabric/src/main/java/com/specialeffect/eyemine/mixin/FabricKeyboardHandlerMixin.java @@ -0,0 +1,33 @@ +package com.specialeffect.eyemine.mixin; + +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.event.EventResult; +import net.minecraft.client.KeyboardHandler; +import net.minecraft.client.Minecraft; +import net.minecraft.client.input.KeyEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * Fabric-specific mixin to forward raw key events to EyeMineEvents.KEY_PRESSED. + * NeoForge has InputEvent.Key for this; Fabric needs a mixin. + */ +@Mixin(KeyboardHandler.class) +public class FabricKeyboardHandlerMixin { + @Shadow + @Final + private Minecraft minecraft; + + @Inject(method = "keyPress(JILnet/minecraft/client/input/KeyEvent;)V", at = @At("HEAD")) + private void eyemine$onKeyPress(long windowHandle, int action, KeyEvent keyEvent, CallbackInfo ci) { + for (var listener : EyeMineEvents.KEY_PRESSED.getListeners()) { + EventResult result = listener.onKeyPressed( + minecraft, keyEvent.key(), keyEvent.scancode(), action, keyEvent.modifiers()); + if (result.isPresent()) break; + } + } +} diff --git a/fabric/src/main/java/com/specialeffect/eyemine/mixin/FabricSetScreenMixin.java b/fabric/src/main/java/com/specialeffect/eyemine/mixin/FabricSetScreenMixin.java new file mode 100644 index 00000000..79bdedd6 --- /dev/null +++ b/fabric/src/main/java/com/specialeffect/eyemine/mixin/FabricSetScreenMixin.java @@ -0,0 +1,26 @@ +package com.specialeffect.eyemine.mixin; + +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.event.ScreenSetResult; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * Fabric-specific mixin to forward screen open events to EyeMineEvents.SCREEN_SET. + * NeoForge has ScreenEvent.Opening for this; Fabric needs a mixin. + */ +@Mixin(Minecraft.class) +public class FabricSetScreenMixin { + + @Inject(method = "setScreen(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) + private void eyemine$onSetScreen(Screen screen, CallbackInfo ci) { + for (var listener : EyeMineEvents.SCREEN_SET.getListeners()) { + ScreenSetResult result = listener.onScreenSet(screen); + if (result.handled()) break; + } + } +} diff --git a/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/EyeMineConfigImpl.java b/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/EyeMineConfigImpl.java index 297b2388..8026664c 100644 --- a/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/EyeMineConfigImpl.java +++ b/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/EyeMineConfigImpl.java @@ -1,166 +1,47 @@ package com.specialeffect.eyemine.platform.fabric; import com.specialeffect.eyemine.config.EyeMineConfig; +import com.specialeffect.eyemine.platform.services.IEyeMineConfigService; import me.shedaniel.autoconfig.AutoConfig; -public class EyeMineConfigImpl { - public static boolean getDisableCustomNewWorld() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.disableCustomNewWorld; - } - - public static void setCustomSpeedFactor(float speed) { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - config.general.customSpeedFactor = speed; - } - - public static boolean getUsingMouseEmulation() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.general.usingMouseEmulation; - } - - public static boolean getAutoSelectTool() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.general.autoSelectTool; - } - - public static boolean getAutoSelectSword() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.general.autoSelectSword; - } - - public static int getRadiusChests() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.radiusChests; - } - - public static int getTicksBetweenMining() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.ticksBetweenMining; - } - - public static double getBowDrawTime() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.bowDrawTime; - } - - public static float getFullscreenOverlayAlpha() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.fullscreenOverlayAlpha; - } - - public static int getIronsightsFovReduction() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.ironsightsFovReduction; - } - - public static double getIronsightsSensitivityReduction() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.ironsightsSensitivityReduction; - } - - public static boolean getUseDwellForSingleUseItem() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.dwell.useDwellForSingleUseItem; - } - - public static boolean getUseDwellForSingleMine() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.dwell.useDwellForSingleMine; - } - - public static int getRadiusDoors() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.radiusDoors; - } - - public static boolean getServerCompatibilityMode() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.advanced.serverCompatibilityMode; - } - - public static int getFlyHeightManual() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.flyHeightManual; - } - - public static int getFlyHeightAuto() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.flyHeightAuto; - } - - public static boolean getDefaultDoAutoJump() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.general.defaultDoAutoJump; - } - - public static boolean getDisableAutoJumpFixes() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.general.disableAutoJumpFixes; - } - - public static boolean getMoveWhenMouseStationary() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.moveWhenMouseStationary; - } - - public static boolean getSlowdownOnCorners() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.slowdownOnCorners; - } - - public static int getWalkingSlowdownFilter() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.walkingSlowdownFilter; - } - - public static boolean getAllowLadderDescent() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.allowLadderDescent; - } - - public static float getCustomSpeedFactor() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.general.customSpeedFactor; - } - - public static float getBoatMaxTurnAtSpeed() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.boatMaxTurnAtSpeed; - } - - public static double getBoatSlowdown() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.boatSlowdown; - } - - public static double getDwellTimeSeconds() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.dwell.dwellTimeSeconds; - } - - public static double getDwellLockonTimeSeconds() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.dwell.dwellLockonTimeSeconds; - } - - public static boolean getDwellShowWithTransparency() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.dwell.dwellShowWithTransparency; - } - - public static boolean getDwellShowExpanding() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.dwell.dwellShowExpanding; - } - - public static boolean getSlowdownOnAttack() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.slowdownOnAttack; - } - - public static int getGazeIdleThreshold() { - EyeMineConfig config = AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); - return config.movement.gazeIdleThreshold; - } +public class EyeMineConfigImpl implements IEyeMineConfigService { + private EyeMineConfig getConfig() { + return AutoConfig.getConfigHolder(EyeMineConfig.class).getConfig(); + } + + @Override public boolean getDisableCustomNewWorld() { return getConfig().advanced.disableCustomNewWorld; } + @Override public void setCustomSpeedFactor(float speed) { + getConfig().general.customSpeedFactor = speed; + AutoConfig.getConfigHolder(EyeMineConfig.class).save(); + } + @Override public boolean getUsingMouseEmulation() { return getConfig().general.usingMouseEmulation; } + @Override public boolean getAutoSelectTool() { return getConfig().general.autoSelectTool; } + @Override public boolean getAutoSelectSword() { return getConfig().general.autoSelectSword; } + @Override public int getRadiusChests() { return getConfig().advanced.radiusChests; } + @Override public int getTicksBetweenMining() { return getConfig().advanced.ticksBetweenMining; } + @Override public double getBowDrawTime() { return getConfig().advanced.bowDrawTime; } + @Override public float getFullscreenOverlayAlpha() { return getConfig().advanced.fullscreenOverlayAlpha; } + @Override public int getIronsightsFovReduction() { return getConfig().advanced.ironsightsFovReduction; } + @Override public double getIronsightsSensitivityReduction() { return getConfig().advanced.ironsightsSensitivityReduction; } + @Override public boolean getUseDwellForSingleUseItem() { return getConfig().dwell.useDwellForSingleUseItem; } + @Override public boolean getUseDwellForSingleMine() { return getConfig().dwell.useDwellForSingleMine; } + @Override public int getRadiusDoors() { return getConfig().advanced.radiusDoors; } + @Override public boolean getServerCompatibilityMode() { return getConfig().advanced.serverCompatibilityMode; } + @Override public int getFlyHeightManual() { return getConfig().movement.flyHeightManual; } + @Override public int getFlyHeightAuto() { return getConfig().movement.flyHeightAuto; } + @Override public boolean getDefaultDoAutoJump() { return getConfig().general.defaultDoAutoJump; } + @Override public boolean getDisableAutoJumpFixes() { return getConfig().general.disableAutoJumpFixes; } + @Override public boolean getMoveWhenMouseStationary() { return getConfig().movement.moveWhenMouseStationary; } + @Override public boolean getSlowdownOnCorners() { return getConfig().movement.slowdownOnCorners; } + @Override public int getWalkingSlowdownFilter() { return getConfig().movement.walkingSlowdownFilter; } + @Override public boolean getAllowLadderDescent() { return getConfig().movement.allowLadderDescent; } + @Override public float getCustomSpeedFactor() { return getConfig().general.customSpeedFactor; } + @Override public float getBoatMaxTurnAtSpeed() { return getConfig().movement.boatMaxTurnAtSpeed; } + @Override public double getBoatSlowdown() { return getConfig().movement.boatSlowdown; } + @Override public double getDwellTimeSeconds() { return getConfig().dwell.dwellTimeSeconds; } + @Override public double getDwellLockonTimeSeconds() { return getConfig().dwell.dwellLockonTimeSeconds; } + @Override public boolean getDwellShowWithTransparency() { return getConfig().dwell.dwellShowWithTransparency; } + @Override public boolean getDwellShowExpanding() { return getConfig().dwell.dwellShowExpanding; } + @Override public boolean getSlowdownOnAttack() { return getConfig().movement.slowdownOnAttack; } + @Override public int getGazeIdleThreshold() { return getConfig().movement.gazeIdleThreshold; } } diff --git a/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/FabricNetworkService.java b/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/FabricNetworkService.java new file mode 100644 index 00000000..89616556 --- /dev/null +++ b/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/FabricNetworkService.java @@ -0,0 +1,41 @@ +package com.specialeffect.eyemine.platform.fabric; + +import com.specialeffect.eyemine.packets.NetworkService; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.world.entity.player.Player; + +public class FabricNetworkService implements NetworkService { + + @Override + public void registerC2S( + CustomPacketPayload.Type type, + StreamCodec codec, + PacketHandler handler) { + PayloadTypeRegistry.serverboundPlay().register(type, codec); + ServerPlayNetworking.registerGlobalReceiver(type, (payload, context) -> { + handler.handle(payload, new FabricPacketContext(context)); + }); + } + + @Override + public void sendToServer(CustomPacketPayload payload) { + ClientPlayNetworking.send(payload); + } + + private record FabricPacketContext(ServerPlayNetworking.Context fabricContext) implements PacketContext { + @Override + public void queue(Runnable work) { + fabricContext.player().level().getServer().execute(work); + } + + @Override + public Player getPlayer() { + return fabricContext.player(); + } + } +} diff --git a/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/FabricPlatformHelper.java b/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/FabricPlatformHelper.java new file mode 100644 index 00000000..e7f50334 --- /dev/null +++ b/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/FabricPlatformHelper.java @@ -0,0 +1,21 @@ +package com.specialeffect.eyemine.platform.fabric; + +import com.specialeffect.eyemine.platform.services.IPlatformHelper; +import net.fabricmc.loader.api.FabricLoader; + +public class FabricPlatformHelper implements IPlatformHelper { + @Override + public String getPlatformName() { + return "Fabric"; + } + + @Override + public boolean isModLoaded(String modId) { + return FabricLoader.getInstance().isModLoaded(modId); + } + + @Override + public boolean isDevelopmentEnvironment() { + return FabricLoader.getInstance().isDevelopmentEnvironment(); + } +} diff --git a/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/InventoryConfigImpl.java b/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/InventoryConfigImpl.java index d787fc16..9882336c 100644 --- a/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/InventoryConfigImpl.java +++ b/fabric/src/main/java/com/specialeffect/eyemine/platform/fabric/InventoryConfigImpl.java @@ -1,131 +1,37 @@ package com.specialeffect.eyemine.platform.fabric; import com.specialeffect.eyemine.config.InventoryConfig; +import com.specialeffect.eyemine.platform.services.IInventoryConfigService; import me.shedaniel.autoconfig.AutoConfig; -public class InventoryConfigImpl { - public static int getKey0() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key0; - } - - public static int getKey1() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key1; - } - - public static int getKey2() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key2; - } - - public static int getKey3() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key3; - } - - public static int getKey4() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key4; - } - - public static int getKey5() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key5; - } - - public static int getKey6() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key6; - } - - public static int getKey7() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key7; - } - - public static int getKey8() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key8; - } - - public static int getKey9() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.configKeys.key9; - } - - public static int getKeySurvPrevTab() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.survival.keySurvPrevTab; - } - - public static int getKeySurvNextTab() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.survival.keySurvNextTab; - } - - public static int getKeySurvRecipes() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.survival.keySurvRecipes; - } - - public static int getKeySurvCraftable() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.survival.keySurvCraftable; - } - - public static int getkeySurvPrevPage() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.survival.keySurvPrevPage; - } - - public static int getkeySurvNextPage() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.survival.keySurvNextPage; - } - - public static int getKeySurvOutput() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.survival.keySurvOutput; - } - - public static int getKeyPrev() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.navKeys.keyPrev; - } - - public static int getKeyNext() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.navKeys.keyNext; - } - - public static int getKeyNextItemRow() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.navKeys.keyNextItemRow; - } - - public static int getKeyNextItemCol() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.navKeys.keyNextItemCol; - } - - public static int getKeyScrollUp() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.navKeys.keyScrollUp; - } - - public static int getKeyScrollDown() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.navKeys.keyScrollDown; - } - - public static int getKeySearch() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.navKeys.keySearch; - } - - public static int getKeyDrop() { - InventoryConfig config = AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); - return config.navKeys.keyDrop; - } +public class InventoryConfigImpl implements IInventoryConfigService { + private InventoryConfig getConfig() { + return AutoConfig.getConfigHolder(InventoryConfig.class).getConfig(); + } + + @Override public int getKey0() { return getConfig().configKeys.key0; } + @Override public int getKey1() { return getConfig().configKeys.key1; } + @Override public int getKey2() { return getConfig().configKeys.key2; } + @Override public int getKey3() { return getConfig().configKeys.key3; } + @Override public int getKey4() { return getConfig().configKeys.key4; } + @Override public int getKey5() { return getConfig().configKeys.key5; } + @Override public int getKey6() { return getConfig().configKeys.key6; } + @Override public int getKey7() { return getConfig().configKeys.key7; } + @Override public int getKey8() { return getConfig().configKeys.key8; } + @Override public int getKey9() { return getConfig().configKeys.key9; } + @Override public int getKeySurvPrevTab() { return getConfig().survival.keySurvPrevTab; } + @Override public int getKeySurvNextTab() { return getConfig().survival.keySurvNextTab; } + @Override public int getKeySurvRecipes() { return getConfig().survival.keySurvRecipes; } + @Override public int getKeySurvCraftable() { return getConfig().survival.keySurvCraftable; } + @Override public int getkeySurvPrevPage() { return getConfig().survival.keySurvPrevPage; } + @Override public int getkeySurvNextPage() { return getConfig().survival.keySurvNextPage; } + @Override public int getKeySurvOutput() { return getConfig().survival.keySurvOutput; } + @Override public int getKeyPrev() { return getConfig().navKeys.keyPrev; } + @Override public int getKeyNext() { return getConfig().navKeys.keyNext; } + @Override public int getKeyNextItemRow() { return getConfig().navKeys.keyNextItemRow; } + @Override public int getKeyNextItemCol() { return getConfig().navKeys.keyNextItemCol; } + @Override public int getKeyScrollUp() { return getConfig().navKeys.keyScrollUp; } + @Override public int getKeyScrollDown() { return getConfig().navKeys.keyScrollDown; } + @Override public int getKeySearch() { return getConfig().navKeys.keySearch; } + @Override public int getKeyDrop() { return getConfig().navKeys.keyDrop; } } diff --git a/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.packets.NetworkService b/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.packets.NetworkService new file mode 100644 index 00000000..aa6877d9 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.packets.NetworkService @@ -0,0 +1 @@ +com.specialeffect.eyemine.platform.fabric.FabricNetworkService diff --git a/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IEyeMineConfigService b/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IEyeMineConfigService new file mode 100644 index 00000000..ad2caad9 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IEyeMineConfigService @@ -0,0 +1 @@ +com.specialeffect.eyemine.platform.fabric.EyeMineConfigImpl diff --git a/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IInventoryConfigService b/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IInventoryConfigService new file mode 100644 index 00000000..53729a40 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IInventoryConfigService @@ -0,0 +1 @@ +com.specialeffect.eyemine.platform.fabric.InventoryConfigImpl diff --git a/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IPlatformHelper b/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IPlatformHelper new file mode 100644 index 00000000..52395038 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IPlatformHelper @@ -0,0 +1 @@ +com.specialeffect.eyemine.platform.fabric.FabricPlatformHelper diff --git a/fabric/src/main/resources/eyemine.fabric.mixins.json b/fabric/src/main/resources/eyemine.fabric.mixins.json new file mode 100644 index 00000000..76bfa73c --- /dev/null +++ b/fabric/src/main/resources/eyemine.fabric.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.specialeffect.eyemine.mixin", + "compatibilityLevel": "JAVA_22", + "client": [ + "FabricKeyboardHandlerMixin", + "FabricSetScreenMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index f20e127b..d387356d 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -1,9 +1,9 @@ { "schemaVersion": 1, - "id": "eyemine", + "id": "${mod_id}", "version": "${version}", - "name": "EyeMine", - "description": "EyeMine by SpecialEffect allows you to play Minecraft using eye gaze.\nIt is designed to work alongside the EyeMine gaze-controlled keyboard. \nFor questions or support, contact eyemine@specialeffect.org.uk", + "name": "${mod_name}", + "description": "${description}", "authors": [ "Kirsty McNaught", "Mrbysco" ], @@ -11,7 +11,7 @@ "homepage": "https://www.specialeffect.org.uk/eyemine", "sources": "https://github.com/SpecialEffect/SpecialEffectMinecraftMods" }, - "license": "GPL-3.0", + "license": "${license}", "icon": "eyemine_logo.png", "environment": "*", "entrypoints": { @@ -20,20 +20,17 @@ ], "client": [ "com.specialeffect.eyemine.EyeMineClientFabric" - ], - "modmenu": [ - "com.specialeffect.eyemine.config.EyeMineModMenuIntegration" ] }, "mixins": [ - "eyemine-common.mixins.json" + "eyemine-common.mixins.json", + "eyemine.fabric.mixins.json" ], "depends": { - "fabricloader": ">=0.15.11", - "minecraft": "~1.21", - "java": ">=21", + "fabricloader": ">=${fabric_loader_version}", + "minecraft": "~${minecraft_version}", + "java": ">=${java_version}", "fabric-api": "*", - "cloth-config": ">=14", - "architectury": ">=13" + "cloth-config": ">=14" } -} \ No newline at end of file +} diff --git a/forge/build.gradle b/forge/build.gradle deleted file mode 100644 index 7c49d846..00000000 --- a/forge/build.gradle +++ /dev/null @@ -1,91 +0,0 @@ -plugins { - id "com.github.johnrengelman.shadow" version "8.1.1" -} - -architectury { - platformSetupLoomIde() - forge() -} - -loom { - accessWidenerPath = project(":common").loom.accessWidenerPath - - forge { - convertAccessWideners = true - extraAccessWideners.add loom.accessWidenerPath.get().asFile.name - - mixinConfig "eyemine-common.mixins.json" - } -} - -configurations { - common - shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files. - compileClasspath.extendsFrom common - runtimeClasspath.extendsFrom common - developmentForge.extendsFrom common -} - -dependencies { - forge "net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}" - // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}" - - common(project(path: ":common", configuration: "namedElements")) { transitive false } - shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } - - modCompileOnly("curse.maven:configured-457570:5105022") -} - -processResources { - inputs.property "version", project.version - - filesMatching("META-INF/mods.toml") { - expand "version": project.version - } -} - -shadowJar { - exclude "fabric.mod.json" - exclude "eyemine.common.json" - - configurations = [project.configurations.shadowCommon] - archiveClassifier.set("dev-shadow") -} - -remapJar { - input.set shadowJar.archiveFile - dependsOn shadowJar - archiveBaseName.set "${rootProject.archives_base_name}-${project.minecraft_version}-${project.name}" - archiveClassifier.set('') -} - -jar { - archiveClassifier.set("dev") -} - -sourcesJar { - def commonSources = project(":common").sourcesJar - dependsOn commonSources - from commonSources.archiveFile.map { zipTree(it) } -} - -components.java { - withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - skip() - } -} - -publishing { - publications { - mavenForge(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.name - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - } -} diff --git a/forge/gradle.properties b/forge/gradle.properties deleted file mode 100644 index 32f842a6..00000000 --- a/forge/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -loom.platform=forge \ No newline at end of file diff --git a/forge/src/main/java/com/inventory/config/InventoryConfig.java b/forge/src/main/java/com/inventory/config/InventoryConfig.java deleted file mode 100644 index b4e7450a..00000000 --- a/forge/src/main/java/com/inventory/config/InventoryConfig.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * Copyright (C) 2016-2020 Kirsty McNaught - *

- * Developed for SpecialEffect, www.specialeffect.org.uk - *

- * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 3 - * of the License, or (at your option) any later version. - */ - -package com.inventory.config; - -import com.electronwill.nightconfig.core.file.CommentedFileConfig; -import com.electronwill.nightconfig.core.io.WritingMode; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.event.config.ModConfigEvent; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.lwjgl.glfw.GLFW; - -import java.nio.file.Path; - -public class InventoryConfig { - // Based on McJty/YouTubeModding14 tutorial, MIT license: - // https://github.com/McJty/YouTubeModding14/blob/master/LICENSE - - // Directly reference a log4j logger. - private static final Logger LOGGER = LogManager.getLogger(); - - public static final String CATEGORY_GENERAL = "general"; - - private static final ForgeConfigSpec.Builder CLIENT_BUILDER = new ForgeConfigSpec.Builder(); - - public static ForgeConfigSpec CLIENT_CONFIG; - - public static ConfigValue key0, key1, key2, key3, key4, - key5, key6, key7, key8, key9, - keyNext, keyPrev, keySearch, - keyScrollUp, keyScrollDown, - keyNextItemRow, keyNextItemCol, keyDrop; - - public static ConfigValue keySurvNextTab, keySurvPrevTab, keySurvRecipes, keySurvCraftable, - keySurvPrevPage, keySurvNextPage, keySurvOutput; - - - static { - CLIENT_BUILDER.comment("Inventory shortcut keys").push("Keys"); - setupConfigKeys(); - CLIENT_BUILDER.pop(); - - CLIENT_BUILDER.comment("Navigation keys").push("Keys"); - setupNavKeys(); - CLIENT_BUILDER.pop(); - - CLIENT_BUILDER.comment("Survival inventory keys").push("Keys"); - setupSurvivalKeys(); - CLIENT_BUILDER.pop(); - - CLIENT_CONFIG = CLIENT_BUILDER.build(); - } - - - private static void setupSurvivalKeys() { - - keySurvPrevTab = CLIENT_BUILDER.comment("recipes: prev tab").define("keySurvPrevTab", GLFW.GLFW_KEY_KP_0); - keySurvNextTab = CLIENT_BUILDER.comment("recipes: next tab").define("keySurvNextTab", GLFW.GLFW_KEY_KP_1); - - keySurvRecipes = CLIENT_BUILDER.comment("open/close recipe book").define("keySurvRecipes", GLFW.GLFW_KEY_KP_2); - keySurvCraftable = CLIENT_BUILDER.comment("toggle all/craftable").define("keySurvCraftable", GLFW.GLFW_KEY_KP_3); - - keySurvPrevPage = CLIENT_BUILDER.comment("recipes: prev page").define("keySurvPrevPage", GLFW.GLFW_KEY_KP_4); - keySurvNextPage = CLIENT_BUILDER.comment("recipes: next page").define("keySurvNextPage", GLFW.GLFW_KEY_KP_5); - - keySurvOutput = CLIENT_BUILDER.comment("hover output").define("keySurvOutput", GLFW.GLFW_KEY_KP_6); - - } - - private static void setupConfigKeys() { - - key0 = CLIENT_BUILDER.comment("key0").define("key0", GLFW.GLFW_KEY_KP_0); - key1 = CLIENT_BUILDER.comment("key1").define("key1", GLFW.GLFW_KEY_KP_1); - key2 = CLIENT_BUILDER.comment("key2").define("key2", GLFW.GLFW_KEY_KP_2); - key3 = CLIENT_BUILDER.comment("key3").define("key3", GLFW.GLFW_KEY_KP_3); - key4 = CLIENT_BUILDER.comment("key4").define("key4", GLFW.GLFW_KEY_KP_4); - key5 = CLIENT_BUILDER.comment("key5").define("key5", GLFW.GLFW_KEY_KP_5); - key6 = CLIENT_BUILDER.comment("key6").define("key6", GLFW.GLFW_KEY_KP_6); - key7 = CLIENT_BUILDER.comment("key7").define("key7", GLFW.GLFW_KEY_KP_7); - key8 = CLIENT_BUILDER.comment("key8").define("key8", GLFW.GLFW_KEY_KP_8); - key9 = CLIENT_BUILDER.comment("key9").define("key9", GLFW.GLFW_KEY_KP_9); - - } - - private static void setupNavKeys() { - - keyPrev = CLIENT_BUILDER.comment("keyPrev").define("keyPrev", GLFW.GLFW_KEY_LEFT); - keyNext = CLIENT_BUILDER.comment("keyNext").define("keyNext", GLFW.GLFW_KEY_RIGHT); - keyNextItemRow = CLIENT_BUILDER.comment("keyNextItemRow").define("keyNextItemRow", GLFW.GLFW_KEY_F6); - keyNextItemCol = CLIENT_BUILDER.comment("keyNextItemCol").define("keyNextItemCol", GLFW.GLFW_KEY_F7); - - keyScrollUp = CLIENT_BUILDER.comment("keyScrollUp").define("keyScrollUp", GLFW.GLFW_KEY_F8); - keyScrollDown = CLIENT_BUILDER.comment("keyScrollDown").define("keyScrollDown", GLFW.GLFW_KEY_F9); - - keySearch = CLIENT_BUILDER.comment("keySearch").define("keySearch", GLFW.GLFW_KEY_DOWN); - keyDrop = CLIENT_BUILDER.comment("keyDrop2").define("keyDrop2", GLFW.GLFW_KEY_MINUS); - } - - public static void loadConfig(ForgeConfigSpec spec, Path path) { - - final CommentedFileConfig configData = CommentedFileConfig.builder(path) - .sync() - .autosave() - .writingMode(WritingMode.REPLACE) - .build(); - - configData.load(); - spec.setConfig(configData); - } - - @SubscribeEvent - public static void onLoad(final ModConfigEvent.Loading configEvent) { - LOGGER.info("Inventory config onLoad"); - } - - @SubscribeEvent - public static void onReload(final ModConfigEvent.Reloading configEvent) { - LOGGER.info("Inventory config onReload"); - - if (configEvent.getConfig() != null && configEvent.getConfig().getSpec() == CLIENT_CONFIG) { - // the configspec values are updated for us, but we may want to hook into here too? - } - } - -} \ No newline at end of file diff --git a/forge/src/main/java/com/specialeffect/eyemine/client/forge/ClientHandler.java b/forge/src/main/java/com/specialeffect/eyemine/client/forge/ClientHandler.java deleted file mode 100644 index 13d4c26d..00000000 --- a/forge/src/main/java/com/specialeffect/eyemine/client/forge/ClientHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (C) 2016-2020 Kirsty McNaught - *

- * Developed for SpecialEffect, www.specialeffect.org.uk - *

- * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 3 - * of the License, or (at your option) any later version. - */ - -package com.specialeffect.eyemine.client.forge; - -import com.specialeffect.eyemine.EyeMineClient; -import com.specialeffect.eyemine.event.BlockOutlineEvent; -import net.minecraftforge.client.event.RenderHighlightEvent; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; - -public class ClientHandler { - public static void setup(final FMLCommonSetupEvent event) { - EyeMineClient.setupComplete = true; - EyeMineClient.refresh(); - } - - public static void onOutlineRender(RenderHighlightEvent.Block event) { - BlockOutlineEvent.OUTLINE.invoker().renderOutline(event.getMultiBufferSource(), event.getPoseStack()); - } -} diff --git a/forge/src/main/java/com/specialeffect/eyemine/config/EyeMineConfig.java b/forge/src/main/java/com/specialeffect/eyemine/config/EyeMineConfig.java deleted file mode 100644 index 770a5eea..00000000 --- a/forge/src/main/java/com/specialeffect/eyemine/config/EyeMineConfig.java +++ /dev/null @@ -1,281 +0,0 @@ -/** - * Copyright (C) 2016-2020 Kirsty McNaught - *

- * Developed for SpecialEffect, www.specialeffect.org.uk - *

- * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 3 - * of the License, or (at your option) any later version. - */ - -package com.specialeffect.eyemine.config; - -import com.electronwill.nightconfig.core.file.CommentedFileConfig; -import com.electronwill.nightconfig.core.io.ParsingMode; -import com.electronwill.nightconfig.core.io.WritingMode; -import com.specialeffect.eyemine.EyeMine; -import com.specialeffect.eyemine.EyeMineClient; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.event.config.ModConfigEvent; - -import java.nio.file.Path; - -public class EyeMineConfig { - // Based on McJty/YouTubeModding14 tutorial, MIT license: - // https://github.com/McJty/YouTubeModding14/blob/master/LICENSE - - // Category names for clustering config options in different UIs - public static final String CATEGORY_BASIC = "basic"; - public static final String CATEGORY_ADVANCED = "advanced"; - public static final String CATEGORY_MOVING = "moving"; - public static final String CATEGORY_DWELLING = "dwelling"; - - public static final String CATEGORY_BASIC_USERSTRING = "Basic options"; - public static final String CATEGORY_ADVANCED_USERSTRING = "Advanced options"; - public static final String CATEGORY_MOVING_USERSTRING = "Moving options"; - public static final String CATEGORY_DWELLING_USERSTRING = "Dwelling options"; - - private static final ForgeConfigSpec.Builder CLIENT_BUILDER = new ForgeConfigSpec.Builder(); - public static ForgeConfigSpec CLIENT_CONFIG; - - // Flying options - public static ForgeConfigSpec.IntValue flyHeightManual; - public static ForgeConfigSpec.IntValue flyHeightAuto; - - // Walking options -> walk with gaze - public static ForgeConfigSpec.IntValue walkingSlowdownFilter; - public static ForgeConfigSpec.BooleanValue moveWhenMouseStationary; - public static ForgeConfigSpec.DoubleValue customSpeedFactor; - public static ForgeConfigSpec.IntValue gazeIdleThreshold; - - public static ForgeConfigSpec.BooleanValue slowdownOnCorners; - public static ForgeConfigSpec.BooleanValue slowdownOnAttack; - - public static ForgeConfigSpec.BooleanValue allowLadderDescent; - - // Boats - public static ForgeConfigSpec.DoubleValue boatSlowdown; - public static ForgeConfigSpec.IntValue boatMaxTurnAtSpeed; - - // AutoJump - public static ForgeConfigSpec.BooleanValue defaultDoAutoJump; - public static ForgeConfigSpec.BooleanValue disableAutoJumpFixes; - - // MouseHandler options - public static ForgeConfigSpec.BooleanValue usingMouseEmulation; - - // Mining - public static ForgeConfigSpec.BooleanValue autoSelectTool; - public static ForgeConfigSpec.IntValue ticksBetweenMining; - public static ForgeConfigSpec.BooleanValue serverCompatibilityMode; - - // AutoOpenDoors - public static ForgeConfigSpec.IntValue radiusDoors; - - // OpenTablesChests - public static ForgeConfigSpec.IntValue radiusChests; - - // ContinuouslyAttack - public static ForgeConfigSpec.BooleanValue autoSelectSword; - - // Dwelling options - public static ForgeConfigSpec.DoubleValue dwellTimeSeconds; - public static ForgeConfigSpec.DoubleValue dwellLockonTimeSeconds; - public static ForgeConfigSpec.BooleanValue dwellShowExpanding; - public static ForgeConfigSpec.BooleanValue dwellShowWithTransparency; - public static ForgeConfigSpec.BooleanValue useDwellForSingleMine; - public static ForgeConfigSpec.BooleanValue useDwellForSingleUseItem; - - // Ironsights - public static ForgeConfigSpec.DoubleValue ironsightsSensitivityReduction; - public static ForgeConfigSpec.IntValue ironsightsFovReduction; - - // Bow and arrow - public static ForgeConfigSpec.DoubleValue bowDrawTime; - - // Graphics - public static ForgeConfigSpec.DoubleValue fullscreenOverlayAlpha; - - // Create World - public static ForgeConfigSpec.BooleanValue disableCustomNewWorld; - - static { - CLIENT_BUILDER.comment(CATEGORY_BASIC_USERSTRING).push(CATEGORY_BASIC); - setupBasicConfig(); - CLIENT_BUILDER.pop(); - - CLIENT_BUILDER.comment(CATEGORY_ADVANCED_USERSTRING).push(CATEGORY_ADVANCED); - setupAdvancedConfig(); - CLIENT_BUILDER.pop(); - - CLIENT_BUILDER.comment(CATEGORY_MOVING_USERSTRING).push(CATEGORY_MOVING); - setupMovingConfig(); - CLIENT_BUILDER.pop(); - - CLIENT_BUILDER.comment(CATEGORY_DWELLING_USERSTRING).push(CATEGORY_DWELLING); - setupDwellConfig(); - CLIENT_BUILDER.pop(); - - CLIENT_CONFIG = CLIENT_BUILDER.build(); - } - - private static void setupBasicConfig() { - customSpeedFactor = CLIENT_BUILDER.comment("Walking speed for walk-with-gaze").defineInRange("walkingSpeed", - 0.6, 0.25, 2.0); - - defaultDoAutoJump = CLIENT_BUILDER.comment("Auto-jump switched on by default?") - .define("defaultDoAutoJump", true); - - disableAutoJumpFixes = CLIENT_BUILDER.comment("Disable Auto-Jump Fixes" + - "(EyeMine's extra Auto-Jump fixes can cause problems on servers, " + - "if you notice yourself being teleported back enable this option)") - .define("disableAutoJumpFixes", false); - - usingMouseEmulation = CLIENT_BUILDER.comment( - "Enable mouse-emulation compatibility mode?.\nTurn this on if you're using mouse position as an input to EyeMine") - .define("usingMouseEmulation", false); - - autoSelectSword = CLIENT_BUILDER.comment( - "When attacking, do you want a sword selected automatically?\nThis only applies in Creative Mode.") - .define("autoSelectSword", true); - - autoSelectTool = CLIENT_BUILDER - .comment( - "When mining, do you want pickaxe selected automatically?\nThis only applies in Creative Mode.") - .define("autoSelectTool", true); - - } - - private static void setupAdvancedConfig() { - - disableCustomNewWorld = CLIENT_BUILDER - .comment("Disable the custom new world screen and the defaults it applies to every world") - .define("disableCustomNewWorld", false); - - // This is limited to 6 blocks since the gui doesn't appear if block is too far - // away - radiusChests = CLIENT_BUILDER - .comment("How far away a player needs to be from a chest/table to be able to open it") - .defineInRange("radiusChests", 5, 1, 6); - - radiusDoors = CLIENT_BUILDER.comment( - "How far away a player needs to be from a door to automatically open/close.\nSet to zero to turn off automatic door-opening") - .defineInRange("radiusDoors", 2, 0, 10); - - ticksBetweenMining = CLIENT_BUILDER - .comment("How many ticks to wait before mining again\nOnly affects creative mode") - .defineInRange("ticksBetweenMining", 15, 0, 50); - - // Ironsights - ironsightsFovReduction = CLIENT_BUILDER - .comment("How much to reduce field of view (degrees) when using ironsights") - .defineInRange("ironsightsFovReduction", 20, 0, 40); - - ironsightsSensitivityReduction = CLIENT_BUILDER - .comment("How much to reduce sensitivity (%) when using ironsights") - .defineInRange("ironsightsSensitivityReduction", 13.0, 0.0, 30.0); - - // Bow-firing - bowDrawTime = CLIENT_BUILDER.comment("How long (seconds) to keep bow drawn for when firing with 'Use Item'") - .defineInRange("bowDrawTime", 1.0, 0.5, 5.0); - - fullscreenOverlayAlpha = CLIENT_BUILDER - .comment("Opacity of full-screen overlays (look, careful walk)") - .defineInRange("fullscreenOverlayAlpha", 0.1, 0.0, 0.2); - - serverCompatibilityMode = CLIENT_BUILDER - .comment("Use simpler mining/placing logic to play on servers without EyeMine installed") - .define("serverCompatibilityMode", false); - - } - - private static void setupMovingConfig() { - - slowdownOnCorners = CLIENT_BUILDER - .comment("Slow down auto-walk when going round a corner\nYou may want to turn this off for survival") - .define("slowdownOnCorners", true); - - walkingSlowdownFilter = CLIENT_BUILDER.comment( - "How many ticks to take into account for slowing down while looking around / turning corners.\n(smaller number = faster, 20 = 1 second)") - .defineInRange("walkingSlowdownFilter", 20, 1, 200); - - moveWhenMouseStationary = CLIENT_BUILDER.comment( - "Continue walking forward when the mouse is stationary?\nRecommended to be turned off for eye gaze control, or turned on for joysticks.") - .define("moveWhenMouseStationary", false); - - gazeIdleThreshold = CLIENT_BUILDER.comment( - "Percentage of screen height from bottom where gaze pauses walking\n(for looking at onboard keyboard). 0 = disabled, 10 = bottom 10% of screen") - .defineInRange("gazeIdleThreshold", 10, 0, 50); - - slowdownOnAttack = CLIENT_BUILDER.comment( - "Slow down auto-walk when attacking an entity\nThis only applies when your crosshair is over an entity, and makes\nit easier to chase mobs") - .define("slowdownOnAttack", true); - - flyHeightManual = CLIENT_BUILDER.comment("How high to fly (up/down) in manual mode") - .defineInRange("flyHeightManual", 2, 1, 20); - - flyHeightAuto = CLIENT_BUILDER.comment("How high to fly in auto mode").defineInRange("flyHeightAuto", 6, 1, 10); - - allowLadderDescent = CLIENT_BUILDER.comment( - "Descend ladders by looking down while moving. \n Experimental; may cause problems getting on/off ladders.") - .define("allowLadderDescent", false); - - // Boats - boatSlowdown = CLIENT_BUILDER - .comment("Slowdown applied to forward motion of boats (lower is slower)") - .defineInRange("boatSlowdown", 0.5, 0.01, 1.0); - - boatMaxTurnAtSpeed = CLIENT_BUILDER - .comment("Maximum angle (degrees) at which boat will still travel forwards while turning") - .defineInRange("boatMaxTurnAtSpeed", 30, 1, 90); - } - - private static void setupDwellConfig() { - - dwellTimeSeconds = CLIENT_BUILDER.comment("Time for dwell to complete (seconds)") - .defineInRange("dwellTimeSeconds", 1.2, 0.2, 5.0); - - dwellLockonTimeSeconds = CLIENT_BUILDER - .comment("Time for dwell to lock on (seconds)\n Must be lower than dwellTimeSeconds") - .defineInRange("dwellLockonTimeSeconds", 0.2, 0.0, 1.0); - - dwellShowExpanding = CLIENT_BUILDER.comment("Show dwell expanding instead of shrinking") - .define("dwellShowExpanding", false); - - dwellShowWithTransparency = CLIENT_BUILDER.comment( - "Show dwell by changing transparency instead of growing/shrinking\nThis option overrides dwellShowExpanding") - .define("dwellShowWithTransparency", false); - - useDwellForSingleMine = CLIENT_BUILDER.comment("Use dwell for 'mine once' (creative only)") - .define("useDwellForSingleMine", false); - - useDwellForSingleUseItem = CLIENT_BUILDER.comment("Use dwell for single 'use item'") - .define("useDwellForSingleUseItem", false); - - } - - public static void loadConfig(ForgeConfigSpec spec, Path path) { - final CommentedFileConfig configData = CommentedFileConfig.builder(path).preserveInsertionOrder().sync() - .autosave().writingMode(WritingMode.REPLACE).parsingMode(ParsingMode.ADD).concurrent().build(); - - configData.load(); - spec.setConfig(configData); - } - - @SubscribeEvent - public static void onLoad(final ModConfigEvent.Loading configEvent) { - EyeMine.LOGGER.debug("EyeMine config onLoad"); - } - - @SubscribeEvent - public static void onReload(final ModConfigEvent.Reloading configEvent) { - // the configspec values are updated for us, but we may want to hook into - // here to notify other mods? - EyeMine.LOGGER.info("EyeMine config onReload"); - - EyeMineClient.refresh(); - } - -} \ No newline at end of file diff --git a/forge/src/main/java/com/specialeffect/eyemine/forge/EyeMineForge.java b/forge/src/main/java/com/specialeffect/eyemine/forge/EyeMineForge.java deleted file mode 100644 index 0311d323..00000000 --- a/forge/src/main/java/com/specialeffect/eyemine/forge/EyeMineForge.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.specialeffect.eyemine.forge; - -import com.inventory.config.InventoryConfig; -import com.specialeffect.eyemine.EyeMine; -import com.specialeffect.eyemine.EyeMineClient; -import com.specialeffect.eyemine.client.forge.ClientHandler; -import com.specialeffect.eyemine.config.EyeMineConfig; -import dev.architectury.platform.forge.EventBuses; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.IExtensionPoint; -import net.minecraftforge.fml.IExtensionPoint.DisplayTest; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; - -@Mod(EyeMine.MOD_ID) -public class EyeMineForge { - public EyeMineForge() { - - // Submit our event bus to let architectury register our content on the right time - IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); - - // Config setup - ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, EyeMineConfig.CLIENT_CONFIG, "eyemine-config.toml"); - eventBus.register(EyeMineConfig.class); - ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, InventoryConfig.CLIENT_CONFIG, "eyemine-inventory-config.toml"); - eventBus.register(InventoryConfig.class); - - EventBuses.registerModEventBus(EyeMine.MOD_ID, eventBus); - EyeMine.init(); - - //Make sure the mod being absent on the other network side does not cause the client to display the server as incompatible - ModLoadingContext.get().registerExtensionPoint(DisplayTest.class, () -> - new IExtensionPoint.DisplayTest(() -> "Everyone is valid", - (remoteVersionString, networkBool) -> networkBool)); - - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - // Hook up config gui -// ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> ClientHandler::openSettings); - - // Register this setup method *after* children have registered theirs - // (this way the children will be fully set up before any config gets loaded) - FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientHandler::setup); - - MinecraftForge.EVENT_BUS.addListener(ClientHandler::onOutlineRender); - EyeMineClient.init(); - }); - } -} diff --git a/forge/src/main/java/com/specialeffect/eyemine/platform/forge/EyeMineConfigImpl.java b/forge/src/main/java/com/specialeffect/eyemine/platform/forge/EyeMineConfigImpl.java deleted file mode 100644 index eeb6f1ad..00000000 --- a/forge/src/main/java/com/specialeffect/eyemine/platform/forge/EyeMineConfigImpl.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.specialeffect.eyemine.platform.forge; - -import com.specialeffect.eyemine.config.EyeMineConfig; - -public class EyeMineConfigImpl { - public static boolean getDisableCustomNewWorld() { - return EyeMineConfig.disableCustomNewWorld.get(); - } - - public static void setCustomSpeedFactor(float speed) { - EyeMineConfig.customSpeedFactor.set((double) speed); - } - - public static boolean getUsingMouseEmulation() { - return EyeMineConfig.usingMouseEmulation.get(); - } - - public static boolean getAutoSelectTool() { - return EyeMineConfig.autoSelectTool.get(); - } - - public static boolean getAutoSelectSword() { - return EyeMineConfig.autoSelectSword.get(); - } - - public static int getRadiusChests() { - return EyeMineConfig.radiusChests.get(); - } - - public static int getTicksBetweenMining() { - return EyeMineConfig.ticksBetweenMining.get(); - } - - public static double getBowDrawTime() { - return EyeMineConfig.bowDrawTime.get(); - } - - public static float getFullscreenOverlayAlpha() { - return EyeMineConfig.fullscreenOverlayAlpha.get().floatValue(); - } - - public static int getIronsightsFovReduction() { - return EyeMineConfig.ironsightsFovReduction.get(); - } - - public static double getIronsightsSensitivityReduction() { - return EyeMineConfig.ironsightsSensitivityReduction.get().floatValue(); - } - - public static boolean getUseDwellForSingleUseItem() { - return EyeMineConfig.useDwellForSingleUseItem.get(); - } - - public static boolean getUseDwellForSingleMine() { - return EyeMineConfig.useDwellForSingleMine.get(); - } - - public static int getRadiusDoors() { - return EyeMineConfig.radiusDoors.get(); - } - - public static boolean getServerCompatibilityMode() { - return EyeMineConfig.serverCompatibilityMode.get(); - } - - public static int getFlyHeightManual() { - return EyeMineConfig.flyHeightManual.get(); - } - - public static int getFlyHeightAuto() { - return EyeMineConfig.flyHeightAuto.get(); - } - - public static boolean getDefaultDoAutoJump() { - return EyeMineConfig.defaultDoAutoJump.get(); - } - - public static boolean getDisableAutoJumpFixes() { - return EyeMineConfig.disableAutoJumpFixes.get(); - } - - public static boolean getMoveWhenMouseStationary() { - return EyeMineConfig.moveWhenMouseStationary.get(); - } - - public static boolean getSlowdownOnCorners() { - return EyeMineConfig.slowdownOnCorners.get(); - } - - public static int getWalkingSlowdownFilter() { - return EyeMineConfig.walkingSlowdownFilter.get(); - } - - public static boolean getAllowLadderDescent() { - return EyeMineConfig.allowLadderDescent.get(); - } - - public static float getCustomSpeedFactor() { - return EyeMineConfig.customSpeedFactor.get().floatValue(); - } - - public static float getBoatMaxTurnAtSpeed() { - return EyeMineConfig.boatMaxTurnAtSpeed.get().floatValue(); - } - - public static double getBoatSlowdown() { - return EyeMineConfig.boatSlowdown.get(); - } - - public static double getDwellTimeSeconds() { - return EyeMineConfig.dwellTimeSeconds.get(); - } - - public static double getDwellLockonTimeSeconds() { - return EyeMineConfig.dwellLockonTimeSeconds.get(); - } - - public static boolean getDwellShowWithTransparency() { - return EyeMineConfig.dwellShowWithTransparency.get(); - } - - public static boolean getDwellShowExpanding() { - return EyeMineConfig.dwellShowExpanding.get(); - } - - public static boolean getSlowdownOnAttack() { - return EyeMineConfig.slowdownOnAttack.get(); - } - - public static int getGazeIdleThreshold() { - return EyeMineConfig.gazeIdleThreshold.get(); - } -} diff --git a/forge/src/main/java/com/specialeffect/eyemine/platform/forge/InventoryConfigImpl.java b/forge/src/main/java/com/specialeffect/eyemine/platform/forge/InventoryConfigImpl.java deleted file mode 100644 index e38e55bf..00000000 --- a/forge/src/main/java/com/specialeffect/eyemine/platform/forge/InventoryConfigImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.specialeffect.eyemine.platform.forge; - -import com.inventory.config.InventoryConfig; - -public class InventoryConfigImpl { - public static int getKey0() { - return InventoryConfig.key0.get(); - } - - public static int getKey1() { - return InventoryConfig.key1.get(); - } - - public static int getKey2() { - return InventoryConfig.key2.get(); - } - - public static int getKey3() { - return InventoryConfig.key3.get(); - } - - public static int getKey4() { - return InventoryConfig.key4.get(); - } - - public static int getKey5() { - return InventoryConfig.key5.get(); - } - - public static int getKey6() { - return InventoryConfig.key6.get(); - } - - public static int getKey7() { - return InventoryConfig.key7.get(); - } - - public static int getKey8() { - return InventoryConfig.key8.get(); - } - - public static int getKey9() { - return InventoryConfig.key9.get(); - } - - public static int getKeySurvPrevTab() { - return InventoryConfig.keySurvPrevTab.get(); - } - - public static int getKeySurvNextTab() { - return InventoryConfig.keySurvNextTab.get(); - } - - public static int getKeySurvRecipes() { - return InventoryConfig.keySurvRecipes.get(); - } - - public static int getKeySurvCraftable() { - return InventoryConfig.keySurvCraftable.get(); - } - - public static int getkeySurvPrevPage() { - return InventoryConfig.keySurvPrevPage.get(); - } - - public static int getkeySurvNextPage() { - return InventoryConfig.keySurvNextPage.get(); - } - - public static int getKeySurvOutput() { - return InventoryConfig.keySurvOutput.get(); - } - - public static int getKeyPrev() { - return InventoryConfig.keyPrev.get(); - } - - public static int getKeyNext() { - return InventoryConfig.keyNext.get(); - } - - public static int getKeyNextItemRow() { - return InventoryConfig.keyNextItemRow.get(); - } - - public static int getKeyNextItemCol() { - return InventoryConfig.keyNextItemCol.get(); - } - - public static int getKeyScrollUp() { - return InventoryConfig.keyScrollUp.get(); - } - - public static int getKeyScrollDown() { - return InventoryConfig.keyScrollDown.get(); - } - - public static int getKeySearch() { - return InventoryConfig.keySearch.get(); - } - - public static int getKeyDrop() { - return InventoryConfig.keyDrop.get(); - } -} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml deleted file mode 100644 index 7cab7bea..00000000 --- a/forge/src/main/resources/META-INF/mods.toml +++ /dev/null @@ -1,42 +0,0 @@ -modLoader="javafml" -loaderVersion="[49,)" -issueTrackerURL="https://github.com/SpecialEffect/SpecialEffectMinecraftMods" -license="GPL-3.0" - -[[mods]] -modId="eyemine" -version="${version}" -displayName="EyeMine" -displayURL="https://www.specialeffect.org.uk/eyemine" -authors="Kirsty McNaught" -logoFile="eyemine_logo.png" -credits = "Written in collaboration with SpecialEffect" -description=''' -EyeMine by SpecialEffect allows you to play Minecraft using eye gaze. - -It is designed to work alongside the EyeMine gaze-controlled keyboard. - -For questions or support, contact eyemine@specialeffect.org.uk -''' - -[[dependencies.eyemine]] - modId="forge" - mandatory=true - versionRange="[49,)" - ordering="NONE" - side="CLIENT" -[[dependencies.eyemine]] - modId="minecraft" - mandatory=true - versionRange="[1.20.4,1.21]" - ordering="NONE" - side="CLIENT" - - - -[[dependencies.eyemine]] -modId = "architectury" -mandatory = true -versionRange = "[11.1.13,)" -ordering = "AFTER" -side = "BOTH" \ No newline at end of file diff --git a/forge/src/main/resources/eyemine_logo.png b/forge/src/main/resources/eyemine_logo.png deleted file mode 100644 index 1cadf8fc..00000000 Binary files a/forge/src/main/resources/eyemine_logo.png and /dev/null differ diff --git a/gradle.properties b/gradle.properties index 95641c23..55fc47f6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,26 @@ -org.gradle.jvmargs=-Xmx2048M +org.gradle.jvmargs=-Xmx4G org.gradle.daemon=false -minecraft_version=1.21.1 -enabled_platforms=fabric,neoforge +# Project +version=7.0.0 +group=com.specialeffect +java_version=25 -archives_base_name=eyemine -mod_version=6.0.2 -maven_group=com.specialeffect +# Common +minecraft_version=26.1.1 +mod_name=EyeMine +mod_author=Kirsty McNaught, Mrbysco +mod_id=eyemine +license=GPL-3.0 +credits=SpecialEffect +description=Eye gaze control for Minecraft +minecraft_version_range=[26.1, 26.2) +neo_form_version=26.1.1-1 -architectury_version=13.0.8 -cloth_config_version=15.0.140 -mod_menu_version=11.0.3 +# Fabric - https://fabricmc.net/develop/ +fabric_version=0.145.4+26.1.1 +fabric_loader_version=0.18.4 -fabric_loader_version=0.16.10 -fabric_api_version=0.115.0+1.21.1 - -forge_version=52.1.0 -neoforge_version=21.1.148 \ No newline at end of file +# NeoForge - https://projects.neoforged.net/neoforged/neoforge +neoforge_version=26.1.1.11-beta +neoforge_loader_version_range=[4,) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e6441136..d997cfc6 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 94113f20..c61a118f 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.11-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/neoforge/build.gradle b/neoforge/build.gradle index fa83b3fd..bfa4914f 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -1,92 +1,46 @@ plugins { - id "com.github.johnrengelman.shadow" version "8.1.1" + id 'multiloader-loader' + id 'net.neoforged.moddev' } -architectury { - platformSetupLoomIde() - neoForge() -} +def accessTransformerFile = project(':common').file("src/main/resources/META-INF/accesstransformer.cfg") -loom { - accessWidenerPath = project(":common").loom.accessWidenerPath +neoForge { + version = neoforge_version - neoForge { - runs { - all {} - } + if (accessTransformerFile.exists()) { + accessTransformers.from(accessTransformerFile) } -} - -configurations { - common - shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. - compileClasspath.extendsFrom common - runtimeClasspath.extendsFrom common - developmentNeoForge.extendsFrom common -} - -dependencies { - neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}" - - // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_version}" - common(project(path: ":common", configuration: "namedElements")) { transitive false } - shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false } - -// modCompileOnly("curse.maven:configured-457570:5105024") -} - -processResources { - inputs.property "version", project.version - - filesMatching("META-INF/neoforge.mods.toml") { - expand "version": project.version + mods { + "${mod_id}" { + sourceSet sourceSets.main + } } -} - -shadowJar { - exclude "fabric.mod.json" - exclude "eyemine.common.json" - configurations = [project.configurations.shadowCommon] - archiveClassifier.set("dev-shadow") -} - -remapJar { - input.set shadowJar.archiveFile - dependsOn shadowJar - archiveBaseName.set "${rootProject.archives_base_name}-${project.minecraft_version}-${project.name}" - archiveClassifier.set('') - atAccessWideners.add("${rootProject.archives_base_name}.accesswidener") // this is a path inside the mod jar -} - -jar { - archiveClassifier.set("dev") -} - -sourcesJar { - def commonSources = project(":common").sourcesJar - dependsOn commonSources - from commonSources.archiveFile.map { zipTree(it) } -} + runs { + client { + client() + ideName = 'NeoForge Client' + } -components.java { - withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - skip() - } -} + server { + server() + ideName = 'NeoForge Server' + } -publishing { - publications { - mavenNeoForge(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.name - from components.java + clientData { + clientData() + ideName = 'NeoForge Client Data' + programArguments.addAll("--mod=${mod_id}", "--output=${file("src/generated/resources").absolutePath}", "--existing=${file("src/main/resources").absolutePath}") } - } - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. + serverData { + serverData() + ideName = 'NeoForge Server Data' + programArguments.addAll("--mod=${mod_id}", "--output=${file("src/generated/resources").absolutePath}", "--existing=${file("src/main/resources").absolutePath}") + } } } + +sourceSets.main.resources.srcDir 'src/generated/resources' diff --git a/neoforge/src/main/java/com/specialeffect/eyemine/client/neoforge/ClientHandler.java b/neoforge/src/main/java/com/specialeffect/eyemine/client/neoforge/ClientHandler.java index 4cc8b34c..db227184 100644 --- a/neoforge/src/main/java/com/specialeffect/eyemine/client/neoforge/ClientHandler.java +++ b/neoforge/src/main/java/com/specialeffect/eyemine/client/neoforge/ClientHandler.java @@ -11,18 +11,118 @@ package com.specialeffect.eyemine.client.neoforge; +import com.specialeffect.eyemine.EyeMine; import com.specialeffect.eyemine.EyeMineClient; -import com.specialeffect.eyemine.event.BlockOutlineEvent; +import com.specialeffect.eyemine.event.EyeMineEvents; +import com.specialeffect.eyemine.event.EventResult; +import com.specialeffect.eyemine.event.ScreenSetResult; +import net.minecraft.client.Minecraft; +import net.minecraft.server.level.ServerLevel; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; -import net.neoforged.neoforge.client.event.RenderHighlightEvent; +import net.neoforged.neoforge.client.event.ClientTickEvent; +import net.neoforged.neoforge.client.event.InputEvent; +import net.neoforged.neoforge.client.event.RenderGuiLayerEvent; +import net.neoforged.neoforge.client.event.ScreenEvent; +import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent; +import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; +import net.neoforged.neoforge.event.level.LevelEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; +@EventBusSubscriber(modid = EyeMine.MOD_ID, value = Dist.CLIENT) public class ClientHandler { - public static void setup(final FMLCommonSetupEvent event) { - EyeMineClient.setupComplete = true; - EyeMineClient.refresh(); - } - - public static void onOutlineRender(RenderHighlightEvent.Block event) { - BlockOutlineEvent.OUTLINE.invoker().renderOutline(event.getMultiBufferSource(), event.getPoseStack()); - } + + @SubscribeEvent + public static void onClientTick(ClientTickEvent.Pre event) { + Minecraft mc = Minecraft.getInstance(); + for (var listener : EyeMineEvents.CLIENT_TICK.getListeners()) { + listener.onClientTick(mc); + } + } + + @SubscribeEvent + public static void onKeyInput(InputEvent.Key event) { + Minecraft mc = Minecraft.getInstance(); + for (var listener : EyeMineEvents.KEY_PRESSED.getListeners()) { + EventResult result = listener.onKeyPressed(mc, event.getKey(), event.getScanCode(), event.getAction(), event.getModifiers()); + if (result.isPresent()) break; + } + } + + @SubscribeEvent + public static void onScreenOpen(ScreenEvent.Opening event) { + for (var listener : EyeMineEvents.SCREEN_SET.getListeners()) { + ScreenSetResult result = listener.onScreenSet(event.getNewScreen()); + if (result.handled()) { + if (result.screen() != null) { + event.setNewScreen(result.screen()); + } + break; + } + } + } + + @SubscribeEvent + public static void onRenderHud(RenderGuiLayerEvent.Post event) { + for (var listener : EyeMineEvents.RENDER_HUD.getListeners()) { + listener.onRenderHud(event.getGuiGraphics(), event.getPartialTick()); + } + } + + @SubscribeEvent + public static void onBlockOutline(net.neoforged.neoforge.client.event.ExtractBlockOutlineRenderStateEvent event) { + if (!EyeMineEvents.BLOCK_OUTLINE.getListeners().isEmpty()) { + // Add a custom renderer that delegates to EyeMine's block outline listeners + event.addCustomRenderer((outlineState, bufferSource, poseStack, isTranslucent, levelRenderState) -> { + for (var listener : EyeMineEvents.BLOCK_OUTLINE.getListeners()) { + EventResult result = listener.renderOutline(bufferSource, poseStack); + if (result.isPresent()) return true; + } + return false; + }); + } + } + + @SubscribeEvent + public static void onLivingDeath(LivingDeathEvent event) { + for (var listener : EyeMineEvents.ENTITY_DEATH.getListeners()) { + EventResult result = listener.onDeath(event.getEntity(), event.getSource()); + if (result.isPresent()) break; + } + } + + @SubscribeEvent + public static void onEntityJoin(EntityJoinLevelEvent event) { + for (var listener : EyeMineEvents.ENTITY_ADD.getListeners()) { + EventResult result = listener.onAdd(event.getEntity(), event.getLevel()); + if (result.isPresent()) break; + } + } + + @SubscribeEvent + public static void onPlayerTick(PlayerTickEvent.Post event) { + for (var listener : EyeMineEvents.PLAYER_TICK.getListeners()) { + listener.onPlayerTick(event.getEntity()); + } + } + + @SubscribeEvent + public static void onWorldLoad(LevelEvent.Load event) { + if (event.getLevel() instanceof ServerLevel serverLevel) { + for (var listener : EyeMineEvents.WORLD_LOAD.getListeners()) { + listener.onWorldLoad(serverLevel); + } + } + } + + public static void onSetup(FMLCommonSetupEvent event) { + EyeMineClient.setupComplete = true; + EyeMineClient.refresh(); + Minecraft mc = Minecraft.getInstance(); + for (var listener : EyeMineEvents.CLIENT_SETUP.getListeners()) { + listener.onClientSetup(mc); + } + } } diff --git a/neoforge/src/main/java/com/specialeffect/eyemine/neoforge/EyeMineNeoForge.java b/neoforge/src/main/java/com/specialeffect/eyemine/neoforge/EyeMineNeoForge.java index 6d9473f1..95f2308c 100644 --- a/neoforge/src/main/java/com/specialeffect/eyemine/neoforge/EyeMineNeoForge.java +++ b/neoforge/src/main/java/com/specialeffect/eyemine/neoforge/EyeMineNeoForge.java @@ -3,38 +3,55 @@ import com.inventory.config.InventoryConfig; import com.specialeffect.eyemine.EyeMine; import com.specialeffect.eyemine.EyeMineClient; -import com.specialeffect.eyemine.client.neoforge.ClientHandler; +import com.specialeffect.eyemine.client.Keybindings; import com.specialeffect.eyemine.config.EyeMineConfig; +import com.specialeffect.eyemine.client.neoforge.ClientHandler; +import com.specialeffect.eyemine.platform.neoforge.NeoForgeNetworkService; +import net.minecraft.client.KeyMapping; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; import net.neoforged.fml.config.ModConfig; -import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; @Mod(EyeMine.MOD_ID) public class EyeMineNeoForge { - public EyeMineNeoForge(IEventBus eventBus, ModContainer container, Dist dist) { - // In NeoForge 1.21+, the event bus is passed directly to the constructor - // and Architectury automatically detects it via ModList.getModContainerById() - EyeMine.init(); - - if (dist.isClient()) { - // Config setup - container.registerConfig(ModConfig.Type.CLIENT, EyeMineConfig.CLIENT_CONFIG, "eyemine-config.toml"); - eventBus.register(EyeMineConfig.class); - container.registerConfig(ModConfig.Type.CLIENT, InventoryConfig.CLIENT_CONFIG, "eyemine-inventory-config.toml"); - eventBus.register(InventoryConfig.class); - - // Hook up config gui -// ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> ClientHandler::openSettings); - - // Register this setup method *after* children have registered theirs - // (this way the children will be fully set up before any config gets loaded) - eventBus.addListener(ClientHandler::setup); - - NeoForge.EVENT_BUS.addListener(ClientHandler::onOutlineRender); - EyeMineClient.init(); - } - } + public EyeMineNeoForge(IEventBus eventBus, ModContainer container, Dist dist) { + EyeMine.init(); + + eventBus.addListener(this::registerPayloads); + + if (dist.isClient()) { + container.registerConfig(ModConfig.Type.CLIENT, EyeMineConfig.CLIENT_CONFIG, "eyemine-config.toml"); + eventBus.register(EyeMineConfig.class); + container.registerConfig(ModConfig.Type.CLIENT, InventoryConfig.CLIENT_CONFIG, "eyemine-inventory-config.toml"); + eventBus.register(InventoryConfig.class); + + eventBus.addListener(this::registerKeyMappings); + eventBus.addListener(ClientHandler::onSetup); + + EyeMineClient.init(); + } + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private void registerPayloads(RegisterPayloadHandlersEvent event) { + PayloadRegistrar registrar = event.registrar(EyeMine.MOD_ID); + for (var entry : NeoForgeNetworkService.getPendingRegistrations().values()) { + registrar.playToServer( + entry.type(), + (net.minecraft.network.codec.StreamCodec) entry.codec(), + (payload, context) -> entry.handlePayload(payload, context) + ); + } + } + + private void registerKeyMappings(RegisterKeyMappingsEvent event) { + for (KeyMapping keyBinding : Keybindings.keybindings) { + event.register(keyBinding); + } + } } diff --git a/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/EyeMineConfigImpl.java b/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/EyeMineConfigImpl.java index 4bb05215..6af7e02f 100644 --- a/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/EyeMineConfigImpl.java +++ b/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/EyeMineConfigImpl.java @@ -1,133 +1,42 @@ package com.specialeffect.eyemine.platform.neoforge; import com.specialeffect.eyemine.config.EyeMineConfig; - -public class EyeMineConfigImpl { - public static boolean getDisableCustomNewWorld() { - return EyeMineConfig.disableCustomNewWorld.get(); - } - - public static void setCustomSpeedFactor(float speed) { - EyeMineConfig.customSpeedFactor.set((double) speed); - } - - public static boolean getUsingMouseEmulation() { - return EyeMineConfig.usingMouseEmulation.get(); - } - - public static boolean getAutoSelectTool() { - return EyeMineConfig.autoSelectTool.get(); - } - - public static boolean getAutoSelectSword() { - return EyeMineConfig.autoSelectSword.get(); - } - - public static int getRadiusChests() { - return EyeMineConfig.radiusChests.get(); - } - - public static int getTicksBetweenMining() { - return EyeMineConfig.ticksBetweenMining.get(); - } - - public static double getBowDrawTime() { - return EyeMineConfig.bowDrawTime.get(); - } - - public static float getFullscreenOverlayAlpha() { - return EyeMineConfig.fullscreenOverlayAlpha.get().floatValue(); - } - - public static int getIronsightsFovReduction() { - return EyeMineConfig.ironsightsFovReduction.get(); - } - - public static double getIronsightsSensitivityReduction() { - return EyeMineConfig.ironsightsSensitivityReduction.get().floatValue(); - } - - public static boolean getUseDwellForSingleUseItem() { - return EyeMineConfig.useDwellForSingleUseItem.get(); - } - - public static boolean getUseDwellForSingleMine() { - return EyeMineConfig.useDwellForSingleMine.get(); - } - - public static int getRadiusDoors() { - return EyeMineConfig.radiusDoors.get(); - } - - public static boolean getServerCompatibilityMode() { - return EyeMineConfig.serverCompatibilityMode.get(); - } - - public static int getFlyHeightManual() { - return EyeMineConfig.flyHeightManual.get(); - } - - public static int getFlyHeightAuto() { - return EyeMineConfig.flyHeightAuto.get(); - } - - public static boolean getDefaultDoAutoJump() { - return EyeMineConfig.defaultDoAutoJump.get(); - } - - public static boolean getDisableAutoJumpFixes() { - return EyeMineConfig.disableAutoJumpFixes.get(); - } - - public static boolean getMoveWhenMouseStationary() { - return EyeMineConfig.moveWhenMouseStationary.get(); - } - - public static boolean getSlowdownOnCorners() { - return EyeMineConfig.slowdownOnCorners.get(); - } - - public static int getWalkingSlowdownFilter() { - return EyeMineConfig.walkingSlowdownFilter.get(); - } - - public static boolean getAllowLadderDescent() { - return EyeMineConfig.allowLadderDescent.get(); - } - - public static float getCustomSpeedFactor() { - return EyeMineConfig.customSpeedFactor.get().floatValue(); - } - - public static float getBoatMaxTurnAtSpeed() { - return EyeMineConfig.boatMaxTurnAtSpeed.get().floatValue(); - } - - public static double getBoatSlowdown() { - return EyeMineConfig.boatSlowdown.get(); - } - - public static double getDwellTimeSeconds() { - return EyeMineConfig.dwellTimeSeconds.get(); - } - - public static double getDwellLockonTimeSeconds() { - return EyeMineConfig.dwellLockonTimeSeconds.get(); - } - - public static boolean getDwellShowWithTransparency() { - return EyeMineConfig.dwellShowWithTransparency.get(); - } - - public static boolean getDwellShowExpanding() { - return EyeMineConfig.dwellShowExpanding.get(); - } - - public static boolean getSlowdownOnAttack() { - return EyeMineConfig.slowdownOnAttack.get(); - } - - public static int getGazeIdleThreshold() { - return EyeMineConfig.gazeIdleThreshold.get(); - } +import com.specialeffect.eyemine.platform.services.IEyeMineConfigService; + +public class EyeMineConfigImpl implements IEyeMineConfigService { + @Override public boolean getDisableCustomNewWorld() { return EyeMineConfig.disableCustomNewWorld.get(); } + @Override public void setCustomSpeedFactor(float speed) { + EyeMineConfig.customSpeedFactor.set((double) speed); + EyeMineConfig.customSpeedFactor.save(); + } + @Override public boolean getUsingMouseEmulation() { return EyeMineConfig.usingMouseEmulation.get(); } + @Override public boolean getAutoSelectTool() { return EyeMineConfig.autoSelectTool.get(); } + @Override public boolean getAutoSelectSword() { return EyeMineConfig.autoSelectSword.get(); } + @Override public int getRadiusChests() { return EyeMineConfig.radiusChests.get(); } + @Override public int getTicksBetweenMining() { return EyeMineConfig.ticksBetweenMining.get(); } + @Override public double getBowDrawTime() { return EyeMineConfig.bowDrawTime.get(); } + @Override public float getFullscreenOverlayAlpha() { return EyeMineConfig.fullscreenOverlayAlpha.get().floatValue(); } + @Override public int getIronsightsFovReduction() { return EyeMineConfig.ironsightsFovReduction.get(); } + @Override public double getIronsightsSensitivityReduction() { return EyeMineConfig.ironsightsSensitivityReduction.get().floatValue(); } + @Override public boolean getUseDwellForSingleUseItem() { return EyeMineConfig.useDwellForSingleUseItem.get(); } + @Override public boolean getUseDwellForSingleMine() { return EyeMineConfig.useDwellForSingleMine.get(); } + @Override public int getRadiusDoors() { return EyeMineConfig.radiusDoors.get(); } + @Override public boolean getServerCompatibilityMode() { return EyeMineConfig.serverCompatibilityMode.get(); } + @Override public int getFlyHeightManual() { return EyeMineConfig.flyHeightManual.get(); } + @Override public int getFlyHeightAuto() { return EyeMineConfig.flyHeightAuto.get(); } + @Override public boolean getDefaultDoAutoJump() { return EyeMineConfig.defaultDoAutoJump.get(); } + @Override public boolean getDisableAutoJumpFixes() { return EyeMineConfig.disableAutoJumpFixes.get(); } + @Override public boolean getMoveWhenMouseStationary() { return EyeMineConfig.moveWhenMouseStationary.get(); } + @Override public boolean getSlowdownOnCorners() { return EyeMineConfig.slowdownOnCorners.get(); } + @Override public int getWalkingSlowdownFilter() { return EyeMineConfig.walkingSlowdownFilter.get(); } + @Override public boolean getAllowLadderDescent() { return EyeMineConfig.allowLadderDescent.get(); } + @Override public float getCustomSpeedFactor() { return EyeMineConfig.customSpeedFactor.get().floatValue(); } + @Override public float getBoatMaxTurnAtSpeed() { return EyeMineConfig.boatMaxTurnAtSpeed.get().floatValue(); } + @Override public double getBoatSlowdown() { return EyeMineConfig.boatSlowdown.get(); } + @Override public double getDwellTimeSeconds() { return EyeMineConfig.dwellTimeSeconds.get(); } + @Override public double getDwellLockonTimeSeconds() { return EyeMineConfig.dwellLockonTimeSeconds.get(); } + @Override public boolean getDwellShowWithTransparency() { return EyeMineConfig.dwellShowWithTransparency.get(); } + @Override public boolean getDwellShowExpanding() { return EyeMineConfig.dwellShowExpanding.get(); } + @Override public boolean getSlowdownOnAttack() { return EyeMineConfig.slowdownOnAttack.get(); } + @Override public int getGazeIdleThreshold() { return EyeMineConfig.gazeIdleThreshold.get(); } } diff --git a/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/InventoryConfigImpl.java b/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/InventoryConfigImpl.java index c950cfce..bdaf5938 100644 --- a/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/InventoryConfigImpl.java +++ b/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/InventoryConfigImpl.java @@ -1,105 +1,32 @@ package com.specialeffect.eyemine.platform.neoforge; import com.inventory.config.InventoryConfig; - -public class InventoryConfigImpl { - public static int getKey0() { - return InventoryConfig.key0.get(); - } - - public static int getKey1() { - return InventoryConfig.key1.get(); - } - - public static int getKey2() { - return InventoryConfig.key2.get(); - } - - public static int getKey3() { - return InventoryConfig.key3.get(); - } - - public static int getKey4() { - return InventoryConfig.key4.get(); - } - - public static int getKey5() { - return InventoryConfig.key5.get(); - } - - public static int getKey6() { - return InventoryConfig.key6.get(); - } - - public static int getKey7() { - return InventoryConfig.key7.get(); - } - - public static int getKey8() { - return InventoryConfig.key8.get(); - } - - public static int getKey9() { - return InventoryConfig.key9.get(); - } - - public static int getKeySurvPrevTab() { - return InventoryConfig.keySurvPrevTab.get(); - } - - public static int getKeySurvNextTab() { - return InventoryConfig.keySurvNextTab.get(); - } - - public static int getKeySurvRecipes() { - return InventoryConfig.keySurvRecipes.get(); - } - - public static int getKeySurvCraftable() { - return InventoryConfig.keySurvCraftable.get(); - } - - public static int getkeySurvPrevPage() { - return InventoryConfig.keySurvPrevPage.get(); - } - - public static int getkeySurvNextPage() { - return InventoryConfig.keySurvNextPage.get(); - } - - public static int getKeySurvOutput() { - return InventoryConfig.keySurvOutput.get(); - } - - public static int getKeyPrev() { - return InventoryConfig.keyPrev.get(); - } - - public static int getKeyNext() { - return InventoryConfig.keyNext.get(); - } - - public static int getKeyNextItemRow() { - return InventoryConfig.keyNextItemRow.get(); - } - - public static int getKeyNextItemCol() { - return InventoryConfig.keyNextItemCol.get(); - } - - public static int getKeyScrollUp() { - return InventoryConfig.keyScrollUp.get(); - } - - public static int getKeyScrollDown() { - return InventoryConfig.keyScrollDown.get(); - } - - public static int getKeySearch() { - return InventoryConfig.keySearch.get(); - } - - public static int getKeyDrop() { - return InventoryConfig.keyDrop.get(); - } +import com.specialeffect.eyemine.platform.services.IInventoryConfigService; + +public class InventoryConfigImpl implements IInventoryConfigService { + @Override public int getKey0() { return InventoryConfig.key0.get(); } + @Override public int getKey1() { return InventoryConfig.key1.get(); } + @Override public int getKey2() { return InventoryConfig.key2.get(); } + @Override public int getKey3() { return InventoryConfig.key3.get(); } + @Override public int getKey4() { return InventoryConfig.key4.get(); } + @Override public int getKey5() { return InventoryConfig.key5.get(); } + @Override public int getKey6() { return InventoryConfig.key6.get(); } + @Override public int getKey7() { return InventoryConfig.key7.get(); } + @Override public int getKey8() { return InventoryConfig.key8.get(); } + @Override public int getKey9() { return InventoryConfig.key9.get(); } + @Override public int getKeySurvPrevTab() { return InventoryConfig.keySurvPrevTab.get(); } + @Override public int getKeySurvNextTab() { return InventoryConfig.keySurvNextTab.get(); } + @Override public int getKeySurvRecipes() { return InventoryConfig.keySurvRecipes.get(); } + @Override public int getKeySurvCraftable() { return InventoryConfig.keySurvCraftable.get(); } + @Override public int getkeySurvPrevPage() { return InventoryConfig.keySurvPrevPage.get(); } + @Override public int getkeySurvNextPage() { return InventoryConfig.keySurvNextPage.get(); } + @Override public int getKeySurvOutput() { return InventoryConfig.keySurvOutput.get(); } + @Override public int getKeyPrev() { return InventoryConfig.keyPrev.get(); } + @Override public int getKeyNext() { return InventoryConfig.keyNext.get(); } + @Override public int getKeyNextItemRow() { return InventoryConfig.keyNextItemRow.get(); } + @Override public int getKeyNextItemCol() { return InventoryConfig.keyNextItemCol.get(); } + @Override public int getKeyScrollUp() { return InventoryConfig.keyScrollUp.get(); } + @Override public int getKeyScrollDown() { return InventoryConfig.keyScrollDown.get(); } + @Override public int getKeySearch() { return InventoryConfig.keySearch.get(); } + @Override public int getKeyDrop() { return InventoryConfig.keyDrop.get(); } } diff --git a/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/NeoForgeNetworkService.java b/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/NeoForgeNetworkService.java new file mode 100644 index 00000000..29e980bc --- /dev/null +++ b/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/NeoForgeNetworkService.java @@ -0,0 +1,57 @@ +package com.specialeffect.eyemine.platform.neoforge; + +import com.specialeffect.eyemine.packets.NetworkService; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.world.entity.player.Player; +import net.neoforged.neoforge.client.network.ClientPacketDistributor; +import net.neoforged.neoforge.network.handling.IPayloadContext; + +import java.util.HashMap; +import java.util.Map; + +public class NeoForgeNetworkService implements NetworkService { + private static final Map, RegistrationEntry> pendingRegistrations = new HashMap<>(); + + @SuppressWarnings("unchecked") + public record RegistrationEntry( + CustomPacketPayload.Type type, + StreamCodec codec, + PacketHandler handler) { + + public void handlePayload(CustomPacketPayload payload, IPayloadContext context) { + T typed = (T) payload; + handler.handle(typed, new NeoForgePacketContext(context)); + } + } + + @Override + public void registerC2S( + CustomPacketPayload.Type type, + StreamCodec codec, + PacketHandler handler) { + pendingRegistrations.put(type, new RegistrationEntry<>(type, codec, handler)); + } + + @Override + public void sendToServer(CustomPacketPayload payload) { + ClientPacketDistributor.sendToServer(payload); + } + + public static Map, RegistrationEntry> getPendingRegistrations() { + return pendingRegistrations; + } + + private record NeoForgePacketContext(IPayloadContext neoContext) implements PacketContext { + @Override + public void queue(Runnable work) { + neoContext.enqueueWork(work); + } + + @Override + public Player getPlayer() { + return neoContext.player(); + } + } +} diff --git a/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/NeoForgePlatformHelper.java b/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/NeoForgePlatformHelper.java new file mode 100644 index 00000000..f7107c9e --- /dev/null +++ b/neoforge/src/main/java/com/specialeffect/eyemine/platform/neoforge/NeoForgePlatformHelper.java @@ -0,0 +1,22 @@ +package com.specialeffect.eyemine.platform.neoforge; + +import com.specialeffect.eyemine.platform.services.IPlatformHelper; +import net.neoforged.fml.ModList; +import net.neoforged.fml.loading.FMLLoader; + +public class NeoForgePlatformHelper implements IPlatformHelper { + @Override + public String getPlatformName() { + return "NeoForge"; + } + + @Override + public boolean isModLoaded(String modId) { + return ModList.get().isLoaded(modId); + } + + @Override + public boolean isDevelopmentEnvironment() { + return !FMLLoader.getCurrent().isProduction(); + } +} diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 3cd4b4da..dc96e01f 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -1,44 +1,31 @@ modLoader="javafml" -loaderVersion="[4,)" +loaderVersion="${neoforge_loader_version_range}" issueTrackerURL="https://github.com/SpecialEffect/SpecialEffectMinecraftMods" -license="GPL-3.0" +license="${license}" [[mods]] -modId="eyemine" +modId="${mod_id}" version="${version}" -displayName="EyeMine" +displayName="${mod_name}" displayURL="https://www.specialeffect.org.uk/eyemine" -authors="Kirsty McNaught, Mrbysco" +authors="${mod_author}" logoFile="eyemine_logo.png" -credits = "Written in collaboration with SpecialEffect" -description=''' -EyeMine by SpecialEffect allows you to play Minecraft using eye gaze. +credits="${credits}" +description='''${description}''' -It is designed to work alongside the EyeMine gaze-controlled keyboard. +[[dependencies.${mod_id}]] +modId="neoforge" +type="required" +versionRange="[${neoforge_version},)" +ordering="NONE" +side="CLIENT" -For questions or support, contact eyemine@specialeffect.org.uk -''' +[[dependencies.${mod_id}]] +modId="minecraft" +type="required" +versionRange="${minecraft_version_range}" +ordering="NONE" +side="CLIENT" -[[dependencies.eyemine]] - modId="neoforge" - type="required" - versionRange="[21.0.0-beta,)" - ordering="NONE" - side="CLIENT" -[[dependencies.eyemine]] - modId="minecraft" - type="required" - versionRange="[1.21,1.22]" - ordering="NONE" - side="CLIENT" - - - -[[dependencies.eyemine]] -modId = "architectury" -type = "required" -versionRange = "[13.0.1,)" -ordering = "AFTER" -side = "BOTH" [[mixins]] -config = "eyemine-common.mixins.json" \ No newline at end of file +config="eyemine-common.mixins.json" diff --git a/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.packets.NetworkService b/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.packets.NetworkService new file mode 100644 index 00000000..f38169a2 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.packets.NetworkService @@ -0,0 +1 @@ +com.specialeffect.eyemine.platform.neoforge.NeoForgeNetworkService diff --git a/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IEyeMineConfigService b/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IEyeMineConfigService new file mode 100644 index 00000000..373a3b29 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IEyeMineConfigService @@ -0,0 +1 @@ +com.specialeffect.eyemine.platform.neoforge.EyeMineConfigImpl diff --git a/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IInventoryConfigService b/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IInventoryConfigService new file mode 100644 index 00000000..27e2377e --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IInventoryConfigService @@ -0,0 +1 @@ +com.specialeffect.eyemine.platform.neoforge.InventoryConfigImpl diff --git a/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IPlatformHelper b/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IPlatformHelper new file mode 100644 index 00000000..575be5a3 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/com.specialeffect.eyemine.platform.services.IPlatformHelper @@ -0,0 +1 @@ +com.specialeffect.eyemine.platform.neoforge.NeoForgePlatformHelper diff --git a/settings.gradle b/settings.gradle index d1f2954b..ba27ebf1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,17 +1,26 @@ pluginManagement { repositories { - maven { url "https://maven.fabricmc.net/" } - maven { url "https://maven.architectury.dev/" } - maven { url "https://maven.neoforged.net/releases/" } - maven { url "https://maven.minecraftforge.net/" } - mavenCentral() gradlePluginPortal() + mavenCentral() + exclusiveContent { + forRepository { + maven { + name = 'Fabric' + url = uri('https://maven.fabricmc.net') + } + } + filter { + includeGroupAndSubgroups('net.fabricmc') + } + } } } -include("common") -include("fabric") -include("neoforge") -//include("forge") +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' +} -rootProject.name = "architectury-eyemine" +rootProject.name = 'eyemine' +include('common') +include('fabric') +include('neoforge')