Uploaded image for project: 'Minecraft (Bedrock codebase)'
  1. Minecraft (Bedrock codebase)
  2. MCPE-168873

[Script API] Equipment set on entities using EntityEquipmentInventoryComponent does not reflect on the client until the entity is re-rendered

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 1.20.0.23 Preview
    • 1.20.0.20 Preview, 1.19.80.24 Preview, 1.19.80.23 Preview, 1.19.80.22 Preview, 1.19.80.21 Preview, 1.19.73
    • None
    • Unconfirmed
    • Multiple

      Equipment set on non-player entities through getComponent('equipment_inventory').setEquipment will not render properly or be read by the client side until the entity is re-rendered. I have an entity using this function to add an item to its hand slot, and when added the item is not rendered on the mob. Once I save and open the world again, or I move away from the entity until it is no longer being rendered and return, it is properly rendered!
      Another situation that shows that the problem is with the client in general: I have an animation added to a second entity once it holds an item. My code is:
       

            "scripts": {
               "animate": [
                 { "bellied": "q.is_item_equipped" }
               ]
             },

      It means the "bellied" animation should render once the entity hand slot is not empty. I remove the item from the entity inventory using:

      <entity>.getComponent('equipment_inventory').setEquipment('mainhand', null);

      Once I set it to null, the entity can again pick up items, what means the item was really removed. Although the bellied animation continues playing! Once I have my entity unrendered and rendered again, it is properly fixed and the entity does not play the animation. Hopefully this desync error gets  fixed as soon as possible, this component is super useful! I have not tested it, but I believe this issue does not happen to players.

      Update: Added showcase behavior pack and Steps to Reproduce.

      I made this little script code for testing the EntityEquipmentInventoryComponent funcionality.

      import { ItemStack, Player, world } from '@minecraft/server';
      
      world.events.entityHit.subscribe((data) => {
        if (
          data.entity instanceof Player &&
          data.hitEntity?.typeId === 'minecraft:husk'
        ) {
          let husk = data.hitEntity;
          let huskInv = husk.getComponent('equipment_inventory');
          huskInv.setEquipment('head', new ItemStack('diamond_helmet'));
          world.sendMessage('Diamond Helmet equipped! Now get away until the Husk is no longer being rendered, then return! Only then the Diamond Helmet should render.');
        }
      });;

      Steps to Reproduce:

      1. Open a world with the attached behavior pack enabled. Enable the experiments Beta API option.
      2. Summon a Husk through the command /summon husk. OBS: the world.sendMessage part of the script crashed the world when I did run it before using a command on the chat before, which shows another bug but with the function.
      3. Hit the Husk. A message will be sent in the chat, so just do what it says!

      Observed Results:
      When hitting a Husk, a Diamond Helmet is equipped to it. But it is not instantly rendered on the mob head! When getting away until the mob is not being rendered and returning, then the Diamond Helmet should be rendered.

      Expected Results:
      The equipment should instantly be rendered after equipping! Just how it works for equipping on the player instead of on a third entity.

            JeanLucasMCPE-TNTgames Jean Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: