Initial Fabric 26.2 port

This commit is contained in:
Darto KLoning
2026-09-28 08:24:43 +07:00
commit 5a2d63c282
28 changed files with 983 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
# gradle
.gradle/
build/
out/
classes/
# eclipse
*.launch
# idea
.idea/
*.iml
*.ipr
*.iws
# vscode
.settings/
.vscode/
bin/
ChatGPT/
.classpath
.project
# macos
*.DS_Store
# fabric
run/
# java
hs_err_*.log
replay_*.log
*.hprof
*.jfr
.architectury-transformer/
+10
View File
@@ -0,0 +1,10 @@
# Item Despawn Timer — Fabric 26.2 port
This branch is Fabric-only and intentionally separates authority:
* `config/item-despawn-timer-server.json` — server gameplay: default despawn time and per-item overrides. `-1` means infinite when enabled.
* `config/item-despawn-timer-client.json` — client presentation only: timer/name visibility, heights, threshold and colors.
Minecraft 26.2 uses the unobfuscated Mojang/official names and Java 25. This port therefore does not reuse the old Yarn-named common/client GUI classes from 0.2.2. Client rendering lives only in `src/client`, while server/gameplay code lives in `src/main`.
Run `compiler.bat` on Windows or `./compiler.sh` on Linux/macOS. The script checks whether the existing JAR contains the same `mod_version+mc<minecraft_version>` as `gradle.properties`; matching builds offer Push/Recompile/Quit. After a successful build it offers Git push and retries failed pushes in groups of three.
+15
View File
@@ -0,0 +1,15 @@
plugins { id 'net.fabricmc.fabric-loom' version '1.17-SNAPSHOT'; id 'maven-publish' }
version = project.mod_version + "+mc" + project.minecraft_version
group = project.maven_group
base { archivesName = project.archives_base_name }
loom { splitEnvironmentSourceSets(); mods { "item-despawn-timer" { sourceSet sourceSets.main; sourceSet sourceSets.client } } }
repositories { mavenCentral(); maven { url = 'https://maven.fabricmc.net/' } }
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
implementation "net.fabricmc:fabric-loader:${project.loader_version}"
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}
processResources { inputs.property 'version', project.version; filesMatching('fabric.mod.json') { expand version: project.version } }
tasks.withType(JavaCompile).configureEach { options.release = 25 }
java { withSourcesJar(); sourceCompatibility = JavaVersion.VERSION_25; targetCompatibility = JavaVersion.VERSION_25 }
+211
View File
@@ -0,0 +1,211 @@
@echo off
setlocal EnableExtensions EnableDelayedExpansion
cd /d "%~dp0"
set "BUILD_ONLY=0"
if /I "%~1"=="--build-only" set "BUILD_ONLY=1"
if not exist "gradle.properties" (
echo [ERROR] gradle.properties tidak ditemukan.
goto :failed
)
for /f "tokens=1,* delims==" %%A in (gradle.properties) do (
if "%%A"=="mod_version" set "MOD_VERSION=%%B"
if "%%A"=="minecraft_version" set "MC_VERSION=%%B"
if "%%A"=="archives_base_name" set "ARCHIVES_BASE_NAME=%%B"
)
if not defined MOD_VERSION goto :properties_failed
if not defined MC_VERSION goto :properties_failed
if not defined ARCHIVES_BASE_NAME set "ARCHIVES_BASE_NAME=item-despawn-timer"
set "PROJECT_VERSION=%MOD_VERSION%+mc%MC_VERSION%"
set "JAR_PATH=%CD%\build\libs\%ARCHIVES_BASE_NAME%-%PROJECT_VERSION%.jar"
set "GIT_ONLY=0"
echo ============================================
echo Item Despawn Timer - Fabric %MC_VERSION%
echo Version: %PROJECT_VERSION%
echo ============================================
REM Nama JAR Gradle berasal langsung dari gradle.properties/build.gradle.
REM Jadi jika JAR versi saat ini sudah ada, jangan compile otomatis.
if "%BUILD_ONLY%"=="0" if exist "%JAR_PATH%" (
echo.
echo [INFO] Build untuk versi %PROJECT_VERSION% sudah tersedia:
echo %JAR_PATH%
echo.
choice /C CGQ /N /M "[C] Compile ulang / [G] Git saja / [Q] Keluar: "
if errorlevel 3 exit /b 0
if errorlevel 2 (
set "GIT_ONLY=1"
goto :git_integration
)
)
call :check_java
if errorlevel 1 goto :failed
echo.
echo [INFO] Menjalankan clean build...
call gradlew.bat clean build
if errorlevel 1 goto :build_failed
if not exist "%JAR_PATH%" (
echo.
echo [ERROR] Gradle selesai tanpa error, tetapi JAR yang diharapkan tidak ditemukan:
echo %JAR_PATH%
echo [INFO] Isi build\libs:
dir /b build\libs\*.jar 2>nul
goto :failed
)
echo.
echo ============================================
echo BUILD SUCCESS
echo ============================================
echo JAR: %JAR_PATH%
if "%BUILD_ONLY%"=="1" exit /b 0
echo.
choice /C YN /N /M "Commit dan push perubahan ke Git? [Y/N]: "
if errorlevel 2 goto :success
:git_integration
echo.
echo ============================================
echo Git Integration
echo ============================================
if "%GIT_ONLY%"=="1" echo [INFO] Build dilewati karena JAR %PROJECT_VERSION% sudah tersedia.
where git.exe >nul 2>&1
if errorlevel 1 (
echo [ERROR] Git tidak ditemukan di PATH.
goto :git_failed
)
git rev-parse --is-inside-work-tree >nul 2>&1
if errorlevel 1 (
echo [ERROR] Folder ini bukan Git repository.
goto :git_failed
)
set "HAS_CHANGES="
for /f "delims=" %%G in ('git status --porcelain') do set "HAS_CHANGES=1"
if defined HAS_CHANGES (
echo.
git status --short
echo.
set "DEFAULT_MSG=Update Item Despawn Timer v%PROJECT_VERSION%"
set "COMMIT_MESSAGE="
set /p "COMMIT_MESSAGE=Commit message [!DEFAULT_MSG!]: "
if not defined COMMIT_MESSAGE set "COMMIT_MESSAGE=!DEFAULT_MSG!"
git add -A
if errorlevel 1 goto :git_failed
git commit -m "!COMMIT_MESSAGE!"
if errorlevel 1 goto :git_failed
) else (
echo [INFO] Tidak ada perubahan source untuk di-commit.
)
for /f "delims=" %%B in ('git branch --show-current') do set "CURRENT_BRANCH=%%B"
if not defined CURRENT_BRANCH (
echo [ERROR] Branch aktif tidak dapat ditentukan.
goto :git_failed
)
git remote get-url origin >nul 2>&1
if errorlevel 1 (
echo [ERROR] Remote 'origin' belum dikonfigurasi.
goto :git_failed
)
call :push_with_retry
if errorlevel 1 goto :git_failed
echo.
echo [SUCCESS] Git push berhasil.
goto :success
:check_java
where java.exe >nul 2>&1
if errorlevel 1 (
echo [ERROR] Java tidak ditemukan di PATH.
exit /b 1
)
set "JAVA_MAJOR="
for /f "tokens=2" %%V in ('java --version 2^>^&1 ^| findstr /R /C:"^openjdk " /C:"^java "') do (
if not defined JAVA_VERSION set "JAVA_VERSION=%%V"
)
if not defined JAVA_VERSION (
echo [ERROR] Versi Java tidak dapat dibaca.
exit /b 1
)
for /f "tokens=1 delims=." %%M in ("%JAVA_VERSION%") do set "JAVA_MAJOR=%%M"
if %JAVA_MAJOR% LSS 25 (
echo [ERROR] Minecraft 26.2 memerlukan Java 25+. Terdeteksi: %JAVA_VERSION%
exit /b 1
)
echo [OK] Java %JAVA_VERSION%
exit /b 0
:push_with_retry
set /a PUSH_ROUND=1
:push_round
set /a PUSH_ATTEMPT=1
:push_try
echo [INFO] Push attempt !PUSH_ATTEMPT!/3 ^(round !PUSH_ROUND!^)...
git push origin "!CURRENT_BRANCH!"
if not errorlevel 1 exit /b 0
if !PUSH_ATTEMPT! LSS 3 (
set /a PUSH_ATTEMPT+=1
timeout /t 2 /nobreak >nul
goto :push_try
)
echo.
choice /C YN /N /M "Push gagal 3x. Coba 3x lagi? [Y/N]: "
if errorlevel 2 exit /b 1
set /a PUSH_ROUND+=1
goto :push_round
:properties_failed
echo [ERROR] mod_version atau minecraft_version tidak ditemukan di gradle.properties.
goto :failed
:build_failed
echo.
echo ============================================
echo BUILD FAILED
echo ============================================
if "%BUILD_ONLY%"=="1" exit /b 1
pause
exit /b 1
:git_failed
echo.
echo ============================================
echo GIT FAILED
echo ============================================
echo [INFO] Build/JAR yang sudah ada tetap aman.
pause
exit /b 2
:success
echo.
echo ============================================
echo Item Despawn Timer %PROJECT_VERSION% selesai.
echo ============================================
pause
exit /b 0
:failed
echo.
echo [ERROR] Proses dihentikan.
if "%BUILD_ONLY%"=="1" exit /b 1
pause
exit /b 1
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/env bash
set -u
cd "$(dirname "$0")" || exit 1
BUILD_ONLY=0
[[ "${1:-}" == "--build-only" ]] && BUILD_ONLY=1
prop() { sed -n "s/^$1=//p" gradle.properties | tail -n 1 | tr -d '\r'; }
[[ -f gradle.properties ]] || { echo "[ERROR] gradle.properties tidak ditemukan."; exit 1; }
MOD_VERSION="$(prop mod_version)"
MC_VERSION="$(prop minecraft_version)"
ARCHIVES_BASE_NAME="$(prop archives_base_name)"
ARCHIVES_BASE_NAME="${ARCHIVES_BASE_NAME:-item-despawn-timer}"
[[ -n "$MOD_VERSION" && -n "$MC_VERSION" ]] || { echo "[ERROR] Versi tidak lengkap di gradle.properties."; exit 1; }
PROJECT_VERSION="${MOD_VERSION}+mc${MC_VERSION}"
JAR_PATH="$PWD/build/libs/${ARCHIVES_BASE_NAME}-${PROJECT_VERSION}.jar"
echo "============================================"
echo " Item Despawn Timer - Fabric $MC_VERSION"
echo " Version: $PROJECT_VERSION"
echo "============================================"
git_integration() {
command -v git >/dev/null || { echo "[ERROR] Git tidak ditemukan."; return 2; }
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || { echo "[ERROR] Bukan Git repository."; return 2; }
if [[ -n "$(git status --porcelain)" ]]; then
git status --short
default="Update Item Despawn Timer v$PROJECT_VERSION"
read -r -p "Commit message [$default]: " msg
msg="${msg:-$default}"
git add -A || return 2
git commit -m "$msg" || return 2
else
echo "[INFO] Tidak ada perubahan source untuk di-commit."
fi
branch="$(git branch --show-current)"
[[ -n "$branch" ]] || { echo "[ERROR] Branch aktif tidak ditemukan."; return 2; }
git remote get-url origin >/dev/null 2>&1 || { echo "[ERROR] Remote origin belum dikonfigurasi."; return 2; }
local round=1
while true; do
local attempt=1
while (( attempt <= 3 )); do
echo "[INFO] Push attempt $attempt/3 (round $round)..."
git push origin "$branch" && return 0
((attempt++))
(( attempt <= 3 )) && sleep 2
done
read -r -p "Push gagal 3x. Coba 3x lagi? [y/N]: " again
[[ "$again" =~ ^[Yy]$ ]] || return 2
((round++))
done
}
if (( BUILD_ONLY == 0 )) && [[ -f "$JAR_PATH" ]]; then
echo
echo "[INFO] Build untuk versi $PROJECT_VERSION sudah tersedia:"
echo " $JAR_PATH"
while true; do
read -r -p "[C] Compile ulang / [G] Git saja / [Q] Keluar: " action
case "$action" in
C|c) break ;;
G|g) git_integration; exit $? ;;
Q|q) exit 0 ;;
esac
done
fi
command -v java >/dev/null || { echo "[ERROR] Java tidak ditemukan."; exit 1; }
JAVA_MAJOR="$(java --version 2>&1 | head -n1 | sed -E 's/.* ([0-9]+)(\..*)? .*/\1/')"
[[ "$JAVA_MAJOR" =~ ^[0-9]+$ ]] && (( JAVA_MAJOR >= 25 )) || { echo "[ERROR] Java 25+ diperlukan."; exit 1; }
chmod +x gradlew 2>/dev/null || true
./gradlew clean build || { echo "[ERROR] Build gagal."; exit 1; }
[[ -f "$JAR_PATH" ]] || {
echo "[ERROR] Build selesai tetapi JAR yang diharapkan tidak ditemukan:"
echo " $JAR_PATH"
ls -1 build/libs/*.jar 2>/dev/null || true
exit 1
}
echo
echo "BUILD SUCCESS"
echo "JAR: $JAR_PATH"
(( BUILD_ONLY == 1 )) && exit 0
read -r -p "Commit dan push perubahan ke Git? [y/N]: " push
[[ "$push" =~ ^[Yy]$ ]] && git_integration
exit $?
+1
View File
@@ -0,0 +1 @@
{"timerVisible":true,"nameVisible":false,"timerLabelHeight":0.75,"nameLabelHeight":1.1,"useTimerVisibilityThreshold":false,"timerVisibilityThresholdSeconds":300,"timerTextColor":"#FFFFFF","nameTextColor":"#FFFFFF","backgroundAlpha":64}
+1
View File
@@ -0,0 +1 @@
{"defaultDespawnSeconds":300,"allowInfiniteLifetime":true,"itemDespawnSeconds":{"minecraft:diamond":600,"minecraft:nether_star":-1}}
+8
View File
@@ -0,0 +1,8 @@
org.gradle.jvmargs=-Xmx2G
org.gradle.configuration-cache=false
minecraft_version=26.2
loader_version=0.19.3
fabric_version=0.160.0+26.2
mod_version=0.3.1
maven_group=whirlfrenzy.itemdespawntimer
archives_base_name=item-despawn-timer
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+249
View File
@@ -0,0 +1,249 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# 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
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# 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" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
Vendored
+92
View File
@@ -0,0 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
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.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
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.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+2
View File
@@ -0,0 +1,2 @@
pluginManagement { repositories { maven { url = 'https://maven.fabricmc.net/' }; gradlePluginPortal() } }
rootProject.name = 'item-despawn-timer-fabric-26.2'
@@ -0,0 +1,8 @@
package whirlfrenzy.itemdespawntimer.client;
import com.google.gson.*; import net.fabricmc.loader.api.FabricLoader; import java.io.*; import java.nio.file.*;
public final class ClientConfig {
private static final Gson GSON=new GsonBuilder().setPrettyPrinting().create(); public static Data data=new Data();
public static final class Data { public boolean timerVisible=true; public boolean nameVisible=false; public float timerLabelHeight=0.75f; public float nameLabelHeight=1.1f; public boolean useTimerVisibilityThreshold=false; public int timerVisibilityThresholdSeconds=300; public String timerTextColor="#FFFFFF"; public String nameTextColor="#FFFFFF"; public int backgroundAlpha=64; }
public static void load(){ Path p=FabricLoader.getInstance().getConfigDir().resolve("item-despawn-timer-client.json"); try{if(Files.exists(p)){try(Reader r=Files.newBufferedReader(p)){Data d=GSON.fromJson(r,Data.class);if(d!=null)data=d;}}else{try(Writer w=Files.newBufferedWriter(p)){GSON.toJson(data,w);}}}catch(Exception ignored){}}
public static int color(String s){try{return 0xFF000000|Integer.parseInt(s.replace("#",""),16);}catch(Exception e){return 0xFFFFFFFF;}}
}
@@ -0,0 +1,3 @@
package whirlfrenzy.itemdespawntimer.client;
import java.util.concurrent.ConcurrentHashMap;
public final class ClientTimerData { public record Timer(int age,int lifespan,long receivedAtMs){} private static final ConcurrentHashMap<Integer,Timer> DATA=new ConcurrentHashMap<>(); public static void put(int id,int age,int life){DATA.put(id,new Timer(age,life,System.currentTimeMillis()));} public static Timer get(int id){return DATA.get(id);} }
@@ -0,0 +1,3 @@
package whirlfrenzy.itemdespawntimer.client;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import whirlfrenzy.itemdespawntimer.network.TimerSyncPayload;
public final class ItemDespawnTimerClient implements ClientModInitializer { @Override public void onInitializeClient(){ ClientConfig.load(); ClientPlayNetworking.registerGlobalReceiver(TimerSyncPayload.TYPE,(p,c)->ClientTimerData.put(p.entityId(),p.age(),p.lifespan())); } }
@@ -0,0 +1,2 @@
package whirlfrenzy.itemdespawntimer.client;
public interface TimerRenderStateAccess { void itemDespawnTimer$set(int entityId,String name); int itemDespawnTimer$id(); String itemDespawnTimer$name(); }
@@ -0,0 +1,3 @@
package whirlfrenzy.itemdespawntimer.mixin.client;
import net.minecraft.client.renderer.entity.state.ItemEntityRenderState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import whirlfrenzy.itemdespawntimer.client.TimerRenderStateAccess;
@Mixin(ItemEntityRenderState.class) public class ItemEntityRenderStateMixin implements TimerRenderStateAccess { @Unique private int itemDespawnTimer$id=-1; @Unique private String itemDespawnTimer$name=""; public void itemDespawnTimer$set(int id,String name){this.itemDespawnTimer$id=id;this.itemDespawnTimer$name=name;} public int itemDespawnTimer$id(){return itemDespawnTimer$id;} public String itemDespawnTimer$name(){return itemDespawnTimer$name;} }
@@ -0,0 +1,31 @@
package whirlfrenzy.itemdespawntimer.mixin.client;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.entity.ItemEntityRenderer;
import net.minecraft.client.renderer.state.level.CameraRenderState;
import net.minecraft.client.renderer.entity.state.ItemEntityRenderState;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.item.ItemEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import whirlfrenzy.itemdespawntimer.client.*;
@Mixin(ItemEntityRenderer.class)
public abstract class ItemEntityRendererMixin {
@Inject(method="extractRenderState", at=@At("TAIL"))
private void itemDespawnTimer$extract(ItemEntity entity, ItemEntityRenderState state, float partialTick, CallbackInfo ci){ ((TimerRenderStateAccess)(Object)state).itemDespawnTimer$set(entity.getId(),entity.getItem().getHoverName().getString()); }
@Inject(method="submit", at=@At("TAIL"))
private void itemDespawnTimer$submit(ItemEntityRenderState state, PoseStack pose, SubmitNodeCollector queue, CameraRenderState camera, CallbackInfo ci){
TimerRenderStateAccess ext=(TimerRenderStateAccess)(Object)state; ClientTimerData.Timer timer=ClientTimerData.get(ext.itemDespawnTimer$id()); if(timer==null)return;
long elapsed=Math.max(0,System.currentTimeMillis()-timer.receivedAtMs()); int age=timer.age()+(int)(elapsed/50L); int remainTicks=timer.lifespan()==Integer.MAX_VALUE?Integer.MAX_VALUE:Math.max(0,timer.lifespan()-age); int seconds=remainTicks==Integer.MAX_VALUE?Integer.MAX_VALUE:(remainTicks+19)/20;
var cfg=ClientConfig.data; var font=Minecraft.getInstance().font;
if(cfg.timerVisible && (!cfg.useTimerVisibilityThreshold || seconds<=cfg.timerVisibilityThresholdSeconds)){
String s=seconds==Integer.MAX_VALUE?"∞":"◷ "+seconds+"s"; float w=font.width(s); pose.pushPose(); pose.translate(0,cfg.timerLabelHeight,0); pose.mulPose(camera.orientation); pose.scale(0.025f,-0.025f,0.025f); queue.submitText(pose,-w/2f,0,Component.literal(s).getVisualOrderText(),false,net.minecraft.client.gui.Font.DisplayMode.SEE_THROUGH,state.lightCoords,ClientConfig.color(cfg.timerTextColor),(cfg.backgroundAlpha&255)<<24,0); pose.popPose();
}
if(cfg.nameVisible){String s=ext.itemDespawnTimer$name();float w=font.width(s);pose.pushPose();pose.translate(0,cfg.nameLabelHeight,0);pose.mulPose(camera.orientation);pose.scale(0.025f,-0.025f,0.025f);queue.submitText(pose,-w/2f,0,Component.literal(s).getVisualOrderText(),false,net.minecraft.client.gui.Font.DisplayMode.SEE_THROUGH,state.lightCoords,ClientConfig.color(cfg.nameTextColor),(cfg.backgroundAlpha&255)<<24,0);pose.popPose();}
}
}
@@ -0,0 +1 @@
{"required":true,"package":"whirlfrenzy.itemdespawntimer.mixin.client","compatibilityLevel":"JAVA_25","client":["ItemEntityRendererMixin","ItemEntityRenderStateMixin"],"injectors":{"defaultRequire":1}}
@@ -0,0 +1,19 @@
package whirlfrenzy.itemdespawntimer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.minecraft.resources.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import whirlfrenzy.itemdespawntimer.config.ServerConfig;
import whirlfrenzy.itemdespawntimer.network.TimerSyncPayload;
public final class ItemDespawnTimer implements ModInitializer {
public static final String MOD_ID = "item-despawn-timer";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static Identifier id(String path) { return Identifier.fromNamespaceAndPath(MOD_ID, path); }
@Override public void onInitialize() {
ServerConfig.load();
PayloadTypeRegistry.clientboundPlay().register(TimerSyncPayload.TYPE, TimerSyncPayload.CODEC);
}
}
@@ -0,0 +1,33 @@
package whirlfrenzy.itemdespawntimer.config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.item.ItemEntity;
import whirlfrenzy.itemdespawntimer.ItemDespawnTimer;
import java.io.*; import java.nio.file.*; import java.util.*;
public final class ServerConfig {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static Data data = new Data();
public static final class Data {
public int defaultDespawnSeconds = 300;
public boolean allowInfiniteLifetime = true;
public Map<String,Integer> itemDespawnSeconds = new LinkedHashMap<>();
}
private ServerConfig() {}
public static void load() {
Path p = FabricLoader.getInstance().getConfigDir().resolve("item-despawn-timer-server.json");
try {
if (Files.exists(p)) { try (Reader r=Files.newBufferedReader(p)) { Data d=GSON.fromJson(r,Data.class); if(d!=null)data=d; } }
else { Files.createDirectories(p.getParent()); try(Writer w=Files.newBufferedWriter(p)){GSON.toJson(data,w);} }
} catch(Exception e){ ItemDespawnTimer.LOGGER.error("Cannot load server config",e); }
}
public static int lifespanTicks(ItemEntity entity) {
String id = BuiltInRegistries.ITEM.getKey(entity.getItem().getItem()).toString();
int seconds = data.itemDespawnSeconds.getOrDefault(id, data.defaultDespawnSeconds);
if (seconds < 0 && data.allowInfiniteLifetime) return Integer.MAX_VALUE;
return Math.max(1, seconds) * 20;
}
}
@@ -0,0 +1,32 @@
package whirlfrenzy.itemdespawntimer.mixin;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.item.ItemEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import whirlfrenzy.itemdespawntimer.config.ServerConfig;
import whirlfrenzy.itemdespawntimer.network.TimerSyncPayload;
@Mixin(ItemEntity.class)
public abstract class ItemEntityMixin {
@Shadow private int age;
@ModifyConstant(method="tick", constant=@Constant(intValue=6000))
private int itemDespawnTimer$serverLifetime(int vanillaLifetime) {
return ServerConfig.lifespanTicks((ItemEntity)(Object)this);
}
@Inject(method="tick", at=@At("TAIL"))
private void itemDespawnTimer$syncTimer(CallbackInfo ci) {
ItemEntity self=(ItemEntity)(Object)this;
if (!self.level().isClientSide() && (self.tickCount % 20 == 0 || self.tickCount < 3)) {
int lifespan=ServerConfig.lifespanTicks(self);
TimerSyncPayload payload=new TimerSyncPayload(self.getId(), this.age, lifespan);
for (ServerPlayer player : PlayerLookup.tracking(self)) ServerPlayNetworking.send(player,payload);
}
}
}
@@ -0,0 +1,17 @@
package whirlfrenzy.itemdespawntimer.network;
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 whirlfrenzy.itemdespawntimer.ItemDespawnTimer;
public record TimerSyncPayload(int entityId, int age, int lifespan) implements CustomPacketPayload {
public static final Type<TimerSyncPayload> TYPE = new Type<>(ItemDespawnTimer.id("timer_sync"));
public static final StreamCodec<RegistryFriendlyByteBuf, TimerSyncPayload> CODEC = StreamCodec.composite(
ByteBufCodecs.VAR_INT, TimerSyncPayload::entityId,
ByteBufCodecs.VAR_INT, TimerSyncPayload::age,
ByteBufCodecs.VAR_INT, TimerSyncPayload::lifespan,
TimerSyncPayload::new);
@Override public Type<? extends CustomPacketPayload> type() { return TYPE; }
}
+17
View File
@@ -0,0 +1,17 @@
{
"schemaVersion": 1,
"id": "item-despawn-timer",
"version": "${version}",
"name": "Item Despawn Timer",
"description": "Server-authoritative item despawn times with client-only countdown presentation settings.",
"environment": "*",
"entrypoints": {
"main": ["whirlfrenzy.itemdespawntimer.ItemDespawnTimer"],
"client": ["whirlfrenzy.itemdespawntimer.client.ItemDespawnTimerClient"]
},
"mixins": [
"item-despawn-timer.mixins.json",
{ "config": "item-despawn-timer.client.mixins.json", "environment": "client" }
],
"depends": { "fabricloader": ">=0.19.3", "minecraft": "~26.2", "java": ">=25", "fabric-api": "*" }
}
@@ -0,0 +1 @@
{"required":true,"package":"whirlfrenzy.itemdespawntimer.mixin","compatibilityLevel":"JAVA_25","mixins":["ItemEntityMixin"],"injectors":{"defaultRequire":1}}
+39
View File
@@ -0,0 +1,39 @@
@echo off
setlocal EnableExtensions
cd /d "%~dp0"
echo ============================================
echo Item Despawn Timer - Fabric Test
echo ============================================
echo [C] Run Minecraft Client
echo [S] Run Dedicated Server
echo [Q] Keluar
echo.
choice /C CSQ /N /M "Pilih test: "
if errorlevel 3 exit /b 0
if errorlevel 2 goto :server
:client
echo.
echo [INFO] Menjalankan Fabric development client...
call gradlew.bat runClient
goto :result
:server
echo.
echo [INFO] Menjalankan Fabric development server...
echo [INFO] Pada run pertama, jika server berhenti karena EULA,
echo buka run\eula.txt, ubah eula=true, lalu jalankan test.bat lagi.
call gradlew.bat runServer
:result
if errorlevel 1 (
echo.
echo [ERROR] Test gagal / Minecraft keluar dengan error.
pause
exit /b 1
)
echo.
echo [OK] Test session selesai tanpa Gradle error.
pause
exit /b 0
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -u
cd "$(dirname "$0")" || exit 1
chmod +x gradlew 2>/dev/null || true
echo "============================================"
echo " Item Despawn Timer - Fabric Test"
echo "============================================"
echo "[C] Run Minecraft Client"
echo "[S] Run Dedicated Server"
echo "[Q] Keluar"
read -r -p "Pilih test: " action
case "$action" in
C|c)
echo "[INFO] Menjalankan Fabric development client..."
./gradlew runClient
;;
S|s)
echo "[INFO] Menjalankan Fabric development server..."
echo "[INFO] Jika run pertama berhenti karena EULA, ubah run/eula.txt menjadi eula=true lalu jalankan lagi."
./gradlew runServer
;;
Q|q)
exit 0
;;
*)
echo "[ERROR] Pilihan tidak dikenal."
exit 2
;;
esac
rc=$?
if (( rc != 0 )); then
echo "[ERROR] Test gagal / Minecraft keluar dengan error."
exit "$rc"
fi
echo "[OK] Test session selesai tanpa Gradle error."