local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local STRINGS = GLOBAL.STRINGS
local Recipe = GLOBAL.Recipe
TECH = GLOBAL.TECH
SpawnPrefab = GLOBAL.SpawnPrefab
Vector3	= GLOBAL.Vector3
TheSim = GLOBAL.TheSim

TUNING.PERISH_FIREBOX = 0.01

--TUNING.PERISH_SUPERFAST = 10*1--食物糜烂时间（测试用）
--TUNING.PERISH_FAST = 15*1
--TUNING.PERISH_MED = 15*1
--TUNING.PERISH_SLOW = 15*1
--TUNING.PERISH_PRESERVED = 20*1
--TUNING.PERISH_SUPERSLOW = 20

---------------------------------------------------------------------------------------------
STRINGS.NAMES.FIREBOX = "Firebox"
STRINGS.RECIPE_DESC.FIREBOX = "Heat food!"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.FIREBOX = "I feel like burning!"

PrefabFiles = 
{
	"firebox", 
}

function load()
	local firebox = GLOBAL.Recipe("firebox", {Ingredient("goldnugget", 10), Ingredient("gears", 2), Ingredient("redgem", 2)}, RECIPETABS.MAGIC,  TECH.MAGIC_THREE, "icebox_placer", 1.5)
	firebox.atlas = "images/inventoryimages/firebox.xml"
end
AddGamePostInit(load)

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

local function redgemfuelPrefabPostInit(inst) 
inst:AddComponent("fuel")
    inst.components.fuel.fueltype = "GEMFUEL"
    inst.components.fuel.fuelvalue =  480*4
end
AddPrefabPostInit("redgem", redgemfuelPrefabPostInit)
    
local function bluegemfuelPrefabPostInit(inst) 
inst:AddComponent("fuel")
    inst.components.fuel.fueltype = "GEMFUEL"
    inst.components.fuel.fuelvalue =  480*1
end
AddPrefabPostInit("bluegem", bluegemfuelPrefabPostInit)
local function purplegemfuelPrefabPostInit(inst) 
inst:AddComponent("fuel")
    inst.components.fuel.fueltype = "GEMFUEL"
    inst.components.fuel.fuelvalue = 480*5
end
AddPrefabPostInit("purplegem", purplegemfuelPrefabPostInit)
    
local function yellowgemfuelPrefabPostInit(inst) 
inst:AddComponent("fuel")
    inst.components.fuel.fueltype = "GEMFUEL"
    inst.components.fuel.fuelvalue = 480*3
end
AddPrefabPostInit("yellowgem", yellowgemfuelPrefabPostInit)
local function orangegemfuelPrefabPostInit(inst) 
inst:AddComponent("fuel")
    inst.components.fuel.fueltype = "GEMFUEL"
    inst.components.fuel.fuelvalue = 480*3
end
AddPrefabPostInit("orangegem", orangegemfuelPrefabPostInit)
    
local function greengemfuelPrefabPostInit(inst) 
inst:AddComponent("fuel")
    inst.components.fuel.fueltype = "GEMFUEL"
    inst.components.fuel.fuelvalue = 480*3.5
end
AddPrefabPostInit("greengem", greengemfuelPrefabPostInit)

function makestackable1PrefabPostInit(inst)

    inst:AddComponent("stackable")
	inst.components.stackable.maxsize = TUNING.STACK_SIZE_LARGEITEM
end

AddPrefabPostInit("rottenegg", makestackable1PrefabPostInit)--臭鸡蛋

---------------------------------------------------------------------------------------------
local function infirebox1(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "cookedmeat"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end

local function meatPrefabPostInit(inst)
                                inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox1(inst) end)
end

