require "prefabutil"

local assets=
{
	Asset("ANIM", "anim/flower_1.zip"),
	Asset("ANIM", "anim/flower_seed.zip"),
    Asset("IMAGE", "images/inventoryimages/flower_seed.tex"),
    Asset("ATLAS", "images/inventoryimages/flower_seed.xml"),
}
	
local prefabs = {
	"spoiled_food",
	"flower_1",
}

local function oneat(inst,eater)
	if eater.prefab == "pigman" or eater.prefab == "bunnyman" then eater.components.health:Kill() local p =  eater:GetPosition() SpawnPrefab("flower_seed").Transform:SetPosition(p.x,p.y,p.z) end
end
	
local function fn(Sim)
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	MakeInventoryPhysics(inst)
	if SaveGameIndex:IsModeShipwrecked() then
	MakeInventoryFloatable(inst, "idle", "idle")
	end
	inst.AnimState:SetBuild("flower_seed")
	inst.AnimState:SetBank("flower_seed")
	inst.AnimState:PlayAnimation("idle", false)
    
    inst:AddTag("preparedfood")
	--inst:AddTag("redtea")
	--
	inst:AddTag("zhaohuncailiao")
	
	inst:AddComponent("edible")
	inst.components.edible.healthvalue = 10
	inst.components.edible.sanityvalue = 10
	inst.components.edible.hungervalue = 15
	--inst.components.edible.temperaturedelta = -3
	
	inst.components.edible.foodtype = "GENERIC"
	inst.components.edible.foodstate = "PREPARED"
	inst.components.edible:SetOnEatenFn(oneat)
	
	inst:AddComponent("inspectable")
	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/flower_seed.xml"
	
	inst:AddComponent("stackable")
	inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM

	inst:AddComponent("perishable")
	inst.components.perishable:SetPerishTime(TUNING.PERISH_PRESERVED)
	inst.components.perishable:StartPerishing()
	inst.components.perishable.onperishreplacement = "spoiled_food"
	
    local function OnDeploy (inst, pt)
	SpawnPrefab("flower_1").Transform:SetPosition(pt.x, pt.y, pt.z)
		inst.components.stackable:Get():Remove()
	end
    inst:AddComponent("deployable")
    inst.components.deployable.ondeploy = OnDeploy

	
	MakeSmallBurnable(inst)
	MakeSmallPropagator(inst)
	---------------------        
	inst:AddComponent("bait")
    
	------------------------------------------------
	inst:AddComponent("tradable")
    
	------------------------------------------------  
    
	return inst
end
	
return Prefab( "common/inventory/flower_seed", fn, assets, prefabs),
MakePlacer( "common/flower_seed_placer", "flower_1", "flower_1", "sway" ) 