#How to get/set a block at a position?

12 messages · Page 1 of 1 (latest)

elder ether
#

How do I change a block at a given position? I know the block.place event let's you easily change one relevant block but if I want to change blocks around it I have no idea.

const level = event.block.level
const pos = [1,2,3]
const id = 'minecraft:dirt'
level.set(pos, id)
level.setBlock(pos, id)
level.setBlockState(pos, id)

None of those last 3 lines work because those functions don't seem to exist there unlike what I've read.

rare brookBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

thin olive
#

Tyr
level.getBlock(pos).set(id)

elder ether
#

Well this doesn't return an error but it's definitely not making any visible changes...

onEvent('block.place', event => {
    const level = event.block.level
    const pos = [60, 100, 30]
    const block = level.getBlock(pos)
    block.set('minecraft:dirt')
})```
elder ether
#

Has anyone ever made this work in 1.18?

thin olive
#

Try .getBlock(x,y,z) instead

elder ether
#

Huh, that actually works, thank you!

#

What I want to know now is why VSC says the function takes only one argument, and why there's no help on the wiki for this?

mossy terrace
#

There's so many things exposed, and the fact that KJS can refer to Java classes means that documenting Minecraft stuff is needed.

thin olive
mossy terrace
#

Hmm, so [number, number, number] can't be type wrapped into BlockPos but can be type wrapped into Vec3?

thin olive
#

Idk, but it seems to not be wrapped to BlockPos