Compare commits
389
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37db94649f | ||
|
|
896f4cccc0 | ||
|
|
de3c554e63 | ||
|
|
8417427059 | ||
|
|
ba5a32fb34 | ||
|
|
8b1c94151a | ||
|
|
3623024cce | ||
|
|
2dcbe0302e | ||
|
|
502bddd720 | ||
|
|
0c22fee8c0 | ||
|
|
f69f6eb883 | ||
|
|
cebd9aec96 | ||
|
|
2554a84950 | ||
|
|
49bbdff418 | ||
|
|
8995de9067 | ||
|
|
18b74212ca | ||
|
|
06190d0ef9 | ||
|
|
254a37d757 | ||
|
|
2b5bcf4098 | ||
|
|
4e00934353 | ||
|
|
c524451704 | ||
|
|
e26ce6d076 | ||
|
|
da3dfaee66 | ||
|
|
463335856f | ||
|
|
3315926f7c | ||
|
|
68d3fb6062 | ||
|
|
b108cc1f4a | ||
|
|
167010380e | ||
|
|
dd91f3844a | ||
|
|
b7cf3092da | ||
|
|
60afc12893 | ||
|
|
8677837a8f | ||
|
|
02f6cf7d71 | ||
|
|
85a46c0bba | ||
|
|
30f65bd914 | ||
|
|
bedb45c8aa | ||
|
|
1602520624 | ||
|
|
f69c379ae1 | ||
|
|
fbd0e23fb3 | ||
|
|
8dbb1d84c1 | ||
|
|
ab70c67a4f | ||
|
|
0a6aa90e23 | ||
|
|
22a7152f0d | ||
|
|
b5ca9dbc8f | ||
|
|
48118f6a84 | ||
|
|
771ed93992 | ||
|
|
a8e6f14022 | ||
|
|
84270c023a | ||
|
|
25a19d7951 | ||
|
|
c5665548a0 | ||
|
|
22142be7b5 | ||
|
|
a949c18ec1 | ||
|
|
6f122b5237 | ||
|
|
85e5ef3f59 | ||
|
|
0bf4fc6808 | ||
|
|
a44b4f4e90 | ||
|
|
f2d30e6611 | ||
|
|
242653054d | ||
|
|
95e4dff448 | ||
|
|
a30cf4d3ab | ||
|
|
eebfe8fa4d | ||
|
|
019e5cfb43 | ||
|
|
6ed2ac1b60 | ||
|
|
1853b09443 | ||
|
|
9126faa11c | ||
|
|
090e5132b2 | ||
|
|
bbe6d02568 | ||
|
|
04e7064790 | ||
|
|
ff0bce4d24 | ||
|
|
2ecb4f80ea | ||
|
|
41f9be8595 | ||
|
|
f73f7e733c | ||
|
|
91b53daac9 | ||
|
|
5bcdc72b83 | ||
|
|
3f0670ea9d | ||
|
|
c54b5ae6d7 | ||
|
|
14c16d8fe0 | ||
|
|
e3d1e4a442 | ||
|
|
04605f6855 | ||
|
|
451ac986c0 | ||
|
|
80d478d2c9 | ||
|
|
79719262a2 | ||
|
|
806c4ab643 | ||
|
|
6ee8b64a38 | ||
|
|
a97e5703c9 | ||
|
|
39f140dae1 | ||
|
|
632591f8d8 | ||
|
|
66e994b5ab | ||
|
|
1d56094388 | ||
|
|
69f572288f | ||
|
|
1a5c7f2a2c | ||
|
|
68734f6ac5 | ||
|
|
333c408d1b | ||
|
|
3c57328b3c | ||
|
|
08178b60fe | ||
|
|
4342233876 | ||
|
|
89cb467016 | ||
|
|
9488a8647e | ||
|
|
fa1d1f312a | ||
|
|
b359224ecd | ||
|
|
a909aa880a | ||
|
|
8f8fec0816 | ||
|
|
c2d20492c3 | ||
|
|
4a7eade70d | ||
|
|
6466d8d8fd | ||
|
|
7c72da978d | ||
|
|
76b842e6a0 | ||
|
|
00cefe14f7 | ||
|
|
2a3034be2c | ||
|
|
910633819a | ||
|
|
daddd0a005 | ||
|
|
cdd6ae8ec9 | ||
|
|
65c9454370 | ||
|
|
8a1e9b49bc | ||
|
|
f288f9148c | ||
|
|
e165f6b65c | ||
|
|
019730c756 | ||
|
|
7fa951b7fa | ||
|
|
b39b19f107 | ||
|
|
88db7a8383 | ||
|
|
d782bccb5f | ||
|
|
84947d6b33 | ||
|
|
f79849d9fb | ||
|
|
cb38639e11 | ||
|
|
8f567c83c6 | ||
|
|
8876abde1c | ||
|
|
2d95bf9043 | ||
|
|
0475d8c43d | ||
|
|
491199cfea | ||
|
|
5aa40d2e61 | ||
|
|
c5b6a858e1 | ||
|
|
e28051a109 | ||
|
|
1471e53a91 | ||
|
|
6ae4f980e4 | ||
|
|
6fbacbcae6 | ||
|
|
e934f24d3e | ||
|
|
191bc1318e | ||
|
|
249219fe57 | ||
|
|
5a86d4cb4a | ||
|
|
75a5d7f52a | ||
|
|
c078637d3d | ||
|
|
6c41e774ff | ||
|
|
c630a4e41a | ||
|
|
33956ea550 | ||
|
|
2e45cc39f7 | ||
|
|
c8860ab837 | ||
|
|
64ab091807 | ||
|
|
243275b414 | ||
|
|
70d7953b45 | ||
|
|
812e7bf593 | ||
|
|
e5c2d8bd36 | ||
|
|
670961acce | ||
|
|
b46410c43b | ||
|
|
2cd7db9ade | ||
|
|
3ba9079101 | ||
|
|
db1d31b1e3 | ||
|
|
d0e712a3c5 | ||
|
|
b86a2775a1 | ||
|
|
2d16da9dd5 | ||
|
|
9c0f9a1434 | ||
|
|
d58b0c90fd | ||
|
|
bf4cec4ea5 | ||
|
|
2d75ee4ee8 | ||
|
|
37569d069d | ||
|
|
f44647ba52 | ||
|
|
518c1d9d57 | ||
|
|
7caff20255 | ||
|
|
69698c16f7 | ||
|
|
3705afb593 | ||
|
|
ebe7200d65 | ||
|
|
b457f070b9 | ||
|
|
4f44274111 | ||
|
|
51c6108e35 | ||
|
|
3a71cd5b02 | ||
|
|
9424e2ec71 | ||
|
|
d50d19b609 | ||
|
|
bf280d945e | ||
|
|
0b469e6a5a | ||
|
|
57da2f1181 | ||
|
|
c771764251 | ||
|
|
a004585cba | ||
|
|
92a1f70eb1 | ||
|
|
1d0c582729 | ||
|
|
0f947b5115 | ||
|
|
8852856d45 | ||
|
|
f7a882b0ab | ||
|
|
35b127def2 | ||
|
|
13a5347412 | ||
|
|
ca235486bb | ||
|
|
89f29d5d0e | ||
|
|
99929c7d64 | ||
|
|
8836cc851b | ||
|
|
7849e2e04c | ||
|
|
0bf5bf030f | ||
|
|
21cc6936f7 | ||
|
|
5f225953c2 | ||
|
|
9fbeac628c | ||
|
|
df102fff84 | ||
|
|
d3cd883782 | ||
|
|
7ce54c8561 | ||
|
|
faa18c99ab | ||
|
|
a73b139256 | ||
|
|
02066bf380 | ||
|
|
925cd6d062 | ||
|
|
f45aa843e5 | ||
|
|
9f4b2f015d | ||
|
|
16b3936649 | ||
|
|
8b8104412c | ||
|
|
2bbabff979 | ||
|
|
39dc0963ce | ||
|
|
c37efa53b3 | ||
|
|
fe629b8bf5 | ||
|
|
a8e15b98dd | ||
|
|
1a71f055ff | ||
|
|
fa68fcad50 | ||
|
|
66e58b31c2 | ||
|
|
938429dca7 | ||
|
|
b9eb77f9e1 | ||
|
|
a9b331044f | ||
|
|
db22e99b0f | ||
|
|
290da45cde | ||
|
|
56e8cde0f9 | ||
|
|
6df7aacb56 | ||
|
|
c2f19ef3cf | ||
|
|
6ac91f10ab | ||
|
|
52930df0a9 | ||
|
|
ac9f765cb6 | ||
|
|
4962e0e4c3 | ||
|
|
020636d293 | ||
|
|
0f172ccbab | ||
|
|
635219a556 | ||
|
|
5e53a2e188 | ||
|
|
39b4b616b0 | ||
|
|
0471a007ce | ||
|
|
b60f218e29 | ||
|
|
67fb65dcf5 | ||
|
|
a6f3fd79b3 | ||
|
|
ab60119266 | ||
|
|
6a40d6b6f1 | ||
|
|
10a4868d8f | ||
|
|
01da8b8198 | ||
|
|
787ffd7bcb | ||
|
|
462b6fc462 | ||
|
|
97603f84ec | ||
|
|
fba84ebb9a | ||
|
|
edfe1d59c1 | ||
|
|
7b95f083e7 | ||
|
|
33c8945d42 | ||
|
|
4e029570d0 | ||
|
|
e5a418d7b2 | ||
|
|
b38e247bff | ||
|
|
59248ee520 | ||
|
|
1ec0b90f9b | ||
|
|
4dca80b6b1 | ||
|
|
2317d981b1 | ||
|
|
dbd096dfbf | ||
|
|
edef4f4893 | ||
|
|
9712bc0f47 | ||
|
|
e0d0571078 | ||
|
|
c467eb3b95 | ||
|
|
57f6ffa3d4 | ||
|
|
2df38b2962 | ||
|
|
f947fa5f17 | ||
|
|
9a8c9670c6 | ||
|
|
301b75c003 | ||
|
|
ceeb64282f | ||
|
|
d68e47d1cc | ||
|
|
b04014a87f | ||
|
|
8854726916 | ||
|
|
f182ac7e91 | ||
|
|
68a366a30b | ||
|
|
dfb3c6e614 | ||
|
|
6af6ecefad | ||
|
|
8039862142 | ||
|
|
b6f164b43b | ||
|
|
962d2c0319 | ||
|
|
12b4a4fc5f | ||
|
|
b99840a937 | ||
|
|
f9938a51e9 | ||
|
|
2fa04b079d | ||
|
|
c22a9ff5ae | ||
|
|
66024ebfa2 | ||
|
|
66e4a12819 | ||
|
|
216b1707ae | ||
|
|
bdc21920eb | ||
|
|
5d2a21dd69 | ||
|
|
7f5acb9daf | ||
|
|
7728c6e818 | ||
|
|
ea6d2958e7 | ||
|
|
04a4a1b226 | ||
|
|
b59c2ba705 | ||
|
|
4ddd650102 | ||
|
|
5f63f8b37a | ||
|
|
9110cbe722 | ||
|
|
c2144dcfc8 | ||
|
|
39d03c4ef6 | ||
|
|
d4107df833 | ||
|
|
196dd08943 | ||
|
|
199635be0b | ||
|
|
d82921976b | ||
|
|
8bfc3bc699 | ||
|
|
e348b94720 | ||
|
|
35df2b2b27 | ||
|
|
a577ee7796 | ||
|
|
8d528387db | ||
|
|
90db3d3915 | ||
|
|
4d7a79f517 | ||
|
|
5b8ce8f048 | ||
|
|
7fd5493995 | ||
|
|
7af945486c | ||
|
|
5bd0d249f9 | ||
|
|
0cd192107d | ||
|
|
3aa98d458d | ||
|
|
eca1be7d81 | ||
|
|
bdc22e87ae | ||
|
|
9b73e4d1c9 | ||
|
|
439dc2653e | ||
|
|
9fee71154e | ||
|
|
afedec45ae | ||
|
|
5544946769 | ||
|
|
debf9ce96d | ||
|
|
c93b0e049d | ||
|
|
6eb7fa4c8b | ||
|
|
a02653c5ab | ||
|
|
12bb846e50 | ||
|
|
58a38ad809 | ||
|
|
b9657d6f45 | ||
|
|
da27d820f7 | ||
|
|
e07ec5a54a | ||
|
|
27c5bafb6b | ||
|
|
3291dc1e6e | ||
|
|
7ada7ea3c8 | ||
|
|
fc87506965 | ||
|
|
0084457008 | ||
|
|
d874d5a388 | ||
|
|
53332157e3 | ||
|
|
e70c1423a4 | ||
|
|
9dbf431a55 | ||
|
|
0f41b2786c | ||
|
|
86d588ffc4 | ||
|
|
c19b92b242 | ||
|
|
8027b627d8 | ||
|
|
9c34198138 | ||
|
|
6226604fa5 | ||
|
|
98d5bf5ce5 | ||
|
|
9bf04639b3 | ||
|
|
e8671640e3 | ||
|
|
daf71b0e8c | ||
|
|
d2b016ddc7 | ||
|
|
4bb6cf8489 | ||
|
|
cd8a41524f | ||
|
|
68a43d55b9 | ||
|
|
8d3f283f4c | ||
|
|
2cd1e39ec5 | ||
|
|
45ceaf8b39 | ||
|
|
dc17e9aa44 | ||
|
|
bd9dc51578 | ||
|
|
1b3c23587d | ||
|
|
da24cc584b | ||
|
|
55b1814c1e | ||
|
|
98976ea745 | ||
|
|
e9f0a49389 | ||
|
|
e414bc2097 | ||
|
|
6711753bec | ||
|
|
076c3d67f8 | ||
|
|
6af269da11 | ||
|
|
b98fe211f0 | ||
|
|
c70ac16978 | ||
|
|
6ad563fd4a | ||
|
|
8be1bab1b6 | ||
|
|
a553360868 | ||
|
|
944bada2a2 | ||
|
|
8ed855723b | ||
|
|
5b9807c5d3 | ||
|
|
d9e5153452 | ||
|
|
92b310e5e2 | ||
|
|
02d973e4e4 | ||
|
|
2f41fc080c | ||
|
|
80684f7e07 | ||
|
|
e3ad918755 | ||
|
|
178fb1a484 | ||
|
|
2b0f1dcb48 | ||
|
|
154fbd774f | ||
|
|
a497d2a14f | ||
|
|
00af8c4cd7 | ||
|
|
3a922418ca | ||
|
|
96d7f5065c | ||
|
|
fb85702ee9 | ||
|
|
69cad4caab |
@@ -1,12 +0,0 @@
|
||||
<factorypath>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/io.github.llamalad7/mixinextras-fabric/0.4.1/8d1a9e96afb990367fa1f904d17580d164da72e3/mixinextras-fabric-0.4.1.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-analysis/9.7.1/f97a3b319f0ed6a8cd944dc79060d3912a28985f/asm-analysis-9.7.1.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/net.fabricmc/fabric-mixin-compile-extensions/0.6.0/6fda0c85c419f0a259da017a1424f27507eb30f0/fabric-mixin-compile-extensions-0.6.0.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/net.fabricmc/mapping-io/0.2.1/2a1aeedce104191bbb9e39e26abfbfeaf9b0590b/mapping-io-0.2.1.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-tree/9.7.1/3a53139787663b139de76b627fca0084ab60d32c/asm-tree-9.7.1.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/fabric-loom/1.21.4/net.fabricmc.yarn.1_21_4.1.21.4+build.7-v2/mappings.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.15.4+mixin.0.8.7/6a12aacc794f1078458433116e9ed42c1cc98096/sponge-mixin-0.15.4+mixin.0.8.7.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/9.7.1/f0ed132a49244b042cd0e15702ab9f2ce3cc8436/asm-9.7.1.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-util/9.7.1/9e23359b598ec6b74b23e53110dd5c577adf2243/asm-util-9.7.1.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="EXTJAR" id="/Users/klestiselimaj/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-commons/9.7.1/406c6a2225cfe1819f102a161e54cc16a5c24f75/asm-commons-9.7.1.jar" enabled="true" runInBatchMode="false"/>
|
||||
</factorypath>
|
||||
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env node
|
||||
// Publish the jars attached to a Gitea release to Modrinth.
|
||||
//
|
||||
// Creates one Modrinth version per jar (saturn-client-<version>+<mc>.jar), for
|
||||
// that Minecraft version, with Fabric API as a required dependency and the
|
||||
// Gitea release notes as the changelog. Versions that already exist on
|
||||
// Modrinth are skipped, so the script is safe to re-run.
|
||||
//
|
||||
// Runs on plain Node (>= 18: fetch, FormData, Blob) with no dependencies, since
|
||||
// every Gitea Actions runner has Node to run JavaScript actions.
|
||||
//
|
||||
// Environment:
|
||||
// TAG release tag, e.g. 0.1.1-beta
|
||||
// SERVER_URL public Gitea URL, e.g. https://git.selimaj.dev
|
||||
// REPO owner/name, e.g. saturnclientmc/saturnclient
|
||||
// MODRINTH_TOKEN Modrinth PAT with the "Create versions" scope
|
||||
// DRY_RUN "true" to check everything and print what would be
|
||||
// published without uploading (no token needed)
|
||||
|
||||
const MODRINTH_API = "https://api.modrinth.com/v2";
|
||||
const MODRINTH_PROJECT_ID = "i6JDSY9x"; // saturnclient
|
||||
const FABRIC_API_PROJECT_ID = "P7dR8mSH";
|
||||
const USER_AGENT =
|
||||
"saturnclientmc/saturnclient release workflow (https://git.selimaj.dev/saturnclientmc/saturnclient)";
|
||||
|
||||
const JAR_NAME = /^saturn-client-(?<version>.+)\+(?<mc>\d+\.\d+(?:\.\d+)?)\.jar$/;
|
||||
|
||||
function fail(message) {
|
||||
console.error(message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
async function http(url, options = {}) {
|
||||
const res = await fetch(url, {
|
||||
...options,
|
||||
headers: { "User-Agent": USER_AGENT, ...options.headers },
|
||||
});
|
||||
if (!res.ok) {
|
||||
const error = new Error(`${options.method ?? "GET"} ${url} returned ${res.status}: ${await res.text()}`);
|
||||
error.status = res.status;
|
||||
throw error;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
async function getJson(url) {
|
||||
return (await http(url)).json();
|
||||
}
|
||||
|
||||
function versionType(tag) {
|
||||
const t = tag.toLowerCase();
|
||||
if (t.includes("alpha")) return "alpha";
|
||||
if (t.includes("beta") || t.includes("rc") || t.includes("pre")) return "beta";
|
||||
return "release";
|
||||
}
|
||||
|
||||
function compareMc(a, b) {
|
||||
const pa = a.split(".").map(Number);
|
||||
const pb = b.split(".").map(Number);
|
||||
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
||||
const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
|
||||
if (diff !== 0) return diff;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const { TAG: tag, SERVER_URL, REPO: repo } = process.env;
|
||||
const serverUrl = (SERVER_URL ?? "").replace(/\/+$/, "");
|
||||
const dryRun = (process.env.DRY_RUN ?? "").toLowerCase() === "true";
|
||||
const token = process.env.MODRINTH_TOKEN ?? "";
|
||||
|
||||
if (!tag || !serverUrl || !repo) fail("TAG, SERVER_URL and REPO must be set.");
|
||||
if (!token && !dryRun) {
|
||||
fail("MODRINTH_TOKEN is not set. Add it as a repository secret (Settings → Actions → Secrets).");
|
||||
}
|
||||
|
||||
let release;
|
||||
try {
|
||||
release = await getJson(`${serverUrl}/api/v1/repos/${repo}/releases/tags/${encodeURIComponent(tag)}`);
|
||||
} catch (e) {
|
||||
if (e.status === 404) fail(`No Gitea release with tag ${tag}.`);
|
||||
throw e;
|
||||
}
|
||||
const changelog = release.body ?? "";
|
||||
|
||||
const jars = (release.assets ?? [])
|
||||
.map((asset) => ({ name: asset.name, match: JAR_NAME.exec(asset.name) }))
|
||||
.filter(({ match }) => match)
|
||||
.map(({ name, match }) => ({ name, version: match.groups.version, mc: match.groups.mc }))
|
||||
.sort((a, b) => compareMc(a.mc, b.mc));
|
||||
|
||||
if (jars.length === 0) fail(`Release ${tag} has no saturn-client-*.jar assets. Run the Release workflow first.`);
|
||||
|
||||
for (const jar of jars) {
|
||||
if (jar.version !== tag.replace(/^v/, "")) fail(`${jar.name} is version ${jar.version}, but the release tag is ${tag}.`);
|
||||
}
|
||||
|
||||
const knownGameVersions = new Set((await getJson(`${MODRINTH_API}/tag/game_version`)).map((g) => g.version));
|
||||
const unknown = [...new Set(jars.map((j) => j.mc))].filter((mc) => !knownGameVersions.has(mc));
|
||||
if (unknown.length > 0) fail(`Modrinth doesn't know these Minecraft versions: ${unknown.join(", ")}`);
|
||||
|
||||
const existing = new Set(
|
||||
(await getJson(`${MODRINTH_API}/project/${MODRINTH_PROJECT_ID}/version`)).map((v) => v.version_number),
|
||||
);
|
||||
const kind = versionType(tag);
|
||||
const failed = [];
|
||||
|
||||
for (const { name, version, mc } of jars) {
|
||||
const versionNumber = `${version}+${mc}`;
|
||||
|
||||
if (existing.has(versionNumber)) {
|
||||
console.log(`skip ${versionNumber}: already on Modrinth`);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Gitea's own download URLs use its internal ROOT_URL, so build a public one.
|
||||
const downloadUrl = `${serverUrl}/${repo}/releases/download/${encodeURIComponent(tag)}/${encodeURIComponent(name)}`;
|
||||
|
||||
const data = {
|
||||
project_id: MODRINTH_PROJECT_ID,
|
||||
name: `Saturn Client ${versionNumber}`,
|
||||
version_number: versionNumber,
|
||||
changelog,
|
||||
dependencies: [{ project_id: FABRIC_API_PROJECT_ID, dependency_type: "required" }],
|
||||
game_versions: [mc],
|
||||
version_type: kind,
|
||||
loaders: ["fabric"],
|
||||
featured: false,
|
||||
status: "listed",
|
||||
file_parts: ["file"],
|
||||
primary_file: "file",
|
||||
};
|
||||
|
||||
if (dryRun) {
|
||||
const probe = await http(downloadUrl, { headers: { Range: "bytes=0-0" } });
|
||||
await probe.arrayBuffer();
|
||||
console.log(`would publish ${versionNumber} (${kind}, Minecraft ${mc}) from ${downloadUrl} [reachable]`);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const jarBytes = await (await http(downloadUrl)).arrayBuffer();
|
||||
|
||||
const form = new FormData();
|
||||
form.append("data", JSON.stringify(data));
|
||||
form.append("file", new Blob([jarBytes], { type: "application/java-archive" }), name);
|
||||
|
||||
await http(`${MODRINTH_API}/version`, {
|
||||
method: "POST",
|
||||
headers: { Authorization: token },
|
||||
body: form,
|
||||
});
|
||||
console.log(`publish ${versionNumber}: done (${(jarBytes.byteLength / 1_000_000).toFixed(1)} MB)`);
|
||||
} catch (e) {
|
||||
console.error(`publish ${versionNumber}: FAILED ${e.message}`);
|
||||
failed.push(versionNumber);
|
||||
}
|
||||
}
|
||||
|
||||
if (failed.length > 0) fail(`Failed to publish: ${failed.join(", ")}`);
|
||||
}
|
||||
|
||||
main().catch((e) => fail(e.stack ?? String(e)));
|
||||
@@ -0,0 +1,33 @@
|
||||
name: Check
|
||||
|
||||
# Compiles every Minecraft version on pull requests, so a change that breaks
|
||||
# one version (e.g. a missed or bad port) fails before it's merged instead of
|
||||
# in the release build. Merges to master aren't re-checked: the PR already
|
||||
# checked that code.
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
compile:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
# The JDK comes from the runner's tool cache. `cache: gradle` stores Gradle's
|
||||
# dependencies, Loom's Minecraft cache and the build cache in the runner's
|
||||
# actions cache.
|
||||
- name: Set up Java 21
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 21
|
||||
cache: gradle
|
||||
|
||||
- name: Compile all versions
|
||||
run: |
|
||||
chmod +x gradlew
|
||||
# --continue reports every version that fails, not just the first.
|
||||
./gradlew compileJava --no-daemon --stacktrace --continue
|
||||
@@ -0,0 +1,36 @@
|
||||
name: Publish to Modrinth
|
||||
|
||||
# Publishes the jars already attached to a Gitea release (built by the Release
|
||||
# workflow) to Modrinth, one version per Minecraft version. Run it manually
|
||||
# after smoke-testing the release. It doesn't rebuild anything, and versions
|
||||
# already on Modrinth are skipped, so re-running is safe.
|
||||
#
|
||||
# Needs a MODRINTH_TOKEN repository secret: a Modrinth PAT with the
|
||||
# "Create versions" scope.
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: Tag of the Gitea release to publish
|
||||
required: true
|
||||
dry_run:
|
||||
description: Only check and print what would be published
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Publish to Modrinth
|
||||
env:
|
||||
TAG: ${{ inputs.tag }}
|
||||
DRY_RUN: ${{ inputs.dry_run }}
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
REPO: ${{ github.repository }}
|
||||
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
|
||||
# Node is always available on Gitea runners (it runs JavaScript actions).
|
||||
run: node .gitea/scripts/publish_modrinth.mjs
|
||||
@@ -0,0 +1,101 @@
|
||||
name: Release
|
||||
|
||||
# Publishing a release builds every Minecraft version and attaches the mod jars
|
||||
# to it. mod_version in gradle.properties is the source of truth: the release
|
||||
# tag must match it (a leading "v" is allowed), so bump mod_version in a PR
|
||||
# before tagging the release.
|
||||
#
|
||||
# To (re)attach jars to an existing release, run this workflow manually with
|
||||
# the release's tag.
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: Tag of the existing release to build and attach jars to
|
||||
required: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
TAG: ${{ github.event.release.tag_name || inputs.tag }}
|
||||
# The public address. Uploads go through the Cloudflare tunnel, which caps
|
||||
# request bodies at 100 MB, so each mod jar must stay under that.
|
||||
GITEA_API: ${{ github.server_url }}/api/v1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ env.TAG }}
|
||||
submodules: true
|
||||
|
||||
- name: Check tag matches mod_version
|
||||
run: |
|
||||
MOD_VERSION="$(sed -n 's/^mod_version=//p' gradle.properties | tr -d '[:space:]')"
|
||||
if [ "${TAG#v}" != "$MOD_VERSION" ]; then
|
||||
echo "::error::Release tag '$TAG' doesn't match mod_version '$MOD_VERSION' in gradle.properties. Bump mod_version to '${TAG#v}' on the release branch, or tag the release '$MOD_VERSION'." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Building Saturn Client $MOD_VERSION"
|
||||
|
||||
# The JDK comes from the runner's tool cache. `cache: gradle` stores Gradle's
|
||||
# dependencies, Loom's Minecraft cache and the build cache in the runner's
|
||||
# actions cache.
|
||||
- name: Set up Java 21
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 21
|
||||
cache: gradle
|
||||
|
||||
- name: Build all versions
|
||||
run: |
|
||||
chmod +x gradlew
|
||||
# buildAll remaps every Minecraft version (two at a time, to stay within the
|
||||
# Gradle heap) into build/allJars.
|
||||
./gradlew buildAll --no-daemon --stacktrace
|
||||
|
||||
- name: Upload jars to the release
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
REPO: ${{ github.repository }}
|
||||
run: |
|
||||
shopt -s nullglob
|
||||
jars=(build/allJars/*.jar)
|
||||
if [ ${#jars[@]} -eq 0 ]; then
|
||||
echo "No jars found in build/allJars" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Cloudflare in front of the server rejects uploads of 100 MB or more.
|
||||
for jar in "${jars[@]}"; do
|
||||
size=$(stat -c%s "$jar")
|
||||
if [ "$size" -ge 100000000 ]; then
|
||||
echo "::error::$(basename "$jar") is $((size / 1000000)) MB; uploads must be under 100 MB. Check what's taking space with: unzip -l \"$jar\" | sort -n" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Look the release up by tag so manual runs work too.
|
||||
RELEASE_ID="$(curl --fail-with-body -sS -H "Authorization: token $TOKEN" \
|
||||
"$GITEA_API/repos/$REPO/releases/tags/$TAG" \
|
||||
| grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)"
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
echo "No release found for tag $TAG" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for jar in "${jars[@]}"; do
|
||||
echo "Uploading $(basename "$jar") to release $TAG ($RELEASE_ID)"
|
||||
curl --fail-with-body -sS -X POST \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
-F "attachment=@$jar" \
|
||||
"$GITEA_API/repos/$REPO/releases/$RELEASE_ID/assets"
|
||||
echo
|
||||
done
|
||||
@@ -1,45 +0,0 @@
|
||||
name: Automate Gradlew Build
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: "21"
|
||||
check-latest: true
|
||||
|
||||
- name: Set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
with:
|
||||
gradle-home-cache-cleanup: false
|
||||
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
|
||||
- name: Build (release)
|
||||
run: ./gradlew clean build -x test --no-daemon --stacktrace
|
||||
|
||||
- name: Remove sources JARs
|
||||
run: |
|
||||
rm -f build/libs/*sources*.jar
|
||||
echo "Removed sources JARs from build/libs"
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: saturnclient-latest
|
||||
path: build/libs/saturnclient-*.jar
|
||||
if-no-files-found: error
|
||||
@@ -1,52 +0,0 @@
|
||||
name: Push Builds
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: "21"
|
||||
|
||||
- name: Set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
with:
|
||||
gradle-home-cache-cleanup: false
|
||||
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
|
||||
- name: Build
|
||||
run: ./gradlew clean build -x test --no-daemon --stacktrace
|
||||
|
||||
- name: Remove sources JARs
|
||||
run: |
|
||||
rm -f build/libs/*sources*.jar
|
||||
echo "Removed sources JARs from build/libs"
|
||||
|
||||
- name: Create timestamped JAR
|
||||
run: |
|
||||
TIMESTAMP=$(date -u +"%Y%m%d-%H%M%S")
|
||||
MAIN_JAR=$(ls build/libs/saturnclient-*.jar | head -1)
|
||||
cp "$MAIN_JAR" "saturnclient-${TIMESTAMP}.jar"
|
||||
echo "Created: saturnclient-${TIMESTAMP}.jar"
|
||||
|
||||
- name: Upload timestamped artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: saturnclient-${{ github.run_number }}
|
||||
path: saturnclient-*.jar
|
||||
if-no-files-found: error
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "common"]
|
||||
path = common
|
||||
url = https://git.selimaj.dev/saturnclientmc/common.git
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# Licenses
|
||||
|
||||
This project is under [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0), but a lot of code taken from other open source projects that are under other licenses that need to be mentioned due to legal reasons.
|
||||
This project is under [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0), but a lot of code taken from other open source projects that are under other licenses that need to be mentioned due to legal or ethical reasons.
|
||||
|
||||
| File | License |
|
||||
| --------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
|
||||
|
||||
@@ -1,19 +1,86 @@
|
||||
<p align="center">
|
||||
<img src="src/main/resources/assets/saturnclient/icon.png" alt="OSUI" width="150px"/>
|
||||
<img src="logo.png" alt="Saturn Client Logo" width="150px"/>
|
||||
</p>
|
||||
|
||||
<h1 align="center">Saturn Client</h1>
|
||||
|
||||
<p align="center">
|
||||
<b>Saturn Client is a free and open source Minecraft client</b>
|
||||
<b>A free and open-source Minecraft client.</b><br/>
|
||||
Built with performance, customization, and community in mind.
|
||||
</p>
|
||||
|
||||

|
||||
<p align="center">
|
||||
<img src="screenshot.png" alt="Saturn Client Screenshot"/>
|
||||
</p>
|
||||
|
||||
# Credits
|
||||
## About
|
||||
|
||||
- Cloak rendering: `IIpho3nix` & `Dhyan Blum`
|
||||
- Who Am I: `FokshaWasTaken`
|
||||
- Panorama: https://www.planetminecraft.com/texture-pack/minecraft-cavesand-cliffs-part-ii-main-menu-panorama/
|
||||
Saturn Client is a free, open-source Minecraft client designed to enhance the gameplay experience while staying lightweight and customizable.
|
||||
Our goal is to build a clean, optimized client that the community can contribute to and improve together.
|
||||
|
||||
If any of the code or assets are in your name and you want to remove them, please submit an issue, we are still in alpha to have any artists so we would also appreciate if you could help us make some cosmetics
|
||||
Saturn runs on Fabric and supports **Minecraft 1.21.4 to 1.21.11**, with one build per version. If something doesn't work on your version, please open an issue.
|
||||
|
||||
## Features
|
||||
|
||||
- Free cosmetics that don't require real money: cloaks, including animated ones, and hats
|
||||
- 18 built-in mods: Armor Display, Auto Sprint, Clock, Coordinates, Crosshair, Day Counter, FPS Display, Freelook, Fullbright, Health Display, Keystrokes, Nametags, No Fog, Ping Display, Speedometer, Status Effects, TPS Display and Zoom
|
||||
- Clean and modern UI with animations
|
||||
- Ongoing performance improvements
|
||||
- Open-source and community-driven
|
||||
|
||||
## Installation
|
||||
|
||||
1. Install [Fabric Loader](https://fabricmc.net/use/) and [Fabric API](https://modrinth.com/mod/fabric-api) for your Minecraft version.
|
||||
2. Download the Saturn Client jar for the same version from [Modrinth](https://modrinth.com/mod/saturnclient) or the [releases page](https://git.selimaj.dev/saturnclientmc/saturnclient/releases).
|
||||
3. Put it in your `mods` folder.
|
||||
|
||||
### Network use
|
||||
|
||||
For cosmetics, Saturn Client connects to the Saturn server (`saturn-server.selimaj.dev`). You're signed in the same way as on an online-mode Minecraft server: your client proves who you are to Mojang's session server, and the Saturn server asks Mojang to confirm it. **Your Minecraft access token is only ever sent to Mojang, never to the Saturn server.**
|
||||
|
||||
## Building from source
|
||||
|
||||
The version-independent code lives in the `common` submodule, so clone with submodules:
|
||||
|
||||
```sh
|
||||
git clone --recurse-submodules https://git.selimaj.dev/saturnclientmc/saturnclient.git
|
||||
cd saturnclient
|
||||
|
||||
./gradlew buildAll # every version → build/allJars/
|
||||
./gradlew :1.21.11:build # a single version
|
||||
./gradlew :1.21.11:runClient # launch a development client
|
||||
```
|
||||
|
||||
Building needs Java 21.
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome contributions of all kinds:
|
||||
|
||||
- Code improvements
|
||||
- Bug fixes
|
||||
- UI enhancements
|
||||
- Cosmetic designs
|
||||
- Suggestions and feedback
|
||||
|
||||
If you're an artist or designer interested in helping with cosmetics or visual assets, we'd love to collaborate.
|
||||
|
||||
Most features belong in `common`, which every Minecraft version shares. For code that differs between versions, see the [version guide](VERSION_GUIDE.md): it covers how the versions share one copy of the code with Stonecutter, writing version-specific code, and adding a new Minecraft version. Every pull request is compiled for all versions automatically.
|
||||
|
||||
## Credits
|
||||
|
||||
- **Cloak Rendering:** `IIpho3nix` & Saturn
|
||||
- **Who Am I:** `FokshaWasTaken`
|
||||
- **Panorama:**
|
||||
https://www.planetminecraft.com/texture-pack/minecraft-cavesand-cliffs-part-ii-main-menu-panorama/
|
||||
|
||||
If any code or assets belong to you and you would like them removed, please open an issue.
|
||||
We aim to properly credit all contributors and respect original creators of their respective art.
|
||||
|
||||
## License
|
||||
|
||||
Saturn Client is free and open-source under the **Apache-2.0** license.
|
||||
|
||||
<p align="center">
|
||||
Made with ❤️ by the Saturn Client team
|
||||
</p>
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# Version guide
|
||||
|
||||
How Saturn Client supports several Minecraft versions, and how to change or add one.
|
||||
|
||||
## Layout
|
||||
|
||||
Every supported Minecraft version (1.21.4 to 1.21.11) builds from one copy of the version-specific code with [Stonecutter](https://stonecutter.kikugie.dev/):
|
||||
|
||||
- `common/`: all version-independent code (mods, UI, cosmetics, the server client). It has no Minecraft dependency and reaches the game only through the interfaces in `org.saturnclient.common`.
|
||||
- `src/`: the version-specific code (providers, refs, mixins and the three mixin configs), one copy for every version. Where Minecraft's API differs between versions, the code goes behind version comments (see below).
|
||||
- `versions/<mc>/`: each version's `gradle.properties` (Minecraft, Yarn, Fabric Loader and Fabric API versions), plus its `build/` and `run/` folders. Each version is the Gradle project `:<mc>`.
|
||||
|
||||
`settings.gradle.kts` lists the versions in `stonecutterVersions`. The root `build.gradle.kts` builds each version, and `stonecutter.gradle.kts` configures the root project (shared repositories, the `common` wiring and `buildAll`). Loom's version is `loom_version` in the root `gradle.properties`.
|
||||
|
||||
## Version-specific code with Stonecutter
|
||||
|
||||
The code in `src/` is always plain Java for the **active** version (1.21.11, set in `stonecutter.gradle.kts`). Code for other versions sits in comments that Stonecutter swaps before building each version:
|
||||
|
||||
```java
|
||||
//? if >=1.21.9 {
|
||||
public void render(MatrixStack matrices, OrderedRenderCommandQueue queue, int light, PlayerEntityRenderState state, float limbAngle, float limbDistance) {
|
||||
//?} else
|
||||
//public void render(MatrixStack matrices, VertexConsumerProvider consumers, int light, PlayerEntityRenderState state, float limbAngle, float limbDistance) {
|
||||
```
|
||||
|
||||
A condition without braces covers the next line only. For several lines, use braces and wrap the inactive block in `/* … */`:
|
||||
|
||||
```java
|
||||
//? if >=1.21.11 {
|
||||
import net.minecraft.client.render.RenderLayers;
|
||||
import net.minecraft.client.render.RenderSetup;
|
||||
//?} else {
|
||||
/*import net.minecraft.client.render.RenderPhase.Textures;
|
||||
*///?}
|
||||
```
|
||||
|
||||
Stonecutter rewrites inactive code into its own layout when switching versions (a single inactive line becomes `//code`), so write it that way to begin with, or run a switch and a reset before committing.
|
||||
|
||||
When a newer version leaves something out that an older one implements, keep the older version's code behind a condition and mark the newer branch with a `TODO`, rather than dropping it for every version. The panorama in `SaturnScreenFabric.render` is an example. Search for `TODO` to find what newer versions still lack (tracked in #30), and remove the condition once a version gap is fixed.
|
||||
|
||||
A whole class that only exists for some versions (such as `MatrixStackMixin`, which only makes sense before 1.21.6's GUI rewrite) can keep an empty class body on the other versions. Before splitting a class like that, look for a hook that works on every version: nametags used to hook label rendering, which 1.21.9 changed, and now replace the name while the render state is built (`LivingEntityRendererMixin`), with no version condition at all. An empty mixin changes nothing, and it keeps the mixin configs the same for every version, since JSON can't hold version comments.
|
||||
|
||||
Inactive code sits inside a `/* … */` comment, so it can't contain `/* … */` comments itself: use `//` comments in code that's only active for some versions. For the same reason, don't nest multi-line version blocks; use `//?} else if <condition> {` for more than two version ranges, as in `PlayerEntityRendererMixin` and `SaturnRenderState`.
|
||||
|
||||
- `./gradlew "Set active project to <mc>"` (or the Stonecutter IntelliJ plugin) rewrites `src/` so that version's code is the uncommented one, for editing it in the IDE.
|
||||
- `./gradlew "Reset active project"` switches back to 1.21.11. **Run it before committing**, so `src/` is always committed with 1.21.11 active.
|
||||
- Each version's processed copy is compiled from `versions/<mc>/build/generated/stonecutter/`, which is also where to look when a non-active version fails to compile.
|
||||
|
||||
The `emotes` repository uses the same setup, and its `BentCubeRenderer` and `PlayerModelMixin` are small examples of version comments.
|
||||
|
||||
## Checking a change on every version
|
||||
|
||||
Since every version shares `src/`, a change applies to all of them at once. Code that uses the Minecraft API may still only compile on some, so build them all:
|
||||
|
||||
```sh
|
||||
./gradlew compileJava
|
||||
```
|
||||
|
||||
The **Check** workflow runs the same compile on every pull request, so a version a change doesn't compile on fails before merging. Mixins whose target changed fail at startup rather than at compile time, so launch the versions a change touches with `./gradlew :<mc>:runClient`.
|
||||
|
||||
For bigger changes, `./gradlew buildAll` builds every version's jar into `build/allJars/`.
|
||||
|
||||
## Adding a Minecraft version
|
||||
|
||||
1. Create `versions/<new>/gradle.properties` with `minecraft_version`, `yarn_mappings`, `loader_version` and `fabric_api_version` (copy 1.21.11's and change the values; they're listed at <https://fabricmc.net/develop>). Loom's version is shared, in the root `gradle.properties`.
|
||||
2. Add `<new>` to `stonecutterVersions` in `settings.gradle.kts`.
|
||||
3. Build it with `./gradlew :<new>:compileJava` and put what Minecraft changed behind version comments. Check the mixin configs in `src/main/resources/*.mixins.json` as well: a mixin whose target changed fails at startup, not at compile time, so launch it with `./gradlew :<new>:runClient`.
|
||||
4. The release workflow builds everything through `buildAll`, and "Publish to Modrinth" takes the game version from each jar's name, so neither needs changing.
|
||||
-193
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* ================================================================
|
||||
* Saturn Client - Fabric Mod Build Configuration
|
||||
* ================================================================
|
||||
*
|
||||
* This build file configures:
|
||||
* - Fabric Loom (Minecraft mod development)
|
||||
* - Dependency management
|
||||
* - Resource processing
|
||||
* - Java toolchain (Java 21)
|
||||
* - Publishing setup
|
||||
*
|
||||
* All version values are defined in gradle.properties.
|
||||
* ================================================================
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Fabric mod development plugin
|
||||
id 'fabric-loom' version '1.9-SNAPSHOT'
|
||||
|
||||
// Maven publishing support
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
/*
|
||||
* ================================================================
|
||||
* Project Metadata
|
||||
* ================================================================
|
||||
*/
|
||||
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
/*
|
||||
* ================================================================
|
||||
* Repositories
|
||||
* ================================================================
|
||||
* All dependency sources.
|
||||
*/
|
||||
repositories {
|
||||
// Fabric
|
||||
maven { url 'https://maven.fabricmc.net/' }
|
||||
|
||||
// JitPack (GitHub releases)
|
||||
maven { url 'https://jitpack.io' }
|
||||
|
||||
// Parchment mappings (if needed later)
|
||||
maven { url 'https://maven.parchmentmc.org' }
|
||||
|
||||
// Special Model Loader
|
||||
maven { name = "FelNull Maven"; url = "https://maven.felnull.dev" }
|
||||
|
||||
// Player Animation Library
|
||||
maven { name = "KosmX Maven"; url = 'https://maven.kosmx.dev/' }
|
||||
|
||||
// Central repository
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
/*
|
||||
* ================================================================
|
||||
* Dependencies
|
||||
* ================================================================
|
||||
*/
|
||||
dependencies {
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Minecraft Core
|
||||
// ─────────────────────────────────────────────
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
|
||||
// Yarn mappings (named mappings for dev environment)
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
|
||||
// Fabric Loader
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// Fabric API
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Rendering / Model Libraries
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
// Special Model Loader (included inside your mod jar)
|
||||
modApi "dev.felnull:special-model-loader:1.4.0+pre.1"
|
||||
include "dev.felnull:special-model-loader:1.4.0+pre.1"
|
||||
|
||||
// SVG Rendering Library
|
||||
include implementation("com.formdev:svgSalamander:1.1.4")
|
||||
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Animation
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
// Player Animation Library (bundled into your mod)
|
||||
include modImplementation(
|
||||
"dev.kosmx.player-anim:player-animation-lib-fabric:${project.player_anim}"
|
||||
)
|
||||
|
||||
// Optional: BendyLib (only if you directly use it)
|
||||
// include modRuntimeOnly(
|
||||
// "io.github.kosmx.bendy-lib:bendy-lib-fabric:${project.bendylib_version}"
|
||||
// )
|
||||
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// External Libraries
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
// Session Java (auth/session handling)
|
||||
include implementation("com.github.selimaj-dev:session-java:0.1.6")
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ================================================================
|
||||
* Resource Processing
|
||||
* ================================================================
|
||||
* Injects version values into fabric.mod.json.
|
||||
*/
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
inputs.property "minecraft_version", project.minecraft_version
|
||||
inputs.property "loader_version", project.loader_version
|
||||
filteringCharset "UTF-8"
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand(
|
||||
"version": project.version,
|
||||
"minecraft_version": project.minecraft_version,
|
||||
"loader_version": project.loader_version
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ================================================================
|
||||
* Java Configuration
|
||||
* ================================================================
|
||||
* Targeting Java 21.
|
||||
*/
|
||||
def targetJavaVersion = 21
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(targetJavaVersion)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ================================================================
|
||||
* Jar Packaging
|
||||
* ================================================================
|
||||
* Includes LICENSE and NOTICE inside the final jar.
|
||||
*/
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${project.archivesBaseName}" }
|
||||
}
|
||||
from("NOTICE") {
|
||||
rename { "${it}_${project.archivesBaseName}" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ================================================================
|
||||
* Publishing
|
||||
* ================================================================
|
||||
* Configured but no remote repository defined yet.
|
||||
*/
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Add publishing repository here when needed
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// Builds one Minecraft version from the shared src/. Stonecutter runs this for each version in
|
||||
// stonecutterVersions (settings.gradle.kts), with that version's versions/<v>/gradle.properties.
|
||||
plugins {
|
||||
id("net.fabricmc.fabric-loom-remap")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
val minecraftVersion = property("minecraft_version") as String
|
||||
val loaderVersion = property("loader_version") as String
|
||||
|
||||
version = "${property("mod_version")}+$minecraftVersion"
|
||||
group = property("maven_group") as String
|
||||
|
||||
base {
|
||||
archivesName = property("archives_base_name") as String
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft("com.mojang:minecraft:$minecraftVersion")
|
||||
mappings("net.fabricmc:yarn:${property("yarn_mappings")}:v2")
|
||||
modImplementation("net.fabricmc:fabric-loader:$loaderVersion")
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_version")}")
|
||||
|
||||
// Saturn's emote library (limb bending, Emotecraft emotes)
|
||||
include(modImplementation("org.saturnclient:emotes-fabric:${property("emotes_version")}+$minecraftVersion")!!)
|
||||
|
||||
implementation(project(":common"))
|
||||
|
||||
for (library in listOf(
|
||||
"dev.selimaj:session-java:0.2.0",
|
||||
"de.javagl:obj:0.4.0",
|
||||
"com.formdev:svgSalamander:1.1.4",
|
||||
"com.fasterxml.jackson.core:jackson-databind:2.17.0",
|
||||
"com.fasterxml.jackson.core:jackson-annotations:2.17.0",
|
||||
"com.fasterxml.jackson.core:jackson-core:2.17.0",
|
||||
)) {
|
||||
include(implementation(library)!!)
|
||||
}
|
||||
}
|
||||
|
||||
// Injects the version values into fabric.mod.json.
|
||||
tasks.processResources {
|
||||
val values = mapOf(
|
||||
"version" to project.version.toString(),
|
||||
"minecraft_version" to minecraftVersion,
|
||||
"loader_version" to loaderVersion,
|
||||
)
|
||||
inputs.properties(values)
|
||||
filteringCharset = "UTF-8"
|
||||
filesMatching("fabric.mod.json") { expand(values) }
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
java {
|
||||
// Loom attaches the sources jar to remapSourcesJar and build.
|
||||
withSourcesJar()
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
val archivesName = base.archivesName
|
||||
inputs.property("archivesName", archivesName)
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${archivesName.get()}" }
|
||||
}
|
||||
from(project(":common").extensions.getByType<SourceSetContainer>()["main"].output)
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
artifactId = property("archives_base_name") as String
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
}
|
||||
Submodule
+1
Submodule common added at b0d75af8c4
File diff suppressed because one or more lines are too long
+10
-13
@@ -1,18 +1,15 @@
|
||||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G -XX:+UseParallelGC
|
||||
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.parallel=true
|
||||
org.gradle.configureondemand=true
|
||||
# Reuse task outputs (e.g. compiled classes) when inputs haven't changed.
|
||||
org.gradle.caching=true
|
||||
|
||||
minecraft_version=1.21.4
|
||||
yarn_mappings=1.21.4+build.7
|
||||
loader_version=0.16.10
|
||||
fabric_version=0.114.0+1.21.4
|
||||
# IntelliJ IDEA is not yet fully compatible with configuration cache, see: https://github.com/FabricMC/fabric-loom/issues/1349
|
||||
org.gradle.configuration-cache=false
|
||||
|
||||
mod_version = 0.0.7-beta1
|
||||
maven_group = org.saturnclient
|
||||
archives_base_name = saturnclient
|
||||
mod_version=0.1.4-beta
|
||||
|
||||
player_anim = 2.0.3+1.21.4
|
||||
# Saturn's emote library (git.selimaj.dev/saturnclientmc/emotes)
|
||||
emotes_version=0.1.1
|
||||
|
||||
# Loom, for every Minecraft version (read in settings.gradle.kts).
|
||||
loom_version=1.17.21
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
# Copyright © 2015 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.
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
# gradlew start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
@@ -29,7 +29,7 @@
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
# ksh gradlew
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
@@ -57,7 +57,7 @@
|
||||
# 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
|
||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/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/.
|
||||
@@ -114,7 +114,6 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -172,7 +171,6 @@ fi
|
||||
# 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" )
|
||||
|
||||
@@ -212,8 +210,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
Vendored
+52
-34
@@ -19,12 +19,39 @@
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem gradlew startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||
setlocal EnableExtensions
|
||||
|
||||
@rem Catch executions from older scripts and ensure they exit cleanly.
|
||||
@rem This can be removed once we can be reasonably confident that few people
|
||||
@rem will be migrating directly to this new wrapper.
|
||||
goto afterSafetyNet
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
goto exitWithErrorLevel
|
||||
:afterSafetyNet
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@@ -45,13 +72,14 @@ 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
|
||||
1>&2 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.
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
goto exitWithErrorLevel
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
@@ -59,36 +87,26 @@ 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
|
||||
1>&2 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.
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
goto exitWithErrorLevel
|
||||
|
||||
: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 %*
|
||||
@rem Execute gradlew
|
||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||
@rem which allows us to clear the local environment before executing the java command
|
||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel
|
||||
|
||||
: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
|
||||
@rem This label must not be changed. We rely on old scripts being able to jump to this point.
|
||||
:exitWithErrorLevel
|
||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||
|
||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 591 KiB |
@@ -1,9 +0,0 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven("https://maven.fabricmc.net/")
|
||||
maven("https://maven.kikugie.dev/releases")
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
// Loom's version for build.gradle.kts, which can't read properties in its plugins block.
|
||||
val loom_version: String by settings
|
||||
plugins {
|
||||
id("net.fabricmc.fabric-loom-remap") version loom_version
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("dev.kikugie.stonecutter") version "0.9.8"
|
||||
}
|
||||
|
||||
rootProject.name = "saturn-client"
|
||||
|
||||
include("common")
|
||||
|
||||
// Versions built by Stonecutter from the shared src/ (see stonecutter.gradle.kts). Each one's
|
||||
// versions/<v>/gradle.properties holds its Minecraft, Yarn and Fabric API versions.
|
||||
val stonecutterVersions = listOf("1.21.4", "1.21.5", "1.21.6", "1.21.7", "1.21.8", "1.21.9", "1.21.10", "1.21.11")
|
||||
|
||||
stonecutter {
|
||||
create(rootProject) {
|
||||
versions(stonecutterVersions)
|
||||
vcsVersion = "1.21.11"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,539 @@
|
||||
package org.saturnclient.impl.cosmetics;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
import org.saturnclient.client.player.SaturnPlayer;
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.cosmetics.Cloaks;
|
||||
import org.saturnclient.emotes.core.Animation;
|
||||
import org.saturnclient.emotes.core.Bone;
|
||||
import org.saturnclient.emotes.core.bend.LimbBend;
|
||||
import org.saturnclient.emotes.core.bend.Vec3;
|
||||
import org.saturnclient.emotes.fabric.access.BendablePart;
|
||||
import org.saturnclient.impl.cosmetics.utils.ShaderUtils;
|
||||
import org.saturnclient.saturnclient.SaturnRenderState;
|
||||
|
||||
import net.minecraft.client.model.ModelPart;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
//? if >=1.21.9 {
|
||||
import net.minecraft.client.render.command.OrderedRenderCommandQueue;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.equipment.EquipmentModel;
|
||||
import net.minecraft.client.render.entity.equipment.EquipmentModelLoader;
|
||||
import net.minecraft.client.render.entity.equipment.EquipmentModel.LayerType;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.PlayerEntityModel;
|
||||
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.EquippableComponent;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.equipment.EquipmentAsset;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
* The cloak renderer
|
||||
* - **Efficient**: uses a image only consisting of the cloak texture, 16x8
|
||||
* whitespace.
|
||||
* - **Curving**: Curves when player velocity increases.
|
||||
* - **Wavey**: Makes the cloak feel like wind, when jump sprinting.
|
||||
*/
|
||||
public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
|
||||
private final EquipmentModelLoader equipmentModelLoader;
|
||||
private static final int PARTS = 24;
|
||||
private final float[] segmentValues = new float[PARTS];
|
||||
private static final int H_PARTS = 6;
|
||||
private float horizontalCurve = 0.0f;
|
||||
|
||||
private static final float TEX_W = 176f;
|
||||
private static final float TEX_H = 138f;
|
||||
|
||||
private static final class PxRect {
|
||||
final int x, y, w, h;
|
||||
|
||||
PxRect(int x, int y, int w, int h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
float u1() {
|
||||
return x / TEX_W;
|
||||
}
|
||||
|
||||
float v1() {
|
||||
return y / TEX_H;
|
||||
}
|
||||
|
||||
float u2() {
|
||||
return (x + w) / TEX_W;
|
||||
}
|
||||
|
||||
float v2() {
|
||||
return (y + h) / TEX_H;
|
||||
}
|
||||
}
|
||||
|
||||
private static final PxRect FRONT_RECT = new PxRect(8, 8, 80, 128);
|
||||
private static final PxRect BACK_RECT = new PxRect(96, 8, 80, 128);
|
||||
private static final PxRect LEFT_EDGE_RECT = new PxRect(0, 8, 8, 128);
|
||||
private static final PxRect RIGHT_EDGE_RECT = new PxRect(88, 8, 8, 128);
|
||||
private static final PxRect TOP_RECT = new PxRect(8, 0, 80, 8);
|
||||
private static final PxRect BOTTOM_RECT = new PxRect(88, 0, 80, 8);
|
||||
|
||||
public CloakFeatureRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context,
|
||||
EquipmentModelLoader equipmentModelLoader) {
|
||||
super(context);
|
||||
this.equipmentModelLoader = equipmentModelLoader;
|
||||
Arrays.fill(segmentValues, 0.0f);
|
||||
}
|
||||
|
||||
private boolean hasCustomModelForLayer(ItemStack stack, EquipmentModel.LayerType layerType) {
|
||||
EquippableComponent equippableComponent = (EquippableComponent) stack
|
||||
.get(DataComponentTypes.EQUIPPABLE);
|
||||
if (equippableComponent != null && !equippableComponent.assetId().isEmpty()) {
|
||||
EquipmentModel equipmentModel = this.equipmentModelLoader
|
||||
.get((RegistryKey<EquipmentAsset>) equippableComponent.assetId().get());
|
||||
return !equipmentModel.getLayers(layerType).isEmpty();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void vertex(VertexConsumer vc, Matrix4f posMat, Matrix3f normalMat,
|
||||
Vec3d pos, int color,
|
||||
float u, float v, int overlay, int light,
|
||||
float nx, float ny, float nz) {
|
||||
|
||||
Vector4f p = new Vector4f((float) pos.x, (float) pos.y, (float) pos.z, 1.0f);
|
||||
p.mul(posMat);
|
||||
|
||||
Vector3f n = new Vector3f(nx, ny, nz);
|
||||
n.mul(normalMat);
|
||||
|
||||
vc.vertex(
|
||||
p.x(), p.y(), p.z(),
|
||||
color,
|
||||
u, v,
|
||||
overlay, light,
|
||||
n.x(), n.y(), n.z());
|
||||
}
|
||||
|
||||
private void renderCapeQuad(VertexConsumer vertexConsumer, MatrixStack.Entry entry,
|
||||
Vec3d bottomLeft, Vec3d bottomRight, Vec3d topRight, Vec3d topLeft,
|
||||
float u1, float v1, float u2, float v2, int light, int overlay,
|
||||
float normalX, float normalY, float normalZ, boolean flipWinding) {
|
||||
// Extract matrix (you must transform positions manually now)
|
||||
Matrix4f pos = entry.getPositionMatrix();
|
||||
Matrix3f normalMat = entry.getNormalMatrix();
|
||||
|
||||
int color = 0xFFFFFFFF; // white RGBA
|
||||
|
||||
if (!flipWinding) {
|
||||
// CCW
|
||||
vertex(vertexConsumer, pos, normalMat, bottomLeft, color, u1, v2, overlay, light, normalX, normalY,
|
||||
normalZ);
|
||||
vertex(vertexConsumer, pos, normalMat, bottomRight, color, u2, v2, overlay, light, normalX, normalY,
|
||||
normalZ);
|
||||
vertex(vertexConsumer, pos, normalMat, topRight, color, u2, v1, overlay, light, normalX, normalY, normalZ);
|
||||
vertex(vertexConsumer, pos, normalMat, topLeft, color, u1, v1, overlay, light, normalX, normalY, normalZ);
|
||||
} else {
|
||||
// CW
|
||||
vertex(vertexConsumer, pos, normalMat, topLeft, color, u1, v1, overlay, light, normalX, normalY, normalZ);
|
||||
vertex(vertexConsumer, pos, normalMat, topRight, color, u2, v1, overlay, light, normalX, normalY, normalZ);
|
||||
vertex(vertexConsumer, pos, normalMat, bottomRight, color, u2, v2, overlay, light, normalX, normalY,
|
||||
normalZ);
|
||||
vertex(vertexConsumer, pos, normalMat, bottomLeft, color, u1, v2, overlay, light, normalX, normalY,
|
||||
normalZ);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderCape(MatrixStack.Entry entry, VertexConsumer vertexConsumer,
|
||||
PlayerEntityRenderState playerState, int light, int overlay) {
|
||||
|
||||
float capeWidth = 10.0f / 16.0f;
|
||||
float capeHeight = 16.0f / 16.0f;
|
||||
float capeDepth = 1.0f / 16.0f;
|
||||
|
||||
final float frontU1 = FRONT_RECT.u1();
|
||||
final float frontU2 = FRONT_RECT.u2();
|
||||
final float frontV1 = FRONT_RECT.v1();
|
||||
final float frontV2 = FRONT_RECT.v2();
|
||||
final float frontPartV = (frontV2 - frontV1) / PARTS;
|
||||
|
||||
final float backU1 = BACK_RECT.u1();
|
||||
final float backU2 = BACK_RECT.u2();
|
||||
final float backV1 = BACK_RECT.v1();
|
||||
final float backV2 = BACK_RECT.v2();
|
||||
final float backPartV = (backV2 - backV1) / PARTS;
|
||||
|
||||
final float leftU1 = LEFT_EDGE_RECT.u1();
|
||||
final float leftU2 = LEFT_EDGE_RECT.u2();
|
||||
final float leftV1 = LEFT_EDGE_RECT.v1();
|
||||
final float leftV2 = LEFT_EDGE_RECT.v2();
|
||||
final float leftPartV = (leftV2 - leftV1) / PARTS;
|
||||
|
||||
final float rightU1 = RIGHT_EDGE_RECT.u1();
|
||||
final float rightU2 = RIGHT_EDGE_RECT.u2();
|
||||
final float rightV1 = RIGHT_EDGE_RECT.v1();
|
||||
final float rightV2 = RIGHT_EDGE_RECT.v2();
|
||||
final float rightPartV = (rightV2 - rightV1) / PARTS;
|
||||
|
||||
final float topU1 = TOP_RECT.u1();
|
||||
final float topU2 = TOP_RECT.u2();
|
||||
final float topV1 = TOP_RECT.v1();
|
||||
final float topV2 = TOP_RECT.v2();
|
||||
|
||||
final float bottomU1 = BOTTOM_RECT.u1();
|
||||
final float bottomU2 = BOTTOM_RECT.u2();
|
||||
final float bottomV1 = BOTTOM_RECT.v1();
|
||||
final float bottomV2 = BOTTOM_RECT.v2();
|
||||
|
||||
// =============================
|
||||
// 1. Spine
|
||||
// =============================
|
||||
|
||||
float[] spineY = new float[PARTS + 1];
|
||||
float[] spineZ = new float[PARTS + 1];
|
||||
|
||||
float partHeight = capeHeight / PARTS;
|
||||
|
||||
for (int i = 0; i < PARTS; i++) {
|
||||
float angle = (2.0f - segmentValues[i]) * ((float) Math.PI / 2f);
|
||||
float dirY = -(float) Math.cos(angle);
|
||||
float dirZ = (float) Math.sin(angle);
|
||||
|
||||
spineY[i + 1] = spineY[i] + dirY * partHeight;
|
||||
spineZ[i + 1] = spineZ[i] + dirZ * partHeight;
|
||||
}
|
||||
|
||||
// =============================
|
||||
// 2. Grid
|
||||
// =============================
|
||||
|
||||
Vec3d[][] inner = new Vec3d[H_PARTS + 1][PARTS + 1];
|
||||
Vec3d[][] outer = new Vec3d[H_PARTS + 1][PARTS + 1];
|
||||
|
||||
for (int x = 0; x <= H_PARTS; x++) {
|
||||
|
||||
float t = (float) x / H_PARTS;
|
||||
float xPos = -capeWidth / 2.0f + capeWidth * t;
|
||||
|
||||
float centered = t - 0.5f;
|
||||
float curve = (centered * centered) * 0.3f;
|
||||
float zCurve = (curve * horizontalCurve) / PARTS;
|
||||
|
||||
for (int i = 0; i <= PARTS; i++) {
|
||||
float y = spineY[i];
|
||||
float z = spineZ[i];
|
||||
|
||||
int idx = Math.min(i, PARTS - 1);
|
||||
// angle: 0 is horizontal (y-flat), PI/2 is vertical (z-flat)
|
||||
float angle = (2.0f - segmentValues[idx]) * ((float) Math.PI / 2f);
|
||||
|
||||
float cosA = (float) Math.cos(angle);
|
||||
float sinA = (float) Math.sin(angle);
|
||||
|
||||
// Calculate how much the horizontal curve shifts the vertex
|
||||
float currentCurve = zCurve * i;
|
||||
|
||||
// Rotate the curve offset so it aligns with the cape's tilt
|
||||
float curveY = sinA * currentCurve;
|
||||
float curveZ = cosA * currentCurve;
|
||||
|
||||
float thickY = sinA * capeDepth;
|
||||
float thickZ = cosA * capeDepth;
|
||||
|
||||
inner[x][i] = new Vec3d(xPos, y - curveY, z - curveZ);
|
||||
outer[x][i] = new Vec3d(xPos, (y - curveY) - thickY, (z - curveZ) - thickZ);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =============================
|
||||
// 3. Front + Back
|
||||
// =============================
|
||||
|
||||
for (int x = 0; x < H_PARTS; x++) {
|
||||
|
||||
float uStart = frontU1 + (frontU2 - frontU1) * (1.0f - ((float) x / H_PARTS));
|
||||
float uEnd = frontU1 + (frontU2 - frontU1) * (1.0f - ((float) (x + 1) / H_PARTS));
|
||||
|
||||
float buStart = backU1 + (backU2 - backU1) * ((float) x / H_PARTS);
|
||||
float buEnd = backU1 + (backU2 - backU1) * ((float) (x + 1) / H_PARTS);
|
||||
|
||||
for (int i = 0; i < PARTS; i++) {
|
||||
|
||||
float vStart = frontV1 + frontPartV * i;
|
||||
float vEnd = frontV1 + frontPartV * (i + 1);
|
||||
|
||||
float bvStart = backV1 + backPartV * i;
|
||||
float bvEnd = backV1 + backPartV * (i + 1);
|
||||
|
||||
Vec3d innerTL = inner[x + 1][i];
|
||||
Vec3d innerTR = inner[x][i];
|
||||
Vec3d innerBL = inner[x + 1][i + 1];
|
||||
Vec3d innerBR = inner[x][i + 1];
|
||||
|
||||
Vec3d outerTL = outer[x + 1][i];
|
||||
Vec3d outerTR = outer[x][i];
|
||||
Vec3d outerBL = outer[x + 1][i + 1];
|
||||
Vec3d outerBR = outer[x][i + 1];
|
||||
|
||||
// FRONT
|
||||
renderCapeQuad(vertexConsumer, entry,
|
||||
outerBR, outerBL, outerTL, outerTR,
|
||||
uStart, vStart, uEnd, vEnd,
|
||||
light, overlay, 0, 0, 1, false);
|
||||
|
||||
// BACK
|
||||
renderCapeQuad(vertexConsumer, entry,
|
||||
innerBL, innerBR, innerTR, innerTL,
|
||||
buEnd, bvStart, buStart, bvEnd,
|
||||
light, overlay, 0, 0, -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
// =============================
|
||||
// 4. LEFT SIDE (x = H_PARTS)
|
||||
// =============================
|
||||
|
||||
for (int i = 0; i < PARTS; i++) {
|
||||
|
||||
Vec3d innerTop = inner[H_PARTS][i];
|
||||
Vec3d innerBot = inner[H_PARTS][i + 1];
|
||||
Vec3d outerTop = outer[H_PARTS][i];
|
||||
Vec3d outerBot = outer[H_PARTS][i + 1];
|
||||
|
||||
float vStart = leftV1 + leftPartV * i;
|
||||
float vEnd = leftV1 + leftPartV * (i + 1);
|
||||
|
||||
renderCapeQuad(vertexConsumer, entry,
|
||||
innerTop, outerTop, outerBot, innerBot,
|
||||
leftU1, vEnd,
|
||||
leftU2, vStart,
|
||||
light, overlay, -1, 0, 0, false);
|
||||
}
|
||||
|
||||
// =============================
|
||||
// 5. RIGHT SIDE (x = 0)
|
||||
// =============================
|
||||
|
||||
for (int i = 0; i < PARTS; i++) {
|
||||
|
||||
Vec3d innerTop = inner[0][i];
|
||||
Vec3d innerBot = inner[0][i + 1];
|
||||
Vec3d outerTop = outer[0][i];
|
||||
Vec3d outerBot = outer[0][i + 1];
|
||||
|
||||
float vStart = rightV1 + rightPartV * i;
|
||||
float vEnd = rightV1 + rightPartV * (i + 1);
|
||||
|
||||
renderCapeQuad(vertexConsumer, entry,
|
||||
outerTop, innerTop, innerBot, outerBot,
|
||||
rightU1, vEnd,
|
||||
rightU2, vStart,
|
||||
light, overlay, 1, 0, 0, false);
|
||||
}
|
||||
|
||||
// =============================
|
||||
// 6. TOP (i = 0)
|
||||
// =============================
|
||||
|
||||
for (int x = 0; x < H_PARTS; x++) {
|
||||
|
||||
Vec3d outerL = outer[x][0];
|
||||
Vec3d outerR = outer[x + 1][0];
|
||||
Vec3d innerR = inner[x + 1][0];
|
||||
Vec3d innerL = inner[x][0];
|
||||
|
||||
float uStart = topU1 + (topU2 - topU1) * ((float) x / H_PARTS);
|
||||
float uEnd = topU1 + (topU2 - topU1) * ((float) (x + 1) / H_PARTS);
|
||||
|
||||
renderCapeQuad(vertexConsumer, entry,
|
||||
outerL, outerR, innerR, innerL,
|
||||
uStart, topV1, uEnd, topV2,
|
||||
light, overlay, 0, 1, 0, false);
|
||||
}
|
||||
|
||||
// =============================
|
||||
// 7. BOTTOM (i = PARTS)
|
||||
// =============================
|
||||
|
||||
for (int x = 0; x < H_PARTS; x++) {
|
||||
|
||||
Vec3d innerL = inner[x][PARTS];
|
||||
Vec3d innerR = inner[x + 1][PARTS];
|
||||
Vec3d outerR = outer[x + 1][PARTS];
|
||||
Vec3d outerL = outer[x][PARTS];
|
||||
|
||||
float uStart = bottomU1 + (bottomU2 - bottomU1) * ((float) x / H_PARTS);
|
||||
float uEnd = bottomU1 + (bottomU2 - bottomU1) * ((float) (x + 1) / H_PARTS);
|
||||
|
||||
renderCapeQuad(vertexConsumer, entry,
|
||||
innerL, innerR, outerR, outerL,
|
||||
uStart, bottomV1, uEnd, bottomV2,
|
||||
light, overlay, 0, -1, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
/** A torso bend past this curves the back more than a flat cloak can follow. */
|
||||
private static final float MAX_CLOAK_BEND = (float) Math.toRadians(10);
|
||||
/** Whether each animation bends the torso past that at any point. */
|
||||
private static final Map<Animation, Boolean> BENDS_TORSO = Collections.synchronizedMap(new WeakHashMap<>());
|
||||
|
||||
/**
|
||||
* Whether the player is playing an emote that curves the torso (a twerk, the griddy). The cloak
|
||||
* would cut through the arched back, so it's hidden for the whole emote rather than only while
|
||||
* the back is curved, which would flicker.
|
||||
*/
|
||||
private static boolean playingTorsoBend(SaturnPlayer player) {
|
||||
return org.saturnclient.emotes.fabric.Emotes.playing(player.uuid)
|
||||
.map(playing -> BENDS_TORSO.computeIfAbsent(playing.animation(), CloakFeatureRenderer::bendsTorso))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
private static boolean bendsTorso(Animation animation) {
|
||||
for (float tick = 0; tick <= animation.length(); tick += 0.5f) {
|
||||
if (animation.sample(tick).get(Bone.BODY).filter(body -> Math.abs(body.bend()) > MAX_CLOAK_BEND).isPresent()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* An emote that bends the torso a little leans the chest from the hips, so the cloak hangs from
|
||||
* where the top of the back ends up, turned as much as the torso is there.
|
||||
*/
|
||||
private static void followBend(MatrixStack matrices, ModelPart body) {
|
||||
LimbBend bend = ((BendablePart) (Object) body).saturnEmotes$getBend();
|
||||
if (bend == null || bend.isStraight()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The top of the torso, in the body's own pixels
|
||||
float[] top = new float[3];
|
||||
bend.bendPoint(0, 0, 0, top);
|
||||
matrices.translate(top[0] / 16.0f, top[1] / 16.0f, top[2] / 16.0f);
|
||||
|
||||
Vec3 axis = bend.axis();
|
||||
matrices.multiply(new Quaternionf().rotationAxis(bend.angleAt(0), axis.x(), axis.y(), axis.z()));
|
||||
}
|
||||
|
||||
// Shift array left and insert new value at the start
|
||||
private void updateSegmentValues(float value) {
|
||||
// Shift all elements one position to the right (from end to start)
|
||||
for (int i = segmentValues.length - 1; i > 0; i--) {
|
||||
segmentValues[i] = segmentValues[i - 1];
|
||||
}
|
||||
|
||||
// Insert the new value at index 0
|
||||
segmentValues[0] = value;
|
||||
}
|
||||
|
||||
private long lastUpdate = 0;
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices,
|
||||
//? if >=1.21.9 {
|
||||
OrderedRenderCommandQueue output,
|
||||
//?} else
|
||||
//VertexConsumerProvider output,
|
||||
int light, PlayerEntityRenderState state, float limbAngle, float limbDistance) {
|
||||
if (state.invisible || !state.capeVisible
|
||||
//? if >=1.21.9 {
|
||||
|| state.skinTextures.cape() != null) {
|
||||
//?} else
|
||||
//|| state.skinTextures.capeTexture() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//? if >=1.21.8 {
|
||||
SaturnPlayer player = state.getData(SaturnRenderState.saturnDataKey);
|
||||
//?} else
|
||||
//SaturnPlayer player = SaturnPlayer.get(state.name);
|
||||
|
||||
if (player == null || playingTorsoBend(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
IdentifierRef customCape = Cloaks.getCurrentCloakTexture(player.cloak);
|
||||
if (customCape == null
|
||||
|| this.hasCustomModelForLayer(state.equippedChestStack, LayerType.WINGS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int minBrightness = 7;
|
||||
int blockLight = (light >> 4) & 0xF;
|
||||
int skyLight = (light >> 20) & 0xF;
|
||||
blockLight = Math.max(blockLight, minBrightness);
|
||||
|
||||
skyLight = Math.max(skyLight, minBrightness);
|
||||
light = (skyLight << 20) | (blockLight << 4);
|
||||
|
||||
matrices.push();
|
||||
|
||||
// On the back: the whole player (which emotes like the backflip turn), then the body's position
|
||||
// and turn (which crouching and emotes move), then the chest's lean when an emote bends the torso
|
||||
PlayerEntityModel model = this.getContextModel();
|
||||
//? if >=1.21.5 {
|
||||
model.getRootPart().applyTransform(matrices);
|
||||
model.body.applyTransform(matrices);
|
||||
//?} else {
|
||||
/*model.getRootPart().rotate(matrices);
|
||||
model.body.rotate(matrices);
|
||||
*///?}
|
||||
followBend(matrices, model.body);
|
||||
|
||||
matrices.translate(0.0f, 0.0f, 0.12f);
|
||||
|
||||
if (this.hasCustomModelForLayer(state.equippedChestStack, LayerType.HUMANOID)) {
|
||||
matrices.translate(0.0F, -0.053125F, 0.06875F);
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastUpdate >= 20) {
|
||||
float velX = Math.min(0.8f, state.field_53537 / 108.0f);
|
||||
float rawVelY = state.field_53536;
|
||||
float velY = (rawVelY > 3.4f ? rawVelY : rawVelY < -3.4f ? rawVelY : 0.0f) / 16;
|
||||
|
||||
float value = Math.max(0.0f, Math.min(2.0f, state.isSwimming ? 0.0f : velX + velY));
|
||||
|
||||
if (Config.cloakPhysics.value) {
|
||||
updateSegmentValues(segmentValues[0] + (value - segmentValues[0]) * 0.3f);
|
||||
} else {
|
||||
Arrays.fill(segmentValues, segmentValues[0] + (value - segmentValues[0]) * 0.05f);
|
||||
}
|
||||
lastUpdate = now;
|
||||
}
|
||||
|
||||
final int l = light;
|
||||
|
||||
horizontalCurve = MathHelper.clamp(state.field_53537 / 150.0f, -1.0f, 1.0f);
|
||||
|
||||
//? if >=1.21.9 {
|
||||
output.submitCustom(matrices, ShaderUtils.getRenderLayer(customCape), (entry, vertexConsumer) -> {
|
||||
renderCape(entry, vertexConsumer, state, l, OverlayTexture.DEFAULT_UV);
|
||||
});
|
||||
//?} else
|
||||
//renderCape(matrices.peek(), output.getBuffer(ShaderUtils.getRenderLayer(customCape)), state, l, OverlayTexture.DEFAULT_UV);
|
||||
|
||||
matrices.pop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.saturnclient.impl.cosmetics;
|
||||
|
||||
import org.saturnclient.client.player.SaturnPlayer;
|
||||
import org.saturnclient.impl.cosmetics.obj.MtlLoader;
|
||||
import org.saturnclient.impl.cosmetics.obj.ObjModel;
|
||||
import org.saturnclient.saturnclient.SaturnRenderState;
|
||||
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
//? if >=1.21.9 {
|
||||
import net.minecraft.client.render.command.OrderedRenderCommandQueue;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.PlayerEntityModel;
|
||||
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
public class HatFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
|
||||
public HatFeatureRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices,
|
||||
//? if >=1.21.9 {
|
||||
OrderedRenderCommandQueue output,
|
||||
//?} else
|
||||
//VertexConsumerProvider output,
|
||||
int light, PlayerEntityRenderState state, float limbAngle, float limbDistance) {
|
||||
//? if >=1.21.8 {
|
||||
SaturnPlayer player = state.getData(SaturnRenderState.saturnDataKey);
|
||||
//?} else
|
||||
//SaturnPlayer player = SaturnPlayer.get(state.name);
|
||||
|
||||
if (state.invisible || player == null || player.hat.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
matrices.push();
|
||||
|
||||
// On the head, as vanilla places head items: the whole player (which emotes like the backflip
|
||||
// turn), then the head's position, turn and scale (which crouching and emotes move)
|
||||
PlayerEntityModel model = this.getContextModel();
|
||||
//? if >=1.21.5 {
|
||||
model.getRootPart().applyTransform(matrices);
|
||||
model.head.applyTransform(matrices);
|
||||
//?} else {
|
||||
/*model.getRootPart().rotate(matrices);
|
||||
model.head.rotate(matrices);
|
||||
*///?}
|
||||
|
||||
ObjModel.cosmetic("hat", player.hat).render(MtlLoader.cosmetic(player.hat),
|
||||
matrices, output, light,
|
||||
OverlayTexture.DEFAULT_UV);
|
||||
|
||||
matrices.pop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.saturnclient.impl.cosmetics.obj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import de.javagl.obj.*;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class MtlLoader {
|
||||
static Map<Identifier, Map<String, Mtl>> loadedMtls = new HashMap<>();
|
||||
|
||||
static Map<String, Mtl> loadMtl(Identifier mtlId) throws IOException {
|
||||
try (InputStream is = MinecraftClient.getInstance().getResourceManager()
|
||||
.getResource(mtlId).get().getInputStream()) {
|
||||
List<Mtl> mtlList = MtlReader.read(is);
|
||||
Map<String, Mtl> mtlMap = new java.util.LinkedHashMap<>();
|
||||
for (Mtl mtl : mtlList) {
|
||||
mtlMap.put(mtl.getName(), mtl);
|
||||
}
|
||||
return mtlMap;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Mtl> of(Identifier mtlId) {
|
||||
if (loadedMtls.containsKey(mtlId))
|
||||
return loadedMtls.get(mtlId);
|
||||
|
||||
try {
|
||||
Map<String, Mtl> mtl = loadMtl(mtlId);
|
||||
loadedMtls.put(mtlId, mtl);
|
||||
|
||||
return mtl;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, Mtl> cosmetic(String cosmeticId) {
|
||||
int index = cosmeticId.indexOf('_');
|
||||
|
||||
String mtlId = (index == -1) ? "" : cosmeticId.substring(index + 1);
|
||||
|
||||
if (mtlId.isEmpty())
|
||||
mtlId = "white";
|
||||
|
||||
return of(Identifier.of("saturnclient", "models/cosmetic/materials/" + mtlId + ".mtl"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package org.saturnclient.impl.cosmetics.obj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import de.javagl.obj.Mtl;
|
||||
import de.javagl.obj.Obj;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
//? if >=1.21.9 {
|
||||
import net.minecraft.client.render.command.OrderedRenderCommandQueue;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ObjModel {
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
public static final Map<Identifier, ObjModel> loadedObjModels = new HashMap<>();
|
||||
|
||||
public record Config(
|
||||
@JsonProperty("translate") Vec3d transform,
|
||||
@JsonProperty("scale") Vec3d scale,
|
||||
@JsonProperty("rotation") Vec3d rotation) {
|
||||
|
||||
public Config {
|
||||
transform = transform == null ? new Vec3d(0, 0, 0) : transform;
|
||||
scale = scale == null ? new Vec3d(1, 1, 1) : scale;
|
||||
rotation = rotation == null ? new Vec3d(0, 0, 0) : rotation;
|
||||
}
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
|
||||
public record Vec3d(float x, float y, float z) {
|
||||
}
|
||||
}
|
||||
|
||||
Obj obj;
|
||||
Config config;
|
||||
|
||||
public static ObjModel cosmetic(String cosmeticKind, String id) {
|
||||
return of(Identifier.of("saturnclient", "models/cosmetic/" + cosmeticKind + "/" + id.split("_")[0] + "/model"));
|
||||
}
|
||||
|
||||
public static ObjModel of(Identifier obj) {
|
||||
if (loadedObjModels.containsKey(obj))
|
||||
return loadedObjModels.get(obj);
|
||||
|
||||
ObjModel o = new ObjModel(obj);
|
||||
loadedObjModels.put(obj, o);
|
||||
return o;
|
||||
}
|
||||
|
||||
ObjModel(Identifier identifier) {
|
||||
Identifier objId = Identifier.of(identifier.getNamespace(), identifier.getPath() + ".obj");
|
||||
Identifier jsonId = Identifier.of(identifier.getNamespace(), identifier.getPath() + ".json");
|
||||
|
||||
try {
|
||||
this.obj = ObjRenderer.loadObj(objId);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Try loading JSON config if it exists
|
||||
ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager();
|
||||
Optional<Resource> resource = resourceManager.getResource(jsonId);
|
||||
|
||||
if (resource.isPresent()) {
|
||||
try (InputStream stream = resource.get().getInputStream()) {
|
||||
this.config = MAPPER.readValue(stream, Config.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void render(Map<String, Mtl> mtlMap, MatrixStack matrices,
|
||||
//? if >=1.21.9 {
|
||||
OrderedRenderCommandQueue output,
|
||||
//?} else
|
||||
//VertexConsumerProvider output,
|
||||
int light, int overlay) {
|
||||
matrices.push();
|
||||
|
||||
matrices.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_X.rotationDegrees(180.0f));
|
||||
matrices.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_Y.rotationDegrees(180.0f));
|
||||
|
||||
if (this.config != null) {
|
||||
matrices.translate(config.transform.x, config.transform.y, config.transform.z);
|
||||
|
||||
matrices.scale(config.scale.x, config.scale.y, config.scale.z);
|
||||
|
||||
matrices.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_X.rotationDegrees(config.rotation.x));
|
||||
matrices.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_Y.rotationDegrees(config.rotation.y));
|
||||
matrices.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_Z.rotationDegrees(config.rotation.z));
|
||||
}
|
||||
|
||||
ObjRenderer.renderObj(this.obj, mtlMap, matrices, output, light, overlay);
|
||||
|
||||
matrices.pop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package org.saturnclient.impl.cosmetics.obj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.impl.cosmetics.utils.ShaderUtils;
|
||||
|
||||
import de.javagl.obj.*;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
//? if >=1.21.9 {
|
||||
import net.minecraft.client.render.command.OrderedRenderCommandQueue;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ObjRenderer {
|
||||
|
||||
public static Obj loadObj(Identifier objId) throws IOException {
|
||||
try (InputStream is = MinecraftClient.getInstance().getResourceManager()
|
||||
.getResource(objId).get().getInputStream()) {
|
||||
return ObjReader.read(is);
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderObj(Obj obj,
|
||||
Map<String, Mtl> mtlMap,
|
||||
MatrixStack matrices,
|
||||
//? if >=1.21.9 {
|
||||
OrderedRenderCommandQueue output,
|
||||
//?} else
|
||||
//VertexConsumerProvider output,
|
||||
int light,
|
||||
int overlay) {
|
||||
|
||||
Map<String, Obj> materialGroups = ObjSplitting.splitByMaterialGroups(obj);
|
||||
|
||||
for (Map.Entry<String, Obj> group : materialGroups.entrySet()) {
|
||||
String materialName = group.getKey();
|
||||
Obj groupObj = group.getValue();
|
||||
|
||||
Mtl mtl = mtlMap != null ? mtlMap.get(materialName) : null;
|
||||
|
||||
IdentifierRef texture = IdentifierRef.ofVanilla("textures/misc/white.png");
|
||||
|
||||
if (mtl != null) {
|
||||
String mapKd = mtl.getMapKd();
|
||||
if (mapKd != null && !mapKd.startsWith("#")) {
|
||||
texture = IdentifierRef.of(mapKd);
|
||||
}
|
||||
}
|
||||
|
||||
float r = 1f, g = 1f, b = 1f;
|
||||
if (mtl != null) {
|
||||
FloatTuple kd = mtl.getKd();
|
||||
if (kd != null) {
|
||||
r = kd.getX();
|
||||
g = kd.getY();
|
||||
b = kd.getZ();
|
||||
}
|
||||
}
|
||||
|
||||
RenderLayer layer = ShaderUtils.getRenderLayer(texture);
|
||||
|
||||
final float fr = r, fg = g, fb = b;
|
||||
final Obj finalObj = groupObj;
|
||||
|
||||
//? if >=1.21.9 {
|
||||
output.submitCustom(matrices, layer,
|
||||
(entry, consumer) -> drawGroup(finalObj, consumer, entry, light, overlay, fr, fg, fb));
|
||||
//?} else
|
||||
//drawGroup(finalObj, output.getBuffer(layer), matrices.peek(), light, overlay, fr, fg, fb);
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawGroup(Obj obj, VertexConsumer consumer, MatrixStack.Entry entry, int light, int overlay,
|
||||
float r, float g, float b) {
|
||||
int faces = obj.getNumFaces();
|
||||
|
||||
for (int f = 0; f < faces; f++) {
|
||||
ObjFace face = obj.getFace(f);
|
||||
int verts = face.getNumVertices();
|
||||
|
||||
for (int i = verts - 1; i >= 0; i--) {
|
||||
writeVertex(obj, face, i, consumer, entry, light, overlay, r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeVertex(Obj obj, ObjFace face, int index, VertexConsumer consumer,
|
||||
MatrixStack.Entry matrix, int light, int overlay,
|
||||
float r, float g, float b) {
|
||||
|
||||
FloatTuple pos = obj.getVertex(face.getVertexIndex(index));
|
||||
float x = pos.getX();
|
||||
float y = pos.getY();
|
||||
float z = pos.getZ();
|
||||
|
||||
float nx = 0f, ny = 1f, nz = 0f;
|
||||
int normalIndex = face.getNormalIndex(index);
|
||||
if (normalIndex >= 0) {
|
||||
FloatTuple n = obj.getNormal(normalIndex);
|
||||
nx = n.getX();
|
||||
ny = n.getY();
|
||||
nz = n.getZ();
|
||||
}
|
||||
|
||||
float u = 0f, v = 0f;
|
||||
int texIndex = face.getTexCoordIndex(index);
|
||||
if (texIndex >= 0) {
|
||||
FloatTuple tc = obj.getTexCoord(texIndex);
|
||||
u = tc.getX();
|
||||
v = 1f - tc.getY(); // Flip V: OBJ bottom-left origin -> Minecraft top-left
|
||||
}
|
||||
|
||||
consumer.vertex(matrix, x, y, z)
|
||||
.color(r, g, b, 1f)
|
||||
.texture(u, v)
|
||||
.overlay(overlay)
|
||||
.light(light)
|
||||
.normal(matrix, nx, ny, nz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.saturnclient.impl.cosmetics.utils;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.texture.NativeImageBackedTexture;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.util.Map;
|
||||
|
||||
public class IdentifierUtils {
|
||||
|
||||
public static void registerBufferedImageTextureFast(IdentifierRef identifierRef, BufferedImage bufferedImage) {
|
||||
try {
|
||||
Identifier identifier = (Identifier) (Object) identifierRef;
|
||||
|
||||
int width = bufferedImage.getWidth();
|
||||
int height = bufferedImage.getHeight();
|
||||
|
||||
NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, width, height, false);
|
||||
|
||||
if (bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB) {
|
||||
int[] pixels = ((DataBufferInt) bufferedImage.getRaster().getDataBuffer()).getData();
|
||||
|
||||
int index = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
nativeImage.setColorArgb(x, y, pixels[index++]);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
nativeImage.setColorArgb(x, y, bufferedImage.getRGB(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SaturnClient.client.execute(() -> {
|
||||
//? if >=1.21.5 {
|
||||
NativeImageBackedTexture texture = new NativeImageBackedTexture(
|
||||
() -> identifier.toString(),
|
||||
nativeImage);
|
||||
//?} else
|
||||
//NativeImageBackedTexture texture = new NativeImageBackedTexture(nativeImage);
|
||||
|
||||
SaturnClient.client.getTextureManager().registerTexture(identifier, texture);
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
SaturnClient.LOGGER.error("Failed to register texture: {}", identifierRef, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerBufferedImageTexturesBulk(Map<IdentifierRef, BufferedImage> textures) {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
textures.forEach(IdentifierUtils::registerBufferedImageTextureFast);
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
SaturnClient.LOGGER.info(
|
||||
"Registered {} textures in {}ms",
|
||||
textures.size(),
|
||||
(end - start));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package org.saturnclient.impl.cosmetics.utils;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.cosmetics.utils.GifUtils;
|
||||
|
||||
//? if >=1.21.5
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
|
||||
//? if >=1.21.5
|
||||
import net.minecraft.client.gl.RenderPipelines;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
//? if <1.21.5 {
|
||||
/*import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.render.VertexFormat.DrawMode;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
*///?}
|
||||
//? if >=1.21.11 {
|
||||
import net.minecraft.client.render.RenderLayers;
|
||||
import net.minecraft.client.render.RenderSetup;
|
||||
import net.minecraft.client.render.block.entity.AbstractEndPortalBlockEntityRenderer;
|
||||
//?} else {
|
||||
/*import net.minecraft.client.render.RenderPhase.Textures;
|
||||
import net.minecraft.client.render.block.entity.EndPortalBlockEntityRenderer;
|
||||
*///?}
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ShaderUtils {
|
||||
// Render pipelines exist from 1.21.5; before that the layer names a shader program directly.
|
||||
//? if >=1.21.5 {
|
||||
public static final RenderPipeline END_GATEWAY_PIPELINE = RenderPipelines.register(
|
||||
RenderPipeline.builder(new RenderPipeline.Snippet[] {
|
||||
RenderPipelines.RENDERTYPE_END_PORTAL_SNIPPET })
|
||||
.withLocation("pipeline/end_gateway")
|
||||
.withShaderDefine("PORTAL_LAYERS", 16)
|
||||
.withCull(false)
|
||||
.build());
|
||||
//?}
|
||||
|
||||
//? if >=1.21.11 {
|
||||
public static final RenderLayer END_GATEWAY = RenderLayer.of("end_gateway",
|
||||
RenderSetup.builder(END_GATEWAY_PIPELINE)
|
||||
.texture("Sampler0", AbstractEndPortalBlockEntityRenderer.SKY_TEXTURE)
|
||||
.texture("Sampler1", AbstractEndPortalBlockEntityRenderer.PORTAL_TEXTURE).build());
|
||||
//?} else if >=1.21.6 {
|
||||
/*public static final RenderLayer END_GATEWAY = RenderLayer.of("end_gateway", 1536, false, false,
|
||||
END_GATEWAY_PIPELINE,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(Textures.create().add(EndPortalBlockEntityRenderer.SKY_TEXTURE, false)
|
||||
.add(EndPortalBlockEntityRenderer.PORTAL_TEXTURE, false).build())
|
||||
.build(false));
|
||||
*///?} else if >=1.21.5 {
|
||||
/*public static final RenderLayer END_GATEWAY = RenderLayer.of("end_gateway", 1536, false, false,
|
||||
END_GATEWAY_PIPELINE,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(Textures.create().add(EndPortalBlockEntityRenderer.SKY_TEXTURE, false, false)
|
||||
.add(EndPortalBlockEntityRenderer.PORTAL_TEXTURE, false, false).build())
|
||||
.build(false));
|
||||
*///?} else {
|
||||
/*public static final RenderLayer END_GATEWAY = RenderLayer.of(
|
||||
"end_gateway",
|
||||
VertexFormats.POSITION,
|
||||
DrawMode.QUADS,
|
||||
1536,
|
||||
false,
|
||||
false,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.program(RenderLayer.END_GATEWAY_PROGRAM)
|
||||
.texture(Textures.create()
|
||||
.add(EndPortalBlockEntityRenderer.SKY_TEXTURE, false, false)
|
||||
.add(EndPortalBlockEntityRenderer.PORTAL_TEXTURE, false, false)
|
||||
.build())
|
||||
.cull(RenderPhase.DISABLE_CULLING)
|
||||
.build(false));
|
||||
*///?}
|
||||
|
||||
public static RenderLayer getRenderLayer(IdentifierRef texture) {
|
||||
String path = texture.toString();
|
||||
if (path.endsWith(".gif")) {
|
||||
return entityAlpha((Identifier) (Object) GifUtils.get(texture));
|
||||
} else if (path.endsWith("end.png")) {
|
||||
return END_GATEWAY;
|
||||
} else {
|
||||
return entityAlpha((Identifier) (Object) texture);
|
||||
}
|
||||
}
|
||||
|
||||
private static RenderLayer entityAlpha(Identifier texture) {
|
||||
//? if >=1.21.11 {
|
||||
return RenderLayers.entityAlpha(texture);
|
||||
//?} else
|
||||
//return RenderLayer.getEntityAlpha(texture);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.saturnclient.impl.features.entity;
|
||||
|
||||
public interface CameraOverriddenEntity {
|
||||
float freelook$getCameraPitch();
|
||||
|
||||
float freelook$getCameraYaw();
|
||||
|
||||
void freelook$setCameraPitch(float pitch);
|
||||
|
||||
void freelook$setCameraYaw(float yaw);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.saturnclient.impl.features.entity;
|
||||
|
||||
import org.saturnclient.common.feature.EntityFeature;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
/**
|
||||
* Fabric implementation of {@link EntityFeature}.
|
||||
*
|
||||
* Crosshair targeting is resolved via {@link MinecraftClient#crosshairTarget}.
|
||||
* Entity state for nametags is built by LivingEntityRendererMixin, which
|
||||
* writes health into the render state and then constructs a
|
||||
* {@link RenderStateEntityState} from that snapshot for NametagsMod.
|
||||
*/
|
||||
public class EntityFeatureImpl implements EntityFeature {
|
||||
|
||||
private final MinecraftClient mc;
|
||||
|
||||
public EntityFeatureImpl(MinecraftClient mc) {
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTargetingLivingEntity() {
|
||||
HitResult target = mc.crosshairTarget;
|
||||
if (target == null || target.getType() != HitResult.Type.ENTITY)
|
||||
return false;
|
||||
Entity hit = ((EntityHitResult) target).getEntity();
|
||||
return hit instanceof LivingEntity;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Render-state adapter
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Wraps a {@link HealthRenderState} (already injected into the
|
||||
* Minecraft render-state object) as a platform-neutral
|
||||
* {@link EntityState} for use by {@link NametagsFeature}.
|
||||
*
|
||||
* This is constructed in LivingEntityRendererMixin, where both the
|
||||
* render-state mixin interface and the entity name are available.
|
||||
*/
|
||||
public static final class RenderStateEntityState implements EntityState {
|
||||
|
||||
private final String customName;
|
||||
private final HealthRenderState hrs;
|
||||
|
||||
public RenderStateEntityState(String customName, HealthRenderState hrs) {
|
||||
this.customName = customName;
|
||||
this.hrs = hrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
return customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return hrs.saturn$getHealth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxHealth() {
|
||||
return hrs.saturn$getMaxHealth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType() {
|
||||
return hrs.saturn$getEntityType();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.saturnclient.impl.features.entity;
|
||||
|
||||
import org.saturnclient.common.feature.EntityFeature;
|
||||
|
||||
/**
|
||||
* Injected interface on
|
||||
* {@link net.minecraft.client.render.entity.state.LivingEntityRenderState}.
|
||||
*
|
||||
* Carries the entity's health snapshot and classification into the render
|
||||
* render state, so NametagsMod's replacement nametag (applied in
|
||||
* LivingEntityRendererMixin) can use them without touching the live entity again.
|
||||
*/
|
||||
public interface HealthRenderState {
|
||||
|
||||
float saturn$getHealth();
|
||||
|
||||
float saturn$getMaxHealth();
|
||||
|
||||
void saturn$setHealth(float health, float maxHealth);
|
||||
|
||||
EntityFeature.EntityType saturn$getEntityType();
|
||||
|
||||
void saturn$setEntityType(EntityFeature.EntityType type);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.saturnclient.impl.features.mixins.entity;
|
||||
|
||||
import org.saturnclient.impl.features.entity.CameraOverriddenEntity;
|
||||
import org.saturnclient.mod.mods.FreelookMod;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.entity.Entity;
|
||||
//? if >=1.21.11 {
|
||||
import net.minecraft.world.World;
|
||||
//?} else
|
||||
//import net.minecraft.world.BlockView;
|
||||
|
||||
@Mixin(Camera.class)
|
||||
public abstract class CameraMixin {
|
||||
@Unique
|
||||
boolean firstTime = true;
|
||||
|
||||
@Shadow
|
||||
protected abstract void setRotation(float yaw, float pitch);
|
||||
|
||||
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V", ordinal = 1, shift = At.Shift.AFTER))
|
||||
public void lockRotation(
|
||||
//? if >=1.21.11 {
|
||||
World focusedBlock,
|
||||
//?} else
|
||||
//BlockView focusedBlock,
|
||||
Entity cameraEntity,
|
||||
boolean isThirdPerson,
|
||||
boolean isFrontFacing,
|
||||
float tickDelta,
|
||||
CallbackInfo ci) {
|
||||
if (FreelookMod.isFreeLooking() && cameraEntity instanceof ClientPlayerEntity) {
|
||||
CameraOverriddenEntity cameraOverriddenEntity = (CameraOverriddenEntity) cameraEntity;
|
||||
|
||||
if (firstTime && SaturnClient.client.player != null) {
|
||||
cameraOverriddenEntity.freelook$setCameraPitch(SaturnClient.client.player.getPitch());
|
||||
cameraOverriddenEntity.freelook$setCameraYaw(SaturnClient.client.player.getYaw());
|
||||
firstTime = false;
|
||||
}
|
||||
this.setRotation(cameraOverriddenEntity.freelook$getCameraYaw(),
|
||||
cameraOverriddenEntity.freelook$getCameraPitch());
|
||||
|
||||
}
|
||||
if (!FreelookMod.isFreeLooking() && cameraEntity instanceof ClientPlayerEntity) {
|
||||
firstTime = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.saturnclient.impl.features.mixins.entity;
|
||||
|
||||
import org.saturnclient.impl.features.entity.CameraOverriddenEntity;
|
||||
import org.saturnclient.mod.mods.FreelookMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public class EntityMixin implements CameraOverriddenEntity {
|
||||
@Unique
|
||||
private float cameraPitch;
|
||||
|
||||
@Unique
|
||||
private float cameraYaw;
|
||||
|
||||
@Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true)
|
||||
public void changeCameraLookDirection(double xDelta, double yDelta, CallbackInfo ci) {
|
||||
// noinspection ConstantValue// IntelliJ is incorrect here, this code block is
|
||||
// reachable
|
||||
if (FreelookMod.isFreeLooking() && (Object) this instanceof ClientPlayerEntity) {
|
||||
double pitchDelta = (yDelta * 0.15);
|
||||
double yawDelta = (xDelta * 0.15);
|
||||
|
||||
this.cameraPitch = MathHelper.clamp(this.cameraPitch + (float) pitchDelta, -90.0f, 90.0f);
|
||||
this.cameraYaw += (float) yawDelta;
|
||||
|
||||
ci.cancel();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unique
|
||||
public float freelook$getCameraPitch() {
|
||||
return this.cameraPitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unique
|
||||
public float freelook$getCameraYaw() {
|
||||
return this.cameraYaw;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unique
|
||||
public void freelook$setCameraPitch(float pitch) {
|
||||
this.cameraPitch = pitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unique
|
||||
public void freelook$setCameraYaw(float yaw) {
|
||||
this.cameraYaw = yaw;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.saturnclient.impl.features.mixins.render;
|
||||
|
||||
//? if >=1.21.6 {
|
||||
import net.minecraft.client.render.fog.FogRenderer;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.BackgroundRenderer;
|
||||
|
||||
import org.saturnclient.mod.mods.NoFogMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
|
||||
//? if >=1.21.6 {
|
||||
@Mixin(FogRenderer.class)
|
||||
//?} else
|
||||
//@Mixin(BackgroundRenderer.class)
|
||||
public class BackgroundRendererMixin {
|
||||
// fog
|
||||
@ModifyVariable(method = "applyFog", at = @At("HEAD"), ordinal = 0, argsOnly = true)
|
||||
private static float modifyFogStart(float viewDistance) {
|
||||
if (NoFogMod.isActive()) {
|
||||
return viewDistance * 2.0f;
|
||||
}
|
||||
|
||||
return viewDistance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.saturnclient.impl.features.mixins.render;
|
||||
|
||||
//? if >=1.21.6
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
//? if >=1.21.6
|
||||
import net.minecraft.client.option.GameOptions;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
|
||||
//? if >=1.21.6
|
||||
import org.saturnclient.impl.ui.SaturnScreenFabric;
|
||||
import org.saturnclient.mod.mods.FreelookMod;
|
||||
import org.saturnclient.mod.mods.ZoomMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
//? if >=1.21.6
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
/**
|
||||
* Overrides the game's field-of-view when {@link ZoomMod} is active.
|
||||
*
|
||||
* The old code checked both {@code Zoom.isZooming} and
|
||||
* {@code Zoom.shouldZoom()} separately. The refactored
|
||||
* {@link ZoomMod#shouldZoom()} already ORs both conditions
|
||||
* ({@code enabled.value && isZooming}), so only one check is needed.
|
||||
*
|
||||
* No {@link org.saturnclient.common.module.ModProvider} is required
|
||||
* here because zooming is a pure render-time override with no per-tick
|
||||
* engine queries.
|
||||
*/
|
||||
@Mixin(GameRenderer.class)
|
||||
public class GameRendererMixin {
|
||||
|
||||
/**
|
||||
* After the vanilla FOV has been computed, divide it by the zoom
|
||||
* level to produce the narrowed field-of-view.
|
||||
*/
|
||||
@Inject(method = "getFov", at = @At("RETURN"), cancellable = true)
|
||||
private void onGetFov(CallbackInfoReturnable<Float> cir) {
|
||||
if (ZoomMod.shouldZoom()) {
|
||||
float zoomedFov = cir.getReturnValue() / ZoomMod.getZoomLevel();
|
||||
cir.setReturnValue(zoomedFov);
|
||||
} else if (FreelookMod.shouldZoomOut()) {
|
||||
float zoomedFov = cir.getReturnValue() / FreelookMod.getZoomLevel();
|
||||
cir.setReturnValue(zoomedFov);
|
||||
}
|
||||
}
|
||||
|
||||
//? if >=1.21.6 {
|
||||
// From 1.21.6 the menu blur's strength is the vanilla setting, read here every frame. While a
|
||||
// Saturn screen is open, it's Saturn's background blur instead, faded in with the screen.
|
||||
@Redirect(method = "render", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/option/GameOptions;getMenuBackgroundBlurrinessValue()I"))
|
||||
private int useSaturnBlur(GameOptions options) {
|
||||
if (MinecraftClient.getInstance().currentScreen instanceof SaturnScreenFabric saturnScreen) {
|
||||
return saturnScreen.screen.getBackgroundBlur();
|
||||
}
|
||||
|
||||
return options.getMenuBackgroundBlurrinessValue();
|
||||
}
|
||||
//?}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.saturnclient.impl.features.mixins.render;
|
||||
|
||||
// Code approach adapted from Gamma Utils: https://github.com/Sjouwer/gamma-utils
|
||||
|
||||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||
import net.minecraft.client.render.LightmapTextureManager;
|
||||
|
||||
import org.saturnclient.mod.mods.FullbrightMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
/**
|
||||
* Overrides the lightmap's gamma computation when
|
||||
* {@link FullbrightMod} is active, replacing the vanilla
|
||||
* brightness with a user-configured value.
|
||||
*
|
||||
* The old import was {@code org.saturnclient.feature.features.Fullbright};
|
||||
* it is now {@link FullbrightMod}. The injection target and
|
||||
* strategy are unchanged.
|
||||
*/
|
||||
@Mixin(LightmapTextureManager.class)
|
||||
public class LightmapTextureManagerMixin {
|
||||
|
||||
/**
|
||||
* If fullbright is active, substitute the feature's brightness
|
||||
* value for whatever vanilla calculated.
|
||||
*/
|
||||
@ModifyExpressionValue(method = "update", at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(FF)F", ordinal = 0))
|
||||
private float modifyGamma(float original) {
|
||||
if (FullbrightMod.shouldOverrideBrightness()) {
|
||||
return FullbrightMod.getBrightnessValue();
|
||||
}
|
||||
return original;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package org.saturnclient.impl.features.mixins.render;
|
||||
|
||||
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
|
||||
|
||||
import org.saturnclient.common.feature.EntityFeature;
|
||||
import org.saturnclient.impl.features.entity.HealthRenderState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
/**
|
||||
* Implements {@link HealthRenderState} on
|
||||
* {@link LivingEntityRenderState}, injecting health and entity-type
|
||||
* storage into every living entity's render-state snapshot.
|
||||
*
|
||||
* Previously imported {@code NametagsInterface.EntityType}; the enum
|
||||
* now lives in {@link EntityFeature.EntityType} which is the single
|
||||
* canonical definition shared by the mixin layer and the feature layer.
|
||||
*
|
||||
* The stored values are written by
|
||||
* {@link LivingEntityRendererMixin#saturn$captureHealth} each time a
|
||||
* render state is extracted from a live entity, and read there right away for
|
||||
* NametagsMod's replacement nametag.
|
||||
*/
|
||||
@Mixin(LivingEntityRenderState.class)
|
||||
public class LivingEntityRenderStateMixin implements HealthRenderState {
|
||||
|
||||
@Unique
|
||||
private float saturn$health = 0f;
|
||||
@Unique
|
||||
private float saturn$maxHealth = 1f;
|
||||
@Unique
|
||||
private EntityFeature.EntityType saturn$entityType = EntityFeature.EntityType.OTHER;
|
||||
|
||||
@Override
|
||||
public float saturn$getHealth() {
|
||||
return saturn$health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float saturn$getMaxHealth() {
|
||||
return saturn$maxHealth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saturn$setHealth(float health, float maxHealth) {
|
||||
this.saturn$health = health;
|
||||
this.saturn$maxHealth = maxHealth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityFeature.EntityType saturn$getEntityType() {
|
||||
return saturn$entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saturn$setEntityType(EntityFeature.EntityType type) {
|
||||
saturn$entityType = type;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package org.saturnclient.impl.features.mixins.render;
|
||||
|
||||
import net.minecraft.client.render.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.mob.HostileEntity;
|
||||
import net.minecraft.entity.passive.PassiveEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import org.saturnclient.common.feature.EntityFeature;
|
||||
import org.saturnclient.impl.features.entity.EntityFeatureImpl;
|
||||
import org.saturnclient.impl.features.entity.HealthRenderState;
|
||||
import org.saturnclient.mod.mods.NametagsMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Captures each living entity's health and type into the render state during
|
||||
* {@code updateRenderState}, and applies {@link NametagsMod}'s replacement nametag to the state's
|
||||
* display name.
|
||||
*
|
||||
* Replacing the name here, while the render state is built, works the same on every version. Hooking
|
||||
* label rendering instead doesn't: 1.21.9 moved it to the render command queue. Player role icons are
|
||||
* added after this, in PlayerEntityRendererMixin.
|
||||
*/
|
||||
@Mixin(LivingEntityRenderer.class)
|
||||
public abstract class LivingEntityRendererMixin<T extends LivingEntity, S extends LivingEntityRenderState> {
|
||||
|
||||
@Inject(method = "updateRenderState", at = @At("TAIL"))
|
||||
private void saturn$captureHealth(T entity, S state, float tickDelta, CallbackInfo ci) {
|
||||
if (!(state instanceof HealthRenderState hrs))
|
||||
return;
|
||||
|
||||
hrs.saturn$setHealth(entity.getHealth(), entity.getMaxHealth());
|
||||
|
||||
// Classify entity type for the nametag feature's filtering logic
|
||||
EntityFeature.EntityType type;
|
||||
if (entity instanceof PlayerEntity)
|
||||
type = EntityFeature.EntityType.PLAYER;
|
||||
else if (entity instanceof HostileEntity)
|
||||
type = EntityFeature.EntityType.HOSTILE;
|
||||
else if (entity instanceof PassiveEntity)
|
||||
type = EntityFeature.EntityType.PASSIVE;
|
||||
else
|
||||
type = EntityFeature.EntityType.OTHER;
|
||||
|
||||
hrs.saturn$setEntityType(type);
|
||||
|
||||
// Only entities that already show a label get a replacement one, as when this hooked label
|
||||
// rendering.
|
||||
if (NametagsMod.shouldReplaceName() && state.displayName != null) {
|
||||
String replacement = NametagsMod.getNametagString(
|
||||
new EntityFeatureImpl.RenderStateEntityState(state.displayName.getString(), hrs));
|
||||
if (replacement != null) {
|
||||
state.displayName = Text.literal(replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.saturnclient.impl.features.mixins.render;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.client.render.RenderTickCounter;
|
||||
|
||||
import org.saturnclient.impl.ui.RenderScopeImpl;
|
||||
import org.saturnclient.impl.ui.SaturnScreenFabric;
|
||||
import org.saturnclient.mod.HudMod;
|
||||
import org.saturnclient.mod.Mod;
|
||||
import org.saturnclient.mod.ModLayout;
|
||||
import org.saturnclient.mod.ModManager;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.screens.HudEditor;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Drives per-frame rendering for all registered features.
|
||||
*
|
||||
* This mixin is intentionally kept thin: it creates a {@link RenderScope},
|
||||
* iterates the enabled feature list from {@link ModManager}, and
|
||||
* dispatches either {@link HudMod#renderHud} (for HUD elements) or
|
||||
* {@link Mod#render} (for world-overlay features like Crosshair).
|
||||
*
|
||||
* No feature-specific logic lives here — all decisions about what to
|
||||
* draw are made inside each feature class.
|
||||
*
|
||||
* Changes from the original:
|
||||
* - Package imports updated to the refactored feature names (no
|
||||
* more {@code feature.features.*}).
|
||||
* - The HUD-editor screen check still uses the existing
|
||||
* {@link SaturnScreenFabric} / {@link HudEditor} pair; that is
|
||||
* unchanged infrastructure.
|
||||
*/
|
||||
@Mixin(InGameHud.class)
|
||||
public class RenderMixin {
|
||||
|
||||
@Inject(method = "renderChat", at = @At("TAIL"))
|
||||
public void renderMods(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
|
||||
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
||||
|
||||
// Skip rendering while the HUD editor is open so the editor
|
||||
// can draw its own preview layout without double-drawing.
|
||||
if (textRenderer == null)
|
||||
return;
|
||||
if (SaturnClient.client.currentScreen instanceof SaturnScreenFabric f
|
||||
&& f.screen instanceof HudEditor)
|
||||
return;
|
||||
|
||||
RenderScope scope = new RenderScopeImpl(context);
|
||||
|
||||
for (Mod feature : ModManager.ENABLED_MODS) {
|
||||
if (!feature.isEnabled())
|
||||
continue;
|
||||
|
||||
if (feature instanceof HudMod hud) {
|
||||
ModLayout dim = hud.getDimensions();
|
||||
|
||||
scope.getMatrixStack().push();
|
||||
scope.getMatrixStack().translate(dim.x.value, (float) dim.y.value);
|
||||
scope.getMatrixStack().scale(dim.scale.value, dim.scale.value);
|
||||
|
||||
if (dim.renderBackground) {
|
||||
scope.drawRoundedRectangle(0, 0, dim.width, dim.height,
|
||||
dim.radius.value, dim.bgColor.value);
|
||||
}
|
||||
|
||||
hud.renderHud(scope);
|
||||
scope.getMatrixStack().pop();
|
||||
|
||||
} else {
|
||||
// Non-HUD features (e.g. CrosshairFeature) use the plain render hook.
|
||||
feature.render(scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.saturnclient.impl.features.mixins.world;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.network.packet.s2c.play.WorldTimeUpdateS2CPacket;
|
||||
|
||||
import org.saturnclient.mod.mods.TpsMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Feeds world-time packets into {@link TpsMod}'s TPS estimator.
|
||||
*
|
||||
* This is the only place in the entire codebase that reads a network
|
||||
* packet and passes data to a feature. The feature's
|
||||
* {@link TpsMod#onTimePacket(long)} method handles all averaging
|
||||
* logic; the mixin is intentionally reduced to a single forwarding call.
|
||||
*
|
||||
* The only change from the original is renaming the import from
|
||||
* {@code feature.features.Tps} to {@link TpsMod}.
|
||||
*/
|
||||
@Mixin(ClientPlayNetworkHandler.class)
|
||||
public class TpsMixin {
|
||||
|
||||
@Inject(method = "onWorldTimeUpdate", at = @At("HEAD"))
|
||||
private void onWorldTimeUpdate(WorldTimeUpdateS2CPacket packet, CallbackInfo ci) {
|
||||
TpsMod.onTimePacket(packet.time());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.saturnclient.impl.features.network;
|
||||
|
||||
import org.saturnclient.common.feature.NetworkFeature;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.PlayerListEntry;
|
||||
|
||||
/**
|
||||
* Fabric implementation of {@link NetworkFeature}.
|
||||
*
|
||||
* Connection presence is checked via the network handler.
|
||||
* Ping is read from the player's {@link PlayerListEntry} which the
|
||||
* server populates; returns {@code -1} when unavailable.
|
||||
*/
|
||||
public class NetworkFeatureImpl implements NetworkFeature {
|
||||
|
||||
private final MinecraftClient mc;
|
||||
|
||||
public NetworkFeatureImpl(MinecraftClient mc) {
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNetwork() {
|
||||
return mc.getNetworkHandler() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPing() {
|
||||
if (mc.player == null || mc.getNetworkHandler() == null)
|
||||
return -1;
|
||||
|
||||
PlayerListEntry entry = mc.getNetworkHandler().getPlayerListEntry(mc.player.getUuid());
|
||||
|
||||
return entry != null ? entry.getLatency() : -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
package org.saturnclient.impl.features.player;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import org.saturnclient.common.feature.PlayerFeature;
|
||||
import org.saturnclient.common.ref.game.EffectRef;
|
||||
import org.saturnclient.common.ref.game.ItemStackRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Fabric implementation of {@link PlayerFeature}.
|
||||
*
|
||||
* All access to {@link MinecraftClient} and {@link ClientPlayerEntity}
|
||||
* is encapsulated here. Features only ever see the {@link PlayerFeature}
|
||||
* interface; they never import Minecraft classes directly.
|
||||
*
|
||||
* Every method guards against a missing player and returns a safe
|
||||
* default so features are free of null checks.
|
||||
*/
|
||||
public class PlayerFeatureImpl implements PlayerFeature {
|
||||
|
||||
private final MinecraftClient mc;
|
||||
|
||||
public PlayerFeatureImpl(MinecraftClient mc) {
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Internal helper — never returns null
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
/** Returns the local player, or {@code null} if one is not loaded. */
|
||||
private ClientPlayerEntity player() {
|
||||
return mc.player;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Presence
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean hasPlayer() {
|
||||
return mc.player != null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Position
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return hasPlayer() ? (int) player().getX() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return hasPlayer() ? (int) player().getY() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return hasPlayer() ? (int) player().getZ() : 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Input / movement
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean isForwardPressed() {
|
||||
return mc.options.forwardKey.isPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBackPressed() {
|
||||
return mc.options.backKey.isPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeftPressed() {
|
||||
return mc.options.leftKey.isPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRightPressed() {
|
||||
return mc.options.rightKey.isPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJumpPressed() {
|
||||
return mc.options.jumpKey.isPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAttackPressed() {
|
||||
return mc.options.attackKey.isPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsePressed() {
|
||||
return mc.options.useKey.isPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return hasPlayer() && player().isSneaking();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsingItem() {
|
||||
return hasPlayer() && player().isUsingItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasHorizontalCollision() {
|
||||
return hasPlayer() && player().horizontalCollision;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnGround() {
|
||||
return hasPlayer() && player().isOnGround();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSprinting(boolean sprinting) {
|
||||
if (hasPlayer())
|
||||
player().setSprinting(sprinting);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Velocity
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Velocity getVelocity() {
|
||||
if (!hasPlayer())
|
||||
return Velocity.ZERO;
|
||||
var v = player().getVelocity();
|
||||
return new Velocity(v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Stats
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return hasPlayer() ? player().getHealth() : 0f;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Equipment
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public ItemStackRef getMainHand() {
|
||||
return wrap(hasPlayer() ? player().getMainHandStack() : ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackRef getHelmet() {
|
||||
//? if >=1.21.5 {
|
||||
return wrap(hasPlayer() ? player().getEquippedStack(EquipmentSlot.HEAD) : ItemStack.EMPTY);
|
||||
//?} else
|
||||
//return wrap(hasPlayer() ? player().getInventory().armor.get(3) : ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackRef getChestplate() {
|
||||
//? if >=1.21.5 {
|
||||
return wrap(hasPlayer() ? player().getEquippedStack(EquipmentSlot.CHEST) : ItemStack.EMPTY);
|
||||
//?} else
|
||||
//return wrap(hasPlayer() ? player().getInventory().armor.get(2) : ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackRef getLeggings() {
|
||||
//? if >=1.21.5 {
|
||||
return wrap(hasPlayer() ? player().getEquippedStack(EquipmentSlot.LEGS) : ItemStack.EMPTY);
|
||||
//?} else
|
||||
//return wrap(hasPlayer() ? player().getInventory().armor.get(1) : ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackRef getBoots() {
|
||||
//? if >=1.21.5 {
|
||||
return wrap(hasPlayer() ? player().getEquippedStack(EquipmentSlot.FEET) : ItemStack.EMPTY);
|
||||
//?} else
|
||||
//return wrap(hasPlayer() ? player().getInventory().armor.get(0) : ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Dummy equipment
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public ItemStackRef getDummyMainHand() {
|
||||
return wrap(new ItemStack(Items.DIAMOND_SWORD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackRef getDummyHelmet() {
|
||||
return wrap(new ItemStack(Items.DIAMOND_HELMET));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackRef getDummyChestplate() {
|
||||
return wrap(new ItemStack(Items.DIAMOND_CHESTPLATE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackRef getDummyLeggings() {
|
||||
return wrap(new ItemStack(Items.DIAMOND_LEGGINGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackRef getDummyBoots() {
|
||||
return wrap(new ItemStack(Items.DIAMOND_BOOTS));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Status effects
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public List<? extends EffectRef> getActiveEffects() {
|
||||
if (!hasPlayer())
|
||||
return Collections.emptyList();
|
||||
|
||||
var effects = player().getActiveStatusEffects().values();
|
||||
List<EffectRef> result = new ArrayList<>(effects.size());
|
||||
for (StatusEffectInstance instance : effects) {
|
||||
result.add((EffectRef) instance);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends EffectRef> getDummyEffects() {
|
||||
return List.of(
|
||||
(EffectRef) new StatusEffectInstance(
|
||||
Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("speed")).get(), 12000, 2),
|
||||
(EffectRef) new StatusEffectInstance(
|
||||
Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("strength")).get(), 12000, 2),
|
||||
(EffectRef) new StatusEffectInstance(
|
||||
Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("fire_resistance")).get(), 12000, 2));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
private static ItemStackRef wrap(ItemStack stack) {
|
||||
return (ItemStackRef) (Object) stack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.saturnclient.impl.features.render;
|
||||
|
||||
import org.saturnclient.common.feature.RenderFeature;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.Perspective;
|
||||
|
||||
/**
|
||||
* Fabric implementation of {@link RenderFeature}.
|
||||
*
|
||||
* Window dimensions and FPS are read directly from
|
||||
* {@link MinecraftClient}. Camera perspective control delegates to
|
||||
* {@link net.minecraft.client.option.GameOptions}.
|
||||
*/
|
||||
public class RenderFeatureImpl implements RenderFeature {
|
||||
|
||||
private final MinecraftClient mc;
|
||||
|
||||
public RenderFeatureImpl(MinecraftClient mc) {
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Window
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public int getScaledWindowWidth() {
|
||||
return mc.getWindow().getScaledWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledWindowHeight() {
|
||||
return mc.getWindow().getScaledHeight();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Performance
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public int getFps() {
|
||||
return mc.getCurrentFps();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Camera perspective
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean isFirstPerson() {
|
||||
return mc.options.getPerspective() == Perspective.FIRST_PERSON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFirstPerson() {
|
||||
mc.options.setPerspective(Perspective.FIRST_PERSON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setThirdPersonBack() {
|
||||
mc.options.setPerspective(Perspective.THIRD_PERSON_BACK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.saturnclient.impl.features.world;
|
||||
|
||||
import org.saturnclient.common.feature.WorldFeature;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
/**
|
||||
* Fabric implementation of {@link WorldFeature}.
|
||||
*
|
||||
* Reads the client world's time directly from {@link MinecraftClient}.
|
||||
* Returns safe defaults when no world is loaded.
|
||||
*/
|
||||
public class WorldFeatureImpl implements WorldFeature {
|
||||
|
||||
private final MinecraftClient mc;
|
||||
|
||||
public WorldFeatureImpl(MinecraftClient mc) {
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasWorld() {
|
||||
return mc.world != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total world age in ticks, or {@code 0} when no world
|
||||
* is loaded. Used by {@link TpsFeature#onTimePacket} (which is
|
||||
* called from the mixin and stores its own copy) and by
|
||||
* {@link DayCounterFeature} for the day count.
|
||||
*/
|
||||
@Override
|
||||
public long getWorldAge() {
|
||||
// World.getTime() was a shortcut for this, and 1.21.11 removed it.
|
||||
return hasWorld() ? mc.world.getLevelProperties().getTime() : 0L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@Mixin(Identifier.class)
|
||||
public abstract class IdentifierMixin implements IdentifierRef {
|
||||
@Shadow
|
||||
public abstract String toString();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import org.saturnclient.common.ref.game.ItemStackRef;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
public abstract class ItemStackMixin implements ItemStackRef {
|
||||
@Shadow
|
||||
public abstract boolean isEmpty();
|
||||
|
||||
@Shadow
|
||||
public abstract int getMaxDamage();
|
||||
|
||||
@Shadow
|
||||
public abstract int getDamage();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
//? if <1.21.6 {
|
||||
/*import org.saturnclient.common.ref.render.MatrixStackRef;
|
||||
//? if >=1.21.5
|
||||
import org.joml.Quaternionfc;
|
||||
//? if <1.21.5
|
||||
//import org.joml.Quaternionf;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
*///?}
|
||||
|
||||
/**
|
||||
* Makes MatrixStack a MatrixStackRef, for GUI drawing before 1.21.6. From 1.21.6 the GUI uses a 2D
|
||||
* Matrix3x2fStack (Matrix3x2fStackRef) instead, so this mixin is empty but stays registered, keeping
|
||||
* impl.mixins.json the same for every version.
|
||||
*/
|
||||
@Mixin(MatrixStack.class)
|
||||
//? if <1.21.6 {
|
||||
/*public abstract class MatrixStackMixin implements MatrixStackRef {
|
||||
@Shadow
|
||||
public abstract void push();
|
||||
|
||||
@Shadow
|
||||
public abstract void pop();
|
||||
|
||||
@Shadow
|
||||
public abstract void translate(float x, float y, float z);
|
||||
|
||||
@Shadow
|
||||
public abstract void scale(float x, float y, float z);
|
||||
|
||||
@Shadow
|
||||
//? if >=1.21.5
|
||||
public abstract void multiply(Quaternionfc quaternion);
|
||||
//? if <1.21.5
|
||||
//public abstract void multiply(Quaternionf quaternion);
|
||||
|
||||
@Shadow
|
||||
//? if >=1.21.5
|
||||
public abstract void multiply(Quaternionfc quaternion, float originX, float originY, float originZ);
|
||||
//? if <1.21.5
|
||||
//public abstract void multiply(Quaternionf quaternion, float originX, float originY, float originZ);
|
||||
|
||||
@Override
|
||||
public void translate(float x, float y) {
|
||||
translate(x, y, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scale(float x, float y) {
|
||||
scale(x, y, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(float angle, float originX, float originY, float originZ) {
|
||||
multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(angle), originX, originY, originZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(float angle) {
|
||||
multiply(RotationAxis.NEGATIVE_Z.rotationDegrees(angle));
|
||||
}
|
||||
}
|
||||
*///?} else
|
||||
public abstract class MatrixStackMixin {}
|
||||
@@ -0,0 +1,168 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.common.ref.game.MinecraftClientRef;
|
||||
import org.saturnclient.common.ref.render.WindowRef;
|
||||
import org.saturnclient.impl.ui.SaturnScreenFabric;
|
||||
import org.saturnclient.ui.SaturnScreen;
|
||||
import org.saturnclient.ui.screens.TitleMenu;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
|
||||
import net.minecraft.client.option.GameOptions;
|
||||
import net.minecraft.client.session.Session;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.resource.ReloadableResourceManagerImpl;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public abstract class MinecraftClientMixin implements MinecraftClientRef {
|
||||
@Shadow
|
||||
public File runDirectory;
|
||||
|
||||
@Shadow
|
||||
private Window window;
|
||||
|
||||
@Shadow
|
||||
private ReloadableResourceManagerImpl resourceManager;
|
||||
|
||||
@Shadow
|
||||
public GameOptions options;
|
||||
|
||||
@Shadow
|
||||
private Session session;
|
||||
|
||||
@Shadow
|
||||
public abstract void setScreen(@Nullable Screen screen);
|
||||
|
||||
@Shadow
|
||||
@Override
|
||||
public abstract void scheduleStop();
|
||||
|
||||
@Override
|
||||
public File getRunDirectory() {
|
||||
return runDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResource(IdentifierRef identifier) {
|
||||
try {
|
||||
return resourceManager.getResource((Identifier) (Object) identifier).get().getInputStream();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindowRef getWindow() {
|
||||
return (WindowRef) (Object) this.window;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScreen(SaturnScreen screen) {
|
||||
this.setScreen(new SaturnScreenFabric(screen));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScreen(MinecraftScreen screen) {
|
||||
SaturnScreenFabric exitTarget = new SaturnScreenFabric(new TitleMenu());
|
||||
|
||||
switch (screen) {
|
||||
case SelectWorld:
|
||||
this.setScreen(new SelectWorldScreen(exitTarget));
|
||||
break;
|
||||
|
||||
case Multiplayer:
|
||||
this.setScreen(new MultiplayerScreen(exitTarget));
|
||||
break;
|
||||
|
||||
case Options:
|
||||
this.setScreen(new OptionsScreen(exitTarget, this.options));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessToken() {
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.session.getAccessToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
return this.session.getUuidOrNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
return this.session.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientStopping(Runnable handler) {
|
||||
ClientLifecycleEvents.CLIENT_STOPPING.register(_o -> handler.run());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeOnThread(Runnable runnable) {
|
||||
((java.util.concurrent.Executor) (Object) this).execute(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
public String getPlayerListEntry(UUID uuid) {
|
||||
var client = (MinecraftClient) (Object) this;
|
||||
var handler = client.getNetworkHandler();
|
||||
|
||||
if (handler == null)
|
||||
return null;
|
||||
|
||||
var entry = handler.getPlayerListEntry(uuid);
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
//? if >=1.21.9 {
|
||||
return entry.getProfile().name();
|
||||
//?} else
|
||||
//return entry.getProfile().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
public UUID getPlayerListEntryUUID(String name) {
|
||||
var client = (MinecraftClient) (Object) this;
|
||||
var handler = client.getNetworkHandler();
|
||||
|
||||
if (handler == null)
|
||||
return null;
|
||||
|
||||
var entry = handler.getPlayerListEntry(name);
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
//? if >=1.21.9 {
|
||||
return entry.getProfile().id();
|
||||
//?} else
|
||||
//return entry.getProfile().getId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import org.joml.Quaternionf;
|
||||
import org.saturnclient.common.ref.render.QuaternionfRef;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(Quaternionf.class)
|
||||
public abstract class QuaternionfMixin implements QuaternionfRef {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import org.saturnclient.common.ref.asset.SpriteRef;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(Sprite.class)
|
||||
public abstract class SpriteMixin implements SpriteRef {
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.common.ref.asset.SpriteRef;
|
||||
import org.saturnclient.common.ref.game.EffectRef;
|
||||
//? if <1.21.9
|
||||
//import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@Mixin(StatusEffectInstance.class)
|
||||
public abstract class StatusEffectMixin implements EffectRef {
|
||||
|
||||
@Shadow
|
||||
public abstract boolean shouldShowIcon();
|
||||
|
||||
@Shadow
|
||||
public abstract boolean isInfinite();
|
||||
|
||||
@Shadow
|
||||
public abstract int getDuration();
|
||||
|
||||
@Shadow
|
||||
public abstract RegistryEntry<StatusEffect> getEffectType();
|
||||
|
||||
@Override
|
||||
public SpriteRef getIcon() {
|
||||
// 1.21.9 changed the GUI atlas, so newer versions draw the effect's texture (getIconId) instead.
|
||||
//? if >=1.21.9 {
|
||||
return null;
|
||||
//?} else if >=1.21.6 {
|
||||
//return (SpriteRef) SaturnClient.client.getGuiAtlasManager().getSprite((InGameHud.getEffectTexture(getEffectType())));
|
||||
//?} else
|
||||
//return (SpriteRef) SaturnClient.client.getStatusEffectSpriteManager().getSprite(getEffectType());
|
||||
}
|
||||
|
||||
// Before 1.21.6 there's no InGameHud.getEffectTexture; getIcon's sprite is used there instead.
|
||||
//? if >=1.21.6 {
|
||||
@Override
|
||||
public IdentifierRef getIconId() {
|
||||
Identifier id = InGameHud.getEffectTexture(getEffectType());
|
||||
|
||||
return IdentifierRef.of(id.getNamespace(), "textures/" + id.getPath() + ".png");
|
||||
}
|
||||
//?}
|
||||
|
||||
@Override
|
||||
public String getInfiniteText() {
|
||||
return "∞";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDurationSeconds() {
|
||||
return getDuration() / 20; // ticks → seconds
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.common.ref.render.TextRef;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
//? if >=1.21.9
|
||||
import net.minecraft.text.StyleSpriteSource.Font;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@Mixin(Text.class)
|
||||
public interface TextMixin extends TextRef {
|
||||
|
||||
@Override
|
||||
public default TextRef withFont(IdentifierRef font) {
|
||||
//? if >=1.21.9 {
|
||||
return (TextRef) (Text) (((Text) this).copy().setStyle(Style.EMPTY.withFont(new Font((Identifier) (Object) font))));
|
||||
//?} else
|
||||
//return (TextRef) (((Text) this).copy().setStyle(Style.EMPTY.withFont((Identifier) (Object) font)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public default int getWidth() {
|
||||
return SaturnClient.client.textRenderer.getWidth((Text) this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.saturnclient.impl.mixins;
|
||||
|
||||
import org.saturnclient.common.ref.render.WindowRef;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.client.util.Window;
|
||||
|
||||
@Mixin(Window.class)
|
||||
public abstract class WindowMixin implements WindowRef {
|
||||
@Shadow
|
||||
public abstract int getWidth();
|
||||
|
||||
@Shadow
|
||||
public abstract int getHeight();
|
||||
|
||||
@Shadow
|
||||
public abstract int getFramebufferWidth();
|
||||
|
||||
@Shadow
|
||||
public abstract int getFramebufferHeight();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.saturnclient.impl.provider;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import org.saturnclient.common.feature.*;
|
||||
import org.saturnclient.common.provider.FeatureProvider;
|
||||
import org.saturnclient.impl.features.entity.EntityFeatureImpl;
|
||||
import org.saturnclient.impl.features.network.NetworkFeatureImpl;
|
||||
import org.saturnclient.impl.features.player.PlayerFeatureImpl;
|
||||
import org.saturnclient.impl.features.render.RenderFeatureImpl;
|
||||
import org.saturnclient.impl.features.world.WorldFeatureImpl;
|
||||
|
||||
/**
|
||||
* Fabric implementation of {@link FeatureProvider}.
|
||||
*
|
||||
* Instantiated once during client startup (e.g. in the mod initialiser)
|
||||
* and passed to every feature constructor. All five sub-modules share
|
||||
* the same {@link MinecraftClient} reference so there is no
|
||||
* inconsistency between modules reading state within the same tick.
|
||||
*
|
||||
* <pre>{@code
|
||||
* FeatureProvider provider = new FeatureProviderFabric(MinecraftClient.getInstance());
|
||||
* FeatureManager.register(new AutoSprintFeature(provider));
|
||||
* FeatureManager.register(new CoordinatesFeature(provider));
|
||||
* // …
|
||||
* }</pre>
|
||||
*/
|
||||
public class FeatureProviderFabric implements FeatureProvider {
|
||||
|
||||
private final PlayerFeature player;
|
||||
private final WorldFeature world;
|
||||
private final EntityFeature entity;
|
||||
private final RenderFeature render;
|
||||
private final NetworkFeature network;
|
||||
|
||||
public FeatureProviderFabric(MinecraftClient mc) {
|
||||
this.player = new PlayerFeatureImpl(mc);
|
||||
this.world = new WorldFeatureImpl(mc);
|
||||
this.entity = new EntityFeatureImpl(mc);
|
||||
this.render = new RenderFeatureImpl(mc);
|
||||
this.network = new NetworkFeatureImpl(mc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerFeature player() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldFeature world() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityFeature entity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderFeature render() {
|
||||
return render;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkFeature network() {
|
||||
return network;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.saturnclient.impl.provider;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.saturnclient.common.provider.GLFWProvider;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
public class GLFWProviderImpl implements GLFWProvider {
|
||||
@Override
|
||||
public boolean isKeyPressed(int key) {
|
||||
return GLFW.glfwGetKey(SaturnClient.client.getWindow().getHandle(), key) == GLFW.GLFW_PRESS
|
||||
&& SaturnClient.client.currentScreen == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyName(int key) {
|
||||
return GLFW.glfwGetKeyName(key, GLFW.glfwGetKeyScancode(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.saturnclient.impl.provider;
|
||||
|
||||
import org.saturnclient.common.provider.RefConstructorProvider;
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.common.ref.render.TextRef;
|
||||
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class RefConstructorImpl implements RefConstructorProvider {
|
||||
@Override
|
||||
public IdentifierRef identifier(String fullPath) {
|
||||
return (IdentifierRef) (Object) Identifier.of(fullPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierRef identifier(String namespace, String path) {
|
||||
return (IdentifierRef) (Object) Identifier.of(namespace, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextRef text(String text) {
|
||||
return (TextRef) (Text) Text.literal(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.saturnclient.impl.provider;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.toast.SystemToast;
|
||||
//? if >=1.21.9 {
|
||||
import net.minecraft.entity.player.SkinTextures;
|
||||
//?} else
|
||||
//import net.minecraft.client.util.SkinTextures;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import org.saturnclient.common.provider.SaturnProvider;
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.common.ref.game.MinecraftClientRef;
|
||||
import org.saturnclient.cosmetics.Emotes;
|
||||
import org.saturnclient.impl.cosmetics.utils.IdentifierUtils;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
public class SaturnProviderImpl implements SaturnProvider {
|
||||
/** Looks up the signed-in player's skin; made once, since the skin provider caches it */
|
||||
private Supplier<Identifier> playerSkin;
|
||||
|
||||
@Override
|
||||
public MinecraftClientRef getClient() {
|
||||
return (MinecraftClientRef) SaturnClient.client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playEmote(UUID fromPlayerUuid, String emoteIdOrNull) {
|
||||
if (fromPlayerUuid == null) {
|
||||
return;
|
||||
}
|
||||
// An empty or unknown ID stops whatever the player is playing.
|
||||
Emotes.get(emoteIdOrNull == null ? "" : emoteIdOrNull).ifPresentOrElse(
|
||||
emote -> org.saturnclient.emotes.fabric.Emotes.play(fromPlayerUuid, emote.animation()),
|
||||
() -> org.saturnclient.emotes.fabric.Emotes.stop(fromPlayerUuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
SaturnClient.LOGGER.info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
SaturnClient.LOGGER.error(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable throwable) {
|
||||
SaturnClient.LOGGER.error(message, throwable);
|
||||
}
|
||||
|
||||
/** Shown longer than the vanilla default, since these ask the player to act. */
|
||||
private static final SystemToast.Type WARNING_TOAST = new SystemToast.Type(15_000L);
|
||||
|
||||
@Override
|
||||
public IdentifierRef getPlayerSkin() {
|
||||
if (playerSkin == null) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
// 1.21.9 moved SkinTextures and renamed the skin provider's lookup.
|
||||
//? if >=1.21.9 {
|
||||
Supplier<SkinTextures> textures = client.getSkinProvider().supplySkinTextures(client.getGameProfile(), false);
|
||||
playerSkin = () -> textures.get().body().texturePath();
|
||||
//?} else {
|
||||
/*Supplier<SkinTextures> textures = client.getSkinProvider().getSkinTexturesSupplier(client.getGameProfile());
|
||||
playerSkin = () -> textures.get().texture();
|
||||
*///?}
|
||||
}
|
||||
|
||||
return (IdentifierRef) (Object) playerSkin.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModVersion() {
|
||||
return FabricLoader.getInstance().getModContainer(SaturnClient.MOD_ID)
|
||||
.map(mod -> mod.getMetadata().getVersion().getFriendlyString())
|
||||
.orElse("unknown");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showWarning(String title, String message) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
client.execute(() -> client.getToastManager().add(
|
||||
SystemToast.create(client, WARNING_TOAST, Text.literal(title), Text.literal(message))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBufferedImageTexture(IdentifierRef i, BufferedImage bi) {
|
||||
IdentifierUtils.registerBufferedImageTextureFast(i, bi);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.saturnclient.impl.ref;
|
||||
|
||||
import org.joml.Matrix3x2fStack;
|
||||
import org.saturnclient.common.ref.render.MatrixStackRef;
|
||||
|
||||
public class Matrix3x2fStackRef implements MatrixStackRef {
|
||||
public final Matrix3x2fStack stack;
|
||||
|
||||
public Matrix3x2fStackRef(Matrix3x2fStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push() {
|
||||
stack.pushMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pop() {
|
||||
stack.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scale(float x, float y) {
|
||||
stack.scale(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(float x, float y) {
|
||||
stack.translate(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(float angle) {
|
||||
stack.rotate((float) Math.toRadians(angle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(float angle, float originX, float originY, float originZ) {
|
||||
translate(originX, originY);
|
||||
rotate(angle);
|
||||
translate(-originX, -originY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package org.saturnclient.impl.ui;
|
||||
|
||||
// Entities in the UI are drawn through the GUI render state from 1.21.6, and straight into vertex
|
||||
// consumers before. This file has one implementation for each side.
|
||||
//? if >=1.21.6 {
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.components.SkinPreview.EntityDrawer;
|
||||
|
||||
//? if >=1.21.9 {
|
||||
import net.minecraft.client.render.entity.EntityRenderManager;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.client.render.entity.EntityRenderer;
|
||||
import net.minecraft.client.render.entity.state.EntityRenderState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class EntityDrawerImpl implements EntityDrawer {
|
||||
@Override
|
||||
public boolean render(RenderScope renderScope, int width, int height, float yaw) {
|
||||
LivingEntity entity = SaturnClient.client.player;
|
||||
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The player is about 1.8 blocks tall; leave some room above and below.
|
||||
drawEntity(renderScope, 0, 0, width, height, (int) (height / 2.2F), 0.0625F, yaw, entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Draws the entity in the box, turned by yaw degrees (0 faces the viewer) with its head straight.
|
||||
public static void drawEntity(RenderScope renderScope, int x1, int y1, int x2, int y2, int size, float scale,
|
||||
float yaw, LivingEntity entity) {
|
||||
renderScope.enableScissor(x1, y1, x2, y2);
|
||||
Quaternionf quaternionf = (new Quaternionf()).rotateZ((float) Math.PI);
|
||||
Quaternionf quaternionf2 = new Quaternionf();
|
||||
float j = entity.bodyYaw;
|
||||
float k = entity.getYaw();
|
||||
float l = entity.getPitch();
|
||||
float m = entity.lastHeadYaw;
|
||||
float n = entity.headYaw;
|
||||
entity.bodyYaw = 180.0F + yaw;
|
||||
entity.setYaw(180.0F + yaw);
|
||||
entity.setPitch(0.0F);
|
||||
entity.headYaw = entity.getYaw();
|
||||
entity.lastHeadYaw = entity.getYaw();
|
||||
float o = entity.getScale();
|
||||
Vector3f vector3f = new Vector3f(0.0F, entity.getHeight() / 2.0F + scale * o, 0.0F);
|
||||
float p = (float) size / o;
|
||||
drawEntity(renderScope, x1, y1, x2, y2, p, vector3f, quaternionf, quaternionf2, entity);
|
||||
entity.bodyYaw = j;
|
||||
entity.setYaw(k);
|
||||
entity.setPitch(l);
|
||||
entity.lastHeadYaw = m;
|
||||
entity.headYaw = n;
|
||||
renderScope.disableScissor();
|
||||
}
|
||||
|
||||
public static void drawEntity(RenderScope renderScope, int x1, int y1, int x2, int y2, float scale,
|
||||
Vector3f translation, Quaternionf rotation, @Nullable Quaternionf overrideCameraAngle,
|
||||
LivingEntity entity) {
|
||||
//? if >=1.21.9 {
|
||||
EntityRenderManager entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
|
||||
//?} else
|
||||
//EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
|
||||
EntityRenderer<? super LivingEntity, ?> entityRenderer = entityRenderDispatcher.getRenderer(entity);
|
||||
EntityRenderState entityRenderState = entityRenderer.getAndUpdateRenderState(entity, 1.0F);
|
||||
//? if <1.21.11
|
||||
//entityRenderState.hitbox = null;
|
||||
|
||||
if (renderScope instanceof RenderScopeImpl i)
|
||||
i.addEntity(entityRenderState, scale, translation, rotation, overrideCameraAngle, x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
//?} else {
|
||||
/*import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.components.SkinPreview.EntityDrawer;
|
||||
|
||||
import net.minecraft.client.render.DiffuseLighting;
|
||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class EntityDrawerImpl implements EntityDrawer {
|
||||
// Draws the entity in the box, turned by yaw degrees (0 faces the viewer) with its head straight.
|
||||
public static void drawEntity(RenderScope renderScope, int x1, int y1, int x2, int y2, int size, float f,
|
||||
float yaw, LivingEntity entity) {
|
||||
float g = (float) (x1 + x2) / 2.0F;
|
||||
float h = (float) (y1 + y2) / 2.0F;
|
||||
renderScope.enableScissor(x1, y1, x2, y2);
|
||||
Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F);
|
||||
float k = entity.bodyYaw;
|
||||
float l = entity.getYaw();
|
||||
float m = entity.getPitch();
|
||||
//? if >=1.21.5
|
||||
float n = entity.lastHeadYaw;
|
||||
//? if <1.21.5
|
||||
//float n = entity.prevHeadYaw;
|
||||
float o = entity.headYaw;
|
||||
entity.setYaw(180.0F + yaw);
|
||||
entity.bodyYaw = 180.0F + yaw;
|
||||
entity.setPitch(0.0F);
|
||||
entity.headYaw = entity.getYaw();
|
||||
//? if >=1.21.5
|
||||
entity.lastHeadYaw = entity.getHeadYaw();
|
||||
//? if <1.21.5
|
||||
//entity.prevHeadYaw = entity.getHeadYaw();
|
||||
entity.setCustomNameVisible(false);
|
||||
|
||||
float p = entity.getScale();
|
||||
Vector3f vector3f = new Vector3f(0.0F, entity.getHeight() / 2.0F + f * p, 0.0F);
|
||||
float q = (float) size / p;
|
||||
drawEntity(renderScope, g, h, q, vector3f, quaternionf, null, entity);
|
||||
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.bodyYaw = k;
|
||||
entity.setYaw(l);
|
||||
entity.setPitch(m);
|
||||
//? if >=1.21.5
|
||||
entity.lastHeadYaw = n;
|
||||
//? if <1.21.5
|
||||
//entity.prevHeadYaw = n;
|
||||
entity.headYaw = o;
|
||||
renderScope.disableScissor();
|
||||
}
|
||||
|
||||
public static void drawEntity(RenderScope renderScope, float x, float y, float size, Vector3f vector3f,
|
||||
Quaternionf quaternionf, @Nullable Quaternionf quaternionf2, LivingEntity entity) {
|
||||
if (renderScope instanceof RenderScopeImpl scopeImpl) {
|
||||
scopeImpl.matrices.push();
|
||||
scopeImpl.matrices.translate((double) x, (double) y, 0);
|
||||
scopeImpl.matrices.scale(size, size, -size);
|
||||
scopeImpl.matrices.translate(vector3f.x, vector3f.y, vector3f.z);
|
||||
scopeImpl.matrices.multiply(quaternionf);
|
||||
scopeImpl.draw();
|
||||
//? if >=1.21.5
|
||||
DiffuseLighting.disableGuiDepthLighting();
|
||||
//? if <1.21.5
|
||||
//DiffuseLighting.method_34742();
|
||||
EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
|
||||
|
||||
entityRenderDispatcher.setRenderShadows(false);
|
||||
scopeImpl.draw((vertexConsumers) -> {
|
||||
entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 1.0F,
|
||||
scopeImpl.matrices, vertexConsumers, 15728880);
|
||||
});
|
||||
|
||||
scopeImpl.draw();
|
||||
entityRenderDispatcher.setRenderShadows(true);
|
||||
scopeImpl.getMatrixStack().pop();
|
||||
DiffuseLighting.enableGuiDepthLighting();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean render(RenderScope renderScope, int width, int height, float yaw) {
|
||||
LivingEntity entity = SaturnClient.client.player;
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The player is about 1.8 blocks tall; leave some room above and below.
|
||||
drawEntity(renderScope, 0, 0, width, height, (int) (height / 2.2F), 0.0625F, yaw, entity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
@@ -0,0 +1,380 @@
|
||||
package org.saturnclient.impl.ui;
|
||||
|
||||
// Glass: a copy of the game behind the screen, blurred, drawn through each panel's rounded rectangle
|
||||
// texture as a mask. There's a copy for each blur strength in use (menus and widgets have their own),
|
||||
// blurred with vanilla's blur at that radius, so it holds the world or panorama without the screen's
|
||||
// own animated background blur.
|
||||
//
|
||||
// The GUI rewrites split this into three implementations:
|
||||
// - 1.21.6+: the GUI is drawn after the screen builds it, so the copy is taken from the main
|
||||
// framebuffer while the screen builds its GUI, and glass is a GUI element with its own pipeline
|
||||
// (shaders/core/glass.fsh). The blur is vanilla's effect rebuilt with the radius set.
|
||||
// - 1.21.5: the screen draws straight into the framebuffer, blurring it first, so the game is saved
|
||||
// before the blur (saveBackground). Glass is a render layer with its own pipeline
|
||||
// (shaders/core/glass_pre_1_21_6.fsh), and the blur takes the radius as it runs.
|
||||
// - 1.21.4: as 1.21.5, with GL framebuffers copied by blitting, and a shader program
|
||||
// (shaders/core/glass.json) instead of a pipeline.
|
||||
//? if >=1.21.6 {
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.textures.FilterMode;
|
||||
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.gl.PostEffectPipeline;
|
||||
import net.minecraft.client.gl.PostEffectProcessor;
|
||||
import net.minecraft.client.gl.RenderPipelines;
|
||||
import net.minecraft.client.gl.SimpleFramebuffer;
|
||||
import net.minecraft.client.render.DefaultFramebufferSet;
|
||||
import net.minecraft.client.render.ProjectionMatrix2;
|
||||
import net.minecraft.client.texture.AbstractTexture;
|
||||
import net.minecraft.client.texture.TextureSetup;
|
||||
import net.minecraft.client.util.Pool;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public final class GlassRenderer {
|
||||
public static final RenderPipeline PIPELINE = RenderPipeline.builder(RenderPipelines.POSITION_TEX_COLOR_SNIPPET)
|
||||
.withLocation(Identifier.of("saturnclient", "pipeline/glass"))
|
||||
.withFragmentShader(Identifier.of("saturnclient", "core/glass"))
|
||||
.withSampler("Sampler1")
|
||||
// The transforms block ends with LineWidth before 1.21.11 (see glass.fsh).
|
||||
//? if <1.21.11
|
||||
//.withShaderDefine("HAS_LINE_WIDTH")
|
||||
.build();
|
||||
|
||||
private static final Identifier BLUR = Identifier.ofVanilla("post_effect/blur.json");
|
||||
private static final ProjectionMatrix2 PROJECTION = new ProjectionMatrix2("saturn glass", 0.1f, 1000f, false);
|
||||
// For the blurs' intermediate targets, freed once unused for a few frames
|
||||
private static final Pool POOL = new Pool(3);
|
||||
|
||||
// By blur strength. A blur that failed to load is kept as null, so it isn't retried every frame.
|
||||
private static final Map<Integer, PostEffectProcessor> BLURS = new HashMap<>();
|
||||
private static final Map<Integer, SimpleFramebuffer> BACKDROPS = new HashMap<>();
|
||||
|
||||
private GlassRenderer() {
|
||||
}
|
||||
|
||||
// Copies the main framebuffer and blurs the copy by blur. Call once a frame for each blur, while
|
||||
// the screen builds its GUI, before drawing glass with it.
|
||||
public static void captureBackdrop(int blur) {
|
||||
Framebuffer main = SaturnClient.client.getFramebuffer();
|
||||
int width = main.textureWidth;
|
||||
int height = main.textureHeight;
|
||||
|
||||
SimpleFramebuffer backdrop = BACKDROPS.get(blur);
|
||||
if (backdrop == null) {
|
||||
backdrop = new SimpleFramebuffer("Saturn glass " + blur, width, height, false);
|
||||
BACKDROPS.put(blur, backdrop);
|
||||
} else if (backdrop.textureWidth != width || backdrop.textureHeight != height) {
|
||||
backdrop.resize(width, height);
|
||||
}
|
||||
//? if <1.21.11
|
||||
//backdrop.getColorAttachment().setTextureFilter(FilterMode.LINEAR, false);
|
||||
|
||||
RenderSystem.getDevice().createCommandEncoder().copyTextureToTexture(
|
||||
main.getColorAttachment(), backdrop.getColorAttachment(), 0, 0, 0, 0, 0, width, height);
|
||||
|
||||
PostEffectProcessor processor = getBlur(blur);
|
||||
if (processor != null) {
|
||||
processor.render(backdrop, POOL);
|
||||
}
|
||||
POOL.decrementLifespan();
|
||||
release(blur);
|
||||
}
|
||||
|
||||
// The mask, then the copy blurred by blur, as the glass pipeline samples them
|
||||
public static TextureSetup textures(AbstractTexture mask, int blur) {
|
||||
GpuTextureView backdrop = BACKDROPS.get(blur).getColorAttachmentView();
|
||||
//? if >=1.21.11
|
||||
return TextureSetup.of(mask.getGlTextureView(), mask.getSampler(), backdrop, RenderSystem.getSamplerCache().get(FilterMode.LINEAR));
|
||||
//? if <1.21.11
|
||||
//return TextureSetup.of(mask.getGlTextureView(), backdrop);
|
||||
}
|
||||
|
||||
// Frees the copies and blurs of strengths that are no longer set, besides kept
|
||||
private static void release(int kept) {
|
||||
BACKDROPS.entrySet().removeIf(entry -> {
|
||||
boolean unused = entry.getKey() != kept && !isSet(entry.getKey());
|
||||
if (unused) {
|
||||
entry.getValue().delete();
|
||||
}
|
||||
return unused;
|
||||
});
|
||||
BLURS.entrySet().removeIf(entry -> {
|
||||
boolean unused = entry.getKey() != kept && !isSet(entry.getKey());
|
||||
if (unused && entry.getValue() != null) {
|
||||
entry.getValue().close();
|
||||
}
|
||||
return unused;
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isSet(int blur) {
|
||||
return blur == Config.menuBlur.value || blur == Config.widgetBlur.value;
|
||||
}
|
||||
|
||||
private static PostEffectProcessor getBlur(int blur) {
|
||||
if (!BLURS.containsKey(blur)) {
|
||||
BLURS.put(blur, loadBlur(blur));
|
||||
}
|
||||
return BLURS.get(blur);
|
||||
}
|
||||
|
||||
// Vanilla's blur, with its radius set to blur. Vanilla's own leaves it at 0, which makes the shader
|
||||
// read the menu blur setting (Saturn's animated background blur while a Saturn screen is open).
|
||||
private static PostEffectProcessor loadBlur(int blur) {
|
||||
try (Reader reader = SaturnClient.client.getResourceManager().getResourceOrThrow(BLUR).getReader()) {
|
||||
JsonElement json = JsonParser.parseReader(reader);
|
||||
setRadius(json, blur);
|
||||
|
||||
PostEffectPipeline pipeline = PostEffectPipeline.CODEC.parse(JsonOps.INSTANCE, json).getOrThrow();
|
||||
return PostEffectProcessor.parseEffect(pipeline, SaturnClient.client.getTextureManager(),
|
||||
DefaultFramebufferSet.MAIN_ONLY, Identifier.of("saturnclient", "glass_blur_" + blur), PROJECTION);
|
||||
} catch (Exception e) {
|
||||
SaturnClient.LOGGER.error("Couldn't load the glass blur", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Sets every "Radius" uniform in the effect
|
||||
private static void setRadius(JsonElement json, int radius) {
|
||||
if (json.isJsonArray()) {
|
||||
json.getAsJsonArray().forEach(element -> setRadius(element, radius));
|
||||
} else if (json.isJsonObject()) {
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
if (object.has("name") && object.get("name").getAsString().equals("Radius")) {
|
||||
object.addProperty("value", (float) radius);
|
||||
}
|
||||
object.entrySet().forEach(entry -> setRadius(entry.getValue(), radius));
|
||||
}
|
||||
}
|
||||
}
|
||||
//?} else if >=1.21.5 {
|
||||
/*import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.textures.FilterMode;
|
||||
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.gl.PostEffectProcessor;
|
||||
import net.minecraft.client.gl.RenderPipelines;
|
||||
import net.minecraft.client.gl.SimpleFramebuffer;
|
||||
import net.minecraft.client.render.DefaultFramebufferSet;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.util.Pool;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public final class GlassRenderer {
|
||||
private static final RenderPipeline PIPELINE = RenderPipeline.builder(RenderPipelines.POSITION_TEX_COLOR_SNIPPET)
|
||||
.withLocation(Identifier.of("saturnclient", "pipeline/glass"))
|
||||
.withFragmentShader(Identifier.of("saturnclient", "core/glass_pre_1_21_6"))
|
||||
.withSampler("Sampler1")
|
||||
.build();
|
||||
|
||||
private static final Identifier BLUR = Identifier.ofVanilla("blur");
|
||||
// For the blur's intermediate target, freed once unused for a few frames
|
||||
private static final Pool POOL = new Pool(3);
|
||||
|
||||
private static final Map<Integer, SimpleFramebuffer> BACKDROPS = new HashMap<>();
|
||||
// By mask and blur
|
||||
private static final Map<String, RenderLayer> LAYERS = new HashMap<>();
|
||||
// The game behind the screen before the screen blurs it, which glass is blurred from
|
||||
private static SimpleFramebuffer background;
|
||||
|
||||
private GlassRenderer() {
|
||||
}
|
||||
|
||||
// Saves the main framebuffer for glass. Call each frame before the screen blurs its background.
|
||||
public static void saveBackground() {
|
||||
background = copy(SaturnClient.client.getFramebuffer(), background, "Saturn glass background");
|
||||
}
|
||||
|
||||
// Copies the saved background and blurs the copy by blur. Call once a frame for each blur, before
|
||||
// drawing glass with it.
|
||||
public static void captureBackdrop(int blur) {
|
||||
Framebuffer from = background != null ? background : SaturnClient.client.getFramebuffer();
|
||||
SimpleFramebuffer backdrop = copy(from, BACKDROPS.get(blur), "Saturn glass " + blur);
|
||||
BACKDROPS.put(blur, backdrop);
|
||||
|
||||
PostEffectProcessor processor = SaturnClient.client.getShaderLoader().loadPostEffect(BLUR,
|
||||
DefaultFramebufferSet.MAIN_ONLY);
|
||||
if (processor != null) {
|
||||
processor.render(backdrop, POOL, pass -> pass.setUniform("Radius", (float) blur));
|
||||
}
|
||||
POOL.decrementLifespan();
|
||||
release(blur);
|
||||
}
|
||||
|
||||
// Draws glass through mask with the copy blurred by blur
|
||||
public static RenderLayer getLayer(Identifier mask, int blur) {
|
||||
return LAYERS.computeIfAbsent(mask + " " + blur, key -> RenderLayer.of("saturn_glass", 786432, PIPELINE,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(new RenderPhase.TextureBase(() -> {
|
||||
RenderSystem.setShaderTexture(0,
|
||||
SaturnClient.client.getTextureManager().getTexture(mask).getGlTexture());
|
||||
RenderSystem.setShaderTexture(1, BACKDROPS.get(blur).getColorAttachment());
|
||||
}, () -> {
|
||||
}))
|
||||
.build(false)));
|
||||
}
|
||||
|
||||
// Frees the copies of strengths that are no longer set, besides kept
|
||||
private static void release(int kept) {
|
||||
BACKDROPS.entrySet().removeIf(entry -> {
|
||||
boolean unused = entry.getKey() != kept && entry.getKey() != Config.menuBlur.value
|
||||
&& entry.getKey() != Config.widgetBlur.value;
|
||||
if (unused) {
|
||||
entry.getValue().delete();
|
||||
}
|
||||
return unused;
|
||||
});
|
||||
}
|
||||
|
||||
// Copies from into to, made or resized to match
|
||||
private static SimpleFramebuffer copy(Framebuffer from, SimpleFramebuffer to, String name) {
|
||||
int width = from.textureWidth;
|
||||
int height = from.textureHeight;
|
||||
|
||||
if (to == null) {
|
||||
to = new SimpleFramebuffer(name, width, height, false);
|
||||
} else if (to.textureWidth != width || to.textureHeight != height) {
|
||||
to.resize(width, height);
|
||||
}
|
||||
to.getColorAttachment().setTextureFilter(FilterMode.LINEAR, false);
|
||||
|
||||
RenderSystem.getDevice().createCommandEncoder().copyTextureToTexture(
|
||||
from.getColorAttachment(), to.getColorAttachment(), 0, 0, 0, 0, 0, width, height);
|
||||
return to;
|
||||
}
|
||||
}
|
||||
*///?} else {
|
||||
/*import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
|
||||
import net.minecraft.client.gl.Defines;
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.gl.PostEffectProcessor;
|
||||
import net.minecraft.client.gl.ShaderProgramKey;
|
||||
import net.minecraft.client.gl.SimpleFramebuffer;
|
||||
import net.minecraft.client.render.DefaultFramebufferSet;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.util.Pool;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public final class GlassRenderer {
|
||||
private static final ShaderProgramKey PROGRAM = new ShaderProgramKey(Identifier.of("saturnclient", "core/glass"),
|
||||
VertexFormats.POSITION_TEXTURE_COLOR, Defines.EMPTY);
|
||||
|
||||
private static final Identifier BLUR = Identifier.ofVanilla("blur");
|
||||
// For the blur's intermediate target, freed once unused for a few frames
|
||||
private static final Pool POOL = new Pool(3);
|
||||
|
||||
private static final Map<Integer, SimpleFramebuffer> BACKDROPS = new HashMap<>();
|
||||
// By mask and blur
|
||||
private static final Map<String, RenderLayer> LAYERS = new HashMap<>();
|
||||
// The game behind the screen before the screen blurs it, which glass is blurred from
|
||||
private static SimpleFramebuffer background;
|
||||
|
||||
private GlassRenderer() {
|
||||
}
|
||||
|
||||
// Saves the main framebuffer for glass. Call each frame before the screen blurs its background.
|
||||
public static void saveBackground() {
|
||||
background = copy(SaturnClient.client.getFramebuffer(), background);
|
||||
}
|
||||
|
||||
// Copies the saved background and blurs the copy by blur. Call once a frame for each blur, before
|
||||
// drawing glass with it.
|
||||
public static void captureBackdrop(int blur) {
|
||||
Framebuffer from = background != null ? background : SaturnClient.client.getFramebuffer();
|
||||
SimpleFramebuffer backdrop = copy(from, BACKDROPS.get(blur));
|
||||
BACKDROPS.put(blur, backdrop);
|
||||
|
||||
PostEffectProcessor processor = SaturnClient.client.getShaderLoader().loadPostEffect(BLUR,
|
||||
DefaultFramebufferSet.MAIN_ONLY);
|
||||
if (processor != null) {
|
||||
processor.setUniforms("Radius", blur);
|
||||
processor.render(backdrop, POOL);
|
||||
}
|
||||
POOL.decrementLifespan();
|
||||
release(blur);
|
||||
SaturnClient.client.getFramebuffer().beginWrite(false);
|
||||
}
|
||||
|
||||
// Draws glass through mask with the copy blurred by blur
|
||||
public static RenderLayer getLayer(Identifier mask, int blur) {
|
||||
return LAYERS.computeIfAbsent(mask + " " + blur, key -> RenderLayer.of("saturn_glass",
|
||||
VertexFormats.POSITION_TEXTURE_COLOR, VertexFormat.DrawMode.QUADS, 786432,
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(new RenderPhase.TextureBase(() -> {
|
||||
RenderSystem.setShaderTexture(0, mask);
|
||||
RenderSystem.setShaderTexture(1, BACKDROPS.get(blur).getColorAttachment());
|
||||
}, () -> {
|
||||
}))
|
||||
.program(new RenderPhase.ShaderProgram(PROGRAM))
|
||||
.transparency(RenderPhase.TRANSLUCENT_TRANSPARENCY)
|
||||
.build(false)));
|
||||
}
|
||||
|
||||
// Frees the copies of strengths that are no longer set, besides kept
|
||||
private static void release(int kept) {
|
||||
BACKDROPS.entrySet().removeIf(entry -> {
|
||||
boolean unused = entry.getKey() != kept && entry.getKey() != Config.menuBlur.value
|
||||
&& entry.getKey() != Config.widgetBlur.value;
|
||||
if (unused) {
|
||||
entry.getValue().delete();
|
||||
}
|
||||
return unused;
|
||||
});
|
||||
}
|
||||
|
||||
// Copies from into to, made or resized to match
|
||||
private static SimpleFramebuffer copy(Framebuffer from, SimpleFramebuffer to) {
|
||||
int width = from.textureWidth;
|
||||
int height = from.textureHeight;
|
||||
|
||||
if (to == null) {
|
||||
to = new SimpleFramebuffer(width, height, false);
|
||||
} else if (to.textureWidth != width || to.textureHeight != height) {
|
||||
to.resize(width, height);
|
||||
}
|
||||
to.setTexFilter(GL11.GL_LINEAR);
|
||||
|
||||
GlStateManager._glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, from.fbo);
|
||||
GlStateManager._glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, to.fbo);
|
||||
GlStateManager._glBlitFrameBuffer(0, 0, width, height, 0, 0, width, height, GL11.GL_COLOR_BUFFER_BIT,
|
||||
GL11.GL_NEAREST);
|
||||
SaturnClient.client.getFramebuffer().beginWrite(false);
|
||||
return to;
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
@@ -0,0 +1,839 @@
|
||||
package org.saturnclient.impl.ui;
|
||||
|
||||
// 1.21.6 rewrote GUI rendering: render states and a 2D matrix stack (Matrix3x2fStack) instead of
|
||||
// drawing into vertex consumers with a MatrixStack. This file has one implementation for each side.
|
||||
//? if >=1.21.6 {
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix3x2f;
|
||||
import org.joml.Matrix3x2fStack;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.common.ref.asset.SpriteRef;
|
||||
import org.saturnclient.common.ref.game.ItemStackRef;
|
||||
import org.saturnclient.common.ref.render.MatrixStackRef;
|
||||
import org.saturnclient.impl.ref.Matrix3x2fStackRef;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.resources.Fonts;
|
||||
import org.saturnclient.ui.resources.SvgTexture;
|
||||
|
||||
import net.minecraft.client.gl.RenderPipelines;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.ScreenRect;
|
||||
import net.minecraft.client.gui.render.state.ColoredQuadGuiElementRenderState;
|
||||
import net.minecraft.client.gui.render.state.GuiRenderState;
|
||||
import net.minecraft.client.gui.render.state.ItemGuiElementRenderState;
|
||||
import net.minecraft.client.gui.render.state.TextGuiElementRenderState;
|
||||
import net.minecraft.client.gui.render.state.TexturedQuadGuiElementRenderState;
|
||||
import net.minecraft.client.gui.render.state.special.EntityGuiElementRenderState;
|
||||
import net.minecraft.client.render.entity.state.EntityRenderState;
|
||||
//? if >=1.21.7 {
|
||||
import net.minecraft.client.render.item.KeyedItemRenderState;
|
||||
//?} else
|
||||
//import net.minecraft.client.render.item.ItemRenderState;
|
||||
import net.minecraft.client.texture.AbstractTexture;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.texture.TextureSetup;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemDisplayContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import net.minecraft.util.crash.CrashReportSection;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RenderScopeImpl implements RenderScope {
|
||||
|
||||
public final Matrix3x2fStackRef matrices;
|
||||
public final GuiRenderState state;
|
||||
|
||||
private ScissorStack scissorStack;
|
||||
private int opacity = 0xFF << 24;
|
||||
// The glass blurs made for this scope's frame
|
||||
private final Set<Integer> capturedBlurs = new HashSet<>();
|
||||
|
||||
public RenderScopeImpl(DrawContext context) {
|
||||
this(context.getMatrices(), ((DrawContextAccessor) (Object) context).getState());
|
||||
}
|
||||
|
||||
public RenderScopeImpl(Matrix3x2fStack matrices, GuiRenderState state) {
|
||||
this.matrices = new Matrix3x2fStackRef(matrices);
|
||||
this.state = state;
|
||||
this.scissorStack = new ScissorStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MatrixStackRef getMatrixStack() {
|
||||
return matrices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOpacity(float alpha) {
|
||||
this.opacity = ((int) (alpha * 255)) << 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(int color) {
|
||||
int originalAlpha = (color >>> 24) & 0xFF;
|
||||
int newAlpha = (opacity >>> 24) & 0xFF;
|
||||
int mixedAlpha = (originalAlpha * newAlpha) / 255;
|
||||
return (mixedAlpha << 24) | (color & 0x00FFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(int x1, int y1, int x2, int y2, int color) {
|
||||
this.state.addSimpleElement(
|
||||
new ColoredQuadGuiElementRenderState(
|
||||
RenderPipelines.GUI,
|
||||
TextureSetup.empty(),
|
||||
new Matrix3x2f(this.matrices.stack),
|
||||
x1, y1, x2, y2, color, color,
|
||||
this.scissorStack.peekLast()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRectangle(int x, int y, int width, int height, int color) {
|
||||
if (color == 0)
|
||||
return;
|
||||
color = getColor(color);
|
||||
|
||||
int x1 = x;
|
||||
int x2 = x + width;
|
||||
int y1 = y;
|
||||
int y2 = y + height;
|
||||
|
||||
if (x2 < x1) {
|
||||
int tmp = x1;
|
||||
x1 = x2;
|
||||
x2 = tmp;
|
||||
}
|
||||
if (y2 < y1) {
|
||||
int tmp = y1;
|
||||
y1 = y2;
|
||||
y2 = tmp;
|
||||
}
|
||||
|
||||
this.fill(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(String text, int x, int y, int font, int color) {
|
||||
drawText(1.0f, text, x, y, font, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(float scale, String text, int x, int y, int font, int color) {
|
||||
if (color == 0)
|
||||
return;
|
||||
if (font == 0)
|
||||
scale *= 2;
|
||||
|
||||
int lineIndex = 0;
|
||||
for (String line : text.split("\n")) {
|
||||
int finalColor = getColor(color);
|
||||
|
||||
matrices.push();
|
||||
matrices.translate(x, y + (lineIndex * Fonts.getHeight()));
|
||||
matrices.scale(scale, scale);
|
||||
|
||||
this.state.addText(
|
||||
new TextGuiElementRenderState(
|
||||
SaturnClient.client.textRenderer,
|
||||
((Text) Fonts.setFont(line, font)).asOrderedText(),
|
||||
new Matrix3x2f(this.matrices.stack),
|
||||
0, font == 0 ? 1 : 8,
|
||||
//? if >=1.21.11 {
|
||||
finalColor, 0, false, false, this.scissorStack.peekLast()));
|
||||
//?} else
|
||||
//finalColor, 0, false, this.scissorStack.peekLast()));
|
||||
|
||||
matrices.pop();
|
||||
|
||||
lineIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledWindowWidth() {
|
||||
return SaturnClient.client.getWindow().getScaledWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledWindowHeight() {
|
||||
return SaturnClient.client.getWindow().getScaledHeight();
|
||||
}
|
||||
|
||||
// Texture rendering
|
||||
@Override
|
||||
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height) {
|
||||
drawTexture(sprite, x, y, u, v, width, height, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height, int color) {
|
||||
drawTexture(sprite, x, y, u, v, width, height, width, height, width, height, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
|
||||
int regionWidth, int regionHeight, int textureWidth, int textureHeight) {
|
||||
drawTexture(sprite, x, y, u, v, width, height, regionWidth, regionHeight, textureWidth, textureHeight, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
|
||||
int regionWidth, int regionHeight, int textureWidth, int textureHeight, int color) {
|
||||
drawTexturedQuad((Identifier) (Object) sprite, x, x + width, y, y + height,
|
||||
(u + 0f) / textureWidth,
|
||||
(u + regionWidth) / textureWidth,
|
||||
(v + 0f) / textureHeight,
|
||||
(v + regionHeight) / textureHeight,
|
||||
color);
|
||||
}
|
||||
|
||||
private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2,
|
||||
float u1, float u2, float v1, float v2, int color) {
|
||||
if (color == 0)
|
||||
return;
|
||||
color = getColor(color);
|
||||
|
||||
if (sprite.getPath().endsWith(".svg")) {
|
||||
sprite = (Identifier) (Object) SvgTexture.getSvg(
|
||||
(IdentifierRef) (Object) sprite,
|
||||
(x2 - x1) * 2, (y2 - y1) * 2);
|
||||
}
|
||||
|
||||
GpuTextureView gpuTextureView = SaturnClient.client.getTextureManager()
|
||||
.getTexture(sprite).getGlTextureView();
|
||||
|
||||
//? if >=1.21.11
|
||||
AbstractTexture abstractTexture = SaturnClient.client.getTextureManager().getTexture(sprite);
|
||||
|
||||
this.state.addSimpleElement(new TexturedQuadGuiElementRenderState(
|
||||
RenderPipelines.GUI_TEXTURED,
|
||||
//? if >=1.21.11 {
|
||||
TextureSetup.of(gpuTextureView, abstractTexture.getSampler()),
|
||||
//?} else
|
||||
//TextureSetup.withoutGlTexture(gpuTextureView),
|
||||
new Matrix3x2f(this.matrices.stack),
|
||||
x1, y1, x2, y2, u1, u2, v1, v2, color,
|
||||
this.scissorStack.peekLast()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGlass(IdentifierRef mask, int x, int y, int width, int height, int blur) {
|
||||
int color = getColor(0xFFFFFFFF);
|
||||
if (mask == null || color >>> 24 == 0)
|
||||
return;
|
||||
|
||||
if (capturedBlurs.add(blur)) {
|
||||
GlassRenderer.captureBackdrop(blur);
|
||||
}
|
||||
|
||||
AbstractTexture maskTexture = SaturnClient.client.getTextureManager().getTexture((Identifier) (Object) mask);
|
||||
this.state.addSimpleElement(new TexturedQuadGuiElementRenderState(
|
||||
GlassRenderer.PIPELINE,
|
||||
GlassRenderer.textures(maskTexture, blur),
|
||||
new Matrix3x2f(this.matrices.stack),
|
||||
x, y, x + width, y + height, 0, 1, 0, 1, color,
|
||||
this.scissorStack.peekLast()));
|
||||
}
|
||||
|
||||
// Scissor management
|
||||
@Override
|
||||
public void enableScissor(int x1, int y1, int x2, int y2) {
|
||||
ScreenRect rect = new ScreenRect(x1, y1, x2 - x1, y2 - y1).transform(this.matrices.stack);
|
||||
scissorStack.push(rect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableScissor() {
|
||||
scissorStack.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scissorContains(int x, int y) {
|
||||
return scissorStack.contains(x, y);
|
||||
}
|
||||
|
||||
public static class ScissorStack {
|
||||
private final Deque<ScreenRect> stack = new ArrayDeque<>();
|
||||
|
||||
public ScreenRect push(ScreenRect rect) {
|
||||
ScreenRect last = stack.peekLast();
|
||||
if (last != null) {
|
||||
ScreenRect intersection = Objects.requireNonNullElse(rect.intersection(last), ScreenRect.empty());
|
||||
stack.addLast(intersection);
|
||||
return intersection;
|
||||
} else {
|
||||
stack.addLast(rect);
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ScreenRect pop() {
|
||||
if (stack.isEmpty())
|
||||
throw new IllegalStateException("Scissor stack underflow");
|
||||
stack.removeLast();
|
||||
return stack.peekLast();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ScreenRect peekLast() {
|
||||
return stack.peekLast();
|
||||
}
|
||||
|
||||
public boolean contains(int x, int y) {
|
||||
return stack.isEmpty() || stack.peekLast().contains(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// Item rendering
|
||||
@Override
|
||||
public void drawItem(ItemStackRef stack, int x, int y) {
|
||||
drawItem(null, SaturnClient.client.world, stack, x, y, 0);
|
||||
}
|
||||
|
||||
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStackRef stack, int x, int y,
|
||||
int seed) {
|
||||
drawItem(entity, world, (ItemStack) (Object) stack, x, y, seed, 0);
|
||||
}
|
||||
|
||||
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed,
|
||||
int z) {
|
||||
if (!stack.isEmpty()) {
|
||||
//? if >=1.21.7 {
|
||||
KeyedItemRenderState keyedItemRenderState = new KeyedItemRenderState();
|
||||
//?} else
|
||||
//ItemRenderState keyedItemRenderState = new ItemRenderState();
|
||||
SaturnClient.client.getItemModelManager().clearAndUpdate(keyedItemRenderState, stack,
|
||||
ItemDisplayContext.GUI, world,
|
||||
entity, seed);
|
||||
|
||||
try {
|
||||
this.state.addItem(new ItemGuiElementRenderState(stack.getItem().getName().toString(),
|
||||
new Matrix3x2f(this.matrices.stack), keyedItemRenderState, x, y,
|
||||
this.scissorStack.peekLast()));
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashReport = CrashReport.create(throwable, "Rendering item");
|
||||
CrashReportSection crashReportSection = crashReport.addElement("Item being rendered");
|
||||
crashReportSection.add("Item Type", () -> String.valueOf(stack.getItem()));
|
||||
crashReportSection.add("Item Components", () -> String.valueOf(stack.getComponents()));
|
||||
crashReportSection.add("Item Foil", () -> String.valueOf(stack.hasGlint()));
|
||||
throw new CrashException(crashReport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height) {
|
||||
drawSpriteStretched(sprite, x, y, width, height, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height, int color) {
|
||||
Sprite mcSprite = (Sprite) sprite;
|
||||
if (color == 0 || width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
drawTexturedQuad(mcSprite.getAtlasId(), x, x + width, y, y + height,
|
||||
mcSprite.getMinU(), mcSprite.getMaxU(), mcSprite.getMinV(), mcSprite.getMaxV(), color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
// No-op for now
|
||||
}
|
||||
|
||||
public void drawBorder(int x, int y, int width, int height, int color) {
|
||||
fill(x, y, x + width, y + 1, color);
|
||||
fill(x, y + height - 1, x + width, y + height, color);
|
||||
fill(x, y + 1, x + 1, y + height - 1, color);
|
||||
fill(x + width - 1, y + 1, x + width, y + height - 1, color);
|
||||
}
|
||||
|
||||
public void addEntity(EntityRenderState entityState, float scale, Vector3f translation, Quaternionf rotation,
|
||||
@Nullable Quaternionf overrideCameraAngle, int x1, int y1, int x2, int y2) {
|
||||
|
||||
Matrix3x2f mat = this.matrices.stack;
|
||||
float offsetX = mat.m20;
|
||||
float offsetY = mat.m21;
|
||||
float scaleX = mat.m00; // current matrix X scale
|
||||
float scaleY = mat.m11; // current matrix Y scale
|
||||
|
||||
int adjustedX1 = (int) (x1 * scaleX + offsetX);
|
||||
int adjustedY1 = (int) (y1 * scaleY + offsetY);
|
||||
int adjustedX2 = (int) (x2 * scaleX + offsetX);
|
||||
int adjustedY2 = (int) (y2 * scaleY + offsetY);
|
||||
|
||||
float adjustedScale = scale * scaleX; // apply matrix scale to entity scale too
|
||||
|
||||
this.state.addSpecialElement(new EntityGuiElementRenderState(entityState, translation, rotation,
|
||||
overrideCameraAngle, adjustedX1, adjustedY1, adjustedX2, adjustedY2, adjustedScale,
|
||||
this.scissorStack.peekLast()));
|
||||
}
|
||||
}
|
||||
//?} else {
|
||||
/*import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||
import org.saturnclient.common.ref.asset.SpriteRef;
|
||||
import org.saturnclient.common.ref.game.ItemStackRef;
|
||||
import org.saturnclient.common.ref.render.MatrixStackRef;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.resources.Fonts;
|
||||
import org.saturnclient.ui.resources.SvgTexture;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.font.TextRenderer.TextLayerType;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.ScreenRect;
|
||||
import net.minecraft.client.render.DiffuseLighting;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.ItemRenderState;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.Window;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
//? if >=1.21.5
|
||||
import net.minecraft.item.ItemDisplayContext;
|
||||
//? if <1.21.5
|
||||
//import net.minecraft.item.ModelTransformationMode;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import net.minecraft.util.crash.CrashReportSection;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RenderScopeImpl implements RenderScope {
|
||||
// ----------------------------
|
||||
// Fields
|
||||
// ----------------------------
|
||||
public MatrixStack matrices;
|
||||
public VertexConsumerProvider.Immediate vertexConsumers;
|
||||
private ScissorStack scissorStack = new ScissorStack();
|
||||
private int opacity = 255 << 24;
|
||||
// The glass blurs made for this scope's frame
|
||||
private final Set<Integer> capturedBlurs = new HashSet<>();
|
||||
private final ItemRenderState itemRenderState;
|
||||
|
||||
// ----------------------------
|
||||
// Constructors
|
||||
// ----------------------------
|
||||
public RenderScopeImpl(DrawContext context) {
|
||||
this(context.getMatrices(), ((DrawContextAccessor) context).getVertexConsumers());
|
||||
}
|
||||
|
||||
public RenderScopeImpl(MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers) {
|
||||
this.matrices = matrices;
|
||||
this.vertexConsumers = vertexConsumers;
|
||||
this.scissorStack = new ScissorStack();
|
||||
this.itemRenderState = new ItemRenderState();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Matrix & Transform
|
||||
// ----------------------------
|
||||
@Override
|
||||
public MatrixStackRef getMatrixStack() {
|
||||
return (MatrixStackRef) matrices;
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Color & Opacity
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void setOpacity(float alpha) {
|
||||
this.opacity = (int) (alpha * 255) << 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(int color) {
|
||||
int originalAlpha = (color >>> 24) & 0xFF;
|
||||
int newAlpha = (opacity >>> 24) & 0xFF;
|
||||
int mixedAlpha = (originalAlpha * newAlpha) / 255;
|
||||
return (mixedAlpha << 24) | (color & 0x00FFFFFF);
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Draw / Window Info
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void draw() {
|
||||
this.vertexConsumers.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledWindowWidth() {
|
||||
return SaturnClient.client.getWindow().getScaledWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScaledWindowHeight() {
|
||||
return SaturnClient.client.getWindow().getScaledHeight();
|
||||
}
|
||||
|
||||
public void draw(Consumer<VertexConsumerProvider> drawer) {
|
||||
drawer.accept(this.vertexConsumers);
|
||||
this.vertexConsumers.draw();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Shapes
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void drawRectangle(int x, int y, int width, int height, int color) {
|
||||
if (color == 0)
|
||||
return;
|
||||
color = getColor(color);
|
||||
|
||||
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
||||
|
||||
int x1 = x;
|
||||
int x2 = x + width;
|
||||
int y1 = y;
|
||||
int y2 = y + height;
|
||||
|
||||
if (x1 < x2) {
|
||||
int tmp = x1;
|
||||
x1 = x2;
|
||||
x2 = tmp;
|
||||
}
|
||||
if (y1 < y2) {
|
||||
int tmp = y1;
|
||||
y1 = y2;
|
||||
y2 = tmp;
|
||||
}
|
||||
|
||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(RenderLayer.getGui());
|
||||
vertexConsumer.vertex(matrix4f, x1, y1, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x1, y2, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y2, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y1, 0).color(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(int x1, int y1, int x2, int y2, int color) {
|
||||
fill(x1, y1, x2, y2, 0, color);
|
||||
}
|
||||
|
||||
public void fill(int x1, int y1, int x2, int y2, int z, int color) {
|
||||
fill(RenderLayer.getGui(), x1, y1, x2, y2, z, color);
|
||||
}
|
||||
|
||||
public void fill(RenderLayer layer, int x1, int y1, int x2, int y2, int color) {
|
||||
fill(layer, x1, y1, x2, y2, 0, color);
|
||||
}
|
||||
|
||||
public void fill(RenderLayer layer, int x1, int y1, int x2, int y2, int z, int color) {
|
||||
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
||||
if (x1 < x2) {
|
||||
int tmp = x1;
|
||||
x1 = x2;
|
||||
x2 = tmp;
|
||||
}
|
||||
if (y1 < y2) {
|
||||
int tmp = y1;
|
||||
y1 = y2;
|
||||
y2 = tmp;
|
||||
}
|
||||
|
||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(layer);
|
||||
vertexConsumer.vertex(matrix4f, x1, y1, z).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x1, y2, z).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y2, z).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y1, z).color(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBorder(int x, int y, int width, int height, int color) {
|
||||
fill(x, y, x + width, y + 1, color);
|
||||
fill(x, y + height - 1, x + width, y + height, color);
|
||||
fill(x, y + 1, x + 1, y + height - 1, color);
|
||||
fill(x + width - 1, y + 1, x + width, y + height - 1, color);
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Text
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void drawText(String text, int x, int y, int font, int color) {
|
||||
drawText(1.0f, text, x, y, font, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawText(float scale, String text, int x, int y, int font, int color) {
|
||||
if (color == 0)
|
||||
return;
|
||||
if (font == 0)
|
||||
scale *= 2;
|
||||
|
||||
int i = 0;
|
||||
for (String line : text.split("\n")) {
|
||||
color = getColor(color);
|
||||
matrices.push();
|
||||
matrices.translate(x, y + i * Fonts.getHeight(), 0);
|
||||
matrices.scale(scale, scale, 1.0f);
|
||||
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
||||
textRenderer.draw((Text) Fonts.setFont(line, font), 0, font == 0 ? 1 : 7, color, false,
|
||||
matrices.peek().getPositionMatrix(), vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
||||
matrices.pop();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Textures & Sprites
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height) {
|
||||
drawTexture(sprite, x, y, u, v, width, height, width, height, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height, int color) {
|
||||
drawTexture(sprite, x, y, u, v, width, height, width, height, width, height, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
|
||||
int regionWidth, int regionHeight, int textureWidth, int textureHeight) {
|
||||
drawTexture(sprite, x, y, u, v, width, height, regionWidth, regionHeight, textureWidth, textureHeight, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTexture(IdentifierRef sprite, int x, int y, float u, float v, int width, int height,
|
||||
int regionWidth, int regionHeight, int textureWidth, int textureHeight, int color) {
|
||||
drawTexturedQuad((Identifier) (Object) sprite, x, x + width, y, y + height,
|
||||
(u + 0.0f) / textureWidth, (u + regionWidth) / textureWidth,
|
||||
(v + 0.0f) / textureHeight, (v + regionHeight) / textureHeight, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSpriteStretched(SpriteRef sprite, int x, int y, int width, int height) {
|
||||
drawSpriteStretched(sprite, x, y, width, height, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSpriteStretched(SpriteRef saturnSprite, int x, int y, int width, int height, int color) {
|
||||
Sprite sprite = (Sprite) saturnSprite;
|
||||
if (color == 0)
|
||||
return;
|
||||
if (width != 0 && height != 0) {
|
||||
drawTexturedQuad(sprite.getAtlasId(), x, x + width, y, y + height,
|
||||
sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV(), color);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2,
|
||||
float u1, float u2, float v1, float v2, int color) {
|
||||
if (sprite.toString().endsWith(".svg")) {
|
||||
sprite = (Identifier) (Object) SvgTexture.getSvg((IdentifierRef) (Object) sprite, (x2 - x1) * 2,
|
||||
(y2 - y1) * 2);
|
||||
}
|
||||
if (color == 0)
|
||||
return;
|
||||
|
||||
x1 *= 4;
|
||||
x2 *= 4;
|
||||
y1 *= 4;
|
||||
y2 *= 4;
|
||||
color = getColor(color);
|
||||
|
||||
matrices.push();
|
||||
matrices.scale(0.25f, 0.25f, 1.0f);
|
||||
//? if <1.21.5
|
||||
//RenderSystem.setShaderTexture(0, sprite);
|
||||
RenderLayer renderLayer = RenderLayer.getGuiTextured(sprite);
|
||||
Matrix4f matrix4f = matrices.peek().getPositionMatrix();
|
||||
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(renderLayer);
|
||||
vertexConsumer.vertex(matrix4f, x1, y1, 0).texture(u1, v1).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x1, y2, 0).texture(u1, v2).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y2, 0).texture(u2, v2).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y1, 0).texture(u2, v1).color(color);
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGlass(IdentifierRef mask, int x, int y, int width, int height, int blur) {
|
||||
int color = getColor(0xFFFFFFFF);
|
||||
if (mask == null || color >>> 24 == 0)
|
||||
return;
|
||||
|
||||
if (capturedBlurs.add(blur)) {
|
||||
GlassRenderer.captureBackdrop(blur);
|
||||
}
|
||||
|
||||
// In quarter units, as drawTexturedQuad draws
|
||||
int x1 = x * 4;
|
||||
int x2 = (x + width) * 4;
|
||||
int y1 = y * 4;
|
||||
int y2 = (y + height) * 4;
|
||||
|
||||
matrices.push();
|
||||
matrices.scale(0.25f, 0.25f, 1.0f);
|
||||
Matrix4f matrix4f = matrices.peek().getPositionMatrix();
|
||||
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(GlassRenderer.getLayer((Identifier) (Object) mask, blur));
|
||||
vertexConsumer.vertex(matrix4f, x1, y1, 0).texture(0, 0).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x1, y2, 0).texture(0, 1).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y2, 0).texture(1, 1).color(color);
|
||||
vertexConsumer.vertex(matrix4f, x2, y1, 0).texture(1, 0).color(color);
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Items
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void drawItem(ItemStackRef item, int x, int y) {
|
||||
drawItem(SaturnClient.client.player, SaturnClient.client.world, item, x, y, 0);
|
||||
}
|
||||
|
||||
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStackRef stack, int x, int y,
|
||||
int seed) {
|
||||
drawItem(entity, world, (ItemStack) (Object) stack, x, y, seed, 0);
|
||||
}
|
||||
|
||||
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed,
|
||||
int z) {
|
||||
if (stack.isEmpty())
|
||||
return;
|
||||
|
||||
//? if >=1.21.5
|
||||
SaturnClient.client.getItemModelManager().update(itemRenderState, stack, ItemDisplayContext.GUI, world, entity, seed);
|
||||
//? if >=1.21.5
|
||||
SaturnClient.client.getItemModelManager().clearAndUpdate(this.itemRenderState, stack, ItemDisplayContext.GUI, world, entity, seed);
|
||||
//? if <1.21.5
|
||||
//SaturnClient.client.getItemModelManager().update(itemRenderState, stack, ModelTransformationMode.GUI, false, world, entity, seed);
|
||||
|
||||
this.matrices.push();
|
||||
//? if >=1.21.5
|
||||
this.matrices.translate((float) (x + 8), (float) (y + 8), (float) (150 + z));
|
||||
//? if <1.21.5
|
||||
//this.matrices.translate(x + 8, y + 8, 150 + (itemRenderState.hasDepth() ? z : 0));
|
||||
|
||||
try {
|
||||
this.matrices.scale(16.0F, -16.0F, 16.0F);
|
||||
boolean bl = !this.itemRenderState.isSideLit();
|
||||
if (bl) {
|
||||
this.draw();
|
||||
DiffuseLighting.disableGuiDepthLighting();
|
||||
}
|
||||
|
||||
this.itemRenderState.render(this.matrices, this.vertexConsumers, 15728880, OverlayTexture.DEFAULT_UV);
|
||||
this.draw();
|
||||
if (bl) {
|
||||
DiffuseLighting.enableGuiDepthLighting();
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashReport = CrashReport.create(throwable, "Rendering item");
|
||||
CrashReportSection crashReportSection = crashReport.addElement("Item being rendered");
|
||||
crashReportSection.add("Item Type", () -> String.valueOf(stack.getItem()));
|
||||
crashReportSection.add("Item Components", () -> String.valueOf(stack.getComponents()));
|
||||
crashReportSection.add("Item Foil", () -> String.valueOf(stack.hasGlint()));
|
||||
throw new CrashException(crashReport);
|
||||
}
|
||||
|
||||
this.matrices.pop();
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// Scissor / Clipping
|
||||
// ----------------------------
|
||||
@Override
|
||||
public void enableScissor(int x1, int y1, int x2, int y2) {
|
||||
ScreenRect screenRect = new ScreenRect(x1, y1, x2 - x1, y2 - y1)
|
||||
.transform(matrices.peek().getPositionMatrix());
|
||||
setScissor(scissorStack.push(screenRect));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableScissor() {
|
||||
setScissor(scissorStack.pop());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scissorContains(int x, int y) {
|
||||
return scissorStack.containsPoint(x, y);
|
||||
}
|
||||
|
||||
private void setScissor(@Nullable ScreenRect rect) {
|
||||
draw();
|
||||
if (rect != null) {
|
||||
Window window = SaturnClient.client.getWindow();
|
||||
int framebufferHeight = window.getFramebufferHeight();
|
||||
double scaleFactor = window.getScaleFactor();
|
||||
RenderSystem.enableScissor(
|
||||
(int) (rect.getLeft() * scaleFactor),
|
||||
(int) (framebufferHeight - rect.getBottom() * scaleFactor),
|
||||
Math.max(0, (int) (rect.width() * scaleFactor)),
|
||||
Math.max(0, (int) (rect.height() * scaleFactor)));
|
||||
} else {
|
||||
RenderSystem.disableScissor();
|
||||
}
|
||||
}
|
||||
|
||||
static class ScissorStack {
|
||||
private final Deque<ScreenRect> stack = new ArrayDeque<>();
|
||||
|
||||
public ScreenRect push(ScreenRect p_281812_) {
|
||||
ScreenRect screenrectangle = this.stack.peekLast();
|
||||
if (screenrectangle != null) {
|
||||
ScreenRect screenrectangle1 = Objects.requireNonNullElse(p_281812_.intersection(screenrectangle),
|
||||
ScreenRect.empty());
|
||||
this.stack.addLast(screenrectangle1);
|
||||
return screenrectangle1;
|
||||
} else {
|
||||
this.stack.addLast(p_281812_);
|
||||
return p_281812_;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ScreenRect pop() {
|
||||
if (this.stack.isEmpty()) {
|
||||
throw new IllegalStateException("Scissor stack underflow");
|
||||
} else {
|
||||
this.stack.removeLast();
|
||||
return this.stack.peekLast();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsPoint(int p_329411_, int p_333404_) {
|
||||
return this.stack.isEmpty() ? true : this.stack.peek().contains(p_329411_, p_333404_);
|
||||
}
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
@@ -0,0 +1,264 @@
|
||||
package org.saturnclient.impl.ui;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.saturnclient.config.Config;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.SaturnScreen;
|
||||
import org.saturnclient.ui.SaturnScreen.ScreenProvider;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
//? if >=1.21.9
|
||||
import net.minecraft.client.gui.Click;
|
||||
import net.minecraft.client.gui.CubeMapRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.RotatingCubeMapRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
//? if >=1.21.6 {
|
||||
import net.minecraft.client.texture.CubemapTexture;
|
||||
//?} else {
|
||||
/*import net.minecraft.client.texture.ResourceTexture;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
*///?}
|
||||
//? if >=1.21.9
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
//? if <1.21.6 {
|
||||
/*import net.minecraft.client.gl.PostEffectProcessor;
|
||||
import net.minecraft.client.render.DefaultFramebufferSet;
|
||||
import net.minecraft.client.util.Pool;
|
||||
*///?}
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class SaturnScreenFabric extends Screen implements ScreenProvider {
|
||||
protected static final Identifier PANORAMA = Identifier.of("saturnclient",
|
||||
"textures/gui/title/background/panorama");
|
||||
protected static final CubeMapRenderer PANORAMA_RENDERER = new CubeMapRenderer(PANORAMA);
|
||||
|
||||
public static final RotatingCubeMapRenderer ROTATING_PANORAMA_RENDERER;
|
||||
|
||||
static {
|
||||
ROTATING_PANORAMA_RENDERER = new RotatingCubeMapRenderer(PANORAMA_RENDERER);
|
||||
}
|
||||
|
||||
//? if <1.21.6
|
||||
//private final Pool pool = new Pool(3);
|
||||
public final SaturnScreen screen;
|
||||
|
||||
/** Whether the panorama's textures are loaded; it isn't drawn before (e.g. under the splash). */
|
||||
private static volatile boolean panoramaReady = false;
|
||||
|
||||
public static void preload(MinecraftClient client) {
|
||||
//? if >=1.21.6 {
|
||||
// From 1.21.6 CubeMapRenderer draws from one cube map texture made of panorama_0..5.png.
|
||||
// CubeMapRenderer.registerTextures only stores it for the next resource reload, which has
|
||||
// already happened by now, so register it through the overload that loads it right away.
|
||||
client.getTextureManager().registerTexture(PANORAMA, new CubemapTexture(PANORAMA));
|
||||
//?} else {
|
||||
/*TextureManager textureManager = client.getTextureManager();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
String var10001 = PANORAMA.getPath();
|
||||
Identifier tex = PANORAMA.withPath(var10001 + "_" + i + ".png");
|
||||
ResourceTexture resourceTexture = new ResourceTexture(tex);
|
||||
textureManager.registerTexture(tex, resourceTexture);
|
||||
}
|
||||
*///?}
|
||||
panoramaReady = true;
|
||||
}
|
||||
|
||||
public SaturnScreenFabric(SaturnScreen screen) {
|
||||
super(Text.literal(screen.title));
|
||||
screen.provider = this;
|
||||
this.screen = screen;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
screen.init();
|
||||
}
|
||||
|
||||
//? if <1.21.6
|
||||
//@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
if (screen.start == null) {
|
||||
screen.start = Instant.now();
|
||||
}
|
||||
long elapsed = Duration.between(screen.start, Instant.now()).toMillis();
|
||||
|
||||
screen.updateScale();
|
||||
|
||||
mouseX = (int) (mouseX / screen.scale);
|
||||
mouseY = (int) (mouseY / screen.scale);
|
||||
|
||||
// From 1.21.6 the background, blur included, is drawn in renderBackground.
|
||||
//? if <1.21.6 {
|
||||
/*if (isShowingPanorama()) {
|
||||
ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, screen.backgroundOpacity, delta);
|
||||
}
|
||||
|
||||
// Glass is blurred from the game as it is before this screen blurs it.
|
||||
if (Config.usesGlass()) {
|
||||
context.draw();
|
||||
GlassRenderer.saveBackground();
|
||||
}
|
||||
|
||||
float radius = screen.getBackgroundBlur();
|
||||
PostEffectProcessor postEffectProcessor = radius < 1 ? null : this.client.getShaderLoader().loadPostEffect(
|
||||
Identifier.ofVanilla("blur"),
|
||||
DefaultFramebufferSet.MAIN_ONLY);
|
||||
|
||||
if (postEffectProcessor != null) {
|
||||
//? if >=1.21.5
|
||||
postEffectProcessor.render(this.client.getFramebuffer(), this.pool, pass -> pass.setUniform("Radius", radius));
|
||||
//? if <1.21.5
|
||||
//postEffectProcessor.setUniforms("Radius", radius);
|
||||
//? if <1.21.5
|
||||
//postEffectProcessor.render(this.client.getFramebuffer(), this.pool);
|
||||
}
|
||||
*///?}
|
||||
|
||||
RenderScope renderScope = new RenderScopeImpl(context);
|
||||
|
||||
screen.render(renderScope, mouseX, mouseY, delta, elapsed);
|
||||
}
|
||||
|
||||
//? if >=1.21.6 {
|
||||
// Vanilla's background would cover Saturn's panorama, and blurs by the vanilla setting. The
|
||||
// strength of this blur comes from GameRendererMixin, which gives Saturn's setting instead.
|
||||
@Override
|
||||
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
// The panorama renderer has no opacity (and takes no delta) from 1.21.6, so it's drawn fully
|
||||
// opaque.
|
||||
if (isShowingPanorama()) {
|
||||
ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, true);
|
||||
}
|
||||
|
||||
if (screen.getBackgroundBlur() >= 1) {
|
||||
context.applyBlur();
|
||||
}
|
||||
|
||||
if (client.world != null) {
|
||||
renderDarkening(context);
|
||||
}
|
||||
}
|
||||
//?}
|
||||
|
||||
/** Whether Saturn's panorama is behind the screen: outside a world, once it's loaded. */
|
||||
private boolean isShowingPanorama() {
|
||||
return panoramaReady && client.world == null && client.getCurrentServerEntry() == null;
|
||||
}
|
||||
|
||||
// 1.21.9 moved mouse and key events to Click and KeyInput.
|
||||
//? if >=1.21.9 {
|
||||
@Override
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
if (screen.mouseClicked(click.x(), click.y(), click.button())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.mouseClicked(click, doubled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(Click click, double offsetX, double offsetY) {
|
||||
// offsetX and offsetY are the drag deltas, as mouseDragged's deltaX and deltaY were before 1.21.9.
|
||||
if (screen.mouseDragged(click.x(), click.y(), click.button(), offsetX, offsetY)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.mouseDragged(click, offsetX, offsetY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
if (screen.mouseReleased(click.x(), click.y(), click.button())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.mouseReleased(click);
|
||||
}
|
||||
//?} else {
|
||||
/*@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (screen.mouseClicked(mouseX, mouseY, button)) {
|
||||
return true;
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
if (screen.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) {
|
||||
return true;
|
||||
}
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
if (screen.mouseReleased(mouseX, mouseY, button)) {
|
||||
return true;
|
||||
}
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
*///?}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
|
||||
if (screen.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) {
|
||||
return true;
|
||||
}
|
||||
return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
|
||||
}
|
||||
|
||||
//? if >=1.21.9 {
|
||||
@Override
|
||||
public boolean keyPressed(KeyInput input) {
|
||||
if (screen.keyPressed(input.getKeycode(), input.scancode(), input.modifiers())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.keyPressed(input);
|
||||
}
|
||||
//?} else {
|
||||
/*@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (screen.keyPressed(keyCode, scanCode, modifiers)) {
|
||||
return true;
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
*///?}
|
||||
|
||||
//? if >=1.21.11 {
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
screen.resize(width, height);
|
||||
super.resize(width, height);
|
||||
}
|
||||
//?} else {
|
||||
/*@Override
|
||||
public void resize(MinecraftClient client, int width, int height) {
|
||||
screen.resize(width, height);
|
||||
super.resize(client, width, height);
|
||||
}
|
||||
*///?}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.screen.onClose();
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.saturnclient.modules;
|
||||
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
public interface HudMod {
|
||||
public ModDimensions getDimensions();
|
||||
|
||||
public void renderDummy(RenderScope scope);
|
||||
|
||||
public void renderHud(RenderScope scope);
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package org.saturnclient.modules;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.saturnclient.config.manager.Property.NamedProperty;
|
||||
|
||||
public class ModDimensions {
|
||||
public Property<Integer> x = Property.integer(0);
|
||||
public Property<Integer> y = Property.integer(0);
|
||||
public Property<Float> scale = Property.floatProp(1.0f);
|
||||
public Property<Integer> bgColor = Property.color(0x00000000);
|
||||
public Property<Integer> fgColor = Property.color(0xFFffffff);
|
||||
public Property<Integer> radius = Property.integer(0);
|
||||
public Property<Integer> font = Property.font(0);
|
||||
public boolean renderBackground = true;
|
||||
|
||||
public int width = 0;
|
||||
public int height = 0;
|
||||
|
||||
public NamedProperty<Map<String, Property<?>>> prop() {
|
||||
return Property.namespace(Map.of(
|
||||
"X", x,
|
||||
"Y", y,
|
||||
"Scale", scale,
|
||||
"Background Color", bgColor,
|
||||
"Foreground Color", fgColor,
|
||||
"Corner Radius", radius,
|
||||
"Font", font)).named("In-Game Display");
|
||||
}
|
||||
|
||||
public ModDimensions() {
|
||||
}
|
||||
|
||||
public ModDimensions(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ModDimensions(int x, int y, int width, int height) {
|
||||
this.x.value = x;
|
||||
this.y.value = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ModDimensions(int x, int y, int width, int height, float scale) {
|
||||
this.x.value = x;
|
||||
this.y.value = y;
|
||||
this.scale.value = scale;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package org.saturnclient.modules;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.saturnclient.modules.mods.*;
|
||||
|
||||
public class ModManager {
|
||||
public static final List<Module> ENABLED_MODS = new ArrayList<>();
|
||||
public static final Module[] ALL_MODS = {
|
||||
new Crosshair(),
|
||||
new AutoSprint(),
|
||||
new ArmorDisplay(),
|
||||
new Fps(),
|
||||
new StatusEffects(),
|
||||
new Coordinates(),
|
||||
new Freelook(),
|
||||
new Keystrokes(),
|
||||
new Fullbright(),
|
||||
new NoFog(),
|
||||
new DayCounter(),
|
||||
new Speedometer(),
|
||||
new Zoom(),
|
||||
new HealthDisplay(),
|
||||
new Nametags(),
|
||||
new Ping(),
|
||||
new Tps(),
|
||||
new Clock()
|
||||
};
|
||||
|
||||
public static void init() {
|
||||
// Pre-filter enabled modules to avoid checking every tick
|
||||
updateEnabledModules();
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
// Only iterate over enabled modules
|
||||
for (Module m : ENABLED_MODS) {
|
||||
m.tick();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static synchronized void updateEnabledModules() {
|
||||
ENABLED_MODS.clear();
|
||||
for (Module m : ALL_MODS) {
|
||||
if (m.isEnabled()) {
|
||||
ENABLED_MODS.add(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Module[] getAllMods() {
|
||||
return ALL_MODS;
|
||||
}
|
||||
|
||||
public static void refreshEnabledModules() {
|
||||
updateEnabledModules();
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package org.saturnclient.modules;
|
||||
|
||||
import org.saturnclient.ui2.resources.Textures;
|
||||
import org.saturnclient.saturnclient.config.manager.ConfigManager;
|
||||
import org.saturnclient.saturnclient.config.manager.Property.NamedProperty;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public abstract class Module {
|
||||
private final ModuleDetails details;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public Module(ModuleDetails details, NamedProperty<?>... props) {
|
||||
this.details = details;
|
||||
configManager = new ConfigManager(details.name);
|
||||
for (NamedProperty<?> prop : props) {
|
||||
configManager.property(prop.name, prop.prop);
|
||||
}
|
||||
}
|
||||
|
||||
public void render(RenderScope scope) {
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
}
|
||||
|
||||
public abstract boolean isEnabled();
|
||||
|
||||
public final void setEnabled(boolean e) {
|
||||
onEnabled(e);
|
||||
ModManager.updateEnabledModules();
|
||||
}
|
||||
|
||||
public abstract void onEnabled(boolean e);
|
||||
|
||||
public final String getName() {
|
||||
return details.name;
|
||||
}
|
||||
|
||||
public Identifier getIconTexture() {
|
||||
return Textures.getModIcon(details.namespace);
|
||||
}
|
||||
|
||||
public ConfigManager getConfig() {
|
||||
return configManager;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return details.description;
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return details.tags;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return details.version;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package org.saturnclient.modules;
|
||||
|
||||
public class ModuleDetails {
|
||||
public String name;
|
||||
public String namespace;
|
||||
public String description;
|
||||
public String version;
|
||||
public String[] tags = {};
|
||||
|
||||
public ModuleDetails(String name, String namespace) {
|
||||
this.name = name;
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public ModuleDetails name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModuleDetails namespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModuleDetails description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModuleDetails version(String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModuleDetails tags(String... tags) {
|
||||
this.tags = tags;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
# Credits
|
||||
### Freelook
|
||||
- https://github.com/Celibistrial/freelook
|
||||
- https://modrinth.com/mod/freelook
|
||||
|
||||
**The other mods are coded by us, if you have a concern or we missed something feel free to submit a issue with the credits tag**
|
||||
@@ -1,102 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
|
||||
public class ArmorDisplay extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static ModDimensions dimensions = new ModDimensions(40, 75);
|
||||
private static Property<Boolean> useMainHand = Property.bool(false);
|
||||
|
||||
public ArmorDisplay() {
|
||||
super(new ModuleDetails("Armor Display", "armor")
|
||||
.description("Displays armor durability")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
useMainHand.named("Use Main Hand"),
|
||||
dimensions.prop());
|
||||
}
|
||||
|
||||
public void renderArmor(RenderScope scope, ItemStack mainHand, ItemStack helmet, ItemStack chestplate,
|
||||
ItemStack leggings, ItemStack boots) {
|
||||
int row = 0;
|
||||
|
||||
if (useMainHand.value && !mainHand.isEmpty()) {
|
||||
scope.drawItem(mainHand, 0, 15 * row);
|
||||
renderHealth(scope, row, mainHand.getMaxDamage(), mainHand.getDamage());
|
||||
row++;
|
||||
}
|
||||
|
||||
if (!helmet.isEmpty()) {
|
||||
scope.drawItem(helmet, 0, 15 * row);
|
||||
renderHealth(scope, row, helmet.getMaxDamage(), helmet.getDamage());
|
||||
row++;
|
||||
}
|
||||
|
||||
if (!chestplate.isEmpty()) {
|
||||
scope.drawItem(chestplate, 0, 15 * row);
|
||||
renderHealth(scope, row, chestplate.getMaxDamage(), chestplate.getDamage());
|
||||
row++;
|
||||
}
|
||||
if (!leggings.isEmpty()) {
|
||||
scope.drawItem(leggings, 0, 15 * row);
|
||||
renderHealth(scope, row, leggings.getMaxDamage(), leggings.getDamage());
|
||||
row++;
|
||||
}
|
||||
|
||||
if (!boots.isEmpty()) {
|
||||
scope.drawItem(boots, 0, 15 * row);
|
||||
renderHealth(scope, row, boots.getMaxDamage(), boots.getDamage());
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
public void renderHealth(RenderScope scope, int i, int max_damage, int damage) {
|
||||
if (max_damage > 0) {
|
||||
scope.drawText(0.5f, "" + (max_damage - damage), 17, (15 * i) + 3, dimensions.font.value,
|
||||
dimensions.fgColor.value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
renderArmor(scope,
|
||||
SaturnClient.client.player.getEquippedStack(EquipmentSlot.MAINHAND),
|
||||
SaturnClient.client.player.getEquippedStack(EquipmentSlot.HEAD),
|
||||
SaturnClient.client.player.getEquippedStack(EquipmentSlot.CHEST),
|
||||
SaturnClient.client.player.getEquippedStack(EquipmentSlot.LEGS),
|
||||
SaturnClient.client.player.getEquippedStack(EquipmentSlot.FEET));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
renderArmor(scope, new ItemStack(Items.DIAMOND_SWORD), new ItemStack(Items.DIAMOND_HELMET),
|
||||
new ItemStack(Items.DIAMOND_CHESTPLATE),
|
||||
new ItemStack(Items.DIAMOND_LEGGINGS), new ItemStack(Items.DIAMOND_BOOTS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
|
||||
public class AutoSprint extends Module {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
|
||||
public AutoSprint() {
|
||||
super(
|
||||
new ModuleDetails("Auto Sprint", "sprint")
|
||||
.description("Makes the player always sprint")
|
||||
.tags("Movement")
|
||||
.version("v0.1.0"),
|
||||
enabled.named("Enabled"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (SaturnClient.client.player == null || SaturnClient.client.getNetworkHandler() == null) {
|
||||
return;
|
||||
}
|
||||
if (SaturnClient.client.options.forwardKey.isPressed()
|
||||
&& !SaturnClient.client.options.backKey.isPressed()
|
||||
&& !SaturnClient.client.player.isSneaking()
|
||||
&& !SaturnClient.client.player.horizontalCollision
|
||||
&& !SaturnClient.client.player.isUsingItem()) {
|
||||
|
||||
Objects.requireNonNull(SaturnClient.client.player).setSprinting(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
public class Clock extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Integer> format = Property.select(0, "24 hour", "12 hour");
|
||||
private static Property<Boolean> seconds = Property.bool(false);
|
||||
private static ModDimensions dimensions = new ModDimensions(60, Fonts.getHeight());
|
||||
|
||||
public Clock() {
|
||||
super(new ModuleDetails("Clock", "clock")
|
||||
.description("Displays the current real-world time")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
format.named("Format"),
|
||||
seconds.named("Show seconds"),
|
||||
dimensions.prop()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
renderClock(scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
renderClock(scope);
|
||||
}
|
||||
|
||||
public void renderClock(RenderScope scope) {
|
||||
String text = "";
|
||||
LocalTime currentTime = LocalTime.now();
|
||||
|
||||
switch (format.value) {
|
||||
case 0:
|
||||
if (seconds.value) { text = currentTime.format(DateTimeFormatter.ofPattern("HH:mm:ss")); }
|
||||
else { text = currentTime.format(DateTimeFormatter.ofPattern("HH:mm")); }
|
||||
break;
|
||||
case 1:
|
||||
if (seconds.value) { text = currentTime.format(DateTimeFormatter.ofPattern("hh:mm:ss a")); }
|
||||
else { text = currentTime.format(DateTimeFormatter.ofPattern("hh:mm a")); }
|
||||
break;
|
||||
}
|
||||
|
||||
scope.drawText(text,
|
||||
0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
dimensions.height = 18 * text.split("\n").length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class Coordinates extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Integer> displayMethod = Property.select(0, "Flat", "Flat annotated", "Newline", "Newline annotated");
|
||||
private static ModDimensions dimensions = new ModDimensions(40, 18);
|
||||
|
||||
public Coordinates() {
|
||||
super(new ModuleDetails("Coordinates", "coords")
|
||||
.description("Displays your current coordinates")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
displayMethod.named("Display Method"),
|
||||
dimensions.prop()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
renderCoords(532, 69, 253, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
Vec3d pos = SaturnClient.client.player.getPos();
|
||||
renderCoords((int) pos.x, (int) pos.y, (int) pos.z, scope);
|
||||
}
|
||||
|
||||
public void renderCoords(int x, int y, int z, RenderScope scope) {
|
||||
String f = "%d %d %d"; // Flat
|
||||
switch (displayMethod.value) {
|
||||
case 1: // Flat annotated
|
||||
f = "X: %d Y: %d Z: %d";
|
||||
break;
|
||||
case 2: // Newline
|
||||
f = "%d\n%d\n%d";
|
||||
break;
|
||||
case 3: // Newline annotated
|
||||
f = "X: %d\nY: %d\nZ: %d";
|
||||
break;
|
||||
}
|
||||
String text = String.format(f, x, y, z);
|
||||
scope.drawText(text,
|
||||
0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
dimensions.height = 18 * text.split("\n").length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Textures;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
|
||||
public class Crosshair extends Module {
|
||||
public static Property<Boolean> enabled = Property.bool(false);
|
||||
|
||||
public Crosshair() {
|
||||
super(
|
||||
new ModuleDetails("Crosshair", "crosshair")
|
||||
.description("Changes the crosshair if you're aiming at a entity")
|
||||
.tags("Visuals", "Utility")
|
||||
.version("v0.1.0"),
|
||||
enabled.named("Enabled"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderScope scope) {
|
||||
if (enabled.value
|
||||
&& SaturnClient.client.targetedEntity != null
|
||||
&& SaturnClient.client.targetedEntity.isAlive()) {
|
||||
int scaledWidth = 15;
|
||||
int scaledHeight = 15;
|
||||
|
||||
scope.setRenderLayer(RenderLayer::getCrosshair);
|
||||
scope.drawTexture(Textures.CROSSHAIR_RANGE,
|
||||
(scope.getScaledWindowWidth() - scaledWidth) / 2,
|
||||
(scope.getScaledWindowHeight() - scaledHeight) / 2, 0.0F, 0.0F, scaledWidth, scaledHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
public class DayCounter extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static ModDimensions dimensions = new ModDimensions(40, 18);
|
||||
long day = 0;
|
||||
|
||||
public DayCounter() {
|
||||
super(new ModuleDetails("DayCounter", "day")
|
||||
.description("Displays the number of days that have passed")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
dimensions.prop()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
renderDay(271, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
day = (SaturnClient.client.world.getTimeOfDay() / 24000L);
|
||||
renderDay(day, scope);
|
||||
}
|
||||
|
||||
public void renderDay(long day, RenderScope scope) {
|
||||
String text = "Day: " + day;
|
||||
scope.drawText(text,
|
||||
0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
dimensions.height = 18 * text.split("\n").length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
public class Fps extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static ModDimensions dimensions = new ModDimensions(60, Fonts.getHeight());
|
||||
|
||||
public Fps() {
|
||||
super(new ModuleDetails("FPS Display", "fps")
|
||||
.description("Displays current FPS")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
dimensions.prop());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
String text = String.valueOf(SaturnClient.client.getCurrentFps()) + " FPS";
|
||||
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
String text = "369 FPS";
|
||||
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
|
||||
import net.minecraft.client.option.Perspective;
|
||||
|
||||
public class Freelook extends Module {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Boolean> toggle = Property.bool(true);
|
||||
public static Property<Integer> freelookKey = Property.keybinding(GLFW.GLFW_KEY_H);
|
||||
public static boolean isFreeLooking = false;
|
||||
private static boolean was1stPerson = false;
|
||||
|
||||
public Freelook() {
|
||||
super(
|
||||
new ModuleDetails("Freelook", "freelook")
|
||||
.description("Allows you to look around freely without moving your character")
|
||||
.tags("Movement", "Camera")
|
||||
.version("0.1.0"),
|
||||
enabled.named("Enabled"),
|
||||
toggle.named("Toggle freelook"),
|
||||
freelookKey.named("Freelook Keybinding")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (toggle.value) {
|
||||
if (freelookKey.wasKeyPressed()) {
|
||||
if (isFreeLooking) {
|
||||
stopFreelook();
|
||||
} else {
|
||||
startFreelook();
|
||||
}
|
||||
}
|
||||
} else if (freelookKey.isKeyPressed()) {
|
||||
if (!isFreeLooking) {
|
||||
startFreelook();
|
||||
}
|
||||
} else if (isFreeLooking) {
|
||||
stopFreelook();
|
||||
}
|
||||
}
|
||||
|
||||
private void startFreelook() {
|
||||
isFreeLooking = true;
|
||||
was1stPerson = SaturnClient.client.options.getPerspective() == Perspective.FIRST_PERSON;
|
||||
SaturnClient.client.options.setPerspective(Perspective.THIRD_PERSON_BACK);
|
||||
}
|
||||
|
||||
private void stopFreelook() {
|
||||
if (was1stPerson) {
|
||||
SaturnClient.client.options.setPerspective(Perspective.FIRST_PERSON);
|
||||
}
|
||||
isFreeLooking = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
|
||||
public class Fullbright extends Module {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Integer> brightness = Property.integer(100);
|
||||
|
||||
public Fullbright() {
|
||||
super(
|
||||
new ModuleDetails("Fullbright", "fullbright")
|
||||
.description("Allows you to see in the dark")
|
||||
.tags("Camera")
|
||||
.version("v0.1.0"),
|
||||
enabled.named("Enabled"),
|
||||
brightness.named("Brightness %"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
|
||||
public static boolean shouldOverrideBrightness() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
public static float getBrightnessValue() {
|
||||
return brightness.value / 10;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class HealthDisplay extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Integer> displayMode = Property.select(0, "Health", "Hearts");
|
||||
private static Property<Integer> decimals = Property.select(0, "0", "1", "2");
|
||||
private static ModDimensions dimensions = new ModDimensions(40, 18);
|
||||
double speed = 0.;
|
||||
Vec3d velocity;
|
||||
double y = 0.;
|
||||
|
||||
public HealthDisplay() {
|
||||
super(new ModuleDetails("Health display", "health")
|
||||
.description("Displays your current health")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
displayMode.named("Display mode"),
|
||||
decimals.named("Decimals"),
|
||||
dimensions.prop()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
renderHealth(10, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
float health = SaturnClient.client.player.getHealth();
|
||||
switch (displayMode.value) {
|
||||
case 1:
|
||||
health = health / 2;
|
||||
}
|
||||
renderHealth(health, scope);
|
||||
}
|
||||
|
||||
public void renderHealth(float health, RenderScope scope) {
|
||||
String text = "";
|
||||
|
||||
switch (decimals.value) {
|
||||
case 0:
|
||||
text = String.format("%.0f ", health);
|
||||
break;
|
||||
case 1:
|
||||
text = String.format("%.1f ", health);
|
||||
break;
|
||||
case 2:
|
||||
text = String.format("%.2f ", health);
|
||||
break;
|
||||
}
|
||||
|
||||
scope.drawText(text,
|
||||
0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
dimensions.height = 18 * text.split("\n").length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
|
||||
public class Keystrokes extends Module implements HudMod {
|
||||
|
||||
private static final Property<Boolean> enabled = Property.bool(false);
|
||||
private static final Property<Boolean> showMouse = Property.bool(true);
|
||||
private static final Property<Boolean> showSpace = Property.bool(false);
|
||||
|
||||
private static final Property<Integer> clickBg = Property.color(0xFFCCCCCC);
|
||||
private static final Property<Integer> clickFg = Property.color(0xFFFFFFFF);
|
||||
|
||||
private static final ModDimensions dimensions = new ModDimensions(78, 54);
|
||||
|
||||
// Key states
|
||||
private boolean w, a, s, d, lmb, rmb, space;
|
||||
|
||||
// Layout constants
|
||||
private static final int KEY_SIZE = 24;
|
||||
private static final int KEY_SPACING = 3;
|
||||
private static final int MOUSE_WIDTH = 38;
|
||||
private static final int MOUSE_HEIGHT = 24;
|
||||
private static final int SPACE_HEIGHT = 19;
|
||||
|
||||
public Keystrokes() {
|
||||
super(new ModuleDetails("Keystrokes", "keystrokes")
|
||||
.description("Displays movement keystrokes")
|
||||
.version("v0.2.0")
|
||||
.tags("Utility"),
|
||||
|
||||
enabled.named("Enabled"),
|
||||
showMouse.named("Show mouse clicks"),
|
||||
showSpace.named("Show space"),
|
||||
dimensions.prop(),
|
||||
clickFg.named("Clicked fg"),
|
||||
clickBg.named("Clicked bg")
|
||||
);
|
||||
|
||||
dimensions.renderBackground = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
w = SaturnClient.client.options.forwardKey.isPressed();
|
||||
a = SaturnClient.client.options.leftKey.isPressed();
|
||||
s = SaturnClient.client.options.backKey.isPressed();
|
||||
d = SaturnClient.client.options.rightKey.isPressed();
|
||||
lmb = SaturnClient.client.options.attackKey.isPressed();
|
||||
rmb = SaturnClient.client.options.useKey.isPressed();
|
||||
space = SaturnClient.client.options.jumpKey.isPressed();
|
||||
|
||||
updateHeight();
|
||||
}
|
||||
|
||||
private void updateHeight() {
|
||||
int height = KEY_SIZE * 2 + KEY_SPACING;
|
||||
|
||||
if (showSpace.value)
|
||||
height += SPACE_HEIGHT + KEY_SPACING;
|
||||
|
||||
if (showMouse.value)
|
||||
height += MOUSE_HEIGHT + KEY_SPACING;
|
||||
|
||||
dimensions.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
render(scope, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
render(scope, true);
|
||||
}
|
||||
|
||||
private void render(RenderScope scope, boolean live) {
|
||||
|
||||
int yOffset = 0;
|
||||
|
||||
// --- W ---
|
||||
renderKey(scope, live && w, 'W', KEY_SIZE + KEY_SPACING, yOffset);
|
||||
|
||||
// --- A S D ---
|
||||
yOffset += KEY_SIZE + KEY_SPACING;
|
||||
|
||||
renderKey(scope, live && a, 'A', 0, yOffset);
|
||||
renderKey(scope, live && s, 'S', KEY_SIZE + KEY_SPACING, yOffset);
|
||||
renderKey(scope, live && d, 'D', (KEY_SIZE + KEY_SPACING) * 2, yOffset);
|
||||
|
||||
yOffset += KEY_SIZE + KEY_SPACING;
|
||||
|
||||
// --- SPACE ---
|
||||
if (showSpace.value) {
|
||||
renderKeySpace(scope, live && space, 0, yOffset);
|
||||
yOffset += SPACE_HEIGHT + KEY_SPACING;
|
||||
}
|
||||
|
||||
// --- MOUSE ---
|
||||
if (showMouse.value) {
|
||||
renderKeyMouse(scope, live && lmb, "LMB", 0, yOffset);
|
||||
renderKeyMouse(scope, live && rmb, "RMB", MOUSE_WIDTH + KEY_SPACING, yOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderKey(RenderScope scope, boolean pressed, char c, int x, int y) {
|
||||
int bg = pressed ? clickBg.value : dimensions.bgColor.value;
|
||||
int fg = pressed ? clickFg.value : dimensions.fgColor.value;
|
||||
|
||||
scope.drawRoundedRectangle(x, y, KEY_SIZE, KEY_SIZE, dimensions.radius.value, bg);
|
||||
scope.drawText(0.6f, String.valueOf(c), x + 9, y + 7, dimensions.font.value, fg);
|
||||
}
|
||||
|
||||
private void renderKeyMouse(RenderScope scope, boolean pressed, String text, int x, int y) {
|
||||
int bg = pressed ? clickBg.value : dimensions.bgColor.value;
|
||||
int fg = pressed ? clickFg.value : dimensions.fgColor.value;
|
||||
|
||||
scope.drawRoundedRectangle(x, y, MOUSE_WIDTH, MOUSE_HEIGHT, dimensions.radius.value, bg);
|
||||
scope.drawText(0.6f, text, x + 9, y + 7, dimensions.font.value, fg);
|
||||
}
|
||||
|
||||
private void renderKeySpace(RenderScope scope, boolean pressed, int x, int y) {
|
||||
int bg = pressed ? clickBg.value : dimensions.bgColor.value;
|
||||
int fg = pressed ? clickFg.value : dimensions.fgColor.value;
|
||||
|
||||
scope.drawRoundedRectangle(x, y, dimensions.width, SPACE_HEIGHT, dimensions.radius.value, bg);
|
||||
|
||||
int lineY = y + SPACE_HEIGHT / 2;
|
||||
scope.drawRect(x + (dimensions.width - 30) / 2, lineY, 30, 1, fg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.modules.mods.utils.HealthRenderState;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
|
||||
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
|
||||
|
||||
// todo: rendering modes, custom names
|
||||
|
||||
public class Nametags extends Module {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Boolean> healthDisplay = Property.bool(false);
|
||||
private static Property<Boolean> players = Property.bool(true);
|
||||
private static Property<Boolean> hostile = Property.bool(false);
|
||||
private static Property<Boolean> passive = Property.bool(false);
|
||||
private static Property<Boolean> heartEmoji = Property.bool(true);
|
||||
private static Property<Boolean> obfuscate = Property.bool(false);
|
||||
private static Property<Integer> unit = Property.select(0, "Health", "Hearts");
|
||||
private static Property<Integer> format = Property.select(0, "Value", "Value / Total", "%");
|
||||
private static Property<Integer> nameColor = Property.select(15,
|
||||
"Black",
|
||||
"Dark Blue",
|
||||
"Dark Green",
|
||||
"Dark Aqua",
|
||||
"Dark Red",
|
||||
"Dark Purple",
|
||||
"Gold",
|
||||
"Gray",
|
||||
"Dark Gray",
|
||||
"Blue",
|
||||
"Green",
|
||||
"Aqua",
|
||||
"Red",
|
||||
"Light Purple",
|
||||
"Yellow",
|
||||
"White"
|
||||
);
|
||||
private static Property<Integer> healthColor = Property.select(12,
|
||||
"Black",
|
||||
"Dark Blue",
|
||||
"Dark Green",
|
||||
"Dark Aqua",
|
||||
"Dark Red",
|
||||
"Dark Purple",
|
||||
"Gold",
|
||||
"Gray",
|
||||
"Dark Gray",
|
||||
"Blue",
|
||||
"Green",
|
||||
"Aqua",
|
||||
"Red",
|
||||
"Light Purple",
|
||||
"Yellow",
|
||||
"White"
|
||||
);
|
||||
|
||||
private static final String[] COLOR_CODES = {
|
||||
"§0", "§1", "§2", "§3", "§4", "§5", "§6", "§7",
|
||||
"§8", "§9", "§a", "§b", "§c", "§d", "§e", "§f"
|
||||
};
|
||||
|
||||
public Nametags() {
|
||||
super(
|
||||
new ModuleDetails("Nametags", "nametags")
|
||||
.description("Allows you to modify entity nametags")
|
||||
.tags("Camera", "Utility")
|
||||
.version("0.1.0"),
|
||||
enabled.named("Enabled"),
|
||||
healthDisplay.named("Display health"),
|
||||
players.named("Players"),
|
||||
hostile.named("Hostile"),
|
||||
passive.named("Passive"),
|
||||
heartEmoji.named("Heart emoji"),
|
||||
obfuscate.named("Obfuscate enemy names"),
|
||||
unit.named("Unit"),
|
||||
format.named("Format"),
|
||||
nameColor.named("Name color"),
|
||||
healthColor.named("Health color")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
}
|
||||
|
||||
public static String getHealthString(LivingEntityRenderState state, HealthRenderState hrs, float health, float maxHealth) {
|
||||
String ret = "";
|
||||
|
||||
switch (format.value){
|
||||
case 0: // value
|
||||
ret = String.format("%.1f", health / (unit.value + 1));
|
||||
break;
|
||||
|
||||
case 1: // value / total
|
||||
ret = String.format("%.1f", health / (unit.value + 1)) + " / " + String.format("%.1f", maxHealth / (unit.value + 1));
|
||||
break;
|
||||
|
||||
case 2: // %
|
||||
ret = String.format("%.0f%%", (health / maxHealth) * 100);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String getNametagString(LivingEntityRenderState state) {
|
||||
if (state.customName == null) return null;
|
||||
if (!healthDisplay.value) return state.customName.getString(); // name only
|
||||
if (!(state instanceof HealthRenderState hrs)) return null;
|
||||
|
||||
float health = hrs.saturn$getHealth();
|
||||
float maxHealth = hrs.saturn$getMaxHealth();
|
||||
|
||||
HealthRenderState.EntityType type = hrs.saturn$getEntityType();
|
||||
if (type == HealthRenderState.EntityType.PASSIVE && !passive.value) return null;
|
||||
if (type == HealthRenderState.EntityType.HOSTILE && !hostile.value) return null;
|
||||
if (type == HealthRenderState.EntityType.PLAYER && !players.value) return null;
|
||||
if (type == HealthRenderState.EntityType.OTHER) return null;
|
||||
|
||||
if (health < 0f || maxHealth < 0f || health > maxHealth) return null;
|
||||
|
||||
String hpColor = COLOR_CODES[healthColor.value];
|
||||
String color = COLOR_CODES[nameColor.value];
|
||||
String heart = heartEmoji.value ? " ❤" : "";
|
||||
String obf = obfuscate.value ? "§k" : "";
|
||||
String reset = "§r";
|
||||
|
||||
String ret = color + obf + state.customName.getString() + reset + " " + hpColor + getHealthString(state, hrs, health, maxHealth) + heart;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static boolean shouldReplaceName() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
|
||||
public class NoFog extends Module {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Boolean> liquids = Property.bool(false);
|
||||
|
||||
public NoFog() {
|
||||
super(
|
||||
new ModuleDetails("No Fog", "nofog")
|
||||
.description("Stops fog from rendering")
|
||||
.tags("Camera")
|
||||
.version("v0.1.0"),
|
||||
enabled.named("Enabled"),
|
||||
liquids.named("See through liquids"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
|
||||
// static for the mixin
|
||||
public static boolean isActive() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
public static boolean liquids() {
|
||||
return liquids.value;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
|
||||
public class Ping extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static ModDimensions dimensions = new ModDimensions(60, Fonts.getHeight());
|
||||
|
||||
public Ping() {
|
||||
super(new ModuleDetails("Ping Display", "ping")
|
||||
.description("Displays ping")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
dimensions.prop());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
ClientPlayNetworkHandler handler = client.getNetworkHandler();
|
||||
String text = "0 ms";
|
||||
if (handler != null) {
|
||||
text = String.valueOf(handler.getPlayerListEntry(client.player.getUuid()).getLatency()) + " ms";
|
||||
}
|
||||
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
String text = "10 ms";
|
||||
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class Speedometer extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Integer> axis = Property.select(1, "Absolute", "X axis", "Y axis");
|
||||
private static Property<Integer> unitText = Property.select(0, "None", "Blocks/s", "blocks/s", "b/s");
|
||||
private static Property<Boolean> speedText = Property.bool(true);
|
||||
private static ModDimensions dimensions = new ModDimensions(40, 18);
|
||||
double speed = 0.;
|
||||
Vec3d velocity;
|
||||
double y = 0.;
|
||||
|
||||
public Speedometer() {
|
||||
super(new ModuleDetails("Speedometer", "speed")
|
||||
.description("Displays your current speed")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
axis.named("Speed type"),
|
||||
unitText.named("Unit text"),
|
||||
speedText.named("Show speed text"),
|
||||
dimensions.prop()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
renderSpeed(2.71, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
Entity vehicle = SaturnClient.client.player.getVehicle();
|
||||
Entity player = SaturnClient.client.player;
|
||||
|
||||
if (vehicle == null) {
|
||||
velocity = player.getVelocity();
|
||||
y = player.isOnGround() ? 0. : velocity.y;
|
||||
} else {
|
||||
velocity = vehicle.getVelocity();
|
||||
y = vehicle.isOnGround() ? 0. : velocity.y;
|
||||
}
|
||||
|
||||
switch (axis.value) {
|
||||
case 0: // Absolute
|
||||
speed = (Math.sqrt(Math.pow(velocity.x, 2) + Math.pow(y, 2) + Math.pow(velocity.z, 2)));
|
||||
break;
|
||||
|
||||
case 1: // x axis
|
||||
speed = (Math.sqrt(Math.pow(velocity.x, 2) + Math.pow(velocity.z, 2)));
|
||||
break;
|
||||
|
||||
case 2: // y axis
|
||||
speed = (Math.abs(y));
|
||||
break;
|
||||
}
|
||||
renderSpeed(speed * 20, scope); // blocks/tick to blocks/s
|
||||
}
|
||||
|
||||
public void renderSpeed(double speed, RenderScope scope) {
|
||||
String f = String.format("%.2f ", speed);
|
||||
|
||||
switch (unitText.value) {
|
||||
case 1:
|
||||
f += "Blocks/s";
|
||||
break;
|
||||
|
||||
case 2:
|
||||
f += "blocks/s";
|
||||
break;
|
||||
case 3:
|
||||
f += "b/s";
|
||||
break;
|
||||
}
|
||||
|
||||
String text = f;
|
||||
|
||||
if (speedText.value) {
|
||||
text = "Speed: " + text;
|
||||
}
|
||||
|
||||
scope.drawText(text,
|
||||
0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
dimensions.height = 18 * text.split("\n").length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.texture.StatusEffectSpriteManager;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class StatusEffects extends Module implements HudMod {
|
||||
public static Property<Boolean> enabled = Property.bool(false);
|
||||
private static ModDimensions dimensions = new ModDimensions(60, 0);
|
||||
|
||||
private final StatusEffectInstance[] dummyEffects = {
|
||||
new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("speed")).get(), 12000, 2),
|
||||
new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("strength")).get(), 12000, 2),
|
||||
new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("fire_resistance")).get(), 12000, 2),
|
||||
};
|
||||
|
||||
public StatusEffects() {
|
||||
super(new ModuleDetails("Status effects", "effect")
|
||||
.description("Displays status effects")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
|
||||
enabled.named("Enabled"),
|
||||
dimensions.prop());
|
||||
}
|
||||
|
||||
private void renderEffects(RenderScope scope, Iterable<StatusEffectInstance> effects) {
|
||||
int row = 0;
|
||||
|
||||
StatusEffectSpriteManager statusEffectSpriteManager = SaturnClient.client.getStatusEffectSpriteManager();
|
||||
|
||||
for (StatusEffectInstance effect : effects) {
|
||||
if (effect.shouldShowIcon()) {
|
||||
RegistryEntry<StatusEffect> registryEntry = effect.getEffectType();
|
||||
Sprite sprite = statusEffectSpriteManager.getSprite(registryEntry);
|
||||
scope.drawSpriteStretched(sprite, 0, 18 * row, 16, 16);
|
||||
scope.drawText(0.5f, getDurationAsString(effect), 18, 18 * row + 3, dimensions.font.value, -1);
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
dimensions.height = 18 * row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
renderEffects(scope, SaturnClient.client.player.getStatusEffects());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
renderEffects(scope, Arrays.asList(dummyEffects));
|
||||
}
|
||||
|
||||
// This code was from: https://github.com/magicus/statuseffecttimer/blob/master/src/main/java/se/icus/mag/statuseffecttimer/mixin/StatusEffectTimerMixin.java
|
||||
private String getDurationAsString(StatusEffectInstance statusEffectInstance) {
|
||||
if (statusEffectInstance.isInfinite()) {
|
||||
return I18n.translate("effect.duration.infinite");
|
||||
}
|
||||
|
||||
int ticks = MathHelper.floor((float) statusEffectInstance.getDuration());
|
||||
int totalSeconds = ticks / 20;
|
||||
|
||||
if (totalSeconds >= 3600) {
|
||||
return totalSeconds / 3600 + "h";
|
||||
} else if (totalSeconds >= 60) {
|
||||
int minutes = totalSeconds / 60;
|
||||
int seconds = totalSeconds % 60;
|
||||
return String.format("%d:%02d", minutes, seconds);
|
||||
} else {
|
||||
return String.valueOf(totalSeconds) + "s";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.saturnclient.ui2.resources.Fonts;
|
||||
|
||||
public class Tps extends Module implements HudMod {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static ModDimensions dimensions = new ModDimensions(60, Fonts.getHeight());
|
||||
|
||||
private static long lastWorldAge = -1;
|
||||
private static long lastRealTime = -1;
|
||||
private static double currentTps = 20.0;
|
||||
|
||||
private static final int SAMPLE_COUNT = 2;
|
||||
private static final double[] samples = new double[SAMPLE_COUNT];
|
||||
static {
|
||||
java.util.Arrays.fill(samples, 20.0);
|
||||
}
|
||||
private static int sampleIndex = 0;
|
||||
private static int samplesFilled = 0;
|
||||
|
||||
public Tps() {
|
||||
super(new ModuleDetails("TPS Display", "tps")
|
||||
.description("Displays the TPS")
|
||||
.version("v0.1.0")
|
||||
.tags("Utility"),
|
||||
enabled.named("Enabled"),
|
||||
dimensions.prop()
|
||||
);
|
||||
}
|
||||
|
||||
public static void onTimePacket(long worldAge) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
if (lastWorldAge != -1 && lastRealTime != -1) {
|
||||
long tickDelta = worldAge - lastWorldAge;
|
||||
long timeDelta = now - lastRealTime;
|
||||
|
||||
if (timeDelta > 0 && tickDelta > 0) {
|
||||
double sample = (tickDelta / (double) timeDelta) * 1000.0;
|
||||
sample = Math.min(sample, 20.0);
|
||||
|
||||
samples[sampleIndex % SAMPLE_COUNT] = sample;
|
||||
sampleIndex++;
|
||||
samplesFilled = Math.min(samplesFilled + 1, SAMPLE_COUNT);
|
||||
|
||||
double sum = 0;
|
||||
for (int i = 0; i < samplesFilled; i++) sum += samples[i];
|
||||
currentTps = sum / samplesFilled;
|
||||
}
|
||||
}
|
||||
|
||||
lastWorldAge = worldAge;
|
||||
lastRealTime = now;
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
lastWorldAge = -1;
|
||||
lastRealTime = -1;
|
||||
currentTps = 20.0;
|
||||
sampleIndex = 0;
|
||||
samplesFilled = SAMPLE_COUNT;
|
||||
for (int i = 0; i < SAMPLE_COUNT; i++) samples[i] = 20.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(RenderScope scope) {
|
||||
String text = String.format("%.1f TPS", currentTps);
|
||||
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDummy(RenderScope scope) {
|
||||
String text = "20.0 TPS";
|
||||
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModDimensions getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.modules.ModuleDetails;
|
||||
import org.saturnclient.saturnclient.config.manager.Property;
|
||||
|
||||
public class Zoom extends Module {
|
||||
private static Property<Boolean> enabled = Property.bool(false);
|
||||
private static Property<Boolean> toggle = Property.bool(false);
|
||||
public static Property<Integer> zoomKey = Property.keybinding(GLFW.GLFW_KEY_C);
|
||||
public static Property<Float> zoomLevel = Property.floatProp(3.0f);
|
||||
|
||||
public static boolean isZooming = false;
|
||||
|
||||
public Zoom() {
|
||||
super(
|
||||
new ModuleDetails("Zoom", "zoom")
|
||||
.description("Allows you to zoom in for a closer view")
|
||||
.tags("Camera", "Utility")
|
||||
.version("0.1.0"),
|
||||
enabled.named("Enabled"),
|
||||
toggle.named("Toggle zoom"),
|
||||
zoomKey.named("Zoom Keybinding"),
|
||||
zoomLevel.named("Zoom Level")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (toggle.value) {
|
||||
if (zoomKey.wasKeyPressed()) {
|
||||
isZooming = !isZooming;
|
||||
}
|
||||
} else {
|
||||
isZooming = zoomKey.isKeyPressed();
|
||||
}
|
||||
}
|
||||
|
||||
public static float getZoomLevel() {
|
||||
return zoomLevel.value;
|
||||
}
|
||||
|
||||
public static boolean shouldZoom() {
|
||||
return enabled.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnabled(boolean e) {
|
||||
enabled.value = e;
|
||||
if (!e) {
|
||||
isZooming = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.value;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
import net.minecraft.client.render.BackgroundRenderer;
|
||||
|
||||
import org.saturnclient.modules.mods.NoFog;
|
||||
import net.minecraft.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(BackgroundRenderer.class)
|
||||
public class BackgroundRendererMixin {
|
||||
|
||||
@ModifyVariable(method = "applyFog", at = @At("HEAD"), ordinal = 0, argsOnly = true)
|
||||
private static float modifyFogStart(float viewDistance) {
|
||||
if (NoFog.isActive()) {
|
||||
return Float.MAX_VALUE; // this could be customised
|
||||
}
|
||||
return viewDistance;
|
||||
}
|
||||
// liquids
|
||||
@Redirect(
|
||||
method = "applyFog",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSpectator()Z")
|
||||
)
|
||||
private static boolean redirectIsSpectator(Entity entity) {
|
||||
if (NoFog.isActive() && NoFog.liquids()) {
|
||||
return true; // pretend to be spectator
|
||||
}
|
||||
return entity.isSpectator();
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.BlockView;
|
||||
|
||||
import org.saturnclient.modules.mods.Freelook;
|
||||
import org.saturnclient.modules.mods.utils.CameraOverriddenEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Camera.class)
|
||||
public abstract class CameraMixin {
|
||||
@Unique
|
||||
boolean firstTime = true;
|
||||
|
||||
@Shadow
|
||||
protected abstract void setRotation(float yaw, float pitch);
|
||||
|
||||
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V", ordinal = 1, shift = At.Shift.AFTER))
|
||||
public void lockRotation(BlockView focusedBlock, Entity cameraEntity, boolean isThirdPerson, boolean isFrontFacing, float tickDelta, CallbackInfo ci) {
|
||||
if (Freelook.isFreeLooking && cameraEntity instanceof ClientPlayerEntity) {
|
||||
CameraOverriddenEntity cameraOverriddenEntity = (CameraOverriddenEntity) cameraEntity;
|
||||
|
||||
if (firstTime && MinecraftClient.getInstance().player != null) {
|
||||
cameraOverriddenEntity.freelook$setCameraPitch(MinecraftClient.getInstance().player.getPitch());
|
||||
cameraOverriddenEntity.freelook$setCameraYaw(MinecraftClient.getInstance().player.getYaw());
|
||||
firstTime = false;
|
||||
}
|
||||
this.setRotation(cameraOverriddenEntity.freelook$getCameraYaw(), cameraOverriddenEntity.freelook$getCameraPitch());
|
||||
|
||||
}
|
||||
if (!Freelook.isFreeLooking && cameraEntity instanceof ClientPlayerEntity) {
|
||||
firstTime = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
import org.saturnclient.modules.mods.Freelook;
|
||||
import org.saturnclient.modules.mods.utils.CameraOverriddenEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public class EntityMixin implements CameraOverriddenEntity {
|
||||
@Unique
|
||||
private float cameraPitch;
|
||||
|
||||
@Unique
|
||||
private float cameraYaw;
|
||||
|
||||
@Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true)
|
||||
public void changeCameraLookDirection(double xDelta, double yDelta, CallbackInfo ci) {
|
||||
//noinspection ConstantValue// IntelliJ is incorrect here, this code block is reachable
|
||||
if (Freelook.isFreeLooking && (Object) this instanceof ClientPlayerEntity) {
|
||||
double pitchDelta = (yDelta * 0.15);
|
||||
double yawDelta = (xDelta * 0.15);
|
||||
|
||||
this.cameraPitch = MathHelper.clamp(this.cameraPitch + (float) pitchDelta, -90.0f, 90.0f);
|
||||
this.cameraYaw += (float) yawDelta;
|
||||
|
||||
ci.cancel();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unique
|
||||
public float freelook$getCameraPitch() {
|
||||
return this.cameraPitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unique
|
||||
public float freelook$getCameraYaw() {
|
||||
return this.cameraYaw;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unique
|
||||
public void freelook$setCameraPitch(float pitch) {
|
||||
this.cameraPitch = pitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Unique
|
||||
public void freelook$setCameraYaw(float yaw) {
|
||||
this.cameraYaw = yaw;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
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 org.saturnclient.modules.mods.Zoom;
|
||||
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public class GameRendererMixin {
|
||||
|
||||
@Inject(method = "getFov", at = @At("RETURN"), cancellable = true)
|
||||
private void onGetFov(CallbackInfoReturnable<Float> cir) {
|
||||
if (Zoom.isZooming && Zoom.shouldZoom()) {
|
||||
float originalFov = cir.getReturnValue();
|
||||
float zoomedFov = originalFov / Zoom.getZoomLevel();
|
||||
cir.setReturnValue(zoomedFov);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
// code modified from Gamma utils: https://github.com/Sjouwer/gamma-utils
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||
import net.minecraft.client.render.LightmapTextureManager;
|
||||
import org.saturnclient.modules.mods.Fullbright;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
@Mixin(LightmapTextureManager.class)
|
||||
public class LightmapTextureManagerMixin {
|
||||
|
||||
@ModifyExpressionValue(
|
||||
method = "update",
|
||||
at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(FF)F", ordinal = 0)
|
||||
)
|
||||
private float modifyGamma(float original) {
|
||||
if (Fullbright.shouldOverrideBrightness()) {
|
||||
return Fullbright.getBrightnessValue();
|
||||
}
|
||||
return original;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
|
||||
|
||||
import org.saturnclient.modules.mods.utils.HealthRenderState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
@Mixin(LivingEntityRenderState.class)
|
||||
public class LivingEntityRenderStateMixin implements org.saturnclient.modules.mods.utils.HealthRenderState {
|
||||
|
||||
@Unique private float saturn$health = 0f;
|
||||
@Unique private float saturn$maxHealth = 1f;
|
||||
@Unique private HealthRenderState.EntityType saturn$entityType = HealthRenderState.EntityType.OTHER;
|
||||
|
||||
public float saturn$getHealth() { return saturn$health; }
|
||||
public float saturn$getMaxHealth() { return saturn$maxHealth; }
|
||||
public void saturn$setHealth(float health, float maxHealth) {
|
||||
this.saturn$health = health;
|
||||
this.saturn$maxHealth = maxHealth;
|
||||
}
|
||||
|
||||
public HealthRenderState.EntityType saturn$getEntityType() { return saturn$entityType; }
|
||||
public void saturn$setEntityType(HealthRenderState.EntityType type) { this.saturn$entityType = type; }
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
import net.minecraft.client.render.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
|
||||
import org.saturnclient.modules.mods.utils.HealthRenderState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.mob.HostileEntity;
|
||||
import net.minecraft.entity.passive.PassiveEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LivingEntityRenderer.class)
|
||||
public abstract class LivingEntityRendererMixin<T extends LivingEntity, S extends LivingEntityRenderState> {
|
||||
|
||||
@Inject(method = "updateRenderState", at = @At("TAIL"))
|
||||
private void saturn$captureHealth(T entity, S state, float tickDelta, CallbackInfo ci) {
|
||||
if (!(state instanceof HealthRenderState hrs)) return;
|
||||
|
||||
hrs.saturn$setHealth(entity.getHealth(), entity.getMaxHealth());
|
||||
|
||||
if (entity instanceof PlayerEntity) {
|
||||
hrs.saturn$setEntityType(HealthRenderState.EntityType.PLAYER);
|
||||
} else if (entity instanceof HostileEntity) {
|
||||
hrs.saturn$setEntityType(HealthRenderState.EntityType.HOSTILE);
|
||||
} else if (entity instanceof PassiveEntity) {
|
||||
hrs.saturn$setEntityType(HealthRenderState.EntityType.PASSIVE);
|
||||
} else {
|
||||
hrs.saturn$setEntityType(HealthRenderState.EntityType.OTHER);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.EntityRenderer;
|
||||
import net.minecraft.client.render.entity.state.EntityRenderState;
|
||||
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import org.saturnclient.modules.mods.Nametags;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(EntityRenderer.class)
|
||||
public abstract class NametagsMixin {
|
||||
|
||||
@Unique
|
||||
private static final ThreadLocal<Boolean> saturn$rendering = ThreadLocal.withInitial(() -> false);
|
||||
|
||||
@Shadow
|
||||
protected abstract <S extends EntityRenderState> void renderLabelIfPresent(
|
||||
S state, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light
|
||||
);
|
||||
|
||||
@Inject(method = "renderLabelIfPresent", at = @At("HEAD"), cancellable = true)
|
||||
private <S extends EntityRenderState> void saturn$replaceNametag(S state, Text text,
|
||||
MatrixStack matrices, VertexConsumerProvider vertexConsumers,
|
||||
int light, CallbackInfo ci) {
|
||||
|
||||
if (saturn$rendering.get()) return;
|
||||
if (!Nametags.shouldReplaceName()) return;
|
||||
if (!(state instanceof LivingEntityRenderState living)) return;
|
||||
|
||||
String replacement = Nametags.getNametagString(living);
|
||||
if (replacement == null) return;
|
||||
|
||||
ci.cancel();
|
||||
saturn$rendering.set(true);
|
||||
try {
|
||||
renderLabelIfPresent(state, Text.literal(replacement), matrices, vertexConsumers, light);
|
||||
} finally {
|
||||
saturn$rendering.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
import org.saturnclient.modules.HudMod;
|
||||
import org.saturnclient.modules.ModDimensions;
|
||||
import org.saturnclient.modules.ModManager;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.menus.HudEditor;
|
||||
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderTickCounter;
|
||||
|
||||
@Mixin(InGameHud.class)
|
||||
public class RenderMixin {
|
||||
@Inject(method = "renderChat", at = @At("TAIL"))
|
||||
public void renderMods(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
|
||||
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
||||
|
||||
if (textRenderer != null &&
|
||||
!(SaturnClient.client.currentScreen instanceof HudEditor)) {
|
||||
RenderScope renderScope = new RenderScope(context.getMatrices(),
|
||||
((DrawContextAccessor) context).getVertexConsumers());
|
||||
|
||||
for (org.saturnclient.modules.Module m : ModManager.ENABLED_MODS) {
|
||||
if (m instanceof HudMod && m.isEnabled()) {
|
||||
ModDimensions dim = ((HudMod) m).getDimensions();
|
||||
|
||||
renderScope.matrices.push();
|
||||
|
||||
renderScope.matrices.translate(dim.x.value, (float) dim.y.value, 0);
|
||||
|
||||
renderScope.matrices.scale(dim.scale.value, dim.scale.value, 1.0f);
|
||||
|
||||
if (dim.renderBackground) {
|
||||
renderScope.drawRoundedRectangle(0, 0, dim.width, dim.height, dim.radius.value,
|
||||
dim.bgColor.value);
|
||||
}
|
||||
|
||||
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
||||
|
||||
((HudMod) m).renderHud(renderScope);
|
||||
|
||||
renderScope.matrices.pop();
|
||||
} else {
|
||||
m.render(renderScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.saturnclient.modules.mods.mixins;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.network.packet.s2c.play.WorldTimeUpdateS2CPacket;
|
||||
import org.saturnclient.modules.mods.Tps;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ClientPlayNetworkHandler.class)
|
||||
public class TpsMixin {
|
||||
|
||||
@Inject(method = "onWorldTimeUpdate", at = @At("HEAD"))
|
||||
private void onWorldTimeUpdate(WorldTimeUpdateS2CPacket packet, CallbackInfo ci) {
|
||||
Tps.onTimePacket(packet.time());
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package org.saturnclient.modules.mods.utils;
|
||||
|
||||
public interface CameraOverriddenEntity {
|
||||
float freelook$getCameraPitch();
|
||||
float freelook$getCameraYaw();
|
||||
|
||||
void freelook$setCameraPitch(float pitch);
|
||||
void freelook$setCameraYaw(float yaw);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user