#Modifiying food wont work

53 messages · Page 1 of 1 (latest)

rigid saddle
#

so im trying to modify 'corn_delight:cornbread' but I cant for some reason. This exact same code works for diamonds and other items. Why?

event.modify('corn_delight:cornbread', item => {
    item.foodProperties = food => {
        food.hunger(2)
        food.saturation(3)
        food.fastToEat(true) 
    }
})
pine basaltBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

limber raven
#

is that the whole script?

#

nvm, hmmm

forest magnet
#

💀

#

they always generate own food properties when accessing the method

limber raven
#

tazz beat me to it

rigid saddle
#

oh damn

#

is there any way i could get around that

#

or would i have to go into mod files and change the code

forest magnet
#

ask the mod author to fix their code or use reflection through kubejs

#

should not be that hard

limber raven
#

you could recreate the item through kubejs and set custom properties

rigid saddle
#

if i cant find any other way i might just take the textures and do that lmao

#

but ty guys

limber raven
#

if youd give me a moment id do it for you here ahujel

rigid saddle
#

oh alr sure

limber raven
#

nevermind this didnt work pain js StartupEvents.registry('item', event => { event.create('corn_delight:cornbread') .food(food => { food .hunger(20) .saturation(30) .fastToEat(true) }).maxStackSize(3) })

#

it should blobbongoree

rigid saddle
#

oh damnn

forest magnet
#

I mean if you depend on their food infos somehow

#

that will not work

limber raven
#

yeah thats fair ig

#

was worth a shot

forest magnet
#
event.modify('corn_delight:cornbread', item => {

    let foodInfo = item.getFoodInfo()
    let field = item.getClass().getDeclaredField("info")
    field.setAccessible(true)

    // calories seems to be saturation
    let caloriedField = foodInfo.getClass().getDeclaredField("caloried")
    caloriedField.setAccessible(true)
    caloriedField.setFloat(foodInfo, 32) // calories is a float
})

that would be the reflection example

#

I have no clue what hunger is in their FoodInfo

limber raven
#

whatever this stuff is

#

why do they do this

forest magnet
#

no clue

rigid saddle
#

wow that is certainly something

forest magnet
#

amount is probably hunger?

limber raven
#

amountandcalories i think

#

whats nutirents then

rigid saddle
#

its a secret

#

its just nutrients

limber raven
#

oh maybe for addon mods like that one mod that requires a "balanced diet"

rigid saddle
#

yea thats prob why they have the other goofy stuff aswell

limber raven
#

i guess

forest magnet
#
event.modify('corn_delight:cornbread', item => {

    let foodInfo = item.getFoodInfo()
    let field = item.getClass().getDeclaredField("info")
    field.setAccessible(true)

    // calories seems to be saturation
    let caloriesField = foodInfo.getClass().getDeclaredField("calories")
    caloriesField.setAccessible(true)
    caloriesField.setFloat(foodInfo, 0.5) // calories is a float

    let amountField = foodInfo.getClass().getDeclaredField("amount")
    amountField.setAccessible(true)
    amountField.setInt(foodInfo, 10) // calories is a float

    let eatTimeField = foodInfo.getClass().getDeclaredField("eatTime")
    eatTimeField.setAccessible(true)
    eatTimeField.setInt(foodInfo, 16) // 16 is for fast eat
})
#

that should be all three fields

rigid saddle
#

thank you brotha

rigid saddle
#

its alright

limber raven