mirror of
https://github.com/Jacobwasbeast/LegacyWeaveLoader.git
synced 2026-07-04 10:04:26 +00:00
refactor(creative): prepend support and logging
This commit is contained in:
@@ -12,6 +12,7 @@ public class ItemProperties
|
||||
internal float AttackDamageValue = 0.0f;
|
||||
internal string IconValue = "";
|
||||
internal CreativeTab CreativeTabValue = CreativeTab.None;
|
||||
internal CreativePlacement? CreativePlacementValue;
|
||||
internal Text? NameValue;
|
||||
|
||||
public ItemProperties MaxStackSize(int size) { MaxStackSizeValue = size; return this; }
|
||||
@@ -29,6 +30,8 @@ public class ItemProperties
|
||||
/// <summary>Override the native attack damage value for tool items.</summary>
|
||||
public ItemProperties AttackDamage(float damage) { AttackDamageValue = damage; return this; }
|
||||
public ItemProperties InCreativeTab(CreativeTab tab) { CreativeTabValue = tab; return this; }
|
||||
public ItemProperties CreativePlacement(CreativePlacement placement) { CreativePlacementValue = placement; return this; }
|
||||
public ItemProperties Prepend() { CreativePlacementValue = global::WeaveLoader.API.CreativePlacement.Prepend(); return this; }
|
||||
/// <summary>Display name shown in-game (e.g. "Ruby"). Used for localization.</summary>
|
||||
public ItemProperties Name(string displayName) { NameValue = Text.Literal(displayName); return this; }
|
||||
/// <summary>Localized display name using a language key (e.g. "item.examplemod.ruby").</summary>
|
||||
|
||||
@@ -184,13 +184,63 @@ public static class ItemRegistry
|
||||
}
|
||||
|
||||
if (numericId < 0)
|
||||
{
|
||||
Logger.Error($"Failed to register item '{id}'. No free IDs or invalid parameters.");
|
||||
throw new InvalidOperationException($"Failed to register item '{id}'. No free IDs or invalid parameters.");
|
||||
}
|
||||
|
||||
if (properties.CreativeTabValue != CreativeTab.None)
|
||||
{
|
||||
NativeInterop.native_add_to_creative(numericId, 1, 0, (int)properties.CreativeTabValue);
|
||||
bool added = false;
|
||||
if (properties.CreativePlacementValue.HasValue)
|
||||
{
|
||||
CreativePlacement placement = properties.CreativePlacementValue.Value;
|
||||
if (placement.Insert == CreativeInsert.Prepend)
|
||||
{
|
||||
try
|
||||
{
|
||||
NativeInterop.native_add_to_creative_ex(
|
||||
numericId, 1, 0, (int)properties.CreativeTabValue,
|
||||
(int)placement.Insert, -1, -1);
|
||||
}
|
||||
catch (DllNotFoundException e)
|
||||
{
|
||||
Logger.Error($"Creative add failed for item '{id}': {e.Message}. Check that WeaveLoaderRuntime is present.");
|
||||
throw;
|
||||
}
|
||||
catch (EntryPointNotFoundException e)
|
||||
{
|
||||
Logger.Error($"Creative add failed for item '{id}': {e.Message}. API/runtime mismatch.");
|
||||
throw;
|
||||
}
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added)
|
||||
{
|
||||
try
|
||||
{
|
||||
NativeInterop.native_add_to_creative(numericId, 1, 0, (int)properties.CreativeTabValue);
|
||||
}
|
||||
catch (DllNotFoundException e)
|
||||
{
|
||||
Logger.Error($"Creative add failed for item '{id}': {e.Message}. Check that WeaveLoaderRuntime is present.");
|
||||
throw;
|
||||
}
|
||||
catch (EntryPointNotFoundException e)
|
||||
{
|
||||
Logger.Error($"Creative add failed for item '{id}': {e.Message}. API/runtime mismatch.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Debug($"Item '{id}' added to creative tab {properties.CreativeTabValue}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Debug($"Item '{id}' not added to creative (CreativeTab.None)");
|
||||
}
|
||||
|
||||
if (managedItem != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user