Skip to content

Commit

Permalink
Fix fuel tanks not updating properly
Browse files Browse the repository at this point in the history
Also fixes the PhysicsInit override because it got a new argument in the latest Gmod update
  • Loading branch information
thecraftianman committed Oct 30, 2024
1 parent 5711b2c commit 5701272
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions lua/entities/acf_fueltank/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,15 @@ do -- Spawn and Update functions
local function UpdateFuelTank(Entity, Data, Class, FuelTank, FuelType)
-- If updating, keep the same fuel level
local Percentage = Entity.Capacity and Entity.Fuel / Entity.Capacity or 1
local Material = Class.Material or FuelTank and FuelTank.Model

Entity.ACF = Entity.ACF or {}
Entity.ACF.Model = FuelTank and FuelTank.Model or Class.Model -- Must be set before changing model
Entity.ClassData = Class

if Class.IsScalable then
Entity:SetSize(Data.Size)
else
Contraption.SetModel(Entity, Entity.ACF.Model)
Entity:PhysicsInit(SOLID_VPHYSICS, true)
Entity:SetMoveType(MOVETYPE_VPHYSICS)
end
Entity:SetScaledModel(Entity.ACF.Model)
Entity:SetSize(Class.IsScalable and Data.Size or Entity:GetOriginalSize())
Entity:SetMaterial(Material or "")

-- Storing all the relevant information on the entity for duping
for _, V in ipairs(Entity.DataStore) do
Expand Down Expand Up @@ -593,7 +590,14 @@ function ENT:OnResized(Size)
do -- Calculate new empty mass
local Wall = ACF.FuelArmor * ACF.MmToInch -- Wall thickness in inches
local Class = self.ClassData
local _, Area = Class.CalcVolume(Size, Wall)
local _, Area

if Class.CalcVolume then
_, Area = Class.CalcVolume(Size, Wall)
else -- Default to finding surface area/volume based off physics object instead
local PhysObj = self:GetPhysicsObject()
Area = PhysObj:GetSurfaceArea()
end

local Mass = (Area * Wall) * 16.387 * 0.0079 -- Total wall volume * cu in to cc * density of steel (kg/cc)

Expand Down
4 changes: 2 additions & 2 deletions lua/entities/base_scalable/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ end
do
local EntMeta = FindMetaTable("Entity")

function ENT:PhysicsInit(Solid, Bypass, ...)
function ENT:PhysicsInit(Solid, MassCenter, Bypass, ...)
if Bypass then
return EntMeta.PhysicsInit(self, Solid, Bypass, ...)
return EntMeta.PhysicsInit(self, Solid, MassCenter, Bypass, ...)
end

local Init = self.FirstInit
Expand Down

0 comments on commit 5701272

Please sign in to comment.