Jump to content

Chester slows food spoilage (less than the fridge/freezer)


Recommended Posts

Right now I'm hoping for the following:Chester slows food spoilage (less than the fridge/freezer)

But i try modify chester.lua ,

inst:AddTag("lowcool")

or

inst:AddTag("frozen")

Can not work....

Can someone help me?

Thanks

Link to comment
Share on other sites

Welcome to the forums, @jaowcl!

You need to use both inst:AddTag("fridge") and inst:AddTag("lowcool"). edit: Not a solution. See comments below.

@Lumina, use Find in Files..., Ctrl-Shift-F in Sublime and Notepad++. ;) (Though Sublime is sometimes a little silly and you'll need to right-click the folder you're working on and select Find in Folder... .)

Edited by alainmcd
Link to comment
Share on other sites

Ah, sorry. There are only two mentions of the "lowcool" tag:

  1. In the perishable component, it checks whether the item is "frozen" (i.e. ice) and its owner is a "fridge" and neither a "lowcool" nor a "nocool" and sets the modifier to TUNING.PERISH_COLD_FROZEN_MULT (which is zero) - so ice doesn't spoil in a regular fridge.
  2. In the temperature component, it checks whether it's in a "fridge" that isn't "nocool" and sets the rate at which it cools down to (-TUNING.WARM_DEGREES_PER_SEC), or half that if the owner/container is a "lowcool".

Interestingly, there's no prefab with the "lowcool" tag, so it isn't applied in the game without mods. IIRC, some unused code related to the "frozen" and "lowcool" tags like this was added way back when RoG was in early access.

Link to comment
Share on other sites

Thank everyone for help

Try modify  "data\scripts\components\perishable.lua"

    if owner then
            if owner:HasTag("fridge") then
                if inst:HasTag("frozen") and not owner:HasTag("nocool") and not owner:HasTag("lowcool") then
                modifier = TUNING.PERISH_COLD_FROZEN_MULT
                elseif  inst.ChesterState = "SNOW" then
                modifier = TUNING.PERISH_COLD_FROZEN_MULT
                else
                modifier = TUNING.PERISH_FRIDGE_MULT
                end

Not work again... 

Link to comment
Share on other sites

So if i understand it well, it changes nothing for the spoilage of classic food, but only for ice and maybe for the thermal stone ? Or is it changing something for classic foods too ?

 

Anyway, thanks for the explanation :)

Link to comment
Share on other sites

Exactly, lowcools and nocools have no special effect on food, they act like regular fridges. Ice does spoil in both nocools and lowcools, though slower than on the ground or in regular containers, and Thermal Stones are cooled down at half rate in lowcools and not at all in nocools.

edit: @jaowcl, I just noticed that this means there's no easy solution for your question, lowcool does not affect spoilage. Sorry. :(

Edited by alainmcd
Link to comment
Share on other sites

4 hours ago, alainmcd said:

 

4 hours ago, alainmcd said:

Exactly, lowcools and nocools have no special effect on food, they act like regular fridges. Ice does spoil in both nocools and lowcools, though slower than on the ground or in regular containers, and Thermal Stones are cooled down at half rate in lowcools and not at all in nocools.

edit: @jaowcl, I just noticed that this means there's no easy solution for your question, lowcool does not affect spoilage. Sorry. :(

Thank you

chester.lua 

 

Try modify  "data\scripts\components\perishable.lua"

    elseif owner:HasTag("frozen") then
                modifier = TUNING.PERISH_COLD_FROZEN_MULT
    elseif inst:HasTag("frozen") then
                modifier = TUNING.PERISH_COLD_FROZEN_MULT
            end

Link to comment
Share on other sites

Hey, sorry, new users' comments are sometimes filtered to avoid spam and aren't displayed immediately, I hadn't seen your first answer yet. You could try something like this in perishable.lua, in the Update function:

