Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
plugins {
id 'fabric-loom' version '1.9-SNAPSHOT'
id 'fabric-loom' version '1.10-SNAPSHOT'
id 'maven-publish'
}

version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
}

allprojects {
apply plugin: "java"
apply plugin: "maven-publish"

archivesBaseName = rootProject.archives_base_name
version = rootProject.mod_version
group = rootProject.maven_group
}

repositories {
Expand All @@ -23,7 +28,6 @@ repositories {
name 'Xander Maven'
url 'https://maven.isxander.dev/releases'
}
maven { url "https://maven.terraformersmc.com/releases" }
}

dependencies {
Expand All @@ -38,14 +42,17 @@ dependencies {

processResources {
inputs.property "version", project.version
inputs.property "minecraft_version", project.minecraft_version
inputs.property "loader_version", project.loader_version
filteringCharset "UTF-8"
inputs.property "minecraft_version", project.minecraft_version
inputs.property "yacl_version", project.yacl_version

filesMatching("fabric.mod.json") {
expand "version": project.version,
"minecraft_version": project.minecraft_version,
"loader_version": project.loader_version
expand([
"version": inputs.properties.version,
"loader_version": inputs.properties.loader_version,
"minecraft_version": inputs.properties.minecraft_version,
"yacl_version": inputs.properties.yacl_version
])
}
}

Expand All @@ -65,8 +72,10 @@ java {
}

jar {
inputs.property "archivesName", project.base.archivesName

from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
rename { "${it}_${inputs.properties.archivesName}"}
}
}

Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.1
loader_version=0.16.9
minecraft_version=1.21.5
yarn_mappings=1.21.5+build.1
loader_version=0.16.10

# Mod Properties
# need versioning system
mod_version = 3.0.0
mod_version = 3.1.0
maven_group = com.tanishisherewith
archives_base_name = dynamichud

# Dependencies
fabric_version=0.111.0+1.21.4
yacl_version=3.6.6+1.21.4-fabric
fabric_version=0.119.5+1.21.5
yacl_version=3.6.6+1.21.5-fabric
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 21 additions & 14 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -83,10 +85,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +133,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +200,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down Expand Up @@ -241,4 +248,4 @@ eval "set -- $(
tr '\n' ' '
)" '"$@"'

exec "$JAVACMD" "$@"
exec "$JAVACMD" "$@"
24 changes: 13 additions & 11 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down Expand Up @@ -89,4 +91,4 @@ exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
:omega
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.config.GlobalConfig;
import com.tanishisherewith.dynamichud.helpers.MouseColorQuery;
import com.tanishisherewith.dynamichud.integration.IntegrationManager;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudLayerRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import org.slf4j.Logger;
Expand Down Expand Up @@ -35,6 +38,7 @@ public void onInitializeClient() {
IntegrationManager.integrate();

//In game screen render.
HudRenderCallback.EVENT.register(new HudRender());
HudLayerRegistrationCallback.EVENT.register(new HudRender());
ClientTickEvents.END_CLIENT_TICK.register(mc-> MouseColorQuery.processIfPending());
}
}
23 changes: 16 additions & 7 deletions src/main/java/com/tanishisherewith/dynamichud/HudRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@

import com.tanishisherewith.dynamichud.integration.IntegrationManager;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.HudLayerRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.client.rendering.v1.IdentifiedLayer;
import net.fabricmc.fabric.api.client.rendering.v1.LayeredDrawerWrapper;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.util.Identifier;

/**
* Using the fabric event {@link HudRenderCallback} to render widgets in the game HUD.
* Using the fabric event {@link HudLayerRegistrationCallback} to render widgets in the game HUD.
* Mouse positions are passed in the negatives even though theoretically it's in the centre of the screen.
*/
public class HudRender implements HudRenderCallback {

public class HudRender implements HudLayerRegistrationCallback {
@Override
public void onHudRender(DrawContext drawContext, RenderTickCounter tickCounter) {
for (WidgetRenderer widgetRenderer : IntegrationManager.getWidgetRenderers()) {
widgetRenderer.renderWidgets(drawContext, -120, -120);
}
public void register(LayeredDrawerWrapper layeredDrawer) {
layeredDrawer.attachLayerAfter(
IdentifiedLayer.MISC_OVERLAYS,
IdentifiedLayer.of(Identifier.of("dynamichud","hudrender_callback"),
(context, tickCounter) -> {
for (WidgetRenderer widgetRenderer : IntegrationManager.getWidgetRenderers()) {
widgetRenderer.renderWidgets(context, -120, -120);
}
})
);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.tanishisherewith.dynamichud.helpers;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.util.Window;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;

Expand Down Expand Up @@ -174,47 +176,8 @@ public static Color changeAlpha(Color color, int alpha) {
return new Color(0);
}

public static int[] getMousePixelColor(double mouseX, double mouseY) {
MinecraftClient client = MinecraftClient.getInstance();
Framebuffer framebuffer = client.getFramebuffer();
Window window = client.getWindow();

// Get the window and framebuffer dimensions
int windowWidth = window.getWidth();
int windowHeight = window.getHeight();
int framebufferWidth = framebuffer.textureWidth;
int framebufferHeight = framebuffer.textureHeight;

// Calculate scaling factors
double scaleX = (double) framebufferWidth / windowWidth;
double scaleY = (double) framebufferHeight / windowHeight;

// Convert mouse coordinates to framebuffer coordinates
int x = (int) (mouseX * scaleX);
int y = (int) ((windowHeight - mouseY) * scaleY);

// Ensure the coordinates are within the framebuffer bounds
if (x < 0 || x >= framebufferWidth || y < 0 || y >= framebufferHeight) {
System.err.println("Mouse coordinates are out of bounds");
return null;
}

// Allocate a buffer to store the pixel data
ByteBuffer buffer = ByteBuffer.allocateDirect(4); // 4 bytes for RGBA

// Bind the framebuffer for reading
GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, framebuffer.fbo);

// Read the pixel at the mouse position
GL11.glReadPixels(x, y, 1, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);

// Extract the color components from the buffer
int red = buffer.get(0) & 0xFF;
int green = buffer.get(1) & 0xFF;
int blue = buffer.get(2) & 0xFF;
int alpha = buffer.get(3) & 0xFF;

return new int[]{red, green, blue, alpha};
public static Color changeAlpha(int color, int alpha) {
return changeAlpha(new Color(color),alpha);
}

public static int fromRGBA(int r, int g, int b, int a) {
Expand Down
Loading