#How do you play a sound at a block location?

1 messages · Page 1 of 1 (latest)

exotic turtle
#

Converting my mob head sound scripts from 1.19.60 to 1.19.70 . I use these two scripts in order to

world.events.beforeItemUseOn.subscribe((eventData) => {

    const block = eventData.source.dimension.getBlock(eventData.blockLocation);


    const blockAbove = eventData.source.dimension.getBlock({x:block.location.x, y:(block.location.y)++, z:block.location.z});

    if (block.type.id == "minecraft:noteblock") {
        const location = block.location;
        if (blockAbove.type.id == "runecraft:witch_head_block") {
            world.playSound("mob.witch.ambient", {location});
        }
        else if (blockAbove.type.id == "runecraft:panda_head_block") {
            world.playSound("mob.panda.eat", {location});
        }
        else if (blockAbove.type.id == "runecraft:panda_head_brown_block") {
            world.playSound("mob.panda.sneeze", {location});
        }
        else if (blockAbove.type.id == "runecraft:llama_head_white_block") {
            world.playSound("mob.llama.idle", {location});
        }
        else if (blockAbove.type.id == "runecraft:llama_head_gray_block") {
            world.playSound("mob.llama.hurt", {location});
        }
        else if (blockAbove.type.id == "runecraft:llama_head_brown_block") {
            world.playSound("mob.llama.spit", {location});
        }
        else if (blockAbove.type.id == "runecraft:llama_head_cream_block") {
            world.playSound("mob.llama.angry", {location});
        }
    }
})```

I am unable to get the sound to play at the location. I don't get any errors in game so I'm not really sure what to do. I have tried several ways of putting the location in.
woven tangle
exotic turtle
#

yeah, doesn't work

plush vortexBOT
#
Debug Result

There are errors in this [code](#1071562046291857509 message):

<repl>.js:3:65 - error TS2551: Property 'blockLocation' does not exist on type 'BeforeItemUseOnEvent'. Did you mean 'getBlockLocation'?

3     const block = eventData.source.dimension.getBlock(eventData.blockLocation);
                                                                  ~~~~~~~~~~~~~

  @minecraft/server.d.ts:161:13
    161             getBlockLocation(): Vector3;
                    ~~~~~~~~~~~~~~~~
    'getBlockLocation' is declared here.

woven tangle
#
world.events.beforeItemUseOn.subscribe((eventData) => {

    const block = eventData.source.dimension.getBlock(eventData.getBlockLocation());


    const blockAbove = eventData.source.dimension.getBlock({x:block.location.x, y:(block.location.y)++, z:block.location.z});

    if (block.typeId == "minecraft:noteblock") {
        const location = block.location;
        if (blockAbove.typeId == "runecraft:witch_head_block") {
            world.playSound("mob.witch.ambient", {location});
        }
        else if (blockAbove.typeId == "runecraft:panda_head_block") {
            world.playSound("mob.panda.eat", {location});
        }
        else if (blockAbove.typeId == "runecraft:panda_head_brown_block") {
            world.playSound("mob.panda.sneeze", {location});
        }
        else if (blockAbove.typeId == "runecraft:llama_head_white_block") {
            world.playSound("mob.llama.idle", {location});
        }
        else if (blockAbove.typeId == "runecraft:llama_head_gray_block") {
            world.playSound("mob.llama.hurt", {location});
        }
        else if (blockAbove.typeId == "runecraft:llama_head_brown_block") {
            world.playSound("mob.llama.spit", {location});
        }
        else if (blockAbove.typeId == "runecraft:llama_head_cream_block") {
            world.playSound("mob.llama.angry", {location});
        }
    }
});
plush vortexBOT
#
No errors

No errors in [code](#1071562046291857509 message)

exotic turtle
#

I think that's what it was before