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.

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

              Created:
              Updated:
              Resolved: