Don't Starve Together

Don't Starve Together

Không đủ lượt đánh giá
模组制作教程-自定义农作物代码模板
Bởi 凌
代码旁边有文字说明
   
Giải thưởng
Yêu thích
Đã yêu thích
Bỏ thích
modmain
modinfo没有新的部分,以下是modmain关于农作物的代码。

GLOBAL.setmetatable(env,{__index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end})--全局变量

PrefabFiles = {
"fx_apple", --载入农作物产品
}

Assets ={} --加载图片

modimport"scripts/farm_plant_fx_apple" --载入农作物生长文件

AddRecipe("fx_apple_seeds", --添加物品的配方(苹果种子)
{Ingredient("seeds", 1),}, --材料
RECIPETABS.WAR, TECH.NONE, --制作栏和解锁的科技(这里是战斗栏,需要科学一本)
nil, nil, nil, nil, nil, --是否有placer 是否有放置的间隔 科技锁 制作的数量(改成2就可以一次做两个) 需要的标签(比如女武神的配方需要女武神的自有标签才可以看得到)
"images/fx_apple_seeds.xml", "fx_apple_seeds.tex") --配方的贴图(跟物品栏使用同一个贴图)


STRINGS.NAMES.FX_APPLE = "开心橙子" --农产品命名
STRINGS.CHARACTERS.GENERIC.DESCRIBE.FX_APPLE = "开心橙子!开心!" --人物检查

STRINGS.NAMES.FX_APPLE_SEEDS = "开心橙子种子"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.FX_APPLE_SEEDS = "种下希望就会发芽!" --制作栏说明
STRINGS.NAMES.KNOWN_FX_APPLE_SEEDS = "开心橙子种子"

STRINGS.NAMES.FX_APPLE_OVERSIZED = "巨型开心橙子"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.FX_APPLE_OVERSIZED = "超级大的开心!"

STRINGS.NAMES.FX_APPLE_OVERSIZED_WAXED = "打蜡的巨型开心橙子"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.FX_APPLE_OVERSIZED_WAXED = "一闪一闪亮晶晶~满天都是开心心~"

STRINGS.NAMES.FX_APPLE_OVERSIZED_ROOTEN = "腐烂的巨型开心橙子"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.FX_APPLE_OVERSIZED_ROOTEN = "伤心..."

STRINGS.NAMES.FARM_PLANT_FX_APPLE = "开心橙子作物"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.FARM_PLANT_FX_APPLE = "开心橙子作物"
在scripts的根目录创建farm_plant_fx_apple.lua
--将以下代码复制粘贴进去
local PLANT_DEFS = require("prefabs/farm_plant_defs").PLANT_DEFS

local function MakeGrowTimes(germination_min, germination_max, full_grow_min, full_grow_max)
local grow_time = {}

-- 发芽时间
grow_time.seed = {germination_min, germination_max}

-- 生长时间
grow_time.sprout = {full_grow_min * 0.6, full_grow_max * 0.6}
grow_time.small = {full_grow_min * 0.4, full_grow_max * 0.4}
grow_time.med = {full_grow_min * 0.3, full_grow_max * 0.3}

-- 收获后腐烂时间
grow_time.full = 6 * TUNING.TOTAL_DAY_TIME
grow_time.oversized = 8 * TUNING.TOTAL_DAY_TIME
grow_time.regrow = {6 * TUNING.TOTAL_DAY_TIME, 7 * TUNING.TOTAL_DAY_TIME} -- min, max

return grow_time
end

--潮湿度需求
local drink_low = TUNING.FARM_PLANT_DRINK_LOW
local drink_med = TUNING.FARM_PLANT_DRINK_MED
local drink_high = TUNING.FARM_PLANT_DRINK_HIGH

--肥料需求
local S = TUNING.FARM_PLANT_CONSUME_NUTRIENT_LOW
local M = TUNING.FARM_PLANT_CONSUME_NUTRIENT_MED
local L = TUNING.FARM_PLANT_CONSUME_NUTRIENT_HIGH

