mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2026-06-04 00:56:54 +00:00
fuck it we're rendering blocks using webgl
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
param(
|
||||
[string]$Version = ""
|
||||
)
|
||||
|
||||
# Downloads the vanilla Minecraft assets used by the HTTPD live inventory view
|
||||
# into src/main/resources/httpd/assets for local development.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/download-minecraft-assets.ps1 # latest release
|
||||
# ./scripts/download-minecraft-assets.ps1 1.21.10 # specific version
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$ProjectRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
|
||||
$AssetRoot = Join-Path $ProjectRoot "src/main/resources/httpd/assets"
|
||||
$ManifestUrl = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
|
||||
|
||||
$manifest = Invoke-RestMethod -Uri $ManifestUrl -TimeoutSec 30
|
||||
if ([string]::IsNullOrWhiteSpace($Version)) {
|
||||
$Version = $manifest.latest.release
|
||||
}
|
||||
|
||||
$versionEntry = $manifest.versions | Where-Object { $_.id -eq $Version } | Select-Object -First 1
|
||||
if ($null -eq $versionEntry) {
|
||||
throw "Minecraft version '$Version' was not found in Mojang's manifest"
|
||||
}
|
||||
|
||||
$versionJson = Invoke-RestMethod -Uri $versionEntry.url -TimeoutSec 30
|
||||
$clientUrl = $versionJson.downloads.client.url
|
||||
|
||||
Write-Host "Downloading Minecraft $Version client assets..."
|
||||
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ("plex-httpd-assets-" + [Guid]::NewGuid())
|
||||
New-Item -ItemType Directory -Path $tempDir | Out-Null
|
||||
$jarPath = Join-Path $tempDir "minecraft-$Version.jar"
|
||||
|
||||
try {
|
||||
Invoke-WebRequest -Uri $clientUrl -OutFile $jarPath -TimeoutSec 300
|
||||
|
||||
foreach ($directory in @("textures", "models", "items")) {
|
||||
$path = Join-Path $AssetRoot $directory
|
||||
if (Test-Path $path) {
|
||||
Remove-Item -Recurse -Force $path
|
||||
}
|
||||
New-Item -ItemType Directory -Path $path -Force | Out-Null
|
||||
}
|
||||
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$zip = [System.IO.Compression.ZipFile]::OpenRead($jarPath)
|
||||
$extracted = 0
|
||||
try {
|
||||
foreach ($entry in $zip.Entries) {
|
||||
if ([string]::IsNullOrEmpty($entry.Name)) {
|
||||
continue
|
||||
}
|
||||
|
||||
$name = $entry.FullName -replace '\\', '/'
|
||||
$wanted = $name.StartsWith("assets/minecraft/textures/item/") -or
|
||||
$name.StartsWith("assets/minecraft/textures/block/") -or
|
||||
($name -eq "assets/minecraft/textures/entity/shield/shield_base_nopattern.png") -or
|
||||
$name.StartsWith("assets/minecraft/models/item/") -or
|
||||
$name.StartsWith("assets/minecraft/models/block/") -or
|
||||
$name.StartsWith("assets/minecraft/items/")
|
||||
if (-not $wanted) {
|
||||
continue
|
||||
}
|
||||
|
||||
$relative = $name.Substring("assets/minecraft/".Length)
|
||||
$target = Join-Path $AssetRoot ($relative -replace '/', [System.IO.Path]::DirectorySeparatorChar)
|
||||
$targetParent = Split-Path -Parent $target
|
||||
New-Item -ItemType Directory -Path $targetParent -Force | Out-Null
|
||||
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target, $true)
|
||||
$extracted++
|
||||
}
|
||||
}
|
||||
finally {
|
||||
$zip.Dispose()
|
||||
}
|
||||
|
||||
Set-Content -Path (Join-Path $AssetRoot ".minecraft-version") -Value $Version -Encoding UTF8
|
||||
Write-Host "Extracted $extracted files to $AssetRoot"
|
||||
}
|
||||
finally {
|
||||
if (Test-Path $tempDir) {
|
||||
Remove-Item -Recurse -Force $tempDir
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
# Downloads the vanilla Minecraft assets used by the HTTPD live inventory view
|
||||
# into src/main/resources/httpd/assets for local development.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/download-minecraft-assets.sh # latest release
|
||||
# ./scripts/download-minecraft-assets.sh 1.21.10 # specific version
|
||||
|
||||
VERSION="${1:-}"
|
||||
PROJECT_ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
|
||||
ASSET_ROOT="$PROJECT_ROOT/src/main/resources/httpd/assets"
|
||||
|
||||
python3 - "$VERSION" "$ASSET_ROOT" <<'PY'
|
||||
import json
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import urllib.request
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
version_arg = sys.argv[1].strip()
|
||||
asset_root = Path(sys.argv[2])
|
||||
manifest_url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
|
||||
|
||||
|
||||
def get_json(url):
|
||||
with urllib.request.urlopen(url, timeout=30) as response:
|
||||
return json.loads(response.read().decode("utf-8"))
|
||||
|
||||
|
||||
manifest = get_json(manifest_url)
|
||||
version = version_arg or manifest["latest"]["release"]
|
||||
version_entry = next((v for v in manifest["versions"] if v["id"] == version), None)
|
||||
if version_entry is None:
|
||||
raise SystemExit(f"Minecraft version {version!r} was not found in Mojang's manifest")
|
||||
|
||||
version_json = get_json(version_entry["url"])
|
||||
client_url = version_json["downloads"]["client"]["url"]
|
||||
|
||||
print(f"Downloading Minecraft {version} client assets...")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
jar_path = Path(tmp) / f"minecraft-{version}.jar"
|
||||
with urllib.request.urlopen(client_url, timeout=300) as response, jar_path.open("wb") as out:
|
||||
shutil.copyfileobj(response, out)
|
||||
|
||||
for directory in ("textures", "models", "items"):
|
||||
shutil.rmtree(asset_root / directory, ignore_errors=True)
|
||||
(asset_root / directory).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
prefixes = (
|
||||
"assets/minecraft/textures/item/",
|
||||
"assets/minecraft/textures/block/",
|
||||
"assets/minecraft/textures/entity/shield/shield_base_nopattern.png",
|
||||
"assets/minecraft/models/item/",
|
||||
"assets/minecraft/models/block/",
|
||||
"assets/minecraft/items/",
|
||||
)
|
||||
|
||||
extracted = 0
|
||||
with zipfile.ZipFile(jar_path) as jar:
|
||||
for info in jar.infolist():
|
||||
if info.is_dir() or not info.filename.startswith(prefixes):
|
||||
continue
|
||||
relative = info.filename[len("assets/minecraft/"):]
|
||||
target = asset_root / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
with jar.open(info) as source, target.open("wb") as out:
|
||||
shutil.copyfileobj(source, out)
|
||||
extracted += 1
|
||||
|
||||
(asset_root / ".minecraft-version").write_text(version + "\n", encoding="utf-8")
|
||||
print(f"Extracted {extracted} files to {asset_root}")
|
||||
PY
|
||||
Reference in New Issue
Block a user