Quote

        if owner then
            if owner:HasTag("fridge") then
                if inst:HasTag("frozen") and not owner:HasTag("nocool") and not owner:HasTag("lowcool") then
                    modifier = TUNING.PERISH_COLD_FROZEN_MULT
                else
                    modifier = (owner.prefab == "chester" and 1.5 or 1) * TUNING.PERISH_FRIDGE_MULT
                end
            elseif owner:HasTag("spoiler") then
                modifier = TUNING.PERISH_GROUND_MULT 
            elseif owner:HasTag("cage") and inst:HasTag("small_livestock") then
                modifier = TUNING.PERISH_CAGE_MULT
            end
        else
            modifier = TUNING.PERISH_GROUND_MULT 
        end

Text in bold is what I've changed. What this does is increase the modifier by 50% if the container is Chester, this only applies to Ice Chester. You don't need to add any tags.

Remember not to change your files directly, instead copy them to your mod folder to the same path relative to data (so copy perishable.lua to YOURMOD\scripts\components and edit this new file). Usually you'd want to not copy files over but rather use AddComponentPostInit or similar functions in your modmain, however there's no good way to do so when dealing with local functions and values.

Link to comment
Share on other sites

54 minutes ago, jaowcl said:

Thank you for help!

I try make a new mod folder 

Can you help me look right?

 

Alainmcd-Chester.zip

The file structure is right, but you have to copy the contents of the original perishable.lua and then change whatever you need. Also, in case you don't know: you need a modinfo.lua file in your mod's folder (in this case, Alainmcd-Chester). Your file should look something like this:

name = "My Chester mod"
description = "Write here what your mod does."

author = "jaowcl"

version = "1"

dst_compatible = true
all_clients_require_mod = false
client_only_mod = false

api_version_dst = 10

In this case, clients don't need to install the mod, so all_clients_require_mod and client_only_mod are set to false. Depending on how your mod works, you will need to change this.

--

35 minutes ago, jaowcl said:

@alainmcd

if need modify to Never Perish

                    modifier = (owner.prefab == "chester" and 0) * TUNING.PERISH_FRIDGE_MULT

right?

Minor correction:

Quote

modifier = (owner.prefab == "chester" and 0 or 1) * TUNING.PERISH_FRIDGE_MULT

Or else (owner.prefab == "chester" and 0) will result in nil if it's not in Chester and crash when trying to multiply nil. But yes, this will prevent all food stored in Ice Chester from spoiling.

Link to comment
Share on other sites

Mistakes happen, no need to apologise.

If you're replacing the file, you need the whole code. This is what the perishable.lua for your mod should look like:

Spoiler

local function onpercent(self)
    self.inst:RemoveTag("fresh")
    self.inst:RemoveTag("stale")
    self.inst:RemoveTag("spoiled")
    local percent = self:GetPercent()
    if percent >= .5 then
        self.inst:AddTag("fresh")
    elseif percent > .2 then
        self.inst:AddTag("stale")
    else
        self.inst:AddTag("spoiled")
    end
end

local Perishable = Class(function(self, inst)
    self.inst = inst
    self.perishfn = nil
    self.perishtime = nil

    self.frozenfiremult = false
    
    self.targettime = nil
    self.perishremainingtime = nil
    self.updatetask = nil
    self.dt = nil
    self.onperishreplacement = nil

    self.localPerishMultiplyer = 1
end,
nil,
{
    perishtime = onpercent,
    perishremainingtime = onpercent,
})

function Perishable:OnRemoveFromEntity()
    self.inst:RemoveTag("fresh")
    self.inst:RemoveTag("stale")
    self.inst:RemoveTag("spoiled")
end

function Perishable:OnRemoveEntity()
	self:StopPerishing()
end