PLANT_DEFS.fx_apple = {
build = "farm_plant_fx_apple", --这是作物的动画文件,也就是你需要改的地方
bank = "farm_plant_potato", --这是bank文件,直接用土豆的就行
--生长时间
grow_time = MakeGrowTimes(12 * TUNING.SEG_TIME, 16 * TUNING.SEG_TIME, 4 * TUNING.TOTAL_DAY_TIME, 7 * TUNING.TOTAL_DAY_TIME),
--潮湿度
moisture = {drink_rate = drink_high, min_percent = TUNING.FARM_PLANT_DROUGHT_TOLERANCE},
--肥料需求
nutrient_consumption = {S, 0, S},
--肥料产出
nutrient_restoration = {nil, true, nil},
--杂草容忍度
max_killjoys_tolerance = TUNING.FARM_PLANT_KILLJOY_TOLERANCE,
--生长季节(春、秋)
good_seasons = { autumn = true, winter = true},
--重量数据 min max sigmoid%
weight_data = { 484.59, 862.77, .18 },
--音效
sounds = {
grow_oversized = "farming/common/farm/potato/grow_oversized",
grow_full = "farming/common/farm/grow_full",
grow_rot = "farming/common/farm/rot",
},
--农作物代码
prefab = "farm_plant_fx_apple", --记得改
--果实
product = "fx_apple", --记得改
--巨型果实
product_oversized = "fx_apple_oversized", --记得改
--种子
seed = "fx_apple_seeds", --记得改
--作物标签
plant_type_tag = "farm_plant_fx_apple", --记得改
--巨型腐烂果实产出
loot_oversized_rot = {"spoiled_food", "spoiled_food", "spoiled_food", "fx_apple_seeds", "fruitfly", "fruitfly"}, --记得改
--同种植物需求数量
family_min_count = TUNING.FARM_PLANT_SAME_FAMILY_MIN,
--同种植物检索距离
family_check_dist = TUNING.FARM_PLANT_SAME_FAMILY_RADIUS,
--农作物状态标签对应网络变量类型
stage_netvar = net_tinybyte,
--生长状态信息
plantregistryinfo = {
{
text = "seed",
anim = "crop_seed",
grow_anim = "grow_seed",
learnseed = true,
growing = true,
},
{
text = "sprout",
anim = "crop_sprout",
grow_anim = "grow_sprout",
growing = true,
},
{
text = "small",
anim = "crop_small",
grow_anim = "grow_small",
growing = true,
},
{
text = "medium",
anim = "crop_med",
grow_anim = "grow_med",
growing = true,
},
{
text = "grown",
anim = "crop_full",
grow_anim = "grow_full",
revealplantname = true,
fullgrown = true,
},
{
text = "oversized",
anim = "crop_oversized",
grow_anim = "grow_oversized",
revealplantname = true,
fullgrown = true,
hidden = true,
},
{
text = "rotting",
anim = "crop_rot",
grow_anim = "grow_rot",
stagepriority = -100,
is_rotten = true,
hidden = true,
},
{
text = "oversized_rotting",
anim = "crop_rot_oversized",
grow_anim = "grow_rot_oversized",
stagepriority = -100,
is_rotten = true,
hidden = true,
},
},
plantregistrywidget = "widgets/redux/farmplantpage",
plantregistrysummarywidget = "widgets/redux/farmplantsummarywidget",
--合影动画
pictureframeanim = {anim = "emoteXL_loop_dance0", time = 7*FRAMES},
}
prefabs/fx_apple.lua
新建fx_apple.lua

equire "tuning"
local PLANT_DEFS = require("prefabs/farm_plant_defs").PLANT_DEFS

local OVERSIZED_PHYSICS_RADIUS = 0.1
local OVERSIZED_MAXWORK = 1
local OVERSIZED_PERISHTIME_MULT = 4

