local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
local resolvefilepath = GLOBAL.resolvefilepath
local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
Recipe = GLOBAL.Recipe
TECH = GLOBAL.TECH
local ACTIONS = GLOBAL.ACTIONS
--local ThePlayer = GLOBAL.ThePlayer
local GetPlayer = GLOBAL.GetPlayer
local GetWorld = GLOBAL.GetWorld
local IsServer = true --GLOBAL.TheNet:GetIsServer()
local containers = require("containers_mod")

PrefabFiles = {
	"fhl",
	"fhl_zzj",
	"fhl_zzj1",
	"fhl_zzj2",
	"fhl_zzj3",
	"fhl_zzj4",
	"fhl_zzj5",
	"fhl_hsf",
	"fhl_bz",
	"fhl_cake",
	"fhl_x",
	"fhl_cy",
	"personal_licking",
	"personal_licking_eyebone",
	"ancient_soul",
	"ancient_gem",
	"fhl_tree",
	--"krampus_sack",
	"fhl_bb",
}

local LAN_ = GetModConfigData('LANGUAGE')

GLOBAL.TUNING.FHL = {}
if LAN_ then
require 'strings_fhl_c'
-- 人物说话
STRINGS.CHARACTERS.FHL = require "speech_fhl" --谁来汉化？
else -- english
require 'strings_fhl_e'
-- 人物说话
STRINGS.CHARACTERS.FHL = require "speech_fhl"
end

Assets = {
    --存档界面人物头像
    Asset( "IMAGE", "images/saveslot_portraits/fhl.tex" ),
    Asset( "ATLAS", "images/saveslot_portraits/fhl.xml" ),

    --选择人物界面的人物头像
    Asset( "IMAGE", "images/selectscreen_portraits/fhl.tex" ),
    Asset( "ATLAS", "images/selectscreen_portraits/fhl.xml" ),
    --人物大图
    Asset( "IMAGE", "bigportraits/fhl.tex" ),
    Asset( "ATLAS", "bigportraits/fhl.xml" ),
    --地图上的人物图标
	Asset( "IMAGE", "images/map_icons/fhl.tex" ),
	Asset( "ATLAS", "images/map_icons/fhl.xml" ),
    --人物头像
	Asset( "IMAGE", "images/avatars/avatar_fhl.tex" ),
    Asset( "ATLAS", "images/avatars/avatar_fhl.xml" ),
    --人物死后图像
	Asset( "IMAGE", "images/avatars/avatar_ghost_fhl.tex" ),
    Asset( "ATLAS", "images/avatars/avatar_ghost_fhl.xml" ),
	--剑小图标
	Asset( "ATLAS", "images/inventoryimages/fhl_zzj.xml"),
	Asset( "IMAGE", "images/inventoryimages/fhl_zzj.tex" ),
	
	Asset( "ATLAS", "images/inventoryimages/fhl_zzj1.xml"),
	Asset( "IMAGE", "images/inventoryimages/fhl_zzj1.tex" ),
	
	Asset( "ATLAS", "images/inventoryimages/fhl_zzj2.xml"),
	Asset( "IMAGE", "images/inventoryimages/fhl_zzj2.tex" ),
	
	Asset( "ATLAS", "images/inventoryimages/fhl_zzj3.xml"),
	Asset( "IMAGE", "images/inventoryimages/fhl_zzj3.tex" ),
	
	Asset( "ATLAS", "images/inventoryimages/fhl_zzj4.xml"),
	Asset( "IMAGE", "images/inventoryimages/fhl_zzj4.tex" ),
	
	Asset( "ATLAS", "images/inventoryimages/fhl_zzj5.xml"),
	Asset( "IMAGE", "images/inventoryimages/fhl_zzj5.tex" ),

	Asset( "ATLAS", "images/inventoryimages/fhltab.xml"),
	Asset( "IMAGE", "images/inventoryimages/fhltab.tex" ),
	
	Asset( "ATLAS", "images/inventoryimages/fhl_hsf.xml"),
	
	Asset("ANIM", "anim/sweet_n_sour.zip"),
	Asset( "IMAGE", "images/inventoryimages/fhl_bz.tex" ),
	Asset( "ATLAS", "images/inventoryimages/fhl_bz.xml" ),
	
	Asset("ANIM", "anim/cake.zip"),
	Asset( "IMAGE", "images/inventoryimages/fhl_cake.tex" ),
	Asset( "ATLAS", "images/inventoryimages/fhl_cake.xml" ),
	
	Asset("ANIM", "anim/dy_x.zip"),
	Asset( "IMAGE", "images/inventoryimages/fhl_x.tex" ),
	Asset( "ATLAS", "images/inventoryimages/fhl_x.xml" ),
	
	Asset("ANIM", "anim/fhl_cy.zip"),
	Asset( "IMAGE", "images/inventoryimages/fhl_cy.tex" ),
	Asset( "ATLAS", "images/inventoryimages/fhl_cy.xml" ),
	
	Asset("ANIM", "anim/ancient_soul.zip"),
	Asset("ATLAS", "images/inventoryimages/ancient_soul.xml"),
    Asset("IMAGE", "images/inventoryimages/ancient_soul.tex"),
	
	Asset("ANIM", "anim/ancient_gem.zip"),
	Asset("ATLAS", "images/inventoryimages/ancient_gem.xml"),
    Asset("IMAGE", "images/inventoryimages/ancient_gem.tex"),
	
	Asset("ANIM", "anim/fhl_tree.zip"),
	Asset("ATLAS", "images/inventoryimages/fhl_tree.xml"),
    Asset("IMAGE", "images/inventoryimages/fhl_tree.tex"),
	
	Asset("ATLAS", "images/inventoryimages/fhl_bb.xml"),
	Asset("IMAGE", "images/inventoryimages/fhl_bb.tex"),

}

