require "prefabutil"

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

local function oneat(inst,eater)
	if eater.prefab == "pigman" or eater.prefab == "bunnyman" then eater.components.health:Kill() local p =  eater:GetPosition() SpawnPrefab("teatree").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("linglibuchong")
	inst.AnimState:SetBank("linglibuchong")
	inst.AnimState:PlayAnimation("idle", false)
    
    inst:AddTag("preparedfood")
	--inst:AddTag("redtea")
	--
	inst:AddTag("zhaohuncailiao")
	
	inst:AddComponent("edible")
	inst.components.edible.healthvalue = 1
	inst.components.edible.sanityvalue = 1
	inst.components.edible.hungervalue = 1
	--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.imagename = "linglibuchong"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/linglibuchong.xml"
	
	inst:AddComponent("stackable")
	inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM

	inst:AddComponent("perishable")
	inst.components.perishable:SetPerishTime(TUNING.PERISH_PRESERVED*50)
	inst.components.perishable:StartPerishing()
	inst.components.perishable.onperishreplacement = "spoiled_food"
	
    local function OnDeploy (inst, pt)
	SpawnPrefab("teatree").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/linglibuchong", fn, assets, prefabs)
--MakePlacer( "common/linglibuchong_placer", "teatree", "teatree", "sway" ) 