local fruit_def =
{
fx_apple = { --这是产品的食物信息
health = 20, --健康值
hunger = 10, --饥饿值
perishtime = TUNING.PERISH_MED, --腐烂时间
sanity = 36, --理智属性
float_settings = {"small", 0.1, 0.8}, --漂浮属性

}
}

local assets_seeds =
{
Asset("ANIM", "anim/seeds.zip"), --在这里加载动画图片
Asset("ANIM", "anim/fx_apple_seeds.zip"),
}

local prefabs_seeds =
{
"plant_normal_ground",
"seeds_placer",
}

local function can_plant_seed(inst, pt, mouseover, deployer)
local x, z = pt.x, pt.z
return TheWorld.Map:CanTillSoilAtPoint(x, 0, z, true)
end

local function OnDeploy(inst, pt, deployer)
local plant = SpawnPrefab(inst.components.farmplantable.plant)
plant.Transform:SetPosition(pt.x, 0, pt.z)
plant:PushEvent("on_planted", {in_soil = false, doer = deployer, seed = inst})
TheWorld.Map:CollapseSoilAtPoint(pt.x, 0, pt.z)
--plant.SoundEmitter:PlaySound("dontstarve/wilson/plant_seeds")
inst:Remove()
end

local function oversized_calcweightcoefficient(name)
if PLANT_DEFS[name].weight_data[3] ~= nil and math.random() < PLANT_DEFS[name].weight_data[3] then
return (math.random() + math.random()) / 2
else
return math.random()
end
end

local function oversized_onequip(inst, owner)
if PLANT_DEFS[inst._base_name].build ~= nil then
owner.AnimState:OverrideSymbol("swap_body", PLANT_DEFS[inst._base_name].build, "swap_body")
else
owner.AnimState:OverrideSymbol("swap_body", "farm_plant_"..inst._base_name, "swap_body")
end
end

local function oversized_onunequip(inst, owner)
owner.AnimState:ClearOverrideSymbol("swap_body")
end

local function oversized_onfinishwork(inst, chopper)
inst.components.lootdropper:DropLoot()
inst:Remove()
end

local function oversized_onburnt(inst)
inst.components.lootdropper:DropLoot()
inst:Remove()
end

local function oversized_makeloots(inst, name)
local product = name
local seeds = name.."_seeds"
return {product, product, seeds, seeds, math.random() < 0.75 and product or seeds}
end

local function oversized_onperish(inst)
if inst.components.inventoryitem:GetGrandOwner() ~= nil then
local loots = {}
for i=1, #inst.components.lootdropper.loot do
table.insert(loots, "spoiled_food")
end
inst.components.lootdropper:SetLoot(loots)
inst.components.lootdropper:DropLoot()
else
SpawnPrefab(inst.prefab.."_rotten").Transform:SetPosition(inst.Transform:GetWorldPosition())
end

inst:Remove()
end

local function Seed_GetDisplayName(inst)
local registry_key = inst.plant_def.product

local plantregistryinfo = inst.plant_def.plantregistryinfo
return (ThePlantRegistry:KnowsSeed(registry_key, plantregistryinfo) and ThePlantRegistry:KnowsPlantName(registry_key, plantregistryinfo)) and STRINGS.NAMES["KNOWN_"..string.upper(inst.prefab)]
or nil
end

local function OnSave(inst, data)
data.from_plant = inst.from_plant
end

local function OnPreLoad(inst, data)
if data ~= nil then
inst.from_plant = data.from_plant
end
end

local function Oversized_OnSave(inst, data)
data.from_plant = inst.from_plant
data.harvested_on_day = inst.harvested_on_day
end

local function Oversized_OnPreLoad(inst, data)
if data ~= nil then
inst.from_plant = data.from_plant
inst.harvested_on_day = data.harvested_on_day
end
end

local function displayadjectivefn(inst)
return STRINGS.UI.HUD.WAXED
end

local function dowaxfn(inst, doer, waxitem)
local waxedveggie = SpawnPrefab(inst.prefab.."_waxed")
if doer.components.inventory and doer.components.inventory:IsHeavyLifting() and doer.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY) == inst then
doer.components.inventory:Unequip(EQUIPSLOTS.BODY)
doer.components.inventory:Equip(waxedveggie)
else
waxedveggie.Transform:SetPosition(inst.Transform:GetWorldPosition())
waxedveggie.AnimState:PlayAnimation("wax_oversized", false)
waxedveggie.AnimState:PushAnimation("idle_oversized")
end
inst:Remove()
return true
end

local PlayWaxAnimation

local function CancelWaxTask(inst)
if inst._waxtask ~= nil then
inst._waxtask:Cancel()
inst._waxtask = nil
end
end

local function StartWaxTask(inst)
if not inst.inlimbo and inst._waxtask == nil then
inst._waxtask = inst:DoTaskInTime(GetRandomMinMax(20, 40), PlayWaxAnimation)
end
end

PlayWaxAnimation = function(inst)
inst.AnimState:PlayAnimation("wax_oversized", false)
inst.AnimState:PushAnimation("idle_oversized")
end

local function MakeVeggie(name, has_seeds)
local assets =
{
Asset("ANIM", "anim/"..name..".zip"),
Asset("ATLAS", "images/fx_apple.xml"),
Asset("ATLAS", "images/fx_apple_seeds.xml"),--============================================================================
--===========================================================================================================================
}
if has_seeds then
table.insert(assets, Asset("ANIM", "anim/oceanfishing_lure_mis.zip"))
end

local prefabs =
{
"spoiled_food",
}
table.insert(prefabs, name.."_seeds")

local seeds_prefabs = { "farm_plant_"..name }

local assets_oversized = {
Asset("ANIM", "anim/"..PLANT_DEFS[name].build..".zip"),
Asset("ANIM", "anim/"..PLANT_DEFS[name].bank..".zip"),
Asset("ATLAS", "images/fx_apple_oversized.xml"),
}

table.insert(prefabs, name.."_oversized")
table.insert(prefabs, name.."_oversized_waxed")
table.insert(prefabs, name.."_oversized_rotten")
table.insert(prefabs, "splash_green")
------------------------------------------------------种子定义------------------------------------------------
local function fn_seeds()
local inst = CreateEntity()

inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()

MakeInventoryPhysics(inst)

inst.AnimState:SetBank("fx_apple_seeds")
inst.AnimState:SetBuild("fx_apple_seeds")
inst.AnimState:PlayAnimation("fx_apple_seeds")
inst.AnimState:SetRayTestOnBB(true)

--cookable (from cookable component) added to pristine state for optimization
inst:AddTag("cookable")
inst:AddTag("deployedplant")
inst:AddTag("deployedfarmplant")
inst:AddTag("oceanfishing_lure")

inst.overridedeployplacername = "seeds_placer"

inst.plant_def = PLANT_DEFS[name]
inst.displaynamefn = Seed_GetDisplayName

inst._custom_candeploy_fn = can_plant_seed -- for DEPLOYMODE.CUSTOM

MakeInventoryFloatable(inst)

inst.entity:SetPristine()

if not TheWorld.ismastersim then
return inst
end

inst:AddComponent("edible")
inst.components.edible.foodtype = FOODTYPE.SEEDS

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

inst:AddComponent("tradable")
inst:AddComponent("inspectable")
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.imagename = "fx_apple_seeds"
inst.components.inventoryitem.atlasname = "images/fx_apple_seeds.xml"

inst.components.edible.healthvalue = TUNING.HEALING_TINY / 2
inst.components.edible.hungervalue = TUNING.CALORIES_TINY

inst:AddComponent("perishable")
inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW)
inst.components.perishable:StartPerishing()
inst.components.perishable.onperishreplacement = "spoiled_food"

--还没复制完呢,下面接下去
inst:AddComponent("cookable")
inst.components.cookable.product = "seeds_cooked"

inst:AddComponent("bait")

inst:AddComponent("farmplantable")
inst.components.farmplantable.plant = "farm_plant_"..name

-- deprecated (used for crafted farm structures)
inst:AddComponent("plantable")
inst.components.plantable.growtime = TUNING.SEEDS_GROW_TIME
inst.components.plantable.product = name

-- deprecated (used for wormwood)
inst:AddComponent("deployable")
inst.components.deployable:SetDeployMode(DEPLOYMODE.CUSTOM) -- use inst._custom_candeploy_fn
inst.components.deployable.restrictedtag = "plantkin"
inst.components.deployable.ondeploy = OnDeploy

inst:AddComponent("oceanfishingtackle")
inst.components.oceanfishingtackle:SetupLure({build = "oceanfishing_lure_mis", symbol = "hook_seeds", single_use = true, lure_data = TUNING.OCEANFISHING_LURE.SEED})

MakeSmallBurnable(inst)
MakeSmallPropagator(inst)

MakeHauntableLaunchAndPerish(inst)

return inst
end
------------------------------------------------------果实定义------------------------------------------------
local function fn()
local inst = CreateEntity()

inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()

MakeInventoryPhysics(inst)

inst.AnimState:SetBank(name)
inst.AnimState:SetBuild(name)
inst.AnimState:PlayAnimation("idle")



--weighable (from weighable component) added to pristine state for optimization
inst:AddTag("weighable_OVERSIZEDVEGGIES")--可称重

local float = fruit_def[name].float_settings
if float ~= nil then
MakeInventoryFloatable(inst, float[1], float[2], float[3])
else
MakeInventoryFloatable(inst)
end

inst.entity:SetPristine()

if not TheWorld.ismastersim then
return inst
end

inst:AddComponent("edible")
inst.components.edible.healthvalue = fruit_def[name].health
inst.components.edible.hungervalue = fruit_def[name].hunger
inst.components.edible.sanityvalue = fruit_def[name].sanity or 0
inst.components.edible.foodtype = FOODTYPE.VEGGIE
inst.components.edible:SetOnEatenFn(fruit_def[name].eatfn)

inst:AddComponent("perishable")
inst.components.perishable:SetPerishTime(fruit_def[name].perishtime)
inst.components.perishable:StartPerishing()
inst.components.perishable.onperishreplacement = "spoiled_food"

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

inst:AddComponent("inspectable")
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.imagename = "fx_apple"
inst.components.inventoryitem.atlasname = "images/fx_apple.xml"

-- Regular veggies are weighable but don't have a weight. They all show the same
-- result when put in a trophyscale_oversizedveggies, and always replace other
-- regular veggies when attempting to do so.
--可称重
inst:AddComponent("weighable")
inst.components.weighable.type = TROPHYSCALE_TYPES.OVERSIZEDVEGGIES

MakeSmallBurnable(inst)
MakeSmallPropagator(inst)
---------------------

inst:AddComponent("bait")

------------------------------------------------
inst:AddComponent("tradable")

MakeHauntableLaunchAndPerish(inst)

if has_seeds then
inst.OnSave = OnSave
inst.OnPreLoad = OnPreLoad
end

return inst
end
------------------------------------------------------巨型作物定义------------------------------------------------
local function fn_oversized()
local inst = CreateEntity()

inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()

local plant_def = PLANT_DEFS[name]

inst.AnimState:SetBank(plant_def.bank)
inst.AnimState:SetBuild(plant_def.build)
inst.AnimState:PlayAnimation("idle_oversized")

inst:AddTag("heavy")
inst:AddTag("waxable")
inst:AddTag("show_spoilage")

MakeHeavyObstaclePhysics(inst, OVERSIZED_PHYSICS_RADIUS)
inst:SetPhysicsRadiusOverride(OVERSIZED_PHYSICS_RADIUS)

inst._base_name = name

inst.entity:SetPristine()

if not TheWorld.ismastersim then
return inst
end

inst.harvested_on_day = inst.harvested_on_day or (TheWorld.state.cycles + 1)

inst:AddComponent("heavyobstaclephysics")
inst.components.heavyobstaclephysics:SetRadius(OVERSIZED_PHYSICS_RADIUS)
inst.components.heavyobstaclephysics:MakeSmallObstacle()

inst:AddComponent("perishable")
inst.components.perishable:SetPerishTime(fruit_def[name].perishtime * OVERSIZED_PERISHTIME_MULT)
inst.components.perishable:StartPerishing()
inst.components.perishable.onperishreplacement = nil
inst.components.perishable:SetOnPerishFn(oversized_onperish)

inst:AddComponent("inspectable")
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.cangoincontainer = false
inst.components.inventoryitem:SetSinks(true)
inst.components.inventoryitem.imagename = "fx_apple_oversized"
inst.components.inventoryitem.atlasname = "images/fx_apple_oversized.xml"

inst:AddComponent("equippable")
inst.components.equippable.equipslot = EQUIPSLOTS.BODY
inst.components.equippable:SetOnEquip(oversized_onequip)
inst.components.equippable:SetOnUnequip(oversized_onunequip)
inst.components.equippable.walkspeedmult = TUNING.HEAVY_SPEED_MULT

inst:AddComponent("workable")
inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
inst.components.workable:SetOnFinishCallback(oversized_onfinishwork)
inst.components.workable:SetWorkLeft(OVERSIZED_MAXWORK)

inst:AddComponent("waxable")
inst.components.waxable:SetWaxfn(dowaxfn)

inst:AddComponent("submersible")
inst:AddComponent("symbolswapdata")
inst.components.symbolswapdata:SetData(plant_def.build, "swap_body")

local weight_data = plant_def.weight_data
inst:AddComponent("weighable")
inst.components.weighable.type = TROPHYSCALE_TYPES.OVERSIZEDVEGGIES
inst.components.weighable:Initialize(weight_data.min, weight_data.max)
local coefficient = oversized_calcweightcoefficient(name)
inst.components.weighable:SetWeight(Lerp(weight_data[1], weight_data[2], coefficient))

inst:AddComponent("lootdropper")
inst.components.lootdropper:SetLoot(oversized_makeloots(inst, name))

MakeMediumBurnable(inst)
inst.components.burnable:SetOnBurntFn(oversized_onburnt)
MakeMediumPropagator(inst)

MakeHauntableWork(inst)

inst.OnSave = Oversized_OnSave
inst.OnPreLoad = Oversized_OnPreLoad

return inst
end
------------------------------------------------------巨型打蜡果实定义------------------------------------------------
local function fn_oversized_waxed()
local inst = CreateEntity()

inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()

local plant_def = PLANT_DEFS[name]

inst.AnimState:SetBank(plant_def.bank)
inst.AnimState:SetBuild(plant_def.build)
inst.AnimState:PlayAnimation("idle_oversized")

inst:AddTag("heavy")

inst.displayadjectivefn = displayadjectivefn
inst:SetPrefabNameOverride(name.."_oversized")

MakeHeavyObstaclePhysics(inst, OVERSIZED_PHYSICS_RADIUS)
inst:SetPhysicsRadiusOverride(OVERSIZED_PHYSICS_RADIUS)

inst._base_name = name

inst.entity:SetPristine()

if not TheWorld.ismastersim then
--还没复制完呢,下面接下去~!
return inst
end

inst:AddComponent("heavyobstaclephysics")
inst.components.heavyobstaclephysics:SetRadius(OVERSIZED_PHYSICS_RADIUS)
inst.components.heavyobstaclephysics:MakeSmallObstacle()

inst:AddComponent("inspectable")
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.cangoincontainer = false
inst.components.inventoryitem:SetSinks(true)
inst.components.inventoryitem.imagename = "fx_apple_oversized"
inst.components.inventoryitem.atlasname = "images/fx_apple_oversized.xml"

