#Error with BlockTypes

1 messages · Page 1 of 1 (latest)

rare gulch
#

I can't understand what's the problem here can anyone help me fix it this error came in latest version of minecraft it was not a problem before

import {
  BlockTypes,
  ItemStack,
  ItemTypes,
  world
} from '@minecraft/server';

await null;

function createRandomBlockMapping() {
  const validBlockTypes = BlockTypes.getAll().filter(blockType =>
    ItemTypes.get(blockType.id) !== undefined
  );

  const shuffledBlockTypes = validBlockTypes.slice().sort(() => Math.random() - 0.5);

  const mapping = new Map();
  for (let i = 0; i < validBlockTypes.length; i++) {
    mapping.set(validBlockTypes[i].id, shuffledBlockTypes[i].id);
  }

  return mapping;
}

const randomizedBlockMap = createRandomBlockMapping();

world.afterEvents.playerBreakBlock.subscribe(event => {
  const brokenBlockId = event.brokenBlockPermutation.type.id;

  if (!randomizedBlockMap.has(brokenBlockId)) return;

  const droppedItem = new ItemStack(randomizedBlockMap.get(brokenBlockId));
  event.block.dimension.spawnItem(droppedItem, event.block.location);
});

it throws error

    at <anonymous> (mrg.js:25)```
lime musk
#

Hmm, I'm not sure why that method requires permissions but wrap it in system.run() to offset the calling so it executes during a tick where it has permission.

ember tundra
#

even a begginer could come here and say: use system.run()

#

i dont even call myself a developer bruh
.

#

wait wha-

await null;
#

why do you use it there 😭

#

i mean bro using await null is not good.

#

either do worldLoad for getting values or do system.run() or do system.waitTicks(1) for solving privilage problems

rare gulch
ember tundra
#

:) xd hahhahahhaahah
-# dont take it seriously