print('beaverness replica is actually being loaded! yay!!!') -- this isn't happening. :(

local Beaverness = Class(function(self, inst)
    self.inst = inst

    self._isbeaver = net_bool(inst.GUID, "beaverness._isbeaver")
    self.currenthealth = net_byte(inst.GUID, "beaverness.currentbeaverness", "beavernessdirty")

    if TheWorld.ismastersim then
        self.classified = inst.player_classified
    elseif self.classified == nil and inst.player_classified ~= nil then
        self:AttachClassified(inst.player_classified)
    end
end)

--------------------------------------------------------------------------

function Beaverness:OnRemoveFromEntity()
    if self.classified ~= nil then
        if TheWorld.ismastersim then
            self.classified = nil
        else
            self.inst:RemoveEventCallback("onremove", self.ondetachclassified, self.classified)
            self:DetachClassified()
        end
    end
end

Beaverness.OnRemoveEntity = Beaverness.OnRemoveFromEntity

function Beaverness:AttachClassified(classified)
    self.classified = classified
    self.ondetachclassified = function() self:DetachClassified() end
    self.inst:ListenForEvent("onremove", self.ondetachclassified, classified)
end

function Beaverness:DetachClassified()
    self.classified = nil
    self.ondetachclassified = nil
end

--------------------------------------------------------------------------

function Beaverness:SetCurrent(current)
    if self.classified ~= nil and self.classified.replica.beaverness then
        self.classified:SetValue("currentbeaverness", current)
    end
end

function Beaverness:SetMax(max)
    if self.classified ~= nil then
        self.classified:SetValue("maxbeaverness", max)
    end
end

function Beaverness:Max()
    if self.inst.components.beaverness ~= nil then
        return self.inst.components.beaverness.max
    elseif self.classified ~= nil then
        return self.classified.maxbeaverness:value()
    else
        return 100
    end
end

function Beaverness:GetPercent()
    if self.inst.components.beaverness ~= nil then
        return self.inst.components.beaverness:GetPercent()
    elseif self.classified ~= nil then
        return self.classified.currentbeaverness:value() / self.classified.maxbeaverness:value()
    else
        return 1
    end
end

return Beaverness