#Detect explosion on block

1 messages ยท Page 1 of 1 (latest)

lapis lava
#

Hi, I am trying to detect when a block is broken by explosion, as far as I can see, ExplosionAfterEvent is in stable, but I can't work out how I should be using it, here is what I have so far:

import { world } from "@minecraft/server";

const blockTypes = [
  "minecraft:dirt"
];


world.afterEvents.Explosion.subscribe((event) => {
  const { brokenBlockPermutation } = event;
  
  blockTypes.forEach((id) => {
    if (brokenBlockPermutation.matches(id)) {
      event.source.dimension.runCommand(
        `summon minecraft:pig ${event.block.x} ${event.block.y} ${event.block.z}`
      );

      return;
    }
  });
});

any help will be greatly appreciated ๐Ÿ™‚

robust axle
#
import { world } from "@minecraft/server";

const blockTypes = [
  "minecraft:dirt"
];


world.afterEvents.explosion.subscribe( event => {
  const { brokenBlockPermutation } = event;
  
  blockTypes.forEach( id => {
    if (brokenBlockPermutation.matches(id)) {
      event.source.dimension.runCommand(
        `summon minecraft:pig ${event.block.x} ${event.block.y} ${event.block.z}`
      );

      return;
    }
  });
});
#

@lapis lava

lapis lava
#

@robust axle Thanks, it looks like the only difference between our codes is the capitalisation of "explosion". But I am still getting an error

[Scripting][error]-Plugin [Test - 0.0.1] - [cyan/test/main.js] ran with error: [TypeError: cannot read property 'subscribe' of undefined    at <anonymous> (cyan/test/TestExplode.js:8)
]
#

ive copied and pasted yours btw

robust axle
#

whats ur game ver and api ver

#

this requires 1.10.0-beta

lapis lava
#

Contents of the @minecraft/server.ExplosionAfterEvent class.

robust axle
#

well than try stable

lapis lava
#

I just changed the script version to 1.8.0 and it still didnt work.

afaik I am using stable features

#

im on 1.20.60 too

robust axle
#

wats error

lapis lava
#

it cannot read property 'subscribe' of undefined, js:8

which is this line:

world.afterEvents.explosion.subscribe( event

robust axle
#

ur using dev packs right?

#

cuz then cache will be issue

lapis lava
#

I dont think so... how would I know? I am just using nraml MC, with Visual Studio. I have used bridge for some files, so maybe that has cached them, i will check

robust axle
#

there 2 types of packa

#

behaviour packs
development behaviour packs

lapis lava
#

oh, sorry, I am using dev

robust axle
#

hmm

#

weird

dawn reef
#

send your pac

#

(manifest or the script file is enough)

lapis lava
#

okay, 1 sec, need to remove some bits (NDA)

#

Here is the manifest:

{
    "format_version": 2,
    "header": {
        "name": "TEST",
        "description": "TEST",
        "uuid": "1b5b1173-373e-47f0-d570-99a3c3396007",
        "version": [
            1,
            0,
            0
        ],
        "min_engine_version": [
            1,
            20,
            60
        ]
    },
    "metadata": {
        "authors": [
            "CyanSaber"
        ]
    },
    "modules": [
        {
            "description": "Behavior",
            "version": [
                1,
                0,
                0
            ],
            "uuid": "8a4c393d-0f57-2465-5ac0-9b6cd87ed368",
            "type": "data"
        },
        {
            "description": "Script resources",
            "language": "javascript",
            "type": "script",
            "uuid": "0bc05e4d-73ce-454c-bc43-ed1b4df5a44f",
            "version": [
                0,
                0,
                1
            ],
            "entry": "cyan/test/main.js"
        }
    ],
    "dependencies": [
        {
            "uuid": "3a2164f6-9793-5a05-57c8-dc685c1d006d",
            "version": [
                1,
                0,
                0
            ]
        },
        {
            "module_name": "@minecraft/server",
            "version": "1.8.0"
        }
    ]
}

Here is the script:

import { world } from "@minecraft/server";

const blockTypes = [
  "minecraft:dirt"
];


world.afterEvents.explosion.subscribe( event => {
  const { brokenBlockPermutation } = event;
  
  blockTypes.forEach( id => {
    if (brokenBlockPermutation.matches(id)) {
      event.source.dimension.runCommand(
        `summon minecraft:pig ${event.block.x} ${event.block.y} ${event.block.z}`
      );

      return;
    }
  });
});
#

so my script module is on the latest stable version 1.8.0 and my game is on 1.20.60

dawn reef
#

I'll check, maybe stable docs lie again

lapis lava
#

yeah, maybe. I was looking at this like 2 weeks ago and it was still beta iirc, I thought they had released it with 1.20.60 maybe

#

thanks btw ๐Ÿ˜‰

dawn reef
#

Yea, same thing happened to me. Ig still beta

#

Same case with playerInteractWith...

Even though it appears in stable docs, it is still in fact in Beta-API