--function Addtradableprefab(inst)
	--if not inst.components.tradable then
		--inst:AddComponent("tradable")
--end end

------------------box


local oldwidgetsetup = containers.widgetsetup
containers.widgetsetup = function(container, prefab)
if not prefab and container.inst.prefab == "fhl_bb" then
prefab = "krampus_sack" end
oldwidgetsetup(container, prefab)
end

---------------
--small icebox1
local params = {}
local OVERRIDE_WIDGETSETUP = false
local containers_widgetsetup_base = containers.widgetsetup
function containers.widgetsetup(container, prefab)
    local t = params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
        if OVERRIDE_WIDGETSETUP then
            container.type = "frostsmall"
        end
    else
        containers_widgetsetup_base(container, prefab)
    end
end
local function frostsmall()
    local container =
    {
        widget =
        {
            slotpos = {},
            animbank = "ui_backpack_2x4",
            animbuild = "ui_chest_frosthammer",
            pos = GLOBAL.Vector3(-5, 100, 0),
            side_align_tip = 160,
        },
		 issidewidget = true,
        type = "chest",
    }
    
	for y = 0, 1 do
		table.insert(container.widget.slotpos, GLOBAL.Vector3(-126, -y*75 + 114 ,-126 +75, -y*75 + 114 ))

end
    return container
end
params.frostsmall = frostsmall()
for k, v in pairs(params) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
local containers_widgetsetup_custom = containers.widgetsetup
local MAXITEMSLOTS = containers.MAXITEMSLOTS
AddPrefabPostInit("world_network", function(inst)
    if containers.widgetsetup ~= containers_widgetsetup_custom then
        OVERRIDE_WIDGETSETUP = true
        local containers_widgetsetup_base2 = containers.widgetsetup
        function containers.widgetsetup(container, prefab)
            containers_widgetsetup_base2(container, prefab)
            if container.type == "frostsmall" then
                container.type = "chest"
            end end end
    if containers.MAXITEMSLOTS < MAXITEMSLOTS then
        containers.MAXITEMSLOTS = MAXITEMSLOTS
    end
end)

function params.frostsmall.itemtestfn(container, item, slot)
    return not item:HasTag("heatrock") 

end
--------------------------------------------------
--icebox1
local params = {}
local OVERRIDE_WIDGETSETUP = false
local containers_widgetsetup_base = containers.widgetsetup
function containers.widgetsetup(container, prefab)
    local t = params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
        if OVERRIDE_WIDGETSETUP then
            container.type = "frostbox"
        end
    else
        containers_widgetsetup_base(container, prefab)
    end
