From 0a1e5428e849ed94c29ca3ba2552e4c319694d4c Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Thu, 11 Apr 2024 10:34:58 -0500 Subject: [PATCH] Position and rotation offsets for custom item holding and socketing --- NewHorizons/Builder/Props/ItemBuilder.cs | 4 ++++ NewHorizons/Components/Props/NHItem.cs | 8 ++++++++ .../External/Modules/Props/Item/ItemInfo.cs | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/NewHorizons/Builder/Props/ItemBuilder.cs b/NewHorizons/Builder/Props/ItemBuilder.cs index 78a866be..2a678d58 100644 --- a/NewHorizons/Builder/Props/ItemBuilder.cs +++ b/NewHorizons/Builder/Props/ItemBuilder.cs @@ -51,6 +51,10 @@ namespace NewHorizons.Builder.Props item.DisplayName = itemName; item.ItemType = itemType; item.Droppable = info.droppable; + item.HoldOffset = info.holdOffset ?? Vector3.zero; + item.HoldRotation = info.holdRotation ?? Vector3.zero; + item.SocketOffset = info.socketOffset ?? Vector3.zero; + item.SocketRotation = info.socketRotation ?? Vector3.zero; if (!string.IsNullOrEmpty(info.pickupAudio)) { item.PickupAudio = AudioTypeHandler.GetAudioType(info.pickupAudio, mod); diff --git a/NewHorizons/Components/Props/NHItem.cs b/NewHorizons/Components/Props/NHItem.cs index b21db7ea..bdf3e388 100644 --- a/NewHorizons/Components/Props/NHItem.cs +++ b/NewHorizons/Components/Props/NHItem.cs @@ -19,6 +19,10 @@ namespace NewHorizons.Components.Props public AudioType DropAudio; public AudioType SocketAudio; public AudioType UnsocketAudio; + public Vector3 HoldOffset; + public Vector3 HoldRotation; + public Vector3 SocketOffset; + public Vector3 SocketRotation; public string PickupCondition; public bool ClearPickupConditionOnDrop; public string PickupFact; @@ -42,6 +46,8 @@ namespace NewHorizons.Components.Props public override void PickUpItem(Transform holdTranform) { base.PickUpItem(holdTranform); + transform.localPosition = HoldOffset; + transform.localEulerAngles = HoldRotation; TriggerPickupConditions(); PlayCustomSound(PickupAudio); } @@ -56,6 +62,8 @@ namespace NewHorizons.Components.Props public override void SocketItem(Transform socketTransform, Sector sector) { base.SocketItem(socketTransform, sector); + transform.localPosition = SocketOffset; + transform.localEulerAngles = SocketRotation; TriggerDropConditions(); PlayCustomSound(SocketAudio); } diff --git a/NewHorizons/External/Modules/Props/Item/ItemInfo.cs b/NewHorizons/External/Modules/Props/Item/ItemInfo.cs index 6307db11..23253119 100644 --- a/NewHorizons/External/Modules/Props/Item/ItemInfo.cs +++ b/NewHorizons/External/Modules/Props/Item/ItemInfo.cs @@ -44,6 +44,22 @@ namespace NewHorizons.External.Modules.Props.Item /// public MVector3 dropNormal; /// + /// A relative offset to apply to the item's position when holding it. The initial position varies for vanilla item types. + /// + public MVector3 holdOffset; + /// + /// A relative offset to apply to the item's rotation when holding it. + /// + public MVector3 holdRotation; + /// + /// A relative offset to apply to the item's position when placing it into a socket. + /// + public MVector3 socketOffset; + /// + /// A relative offset to apply to the item's rotation when placing it into a socket. + /// + public MVector3 socketRotation; + /// /// The audio to play when this item is picked up. Only applies to custom/non-vanilla item types. /// Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list. ///