#Modify/change block upon placement

14 messages · Page 1 of 1 (latest)

blissful violet
#

I'm trying to change specific block to another one upon placement. But I just don't know how. (Yes, I checked wiki, but didn't find anything useful)
My last attempt:

BlockEvents.placed (event => {
 if (event.block.id == "minecraft:stone") {
     console.info("GOD SAVE ME")
     event.block.set("minecraft:dirt")
 }
})
proven oysterBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

unborn osprey
#
BlockEvents.placed ('minecraft:stone', event => {
 //no need for if
})

You can filter block with this syntax in 1.19 iirc no need for if

#

and to set block event.level.getblock(pos).set('blockid')

blissful violet
#

A new error has appeared:
#521: Error occurred while handling event 'BlockEvents.placed': TypeError: Cannot find function getblock in object ServerLevel[New World]

BlockEvents.placed ( 'minecraft:stone', event => {
     console.info("GOD SAVE ME")
     event.level.getblock(event.block.pos).set('minecraft:dirt')
})
unborn osprey
#

do you have probejs ?

blissful violet
#

No....

sonic pathBOT
#

ProbeJS is an addon mod for KubeJS that generates typings files for VSCode, allowing VSCode to offer autocompletions for a ton of things!

Mod by @opal lark

unborn osprey
#

ah it is getBlock() not getblock()

#

your B is lowercase

#

sory mb i wrote lowercase in first place hehehe

blissful violet
#

This works ... very strange...
It definitely does not work like this

BlockEvents.placed ('minecraft:stone', event => {
     event.level.getBlock(event.block.x, event.block.y, event.block.z).set('minecraft:dirt', event.block.properties)
})

The stone does not get replaced by dirt.

BUT!

This thing will remove BlockTags from the chest that facing north somehow.

BlockEvents.placed ('minecraft:chest', event => {
     event.level.getBlock(event.block.x, event.block.y, event.block.z).set('minecraft:chest')
})

This thing will remove BlockTags from all trapped chests.

BlockEvents.placed ('minecraft:trapped_chest', event => {
     event.level.getBlock(event.block.x, event.block.y, event.block.z).set('minecraft:trapped_chest', event.block.properties)
})

At this point, I just lost.
Looks like this script can only change block to itself.

#

Acceptable for now

#

Thank you, Sona