3

Item Events not working in 1.20.30 - Is there a fix? [RESOLVED - 50%]

NeonNinja3's Avatar NeonNinja310/2/23 4:05 pm history
3 emeralds 815 5
12/20/2023 7:10 pm
NeonNinja3's Avatar NeonNinja3
UPDATE: There are 3 different ways of having custom foods apply status effects that work in the latest Bedrock version.

1. Revert the BP .item.json files to format version 1.10 (don't forget to add the extra .item.json file in the RP) - it will still work and will allow using the "effects" property of "minecraft:food." Downsides: Doesn't allow you to choose where the items get placed in the Creative Inventory, and requires adding redundant files to the RP.

2. Use the 1.16.100 format with Experimental Features enabled (see LieutSavg99's reply and linked examples). This allows you to still use the menu category and item group properties, unlike 1.10.

3. Use the 1.20.30 file format, remove all effect-related functionality from the .item.json file, and add it back in with a server-side script. This allows setting the inventory category and item group without requiring you to use experimental features for the pack. You can see an example of the script syntax for the Amethyst Apple here: https://gaming.stackexchange.com/a/404675/306012



Hi everyone!

Recently I started my first behavior/resource pack for Bedrock Edition, which is supposed to have custom tools and foods. But, I have encountered two similar problems where there doesn't seem to be a way to make tools wear out when being used, or to make foods apply status effects to the player.

Everything else about the custom items works fine - the tools are usable and have correct mining speeds, crafting recipes etc., the foods are edible and restore correct hunger and saturation - just no effects. Using the custom tools as weapons causes their durability to decrease, as expected, but mining blocks does not, regardless of whether the blocks are or are not listed in "destroy_speeds."

It seems like the "effects" array inside the "minecraft:food" component no longer works (in formats above 1.10 or maybe 1.16?) The vanilla behavior pack which I was using as a template has the Golden Apple file with version 1.10. Obviously, the vanilla Golden Apple in the game still works correctly :) But, trying to use this same format to add custom items in new packs causes errors such as the texture being missing and the item name not displaying correctly.

I tried implementing a workaround using a custom event (which gets called by "on_consume") to apply the effects instead of the "effects" array, but I got a warning in the console that [Item][error]-eat | add_mob_effect | child 'add_mob_effect' not valid here, and the effects still did not work. (The same thing with custom tools and child 'damage' not valid here.) Turning on Experimental Features did not fix the problem.

I was following along with the official tutorial here, which has complete guides to making custom blocks and entities, but only has documentation pages for items. Unfortunately, the item documentation is incomplete and/or out of date in some places. It lists all possible item components, but does not always give examples of the correct syntax to use for the values of those components (or for events). The Bedrock Wiki site has a custom item tutorial showing how to make a food that applies an effect to the player, but it is for an earlier pack format and no longer works (as in, the effect is not applied) in 1.20.30. I have not been able to find any video tutorials with newer syntax than in the two references I linked.

No answers on StackOverflow or Arquade, either.

I tried downloading a finished behavior pack from a professional developer, to use as a reference to see what I was doing wrong in my own files, but his custom tools demonstrated the exact same issue as mine (failed to decrement durability bar when mining) in the latest version, even though the pack was listed as compatible with 1.20.30. This leads me to believe there may not currently be a working solution to this issue.

But if anyone HAS found a solution, this seems like the most likely place :D

Here is my diamond_apple.item.json file:

{
"format_version": "1.20.30", // Item won't show up if this is set back down to 1.10
"minecraft:item": {
"description": {
"identifier": "addtns:diamond_apple",
"menu_category": {
"group": "itemGroup.name.crop",
"category": "nature"
}
},
"components": {
"minecraft:hand_equipped": false,
"minecraft:max_stack_size": 64,
"minecraft:icon": {
"texture": "diamond_apple"
},
"minecraft:display_name": {
"value": "Diamond Apple"
},
"minecraft:hover_text_color": "cyan", // This, "#0000ff", and "light_blue" don't work, but "blue" and "light_purple" do. It's supposed to be the same color as for the Golden Apple.
"minecraft:use_duration": 2,
"minecraft:use_animation": "eat",
"minecraft:food": {
"nutrition": 4, // Same as other apples
"saturation_modifier": 9.6, // Same as Golden Apple
"can_always_eat": true,
"effects": [
{
"name": "haste",
"chance": 1.0,
"duration": 120,
"amplifier": 1
},
{
"name": "jump_boost",
"chance": 1.0,
"duration": 120,
"amplifier": 1
},
{
"name": "regeneration",
"chance": 1.0,
"duration": 5,
"amplifier": 2
}
]
},
"minecraft:on_consume": {
"event": "eat",
"target": "holder" // Credit to IcyFlag from www.minecraftforum.net/forums/minecraft-pocket-edition/mcpe-mods-tools/mcpe-mod-tool-discussion/3062942-need-help-with-making-a-custom-item for the suggestion of making the target here the same as in the event
}
},

// The event displays a console warning and does not work.
"events": { // Syntax: Credit goes to CyanSaber and digitaldruid1388 (from this video: www.youtube.com/watch?v=D1yF46NwmDk and a comment)
"eat": {
"sequence": [
{
"add_mob_effect": {
"effect": "haste",
"duration": 120,
"amplifier": 1,
"target": "holder"
}
},
{
"add_mob_effect": {
"effect": "jump_boost",
"duration": 120,
"amplifier": 1,
"target": "holder"
}
},
{
"add_mob_effect": {
"effect": "regeneration",
"duration": 5,
"amplifier": 2,
"target": "holder"
}
}
]
}
}
}
}
Posted by NeonNinja3's Avatar
NeonNinja3
Level 28 : Expert Unicorn
28

Create an account or sign in to comment.

5

NeonNinja3
12/20/2023 7:10 pm
Level 28 : Expert Unicorn
NeonNinja3's Avatar
Here is a new solution to the tool durability problem, using the 1.8.0-beta version of the @minecraft/server module: gaming.stackexchange.com/questions/405592/item-component-on-dig-has-been-removed-how-to-handle-tool-durability-in-new
1
LieutSavg99
10/07/2023 10:58 pm
Level 21 : Expert Procrastinator
history
LieutSavg99's Avatar
I am not the greatest at commands or coding in general, but I wanted to help. :)