end
local function frostbox()
    local container =
    {
        widget =
        {
            slotpos = {},
            animbank = "ui_backpack_2x4",
            animbuild = "ui_chest_frosthammer2",
            pos = GLOBAL.Vector3(-5, -70, 0),
            side_align_tip = 160,
        },
		 issidewidget = true,
			type = "pack",
    }
    	for y = 0, 4 do
	table.insert(container.widget.slotpos, GLOBAL.Vector3(-162, -y*58 + 124 ,0))
	table.insert(container.widget.slotpos, GLOBAL.Vector3(-162 +75, -y*58 + 124 ,0))

end
    return container
end
params.frostbox = frostbox()
for k, v in pairs(params) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
local containers_widgetsetup_custom = containers.widgetsetup
local MAXITEMSLOTS = containers.MAXITEMSLOTS
AddPrefabPostInit("world_network", function(inst)
    if containers.widgetsetup ~= containers_widgetsetup_custom then
        OVERRIDE_WIDGETSETUP = true
        local containers_widgetsetup_base2 = containers.widgetsetup
        function containers.widgetsetup(container, prefab)
            containers_widgetsetup_base2(container, prefab)
            if container.type == "frostbox" then
                container.type = "pack"
            end end end
    if containers.MAXITEMSLOTS < MAXITEMSLOTS then
        containers.MAXITEMSLOTS = MAXITEMSLOTS
    end
end)

function params.frostbox.itemtestfn(container, item, slot)
    return not item:HasTag("heatrock") 

end
--------------------------------------------------

--box1
local params = {}
local OVERRIDE_WIDGETSETUP = false
local containers_widgetsetup_base = containers.widgetsetup
function containers.widgetsetup(container, prefab)
    local t = params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
        if OVERRIDE_WIDGETSETUP then
            container.type = "chest_yamche0"
        end
    else
        containers_widgetsetup_base(container, prefab)
    end
end
local function chest_yamche0()
    local container =
    {
        widget =
        {
            slotpos = {},
            animbank = "ui_chest_3x2",
            animbuild = "ui_chest_yamche0",
            pos = GLOBAL.Vector3(0, 200, 0),
            side_align_tip = 160,
        },
        type = "chest",
    }
    for y = 1, 0, -1 do
        table.insert(container.widget.slotpos, GLOBAL.Vector3(74*y-74*2+70, 0))
 
end
    return container
end
params.chest_yamche0 = chest_yamche0()
for k, v in pairs(params) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
local containers_widgetsetup_custom = containers.widgetsetup
local MAXITEMSLOTS = containers.MAXITEMSLOTS
AddPrefabPostInit("world_network", function(inst)
    if containers.widgetsetup ~= containers_widgetsetup_custom then
        OVERRIDE_WIDGETSETUP = true
        local containers_widgetsetup_base2 = containers.widgetsetup
        function containers.widgetsetup(container, prefab)
            containers_widgetsetup_base2(container, prefab)
            if container.type == "chest_yamche0" then
                container.type = "chest"
            end end end
    if containers.MAXITEMSLOTS < MAXITEMSLOTS then
        containers.MAXITEMSLOTS = MAXITEMSLOTS
    end
end)
---------------------------------------------------------------
--box2
local params = {}
local OVERRIDE_WIDGETSETUP = false
local containers_widgetsetup_base = containers.widgetsetup
function containers.widgetsetup(container, prefab)
    local t = params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
        if OVERRIDE_WIDGETSETUP then
            container.type = "chest_yamche1"
        end
    else
        containers_widgetsetup_base(container, prefab)
    end
end
local function chest_yamche1()
    local container =
    {
        widget =
        {
            slotpos = {},
            animbank = "ui_chest_3x3",
            animbuild = "ui_chest_yamche1",
            pos = GLOBAL.Vector3(0, 200, 0),
            side_align_tip = 160,
        },
        type = "chest",
    }
 for y = 1, 0, -1 do
    for x = 0, 1 do
        table.insert(container.widget.slotpos, GLOBAL.Vector3(80*x-80*2+78, 80*y-80*2+80,0))
    end
end
    return container
end
params.chest_yamche1 = chest_yamche1()
for k, v in pairs(params) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
local containers_widgetsetup_custom = containers.widgetsetup
local MAXITEMSLOTS = containers.MAXITEMSLOTS
AddPrefabPostInit("world_network", function(inst)
    if containers.widgetsetup ~= containers_widgetsetup_custom then
        OVERRIDE_WIDGETSETUP = true
        local containers_widgetsetup_base2 = containers.widgetsetup
        function containers.widgetsetup(container, prefab)
            containers_widgetsetup_base2(container, prefab)
            if container.type == "chest_yamche1" then
                container.type = "chest"
            end end end
    if containers.MAXITEMSLOTS < MAXITEMSLOTS then
        containers.MAXITEMSLOTS = MAXITEMSLOTS
    end
end)
---------------------------------------------------------------
--box3
local params = {}
local OVERRIDE_WIDGETSETUP = false
local containers_widgetsetup_base = containers.widgetsetup
function containers.widgetsetup(container, prefab)
    local t = params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
        if OVERRIDE_WIDGETSETUP then
            container.type = "chest_yamche2"
        end
    else
        containers_widgetsetup_base(container, prefab)
    end
end
local function chest_yamche2()
    local container =
    {
        widget =
        {
            slotpos = {},
            animbank = "ui_chest_3x3",
            animbuild = "ui_chest_yamche2",
            pos = GLOBAL.Vector3(0, 200, 0),
            side_align_tip = 160,
        },
        type = "chest",
    }
		
for y = 2, 0, -1 do
    for x = 0, 1 do
        table.insert(container.widget.slotpos, GLOBAL.Vector3(80*x-80*2+78, 80*y-80*2+80,0))
    end
end
    return container
end
params.chest_yamche2 = chest_yamche2()
for k, v in pairs(params) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
local containers_widgetsetup_custom = containers.widgetsetup
local MAXITEMSLOTS = containers.MAXITEMSLOTS
AddPrefabPostInit("world_network", function(inst)
    if containers.widgetsetup ~= containers_widgetsetup_custom then
        OVERRIDE_WIDGETSETUP = true
        local containers_widgetsetup_base2 = containers.widgetsetup
        function containers.widgetsetup(container, prefab)
            containers_widgetsetup_base2(container, prefab)
            if container.type == "chest_yamche2" then
                container.type = "chest"
        end end end
    if containers.MAXITEMSLOTS < MAXITEMSLOTS then
        containers.MAXITEMSLOTS = MAXITEMSLOTS
    end
end)
---------------------------------------------------------------
--box5
local params = {}
local OVERRIDE_WIDGETSETUP = false
local containers_widgetsetup_base = containers.widgetsetup
function containers.widgetsetup(container, prefab)
    local t = params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
        if OVERRIDE_WIDGETSETUP then
            container.type = "chest_yamche4"
        end
    else
        containers_widgetsetup_base(container, prefab)
    end
end
local function chest_yamche4()
    local container =
    {
        widget =
        {
            slotpos = {},
            animbank = "ui_chest_3x3",
            animbuild = "ui_chest_3x3",
            pos = GLOBAL.Vector3(0, 200, 0),
            side_align_tip = 160,
        },
        type = "chest",
    }
for y = 3, 0, -1 do
    for x = 0, 2 do
        table.insert(container.widget.slotpos, GLOBAL.Vector3(75*x-75*2+75, 60*y-60*2+32,0))
    end
end
    return container
end
params.chest_yamche4 = chest_yamche4()
for k, v in pairs(params) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
local containers_widgetsetup_custom = containers.widgetsetup
local MAXITEMSLOTS = containers.MAXITEMSLOTS
AddPrefabPostInit("world_network", function(inst)
    if containers.widgetsetup ~= containers_widgetsetup_custom then
        OVERRIDE_WIDGETSETUP = true
        local containers_widgetsetup_base2 = containers.widgetsetup
        function containers.widgetsetup(container, prefab)
            containers_widgetsetup_base2(container, prefab)
            if container.type == "chest_yamche4" then
                container.type = "chest"
        end end end
    if containers.MAXITEMSLOTS < MAXITEMSLOTS then
        containers.MAXITEMSLOTS = MAXITEMSLOTS
    end
end)
---------------------------------------------------------------
--box6
local params = {}
local OVERRIDE_WIDGETSETUP = false
local containers_widgetsetup_base = containers.widgetsetup
function containers.widgetsetup(container, prefab)
    local t = params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
        if OVERRIDE_WIDGETSETUP then
            container.type = "chest_yamche5"
        end
    else
        containers_widgetsetup_base(container, prefab)
    end
