#how can I make this work with custom foods and make it check the food consumethen give you heart

1 messages · Page 1 of 1 (latest)

drifting osprey
#

how can I make this work with custom foods and make it check the food consume then give you a heart?

#

how can I make this work with custom foods and make it check the food consumethen give you heart

#

Typescript

proud vector
#

you can check if the item has the food component

#

i think it only works for custom foods though, not vanilla ones

#

but thats fine in your use case

drifting osprey
proud vector
#

theres 2 methods

#
if (item.getComponent(ItemComponentTypes.Food)) {
  //do something...
}```
#
if (item.getComponent(ItemFoodComponent.componentId)) {
  //do something...
}```
drifting osprey
proud vector
#

no

#

do you seriously not know where to put that snippet of code...? ;-;

drifting osprey
#

I do

#

@proud vector How do you make it check the food after consume then give you a heart?

proud vector
drifting osprey
proud vector
drifting osprey
#
world.afterEvents.itemStopUse.subscribe((event: ItemStopUseAfterEvent) => {
    const player = event.source;
    const item = event.itemStack;
#

Like this

#

@proud vector

proud vector
#

wrong event

#

there is an example given too so you can just copy it from there

drifting osprey
#

Ohhhh

proud vector
#
world.afterEvents.itemCompleteUse.subscribe((eventData) => {
    // Extract the player who used the item and the item stack from the event data
    const { source, itemStack } = eventData;

    // Construct a message indicating the player's name and the type of item they used
    world.sendMessage(
        `Player ${source.name} completed use of item (${itemStack.typeId})`
    );
});
drifting osprey
#
// Subscribe to the itemUse event
world.afterEvents.itemUse.subscribe((event) => {
    const player = event.source;
    const item = event.itemStack;

    // Check if the item is food
    if (!item || !item.typeId.startsWith('minecraft:')) return;

    // Check if the item has a food component
    if (item.getComponent(ItemComponentTypes.Food)) {
        // The actual processing will be done in the itemCompleteUse event
    }
});

// Subscribe to the itemCompleteUse event
world.afterEvents.itemCompleteUse.subscribe((eventData) => {
    const { source: player, itemStack: item } = eventData;
#

@proud vector

#

It fine

proud vector
#

are you using chatgpt ?

drifting osprey
#

I'm not

teal cape
#

you are a bad liar..

proud vector
#

🤭

proud vector
drifting osprey
drifting osprey
drifting osprey
#

I had it like that but I change it Ja ja

teal cape
#

what is Ja ja?

drifting osprey
#

[Scripting][error]-Unhandled promise rejection: TypeError: cannot read property 'subscribe' of undefined

[Scripting][error]-Unhandled promise rejection: TypeError: cannot read property 'subscribe' of undefined

[Scripting][error]-Plugin [Food Tracker - 2.0.20] - [main.js] ran with error: [TypeError: cannot read property 'subscribe' of undefined at <anonymous> (custom/food_hearts.js:92)
]
But I'm looking at line 92 I don't see any out of the ordinary.

92 world.beforeEvents.chatSend.subscribe((event) => {

#

Maybe it becomes it hav ((

#

Am I right

#

92 world.beforeEvents.chatSend.subscribe(event) => {

#

[Scripting][error]-Plugin [Food Tracker - 2.0.21] - [main.js] ran with error: [SyntaxError: expecting ';' at custom/food_hearts.js:92
]

Now I just get this

teal cape
#

chatSend it's Beta, can't use in stable