#custom component not registering

1 messages · Page 1 of 1 (latest)

marsh swan
#

console.warn('slowness.js loaded');

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

world.beforeEvents.worldInitialize.subscribe((data) => {
BlockComponentRegistry("bshy:slowness", {
onApply() {
console.log("Slowness component applied!");
}
});
});

#

Errors

#

[Scripting][warning]-slowness.js loaded

[Scripting][warning]-main.js loaded

[Scripting][error]-TypeError: must be called with new at BlockComponentRegistry (native)
at <anonymous> (custom_components/slowness.js:10)

#

can somone help please

fair pike
marsh swan
#

@fair pike can i ask you a question

#

so ive changed it to onStepOn and it works with a full collision box, but my block has no collison box and is till want it to work is that still possible

fair pike
# marsh swan so ive changed it to onStepOn and it works with a full collision box, but my blo...

I don't think it's possible, you can use onTick to constantly check if there is an entity at the block location

const slownessComponent = {
    onTick({ block }) {
        const entities = block.dimension.getEntitiesAtBlockLocation(block.location);
        if (entities.length === 0) return;
        entities.forEach((entity) => {
            entity.addEffect('slowness', 10 * 20, { amplifier: 0, showParticles: true });
        });
    }
}
marsh swan
#

@fair pike can you only change block states with scripts ?