local z={}z.__index=z z.__type="\080\097\114\116\067\097\099\104\101"local p=CFrame.new(0,1000000000,0)local K=require(script:WaitForChild("\084\097\098\108\101"))function z.new(M,b,h)assert(b>0,"\080\114\101\099\114\101\097\116\101\100\080\097\114\116\115 \099\097\110 \110\111\116 \098\101 \110\101\103\097\116\105\118\101\033")if(b~=0)==false then warn("\080\114\101\099\114\101\097\116\101\100\080\097\114\116\115 \105\115 \048\033 \084\104\105\115 \109\097\121 \104\097\118\101 \097\100\118\101\114\115\101 \101\102\102\101\099\116\115 \119\104\101\110 \105\110\105\116\105\097\108\108\121 \117\115\105\110\103 \116\104\101 \099\097\099\104\101\046")end if M.Archivable==false then warn("\084\104\101 \116\101\109\112\108\097\116\101\'\115 \065\114\099\104\105\118\097\098\108\101 \112\114\111\112\101\114\116\121 \104\097\115 \098\101\101\110 \115\101\116 \116\111 \102\097\108\115\101\044 \119\104\105\099\104 \112\114\101\118\101\110\116\115 \105\116 \102\114\111\109 \098\101\105\110\103 \099\108\111\110\101\100\046 \073\116 \119\105\108\108 \116\101\109\112\111\114\097\114\105\108\121 \098\101 \115\101\116 \116\111 \116\114\117\101\046")end M.Archivable=true M.Archivable=M.Archivable M=M:Clone()local N={Open={},InUse={};CurrentCacheParent=h or workspace,Template=M,ExpansionSize=10}setmetatable(N,z)for z=1,b and 5,1 do local b=M:Clone()b.CFrame=p b.Anchored=true b.Parent=N.CurrentCacheParent K.insert(N.Open,b)end N.Template.Parent=nil return N end function z.GetPart(M)assert(getmetatable(M)==z,("\067\097\110\110\111\116 \115\116\097\116\105\099\097\108\108\121 \105\110\118\111\107\101 \109\101\116\104\111\100 \'\037\115\' - \073\116 \105\115 \097\110 \105\110\115\116\097\110\099\101 \109\101\116\104\111\100\046 \067\097\108\108 \105\116 \111\110 \097\110 \105\110\115\116\097\110\099\101 \111\102 \116\104\105\115 \099\108\097\115\115 \099\114\101\097\116\101\100 \118\105\097 \037\115"):format("\071\101\116\080\097\114\116","\080\097\114\116\067\097\099\104\101\046\110\101\119"))if#M.Open==0 then for z=1,M.ExpansionSize,1 do local b=M.Template:Clone()b.CFrame=p b.Anchored=true b.Parent=M.CurrentCacheParent K.insert(M.Open,b)end end local b=M.Open[#M.Open]M.Open[#M.Open]=nil K.insert(M.InUse,b)return b end function z.ReturnPart(M,b)assert(getmetatable(M)==z,("\067\097\110\110\111\116 \115\116\097\116\105\099\097\108\108\121 \105\110\118\111\107\101 \109\101\116\104\111\100 \'\037\115\' - \073\116 \105\115 \097\110 \105\110\115\116\097\110\099\101 \109\101\116\104\111\100\046 \067\097\108\108 \105\116 \111\110 \097\110 \105\110\115\116\097\110\099\101 \111\102 \116\104\105\115 \099\108\097\115\115 \099\114\101\097\116\101\100 \118\105\097 \037\115"):format("\082\101\116\117\114\110\080\097\114\116","\080\097\114\116\067\097\099\104\101\046\110\101\119"))local h=K.indexOf(M.InUse,b)if h==nil then return end K.remove(M.InUse,h)K.insert(M.Open,b)b.CFrame=p b.Anchored=true end function z.SetCacheParent(p,K)assert(getmetatable(p)==z,("\067\097\110\110\111\116 \115\116\097\116\105\099\097\108\108\121 \105\110\118\111\107\101 \109\101\116\104\111\100 \'\037\115\' - \073\116 \105\115 \097\110 \105\110\115\116\097\110\099\101 \109\101\116\104\111\100\046 \067\097\108\108 \105\116 \111\110 \097\110 \105\110\115\116\097\110\099\101 \111\102 \116\104\105\115 \099\108\097\115\115 \099\114\101\097\116\101\100 \118\105\097 \037\115"):format("\083\101\116\067\097\099\104\101\080\097\114\101\110\116","\080\097\114\116\067\097\099\104\101\046\110\101\119"))assert(K:IsDescendantOf(workspace)or K==workspace,"\067\097\099\104\101 \112\097\114\101\110\116 \105\115 \110\111\116 \097 \100\101\115\099\101\110\100\097\110\116 \111\102 \087\111\114\107\115\112\097\099\101\033 \080\097\114\116\115 \115\104\111\117\108\100 \098\101 \107\101\112\116 \119\104\101\114\101 \116\104\101\121 \119\105\108\108 \114\101\109\097\105\110 \105\110 \116\104\101 \118\105\115\105\098\108\101 \119\111\114\108\100\046")p.CurrentCacheParent=K for z=1,#p.Open,1 do p.Open[z].Parent=K end for z=1,#p.InUse,1 do p.InUse[z].Parent=K end end function z.Expand(M,b)assert(getmetatable(M)==z,("\067\097\110\110\111\116 \115\116\097\116\105\099\097\108\108\121 \105\110\118\111\107\101 \109\101\116\104\111\100 \'\037\115\' - \073\116 \105\115 \097\110 \105\110\115\116\097\110\099\101 \109\101\116\104\111\100\046 \067\097\108\108 \105\116 \111\110 \097\110 \105\110\115\116\097\110\099\101 \111\102 \116\104\105\115 \099\108\097\115\115 \099\114\101\097\116\101\100 \118\105\097 \037\115"):format("\069\120\112\097\110\100","\080\097\114\116\067\097\099\104\101\046\110\101\119"))if b==nil then b=M.ExpansionSize end for z=1,b,1 do local b=M.Template:Clone()b.CFrame=p b.Anchored=true b.Parent=M.CurrentCacheParent K.insert(M.Open,b)end end function z.Dispose(p)assert(getmetatable(p)==z,("\067\097\110\110\111\116 \115\116\097\116\105\099\097\108\108\121 \105\110\118\111\107\101 \109\101\116\104\111\100 \'\037\115\' - \073\116 \105\115 \097\110 \105\110\115\116\097\110\099\101 \109\101\116\104\111\100\046 \067\097\108\108 \105\116 \111\110 \097\110 \105\110\115\116\097\110\099\101 \111\102 \116\104\105\115 \099\108\097\115\115 \099\114\101\097\116\101\100 \118\105\097 \037\115"):format("\068\105\115\112\111\115\101","\080\097\114\116\067\097\099\104\101\046\110\101\119"))for z=1,#p.Open,1 do p.Open[z]:Destroy()end for z=1,#p.InUse,1 do p.InUse[z]:Destroy()end p.Template:Destroy()p.Open={}p.InUse={}p.CurrentCacheParent=nil p.GetPart=nil p.ReturnPart=nil p.SetCacheParent=nil p.Expand=nil p.Dispose=nil end return z


