Skip to content

Commit

Permalink
Patched armor changes on physclipped entities
Browse files Browse the repository at this point in the history
- Worked around Proper Clipping messing around with the mass entity modifier, which will overwrite the ACF Armor thickness value.
  • Loading branch information
TwistedTail committed Sep 13, 2024
1 parent 51c4b44 commit 31b50c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
16 changes: 12 additions & 4 deletions lua/acf/compatibility/proper_clipping_sv.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
local hook = hook
local ACF = ACF
local duplicator = duplicator
local hook = hook
local ACF = ACF

do -- Triggers an ACF.Activate update whenever a new physical clip is created or removed
local timer = timer

local function Update(Entity)
if Entity._ACF_Physclip_Update then return end

local EntMods = Entity.EntityMods

Entity._ACF_Physclip_Update = true
Entity._ACF_HasMassEntmod = EntMods and EntMods.mass

timer.Simple(0, function()
if not IsValid(Entity) then return end

Entity._ACF_Physclip_Update = nil

if not Entity._ACF_HasMassEntmod then
duplicator.ClearEntityModifier(Entity, "mass")
else
Entity._ACF_HasMassEntmod = nil
end

ACF.Activate(Entity, true)
end)
end
Expand All @@ -23,8 +33,6 @@ do -- Triggers an ACF.Activate update whenever a new physical clip is created or
end

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

Expand Down
9 changes: 4 additions & 5 deletions lua/acf/core/validation_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ function ACF.UpdateArea(Entity, PhysObj)
end

function ACF.UpdateThickness(Entity, PhysObj, Area, Ductility)
local Thickness = Entity.ACF.Thickness
local EntMods = Entity.EntityMods
local MassMod = EntMods and EntMods.mass
local EntMods = Entity.EntityMods
local ArmorMod = EntMods.ACF_Armor
local MassMod = EntMods and EntMods.mass
local Thickness = ArmorMod and ArmorMod.Thickness

if Thickness then
if not MassMod then
Expand All @@ -153,8 +154,6 @@ function ACF.UpdateThickness(Entity, PhysObj, Area, Ductility)
return Thickness
end

Entity.ACF.Thickness = nil

duplicator.ClearEntityModifier(Entity, "ACF_Armor")
duplicator.StoreEntityModifier(Entity, "ACF_Armor", { Ductility = Ductility * 100 })
end
Expand Down
1 change: 0 additions & 1 deletion lua/weapons/gmod_tool/stools/acfarmorprop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ local function UpdateValues(Entity, Data, PhysObj, Area, Ductility)
Mass = MassMod and MassMod.Mass or PhysObj:GetMass()
end

Entity.ACF.Thickness = Thickness
Entity.ACF.Ductility = Ductility * 0.01

if Mass ~= Entity.ACF.Mass then
Expand Down

0 comments on commit 31b50c6

Please sign in to comment.