#The block.typeId and hasTag function is not working

1 messages · Page 1 of 1 (latest)

tall spade
#

I got this script where after a players breaks a block it will get all entities in radius of 2 and kill them

world.afterEvents.playerBreakBlock.subscribe((e) =>{
    const block = e.block;
    const { dimension } = block;
    const location = block.center();
    if (block.typeId == "si:corpse") {
        const entities = dimension.getEntities({location:location, maxDistance: 2});
        entities.forEach(entity =>{
            if (entities.typeId == "si:corpse") {
                entity.remove();
            }
        })
    }
})
tall spade
#

content logs?

tall spade
indigo wasp
#

did you turn it on though

tall spade
#

yeah it's on

#

the if statement is the only part is not working

indigo wasp
#

then the check is failing

tall spade
#

the event triggers but the if is ain't working

tall spade
#

I don't know why it can't read the typeId

indigo wasp
#

what about using beforeEvents

tall spade
#

it's the same

#

tried hasTag() and mathcing the typeId both method didn't work with after and before events

#

however

#

On placeblock it works

tall spade
#

yeah

#

im looking at that right now

indigo wasp
#

try using matches instead

#

matches("si:corpse")

#

from brokenBlockPermutation

#

actually hold on

tall spade
#
world.afterEvents.playerBreakBlock.subscribe((e) =>{
    const block = e.block;
    const { dimension, brokenBlockPermutation } = block;
    const location = block.center();
    if (brokenBlockPermutation.matches("si:corpse")) {
        const entities = dimension.getEntities({location:location, maxDistance: 2});
        entities.forEach(entity =>{
            if (entities.typeId == "si:corpse") {
                entity.remove();
            }
        })
    }
})
indigo wasp
#

brokenBlockPermutation is from event

tall spade
#

it cannot read property

indigo wasp
#

not block

tall spade
#

yeah

indigo wasp
#
world.afterEvents.playerBreakBlock.subscribe((e) =>{
    const { block, brokenBlockPermutation } = e;
    const { dimension } = block;
    const location = block.center();
    if (brokenBlockPermutation.matches("si:corpse")) {
        const entities = dimension.getEntities({location:location, maxDistance: 2});
        entities.forEach(entity =>{
            if (entities.typeId == "si:corpse") {
                entity.remove();
            }
        })
    }
})
#

whoop

#

made a typo

#

should be good now

tall spade
#

welp

#

it works

#

why won't the block get read though

indigo wasp
#

i dunno actually

#

but considering theres brokenBlockPermutation, its prob the game limitation and they made that

balmy dove
#

hope it's clear now

wheat robin
#

use beforeEvents and save block id

#
world.beforeEvents.playerBreakBlock.subscribe(data => {
  if (data.block.typeId != "si:corpse") return;
  system.runTimeout(() => {
    // Code here
  }, 1)
})