local v1 = {};
v1.__index = v1;
v1.__type = "PartCache";
local u1 = CFrame.new(0, 1000000000, 0);
local u2 = require(script:WaitForChild("Table"));
function v1.new(p1, p2, p3)
	assert(p2 > 0, "PrecreatedParts can not be negative!");
	if p2 ~= 0 == false then
		warn("PrecreatedParts is 0! This may have adverse effects when initially using the cache.");
	end;
	if p1.Archivable == false then
		warn("The template's Archivable property has been set to false, which prevents it from being cloned. It will temporarily be set to true.");
	end;
	p1.Archivable = true;
	p1.Archivable = p1.Archivable;
	p1 = p1:Clone();
	local v2 = {
		Open = {}, 
		InUse = {}, 
		CurrentCacheParent = p3 or workspace, 
		Template = p1, 
		ExpansionSize = 10
	};
	setmetatable(v2, v1);
	for v3 = 1, p2 and 5 do
		local v4 = p1:Clone();
		v4.CFrame = u1;
		v4.Anchored = true;
		v4.Parent = v2.CurrentCacheParent;
		u2.insert(v2.Open, v4);
	end;
	v2.Template.Parent = nil;
	return v2;
end;
function v1.GetPart(p4)
	assert(getmetatable(p4) == v1, ("Cannot statically invoke method '%s' - It is an instance method. Call it on an instance of this class created via %s"):format("GetPart", "PartCache.new"));
	if #p4.Open == 0 then
		for v5 = 1, p4.ExpansionSize do
			local v6 = p4.Template:Clone();
			v6.CFrame = u1;
			v6.Anchored = true;
			v6.Parent = p4.CurrentCacheParent;
			u2.insert(p4.Open, v6);
		end;
	end;
	local v7 = p4.Open[#p4.Open];
	p4.Open[#p4.Open] = nil;
	u2.insert(p4.InUse, v7);
	return v7;
end;
function v1.ReturnPart(p5, p6)
	assert(getmetatable(p5) == v1, ("Cannot statically invoke method '%s' - It is an instance method. Call it on an instance of this class created via %s"):format("ReturnPart", "PartCache.new"));
	local v8 = u2.indexOf(p5.InUse, p6);
	if v8 == nil then
		return;
	end;
	u2.remove(p5.InUse, v8);
	u2.insert(p5.Open, p6);
	p6.CFrame = u1;
	p6.Anchored = true;
end;
function v1.SetCacheParent(p7, p8)
	assert(getmetatable(p7) == v1, ("Cannot statically invoke method '%s' - It is an instance method. Call it on an instance of this class created via %s"):format("SetCacheParent", "PartCache.new"));
	assert(p8:IsDescendantOf(workspace) or p8 == workspace, "Cache parent is not a descendant of Workspace! Parts should be kept where they will remain in the visible world.");
	p7.CurrentCacheParent = p8;
	for v9 = 1, #p7.Open do
		p7.Open[v9].Parent = p8;
	end;
	for v10 = 1, #p7.InUse do
		p7.InUse[v10].Parent = p8;
	end;
end;
function v1.Expand(p9, p10)
	assert(getmetatable(p9) == v1, ("Cannot statically invoke method '%s' - It is an instance method. Call it on an instance of this class created via %s"):format("Expand", "PartCache.new"));
	if p10 == nil then
		p10 = p9.ExpansionSize;
	end;
	for v11 = 1, p10 do
		local v12 = p9.Template:Clone();
		v12.CFrame = u1;
		v12.Anchored = true;
		v12.Parent = p9.CurrentCacheParent;
		u2.insert(p9.Open, v12);
	end;
end;
function v1.Dispose(p11)
	assert(getmetatable(p11) == v1, ("Cannot statically invoke method '%s' - It is an instance method. Call it on an instance of this class created via %s"):format("Dispose", "PartCache.new"));
	for v13 = 1, #p11.Open do
		p11.Open[v13]:Destroy();
	end;
	for v14 = 1, #p11.InUse do
		p11.InUse[v14]:Destroy();
	end;
	p11.Template:Destroy();
	p11.Open = {};
	p11.InUse = {};
	p11.CurrentCacheParent = nil;
	p11.GetPart = nil;
	p11.ReturnPart = nil;
	p11.SetCacheParent = nil;
	p11.Expand = nil;
	p11.Dispose = nil;
end;
return v1;
