From 95e26155d707d9e09b936e2298100e6e094dc6b6 Mon Sep 17 00:00:00 2001 From: morgana-x <89588301+morgana-x@users.noreply.github.com> Date: Wed, 4 Feb 2026 13:37:18 +1100 Subject: [PATCH] Add ComputeModelAndParts event, add RedefineModel method --- CustomModels/BlockBench.cs | 1 + CustomModels/CustomModels.cs | 5 +++++ CustomModels/Events.cs | 17 +++++++++++++++++ CustomModels/StoredCustomModel.cs | 13 +++++++++---- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CustomModels/BlockBench.cs b/CustomModels/BlockBench.cs index 2da27b2..a328b85 100644 --- a/CustomModels/BlockBench.cs +++ b/CustomModels/BlockBench.cs @@ -390,6 +390,7 @@ private Part ToPart(Element e) { }; var part = new Part { + name = e.name, min = min, max = max, u1 = u2, diff --git a/CustomModels/CustomModels.cs b/CustomModels/CustomModels.cs index 9956606..f446516 100644 --- a/CustomModels/CustomModels.cs +++ b/CustomModels/CustomModels.cs @@ -168,6 +168,11 @@ public override void Unload(bool shutdown) { foreach (Command cmd in commands) { Command.Unregister(cmd); } } + public static void RedefineModel(StoredCustomModel model) + { + CheckUpdateAll(model); + } + } // class CustomModelsPlugin } // namespace MCGalaxy diff --git a/CustomModels/Events.cs b/CustomModels/Events.cs index c14c97c..ec3c96a 100644 --- a/CustomModels/Events.cs +++ b/CustomModels/Events.cs @@ -1,13 +1,30 @@ +using MCGalaxy.Events; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; namespace MCGalaxy { public sealed partial class CustomModelsPlugin { + public delegate void ComputeModelAndPartsEvent(Player target, CustomModel model, List parts); + + public sealed class ComputeModelAndParts : IEvent + { + internal static void Call(Player target, CustomModel model, List parts) + { + IEvent[] items = handlers.Items; + for (int i = 0; i < items.Length; i++) + { + try { items[i].method(target, model, parts); } + catch (Exception ex) { LogHandlerException(ex, items[i]); } + } + } + } + // [player name] = { model name } static readonly ConcurrentDictionary> SentCustomModels = new ConcurrentDictionary>(); diff --git a/CustomModels/StoredCustomModel.cs b/CustomModels/StoredCustomModel.cs index 7e00dbe..05c9846 100644 --- a/CustomModels/StoredCustomModel.cs +++ b/CustomModels/StoredCustomModel.cs @@ -12,7 +12,7 @@ public sealed partial class CustomModelsPlugin { // don't store "name" because we will use filename for model name // don't store "parts" because we store those in the full .bbmodel file // don't store "u/vScale" because we take it from bbmodel's resolution.width - class StoredCustomModel { + public class StoredCustomModel { [JsonIgnore] public string modelName = null; [JsonIgnore] public HashSet modifiers = new HashSet(StringComparer.OrdinalIgnoreCase); [JsonIgnore] public float scale = 1.0f; @@ -276,11 +276,15 @@ public class ModelAndParts { public CustomModel model; public CustomModelPart[] parts; } - public ModelAndParts ComputeModelAndParts() { + public ModelAndParts ComputeModelAndParts(Player dest=null) { var blockBench = ParseBlockBench(); var model = this.ToCustomModel(blockBench); var parts = new List(blockBench.ToParts()); + // Call event so parts can be dynamically added/modified on the fly by plugins + // Good for clocks, signs, etc + CustomModelsPlugin.ComputeModelAndParts.Call(dest, model, parts); + if (this.autoNameY) { float maxPartHeight = 0.0f; foreach (var part in parts) { @@ -481,14 +485,15 @@ void f(Part left, Part right) { } public void Define(Player p) { - var modelAndParts = this.ComputeModelAndParts(); + var modelAndParts = this.ComputeModelAndParts(p); DefineModel(p, modelAndParts.model, modelAndParts.parts); } } // class StoredCustomModel - class Part : CustomModelPart { + public class Part : CustomModelPart { + public string name = string.Empty; public bool layer = false; public bool skinLeftArm = false; public bool skinRightArm = false;