diff --git a/lua/acf/compatibility/proper_clipping_sv.lua b/lua/acf/compatibility/proper_clipping_sv.lua index 585814e8a..ff1e8546d 100644 --- a/lua/acf/compatibility/proper_clipping_sv.lua +++ b/lua/acf/compatibility/proper_clipping_sv.lua @@ -1,21 +1,50 @@ --- Resolves issues with properClipping --- Triggers an ACF.Activate update whenever a new clip is created or removed +local hook = hook +local ACF = ACF -local timerSimple = timer.Simple +do -- Triggers an ACF.Activate update whenever a new physical clip is created or removed + local timer = timer -local function activate(ent) - if ent._ACF_ProperClipping then return end + local function Update(Entity) + if Entity._ACF_Physclip_Update then return end - ent._ACF_ProperClipping = true + Entity._ACF_Physclip_Update = true - timerSimple(engine.TickInterval() * 2, function() - if not IsValid(ent) then return end + timer.Simple(0, function() + if not IsValid(Entity) then return end - ent._ACF_ProperClipping = nil + Entity._ACF_Physclip_Update = nil - ACF.Activate(ent, true) - end) + ACF.Activate(Entity, true) + end) + end + + hook.Add("ProperClippingPhysicsClipped", "ACF", Update) + hook.Add("ProperClippingPhysicsReset", "ACF", Update) end -hook.Add("ProperClippingClipAdded", "ACF", activate) -hook.Add("ProperClippingClipRemoved", "ACF", activate) \ No newline at end of file +do -- Forces an ACF armored entity to get rid of their mass entity modifier and use the ACF_Armor one instead + local duplicator = duplicator + + local function UpdateMass(Entity) + local EntMods = Entity.EntityMods + + if not EntMods then return end + + local Armor = EntMods.ACF_Armor + + if Armor and Armor.Thickness then + local MassMod = EntMods and EntMods.mass + + if MassMod then + duplicator.ClearEntityModifier(Entity, "ACF_Armor") + duplicator.StoreEntityModifier(Entity, "ACF_Armor", { Ductility = Armor.Ductility }) + else + duplicator.ClearEntityModifier(Entity, "mass") + end + end + end + + hook.Add("ProperClippingClipAdded", "ACF", UpdateMass) + hook.Add("ProperClippingClipRemoved", "ACF", UpdateMass) + hook.Add("ProperClippingClipsRemoved", "ACF", UpdateMass) +end \ No newline at end of file diff --git a/lua/acf/contraption/contraption_sv.lua b/lua/acf/contraption/contraption_sv.lua index 6c03b7586..8798dc092 100644 --- a/lua/acf/contraption/contraption_sv.lua +++ b/lua/acf/contraption/contraption_sv.lua @@ -52,7 +52,7 @@ end function Contraption.GetAllPhysicalEntities(Ent, Tab) local Res = Tab or {} - if ACF.Check(Ent) and not Res[Ent] then + if IsValid(Ent) and not Res[Ent] then Res[Ent] = true if Ent.Constraints then @@ -77,7 +77,7 @@ function Contraption.GetAllChildren(Ent, Tab) local Res = Tab or {} for _, V in pairs(Ent:GetChildren()) do - if not ACF.Check(V) or Res[V] then continue end + if not IsValid(V) or Res[V] then continue end Res[V] = true Contraption.GetAllChildren(V, Res) diff --git a/lua/weapons/gmod_tool/stools/acfarmorprop.lua b/lua/weapons/gmod_tool/stools/acfarmorprop.lua index aefe720bc..be7d3785e 100644 --- a/lua/weapons/gmod_tool/stools/acfarmorprop.lua +++ b/lua/weapons/gmod_tool/stools/acfarmorprop.lua @@ -360,41 +360,6 @@ else -- Serverside-only stuff UpdateArmor(_, Entity, { Thickness = Thickness, Ductility = Ductility * 100 }) end) - - -- ProperClipping compatibility - - if ProperClipping then - local Override = { - AddClip = true, - RemoveClip = true, - RemoveClips = true, - } - - for Name in pairs(Override) do - local Old = ProperClipping[Name] - - ProperClipping[Name] = function(Entity, ...) - local EntMods = Entity.EntityMods - local MassMod = EntMods and EntMods.mass - local Result = Old(Entity, ...) - - if not EntMods then return Result end - - local Armor = EntMods.ACF_Armor - - if Armor and Armor.Thickness then - if MassMod then - duplicator.ClearEntityModifier(Entity, "ACF_Armor") - duplicator.StoreEntityModifier(Entity, "ACF_Armor", { Ductility = Armor.Ductility }) - else - duplicator.ClearEntityModifier(Entity, "mass") - end - end - - return Result - end - end - end end do -- Allowing everyone to read contraptions