Mod textures, display names, and atlas injection

Mod Atlas (ModAtlas.cpp/h):
- Build merged terrain.png and items.png from mod assets (blocks/*.png, items/*.png)
- Scan vanilla atlas for empty (fully transparent) cells; place mod textures only there
- Install merged atlases over game files before Minecraft::init; restore originals after
- Hook loadUVs to create SimpleIcon objects for mod textures
- Hook registerIcon to return mod icons when requested by name
- FixupModIcons: copy field_0x48 (source-image ptr) from vanilla icons after init

Mod Strings (ModStrings.cpp/h):
- Store mod display names by description ID
- Hook GetString to serve mod names for blocks/items

API changes:
- BlockProperties/ItemProperties: .Name(displayName), namespaced .Icon()
- NativeInterop: displayName params, native_allocate_description_id, native_register_string
- Registry.Assets for string registration
- Output: mods/LegacyForge.API/, mods/ExampleMod/ (per-mod folders)

Mod discovery:
- Scan mods/*/ for mod folders; load DLLs from each
- LegacyForge.API as mod in mods/LegacyForge.API/

ExampleMod:
- Ruby ore block and ruby item with custom textures and names
- Assets: blocks/ruby_ore.png, items/ruby.png, lang files
- Furnace recipe: ruby_ore -> ruby

Runtime: loadUVs, registerIcon, getResourceAsStream, GetString hooks; stb_image for PNG
This commit is contained in:
Jacobwasbeast
2026-03-06 22:04:15 -06:00
parent 336e037730
commit 2280cb1192
34 changed files with 10770 additions and 50 deletions

View File

@@ -0,0 +1,39 @@
#include "ModStrings.h"
#include "LogUtil.h"
#include <vector>
#include <cstring>
namespace ModStrings
{
static std::mutex s_mutex;
static std::unordered_map<int, std::wstring> s_strings;
static int s_nextId = MOD_DESC_ID_BASE;
void Register(int descriptionId, const wchar_t* value)
{
if (!value) return;
std::lock_guard<std::mutex> lock(s_mutex);
s_strings[descriptionId] = value;
LogUtil::Log("[LegacyForge] ModStrings: registered id=%d -> %ls", descriptionId, value);
}
const wchar_t* Get(int descriptionId)
{
std::lock_guard<std::mutex> lock(s_mutex);
auto it = s_strings.find(descriptionId);
if (it != s_strings.end())
return it->second.c_str();
return nullptr;
}
int AllocateId()
{
std::lock_guard<std::mutex> lock(s_mutex);
return s_nextId++;
}
bool IsModId(int id)
{
return id >= MOD_DESC_ID_BASE;
}
}