A player asked to build below vanilla size for small details. The new Shrink Hammer, craftable by any race, builds from 0.25 to 1; Trol's Hammer keeps 1 to 3. With either hammer, Alt + scroll in build mode changes the size in steps of 0.05, an Alt: Size row joins the build hints, and the size floats over the ghost when it is not the default. With the repair tool, the aimed piece shows the size it was built at. Both hammers get icons of their own.
77 lines
3.3 KiB
C#
77 lines
3.3 KiB
C#
using Jotunn.Configs;
|
|
using Jotunn.Entities;
|
|
using Jotunn.Managers;
|
|
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// The Shrink Hammer: the builder's hammer for small work, down to a quarter of the vanilla size.
|
|
/// Any race can craft it. Built the same way as <see cref="TrolsHammerItem"/>: a clone of the
|
|
/// vanilla Hammer that keeps the vanilla piece table, so every piece, including those other mods
|
|
/// add, is in its menu at the same cost. The size lives on the placement (TrolsHammerPatches,
|
|
/// BuildScale), never on the piece prefabs.
|
|
/// </summary>
|
|
public static class ShrinkHammerItem
|
|
{
|
|
public const string PrefabName = "ShrinkHammer";
|
|
public const string DisplayName = "$rov_item_shrinkhammer_name";
|
|
|
|
private const string SourcePrefab = "Hammer";
|
|
private const string Label = "ShrinkHammer";
|
|
|
|
public static void Register()
|
|
{
|
|
GameObject prefab = PrefabManager.Instance.CreateClonedPrefab(PrefabName, SourcePrefab);
|
|
ItemDrop drop = prefab != null ? prefab.GetComponent<ItemDrop>() : null;
|
|
if (drop == null || drop.m_itemData == null || drop.m_itemData.m_shared == null)
|
|
{
|
|
Jotunn.Logger.LogWarning($"[{Label}] Could not clone {SourcePrefab}; {DisplayName} not registered.");
|
|
return;
|
|
}
|
|
|
|
ItemDrop.ItemData.SharedData shared = drop.m_itemData.m_shared;
|
|
shared.m_name = DisplayName;
|
|
shared.m_description = "$rov_item_shrinkhammer_desc";
|
|
Sprite icon = HammerIcon.Load("ShrinkHammer_icon.png");
|
|
if (icon != null) shared.m_icons = new[] { icon };
|
|
|
|
ItemManager.Instance.AddItem(new CustomItem(prefab, fixReference: false));
|
|
ItemManager.Instance.AddRecipe(new CustomRecipe(new RecipeConfig
|
|
{
|
|
Item = PrefabName,
|
|
Amount = 1,
|
|
CraftingStation = CraftingStations.Workbench,
|
|
MinStationLevel = 1,
|
|
Requirements = new[]
|
|
{
|
|
new RequirementConfig("FineWood", 2, 0, true),
|
|
new RequirementConfig("Resin", 2, 0, true),
|
|
},
|
|
}));
|
|
|
|
Jotunn.Logger.LogInfo($"[{Label}] {DisplayName} registered on the vanilla hammer's piece table.");
|
|
}
|
|
|
|
/// <summary>Whether an item in hand is this hammer; the display name is the fallback for an
|
|
/// ItemData built before ObjectDB finished, as in TrolsHammerItem.</summary>
|
|
public static bool IsShrinkHammer(ItemDrop.ItemData item)
|
|
{
|
|
if (item == null) return false;
|
|
if (item.m_dropPrefab != null) return item.m_dropPrefab.name == PrefabName;
|
|
return item.m_shared != null && item.m_shared.m_name == DisplayName;
|
|
}
|
|
}
|
|
|
|
/// <summary>The two hammers' own icons, painted offline (scripts/paint_hammer_icons.py) and
|
|
/// embedded in the DLL.</summary>
|
|
internal static class HammerIcon
|
|
{
|
|
public static Sprite Load(string resource)
|
|
{
|
|
Texture2D texture = PieceLook.LoadTexture(resource);
|
|
if (texture == null) return null;
|
|
return Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
|
}
|
|
}
|
|
}
|