From 5b2798c80576cd3627bf231bf577d17b75860326 Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Mon, 21 Oct 2024 21:09:36 -0400 Subject: [PATCH] Add better rendergroup restriction (#1879) --- lua/entities/starfall_hologram/cl_init.lua | 1 - lua/starfall/libs_sh/hologram.lua | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/entities/starfall_hologram/cl_init.lua b/lua/entities/starfall_hologram/cl_init.lua index 5e97536bf..b6d00ac89 100644 --- a/lua/entities/starfall_hologram/cl_init.lua +++ b/lua/entities/starfall_hologram/cl_init.lua @@ -65,7 +65,6 @@ function ENT:Initialize() self.sf_userrenderbounds = false self:SetupBones() self:OnScaleChanged(nil, nil, self:GetScale()) - self:OnRenderGroupChanged(nil, nil, self:GetRenderGroupInternal()) if self:EntIndex() == -1 then self:SetPlayerColorInternal(VECTOR_PLAYER_COLOR_DISABLED) diff --git a/lua/starfall/libs_sh/hologram.lua b/lua/starfall/libs_sh/hologram.lua index 99676596d..16c799267 100644 --- a/lua/starfall/libs_sh/hologram.lua +++ b/lua/starfall/libs_sh/hologram.lua @@ -500,17 +500,25 @@ function hologram_methods:setCullMode(mode) holo:SetCullMode(mode==1) end +local allowedRenderGroups = { +[RENDERGROUP_OPAQUE]=true, +[RENDERGROUP_TRANSLUCENT]=true, +[RENDERGROUP_BOTH]=true, +[RENDERGROUP_VIEWMODEL]=true, +[RENDERGROUP_VIEWMODEL_TRANSLUCENT]=true, +[RENDERGROUP_OPAQUE_BRUSH]=true, +} --- Set the render group for a hologram. -- @shared --- @param number|nil group Render group. If unset, the engine will decide the render group based on the entity's materials. +-- @param number|nil group Render group. If unset, the engine will decide the render group based on the entity's materials. Can be RENDERGROUP.OPAQUE RENDERGROUP.TRANSLUCENT RENDERGROUP.BOTH RENDERGROUP.VIEWMODEL RENDERGROUP.VIEWMODEL.TRANSLUCENT RENDERGROUP.OPAQUE.BRUSH function hologram_methods:setRenderGroup(group) local holo = getholo(self) checkpermission(instance, holo, "entities.setRenderProperty") if group then checkluatype(group, TYPE_NUMBER) - - holo:SetRenderGroupInternal(math.Truncate(group)) + if not allowedRenderGroups[group] then SF.Throw("Invalid rendergroup!") end + holo:SetRenderGroupInternal(group) else holo:SetRenderGroupInternal(-1) end