---------------------------------------------------------------------------------------------
local function infirebox2(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "meat_dried"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end

local function cookedmeatPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox2(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox3(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "cookedmonstermeat"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function monstermeatPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox3(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox4(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "monstermeat_dried"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function cookedmonstermeatPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox4(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox5(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "cookedsmallmeat"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function smallmeatPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox5(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox6(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "smallmeat_dried"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function cookedsmallmeatPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox6(inst) end)
end

---------------------------------------------------------------------------------------------
local function infirebox7(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "drumstick_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function drumstickPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox7(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox8(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "batwing_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function batwingPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox8(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox9(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "plantmeat_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function plantmeatPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox9(inst) end)
end

---------------------------------------------------------------------------------------------
local function infirebox12(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "froglegs_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function froglegsPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox12(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox13(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "fish_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function fishPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox13(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox14(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "bird_egg_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function bird_eggPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox14(inst) end)
end

--------------------------------------------------------------------------------------------
local function infirebox15(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                                      if perishPercent * TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST < 1 then
                                             if not inst:HasTag("burned") then
                                       local perishreplacement = SpawnPrefab("rottenegg")
                                       local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0,4.5,0)                
                                       perishreplacement.Transform:SetPosition(pt:Get())
 				perishreplacement.components.stackable:SetStackSize(inst.components.stackable.stacksize)
                                       local perishPercent = 0
                                       inst:AddTag("burned")
                                             end
                                       end
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
	                        inst.components.perishable.onperishreplacement = "rottenegg"
                                inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function bird_egg_cookedPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox15(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox16(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "fish_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function fishPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox16(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox17(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "trunk_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function trunkPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox17(inst) end)
end
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------红宝石
local function infirebox10(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then
                                       if perishPercent * TUNING.PERISH_FIREBOX * TUNING.PERISH_PRESERVED < 1 then
                                             if not inst:HasTag("burned") then
                                       local perishreplacement = SpawnPrefab("redgem")
                                       local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0,4.5,0)                
                                       perishreplacement.Transform:SetPosition(pt:Get())
		              if inst.components.stackable then 
                              local thestacksize = inst.components.stackable.stacksize 
                              local themaxsize = inst.components.stackable.maxsize
	                      if thestacksize == themaxsize then
                                     thestacksize = themaxsize
                              elseif thestacksize >= (0.5 * themaxsize) then 
                                     thestacksize = 5
                              elseif thestacksize >= (0.3 * themaxsize) then
                                      thestacksize = 1
                              else 
                                      thestacksize = 0
                              end 
 				perishreplacement.components.stackable:SetStackSize(thestacksize)
                              end
                                       local perishPercent = 0
                                       inst:AddTag("burned")
                                             end
                                       end
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_PRESERVED)
                                inst.components.perishable:SetPercent(perishPercent)
	                        inst.components.perishable.onperishreplacement = "redgem"
                                inst:AddTag("infirebox")
			        end

                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_PRESERVED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function burntoredgemPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_PRESERVED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox10(inst) end)
end
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------PRESERVED
local function infirebox11(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then
                                       if perishPercent * TUNING.PERISH_FIREBOX * TUNING.PERISH_PRESERVED < 1 then
                                             if not inst:HasTag("burned") then
                                       local perishreplacement = SpawnPrefab("ash")
                                       local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0,4.5,0)                
                                       perishreplacement.Transform:SetPosition(pt:Get())
 				perishreplacement.components.stackable:SetStackSize(inst.components.stackable.stacksize)
                                       local perishPercent = 0
                                       inst:AddTag("burned")
                                             end
                                       end
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_PRESERVED)
                                inst.components.perishable:SetPercent(perishPercent)
	                        inst.components.perishable.onperishreplacement = "ash"
                                inst:AddTag("infirebox")
			        end

                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_PRESERVED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function burntoashPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_PRESERVED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox11(inst) end)
end

---------------------------------------------------------------------------------------------FAST
local function infirebox30(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then
                                       if perishPercent * TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST < 1 then
                                             if not inst:HasTag("burned") then
                                       local perishreplacement = SpawnPrefab("ash")
                                       local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0,4.5,0)                
                                       perishreplacement.Transform:SetPosition(pt:Get())
 				perishreplacement.components.stackable:SetStackSize(inst.components.stackable.stacksize)
                                       local perishPercent = 0
                                       inst:AddTag("burned")
                                             end
                                       end
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
	                        inst.components.perishable.onperishreplacement = "ash"
                                inst:AddTag("infirebox")
			        end

                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function burntoash2PrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox30(inst) end)
end

---------------------------------------------------------------------------------------------SUPERFAST
local function infirebox31(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then
                                       if perishPercent * TUNING.PERISH_FIREBOX * TUNING.PERISH_SUPERFAST < 1 then
                                             if not inst:HasTag("burned") then
                                       local perishreplacement = SpawnPrefab("ash")
                                       local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0,4.5,0)                
                                       perishreplacement.Transform:SetPosition(pt:Get())
 				perishreplacement.components.stackable:SetStackSize(inst.components.stackable.stacksize)
                                       local perishPercent = 0
                                       inst:AddTag("burned")
                                             end
                                       end
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_SUPERFAST)
                                inst.components.perishable:SetPercent(perishPercent)
	                        inst.components.perishable.onperishreplacement = "ash"
                                inst:AddTag("infirebox")
			        end

                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERFAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function burntoash3PrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERFAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox31(inst) end)
end

---------------------------------------------------------------------------------------------MED
local function infirebox32(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then
                                       if perishPercent * TUNING.PERISH_FIREBOX * TUNING.PERISH_MED < 1 then
                                             if not inst:HasTag("burned") then
                                       local perishreplacement = SpawnPrefab("ash")
                                       local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0,4.5,0)                
                                       perishreplacement.Transform:SetPosition(pt:Get())
 				perishreplacement.components.stackable:SetStackSize(inst.components.stackable.stacksize)
                                       local perishPercent = 0
                                       inst:AddTag("burned")
                                             end
                                       end
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
	                        inst.components.perishable.onperishreplacement = "ash"
                                inst:AddTag("infirebox")
			        end

                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function burntoash4PrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox32(inst) end)
end

---------------------------------------------------------------------------------------------SLOW
local function infirebox33(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then
                                       if perishPercent * TUNING.PERISH_FIREBOX * TUNING.PERISH_SLOW < 1 then
                                             if not inst:HasTag("burned") then
                                       local perishreplacement = SpawnPrefab("ash")
                                       local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0,4.5,0)                
                                       perishreplacement.Transform:SetPosition(pt:Get())
 				perishreplacement.components.stackable:SetStackSize(inst.components.stackable.stacksize)
                                       local perishPercent = 0
                                       inst:AddTag("burned")
                                             end
                                       end
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_SLOW)
                                inst.components.perishable:SetPercent(perishPercent)
	                        inst.components.perishable.onperishreplacement = "ash"
                                inst:AddTag("infirebox")
			        end

                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_SLOW)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function burntoash5PrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_SLOW)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox33(inst) end)
end
---------------------------------------------------------------------------------------------
AddPrefabPostInit("meat", meatPrefabPostInit)
AddPrefabPostInit("cookedmeat", cookedmeatPrefabPostInit)
AddPrefabPostInit("meat_dried", burntoredgemPrefabPostInit)

AddPrefabPostInit("monstermeat", monstermeatPrefabPostInit)
AddPrefabPostInit("cookedmonstermeat", cookedmonstermeatPrefabPostInit)
AddPrefabPostInit("monstermeat_dried", burntoashPrefabPostInit)

AddPrefabPostInit("smallmeat", smallmeatPrefabPostInit)
AddPrefabPostInit("cookedsmallmeat", cookedsmallmeatPrefabPostInit)
AddPrefabPostInit("smallmeat_dried", burntoashPrefabPostInit)

AddPrefabPostInit("drumstick", drumstickPrefabPostInit)
AddPrefabPostInit("drumstick_cooked", cookedmeatPrefabPostInit)

AddPrefabPostInit("batwing", batwingPrefabPostInit)
AddPrefabPostInit("batwing_cooked", cookedmonstermeatPrefabPostInit)
AddPrefabPostInit("plantmeat", plantmeatPrefabPostInit)
AddPrefabPostInit("plantmeat_cooked", cookedmonstermeatPrefabPostInit)

AddPrefabPostInit("froglegs", froglegsPrefabPostInit)
AddPrefabPostInit("froglegs_cooked", cookedsmallmeatPrefabPostInit)
AddPrefabPostInit("fish", fishPrefabPostInit)
AddPrefabPostInit("fish_cooked", cookedsmallmeatPostInit)

AddPrefabPostInit("bird_egg", bird_eggPrefabPostInit)
AddPrefabPostInit("bird_egg_cooked", bird_egg_cookedPrefabPostInit)
AddPrefabPostInit("hambat", meatPrefabPostInit)

AddPrefabPostInit("trunk_summer", trunkPrefabPostInit)
AddPrefabPostInit("trunk_winter", trunkPrefabPostInit)
AddPrefabPostInit("trunk_cooked", cookedmeatPrefabPostInit)
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

local function infirebox20(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_SUPERSLOW)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "seeds_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function seedsPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox20(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox21(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "berries_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function berriesPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox21(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox22(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "cave_banana_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function cave_bananaPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox22(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox23(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "carrot_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function carrotPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox23(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox24(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "corn_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function cornPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox24(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox25(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "pumpkin_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function pumpkinPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox25(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox26(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "eggplant_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function eggplantPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox26(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox27(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_MED)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "durian_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function durianPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox27(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox28(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "pomegranate_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function pomegranatePrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox28(inst) end)
end
---------------------------------------------------------------------------------------------
local function infirebox29(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "dragonfruit_cooked"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function dragonfruitPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox29(inst) end)
end

---------------------------------------------------------------------------------------------
local function infirebox40(inst)

                                local perishPercent = inst.components.perishable:GetPercent()
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or nil
		if owner and owner:HasTag("firebox") then  
                     if inst:HasTag("outoffirebox") then inst:RemoveTag("outoffirebox") end
                                if not inst:HasTag("infirebox") then
		                inst.components.perishable:SetPerishTime(TUNING.PERISH_FIREBOX * TUNING.PERISH_FAST)
                                inst.components.perishable:SetPercent(perishPercent)
		                inst.components.perishable.onperishreplacement = "petals"
                             inst:AddTag("infirebox")
			        end
                else 
                           if inst:HasTag("infirebox") then inst:RemoveTag("infirebox") end
                      if not inst:HasTag("outoffirebox") then                    
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
              inst.components.perishable:SetPercent(perishPercent)
	      inst.components.perishable.onperishreplacement = "spoiled_food"
                             inst:AddTag("outoffirebox")
                      end  
               end
end
local function flowerhatPrefabPostInit(inst)
inst:AddComponent("perishable")
	      inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)
	      inst.components.perishable:StartPerishing()
	      inst.components.perishable.onperishreplacement = "spoiled_food"
    inst.task = inst:DoPeriodicTask(0.5, function() infirebox40(inst) end)
end

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

AddPrefabPostInit("honey", burntoashPrefabPostInit)
AddPrefabPostInit("seeds", seedsPrefabPostInit)
AddPrefabPostInit("seeds_cooked", burntoash4PrefabPostInit)

AddPrefabPostInit("berries", berriesPrefabPostInit)
AddPrefabPostInit("cave_banana", cave_bananaPrefabPostInit)
AddPrefabPostInit("carrot", carrotPrefabPostInit)
AddPrefabPostInit("corn", cornPrefabPostInit)
AddPrefabPostInit("pumpkin", pumpkinPrefabPostInit)
AddPrefabPostInit("eggplant", eggplantPrefabPostInit)--茄子
AddPrefabPostInit("durian", durianPrefabPostInit)--榴莲
AddPrefabPostInit("pomegranate", pomegranatePrefabPostInit)--石榴
AddPrefabPostInit("dragonfruit", dragonfruitPrefabPostInit)

AddPrefabPostInit("berries_cooked", burntoash3PrefabPostInit)
AddPrefabPostInit("cave_banana_cooked", burntoash2PrefabPostInit)
AddPrefabPostInit("carrot_cooked", burntoash2PrefabPostInit)
AddPrefabPostInit("corn_cooked", burntoash5PrefabPostInit)
AddPrefabPostInit("pumpkin_cooked", burntoash2PrefabPostInit)
AddPrefabPostInit("eggplant_cooked", burntoash2PrefabPostInit)
AddPrefabPostInit("durian_cooked", burntoash2PrefabPostInit)
AddPrefabPostInit("pomegranate_cooked", burntoash3PrefabPostInit)
AddPrefabPostInit("dragonfruit_cooked", burntoredgemPrefabPostInit)


AddPrefabPostInit("cave_banana_seeds", burntoash4PrefabPostInit)
AddPrefabPostInit("carrot_seeds", burntoash4PrefabPostInit)
AddPrefabPostInit("corn_seeds", burntoash4PrefabPostInit)
AddPrefabPostInit("pumpkin_seeds", burntoash4PrefabPostInit)
AddPrefabPostInit("eggplant_seeds", burntoash4PrefabPostInit)
AddPrefabPostInit("durian_seeds", burntoash4PrefabPostInit)
AddPrefabPostInit("pomegranate_seeds", burntoash4PrefabPostInit)
AddPrefabPostInit("dragonfruit_seeds", burntoash4PrefabPostInit)
AddPrefabPostInit("berries_seeds", burntoash4PrefabPostInit)

AddPrefabPostInit("flowerhat", flowerhatPrefabPostInit)
AddPrefabPostInit("butterflywings", burntoash2PrefabPostInit)
AddPrefabPostInit("butter", burntoash5PrefabPostInit)
AddPrefabPostInit("petals", burntoash2PrefabPostInit)
AddPrefabPostInit("petals_evil", burntoash2PrefabPostInit)
AddPrefabPostInit("lightbulb", burntoash2PrefabPostInit)

--burntoash-PRESERVED
--burntoash2-FAST
--burntoash3-SUPERFAST
--burntoash4-MED
--burntoash5-SLOW