local P={}local z local g=game:GetService("\082\117\110\083\101\114\118\105\099\101")function P.setupWorldModel(P)if z then return z end local q=g:IsClient()and"\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"or"\083\101\114\118\101\114\083\116\111\114\097\103\101"z=Instance.new("\087\111\114\108\100\077\111\100\101\108")z.Name="\090\111\110\101\080\108\117\115\087\111\114\108\100\077\111\100\101\108"z.Parent=game:GetService(q)return z end function P._getCombinedResults(g,P,...)local q=workspace[P](workspace,...)if z then local g=z[P](z,...)for P,z in pairs(g)do table.insert(q,z)end end return q end function P.GetPartBoundsInBox(q,P,z,g)return q:_getCombinedResults("\071\101\116\080\097\114\116\066\111\117\110\100\115\073\110\066\111\120",P,z,g)end function P.GetPartBoundsInRadius(q,P,z,g)return q:_getCombinedResults("\071\101\116\080\097\114\116\066\111\117\110\100\115\073\110\082\097\100\105\117\115",P,z,g)end function P.GetPartsInPart(g,P,z)return g:_getCombinedResults("\071\101\116\080\097\114\116\115\073\110\080\097\114\116",P,z)end return P
-- #selene: allow(unused_variable)

local CollectiveWorldModel = {}
local worldModel
local runService = game:GetService("RunService")

-- FUNCTIONS
function CollectiveWorldModel.setupWorldModel(zone)
	if worldModel then
		return worldModel
	end
	local location = (runService:IsClient() and "ReplicatedStorage") or "ServerStorage"
	worldModel = Instance.new("WorldModel")
	worldModel.Name = "ZonePlusWorldModel"
	worldModel.Parent = game:GetService(location)
	return worldModel
end

-- METHODS
function CollectiveWorldModel:_getCombinedResults(methodName, ...)
	local results = workspace[methodName](workspace, ...)
	if worldModel then
		local additionalResults = worldModel[methodName](worldModel, ...)
		for _, result in pairs(additionalResults) do
			table.insert(results, result)
		end
	end
	return results
end

function CollectiveWorldModel:GetPartBoundsInBox(cframe, size, overlapParams)
	return self:_getCombinedResults("GetPartBoundsInBox", cframe, size, overlapParams)
end

function CollectiveWorldModel:GetPartBoundsInRadius(position, radius, overlapParams)
	return self:_getCombinedResults("GetPartBoundsInRadius", position, radius, overlapParams)
end

function CollectiveWorldModel:GetPartsInPart(part, overlapParams)
	return self:_getCombinedResults("GetPartsInPart", part, overlapParams)
end

return CollectiveWorldModel
