#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)
how can I make this work with custom foods and make it check the food consumethen give you heart
Typescript
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
I tested it and it's only work with Minecraft foods
theres 2 methods
if (item.getComponent(ItemComponentTypes.Food)) {
//do something...
}```
if (item.getComponent(ItemFoodComponent.componentId)) {
//do something...
}```
This sounds good
Try tweaking my code then send it here
I do
@proud vector How do you make it check the food after consume then give you a heart?
there is an ItemStopUseAfterEvent you can use
Ohhh
you can look here for an example:
https://jaylydev.github.io/scriptapi-docs/1.21.30/classes/_minecraft_server_1_14_0.WorldAfterEvents.html#itemCompleteUse
world.afterEvents.itemStopUse.subscribe((event: ItemStopUseAfterEvent) => {
const player = event.source;
const item = event.itemStack;
Like this
@proud vector
Ohhhh
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})`
);
});
// 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
are you using chatgpt ?
I'm not
the code itself is reflecting your answer..
you are a bad liar..
🤭
¿Hay algún problema con esta línea de código? world.beforeEvents.chat.subscribe((event) => {
I don't talk English a lot I'm Mexican
I had it like that but I change it Ja ja
what is Ja ja?
Jaja is Haha
[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
chatSend it's Beta, can't use in stable
