local a=20 local d=12 local T=.5 local j={PetCostumeHat="\072\097\116";PetCostumeCollar="\067\111\108\108\097\114";PetCostumeBack="\067\097\112\101",PetCostumeAnkle="\065\110\107\108\101\116"}local D=game:GetService("\082\117\110\083\101\114\118\105\099\101")local p=require(((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local X=p:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\079\098\106\101\099\116")local G=p:GetResource("\071\097\109\101\068\097\116\097\046\073\116\101\109\046\073\116\101\109\115")local B=p:GetResource("\071\097\109\101\068\097\116\097\046\073\116\101\109\046\080\101\116\083\107\105\110\084\101\120\116\117\114\101\115")local g=X:Extend()g:SetClassName("\080\101\116\068\105\115\112\108\097\121")function g.__new(p,j)p:InitializeSuper()p.LastClothes={}p.LastClothCostumes={}local X=Instance.new("\086\105\101\119\112\111\114\116\070\114\097\109\101")X.BackgroundTransparency=1 X.Size=UDim2.new(1,0,1,0)X.Parent=j p.ViewportFrame=X local G=Instance.new("\067\097\109\101\114\097")G.FieldOfView=a G.Parent=X p.Camera=G X.CurrentCamera=G local B=Instance.new("\087\111\114\108\100\077\111\100\101\108")B.Parent=X p.WorldModel=B D.RenderStepped:Connect(function()G.CFrame=CFrame.Angles(0,math.sin(tick()*T)/2,0)*CFrame.new(0,0,d)end)end function g.SetPet(d,a)if d.LastPetName==a then return end d.LastPetName=a if d.Pet then d.Pet:Destroy()end local T=(p:GetResource("\080\101\116\077\111\100\101\108\115\046"..a)):Clone()T.PrimaryPart=T:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")T:SetPrimaryPartCFrame(CFrame.Angles(0,math.pi,0))T.Parent=d.WorldModel d.Pet=T d.Clothes=T:WaitForChild("\067\108\111\116\104\101\115")local D=d.LastClothes for a,T in pairs(j)do d:SetItem(a,{Name=D[a]},true)end local X=Instance.new("\065\110\105\109\097\116\105\111\110")X.AnimationId="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\054\049\050\049\048\052\053\049"local G=T:WaitForChild("\072\117\109\097\110\111\105\100")local B=G:LoadAnimation(X)B.Stopped:Connect(function()B:Play()end)B:Play()end function g.SetItem(D,a,d,T)local p if d then p=d.Name end if D.LastClothes[a]==p and not T then return end D.LastClothes[a]=p if not D.Pet or not D.Clothes then return end local X if p and G[p]then X=G[p].TextureId end for d,T in pairs(D.Clothes:GetChildren())do if T:IsA("\066\097\115\101\080\097\114\116")and T.Name==j[a]then local a=T:FindFirstChildWhichIsA("\070\105\108\101\077\101\115\104")if a then if X then T.Transparency=0 a.TextureId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..tostring(X)else T.Transparency=1 end end end end if p and G[p]then D.LastClothCostumes[a]=G[p].CostumeName else D.LastClothCostumes[a]=nil end local g=D.LastClothCostumes.PetCostumeHat==D.LastClothCostumes.PetCostumeCollar and(D.LastClothCostumes.PetCostumeHat==D.LastClothCostumes.PetCostumeBack and D.LastClothCostumes.PetCostumeHat==D.LastClothCostumes.PetCostumeAnkle)local m=g and D.LastClothCostumes.PetCostumeHat or"\068\101\102\097\117\108\116"local H=B[m][D.LastPetName]for a,d in pairs(D.Pet:GetChildren())do if d:IsA("\066\097\115\101\080\097\114\116")then local a=d:FindFirstChildWhichIsA("\070\105\108\101\077\101\115\104")if a then a.TextureId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..tostring(H)elseif d:IsA("\077\101\115\104\080\097\114\116")then d.TextureID="\114\098\120\097\115\115\101\116\105\100\058\047\047"..tostring(H)end end end end return g
--[[
TheNexusAvenger

Displays the pet for the inventory.
--]]

local CAMERA_FIELD_OF_VIEW = 20
local CAMERA_CFRAME_BACK = 12
local ROTATE_SPEED_MULTIPLIER = 0.5
local SLOT_TO_PART_NAME = {
	PetCostumeHat = "Hat",
	PetCostumeCollar = "Collar",
	PetCostumeBack = "Cape",
	PetCostumeAnkle = "Anklet",
}



local RunService = game:GetService("RunService")

local ReplicatedStorageProject = require(game:GetService("ReplicatedStorage"):WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local NexusObject = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusObject")
local ItemData = ReplicatedStorageProject:GetResource("GameData.Item.Items")
local PetSkinTextures = ReplicatedStorageProject:GetResource("GameData.Item.PetSkinTextures")

local PetDisplay = NexusObject:Extend()
PetDisplay:SetClassName("PetDisplay")



--[[
Creates a pet display.
--]]
function PetDisplay:__new(Parent)
	self:InitializeSuper()
	
	--Store the state.
	self.LastClothes = {}
	self.LastClothCostumes = {}
	
	--Create the container.
	local ViewportFrame = Instance.new("ViewportFrame")
	ViewportFrame.BackgroundTransparency = 1
	ViewportFrame.Size = UDim2.new(1,0,1,0)
	ViewportFrame.Parent = Parent
	self.ViewportFrame = ViewportFrame
	
	local Camera = Instance.new("Camera")
	Camera.FieldOfView = CAMERA_FIELD_OF_VIEW
	Camera.Parent = ViewportFrame
	self.Camera = Camera
	ViewportFrame.CurrentCamera = Camera
	
	local WorldModel = Instance.new("WorldModel")
	WorldModel.Parent = ViewportFrame
	self.WorldModel = WorldModel
	
	--Start rotating the camera.
	RunService.RenderStepped:Connect(function()
		Camera.CFrame = CFrame.Angles(0,math.sin(tick() * ROTATE_SPEED_MULTIPLIER)/2,0) * CFrame.new(0,0,CAMERA_CFRAME_BACK)
	end)
end

--[[
Sets the pet to display.
--]]
function PetDisplay:SetPet(PetName)
	--Return if the pet hasn't changed.
	if self.LastPetName == PetName then return end
	self.LastPetName = PetName

	--Destroy the existing pet.
	if self.Pet then
		self.Pet:Destroy()
	end

	--Add the pet.
	local Pet = ReplicatedStorageProject:GetResource("PetModels."..PetName):Clone()
	Pet.PrimaryPart = Pet:WaitForChild("HumanoidRootPart")
	Pet:SetPrimaryPartCFrame(CFrame.Angles(0,math.pi,0))
	Pet.Parent = self.WorldModel
	self.Pet = Pet
	self.Clothes = Pet:WaitForChild("Clothes")
	
	--Set the clothing.
	local ExistingClothing = self.LastClothes
	for Slot,_ in pairs(SLOT_TO_PART_NAME) do
		self:SetItem(Slot,{Name=ExistingClothing[Slot]},true)
	end

	--Start animating the pet.
	local Animation = Instance.new("Animation")
	Animation.AnimationId = "rbxassetid://161210451"
	
	local Humanoid = Pet:WaitForChild("Humanoid")
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack.Stopped:Connect(function()
		AnimationTrack:Play()
	end)
	AnimationTrack:Play()
end

--[[
Sets the clothing to use for the pet.
--]]
function PetDisplay:SetItem(Slot,Item,ForceUpdate)
	local Name
	if Item then Name = Item.Name end

	--Return if the name hasn't changed.
	if self.LastClothes[Slot] == Name and not ForceUpdate then
		return
	end
	self.LastClothes[Slot] = Name

	--Return if the pet is not set.
	if not self.Pet or not self.Clothes then
		return
	end

	--Determine the texture.
	local Texture
	if Name and ItemData[Name] then
		Texture = ItemData[Name].TextureId
	end

	--Update the textures.
	for _,Part in pairs(self.Clothes:GetChildren()) do
		if Part:IsA("BasePart") and Part.Name == SLOT_TO_PART_NAME[Slot] then
			local Mesh = Part:FindFirstChildWhichIsA("FileMesh")
			if Mesh then
				if Texture then
					Part.Transparency = 0
					Mesh.TextureId = "rbxassetid://"..tostring(Texture)
				else
					Part.Transparency = 1
				end
			end
		end
	end

	--Update the costume for the slot.
	if Name and ItemData[Name] then
		self.LastClothCostumes[Slot] = ItemData[Name].CostumeName
	else
		self.LastClothCostumes[Slot] = nil
	end

	--Update the pet texture if all 4 parts are part of costume match.
	local HasFullCostume = (self.LastClothCostumes["PetCostumeHat"] == self.LastClothCostumes["PetCostumeCollar"]) and (self.LastClothCostumes["PetCostumeHat"] == self.LastClothCostumes["PetCostumeBack"]) and (self.LastClothCostumes["PetCostumeHat"] == self.LastClothCostumes["PetCostumeAnkle"])
	local Costume = HasFullCostume and self.LastClothCostumes["PetCostumeHat"] or "Default"
	local PetTextureId = PetSkinTextures[Costume][self.LastPetName]
	for _,Part in pairs(self.Pet:GetChildren()) do
		if Part:IsA("BasePart") then
			local Mesh = Part:FindFirstChildWhichIsA("FileMesh")
			if Mesh then
				Mesh.TextureId = "rbxassetid://"..tostring(PetTextureId)
			elseif Part:IsA("MeshPart") then
				Part.TextureID = "rbxassetid://"..tostring(PetTextureId)
			end
		end
	end
end



return PetDisplay