HD skins and animated GIF capes for NeoForge 1.21.1
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
# Disable autocrlf on generated files, they always generate with LF
|
||||||
|
# Add any extra files or paths here to make git stop saying they
|
||||||
|
# are changed when only line endings change.
|
||||||
|
src/generated/**/.cache/cache text eol=lf
|
||||||
|
src/generated/**/*.json text eol=lf
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: '21'
|
||||||
|
- run: chmod +x ./gradlew
|
||||||
|
- run: ./gradlew build --no-daemon
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: skinsg-jar
|
||||||
|
path: build/libs/*.jar
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ['v*']
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: '21'
|
||||||
|
- run: chmod +x ./gradlew
|
||||||
|
- run: ./gradlew build --no-daemon
|
||||||
|
- uses: akkuman/gitea-release-action@v1
|
||||||
|
with:
|
||||||
|
files: build/libs/*.jar
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
# eclipse
|
||||||
|
bin
|
||||||
|
*.launch
|
||||||
|
.settings
|
||||||
|
.metadata
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
|
||||||
|
# idea
|
||||||
|
out
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# gradle
|
||||||
|
build
|
||||||
|
.gradle
|
||||||
|
|
||||||
|
# other
|
||||||
|
eclipse
|
||||||
|
run
|
||||||
|
runs
|
||||||
|
run-data
|
||||||
|
|
||||||
|
repo
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
# SkinsG
|
||||||
|
|
||||||
|
Client-side Minecraft mod that adds **HD skins** (up to 2048×2048) and **animated GIF capes**
|
||||||
|
(with HD & transparency), driven by a launcher/site asset API keyed on player UUID.
|
||||||
|
|
||||||
|
Currently targets **NeoForge 1.21.1**. Fabric/Forge and 1.20.1 / 1.19.2 are planned — the core
|
||||||
|
(GIF decoder, cape state, mixins) is written to be loader/version agnostic.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- HD skins: the legacy-skin conversion is rescaled so 128/256/…/2048-wide skins render correctly.
|
||||||
|
- GIF capes: decoded once, then played back by copying a pre-composited frame per tick — no
|
||||||
|
per-frame decoding, no AWT, so it doesn't cost FPS. Playback speed comes from the GIF itself.
|
||||||
|
- HD PNG capes fall through to the vanilla renderer untouched.
|
||||||
|
- Per-player control and persistence (see below).
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Drop `skinsg-x.y.z.jar` into your `mods/` folder on a NeoForge 1.21.1 client. Client-side only.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
On first launch the mod writes `config/skinsg.json` with an **empty** `baseUrl`. Nothing is
|
||||||
|
fetched until you set it.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"baseUrl": "https://your.host",
|
||||||
|
"mode": "ALL",
|
||||||
|
"enabled": [],
|
||||||
|
"blocked": [],
|
||||||
|
"globalSpeed": 100,
|
||||||
|
"speed": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `baseUrl` — root of your asset API. The mod requests `"<baseUrl>/api/minecraft/cape/<uuid>?gif"`;
|
||||||
|
if the response is a GIF it is animated, otherwise the vanilla cape is kept.
|
||||||
|
- `globalSpeed` — playback speed in percent (`100` = the GIF's own timing).
|
||||||
|
- The rest is managed by the in-game commands and shouldn't be edited by hand.
|
||||||
|
|
||||||
|
Edit `baseUrl`, then restart the client (or rejoin).
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
`/skinsg` (client-side, tab-completes online players and `@a`):
|
||||||
|
|
||||||
|
| Command | Effect |
|
||||||
|
| --- | --- |
|
||||||
|
| `/skinsg playgif` | Turn animated capes off (frees memory) |
|
||||||
|
| `/skinsg playgif @a` | Animate everyone |
|
||||||
|
| `/skinsg playgif <player>` | Animate only listed players |
|
||||||
|
| `/skinsg stopgif` | Same as `playgif` with no target — off |
|
||||||
|
| `/skinsg stopgif @a` | Off for everyone |
|
||||||
|
| `/skinsg stopgif <player>` | Stop a specific player (works even in `@a` mode) |
|
||||||
|
| `/skinsg self` | Animate only your own cape |
|
||||||
|
| `/skinsg speed @a <percent>` | Global speed override |
|
||||||
|
| `/skinsg speed <player> <percent>` | Per-player speed override |
|
||||||
|
|
||||||
|
All settings persist in `config/skinsg.json`.
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
```
|
||||||
|
./gradlew build
|
||||||
|
```
|
||||||
|
|
||||||
|
Output: `build/libs/skinsg-<version>.jar`. Requires JDK 21.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
+168
@@ -0,0 +1,168 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'net.neoforged.gradle.userdev' version '7.1.20'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('wrapper', Wrapper).configure {
|
||||||
|
// Define wrapper values here so as to not have to always do so when updating gradlew.properties.
|
||||||
|
// Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with
|
||||||
|
// documentation attached on cursor hover of gradle classes and methods. However, this comes with increased
|
||||||
|
// file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards.
|
||||||
|
// (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`)
|
||||||
|
distributionType = Wrapper.DistributionType.BIN
|
||||||
|
}
|
||||||
|
|
||||||
|
version = mod_version
|
||||||
|
group = mod_group_id
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
// Add here additional repositories if required by some of the dependencies below.
|
||||||
|
}
|
||||||
|
|
||||||
|
base {
|
||||||
|
archivesName = mod_id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mojang ships Java 21 to end users in 1.21.1, so mods should target Java 21.
|
||||||
|
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||||
|
|
||||||
|
//minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||||
|
//minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager
|
||||||
|
|
||||||
|
// Default run configurations.
|
||||||
|
// These can be tweaked, removed, or duplicated as needed.
|
||||||
|
runs {
|
||||||
|
// applies to all the run configs below
|
||||||
|
configureEach {
|
||||||
|
// Recommended logging data for a userdev environment
|
||||||
|
// The markers can be added/remove as needed separated by commas.
|
||||||
|
// "SCAN": For mods scan.
|
||||||
|
// "REGISTRIES": For firing of registry events.
|
||||||
|
// "REGISTRYDUMP": For getting the contents of all registries.
|
||||||
|
systemProperty 'forge.logging.markers', 'REGISTRIES'
|
||||||
|
|
||||||
|
// Recommended logging level for the console
|
||||||
|
// You can set various levels here.
|
||||||
|
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
|
||||||
|
systemProperty 'forge.logging.console.level', 'debug'
|
||||||
|
|
||||||
|
modSource project.sourceSets.main
|
||||||
|
}
|
||||||
|
|
||||||
|
client {
|
||||||
|
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
|
||||||
|
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
|
||||||
|
argument '--nogui'
|
||||||
|
}
|
||||||
|
|
||||||
|
// This run config launches GameTestServer and runs all registered gametests, then exits.
|
||||||
|
// By default, the server will crash when no gametests are provided.
|
||||||
|
// The gametest system is also enabled by default for other run configs under the /test command.
|
||||||
|
gameTestServer {
|
||||||
|
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
|
||||||
|
}
|
||||||
|
|
||||||
|
data {
|
||||||
|
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
|
||||||
|
// workingDirectory project.file('run-data')
|
||||||
|
|
||||||
|
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
|
||||||
|
arguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include resources generated by data generators.
|
||||||
|
sourceSets.main.resources { srcDir 'src/generated/resources' }
|
||||||
|
|
||||||
|
// Sets up a dependency configuration called 'localRuntime'.
|
||||||
|
// This configuration should be used instead of 'runtimeOnly' to declare
|
||||||
|
// a dependency that will be present for runtime testing but that is
|
||||||
|
// "optional", meaning it will not be pulled by dependents of this mod.
|
||||||
|
configurations {
|
||||||
|
runtimeClasspath.extendsFrom localRuntime
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// Specify the version of Minecraft to use.
|
||||||
|
// Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above.
|
||||||
|
// The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version.
|
||||||
|
// You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader.
|
||||||
|
// And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version.
|
||||||
|
// For all intends and purposes: You can treat this dependency as if it is a normal library you would use.
|
||||||
|
implementation "net.neoforged:neoforge:${neo_version}"
|
||||||
|
|
||||||
|
// Example optional mod dependency with JEI
|
||||||
|
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
|
||||||
|
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
|
||||||
|
// compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}"
|
||||||
|
// We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it
|
||||||
|
// localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}"
|
||||||
|
|
||||||
|
// Example mod dependency using a mod jar from ./libs with a flat dir repository
|
||||||
|
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
|
||||||
|
// The group id is ignored when searching -- in this case, it is "blank"
|
||||||
|
// implementation "blank:coolmod-${mc_version}:${coolmod_version}"
|
||||||
|
|
||||||
|
// Example mod dependency using a file as dependency
|
||||||
|
// implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar")
|
||||||
|
|
||||||
|
// Example project dependency using a sister or child project:
|
||||||
|
// implementation project(":myproject")
|
||||||
|
|
||||||
|
// For more info:
|
||||||
|
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
|
||||||
|
// http://www.gradle.org/docs/current/userguide/dependency_management.html
|
||||||
|
}
|
||||||
|
|
||||||
|
// This block of code expands all declared replace properties in the specified resource targets.
|
||||||
|
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
|
||||||
|
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
|
||||||
|
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
|
||||||
|
tasks.withType(ProcessResources).configureEach {
|
||||||
|
var replaceProperties = [
|
||||||
|
minecraft_version : minecraft_version,
|
||||||
|
minecraft_version_range: minecraft_version_range,
|
||||||
|
neo_version : neo_version,
|
||||||
|
loader_version_range : loader_version_range,
|
||||||
|
mod_id : mod_id,
|
||||||
|
mod_name : mod_name,
|
||||||
|
mod_license : mod_license,
|
||||||
|
mod_version : mod_version,
|
||||||
|
]
|
||||||
|
inputs.properties replaceProperties
|
||||||
|
|
||||||
|
filesMatching(['META-INF/neoforge.mods.toml']) {
|
||||||
|
expand replaceProperties
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example configuration to allow publishing using the maven-publish plugin
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
register('mavenJava', MavenPublication) {
|
||||||
|
from components.java
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url "file://${project.projectDir}/repo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
|
||||||
|
idea {
|
||||||
|
module {
|
||||||
|
downloadSources = true
|
||||||
|
downloadJavadoc = true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
|
||||||
|
org.gradle.jvmargs=-Xmx1G
|
||||||
|
org.gradle.daemon=true
|
||||||
|
org.gradle.parallel=true
|
||||||
|
org.gradle.caching=true
|
||||||
|
org.gradle.configuration-cache=true
|
||||||
|
|
||||||
|
#read more on this at https://github.com/neoforged/NeoGradle/blob/NG_7.0/README.md#apply-parchment-mappings
|
||||||
|
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
|
||||||
|
neogradle.subsystems.parchment.minecraftVersion=1.21.1
|
||||||
|
neogradle.subsystems.parchment.mappingsVersion=2024.11.17
|
||||||
|
# Environment Properties
|
||||||
|
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
|
||||||
|
# The Minecraft version must agree with the Neo version to get a valid artifact
|
||||||
|
minecraft_version=1.21.1
|
||||||
|
# The Minecraft version range can use any release version of Minecraft as bounds.
|
||||||
|
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
|
||||||
|
# as they do not follow standard versioning conventions.
|
||||||
|
minecraft_version_range=[1.21.1]
|
||||||
|
# The Neo version must agree with the Minecraft version to get a valid artifact
|
||||||
|
neo_version=21.1.219
|
||||||
|
# The loader version range can only use the major version of FML as bounds
|
||||||
|
loader_version_range=[1,)
|
||||||
|
|
||||||
|
## Mod Properties
|
||||||
|
|
||||||
|
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
|
||||||
|
# Must match the String constant located in the main mod class annotated with @Mod.
|
||||||
|
mod_id=skinsg
|
||||||
|
# The human-readable display name for the mod.
|
||||||
|
mod_name=NightSync Skins (HD + animated capes)
|
||||||
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
|
mod_license=All Rights Reserved
|
||||||
|
# The mod version. See https://semver.org/
|
||||||
|
mod_version=0.1.0
|
||||||
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
|
# This should match the base package used for the mod sources.
|
||||||
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
mod_group_id=xyz.nightsync.skinsg
|
||||||
Vendored
BIN
Binary file not shown.
+7
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
@@ -0,0 +1,251 @@
|
|||||||
|
#!/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.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# 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/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/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# 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 -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
|
||||||
|
|
||||||
|
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="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
|
# 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, 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" \
|
||||||
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# 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
+94
@@ -0,0 +1,94 @@
|
|||||||
|
@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
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@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. 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
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
|
: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
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
maven { url = 'https://maven.neoforged.net/releases' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package xyz.nightsync.skinsg;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public final class SkinsgConfig {
|
||||||
|
|
||||||
|
public enum Mode { ALL, NONE, SELF, SET }
|
||||||
|
|
||||||
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
public static final int DEFAULT_SPEED = 100;
|
||||||
|
|
||||||
|
public String baseUrl = "";
|
||||||
|
public Mode mode = Mode.ALL;
|
||||||
|
public Set<String> enabled = new LinkedHashSet<>();
|
||||||
|
public Set<String> blocked = new LinkedHashSet<>();
|
||||||
|
public int globalSpeed = DEFAULT_SPEED;
|
||||||
|
public Map<String, Integer> speed = new HashMap<>();
|
||||||
|
|
||||||
|
private transient Path file;
|
||||||
|
|
||||||
|
public static SkinsgConfig load(Path configDir) {
|
||||||
|
Path f = configDir.resolve("skinsg.json");
|
||||||
|
boolean fresh = !Files.exists(f);
|
||||||
|
SkinsgConfig cfg;
|
||||||
|
try {
|
||||||
|
cfg = fresh ? new SkinsgConfig()
|
||||||
|
: GSON.fromJson(Files.readString(f, StandardCharsets.UTF_8), SkinsgConfig.class);
|
||||||
|
if (cfg == null) cfg = new SkinsgConfig();
|
||||||
|
} catch (Exception e) {
|
||||||
|
cfg = new SkinsgConfig();
|
||||||
|
}
|
||||||
|
cfg.normalize();
|
||||||
|
cfg.file = f;
|
||||||
|
if (fresh) cfg.save();
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void normalize() {
|
||||||
|
if (baseUrl == null) baseUrl = "";
|
||||||
|
baseUrl = baseUrl.trim();
|
||||||
|
while (baseUrl.endsWith("/")) baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
|
||||||
|
if (mode == null) mode = Mode.ALL;
|
||||||
|
if (enabled == null) enabled = new LinkedHashSet<>();
|
||||||
|
if (blocked == null) blocked = new LinkedHashSet<>();
|
||||||
|
if (speed == null) speed = new HashMap<>();
|
||||||
|
if (globalSpeed <= 0) globalSpeed = DEFAULT_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasBaseUrl() {
|
||||||
|
return baseUrl != null && !baseUrl.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void save() {
|
||||||
|
if (file == null) return;
|
||||||
|
try {
|
||||||
|
Files.createDirectories(file.getParent());
|
||||||
|
Files.writeString(file, GSON.toJson(this), StandardCharsets.UTF_8);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldAnimate(UUID player, UUID self) {
|
||||||
|
if (blocked.contains(player.toString())) return false;
|
||||||
|
return switch (mode) {
|
||||||
|
case ALL -> true;
|
||||||
|
case NONE -> false;
|
||||||
|
case SELF -> self != null && self.equals(player);
|
||||||
|
case SET -> enabled.contains(player.toString());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public int speedFor(UUID player) {
|
||||||
|
Integer s = speed.get(player.toString());
|
||||||
|
return s != null && s > 0 ? s : globalSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setNone() { mode = Mode.NONE; enabled.clear(); blocked.clear(); save(); }
|
||||||
|
|
||||||
|
public synchronized void setAll() { mode = Mode.ALL; enabled.clear(); blocked.clear(); save(); }
|
||||||
|
|
||||||
|
public synchronized void setSelf() { mode = Mode.SELF; enabled.clear(); blocked.clear(); save(); }
|
||||||
|
|
||||||
|
public synchronized void enableFor(Set<UUID> players) {
|
||||||
|
for (UUID u : players) blocked.remove(u.toString());
|
||||||
|
if (mode == Mode.NONE || mode == Mode.SELF) mode = Mode.SET;
|
||||||
|
if (mode == Mode.SET) for (UUID u : players) enabled.add(u.toString());
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void disableFor(Set<UUID> players) {
|
||||||
|
for (UUID u : players) { blocked.add(u.toString()); enabled.remove(u.toString()); }
|
||||||
|
if (mode == Mode.SET && enabled.isEmpty()) mode = Mode.NONE;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setSpeed(UUID player, int percent) {
|
||||||
|
if (percent <= 0) speed.remove(player.toString());
|
||||||
|
else speed.put(player.toString(), percent);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setGlobalSpeed(int percent) {
|
||||||
|
globalSpeed = percent > 0 ? percent : DEFAULT_SPEED;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package xyz.nightsync.skinsg;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
|
import net.neoforged.fml.common.Mod;
|
||||||
|
import net.neoforged.fml.loading.FMLPaths;
|
||||||
|
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||||
|
import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
|
||||||
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
import xyz.nightsync.skinsg.client.CapeManager;
|
||||||
|
import xyz.nightsync.skinsg.commands.SkinsgCommands;
|
||||||
|
|
||||||
|
@Mod(value = SkinsgMod.MODID, dist = Dist.CLIENT)
|
||||||
|
public final class SkinsgMod {
|
||||||
|
|
||||||
|
public static final String MODID = "skinsg";
|
||||||
|
private static SkinsgConfig config;
|
||||||
|
|
||||||
|
public SkinsgMod(IEventBus modBus) {
|
||||||
|
config = SkinsgConfig.load(FMLPaths.CONFIGDIR.get());
|
||||||
|
CapeManager.init(config, () -> {
|
||||||
|
var p = Minecraft.getInstance().player;
|
||||||
|
return p != null ? p.getUUID() : null;
|
||||||
|
});
|
||||||
|
NeoForge.EVENT_BUS.addListener(this::onRegisterCommands);
|
||||||
|
NeoForge.EVENT_BUS.addListener(this::onClientTick);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SkinsgConfig config() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onRegisterCommands(RegisterClientCommandsEvent e) {
|
||||||
|
SkinsgCommands.register(e.getDispatcher(), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onClientTick(ClientTickEvent.Post e) {
|
||||||
|
CapeManager.clientTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
package xyz.nightsync.skinsg.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.NativeImage;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||||
|
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import xyz.nightsync.skinsg.SkinsgConfig;
|
||||||
|
import xyz.nightsync.skinsg.gif.GifDecoder;
|
||||||
|
import xyz.nightsync.skinsg.gif.GifImage;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches a player's GIF cape once, decodes it whole, then advances frames each tick by copying a
|
||||||
|
* pre-composited buffer into a dynamic texture. Players that policy excludes are dropped so the
|
||||||
|
* vanilla (static) cape shows and no memory is held.
|
||||||
|
*
|
||||||
|
* @author Nghtly
|
||||||
|
*/
|
||||||
|
public final class CapeManager {
|
||||||
|
|
||||||
|
private static final String MODID = "skinsg";
|
||||||
|
private static final int MAX_CACHE = 96;
|
||||||
|
private static final int MAX_BYTES = 12 * 1024 * 1024;
|
||||||
|
|
||||||
|
private static SkinsgConfig config;
|
||||||
|
private static Supplier<UUID> selfProvider = () -> null;
|
||||||
|
|
||||||
|
private static final GifDecoder.Limits LIMITS = new GifDecoder.Limits();
|
||||||
|
|
||||||
|
private static final ExecutorService IO = Executors.newFixedThreadPool(2, r -> {
|
||||||
|
Thread t = new Thread(r, "skinsg-cape-io");
|
||||||
|
t.setDaemon(true);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
|
||||||
|
private static final Map<UUID, Entry> CACHE = Collections.synchronizedMap(
|
||||||
|
new LinkedHashMap<>(64, 0.75f, true) {
|
||||||
|
@Override
|
||||||
|
protected boolean removeEldestEntry(Map.Entry<UUID, Entry> e) {
|
||||||
|
if (size() > MAX_CACHE) {
|
||||||
|
e.getValue().release();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
private CapeManager() {}
|
||||||
|
|
||||||
|
public static void init(SkinsgConfig cfg, Supplier<UUID> self) {
|
||||||
|
config = cfg;
|
||||||
|
selfProvider = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResourceLocation getCape(UUID uuid) {
|
||||||
|
if (config == null || uuid == null || !config.hasBaseUrl()) return null;
|
||||||
|
if (!config.shouldAnimate(uuid, selfProvider.get())) {
|
||||||
|
releaseIfPresent(uuid);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return CACHE.computeIfAbsent(uuid, CapeManager::startLoad).texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clientTick() {
|
||||||
|
if (config == null) return;
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
UUID self = selfProvider.get();
|
||||||
|
synchronized (CACHE) {
|
||||||
|
for (Map.Entry<UUID, Entry> en : CACHE.entrySet()) {
|
||||||
|
if (config.shouldAnimate(en.getKey(), self)) {
|
||||||
|
en.getValue().tick(now, config.speedFor(en.getKey()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void releaseAll() {
|
||||||
|
synchronized (CACHE) {
|
||||||
|
for (Entry e : CACHE.values()) e.release();
|
||||||
|
CACHE.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void releaseIfPresent(UUID uuid) {
|
||||||
|
Entry e = CACHE.remove(uuid);
|
||||||
|
if (e != null) e.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Entry startLoad(UUID uuid) {
|
||||||
|
Entry entry = new Entry(uuid);
|
||||||
|
IO.submit(() -> {
|
||||||
|
try {
|
||||||
|
byte[] bytes = httpGet(config.baseUrl + "/api/minecraft/cape/" + uuid + "?gif");
|
||||||
|
if (bytes == null || bytes.length < 6 || !isGif(bytes)) {
|
||||||
|
entry.noAnimation = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buildTexture(entry, GifDecoder.decode(bytes, LIMITS));
|
||||||
|
} catch (Throwable t) {
|
||||||
|
entry.noAnimation = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void buildTexture(Entry entry, GifImage gif) {
|
||||||
|
RenderSystem.recordRenderCall(() -> {
|
||||||
|
try {
|
||||||
|
DynamicTexture tex = new DynamicTexture(gif.width, gif.height, true);
|
||||||
|
((AbstractTexture) tex).setFilter(false, false);
|
||||||
|
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(MODID, "cape/" + entry.uuid + "/anim");
|
||||||
|
Minecraft.getInstance().getTextureManager().register(id, tex);
|
||||||
|
entry.attach(gif, tex, id);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
entry.noAnimation = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isGif(byte[] b) {
|
||||||
|
return b[0] == 'G' && b[1] == 'I' && b[2] == 'F';
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] httpGet(String url) throws IOException {
|
||||||
|
HttpURLConnection c = (HttpURLConnection) URI.create(url).toURL().openConnection();
|
||||||
|
c.setConnectTimeout(7000);
|
||||||
|
c.setReadTimeout(10000);
|
||||||
|
c.setRequestProperty("User-Agent", MODID + "/1.0");
|
||||||
|
if (c.getResponseCode() != 200) return null;
|
||||||
|
int len = c.getContentLength();
|
||||||
|
if (len > MAX_BYTES) return null;
|
||||||
|
try (InputStream in = c.getInputStream()) {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(1024, Math.min(Math.max(len, 0), MAX_BYTES)));
|
||||||
|
byte[] buf = new byte[8192];
|
||||||
|
int r, total = 0;
|
||||||
|
while ((r = in.read(buf)) != -1) {
|
||||||
|
total += r;
|
||||||
|
if (total > MAX_BYTES) return null;
|
||||||
|
out.write(buf, 0, r);
|
||||||
|
}
|
||||||
|
return out.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class Entry {
|
||||||
|
final UUID uuid;
|
||||||
|
volatile boolean noAnimation;
|
||||||
|
|
||||||
|
private GifImage gif;
|
||||||
|
private DynamicTexture tex;
|
||||||
|
private volatile ResourceLocation texture;
|
||||||
|
private int frame = -1;
|
||||||
|
private long nextAt;
|
||||||
|
|
||||||
|
Entry(UUID uuid) { this.uuid = uuid; }
|
||||||
|
|
||||||
|
void attach(GifImage gif, DynamicTexture tex, ResourceLocation id) {
|
||||||
|
this.gif = gif;
|
||||||
|
this.tex = tex;
|
||||||
|
this.texture = id;
|
||||||
|
this.frame = -1;
|
||||||
|
this.nextAt = 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tick(long now, int speedPercent) {
|
||||||
|
if (gif == null || tex == null) return;
|
||||||
|
if (frame != -1 && now < nextAt) return;
|
||||||
|
frame = (frame + 1) % gif.frameCount();
|
||||||
|
|
||||||
|
int[] src = gif.framesAbgr[frame];
|
||||||
|
NativeImage px = tex.getPixels();
|
||||||
|
if (px != null && px.getWidth() == gif.width && px.getHeight() == gif.height) {
|
||||||
|
int i = 0;
|
||||||
|
for (int y = 0; y < gif.height; y++) {
|
||||||
|
for (int x = 0; x < gif.width; x++) {
|
||||||
|
px.setPixelRGBA(x, y, src[i++]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RenderSystem.recordRenderCall(tex::upload);
|
||||||
|
}
|
||||||
|
|
||||||
|
int base = gif.delaysMs[frame];
|
||||||
|
long dur = speedPercent > 0 ? (long) base * 100L / speedPercent : base;
|
||||||
|
nextAt = now + Math.max(20L, dur);
|
||||||
|
}
|
||||||
|
|
||||||
|
void release() {
|
||||||
|
ResourceLocation id = texture;
|
||||||
|
if (id != null) {
|
||||||
|
RenderSystem.recordRenderCall(() -> {
|
||||||
|
try {
|
||||||
|
Minecraft.getInstance().getTextureManager().release(id);
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
texture = null;
|
||||||
|
tex = null;
|
||||||
|
gif = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package xyz.nightsync.skinsg.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import xyz.nightsync.skinsg.SkinsgConfig;
|
||||||
|
import xyz.nightsync.skinsg.client.CapeManager;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static net.minecraft.commands.Commands.argument;
|
||||||
|
import static net.minecraft.commands.Commands.literal;
|
||||||
|
|
||||||
|
public final class SkinsgCommands {
|
||||||
|
|
||||||
|
private static SkinsgConfig cfg;
|
||||||
|
public static final String ALL = "@a";
|
||||||
|
|
||||||
|
private SkinsgCommands() {}
|
||||||
|
|
||||||
|
private static final SuggestionProvider<CommandSourceStack> TARGETS = (ctx, b) -> {
|
||||||
|
b.suggest(ALL);
|
||||||
|
var conn = Minecraft.getInstance().getConnection();
|
||||||
|
if (conn != null) {
|
||||||
|
for (PlayerInfo pi : conn.getOnlinePlayers()) {
|
||||||
|
b.suggest(pi.getProfile().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b.buildFuture();
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void register(CommandDispatcher<CommandSourceStack> d, SkinsgConfig config) {
|
||||||
|
cfg = config;
|
||||||
|
d.register(literal("skinsg")
|
||||||
|
.then(literal("playgif")
|
||||||
|
.executes(c -> { cfg.setNone(); CapeManager.releaseAll(); return msg(c, "GIF capes: off"); })
|
||||||
|
.then(argument("target", StringArgumentType.word()).suggests(TARGETS)
|
||||||
|
.executes(SkinsgCommands::playgif)))
|
||||||
|
.then(literal("stopgif")
|
||||||
|
.executes(c -> { cfg.setNone(); CapeManager.releaseAll(); return msg(c, "GIF capes: off"); })
|
||||||
|
.then(argument("target", StringArgumentType.word()).suggests(TARGETS)
|
||||||
|
.executes(SkinsgCommands::stopgif)))
|
||||||
|
.then(literal("self")
|
||||||
|
.executes(c -> { cfg.setSelf(); CapeManager.releaseAll(); return msg(c, "GIF capes: self only"); }))
|
||||||
|
.then(literal("speed")
|
||||||
|
.then(argument("target", StringArgumentType.word()).suggests(TARGETS)
|
||||||
|
.then(argument("percent", IntegerArgumentType.integer(1, 2000))
|
||||||
|
.executes(SkinsgCommands::speed)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int playgif(CommandContext<CommandSourceStack> c) {
|
||||||
|
String target = StringArgumentType.getString(c, "target");
|
||||||
|
if (ALL.equals(target)) { cfg.setAll(); return msg(c, "GIF capes: everyone"); }
|
||||||
|
Set<UUID> ids = resolve(target);
|
||||||
|
if (ids.isEmpty()) return err(c, "player not found: " + target);
|
||||||
|
cfg.enableFor(ids);
|
||||||
|
return msg(c, "GIF capes: on for " + target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int stopgif(CommandContext<CommandSourceStack> c) {
|
||||||
|
String target = StringArgumentType.getString(c, "target");
|
||||||
|
if (ALL.equals(target)) { cfg.setNone(); CapeManager.releaseAll(); return msg(c, "GIF capes: off"); }
|
||||||
|
Set<UUID> ids = resolve(target);
|
||||||
|
if (ids.isEmpty()) return err(c, "player not found: " + target);
|
||||||
|
cfg.disableFor(ids);
|
||||||
|
for (UUID id : ids) CapeManager.releaseIfPresent(id);
|
||||||
|
return msg(c, "GIF capes: stopped for " + target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int speed(CommandContext<CommandSourceStack> c) {
|
||||||
|
String target = StringArgumentType.getString(c, "target");
|
||||||
|
int percent = IntegerArgumentType.getInteger(c, "percent");
|
||||||
|
if (ALL.equals(target)) { cfg.setGlobalSpeed(percent); return msg(c, "GIF speed: " + percent + "% (all)"); }
|
||||||
|
Set<UUID> ids = resolve(target);
|
||||||
|
if (ids.isEmpty()) return err(c, "player not found: " + target);
|
||||||
|
for (UUID id : ids) cfg.setSpeed(id, percent);
|
||||||
|
return msg(c, "GIF speed: " + percent + "% for " + target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<UUID> resolve(String name) {
|
||||||
|
Set<UUID> out = new HashSet<>();
|
||||||
|
var conn = Minecraft.getInstance().getConnection();
|
||||||
|
if (conn != null) {
|
||||||
|
for (PlayerInfo pi : conn.getOnlinePlayers()) {
|
||||||
|
if (pi.getProfile().getName().equalsIgnoreCase(name)) out.add(pi.getProfile().getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int msg(CommandContext<CommandSourceStack> c, String text) {
|
||||||
|
c.getSource().sendSuccess(() -> Component.literal("[skinsg] " + text), false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int err(CommandContext<CommandSourceStack> c, String text) {
|
||||||
|
c.getSource().sendFailure(Component.literal("[skinsg] " + text));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,250 @@
|
|||||||
|
package xyz.nightsync.skinsg.gif;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a GIF87a/89a in one pass into pre-composited ABGR frames (disposal already applied),
|
||||||
|
* so playback is a plain buffer copy instead of per-frame LZW + compositing. Streaming-safe with
|
||||||
|
* hard size limits.
|
||||||
|
*
|
||||||
|
* @author Nghtly
|
||||||
|
*/
|
||||||
|
public final class GifDecoder {
|
||||||
|
|
||||||
|
public static final class GifException extends Exception {
|
||||||
|
public GifException(String message) { super(message); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Limits {
|
||||||
|
public int maxDimension = 2048;
|
||||||
|
public int maxFrames = 240;
|
||||||
|
public long maxTotalPixels = 128L * 1024 * 1024;
|
||||||
|
public int minDelayMs = 20;
|
||||||
|
public int maxDelayMs = 10_000;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final byte[] d;
|
||||||
|
private int p;
|
||||||
|
private final Limits lim;
|
||||||
|
|
||||||
|
private int width, height;
|
||||||
|
private int[] gct;
|
||||||
|
private int bgIndex;
|
||||||
|
|
||||||
|
private int disposal = 0;
|
||||||
|
private int transparentIndex = -1;
|
||||||
|
private int delayCs = 0;
|
||||||
|
|
||||||
|
private GifDecoder(byte[] data, Limits limits) {
|
||||||
|
this.d = data;
|
||||||
|
this.lim = limits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GifImage decode(byte[] data, Limits limits) throws GifException {
|
||||||
|
return new GifDecoder(data, limits).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int u8() throws GifException {
|
||||||
|
if (p >= d.length) throw new GifException("unexpected EOF");
|
||||||
|
return d[p++] & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int u16() throws GifException {
|
||||||
|
int lo = u8(), hi = u8();
|
||||||
|
return lo | (hi << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void skip(int n) throws GifException {
|
||||||
|
if (p + n > d.length) throw new GifException("unexpected EOF");
|
||||||
|
p += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[] readColorTable(int size) throws GifException {
|
||||||
|
int[] table = new int[size];
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
int r = u8(), g = u8(), b = u8();
|
||||||
|
table[i] = (r << 16) | (g << 8) | b;
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] readSubBlocks() throws GifException {
|
||||||
|
int start = p;
|
||||||
|
int total = 0;
|
||||||
|
while (true) {
|
||||||
|
int size = u8();
|
||||||
|
if (size == 0) break;
|
||||||
|
skip(size);
|
||||||
|
total += size;
|
||||||
|
}
|
||||||
|
byte[] out = new byte[total];
|
||||||
|
int op = 0, rp = start;
|
||||||
|
while (true) {
|
||||||
|
int size = d[rp++] & 0xFF;
|
||||||
|
if (size == 0) break;
|
||||||
|
System.arraycopy(d, rp, out, op, size);
|
||||||
|
op += size;
|
||||||
|
rp += size;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void skipSubBlocks() throws GifException {
|
||||||
|
while (true) {
|
||||||
|
int size = u8();
|
||||||
|
if (size == 0) break;
|
||||||
|
skip(size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private GifImage run() throws GifException {
|
||||||
|
if (d.length < 13) throw new GifException("too small");
|
||||||
|
if (!(d[0] == 'G' && d[1] == 'I' && d[2] == 'F')) throw new GifException("not a GIF");
|
||||||
|
p = 6;
|
||||||
|
width = u16();
|
||||||
|
height = u16();
|
||||||
|
if (width < 1 || height < 1 || width > lim.maxDimension || height > lim.maxDimension) {
|
||||||
|
throw new GifException("bad dimensions " + width + "x" + height);
|
||||||
|
}
|
||||||
|
int packed = u8();
|
||||||
|
bgIndex = u8();
|
||||||
|
u8();
|
||||||
|
if ((packed & 0x80) != 0) {
|
||||||
|
gct = readColorTable(2 << (packed & 0x07));
|
||||||
|
}
|
||||||
|
|
||||||
|
final long area = (long) width * height;
|
||||||
|
final int frameCap = (int) Math.max(1, Math.min(lim.maxFrames, lim.maxTotalPixels / Math.max(1, area)));
|
||||||
|
|
||||||
|
List<int[]> frames = new ArrayList<>();
|
||||||
|
List<Integer> delays = new ArrayList<>();
|
||||||
|
|
||||||
|
int[] canvas = new int[(int) area];
|
||||||
|
int[] saved = null;
|
||||||
|
int prevDisposal = 0;
|
||||||
|
int prevX = 0, prevY = 0, prevW = 0, prevH = 0;
|
||||||
|
|
||||||
|
boolean done = false;
|
||||||
|
while (!done) {
|
||||||
|
int block = u8();
|
||||||
|
switch (block) {
|
||||||
|
case 0x3B:
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
case 0x21:
|
||||||
|
handleExtension();
|
||||||
|
break;
|
||||||
|
case 0x2C: {
|
||||||
|
int ix = u16(), iy = u16(), iw = u16(), ih = u16();
|
||||||
|
int ipacked = u8();
|
||||||
|
int[] lct = null;
|
||||||
|
if ((ipacked & 0x80) != 0) lct = readColorTable(2 << (ipacked & 0x07));
|
||||||
|
boolean interlaced = (ipacked & 0x40) != 0;
|
||||||
|
int minCode = u8();
|
||||||
|
byte[] lzw = readSubBlocks();
|
||||||
|
|
||||||
|
if (ix < 0 || iy < 0 || iw < 0 || ih < 0 || ix + iw > width || iy + ih > height) {
|
||||||
|
throw new GifException("frame rect out of bounds");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prevDisposal == 2) {
|
||||||
|
clearRect(canvas, prevX, prevY, prevW, prevH);
|
||||||
|
} else if (prevDisposal == 3 && saved != null) {
|
||||||
|
System.arraycopy(saved, 0, canvas, 0, canvas.length);
|
||||||
|
}
|
||||||
|
if (disposal == 3) {
|
||||||
|
if (saved == null) saved = new int[canvas.length];
|
||||||
|
System.arraycopy(canvas, 0, saved, 0, canvas.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frames.size() < frameCap && iw > 0 && ih > 0) {
|
||||||
|
int[] palette = lct != null ? lct : gct;
|
||||||
|
if (palette == null) throw new GifException("no color table");
|
||||||
|
byte[] indices = LzwDecoder.decode(lzw, minCode, iw * ih);
|
||||||
|
drawFrame(canvas, ix, iy, iw, ih, interlaced, indices, palette, transparentIndex);
|
||||||
|
frames.add(canvas.clone());
|
||||||
|
delays.add(clampDelay(delayCs));
|
||||||
|
}
|
||||||
|
|
||||||
|
prevDisposal = disposal;
|
||||||
|
prevX = ix; prevY = iy; prevW = iw; prevH = ih;
|
||||||
|
transparentIndex = -1;
|
||||||
|
disposal = 0;
|
||||||
|
delayCs = 0;
|
||||||
|
if (frames.size() >= frameCap) done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new GifException("bad block 0x" + Integer.toHexString(block));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frames.isEmpty()) throw new GifException("no frames");
|
||||||
|
int[][] arr = frames.toArray(new int[0][]);
|
||||||
|
int[] del = new int[delays.size()];
|
||||||
|
for (int i = 0; i < del.length; i++) del[i] = delays.get(i);
|
||||||
|
return new GifImage(width, height, arr, del);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleExtension() throws GifException {
|
||||||
|
int label = u8();
|
||||||
|
if (label == 0xF9) {
|
||||||
|
int size = u8();
|
||||||
|
int flags = u8();
|
||||||
|
disposal = (flags >> 2) & 0x07;
|
||||||
|
delayCs = u16();
|
||||||
|
int tIndex = u8();
|
||||||
|
transparentIndex = (flags & 0x01) != 0 ? tIndex : -1;
|
||||||
|
if (size > 4) skip(size - 4);
|
||||||
|
int term = u8();
|
||||||
|
if (term != 0) skipSubBlocks();
|
||||||
|
} else {
|
||||||
|
skipSubBlocks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int clampDelay(int cs) {
|
||||||
|
int ms = cs * 10;
|
||||||
|
if (ms <= 0) ms = 100;
|
||||||
|
return Math.max(lim.minDelayMs, Math.min(lim.maxDelayMs, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearRect(int[] canvas, int x, int y, int w, int h) {
|
||||||
|
for (int row = 0; row < h; row++) {
|
||||||
|
int base = (y + row) * width + x;
|
||||||
|
Arrays.fill(canvas, base, base + w, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawFrame(int[] canvas, int fx, int fy, int fw, int fh, boolean interlaced,
|
||||||
|
byte[] indices, int[] palette, int tIndex) {
|
||||||
|
int pal = palette.length;
|
||||||
|
for (int row = 0; row < fh; row++) {
|
||||||
|
int dstY = interlaced ? interlacedRow(row, fh) : row;
|
||||||
|
int dst = (fy + dstY) * width + fx;
|
||||||
|
int src = row * fw;
|
||||||
|
for (int col = 0; col < fw; col++) {
|
||||||
|
int idx = indices[src + col] & 0xFF;
|
||||||
|
if (idx == tIndex || idx >= pal) continue;
|
||||||
|
int rgb = palette[idx];
|
||||||
|
int r = (rgb >> 16) & 0xFF, g = (rgb >> 8) & 0xFF, b = rgb & 0xFF;
|
||||||
|
canvas[dst + col] = 0xFF000000 | (b << 16) | (g << 8) | r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int interlacedRow(int row, int h) {
|
||||||
|
int p1 = (h + 7) / 8;
|
||||||
|
int p2 = (h + 3) / 8;
|
||||||
|
int p3 = (h + 1) / 4;
|
||||||
|
if (row < p1) return row * 8;
|
||||||
|
row -= p1;
|
||||||
|
if (row < p2) return row * 8 + 4;
|
||||||
|
row -= p2;
|
||||||
|
if (row < p3) return row * 4 + 2;
|
||||||
|
row -= p3;
|
||||||
|
return row * 2 + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package xyz.nightsync.skinsg.gif;
|
||||||
|
|
||||||
|
public final class GifImage {
|
||||||
|
|
||||||
|
public final int width;
|
||||||
|
public final int height;
|
||||||
|
public final int[][] framesAbgr;
|
||||||
|
public final int[] delaysMs;
|
||||||
|
|
||||||
|
GifImage(int width, int height, int[][] framesAbgr, int[] delaysMs) {
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.framesAbgr = framesAbgr;
|
||||||
|
this.delaysMs = delaysMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int frameCount() {
|
||||||
|
return framesAbgr.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package xyz.nightsync.skinsg.gif;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GIF variable-width LZW decompressor; returns one palette index per pixel.
|
||||||
|
*
|
||||||
|
* @author Nghtly
|
||||||
|
*/
|
||||||
|
final class LzwDecoder {
|
||||||
|
|
||||||
|
private LzwDecoder() {}
|
||||||
|
|
||||||
|
private static final int MAX_CODES = 4096;
|
||||||
|
|
||||||
|
static byte[] decode(byte[] data, int minCodeSize, int pixelCount) throws GifDecoder.GifException {
|
||||||
|
if (minCodeSize < 2 || minCodeSize > 8) throw new GifDecoder.GifException("bad LZW code size");
|
||||||
|
|
||||||
|
final int clearCode = 1 << minCodeSize;
|
||||||
|
final int endCode = clearCode + 1;
|
||||||
|
|
||||||
|
final int[] prefix = new int[MAX_CODES];
|
||||||
|
final int[] suffix = new int[MAX_CODES];
|
||||||
|
final byte[] stack = new byte[MAX_CODES + 1];
|
||||||
|
|
||||||
|
final byte[] out = new byte[pixelCount];
|
||||||
|
int outPos = 0;
|
||||||
|
|
||||||
|
int codeSize = minCodeSize + 1;
|
||||||
|
int codeMask = (1 << codeSize) - 1;
|
||||||
|
int available = clearCode + 2;
|
||||||
|
|
||||||
|
for (int i = 0; i < clearCode; i++) {
|
||||||
|
prefix[i] = 0;
|
||||||
|
suffix[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bitBuffer = 0, bitCount = 0, dataPos = 0;
|
||||||
|
int oldCode = -1, firstByte = 0;
|
||||||
|
|
||||||
|
while (outPos < pixelCount) {
|
||||||
|
while (bitCount < codeSize) {
|
||||||
|
if (dataPos >= data.length) return out;
|
||||||
|
bitBuffer |= (data[dataPos++] & 0xFF) << bitCount;
|
||||||
|
bitCount += 8;
|
||||||
|
}
|
||||||
|
int code = bitBuffer & codeMask;
|
||||||
|
bitBuffer >>>= codeSize;
|
||||||
|
bitCount -= codeSize;
|
||||||
|
|
||||||
|
if (code == clearCode) {
|
||||||
|
codeSize = minCodeSize + 1;
|
||||||
|
codeMask = (1 << codeSize) - 1;
|
||||||
|
available = clearCode + 2;
|
||||||
|
oldCode = -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (code == endCode) break;
|
||||||
|
|
||||||
|
int sp = 0;
|
||||||
|
int inCode;
|
||||||
|
if (oldCode == -1) {
|
||||||
|
out[outPos++] = (byte) suffix[code];
|
||||||
|
oldCode = code;
|
||||||
|
firstByte = code;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (code < available) {
|
||||||
|
inCode = code;
|
||||||
|
} else {
|
||||||
|
stack[sp++] = (byte) firstByte;
|
||||||
|
inCode = oldCode;
|
||||||
|
}
|
||||||
|
while (inCode >= clearCode) {
|
||||||
|
stack[sp++] = (byte) suffix[inCode];
|
||||||
|
inCode = prefix[inCode];
|
||||||
|
}
|
||||||
|
firstByte = suffix[inCode];
|
||||||
|
stack[sp++] = (byte) firstByte;
|
||||||
|
|
||||||
|
if (available < MAX_CODES) {
|
||||||
|
prefix[available] = oldCode;
|
||||||
|
suffix[available] = firstByte;
|
||||||
|
available++;
|
||||||
|
if ((available & codeMask) == 0 && available < MAX_CODES) {
|
||||||
|
codeSize++;
|
||||||
|
codeMask += available;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oldCode = code;
|
||||||
|
|
||||||
|
while (sp > 0 && outPos < pixelCount) {
|
||||||
|
out[outPos++] = stack[--sp];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package xyz.nightsync.skinsg.mixin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.client.player.AbstractClientPlayer;
|
||||||
|
import net.minecraft.client.resources.PlayerSkin;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
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.CallbackInfoReturnable;
|
||||||
|
import xyz.nightsync.skinsg.client.CapeManager;
|
||||||
|
|
||||||
|
@Mixin(AbstractClientPlayer.class)
|
||||||
|
public abstract class CapeMagicMixin {
|
||||||
|
|
||||||
|
@Inject(method = "getSkin", at = @At("RETURN"), cancellable = true)
|
||||||
|
private void skinsg$overrideCape(CallbackInfoReturnable<PlayerSkin> cir) {
|
||||||
|
GameProfile profile = ((AbstractClientPlayer) (Object) this).getGameProfile();
|
||||||
|
ResourceLocation animated = CapeManager.getCape(profile.getId());
|
||||||
|
if (animated == null) return;
|
||||||
|
PlayerSkin s = cir.getReturnValue();
|
||||||
|
if (s == null) return;
|
||||||
|
cir.setReturnValue(new PlayerSkin(
|
||||||
|
s.texture(), s.textureUrl(), animated, s.elytraTexture(), s.model(), s.secure()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package xyz.nightsync.skinsg.mixin;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.NativeImage;
|
||||||
|
import net.minecraft.client.renderer.texture.HttpTexture;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
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.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewrites the vanilla legacy-skin conversion so it scales from {@code s = w/8} instead of a fixed
|
||||||
|
* 64px grid, giving HD skins (up to 2048) the same 32->64 layer expansion and alpha fixes.
|
||||||
|
* Non-matching proportions are left to vanilla/other mods.
|
||||||
|
*
|
||||||
|
* @author Nghtly
|
||||||
|
*/
|
||||||
|
@Mixin(HttpTexture.class)
|
||||||
|
public abstract class SkinMagicMixin {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private static void setNoAlpha(NativeImage img, int x1, int y1, int x2, int y2) {}
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private static void doNotchTransparencyHack(NativeImage img, int x1, int y1, int x2, int y2) {}
|
||||||
|
|
||||||
|
@Inject(method = "processLegacySkin", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void skinsg$processLegacySkin(NativeImage image, CallbackInfoReturnable<@Nullable NativeImage> cir) {
|
||||||
|
final int h = image.getHeight();
|
||||||
|
final int w = image.getWidth();
|
||||||
|
|
||||||
|
final int s = w / 8;
|
||||||
|
final int x64 = s * 8;
|
||||||
|
final int x32 = s * 4;
|
||||||
|
final int x16 = s * 2;
|
||||||
|
final int x8 = s;
|
||||||
|
final int x4 = s / 2;
|
||||||
|
final int x12 = x8 + x4;
|
||||||
|
final int x48 = s * 6;
|
||||||
|
final int x44 = s * 5;
|
||||||
|
final int x52 = x48 + x4;
|
||||||
|
final int x48m4 = x48 - x4;
|
||||||
|
|
||||||
|
if (w != x64 || (h != x32 && h != x64)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean legacy = h == x32;
|
||||||
|
if (legacy) {
|
||||||
|
NativeImage newImg = new NativeImage(x64, x64, true);
|
||||||
|
newImg.copyFrom(image);
|
||||||
|
image.close();
|
||||||
|
image = newImg;
|
||||||
|
|
||||||
|
newImg.fillRect(0, x32, x64, x32, 0);
|
||||||
|
|
||||||
|
newImg.copyRect(x4, x16, x16, x32, x4, x4, true, false);
|
||||||
|
newImg.copyRect(x8, x16, x16, x32, x4, x4, true, false);
|
||||||
|
newImg.copyRect(0, x16 + x4 + x8, x16 + x8, x32, x4, x12, true, false);
|
||||||
|
newImg.copyRect(x4, x16 + x4 + x8, x16, x32, x4, x12, true, false);
|
||||||
|
newImg.copyRect(x8, x16 + x4 + x8, x8, x32, x4, x12, true, false);
|
||||||
|
newImg.copyRect(x12, x16 + x4 + x8, x16, x32, x4, x12, true, false);
|
||||||
|
|
||||||
|
newImg.copyRect(x48m4, x16, -x8, x32, x4, x4, true, false);
|
||||||
|
newImg.copyRect(x48, x16, -x8, x32, x4, x4, true, false);
|
||||||
|
|
||||||
|
newImg.copyRect(x44, x16 + x4 + x8, 0, x32, x4, x12, true, false);
|
||||||
|
newImg.copyRect(x48m4, x16 + x4 + x8, -x8, x32, x4, x12, true, false);
|
||||||
|
newImg.copyRect(x48, x16 + x4 + x8, -x16, x32, x4, x12, true, false);
|
||||||
|
newImg.copyRect(x52, x16 + x4 + x8, -x8, x32, x4, x12, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
setNoAlpha(image, 0, 0, x32, x16);
|
||||||
|
if (legacy) {
|
||||||
|
doNotchTransparencyHack(image, x32, 0, x64, x32);
|
||||||
|
}
|
||||||
|
setNoAlpha(image, 0, x16, x64, x32);
|
||||||
|
setNoAlpha(image, x16, x52 - x4, x52 - x4, x64);
|
||||||
|
|
||||||
|
cir.setReturnValue(image);
|
||||||
|
cir.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
modLoader="javafml"
|
||||||
|
loaderVersion="${loader_version_range}"
|
||||||
|
license="${mod_license}"
|
||||||
|
|
||||||
|
[[mods]]
|
||||||
|
modId="${mod_id}"
|
||||||
|
version="${mod_version}"
|
||||||
|
displayName="${mod_name}"
|
||||||
|
displayURL="https://git.mcbcorp.ru/Fiden/SkinsG"
|
||||||
|
authors="Nghtly"
|
||||||
|
description='''
|
||||||
|
HD skins (up to 2048x2048) and animated GIF capes, driven by a UUID-keyed asset API.
|
||||||
|
'''
|
||||||
|
|
||||||
|
[[mixins]]
|
||||||
|
config="${mod_id}.mixins.json"
|
||||||
|
|
||||||
|
[[dependencies.${mod_id}]]
|
||||||
|
modId="neoforge"
|
||||||
|
type="required"
|
||||||
|
versionRange="[21.1,)"
|
||||||
|
ordering="NONE"
|
||||||
|
side="CLIENT"
|
||||||
|
|
||||||
|
[[dependencies.${mod_id}]]
|
||||||
|
modId="minecraft"
|
||||||
|
type="required"
|
||||||
|
versionRange="${minecraft_version_range}"
|
||||||
|
ordering="NONE"
|
||||||
|
side="CLIENT"
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"compatibilityLevel": "JAVA_21",
|
||||||
|
"package": "xyz.nightsync.skinsg.mixin",
|
||||||
|
"refmap": "skinsg.refmap.json",
|
||||||
|
"client": [
|
||||||
|
"SkinMagicMixin",
|
||||||
|
"CapeMagicMixin"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user