end
local function chest_yamche5()
    local container =
    {
        widget =
        {
            slotpos = {},
            animbank = "ui_chest_3x3",
            animbuild = "ui_chest_3x3",
            pos = GLOBAL.Vector3(0, 200, 0),
            side_align_tip = 160,
        },
        type = "chest",
    }
for y = 3, 0, -1 do
    for x = 0, 3 do
        table.insert(container.widget.slotpos, GLOBAL.Vector3(60*x-60*2+30, 60*y-60*2+30,0))
    end
end
    return container
end
params.chest_yamche5 = chest_yamche5()
for k, v in pairs(params) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
local containers_widgetsetup_custom = containers.widgetsetup
local MAXITEMSLOTS = containers.MAXITEMSLOTS
AddPrefabPostInit("world_network", function(inst)
    if containers.widgetsetup ~= containers_widgetsetup_custom then
        OVERRIDE_WIDGETSETUP = true
        local containers_widgetsetup_base2 = containers.widgetsetup
        function containers.widgetsetup(container, prefab)
            containers_widgetsetup_base2(container, prefab)
            if container.type == "chest_yamche5" then
                container.type = "chest"
    end end end
    if containers.MAXITEMSLOTS < MAXITEMSLOTS then
        containers.MAXITEMSLOTS = MAXITEMSLOTS
    end
end)

---------------------------------------------------------------
---------------------------------------------------------------
--box7
local params = {}
local OVERRIDE_WIDGETSETUP = false
local containers_widgetsetup_base = containers.widgetsetup
function containers.widgetsetup(container, prefab)
    local t = params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
        if OVERRIDE_WIDGETSETUP then
            container.type = "chest_yamche6"
        end
    else
        containers_widgetsetup_base(container, prefab)
    end
end
local function chest_yamche6()
    local container =
    {
        widget =
        {
            slotpos = {},
            animbank = "ui_chest_3x3",
            animbuild = "",--"ui_chest_moon",
            pos = GLOBAL.Vector3(0, 200, 0),
            side_align_tip = 160,
        },
        type = "chest",
    }
for y = 5, 0, -1 do
    for x = 0, 14 do
        table.insert(container.widget.slotpos, GLOBAL.Vector3(60*x-60*2+-150, 60*y-60*2+10,0))
    end
end
    return container
end
params.chest_yamche6 = chest_yamche6()
for k, v in pairs(params) do
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
local containers_widgetsetup_custom = containers.widgetsetup
local MAXITEMSLOTS = containers.MAXITEMSLOTS
AddPrefabPostInit("world_network", function(inst)
    if containers.widgetsetup ~= containers_widgetsetup_custom then
        OVERRIDE_WIDGETSETUP = true
        local containers_widgetsetup_base2 = containers.widgetsetup
        function containers.widgetsetup(container, prefab)
            containers_widgetsetup_base2(container, prefab)
            if container.type == "chest_yamche6" then
                container.type = "chest"
    end end end
    if containers.MAXITEMSLOTS < MAXITEMSLOTS then
        containers.MAXITEMSLOTS = MAXITEMSLOTS
    end
end)


--AddPrefabPostInit("ancient_soul", Addtradableprefab)
--AddPrefabPostInit("maxwellintro", InoriMaxwellIntro)
----------------------------------------------------------------------------------------------------

local function Givelickingbone(inst)
	local lickingbone = GLOBAL.SpawnPrefab("personal_licking_eyebone")
	if lickingbone then
		lickingbone.owner = inst
		inst.lickingbone = lickingbone
		inst.components.inventory.ignoresound = true
		inst.components.inventory:GiveItem(lickingbone)
		inst.components.inventory.ignoresound = false
--		lickingbone.components.named:SetName('Your pet\'s bell')--((inst.name or '你').."的铃铛")
	return lickingbone
	end
