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

GameTest Interface: can't get block inventory container correctly

XMLWordPrintable

    • Unconfirmed
    • Windows

      Firstly, I beg your parden for my poor english.

      Question description

      As the title said, I can't get the block inventory container component in GameTest code. As the code below, I've tried that it will works perfectly if I comment the code at last line, and the whole code will be invalid once I uncomment it.(PS: The coordinate (-32, 64, 14) is a position which near my spawn point in the test world)

      import { World, Commands, BlockTypes, BlockPermutation, BlockProperties, BlockInventoryComponentContainer, BlockInventoryComponent, BlockLocation, Items, ItemStack } from 'Minecraft';
      
      function print(msg) { 
          Commands.run('say ' + msg); 
      }
      
      let gameTick = 0;
      World.events.tick.subscribe(() => {
        gameTick++;
        if (gameTick === 20) {
          gameTick = 0;
          const block = World.getDimension("overworld").getBlock(new BlockLocation(-32, 64, 14));
          if (block.getBlockData().getType().getName() !== BlockTypes.chest.getName()) {
            block.setType(BlockTypes.chest);
          }
          const inventoryComponent = block.getComponent("inventory");
          for (const key in inventoryComponent) {
            print(key);
          }
          //Comment the code below, the code will run normally
          const inventoryContainer = inventoryComponent.container;
        }
      });
      

      Solution Explore

      I've tried to use the code below to print the block inventory component's child properties, it proved that the block inventory component does contain the "container" property, at least contains the key.

      for (const key in inventoryComponent) {
        print(key);
      }
      

      But the strange thing is, I can't get it by the form of "<Object>.<attributeName>", after testing, the code below is the only way that I know to get the container.

      const inventoryComponent = block.getComponent("inventory");
      let inventoryContainer;
      for (let i in inventoryComponent) {
        inventoryContainer = inventoryComponent[i];
        break;
      }
      print(typeof inventoryContainer);

      Then I tried to print the container object I've got, the print result shows the same properties as the Container object in the document.

      for (const key in inventoryContainer) {
            print(key);
      }
      

      At Last

      After all this testing, my conclusion is that this is a bug. So I wrote this feedback.
      I really hope you can find out the cause and fix it as fast as you can.

        1. image-2021-06-11-16-28-29-422.png
          399 kB
          Qian Shan yao
        2. image-2021-06-11-16-28-29-559.png
          46 kB
          Qian Shan yao
        3. image-2021-06-11-16-30-23-427.png
          7 kB
          Qian Shan yao
        4. image-2021-06-11-16-31-51-292.png
          14 kB
          Qian Shan yao
        5. image-2021-06-11-16-32-37-180.png
          153 kB
          Qian Shan yao

            QianShanyao Qian Shan yao
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: