mojira.dev
MCPE-189938

custom copper hoe can't play animation when hoeing

I found a suspicious bug when I was customizing the tool.

According to the official documentation, I think I should use "onUseOn" to define the behavior of a custom copper pickaxe, but that doesn't look like vanilla's hoe. This bothered me for a long time, I consulted a lot of official documentation and was dizzy.I've tried things like playanimation or molang, but I still haven't found a way to get the player to wave their arms. At this point, I don't think I can solve this problem, so I have to contact your team and hope to give you constructive suggestions.

[minecraft/server.ItemUseOnEvent Class | Microsoft Learn|https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/itemuseonevent?view=minecraft-bedrock-stable]

Here are the two ways to write the definition of my item and the script:

item define:
{
    "format_version": "1.21.50",
    "minecraft:item": {
      "description": {
        "identifier": "reality:copper_hoe",
        "menu_category": {
          "category": "equipment",
          "group": "itemGroup.name.hoe"
        }
      },
      "components": {
        "minecraft:icon": {

[media][media]

          "textures": {

            "default": "copper_hoe"
          }
        },

        "minecraft:can_destroy_in_creative": { "value": true},
        "minecraft:damage": { "value": 3 },
        "minecraft:hand_equipped": { "value": true },
        "minecraft:enchantable": { "slot": "hoe", "value": 10 },
        "minecraft:glint": { "value": false },
        "minecraft:digger": {
          "use_efficiency": true,
          "destroy_speeds": [
            {
              "speed": 16,
              "block": { "tags": "q.any_tag('minecraft:is_hoe_item_destructible')" }
            }
          ]
        },
        "minecraft:durability": {
          "max_durability": 192
        },
        "minecraft:durability_sensor": {
          "durability_thresholds": [
              { "durability": 4, "sound_event": "copper.wax.off" }
          ]
        },
        "minecraft:max_stack_size": { "value": 1 },
        "minecraft:repairable":{
          "repair_items": [
              { "items":[ "minecraft:copper_ingot"], "repair_amount": 86 }
            ]
        },
        "minecraft:tags": {
          "tags": [
            "minecraft:is_hoe",
            "minecraft:is_tool",
            "minecraft:iron_tier"
          ]
        },

        "minecraft:custom_components": ["reality:copper_hoe"]
      }
    }
  }
 

script:

First way:

As written, the custom copper hoe can hoe the ground, but it does not have an animation like an item using a waving arm.

 
 
import { world, system, ItemComponentTypes, ItemStack } from "@minecraft/server";
world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.itemComponentRegistry.registerCustomComponent('reality:copper_hoe', {
        onUse(event){
            world.sendMessage("debug");
            const item = event.itemStack.typeId;
            world.sendMessage(String(item));

            const player = event.source;
        }
 
    });
});
 
world.beforeEvents.itemUseOn.subscribe((event) => {
    // event.source.sendMessage("itemUseOn")
    if (event.itemStack.typeId ==='reality:copper_hoe' && allDirtsIds.includes(event.block.typeId)) {
        event.source.runCommandAsync("playsound use.gravel @s ~ ~ ~ 1 1 16");
    }
});//持续事件
 
 

Second way:

Written this way, a custom copper hoe can also hoe the ground, but the frequency of waving the arm is incorrect. The vanilla hoe can hoe the ground at no intervals under the grass tag block. My second way of writing it, the custom Copper Pickaxe will be able to swing its arms under non-grass blocks, and it will also be able to swing its arms all the time on farmlands, as well as not hoeing the ground continuously.

 
world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.itemComponentRegistry.registerCustomComponent('reality:copper_hoe', {
        onUseOn(event){
            const item = event.itemStack.typeId;
            world.sendMessage(String(item));
        },
    });
});
 
world.beforeEvents.itemUseOn.subscribe((event) => {
    // event.source.sendMessage("itemUseOn")
    if (event.itemStack.typeId ==='reality:copper_hoe' && allDirtsIds.includes(event.block.typeId)) {
        event.source.runCommandAsync("playsound use.gravel @s ~ ~ ~ 1 1 16");
    }
});//持续事件
 
 
In addition, the item's component tags specify is_hoe and other functions that "can affect whether the hoe hoes the ground or not, rather than replacing the original block in the script", and I beg to see it in the documentation, because the document only shows the relevant tag, and does not say the function of the name tag.
[Item Tags | Bedrock Wiki|https://wiki.bedrock.dev/items/item-tags.html]
[Item Documentation - minecraft:tags | Microsoft Learn|https://learn.microsoft.com/en-us/minecraft/creator/reference/content/itemreference/examples/itemcomponents/minecraft_tags?view=minecraft-bedrock-stable]

Attachments

Comments 1

Please attach an add-on that can be used to reproduce the issue.

This report has been temporarily resolved as Awaiting Response. It will automatically reopen when you comment with new information. Please provide all requested information. Reports that do not contain enough information may be closed as Incomplete.

Many players find this Bug Report Creation Form useful for filling in all helpful information.

FalsonAuYeung

(Unassigned)

Unconfirmed

Windows

1.21.51

1.21.51 Hotfix

Retrieved