inst:AddComponent("equippable")
inst.components.equippable.equipslot = EQUIPSLOTS.BODY
inst.components.equippable:SetOnEquip(oversized_onequip)
inst.components.equippable:SetOnUnequip(oversized_onunequip)
inst.components.equippable.walkspeedmult = TUNING.HEAVY_SPEED_MULT

inst:AddComponent("workable")
inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
inst.components.workable:SetOnFinishCallback(oversized_onfinishwork)
inst.components.workable:SetWorkLeft(OVERSIZED_MAXWORK)

inst:AddComponent("submersible")
inst:AddComponent("symbolswapdata")
inst.components.symbolswapdata:SetData(plant_def.build, "swap_body")

inst:AddComponent("lootdropper")
inst.components.lootdropper:SetLoot({"spoiled_food"})

MakeMediumBurnable(inst)
inst.components.burnable:SetOnBurntFn(oversized_onburnt)
MakeMediumPropagator(inst)

MakeHauntableWork(inst)

inst:ListenForEvent("onputininventory", CancelWaxTask)
inst:ListenForEvent("ondropped", StartWaxTask)

inst.OnEntitySleep = CancelWaxTask
inst.OnEntityWake = StartWaxTask

StartWaxTask(inst)

return inst
end
------------------------------------------------------巨型腐烂果实定义------------------------------------------------
local function fn_oversized_rotten()
local inst = CreateEntity()

inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()

MakeObstaclePhysics(inst, OVERSIZED_PHYSICS_RADIUS)

local plant_def = PLANT_DEFS[name]

inst.AnimState:SetBank(plant_def.bank)
inst.AnimState:SetBuild(plant_def.build)
inst.AnimState:PlayAnimation("idle_rot_oversized")

inst:AddTag("farm_plant_killjoy")
inst:AddTag("pickable_harvest_str")
inst:AddTag("pickable")

inst._base_name = name

inst.entity:SetPristine()

if not TheWorld.ismastersim then
return inst
end

inst:AddComponent("inspectable")
inst.components.inspectable.nameoverride = "VEGGIE_OVERSIZED_ROTTEN"

inst:AddComponent("workable")
inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
inst.components.workable:SetOnFinishCallback(oversized_onfinishwork)
inst.components.workable:SetWorkLeft(OVERSIZED_MAXWORK)

inst:AddComponent("pickable")
inst.components.pickable.onpickedfn = function(inst,picker)
inst:Remove()
end
inst.components.pickable:SetUp(nil)
inst.components.pickable.use_lootdropper_for_product = true
inst.components.pickable.picksound = "dontstarve/wilson/harvest_berries"

inst:AddComponent("inventoryitem")
inst.components.inventoryitem.cangoincontainer = false
inst.components.inventoryitem.canbepickedup = false
inst.components.inventoryitem:SetSinks(true)

inst:AddComponent("lootdropper")
inst.components.lootdropper:SetLoot(plant_def.loot_oversized_rot)

MakeMediumBurnable(inst)
inst.components.burnable:SetOnBurntFn(oversized_onburnt)
MakeMediumPropagator(inst)

MakeHauntableWork(inst)

return inst
end

local exported_prefabs = {}
table.insert(exported_prefabs, Prefab(name.."_seeds", fn_seeds, assets_seeds, seeds_prefabs))
table.insert(exported_prefabs, Prefab(name.."_oversized", fn_oversized, assets_oversized))
table.insert(exported_prefabs, Prefab(name.."_oversized_waxed", fn_oversized_waxed, assets_oversized))
table.insert(exported_prefabs, Prefab(name.."_oversized_rotten", fn_oversized_rotten, assets_oversized))
table.insert(exported_prefabs, Prefab(name, fn, assets, prefabs))

return exported_prefabs
end

local prefs = {}
for veggiename,veggiedata in pairs(fruit_def) do
local veggies = MakeVeggie(veggiename, true)
for _, v in ipairs(veggies) do
table.insert(prefs, v)
end
end

return unpack(prefs)