end
local function GetSpawnPoint(pt)
	local theta = math.random() * 2 * GLOBAL.PI
	local radius = 4
	local offset = GLOBAL.FindWalkableOffset(pt, theta, radius, 12, true)
	return offset ~= nil and (pt + offset) or nil
end
local function Personallicking(inst)
	if not inst:HasTag("speciallickingowner") then
		return
	end
--===================================
--		local is_survive=GetWorld() and not (GetWorld():HasTag('cave') or GetWorld():HasTag('ruin') or GetWorld():HasTag('volcano')) 
--		if is_survive and GetClock:GetNumCycles()==1 then
--			Givelickingbone(inst)
--		end
--===================================
	-- Debug function to return lickingbone
	inst.Returnlickingbone = function()
--===================================
if not inst.lickingbone then
	inst.lickingbone = GLOBAL.TheSim:FindFirstEntityWithTag("personal_licking_eyebone")
end

if not inst.licking then
	inst.licking = GLOBAL.TheSim:FindFirstEntityWithTag("personal_licking")
end
--===================================	
	
		if inst.lickingbone and inst.lickingbone:IsValid() then
			if inst.lickingbone.components.inventoryitem.owner ~= inst then
				inst.components.inventory:GiveItem(inst.lickingbone)
			end
		else
			Givelickingbone(inst)
		end
		if inst.licking and not inst:IsNear(inst.licking, 20) then
			local pt = inst:GetPosition()
			local spawn_pt = GetSpawnPoint(pt)
			if spawn_pt ~= nil then
				inst.licking.Physics:Teleport(spawn_pt:Get())
				inst.licking:FacePoint(pt:Get())
			end
		end
	end
end

GLOBAL.c_returnlickingbone = function(inst)
	if not inst then
		inst = GetPlayer() --or GLOBAL.AllPlayers[1]
	end
	if not inst or not inst.Returnlickingbone then 
		print("Error: Cannot return lickingbone")
		return 
	end
	inst:Returnlickingbone()
end

AddPlayerPostInit(Personallicking)

--No One Enters Chester cept the one with the licking bone!

local function HaslickingBone(doer)
    if doer.components.inventory and doer.components.inventory:FindItem(function(item)
            if item.prefab == "personal_licking_eyebone" then return true end
        end) ~= nil then
        return true
    else
        return false
    end
end
 
local oldACTIONSTORE = GLOBAL.ACTIONS.STORE.fn
GLOBAL.ACTIONS.STORE.fn = function(act)
    if act.target and act.target.prefab == "personal_licking" and act.target.components.container ~= nil and act.invobject.components.inventoryitem ~= nil and act.doer.components.inventory ~= nil then
--        print(act.doer.name,"is trying to do something with a licking")
        if HaslickingBone(act.doer) then
--           print(act.doer.name,"has licking Bone, proceed")
            return oldACTIONSTORE(act)
        else
--            print(act.doer.name,"doesn't has the licking Bone, exit")
            if act.doer.components.talker then act.doer.components.talker:Say("No Can Do!") end
                        return true
        end
    else
        return oldACTIONSTORE(act)
    end
end

local old_RUMMAGE = GLOBAL.ACTIONS.RUMMAGE.fn 
GLOBAL.ACTIONS.RUMMAGE.fn = function(act)
    if act.target and act.target.prefab == "personal_licking" then  
--        print("GLOBAL.ACTIONS.RUMMAGE--"..tostring(act.doer.components.inventory))
        result = act.doer.components.inventory:FindItem(function(item)
            if item.prefab == "personal_licking_eyebone" then 
--               print("GLOBAL.ACTIONS.RUMMAGE--"..tostring(item).."--ok--") 
               return true
            end
        end)
        if result then 
            return old_RUMMAGE(act)
        else
--            print("GLOBAL.ACTIONS.RUMMAGE--"..tostring(item).."--fail--") 
            act.doer:DoTaskInTime(1, function ()
                act.doer.components.talker:Say("No Can Do!")
            end)
            return false
        end
    else
        return old_RUMMAGE(act)
    end
end


AddMinimapAtlas("images/inventoryimages/personal_licking.xml")

