local H=20 local u=3.6 local z=.5 local A=game:GetService("\082\117\110\083\101\114\118\105\099\101")local Z=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 W=Z: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 s=Z:GetObjectReference("\071\097\109\101\068\097\116\097\046\073\116\101\109\046\073\116\101\109\115")local V=Z:GetResource("\071\097\109\101\068\097\116\097\046\073\116\101\109\046\073\116\101\109\115")local U=W:Extend()U:SetClassName("\073\116\101\109\073\099\111\110")function U.__new(u)u:InitializeSuper()local z=Instance.new("\086\105\101\119\112\111\114\116\070\114\097\109\101")z.BackgroundTransparency=1 z.Size=UDim2.new(1,0,1,0)u.ViewportFrame=z local A=Instance.new("\067\097\109\101\114\097")A.FieldOfView=H A.Parent=z u.Camera=A z.CurrentCamera=A end function U.SetItem(Z,H)if Z.LastModelname==H then return end Z.LastModelname=H if Z.Model then Z.Model:Destroy()end if Z.RotateModelEvent then Z.RotateModelEvent:Disconnect()end if not H or not V[H]then return end local W=V[H]local U=s:FindFirstChild(H)if U then if W.ItemType=="\080\108\097\121\101\114\072\097\116"then local H=U:FindFirstChildWhichIsA("\065\099\099\111\117\116\114\101\109\101\110\116")if H then local u=H:FindFirstChild("\072\097\110\100\108\101")if u then Z.Model=u:Clone()Z.Model.Parent=Z.ViewportFrame end end elseif U:FindFirstChild("\082\054")then local H=(U:FindFirstChild("\082\054")):FindFirstChildWhichIsA("\067\104\097\114\097\099\116\101\114\077\101\115\104")if H then Z.Model=Instance.new("\080\097\114\116")Z.Model.Size=W.ItemType=="\080\108\097\121\101\114\084\111\114\115\111"and Vector3.new(2,2,1)or Vector3.new(1,2,1)Z.Model.Parent=Z.ViewportFrame if W.ItemType=="\080\108\097\121\101\114\084\111\114\115\111"then Z.Model.BrickColor=BrickColor.new("\066\114\105\103\104\116 \103\114\101\101\110")elseif W.ItemType=="\080\108\097\121\101\114\076\101\102\116\065\114\109"or W.ItemType=="\080\108\097\121\101\114\082\105\103\104\116\065\114\109"then Z.Model.BrickColor=BrickColor.new("\066\114\105\103\104\116 \098\108\117\101")else Z.Model.BrickColor=BrickColor.new("\066\114\105\103\104\116 \121\101\108\108\111\119")end local u=Instance.new("\083\112\101\099\105\097\108\077\101\115\104")u.MeshType=Enum.MeshType.FileMesh u.MeshId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..H.MeshId if H.OverlayTextureId~=0 then u.TextureId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..H.OverlayTextureId elseif H.BaseTextureId~=0 then u.TextureId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..H.BaseTextureId end u.Parent=Z.Model end end else if W.MeshId then local H=Instance.new("\080\097\114\116")H.Size=W.Size or Vector3.new(1,1,1)H.Parent=Z.ViewportFrame Z.Model=H local u=Instance.new("\083\112\101\099\105\097\108\077\101\115\104")u.MeshType=Enum.MeshType.FileMesh u.MeshId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..tostring(W.MeshId)u.TextureId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..tostring(W.TextureId)u.Parent=H elseif W.TextureId then local H=Instance.new("\080\097\114\116")H.Transparency=1 H.Size=W.Size or Vector3.new(1,1,1)H.Parent=Z.ViewportFrame Z.Model=H local u=Instance.new("\083\112\101\099\105\097\108\077\101\115\104")u.MeshType=Enum.MeshType.Brick u.Scale=Vector3.new(1,1,0)u.Parent=H local z=Instance.new("\068\101\099\097\108")z.Texture="\114\098\120\097\115\115\101\116\105\100\058\047\047"..tostring(W.TextureId)z.Face=Enum.NormalId.Front z.Parent=H local A=Instance.new("\068\101\099\097\108")A.Texture="\114\098\120\097\115\115\101\116\105\100\058\047\047"..tostring(W.TextureId)A.Face=Enum.NormalId.Back A.Parent=H end end if Z.Model then Z.Camera.CFrame=CFrame.new(0,0,u*math.max(Z.Model.Size.X,Z.Model.Size.Y,Z.Model.Size.Z))end if Z.Model then Z.RotateModelEvent=A.RenderStepped:Connect(function()Z.Model.CFrame=CFrame.Angles(0,0,math.rad(-30))*CFrame.Angles(0,(tick()*z)%(math.pi*2),0)end)end end function U.SetParent(u,H)u.ViewportFrame.Parent=H u.ViewportFrame.ZIndex=H.ZIndex end function U.Destroy(H)if H.Model then H.Model:Destroy()end if H.RotateModelEvent then H.RotateModelEvent:Disconnect()end H.ViewportFrame:Destroy()end return U
--[[
TheNexusAvenger

Displays an item in the inventory.
--]]

local CAMERA_FIELD_OF_VIEW = 20
local CAMERA_CFRAME_BACK_MULTIPLIER = 3.6
local ROTATE_SPEED_MULTIPLIER = 0.5



local RunService = game:GetService("RunService")

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

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

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



