#I wanna make interactive blocks like light u can turn on and, doors, and computers, where?

1 messages · Page 1 of 1 (latest)

jagged lance
#

How and where can i learn it, is there someone who wants to take their time and teach?

quaint prism
#

You would need to use a custom component which modifies the blocks state

azure boughBOT
#
HCF Removal and Custom Components

The Holiday Creator Features experimental toggle has been removed. Along with it includes JSON block and item events. This functionality has been replaced with custom components.

Please take a look at the following links to learn more about custom components:

Bedrock Wiki

MS Docs

quaint prism
#

Those pages should explain what you need for custom components

#

Here's the specific custom component you'd need to use:

https://wiki.bedrock.dev/blocks/block-events#player-interact

And here's how you set a block state with them:

https://wiki.bedrock.dev/blocks/block-event-migration#set-block-state

#

Let me know if you need any more help after reading that!

proper mountain
#
import { world, BlockComponentPlayerInteractEvent } from "@minecraft/server";
import { BlockStateSuperset } from "@minecraft/vanilla-data";

const LIGHT_CONTROL_COMPONENT = "mkt:light_control_simple";
const LIGHT_CONTROL_STATE = "mkt:light_is_on";

world.beforeEvents.worldInitialize.subscribe((ievent) => {
  ievent.blockComponentRegistry.registerCustomComponent(LIGHT_CONTROL_COMPONENT, {
    onPlayerInteract: (event: BlockComponentPlayerInteractEvent) => {
      let block = event.block;
      const perm = block.permutation;
      const light_is_on = perm.getState(LIGHT_CONTROL_STATE as keyof BlockStateSuperset);
      block.setPermutation(perm.withState(LIGHT_CONTROL_STATE as keyof BlockStateSuperset, !light_is_on));
    },
  });
});
#

this basic script will work (thats in "ts" - remove types for "js" version)

#

then permutaions for light_is_on 0: light = 0 1: light=14

#

this is a simple lantern example i made a little bit ago

alpine wave
proper mountain
#

prety sure it had a license file with it

#

not a alot of code - its all pasted above -vs the github example. I shared the code here so you can use that for sure.

alpine wave
#

Oh thank you, how i credit you?