local function Update(inst, dt)
    if inst.components.perishable then
		
		local modifier = 1
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
        if not owner and inst.components.occupier then
            owner = inst.components.occupier:GetOwner()
        end

		if owner then
			if owner:HasTag("fridge") then
				if inst:HasTag("frozen") and not owner:HasTag("nocool") and not owner:HasTag("lowcool") then
					modifier = TUNING.PERISH_COLD_FROZEN_MULT
				else
					modifier = (owner.prefab == "chester" and 0 or 1) * TUNING.PERISH_FRIDGE_MULT	-- food won't spoil in ice chester
				end
			elseif owner:HasTag("spoiler") then
				modifier = TUNING.PERISH_GROUND_MULT 
			elseif owner:HasTag("cage") and inst:HasTag("small_livestock") then
                modifier = TUNING.PERISH_CAGE_MULT
            end
		else
			modifier = TUNING.PERISH_GROUND_MULT 
		end

		if inst:GetIsWet() then
			modifier = modifier * TUNING.PERISH_WET_MULT
		end

		
		if TheWorld.state.temperature < 0 then
			if inst:HasTag("frozen") and not inst.components.perishable.frozenfiremult then
				modifier = TUNING.PERISH_COLD_FROZEN_MULT
			else
				modifier = modifier * TUNING.PERISH_WINTER_MULT
			end
		end

		if inst.components.perishable.frozenfiremult then
			modifier = modifier * TUNING.PERISH_FROZEN_FIRE_MULT
		end

		if TheWorld.state.temperature > TUNING.OVERHEAT_TEMP then
			modifier = modifier * TUNING.PERISH_SUMMER_MULT
		end

        modifier = modifier * inst.components.perishable.localPerishMultiplyer

		modifier = modifier * TUNING.PERISH_GLOBAL_MULT
		
		local old_val = inst.components.perishable.perishremainingtime
		local delta = dt or (10 + math.random()*FRAMES*8)
		if inst.components.perishable.perishremainingtime then 
			inst.components.perishable.perishremainingtime = inst.components.perishable.perishremainingtime - delta*modifier
	        if math.floor(old_val*100) ~= math.floor(inst.components.perishable.perishremainingtime*100) then
		        inst:PushEvent("perishchange", {percent = inst.components.perishable:GetPercent()})
		    end
		end

		-- Cool off hot foods over time (faster if in a fridge)
		if inst.components.edible and inst.components.edible.temperaturedelta and inst.components.edible.temperaturedelta > 0 then
			if owner and owner:HasTag("fridge") then
				if not owner:HasTag("nocool") then
					inst.components.edible.temperatureduration = inst.components.edible.temperatureduration - 1
				end
			elseif TheWorld.state.temperature < TUNING.OVERHEAT_TEMP - 5 then
				inst.components.edible.temperatureduration = inst.components.edible.temperatureduration - .25
			end
			if inst.components.edible.temperatureduration < 0 then inst.components.edible.temperatureduration = 0 end
		end
        
        --trigger the next callback
        if inst.components.perishable.perishremainingtime and inst.components.perishable.perishremainingtime <= 0 then
			inst.components.perishable:Perish()
        end
    end
end

function Perishable:IsFresh()
	return self.inst:HasTag("fresh")
end

function Perishable:IsStale()
	return self.inst:HasTag("stale")
end

function Perishable:IsSpoiled()
	return self.inst:HasTag("spoiled")
end

function Perishable:Dilute(number, timeleft)
	if self.inst.components.stackable then
        if self.perishremainingtime or self.perishtime then
            local perishtime = self.perishremainingtime or self.perishtime
            self.perishremainingtime = (self.inst.components.stackable.stacksize * perishtime + number * timeleft) / ( number + self.inst.components.stackable.stacksize )
        else
            self.perishremainingtime = timeleft
        end
		self.inst:PushEvent("perishchange", {percent = self:GetPercent()})
	end
end

function Perishable:SetPerishTime(time)
	self.perishtime = time
	self.perishremainingtime = time
    if self.updatetask ~= nil then
        self:StartPerishing()
    end
end

function Perishable:SetLocalMultiplier(newMult)
    self.localPerishMultiplyer = newMult
end

function Perishable:GetLocalMultiplier()
    return self.localPerishMultiplyer
end