--[[
Creates an item icon.
--]]
function ItemIcon:__new()
    self:InitializeSuper()

    --Create the container.
    local ViewportFrame = Instance.new("ViewportFrame")
    ViewportFrame.BackgroundTransparency = 1
    ViewportFrame.Size = UDim2.new(1,0,1,0)
    self.ViewportFrame = ViewportFrame

    local Camera = Instance.new("Camera")
    Camera.FieldOfView = CAMERA_FIELD_OF_VIEW
    Camera.Parent = ViewportFrame
    self.Camera = Camera
    ViewportFrame.CurrentCamera = Camera
end

--[[
Sets the item to display.
--]]
function ItemIcon:SetItem(ModelName)
    --Return if the model name hasn't changed.
    if self.LastModelname == ModelName then return end
    self.LastModelname = ModelName

    --Destroy the existing model.
    if self.Model then
        self.Model:Destroy()
    end
    if self.RotateModelEvent then
        self.RotateModelEvent:Disconnect()
    end

    --Return if the model name is undefined (such as clearing).
    if not ModelName or not ItemData[ModelName] then return end

    --Create the model.
    local ModelData = ItemData[ModelName]
    local Model = ItemDataModule:FindFirstChild(ModelName)
    if Model then
        if ModelData.ItemType == "PlayerHat" then
            --Clone the hat's handle if it exists.
            local Accessory = Model:FindFirstChildWhichIsA("Accoutrement")
            if Accessory then
                local Handle = Accessory:FindFirstChild("Handle")
                if Handle then
                    self.Model = Handle:Clone()
                    self.Model.Parent = self.ViewportFrame
                end
            end
        elseif Model:FindFirstChild("R6") then
            --Create the body part for the R6 body part.
            local CharacterMesh = Model:FindFirstChild("R6"):FindFirstChildWhichIsA("CharacterMesh")
            if CharacterMesh then
                self.Model = Instance.new("Part")
                self.Model.Size = (ModelData.ItemType == "PlayerTorso" and Vector3.new(2,2,1) or Vector3.new(1,2,1))
                self.Model.Parent = self.ViewportFrame

                if ModelData.ItemType == "PlayerTorso" then
                    self.Model.BrickColor = BrickColor.new("Bright green")
                elseif ModelData.ItemType == "PlayerLeftArm" or  ModelData.ItemType == "PlayerRightArm" then
                    self.Model.BrickColor = BrickColor.new("Bright blue")
                else
                    self.Model.BrickColor = BrickColor.new("Bright yellow")
                end

                local Mesh = Instance.new("SpecialMesh")
                Mesh.MeshType = Enum.MeshType.FileMesh
                Mesh.MeshId = "rbxassetid://"..CharacterMesh.MeshId
                if CharacterMesh.OverlayTextureId ~= 0 then
                    Mesh.TextureId = "rbxassetid://"..CharacterMesh.OverlayTextureId
                elseif CharacterMesh.BaseTextureId ~= 0 then
                    Mesh.TextureId = "rbxassetid://"..CharacterMesh.BaseTextureId
                end
                Mesh.Parent = self.Model
            end
        end
    else
        if ModelData.MeshId then
            --Create the mesh.
            local Part = Instance.new("Part")
            Part.Size = ModelData.Size or Vector3.new(1,1,1)
            Part.Parent = self.ViewportFrame
            self.Model = Part

            local Mesh = Instance.new("SpecialMesh")
            Mesh.MeshType = Enum.MeshType.FileMesh
            Mesh.MeshId = "rbxassetid://"..tostring(ModelData.MeshId)
            Mesh.TextureId = "rbxassetid://"..tostring(ModelData.TextureId)
            Mesh.Parent = Part
        elseif ModelData.TextureId then
             --Create the mesh.
             local Part = Instance.new("Part")
             Part.Transparency = 1
             Part.Size = ModelData.Size or Vector3.new(1,1,1)
             Part.Parent = self.ViewportFrame
             self.Model = Part
 
             local Mesh = Instance.new("SpecialMesh")
             Mesh.MeshType = Enum.MeshType.Brick
             Mesh.Scale = Vector3.new(1,1,0)
             Mesh.Parent = Part

             local Front = Instance.new("Decal")
             Front.Texture = "rbxassetid://"..tostring(ModelData.TextureId)
             Front.Face = Enum.NormalId.Front
             Front.Parent = Part

             local Back = Instance.new("Decal")
             Back.Texture = "rbxassetid://"..tostring(ModelData.TextureId)
             Back.Face = Enum.NormalId.Back
             Back.Parent = Part
        end
    end

    --Update the camera.
    if self.Model then
        self.Camera.CFrame = CFrame.new(0,0,CAMERA_CFRAME_BACK_MULTIPLIER * math.max(self.Model.Size.X,self.Model.Size.Y,self.Model.Size.Z))
    end

    --Start rotating the model.
    if self.Model then
        self.RotateModelEvent = RunService.RenderStepped:Connect(function()
            self.Model.CFrame = CFrame.Angles(0,0,math.rad(-30)) * CFrame.Angles(0,(tick() * ROTATE_SPEED_MULTIPLIER) % (math.pi * 2),0)
        end)
    end
end

--[[
Sets the parent of the frame.
--]]
function ItemIcon:SetParent(Parent)
    self.ViewportFrame.Parent = Parent
    self.ViewportFrame.ZIndex = Parent.ZIndex
end

--[[
Destroys the frame.
--]]
function ItemIcon:Destroy()
    if self.Model then
        self.Model:Destroy()
    end
    if self.RotateModelEvent then
        self.RotateModelEvent:Disconnect()
    end
    self.ViewportFrame:Destroy()
end


return ItemIcon