Files
LegacyWeaveLoader/ExampleMod/ExampleMod.cs
Jacobwasbeast 2280cb1192 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
2026-03-06 22:04:15 -06:00

59 lines
1.7 KiB
C#

using LegacyForge.API;
using LegacyForge.API.Block;
using LegacyForge.API.Item;
using LegacyForge.API.Events;
namespace ExampleMod;
[Mod("examplemod", Name = "Example Mod", Version = "1.0.0", Author = "LegacyForge",
Description = "A sample mod demonstrating the LegacyForge API")]
public class ExampleMod : IMod
{
public static RegisteredBlock? RubyOre;
public static RegisteredItem? Ruby;
public void OnInitialize()
{
RubyOre = Registry.Block.Register("examplemod:ruby_ore",
new BlockProperties()
.Material(MaterialType.Stone)
.Hardness(3.0f)
.Resistance(15f)
.Sound(SoundType.Stone)
.Icon("examplemod:ruby_ore") // From assets/blocks/ruby_ore.png
.Name("Ruby Ore")
.InCreativeTab(CreativeTab.BuildingBlocks));
Ruby = Registry.Item.Register("examplemod:ruby",
new ItemProperties()
.MaxStackSize(64)
.Icon("examplemod:ruby") // From assets/items/ruby.png
.Name("Ruby")
.InCreativeTab(CreativeTab.Materials));
Registry.Recipe.AddFurnace("examplemod:ruby_ore", "examplemod:ruby", 1.0f);
GameEvents.OnBlockBreak += OnBlockBroken;
Logger.Info("Example Mod initialized! Ruby ore and ruby registered.");
}
private void OnBlockBroken(object? sender, BlockBreakEventArgs e)
{
if (RubyOre != null && e.BlockId == RubyOre.StringId.ToString())
{
Logger.Info($"Ruby ore broken at ({e.X}, {e.Y}, {e.Z})!");
}
}
public void OnTick()
{
// Per-tick logic goes here
}
public void OnShutdown()
{
Logger.Info("Example Mod shutting down.");
}
}