--TUNING.ZZJ_DAMAGE = GetModConfigData("zzj_damage")
TUNING.ZZJ_TIMES = GetModConfigData("zzj_times")
TUNING.FHL_COS = GetModConfigData("fhl_cos")
TUNING.ZZJ_CAN_USE_AS_HAMMER = GetModConfigData("zzj_canuseashammer")
TUNING.ZZJ_CAN_USE_AS_SHOVEL = GetModConfigData("zzj_canuseasshovel")
TUNING.ZZJ_FINITE_USES = GetModConfigData("zzj_finiteuses")
TUNING.ZZJ_CANKANSHU = GetModConfigData("zzj_cankanshu")
TUNING.ZZJ_CANWAKUANG = GetModConfigData("zzj_canwakuang")
TUNING.ZZJ_PRE = GetModConfigData("zzj_pre")
--TUNING.ZZJ_RANGE = GetModConfigData("zzj_range")
TUNING.OPENLIGHT = GetModConfigData("openlight")
TUNING.OPENLI = GetModConfigData("openli")
TUNING.BUFFGO = GetModConfigData("buffgo")
TUNING.FHL_HJOPEN = GetModConfigData("fhl_hjopen")
TUNING.ZZJ_FIREOPEN = GetModConfigData("zzj_fireopen")

GLOBAL.STRINGS.TABS.FHL = "风幻空间"
--GLOBAL.RECIPETABS['FHL'] = {str = "FHL", sort=10, icon = "fhltab.tex", icon_atlas = "images/inventoryimages/fhltab.xml", "fhl"}
--=====================================================
AddComponentPostInit('container',function(self,inst) 
	function self:WidgetSetup(prefab, data)
		containers.widgetsetup(self, prefab, data)
	end	
end)

AddClassPostConstruct("widgets/crafttabs", function(inst)  --加专属制作栏
  	  if inst.prefab == "fhl" then
		table.insert(tabnames, RECIPETABS['FHL'])
	end
end)

local function fhlpostinit()

local ancient_soul18 = Ingredient( "ancient_soul", 18)
ancient_soul18.atlas = "images/inventoryimages/ancient_soul.xml"

local ancient_soul8 = Ingredient( "ancient_soul", 8)
ancient_soul8.atlas = "images/inventoryimages/ancient_soul.xml"

local ancient_soul5 = Ingredient( "ancient_soul", 5)
ancient_soul5.atlas = "images/inventoryimages/ancient_soul.xml"

local ancient_soul3 = Ingredient( "ancient_soul", 3)
ancient_soul3.atlas = "images/inventoryimages/ancient_soul.xml"

local ancient_soul1 = Ingredient( "ancient_soul", 1)
ancient_soul1.atlas = "images/inventoryimages/ancient_soul.xml"

local fhl_zzj = Recipe("fhl_zzj", {ancient_soul1,Ingredient("goldnugget", 3)}, RECIPETABS.FHL, {SCIENCE=0})
fhl_zzj.atlas = "images/inventoryimages/fhl_zzj.xml"

