Skip to content

Commit b802c39

Browse files
committed
fuck it we're rendering blocks using webgl
1 parent d440199 commit b802c39

15 files changed

Lines changed: 80457 additions & 173 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
*.iml
44
/target/
55
/src/main/resources/build.properties
6+
/src/main/resources/httpd/assets/textures/
7+
/src/main/resources/httpd/assets/models/
8+
/src/main/resources/httpd/assets/items/
9+
/src/main/resources/httpd/assets/.minecraft-version
610

711
# OS
812
.DS_Store

build.gradle.kts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
plexLibrary("org.eclipse.jetty:jetty-server:12.1.9")
3636
plexLibrary("org.eclipse.jetty.ee10:jetty-ee10-servlet:12.1.9")
3737
plexLibrary("org.eclipse.jetty:jetty-proxy:12.1.9")
38-
plexLibrary("de.tr7zw:item-nbt-api:2.15.7")
38+
implementation("de.tr7zw:item-nbt-api:2.15.7")
3939
implementation(platform("com.intellectualsites.bom:bom-newest:1.56")) // Ref: https://github.com/IntellectualSites/bom
4040
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")
4141
implementation("commons-io:commons-io:2.22.0")
@@ -47,6 +47,10 @@ tasks.getByName<Jar>("jar") {
4747
archiveVersion.set("")
4848
from("src/main/resources") {
4949
exclude("dev/**")
50+
exclude("httpd/assets/textures/**")
51+
exclude("httpd/assets/models/**")
52+
exclude("httpd/assets/items/**")
53+
exclude("httpd/assets/.minecraft-version")
5054
}
5155
}
5256

