#How to change the state of a block with script?

1 messages · Page 1 of 1 (latest)

deep fox
#

I want to make that when I touch a block with an item, this block changes its state, can you help me with the code?

import {world, ItemStack, BlockPermutation, Block, system} from '@minecraft/server';

world.afterEvents.itemUseOn.subscribe((event) => {
console.log('itemuse found');
if (event.itemStack.typeId == "bd:knife" && event.block.typeId == "bd:bar"){
console.log('if found');
event.block.setPermutation(permutation);
}
})

mental panther
#
import {world, ItemStack, BlockPermutation, Block, system} from '@minecraft/server';

world.afterEvents.itemUseOn.subscribe((event) => {
console.log('itemuse found');
    if (event.itemStack.typeId == "bd:knife" && event.block.typeId == "bd:bar"){
console.log('if found');
    event.block.setPermutation(event.block.permutation.withState('your state', 'your value'));
    }
});```
fringe tendon
#

Or to get a new permutable block you can do permutation.resolve(id, states) (i think)

deep fox