function Perishable:SetNewMaxPerishTime(newtime)
    local percent = self:GetPercent()
    self.perishtime = newtime
    self:SetPercent(percent)
end

function Perishable:SetOnPerishFn(fn)
	self.perishfn = fn
end


function Perishable:GetPercent()
	if self.perishremainingtime and self.perishtime and self.perishtime > 0 then
		return math.min(1, self.perishremainingtime / self.perishtime)
	else
		return 0
	end
end

function Perishable:SetPercent(percent)
	if self.perishtime then 
		if percent < 0 then percent = 0 end
		if percent > 1 then percent = 1 end
		self.perishremainingtime = percent*self.perishtime
	    self.inst:PushEvent("perishchange", {percent = self.inst.components.perishable:GetPercent()})
	end

    if self.updatetask ~= nil then
        self:StartPerishing()
    end
end

function Perishable:ReducePercent(amount)
	local cur = self:GetPercent()
	self:SetPercent(cur - amount)
end

function Perishable:GetDebugString()
	if self.perishremainingtime and  self.perishremainingtime > 0 then
        return string.format("%s %2.2fs %s",
            self.updatetask and "Perishing" or "Paused",
            self.perishremainingtime,
            self.frozenfiremult and "frozenfiremult" or "")
	else
		return "perished"
	end
end

function Perishable:LongUpdate(dt)
    if self.updatetask ~= nil then
        Update(self.inst, dt or 0)
    end
end

function Perishable:StartPerishing()
    if self.updatetask ~= nil then
        self.updatetask:Cancel()
        self.updatetask = nil
    end

    local dt = 10 + math.random()*FRAMES*8
    self.updatetask = self.inst:DoPeriodicTask(dt, Update, math.random()*2, dt)
end

function Perishable:Perish()
    if self.updatetask ~= nil then
        self.updatetask:Cancel()
        self.updatetask = nil
    end

    if self.perishfn ~= nil then
        self.perishfn(self.inst)
    end

    if self.inst:IsValid() then
        self.inst:PushEvent("perished")
    end

    --NOTE: callbacks may have removed this inst!

    if self.inst:IsValid() and self.onperishreplacement ~= nil then
        local goop = SpawnPrefab(self.onperishreplacement)
        if goop ~= nil then
            if goop.components.stackable ~= nil and self.inst.components.stackable ~= nil then
                goop.components.stackable:SetStackSize(self.inst.components.stackable.stacksize)
            end
            local owner = self.inst.components.inventoryitem ~= nil and self.inst.components.inventoryitem.owner or nil
            local holder = owner ~= nil and (owner.components.inventory or owner.components.container) or nil
            if holder ~= nil then
                local slot = holder:GetItemSlot(self.inst)
                self.inst:Remove()
                holder:GiveItem(goop, slot)
            else
                local x, y, z = self.inst.Transform:GetWorldPosition()
                self.inst:Remove()
                goop.Transform:SetPosition(x, y, z)
            end
        end
    end
end

function Perishable:StopPerishing()
    if self.updatetask ~= nil then
        self.updatetask:Cancel()
        self.updatetask = nil
    end
end

function Perishable:OnSave()
    return
    {
        paused = self.updatetask == nil or nil,
        time = self.perishremainingtime,
    }
end

function Perishable:OnLoad(data)
    if data ~= nil and data.time ~= nil then
        self.perishremainingtime = data.time
        if not data.paused then
            self:StartPerishing()
        end
    end
end

return Perishable

 

Note: I haven't tested it, can't right now. Let me know if it's not working and I'll do some testing tomorrow.

Link to comment
Share on other sites

Have add .. 

But not work.

Quote

name = "Alainmcd-Chester"
description = "NeverPerishIce For Chester"
author = "Alainmcd"
version = "1"
priority = 10
dst_compatible = true
all_clients_require_mod = false
client_only_mod = false
forumthread = ""
api_version = 10
all_clients_require_mod = true

 

Edited by jaowcl
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...