#I wanna make interactive blocks like light u can turn on and, doors, and computers, where?
1 messages · Page 1 of 1 (latest)
You would need to use a custom component which modifies the blocks state
Info on block states: https://learn.microsoft.com/en-us/minecraft/creator/reference/content/blockreference/examples/blockstatesandpermutations?view=minecraft-bedrock-stable
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
- Block Events
- Block Events Migration to Custom Components
- Item Events
- Item Events Migration to Custom Components
MS Docs
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!
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
Hey sorry to ping, but can i ask permission to use this?
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.
Oh thank you, how i credit you?