From f4e75425abf8d90fbae5eb481db8794e5ff74156 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sat, 6 Dec 2025 09:10:52 +0900 Subject: [PATCH] Particle as ILoadable --- Particles/GeneralParticleHandler.cs | 26 +++++++++----------------- Particles/Particle.cs | 13 ++++++++++++- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Particles/GeneralParticleHandler.cs b/Particles/GeneralParticleHandler.cs index 672f3c995f..0378af48d6 100644 --- a/Particles/GeneralParticleHandler.cs +++ b/Particles/GeneralParticleHandler.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; using CalamityMod.Enums; using CalamityMod.Systems.Graphic.PixelationSystem; using Microsoft.Xna.Framework; @@ -64,25 +63,18 @@ namespace CalamityMod.Particles #endregion #region Loading and Unloading - public override void PostSetupContent() + + internal static void RegisterParticleType(Particle particle) { - Type baseParticleType = typeof(Particle); - ReflectionHelper.IterateEveryModsTypes(action: type => - { - int ID = particleIDsByTypes.Count; //Get the ID of the particle - particleIDsByTypes[type] = ID; + var type = particle.GetType(); + int ID = particleIDsByTypes.Count; //Get the ID of the particle + particleIDsByTypes[type] = ID; - // Flow: 2024/09/17 - // 'UnintializedObject' is allowed to use here as it's only read for Texture string Property - // But do NOT EVER use it's instance as they are literally Uninitialized. - // It might cause unintended behaviour if we do that. - Particle instance = (Particle)RuntimeHelpers.GetUninitializedObject(type); + string texturePath = particle.Texture; + if (string.IsNullOrEmpty(texturePath)) + texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name; - string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name; - if (instance.Texture != "") - texturePath = instance.Texture; - particleTexturesByIDs[ID] = ModContent.Request(texturePath, instance.TextureRequestMode); - }); + particleTexturesByIDs[ID] = ModContent.Request(texturePath, particle.TextureRequestMode); } public override void Load() diff --git a/Particles/Particle.cs b/Particles/Particle.cs index f5c9ec50e1..30f5ad6813 100644 --- a/Particles/Particle.cs +++ b/Particles/Particle.cs @@ -2,10 +2,11 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; +using Terraria.ModLoader; namespace CalamityMod.Particles { - public class Particle + public class Particle : ILoadable { /// /// The ID of the particle type as registered by when the mod loads. @@ -146,5 +147,15 @@ namespace CalamityMod.Particles /// Removes the particle from the handler /// public void Kill() => GeneralParticleHandler.RemoveParticle(this); + + public void Load(Mod mod) + { + GeneralParticleHandler.RegisterParticleType(this); + } + + public void Unload() + { + + } } }