local fhl_zzj1 = Recipe("fhl_zzj1", {Ingredient("fhl_zzj", 1,"images/inventoryimages/fhl_zzj.xml"),ancient_soul1,Ingredient("goldnugget", 6)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_zzj1.atlas = "images/inventoryimages/fhl_zzj1.xml"

local fhl_zzj2 = Recipe("fhl_zzj2", {Ingredient("fhl_zzj1", 1,"images/inventoryimages/fhl_zzj1.xml"),ancient_soul3,Ingredient("goldnugget", 12)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_zzj2.atlas = "images/inventoryimages/fhl_zzj2.xml"

local fhl_zzj3 = Recipe("fhl_zzj3", {Ingredient("fhl_zzj2", 1,"images/inventoryimages/fhl_zzj2.xml"),ancient_soul5,Ingredient("goldnugget", 24),Ingredient("bluegem", 3)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_zzj3.atlas = "images/inventoryimages/fhl_zzj3.xml"

local fhl_zzj4 = Recipe("fhl_zzj4", {Ingredient("fhl_zzj3", 1,"images/inventoryimages/fhl_zzj3.xml"),ancient_soul8,Ingredient("goldnugget", 50),Ingredient("bluegem", 9)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_zzj4.atlas = "images/inventoryimages/fhl_zzj4.xml"

local fhl_zzj5 = Recipe("fhl_zzj5", {Ingredient("fhl_zzj4", 1,"images/inventoryimages/fhl_zzj4.xml"),ancient_soul18,Ingredient("goldnugget", 100),Ingredient("bluegem", 21)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_zzj5.atlas = "images/inventoryimages/fhl_zzj5.xml"

local fhl_hsf = Recipe("fhl_hsf", {Ingredient( "feather_robin",3),Ingredient("feather_crow", 3),ancient_soul5}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_hsf.atlas = "images/inventoryimages/fhl_hsf.xml"

local fhl_bz = Recipe("fhl_bz", {Ingredient( "berries",8), Ingredient("watermelon", 2)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_bz.atlas = "images/inventoryimages/fhl_bz.xml"

local fhl_cake = Recipe("fhl_cake", {Ingredient( "berries",4), Ingredient("pumpkin", 2)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_cake.atlas = "images/inventoryimages/fhl_cake.xml"

local fhl_x = Recipe("fhl_x", {Ingredient( "froglegs_cooked",3), Ingredient("berries", 3)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_x.atlas = "images/inventoryimages/fhl_x.xml"

local fhl_cy = Recipe("fhl_cy", {Ingredient( "butterflywings",5), Ingredient("honey", 2)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_cy.atlas = "images/inventoryimages/fhl_cy.xml"


local ancient_gem = Recipe("ancient_gem", { ancient_soul18, Ingredient("goldnugget", 12)}, RECIPETABS.FHL, {SCIENCE=0} )
ancient_gem.atlas = "images/inventoryimages/ancient_gem.xml"

local fhl_tree = Recipe("fhl_tree", { ancient_soul3, Ingredient("twigs", 3)}, RECIPETABS.FHL, {SCIENCE=0} )
fhl_tree.atlas = "images/inventoryimages/fhl_tree.xml"

local fhl_bb = Recipe("fhl_bb", {Ingredient("cutgrass", 5),Ingredient("twigs", 5),ancient_soul8}, RECIPETABS.FHL, {SCIENCE=0})
fhl_bb.atlas = "images/inventoryimages/fhl_bb.xml"
----BOOK----
Recipe("book_birds", {Ingredient("papyrus", 2), Ingredient("bird_egg", 2)}, RECIPETABS.FHL, TECH.NONE, nil, nil, nil, nil)--,"bookbuilder")
Recipe("book_gardening", {Ingredient("papyrus", 2), Ingredient("seeds", 1), Ingredient("poop", 1)}, RECIPETABS.FHL, TECH.NONE, nil, nil, nil, nil)--,"bookbuilder")
Recipe("book_sleep", {Ingredient("papyrus", 2), Ingredient("nightmarefuel", 2)}, RECIPETABS.FHL, TECH.NONE, nil, nil, nil, nil)--,"bookbuilder")
Recipe("book_brimstone", {Ingredient("papyrus", 2), Ingredient("redgem", 1)}, RECIPETABS.FHL, TECH.NONE, nil, nil, nil, nil)--,"bookbuilder")
Recipe("book_tentacles", {Ingredient("papyrus", 2), Ingredient("tentaclespots", 1)}, RECIPETABS.FHL, TECH.NONE, nil, nil, nil, nil)--,"bookbuilder")

end
AddSimPostInit(function(inst)
	if inst.prefab == "fhl" then
        fhlpostinit()
    end
end)

local books = {'book_birds','book_gardening','book_sleep','book_brimstone','book_tentacles'}
for k,v in pairs(books) do
	AddPrefabPostInit(v,function(inst)
		if inst.components.characterspecific and GetPlayer() and GetPlayer().prefab == 'fhl' then
			inst.components.characterspecific:SetOwner("fhl")
		end
	end)
end
--=====================================================
-----------创建地图图标和角色基础属性
AddMinimapAtlas("images/map_icons/fhl.xml")
AddModCharacter("fhl","FEMALE")

GLOBAL.glassesdrop = GetModConfigData("DROPGLASSES")