@@ -63,6 +67,10 @@ tasks {
6367
}
6468
processResources {
6569
filteringCharset = Charsets.UTF_8.name()
70+
exclude("httpd/assets/textures/**")
71+
exclude("httpd/assets/models/**")
72+
exclude("httpd/assets/items/**")
73+
exclude("httpd/assets/.minecraft-version")
6674
}
6775
}
6876

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
param(
2+
[string]$Version = ""
3+
)
4+
5+
# Downloads the vanilla Minecraft assets used by the HTTPD live inventory view
6+
# into src/main/resources/httpd/assets for local development.
7+
#
8+
# Usage:
9+
# ./scripts/download-minecraft-assets.ps1 # latest release
10+
# ./scripts/download-minecraft-assets.ps1 1.21.10 # specific version
11+
12+
$ErrorActionPreference = "Stop"
13+
14+
$ProjectRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
15+
$AssetRoot = Join-Path $ProjectRoot "src/main/resources/httpd/assets"
16+
$ManifestUrl = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
17+
18+
$manifest = Invoke-RestMethod -Uri $ManifestUrl -TimeoutSec 30
19+
if ([string]::IsNullOrWhiteSpace($Version)) {
20+
$Version = $manifest.latest.release
21+
}
22+
23+
$versionEntry = $manifest.versions | Where-Object { $_.id -eq $Version } | Select-Object -First 1
24+
if ($null -eq $versionEntry) {
25+
throw "Minecraft version '$Version' was not found in Mojang's manifest"
26+
}
27+
28+
$versionJson = Invoke-RestMethod -Uri $versionEntry.url -TimeoutSec 30
29+
$clientUrl = $versionJson.downloads.client.url
30+
31+
Write-Host "Downloading Minecraft $Version client assets..."
32+
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ("plex-httpd-assets-" + [Guid]::NewGuid())
33+
New-Item -ItemType Directory -Path $tempDir | Out-Null
34+
$jarPath = Join-Path $tempDir "minecraft-$Version.jar"
35+
36+
try {
37+
Invoke-WebRequest -Uri $clientUrl -OutFile $jarPath -TimeoutSec 300
38+
39+
foreach ($directory in @("textures", "models", "items")) {
40+
$path = Join-Path $AssetRoot $directory
41+
if (Test-Path $path) {
42+
Remove-Item -Recurse -Force $path
43+
}
44+
New-Item -ItemType Directory -Path $path -Force | Out-Null
45+
}
46+
47+
Add-Type -AssemblyName System.IO.Compression.FileSystem
48+
$zip = [System.IO.Compression.ZipFile]::OpenRead($jarPath)
49+
$extracted = 0
50+
try {
51+
foreach ($entry in $zip.Entries) {
52+
if ([string]::IsNullOrEmpty($entry.Name)) {
53+
continue
54+
}
55+
56+
$name = $entry.FullName -replace '\\', '/'
57+
$wanted = $name.StartsWith("assets/minecraft/textures/item/") -or
58+
$name.StartsWith("assets/minecraft/textures/block/") -or
59+
($name -eq "assets/minecraft/textures/entity/shield/shield_base_nopattern.png") -or
60+
$name.StartsWith("assets/minecraft/models/item/") -or
61+
$name.StartsWith("assets/minecraft/models/block/") -or
62+
$name.StartsWith("assets/minecraft/items/")
63+
if (-not $wanted) {
64+
continue
65+
}
66+
67+
$relative = $name.Substring("assets/minecraft/".Length)
68+
$target = Join-Path $AssetRoot ($relative -replace '/', [System.IO.Path]::DirectorySeparatorChar)
69+
$targetParent = Split-Path -Parent $target
70+
New-Item -ItemType Directory -Path $targetParent -Force | Out-Null
71+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target, $true)
72+
$extracted++
73+
}
74+
}
75+
finally {
76+
$zip.Dispose()
77+
}
78+
79+
Set-Content -Path (Join-Path $AssetRoot ".minecraft-version") -Value $Version -Encoding UTF8
80+
Write-Host "Extracted $extracted files to $AssetRoot"
81+
}
82+
finally {
83+
if (Test-Path $tempDir) {
84+
Remove-Item -Recurse -Force $tempDir
85+
}
86+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
# Downloads the vanilla Minecraft assets used by the HTTPD live inventory view
5+
# into src/main/resources/httpd/assets for local development.
6+
#
7+
# Usage:
8+
# ./scripts/download-minecraft-assets.sh # latest release
9+
# ./scripts/download-minecraft-assets.sh 1.21.10 # specific version
10+
11+
VERSION="${1:-}"
12+
PROJECT_ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
13+
ASSET_ROOT="$PROJECT_ROOT/src/main/resources/httpd/assets"
14+
15+
python3 - "$VERSION" "$ASSET_ROOT" <<'PY'
16+
import json
17+
import shutil
18+
import sys
19+
import tempfile
20+
import urllib.request
21+
import zipfile
22+
from pathlib import Path
23+
24+
version_arg = sys.argv[1].strip()
25+
asset_root = Path(sys.argv[2])
26+
manifest_url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
27+
28+
29+
def get_json(url):
30+
with urllib.request.urlopen(url, timeout=30) as response:
31+
return json.loads(response.read().decode("utf-8"))
32+
33+
34+
manifest = get_json(manifest_url)
35+
version = version_arg or manifest["latest"]["release"]
36+
version_entry = next((v for v in manifest["versions"] if v["id"] == version), None)
37+
if version_entry is None:
38+
raise SystemExit(f"Minecraft version {version!r} was not found in Mojang's manifest")
39+
40+
version_json = get_json(version_entry["url"])
41+
client_url = version_json["downloads"]["client"]["url"]
42+
43+
print(f"Downloading Minecraft {version} client assets...")
44+
with tempfile.TemporaryDirectory() as tmp:
45+
jar_path = Path(tmp) / f"minecraft-{version}.jar"
46+
with urllib.request.urlopen(client_url, timeout=300) as response, jar_path.open("wb") as out:
47+
shutil.copyfileobj(response, out)
48+
49+
for directory in ("textures", "models", "items"):
50+
shutil.rmtree(asset_root / directory, ignore_errors=True)
51+
(asset_root / directory).mkdir(parents=True, exist_ok=True)
52+
53+
prefixes = (
54+
"assets/minecraft/textures/item/",
55+
"assets/minecraft/textures/block/",
56+
"assets/minecraft/textures/entity/shield/shield_base_nopattern.png",
57+
"assets/minecraft/models/item/",
58+
"assets/minecraft/models/block/",
59+
"assets/minecraft/items/",
60+
)
61+
62+
extracted = 0
63+
with zipfile.ZipFile(jar_path) as jar:
64+
for info in jar.infolist():
65+
if info.is_dir() or not info.filename.startswith(prefixes):
66+
continue
67+
relative = info.filename[len("assets/minecraft/"):]
68+
target = asset_root / relative
69+
target.parent.mkdir(parents=True, exist_ok=True)
70+
with jar.open(info) as source, target.open("wb") as out:
71+
shutil.copyfileobj(source, out)
72+
extracted += 1
73+
74+
(asset_root / ".minecraft-version").write_text(version + "\n", encoding="utf-8")
75+
print(f"Extracted {extracted} files to {asset_root}")
76+
PY

src/main/java/dev/plex/HTTPDModule.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.plex;
22

3+
import dev.plex.assets.MinecraftAssetsManager;
34
import dev.plex.authentication.AuthenticationManager;
45
import dev.plex.cache.FileCache;
56
import dev.plex.config.ModuleConfig;
@@ -48,6 +49,9 @@ public class HTTPDModule extends PlexModule
4849
@Getter
4950
private static File accessLogFile;
5051

52+
@Getter
53+
private static MinecraftAssetsManager minecraftAssetsManager;
54+
5155
@Override
5256
public void load()
5357
{
@@ -63,6 +67,9 @@ public void enable()
6367

6468
accessLogFile = new File(getDataFolder(), moduleConfig.getString("server.logging.file-path", "httpd.log"));
6569

70+
minecraftAssetsManager = new MinecraftAssetsManager(getDataFolder().toPath());
71+
minecraftAssetsManager.refreshAsync();
72+
6673
authenticationManager = new AuthenticationManager();
6774
if (authenticationManager.provider() == null)
6875
{

0 commit comments

Comments
 (0)