I've uploaded a "diamond_apple" .json file for download/review in the following MediaFire link:
https://www.mediafire.com/folder/bxflq93og2v88/Public

I'm not sure whether this will help you or anyone in the future, but I've uploaded a "resources" .txt file in the following MediaFire link; a list of YouTube videos that served as useful resources for add-on development:
https://www.mediafire.com/folder/9adk9gv1bty7i/trading_revamp
3
NeonNinja3
10/08/2023 2:00 am
Level 28 : Expert Unicorn
NeonNinja3's Avatar
That's really cool, I didn't know that trick for changing the text color! I don't want my pack to require the Experimental Features, so for now I'm sticking with the server-side scripting solution, but your method is much more efficient running the commands from inside the "on_consume" event!
2
NeonNinja3
10/08/2023 1:52 am
Level 28 : Expert Unicorn
NeonNinja3's Avatar
LieutSavg99 Wow, thank you! I will definitely take a look. If you're interested, I found my own working solution here: https://gaming.stackexchange.com/questions/404589/custom-items-on-consume-event-gives-error-child-add-mob-effect-not-valid-her but yours may very well be better :D
1
LieutSavg99
10/08/2023 2:10 am
Level 21 : Expert Procrastinator
LieutSavg99's Avatar
I hope this resolves any issues you've been having! :)

[NOTE: It is recommended to set the "min_engine_version" within the "manifest" .json file of any add-on to [1, 16, 0] that utilizes those custom item changes.]
2
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome