PocketPossum Posted September 25, 2025 Share Posted September 25, 2025 Hi I'm trying to add custom crops for my mod, and I managed to make an item that spawns in and seems to work for everything except, actually eating it? I'm not sure what's up with that or why it can't be eaten, and was wondering if anyone had any ideas. local assets = { Asset("ANIM", "anim/sitrus_berry.zip"), Asset("ATLAS", "images/inventoryimages/sitrus_berry.xml"), } local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("sitrus_berry") inst.AnimState:SetBuild("sitrus_berry") inst.AnimState:PlayAnimation("idle") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_LARGEITEM inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/sitrus_berry.xml" inst:AddComponent("edible") inst.components.edible.healthvalue = 50 inst.components.edible.hungervalue = 10 inst.components.edible.sanityvalue = 0 inst.components.edible.foodtype = FOODTYPE.BERRY inst:AddComponent("inspectable") inst:AddComponent("perishable") inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW) inst.components.perishable:StartPerishing() inst.components.perishable.onperishreplacement = "spoiled_food" return inst end return Prefab( "common/inventory/sitrus_berry", fn, assets) I added the "edible" component, but for some reason it just inspects the item rather than actually eating it in-game. Link to comment https://forums.kleientertainment.com/forums/topic/168167-my-edible-item-isnt-edible-any-ideas-why/ Share on other sites More sharing options...
FerniFrenito Posted September 25, 2025 Share Posted September 25, 2025 try putting the edible component before returning to the client local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("sitrus_berry") inst.AnimState:SetBuild("sitrus_berry") inst.AnimState:PlayAnimation("idle") inst:AddComponent("edible") inst.components.edible.healthvalue = 50 inst.components.edible.hungervalue = 10 inst.components.edible.sanityvalue = 0 inst.components.edible.foodtype = FOODTYPE.BERRY inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_LARGEITEM inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/sitrus_berry.xml" inst:AddComponent("inspectable") inst:AddComponent("perishable") inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW) inst.components.perishable:StartPerishing() inst.components.perishable.onperishreplacement = "spoiled_food" return inst end As far as I understand, everything after that if not TheWorld.ismastersim then return inst end This won't be reflected on the client and will only exist on the server. This is to avoid adding things the client doesn't need to know. I assume the client does need to know that the object has the "edible" component because the action system (which runs on the client) is based on the object's components. Link to comment https://forums.kleientertainment.com/forums/topic/168167-my-edible-item-isnt-edible-any-ideas-why/#findComment-1837262 Share on other sites More sharing options...
PocketPossum Posted September 25, 2025 Author Share Posted September 25, 2025 6 hours ago, FerniFrenito said: try putting the edible component before returning to the client local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("sitrus_berry") inst.AnimState:SetBuild("sitrus_berry") inst.AnimState:PlayAnimation("idle") inst:AddComponent("edible") inst.components.edible.healthvalue = 50 inst.components.edible.hungervalue = 10 inst.components.edible.sanityvalue = 0 inst.components.edible.foodtype = FOODTYPE.BERRY inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_LARGEITEM inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/sitrus_berry.xml" inst:AddComponent("inspectable") inst:AddComponent("perishable") inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW) inst.components.perishable:StartPerishing() inst.components.perishable.onperishreplacement = "spoiled_food" return inst end As far as I understand, everything after that if not TheWorld.ismastersim then return inst end This won't be reflected on the client and will only exist on the server. This is to avoid adding things the client doesn't need to know. I assume the client does need to know that the object has the "edible" component because the action system (which runs on the client) is based on the object's components. Trying that out, it also doesn't seem to work. I wanna mention, I have a mod that lets you see the hunger value and stuff for any food item, and it shows the values correctly as it would other foods. I'm wondering if I'm missing something? Or if I somehow messed up the edible component part. OH, I figured something out. For some reason, having the inst.components.edible.foodtype = FOODTYPE.BERRY line of code prevents it from being edible. So I'm thinking that's what I messed up on. I've removed it for now. Link to comment https://forums.kleientertainment.com/forums/topic/168167-my-edible-item-isnt-edible-any-ideas-why/#findComment-1837302 Share on other sites More sharing options...
ClumsyPenny Posted September 25, 2025 Share Posted September 25, 2025 Don't put the edible component before the mastersim check. It should be server side, right where you put it in your original post. The reason you can't eat your item is because FOODTYPE.BERRY isn't edible by players. Yes, I know, weird, but it's typically used as a secondary foodtype, Berries's primary foodtype is FOODTYPE.VEGGIE, so use that. BERRY mainly exists for Smallbirds, since their diet is so limited. 1 Link to comment https://forums.kleientertainment.com/forums/topic/168167-my-edible-item-isnt-edible-any-ideas-why/#findComment-1837304 Share on other sites More sharing options...
PocketPossum Posted September 25, 2025 Author Share Posted September 25, 2025 24 minutes ago, ClumsyPenny said: Don't put the edible component before the mastersim check. It should be server side, right where you put it in your original post. The reason you can't eat your item is because FOODTYPE.BERRY isn't edible by players. Yes, I know, weird, but it's typically used as a secondary foodtype, Berries's primary foodtype is FOODTYPE.VEGGIE, so use that. BERRY mainly exists for Smallbirds, since their diet is so limited. Thank you for letting me know! I appreciate it. Link to comment https://forums.kleientertainment.com/forums/topic/168167-my-edible-item-isnt-edible-any-ideas-why/#findComment-1837307 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now